Merge "Remove animateChange in ConditionAdapterUtils"
This commit is contained in:
@@ -66,7 +66,7 @@
|
||||
<LinearLayout
|
||||
android:id="@+id/detail_group"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="72dp"
|
||||
android:visibility="gone"
|
||||
android:orientation="vertical">
|
||||
@@ -96,7 +96,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="8dp"
|
||||
android:paddingBottom="8dp"
|
||||
style="?attr/buttonBarStyle"
|
||||
style="?android:attr/buttonBarStyle"
|
||||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
|
||||
|
||||
<Button
|
||||
|
@@ -81,9 +81,17 @@ public class ConditionAdapterUtils {
|
||||
View detailGroup = view.itemView.findViewById(R.id.detail_group);
|
||||
CharSequence[] actions = condition.getActions();
|
||||
if (isExpanded != (detailGroup.getVisibility() == View.VISIBLE)) {
|
||||
animateChange(view.itemView, view.itemView.findViewById(R.id.content),
|
||||
detailGroup, isExpanded, actions.length > 0);
|
||||
if (isExpanded) {
|
||||
final boolean hasButtons = actions.length > 0;
|
||||
setViewVisibility(detailGroup, R.id.divider, hasButtons);
|
||||
setViewVisibility(detailGroup, R.id.buttonBar, hasButtons);
|
||||
|
||||
detailGroup.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
detailGroup.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
if (isExpanded) {
|
||||
view.summary.setText(condition.getSummary());
|
||||
for (int i = 0; i < 2; i++) {
|
||||
@@ -110,37 +118,6 @@ public class ConditionAdapterUtils {
|
||||
}
|
||||
}
|
||||
|
||||
private static void animateChange(final View view, final View content,
|
||||
final View detailGroup, final boolean visible, final boolean hasButtons) {
|
||||
setViewVisibility(detailGroup, R.id.divider, hasButtons);
|
||||
setViewVisibility(detailGroup, R.id.buttonBar, hasButtons);
|
||||
final int beforeBottom = content.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 = content.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;
|
||||
|
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.settings.conditional;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.dashboard.DashboardAdapter;
|
||||
import com.android.settings.dashboard.conditional.Condition;
|
||||
import com.android.settings.dashboard.conditional.ConditionAdapterUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import com.android.settings.R;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class ConditionAdapterUtilsTest{
|
||||
@Mock
|
||||
private Condition mCondition;
|
||||
private DashboardAdapter.DashboardItemHolder mViewHolder;
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
final CharSequence[] actions = new CharSequence[2];
|
||||
when(mCondition.getActions()).thenReturn(actions);
|
||||
|
||||
final View view = LayoutInflater.from(mContext).inflate(R.layout.condition_card, new
|
||||
LinearLayout(mContext), true);
|
||||
mViewHolder = new DashboardAdapter.DashboardItemHolder(view);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindView_isExpanded_returnVisible() {
|
||||
ConditionAdapterUtils.bindViews(mCondition, mViewHolder, true, null, null);
|
||||
assertThat(mViewHolder.itemView.findViewById(R.id.detail_group).getVisibility())
|
||||
.isEqualTo(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindView_isNotExpanded_returnGone() {
|
||||
ConditionAdapterUtils.bindViews(mCondition, mViewHolder, false, null, null);
|
||||
assertThat(mViewHolder.itemView.findViewById(R.id.detail_group).getVisibility())
|
||||
.isEqualTo(View.GONE);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user