1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-05 00:55:08 -05:00

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.)
This commit is contained in:
Joe Steele 2014-08-28 17:46:56 -04:00
parent 348fb4dceb
commit a756fa3683
20 changed files with 67 additions and 35 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 416 B

View File

Before

Width:  |  Height:  |  Size: 467 B

After

Width:  |  Height:  |  Size: 467 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 414 B

View File

Before

Width:  |  Height:  |  Size: 415 B

After

Width:  |  Height:  |  Size: 415 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 317 B

View File

Before

Width:  |  Height:  |  Size: 404 B

After

Width:  |  Height:  |  Size: 404 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 327 B

View File

Before

Width:  |  Height:  |  Size: 345 B

After

Width:  |  Height:  |  Size: 345 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 602 B

View File

Before

Width:  |  Height:  |  Size: 631 B

After

Width:  |  Height:  |  Size: 631 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 529 B

View File

Before

Width:  |  Height:  |  Size: 582 B

After

Width:  |  Height:  |  Size: 582 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 681 B

View File

Before

Width:  |  Height:  |  Size: 901 B

After

Width:  |  Height:  |  Size: 901 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 726 B

View File

Before

Width:  |  Height:  |  Size: 974 B

After

Width:  |  Height:  |  Size: 974 B

View File

@ -17,7 +17,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:layout_marginRight="10dp" android:layout_marginRight="10dp"
android:src="@drawable/ic_action_expand" /> android:src="?attr/iconActionExpand" />
<TextView <TextView
android:id="@+id/foldableText" android:id="@+id/foldableText"
@ -25,7 +25,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:text="" android:text=""
android:textColor="@android:color/darker_gray" /> android:textColor="?android:attr/textColorTertiary" />
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout

View File

@ -35,6 +35,8 @@
<attr name="iconActionSave" format="reference" /> <attr name="iconActionSave" format="reference" />
<attr name="iconActionCancel" format="reference" /> <attr name="iconActionCancel" format="reference" />
<attr name="iconActionRequestReadReceipt" format="reference" /> <attr name="iconActionRequestReadReceipt" format="reference" />
<attr name="iconActionExpand" format="reference" />
<attr name="iconActionCollapse" format="reference" />
<attr name="textColorPrimaryRecipientDropdown" format="reference" /> <attr name="textColorPrimaryRecipientDropdown" format="reference" />
<attr name="textColorSecondaryRecipientDropdown" format="reference" /> <attr name="textColorSecondaryRecipientDropdown" format="reference" />
<attr name="backgroundColorChooseAccountHeader" format="color" /> <attr name="backgroundColorChooseAccountHeader" format="color" />

View File

@ -37,6 +37,8 @@
<item name="iconActionSave">@drawable/ic_action_save_light</item> <item name="iconActionSave">@drawable/ic_action_save_light</item>
<item name="iconActionCancel">@drawable/ic_action_cancel_light</item> <item name="iconActionCancel">@drawable/ic_action_cancel_light</item>
<item name="iconActionRequestReadReceipt">@drawable/ic_action_request_read_receipt_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="textColorPrimaryRecipientDropdown">@android:color/primary_text_light</item>
<item name="textColorSecondaryRecipientDropdown">@android:color/secondary_text_light</item> <item name="textColorSecondaryRecipientDropdown">@android:color/secondary_text_light</item>
<item name="messageListSelectedBackgroundColor">#8038B8E2</item> <item name="messageListSelectedBackgroundColor">#8038B8E2</item>
@ -89,6 +91,8 @@
<item name="iconActionSave">@drawable/ic_action_save_dark</item> <item name="iconActionSave">@drawable/ic_action_save_dark</item>
<item name="iconActionCancel">@drawable/ic_action_cancel_dark</item> <item name="iconActionCancel">@drawable/ic_action_cancel_dark</item>
<item name="iconActionRequestReadReceipt">@drawable/ic_action_request_read_receipt_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="textColorPrimaryRecipientDropdown">@android:color/primary_text_dark</item>
<item name="textColorSecondaryRecipientDropdown">@android:color/secondary_text_dark</item> <item name="textColorSecondaryRecipientDropdown">@android:color/secondary_text_dark</item>
<item name="messageListSelectedBackgroundColor">#8038B8E2</item> <item name="messageListSelectedBackgroundColor">#8038B8E2</item>

View File

@ -3,8 +3,10 @@ package com.fsck.k9.view;
import com.fsck.k9.R; import com.fsck.k9.R;
import android.content.Context; import android.content.Context;
import android.content.res.Resources.Theme;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.animation.AlphaAnimation; import android.view.animation.AlphaAnimation;
@ -24,8 +26,11 @@ import android.widget.TextView;
* </com.fsck.k9.view.FoldableLinearLayout> * </com.fsck.k9.view.FoldableLinearLayout>
*/ */
public class FoldableLinearLayout extends LinearLayout { public class FoldableLinearLayout extends LinearLayout {
private ImageView mFoldableIcon; private ImageView mFoldableIcon;
private boolean mFolded;
// Start with the view folded
private boolean mIsFolded = true;
private boolean mHasMigrated = false; private boolean mHasMigrated = false;
private Integer mShortAnimationDuration = null; private Integer mShortAnimationDuration = null;
private TextView mFoldableTextView = null; private TextView mFoldableTextView = null;
@ -33,6 +38,8 @@ public class FoldableLinearLayout extends LinearLayout {
private View mFoldableLayout = null; private View mFoldableLayout = null;
private String mFoldedLabel; private String mFoldedLabel;
private String mUnFoldedLabel; private String mUnFoldedLabel;
private int mIconActionCollapseId;
private int mIconActionExpandId;
public FoldableLinearLayout(Context context) { public FoldableLinearLayout(Context context) {
super(context); super(context);
@ -56,6 +63,16 @@ public class FoldableLinearLayout extends LinearLayout {
* @param attrs * @param attrs
*/ */
private void processAttributes(Context context, AttributeSet 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) { if (attrs != null) {
TypedArray a = context.obtainStyledAttributes(attrs, TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.FoldableLinearLayout, 0, 0); R.styleable.FoldableLinearLayout, 0, 0);
@ -107,7 +124,6 @@ public class FoldableLinearLayout extends LinearLayout {
private void initialiseInnerViews() { private void initialiseInnerViews() {
mFoldableIcon = (ImageView) mFoldableLayout.findViewById(R.id.foldableIcon); mFoldableIcon = (ImageView) mFoldableLayout.findViewById(R.id.foldableIcon);
mFoldableIcon.setImageResource(R.drawable.ic_action_expand);
mFoldableTextView = (TextView) mFoldableLayout.findViewById(R.id.foldableText); mFoldableTextView = (TextView) mFoldableLayout.findViewById(R.id.foldableText);
mFoldableTextView.setText(mFoldedLabel); mFoldableTextView.setText(mFoldedLabel);
// retrieve and cache the system's short animation time // retrieve and cache the system's short animation time
@ -117,16 +133,16 @@ public class FoldableLinearLayout extends LinearLayout {
foldableControl.setOnClickListener(new View.OnClickListener() { foldableControl.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
mFolded = !mFolded; mIsFolded = !mIsFolded;
if (mFolded) { updateFoldedState(mIsFolded, true);
mFoldableIcon.setImageResource(R.drawable.ic_action_collapse); }
mFoldableContainer.setVisibility(View.VISIBLE); });
AlphaAnimation animation = new AlphaAnimation(0f, 1f); }
animation.setDuration(mShortAnimationDuration);
mFoldableContainer.startAnimation(animation); protected void updateFoldedState(boolean newStateIsFolded, boolean animate) {
mFoldableTextView.setText(mUnFoldedLabel); if (newStateIsFolded) {
} else { mFoldableIcon.setImageResource(mIconActionExpandId);
mFoldableIcon.setImageResource(R.drawable.ic_action_expand); if (animate) {
AlphaAnimation animation = new AlphaAnimation(1f, 0f); AlphaAnimation animation = new AlphaAnimation(1f, 0f);
animation.setDuration(mShortAnimationDuration); animation.setDuration(mShortAnimationDuration);
animation.setAnimationListener(new Animation.AnimationListener() { animation.setAnimationListener(new Animation.AnimationListener() {
@ -146,10 +162,20 @@ public class FoldableLinearLayout extends LinearLayout {
} }
}); });
mFoldableContainer.startAnimation(animation); mFoldableContainer.startAnimation(animation);
} else {
mFoldableContainer.setVisibility(View.GONE);
}
mFoldableTextView.setText(mFoldedLabel); 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);
} }
});
} }
/** /**