Add buttonless UI for watch type devices.
am: f1c53f21f8
Change-Id: Ifee78f6b3ab36bf6473c583f8edf05a32b5feec1
diff --git a/res/values-watch/config.xml b/res/values-watch/config.xml
new file mode 100644
index 0000000..0bc24fa
--- /dev/null
+++ b/res/values-watch/config.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2016 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.
+-->
+
+<!-- These resources are around just to allow their values to be customized
+ for different hardware and product builds. Do not translate.
+
+ NOTE: The naming convention is "config_camelCaseValue". -->
+<resources xmlns:android="http://schemas.android.com/apk/res/android">
+ <!-- True if the ringtone picker should show the ok/cancel buttons. If it is not shown, the
+ ringtone will be automatically selected when the picker is closed. -->
+ <bool name="config_showOkCancelButtons">false</bool>
+</resources>
diff --git a/res/values/config.xml b/res/values/config.xml
new file mode 100644
index 0000000..4e237a2
--- /dev/null
+++ b/res/values/config.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2016 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.
+-->
+
+<!-- These resources are around just to allow their values to be customized
+ for different hardware and product builds. Do not translate.
+
+ NOTE: The naming convention is "config_camelCaseValue". -->
+<resources xmlns:android="http://schemas.android.com/apk/res/android">
+ <!-- True if the ringtone picker should show the ok/cancel buttons. If it is not shown, the
+ ringtone will be automatically selected when the picker is closed. -->
+ <bool name="config_showOkCancelButtons">true</bool>
+</resources>
diff --git a/src/com/android/providers/media/RingtonePickerActivity.java b/src/com/android/providers/media/RingtonePickerActivity.java
index 86d55b3..03516ef 100644
--- a/src/com/android/providers/media/RingtonePickerActivity.java
+++ b/src/com/android/providers/media/RingtonePickerActivity.java
@@ -40,6 +40,7 @@
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 @@
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 @@
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 @@
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 @@
}
}
+ @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;