mirror of
https://github.com/FatttSnake/OxygenToolbox.git
synced 2026-04-06 01:01:27 +08:00
Optimized the loading of ToolList. Fix the repeated bug when ToolList is reloaded. Display ToolList using RecyclerView. Optimized FoldLayout, removed the default hidden function.
This commit is contained in:
4
.idea/deploymentTargetDropDown.xml
generated
4
.idea/deploymentTargetDropDown.xml
generated
@@ -7,12 +7,12 @@
|
||||
<deviceKey>
|
||||
<Key>
|
||||
<type value="SERIAL_NUMBER" />
|
||||
<value value="adb-a9f1bb3a-moNgbH._adb-tls-connect._tcp" />
|
||||
<value value="a8cada36" />
|
||||
</Key>
|
||||
</deviceKey>
|
||||
</Target>
|
||||
</runningDeviceTargetSelectedWithDropDown>
|
||||
<timeTargetWasSelectedWithDropDown value="2022-08-07T05:21:28.685430900Z" />
|
||||
<timeTargetWasSelectedWithDropDown value="2022-08-07T06:23:39.099208800Z" />
|
||||
<runningDeviceTargetsSelectedWithDialog>
|
||||
<Target>
|
||||
<type value="RUNNING_DEVICE_TARGET" />
|
||||
|
||||
7
.idea/misc.xml
generated
7
.idea/misc.xml
generated
@@ -10,8 +10,11 @@
|
||||
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/drawable-v21/ic_menu_theme.xml" value="0.246875" />
|
||||
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/drawable-v21/ripple_foreground.xml" value="0.15520833333333334" />
|
||||
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/drawable-v24/ic_launcher_foreground.xml" value="0.11944444444444445" />
|
||||
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/drawable/animation_right_to_down_arrow.xml" value="0.164" />
|
||||
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/drawable/background_bottom_radius.xml" value="0.2915" />
|
||||
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/drawable/background_no_radius.xml" value="0.165" />
|
||||
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/drawable/background_theme_bottom.xml" value="0.164" />
|
||||
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/drawable/background_theme_top.xml" value="0.164" />
|
||||
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/drawable/background_top_bottom_radius.xml" value="0.2915" />
|
||||
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/drawable/background_top_radius.xml" value="0.165" />
|
||||
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/drawable/bottom_radius_background.xml" value="0.11944444444444445" />
|
||||
@@ -44,6 +47,7 @@
|
||||
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/drawable/tools_icon.xml" value="0.11944444444444445" />
|
||||
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/drawable/top_bottom_radius_background.xml" value="0.11944444444444445" />
|
||||
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/drawable/top_radius_background.xml" value="0.11944444444444445" />
|
||||
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/layout-v23/fold_layout_button.xml" value="0.10416666666666667" />
|
||||
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/layout/activity_libraries.xml" value="0.1" />
|
||||
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/layout/activity_licenses.xml" value="0.1" />
|
||||
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/layout/activity_main.xml" value="0.1" />
|
||||
@@ -54,6 +58,7 @@
|
||||
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/layout/content_main.xml" value="0.14990942028985507" />
|
||||
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/layout/fold_layout.xml" value="0.67" />
|
||||
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/layout/fold_layout_body.xml" value="0.21932449764856776" />
|
||||
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/layout/fold_layout_button.xml" value="0.29713552800342025" />
|
||||
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/layout/fold_layout_head.xml" value="0.33" />
|
||||
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/layout/fragment_about.xml" value="0.25" />
|
||||
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/layout/fragment_gallery.xml" value="0.1" />
|
||||
@@ -65,9 +70,11 @@
|
||||
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/layout/fragment_slideshow.xml" value="0.1" />
|
||||
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/layout/fragment_theme.xml" value="0.33" />
|
||||
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/layout/fragment_tools.xml" value="0.33" />
|
||||
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/layout/item_fold_layout.xml" value="0.2756119673617407" />
|
||||
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/layout/item_libraries.xml" value="0.5" />
|
||||
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/layout/item_licenses.xml" value="0.33" />
|
||||
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/layout/item_themes.xml" value="0.33" />
|
||||
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/layout/item_tools.xml" value="0.1483539974348012" />
|
||||
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/layout/layout_item.xml" value="0.1" />
|
||||
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/layout/nav_header_main.xml" value="0.1" />
|
||||
<entry key="..\:/.workspace-android/Project-ToolBox/OxygenToolbox/app/src/main/res/layout/tool_button.xml" value="0.3619791666666667" />
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -12,12 +13,23 @@ import androidx.annotation.Nullable;
|
||||
import com.fatapp.oxygentoolbox.util.MultiLanguageUtils;
|
||||
import com.fatapp.oxygentoolbox.util.ResourceUtil;
|
||||
import com.fatapp.oxygentoolbox.util.SharedPreferencesUtils;
|
||||
import com.fatapp.oxygentoolbox.util.ToolsList;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class App extends Application {
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
try {
|
||||
ToolsList.init(getResources().getAssets().open("json/BasicTools.json"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Toast.makeText(getApplicationContext(), R.string.init_tools_failed, Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
|
||||
@Override
|
||||
public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle bundle) {
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.fatapp.oxygentoolbox.layout;
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.drawable.AnimatedVectorDrawable;
|
||||
@@ -14,6 +13,7 @@ import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.content.res.AppCompatResources;
|
||||
|
||||
import com.fatapp.oxygentoolbox.R;
|
||||
@@ -24,8 +24,8 @@ public class FoldLayout extends LinearLayout implements View.OnClickListener {
|
||||
|
||||
private boolean init;
|
||||
private final int layoutId;
|
||||
private boolean isShow;
|
||||
private boolean isDefaultShow;
|
||||
private final long duration;
|
||||
private boolean isShow = true;
|
||||
private LinearLayout content;
|
||||
private ValueAnimator showAnimator;
|
||||
private ValueAnimator hideAnimator;
|
||||
@@ -37,15 +37,19 @@ public class FoldLayout extends LinearLayout implements View.OnClickListener {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public FoldLayout(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0, false);
|
||||
public FoldLayout(Context context, @Nullable AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public FoldLayout(Context context, AttributeSet attrs, int defStyleAttr, boolean isDefaultShow) {
|
||||
public FoldLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
@SuppressLint("Recycle") TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.FoldLayout, defStyleAttr, 0);
|
||||
layoutId = ta.getResourceId(R.styleable.FoldLayout_layoutId, -1);
|
||||
this.isDefaultShow = isDefaultShow;
|
||||
TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.FoldLayout, defStyleAttr, 0);
|
||||
try {
|
||||
layoutId = typedArray.getResourceId(R.styleable.FoldLayout_layoutId, -1);
|
||||
duration = typedArray.getInt(R.styleable.FoldLayout_transitionTime, 500);
|
||||
} finally {
|
||||
typedArray.recycle();
|
||||
}
|
||||
init(context);
|
||||
}
|
||||
|
||||
@@ -54,19 +58,11 @@ public class FoldLayout extends LinearLayout implements View.OnClickListener {
|
||||
addDefaultLayout(context);
|
||||
}
|
||||
|
||||
public void setDefaultShow(boolean defaultShow) {
|
||||
isDefaultShow = defaultShow;
|
||||
}
|
||||
|
||||
public View getDefaultView() {
|
||||
return defaultView;
|
||||
}
|
||||
|
||||
/**
|
||||
* Init
|
||||
*/
|
||||
private void addDefaultLayout(Context context) {
|
||||
|
||||
defaultView = LayoutInflater.from(context).inflate(layoutId, this, true);
|
||||
defaultView.setOnClickListener(this);
|
||||
content = new LinearLayout(context);
|
||||
@@ -95,53 +91,46 @@ public class FoldLayout extends LinearLayout implements View.OnClickListener {
|
||||
* Animation
|
||||
*/
|
||||
private void initAnimation() {
|
||||
|
||||
int contentHeight = content.getMeasuredHeight();
|
||||
if (!init) {
|
||||
int contentHeight = content.getMeasuredHeight();
|
||||
LayoutParams layoutParams = (LayoutParams) content.getLayoutParams();
|
||||
if (isDefaultShow) {
|
||||
isShow = true;
|
||||
layoutParams.height = contentHeight;
|
||||
LinearLayout linearLayout = defaultView.findViewById(R.id.fold_layout_linear_layout);
|
||||
linearLayout.setBackground(AppCompatResources.getDrawable(getContext(), R.drawable.background_top_radius));
|
||||
ImageView imageView = defaultView.findViewById(R.id.arrow_icon);
|
||||
imageView.setImageDrawable(AppCompatResources.getDrawable(getContext(), R.drawable.down_to_right_arrow));
|
||||
} else {
|
||||
layoutParams.height = 0;
|
||||
LinearLayout linearLayout = defaultView.findViewById(R.id.fold_layout_linear_layout);
|
||||
linearLayout.setBackground(AppCompatResources.getDrawable(getContext(), R.drawable.background_top_bottom_radius));
|
||||
ImageView imageView = defaultView.findViewById(R.id.arrow_icon);
|
||||
imageView.setImageDrawable(AppCompatResources.getDrawable(getContext(), R.drawable.right_to_down_arrow));
|
||||
}
|
||||
layoutParams.height = contentHeight;
|
||||
LinearLayout linearLayout = defaultView.findViewById(R.id.fold_layout_head_layout);
|
||||
linearLayout.setBackground(AppCompatResources.getDrawable(getContext(), R.drawable.background_top_radius));
|
||||
ImageView imageView = defaultView.findViewById(R.id.fold_layout_arrow_icon);
|
||||
imageView.setImageDrawable(AppCompatResources.getDrawable(getContext(), R.drawable.animation_down_to_right_arrow));
|
||||
content.setLayoutParams(layoutParams);
|
||||
|
||||
showAnimator = ValueAnimator.ofInt(0, contentHeight);
|
||||
showAnimator.setDuration(duration);
|
||||
showAnimator.addUpdateListener(animation -> {
|
||||
layoutParams.height = (int) animation.getAnimatedValue();
|
||||
content.setLayoutParams(layoutParams);
|
||||
});
|
||||
showAnimator.addListener(new AnimatorListenerAdapter() {
|
||||
@SuppressLint("UseCompatLoadingForDrawables")
|
||||
@Override
|
||||
public void onAnimationStart(Animator animation) {
|
||||
super.onAnimationStart(animation);
|
||||
LinearLayout linearLayout = defaultView.findViewById(R.id.fold_layout_linear_layout);
|
||||
linearLayout.setBackground(getContext().getDrawable(R.drawable.background_top_radius));
|
||||
if (isShow) {
|
||||
LinearLayout linearLayout = defaultView.findViewById(R.id.fold_layout_head_layout);
|
||||
linearLayout.setBackground(AppCompatResources.getDrawable(getContext(), R.drawable.background_top_radius));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
hideAnimator = ValueAnimator.ofInt(contentHeight, 0);
|
||||
hideAnimator.setDuration(duration);
|
||||
hideAnimator.addUpdateListener(animation -> {
|
||||
layoutParams.height = (int) animation.getAnimatedValue();
|
||||
content.setLayoutParams(layoutParams);
|
||||
});
|
||||
hideAnimator.addListener(new AnimatorListenerAdapter() {
|
||||
@SuppressLint("UseCompatLoadingForDrawables")
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
super.onAnimationEnd(animation);
|
||||
if (!isShow) {
|
||||
LinearLayout linearLayout = defaultView.findViewById(R.id.fold_layout_linear_layout);
|
||||
linearLayout.setBackground(getContext().getDrawable(R.drawable.background_top_bottom_radius));
|
||||
LinearLayout linearLayout = defaultView.findViewById(R.id.fold_layout_head_layout);
|
||||
linearLayout.setBackground(AppCompatResources.getDrawable(getContext(), R.drawable.background_top_bottom_radius));
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -156,30 +145,28 @@ public class FoldLayout extends LinearLayout implements View.OnClickListener {
|
||||
for (int i = 0; i < views.size(); i++) {
|
||||
final int position = i;
|
||||
content.addView(views.get(i));
|
||||
views.get(i).setOnClickListener(v -> {
|
||||
views.get(i).setOnClickListener(view -> {
|
||||
if (null != mOnItemClickListener) {
|
||||
mOnItemClickListener.onItemClick(v, position);
|
||||
mOnItemClickListener.onItemClick(view, position);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("UseCompatLoadingForDrawables")
|
||||
public void showItem() {
|
||||
isShow = true;
|
||||
showAnimator.start();
|
||||
ImageView imageView = defaultView.findViewById(R.id.arrow_icon);
|
||||
imageView.setImageDrawable(getContext().getDrawable(R.drawable.right_to_down_arrow));
|
||||
ImageView imageView = defaultView.findViewById(R.id.fold_layout_arrow_icon);
|
||||
imageView.setImageDrawable(AppCompatResources.getDrawable(getContext(), R.drawable.animation_right_to_down_arrow));
|
||||
AnimatedVectorDrawable animatedVectorDrawable = (AnimatedVectorDrawable) imageView.getDrawable();
|
||||
animatedVectorDrawable.start();
|
||||
}
|
||||
|
||||
@SuppressLint("UseCompatLoadingForDrawables")
|
||||
public void hideItem() {
|
||||
isShow = false;
|
||||
hideAnimator.start();
|
||||
ImageView imageView = defaultView.findViewById(R.id.arrow_icon);
|
||||
imageView.setImageDrawable(getContext().getDrawable(R.drawable.down_to_right_arrow));
|
||||
ImageView imageView = defaultView.findViewById(R.id.fold_layout_arrow_icon);
|
||||
imageView.setImageDrawable(AppCompatResources.getDrawable(getContext(), R.drawable.animation_down_to_right_arrow));
|
||||
AnimatedVectorDrawable animatedVectorDrawable = (AnimatedVectorDrawable) imageView.getDrawable();
|
||||
animatedVectorDrawable.start();
|
||||
}
|
||||
|
||||
@@ -1,30 +1,18 @@
|
||||
package com.fatapp.oxygentoolbox.ui.home.tools;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.fatapp.oxygentoolbox.R;
|
||||
import com.fatapp.oxygentoolbox.layout.FoldLayout;
|
||||
import com.fatapp.oxygentoolbox.util.ToolsLauncher;
|
||||
import com.fatapp.oxygentoolbox.util.ToolsList;
|
||||
import com.fatapp.oxygentoolbox.util.VibratorController;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.fatapp.oxygentoolbox.ui.home.util.ToolsAdapter;
|
||||
|
||||
public class ToolsFragment extends Fragment {
|
||||
|
||||
@@ -32,7 +20,7 @@ public class ToolsFragment extends Fragment {
|
||||
|
||||
private ToolsViewModel toolsViewModel;
|
||||
|
||||
private LinearLayout foldLayoutsLinearLayout;
|
||||
private RecyclerView toolsRecyclerView;
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
toolsViewModel = new ViewModelProvider(this).get(ToolsViewModel.class);
|
||||
@@ -46,92 +34,11 @@ public class ToolsFragment extends Fragment {
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
foldLayoutsLinearLayout = root.findViewById(R.id.fold_layouts_linear_layout);
|
||||
toolsRecyclerView = root.findViewById(R.id.tools_recycler_view);
|
||||
}
|
||||
|
||||
private void initLayout() {
|
||||
initFoldLayout();
|
||||
toolsRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
toolsRecyclerView.setAdapter(new ToolsAdapter());
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
private void initFoldLayout() {
|
||||
try {
|
||||
ToolsList.init(getResources().getAssets().open("json/BasicTools.json"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Toast.makeText(getContext(), R.string.init_tools_failed, 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 toolButtonLayout = getLayoutInflater().inflate(R.layout.fold_layout_button, null);
|
||||
Button toolButton = toolButtonLayout.findViewById(R.id.tool_button);
|
||||
toolButton.setText(button.getText());
|
||||
|
||||
toolButton.setOnClickListener(v -> ToolsLauncher.launch(getContext(), button.getActivity()));
|
||||
|
||||
toolButton.setOnTouchListener((v, event) -> {
|
||||
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
v.animate().translationZ(8f).setDuration(100L);
|
||||
}
|
||||
if (event.getAction() == MotionEvent.ACTION_UP) {
|
||||
v.animate().translationZ(0).setDuration(100L);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
toolButton.setOnLongClickListener(v -> {
|
||||
v.animate().translationZ(0).setDuration(100L);
|
||||
VibratorController.vibrate(1);
|
||||
return false;
|
||||
});
|
||||
|
||||
autoLinefeedLayout.addView(toolButtonLayout);
|
||||
}
|
||||
|
||||
List<View> viewList = new ArrayList<>();
|
||||
viewList.add(foldLayoutBodyLayout);
|
||||
|
||||
View foldLayoutHead = getLayoutInflater().inflate(R.layout.fold_layout, null);
|
||||
FoldLayout foldLayout = foldLayoutHead.findViewById(R.id.fold_layout);
|
||||
foldLayout.setDefaultShow(true);
|
||||
((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(requireContext().getAssets(), tool.getFont()));
|
||||
foldLayoutIcon.setText(tool.getIcon());
|
||||
|
||||
foldLayout.addItemView(viewList);
|
||||
|
||||
foldLayoutsLinearLayout.removeAllViews();
|
||||
foldLayoutsLinearLayout.addView(foldLayoutHead);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
View toolButton = getLayoutInflater().inflate(R.layout.fold_layout_button, null);
|
||||
((Button) toolButton.findViewById(R.id.tool_button)).setText("Button");
|
||||
toolButton.findViewById(R.id.tool_button).setOnClickListener(v -> {
|
||||
});
|
||||
|
||||
View foldLayoutBody = getLayoutInflater().inflate(R.layout.fold_layout_body, null);
|
||||
ViewGroup layout_item_AutoLinefeedLayout = foldLayoutBody.findViewById(R.id.auto_linefeed_layout);
|
||||
layout_item_AutoLinefeedLayout.addView(toolButton);
|
||||
|
||||
List<View> viewList = new ArrayList<>();
|
||||
viewList.add(foldLayoutBody);
|
||||
|
||||
View foldLayoutHead = getLayoutInflater().inflate(R.layout.fold_layout, null);
|
||||
FoldLayout foldLayout = foldLayoutHead.findViewById(R.id.fold_layout);
|
||||
((TextView) foldLayout.findViewById(R.id.fold_layout_text_view)).setText("FoldLayout_" + i);
|
||||
foldLayout.addItemView(viewList);
|
||||
|
||||
foldLayoutsLinearLayout.addView(foldLayoutHead);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.fatapp.oxygentoolbox.ui.home.util;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.graphics.Typeface;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.fatapp.oxygentoolbox.R;
|
||||
import com.fatapp.oxygentoolbox.layout.AutoLinefeedLayout;
|
||||
import com.fatapp.oxygentoolbox.layout.FoldLayout;
|
||||
import com.fatapp.oxygentoolbox.util.ToolsLauncher;
|
||||
import com.fatapp.oxygentoolbox.util.ToolsList;
|
||||
import com.fatapp.oxygentoolbox.util.VibratorController;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
public class ToolsAdapter extends RecyclerView.Adapter<ToolsAdapter.ViewHolder> {
|
||||
private ViewGroup parent;
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
this.parent = parent;
|
||||
View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_tools, parent, false);
|
||||
return new ViewHolder(inflate);
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
||||
View foldLayoutBodyLayout = LayoutInflater.from(parent.getContext()).inflate(R.layout.fold_layout_body, parent, false);
|
||||
AutoLinefeedLayout autoLinefeedLayout = foldLayoutBodyLayout.findViewById(R.id.auto_linefeed_layout);
|
||||
ToolsList.Tool tool = ToolsList.getToolList().get(position);
|
||||
for (ToolsList.Button button : tool.getButtonList()) {
|
||||
View toolButtonLayout = LayoutInflater.from(parent.getContext()).inflate(R.layout.fold_layout_button, parent, false);
|
||||
Button toolButton = toolButtonLayout.findViewById(R.id.tool_button);
|
||||
toolButton.setText(button.getText());
|
||||
toolButton.setOnClickListener(view -> ToolsLauncher.launch(parent.getContext(), button.getActivity()));
|
||||
toolButton.setOnTouchListener((view, motionEvent) -> {
|
||||
|
||||
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
view.animate().translationZ(8f).setDuration(100L);
|
||||
}
|
||||
if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
|
||||
view.animate().translationZ(0).setDuration(100L);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
toolButton.setOnLongClickListener(v -> {
|
||||
v.animate().translationZ(0).setDuration(100L);
|
||||
VibratorController.vibrate(1);
|
||||
return false;
|
||||
});
|
||||
|
||||
autoLinefeedLayout.addView(toolButtonLayout);
|
||||
}
|
||||
|
||||
TextView foldLayoutIcon = holder.getFoldLayout().findViewById(R.id.fold_layout_icon);
|
||||
foldLayoutIcon.setTypeface(Typeface.createFromAsset(parent.getContext().getAssets(), tool.getFont()));
|
||||
foldLayoutIcon.setText(tool.getIcon());
|
||||
((TextView) holder.getFoldLayout().findViewById(R.id.fold_layout_text_view)).setText(tool.getFoldLayoutTitle());
|
||||
holder.getFoldLayout().addItemView(Collections.singletonList(foldLayoutBodyLayout));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return ToolsList.getToolList().size();
|
||||
}
|
||||
|
||||
public static class ViewHolder extends RecyclerView.ViewHolder {
|
||||
private final FoldLayout foldLayout;
|
||||
public ViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
foldLayout = itemView.findViewById(R.id.fold_layout);
|
||||
}
|
||||
|
||||
public FoldLayout getFoldLayout() {
|
||||
return foldLayout;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ public class ToolsList {
|
||||
private static List<Tool> toolList = new ArrayList<>();
|
||||
|
||||
public static void init(InputStream file) throws IOException {
|
||||
toolList.clear();
|
||||
String str;
|
||||
StringBuilder jsonStringBuilder = new StringBuilder();
|
||||
InputStreamReader inputStreamReader = new InputStreamReader(file);
|
||||
|
||||
7
app/src/main/res/drawable/background_theme_bottom.xml
Normal file
7
app/src/main/res/drawable/background_theme_bottom.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="?attr/fold_layout_background" />
|
||||
<corners
|
||||
android:bottomLeftRadius="10dp"
|
||||
android:bottomRightRadius="10dp"/>
|
||||
</shape>
|
||||
7
app/src/main/res/drawable/background_theme_top.xml
Normal file
7
app/src/main/res/drawable/background_theme_top.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="?attr/fold_layout_background" />
|
||||
<corners
|
||||
android:topLeftRadius="10dp"
|
||||
android:topRightRadius="10dp"/>
|
||||
</shape>
|
||||
@@ -3,7 +3,7 @@
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/nav_header_height"
|
||||
android:background="@drawable/side_nav_bar"
|
||||
android:background="@drawable/background_side_nav_bar"
|
||||
android:gravity="bottom"
|
||||
android:orientation="vertical"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
|
||||
@@ -11,12 +11,11 @@
|
||||
android:id="@+id/auto_linefeed_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginRight="10dp"
|
||||
android:paddingHorizontal="5dp"
|
||||
android:paddingBottom="2dp"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:background="@drawable/background_bottom_radius"
|
||||
android:gravity="center_vertical">
|
||||
</com.fatapp.oxygentoolbox.layout.AutoLinefeedLayout>
|
||||
android:gravity="center_vertical"
|
||||
android:paddingHorizontal="5dp"
|
||||
android:paddingBottom="2dp" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -1,11 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/fold_layout_linear_layout"
|
||||
android:id="@+id/fold_layout_head_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="40dp"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginRight="10dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
@@ -29,7 +29,7 @@
|
||||
android:textStyle="bold" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/arrow_icon"
|
||||
android:id="@+id/fold_layout_arrow_icon"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="15dp"
|
||||
android:layout_weight="1"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/fragment_home_tools"
|
||||
android:layout_width="match_parent"
|
||||
@@ -7,12 +7,8 @@
|
||||
android:background="?attr/app_background_theme"
|
||||
android:orientation="vertical"
|
||||
tools:context=".ui.home.tools.ToolsFragment">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/fold_layouts_linear_layout"
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/tools_recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingTop="10dp"
|
||||
android:paddingBottom="10dp" />
|
||||
</ScrollView>
|
||||
android:layout_height="match_parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -1,6 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
@@ -10,7 +9,5 @@
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/theme_recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
android:layout_height="match_parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -90,8 +90,8 @@
|
||||
android:id="@+id/library_description"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/library_item_card_inner_padding"
|
||||
android:layout_marginRight="@dimen/library_item_card_inner_padding"
|
||||
android:layout_marginStart="@dimen/library_item_card_inner_padding"
|
||||
android:layout_marginEnd="@dimen/library_item_card_inner_padding"
|
||||
android:maxLines="20"
|
||||
android:textAppearance="?textAppearanceBody2"
|
||||
android:textColor="?attr/app_text_theme"
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
android:layout_height="40dp"
|
||||
android:gravity="center_vertical"
|
||||
android:padding="10dp"
|
||||
android:background="@drawable/background_top_radius"
|
||||
android:background="@drawable/background_theme_top"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
@@ -34,17 +34,17 @@
|
||||
android:id="@+id/primary_dark_color"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="20dp"
|
||||
android:background="@drawable/background_no_radius" />
|
||||
android:background="@drawable/background_theme_middle" />
|
||||
|
||||
<View
|
||||
android:id="@+id/primary_light_color"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="20dp"
|
||||
android:background="@drawable/background_no_radius" />
|
||||
android:background="@drawable/background_theme_middle" />
|
||||
|
||||
<View
|
||||
android:id="@+id/accent_color"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="20dp"
|
||||
android:background="@drawable/background_bottom_radius" />
|
||||
android:background="@drawable/background_theme_bottom" />
|
||||
</LinearLayout>
|
||||
@@ -2,13 +2,14 @@
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<com.fatapp.oxygentoolbox.layout.FoldLayout
|
||||
android:id="@+id/fold_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layoutId="@layout/fold_layout_head"
|
||||
app:transitionTime="300"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
<resources>
|
||||
<declare-styleable name="FoldLayout">
|
||||
<attr name="layoutId" format="integer" />
|
||||
<attr name="transitionTime" format="integer" />
|
||||
</declare-styleable>
|
||||
|
||||
<attr name="app_theme" format="color" />
|
||||
|
||||
@@ -5,14 +5,11 @@
|
||||
<item name="android:layout_width">wrap_content</item>
|
||||
<item name="android:minWidth">0dp</item>
|
||||
<item name="android:layout_height">35dp</item>
|
||||
<item name="android:layout_marginStart">5dp</item>
|
||||
<item name="android:layout_marginEnd">5dp</item>
|
||||
<item name="android:layout_marginTop">5dp</item>
|
||||
<item name="android:layout_marginBottom">5dp</item>
|
||||
<item name="android:layout_margin">5dp</item>
|
||||
<item name="android:paddingStart">15dp</item>
|
||||
<item name="android:paddingEnd">15dp</item>
|
||||
<item name="android:background">@drawable/radius_shape</item>
|
||||
<item name="android:foreground">@drawable/ripple_foreground</item>
|
||||
<item name="android:background">@drawable/shape_radius</item>
|
||||
<item name="android:foreground">@drawable/foreground_ripple</item>
|
||||
<item name="android:stateListAnimator">@null</item>
|
||||
<item name="android:textColor">?attr/tools_button_text</item>
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user