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