upload android base code part8
|
@ -0,0 +1,36 @@
|
|||
#
|
||||
# Copyright (C) 2012 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.
|
||||
#
|
||||
|
||||
LOCAL_PATH:= $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
|
||||
LOCAL_AAPT_FLAGS += -c mdpi,hdpi,xhdpi
|
||||
|
||||
LOCAL_SRC_FILES := $(call all-java-files-under, src)
|
||||
|
||||
LOCAL_STATIC_ANDROID_LIBRARIES := \
|
||||
android-support-v4 \
|
||||
android-support-v7-preference
|
||||
|
||||
LOCAL_USE_AAPT2 := true
|
||||
|
||||
LOCAL_PACKAGE_NAME := NotificationShowcase
|
||||
include $(BUILD_PACKAGE)
|
||||
|
||||
include $(call all-makefiles-under,$(LOCAL_PATH))
|
|
@ -0,0 +1,42 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.android.example.notificationshowcase"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0">
|
||||
<uses-sdk android:minSdkVersion="7"
|
||||
android:targetSdkVersion="21" />
|
||||
|
||||
<uses-permission android:name="android.permission.READ_CONTACTS" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
|
||||
<application android:icon="@drawable/icon" android:label="@string/app_name">
|
||||
<activity android:name=".NotificationShowcaseActivity"
|
||||
android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".FullScreenActivity"
|
||||
android:label="@string/full_screen_name"
|
||||
android:showForAllUsers="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name="SettingsActivity"
|
||||
android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.NOTIFICATION_PREFERENCES" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<service android:name=".NotificationService"/>
|
||||
<service android:name=".UpdateService"/>
|
||||
<service android:name=".ProgressService"/>
|
||||
<service android:name=".PhoneService"/>
|
||||
<service android:name=".ToastService"/>
|
||||
</application>
|
||||
</manifest>
|
|
@ -0,0 +1,40 @@
|
|||
-optimizationpasses 5
|
||||
-dontusemixedcaseclassnames
|
||||
-dontskipnonpubliclibraryclasses
|
||||
-dontpreverify
|
||||
-verbose
|
||||
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
|
||||
|
||||
-keep public class * extends android.app.Activity
|
||||
-keep public class * extends android.app.Application
|
||||
-keep public class * extends android.app.Service
|
||||
-keep public class * extends android.content.BroadcastReceiver
|
||||
-keep public class * extends android.content.ContentProvider
|
||||
-keep public class * extends android.app.backup.BackupAgentHelper
|
||||
-keep public class * extends android.preference.Preference
|
||||
-keep public class com.android.vending.licensing.ILicensingService
|
||||
|
||||
-keepclasseswithmembernames class * {
|
||||
native <methods>;
|
||||
}
|
||||
|
||||
-keepclasseswithmembers class * {
|
||||
public <init>(android.content.Context, android.util.AttributeSet);
|
||||
}
|
||||
|
||||
-keepclasseswithmembers class * {
|
||||
public <init>(android.content.Context, android.util.AttributeSet, int);
|
||||
}
|
||||
|
||||
-keepclassmembers class * extends android.app.Activity {
|
||||
public void *(android.view.View);
|
||||
}
|
||||
|
||||
-keepclassmembers enum * {
|
||||
public static **[] values();
|
||||
public static ** valueOf(java.lang.String);
|
||||
}
|
||||
|
||||
-keep class * implements android.os.Parcelable {
|
||||
public static final android.os.Parcelable$Creator *;
|
||||
}
|
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 662 B |
After Width: | Height: | Size: 635 B |
After Width: | Height: | Size: 1 KiB |
After Width: | Height: | Size: 656 B |
After Width: | Height: | Size: 659 B |
After Width: | Height: | Size: 902 B |
After Width: | Height: | Size: 765 B |
After Width: | Height: | Size: 794 B |
After Width: | Height: | Size: 861 B |
After Width: | Height: | Size: 772 B |
After Width: | Height: | Size: 4.6 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 7.4 KiB |
After Width: | Height: | Size: 49 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 9 KiB |
After Width: | Height: | Size: 19 KiB |
After Width: | Height: | Size: 405 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 823 B |
After Width: | Height: | Size: 1 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 987 B |
After Width: | Height: | Size: 343 B |
After Width: | Height: | Size: 578 B |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 905 B |
After Width: | Height: | Size: 1 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1 KiB |
After Width: | Height: | Size: 211 B |
After Width: | Height: | Size: 3.5 KiB |
After Width: | Height: | Size: 2.7 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 485 B |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 2 KiB |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 1.8 KiB |
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
>
|
||||
|
||||
<ImageView android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:orientation="vertical"
|
||||
android:layout_weight="1"
|
||||
android:src="@drawable/page_hed"
|
||||
android:onClick="dismiss"
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom"
|
||||
android:text="@string/hang_up_button_label"
|
||||
android:onClick="dismiss"
|
||||
android:layout_weight="0"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
>
|
||||
<LinearLayout android:id="@+id/linearLayout1" android:orientation="vertical" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_width="match_parent" android:layout_margin="35dp">
|
||||
<Button android:id="@+id/button1" android:text="@string/post_button_label" android:layout_height="wrap_content" android:layout_width="match_parent" android:onClick="doPost"></Button>
|
||||
<Button android:id="@+id/button2" android:text="@string/remove_button_label" android:layout_height="wrap_content" android:layout_width="match_parent" android:onClick="doRemove"></Button>
|
||||
<Button android:id="@+id/button3" android:text="@string/prefs_button_label" android:layout_height="wrap_content" android:layout_width="match_parent" android:onClick="doPrefs"></Button>
|
||||
<Button android:id="@+id/disable" android:text="@string/no_button_label" android:layout_height="wrap_content" android:layout_width="match_parent" android:onClick="doDisable"></Button>
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
** Copyright 2012, 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.
|
||||
*/
|
||||
-->
|
||||
<resources>
|
||||
<!-- The width of the big icons in notifications. -->
|
||||
<dimen name="notification_large_icon_width">64dp</dimen>
|
||||
<!-- The width of the big icons in notifications. -->
|
||||
<dimen name="notification_large_icon_height">64dp</dimen>
|
||||
</resources>
|
|
@ -0,0 +1,131 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="hello">Hello World, NotificationShowcaseActivity!</string>
|
||||
<string name="app_name">NotificationShowcase</string>
|
||||
<string name="post_button_label">Post Notifications</string>
|
||||
<string name="remove_button_label">Remove Notifications</string>
|
||||
<string name="prefs_button_label">Preferences</string>
|
||||
<string name="disable_button_label">Disable Notifications</string>
|
||||
<string name="enable_button_label">Enable Notifications</string>
|
||||
<string name="no_button_label">No Idea Dog</string>
|
||||
<string name="answered">call answered</string>
|
||||
<string name="ignored">call ignored</string>
|
||||
<string name="full_screen_name">Full Screen Activity</string>
|
||||
<string name="sms_click">Clicked on bigText</string>
|
||||
<string name="sms_reply">reply</string>
|
||||
<string name="sms_sender">Mike Cleron</string>
|
||||
<string name="sms_message">Hey, looks like I\'m getting kicked out of this
|
||||
conference room, so stay in the hangout and I\'ll rejoin in about
|
||||
5-10 minutes. If you don\'t see me, assume I got pulled into another
|
||||
meeting. And now\u2026 I have to find my shoes.
|
||||
</string>
|
||||
|
||||
<string name="upload_click">Clicked on Upload</string>
|
||||
<string name="upload_title">File Upload</string>
|
||||
<string name="upload_text">foo.txt</string>
|
||||
|
||||
<string name="call_title">Incoming call</string>
|
||||
<string name="call_text">Matias Duarte</string>
|
||||
<string name="call_answer">Answer</string>
|
||||
<string name="call_ignore">Ignore</string>
|
||||
|
||||
<string name="timer_click">Clicked on Stopwatch</string>
|
||||
<string name="timer_title">Stopwatch PRO</string>
|
||||
<string name="timer_text">Counting up</string>
|
||||
|
||||
<string name="calendar_click">Clicked on calendar event</string>
|
||||
<string name="calendar_title">J Planning</string>
|
||||
<string name="calendar_text">The Botcave</string>
|
||||
<string name="calendar_10">+10 min</string>
|
||||
<string name="calendar_10_click">snoozed 10 min</string>
|
||||
<string name="calendar_60">+1 hour</string>
|
||||
<string name="calendar_60_click">snoozed 1 hr</string>
|
||||
|
||||
<string name="picture_click">Clicked on bigPicture</string>
|
||||
<string name="picture_add_click">added! (just kidding)</string>
|
||||
<string name="picture_title">Romain Guy</string>
|
||||
<string name="picture_text">I was lucky to find a Canon 5D Mk III at a
|
||||
local Bay Area store last week but I had not been able to try it in the
|
||||
field until tonight. After a few days of rain the sky finally cleared
|
||||
up. Rockaway Beach did not disappoint and I was finally able to see
|
||||
what my new camera feels like when shooting landscapes.
|
||||
</string>
|
||||
<string name="picture_add">Add to Gallery</string>
|
||||
<string name="picture_sub_text">talk rocks!</string>
|
||||
|
||||
<string name="email_click">Clicked on Email</string>
|
||||
<string name="email_title">24 new messages</string>
|
||||
<string name="email_text">You have mail!</string>
|
||||
<string name="email_sub_text">test.hugo2@gmail.com</string>
|
||||
<string name="email_c"><b>Charlie</b>: I see you!</string>
|
||||
<string name="email_a"><b>Alice</b>: hey there!</string>
|
||||
<string name="email_b"><b>Bob</b>: hi there!</string>
|
||||
|
||||
<string name="social_click">Clicked on Social</string>
|
||||
<string name="social_title">Social</string>
|
||||
<string name="social_text">New mentions</string>
|
||||
|
||||
<string name="pref_title_enable">Enable</string>
|
||||
|
||||
<string name="pref_title_global">Global</string>
|
||||
<string name="pref_title_global_fade">Fade Away</string>
|
||||
<string name="pref_summary_global_fade">Automatically remove notifications after a short time</string>
|
||||
|
||||
<string name="pref_title_sms">SMS Example</string>
|
||||
<string name="pref_summary_sms_enable">Enable the SMS example</string>
|
||||
<string name="pref_title_sms_sound">Ringtone</string>
|
||||
<string name="pref_title_sms_noisy">Noise</string>
|
||||
<string name="pref_summary_sms_noisy">Allow the SMS example to be noisy</string>
|
||||
<string name="pref_title_sms_buzzy">Vibration</string>
|
||||
<string name="pref_summary_sms_buzzy">Allow the SMS example to vibrate</string>
|
||||
<string name="pref_title_sms_priority">SMS Priority</string>
|
||||
<string name="pref_title_sms_once">Alert Only Once</string>
|
||||
<string name="pref_summary_sms_once">Updates should not interrupt the user.</string>
|
||||
<string name="pref_title_sms_person">SMS Person</string>
|
||||
<string name="pref_summary_sms_person">Add a person to the SMS notification</string>
|
||||
|
||||
<string name="pref_title_phone">Phone Example</string>
|
||||
<string name="pref_summary_phone_enable">Enable the phone notification</string>
|
||||
<string name="pref_title_phone_noisy">Noise</string>
|
||||
<string name="pref_summary_phone_noisy">Allow the phone example to be noisy</string>
|
||||
<string name="pref_title_phone_fullscreen">Fullscreen</string>
|
||||
<string name="pref_summary_phone_fullscreen">Add a fullscreen intent</string>
|
||||
<string name="pref_title_phone_person">Phone Person</string>
|
||||
<string name="pref_summary_phone_person">Add a person to the phone notification</string>
|
||||
|
||||
<string name="pref_title_upload">Upload Example</string>
|
||||
<string name="pref_summary_upload_enable">Enable the upload notification</string>
|
||||
|
||||
<string name="pref_title_timer">Timer Example</string>
|
||||
<string name="pref_summary_timer_enable">Enable the timer notification</string>
|
||||
|
||||
<string name="pref_title_calendar">Calendar Example</string>
|
||||
<string name="pref_summary_calendar_enable">Enable the calendar notification</string>
|
||||
|
||||
<string name="pref_title_picture">Picture Example</string>
|
||||
<string name="pref_summary_picture_enable">Enable the big picture notification</string>
|
||||
|
||||
<string name="pref_title_inbox">Email Example</string>
|
||||
<string name="pref_summary_inbox_enable">Enable the email notification</string>
|
||||
|
||||
<string name="pref_title_social">Social Example</string>
|
||||
<string name="pref_summary_social_enable">Enable the social notification</string>
|
||||
|
||||
<string-array name ="priority_names">
|
||||
<item>maximum</item>
|
||||
<item>high</item>
|
||||
<item>default</item>
|
||||
<item>low</item>
|
||||
<item>minimum</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="priority_values">
|
||||
<item>2</item>
|
||||
<item>1</item>
|
||||
<item>0</item>
|
||||
<item>-1</item>
|
||||
<item>-2</item>
|
||||
</string-array>
|
||||
|
||||
<string name="hang_up_button_label">hang up</string>
|
||||
</resources>
|
|
@ -0,0 +1,170 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright (C) 2015 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
|
||||
-->
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<PreferenceCategory
|
||||
android:title="@string/pref_title_global"
|
||||
android:key="pref_key_global_settings">
|
||||
<CheckBoxPreference
|
||||
android:persistent="true"
|
||||
android:key="pref_key_global_fade"
|
||||
android:summary="@string/pref_summary_global_fade"
|
||||
android:title="@string/pref_title_global_fade"
|
||||
android:defaultValue="true" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory
|
||||
android:title="@string/pref_title_sms"
|
||||
android:key="pref_key_sms_settings">
|
||||
<CheckBoxPreference
|
||||
android:persistent="true"
|
||||
android:key="pref_key_sms_enable"
|
||||
android:summary="@string/pref_summary_sms_enable"
|
||||
android:title="@string/pref_title_enable"
|
||||
android:defaultValue="true" />
|
||||
<CheckBoxPreference
|
||||
android:persistent="true"
|
||||
android:key="pref_key_sms_noisy"
|
||||
android:dependency="pref_key_sms_enable"
|
||||
android:summary="@string/pref_summary_sms_noisy"
|
||||
android:title="@string/pref_title_sms_noisy"
|
||||
android:defaultValue="true" />
|
||||
<RingtonePreference
|
||||
android:persistent="true"
|
||||
android:key="pref_key_sms_sound"
|
||||
android:dependency="pref_key_sms_enable"
|
||||
android:ringtoneType="notification"
|
||||
android:title="@string/pref_title_sms_sound" />
|
||||
<CheckBoxPreference
|
||||
android:persistent="true"
|
||||
android:key="pref_key_sms_buzzy"
|
||||
android:dependency="pref_key_sms_enable"
|
||||
android:summary="@string/pref_summary_sms_buzzy"
|
||||
android:title="@string/pref_title_sms_buzzy"
|
||||
android:defaultValue="true" />
|
||||
<ListPreference android:key="pref_key_sms_priority"
|
||||
android:persistent="true"
|
||||
android:dependency="pref_key_sms_enable"
|
||||
android:title="@string/pref_title_sms_priority"
|
||||
android:entries="@array/priority_names"
|
||||
android:entryValues="@array/priority_values"
|
||||
android:defaultValue="0"/>
|
||||
<CheckBoxPreference
|
||||
android:persistent="true"
|
||||
android:key="pref_key_sms_once"
|
||||
android:dependency="pref_key_sms_enable"
|
||||
android:summary="@string/pref_summary_sms_once"
|
||||
android:title="@string/pref_title_sms_once"
|
||||
android:defaultValue="true" />
|
||||
<CheckBoxPreference
|
||||
android:persistent="true"
|
||||
android:dependency="pref_key_sms_enable"
|
||||
android:key="pref_key_sms_person"
|
||||
android:summary="@string/pref_summary_sms_person"
|
||||
android:title="@string/pref_title_sms_person"
|
||||
android:defaultValue="true" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory
|
||||
android:title="@string/pref_title_phone"
|
||||
android:key="pref_key_phone_settings">
|
||||
<CheckBoxPreference
|
||||
android:persistent="true"
|
||||
android:key="pref_key_phone_enable"
|
||||
android:summary="@string/pref_summary_phone_enable"
|
||||
android:title="@string/pref_title_enable"
|
||||
android:defaultValue="true" />
|
||||
<CheckBoxPreference
|
||||
android:persistent="true"
|
||||
android:key="pref_key_phone_noisy"
|
||||
android:dependency="pref_key_phone_enable"
|
||||
android:summary="@string/pref_summary_phone_noisy"
|
||||
android:title="@string/pref_title_phone_noisy"
|
||||
android:defaultValue="true" />
|
||||
<CheckBoxPreference
|
||||
android:persistent="true"
|
||||
android:key="pref_key_phone_fullscreen"
|
||||
android:dependency="pref_key_phone_enable"
|
||||
android:summary="@string/pref_summary_phone_fullscreen"
|
||||
android:title="@string/pref_title_phone_fullscreen"
|
||||
android:defaultValue="true" />
|
||||
<CheckBoxPreference
|
||||
android:persistent="true"
|
||||
android:key="pref_key_phone_person"
|
||||
android:dependency="pref_key_phone_enable"
|
||||
android:summary="@string/pref_summary_phone_person"
|
||||
android:title="@string/pref_title_phone_person"
|
||||
android:defaultValue="true" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory
|
||||
android:title="@string/pref_title_upload"
|
||||
android:key="pref_key_upload_settings">
|
||||
<CheckBoxPreference
|
||||
android:persistent="true"
|
||||
android:key="pref_key_upload_enable"
|
||||
android:summary="@string/pref_summary_upload_enable"
|
||||
android:title="@string/pref_title_enable"
|
||||
android:defaultValue="true" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory
|
||||
android:title="@string/pref_title_timer"
|
||||
android:key="pref_key_timer_settings">
|
||||
<CheckBoxPreference
|
||||
android:persistent="true"
|
||||
android:key="pref_key_timer_enable"
|
||||
android:summary="@string/pref_summary_timer_enable"
|
||||
android:title="@string/pref_title_enable"
|
||||
android:defaultValue="true" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory
|
||||
android:title="@string/pref_title_calendar"
|
||||
android:key="pref_key_calendar_settings">
|
||||
<CheckBoxPreference
|
||||
android:persistent="true"
|
||||
android:key="pref_key_calendar_enable"
|
||||
android:summary="@string/pref_summary_calendar_enable"
|
||||
android:title="@string/pref_title_enable"
|
||||
android:defaultValue="true" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory
|
||||
android:title="@string/pref_title_picture"
|
||||
android:key="pref_key_picture_settings">
|
||||
<CheckBoxPreference
|
||||
android:persistent="true"
|
||||
android:key="pref_key_picture_enable"
|
||||
android:summary="@string/pref_summary_picture_enable"
|
||||
android:title="@string/pref_title_enable"
|
||||
android:defaultValue="true" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory
|
||||
android:title="@string/pref_title_inbox"
|
||||
android:key="pref_key_inbox_settings">
|
||||
<CheckBoxPreference
|
||||
android:persistent="true"
|
||||
android:key="pref_key_inbox_enable"
|
||||
android:summary="@string/pref_summary_inbox_enable"
|
||||
android:title="@string/pref_title_enable"
|
||||
android:defaultValue="true" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory
|
||||
android:title="@string/pref_title_social"
|
||||
android:key="pref_key_social_settings">
|
||||
<CheckBoxPreference
|
||||
android:persistent="true"
|
||||
android:key="pref_key_social_enable"
|
||||
android:summary="@string/pref_summary_social_enable"
|
||||
android:title="@string/pref_title_enable"
|
||||
android:defaultValue="true" />
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
BIN
android/packages/experimental/NotificationShowcase/showcase.png
Normal file
After Width: | Height: | Size: 7.6 KiB |
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* Copyright (C) 2013 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.
|
||||
*/
|
||||
|
||||
package com.android.example.notificationshowcase;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.os.PowerManager;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
|
||||
public class FullScreenActivity extends Activity {
|
||||
private static final String TAG = "NotificationShowcase";
|
||||
|
||||
public static final String EXTRA_ID = "id";
|
||||
private Handler mHandler = new Handler(Looper.getMainLooper());
|
||||
private PowerManager.WakeLock mWakeLock;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.full_screen);
|
||||
|
||||
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
||||
mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Incoming Call");
|
||||
mWakeLock.acquire(15 * 1000);
|
||||
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON |
|
||||
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
|
||||
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
|
||||
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
|
||||
|
||||
final Intent intent = getIntent();
|
||||
if (intent != null && intent.hasExtra(EXTRA_ID)) {
|
||||
final int id = intent.getIntExtra(EXTRA_ID, -1);
|
||||
if (id >= 0) {
|
||||
NotificationManager noMa =
|
||||
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
noMa.cancel(NotificationService.NOTIFICATION_ID + id);
|
||||
}
|
||||
}
|
||||
|
||||
mHandler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
dismiss(null);
|
||||
}
|
||||
}, 30 * 1000);
|
||||
}
|
||||
|
||||
public void dismiss(View v) {
|
||||
if (mWakeLock.isHeld()) {
|
||||
mWakeLock.release();
|
||||
}
|
||||
finish();
|
||||
}
|
||||
|
||||
public static PendingIntent getPendingIntent(Context context, int id) {
|
||||
Intent fullScreenIntent = new Intent(context, FullScreenActivity.class);
|
||||
fullScreenIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
|
||||
fullScreenIntent.putExtra(EXTRA_ID, id);
|
||||
PendingIntent pi = PendingIntent.getActivity(
|
||||
context, 22, fullScreenIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
return pi;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,337 @@
|
|||
/*
|
||||
* Copyright (C) 2013 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.
|
||||
*/
|
||||
|
||||
package com.android.example.notificationshowcase;
|
||||
|
||||
import android.app.AlarmManager;
|
||||
import android.app.IntentService;
|
||||
import android.app.Notification;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.ComponentName;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.SystemClock;
|
||||
import android.provider.ContactsContract;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.app.NotificationManagerCompat;
|
||||
import android.support.v7.preference.PreferenceManager;
|
||||
import android.text.SpannableString;
|
||||
import android.text.TextUtils;
|
||||
import android.text.style.StyleSpan;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.example.notificationshowcase.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class NotificationService extends IntentService {
|
||||
|
||||
private static final String TAG = "NotificationService";
|
||||
|
||||
public static final String ACTION_CREATE = "create";
|
||||
public static final String ACTION_DESTROY = "destroy";
|
||||
public static final int NOTIFICATION_ID = 31338;
|
||||
private static final long FADE_TIME_MILLIS = 1000 * 60 * 5;
|
||||
|
||||
public NotificationService() {
|
||||
super(TAG);
|
||||
}
|
||||
|
||||
public NotificationService(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
private static PendingIntent makeCancelAllIntent(Context context) {
|
||||
final Intent intent = new Intent(ACTION_DESTROY);
|
||||
intent.setComponent(new ComponentName(context, NotificationService.class));
|
||||
return PendingIntent.getService(
|
||||
context, 0, intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
}
|
||||
|
||||
private static Bitmap getBitmap(Context context, int resId) {
|
||||
int largeIconWidth = (int) context.getResources()
|
||||
.getDimension(R.dimen.notification_large_icon_width);
|
||||
int largeIconHeight = (int) context.getResources()
|
||||
.getDimension(R.dimen.notification_large_icon_height);
|
||||
Drawable d = context.getResources().getDrawable(resId);
|
||||
Bitmap b = Bitmap.createBitmap(largeIconWidth, largeIconHeight, Bitmap.Config.ARGB_8888);
|
||||
Canvas c = new Canvas(b);
|
||||
d.setBounds(0, 0, largeIconWidth, largeIconHeight);
|
||||
d.draw(c);
|
||||
return b;
|
||||
}
|
||||
|
||||
private static PendingIntent makeEmailIntent(Context context, String who) {
|
||||
final Intent intent = new Intent(android.content.Intent.ACTION_SENDTO,
|
||||
Uri.parse("mailto:" + who));
|
||||
return PendingIntent.getActivity(
|
||||
context, 0, intent,
|
||||
PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
}
|
||||
|
||||
public static Notification makeSmsNotification(Context context, int update, int id, long when) {
|
||||
final SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
String sender = context.getString(R.string.sms_sender);
|
||||
|
||||
String personUri = null;
|
||||
if (sharedPref.getBoolean(SettingsActivity.KEY_SMS_PERSON, false)) {
|
||||
Cursor c = null;
|
||||
try {
|
||||
String[] projection = new String[] { ContactsContract.Contacts._ID,
|
||||
ContactsContract.Contacts.LOOKUP_KEY };
|
||||
String selections = ContactsContract.Contacts.DISPLAY_NAME + " = ?";
|
||||
String[] selectionArgs = { sender };
|
||||
final ContentResolver contentResolver = context.getContentResolver();
|
||||
c = contentResolver.query(ContactsContract.Contacts.CONTENT_URI,
|
||||
projection, selections, selectionArgs, null);
|
||||
if (c != null && c.getCount() > 0) {
|
||||
c.moveToFirst();
|
||||
int lookupIdx = c.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY);
|
||||
int idIdx = c.getColumnIndex(ContactsContract.Contacts._ID);
|
||||
String lookupKey = c.getString(lookupIdx);
|
||||
long contactId = c.getLong(idIdx);
|
||||
Uri lookupUri = ContactsContract.Contacts.getLookupUri(contactId, lookupKey);
|
||||
personUri = lookupUri.toString();
|
||||
}
|
||||
} finally {
|
||||
if (c != null) {
|
||||
c.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (update > 2) {
|
||||
when = System.currentTimeMillis();
|
||||
}
|
||||
final String priorityName = sharedPref.getString(SettingsActivity.KEY_SMS_PRIORITY, "0");
|
||||
final int priority = Integer.valueOf(priorityName);
|
||||
NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
|
||||
bigTextStyle.bigText(context.getString(R.string.sms_message));
|
||||
PendingIntent ci = ToastService.getPendingIntent(context, R.string.sms_click);
|
||||
PendingIntent ai = UpdateService.getPendingIntent(context, update + 1, id, when);
|
||||
NotificationCompat.Builder bigText = new NotificationCompat.Builder(context)
|
||||
.setContentTitle(sender)
|
||||
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
|
||||
.setContentIntent(ci)
|
||||
.setContentText(context.getString(R.string.sms_message))
|
||||
.setWhen(when)
|
||||
.setLargeIcon(getBitmap(context, R.drawable.bucket))
|
||||
.setPriority(priority)
|
||||
.addAction(R.drawable.ic_media_next, context.getString(R.string.sms_reply), ai)
|
||||
.setSmallIcon(R.drawable.stat_notify_talk_text)
|
||||
.setStyle(bigTextStyle)
|
||||
.setOnlyAlertOnce(sharedPref.getBoolean(SettingsActivity.KEY_SMS_ONCE, true));
|
||||
|
||||
if (TextUtils.isEmpty(personUri)) {
|
||||
Log.w(TAG, "failed to find contact for Mike Cleron");
|
||||
} else {
|
||||
bigText.addPerson(personUri);
|
||||
Log.w(TAG, "Mike Cleron is " + personUri);
|
||||
}
|
||||
|
||||
int defaults = 0;
|
||||
if(sharedPref.getBoolean(SettingsActivity.KEY_SMS_NOISY, true)) {
|
||||
String uri = sharedPref.getString(SettingsActivity.KEY_SMS_SOUND, null);
|
||||
if(uri == null) {
|
||||
defaults |= Notification.DEFAULT_SOUND;
|
||||
} else {
|
||||
bigText.setSound(Uri.parse(uri));
|
||||
}
|
||||
}
|
||||
if(sharedPref.getBoolean(SettingsActivity.KEY_SMS_BUZZY, false)) {
|
||||
defaults |= Notification.DEFAULT_VIBRATE;
|
||||
}
|
||||
bigText.setDefaults(defaults);
|
||||
|
||||
return bigText.build();
|
||||
}
|
||||
|
||||
public static Notification makeUploadNotification(Context context, int progress, long when) {
|
||||
PendingIntent pi = ToastService.getPendingIntent(context, R.string.upload_click);
|
||||
NotificationCompat.Builder uploadNotification = new NotificationCompat.Builder(context)
|
||||
.setContentTitle(context.getString(R.string.upload_title))
|
||||
.setContentText(context.getString(R.string.upload_text))
|
||||
.setCategory(NotificationCompat.CATEGORY_PROGRESS)
|
||||
.setPriority(NotificationCompat.PRIORITY_MIN)
|
||||
.setContentIntent(pi)
|
||||
.setWhen(when)
|
||||
.setSmallIcon(R.drawable.ic_menu_upload)
|
||||
.setProgress(100, Math.min(progress, 100), false);
|
||||
return uploadNotification.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onHandleIntent(Intent intent) {
|
||||
NotificationManagerCompat noMa = NotificationManagerCompat.from(this);
|
||||
if (ACTION_DESTROY.equals(intent.getAction())) {
|
||||
noMa.cancelAll();
|
||||
return;
|
||||
}
|
||||
|
||||
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
ArrayList<Notification> mNotifications = new ArrayList<Notification>();
|
||||
|
||||
if(sharedPref.getBoolean(SettingsActivity.KEY_SMS_ENABLE, true)) {
|
||||
final int id = mNotifications.size();
|
||||
mNotifications.add(makeSmsNotification(this, 2, id, System.currentTimeMillis()));
|
||||
}
|
||||
|
||||
if(sharedPref.getBoolean(SettingsActivity.KEY_UPLOAD_ENABLE, false)) {
|
||||
final int id = mNotifications.size();
|
||||
final long uploadWhen = System.currentTimeMillis();
|
||||
mNotifications.add(makeUploadNotification(this, 10, uploadWhen));
|
||||
ProgressService.startProgressUpdater(this, id, uploadWhen, 0);
|
||||
}
|
||||
|
||||
if(sharedPref.getBoolean(SettingsActivity.KEY_PHONE_ENABLE, false)) {
|
||||
final int id = mNotifications.size();
|
||||
final PendingIntent fullscreen = FullScreenActivity.getPendingIntent(this, id);
|
||||
PendingIntent ans = PhoneService.getPendingIntent(this, id,
|
||||
PhoneService.ACTION_ANSWER);
|
||||
PendingIntent ign =
|
||||
PhoneService.getPendingIntent(this, id, PhoneService.ACTION_IGNORE);
|
||||
NotificationCompat.Builder phoneCall = new NotificationCompat.Builder(this)
|
||||
.setContentTitle(getString(R.string.call_title))
|
||||
.setContentText(getString(R.string.call_text))
|
||||
.setLargeIcon(getBitmap(this, R.drawable.matias_hed))
|
||||
.setSmallIcon(R.drawable.stat_sys_phone_call)
|
||||
.setPriority(NotificationCompat.PRIORITY_MAX)
|
||||
.setCategory(NotificationCompat.CATEGORY_CALL)
|
||||
.setContentIntent(fullscreen)
|
||||
.addAction(R.drawable.ic_dial_action_call, getString(R.string.call_answer), ans)
|
||||
.addAction(R.drawable.ic_end_call, getString(R.string.call_ignore), ign)
|
||||
.setOngoing(true);
|
||||
|
||||
if(sharedPref.getBoolean(SettingsActivity.KEY_PHONE_FULLSCREEN, false)) {
|
||||
phoneCall.setFullScreenIntent(fullscreen, true);
|
||||
}
|
||||
|
||||
if(sharedPref.getBoolean(SettingsActivity.KEY_PHONE_NOISY, false)) {
|
||||
phoneCall.setDefaults(Notification.DEFAULT_SOUND);
|
||||
}
|
||||
|
||||
if (sharedPref.getBoolean(SettingsActivity.KEY_PHONE_PERSON, false)) {
|
||||
phoneCall.addPerson(Uri.fromParts("tel",
|
||||
"1 (617) 555-1212", null)
|
||||
.toString());
|
||||
}
|
||||
mNotifications.add(phoneCall.build());
|
||||
}
|
||||
|
||||
if(sharedPref.getBoolean(SettingsActivity.KEY_TIMER_ENABLE, false)) {
|
||||
PendingIntent pi = ToastService.getPendingIntent(this, R.string.timer_click);
|
||||
mNotifications.add(new NotificationCompat.Builder(this)
|
||||
.setContentTitle(getString(R.string.timer_title))
|
||||
.setContentText(getString(R.string.timer_text))
|
||||
.setCategory(NotificationCompat.CATEGORY_PROGRESS)
|
||||
.setContentIntent(pi)
|
||||
.setSmallIcon(R.drawable.stat_notify_alarm)
|
||||
.setUsesChronometer(true)
|
||||
.build());
|
||||
}
|
||||
|
||||
if(sharedPref.getBoolean(SettingsActivity.KEY_CALENDAR_ENABLE, false)) {
|
||||
mNotifications.add(new NotificationCompat.Builder(this)
|
||||
.setContentTitle(getString(R.string.calendar_title))
|
||||
.setContentText(getString(R.string.calendar_text))
|
||||
.setCategory(NotificationCompat.CATEGORY_EVENT)
|
||||
.setWhen(System.currentTimeMillis())
|
||||
.setSmallIcon(R.drawable.stat_notify_calendar)
|
||||
.setContentIntent(ToastService.getPendingIntent(this, R.string.calendar_click))
|
||||
.setContentInfo("7PM")
|
||||
.addAction(R.drawable.stat_notify_snooze, getString(R.string.calendar_10),
|
||||
ToastService.getPendingIntent(this, R.string.calendar_10_click))
|
||||
.addAction(R.drawable.stat_notify_snooze_longer, getString(R.string.calendar_60),
|
||||
ToastService.getPendingIntent(this, R.string.calendar_60_click))
|
||||
.addAction(R.drawable.stat_notify_email, "Email",
|
||||
makeEmailIntent(this,
|
||||
"gabec@example.com,mcleron@example.com,dsandler@example.com"))
|
||||
.build());
|
||||
}
|
||||
|
||||
if(sharedPref.getBoolean(SettingsActivity.KEY_PICTURE_ENABLE, false)) {
|
||||
BitmapDrawable d =
|
||||
(BitmapDrawable) getResources().getDrawable(R.drawable.romainguy_rockaway);
|
||||
PendingIntent ci = ToastService.getPendingIntent(this, R.string.picture_click);
|
||||
PendingIntent ai = ToastService.getPendingIntent(this, R.string.picture_add_click);
|
||||
mNotifications.add(new NotificationCompat.BigPictureStyle(
|
||||
new NotificationCompat.Builder(this)
|
||||
.setCategory(NotificationCompat.CATEGORY_SOCIAL)
|
||||
.setContentTitle(getString(R.string.picture_title))
|
||||
.setContentText(getString(R.string.picture_text))
|
||||
.setSmallIcon(R.drawable.ic_stat_gplus)
|
||||
.setContentIntent(ci)
|
||||
.setLargeIcon(getBitmap(this, R.drawable.romainguy_hed))
|
||||
.addAction(R.drawable.add, getString(R.string.picture_add), ai)
|
||||
.setSubText(getString(R.string.picture_sub_text)))
|
||||
.bigPicture(d.getBitmap())
|
||||
.build());
|
||||
}
|
||||
|
||||
if(sharedPref.getBoolean(SettingsActivity.KEY_INBOX_ENABLE, false)) {
|
||||
PendingIntent pi = ToastService.getPendingIntent(this, R.string.email_click);
|
||||
mNotifications.add(new NotificationCompat.InboxStyle(
|
||||
new NotificationCompat.Builder(this)
|
||||
.setContentTitle(getString(R.string.email_title))
|
||||
.setContentText(getString(R.string.email_text))
|
||||
.setSubText(getString(R.string.email_sub_text))
|
||||
.setCategory(NotificationCompat.CATEGORY_EMAIL)
|
||||
.setContentIntent(pi)
|
||||
.setSmallIcon(R.drawable.stat_notify_email))
|
||||
.setSummaryText("+21 more")
|
||||
.addLine(getString(R.string.email_a))
|
||||
.addLine(getString(R.string.email_b))
|
||||
.addLine(getString(R.string.email_c))
|
||||
.build());
|
||||
}
|
||||
|
||||
if(sharedPref.getBoolean(SettingsActivity.KEY_SOCIAL_ENABLE, false)) {
|
||||
PendingIntent pi = ToastService.getPendingIntent(this, R.string.social_click);
|
||||
mNotifications.add(new NotificationCompat.Builder(this)
|
||||
.setContentTitle(getString(R.string.social_title))
|
||||
.setContentText(getString(R.string.social_text))
|
||||
.setCategory(NotificationCompat.CATEGORY_SOCIAL)
|
||||
.setContentIntent(pi)
|
||||
.setSmallIcon(R.drawable.twitter_icon)
|
||||
.setNumber(15)
|
||||
.setPriority(NotificationCompat.PRIORITY_LOW)
|
||||
.build());
|
||||
}
|
||||
|
||||
for (int i=0; i<mNotifications.size(); i++) {
|
||||
noMa.notify(NOTIFICATION_ID + i, mNotifications.get(i));
|
||||
}
|
||||
|
||||
// always cancel any previous alarm
|
||||
PendingIntent pendingCancel = makeCancelAllIntent(this);
|
||||
AlarmManager alMa = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
||||
alMa.cancel(pendingCancel);
|
||||
if(sharedPref.getBoolean(SettingsActivity.KEY_GLOBAL_FADE, false)) {
|
||||
long t = SystemClock.elapsedRealtime() + FADE_TIME_MILLIS;
|
||||
alMa.set(AlarmManager.ELAPSED_REALTIME, t, pendingCancel);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
// dummy notifications for demos
|
||||
// for anandx@google.com by dsandler@google.com
|
||||
|
||||
package com.android.example.notificationshowcase;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.NotificationManagerCompat;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
|
||||
public class NotificationShowcaseActivity extends Activity {
|
||||
private static final String TAG = "NotificationShowcase";
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.main);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
Button disableBtn = (Button) findViewById(R.id.disable);
|
||||
NotificationManagerCompat noMa = NotificationManagerCompat.from(this);
|
||||
if(noMa.areNotificationsEnabled()) {
|
||||
disableBtn.setText(R.string.disable_button_label);
|
||||
} else {
|
||||
disableBtn.setText(R.string.enable_button_label);
|
||||
}
|
||||
}
|
||||
|
||||
public void doPost(View v) {
|
||||
Intent intent = new Intent(NotificationService.ACTION_CREATE);
|
||||
intent.setComponent(new ComponentName(this, NotificationService.class));
|
||||
startService(intent);
|
||||
}
|
||||
|
||||
public void doRemove(View v) {
|
||||
Intent intent = new Intent(NotificationService.ACTION_DESTROY);
|
||||
intent.setComponent(new ComponentName(this, NotificationService.class));
|
||||
startService(intent);
|
||||
}
|
||||
|
||||
public void doPrefs(View v) {
|
||||
Intent intent = new Intent();
|
||||
intent.setComponent(new ComponentName(this, SettingsActivity.class));
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
public void doDisable(View v) {
|
||||
startActivity(new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
|
||||
Uri.parse("package:com.android.example.notificationshowcase")));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* Copyright (C) 2013 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.
|
||||
*/
|
||||
|
||||
package com.android.example.notificationshowcase;
|
||||
|
||||
import android.app.IntentService;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class PhoneService extends IntentService {
|
||||
|
||||
private static final String TAG = "PhoneService";
|
||||
|
||||
public static final String ACTION_ANSWER = "answer";
|
||||
public static final String ACTION_IGNORE = "ignore";
|
||||
|
||||
public static final String EXTRA_ID = "id";
|
||||
|
||||
private Handler handler;
|
||||
|
||||
public PhoneService() {
|
||||
super(TAG);
|
||||
}
|
||||
public PhoneService(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
handler = new Handler();
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onHandleIntent(Intent intent) {
|
||||
Log.v(TAG, "clicked a thing! intent=" + intent.toString());
|
||||
int res = ACTION_ANSWER.equals(intent.getAction()) ? R.string.answered : R.string.ignored;
|
||||
final String text = getString(res);
|
||||
final int id = intent.getIntExtra(EXTRA_ID, -1);
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(PhoneService.this, text, Toast.LENGTH_LONG).show();
|
||||
if (id >= 0) {
|
||||
NotificationManager noMa =
|
||||
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
noMa.cancel(NotificationService.NOTIFICATION_ID + id);
|
||||
}
|
||||
Log.v(TAG, "phone toast " + text);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static PendingIntent getPendingIntent(Context context, int id, String action) {
|
||||
Intent phoneIntent = new Intent(context, PhoneService.class);
|
||||
phoneIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
phoneIntent.setAction(action);
|
||||
phoneIntent.putExtra(EXTRA_ID, id);
|
||||
PendingIntent pi = PendingIntent.getService(
|
||||
context, 58, phoneIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
return pi;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* Copyright (C) 2013 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.
|
||||
*/
|
||||
|
||||
package com.android.example.notificationshowcase;
|
||||
|
||||
import android.app.IntentService;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.Service;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
|
||||
public class ProgressService extends IntentService {
|
||||
|
||||
private static final String TAG = "ProgressService";
|
||||
|
||||
private static final String ACTION_PROGRESS = "progress";
|
||||
|
||||
private Handler handler;
|
||||
|
||||
public ProgressService() {
|
||||
super(TAG);
|
||||
}
|
||||
public ProgressService(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
class UpdateRunnable implements Runnable {
|
||||
|
||||
private final int mId;
|
||||
private final long mWhen;
|
||||
private int mProgress;
|
||||
|
||||
UpdateRunnable(int id, long when, int progress) {
|
||||
mId = id;
|
||||
mWhen = when;
|
||||
mProgress = progress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() { NotificationManager noMa = (NotificationManager)
|
||||
getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
Log.v(TAG, "id: " + mId + " when: " + mWhen + " progress: " + mProgress);
|
||||
noMa.notify(NotificationService.NOTIFICATION_ID + mId,
|
||||
NotificationService.makeUploadNotification(
|
||||
ProgressService.this, mProgress, mWhen));
|
||||
mProgress += 2;
|
||||
if (mProgress <= 100) {
|
||||
handler.postDelayed(this, 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
handler = new Handler();
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onHandleIntent(Intent intent) {
|
||||
final int id = intent.getIntExtra("id", 0);
|
||||
final long when = intent.getLongExtra("when", 0L);
|
||||
int progress = intent.getIntExtra("progress", 0);
|
||||
handler.postDelayed(new UpdateRunnable(id, when, progress), 1000);
|
||||
}
|
||||
|
||||
public static void startProgressUpdater(Context context, int id, long when, int progress) {
|
||||
Intent progressIntent = new Intent(context, ProgressService.class);
|
||||
progressIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
progressIntent.setAction(ACTION_PROGRESS);
|
||||
progressIntent.putExtra("id", id);
|
||||
progressIntent.putExtra("when", when);
|
||||
progressIntent.putExtra("progress", progress);
|
||||
context.startService(progressIntent);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (C) 2015 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.
|
||||
*/
|
||||
|
||||
package com.android.example.notificationshowcase;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceFragment;
|
||||
|
||||
public class SettingsActivity extends Activity {
|
||||
public static final String KEY_GLOBAL_FADE = "pref_key_global_fade";
|
||||
public static final String KEY_SMS_ENABLE = "pref_key_sms_enable";
|
||||
public static final String KEY_SMS_NOISY = "pref_key_sms_noisy";
|
||||
public static final String KEY_SMS_SOUND = "pref_key_sms_sound";
|
||||
public static final String KEY_SMS_BUZZY = "pref_key_sms_buzzy";
|
||||
public static final String KEY_SMS_ONCE = "pref_key_sms_once";
|
||||
public static final String KEY_SMS_PRIORITY = "pref_key_sms_priority";
|
||||
public static final String KEY_SMS_PERSON = "pref_key_sms_person";
|
||||
public static final String KEY_PHONE_ENABLE = "pref_key_phone_enable";
|
||||
public static final String KEY_PHONE_NOISY = "pref_key_phone_noisy";
|
||||
public static final String KEY_PHONE_FULLSCREEN = "pref_key_phone_fullscreen";
|
||||
public static final String KEY_PHONE_PERSON = "pref_key_phone_person";
|
||||
public static final String KEY_UPLOAD_ENABLE = "pref_key_upload_enable";
|
||||
public static final String KEY_TIMER_ENABLE = "pref_key_timer_enable";
|
||||
public static final String KEY_CALENDAR_ENABLE = "pref_key_calendar_enable";
|
||||
public static final String KEY_SOCIAL_ENABLE = "pref_key_social_enable";
|
||||
public static final String KEY_INBOX_ENABLE = "pref_key_inbox_enable";
|
||||
public static final String KEY_PICTURE_ENABLE = "pref_key_picture_enable";
|
||||
|
||||
public class SettingsFragment extends PreferenceFragment {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.preferences);
|
||||
}
|
||||
|
||||
public SettingsFragment() {}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getFragmentManager().beginTransaction()
|
||||
.replace(android.R.id.content, new SettingsFragment())
|
||||
.commit();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Copyright (C) 2013 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.
|
||||
*/
|
||||
|
||||
package com.android.example.notificationshowcase;
|
||||
|
||||
import android.app.IntentService;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class ToastService extends IntentService {
|
||||
|
||||
private static final String TAG = "ToastService";
|
||||
|
||||
private static final String ACTION_TOAST = "toast";
|
||||
|
||||
private Handler handler;
|
||||
|
||||
public ToastService() {
|
||||
super(TAG);
|
||||
}
|
||||
public ToastService(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
handler = new Handler();
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onHandleIntent(Intent intent) {
|
||||
Log.v(TAG, "clicked a thing! intent=" + intent.toString());
|
||||
if (intent.hasExtra("text")) {
|
||||
final String text = intent.getStringExtra("text");
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(ToastService.this, text, Toast.LENGTH_LONG).show();
|
||||
Log.v(TAG, "toast " + text);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static PendingIntent getPendingIntent(Context context, int resId) {
|
||||
String text = context.getString(resId);
|
||||
Intent toastIntent = new Intent(context, ToastService.class);
|
||||
toastIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
toastIntent.setAction(ACTION_TOAST + ":" + resId); // one per toast message
|
||||
toastIntent.putExtra("text", text);
|
||||
PendingIntent pi = PendingIntent.getService(
|
||||
context, 58, toastIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
return pi;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright (C) 2013 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.
|
||||
*/
|
||||
|
||||
package com.android.example.notificationshowcase;
|
||||
|
||||
import android.app.IntentService;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.support.v7.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
||||
public class UpdateService extends IntentService {
|
||||
|
||||
private static final String TAG = "UpdateService";
|
||||
|
||||
private static final String ACTION_UPDATE = "update";
|
||||
|
||||
public UpdateService() {
|
||||
super(TAG);
|
||||
}
|
||||
|
||||
public UpdateService(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onHandleIntent(Intent intent) {
|
||||
Log.v(TAG, "clicked a thing! intent=" + intent.toString());
|
||||
if (intent.hasExtra("id") && intent.hasExtra("when")) {
|
||||
final int id = intent.getIntExtra("id", 0);
|
||||
NotificationManager noMa =
|
||||
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
final int update = intent.getIntExtra("update", 0);
|
||||
final long when = intent.getLongExtra("when", 0L);
|
||||
Log.v(TAG, "id: " + id + " when: " + when + " update: " + update);
|
||||
noMa.notify(NotificationService.NOTIFICATION_ID + id,
|
||||
NotificationService.makeSmsNotification(this, update, id, when));
|
||||
} else {
|
||||
Log.v(TAG, "id extra was " + (intent.hasExtra("id") ? "present" : "missing"));
|
||||
Log.v(TAG, "when extra was " + (intent.hasExtra("when") ? "present" : "missing"));
|
||||
}
|
||||
}
|
||||
|
||||
public static PendingIntent getPendingIntent(Context context, int update, int id, long when) {
|
||||
Intent updateIntent = new Intent(context, UpdateService.class);
|
||||
updateIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
updateIntent.setAction(ACTION_UPDATE);
|
||||
updateIntent.putExtra("id", id);
|
||||
updateIntent.putExtra("when", when);
|
||||
updateIntent.putExtra("update", update);
|
||||
PendingIntent pi = PendingIntent.getService(
|
||||
context, 58, updateIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
return pi;
|
||||
}
|
||||
}
|