From 623d8a0bf55f8381e6cb6658ce7eddc8e9dfa162 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Tue, 14 Feb 2017 16:18:15 +0100 Subject: [PATCH] add initial state attribute to FoldableLinearLayout --- .../ui/widget/FoldableLinearLayout.java | 72 +++++++++++-------- OpenKeychain/src/main/res/values/attr.xml | 1 + 2 files changed, 42 insertions(+), 31 deletions(-) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/FoldableLinearLayout.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/FoldableLinearLayout.java index 34e7b639a..961c40844 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/FoldableLinearLayout.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/FoldableLinearLayout.java @@ -56,6 +56,7 @@ public class FoldableLinearLayout extends LinearLayout { private String mFoldedLabel; private String mUnFoldedLabel; + private boolean mInitializeFolded; public FoldableLinearLayout(Context context) { super(context); @@ -84,6 +85,7 @@ public class FoldableLinearLayout extends LinearLayout { R.styleable.FoldableLinearLayout, 0, 0); mFoldedLabel = a.getString(R.styleable.FoldableLinearLayout_foldedLabel); mUnFoldedLabel = a.getString(R.styleable.FoldableLinearLayout_unFoldedLabel); + mInitializeFolded = a.getBoolean(R.styleable.FoldableLinearLayout_initializeFolded, true); a.recycle(); } // If any attribute isn't found then set a default one @@ -102,6 +104,10 @@ public class FoldableLinearLayout extends LinearLayout { initialiseInnerViews(); + if (!mInitializeFolded) { + toggleFolded(); + } + super.onFinishInflate(); } @@ -149,42 +155,46 @@ 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_expand_less_black_24dp); - 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_expand_more_black_24dp); - 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); - } + toggleFolded(); } }); } + private void toggleFolded() { + mFolded = !mFolded; + if (mFolded) { + mFoldableIcon.setImageResource(R.drawable.ic_expand_less_black_24dp); + 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_expand_more_black_24dp); + 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); + } + } + /** * Adds provided child view to foldableContainer View * diff --git a/OpenKeychain/src/main/res/values/attr.xml b/OpenKeychain/src/main/res/values/attr.xml index 7e8b98343..50f2126a5 100644 --- a/OpenKeychain/src/main/res/values/attr.xml +++ b/OpenKeychain/src/main/res/values/attr.xml @@ -8,6 +8,7 @@ +