Files
packages_apps_Settings/src/com/android/settings/datausage/AppDataUsagePreference.java
Fan Zhang 1c3a4de93d Switch to use small icon for most app related pages
- Renamed AppProgressPreference to AppPreference to handle most app
  related prefs
- Add ed AppSwitchPreference - the same layout as AppPreference except
  it's a SwitchPreference
- Use above 2 prefs in most app related pages.
  - Everything under special access pages
  - Recent app list in App & notifications
  - App data usage detail page
  - Default app picker pages

Bug: 65182905
Test: robotests
Change-Id: I96c980ba1db49e36dabe25b5eade1197215aad11
2017-10-30 12:20:49 -07:00

85 lines
2.7 KiB
Java

/*
* 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.datausage;
import android.content.Context;
import android.support.v7.preference.PreferenceViewHolder;
import android.text.format.Formatter;
import android.view.View;
import android.widget.ProgressBar;
import com.android.settings.widget.AppPreference;
import com.android.settingslib.AppItem;
import com.android.settingslib.net.UidDetail;
import com.android.settingslib.net.UidDetailProvider;
import com.android.settingslib.utils.ThreadUtils;
public class AppDataUsagePreference extends AppPreference {
private final AppItem mItem;
private final int mPercent;
private UidDetail mDetail;
public AppDataUsagePreference(Context context, AppItem item, int percent,
UidDetailProvider provider) {
super(context);
mItem = item;
mPercent = percent;
if (item.restricted && item.total <= 0) {
setSummary(com.android.settings.R.string.data_usage_app_restricted);
} else {
setSummary(Formatter.formatFileSize(context, item.total));
}
mDetail = provider.getUidDetail(item.key, false /* blocking */);
if (mDetail != null) {
setAppInfo();
} else {
ThreadUtils.postOnBackgroundThread(() -> {
mDetail = provider.getUidDetail(mItem.key, true /* blocking */);
ThreadUtils.postOnMainThread(() -> setAppInfo());
});
}
}
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
final ProgressBar progress = (ProgressBar) holder.findViewById(
android.R.id.progress);
if (mItem.restricted && mItem.total <= 0) {
progress.setVisibility(View.GONE);
} else {
progress.setVisibility(View.VISIBLE);
}
progress.setProgress(mPercent);
}
private void setAppInfo() {
if (mDetail != null) {
setIcon(mDetail.icon);
setTitle(mDetail.label);
} else {
setIcon(null);
setTitle(null);
}
}
public AppItem getItem() {
return mItem;
}
}