Optimize fold layout and ids

This commit is contained in:
2022-03-22 12:22:01 +08:00
parent 5b2b60624c
commit ef0760ef16
33 changed files with 206 additions and 110 deletions

View File

@@ -21,31 +21,49 @@ import androidx.drawerlayout.widget.DrawerLayout;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import java.io.IOException;
import java.util.Collections;
public class MainActivity extends AppCompatActivity {
private AppBarConfiguration mAppBarConfiguration;
private Toolbar toolbar;
private FloatingActionButton fab;
private DrawerLayout drawer;
private NavigationView navigationView;
private void initView() {
toolbar = findViewById(R.id.toolbar);
fab = findViewById(R.id.fab);
drawer = findViewById(R.id.drawer_layout);
navigationView = findViewById(R.id.nav_view);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
//init
initView();
initLayout();
shortCutCreateTest();
}
private void initLayout() {
setSupportActionBar(toolbar);
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(view -> {
/*Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();*/
});
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 if (navigationView.getMenu().getItem(4).isChecked()) {
System.exit(0);
} else {
fab.setVisibility(View.GONE);
}
@@ -53,23 +71,14 @@ public class MainActivity extends AppCompatActivity {
// 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)
.setDrawerLayout(drawer)
.setOpenableLayout(drawer)
.build();
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
NavigationUI.setupWithNavController(navigationView, navController);
try {
ToolsList.init(getResources().getAssets().open("json/BasicTools.json"));
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), "初始化工具集失败", Toast.LENGTH_LONG).show();
}
shortCutCreateTest();
}
private void shortCutCreateTest() {
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.N_MR1) {
return;
}
@@ -78,12 +87,12 @@ public class MainActivity extends AppCompatActivity {
intent.setClassName("com.fatapp.oxygentoolbox",
"com.fatapp.oxygentoolbox.MainActivity");
ShortcutInfo.Builder builder;
builder = new ShortcutInfo.Builder(this, "dynamic shortcut")
builder = new ShortcutInfo.Builder(this, "Time Screen")
.setIntent(new Intent()
.setAction("android.intent.action.VIEW")
.setClassName("com.fatapp.oxygentoolbox", "com.fatapp.oxygentoolbox.MainActivity"))
.setShortLabel("This is a dynamic shortcut")
.setLongLabel("This is a dynamic shortcut with long label")
.setAction("activity.timescreen")
.setClassName("com.fatapp.oxygentoolbox", "com.fatapp.oxygentoolbox.tools.TimeScreenActivity"))
.setShortLabel("Time Screen")
.setLongLabel("Time Screen")
.setIcon(Icon.createWithResource(this, R.drawable.ic_menu_home));
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
shortcutManager.addDynamicShortcuts(Collections.singletonList(builder.build()));

View File

@@ -0,0 +1,14 @@
package com.fatapp.oxygentoolbox;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
}
}

View File

@@ -28,7 +28,7 @@ public class FoldLayout extends LinearLayout implements View.OnClickListener {
private ValueAnimator hideAnimator;
private View defaultView;
private OnItemClickListener mOnItemClickListener;
private OnItemClickListenerInterface mOnItemClickListener;
public FoldLayout(Context context) {
this(context, null);
@@ -58,7 +58,7 @@ public class FoldLayout extends LinearLayout implements View.OnClickListener {
defaultView = LayoutInflater.from(context).inflate(layoutId, this, true);
defaultView.setOnClickListener(this);
content = new LinearLayout(context);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
content.setOrientation(VERTICAL);
addView(content, layoutParams);
@@ -96,7 +96,7 @@ public class FoldLayout extends LinearLayout implements View.OnClickListener {
@SuppressLint("UseCompatLoadingForDrawables")
public void onAnimationStart(Animator animation) {
super.onAnimationStart(animation);
LinearLayout linearLayout = defaultView.findViewById(R.id.foldLayoutLinearLayout);
LinearLayout linearLayout = defaultView.findViewById(R.id.fold_layout_linear_layout);
linearLayout.setBackground(getResources().getDrawable(R.drawable.top_radius_background));
}
});
@@ -113,7 +113,7 @@ public class FoldLayout extends LinearLayout implements View.OnClickListener {
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
if (!isShow) {
LinearLayout linearLayout = defaultView.findViewById(R.id.foldLayoutLinearLayout);
LinearLayout linearLayout = defaultView.findViewById(R.id.fold_layout_linear_layout);
linearLayout.setBackground(getResources().getDrawable(R.drawable.top_bottom_radius_background));
}
}
@@ -143,7 +143,7 @@ public class FoldLayout extends LinearLayout implements View.OnClickListener {
public void showItem() {
isShow = true;
showAnimator.start();
ImageView imageView = defaultView.findViewById(R.id.arrowIcon);
ImageView imageView = defaultView.findViewById(R.id.arrow_icon);
imageView.setImageDrawable(getResources().getDrawable(R.drawable.right_to_down_arrow));
AnimatedVectorDrawable animatedVectorDrawable = (AnimatedVectorDrawable) imageView.getDrawable();
animatedVectorDrawable.start();
@@ -153,17 +153,13 @@ public class FoldLayout extends LinearLayout implements View.OnClickListener {
public void hideItem() {
isShow = false;
hideAnimator.start();
ImageView imageView = defaultView.findViewById(R.id.arrowIcon);
ImageView imageView = defaultView.findViewById(R.id.arrow_icon);
imageView.setImageDrawable(getResources().getDrawable(R.drawable.down_to_right_arrow));
AnimatedVectorDrawable animatedVectorDrawable = (AnimatedVectorDrawable) imageView.getDrawable();
animatedVectorDrawable.start();
}
interface OnItemClickListener {
void onItemClick(View view, int position);
}
public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
public void setOnItemClickListener(OnItemClickListenerInterface onItemClickListener) {
this.mOnItemClickListener = onItemClickListener;
}
}

View File

@@ -0,0 +1,7 @@
package com.fatapp.oxygentoolbox.layout;
import android.view.View;
interface OnItemClickListenerInterface {
void onItemClick(View view, int position);
}

View File

@@ -11,7 +11,6 @@ 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;
}
}

View File

@@ -1,16 +1,14 @@
package com.fatapp.oxygentoolbox.ui.home;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Icon;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
@@ -21,12 +19,14 @@ import com.fatapp.oxygentoolbox.layout.FoldLayout;
import com.fatapp.oxygentoolbox.util.BasicToolsLauncher;
import com.fatapp.oxygentoolbox.util.ToolsList;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class HomeFragment extends Fragment {
View root;
private View root;
private HomeViewModel homeViewModel;
@@ -36,37 +36,60 @@ public class HomeFragment extends Fragment {
homeViewModel =
new ViewModelProvider(this).get(HomeViewModel.class);
root = inflater.inflate(R.layout.fragment_home, container, false);
//init
initView();
initLayout();
return root;
}
private void initView() {
for (ToolsList.Tool tool : ToolsList.getToolList()) {
foldLayoutsLinearLayout = root.findViewById(R.id.fold_layouts_linear_layout);
}
View foldLayoutBody = getLayoutInflater().inflate(R.layout.fold_layout_body, null);
ViewGroup layout_item_AutoLinefeedLayout = foldLayoutBody.findViewById(R.id.layout_item_AutoLinefeedLayout);
private void initLayout() {
initFoldLayout();
}
private void initFoldLayout() {
try {
ToolsList.init(getResources().getAssets().open("json/BasicTools.json"));
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(getContext(), "初始化工具集失败", Toast.LENGTH_LONG).show();
return;
}
for (ToolsList.Tool tool : ToolsList.getToolList()) {
View foldLayoutBodyLayout = getLayoutInflater().inflate(R.layout.fold_layout_body, null);
ViewGroup autoLinefeedLayout = foldLayoutBodyLayout.findViewById(R.id.auto_linefeed_layout);
for (ToolsList.Button button : tool.getButtonList()) {
View toolButton = getLayoutInflater().inflate(R.layout.tool_button, null);
((Button) toolButton.findViewById(R.id.toolButton)).setText(button.getText());
toolButton.findViewById(R.id.toolButton).setOnClickListener(v -> {
View toolButtonLayout = getLayoutInflater().inflate(R.layout.tool_button, null);
Button toolButton = toolButtonLayout.findViewById(R.id.tool_button);
toolButton.setText(button.getText());
toolButton.setOnClickListener(v -> {
BasicToolsLauncher.launch(button.getActivity(), getContext());
});
layout_item_AutoLinefeedLayout.addView(toolButton);
autoLinefeedLayout.addView(toolButtonLayout);
}
List<View> viewList = new ArrayList<>();
viewList.add(foldLayoutBody);
viewList.add(foldLayoutBodyLayout);
View foldLayoutHead = getLayoutInflater().inflate(R.layout.fold_layout, null);
FoldLayout foldLayout = foldLayoutHead.findViewById(R.id.foldLayout);
((TextView) foldLayout.findViewById(R.id.foldLayoutTextView)).setText(tool.getFoldLayoutTitle());
((TextView) foldLayout.findViewById(R.id.foldLayoutIcon)).setTypeface(Typeface.createFromAsset(getContext().getAssets(), tool.getFont()));
((TextView) foldLayout.findViewById(R.id.foldLayoutIcon)).setText(tool.getIcon());
FoldLayout foldLayout = foldLayoutHead.findViewById(R.id.fold_layout);
((TextView) foldLayout.findViewById(R.id.fold_layout_text_view)).setText(tool.getFoldLayoutTitle());
TextView foldLayoutIcon = foldLayout.findViewById(R.id.fold_layout_icon);
foldLayoutIcon.setTypeface(Typeface.createFromAsset(Objects.requireNonNull(getContext()).getAssets(), tool.getFont()));
foldLayoutIcon.setText(tool.getIcon());
foldLayout.addItemView(viewList);
foldLayoutsLinearLayout = root.findViewById(R.id.foldLayoutsLinearLayout);
foldLayoutsLinearLayout.removeAllViews();
foldLayoutsLinearLayout.addView(foldLayoutHead);
}
@@ -93,4 +116,6 @@ public class HomeFragment extends Fragment {
foldLayoutsLinearLayout.addView(foldLayoutHead);
}*/
}
}

View File

@@ -22,7 +22,8 @@ public class SettingFragment extends Fragment {
ViewGroup container, Bundle savedInstanceState) {
settingViewModel =
new ViewModelProvider(this).get(SettingViewModel.class);
View root = inflater.inflate(R.layout.fragment_about, container, false);
View root = inflater.inflate(R.layout.fragment_setting, container, false);
/*
final TextView textView = root.findViewById(R.id.text_setting);
settingViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
@Override
@@ -30,6 +31,7 @@ public class SettingFragment extends Fragment {
textView.setText(s);
}
});
*/
return root;
}
}

View File

@@ -40,7 +40,7 @@ public class ToolsList {
return toolList;
}
public void setToolList(List<Tool> toolList) {
public static void setToolList(List<Tool> toolList) {
ToolsList.toolList = toolList;
}