summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/AccountPreference.java
diff options
context:
space:
mode:
authorDaisuke Miyakawa <dmiyakawa@google.com>2010-09-15 20:09:12 -0700
committerDaisuke Miyakawa <dmiyakawa@google.com>2010-09-17 11:22:02 -0700
commita2633d0232adefd2767484add759a46906e00bcc (patch)
tree0215bb1f1a755f4d7226d19ff20d3529e6da8de9 /src/com/android/settings/AccountPreference.java
parent4f169ba1aa78fc1ff0debc4101b97ad54a45ca40 (diff)
downloadpackages_apps_Settings-a2633d0232adefd2767484add759a46906e00bcc.zip
packages_apps_Settings-a2633d0232adefd2767484add759a46906e00bcc.tar.gz
packages_apps_Settings-a2633d0232adefd2767484add759a46906e00bcc.tar.bz2
Move ManageAccountsSettings into Settings.
- Add activity-alias for the Activity. - Copy the Activity from AccountsAndSyncSettings. - Fragmentize ManageAccountsSettings. - Remove dependency toward AccountPreferenceBase, which is used in AccountsAndSyncSettings widely. - Add missing implementation derived from AccountPrefernceBase. - Copy dependent drawables. - Copy dependent xmls - Copy AccountPrefernce.java. - Copy strings, adding CHAR LIMIT. - Remove the logic which remove the preference when its destination Activity is missing. We already have the destination as Fragment, and it never disappear. Change-Id: Id41c63d7064aebeaae31bcd84bf4fd20a5636dfe
Diffstat (limited to 'src/com/android/settings/AccountPreference.java')
-rw-r--r--src/com/android/settings/AccountPreference.java142
1 files changed, 142 insertions, 0 deletions
diff --git a/src/com/android/settings/AccountPreference.java b/src/com/android/settings/AccountPreference.java
new file mode 100644
index 0000000..a860d1a
--- /dev/null
+++ b/src/com/android/settings/AccountPreference.java
@@ -0,0 +1,142 @@
+/*
+ * 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.content.Intent;
+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
+ private int mStatus;
+ private Account mAccount;
+ private ArrayList<String> mAuthorities;
+ private Drawable mProviderIcon;
+ private ImageView mSyncStatusIcon;
+ private ImageView mProviderIconView;
+
+ public AccountPreference(Context context, Account account, Drawable icon,
+ ArrayList<String> authorities) {
+ super(context);
+ mAccount = account;
+ mAuthorities = authorities;
+ mProviderIcon = icon;
+ setLayoutResource(R.layout.account_preference);
+ setTitle(mAccount.name);
+ setSummary("");
+ // Add account info to the intent for AccountSyncSettings
+ Intent intent = new Intent("android.settings.ACCOUNT_SYNC_SETTINGS");
+ intent.putExtra("account", mAccount);
+ setIntent(intent);
+ 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));
+ mProviderIconView = (ImageView) view.findViewById(R.id.providerIcon);
+ mProviderIconView.setImageDrawable(mProviderIcon);
+ mSyncStatusIcon = (ImageView) view.findViewById(R.id.syncStatusIcon);
+ mSyncStatusIcon.setImageResource(getSyncStatusIcon(mStatus));
+ }
+
+ public void setProviderIcon(Drawable icon) {
+ mProviderIcon = icon;
+ if (mProviderIconView != null) {
+ mProviderIconView.setImageDrawable(icon);
+ }
+ }
+
+ public void setSyncStatus(int status) {
+ mStatus = status;
+ if (mSyncStatusIcon != null) {
+ mSyncStatusIcon.setImageResource(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;
+ 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;
+ break;
+ case SYNC_DISABLED:
+ res = R.drawable.ic_sync_grey;
+ break;
+ case SYNC_ERROR:
+ res = R.drawable.ic_sync_red;
+ break;
+ default:
+ res = R.drawable.ic_sync_red;
+ Log.e(TAG, "Unknown sync status: " + status);
+ }
+ return res;
+ }
+
+ @Override
+ public int compareTo(Preference other) {
+ if (!(other instanceof AccountPreference)) {
+ // Put other preference types above us
+ return 1;
+ }
+ return mAccount.name.compareTo(((AccountPreference) other).mAccount.name);
+ }
+}