diff options
-rw-r--r-- | AndroidManifest.xml | 1 | ||||
-rw-r--r-- | res/drawable-hdpi/ic_profile.png | bin | 0 -> 1059 bytes | |||
-rw-r--r-- | res/drawable-mdpi/ic_profile.png | bin | 0 -> 657 bytes | |||
-rw-r--r-- | res/drawable-xhdpi/ic_profile.png | bin | 0 -> 826 bytes | |||
-rwxr-xr-x | res/drawable-xxhdpi/ic_profile.png | bin | 0 -> 1688 bytes | |||
-rw-r--r-- | res/layout/alarm_time.xml | 19 | ||||
-rw-r--r-- | res/values/cm_strings.xml | 7 | ||||
-rw-r--r-- | src/com/android/deskclock/AlarmClockFragment.java | 96 | ||||
-rwxr-xr-x[-rw-r--r--] | src/com/android/deskclock/alarms/AlarmService.java | 38 |
9 files changed, 161 insertions, 0 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 5b4372764..c8e64a9f9 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -37,6 +37,7 @@ <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.SHUTDOWN" /> <uses-permission android:name="cyanogenmod.permission.WRITE_SETTINGS" /> + <uses-permission android:name="cyanogenmod.permission.MODIFY_PROFILES" /> <application android:label="@string/app_label" android:name=".DeskClockApplication" diff --git a/res/drawable-hdpi/ic_profile.png b/res/drawable-hdpi/ic_profile.png Binary files differnew file mode 100644 index 000000000..38c3f44cb --- /dev/null +++ b/res/drawable-hdpi/ic_profile.png diff --git a/res/drawable-mdpi/ic_profile.png b/res/drawable-mdpi/ic_profile.png Binary files differnew file mode 100644 index 000000000..14ffe2260 --- /dev/null +++ b/res/drawable-mdpi/ic_profile.png diff --git a/res/drawable-xhdpi/ic_profile.png b/res/drawable-xhdpi/ic_profile.png Binary files differnew file mode 100644 index 000000000..b015d5960 --- /dev/null +++ b/res/drawable-xhdpi/ic_profile.png diff --git a/res/drawable-xxhdpi/ic_profile.png b/res/drawable-xxhdpi/ic_profile.png Binary files differnew file mode 100755 index 000000000..aa419817d --- /dev/null +++ b/res/drawable-xxhdpi/ic_profile.png diff --git a/res/layout/alarm_time.xml b/res/layout/alarm_time.xml index fee4ccb98..5e301359f 100644 --- a/res/layout/alarm_time.xml +++ b/res/layout/alarm_time.xml @@ -106,8 +106,27 @@ android:paddingStart="4dip" android:drawablePadding="20dp" android:drawableStart="@drawable/ic_ringtone" + android:gravity="center_vertical" android:ellipsize="marquee" + android:marqueeRepeatLimit="marquee_forever" + android:scrollHorizontally="true" + android:singleLine="true" + android:textAlignment="viewStart" + android:textSize="16sp" + android:textColor="@color/clock_white" + /> + + <TextView + android:id="@+id/choose_profile" + android:layout_width="match_parent" + android:layout_height="@dimen/touch_target_min_size" + android:background="?android:attr/selectableItemBackground" + android:clickable="true" + android:paddingStart="4dip" + android:drawablePadding="20dp" + android:drawableStart="@drawable/ic_profile" android:gravity="center_vertical" + android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever" android:scrollHorizontally="true" android:singleLine="true" diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml index 067fedd6e..a23739dbe 100644 --- a/res/values/cm_strings.xml +++ b/res/values/cm_strings.xml @@ -23,4 +23,11 @@ <!-- Setting labels on Set alarm screen: Increasing volume on or off --> <string name="alarm_increasing_volume">Increasing volume</string> + + <!-- Setting labels on Set alarm screen: Choose profile --> + <string name="profile_description">Profile <xliff:g id="profile">%s</xliff:g></string> + + <!-- No profile selected label --> + <string name="profile_no_selected">No profile selected</string> + </resources> diff --git a/src/com/android/deskclock/AlarmClockFragment.java b/src/com/android/deskclock/AlarmClockFragment.java index 14906d870..7866d2aaf 100644 --- a/src/com/android/deskclock/AlarmClockFragment.java +++ b/src/com/android/deskclock/AlarmClockFragment.java @@ -24,13 +24,16 @@ import android.app.Activity; import android.app.Fragment; import android.app.FragmentTransaction; import android.app.LoaderManager; +import android.content.BroadcastReceiver; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; +import android.content.IntentFilter; import android.content.Loader; import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; +import android.database.ContentObserver; import android.database.Cursor; import android.database.DataSetObserver; import android.graphics.Color; @@ -41,8 +44,11 @@ import android.media.RingtoneManager; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; +import android.os.Handler; +import android.os.Message; import android.os.Vibrator; import android.preference.PreferenceManager; +import android.provider.Settings; import android.support.v4.view.ViewCompat; import android.transition.AutoTransition; import android.transition.Fade; @@ -78,6 +84,10 @@ import com.android.deskclock.widget.TextTime; import java.util.Calendar; import java.util.HashSet; +import java.util.UUID; + +import cyanogenmod.app.Profile; +import cyanogenmod.app.ProfileManager; /** * AlarmClock application. @@ -106,6 +116,7 @@ public abstract class AlarmClockFragment extends DeskClockFragment implements private static final int REQUEST_CODE_RINGTONE = 1; private static final int REQUEST_CODE_PERMISSIONS = 2; + private static final int REQUEST_CODE_PROFILE = 3; private static final long INVALID_ID = -1; private static final String PREF_KEY_DEFAULT_ALARM_RINGTONE_URI = "default_alarm_ringtone_uri"; @@ -126,6 +137,21 @@ public abstract class AlarmClockFragment extends DeskClockFragment implements private View mEmptyView; private View mFooterView; + private ProfileManager mProfileManager; + private boolean mProfilesEnabled; + private BroadcastReceiver mProfileReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + if (ProfileManager.PROFILES_STATE_CHANGED_ACTION.equals(action)) { + boolean newState = intent.getIntExtra(ProfileManager.EXTRA_PROFILES_STATE, + ProfileManager.PROFILES_STATE_DISABLED) + == ProfileManager.PROFILES_STATE_ENABLED; + updateProfilesStatus(newState); + } + } + }; + private Bundle mRingtoneTitleCache; // Key: ringtone uri, value: ringtone title private ActionableToastBar mUndoBar; private View mUndoFrame; @@ -183,6 +209,8 @@ public abstract class AlarmClockFragment extends DeskClockFragment implements @Override public void onCreate(Bundle savedState) { super.onCreate(savedState); + mProfileManager = ProfileManager.getInstance(getActivity()); + mProfilesEnabled = mProfileManager.isProfilesEnabled(); mCursorLoader = getLoaderManager().initLoader(0, null, this); } @@ -326,6 +354,10 @@ public abstract class AlarmClockFragment extends DeskClockFragment implements } setTimePickerListener(); + + updateProfilesStatus(mProfileManager.isProfilesEnabled()); + getActivity().registerReceiver(mProfileReceiver, new IntentFilter( + ProfileManager.PROFILES_STATE_CHANGED_ACTION)); } private void hideUndoBar(boolean animate, MotionEvent event) { @@ -383,6 +415,8 @@ public abstract class AlarmClockFragment extends DeskClockFragment implements // home was pressed, just dismiss any existing toast bar when restarting // the app. hideUndoBar(false, null); + + getActivity().unregisterReceiver(mProfileReceiver); } private void showLabelDialog(final Alarm alarm) { @@ -462,6 +496,14 @@ public abstract class AlarmClockFragment extends DeskClockFragment implements startActivityForResult(intent, REQUEST_CODE_RINGTONE); } + private void launchProfilePicker(Alarm alarm) { + mSelectedAlarm = alarm; + final Intent intent = new Intent(ProfileManager.ACTION_PROFILE_PICKER); + intent.putExtra(ProfileManager.EXTRA_PROFILE_EXISTING_UUID, alarm.profile.toString()); + intent.putExtra(ProfileManager.EXTRA_PROFILE_SHOW_NONE, true); + startActivityForResult(intent, REQUEST_CODE_PROFILE); + } + private void saveRingtoneUri(Intent intent) { Uri uri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI); if (uri == null) { @@ -506,6 +548,41 @@ public abstract class AlarmClockFragment extends DeskClockFragment implements } } + private void saveProfile(Intent intent) { + final String uuid = intent.getStringExtra(ProfileManager.EXTRA_PROFILE_PICKED_UUID); + if (uuid != null) { + try { + mSelectedAlarm.profile = UUID.fromString(uuid); + } catch (IllegalArgumentException ex) { + mSelectedAlarm.profile = ProfileManager.NO_PROFILE; + } + } else { + mSelectedAlarm.profile = ProfileManager.NO_PROFILE; + } + asyncUpdateAlarm(mSelectedAlarm, false); + } + + private String getProfileName(Alarm alarm) { + if (!mProfilesEnabled || alarm.profile.equals(ProfileManager.NO_PROFILE)) { + return getString(R.string.profile_no_selected); + } + Profile profile = mProfileManager.getProfile(alarm.profile); + if (profile == null) { + return getString(R.string.profile_no_selected); + } + return profile.getName(); + } + + private void updateProfilesStatus(boolean newState) { + if (mProfilesEnabled != newState) { + mProfilesEnabled = newState; + // Need to refresh the data + if (mAdapter != null) { + mAdapter.notifyDataSetChanged(); + } + } + } + @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK) { @@ -513,6 +590,9 @@ public abstract class AlarmClockFragment extends DeskClockFragment implements case REQUEST_CODE_RINGTONE: saveRingtoneUri(data); break; + case REQUEST_CODE_PROFILE: + saveProfile(data); + break; default: LogUtils.w("Unhandled request code in onActivityResult: " + requestCode); } @@ -575,6 +655,7 @@ public abstract class AlarmClockFragment extends DeskClockFragment implements CheckBox vibrate; CheckBox increasingVolume; TextView ringtone; + TextView profile; View hairLine; View arrow; View collapseExpandArea; @@ -716,6 +797,7 @@ public abstract class AlarmClockFragment extends DeskClockFragment implements holder.vibrate = (CheckBox) view.findViewById(R.id.vibrate_onoff); holder.increasingVolume = (CheckBox) view.findViewById(R.id.increasing_volume_onoff); holder.ringtone = (TextView) view.findViewById(R.id.choose_ringtone); + holder.profile = (TextView) view.findViewById(R.id.choose_profile); view.setTag(holder); return holder; @@ -883,6 +965,8 @@ public abstract class AlarmClockFragment extends DeskClockFragment implements } } }); + + itemHolder.profile.setVisibility(mProfilesEnabled ? View.VISIBLE : View.GONE); } private void setAlarmItemBackgroundAndElevation(LinearLayout layout, boolean expanded) { @@ -1065,6 +1149,18 @@ public abstract class AlarmClockFragment extends DeskClockFragment implements asyncUpdateAlarm(alarm, false); } }); + + final String profile = getProfileName(alarm); + itemHolder.profile.setText(profile); + itemHolder.profile.setVisibility(mProfilesEnabled ? View.VISIBLE : View.GONE); + itemHolder.profile.setContentDescription( + mContext.getResources().getString(R.string.profile_description, profile)); + itemHolder.profile.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + launchProfilePicker(alarm); + } + }); } // Sets the alpha of the digital time display. This gives a visual effect diff --git a/src/com/android/deskclock/alarms/AlarmService.java b/src/com/android/deskclock/alarms/AlarmService.java index a75b7f652..50a1d8113 100644..100755 --- a/src/com/android/deskclock/alarms/AlarmService.java +++ b/src/com/android/deskclock/alarms/AlarmService.java @@ -32,6 +32,9 @@ import com.android.deskclock.R; import com.android.deskclock.events.Events; import com.android.deskclock.provider.AlarmInstance; +import cyanogenmod.app.Profile; +import cyanogenmod.app.ProfileManager; + /** * This service is in charge of starting/stopping the alarm. It will bring up and manage the * {@link AlarmActivity} as well as {@link AlarmKlaxon}. @@ -135,6 +138,40 @@ public class AlarmService extends Service { } }; + private void changeToProfile(final Context context, final AlarmInstance instance) { + final ProfileManager profileManager = ProfileManager.getInstance(this); + if (!profileManager.isProfilesEnabled()) { + LogUtils.v("Profiles are disabled"); + return; + } + + // The alarm is defined to change the active profile? + if (instance.mProfile.equals(ProfileManager.NO_PROFILE)) { + LogUtils.v("Alarm doesn't define a profile to change to"); + return; + } + + // Ensure that the profile still exists + Profile profile = profileManager.getProfile(instance.mProfile); + if (profile == null) { + LogUtils.e("The profile \"" + instance.mProfile + + "\" does not exist. Can't change to this profile"); + return; + } + + // Is the current profile different? + Profile activeProfile = profileManager.getActiveProfile(); + if (activeProfile == null || !profile.getUuid().equals(activeProfile.getUuid())) { + // Change to profile + LogUtils.i("Changing to profile \"" + profile.getName() + "\" (" + profile.getUuid() + + ") requested by alarm \"" + instance.mLabel + "\" (" + instance.mId + ")"); + profileManager.setActiveProfile(profile.getUuid()); + } else { + LogUtils.v("The profile \"" + profile.getName() + "\" (" + profile.getUuid() + + " is already active. No need to change to"); + } + } + private void startAlarm(AlarmInstance instance) { LogUtils.v("AlarmService.start with instance: " + instance.mId); if (mCurrentAlarm != null) { @@ -153,6 +190,7 @@ public class AlarmService extends Service { mInitialCallState = mTelephonyManager.getCallState(); mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); AlarmKlaxon.start(this, mCurrentAlarm); + changeToProfile(this, mCurrentAlarm); sendBroadcast(new Intent(ALARM_ALERT_ACTION)); } |