Use Theme consistent styles in FoldableLinearLayout
For support of the dark and light themes. Also: Redefine mFolded and call it mIsFolded. Previously, the view started with mFolded = false (which implies to me the initial state is unfolded) and yet the view started in a folded state, which seemed contradictory. Create updateFoldedState() with code from onClick() (In preparation for subsequent commit.)
BIN
res/drawable-hdpi/ic_action_collapse_dark.png
Normal file
After Width: | Height: | Size: 416 B |
Before Width: | Height: | Size: 467 B After Width: | Height: | Size: 467 B |
BIN
res/drawable-hdpi/ic_action_expand_dark.png
Normal file
After Width: | Height: | Size: 414 B |
Before Width: | Height: | Size: 415 B After Width: | Height: | Size: 415 B |
BIN
res/drawable-mdpi/ic_action_collapse_dark.png
Normal file
After Width: | Height: | Size: 317 B |
Before Width: | Height: | Size: 404 B After Width: | Height: | Size: 404 B |
BIN
res/drawable-mdpi/ic_action_expand_dark.png
Normal file
After Width: | Height: | Size: 327 B |
Before Width: | Height: | Size: 345 B After Width: | Height: | Size: 345 B |
BIN
res/drawable-xhdpi/ic_action_collapse_dark.png
Normal file
After Width: | Height: | Size: 602 B |
Before Width: | Height: | Size: 631 B After Width: | Height: | Size: 631 B |
BIN
res/drawable-xhdpi/ic_action_expand_dark.png
Normal file
After Width: | Height: | Size: 529 B |
Before Width: | Height: | Size: 582 B After Width: | Height: | Size: 582 B |
BIN
res/drawable-xxhdpi/ic_action_collapse_dark.png
Normal file
After Width: | Height: | Size: 681 B |
Before Width: | Height: | Size: 901 B After Width: | Height: | Size: 901 B |
BIN
res/drawable-xxhdpi/ic_action_expand_dark.png
Normal file
After Width: | Height: | Size: 726 B |
Before Width: | Height: | Size: 974 B After Width: | Height: | Size: 974 B |
@ -17,7 +17,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginRight="10dp"
|
||||
android:src="@drawable/ic_action_expand" />
|
||||
android:src="?attr/iconActionExpand" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/foldableText"
|
||||
@ -25,7 +25,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:text=""
|
||||
android:textColor="@android:color/darker_gray" />
|
||||
android:textColor="?android:attr/textColorTertiary" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
|
@ -35,6 +35,8 @@
|
||||
<attr name="iconActionSave" format="reference" />
|
||||
<attr name="iconActionCancel" format="reference" />
|
||||
<attr name="iconActionRequestReadReceipt" format="reference" />
|
||||
<attr name="iconActionExpand" format="reference" />
|
||||
<attr name="iconActionCollapse" format="reference" />
|
||||
<attr name="textColorPrimaryRecipientDropdown" format="reference" />
|
||||
<attr name="textColorSecondaryRecipientDropdown" format="reference" />
|
||||
<attr name="backgroundColorChooseAccountHeader" format="color" />
|
||||
|
@ -37,6 +37,8 @@
|
||||
<item name="iconActionSave">@drawable/ic_action_save_light</item>
|
||||
<item name="iconActionCancel">@drawable/ic_action_cancel_light</item>
|
||||
<item name="iconActionRequestReadReceipt">@drawable/ic_action_request_read_receipt_light</item>
|
||||
<item name="iconActionExpand">@drawable/ic_action_expand_light</item>
|
||||
<item name="iconActionCollapse">@drawable/ic_action_collapse_light</item>
|
||||
<item name="textColorPrimaryRecipientDropdown">@android:color/primary_text_light</item>
|
||||
<item name="textColorSecondaryRecipientDropdown">@android:color/secondary_text_light</item>
|
||||
<item name="messageListSelectedBackgroundColor">#8038B8E2</item>
|
||||
@ -89,6 +91,8 @@
|
||||
<item name="iconActionSave">@drawable/ic_action_save_dark</item>
|
||||
<item name="iconActionCancel">@drawable/ic_action_cancel_dark</item>
|
||||
<item name="iconActionRequestReadReceipt">@drawable/ic_action_request_read_receipt_dark</item>
|
||||
<item name="iconActionExpand">@drawable/ic_action_expand_dark</item>
|
||||
<item name="iconActionCollapse">@drawable/ic_action_collapse_dark</item>
|
||||
<item name="textColorPrimaryRecipientDropdown">@android:color/primary_text_dark</item>
|
||||
<item name="textColorSecondaryRecipientDropdown">@android:color/secondary_text_dark</item>
|
||||
<item name="messageListSelectedBackgroundColor">#8038B8E2</item>
|
||||
|
@ -3,8 +3,10 @@ package com.fsck.k9.view;
|
||||
import com.fsck.k9.R;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources.Theme;
|
||||
import android.content.res.TypedArray;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.animation.AlphaAnimation;
|
||||
@ -24,8 +26,11 @@ import android.widget.TextView;
|
||||
* </com.fsck.k9.view.FoldableLinearLayout>
|
||||
*/
|
||||
public class FoldableLinearLayout extends LinearLayout {
|
||||
|
||||
private ImageView mFoldableIcon;
|
||||
private boolean mFolded;
|
||||
|
||||
// Start with the view folded
|
||||
private boolean mIsFolded = true;
|
||||
private boolean mHasMigrated = false;
|
||||
private Integer mShortAnimationDuration = null;
|
||||
private TextView mFoldableTextView = null;
|
||||
@ -33,6 +38,8 @@ public class FoldableLinearLayout extends LinearLayout {
|
||||
private View mFoldableLayout = null;
|
||||
private String mFoldedLabel;
|
||||
private String mUnFoldedLabel;
|
||||
private int mIconActionCollapseId;
|
||||
private int mIconActionExpandId;
|
||||
|
||||
public FoldableLinearLayout(Context context) {
|
||||
super(context);
|
||||
@ -56,6 +63,16 @@ public class FoldableLinearLayout extends LinearLayout {
|
||||
* @param attrs
|
||||
*/
|
||||
private void processAttributes(Context context, AttributeSet attrs) {
|
||||
Theme theme = context.getTheme();
|
||||
TypedValue outValue = new TypedValue();
|
||||
boolean found = theme.resolveAttribute(R.attr.iconActionCollapse, outValue, true);
|
||||
if (found) {
|
||||
mIconActionCollapseId = outValue.resourceId;
|
||||
}
|
||||
found = theme.resolveAttribute(R.attr.iconActionExpand, outValue, true);
|
||||
if (found) {
|
||||
mIconActionExpandId = outValue.resourceId;
|
||||
}
|
||||
if (attrs != null) {
|
||||
TypedArray a = context.obtainStyledAttributes(attrs,
|
||||
R.styleable.FoldableLinearLayout, 0, 0);
|
||||
@ -107,7 +124,6 @@ public class FoldableLinearLayout extends LinearLayout {
|
||||
|
||||
private void initialiseInnerViews() {
|
||||
mFoldableIcon = (ImageView) mFoldableLayout.findViewById(R.id.foldableIcon);
|
||||
mFoldableIcon.setImageResource(R.drawable.ic_action_expand);
|
||||
mFoldableTextView = (TextView) mFoldableLayout.findViewById(R.id.foldableText);
|
||||
mFoldableTextView.setText(mFoldedLabel);
|
||||
// retrieve and cache the system's short animation time
|
||||
@ -117,41 +133,51 @@ public class FoldableLinearLayout extends LinearLayout {
|
||||
foldableControl.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
mFolded = !mFolded;
|
||||
if (mFolded) {
|
||||
mFoldableIcon.setImageResource(R.drawable.ic_action_collapse);
|
||||
mFoldableContainer.setVisibility(View.VISIBLE);
|
||||
AlphaAnimation animation = new AlphaAnimation(0f, 1f);
|
||||
animation.setDuration(mShortAnimationDuration);
|
||||
mFoldableContainer.startAnimation(animation);
|
||||
mFoldableTextView.setText(mUnFoldedLabel);
|
||||
} else {
|
||||
mFoldableIcon.setImageResource(R.drawable.ic_action_expand);
|
||||
AlphaAnimation animation = new AlphaAnimation(1f, 0f);
|
||||
animation.setDuration(mShortAnimationDuration);
|
||||
animation.setAnimationListener(new Animation.AnimationListener() {
|
||||
@Override
|
||||
public void onAnimationStart(Animation animation) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animation animation) {
|
||||
// making sure that at the end the container is
|
||||
// completely removed from view
|
||||
mFoldableContainer.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animation animation) {
|
||||
}
|
||||
});
|
||||
mFoldableContainer.startAnimation(animation);
|
||||
mFoldableTextView.setText(mFoldedLabel);
|
||||
}
|
||||
mIsFolded = !mIsFolded;
|
||||
updateFoldedState(mIsFolded, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void updateFoldedState(boolean newStateIsFolded, boolean animate) {
|
||||
if (newStateIsFolded) {
|
||||
mFoldableIcon.setImageResource(mIconActionExpandId);
|
||||
if (animate) {
|
||||
AlphaAnimation animation = new AlphaAnimation(1f, 0f);
|
||||
animation.setDuration(mShortAnimationDuration);
|
||||
animation.setAnimationListener(new Animation.AnimationListener() {
|
||||
@Override
|
||||
public void onAnimationStart(Animation animation) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animation animation) {
|
||||
// making sure that at the end the container is
|
||||
// completely removed from view
|
||||
mFoldableContainer.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animation animation) {
|
||||
}
|
||||
});
|
||||
mFoldableContainer.startAnimation(animation);
|
||||
} else {
|
||||
mFoldableContainer.setVisibility(View.GONE);
|
||||
}
|
||||
mFoldableTextView.setText(mFoldedLabel);
|
||||
} else {
|
||||
mFoldableIcon.setImageResource(mIconActionCollapseId);
|
||||
mFoldableContainer.setVisibility(View.VISIBLE);
|
||||
if (animate) {
|
||||
AlphaAnimation animation = new AlphaAnimation(0f, 1f);
|
||||
animation.setDuration(mShortAnimationDuration);
|
||||
mFoldableContainer.startAnimation(animation);
|
||||
}
|
||||
mFoldableTextView.setText(mUnFoldedLabel);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds provided child view to foldableContainer View
|
||||
*
|
||||
|