Misc layout fixes
- Apply entity header effect to battery summary screen. - BidiWrap wifi ap name is it's correctly displayed in RLT languages - Remove footer preference layout - settingslib already has one Fix: 62039146 Fix: 62138362 Fix: 37920219 Test: make RunSettingsRoboTests Change-Id: Idf1385ee40772c63075e5f81eb039c6da56256ab
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/app_snippet"
|
||||
android:id="@+id/battery_entity_header"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center"
|
||||
|
@@ -1,54 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
|
||||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:clipToPadding="false">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/icon_container"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:minWidth="56dp"
|
||||
android:gravity="start|top"
|
||||
android:orientation="horizontal"
|
||||
android:paddingEnd="12dp"
|
||||
android:paddingTop="20dp"
|
||||
android:paddingBottom="4dp">
|
||||
<ImageView
|
||||
android:id="@android:id/icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
|
||||
<com.android.settingslib.widget.LinkTextView
|
||||
android:id="@android:id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="16dp"
|
||||
android:paddingTop="16dp"
|
||||
android:maxLines="10"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:ellipsize="marquee" />
|
||||
|
||||
</LinearLayout>
|
@@ -17,24 +17,32 @@
|
||||
|
||||
package com.android.settings.fuelgauge;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v14.preference.PreferenceFragment;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.applications.LayoutPreference;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.widget.EntityHeaderController;
|
||||
import com.android.settingslib.Utils;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
|
||||
/**
|
||||
* Controller that update the battery header view
|
||||
*/
|
||||
public class BatteryHeaderPreferenceController extends PreferenceController {
|
||||
public class BatteryHeaderPreferenceController extends PreferenceController
|
||||
implements LifecycleObserver, OnStart {
|
||||
@VisibleForTesting
|
||||
static final String KEY_BATTERY_HEADER = "battery_header";
|
||||
|
||||
@VisibleForTesting
|
||||
BatteryMeterView mBatteryMeterView;
|
||||
@VisibleForTesting
|
||||
@@ -42,16 +50,26 @@ public class BatteryHeaderPreferenceController extends PreferenceController {
|
||||
@VisibleForTesting
|
||||
TextView mSummary;
|
||||
|
||||
private final Activity mActivity;
|
||||
private final PreferenceFragment mHost;
|
||||
private final Lifecycle mLifecycle;
|
||||
|
||||
private LayoutPreference mBatteryLayoutPref;
|
||||
|
||||
public BatteryHeaderPreferenceController(Context context) {
|
||||
public BatteryHeaderPreferenceController(Context context, Activity activity,
|
||||
PreferenceFragment host, Lifecycle lifecycle) {
|
||||
super(context);
|
||||
mActivity = activity;
|
||||
mHost = host;
|
||||
mLifecycle = lifecycle;
|
||||
if (mLifecycle != null) {
|
||||
mLifecycle.addObserver(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
|
||||
mBatteryLayoutPref = (LayoutPreference) screen.findPreference(KEY_BATTERY_HEADER);
|
||||
mBatteryMeterView = (BatteryMeterView) mBatteryLayoutPref
|
||||
.findViewById(R.id.battery_header_icon);
|
||||
@@ -76,6 +94,14 @@ public class BatteryHeaderPreferenceController extends PreferenceController {
|
||||
return KEY_BATTERY_HEADER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
EntityHeaderController.newInstance(mActivity, mHost,
|
||||
mBatteryLayoutPref.findViewById(R.id.battery_entity_header))
|
||||
.setRecyclerView(mHost.getListView(), mLifecycle)
|
||||
.styleActionBar(mActivity);
|
||||
}
|
||||
|
||||
public void updateHeaderPreference(BatteryInfo info) {
|
||||
mTimeText.setText(Utils.formatPercentage(info.batteryLevel));
|
||||
if (info.remainingLabel == null) {
|
||||
|
@@ -63,7 +63,6 @@ import com.android.settings.fuelgauge.anomaly.AnomalyLoader;
|
||||
import com.android.settings.fuelgauge.anomaly.AnomalySummaryPreferenceController;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.widget.FooterPreferenceMixin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -106,9 +105,6 @@ public class PowerUsageSummary extends PowerUsageBase implements
|
||||
static final int MENU_TOGGLE_APPS = Menu.FIRST + 5;
|
||||
private static final int MENU_HELP = Menu.FIRST + 6;
|
||||
|
||||
private final FooterPreferenceMixin mFooterPreferenceMixin =
|
||||
new FooterPreferenceMixin(this, getLifecycle());
|
||||
|
||||
@VisibleForTesting
|
||||
boolean mShowAllApps = false;
|
||||
@VisibleForTesting
|
||||
@@ -246,7 +242,8 @@ public class PowerUsageSummary extends PowerUsageBase implements
|
||||
@Override
|
||||
protected List<PreferenceController> getPreferenceControllers(Context context) {
|
||||
final List<PreferenceController> controllers = new ArrayList<>();
|
||||
mBatteryHeaderPreferenceController = new BatteryHeaderPreferenceController(context);
|
||||
mBatteryHeaderPreferenceController = new BatteryHeaderPreferenceController(
|
||||
context, getActivity(), this /* host */, getLifecycle());
|
||||
controllers.add(mBatteryHeaderPreferenceController);
|
||||
controllers.add(new AutoBrightnessPreferenceController(context, KEY_AUTO_BRIGHTNESS));
|
||||
controllers.add(new TimeoutPreferenceController(context, KEY_SCREEN_TIMEOUT));
|
||||
|
@@ -25,6 +25,7 @@ import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.provider.Settings;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
import android.text.BidiFormatter;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.datausage.DataSaverBackend;
|
||||
@@ -109,12 +110,13 @@ public class WifiApEnabler {
|
||||
}
|
||||
}
|
||||
|
||||
public void updateConfigSummary(WifiConfiguration wifiConfig) {
|
||||
private void updateConfigSummary(WifiConfiguration wifiConfig) {
|
||||
String s = mContext.getString(
|
||||
com.android.internal.R.string.wifi_tether_configure_ssid_default);
|
||||
mSwitch.setSummary(String.format(
|
||||
mContext.getString(R.string.wifi_tether_enabled_subtext),
|
||||
(wifiConfig == null) ? s : wifiConfig.SSID));
|
||||
|
||||
mSwitch.setSummary(mContext.getString(R.string.wifi_tether_enabled_subtext,
|
||||
BidiFormatter.getInstance().unicodeWrap(
|
||||
(wifiConfig == null) ? s : wifiConfig.SSID)));
|
||||
}
|
||||
|
||||
private void updateTetherState(Object[] available, Object[] tethered, Object[] errored) {
|
||||
|
@@ -17,10 +17,13 @@
|
||||
|
||||
package com.android.settings.fuelgauge;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.BatteryManager;
|
||||
import android.support.v14.preference.PreferenceFragment;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.settings.R;
|
||||
@@ -29,7 +32,11 @@ import com.android.settings.TestConfig;
|
||||
import com.android.settings.applications.LayoutPreference;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
import com.android.settings.testutils.shadow.ShadowDynamicIndexableContentMonitor;
|
||||
import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
|
||||
import com.android.settings.widget.EntityHeaderController;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -39,9 +46,13 @@ import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH,
|
||||
@@ -49,17 +60,24 @@ import static org.mockito.Mockito.spy;
|
||||
shadows = {
|
||||
SettingsShadowResources.class,
|
||||
SettingsShadowResources.SettingsShadowTheme.class,
|
||||
ShadowDynamicIndexableContentMonitor.class
|
||||
ShadowDynamicIndexableContentMonitor.class,
|
||||
ShadowEntityHeaderController.class
|
||||
})
|
||||
public class BatteryHeaderPreferenceControllerTest {
|
||||
private static final int BATTERY_LEVEL = 60;
|
||||
private static final String TIME_LEFT = "2h30min";
|
||||
private static final String BATTERY_STATUS = "Charging";
|
||||
|
||||
@Mock
|
||||
private Activity mActivity;
|
||||
@Mock
|
||||
private PreferenceFragment mPreferenceFragment;
|
||||
@Mock
|
||||
private PreferenceScreen mPreferenceScreen;
|
||||
@Mock
|
||||
private BatteryInfo mBatteryInfo;
|
||||
@Mock
|
||||
private EntityHeaderController mEntityHeaderController;
|
||||
private BatteryHeaderPreferenceController mController;
|
||||
private Context mContext;
|
||||
private BatteryMeterView mBatteryMeterView;
|
||||
@@ -67,15 +85,18 @@ public class BatteryHeaderPreferenceControllerTest {
|
||||
private TextView mSummary;
|
||||
private LayoutPreference mBatteryLayoutPref;
|
||||
private Intent mBatteryIntent;
|
||||
private Lifecycle mLifecycle;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mLifecycle = new Lifecycle();
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mBatteryMeterView = new BatteryMeterView(mContext);
|
||||
mTimeText = new TextView(mContext);
|
||||
mSummary = new TextView(mContext);
|
||||
ShadowEntityHeaderController.setUseMock(mEntityHeaderController);
|
||||
|
||||
mBatteryIntent = new Intent();
|
||||
mBatteryIntent.putExtra(BatteryManager.EXTRA_LEVEL, BATTERY_LEVEL);
|
||||
@@ -88,12 +109,18 @@ public class BatteryHeaderPreferenceControllerTest {
|
||||
|
||||
mBatteryInfo.batteryLevel = BATTERY_LEVEL;
|
||||
|
||||
mController = new BatteryHeaderPreferenceController(mContext);
|
||||
mController = new BatteryHeaderPreferenceController(
|
||||
mContext, mActivity, mPreferenceFragment, mLifecycle);
|
||||
mController.mBatteryMeterView = mBatteryMeterView;
|
||||
mController.mTimeText = mTimeText;
|
||||
mController.mSummary = mSummary;
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ShadowEntityHeaderController.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisplayPreference_displayBatteryLevel() {
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
@@ -134,4 +161,15 @@ public class BatteryHeaderPreferenceControllerTest {
|
||||
|
||||
assertThat(mSummary.getText()).isEqualTo(BATTERY_STATUS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnStart_shouldStyleActionBar() {
|
||||
when(mEntityHeaderController.setRecyclerView(nullable(RecyclerView.class), eq(mLifecycle)))
|
||||
.thenReturn(mEntityHeaderController);
|
||||
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
mLifecycle.onStart();
|
||||
|
||||
verify(mEntityHeaderController).styleActionBar(mActivity);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user