- 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
117 lines
4.0 KiB
Java
117 lines
4.0 KiB
Java
/*
|
|
* Copyright (C) 2017 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.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
|
|
implements LifecycleObserver, OnStart {
|
|
@VisibleForTesting
|
|
static final String KEY_BATTERY_HEADER = "battery_header";
|
|
|
|
@VisibleForTesting
|
|
BatteryMeterView mBatteryMeterView;
|
|
@VisibleForTesting
|
|
TextView mTimeText;
|
|
@VisibleForTesting
|
|
TextView mSummary;
|
|
|
|
private final Activity mActivity;
|
|
private final PreferenceFragment mHost;
|
|
private final Lifecycle mLifecycle;
|
|
|
|
private LayoutPreference mBatteryLayoutPref;
|
|
|
|
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);
|
|
mTimeText = (TextView) mBatteryLayoutPref.findViewById(R.id.battery_percent);
|
|
mSummary = (TextView) mBatteryLayoutPref.findViewById(R.id.summary1);
|
|
|
|
Intent batteryBroadcast = mContext.registerReceiver(null,
|
|
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
|
final int batteryLevel = Utils.getBatteryLevel(batteryBroadcast);
|
|
|
|
mBatteryMeterView.setBatteryLevel(batteryLevel);
|
|
mTimeText.setText(Utils.formatPercentage(batteryLevel));
|
|
}
|
|
|
|
@Override
|
|
public boolean isAvailable() {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public String getPreferenceKey() {
|
|
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) {
|
|
mSummary.setText(info.statusLabel);
|
|
} else {
|
|
mSummary.setText(info.remainingLabel);
|
|
}
|
|
|
|
mBatteryMeterView.setBatteryLevel(info.batteryLevel);
|
|
mBatteryMeterView.setCharging(!info.discharging);
|
|
}
|
|
}
|