diff options
author | Michael Kwan <mkwan@google.com> | 2016-10-12 01:05:24 -0700 |
---|---|---|
committer | Michael Kwan <mkwan@google.com> | 2016-10-12 01:29:39 -0700 |
commit | f1c53f21f8da9abbd0c83fb941cfcbd7a7801671 (patch) | |
tree | 1834cfd78a6b836bd9c5208de6290295ad7d44c8 /src/com | |
parent | d6b2fc2280887076079ecba830cc95187100005a (diff) | |
download | MediaProvider-f1c53f21f8da9abbd0c83fb941cfcbd7a7801671.tar.gz |
Add buttonless UI for watch type devices.
Watch type devices defaults to using an interaction model that
avoids the use of buttons in AlertDialogs. A buttonless
mode was added and enabled for watch devices to conform
with the behaviour of other similar dialogs.
Test: manual using watch system settings
Bug: 30946435
Change-Id: Iaee39ac373bc5c1ec669cdaea025a56360725f28
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/android/providers/media/RingtonePickerActivity.java | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/src/com/android/providers/media/RingtonePickerActivity.java b/src/com/android/providers/media/RingtonePickerActivity.java index 86d55b392..03516ef3a 100644 --- a/src/com/android/providers/media/RingtonePickerActivity.java +++ b/src/com/android/providers/media/RingtonePickerActivity.java @@ -40,6 +40,7 @@ import android.widget.TextView; import com.android.internal.app.AlertActivity; import com.android.internal.app.AlertController; +import java.util.Objects; import java.util.regex.Pattern; /** @@ -112,6 +113,8 @@ public final class RingtonePickerActivity extends AlertActivity implements private int mAttributesFlags; + private boolean mShowOkCancelButtons; + /** * Keep the currently playing ringtone around when changing orientation, so that it * can be stopped later, after the activity is recreated. @@ -180,6 +183,8 @@ public final class RingtonePickerActivity extends AlertActivity implements RingtoneManager.EXTRA_RINGTONE_AUDIO_ATTRIBUTES_FLAGS, 0 /*defaultValue == no flags*/); + mShowOkCancelButtons = getResources().getBoolean(R.bool.config_showOkCancelButtons); + mCursor = new LocalizedCursor(mRingtoneManager.getCursor(), getResources(), COLUMN_LABEL); @@ -196,10 +201,12 @@ public final class RingtonePickerActivity extends AlertActivity implements p.mLabelColumn = COLUMN_LABEL; p.mIsSingleChoice = true; p.mOnItemSelectedListener = this; - p.mPositiveButtonText = getString(com.android.internal.R.string.ok); - p.mPositiveButtonListener = this; - p.mNegativeButtonText = getString(com.android.internal.R.string.cancel); - p.mPositiveButtonListener = this; + if (mShowOkCancelButtons) { + p.mPositiveButtonText = getString(com.android.internal.R.string.ok); + p.mPositiveButtonListener = this; + p.mNegativeButtonText = getString(com.android.internal.R.string.cancel); + p.mPositiveButtonListener = this; + } p.mOnPrepareListViewListener = this; p.mTitle = intent.getCharSequenceExtra(RingtoneManager.EXTRA_RINGTONE_TITLE); @@ -377,6 +384,34 @@ public final class RingtonePickerActivity extends AlertActivity implements } } + @Override + public void onBackPressed() { + if (!mShowOkCancelButtons) { + // Obtain the currently selected ringtone + Uri uri = null; + if (mClickedPos == mDefaultRingtonePos) { + // Set it to the default Uri that they originally gave us + uri = mUriForDefaultItem; + } else if (mClickedPos == mSilentPos) { + // A null Uri is for the 'Silent' item + uri = null; + } else { + uri = mRingtoneManager.getRingtoneUri(getRingtoneManagerPosition(mClickedPos)); + } + + // Return new URI if another ringtone was selected, as there's no ok/cancel button + if (Objects.equals(uri, mExistingUri)) { + setResult(RESULT_CANCELED); + } else { + Intent resultIntent = new Intent(); + resultIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI, uri); + setResult(RESULT_OK, resultIntent); + } + } + + super.onBackPressed(); + } + private void saveAnyPlayingRingtone() { if (mDefaultRingtone != null && mDefaultRingtone.isPlaying()) { sPlayingRingtone = mDefaultRingtone; |