diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/settings/CryptKeeper.java | 40 | ||||
-rw-r--r-- | src/com/android/settings/fuelgauge/PowerUsageDetail.java | 8 | ||||
-rw-r--r-- | src/com/android/settings/fuelgauge/Utils.java | 17 | ||||
-rw-r--r-- | src/com/android/settings/users/UserSettings.java | 7 |
4 files changed, 39 insertions, 33 deletions
diff --git a/src/com/android/settings/CryptKeeper.java b/src/com/android/settings/CryptKeeper.java index f07d6fa..94c793d 100644 --- a/src/com/android/settings/CryptKeeper.java +++ b/src/com/android/settings/CryptKeeper.java @@ -55,6 +55,7 @@ import android.widget.EditText; import android.widget.ProgressBar; import android.widget.TextView; +import com.android.internal.statusbar.StatusBarIcon; import com.android.internal.telephony.ITelephony; import com.android.internal.telephony.Phone; import com.android.internal.telephony.PhoneConstants; @@ -229,6 +230,16 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList }; private AudioManager mAudioManager; + /** The status bar where back/home/recent buttons are shown. */ + private StatusBarManager mStatusBar; + + /** All the widgets to disable in the status bar */ + final private static int sWidgetsToDisable = StatusBarManager.DISABLE_EXPAND + | StatusBarManager.DISABLE_NOTIFICATION_ICONS + | StatusBarManager.DISABLE_NOTIFICATION_ALERTS + | StatusBarManager.DISABLE_SYSTEM_INFO + | StatusBarManager.DISABLE_HOME + | StatusBarManager.DISABLE_RECENT; /** @return whether or not this Activity was started for debugging the UI only. */ private boolean isDebugView() { @@ -269,6 +280,7 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList */ @Override public void onBackPressed() { + // In the rare case that something pressed back even though we were disabled. if (mIgnoreBack) return; super.onBackPressed(); @@ -299,13 +311,8 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList // Disable the status bar, but do NOT disable back because the user needs a way to go // from keyboard settings and back to the password screen. - StatusBarManager sbm = (StatusBarManager) getSystemService(Context.STATUS_BAR_SERVICE); - sbm.disable(StatusBarManager.DISABLE_EXPAND - | StatusBarManager.DISABLE_NOTIFICATION_ICONS - | StatusBarManager.DISABLE_NOTIFICATION_ALERTS - | StatusBarManager.DISABLE_SYSTEM_INFO - | StatusBarManager.DISABLE_HOME - | StatusBarManager.DISABLE_RECENT); + mStatusBar = (StatusBarManager) getSystemService(Context.STATUS_BAR_SERVICE); + mStatusBar.disable(sWidgetsToDisable); setAirplaneModeIfNecessary(); mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); @@ -403,7 +410,7 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList ((ProgressBar) findViewById(R.id.progress_bar)).setIndeterminate(true); // Ignore all back presses from now, both hard and soft keys. - mIgnoreBack = true; + setBackFunctionality(false); // Start the first run of progress manually. This method sets up messages to occur at // repeated intervals. updateProgress(); @@ -469,7 +476,7 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList if (mCooldown <= 0) { // Re-enable the password entry and back presses. mPasswordEntry.setEnabled(true); - mIgnoreBack = false; + setBackFunctionality(true); status.setText(R.string.enter_password); } else { CharSequence template = getText(R.string.crypt_keeper_cooldown); @@ -481,6 +488,19 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList } } + /** + * Sets the back status: enabled or disabled according to the parameter. + * @param isEnabled true if back is enabled, false otherwise. + */ + private final void setBackFunctionality(boolean isEnabled) { + mIgnoreBack = !isEnabled; + if (isEnabled) { + mStatusBar.disable(sWidgetsToDisable); + } else { + mStatusBar.disable(sWidgetsToDisable | StatusBarManager.DISABLE_BACK); + } + } + private void passwordEntryInit() { mPasswordEntry = (EditText) findViewById(R.id.passwordEntry); mPasswordEntry.setOnEditorActionListener(this); @@ -610,7 +630,7 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList // Disable the password entry and back keypress while checking the password. These // we either be re-enabled if the password was wrong or after the cooldown period. mPasswordEntry.setEnabled(false); - mIgnoreBack = true; + setBackFunctionality(false); Log.d(TAG, "Attempting to send command to decrypt"); new DecryptTask().execute(password); diff --git a/src/com/android/settings/fuelgauge/PowerUsageDetail.java b/src/com/android/settings/fuelgauge/PowerUsageDetail.java index 4f98163..753bf82 100644 --- a/src/com/android/settings/fuelgauge/PowerUsageDetail.java +++ b/src/com/android/settings/fuelgauge/PowerUsageDetail.java @@ -34,10 +34,10 @@ import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; import android.os.Process; -import android.os.UserHandle; import android.preference.PreferenceActivity; import android.provider.Settings; import android.text.TextUtils; +import android.text.format.Formatter; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -310,10 +310,12 @@ public class PowerUsageDetail extends Fragment implements Button.OnClickListener switch (mTypes[i]) { case R.string.usage_type_data_recv: case R.string.usage_type_data_send: - value = Utils.formatBytes(getActivity(), mValues[i]); + final long bytes = (long) (mValues[i]); + value = Formatter.formatFileSize(getActivity(), bytes); break; case R.string.usage_type_no_coverage: - value = String.format("%d%%", (int) Math.floor(mValues[i])); + final int percentage = (int) Math.floor(mValues[i]); + value = getActivity().getString(R.string.percentage, percentage); break; case R.string.usage_type_gps: mUsesGps = true; diff --git a/src/com/android/settings/fuelgauge/Utils.java b/src/com/android/settings/fuelgauge/Utils.java index 2ffc9de..5c99a86 100644 --- a/src/com/android/settings/fuelgauge/Utils.java +++ b/src/com/android/settings/fuelgauge/Utils.java @@ -64,21 +64,4 @@ public class Utils { } return sb.toString(); } - - /** - * Formats data size in KB, MB, from the given bytes. - * @param context the application context - * @param bytes data size in bytes - * @return the formatted size such as 4.52 MB or 245 KB or 332 bytes - */ - public static String formatBytes(Context context, double bytes) { - // TODO: I18N - if (bytes > 1000 * 1000) { - return String.format("%.2f MB", ((int) (bytes / 1000)) / 1000f); - } else if (bytes > 1024) { - return String.format("%.2f KB", ((int) (bytes / 10)) / 100f); - } else { - return String.format("%d bytes", (int) bytes); - } - } } diff --git a/src/com/android/settings/users/UserSettings.java b/src/com/android/settings/users/UserSettings.java index 632dfe5..dbaaf37 100644 --- a/src/com/android/settings/users/UserSettings.java +++ b/src/com/android/settings/users/UserSettings.java @@ -26,6 +26,7 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; import android.content.pm.UserInfo; +import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.drawable.BitmapDrawable; @@ -477,6 +478,7 @@ public class UserSettings extends SettingsPreferenceFragment } private void loadIconsAsync(List<Integer> missingIcons) { + final Resources resources = getResources(); new AsyncTask<List<Integer>, Void, Void>() { @Override protected void onPostExecute(Void result) { @@ -485,17 +487,16 @@ public class UserSettings extends SettingsPreferenceFragment @Override protected Void doInBackground(List<Integer>... values) { - if (getActivity() == null) return null; for (int userId : values[0]) { Bitmap bitmap = mUserManager.getUserIcon(userId); - Drawable d = new BitmapDrawable(getResources(), bitmap); + Drawable d = new BitmapDrawable(resources, bitmap); mUserIcons.append(userId, d); } return null; } }.execute(missingIcons); - } + private void assignProfilePhoto(final UserInfo user) { if (!Utils.copyMeProfilePhoto(getActivity(), user)) { assignDefaultPhoto(user); |