Merge "Fix ListView being too eager too scroll" into mnc-dev

This commit is contained in:
Jason Monk
2015-06-18 20:07:40 +00:00
committed by Android (Google) Code Review
3 changed files with 82 additions and 44 deletions

View File

@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 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:paddingTop="8dp"
android:paddingBottom="8dp"
android:orientation="vertical">
<include
layout="@layout/radio_with_summary"
android:id="@+id/ignore_on" />
<include
layout="@layout/radio_with_summary"
android:id="@+id/ignore_off" />
</LinearLayout>

View File

@@ -20,6 +20,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="?android:attr/selectableItemBackground"
android:minHeight="?android:attr/listPreferredItemHeightSmall">
<CheckedTextView

View File

@@ -16,7 +16,6 @@
package com.android.settings.fuelgauge;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
@@ -27,18 +26,20 @@ import android.content.DialogInterface.OnClickListener;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.util.Pair;
import android.util.SparseBooleanArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.view.ViewGroup.LayoutParams;
import android.widget.Checkable;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.android.settings.R;
import com.android.settings.applications.AppInfoBase;
import com.android.settingslib.applications.ApplicationsState.AppEntry;
public class HighPowerDetail extends DialogFragment implements OnClickListener {
public class HighPowerDetail extends DialogFragment implements OnClickListener,
View.OnClickListener {
private static final String ARG_DEFAULT_ON = "default_on";
@@ -47,8 +48,9 @@ public class HighPowerDetail extends DialogFragment implements OnClickListener {
private String mPackageName;
private CharSequence mLabel;
private boolean mDefaultOn;
private Adapter mAdapter;
private int mSelectedIndex;
private boolean mIsEnabled;
private Checkable mOptionOn;
private Checkable mOptionOff;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -62,15 +64,20 @@ public class HighPowerDetail extends DialogFragment implements OnClickListener {
mLabel = mPackageName;
}
mDefaultOn = getArguments().getBoolean(ARG_DEFAULT_ON);
mAdapter = new Adapter(getContext(), R.layout.radio_with_summary);
mAdapter.add(new Pair<String, String>(getString(R.string.ignore_optimizations_on),
getString(R.string.ignore_optimizations_on_desc)));
mAdapter.add(new Pair<String, String>(getString(R.string.ignore_optimizations_off),
getString(R.string.ignore_optimizations_off_desc)));
mSelectedIndex = mDefaultOn || mBackend.isWhitelisted(mPackageName) ? 0 : 1;
if (mBackend.isSysWhitelisted(mPackageName)) {
mAdapter.setEnabled(1, false);
mIsEnabled = mDefaultOn || mBackend.isWhitelisted(mPackageName);
}
public Checkable setup(View view, boolean on) {
((TextView) view.findViewById(android.R.id.title)).setText(on
? R.string.ignore_optimizations_on : R.string.ignore_optimizations_off);
((TextView) view.findViewById(android.R.id.summary)).setText(on
? R.string.ignore_optimizations_on_desc : R.string.ignore_optimizations_off_desc);
view.setClickable(true);
view.setOnClickListener(this);
if (!on && mBackend.isSysWhitelisted(mPackageName)) {
view.setEnabled(false);
}
return (Checkable) view;
}
@Override
@@ -78,17 +85,41 @@ public class HighPowerDetail extends DialogFragment implements OnClickListener {
AlertDialog.Builder b = new AlertDialog.Builder(getContext())
.setTitle(getString(R.string.ignore_optimizations_title, mLabel))
.setNegativeButton(R.string.cancel, null)
.setSingleChoiceItems(mAdapter, mSelectedIndex, this);
.setView(R.layout.ignore_optimizations_content);
if (!mBackend.isSysWhitelisted(mPackageName)) {
b.setPositiveButton(R.string.done, this);
}
return b.create();
}
@Override
public void onStart() {
super.onStart();
mOptionOn = setup(getDialog().findViewById(R.id.ignore_on), true);
mOptionOff = setup(getDialog().findViewById(R.id.ignore_off), false);
updateViews();
}
private void updateViews() {
mOptionOn.setChecked(mIsEnabled);
mOptionOff.setChecked(!mIsEnabled);
}
@Override
public void onClick(View v) {
if (v == mOptionOn) {
mIsEnabled = true;
updateViews();
} else if (v == mOptionOff) {
mIsEnabled = false;
updateViews();
}
}
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == DialogInterface.BUTTON_POSITIVE) {
boolean newValue = mSelectedIndex == 0;
boolean newValue = mIsEnabled;
boolean oldValue = mBackend.isWhitelisted(mPackageName);
if (newValue != oldValue) {
if (newValue) {
@@ -97,8 +128,6 @@ public class HighPowerDetail extends DialogFragment implements OnClickListener {
mBackend.removeApp(mPackageName);
}
}
} else {
mSelectedIndex = which;
}
}
@@ -130,29 +159,4 @@ public class HighPowerDetail extends DialogFragment implements OnClickListener {
fragment.setTargetFragment(caller, requestCode);
fragment.show(caller.getFragmentManager(), HighPowerDetail.class.getSimpleName());
}
private class Adapter extends ArrayAdapter<Pair<String, String>> {
private final SparseBooleanArray mEnabled = new SparseBooleanArray();
public Adapter(Context context, int resource) {
super(context, resource, android.R.id.title);
}
public void setEnabled(int index, boolean enabled) {
mEnabled.put(index, enabled);
}
public boolean isEnabled(int position) {
return mEnabled.get(position, true);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
((TextView) view.findViewById(android.R.id.title)).setText(getItem(position).first);
((TextView) view.findViewById(android.R.id.summary)).setText(getItem(position).second);
view.setEnabled(isEnabled(position));
return view;
}
}
}