Merge "Add animation for condition card height change."
This commit is contained in:
@@ -15,10 +15,16 @@
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false">
|
||||
<LinearLayout
|
||||
android:id="@+id/content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingStart="16dp"
|
||||
android:background="?android:attr/colorAccent"
|
||||
android:elevation="3dp"
|
||||
@@ -60,8 +66,9 @@
|
||||
<LinearLayout
|
||||
android:id="@+id/detail_group"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="0dp"
|
||||
android:paddingStart="60dp"
|
||||
android:visibility="gone"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
@@ -107,3 +114,4 @@
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
|
@@ -23,4 +23,5 @@
|
||||
android:paddingEnd="@dimen/dashboard_padding_end"
|
||||
android:paddingTop="@dimen/dashboard_padding_top"
|
||||
android:paddingBottom="@dimen/dashboard_padding_bottom"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false" />
|
||||
|
@@ -15,9 +15,14 @@
|
||||
*/
|
||||
package com.android.settings.dashboard.conditional;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.helper.ItemTouchHelper;
|
||||
import android.view.View;
|
||||
import android.view.View.OnLayoutChangeListener;
|
||||
import android.view.ViewGroup.LayoutParams;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import com.android.settings.R;
|
||||
@@ -66,8 +71,10 @@ public class ConditionAdapterUtils {
|
||||
expand.setOnClickListener(onExpandListener);
|
||||
|
||||
View detailGroup = view.itemView.findViewById(R.id.detail_group);
|
||||
// TODO: Animate expand/collapse
|
||||
detailGroup.setVisibility(isExpanded ? View.VISIBLE : View.GONE);
|
||||
if (isExpanded != (detailGroup.getVisibility() == View.VISIBLE)) {
|
||||
animateChange(view.itemView, view.itemView.findViewById(R.id.content),
|
||||
detailGroup, isExpanded);
|
||||
}
|
||||
if (isExpanded) {
|
||||
view.summary.setText(condition.getSummary());
|
||||
CharSequence[] actions = condition.getActions();
|
||||
@@ -90,4 +97,39 @@ public class ConditionAdapterUtils {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void animateChange(final View view, final View content,
|
||||
final View detailGroup, final boolean visible) {
|
||||
final int beforeBottom = view.getBottom();
|
||||
setHeight(detailGroup, visible ? LayoutParams.WRAP_CONTENT : 0);
|
||||
detailGroup.setVisibility(View.VISIBLE);
|
||||
view.addOnLayoutChangeListener(new OnLayoutChangeListener() {
|
||||
public static final long DURATION = 250;
|
||||
|
||||
@Override
|
||||
public void onLayoutChange(View v, int left, int top, int right, int bottom,
|
||||
int oldLeft, int oldTop, int oldRight, int oldBottom) {
|
||||
final int afterBottom = v.getBottom();
|
||||
v.removeOnLayoutChangeListener(this);
|
||||
final ObjectAnimator animator = ObjectAnimator.ofInt(content, "bottom",
|
||||
beforeBottom, afterBottom);
|
||||
animator.setDuration(DURATION);
|
||||
animator.addListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
if (!visible) {
|
||||
detailGroup.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
});
|
||||
animator.start();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void setHeight(View detailGroup, int height) {
|
||||
final LayoutParams params = detailGroup.getLayoutParams();
|
||||
params.height = height;
|
||||
detailGroup.setLayoutParams(params);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user