Merge "Add animation for condition card height change."
This commit is contained in:
@@ -15,95 +15,103 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingStart="16dp"
|
android:clipChildren="false"
|
||||||
android:background="?android:attr/colorAccent"
|
android:clipToPadding="false">
|
||||||
android:elevation="3dp"
|
|
||||||
android:clickable="true">
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/collapsed_group"
|
android:id="@+id/content"
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="56dp"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:gravity="center">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@android:id/icon"
|
|
||||||
android:layout_width="24dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginEnd="36dp"
|
|
||||||
android:tint="?android:attr/textColorPrimaryInverse" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@android:id/title"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
|
||||||
android:textColor="?android:attr/textColorPrimaryInverse" />
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/expand_indicator"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:padding="16dp"
|
|
||||||
android:tint="?android:attr/textColorPrimaryInverse"
|
|
||||||
android:clickable="true"
|
|
||||||
android:background="?android:attr/selectableItemBackground" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/detail_group"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingStart="60dp"
|
android:orientation="vertical"
|
||||||
android:orientation="vertical">
|
android:paddingStart="16dp"
|
||||||
|
android:background="?android:attr/colorAccent"
|
||||||
|
android:elevation="3dp"
|
||||||
|
android:clickable="true">
|
||||||
|
|
||||||
<TextView
|
<LinearLayout
|
||||||
android:id="@android:id/summary"
|
android:id="@+id/collapsed_group"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="56dp"
|
||||||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
|
android:orientation="horizontal"
|
||||||
android:paddingBottom="16dp"
|
android:gravity="center">
|
||||||
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
|
|
||||||
android:textColor="?android:attr/textColorPrimaryInverse" />
|
|
||||||
|
|
||||||
<!-- TODO: Better background -->
|
<ImageView
|
||||||
<View
|
android:id="@android:id/icon"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="24dp"
|
||||||
android:layout_height=".25dp"
|
|
||||||
android:background="@android:color/white" />
|
|
||||||
|
|
||||||
<com.android.internal.widget.ButtonBarLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:paddingTop="8dp"
|
|
||||||
android:paddingBottom="8dp"
|
|
||||||
style="?attr/buttonBarStyle"
|
|
||||||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/first_action"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingStart="0dp"
|
android:layout_marginEnd="36dp"
|
||||||
android:textColor="?android:attr/textColorPrimaryInverse"
|
android:tint="?android:attr/textColorPrimaryInverse" />
|
||||||
style="?android:attr/buttonBarButtonStyle" />
|
|
||||||
|
|
||||||
<Button
|
<TextView
|
||||||
android:id="@+id/second_action"
|
android:id="@android:id/title"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textColor="?android:attr/textColorPrimaryInverse"
|
android:layout_weight="1"
|
||||||
style="?android:attr/buttonBarButtonStyle" />
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
|
android:textColor="?android:attr/textColorPrimaryInverse" />
|
||||||
|
|
||||||
</com.android.internal.widget.ButtonBarLayout>
|
<ImageView
|
||||||
|
android:id="@+id/expand_indicator"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:padding="16dp"
|
||||||
|
android:tint="?android:attr/textColorPrimaryInverse"
|
||||||
|
android:clickable="true"
|
||||||
|
android:background="?android:attr/selectableItemBackground" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/detail_group"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:paddingStart="60dp"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@android:id/summary"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
|
||||||
|
android:paddingBottom="16dp"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
|
||||||
|
android:textColor="?android:attr/textColorPrimaryInverse" />
|
||||||
|
|
||||||
|
<!-- TODO: Better background -->
|
||||||
|
<View
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height=".25dp"
|
||||||
|
android:background="@android:color/white" />
|
||||||
|
|
||||||
|
<com.android.internal.widget.ButtonBarLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingTop="8dp"
|
||||||
|
android:paddingBottom="8dp"
|
||||||
|
style="?attr/buttonBarStyle"
|
||||||
|
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/first_action"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingStart="0dp"
|
||||||
|
android:textColor="?android:attr/textColorPrimaryInverse"
|
||||||
|
style="?android:attr/buttonBarButtonStyle" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/second_action"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textColor="?android:attr/textColorPrimaryInverse"
|
||||||
|
style="?android:attr/buttonBarButtonStyle" />
|
||||||
|
|
||||||
|
</com.android.internal.widget.ButtonBarLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
</FrameLayout>
|
||||||
</LinearLayout>
|
|
||||||
|
@@ -23,4 +23,5 @@
|
|||||||
android:paddingEnd="@dimen/dashboard_padding_end"
|
android:paddingEnd="@dimen/dashboard_padding_end"
|
||||||
android:paddingTop="@dimen/dashboard_padding_top"
|
android:paddingTop="@dimen/dashboard_padding_top"
|
||||||
android:paddingBottom="@dimen/dashboard_padding_bottom"
|
android:paddingBottom="@dimen/dashboard_padding_bottom"
|
||||||
|
android:clipChildren="false"
|
||||||
android:clipToPadding="false" />
|
android:clipToPadding="false" />
|
||||||
|
@@ -15,9 +15,14 @@
|
|||||||
*/
|
*/
|
||||||
package com.android.settings.dashboard.conditional;
|
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.RecyclerView;
|
||||||
import android.support.v7.widget.helper.ItemTouchHelper;
|
import android.support.v7.widget.helper.ItemTouchHelper;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.View.OnLayoutChangeListener;
|
||||||
|
import android.view.ViewGroup.LayoutParams;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
@@ -66,8 +71,10 @@ public class ConditionAdapterUtils {
|
|||||||
expand.setOnClickListener(onExpandListener);
|
expand.setOnClickListener(onExpandListener);
|
||||||
|
|
||||||
View detailGroup = view.itemView.findViewById(R.id.detail_group);
|
View detailGroup = view.itemView.findViewById(R.id.detail_group);
|
||||||
// TODO: Animate expand/collapse
|
if (isExpanded != (detailGroup.getVisibility() == View.VISIBLE)) {
|
||||||
detailGroup.setVisibility(isExpanded ? View.VISIBLE : View.GONE);
|
animateChange(view.itemView, view.itemView.findViewById(R.id.content),
|
||||||
|
detailGroup, isExpanded);
|
||||||
|
}
|
||||||
if (isExpanded) {
|
if (isExpanded) {
|
||||||
view.summary.setText(condition.getSummary());
|
view.summary.setText(condition.getSummary());
|
||||||
CharSequence[] actions = condition.getActions();
|
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