Fix bug #15730311 Checkboxes on R side should update to Quantum/Material on/off switch
Per UX request, convert Account Sync feeds CheckBoxes to Switches Change-Id: I7017020700b4214a16ca119a6992e6c7a484db0b
This commit is contained in:
@@ -14,7 +14,7 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<!-- Layout used by SyncStateCheckBoxPreference. This is inflated
|
<!-- Layout used by SyncStateSwitchPreference. This is inflated
|
||||||
inside android.R.layout.preference. -->
|
inside android.R.layout.preference. -->
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
@@ -38,8 +38,8 @@
|
|||||||
android:layout_marginEnd="8dip"
|
android:layout_marginEnd="8dip"
|
||||||
android:contentDescription="@string/sync_active" />
|
android:contentDescription="@string/sync_active" />
|
||||||
|
|
||||||
<CheckBox xmlns:android="http://schemas.android.com/apk/res/android"
|
<Switch xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:id="@android:id/checkbox"
|
android:id="@*android:id/switchWidget"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
|
@@ -74,8 +74,8 @@ public class AccountSyncSettings extends AccountPreferenceBase {
|
|||||||
private ImageView mProviderIcon;
|
private ImageView mProviderIcon;
|
||||||
private TextView mErrorInfoView;
|
private TextView mErrorInfoView;
|
||||||
private Account mAccount;
|
private Account mAccount;
|
||||||
private ArrayList<SyncStateCheckBoxPreference> mCheckBoxes =
|
private ArrayList<SyncStateSwitchPreference> mSwitches =
|
||||||
new ArrayList<SyncStateCheckBoxPreference>();
|
new ArrayList<SyncStateSwitchPreference>();
|
||||||
private ArrayList<SyncAdapterType> mInvisibleAdapters = Lists.newArrayList();
|
private ArrayList<SyncAdapterType> mInvisibleAdapters = Lists.newArrayList();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -209,9 +209,9 @@ public class AccountSyncSettings extends AccountPreferenceBase {
|
|||||||
mAuthenticatorHelper.stopListeningToAccountUpdates();
|
mAuthenticatorHelper.stopListeningToAccountUpdates();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addSyncStateCheckBox(Account account, String authority) {
|
private void addSyncStateSwitch(Account account, String authority) {
|
||||||
SyncStateCheckBoxPreference item =
|
SyncStateSwitchPreference item =
|
||||||
new SyncStateCheckBoxPreference(getActivity(), account, authority);
|
new SyncStateSwitchPreference(getActivity(), account, authority);
|
||||||
item.setPersistent(false);
|
item.setPersistent(false);
|
||||||
final ProviderInfo providerInfo = getPackageManager().resolveContentProviderAsUser(
|
final ProviderInfo providerInfo = getPackageManager().resolveContentProviderAsUser(
|
||||||
authority, 0, mUserHandle.getIdentifier());
|
authority, 0, mUserHandle.getIdentifier());
|
||||||
@@ -226,7 +226,7 @@ public class AccountSyncSettings extends AccountPreferenceBase {
|
|||||||
String title = getString(R.string.sync_item_title, providerLabel);
|
String title = getString(R.string.sync_item_title, providerLabel);
|
||||||
item.setTitle(title);
|
item.setTitle(title);
|
||||||
item.setKey(authority);
|
item.setKey(authority);
|
||||||
mCheckBoxes.add(item);
|
mSwitches.add(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -282,8 +282,8 @@ public class AccountSyncSettings extends AccountPreferenceBase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceTreeClick(PreferenceScreen preferences, Preference preference) {
|
public boolean onPreferenceTreeClick(PreferenceScreen preferences, Preference preference) {
|
||||||
if (preference instanceof SyncStateCheckBoxPreference) {
|
if (preference instanceof SyncStateSwitchPreference) {
|
||||||
SyncStateCheckBoxPreference syncPref = (SyncStateCheckBoxPreference) preference;
|
SyncStateSwitchPreference syncPref = (SyncStateSwitchPreference) preference;
|
||||||
String authority = syncPref.getAuthority();
|
String authority = syncPref.getAuthority();
|
||||||
Account account = syncPref.getAccount();
|
Account account = syncPref.getAccount();
|
||||||
final int userId = mUserHandle.getIdentifier();
|
final int userId = mUserHandle.getIdentifier();
|
||||||
@@ -326,10 +326,10 @@ public class AccountSyncSettings extends AccountPreferenceBase {
|
|||||||
int count = getPreferenceScreen().getPreferenceCount();
|
int count = getPreferenceScreen().getPreferenceCount();
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
Preference pref = getPreferenceScreen().getPreference(i);
|
Preference pref = getPreferenceScreen().getPreference(i);
|
||||||
if (! (pref instanceof SyncStateCheckBoxPreference)) {
|
if (! (pref instanceof SyncStateSwitchPreference)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
SyncStateCheckBoxPreference syncPref = (SyncStateCheckBoxPreference) pref;
|
SyncStateSwitchPreference syncPref = (SyncStateSwitchPreference) pref;
|
||||||
if (!syncPref.isChecked()) {
|
if (!syncPref.isChecked()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -376,15 +376,15 @@ public class AccountSyncSettings extends AccountPreferenceBase {
|
|||||||
List<SyncInfo> currentSyncs = ContentResolver.getCurrentSyncsAsUser(userId);
|
List<SyncInfo> currentSyncs = ContentResolver.getCurrentSyncsAsUser(userId);
|
||||||
boolean syncIsFailing = false;
|
boolean syncIsFailing = false;
|
||||||
|
|
||||||
// Refresh the sync status checkboxes - some syncs may have become active.
|
// Refresh the sync status switches - some syncs may have become active.
|
||||||
updateAccountCheckboxes();
|
updateAccountSwitches();
|
||||||
|
|
||||||
for (int i = 0, count = getPreferenceScreen().getPreferenceCount(); i < count; i++) {
|
for (int i = 0, count = getPreferenceScreen().getPreferenceCount(); i < count; i++) {
|
||||||
Preference pref = getPreferenceScreen().getPreference(i);
|
Preference pref = getPreferenceScreen().getPreference(i);
|
||||||
if (! (pref instanceof SyncStateCheckBoxPreference)) {
|
if (! (pref instanceof SyncStateSwitchPreference)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
SyncStateCheckBoxPreference syncPref = (SyncStateCheckBoxPreference) pref;
|
SyncStateSwitchPreference syncPref = (SyncStateSwitchPreference) pref;
|
||||||
|
|
||||||
String authority = syncPref.getAuthority();
|
String authority = syncPref.getAuthority();
|
||||||
Account account = syncPref.getAccount();
|
Account account = syncPref.getAccount();
|
||||||
@@ -450,7 +450,7 @@ public class AccountSyncSettings extends AccountPreferenceBase {
|
|||||||
finish();
|
finish();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
updateAccountCheckboxes();
|
updateAccountSwitches();
|
||||||
onSyncStateUpdated();
|
onSyncStateUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -468,7 +468,7 @@ public class AccountSyncSettings extends AccountPreferenceBase {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateAccountCheckboxes() {
|
private void updateAccountSwitches() {
|
||||||
mInvisibleAdapters.clear();
|
mInvisibleAdapters.clear();
|
||||||
|
|
||||||
SyncAdapterType[] syncAdapters = ContentResolver.getSyncAdapterTypesAsUser(
|
SyncAdapterType[] syncAdapters = ContentResolver.getSyncAdapterTypesAsUser(
|
||||||
@@ -480,7 +480,7 @@ public class AccountSyncSettings extends AccountPreferenceBase {
|
|||||||
if (!sa.accountType.equals(mAccount.type)) continue;
|
if (!sa.accountType.equals(mAccount.type)) continue;
|
||||||
if (sa.isUserVisible()) {
|
if (sa.isUserVisible()) {
|
||||||
if (Log.isLoggable(TAG, Log.VERBOSE)) {
|
if (Log.isLoggable(TAG, Log.VERBOSE)) {
|
||||||
Log.d(TAG, "updateAccountCheckboxes: added authority " + sa.authority
|
Log.d(TAG, "updateAccountSwitches: added authority " + sa.authority
|
||||||
+ " to accountType " + sa.accountType);
|
+ " to accountType " + sa.accountType);
|
||||||
}
|
}
|
||||||
authorities.add(sa.authority);
|
authorities.add(sa.authority);
|
||||||
@@ -491,10 +491,10 @@ public class AccountSyncSettings extends AccountPreferenceBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0, n = mCheckBoxes.size(); i < n; i++) {
|
for (int i = 0, n = mSwitches.size(); i < n; i++) {
|
||||||
getPreferenceScreen().removePreference(mCheckBoxes.get(i));
|
getPreferenceScreen().removePreference(mSwitches.get(i));
|
||||||
}
|
}
|
||||||
mCheckBoxes.clear();
|
mSwitches.clear();
|
||||||
|
|
||||||
if (Log.isLoggable(TAG, Log.VERBOSE)) {
|
if (Log.isLoggable(TAG, Log.VERBOSE)) {
|
||||||
Log.d(TAG, "looking for sync adapters that match account " + mAccount);
|
Log.d(TAG, "looking for sync adapters that match account " + mAccount);
|
||||||
@@ -508,13 +508,13 @@ public class AccountSyncSettings extends AccountPreferenceBase {
|
|||||||
Log.d(TAG, " found authority " + authority + " " + syncState);
|
Log.d(TAG, " found authority " + authority + " " + syncState);
|
||||||
}
|
}
|
||||||
if (syncState > 0) {
|
if (syncState > 0) {
|
||||||
addSyncStateCheckBox(mAccount, authority);
|
addSyncStateSwitch(mAccount, authority);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Collections.sort(mCheckBoxes);
|
Collections.sort(mSwitches);
|
||||||
for (int i = 0, n = mCheckBoxes.size(); i < n; i++) {
|
for (int i = 0, n = mSwitches.size(); i < n; i++) {
|
||||||
getPreferenceScreen().addPreference(mCheckBoxes.get(i));
|
getPreferenceScreen().addPreference(mSwitches.get(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -19,7 +19,7 @@ package com.android.settings.accounts;
|
|||||||
import android.accounts.Account;
|
import android.accounts.Account;
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.preference.CheckBoxPreference;
|
import android.preference.SwitchPreference;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -28,7 +28,7 @@ import android.widget.TextView;
|
|||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.widget.AnimatedImageView;
|
import com.android.settings.widget.AnimatedImageView;
|
||||||
|
|
||||||
public class SyncStateCheckBoxPreference extends CheckBoxPreference {
|
public class SyncStateSwitchPreference extends SwitchPreference {
|
||||||
|
|
||||||
private boolean mIsActive = false;
|
private boolean mIsActive = false;
|
||||||
private boolean mIsPending = false;
|
private boolean mIsPending = false;
|
||||||
@@ -42,14 +42,14 @@ public class SyncStateCheckBoxPreference extends CheckBoxPreference {
|
|||||||
*/
|
*/
|
||||||
private boolean mOneTimeSyncMode = false;
|
private boolean mOneTimeSyncMode = false;
|
||||||
|
|
||||||
public SyncStateCheckBoxPreference(Context context, AttributeSet attrs) {
|
public SyncStateSwitchPreference(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
setWidgetLayoutResource(R.layout.preference_widget_sync_toggle);
|
setWidgetLayoutResource(R.layout.preference_widget_sync_toggle);
|
||||||
mAccount = null;
|
mAccount = null;
|
||||||
mAuthority = null;
|
mAuthority = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SyncStateCheckBoxPreference(Context context, Account account, String authority) {
|
public SyncStateSwitchPreference(Context context, Account account, String authority) {
|
||||||
super(context, null);
|
super(context, null);
|
||||||
mAccount = account;
|
mAccount = account;
|
||||||
mAuthority = authority;
|
mAuthority = authority;
|
||||||
@@ -70,9 +70,9 @@ public class SyncStateCheckBoxPreference extends CheckBoxPreference {
|
|||||||
final boolean failedVisible = mFailed && !activeVisible;
|
final boolean failedVisible = mFailed && !activeVisible;
|
||||||
syncFailedView.setVisibility(failedVisible ? View.VISIBLE : View.GONE);
|
syncFailedView.setVisibility(failedVisible ? View.VISIBLE : View.GONE);
|
||||||
|
|
||||||
View checkBox = view.findViewById(android.R.id.checkbox);
|
View switchView = view.findViewById(com.android.internal.R.id.switchWidget);
|
||||||
if (mOneTimeSyncMode) {
|
if (mOneTimeSyncMode) {
|
||||||
checkBox.setVisibility(View.GONE);
|
switchView.setVisibility(View.GONE);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Override the summary. Fill in the %1$s with the existing summary
|
* Override the summary. Fill in the %1$s with the existing summary
|
||||||
@@ -82,7 +82,7 @@ public class SyncStateCheckBoxPreference extends CheckBoxPreference {
|
|||||||
TextView summary = (TextView) view.findViewById(android.R.id.summary);
|
TextView summary = (TextView) view.findViewById(android.R.id.summary);
|
||||||
summary.setText(getContext().getString(R.string.sync_one_time_sync, getSummary()));
|
summary.setText(getContext().getString(R.string.sync_one_time_sync, getSummary()));
|
||||||
} else {
|
} else {
|
||||||
checkBox.setVisibility(View.VISIBLE);
|
switchView.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,7 +131,7 @@ public class SyncStateCheckBoxPreference extends CheckBoxPreference {
|
|||||||
@Override
|
@Override
|
||||||
protected void onClick() {
|
protected void onClick() {
|
||||||
// When we're in one-time sync mode, we don't want a click to change the
|
// When we're in one-time sync mode, we don't want a click to change the
|
||||||
// checkbox state
|
// Switch state
|
||||||
if (!mOneTimeSyncMode) {
|
if (!mOneTimeSyncMode) {
|
||||||
if (ActivityManager.isUserAMonkey()) {
|
if (ActivityManager.isUserAMonkey()) {
|
||||||
Log.d("SyncState", "ignoring monkey's attempt to flip sync state");
|
Log.d("SyncState", "ignoring monkey's attempt to flip sync state");
|
Reference in New Issue
Block a user