mirror of
https://github.com/FatttSnake/OxygenToolbox.git
synced 2026-04-06 09:41:26 +08:00
Dynamic add ToolButtons
Add Navigation menu Change home_fragment's padding Unified color management
This commit is contained in:
@@ -5,6 +5,7 @@ import android.content.pm.ShortcutInfo;
|
||||
import android.content.pm.ShortcutManager;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.os.Bundle;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.Menu;
|
||||
|
||||
@@ -29,7 +30,6 @@ import java.util.List;
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
private AppBarConfiguration mAppBarConfiguration;
|
||||
private FoldLayout foldLayout;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -44,10 +44,18 @@ public class MainActivity extends AppCompatActivity {
|
||||
});
|
||||
DrawerLayout drawer = findViewById(R.id.drawer_layout);
|
||||
NavigationView navigationView = findViewById(R.id.nav_view);
|
||||
navigationView.inflateHeaderView(R.layout.nav_header_main);
|
||||
navigationView.inflateMenu(R.menu.activity_main_drawer);
|
||||
navigationView.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
|
||||
if (navigationView.getMenu().getItem(0).isChecked()) {
|
||||
fab.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
fab.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
// Passing each menu ID as a set of Ids because each
|
||||
// menu should be considered as top level destinations.
|
||||
mAppBarConfiguration = new AppBarConfiguration.Builder(
|
||||
R.id.nav_home, R.id.nav_gallery, R.id.nav_slideshow)
|
||||
mAppBarConfiguration = new AppBarConfiguration.Builder(R.id.nav_home)
|
||||
.setDrawerLayout(drawer)
|
||||
.build();
|
||||
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
|
||||
@@ -73,7 +81,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
.setClassName("com.fatapp.oxygentoolbox", "com.fatapp.oxygentoolbox.MainActivity"))
|
||||
.setShortLabel("This is a dynamic shortcut")
|
||||
.setLongLabel("This is a dynamic shortcut with long label")
|
||||
.setIcon(Icon.createWithResource(this, R.drawable.ic_menu_camera));
|
||||
.setIcon(Icon.createWithResource(this, R.drawable.ic_menu_home));
|
||||
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
|
||||
shortcutManager.addDynamicShortcuts(Collections.singletonList(builder.build()));
|
||||
}
|
||||
@@ -91,14 +99,4 @@ public class MainActivity extends AppCompatActivity {
|
||||
return NavigationUI.navigateUp(navController, mAppBarConfiguration)
|
||||
|| super.onSupportNavigateUp();
|
||||
}
|
||||
|
||||
public void initView() {
|
||||
foldLayout = (FoldLayout) findViewById(R.id.foldLayout);
|
||||
|
||||
List<View> viewList = new ArrayList<>();
|
||||
|
||||
viewList.add(getLayoutInflater().inflate(R.layout.layout_item, null));
|
||||
|
||||
foldLayout.addItemView(viewList);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.fatapp.oxygentoolbox.ui.slideshow;
|
||||
package com.fatapp.oxygentoolbox.ui.about;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -14,17 +14,17 @@ import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.fatapp.oxygentoolbox.R;
|
||||
|
||||
public class SlideshowFragment extends Fragment {
|
||||
public class AboutFragment extends Fragment {
|
||||
|
||||
private SlideshowViewModel slideshowViewModel;
|
||||
private AboutViewModel aboutViewModel;
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
slideshowViewModel =
|
||||
new ViewModelProvider(this).get(SlideshowViewModel.class);
|
||||
View root = inflater.inflate(R.layout.fragment_slideshow, container, false);
|
||||
final TextView textView = root.findViewById(R.id.text_slideshow);
|
||||
slideshowViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
|
||||
aboutViewModel =
|
||||
new ViewModelProvider(this).get(AboutViewModel.class);
|
||||
View root = inflater.inflate(R.layout.fragment_about, container, false);
|
||||
final TextView textView = root.findViewById(R.id.text_about);
|
||||
aboutViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable String s) {
|
||||
textView.setText(s);
|
||||
@@ -1,16 +1,16 @@
|
||||
package com.fatapp.oxygentoolbox.ui.gallery;
|
||||
package com.fatapp.oxygentoolbox.ui.about;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
public class GalleryViewModel extends ViewModel {
|
||||
public class AboutViewModel extends ViewModel {
|
||||
|
||||
private MutableLiveData<String> mText;
|
||||
|
||||
public GalleryViewModel() {
|
||||
public AboutViewModel() {
|
||||
mText = new MutableLiveData<>();
|
||||
mText.setValue("This is gallery fragment");
|
||||
mText.setValue("This is about fragment");
|
||||
}
|
||||
|
||||
public LiveData<String> getText() {
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.fatapp.oxygentoolbox.ui.exit;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
public class ExitFragment extends Fragment {
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
System.exit(0);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,12 @@ package com.fatapp.oxygentoolbox.ui.home;
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.os.Bundle;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -33,8 +35,7 @@ public class HomeFragment extends Fragment {
|
||||
private FoldLayout foldLayout;
|
||||
private FoldLayout foldLayout1;
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
homeViewModel =
|
||||
new ViewModelProvider(this).get(HomeViewModel.class);
|
||||
root = inflater.inflate(R.layout.fragment_home, container, false);
|
||||
@@ -43,12 +44,19 @@ public class HomeFragment extends Fragment {
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
foldLayout = (FoldLayout) root.findViewById(R.id.foldLayout);
|
||||
foldLayout = root.findViewById(R.id.foldLayout);
|
||||
List<View> viewList = new ArrayList<>();
|
||||
viewList.add(getLayoutInflater().inflate(R.layout.layout_item, null));
|
||||
View layout_item = getLayoutInflater().inflate(R.layout.layout_item, null);
|
||||
ViewGroup layout_item_AutoLinefeedLayout = layout_item.findViewById(R.id.layout_item_AutoLinefeedLayout);
|
||||
for (int i = 1; i < 1000; i++) {
|
||||
View toolButton = getLayoutInflater().inflate(R.layout.tool_button, null);
|
||||
((Button) toolButton.findViewById(R.id.toolButton)).setText("Bt" + i);
|
||||
layout_item_AutoLinefeedLayout.addView(toolButton);
|
||||
}
|
||||
viewList.add(layout_item);
|
||||
foldLayout.addItemView(viewList);
|
||||
|
||||
foldLayout1 = (FoldLayout) root.findViewById(R.id.foldLayout1);
|
||||
foldLayout1 = root.findViewById(R.id.foldLayout1);
|
||||
List<View> viewList1 = new ArrayList<>();
|
||||
viewList1.add(getLayoutInflater().inflate(R.layout.layout_item, null));
|
||||
foldLayout1.addItemView(viewList1);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.fatapp.oxygentoolbox.ui.gallery;
|
||||
package com.fatapp.oxygentoolbox.ui.setting;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -14,17 +14,17 @@ import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.fatapp.oxygentoolbox.R;
|
||||
|
||||
public class GalleryFragment extends Fragment {
|
||||
public class SettingFragment extends Fragment {
|
||||
|
||||
private GalleryViewModel galleryViewModel;
|
||||
private SettingViewModel settingViewModel;
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
galleryViewModel =
|
||||
new ViewModelProvider(this).get(GalleryViewModel.class);
|
||||
View root = inflater.inflate(R.layout.fragment_gallery, container, false);
|
||||
final TextView textView = root.findViewById(R.id.text_gallery);
|
||||
galleryViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
|
||||
settingViewModel =
|
||||
new ViewModelProvider(this).get(SettingViewModel.class);
|
||||
View root = inflater.inflate(R.layout.fragment_about, container, false);
|
||||
final TextView textView = root.findViewById(R.id.text_setting);
|
||||
settingViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable String s) {
|
||||
textView.setText(s);
|
||||
@@ -1,16 +1,16 @@
|
||||
package com.fatapp.oxygentoolbox.ui.slideshow;
|
||||
package com.fatapp.oxygentoolbox.ui.setting;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
public class SlideshowViewModel extends ViewModel {
|
||||
public class SettingViewModel extends ViewModel {
|
||||
|
||||
private MutableLiveData<String> mText;
|
||||
|
||||
public SlideshowViewModel() {
|
||||
public SettingViewModel() {
|
||||
mText = new MutableLiveData<>();
|
||||
mText.setValue("This is slideshow fragment");
|
||||
mText.setValue("This is setting fragment");
|
||||
}
|
||||
|
||||
public LiveData<String> getText() {
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.fatapp.oxygentoolbox.ui.theme;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.fatapp.oxygentoolbox.R;
|
||||
|
||||
public class ThemeFragment extends Fragment {
|
||||
|
||||
private ThemeViewModel themeViewModel;
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
themeViewModel =
|
||||
new ViewModelProvider(this).get(ThemeViewModel.class);
|
||||
View root = inflater.inflate(R.layout.fragment_theme, container, false);
|
||||
final TextView textView = root.findViewById(R.id.text_theme);
|
||||
themeViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable String s) {
|
||||
textView.setText(s);
|
||||
}
|
||||
});
|
||||
return root;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.fatapp.oxygentoolbox.ui.theme;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
public class ThemeViewModel extends ViewModel {
|
||||
|
||||
private MutableLiveData<String> mText;
|
||||
|
||||
public ThemeViewModel() {
|
||||
mText = new MutableLiveData<>();
|
||||
mText.setValue("This is theme fragment");
|
||||
}
|
||||
|
||||
public LiveData<String> getText() {
|
||||
return mText;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user