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"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.fatapp.oxygentoolbox">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.VIBRATE" />

View File

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

View File

@@ -1,13 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:background="@drawable/top_bottom_radius_background"
android:gravity="center_vertical">
<TextView
@@ -34,6 +32,5 @@
android:layout_width="0dp"
android:layout_height="15dp"
android:layout_weight="1"
android:contentDescription="@string/arrow_icon"
app:srcCompat="@drawable/right_to_down_arrow" />
android:contentDescription="@string/arrow_icon" />
</LinearLayout>

View File

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

View File

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