Files
app_Settings/src/com/android/settings/AccountPreference.java
Amith Yamasani d1ab82807a Account types at toplevel of Settings
Reorganized Account settings to show account types at the top-level
of Settings. Only account types that have accounts added are visible
here. There is an Add account button to add a new account.

Master sync toggle has moved to Data Usage screen in the overflow menu.
It shows additional detail of the function of the auto-sync toggle when
it is toggled by the user.

Account type screen (ManageAccountsSettings) shows list of accounts of
that type and any available authenticator settings. It additionally
verifies any Intents can be resolved before showing the corresponding
entry. This screen now shows last synced time for each account.

You can now sync all accounts of a type by selecting Sync now in the
Account type screen.

Account Sync screen that shows the list of syncable items has minor
tweaks:
 - "Last synced...", "Sync is OFF"
 - Doesn't show the authenticator settings here anymore.

Bug: 6579937

Change-Id: I8139a4c992b525a3e1efc24d2d223c3f5caddc76
2012-06-04 17:01:22 -07:00

135 lines
4.5 KiB
Java

/*
* Copyright (C) 2008 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;
import java.util.ArrayList;
import android.accounts.Account;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.preference.Preference;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
/**
* AccountPreference is used to display a username, status and provider icon for an account on
* the device.
*/
public class AccountPreference extends Preference {
private static final String TAG = "AccountPreference";
public static final int SYNC_ENABLED = 0; // all know sync adapters are enabled and OK
public static final int SYNC_DISABLED = 1; // no sync adapters are enabled
public static final int SYNC_ERROR = 2; // one or more sync adapters have a problem
public static final int SYNC_IN_PROGRESS = 3; // currently syncing
private int mStatus;
private Account mAccount;
private ArrayList<String> mAuthorities;
public AccountPreference(Context context, Account account, Drawable icon,
ArrayList<String> authorities) {
super(context);
mAccount = account;
mAuthorities = authorities;
setTitle(mAccount.name);
setSummary("");
setPersistent(false);
setSyncStatus(SYNC_DISABLED);
}
public Account getAccount() {
return mAccount;
}
public ArrayList<String> getAuthorities() {
return mAuthorities;
}
@Override
protected void onBindView(View view) {
super.onBindView(view);
setSummary(getSyncStatusMessage(mStatus));
ImageView iconView = (ImageView) view.findViewById(android.R.id.icon);
iconView.setImageResource(getSyncStatusIcon(mStatus));
iconView.setContentDescription(getSyncContentDescription(mStatus));
}
public void setSyncStatus(int status) {
mStatus = status;
setIcon(getSyncStatusIcon(status));
setSummary(getSyncStatusMessage(status));
}
private int getSyncStatusMessage(int status) {
int res;
switch (status) {
case SYNC_ENABLED:
res = R.string.sync_enabled;
break;
case SYNC_DISABLED:
res = R.string.sync_disabled;
break;
case SYNC_ERROR:
res = R.string.sync_error;
break;
case SYNC_IN_PROGRESS:
res = R.string.sync_in_progress;
break;
default:
res = R.string.sync_error;
Log.e(TAG, "Unknown sync status: " + status);
}
return res;
}
private int getSyncStatusIcon(int status) {
int res;
switch (status) {
case SYNC_ENABLED:
res = R.drawable.ic_sync_green_holo;
break;
case SYNC_DISABLED:
res = R.drawable.ic_sync_grey_holo;
break;
case SYNC_ERROR:
res = R.drawable.ic_sync_red_holo;
break;
case SYNC_IN_PROGRESS:
res = R.drawable.ic_sync_grey_holo;
break;
default:
res = R.drawable.ic_sync_red_holo;
Log.e(TAG, "Unknown sync status: " + status);
}
return res;
}
private String getSyncContentDescription(int status) {
switch (status) {
case SYNC_ENABLED:
return getContext().getString(R.string.accessibility_sync_enabled);
case SYNC_DISABLED:
return getContext().getString(R.string.accessibility_sync_disabled);
case SYNC_ERROR:
return getContext().getString(R.string.accessibility_sync_error);
default:
Log.e(TAG, "Unknown sync status: " + status);
return getContext().getString(R.string.accessibility_sync_error);
}
}
}