Build a new FooterPreference UI.
- Create a new layout for footer prefs. - Create a new FooterPreference type to use the layout - Create a Mixin to create and add the pref to screen - Create a new lifecycle observer type to invoke mixin at right time - Switch SettingsPreferenceFragment to use footer mixin. - Switch FingerprintSettings to use the new footer pref. Bug: 33579394 Test: RunSettingsRoboTests Change-Id: I548ac39a0d120196a7ffed09b4f98bd9a80bae90
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* 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.widget;
|
||||
|
||||
import android.support.v14.preference.PreferenceFragment;
|
||||
import android.support.v7.preference.PreferenceManager;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.core.lifecycle.Lifecycle;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class FooterPreferenceMixinTest {
|
||||
|
||||
@Mock
|
||||
private PreferenceFragment mFragment;
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
|
||||
private Lifecycle mLifecycle;
|
||||
private FooterPreferenceMixin mMixin;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mLifecycle = new Lifecycle();
|
||||
when(mFragment.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
|
||||
when(mFragment.getPreferenceManager().getContext())
|
||||
.thenReturn(ShadowApplication.getInstance().getApplicationContext());
|
||||
mMixin = new FooterPreferenceMixin(mFragment, mLifecycle);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createFooter_screenNotAvailable_noCrash() {
|
||||
assertThat(mMixin.createFooterPreference()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createFooter_screenAvailable_canAttachToScreen() {
|
||||
when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
|
||||
|
||||
final FooterPreference preference = mMixin.createFooterPreference();
|
||||
|
||||
assertThat(preference).isNotNull();
|
||||
verify(mScreen).addPreference(preference);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createFooter_screenAvailableDelayed_canAttachToScreen() {
|
||||
final FooterPreference preference = mMixin.createFooterPreference();
|
||||
|
||||
mLifecycle.setPreferenceScreen(mScreen);
|
||||
|
||||
assertThat(preference).isNotNull();
|
||||
verify(mScreen).addPreference(preference);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createFooterTwice_screenAvailable_replaceOldFooter() {
|
||||
when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
|
||||
|
||||
mMixin.createFooterPreference();
|
||||
mMixin.createFooterPreference();
|
||||
|
||||
verify(mScreen).removePreference(any(FooterPreference.class));
|
||||
verify(mScreen, times(2)).addPreference(any(FooterPreference.class));
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.view.LayoutInflater;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class FooterPreferenceTest {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = ShadowApplication.getInstance().getApplicationContext();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createNewPreference_shouldSetKeyAndOrder() {
|
||||
final FooterPreference preference = new FooterPreference(mContext);
|
||||
|
||||
assertThat(preference.getKey()).isEqualTo(FooterPreference.KEY_FOOTER);
|
||||
assertThat(preference.getOrder()).isEqualTo(FooterPreference.ORDER_FOOTER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bindPreference_shouldLinkifyContent() {
|
||||
final FooterPreference preference = new FooterPreference(mContext);
|
||||
final PreferenceViewHolder holder = new PreferenceViewHolder(
|
||||
LayoutInflater.from(mContext).inflate(R.layout.preference_footer, null));
|
||||
|
||||
preference.onBindViewHolder(holder);
|
||||
assertThat(((TextView) holder.findViewById(android.R.id.title)).getMovementMethod())
|
||||
.isInstanceOf(LinkMovementMethod.class);
|
||||
}
|
||||
}
|
@@ -16,21 +16,21 @@
|
||||
|
||||
package com.android.settings.widget;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View.MeasureSpec;
|
||||
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class RingProgressBarTest {
|
||||
|
||||
|
Reference in New Issue
Block a user