Optimized FoldLayout: Add default status control.

This commit is contained in:
2022-06-24 00:55:14 +08:00
parent d3112fb57e
commit ce448cbc33
6 changed files with 36 additions and 11 deletions

View File

@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android">
package="com.fatapp.oxygentoolbox">
<uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.VIBRATE" />

View File

@@ -14,6 +14,8 @@ import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import androidx.appcompat.content.res.AppCompatResources;
import com.fatapp.oxygentoolbox.R; import com.fatapp.oxygentoolbox.R;
import java.util.List; import java.util.List;
@@ -23,6 +25,7 @@ public class FoldLayout extends LinearLayout implements View.OnClickListener {
private boolean init; private boolean init;
private final int layoutId; private final int layoutId;
private boolean isShow; private boolean isShow;
private boolean isDefaultShow;
private LinearLayout content; private LinearLayout content;
private ValueAnimator showAnimator; private ValueAnimator showAnimator;
private ValueAnimator hideAnimator; private ValueAnimator hideAnimator;
@@ -35,13 +38,14 @@ public class FoldLayout extends LinearLayout implements View.OnClickListener {
} }
public FoldLayout(Context context, AttributeSet attrs) { public FoldLayout(Context context, AttributeSet attrs) {
this(context, attrs, 0); this(context, attrs, 0, false);
} }
public FoldLayout(Context context, AttributeSet attrs, int defStyleAttr) { public FoldLayout(Context context, AttributeSet attrs, int defStyleAttr, boolean isDefaultShow) {
super(context, attrs, defStyleAttr); super(context, attrs, defStyleAttr);
@SuppressLint("Recycle") TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.FoldLayout, defStyleAttr, 0); @SuppressLint("Recycle") TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.FoldLayout, defStyleAttr, 0);
layoutId = ta.getResourceId(R.styleable.FoldLayout_layoutId, -1); layoutId = ta.getResourceId(R.styleable.FoldLayout_layoutId, -1);
this.isDefaultShow = isDefaultShow;
init(context); init(context);
} }
@@ -50,6 +54,14 @@ public class FoldLayout extends LinearLayout implements View.OnClickListener {
addDefaultLayout(context); addDefaultLayout(context);
} }
public void setDefaultShow(boolean defaultShow) {
isDefaultShow = defaultShow;
}
public View getDefaultView() {
return defaultView;
}
/** /**
* Init * Init
*/ */
@@ -87,8 +99,22 @@ public class FoldLayout extends LinearLayout implements View.OnClickListener {
int contentHeight = content.getMeasuredHeight(); int contentHeight = content.getMeasuredHeight();
if (!init) { if (!init) {
LayoutParams layoutParams = (LayoutParams) content.getLayoutParams(); LayoutParams layoutParams = (LayoutParams) content.getLayoutParams();
layoutParams.height = 0; if (isDefaultShow) {
isShow = true;
layoutParams.height = contentHeight;
LinearLayout linearLayout = defaultView.findViewById(R.id.fold_layout_linear_layout);
linearLayout.setBackground(AppCompatResources.getDrawable(getContext(), R.drawable.top_radius_background));
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.top_bottom_radius_background));
ImageView imageView = defaultView.findViewById(R.id.arrow_icon);
imageView.setImageDrawable(AppCompatResources.getDrawable(getContext(), R.drawable.right_to_down_arrow));
}
content.setLayoutParams(layoutParams); content.setLayoutParams(layoutParams);
showAnimator = ValueAnimator.ofInt(0, contentHeight); showAnimator = ValueAnimator.ofInt(0, contentHeight);
showAnimator.addUpdateListener(animation -> { showAnimator.addUpdateListener(animation -> {
layoutParams.height = (int) animation.getAnimatedValue(); layoutParams.height = (int) animation.getAnimatedValue();

View File

@@ -98,6 +98,7 @@ public class ToolsFragment extends Fragment {
View foldLayoutHead = getLayoutInflater().inflate(R.layout.fold_layout, null); View foldLayoutHead = getLayoutInflater().inflate(R.layout.fold_layout, null);
FoldLayout foldLayout = foldLayoutHead.findViewById(R.id.fold_layout); FoldLayout foldLayout = foldLayoutHead.findViewById(R.id.fold_layout);
foldLayout.setDefaultShow(true);
((TextView) foldLayout.findViewById(R.id.fold_layout_text_view)).setText(tool.getFoldLayoutTitle()); ((TextView) foldLayout.findViewById(R.id.fold_layout_text_view)).setText(tool.getFoldLayoutTitle());
TextView foldLayoutIcon = foldLayout.findViewById(R.id.fold_layout_icon); TextView foldLayoutIcon = foldLayout.findViewById(R.id.fold_layout_icon);

View File

@@ -1,13 +1,11 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/fold_layout_linear_layout" android:id="@+id/fold_layout_linear_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="40dp" android:layout_height="40dp"
android:layout_marginLeft="10dp" android:layout_marginLeft="10dp"
android:layout_marginTop="10dp" android:layout_marginTop="10dp"
android:layout_marginRight="10dp" android:layout_marginRight="10dp"
android:background="@drawable/top_bottom_radius_background"
android:gravity="center_vertical"> android:gravity="center_vertical">
<TextView <TextView
@@ -34,6 +32,5 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="15dp" android:layout_height="15dp"
android:layout_weight="1" android:layout_weight="1"
android:contentDescription="@string/arrow_icon" android:contentDescription="@string/arrow_icon" />
app:srcCompat="@drawable/right_to_down_arrow" />
</LinearLayout> </LinearLayout>

View File

@@ -5,4 +5,5 @@
<dimen name="activity_vertical_margin">16dp</dimen> <dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="nav_header_vertical_spacing">8dp</dimen> <dimen name="nav_header_vertical_spacing">8dp</dimen>
<dimen name="nav_header_height">176dp</dimen> <dimen name="nav_header_height">176dp</dimen>
<dimen name="default_text_size">20sp</dimen>
</resources> </resources>

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"> <resources>
<!-- Base application theme. --> <!-- Base application theme. -->
<style name="Theme.OxygenToolbox.Default" parent="Theme.MaterialComponents.DayNight.DarkActionBar.Bridge"> <style name="Theme.OxygenToolbox.Default" parent="Theme.MaterialComponents.DayNight.DarkActionBar.Bridge">
<!-- Primary brand color. --> <!-- Primary brand color. -->
@@ -11,11 +11,12 @@
<item name="colorSecondaryVariant">@color/default_app_second_theme</item> <item name="colorSecondaryVariant">@color/default_app_second_theme</item>
<item name="colorOnSecondary">@color/default_app_second_on_theme</item> <item name="colorOnSecondary">@color/default_app_second_on_theme</item>
<!-- Status bar color. --> <!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item> <item name="android:statusBarColor" >?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. --> <!-- Customize your theme here. -->
<item name="windowActionBar">false</item> <item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item> <item name="windowNoTitle">true</item>
<item name="android:windowTranslucentNavigation">true</item> <item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowDisablePreview">true</item>
<item name="app_theme">@color/default_app_theme</item> <item name="app_theme">@color/default_app_theme</item>
<item name="app_on_theme">@color/default_app_on_theme</item> <item name="app_on_theme">@color/default_app_on_theme</item>