summaryrefslogtreecommitdiffstats
path: root/policy
diff options
context:
space:
mode:
authorDvTonder <david.vantonder@gmail.com>2012-03-01 16:14:23 -0500
committerDavid van Tonder <david.vantonder@gmail.com>2012-03-07 17:30:46 -0800
commitc0498ebfa2e80ca8030f4e084069075576426474 (patch)
tree838a446e33565096f70d23e492a428e4ee831439 /policy
parentd4c5edfb20fe5e5b39d8e6d147876c381b3b485d (diff)
downloadframeworks_base-c0498ebfa2e80ca8030f4e084069075576426474.zip
frameworks_base-c0498ebfa2e80ca8030f4e084069075576426474.tar.gz
frameworks_base-c0498ebfa2e80ca8030f4e084069075576426474.tar.bz2
Profiles - Part 2 of 2
Frameworks support for Profiles. Ported from CM7 with some ICS related updates. Patch set 3 - Adds Phone Rintone and Vibrate intercepts Patch set 4 - Minor cleanup Change-Id: I580aed32b714af8497ede39e0905fb327531bf1c
Diffstat (limited to 'policy')
-rw-r--r--policy/src/com/android/internal/policy/impl/GlobalActions.java108
1 files changed, 106 insertions, 2 deletions
diff --git a/policy/src/com/android/internal/policy/impl/GlobalActions.java b/policy/src/com/android/internal/policy/impl/GlobalActions.java
index dfece30..17e8826 100644
--- a/policy/src/com/android/internal/policy/impl/GlobalActions.java
+++ b/policy/src/com/android/internal/policy/impl/GlobalActions.java
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2008 The Android Open Source Project
- * Copyright (C) 2011 David van Tonder
+ * Copyright (C) 2010-2012 CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,6 +19,10 @@ package com.android.internal.policy.impl;
import android.app.Activity;
import android.app.AlertDialog;
+import android.app.Dialog;
+import android.app.Profile;
+import android.app.ProfileManager;
+import android.app.StatusBarManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
@@ -47,6 +51,7 @@ import com.android.internal.telephony.TelephonyProperties;
import com.google.android.collect.Lists;
import java.util.ArrayList;
+import java.util.UUID;
/**
* Needed for takeScreenshot
@@ -85,6 +90,8 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
private ToggleAction.State mAirplaneState = ToggleAction.State.Off;
private boolean mIsWaitingForEcmExit = false;
+ private Profile mChosenProfile;
+
/**
* @param context everything needs a context :(
*/
@@ -206,6 +213,22 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
}
});
+ // next: profile
+ mItems.add(
+ new ProfileChooseAction() {
+ public void onPress() {
+ createProfileDialog();
+ }
+
+ public boolean showDuringKeyguard() {
+ return false;
+ }
+
+ public boolean showBeforeProvisioning() {
+ return false;
+ }
+ });
+
// next: screenshot
mItems.add(
new SinglePressAction(com.android.internal.R.drawable.ic_lock_screenshot, R.string.global_action_screenshot) {
@@ -247,6 +270,51 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
return dialog;
}
+ private void createProfileDialog(){
+ final ProfileManager profileManager = (ProfileManager)mContext.getSystemService(Context.PROFILE_SERVICE);
+
+ final Profile[] profiles = profileManager.getProfiles();
+ UUID activeProfile = profileManager.getActiveProfile().getUuid();
+ final CharSequence[] names = new CharSequence[profiles.length];
+
+ int i=0;
+ int checkedItem = 0;
+
+ for(Profile profile : profiles) {
+ if(profile.getUuid().equals(activeProfile)) {
+ checkedItem = i;
+ mChosenProfile = profile;
+ }
+ names[i++] = profile.getName();
+ }
+
+ final AlertDialog.Builder ab = new AlertDialog.Builder(mContext);
+
+ AlertDialog dialog = ab
+ .setTitle(R.string.global_action_choose_profile)
+ .setSingleChoiceItems(names, checkedItem, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ if (which < 0)
+ return;
+ mChosenProfile = profiles[which];
+ }
+ })
+ .setPositiveButton(com.android.internal.R.string.yes,
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ profileManager.setActiveProfile(mChosenProfile.getUuid());
+ }
+ })
+ .setNegativeButton(com.android.internal.R.string.no,
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ dialog.cancel();
+ }
+ }).create();
+ dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG);
+ dialog.show();
+ }
+
/**
* functions needed for taking screenhots.
* This leverages the built in ICS screenshot functionality
@@ -306,7 +374,7 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
msg.arg2 = 1;
*/
- /* wait for the dislog box to close */
+ /* wait for the dialog box to close */
try {
Thread.sleep(1000);
} catch (InterruptedException ie) {
@@ -499,6 +567,42 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
}
/**
+ * A single press action maintains no state, just responds to a press
+ * and takes an action.
+ */
+ private abstract class ProfileChooseAction implements Action {
+ private ProfileManager mProfileManager;
+
+ protected ProfileChooseAction() {
+ mProfileManager = (ProfileManager)mContext.getSystemService(Context.PROFILE_SERVICE);
+ }
+
+ public boolean isEnabled() {
+ return true;
+ }
+
+ abstract public void onPress();
+
+ public View create(
+ Context context, View convertView, ViewGroup parent, LayoutInflater inflater) {
+ View v = (convertView != null) ?
+ convertView :
+ inflater.inflate(R.layout.global_actions_item, parent, false);
+
+ ImageView icon = (ImageView) v.findViewById(R.id.icon);
+ TextView messageView = (TextView) v.findViewById(R.id.message);
+ TextView statusView = (TextView) v.findViewById(R.id.status);
+ statusView.setVisibility(View.VISIBLE);
+ statusView.setText(mProfileManager.getActiveProfile().getName());
+
+ icon.setImageDrawable(context.getResources().getDrawable(com.android.internal.R.drawable.ic_lock_profile));
+ messageView.setText(R.string.global_action_choose_profile);
+
+ return v;
+ }
+ }
+
+ /**
* A toggle action knows whether it is on or off, and displays an icon
* and status message accordingly.
*/