summaryrefslogtreecommitdiffstats
path: root/samples/ApiDemos
diff options
context:
space:
mode:
authorMakoto Onuki <omakoto@google.com>2018-01-30 12:58:20 -0800
committerMakoto Onuki <omakoto@google.com>2018-01-30 13:20:06 -0800
commit10d6c41f9bdf940891762ae64caa4cb0c53e3d68 (patch)
tree49eda3ebcd2749653ef15857f7dcd6f63581afb8 /samples/ApiDemos
parente1c924c9e564dbda04f1f971e9904cc2e24a5d4f (diff)
downloadandroid_development-10d6c41f9bdf940891762ae64caa4cb0c53e3d68.tar.gz
android_development-10d6c41f9bdf940891762ae64caa4cb0c53e3d68.tar.bz2
android_development-10d6c41f9bdf940891762ae64caa4cb0c53e3d68.zip
Add while-idle alarm support to apidemos
Test: Manual test Bug: 72124522 Change-Id: I9d0c0ed4b6a045e4f8f566c4e9844290e850e2fc
Diffstat (limited to 'samples/ApiDemos')
-rw-r--r--samples/ApiDemos/res/layout/alarm_controller.xml6
-rw-r--r--samples/ApiDemos/res/values/strings.xml1
-rw-r--r--samples/ApiDemos/src/com/example/android/apis/app/AlarmController.java15
3 files changed, 21 insertions, 1 deletions
diff --git a/samples/ApiDemos/res/layout/alarm_controller.xml b/samples/ApiDemos/res/layout/alarm_controller.xml
index 0a9d00c1d..e3f18128e 100644
--- a/samples/ApiDemos/res/layout/alarm_controller.xml
+++ b/samples/ApiDemos/res/layout/alarm_controller.xml
@@ -33,6 +33,12 @@
<requestFocus />
</Button>
+ <Button android:id="@+id/one_shot_while_idle"
+ android:layout_width="wrap_content" android:layout_height="wrap_content"
+ android:text="@string/one_shot_while_idle_alarm">
+ <requestFocus />
+ </Button>
+
<Button android:id="@+id/start_repeating"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="@string/start_repeating_alarm" />
diff --git a/samples/ApiDemos/res/values/strings.xml b/samples/ApiDemos/res/values/strings.xml
index 2a7d639d9..288e4774d 100644
--- a/samples/ApiDemos/res/values/strings.xml
+++ b/samples/ApiDemos/res/values/strings.xml
@@ -348,6 +348,7 @@
<string name="alarm_controller">This demonstrates how to schedule and handle
one-shot and repeating alarms.</string>
<string name="one_shot_alarm">One Shot Alarm</string>
+ <string name="one_shot_while_idle_alarm">One Shot While-Idle Alarm</string>
<string name="start_repeating_alarm">Start Repeating Alarm</string>
<string name="stop_repeating_alarm">Stop Repeating Alarm</string>
<string name="one_shot_scheduled">One-shot alarm will go off in 30 seconds based on
diff --git a/samples/ApiDemos/src/com/example/android/apis/app/AlarmController.java b/samples/ApiDemos/src/com/example/android/apis/app/AlarmController.java
index 2ba573564..8f2a4cb9c 100644
--- a/samples/ApiDemos/src/com/example/android/apis/app/AlarmController.java
+++ b/samples/ApiDemos/src/com/example/android/apis/app/AlarmController.java
@@ -63,6 +63,8 @@ App/Service/Alarm Controller
</table>
*/
+// Start with:
+// adb shell am start com.example.android.apis/.app.AlarmController
public class AlarmController extends Activity {
Toast mToast;
@@ -75,6 +77,8 @@ public class AlarmController extends Activity {
// Watch for button clicks.
Button button = (Button)findViewById(R.id.one_shot);
button.setOnClickListener(mOneShotListener);
+ button = (Button)findViewById(R.id.one_shot_while_idle);
+ button.setOnClickListener(mOneShotListener);
button = (Button)findViewById(R.id.start_repeating);
button.setOnClickListener(mStartRepeatingListener);
button = (Button)findViewById(R.id.stop_repeating);
@@ -99,7 +103,16 @@ public class AlarmController extends Activity {
// Schedule the alarm!
AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
- am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), sender);
+
+ switch (v.getId()) {
+ case R.id.one_shot:
+ am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), sender);
+ break;
+ default:
+ am.setExactAndAllowWhileIdle(
+ AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), sender);
+ break;
+ }
// Tell the user about what we did.
if (mToast != null) {