Merge "Several fixes for DownloadableFonts sample." into oc-dev
diff --git a/views/EmojiCompat/app/build.gradle b/views/EmojiCompat/app/build.gradle
index fec4dab..4867afc 100644
--- a/views/EmojiCompat/app/build.gradle
+++ b/views/EmojiCompat/app/build.gradle
@@ -17,16 +17,16 @@
apply plugin: 'com.android.application'
ext {
- supportLibVersion = '26.0.0-beta1'
+ supportLibVersion = '26.0.0'
}
android {
- compileSdkVersion 'android-O'
- buildToolsVersion "26.0.0-rc1"
+ compileSdkVersion 26
+ buildToolsVersion "26.0.0"
defaultConfig {
applicationId "com.example.android.emojicompat"
- minSdkVersion 'O'
- targetSdkVersion 'O'
+ minSdkVersion 19
+ targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
@@ -51,5 +51,5 @@
// Test
testCompile 'junit:junit:4.12'
- androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
+ androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.0'
}
diff --git a/views/EmojiCompat/app/src/main/java/com/example/android/emojicompat/MainActivity.java b/views/EmojiCompat/app/src/main/java/com/example/android/emojicompat/MainActivity.java
index 2ef3702..2f93c54 100644
--- a/views/EmojiCompat/app/src/main/java/com/example/android/emojicompat/MainActivity.java
+++ b/views/EmojiCompat/app/src/main/java/com/example/android/emojicompat/MainActivity.java
@@ -16,11 +16,14 @@
package com.example.android.emojicompat;
+import android.content.Context;
import android.os.Bundle;
import android.support.text.emoji.EmojiCompat;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
+import java.lang.ref.WeakReference;
+
public class MainActivity extends AppCompatActivity {
@@ -51,18 +54,32 @@
// Regular TextView without EmojiCompat support; you have to manually process the text
final TextView regularTextView = findViewById(R.id.regular_text_view);
- EmojiCompat.get().registerInitCallback(new EmojiCompat.InitCallback() {
- @Override
- public void onInitialized() {
- final EmojiCompat compat = EmojiCompat.get();
- regularTextView.setText(
- compat.process(getString(R.string.regular_text_view, EMOJI)));
- }
- });
+ EmojiCompat.get().registerInitCallback(new InitCallback(regularTextView));
// Custom TextView
final TextView customTextView = findViewById(R.id.emoji_custom_text_view);
customTextView.setText(getString(R.string.custom_text_view, EMOJI));
}
+ private static class InitCallback extends EmojiCompat.InitCallback {
+
+ private final WeakReference<TextView> mRegularTextViewRef;
+
+ InitCallback(TextView regularTextView) {
+ mRegularTextViewRef = new WeakReference<>(regularTextView);
+ }
+
+ @Override
+ public void onInitialized() {
+ final TextView regularTextView = mRegularTextViewRef.get();
+ if (regularTextView != null) {
+ final EmojiCompat compat = EmojiCompat.get();
+ final Context context = regularTextView.getContext();
+ regularTextView.setText(
+ compat.process(context.getString(R.string.regular_text_view, EMOJI)));
+ }
+ }
+
+ }
+
}
diff --git a/views/EmojiCompat/build.gradle b/views/EmojiCompat/build.gradle
index cb27953..5811ab0 100644
--- a/views/EmojiCompat/build.gradle
+++ b/views/EmojiCompat/build.gradle
@@ -19,14 +19,14 @@
jcenter()
}
dependencies {
- classpath 'com.android.tools.build:gradle:2.4.0-alpha6'
+ classpath 'com.android.tools.build:gradle:2.3.3'
}
}
allprojects {
repositories {
jcenter()
- maven { url 'https://maven.google.com' }
+ google()
}
}
diff --git a/views/EmojiCompat/gradle/wrapper/gradle-wrapper.properties b/views/EmojiCompat/gradle/wrapper/gradle-wrapper.properties
index dbde6ba..93a1579 100644
--- a/views/EmojiCompat/gradle/wrapper/gradle-wrapper.properties
+++ b/views/EmojiCompat/gradle/wrapper/gradle-wrapper.properties
@@ -3,4 +3,4 @@
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-3.4.1-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.0.2-all.zip
diff --git a/views/EmojiCompat/kotlinApp/app/build.gradle b/views/EmojiCompat/kotlinApp/app/build.gradle
index af061cd..de2074b 100644
--- a/views/EmojiCompat/kotlinApp/app/build.gradle
+++ b/views/EmojiCompat/kotlinApp/app/build.gradle
@@ -16,7 +16,7 @@
buildscript {
ext {
- kotlin_version = '1.1.2-3'
+ kotlin_version = '1.1.3-2'
}
repositories {
jcenter()
@@ -30,16 +30,16 @@
apply plugin: 'kotlin-android'
ext {
- supportLibVersion = '26.0.0-beta1'
+ supportLibVersion = '26.0.0'
}
android {
- compileSdkVersion 'android-O'
- buildToolsVersion "26.0.0-rc1"
+ compileSdkVersion 26
+ buildToolsVersion '26.0.0'
defaultConfig {
applicationId "com.example.android.emojicompat"
- minSdkVersion 'O'
- targetSdkVersion 'O'
+ minSdkVersion 19
+ targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
diff --git a/views/EmojiCompat/kotlinApp/app/src/main/java/com/example/android/emojicompat/MainActivity.kt b/views/EmojiCompat/kotlinApp/app/src/main/java/com/example/android/emojicompat/MainActivity.kt
index 7cc9033..b23c800 100644
--- a/views/EmojiCompat/kotlinApp/app/src/main/java/com/example/android/emojicompat/MainActivity.kt
+++ b/views/EmojiCompat/kotlinApp/app/src/main/java/com/example/android/emojicompat/MainActivity.kt
@@ -20,6 +20,7 @@
import android.support.text.emoji.EmojiCompat
import android.support.v7.app.AppCompatActivity
import android.widget.TextView
+import java.lang.ref.WeakReference
class MainActivity : AppCompatActivity() {
@@ -53,16 +54,27 @@
// Regular TextView without EmojiCompat support; you have to manually process the text
val regularTextView: TextView = findViewById(R.id.regular_text_view)
- EmojiCompat.get().registerInitCallback(object : EmojiCompat.InitCallback() {
- override fun onInitialized() {
- val compat = EmojiCompat.get()
- regularTextView.text = compat.process(getString(R.string.regular_text_view, EMOJI))
- }
- })
+ EmojiCompat.get().registerInitCallback(InitCallback(regularTextView))
// Custom TextView
val customTextView: TextView = findViewById(R.id.emoji_custom_text_view)
customTextView.text = getString(R.string.custom_text_view, EMOJI)
}
+ private class InitCallback(regularTextView: TextView) : EmojiCompat.InitCallback() {
+
+ val regularTextViewRef = WeakReference(regularTextView)
+
+ override fun onInitialized() {
+ val regularTextView = regularTextViewRef.get()
+ if (regularTextView != null) {
+ val compat = EmojiCompat.get()
+ val context = regularTextView.context
+ regularTextView.text = compat.process(
+ context.getString(R.string.regular_text_view, EMOJI))
+ }
+ }
+
+ }
+
}
diff --git a/views/EmojiCompat/kotlinApp/build.gradle b/views/EmojiCompat/kotlinApp/build.gradle
index 706e32e..f25c0d2 100644
--- a/views/EmojiCompat/kotlinApp/build.gradle
+++ b/views/EmojiCompat/kotlinApp/build.gradle
@@ -19,14 +19,14 @@
jcenter()
}
dependencies {
- classpath 'com.android.tools.build:gradle:2.4.0-alpha6'
+ classpath 'com.android.tools.build:gradle:2.3.3'
}
}
allprojects {
repositories {
jcenter()
- maven { url 'https://maven.google.com' }
+ google()
}
}
diff --git a/views/EmojiCompat/kotlinApp/gradle/wrapper/gradle-wrapper.properties b/views/EmojiCompat/kotlinApp/gradle/wrapper/gradle-wrapper.properties
index dbde6ba..93a1579 100644
--- a/views/EmojiCompat/kotlinApp/gradle/wrapper/gradle-wrapper.properties
+++ b/views/EmojiCompat/kotlinApp/gradle/wrapper/gradle-wrapper.properties
@@ -3,4 +3,4 @@
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-3.4.1-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.0.2-all.zip
diff --git a/wearable/wear/AlwaysOn/Wearable/src/main/res/layout/activity_main.xml b/wearable/wear/AlwaysOn/Wearable/src/main/res/layout/activity_main.xml
index 82274a2..90570c3 100644
--- a/wearable/wear/AlwaysOn/Wearable/src/main/res/layout/activity_main.xml
+++ b/wearable/wear/AlwaysOn/Wearable/src/main/res/layout/activity_main.xml
@@ -26,7 +26,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
- app:layout_box="all">
+ app:boxedEdges="all">
<TextView
android:id="@+id/time"
diff --git a/wearable/wear/RuntimePermissionsWear/Wearable/src/main/res/layout/activity_main.xml b/wearable/wear/RuntimePermissionsWear/Wearable/src/main/res/layout/activity_main.xml
index ede3a0c..b0e9034 100644
--- a/wearable/wear/RuntimePermissionsWear/Wearable/src/main/res/layout/activity_main.xml
+++ b/wearable/wear/RuntimePermissionsWear/Wearable/src/main/res/layout/activity_main.xml
@@ -25,7 +25,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
- app:layout_box="all">
+ app:boxedEdges="all">
<LinearLayout
android:layout_width="match_parent"
diff --git a/wearable/wear/RuntimePermissionsWear/Wearable/src/main/res/layout/activity_request_permission_on_phone.xml b/wearable/wear/RuntimePermissionsWear/Wearable/src/main/res/layout/activity_request_permission_on_phone.xml
index c8a5d05..f96d80b 100644
--- a/wearable/wear/RuntimePermissionsWear/Wearable/src/main/res/layout/activity_request_permission_on_phone.xml
+++ b/wearable/wear/RuntimePermissionsWear/Wearable/src/main/res/layout/activity_request_permission_on_phone.xml
@@ -12,7 +12,7 @@
limitations under the License.
-->
-<android.support.wearable.view.BoxInsetLayout
+<android.support.wear.widget.BoxInsetLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
@@ -30,7 +30,7 @@
android:layout_height="wrap_content"
android:onClick="onClickPermissionPhoneStorage"
android:orientation="vertical"
- app:layout_box="all">
+ app:boxedEdges="all">
<TextView
android:layout_width="wrap_content"
@@ -71,4 +71,4 @@
android:textColor="#0086D4"/>
</LinearLayout>
</LinearLayout>
-</android.support.wearable.view.BoxInsetLayout>
\ No newline at end of file
+</android.support.wear.widget.BoxInsetLayout>
\ No newline at end of file
diff --git a/wearable/wear/RuntimePermissionsWear/Wearable/src/main/res/layout/rect_activity_main.xml b/wearable/wear/RuntimePermissionsWear/Wearable/src/main/res/layout/rect_activity_main.xml
deleted file mode 100644
index 89627a7..0000000
--- a/wearable/wear/RuntimePermissionsWear/Wearable/src/main/res/layout/rect_activity_main.xml
+++ /dev/null
@@ -1,57 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright 2015 Google Inc. All rights reserved.
- 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.
- -->
-
-<LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- tools:context=".MainActivity"
- tools:deviceIds="wear_square">
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
-
- <Button
- android:id="@+id/wear_body_sensors_permission_button"
- android:layout_width="0dp"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:drawableLeft="@drawable/ic_permission_denied"
- android:textSize="8sp"
- android:text="@string/button_wear_label_activity_main"
- android:onClick="onClickWearBodySensors" />
-
- <Button
- android:id="@+id/phone_storage_permission_button"
- android:layout_width="0dp"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:drawableLeft="@drawable/ic_permission_denied"
- android:textSize="8sp"
- android:text="@string/button_phone_label_activity_main"
- android:onClick="onClickPhoneStorage" />
- </LinearLayout>
-
- <TextView
- android:id="@+id/output"
- android:layout_width="match_parent"
- android:layout_height="0dp"
- android:layout_weight="2"
- android:paddingLeft="8dp"
- android:paddingRight="8dp"
- android:text="@string/hello_wear_activity_main" />
-</LinearLayout>
diff --git a/wearable/wear/RuntimePermissionsWear/Wearable/src/main/res/layout/round_activity_main.xml b/wearable/wear/RuntimePermissionsWear/Wearable/src/main/res/layout/round_activity_main.xml
deleted file mode 100644
index 90d8ccb..0000000
--- a/wearable/wear/RuntimePermissionsWear/Wearable/src/main/res/layout/round_activity_main.xml
+++ /dev/null
@@ -1,61 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright 2015 Google Inc. All rights reserved.
- 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.
- -->
-
-<LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- tools:context=".MainActivity"
- tools:deviceIds="wear_round"
- android:paddingTop="24dp"
- android:paddingLeft="10dp"
- android:paddingRight="10dp">
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
-
- <Button
- android:id="@+id/wear_body_sensors_permission_button"
- android:layout_width="0dp"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:drawableLeft="@drawable/ic_permission_denied"
- android:textSize="8sp"
- android:text="@string/button_wear_label_activity_main"
- android:onClick="onClickWearBodySensors" />
-
- <Button
- android:id="@+id/phone_storage_permission_button"
- android:layout_width="0dp"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:drawableLeft="@drawable/ic_permission_denied"
- android:textSize="8sp"
- android:text="@string/button_phone_label_activity_main"
- android:onClick="onClickPhoneStorage" />
- </LinearLayout>
-
- <TextView
- android:id="@+id/output"
- android:layout_width="match_parent"
- android:layout_height="0dp"
- android:layout_weight="2"
- android:paddingLeft="8dp"
- android:paddingRight="8dp"
- android:text="@string/hello_wear_activity_main" />
-
-</LinearLayout>
diff --git a/wearable/wear/SpeedTracker/Wearable/src/main/res/layout/speed_picker_activity.xml b/wearable/wear/SpeedTracker/Wearable/src/main/res/layout/speed_picker_activity.xml
index de6e4ef..2706211 100644
--- a/wearable/wear/SpeedTracker/Wearable/src/main/res/layout/speed_picker_activity.xml
+++ b/wearable/wear/SpeedTracker/Wearable/src/main/res/layout/speed_picker_activity.xml
@@ -25,7 +25,7 @@
android:id="@+id/frame_layout"
android:layout_height="match_parent"
android:layout_width="match_parent"
- app:layout_box="left|bottom|right">
+ app:boxedEdges="left|bottom|right">
<android.support.wearable.view.WearableListView
diff --git a/wearable/wear/WatchFace/Wearable/src/main/res/layout/activity_digital_config.xml b/wearable/wear/WatchFace/Wearable/src/main/res/layout/activity_digital_config.xml
index d432f82..9ec9949 100644
--- a/wearable/wear/WatchFace/Wearable/src/main/res/layout/activity_digital_config.xml
+++ b/wearable/wear/WatchFace/Wearable/src/main/res/layout/activity_digital_config.xml
@@ -30,11 +30,11 @@
android:textColor="@color/config_activity_header_text_color"
android:text="@string/digital_background_color"
android:fontFamily="sans-serif-condensed-light"
- app:layout_box="left|top"/>
+ app:boxedEdges="left|top"/>
<android.support.wearable.view.WearableListView
android:id="@+id/color_picker"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
- app:layout_box="left|right"/>
+ app:boxedEdges="left|right"/>
</android.support.wear.widget.BoxInsetLayout>
diff --git a/wearable/wear/WearHighBandwidthNetworking/Wearable/src/main/res/layout/activity_main.xml b/wearable/wear/WearHighBandwidthNetworking/Wearable/src/main/res/layout/activity_main.xml
index b7c8efd..6bbf514 100644
--- a/wearable/wear/WearHighBandwidthNetworking/Wearable/src/main/res/layout/activity_main.xml
+++ b/wearable/wear/WearHighBandwidthNetworking/Wearable/src/main/res/layout/activity_main.xml
@@ -53,7 +53,7 @@
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
- app:layout_box="left|right">
+ app:boxedEdges="left|right">
<TextView
android:id="@+id/info_text"
diff --git a/wearable/wear/WearNotifications/Application/src/main/java/com/example/android/wearable/wear/wearnotifications/GlobalNotificationBuilder.java b/wearable/wear/WearNotifications/Application/src/main/java/com/example/android/wearable/wear/wearnotifications/GlobalNotificationBuilder.java
index 1b1743f..79997e2 100644
--- a/wearable/wear/WearNotifications/Application/src/main/java/com/example/android/wearable/wear/wearnotifications/GlobalNotificationBuilder.java
+++ b/wearable/wear/WearNotifications/Application/src/main/java/com/example/android/wearable/wear/wearnotifications/GlobalNotificationBuilder.java
@@ -15,7 +15,7 @@
*/
package com.example.android.wearable.wear.wearnotifications;
-import android.support.v7.app.NotificationCompat;
+import android.support.v4.app.NotificationCompat;
/**
* We use a Singleton for a global copy of the NotificationCompat.Builder to update active
diff --git a/wearable/wear/WearNotifications/Application/src/main/java/com/example/android/wearable/wear/wearnotifications/MainActivity.java b/wearable/wear/WearNotifications/Application/src/main/java/com/example/android/wearable/wear/wearnotifications/MainActivity.java
index 6c44fcb..004f2de 100644
--- a/wearable/wear/WearNotifications/Application/src/main/java/com/example/android/wearable/wear/wearnotifications/MainActivity.java
+++ b/wearable/wear/WearNotifications/Application/src/main/java/com/example/android/wearable/wear/wearnotifications/MainActivity.java
@@ -22,6 +22,7 @@
import android.os.Build;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
+import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationCompat.BigPictureStyle;
import android.support.v4.app.NotificationCompat.BigTextStyle;
import android.support.v4.app.NotificationCompat.InboxStyle;
@@ -29,8 +30,8 @@
import android.support.v4.app.NotificationManagerCompat;
import android.support.v4.app.RemoteInput;
import android.support.v4.app.TaskStackBuilder;
+import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
-import android.support.v7.app.NotificationCompat;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
@@ -39,8 +40,8 @@
import android.widget.Spinner;
import android.widget.TextView;
-
-
+import com.example.android.wearable.wear.common.mock.MockDatabase;
+import com.example.android.wearable.wear.common.util.NotificationUtil;
import com.example.android.wearable.wear.wearnotifications.handlers.BigPictureSocialIntentService;
import com.example.android.wearable.wear.wearnotifications.handlers.BigPictureSocialMainActivity;
import com.example.android.wearable.wear.wearnotifications.handlers.BigTextIntentService;
@@ -48,7 +49,6 @@
import com.example.android.wearable.wear.wearnotifications.handlers.InboxMainActivity;
import com.example.android.wearable.wear.wearnotifications.handlers.MessagingIntentService;
import com.example.android.wearable.wear.wearnotifications.handlers.MessagingMainActivity;
-import com.example.android.wearable.wear.wearnotifications.mock.MockDatabase;
/**
* The Activity demonstrates several popular Notification.Style examples along with their best
@@ -61,13 +61,13 @@
public static final int NOTIFICATION_ID = 888;
- // Used for Notification Style array and switch statement for Spinner selection
+ // Used for Notification Style array and switch statement for Spinner selection.
private static final String BIG_TEXT_STYLE = "BIG_TEXT_STYLE";
private static final String BIG_PICTURE_STYLE = "BIG_PICTURE_STYLE";
private static final String INBOX_STYLE = "INBOX_STYLE";
private static final String MESSAGING_STYLE = "MESSAGING_STYLE";
- // Collection of notification styles to back ArrayAdapter for Spinner
+ // Collection of notification styles to back ArrayAdapter for Spinner.
private static final String[] NOTIFICATION_STYLES =
{BIG_TEXT_STYLE, BIG_PICTURE_STYLE, INBOX_STYLE, MESSAGING_STYLE};
@@ -83,7 +83,7 @@
private int mSelectedNotification = 0;
- // RelativeLayout is needed for SnackBars to alert users when Notifications are disabled for app
+ // RelativeLayout required for SnackBars to alert users when Notifications are disabled for app.
private RelativeLayout mMainRelativeLayout;
private Spinner mSpinner;
private TextView mNotificationDetailsTextView;
@@ -100,15 +100,15 @@
mNotificationManagerCompat = NotificationManagerCompat.from(getApplicationContext());
- // Create an ArrayAdapter using the string array and a default spinner layout
+ // Create an ArrayAdapter using the string array and a default spinner layout.
ArrayAdapter<CharSequence> adapter =
new ArrayAdapter(
this,
android.R.layout.simple_spinner_item,
NOTIFICATION_STYLES);
- // Specify the layout to use when the list of choices appears
+ // Specify the layout to use when the list of choices appears.
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- // Apply the adapter to the spinner
+ // Apply the adapter to the spinner.
mSpinner.setAdapter(adapter);
mSpinner.setOnItemSelectedListener(this);
}
@@ -187,28 +187,34 @@
// Main steps for building a BIG_TEXT_STYLE notification:
// 0. Get your data
- // 1. Build the BIG_TEXT_STYLE
- // 2. Set up main Intent for notification
- // 3. Create additional Actions for the Notification
- // 4. Build and issue the notification
+ // 1. Create/Retrieve Notification Channel for O and beyond devices (26+)
+ // 2. Build the BIG_TEXT_STYLE
+ // 3. Set up main Intent for notification
+ // 4. Create additional Actions for the Notification
+ // 5. Build and issue the notification
- // 0. Get your data (everything unique per Notification)
+ // 0. Get your data (everything unique per Notification).
MockDatabase.BigTextStyleReminderAppData bigTextStyleReminderAppData =
MockDatabase.getBigTextStyleData();
- // 1. Build the BIG_TEXT_STYLE
+ // 1. Create/Retrieve Notification Channel for O and beyond devices (26+).
+ String notificationChannelId =
+ NotificationUtil.createNotificationChannel(this, bigTextStyleReminderAppData);
+
+
+ // 2. Build the BIG_TEXT_STYLE.
BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle()
- // Overrides ContentText in the big form of the template
+ // Overrides ContentText in the big form of the template.
.bigText(bigTextStyleReminderAppData.getBigText())
- // Overrides ContentTitle in the big form of the template
+ // Overrides ContentTitle in the big form of the template.
.setBigContentTitle(bigTextStyleReminderAppData.getBigContentTitle())
- // Summary line after the detail section in the big form of the template
+ // Summary line after the detail section in the big form of the template.
// Note: To improve readability, don't overload the user with info. If Summary Text
// doesn't add critical information, you should skip it.
.setSummaryText(bigTextStyleReminderAppData.getSummaryText());
- // 2. Set up main Intent for notification
+ // 3. Set up main Intent for notification.
Intent notifyIntent = new Intent(this, BigTextMainActivity.class);
// When creating your Intent, you need to take into account the back state, i.e., what
@@ -243,10 +249,10 @@
);
- // 3. Create additional Actions (Intents) for the Notification
+ // 4. Create additional Actions (Intents) for the Notification.
- // In our case, we create two additional actions: a Snooze action and a Dismiss action
- // Snooze Action
+ // In our case, we create two additional actions: a Snooze action and a Dismiss action.
+ // Snooze Action.
Intent snoozeIntent = new Intent(this, BigTextIntentService.class);
snoozeIntent.setAction(BigTextIntentService.ACTION_SNOOZE);
@@ -259,7 +265,7 @@
.build();
- // Dismiss Action
+ // Dismiss Action.
Intent dismissIntent = new Intent(this, BigTextIntentService.class);
dismissIntent.setAction(BigTextIntentService.ACTION_DISMISS);
@@ -272,32 +278,34 @@
.build();
- // 4. Build and issue the notification
+ // 5. Build and issue the notification.
// Because we want this to be a new notification (not updating a previous notification), we
// create a new Builder. Later, we use the same global builder to get back the notification
// we built here for the snooze action, that is, canceling the notification and relaunching
// it several seconds later.
+ // Notification Channel Id is ignored for Android pre O (26).
NotificationCompat.Builder notificationCompatBuilder =
- new NotificationCompat.Builder(getApplicationContext());
+ new NotificationCompat.Builder(
+ getApplicationContext(), notificationChannelId);
GlobalNotificationBuilder.setNotificationCompatBuilderInstance(notificationCompatBuilder);
Notification notification = notificationCompatBuilder
- // BIG_TEXT_STYLE sets title and content for API 16 (4.1 and after)
+ // BIG_TEXT_STYLE sets title and content for API 16 (4.1 and after).
.setStyle(bigTextStyle)
- // Title for API <16 (4.0 and below) devices
+ // Title for API <16 (4.0 and below) devices.
.setContentTitle(bigTextStyleReminderAppData.getContentTitle())
- // Content for API <24 (7.0 and below) devices
+ // Content for API <24 (7.0 and below) devices.
.setContentText(bigTextStyleReminderAppData.getContentText())
.setSmallIcon(R.drawable.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(
getResources(),
R.drawable.ic_alarm_white_48dp))
.setContentIntent(notifyPendingIntent)
- // Set primary color (important for Wear 2.0 Notifications)
- .setColor(getResources().getColor(R.color.colorPrimary))
+ // Set primary color (important for Wear 2.0 Notifications).
+ .setColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary))
// SIDE NOTE: Auto-bundling is enabled for 4 or more notifications on API 24+ (N+)
// devices and all Android Wear devices. If you have more than one notification and
@@ -307,12 +315,17 @@
// .setGroup(GROUP_KEY_YOUR_NAME_HERE)
.setCategory(Notification.CATEGORY_REMINDER)
- .setPriority(Notification.PRIORITY_HIGH)
- // Shows content on the lock-screen
- .setVisibility(Notification.VISIBILITY_PUBLIC)
+ // Sets priority for 25 and below. For 26 and above, 'priority' is deprecated for
+ // 'importance' which is set in the NotificationChannel. The integers representing
+ // 'priority' are different from 'importance', so make sure you don't mix them.
+ .setPriority(bigTextStyleReminderAppData.getPriority())
- // Adds additional actions specified above
+ // Sets lock-screen visibility for 25 and below. For 26 and above, lock screen
+ // visibility is set in the NotificationChannel.
+ .setVisibility(bigTextStyleReminderAppData.getChannelLockscreenVisibility())
+
+ // Adds additional actions specified above.
.addAction(snoozeAction)
.addAction(dismissAction)
@@ -336,28 +349,33 @@
// Main steps for building a BIG_PICTURE_STYLE notification:
// 0. Get your data
- // 1. Build the BIG_PICTURE_STYLE
- // 2. Set up main Intent for notification
- // 3. Set up RemoteInput, so users can input (keyboard and voice) from notification
- // 4. Build and issue the notification
+ // 1. Create/Retrieve Notification Channel for O and beyond devices (26+)
+ // 2. Build the BIG_PICTURE_STYLE
+ // 3. Set up main Intent for notification
+ // 4. Set up RemoteInput, so users can input (keyboard and voice) from notification
+ // 5. Build and issue the notification
- // 0. Get your data (everything unique per Notification)
+ // 0. Get your data (everything unique per Notification).
MockDatabase.BigPictureStyleSocialAppData bigPictureStyleSocialAppData =
MockDatabase.getBigPictureStyleData();
- // 1. Build the BIG_PICTURE_STYLE
+ // 1. Create/Retrieve Notification Channel for O and beyond devices (26+).
+ String notificationChannelId =
+ NotificationUtil.createNotificationChannel(this, bigPictureStyleSocialAppData);
+
+ // 2. Build the BIG_PICTURE_STYLE.
BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle()
- // Provides the bitmap for the BigPicture notification
+ // Provides the bitmap for the BigPicture notification.
.bigPicture(
BitmapFactory.decodeResource(
getResources(),
bigPictureStyleSocialAppData.getBigImage()))
- // Overrides ContentTitle in the big form of the template
+ // Overrides ContentTitle in the big form of the template.
.setBigContentTitle(bigPictureStyleSocialAppData.getBigContentTitle())
- // Summary line after the detail section in the big form of the template
+ // Summary line after the detail section in the big form of the template.
.setSummaryText(bigPictureStyleSocialAppData.getSummaryText());
- // 2. Set up main Intent for notification
+ // 3. Set up main Intent for notification.
Intent mainIntent = new Intent(this, BigPictureSocialMainActivity.class);
// When creating your Intent, you need to take into account the back state, i.e., what
@@ -381,11 +399,11 @@
// https://developer.android.com/training/notify-user/navigation.html
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
- // Adds the back stack
+ // Adds the back stack.
stackBuilder.addParentStack(BigPictureSocialMainActivity.class);
- // Adds the Intent to the top of the stack
+ // Adds the Intent to the top of the stack.
stackBuilder.addNextIntent(mainIntent);
- // Gets a PendingIntent containing the entire back stack
+ // Gets a PendingIntent containing the entire back stack.
PendingIntent mainPendingIntent =
PendingIntent.getActivity(
this,
@@ -394,14 +412,14 @@
PendingIntent.FLAG_UPDATE_CURRENT
);
- // 3. Set up RemoteInput, so users can input (keyboard and voice) from notification
+ // 4. Set up RemoteInput, so users can input (keyboard and voice) from notification.
// Note: For API <24 (M and below) we need to use an Activity, so the lock-screen presents
// the auth challenge. For API 24+ (N and above), we use a Service (could be a
// BroadcastReceiver), so the user can input from Notification or lock-screen (they have
// choice to allow) without leaving the notification.
- // Create the RemoteInput
+ // Create the RemoteInput.
String replyLabel = getString(R.string.reply_label);
RemoteInput remoteInput =
new RemoteInput.Builder(BigPictureSocialIntentService.EXTRA_COMMENT)
@@ -432,32 +450,31 @@
.addRemoteInput(remoteInput)
.build();
- // 4. Build and issue the notification
+ // 5. Build and issue the notification.
// Because we want this to be a new notification (not updating a previous notification), we
// create a new Builder. Later, we use the same global builder to get back the notification
// we built here for a comment on the post.
NotificationCompat.Builder notificationCompatBuilder =
- new NotificationCompat.Builder(getApplicationContext());
+ new NotificationCompat.Builder(getApplicationContext(), notificationChannelId);
GlobalNotificationBuilder.setNotificationCompatBuilderInstance(notificationCompatBuilder);
- // 4. Build and issue the notification
notificationCompatBuilder
- // BIG_PICTURE_STYLE sets title and content for API 16 (4.1 and after)
+ // BIG_PICTURE_STYLE sets title and content for API 16 (4.1 and after).
.setStyle(bigPictureStyle)
- // Title for API <16 (4.0 and below) devices
+ // Title for API <16 (4.0 and below) devices.
.setContentTitle(bigPictureStyleSocialAppData.getContentTitle())
- // Content for API <24 (7.0 and below) devices
+ // Content for API <24 (7.0 and below) devices.
.setContentText(bigPictureStyleSocialAppData.getContentText())
.setSmallIcon(R.drawable.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(
getResources(),
R.drawable.ic_person_black_48dp))
.setContentIntent(mainPendingIntent)
- // Set primary color (important for Wear 2.0 Notifications)
- .setColor(getResources().getColor(R.color.colorPrimary))
+ // Set primary color (important for Wear 2.0 Notifications).
+ .setColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary))
// SIDE NOTE: Auto-bundling is enabled for 4 or more notifications on API 24+ (N+)
// devices and all Android Wear devices. If you have more than one notification and
@@ -469,10 +486,15 @@
.setSubText(Integer.toString(1))
.addAction(replyAction)
.setCategory(Notification.CATEGORY_SOCIAL)
- .setPriority(Notification.PRIORITY_HIGH)
- // Hides content on the lock-screen
- .setVisibility(Notification.VISIBILITY_PRIVATE);
+ // Sets priority for 25 and below. For 26 and above, 'priority' is deprecated for
+ // 'importance' which is set in the NotificationChannel. The integers representing
+ // 'priority' are different from 'importance', so make sure you don't mix them.
+ .setPriority(bigPictureStyleSocialAppData.getPriority())
+
+ // Sets lock-screen visibility for 25 and below. For 26 and above, lock screen
+ // visibility is set in the NotificationChannel.
+ .setVisibility(bigPictureStyleSocialAppData.getChannelLockscreenVisibility());
// If the phone is in "Do not disturb mode, the user will still be notified if
// the sender(s) is starred as a favorite.
@@ -497,27 +519,32 @@
// Main steps for building a INBOX_STYLE notification:
// 0. Get your data
- // 1. Build the INBOX_STYLE
- // 2. Set up main Intent for notification
- // 3. Build and issue the notification
+ // 1. Create/Retrieve Notification Channel for O and beyond devices (26+)
+ // 2. Build the INBOX_STYLE
+ // 3. Set up main Intent for notification
+ // 4. Build and issue the notification
- // 0. Get your data (everything unique per Notification)
+ // 0. Get your data (everything unique per Notification).
MockDatabase.InboxStyleEmailAppData inboxStyleEmailAppData =
MockDatabase.getInboxStyleData();
- // 1. Build the INBOX_STYLE
+ // 1. Create/Retrieve Notification Channel for O and beyond devices (26+).
+ String notificationChannelId =
+ NotificationUtil.createNotificationChannel(this, inboxStyleEmailAppData);
+
+ // 2. Build the INBOX_STYLE.
InboxStyle inboxStyle = new NotificationCompat.InboxStyle()
// This title is slightly different than regular title, since I know INBOX_STYLE is
// available.
.setBigContentTitle(inboxStyleEmailAppData.getBigContentTitle())
.setSummaryText(inboxStyleEmailAppData.getSummaryText());
- // Add each summary line of the new emails, you can add up to 5
+ // Add each summary line of the new emails, you can add up to 5.
for (String summary : inboxStyleEmailAppData.getIndividualEmailSummary()) {
inboxStyle.addLine(summary);
}
- // 2. Set up main Intent for notification
+ // 3. Set up main Intent for notification.
Intent mainIntent = new Intent(this, InboxMainActivity.class);
// When creating your Intent, you need to take into account the back state, i.e., what
@@ -541,11 +568,11 @@
// https://developer.android.com/training/notify-user/navigation.html
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
- // Adds the back stack
+ // Adds the back stack.
stackBuilder.addParentStack(InboxMainActivity.class);
- // Adds the Intent to the top of the stack
+ // Adds the Intent to the top of the stack.
stackBuilder.addNextIntent(mainIntent);
- // Gets a PendingIntent containing the entire back stack
+ // Gets a PendingIntent containing the entire back stack.
PendingIntent mainPendingIntent =
PendingIntent.getActivity(
this,
@@ -554,38 +581,37 @@
PendingIntent.FLAG_UPDATE_CURRENT
);
- // 3. Build and issue the notification
+ // 4. Build and issue the notification.
// Because we want this to be a new notification (not updating a previous notification), we
// create a new Builder. However, we don't need to update this notification later, so we
// will not need to set a global builder for access to the notification later.
NotificationCompat.Builder notificationCompatBuilder =
- new NotificationCompat.Builder(getApplicationContext());
+ new NotificationCompat.Builder(getApplicationContext(), notificationChannelId);
GlobalNotificationBuilder.setNotificationCompatBuilderInstance(notificationCompatBuilder);
- // 4. Build and issue the notification
notificationCompatBuilder
// INBOX_STYLE sets title and content for API 16+ (4.1 and after) when the
- // notification is expanded
+ // notification is expanded.
.setStyle(inboxStyle)
// Title for API <16 (4.0 and below) devices and API 16+ (4.1 and after) when the
- // notification is collapsed
+ // notification is collapsed.
.setContentTitle(inboxStyleEmailAppData.getContentTitle())
// Content for API <24 (7.0 and below) devices and API 16+ (4.1 and after) when the
- // notification is collapsed
+ // notification is collapsed.
.setContentText(inboxStyleEmailAppData.getContentText())
.setSmallIcon(R.drawable.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(
getResources(),
R.drawable.ic_person_black_48dp))
.setContentIntent(mainPendingIntent)
- // Set primary color (important for Wear 2.0 Notifications)
- .setColor(getResources().getColor(R.color.colorPrimary))
+ // Set primary color (important for Wear 2.0 Notifications).
+ .setColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary))
// SIDE NOTE: Auto-bundling is enabled for 4 or more notifications on API 24+ (N+)
// devices and all Android Wear devices. If you have more than one notification and
@@ -594,14 +620,19 @@
// .setGroupSummary(true)
// .setGroup(GROUP_KEY_YOUR_NAME_HERE)
- // Sets large number at the right-hand side of the notification for API <24 devices
+ // Sets large number at the right-hand side of the notification for API <24 devices.
.setSubText(Integer.toString(inboxStyleEmailAppData.getNumberOfNewEmails()))
.setCategory(Notification.CATEGORY_EMAIL)
- .setPriority(Notification.PRIORITY_HIGH)
- // Hides content on the lock-screen
- .setVisibility(Notification.VISIBILITY_PRIVATE);
+ // Sets priority for 25 and below. For 26 and above, 'priority' is deprecated for
+ // 'importance' which is set in the NotificationChannel. The integers representing
+ // 'priority' are different from 'importance', so make sure you don't mix them.
+ .setPriority(inboxStyleEmailAppData.getPriority())
+
+ // Sets lock-screen visibility for 25 and below. For 26 and above, lock screen
+ // visibility is set in the NotificationChannel.
+ .setVisibility(inboxStyleEmailAppData.getChannelLockscreenVisibility());
// If the phone is in "Do not disturb mode, the user will still be notified if
// the sender(s) is starred as a favorite.
@@ -625,16 +656,21 @@
// Main steps for building a MESSAGING_STYLE notification:
// 0. Get your data
- // 1. Build the MESSAGING_STYLE
- // 2. Set up main Intent for notification
- // 3. Set up RemoteInput (users can input directly from notification)
- // 4. Build and issue the notification
+ // 1. Create/Retrieve Notification Channel for O and beyond devices (26+)
+ // 2. Build the MESSAGING_STYLE
+ // 3. Set up main Intent for notification
+ // 4. Set up RemoteInput (users can input directly from notification)
+ // 5. Build and issue the notification
// 0. Get your data (everything unique per Notification)
MockDatabase.MessagingStyleCommsAppData messagingStyleCommsAppData =
MockDatabase.getMessagingStyleData();
- // 1. Build the Notification.Style (MESSAGING_STYLE)
+ // 1. Create/Retrieve Notification Channel for O and beyond devices (26+).
+ String notificationChannelId =
+ NotificationUtil.createNotificationChannel(this, messagingStyleCommsAppData);
+
+ // 2. Build the Notification.Style (MESSAGING_STYLE).
String contentTitle = messagingStyleCommsAppData.getContentTitle();
MessagingStyle messagingStyle =
@@ -647,13 +683,13 @@
// In our case, we use the same title.
.setConversationTitle(contentTitle);
- // Adds all Messages
- // Note: Messages include the text, timestamp, and sender
+ // Adds all Messages.
+ // Note: Messages include the text, timestamp, and sender.
for (MessagingStyle.Message message : messagingStyleCommsAppData.getMessages()) {
messagingStyle.addMessage(message);
}
- // 2. Set up main Intent for notification
+ // 3. Set up main Intent for notification.
Intent notifyIntent = new Intent(this, MessagingMainActivity.class);
// When creating your Intent, you need to take into account the back state, i.e., what
@@ -692,22 +728,22 @@
);
- // 3. Set up RemoteInput, so users can input (keyboard and voice) from notification
+ // 4. Set up RemoteInput, so users can input (keyboard and voice) from notification.
// Note: For API <24 (M and below) we need to use an Activity, so the lock-screen present
// the auth challenge. For API 24+ (N and above), we use a Service (could be a
// BroadcastReceiver), so the user can input from Notification or lock-screen (they have
// choice to allow) without leaving the notification.
- // Create the RemoteInput specifying this key
+ // Create the RemoteInput specifying this key.
String replyLabel = getString(R.string.reply_label);
RemoteInput remoteInput = new RemoteInput.Builder(MessagingIntentService.EXTRA_REPLY)
.setLabel(replyLabel)
.build();
// Pending intent =
- // API <24 (M and below): activity so the lock-screen presents the auth challenge
- // API 24+ (N and above): this should be a Service or BroadcastReceiver
+ // API <24 (M and below): activity so the lock-screen presents the auth challenge.
+ // API 24+ (N and above): this should be a Service or BroadcastReceiver.
PendingIntent replyActionPendingIntent;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
@@ -725,37 +761,36 @@
replyLabel,
replyActionPendingIntent)
.addRemoteInput(remoteInput)
- // Allows system to generate replies by context of conversation
+ // Allows system to generate replies by context of conversation.
.setAllowGeneratedReplies(true)
.build();
- // 4. Build and issue the notification
+ // 5. Build and issue the notification.
// Because we want this to be a new notification (not updating current notification), we
// create a new Builder. Later, we update this same notification, so we need to save this
// Builder globally (as outlined earlier).
NotificationCompat.Builder notificationCompatBuilder =
- new NotificationCompat.Builder(getApplicationContext());
+ new NotificationCompat.Builder(getApplicationContext(), notificationChannelId);
GlobalNotificationBuilder.setNotificationCompatBuilderInstance(notificationCompatBuilder);
- // Builds and issues notification
notificationCompatBuilder
- // MESSAGING_STYLE sets title and content for API 16 and above devices
+ // MESSAGING_STYLE sets title and content for API 16 and above devices.
.setStyle(messagingStyle)
- // Title for API < 16 devices
+ // Title for API < 16 devices.
.setContentTitle(contentTitle)
- // Content for API < 16 devices
+ // Content for API < 16 devices.
.setContentText(messagingStyleCommsAppData.getContentText())
.setSmallIcon(R.drawable.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(
getResources(),
R.drawable.ic_person_black_48dp))
.setContentIntent(mainPendingIntent)
- // Set primary color (important for Wear 2.0 Notifications)
- .setColor(getResources().getColor(R.color.colorPrimary))
+ // Set primary color (important for Wear 2.0 Notifications).
+ .setColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary))
// SIDE NOTE: Auto-bundling is enabled for 4 or more notifications on API 24+ (N+)
// devices and all Android Wear devices. If you have more than one notification and
@@ -764,15 +799,20 @@
// .setGroupSummary(true)
// .setGroup(GROUP_KEY_YOUR_NAME_HERE)
- // Number of new notifications for API <24 (M and below) devices
+ // Number of new notifications for API <24 (M and below) devices.
.setSubText(Integer.toString(messagingStyleCommsAppData.getNumberOfNewMessages()))
.addAction(replyAction)
.setCategory(Notification.CATEGORY_MESSAGE)
- .setPriority(Notification.PRIORITY_HIGH)
- // Hides content on the lock-screen
- .setVisibility(Notification.VISIBILITY_PRIVATE);
+ // Sets priority for 25 and below. For 26 and above, 'priority' is deprecated for
+ // 'importance' which is set in the NotificationChannel. The integers representing
+ // 'priority' are different from 'importance', so make sure you don't mix them.
+ .setPriority(messagingStyleCommsAppData.getPriority())
+
+ // Sets lock-screen visibility for 25 and below. For 26 and above, lock screen
+ // visibility is set in the NotificationChannel.
+ .setVisibility(messagingStyleCommsAppData.getChannelLockscreenVisibility());
// If the phone is in "Do not disturb mode, the user will still be notified if
// the sender(s) is starred as a favorite.
@@ -794,7 +834,7 @@
* is a bad idea.
*/
private void openNotificationSettingsForApp() {
- // Links to this app's notification settings
+ // Links to this app's notification settings.
Intent intent = new Intent();
intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
intent.putExtra("app_package", getPackageName());
diff --git a/wearable/wear/WearNotifications/Application/src/main/java/com/example/android/wearable/wear/wearnotifications/handlers/BigPictureSocialIntentService.java b/wearable/wear/WearNotifications/Application/src/main/java/com/example/android/wearable/wear/wearnotifications/handlers/BigPictureSocialIntentService.java
index 470eedb..30c970b 100644
--- a/wearable/wear/WearNotifications/Application/src/main/java/com/example/android/wearable/wear/wearnotifications/handlers/BigPictureSocialIntentService.java
+++ b/wearable/wear/WearNotifications/Application/src/main/java/com/example/android/wearable/wear/wearnotifications/handlers/BigPictureSocialIntentService.java
@@ -22,17 +22,17 @@
import android.graphics.BitmapFactory;
import android.os.Build;
import android.os.Bundle;
+import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationCompat.BigPictureStyle;
import android.support.v4.app.NotificationManagerCompat;
import android.support.v4.app.RemoteInput;
import android.support.v4.app.TaskStackBuilder;
-import android.support.v7.app.NotificationCompat;
import android.util.Log;
import com.example.android.wearable.wear.wearnotifications.GlobalNotificationBuilder;
import com.example.android.wearable.wear.wearnotifications.MainActivity;
import com.example.android.wearable.wear.wearnotifications.R;
-import com.example.android.wearable.wear.wearnotifications.mock.MockDatabase;
+import com.example.android.wearable.wear.common.mock.MockDatabase;
/**
* Asynchronously handles updating social app posts (and active Notification) with comments from
diff --git a/wearable/wear/WearNotifications/Application/src/main/java/com/example/android/wearable/wear/wearnotifications/handlers/BigTextIntentService.java b/wearable/wear/WearNotifications/Application/src/main/java/com/example/android/wearable/wear/wearnotifications/handlers/BigTextIntentService.java
index 8f6664d..bfd577c 100644
--- a/wearable/wear/WearNotifications/Application/src/main/java/com/example/android/wearable/wear/wearnotifications/handlers/BigTextIntentService.java
+++ b/wearable/wear/WearNotifications/Application/src/main/java/com/example/android/wearable/wear/wearnotifications/handlers/BigTextIntentService.java
@@ -20,15 +20,15 @@
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.BitmapFactory;
+import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationCompat.BigTextStyle;
import android.support.v4.app.NotificationManagerCompat;
-import android.support.v7.app.NotificationCompat;
import android.util.Log;
import com.example.android.wearable.wear.wearnotifications.GlobalNotificationBuilder;
import com.example.android.wearable.wear.wearnotifications.MainActivity;
import com.example.android.wearable.wear.wearnotifications.R;
-import com.example.android.wearable.wear.wearnotifications.mock.MockDatabase;
+import com.example.android.wearable.wear.common.mock.MockDatabase;
import java.util.concurrent.TimeUnit;
diff --git a/wearable/wear/WearNotifications/Application/src/main/java/com/example/android/wearable/wear/wearnotifications/handlers/MessagingIntentService.java b/wearable/wear/WearNotifications/Application/src/main/java/com/example/android/wearable/wear/wearnotifications/handlers/MessagingIntentService.java
index 6d30c4f..da56242 100644
--- a/wearable/wear/WearNotifications/Application/src/main/java/com/example/android/wearable/wear/wearnotifications/handlers/MessagingIntentService.java
+++ b/wearable/wear/WearNotifications/Application/src/main/java/com/example/android/wearable/wear/wearnotifications/handlers/MessagingIntentService.java
@@ -22,17 +22,18 @@
import android.graphics.BitmapFactory;
import android.os.Build;
import android.os.Bundle;
+import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationCompat.MessagingStyle;
import android.support.v4.app.NotificationManagerCompat;
import android.support.v4.app.RemoteInput;
import android.support.v4.app.TaskStackBuilder;
-import android.support.v7.app.NotificationCompat;
+import android.support.v4.content.ContextCompat;
import android.util.Log;
import com.example.android.wearable.wear.wearnotifications.GlobalNotificationBuilder;
import com.example.android.wearable.wear.wearnotifications.MainActivity;
import com.example.android.wearable.wear.wearnotifications.R;
-import com.example.android.wearable.wear.wearnotifications.mock.MockDatabase;
+import com.example.android.wearable.wear.common.mock.MockDatabase;
/**
* Asynchronously handles updating messaging app posts (and active Notification) with replies from
@@ -144,49 +145,38 @@
private NotificationCompat.Builder recreateBuilderWithMessagingStyle() {
// Main steps for building a MESSAGING_STYLE notification (for more detailed comments on
- // building this notification, check MainActivity.java)::
+ // building this notification, check MainActivity.java):
// 0. Get your data
- // 1. Build the MESSAGING_STYLE
- // 2. Add support for Wear 1.+
+ // 1. Retrieve Notification Channel for O and beyond devices (26+)
+ // 2. Build the MESSAGING_STYLE
// 3. Set up main Intent for notification
// 4. Set up RemoteInput (users can input directly from notification)
// 5. Build and issue the notification
- // 0. Get your data
+ // 0. Get your data.
MockDatabase.MessagingStyleCommsAppData messagingData =
MockDatabase.getMessagingStyleData();
- // 1. Build the Notification.Style (MESSAGING_STYLE)
+ // 1. Retrieve Notification Channel for O and beyond devices (26+). We don't need to create
+ // the NotificationChannel, since it was created the first time this Notification was
+ // created.
+ String notificationChannelId = messagingData.getChannelId();
+
+ // 2. Build the Notification.Style (MESSAGING_STYLE).
String contentTitle = messagingData.getContentTitle();
MessagingStyle messagingStyle =
new NotificationCompat.MessagingStyle(messagingData.getReplayName())
.setConversationTitle(contentTitle);
- // Adds all Messages
- // Note: Messages include the text, timestamp, and sender
+ // Adds all Messages.
+ // Note: Messages include the text, timestamp, and sender.
for (MessagingStyle.Message message : messagingData.getMessages()) {
messagingStyle.addMessage(message);
}
- // 2. Add support for Wear 1.+
- String fullMessageForWearVersion1 = messagingData.getFullConversation();
-
- Notification chatHistoryForWearV1 = new NotificationCompat.Builder(getApplicationContext())
- .setStyle(new NotificationCompat.BigTextStyle().bigText(fullMessageForWearVersion1))
- .setContentTitle(contentTitle)
- .setSmallIcon(R.drawable.ic_launcher)
- .setContentText(fullMessageForWearVersion1)
- .build();
-
- NotificationCompat.WearableExtender wearableExtenderForWearVersion1 =
- new NotificationCompat.WearableExtender()
- .addPage(chatHistoryForWearV1);
-
-
-
- // 3. Set up main Intent for notification
+ // 3. Set up main Intent for notification.
Intent notifyIntent = new Intent(this, MessagingMainActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
@@ -202,7 +192,7 @@
);
- // 4. Set up RemoteInput, so users can input (keyboard and voice) from notification
+ // 4. Set up RemoteInput, so users can input (keyboard and voice) from notification.
String replyLabel = getString(R.string.reply_label);
RemoteInput remoteInput = new RemoteInput.Builder(MessagingIntentService.EXTRA_REPLY)
.setLabel(replyLabel)
@@ -225,14 +215,17 @@
replyLabel,
replyActionPendingIntent)
.addRemoteInput(remoteInput)
- // Allows system to generate replies by context of conversation
+ // Allows system to generate replies by context of conversation.
.setAllowGeneratedReplies(true)
.build();
- // 5. Build and issue the notification
+ // 5. Build and issue the notification.
+
+ // Notification Channel Id is ignored for Android pre O (26).
NotificationCompat.Builder notificationCompatBuilder =
- new NotificationCompat.Builder(getApplicationContext());
+ new NotificationCompat.Builder(
+ getApplicationContext(), notificationChannelId);
GlobalNotificationBuilder.setNotificationCompatBuilderInstance(notificationCompatBuilder);
@@ -245,13 +238,12 @@
getResources(),
R.drawable.ic_person_black_48dp))
.setContentIntent(mainPendingIntent)
- .setColor(getResources().getColor(R.color.colorPrimary))
+ .setColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary))
.setSubText(Integer.toString(messagingData.getNumberOfNewMessages()))
.addAction(replyAction)
.setCategory(Notification.CATEGORY_MESSAGE)
- .setPriority(Notification.PRIORITY_HIGH)
- .setVisibility(Notification.VISIBILITY_PRIVATE)
- .extend(wearableExtenderForWearVersion1);
+ .setPriority(messagingData.getPriority())
+ .setVisibility(messagingData.getChannelLockscreenVisibility());
for (String name : messagingData.getParticipants()) {
notificationCompatBuilder.addPerson(name);
diff --git a/wearable/wear/WearNotifications/Application/src/main/res/drawable-hdpi/earth.png b/wearable/wear/WearNotifications/Application/src/main/res/drawable-hdpi/earth.png
deleted file mode 100644
index 13abd77..0000000
--- a/wearable/wear/WearNotifications/Application/src/main/res/drawable-hdpi/earth.png
+++ /dev/null
Binary files differ
diff --git a/wearable/wear/WearNotifications/Application/src/main/res/drawable-hdpi/ic_alarm_white_48dp.png b/wearable/wear/WearNotifications/Application/src/main/res/drawable-hdpi/ic_alarm_white_48dp.png
deleted file mode 100644
index 75e5a46..0000000
--- a/wearable/wear/WearNotifications/Application/src/main/res/drawable-hdpi/ic_alarm_white_48dp.png
+++ /dev/null
Binary files differ
diff --git a/wearable/wear/WearNotifications/Application/src/main/res/drawable-hdpi/ic_cancel_white_48dp.png b/wearable/wear/WearNotifications/Application/src/main/res/drawable-hdpi/ic_cancel_white_48dp.png
deleted file mode 100644
index dc32a14..0000000
--- a/wearable/wear/WearNotifications/Application/src/main/res/drawable-hdpi/ic_cancel_white_48dp.png
+++ /dev/null
Binary files differ
diff --git a/wearable/wear/WearNotifications/Application/src/main/res/drawable-hdpi/ic_message_black_18dp.png b/wearable/wear/WearNotifications/Application/src/main/res/drawable-hdpi/ic_message_black_18dp.png
deleted file mode 100644
index d921ba2..0000000
--- a/wearable/wear/WearNotifications/Application/src/main/res/drawable-hdpi/ic_message_black_18dp.png
+++ /dev/null
Binary files differ
diff --git a/wearable/wear/WearNotifications/Application/src/main/res/drawable-hdpi/ic_person_black_48dp.png b/wearable/wear/WearNotifications/Application/src/main/res/drawable-hdpi/ic_person_black_48dp.png
deleted file mode 100644
index f1e1484..0000000
--- a/wearable/wear/WearNotifications/Application/src/main/res/drawable-hdpi/ic_person_black_48dp.png
+++ /dev/null
Binary files differ
diff --git a/wearable/wear/WearNotifications/Application/src/main/res/drawable-hdpi/ic_reply_white_18dp.png b/wearable/wear/WearNotifications/Application/src/main/res/drawable-hdpi/ic_reply_white_18dp.png
deleted file mode 100644
index cc732ba..0000000
--- a/wearable/wear/WearNotifications/Application/src/main/res/drawable-hdpi/ic_reply_white_18dp.png
+++ /dev/null
Binary files differ
diff --git a/wearable/wear/WearNotifications/Application/src/main/res/drawable-mdpi/ic_alarm_white_48dp.png b/wearable/wear/WearNotifications/Application/src/main/res/drawable-mdpi/ic_alarm_white_48dp.png
deleted file mode 100644
index 280e09d..0000000
--- a/wearable/wear/WearNotifications/Application/src/main/res/drawable-mdpi/ic_alarm_white_48dp.png
+++ /dev/null
Binary files differ
diff --git a/wearable/wear/WearNotifications/Application/src/main/res/drawable-mdpi/ic_cancel_white_48dp.png b/wearable/wear/WearNotifications/Application/src/main/res/drawable-mdpi/ic_cancel_white_48dp.png
deleted file mode 100644
index 6ebbc83..0000000
--- a/wearable/wear/WearNotifications/Application/src/main/res/drawable-mdpi/ic_cancel_white_48dp.png
+++ /dev/null
Binary files differ
diff --git a/wearable/wear/WearNotifications/Application/src/main/res/drawable-mdpi/ic_message_black_18dp.png b/wearable/wear/WearNotifications/Application/src/main/res/drawable-mdpi/ic_message_black_18dp.png
deleted file mode 100644
index 2156f16..0000000
--- a/wearable/wear/WearNotifications/Application/src/main/res/drawable-mdpi/ic_message_black_18dp.png
+++ /dev/null
Binary files differ
diff --git a/wearable/wear/WearNotifications/Application/src/main/res/drawable-mdpi/ic_person_black_48dp.png b/wearable/wear/WearNotifications/Application/src/main/res/drawable-mdpi/ic_person_black_48dp.png
deleted file mode 100644
index 360a32f..0000000
--- a/wearable/wear/WearNotifications/Application/src/main/res/drawable-mdpi/ic_person_black_48dp.png
+++ /dev/null
Binary files differ
diff --git a/wearable/wear/WearNotifications/Application/src/main/res/drawable-mdpi/ic_reply_white_18dp.png b/wearable/wear/WearNotifications/Application/src/main/res/drawable-mdpi/ic_reply_white_18dp.png
deleted file mode 100644
index b336e2f..0000000
--- a/wearable/wear/WearNotifications/Application/src/main/res/drawable-mdpi/ic_reply_white_18dp.png
+++ /dev/null
Binary files differ
diff --git a/wearable/wear/WearNotifications/Application/src/main/res/drawable-xhdpi/ic_alarm_white_48dp.png b/wearable/wear/WearNotifications/Application/src/main/res/drawable-xhdpi/ic_alarm_white_48dp.png
deleted file mode 100644
index aa8102f..0000000
--- a/wearable/wear/WearNotifications/Application/src/main/res/drawable-xhdpi/ic_alarm_white_48dp.png
+++ /dev/null
Binary files differ
diff --git a/wearable/wear/WearNotifications/Application/src/main/res/drawable-xhdpi/ic_cancel_white_48dp.png b/wearable/wear/WearNotifications/Application/src/main/res/drawable-xhdpi/ic_cancel_white_48dp.png
deleted file mode 100644
index dc775b2..0000000
--- a/wearable/wear/WearNotifications/Application/src/main/res/drawable-xhdpi/ic_cancel_white_48dp.png
+++ /dev/null
Binary files differ
diff --git a/wearable/wear/WearNotifications/Application/src/main/res/drawable-xhdpi/ic_message_black_18dp.png b/wearable/wear/WearNotifications/Application/src/main/res/drawable-xhdpi/ic_message_black_18dp.png
deleted file mode 100644
index 185d613..0000000
--- a/wearable/wear/WearNotifications/Application/src/main/res/drawable-xhdpi/ic_message_black_18dp.png
+++ /dev/null
Binary files differ
diff --git a/wearable/wear/WearNotifications/Application/src/main/res/drawable-xhdpi/ic_person_black_48dp.png b/wearable/wear/WearNotifications/Application/src/main/res/drawable-xhdpi/ic_person_black_48dp.png
deleted file mode 100644
index 1ebc37b..0000000
--- a/wearable/wear/WearNotifications/Application/src/main/res/drawable-xhdpi/ic_person_black_48dp.png
+++ /dev/null
Binary files differ
diff --git a/wearable/wear/WearNotifications/Application/src/main/res/drawable-xhdpi/ic_reply_white_18dp.png b/wearable/wear/WearNotifications/Application/src/main/res/drawable-xhdpi/ic_reply_white_18dp.png
deleted file mode 100644
index 0424c2b..0000000
--- a/wearable/wear/WearNotifications/Application/src/main/res/drawable-xhdpi/ic_reply_white_18dp.png
+++ /dev/null
Binary files differ
diff --git a/wearable/wear/WearNotifications/Application/src/main/res/drawable-xxxhdpi/ic_alarm_white_48dp.png b/wearable/wear/WearNotifications/Application/src/main/res/drawable-xxxhdpi/ic_alarm_white_48dp.png
deleted file mode 100644
index 419f4bb..0000000
--- a/wearable/wear/WearNotifications/Application/src/main/res/drawable-xxxhdpi/ic_alarm_white_48dp.png
+++ /dev/null
Binary files differ
diff --git a/wearable/wear/WearNotifications/Application/src/main/res/drawable-xxxhdpi/ic_cancel_white_48dp.png b/wearable/wear/WearNotifications/Application/src/main/res/drawable-xxxhdpi/ic_cancel_white_48dp.png
deleted file mode 100644
index 8bea844..0000000
--- a/wearable/wear/WearNotifications/Application/src/main/res/drawable-xxxhdpi/ic_cancel_white_48dp.png
+++ /dev/null
Binary files differ
diff --git a/wearable/wear/WearNotifications/Application/src/main/res/drawable-xxxhdpi/ic_message_black_18dp.png b/wearable/wear/WearNotifications/Application/src/main/res/drawable-xxxhdpi/ic_message_black_18dp.png
deleted file mode 100644
index 5456c42..0000000
--- a/wearable/wear/WearNotifications/Application/src/main/res/drawable-xxxhdpi/ic_message_black_18dp.png
+++ /dev/null
Binary files differ
diff --git a/wearable/wear/WearNotifications/Application/src/main/res/drawable-xxxhdpi/ic_person_black_48dp.png b/wearable/wear/WearNotifications/Application/src/main/res/drawable-xxxhdpi/ic_person_black_48dp.png
deleted file mode 100644
index 6be3e30..0000000
--- a/wearable/wear/WearNotifications/Application/src/main/res/drawable-xxxhdpi/ic_person_black_48dp.png
+++ /dev/null
Binary files differ
diff --git a/wearable/wear/WearNotifications/Application/src/main/res/drawable-xxxhdpi/ic_reply_white_18dp.png b/wearable/wear/WearNotifications/Application/src/main/res/drawable-xxxhdpi/ic_reply_white_18dp.png
deleted file mode 100644
index de0dad2..0000000
--- a/wearable/wear/WearNotifications/Application/src/main/res/drawable-xxxhdpi/ic_reply_white_18dp.png
+++ /dev/null
Binary files differ
diff --git a/wearable/wear/WearNotifications/Shared/.gitignore b/wearable/wear/WearNotifications/Shared/.gitignore
new file mode 100644
index 0000000..6eb878d
--- /dev/null
+++ b/wearable/wear/WearNotifications/Shared/.gitignore
@@ -0,0 +1,16 @@
+# Copyright 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.
+src/template/
+src/common/
+build.gradle
diff --git a/wearable/wear/SpeedTracker/Wearable/build.gradle b/wearable/wear/WearNotifications/Shared/build.gradle
similarity index 63%
rename from wearable/wear/SpeedTracker/Wearable/build.gradle
rename to wearable/wear/WearNotifications/Shared/build.gradle
index 472738b..0970e28 100644
--- a/wearable/wear/SpeedTracker/Wearable/build.gradle
+++ b/wearable/wear/WearNotifications/Shared/build.gradle
@@ -9,7 +9,7 @@
}
}
-apply plugin: 'com.android.application'
+apply plugin: 'android-library'
repositories {
jcenter()
@@ -19,16 +19,7 @@
}
dependencies {
- compile 'com.android.support:wear:26.0.0'
- compile 'com.google.android.gms:play-services-location:10.2.4'
- compile 'com.google.android.gms:play-services-wearable:10.2.4'
- compile 'com.android.support:support-v13:25.3.1'
-
- provided 'com.google.android.wearable:wearable:2.0.3'
-
- compile 'com.google.android.support:wearable:2.0.3'
-
- compile project(':Shared')
+ compile 'com.android.support:support-v4:26.0.0'
}
// The sample build uses multiple directories to
@@ -40,21 +31,13 @@
'template'] // boilerplate code that is generated by the sample template process
android {
-
compileSdkVersion 26
buildToolsVersion "25.0.3"
defaultConfig {
- versionCode 1
- versionName "1.0"
-
- minSdkVersion 23
-
+ minSdkVersion 18
targetSdkVersion 26
-
- multiDexEnabled true
-
}
compileOptions {
@@ -69,8 +52,6 @@
res.srcDirs "src/${dir}/res"
}
}
- androidTest.setRoot('tests')
- androidTest.java.srcDirs = ['tests/src']
}
}
diff --git a/wearable/wear/WearNotifications/Shared/src/main/AndroidManifest.xml b/wearable/wear/WearNotifications/Shared/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..0f49418
--- /dev/null
+++ b/wearable/wear/WearNotifications/Shared/src/main/AndroidManifest.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright 2017 Google Inc. All rights reserved.
+ 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.
+ -->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.wearable.wear.wearnotifications.common">
+
+ <application android:allowBackup="true" android:label="@string/app_name">
+
+ </application>
+
+</manifest>
diff --git a/wearable/wear/WearNotifications/Application/src/main/java/com/example/android/wearable/wear/wearnotifications/mock/MockDatabase.java b/wearable/wear/WearNotifications/Shared/src/main/java/com/example/android/wearable/wear/common/mock/MockDatabase.java
similarity index 62%
rename from wearable/wear/WearNotifications/Application/src/main/java/com/example/android/wearable/wear/wearnotifications/mock/MockDatabase.java
rename to wearable/wear/WearNotifications/Shared/src/main/java/com/example/android/wearable/wear/common/mock/MockDatabase.java
index b552f6d..de25111 100644
--- a/wearable/wear/WearNotifications/Application/src/main/java/com/example/android/wearable/wear/wearnotifications/mock/MockDatabase.java
+++ b/wearable/wear/WearNotifications/Shared/src/main/java/com/example/android/wearable/wear/common/mock/MockDatabase.java
@@ -1,8 +1,25 @@
-package com.example.android.wearable.wear.wearnotifications.mock;
+/*
+ * Copyright (C) 2017 Google Inc. All Rights Reserved.
+ *
+ * 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.example.android.wearable.wear.common.mock;
+import android.app.NotificationManager;
+import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationCompat.MessagingStyle;
-import com.example.android.wearable.wear.wearnotifications.R;
+import com.example.android.wearable.wear.wearnotifications.common.R;
import java.util.ArrayList;
@@ -30,20 +47,15 @@
/**
* Represents data needed for BigTextStyle Notification.
*/
- public static class BigTextStyleReminderAppData {
+ public static class BigTextStyleReminderAppData extends MockNotificationData {
private static BigTextStyleReminderAppData sInstance = null;
- // Standard notification values
- private String mContentTitle;
- private String mContentText;
-
- // Style notification values
+ // Unique data for this Notification.Style:
private String mBigContentTitle;
private String mBigText;
private String mSummaryText;
-
public static BigTextStyleReminderAppData getInstance() {
if (sInstance == null) {
sInstance = getSync();
@@ -61,24 +73,30 @@
}
private BigTextStyleReminderAppData() {
- // Standard Notification values
- // Title for API <16 (4.0 and below) devices
- mContentTitle = "Don't forget to...";
- // Content for API <24 (4.0 and below) devices
- mContentText = "Feed Dogs and check garage!";
- // BigText Style Notification values
+ // Standard Notification values:
+ // Title for API <16 (4.0 and below) devices.
+ mContentTitle = "Don't forget to...";
+ // Content for API <24 (4.0 and below) devices.
+ mContentText = "Feed Dogs and check garage!";
+ mPriority = NotificationCompat.PRIORITY_DEFAULT;
+
+ // BigText Style Notification values:
mBigContentTitle = "Don't forget to...";
mBigText = "... feed the dogs before you leave for work, and check the garage to "
- + "make sure the door is closed.";
+ + "make sure the door is closed.";
mSummaryText = "Dogs and Garage";
- }
- public String getContentTitle() {
- return mContentTitle;
- }
- public String getContentText() {
- return mContentText;
+
+ // Notification channel values (for devices targeting 26 and above):
+ mChannelId = "channel_reminder_1";
+ // The user-visible name of the channel.
+ mChannelName = "Sample Reminder";
+ // The user-visible description of the channel.
+ mChannelDescription = "Sample Reminder Notifications";
+ mChannelImportance = NotificationManager.IMPORTANCE_DEFAULT;
+ mChannelEnableVibrate = false;
+ mChannelLockscreenVisibility = NotificationCompat.VISIBILITY_PUBLIC;
}
public String getBigContentTitle() {
@@ -102,14 +120,11 @@
/**
* Represents data needed for BigPictureStyle Notification.
*/
- public static class BigPictureStyleSocialAppData {
+ public static class BigPictureStyleSocialAppData extends MockNotificationData {
+
private static BigPictureStyleSocialAppData sInstance = null;
- // Standard notification values
- private String mContentTitle;
- private String mContentText;
-
- // Style notification values
+ // Unique data for this Notification.Style:
private int mBigImage;
private String mBigContentTitle;
private String mSummaryText;
@@ -118,7 +133,6 @@
private ArrayList<String> mParticipants;
-
public static BigPictureStyleSocialAppData getInstance() {
if (sInstance == null) {
sInstance = getSync();
@@ -135,29 +149,32 @@
}
private BigPictureStyleSocialAppData() {
- // Standard Notification values
- // Title/Content for API <16 (4.0 and below) devices
+ // Standard Notification values:
+ // Title/Content for API <16 (4.0 and below) devices.
mContentTitle = "Bob's Post";
mContentText = "[Picture] Like my shot of Earth?";
+ mPriority = NotificationCompat.PRIORITY_HIGH;
- // Style notification values
+ // Style notification values:
mBigImage = R.drawable.earth;
mBigContentTitle = "Bob's Post";
mSummaryText = "Like my shot of Earth?";
- // This would be possible responses based on the contents of the post
+ // This would be possible responses based on the contents of the post.
mPossiblePostResponses = new CharSequence[]{"Yes", "No", "Maybe?"};
mParticipants = new ArrayList<>();
mParticipants.add("Bob Smith");
- }
- public String getContentTitle() {
- return mContentTitle;
- }
-
- public String getContentText() {
- return mContentText;
+ // Notification channel values (for devices targeting 26 and above):
+ mChannelId = "channel_social_1";
+ // The user-visible name of the channel.
+ mChannelName = "Sample Social";
+ // The user-visible description of the channel.
+ mChannelDescription = "Sample Social Notifications";
+ mChannelImportance = NotificationManager.IMPORTANCE_HIGH;
+ mChannelEnableVibrate = true;
+ mChannelLockscreenVisibility = NotificationCompat.VISIBILITY_PRIVATE;
}
public int getBigImage() {
@@ -189,15 +206,12 @@
/**
* Represents data needed for InboxStyle Notification.
*/
- public static class InboxStyleEmailAppData {
+ public static class InboxStyleEmailAppData extends MockNotificationData {
+
private static InboxStyleEmailAppData sInstance = null;
- // Standard notification values
- private String mContentTitle;
- private String mContentText;
+ // Unique data for this Notification.Style:
private int mNumberOfNewEmails;
-
- // Style notification values
private String mBigContentTitle;
private String mSummaryText;
private ArrayList<String> mIndividualEmailSummary;
@@ -220,17 +234,18 @@
}
private InboxStyleEmailAppData() {
- // Standard Notification values
- // Title/Content for API <16 (4.0 and below) devices
+ // Standard Notification values:
+ // Title/Content for API <16 (4.0 and below) devices.
mContentTitle = "5 new emails";
mContentText = "from Jane, Jay, Alex +2 more";
mNumberOfNewEmails = 5;
+ mPriority = NotificationCompat.PRIORITY_DEFAULT;
- // Style notification values
+ // Style notification values:
mBigContentTitle = "5 new emails from Jane, Jay, Alex +2";
mSummaryText = "New emails";
- // Add each summary line of the new emails, you can add up to 5
+ // Add each summary line of the new emails, you can add up to 5.
mIndividualEmailSummary = new ArrayList<>();
mIndividualEmailSummary.add("Jane Faab - Launch Party is here...");
mIndividualEmailSummary.add("Jay Walker - There's a turtle on the server!");
@@ -246,14 +261,17 @@
mParticipants.add("Alex Chang");
mParticipants.add("Jane Johns");
mParticipants.add("John Smith");
- }
- public String getContentTitle() {
- return mContentTitle;
- }
- public String getContentText() {
- return mContentText;
+ // Notification channel values (for devices targeting 26 and above):
+ mChannelId = "channel_email_1";
+ // The user-visible name of the channel.
+ mChannelName = "Sample Email";
+ // The user-visible description of the channel.
+ mChannelDescription = "Sample Email Notifications";
+ mChannelImportance = NotificationManager.IMPORTANCE_DEFAULT;
+ mChannelEnableVibrate = true;
+ mChannelLockscreenVisibility = NotificationCompat.VISIBILITY_PRIVATE;
}
public int getNumberOfNewEmails() {
@@ -285,23 +303,20 @@
/**
* Represents data needed for MessagingStyle Notification.
*/
- public static class MessagingStyleCommsAppData {
+ public static class MessagingStyleCommsAppData extends MockNotificationData {
private static MessagingStyleCommsAppData sInstance = null;
- // Standard notification values
- private String mContentTitle;
- private String mContentText;
-
- // Style notification values
+ // Unique data for this Notification.Style:
private ArrayList<MessagingStyle.Message> mMessages;
- // Basically, String of all mMessages
+ // String of all mMessages.
private String mFullConversation;
- // Name preferred when replying to chat
+ // Name preferred when replying to chat.
private String mReplayName;
private int mNumberOfNewMessages;
private ArrayList<String> mParticipants;
+
public static MessagingStyleCommsAppData getInstance() {
if (sInstance == null) {
sInstance = getSync();
@@ -318,12 +333,11 @@
}
private MessagingStyleCommsAppData() {
- // Standard notification values
- // Content for API <24 (M and below) devices
+ // Standard notification values:
+ // Content for API <24 (M and below) devices.
mContentTitle = "2 Messages w/ Famous McFamously";
- mContentText = "Dude! ... You know I am a Pesce-pescetarian. :P";
-
- // Style notification values
+ mContentText = "HEY! ... You know I am a Pesce-pescetarian. :P";
+ mPriority = NotificationCompat.PRIORITY_HIGH;
// For each message, you need the timestamp, in this case, we are using arbitrary ones.
long currentTime = System.currentTimeMillis();
@@ -337,24 +351,24 @@
"Sounds good.", currentTime - 2000, "Famous"));
mMessages.add(new MessagingStyle.Message(
"How about BBQ?", currentTime - 1000, null));
- // Last two are the newest message (2) from friend
+ // Last two are the newest message (2) from friend.
mMessages.add(new MessagingStyle.Message(
- "Dude!", currentTime, "Famous"));
+ "HEY!", currentTime, "Famous"));
mMessages.add(new MessagingStyle.Message(
"You know I am a Pesce-pescetarian. :P", currentTime, "Famous"));
- // String version of the mMessages above
+ // String version of the mMessages above.
mFullConversation = "Famous: What are you doing tonight?\n\n"
+ "Me: I don't know, dinner maybe?\n\n"
+ "Famous: Sounds good.\n\n"
+ "Me: How about BBQ?\n\n"
- + "Famous: Dude!\n\n"
+ + "Famous: HEY!\n\n"
+ "Famous: You know I am a Pesce-pescetarian. :P\n\n";
mNumberOfNewMessages = 2;
- // Name preferred when replying to chat
+ // Name preferred when replying to chat.
mReplayName = "Me";
// If the phone is in "Do not disturb mode, the user will still be notified if
@@ -362,14 +376,17 @@
mParticipants = new ArrayList<>();
mParticipants.add("Famous McFamously");
- }
- public String getContentTitle() {
- return mContentTitle;
- }
+ // Notification channel values (for devices targeting 26 and above):
+ mChannelId = "channel_messaging_1";
+ // The user-visible name of the channel.
+ mChannelName = "Sample Messaging";
+ // The user-visible description of the channel.
+ mChannelDescription = "Sample Messaging Notifications";
+ mChannelImportance = NotificationManager.IMPORTANCE_MAX;
+ mChannelEnableVibrate = true;
+ mChannelLockscreenVisibility = NotificationCompat.VISIBILITY_PRIVATE;
- public String getContentText() {
- return mContentText;
}
public ArrayList<MessagingStyle.Message> getMessages() {
@@ -396,5 +413,65 @@
public String toString() {
return getFullConversation();
}
+
+
+ }
+
+ /**
+ * Represents standard data needed for a Notification.
+ */
+ public static abstract class MockNotificationData {
+
+ // Standard notification values:
+ protected String mContentTitle;
+ protected String mContentText;
+ protected int mPriority;
+
+ // Notification channel values (O and above):
+ protected String mChannelId;
+ protected CharSequence mChannelName;
+ protected String mChannelDescription;
+ protected int mChannelImportance;
+ protected boolean mChannelEnableVibrate;
+ protected int mChannelLockscreenVisibility;
+
+
+ // Notification Standard notification get methods:
+ public String getContentTitle() {
+ return mContentTitle;
+ }
+
+ public String getContentText() {
+ return mContentText;
+ }
+
+ public int getPriority() {
+ return mPriority;
+ }
+
+ // Channel values (O and above) get methods:
+ public String getChannelId() {
+ return mChannelId;
+ }
+
+ public CharSequence getChannelName() {
+ return mChannelName;
+ }
+
+ public String getChannelDescription() {
+ return mChannelDescription;
+ }
+
+ public int getChannelImportance() {
+ return mChannelImportance;
+ }
+
+ public boolean isChannelEnableVibrate() {
+ return mChannelEnableVibrate;
+ }
+
+ public int getChannelLockscreenVisibility() {
+ return mChannelLockscreenVisibility;
+ }
}
}
\ No newline at end of file
diff --git a/wearable/wear/WearNotifications/Shared/src/main/java/com/example/android/wearable/wear/common/util/NotificationUtil.java b/wearable/wear/WearNotifications/Shared/src/main/java/com/example/android/wearable/wear/common/util/NotificationUtil.java
new file mode 100644
index 0000000..7db1504
--- /dev/null
+++ b/wearable/wear/WearNotifications/Shared/src/main/java/com/example/android/wearable/wear/common/util/NotificationUtil.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2017 Google Inc. All Rights Reserved.
+ *
+ * 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.example.android.wearable.wear.common.util;
+
+import android.app.Notification;
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.content.Context;
+import android.os.Build;
+
+import com.example.android.wearable.wear.common.mock.MockDatabase;
+
+/**
+ * Simplifies common {@link Notification} tasks.
+ */
+public class NotificationUtil {
+
+ public static String createNotificationChannel(
+ Context context,
+ MockDatabase.MockNotificationData mockNotificationData) {
+
+ // NotificationChannels are required for Notifications on O (API 26) and above.
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+
+ // The id of the channel.
+ String channelId = mockNotificationData.getChannelId();
+
+ // The user-visible name of the channel.
+ CharSequence channelName = mockNotificationData.getChannelName();
+ // The user-visible description of the channel.
+ String channelDescription = mockNotificationData.getChannelDescription();
+ int channelImportance = mockNotificationData.getChannelImportance();
+ boolean channelEnableVibrate = mockNotificationData.isChannelEnableVibrate();
+ int channelLockscreenVisibility =
+ mockNotificationData.getChannelLockscreenVisibility();
+
+ // Initializes NotificationChannel.
+ NotificationChannel notificationChannel =
+ new NotificationChannel(channelId, channelName, channelImportance);
+ notificationChannel.setDescription(channelDescription);
+ notificationChannel.enableVibration(channelEnableVibrate);
+ notificationChannel.setLockscreenVisibility(channelLockscreenVisibility);
+
+ // Adds NotificationChannel to system. Attempting to create an existing notification
+ // channel with its original values performs no operation, so it's safe to perform the
+ // below sequence.
+ NotificationManager notificationManager =
+ (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
+ notificationManager.createNotificationChannel(notificationChannel);
+
+ return channelId;
+ } else {
+ // Returns null for pre-O (26) devices.
+ return null;
+ }
+ }
+}
diff --git a/wearable/wear/WearNotifications/Wearable/src/main/res/drawable-hdpi/earth.png b/wearable/wear/WearNotifications/Shared/src/main/res/drawable-hdpi/earth.png
similarity index 100%
rename from wearable/wear/WearNotifications/Wearable/src/main/res/drawable-hdpi/earth.png
rename to wearable/wear/WearNotifications/Shared/src/main/res/drawable-hdpi/earth.png
Binary files differ
diff --git a/wearable/wear/WearNotifications/Wearable/src/main/res/drawable-hdpi/ic_alarm_white_48dp.png b/wearable/wear/WearNotifications/Shared/src/main/res/drawable-hdpi/ic_alarm_white_48dp.png
similarity index 100%
rename from wearable/wear/WearNotifications/Wearable/src/main/res/drawable-hdpi/ic_alarm_white_48dp.png
rename to wearable/wear/WearNotifications/Shared/src/main/res/drawable-hdpi/ic_alarm_white_48dp.png
Binary files differ
diff --git a/wearable/wear/WearNotifications/Wearable/src/main/res/drawable-hdpi/ic_cancel_white_48dp.png b/wearable/wear/WearNotifications/Shared/src/main/res/drawable-hdpi/ic_cancel_white_48dp.png
similarity index 100%
rename from wearable/wear/WearNotifications/Wearable/src/main/res/drawable-hdpi/ic_cancel_white_48dp.png
rename to wearable/wear/WearNotifications/Shared/src/main/res/drawable-hdpi/ic_cancel_white_48dp.png
Binary files differ
diff --git a/wearable/wear/WearNotifications/Shared/src/main/res/drawable-hdpi/ic_launcher.png b/wearable/wear/WearNotifications/Shared/src/main/res/drawable-hdpi/ic_launcher.png
new file mode 100644
index 0000000..0ed1b5f
--- /dev/null
+++ b/wearable/wear/WearNotifications/Shared/src/main/res/drawable-hdpi/ic_launcher.png
Binary files differ
diff --git a/wearable/wear/WearNotifications/Wearable/src/main/res/drawable-hdpi/ic_message_black_18dp.png b/wearable/wear/WearNotifications/Shared/src/main/res/drawable-hdpi/ic_message_black_18dp.png
similarity index 100%
rename from wearable/wear/WearNotifications/Wearable/src/main/res/drawable-hdpi/ic_message_black_18dp.png
rename to wearable/wear/WearNotifications/Shared/src/main/res/drawable-hdpi/ic_message_black_18dp.png
Binary files differ
diff --git a/wearable/wear/WearNotifications/Wearable/src/main/res/drawable-hdpi/ic_n_white_48dp.png b/wearable/wear/WearNotifications/Shared/src/main/res/drawable-hdpi/ic_n_white_48dp.png
similarity index 100%
rename from wearable/wear/WearNotifications/Wearable/src/main/res/drawable-hdpi/ic_n_white_48dp.png
rename to wearable/wear/WearNotifications/Shared/src/main/res/drawable-hdpi/ic_n_white_48dp.png
Binary files differ
diff --git a/wearable/wear/WearNotifications/Wearable/src/main/res/drawable-hdpi/ic_person_black_48dp.png b/wearable/wear/WearNotifications/Shared/src/main/res/drawable-hdpi/ic_person_black_48dp.png
similarity index 100%
rename from wearable/wear/WearNotifications/Wearable/src/main/res/drawable-hdpi/ic_person_black_48dp.png
rename to wearable/wear/WearNotifications/Shared/src/main/res/drawable-hdpi/ic_person_black_48dp.png
Binary files differ
diff --git a/wearable/wear/WearNotifications/Wearable/src/main/res/drawable-hdpi/ic_reply_white_18dp.png b/wearable/wear/WearNotifications/Shared/src/main/res/drawable-hdpi/ic_reply_white_18dp.png
similarity index 100%
rename from wearable/wear/WearNotifications/Wearable/src/main/res/drawable-hdpi/ic_reply_white_18dp.png
rename to wearable/wear/WearNotifications/Shared/src/main/res/drawable-hdpi/ic_reply_white_18dp.png
Binary files differ
diff --git a/wearable/wear/WearNotifications/Wearable/src/main/res/drawable-mdpi/ic_alarm_white_48dp.png b/wearable/wear/WearNotifications/Shared/src/main/res/drawable-mdpi/ic_alarm_white_48dp.png
similarity index 100%
rename from wearable/wear/WearNotifications/Wearable/src/main/res/drawable-mdpi/ic_alarm_white_48dp.png
rename to wearable/wear/WearNotifications/Shared/src/main/res/drawable-mdpi/ic_alarm_white_48dp.png
Binary files differ
diff --git a/wearable/wear/WearNotifications/Wearable/src/main/res/drawable-mdpi/ic_cancel_white_48dp.png b/wearable/wear/WearNotifications/Shared/src/main/res/drawable-mdpi/ic_cancel_white_48dp.png
similarity index 100%
rename from wearable/wear/WearNotifications/Wearable/src/main/res/drawable-mdpi/ic_cancel_white_48dp.png
rename to wearable/wear/WearNotifications/Shared/src/main/res/drawable-mdpi/ic_cancel_white_48dp.png
Binary files differ
diff --git a/wearable/wear/WearNotifications/Shared/src/main/res/drawable-mdpi/ic_launcher.png b/wearable/wear/WearNotifications/Shared/src/main/res/drawable-mdpi/ic_launcher.png
new file mode 100644
index 0000000..2b6948a
--- /dev/null
+++ b/wearable/wear/WearNotifications/Shared/src/main/res/drawable-mdpi/ic_launcher.png
Binary files differ
diff --git a/wearable/wear/WearNotifications/Wearable/src/main/res/drawable-mdpi/ic_message_black_18dp.png b/wearable/wear/WearNotifications/Shared/src/main/res/drawable-mdpi/ic_message_black_18dp.png
similarity index 100%
rename from wearable/wear/WearNotifications/Wearable/src/main/res/drawable-mdpi/ic_message_black_18dp.png
rename to wearable/wear/WearNotifications/Shared/src/main/res/drawable-mdpi/ic_message_black_18dp.png
Binary files differ
diff --git a/wearable/wear/WearNotifications/Wearable/src/main/res/drawable-mdpi/ic_person_black_48dp.png b/wearable/wear/WearNotifications/Shared/src/main/res/drawable-mdpi/ic_person_black_48dp.png
similarity index 100%
rename from wearable/wear/WearNotifications/Wearable/src/main/res/drawable-mdpi/ic_person_black_48dp.png
rename to wearable/wear/WearNotifications/Shared/src/main/res/drawable-mdpi/ic_person_black_48dp.png
Binary files differ
diff --git a/wearable/wear/WearNotifications/Wearable/src/main/res/drawable-mdpi/ic_reply_white_18dp.png b/wearable/wear/WearNotifications/Shared/src/main/res/drawable-mdpi/ic_reply_white_18dp.png
similarity index 100%
rename from wearable/wear/WearNotifications/Wearable/src/main/res/drawable-mdpi/ic_reply_white_18dp.png
rename to wearable/wear/WearNotifications/Shared/src/main/res/drawable-mdpi/ic_reply_white_18dp.png
Binary files differ
diff --git a/wearable/wear/WearNotifications/Wearable/src/main/res/drawable-xhdpi/ic_alarm_white_48dp.png b/wearable/wear/WearNotifications/Shared/src/main/res/drawable-xhdpi/ic_alarm_white_48dp.png
similarity index 100%
rename from wearable/wear/WearNotifications/Wearable/src/main/res/drawable-xhdpi/ic_alarm_white_48dp.png
rename to wearable/wear/WearNotifications/Shared/src/main/res/drawable-xhdpi/ic_alarm_white_48dp.png
Binary files differ
diff --git a/wearable/wear/WearNotifications/Wearable/src/main/res/drawable-xhdpi/ic_cancel_white_48dp.png b/wearable/wear/WearNotifications/Shared/src/main/res/drawable-xhdpi/ic_cancel_white_48dp.png
similarity index 100%
rename from wearable/wear/WearNotifications/Wearable/src/main/res/drawable-xhdpi/ic_cancel_white_48dp.png
rename to wearable/wear/WearNotifications/Shared/src/main/res/drawable-xhdpi/ic_cancel_white_48dp.png
Binary files differ
diff --git a/wearable/wear/WearNotifications/Shared/src/main/res/drawable-xhdpi/ic_launcher.png b/wearable/wear/WearNotifications/Shared/src/main/res/drawable-xhdpi/ic_launcher.png
new file mode 100644
index 0000000..d9b1348
--- /dev/null
+++ b/wearable/wear/WearNotifications/Shared/src/main/res/drawable-xhdpi/ic_launcher.png
Binary files differ
diff --git a/wearable/wear/WearNotifications/Wearable/src/main/res/drawable-xhdpi/ic_message_black_18dp.png b/wearable/wear/WearNotifications/Shared/src/main/res/drawable-xhdpi/ic_message_black_18dp.png
similarity index 100%
rename from wearable/wear/WearNotifications/Wearable/src/main/res/drawable-xhdpi/ic_message_black_18dp.png
rename to wearable/wear/WearNotifications/Shared/src/main/res/drawable-xhdpi/ic_message_black_18dp.png
Binary files differ
diff --git a/wearable/wear/WearNotifications/Wearable/src/main/res/drawable-xhdpi/ic_person_black_48dp.png b/wearable/wear/WearNotifications/Shared/src/main/res/drawable-xhdpi/ic_person_black_48dp.png
similarity index 100%
rename from wearable/wear/WearNotifications/Wearable/src/main/res/drawable-xhdpi/ic_person_black_48dp.png
rename to wearable/wear/WearNotifications/Shared/src/main/res/drawable-xhdpi/ic_person_black_48dp.png
Binary files differ
diff --git a/wearable/wear/WearNotifications/Wearable/src/main/res/drawable-xhdpi/ic_reply_white_18dp.png b/wearable/wear/WearNotifications/Shared/src/main/res/drawable-xhdpi/ic_reply_white_18dp.png
similarity index 100%
rename from wearable/wear/WearNotifications/Wearable/src/main/res/drawable-xhdpi/ic_reply_white_18dp.png
rename to wearable/wear/WearNotifications/Shared/src/main/res/drawable-xhdpi/ic_reply_white_18dp.png
Binary files differ
diff --git a/wearable/wear/WearNotifications/Application/src/main/res/drawable-xxhdpi/ic_alarm_white_48dp.png b/wearable/wear/WearNotifications/Shared/src/main/res/drawable-xxhdpi/ic_alarm_white_48dp.png
similarity index 100%
rename from wearable/wear/WearNotifications/Application/src/main/res/drawable-xxhdpi/ic_alarm_white_48dp.png
rename to wearable/wear/WearNotifications/Shared/src/main/res/drawable-xxhdpi/ic_alarm_white_48dp.png
Binary files differ
diff --git a/wearable/wear/WearNotifications/Application/src/main/res/drawable-xxhdpi/ic_cancel_white_48dp.png b/wearable/wear/WearNotifications/Shared/src/main/res/drawable-xxhdpi/ic_cancel_white_48dp.png
similarity index 100%
rename from wearable/wear/WearNotifications/Application/src/main/res/drawable-xxhdpi/ic_cancel_white_48dp.png
rename to wearable/wear/WearNotifications/Shared/src/main/res/drawable-xxhdpi/ic_cancel_white_48dp.png
Binary files differ
diff --git a/wearable/wear/WearNotifications/Shared/src/main/res/drawable-xxhdpi/ic_launcher.png b/wearable/wear/WearNotifications/Shared/src/main/res/drawable-xxhdpi/ic_launcher.png
new file mode 100644
index 0000000..cb4f56f
--- /dev/null
+++ b/wearable/wear/WearNotifications/Shared/src/main/res/drawable-xxhdpi/ic_launcher.png
Binary files differ
diff --git a/wearable/wear/WearNotifications/Application/src/main/res/drawable-xxhdpi/ic_message_black_18dp.png b/wearable/wear/WearNotifications/Shared/src/main/res/drawable-xxhdpi/ic_message_black_18dp.png
similarity index 100%
rename from wearable/wear/WearNotifications/Application/src/main/res/drawable-xxhdpi/ic_message_black_18dp.png
rename to wearable/wear/WearNotifications/Shared/src/main/res/drawable-xxhdpi/ic_message_black_18dp.png
Binary files differ
diff --git a/wearable/wear/WearNotifications/Application/src/main/res/drawable-xxhdpi/ic_person_black_48dp.png b/wearable/wear/WearNotifications/Shared/src/main/res/drawable-xxhdpi/ic_person_black_48dp.png
similarity index 100%
rename from wearable/wear/WearNotifications/Application/src/main/res/drawable-xxhdpi/ic_person_black_48dp.png
rename to wearable/wear/WearNotifications/Shared/src/main/res/drawable-xxhdpi/ic_person_black_48dp.png
Binary files differ
diff --git a/wearable/wear/WearNotifications/Application/src/main/res/drawable-xxhdpi/ic_reply_white_18dp.png b/wearable/wear/WearNotifications/Shared/src/main/res/drawable-xxhdpi/ic_reply_white_18dp.png
similarity index 100%
rename from wearable/wear/WearNotifications/Application/src/main/res/drawable-xxhdpi/ic_reply_white_18dp.png
rename to wearable/wear/WearNotifications/Shared/src/main/res/drawable-xxhdpi/ic_reply_white_18dp.png
Binary files differ
diff --git a/wearable/wear/WearNotifications/Wearable/src/main/res/drawable-xxxhdpi/ic_alarm_white_48dp.png b/wearable/wear/WearNotifications/Shared/src/main/res/drawable-xxxhdpi/ic_alarm_white_48dp.png
similarity index 100%
rename from wearable/wear/WearNotifications/Wearable/src/main/res/drawable-xxxhdpi/ic_alarm_white_48dp.png
rename to wearable/wear/WearNotifications/Shared/src/main/res/drawable-xxxhdpi/ic_alarm_white_48dp.png
Binary files differ
diff --git a/wearable/wear/WearNotifications/Wearable/src/main/res/drawable-xxxhdpi/ic_cancel_white_48dp.png b/wearable/wear/WearNotifications/Shared/src/main/res/drawable-xxxhdpi/ic_cancel_white_48dp.png
similarity index 100%
rename from wearable/wear/WearNotifications/Wearable/src/main/res/drawable-xxxhdpi/ic_cancel_white_48dp.png
rename to wearable/wear/WearNotifications/Shared/src/main/res/drawable-xxxhdpi/ic_cancel_white_48dp.png
Binary files differ
diff --git a/wearable/wear/WearNotifications/Shared/src/main/res/drawable-xxxhdpi/ic_launcher.png b/wearable/wear/WearNotifications/Shared/src/main/res/drawable-xxxhdpi/ic_launcher.png
new file mode 100644
index 0000000..77c9929
--- /dev/null
+++ b/wearable/wear/WearNotifications/Shared/src/main/res/drawable-xxxhdpi/ic_launcher.png
Binary files differ
diff --git a/wearable/wear/WearNotifications/Wearable/src/main/res/drawable-xxxhdpi/ic_message_black_18dp.png b/wearable/wear/WearNotifications/Shared/src/main/res/drawable-xxxhdpi/ic_message_black_18dp.png
similarity index 100%
rename from wearable/wear/WearNotifications/Wearable/src/main/res/drawable-xxxhdpi/ic_message_black_18dp.png
rename to wearable/wear/WearNotifications/Shared/src/main/res/drawable-xxxhdpi/ic_message_black_18dp.png
Binary files differ
diff --git a/wearable/wear/WearNotifications/Wearable/src/main/res/drawable-xxxhdpi/ic_person_black_48dp.png b/wearable/wear/WearNotifications/Shared/src/main/res/drawable-xxxhdpi/ic_person_black_48dp.png
similarity index 100%
rename from wearable/wear/WearNotifications/Wearable/src/main/res/drawable-xxxhdpi/ic_person_black_48dp.png
rename to wearable/wear/WearNotifications/Shared/src/main/res/drawable-xxxhdpi/ic_person_black_48dp.png
Binary files differ
diff --git a/wearable/wear/WearNotifications/Wearable/src/main/res/drawable-xxxhdpi/ic_reply_white_18dp.png b/wearable/wear/WearNotifications/Shared/src/main/res/drawable-xxxhdpi/ic_reply_white_18dp.png
similarity index 100%
rename from wearable/wear/WearNotifications/Wearable/src/main/res/drawable-xxxhdpi/ic_reply_white_18dp.png
rename to wearable/wear/WearNotifications/Shared/src/main/res/drawable-xxxhdpi/ic_reply_white_18dp.png
Binary files differ
diff --git a/wearable/wear/WearNotifications/Shared/src/main/res/values/strings.xml b/wearable/wear/WearNotifications/Shared/src/main/res/values/strings.xml
new file mode 100644
index 0000000..cc0aaa9
--- /dev/null
+++ b/wearable/wear/WearNotifications/Shared/src/main/res/values/strings.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright 2015 Google Inc. All rights reserved.
+ 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>
+ <string name="app_name">Shared</string>
+</resources>
diff --git a/wearable/wear/WearNotifications/Wearable/src/main/AndroidManifest.xml b/wearable/wear/WearNotifications/Wearable/src/main/AndroidManifest.xml
index 2fdee0d..084bc35 100644
--- a/wearable/wear/WearNotifications/Wearable/src/main/AndroidManifest.xml
+++ b/wearable/wear/WearNotifications/Wearable/src/main/AndroidManifest.xml
@@ -27,7 +27,7 @@
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
- android:theme="@style/AppThemeOverride">
+ android:theme="@android:style/Theme.Material">
<!-- Let's Play Store know this app is standalone. -->
<meta-data android:name="com.google.android.wearable.standalone" android:value="true"/>
diff --git a/wearable/wear/WearNotifications/Wearable/src/main/java/com/example/android/wearable/wear/wearnotifications/Controller.java b/wearable/wear/WearNotifications/Wearable/src/main/java/com/example/android/wearable/wear/wearnotifications/Controller.java
index ee372bc..eb63309 100644
--- a/wearable/wear/WearNotifications/Wearable/src/main/java/com/example/android/wearable/wear/wearnotifications/Controller.java
+++ b/wearable/wear/WearNotifications/Wearable/src/main/java/com/example/android/wearable/wear/wearnotifications/Controller.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright (C) 2017 Google Inc. All Rights Reserved.
+ *
+ * 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.example.android.wearable.wear.wearnotifications;
import android.app.Notification;
diff --git a/wearable/wear/WearNotifications/Wearable/src/main/java/com/example/android/wearable/wear/wearnotifications/GlobalNotificationBuilder.java b/wearable/wear/WearNotifications/Wearable/src/main/java/com/example/android/wearable/wear/wearnotifications/GlobalNotificationBuilder.java
index 427c789..e7d461e 100644
--- a/wearable/wear/WearNotifications/Wearable/src/main/java/com/example/android/wearable/wear/wearnotifications/GlobalNotificationBuilder.java
+++ b/wearable/wear/WearNotifications/Wearable/src/main/java/com/example/android/wearable/wear/wearnotifications/GlobalNotificationBuilder.java
@@ -15,7 +15,7 @@
*/
package com.example.android.wearable.wear.wearnotifications;
-import android.support.v7.app.NotificationCompat;
+import android.support.v4.app.NotificationCompat;
/**
* We use a Singleton for a global copy of the NotificationCompat.Builder to update active
diff --git a/wearable/wear/WearNotifications/Wearable/src/main/java/com/example/android/wearable/wear/wearnotifications/ScalingOffsettingHelper.java b/wearable/wear/WearNotifications/Wearable/src/main/java/com/example/android/wearable/wear/wearnotifications/ScalingScrollLayoutCallback.java
similarity index 60%
rename from wearable/wear/WearNotifications/Wearable/src/main/java/com/example/android/wearable/wear/wearnotifications/ScalingOffsettingHelper.java
rename to wearable/wear/WearNotifications/Wearable/src/main/java/com/example/android/wearable/wear/wearnotifications/ScalingScrollLayoutCallback.java
index 84ec2fd..6c68b43 100644
--- a/wearable/wear/WearNotifications/Wearable/src/main/java/com/example/android/wearable/wear/wearnotifications/ScalingOffsettingHelper.java
+++ b/wearable/wear/WearNotifications/Wearable/src/main/java/com/example/android/wearable/wear/wearnotifications/ScalingScrollLayoutCallback.java
@@ -15,36 +15,37 @@
*/
package com.example.android.wearable.wear.wearnotifications;
-import android.support.wearable.view.DefaultOffsettingHelper;
-import android.support.wearable.view.WearableRecyclerView;
+import android.support.v7.widget.RecyclerView;
+import android.support.wear.widget.WearableLinearLayoutManager;
+import android.support.wear.widget.WearableRecyclerView;
import android.view.View;
/**
- * Customizes all items (children) in a {@link WearableRecyclerView} to align to left side of
- * surface/watch and shrinks each item (child) as you scroll away from it.
+ * Shrinks items (children) farther away from the center in a {@link WearableRecyclerView}. The UX
+ * makes scrolling more readable.
*/
-public class ScalingOffsettingHelper extends DefaultOffsettingHelper {
+public class ScalingScrollLayoutCallback extends WearableLinearLayoutManager.LayoutCallback {
- // Max we scale the child View
+ // Max we scale the child View.
private static final float MAX_CHILD_SCALE = 0.65f;
private float mProgressToCenter;
- public ScalingOffsettingHelper() {}
-
- // Shrinks icons/text and you scroll away
+ /*
+ * Scales the item's icons and text the farther away they are from center allowing the main
+ * item to be more readable to the user on small devices like Wear.
+ */
@Override
- public void updateChild(View child, WearableRecyclerView parent) {
- super.updateChild(child, parent);
+ public void onLayoutFinished(View child, RecyclerView parent) {
- // Figure out % progress from top to bottom
+ // Figure out % progress from top to bottom.
float centerOffset = ((float) child.getHeight() / 2.0f) / (float) parent.getHeight();
float yRelativeToCenterOffset = (child.getY() / parent.getHeight()) + centerOffset;
- // Normalize for center
+ // Normalizes for center.
mProgressToCenter = Math.abs(0.5f - yRelativeToCenterOffset);
- // Adjust to the maximum scale
+ // Adjusts to the maximum scale.
mProgressToCenter = Math.min(mProgressToCenter, MAX_CHILD_SCALE);
child.setScaleX(1 - mProgressToCenter);
diff --git a/wearable/wear/WearNotifications/Wearable/src/main/java/com/example/android/wearable/wear/wearnotifications/StandaloneMainActivity.java b/wearable/wear/WearNotifications/Wearable/src/main/java/com/example/android/wearable/wear/wearnotifications/StandaloneMainActivity.java
index 64c1b55..28fa1e5 100644
--- a/wearable/wear/WearNotifications/Wearable/src/main/java/com/example/android/wearable/wear/wearnotifications/StandaloneMainActivity.java
+++ b/wearable/wear/WearNotifications/Wearable/src/main/java/com/example/android/wearable/wear/wearnotifications/StandaloneMainActivity.java
@@ -22,19 +22,23 @@
import android.os.Build;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
+import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationCompat.BigPictureStyle;
import android.support.v4.app.NotificationCompat.BigTextStyle;
import android.support.v4.app.NotificationCompat.InboxStyle;
import android.support.v4.app.NotificationCompat.MessagingStyle;
import android.support.v4.app.NotificationManagerCompat;
import android.support.v4.app.RemoteInput;
-import android.support.v7.app.NotificationCompat;
+import android.support.v4.content.ContextCompat;
+import android.support.wear.widget.WearableLinearLayoutManager;
+import android.support.wear.widget.WearableRecyclerView;
import android.support.wearable.activity.WearableActivity;
-import android.support.wearable.view.WearableRecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;
+import com.example.android.wearable.wear.common.mock.MockDatabase;
+import com.example.android.wearable.wear.common.util.NotificationUtil;
import com.example.android.wearable.wear.wearnotifications.handlers.BigPictureSocialIntentService;
import com.example.android.wearable.wear.wearnotifications.handlers.BigPictureSocialMainActivity;
import com.example.android.wearable.wear.wearnotifications.handlers.BigTextIntentService;
@@ -42,7 +46,7 @@
import com.example.android.wearable.wear.wearnotifications.handlers.InboxMainActivity;
import com.example.android.wearable.wear.wearnotifications.handlers.MessagingIntentService;
import com.example.android.wearable.wear.wearnotifications.handlers.MessagingMainActivity;
-import com.example.android.wearable.wear.wearnotifications.mock.MockDatabase;
+
/**
* Demonstrates best practice for {@link NotificationCompat} Notifications created by local
@@ -93,11 +97,13 @@
mWearableRecyclerView = (WearableRecyclerView) findViewById(R.id.recycler_view);
// Aligns the first and last items on the list vertically centered on the screen.
- mWearableRecyclerView.setCenterEdgeItems(true);
+ mWearableRecyclerView.setEdgeItemsCenteringEnabled(true);
- // Customizes scrolling (zoom) and offsets of WearableRecyclerView's items
- ScalingOffsettingHelper scalingOffsettingHelper = new ScalingOffsettingHelper();
- mWearableRecyclerView.setOffsettingHelper(scalingOffsettingHelper);
+ // Customizes scrolling so items farther away form center are smaller.
+ ScalingScrollLayoutCallback scalingScrollLayoutCallback =
+ new ScalingScrollLayoutCallback();
+ mWearableRecyclerView.setLayoutManager(
+ new WearableLinearLayoutManager(this, scalingScrollLayoutCallback));
// Improves performance because we know changes in content do not change the layout size of
// the RecyclerView.
@@ -113,7 +119,8 @@
mWearableRecyclerView.setAdapter(mCustomRecyclerAdapter);
}
- // Called by WearableRecyclerView when an item is selected (check onCreate() for initialization)
+ // Called by WearableRecyclerView when an item is selected (check onCreate() for
+ // initialization).
public void itemSelected(String data) {
Log.d(TAG, "itemSelected()");
@@ -127,12 +134,12 @@
Snackbar snackbar = Snackbar
.make(
mMainFrameLayout,
- "", // Not enough space for both text and action text
+ "", // Not enough space for both text and action text.
Snackbar.LENGTH_LONG)
.setAction("Enable Notifications", new View.OnClickListener() {
@Override
public void onClick(View view) {
- // Links to this app's notification settings
+ // Links to this app's notification settings.
openNotificationSettingsForApp();
}
});
@@ -160,7 +167,7 @@
break;
default:
- // continue below
+ // continue below.
}
}
@@ -187,20 +194,25 @@
// Main steps for building a BIG_TEXT_STYLE notification:
// 0. Get your data
- // 1. Build the BIG_TEXT_STYLE
- // 2. Set up main Intent for notification
- // 3. Create additional Actions for the Notification
- // 4. Build and issue the notification
+ // 1. Create/Retrieve Notification Channel for O and beyond devices (26+)
+ // 2. Build the BIG_TEXT_STYLE
+ // 3. Set up main Intent for notification
+ // 4. Create additional Actions for the Notification
+ // 5. Build and issue the notification
- // 0. Get your data (everything unique per Notification)
+ // 0. Get your data (everything unique per Notification).
MockDatabase.BigTextStyleReminderAppData bigTextStyleReminderAppData =
MockDatabase.getBigTextStyleData();
- // 1. Build the BIG_TEXT_STYLE
+ // 1. Create/Retrieve Notification Channel for O and beyond devices (26+).
+ String notificationChannelId =
+ NotificationUtil.createNotificationChannel(this, bigTextStyleReminderAppData);
+
+ // 2. Build the BIG_TEXT_STYLE
BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle()
- // Overrides ContentText in the big form of the template
+ // Overrides ContentText in the big form of the template.
.bigText(bigTextStyleReminderAppData.getBigText())
- // Overrides ContentTitle in the big form of the template
+ // Overrides ContentTitle in the big form of the template.
.setBigContentTitle(bigTextStyleReminderAppData.getBigContentTitle())
// Summary line after the detail section in the big form of the template
// Note: To improve readability, don't overload the user with info. If Summary Text
@@ -208,7 +220,7 @@
.setSummaryText(bigTextStyleReminderAppData.getSummaryText());
- // 2. Set up main Intent for notification
+ // 3. Set up main Intent for notification.
Intent mainIntent = new Intent(this, BigTextMainActivity.class);
PendingIntent mainPendingIntent =
@@ -220,11 +232,11 @@
);
- // 3. Create additional Actions (Intents) for the Notification
+ // 4. Create additional Actions (Intents) for the Notification.
// In our case, we create two additional actions: a Snooze action and a Dismiss action.
- // Snooze Action
+ // Snooze Action.
Intent snoozeIntent = new Intent(this, BigTextIntentService.class);
snoozeIntent.setAction(BigTextIntentService.ACTION_SNOOZE);
@@ -236,7 +248,7 @@
snoozePendingIntent)
.build();
- // Dismiss Action
+ // Dismiss Action.
Intent dismissIntent = new Intent(this, BigTextIntentService.class);
dismissIntent.setAction(BigTextIntentService.ACTION_DISMISS);
@@ -249,20 +261,22 @@
.build();
- // 4. Build and issue the notification
+ // 5. Build and issue the notification.
// Because we want this to be a new notification (not updating a previous notification), we
// create a new Builder. Later, we use the same global builder to get back the notification
// we built here for the snooze action, that is, canceling the notification and relaunching
// it several seconds later.
+ // Notification Channel Id is ignored for Android pre O (26).
NotificationCompat.Builder notificationCompatBuilder =
- new NotificationCompat.Builder(getApplicationContext());
+ new NotificationCompat.Builder(
+ getApplicationContext(), notificationChannelId);
GlobalNotificationBuilder.setNotificationCompatBuilderInstance(notificationCompatBuilder);
notificationCompatBuilder
- // BIG_TEXT_STYLE sets title and content
+ // BIG_TEXT_STYLE sets title and content.
.setStyle(bigTextStyle)
.setContentTitle(bigTextStyleReminderAppData.getContentTitle())
.setContentText(bigTextStyleReminderAppData.getContentText())
@@ -270,16 +284,21 @@
.setLargeIcon(BitmapFactory.decodeResource(
getResources(),
R.drawable.ic_alarm_white_48dp))
- // Set primary color (important for Wear 2.0 Notifications)
- .setColor(getResources().getColor(R.color.colorPrimary))
+ // Set primary color (important for Wear 2.0 Notifications).
+ .setColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary))
.setCategory(Notification.CATEGORY_REMINDER)
- .setPriority(Notification.PRIORITY_HIGH)
- // Shows content on the lock-screen
- .setVisibility(Notification.VISIBILITY_PUBLIC)
+ // Sets priority for 25 and below. For 26 and above, 'priority' is deprecated for
+ // 'importance' which is set in the NotificationChannel. The integers representing
+ // 'priority' are different from 'importance', so make sure you don't mix them.
+ .setPriority(bigTextStyleReminderAppData.getPriority())
- // Adds additional actions specified above
+ // Sets lock-screen visibility for 25 and below. For 26 and above, lock screen
+ // visibility is set in the NotificationChannel.
+ .setVisibility(bigTextStyleReminderAppData.getChannelLockscreenVisibility())
+
+ // Adds additional actions specified above.
.addAction(snoozeAction)
.addAction(dismissAction);
@@ -340,28 +359,33 @@
// Main steps for building a BIG_PICTURE_STYLE notification:
// 0. Get your data
- // 1. Build the BIG_PICTURE_STYLE
- // 2. Set up main Intent for notification
- // 3. Set up RemoteInput, so users can input (keyboard and voice) from notification
- // 4. Build and issue the notification
+ // 1. Create/Retrieve Notification Channel for O and beyond devices (26+)
+ // 2. Build the BIG_PICTURE_STYLE
+ // 3. Set up main Intent for notification
+ // 4. Set up RemoteInput, so users can input (keyboard and voice) from notification
+ // 5. Build and issue the notification
- // 0. Get your data (everything unique per Notification)
+ // 0. Get your data (everything unique per Notification).
MockDatabase.BigPictureStyleSocialAppData bigPictureStyleSocialAppData =
MockDatabase.getBigPictureStyleData();
- // 1. Build the BIG_PICTURE_STYLE
+ // 1. Build the BIG_PICTURE_STYLE.
BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle()
- // Provides the bitmap for the BigPicture notification
+ // Provides the bitmap for the BigPicture notification.
.bigPicture(
BitmapFactory.decodeResource(
getResources(),
bigPictureStyleSocialAppData.getBigImage()))
- // Overrides ContentTitle in the big form of the template
+ // Overrides ContentTitle in the big form of the template.
.setBigContentTitle(bigPictureStyleSocialAppData.getBigContentTitle())
- // Summary line after the detail section in the big form of the template
+ // Summary line after the detail section in the big form of the template.
.setSummaryText(bigPictureStyleSocialAppData.getSummaryText());
- // 2. Set up main Intent for notification
+ // 2. Create/Retrieve Notification Channel for O and beyond devices (26+).
+ String notificationChannelId =
+ NotificationUtil.createNotificationChannel(this, bigPictureStyleSocialAppData);
+
+ // 3. Set up main Intent for notification.
Intent mainIntent = new Intent(this, BigPictureSocialMainActivity.class);
PendingIntent mainPendingIntent =
@@ -372,7 +396,7 @@
PendingIntent.FLAG_UPDATE_CURRENT
);
- // 3. Set up a RemoteInput Action, so users can input (keyboard, drawing, voice) directly
+ // 4. Set up a RemoteInput Action, so users can input (keyboard, drawing, voice) directly
// from the notification without entering the app.
// Create the RemoteInput.
@@ -380,7 +404,7 @@
RemoteInput remoteInput =
new RemoteInput.Builder(BigPictureSocialIntentService.EXTRA_COMMENT)
.setLabel(replyLabel)
- // List of quick response choices for any wearables paired with the phone
+ // List of quick response choices for any wearables paired with the phone.
.setChoices(bigPictureStyleSocialAppData.getPossiblePostResponses())
.build();
@@ -402,24 +426,25 @@
replyLabel,
replyActionPendingIntent)
.addRemoteInput(remoteInput)
- // Add WearableExtender to enable inline actions
+ // Add WearableExtender to enable inline actions.
.extend(inlineActionForWear2)
.build();
- // 4. Build and issue the notification
+ // 5. Build and issue the notification
// Because we want this to be a new notification (not updating a previous notification), we
// create a new Builder. Later, we use the same global builder to get back the notification
// we built here for a comment on the post.
+ // Notification Channel Id is ignored for Android pre O (26).
NotificationCompat.Builder notificationCompatBuilder =
- new NotificationCompat.Builder(getApplicationContext());
+ new NotificationCompat.Builder(
+ getApplicationContext(), notificationChannelId);
GlobalNotificationBuilder.setNotificationCompatBuilderInstance(notificationCompatBuilder);
- // Build notification
notificationCompatBuilder
- // BIG_PICTURE_STYLE sets title and content
+ // BIG_PICTURE_STYLE sets title and content.
.setStyle(bigPictureStyle)
.setContentTitle(bigPictureStyleSocialAppData.getContentTitle())
.setContentText(bigPictureStyleSocialAppData.getContentText())
@@ -428,16 +453,21 @@
getResources(),
R.drawable.ic_person_black_48dp))
.setContentIntent(mainPendingIntent)
- // Set primary color (important for Wear 2.0 Notifications)
- .setColor(getResources().getColor(R.color.colorPrimary))
+ // Set primary color (important for Wear 2.0 Notifications).
+ .setColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary))
.setSubText(Integer.toString(1))
.addAction(replyAction)
.setCategory(Notification.CATEGORY_SOCIAL)
- .setPriority(Notification.PRIORITY_HIGH)
- // Hides content on the lock-screen
- .setVisibility(Notification.VISIBILITY_PRIVATE)
+ // Sets priority for 25 and below. For 26 and above, 'priority' is deprecated for
+ // 'importance' which is set in the NotificationChannel. The integers representing
+ // 'priority' are different from 'importance', so make sure you don't mix them.
+ .setPriority(bigPictureStyleSocialAppData.getPriority())
+
+ // Sets lock-screen visibility for 25 and below. For 26 and above, lock screen
+ // visibility is set in the NotificationChannel.
+ .setVisibility(bigPictureStyleSocialAppData.getChannelLockscreenVisibility())
// Notifies system that the main launch intent is an Activity.
.extend(new NotificationCompat.WearableExtender()
.setHintContentIntentLaunchesActivity(true));
@@ -465,27 +495,32 @@
// Main steps for building a INBOX_STYLE notification:
// 0. Get your data
- // 1. Build the INBOX_STYLE
- // 2. Set up main Intent for notification
- // 3. Build and issue the notification
+ // 1. Create/Retrieve Notification Channel for O and beyond devices (26+)
+ // 2. Build the INBOX_STYLE
+ // 3. Set up main Intent for notification
+ // 4. Build and issue the notification
- // 0. Get your data (everything unique per Notification)
+ // 0. Get your data (everything unique per Notification).
MockDatabase.InboxStyleEmailAppData inboxStyleEmailAppData =
MockDatabase.getInboxStyleData();
- // 1. Build the INBOX_STYLE
+ // 1. Create/Retrieve Notification Channel for O and beyond devices (26+).
+ String notificationChannelId =
+ NotificationUtil.createNotificationChannel(this, inboxStyleEmailAppData);
+
+ // 2. Build the INBOX_STYLE
InboxStyle inboxStyle = new NotificationCompat.InboxStyle()
// This title is slightly different than regular title, since I know INBOX_STYLE is
// available.
.setBigContentTitle(inboxStyleEmailAppData.getBigContentTitle())
.setSummaryText(inboxStyleEmailAppData.getSummaryText());
- // Add each summary line of the new emails, you can add up to 5
+ // Add each summary line of the new emails, you can add up to 5.
for (String summary : inboxStyleEmailAppData.getIndividualEmailSummary()) {
inboxStyle.addLine(summary);
}
- // 2. Set up main Intent for notification
+ // 3. Set up main Intent for notification.
Intent mainIntent = new Intent(this, InboxMainActivity.class);
PendingIntent mainPendingIntent =
@@ -496,20 +531,21 @@
PendingIntent.FLAG_UPDATE_CURRENT
);
- // 3. Build and issue the notification
+ // 4. Build and issue the notification.
// Because we want this to be a new notification (not updating a previous notification), we
// create a new Builder. However, we don't need to update this notification later, so we
// will not need to set a global builder for access to the notification later.
+ // Notification Channel Id is ignored for Android pre O (26).
NotificationCompat.Builder notificationCompatBuilder =
- new NotificationCompat.Builder(getApplicationContext());
+ new NotificationCompat.Builder(
+ getApplicationContext(), notificationChannelId);
GlobalNotificationBuilder.setNotificationCompatBuilderInstance(notificationCompatBuilder);
- // 4. Build and issue the notification
notificationCompatBuilder
- // INBOX_STYLE sets title and content
+ // INBOX_STYLE sets title and content.
.setStyle(inboxStyle)
.setContentTitle(inboxStyleEmailAppData.getContentTitle())
.setContentText(inboxStyleEmailAppData.getContentText())
@@ -518,17 +554,22 @@
getResources(),
R.drawable.ic_person_black_48dp))
.setContentIntent(mainPendingIntent)
- // Set primary color (important for Wear 2.0 Notifications)
- .setColor(getResources().getColor(R.color.colorPrimary))
+ // Set primary color (important for Wear 2.0 Notifications).
+ .setColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary))
// Sets large number at the right-hand side of the notification for Wear 1.+.
.setSubText(Integer.toString(inboxStyleEmailAppData.getNumberOfNewEmails()))
.setCategory(Notification.CATEGORY_EMAIL)
- .setPriority(Notification.PRIORITY_HIGH)
- // Hides content on the lock-screen
- .setVisibility(Notification.VISIBILITY_PRIVATE)
+ // Sets priority for 25 and below. For 26 and above, 'priority' is deprecated for
+ // 'importance' which is set in the NotificationChannel. The integers representing
+ // 'priority' are different from 'importance', so make sure you don't mix them.
+ .setPriority(inboxStyleEmailAppData.getPriority())
+
+ // Sets lock-screen visibility for 25 and below. For 26 and above, lock screen
+ // visibility is set in the NotificationChannel.
+ .setVisibility(inboxStyleEmailAppData.getChannelLockscreenVisibility())
// Notifies system that the main launch intent is an Activity.
.extend(new NotificationCompat.WearableExtender()
.setHintContentIntentLaunchesActivity(true));
@@ -570,16 +611,21 @@
// Main steps for building a MESSAGING_STYLE notification:
// 0. Get your data
- // 1. Build the MESSAGING_STYLE
- // 2. Set up main Intent for notification
- // 3. Set up RemoteInput (users can input directly from notification)
- // 4. Build and issue the notification
+ // 1. Create/Retrieve Notification Channel for O and beyond devices (26+)
+ // 2. Build the MESSAGING_STYLE
+ // 3. Set up main Intent for notification
+ // 4. Set up RemoteInput (users can input directly from notification)
+ // 5. Build and issue the notification
- // 0. Get your data (everything unique per Notification)
+ // 0. Get your data (everything unique per Notification).
MockDatabase.MessagingStyleCommsAppData messagingStyleCommsAppData =
MockDatabase.getMessagingStyleData();
- // 1. Build the Notification.Style (MESSAGING_STYLE)
+ // 1. Create/Retrieve Notification Channel for O and beyond devices (26+).
+ String notificationChannelId =
+ NotificationUtil.createNotificationChannel(this, messagingStyleCommsAppData);
+
+ // 2. Build the Notification.Style (MESSAGING_STYLE).
String contentTitle = messagingStyleCommsAppData.getContentTitle();
MessagingStyle messagingStyle =
@@ -589,13 +635,13 @@
// title.
.setConversationTitle(contentTitle);
- // Adds all Messages
- // Note: Messages include the text, timestamp, and sender
+ // Adds all Messages.
+ // Note: Messages include the text, timestamp, and sender.
for (MessagingStyle.Message message : messagingStyleCommsAppData.getMessages()) {
messagingStyle.addMessage(message);
}
- // 2. Set up main Intent for notification
+ // 3. Set up main Intent for notification.
Intent notifyIntent = new Intent(this, MessagingMainActivity.class);
PendingIntent mainPendingIntent =
@@ -607,7 +653,7 @@
);
- // 3. Set up a RemoteInput Action, so users can input (keyboard, drawing, voice) directly
+ // 4. Set up a RemoteInput Action, so users can input (keyboard, drawing, voice) directly
// from the notification without entering the app.
// Create the RemoteInput specifying this key.
@@ -634,25 +680,26 @@
replyLabel,
replyActionPendingIntent)
.addRemoteInput(remoteInput)
- // Allows system to generate replies by context of conversation
+ // Allows system to generate replies by context of conversation.
.setAllowGeneratedReplies(true)
- // Add WearableExtender to enable inline actions
+ // Add WearableExtender to enable inline actions.
.extend(inlineActionForWear2)
.build();
- // 4. Build and issue the notification
+ // 5. Build and issue the notification.
// Because we want this to be a new notification (not updating current notification), we
// create a new Builder. Later, we update this same notification, so we need to save this
// Builder globally (as outlined earlier).
+ // Notification Channel Id is ignored for Android pre O (26).
NotificationCompat.Builder notificationCompatBuilder =
- new NotificationCompat.Builder(getApplicationContext());
+ new NotificationCompat.Builder(
+ getApplicationContext(), notificationChannelId);
GlobalNotificationBuilder.setNotificationCompatBuilderInstance(notificationCompatBuilder);
- // Builds and issues notification
notificationCompatBuilder
// MESSAGING_STYLE sets title and content for Wear 1.+ and Wear 2.0 devices.
.setStyle(messagingStyle)
@@ -663,18 +710,23 @@
getResources(),
R.drawable.ic_person_black_48dp))
.setContentIntent(mainPendingIntent)
- // Set primary color (important for Wear 2.0 Notifications)
- .setColor(getResources().getColor(R.color.colorPrimary))
+ // Set primary color (important for Wear 2.0 Notifications).
+ .setColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary))
- // Number of new notifications for API <24 (Wear 1.+) devices
+ // Number of new notifications for API <24 (Wear 1.+) devices.
.setSubText(Integer.toString(messagingStyleCommsAppData.getNumberOfNewMessages()))
.addAction(replyAction)
.setCategory(Notification.CATEGORY_MESSAGE)
- .setPriority(Notification.PRIORITY_HIGH)
- // Hides content on the lock-screen
- .setVisibility(Notification.VISIBILITY_PRIVATE);
+ // Sets priority for 25 and below. For 26 and above, 'priority' is deprecated for
+ // 'importance' which is set in the NotificationChannel. The integers representing
+ // 'priority' are different from 'importance', so make sure you don't mix them.
+ .setPriority(messagingStyleCommsAppData.getPriority())
+
+ // Sets lock-screen visibility for 25 and below. For 26 and above, lock screen
+ // visibility is set in the NotificationChannel.
+ .setVisibility(messagingStyleCommsAppData.getChannelLockscreenVisibility());
// If the phone is in "Do not disturb mode, the user will still be notified if
// the sender(s) is starred as a favorite.
diff --git a/wearable/wear/WearNotifications/Wearable/src/main/java/com/example/android/wearable/wear/wearnotifications/handlers/BigPictureSocialIntentService.java b/wearable/wear/WearNotifications/Wearable/src/main/java/com/example/android/wearable/wear/wearnotifications/handlers/BigPictureSocialIntentService.java
index d49210c..cc22dc1 100644
--- a/wearable/wear/WearNotifications/Wearable/src/main/java/com/example/android/wearable/wear/wearnotifications/handlers/BigPictureSocialIntentService.java
+++ b/wearable/wear/WearNotifications/Wearable/src/main/java/com/example/android/wearable/wear/wearnotifications/handlers/BigPictureSocialIntentService.java
@@ -21,16 +21,17 @@
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Bundle;
+import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationCompat.BigPictureStyle;
import android.support.v4.app.NotificationManagerCompat;
import android.support.v4.app.RemoteInput;
-import android.support.v7.app.NotificationCompat;
+import android.support.v4.content.ContextCompat;
import android.util.Log;
import com.example.android.wearable.wear.wearnotifications.GlobalNotificationBuilder;
import com.example.android.wearable.wear.wearnotifications.R;
import com.example.android.wearable.wear.wearnotifications.StandaloneMainActivity;
-import com.example.android.wearable.wear.wearnotifications.mock.MockDatabase;
+import com.example.android.wearable.wear.common.mock.MockDatabase;
/**
* Asynchronously handles updating social app posts (and active Notification) with comments from
@@ -135,16 +136,23 @@
// Main steps for building a BIG_PICTURE_STYLE notification (for more detailed comments on
// building this notification, check StandaloneMainActivity.java):
// 0. Get your data
- // 1. Build the BIG_PICTURE_STYLE
- // 2. Set up main Intent for notification
- // 3. Set up RemoteInput, so users can input (keyboard and voice) from notification
- // 4. Build and issue the notification
+ // 1. Retrieve Notification Channel for O and beyond devices (26+)
+ // 2. Build the BIG_PICTURE_STYLE
+ // 3. Set up main Intent for notification
+ // 4. Set up RemoteInput, so users can input (keyboard and voice) from notification
+ // 5. Build and issue the notification
// 0. Get your data (everything unique per Notification)
MockDatabase.BigPictureStyleSocialAppData bigPictureStyleSocialAppData =
MockDatabase.getBigPictureStyleData();
- // 1. Build the BIG_PICTURE_STYLE
+ // 1. Retrieve Notification Channel for O and beyond devices (26+). We don't need to create
+ // the NotificationChannel, since it was created the first time this Notification was
+ // created.
+ String notificationChannelId = bigPictureStyleSocialAppData.getChannelId();
+
+
+ // 2. Build the BIG_PICTURE_STYLE.
BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle()
.bigPicture(
BitmapFactory.decodeResource(
@@ -153,7 +161,7 @@
.setBigContentTitle(bigPictureStyleSocialAppData.getBigContentTitle())
.setSummaryText(bigPictureStyleSocialAppData.getSummaryText());
- // 2. Set up main Intent for notification
+ // 3. Set up main Intent for notification.
Intent mainIntent = new Intent(this, BigPictureSocialMainActivity.class);
PendingIntent mainPendingIntent =
@@ -164,7 +172,7 @@
PendingIntent.FLAG_UPDATE_CURRENT
);
- // 3. Set up a RemoteInput Action, so users can input (keyboard, drawing, voice) directly
+ // 4. Set up a RemoteInput Action, so users can input (keyboard, drawing, voice) directly
// from the notification without entering the app.
String replyLabel = getString(R.string.reply_label);
RemoteInput remoteInput =
@@ -190,17 +198,19 @@
replyLabel,
replyActionPendingIntent)
.addRemoteInput(remoteInput)
- // Add WearableExtender to enable inline actions
+ // Add WearableExtender to enable inline actions.
.extend(inlineActionForWear2)
.build();
- // 4. Build and issue the notification
+ // 5. Build and issue the notification.
+
+ // Notification Channel Id is ignored for Android pre O (26).
NotificationCompat.Builder notificationCompatBuilder =
- new NotificationCompat.Builder(getApplicationContext());
+ new NotificationCompat.Builder(
+ getApplicationContext(), notificationChannelId);
GlobalNotificationBuilder.setNotificationCompatBuilderInstance(notificationCompatBuilder);
- // Build notification
notificationCompatBuilder
.setStyle(bigPictureStyle)
.setContentTitle(bigPictureStyleSocialAppData.getContentTitle())
@@ -210,12 +220,12 @@
getResources(),
R.drawable.ic_person_black_48dp))
.setContentIntent(mainPendingIntent)
- .setColor(getResources().getColor(R.color.colorPrimary))
+ .setColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary))
.setSubText(Integer.toString(1))
.addAction(replyAction)
.setCategory(Notification.CATEGORY_SOCIAL)
- .setPriority(Notification.PRIORITY_HIGH)
- .setVisibility(Notification.VISIBILITY_PRIVATE)
+ .setPriority(bigPictureStyleSocialAppData.getPriority())
+ .setVisibility(bigPictureStyleSocialAppData.getChannelLockscreenVisibility())
.extend(new NotificationCompat.WearableExtender()
.setHintContentIntentLaunchesActivity(true));
diff --git a/wearable/wear/WearNotifications/Wearable/src/main/java/com/example/android/wearable/wear/wearnotifications/handlers/BigTextIntentService.java b/wearable/wear/WearNotifications/Wearable/src/main/java/com/example/android/wearable/wear/wearnotifications/handlers/BigTextIntentService.java
index 67e92a7..bf50afd 100644
--- a/wearable/wear/WearNotifications/Wearable/src/main/java/com/example/android/wearable/wear/wearnotifications/handlers/BigTextIntentService.java
+++ b/wearable/wear/WearNotifications/Wearable/src/main/java/com/example/android/wearable/wear/wearnotifications/handlers/BigTextIntentService.java
@@ -21,15 +21,16 @@
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Build;
+import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationCompat.BigTextStyle;
import android.support.v4.app.NotificationManagerCompat;
-import android.support.v7.app.NotificationCompat;
+import android.support.v4.content.ContextCompat;
import android.util.Log;
import com.example.android.wearable.wear.wearnotifications.GlobalNotificationBuilder;
import com.example.android.wearable.wear.wearnotifications.R;
import com.example.android.wearable.wear.wearnotifications.StandaloneMainActivity;
-import com.example.android.wearable.wear.wearnotifications.mock.MockDatabase;
+import com.example.android.wearable.wear.common.mock.MockDatabase;
import java.util.concurrent.TimeUnit;
@@ -123,25 +124,31 @@
private NotificationCompat.Builder recreateBuilderWithBigTextStyle() {
// Main steps for building a BIG_TEXT_STYLE notification (for more detailed comments on
- // building this notification, check StandaloneMainActivity.java)::
+ // building this notification, check StandaloneMainActivity.java):
// 0. Get your data
- // 1. Build the BIG_TEXT_STYLE
- // 2. Set up main Intent for notification
- // 3. Create additional Actions for the Notification
- // 4. Build and issue the notification
+ // 1. Retrieve Notification Channel for O and beyond devices (26+)
+ // 2. Build the BIG_TEXT_STYLE
+ // 3. Set up main Intent for notification
+ // 4. Create additional Actions for the Notification
+ // 5. Build and issue the notification
- // 0. Get your data (everything unique per Notification)
+ // 0. Get your data (everything unique per Notification).
MockDatabase.BigTextStyleReminderAppData bigTextStyleReminderAppData =
MockDatabase.getBigTextStyleData();
- // 1. Build the BIG_TEXT_STYLE
+ // 1. Retrieve Notification Channel for O and beyond devices (26+). We don't need to create
+ // the NotificationChannel, since it was created the first time this Notification was
+ // created.
+ String notificationChannelId = bigTextStyleReminderAppData.getChannelId();
+
+ // 2. Build the BIG_TEXT_STYLE.
BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle()
.bigText(bigTextStyleReminderAppData.getBigText())
.setBigContentTitle(bigTextStyleReminderAppData.getBigContentTitle())
.setSummaryText(bigTextStyleReminderAppData.getSummaryText());
- // 2. Set up main Intent for notification
+ // 3. Set up main Intent for notification.
Intent mainIntent = new Intent(this, BigTextMainActivity.class);
PendingIntent mainPendingIntent =
@@ -153,8 +160,9 @@
);
- // 3. Create additional Actions (Intents) for the Notification
- // Snooze Action
+ // 4. Create additional Actions (Intents) for the Notification.
+
+ // Snooze Action.
Intent snoozeIntent = new Intent(this, BigTextIntentService.class);
snoozeIntent.setAction(BigTextIntentService.ACTION_SNOOZE);
@@ -179,9 +187,12 @@
.build();
- // 4. Build and issue the notification
+ // 5. Build and issue the notification.
+
+ // Notification Channel Id is ignored for Android pre O (26).
NotificationCompat.Builder notificationCompatBuilder =
- new NotificationCompat.Builder(getApplicationContext());
+ new NotificationCompat.Builder(
+ getApplicationContext(), notificationChannelId);
GlobalNotificationBuilder.setNotificationCompatBuilderInstance(notificationCompatBuilder);
@@ -193,10 +204,10 @@
.setLargeIcon(BitmapFactory.decodeResource(
getResources(),
R.drawable.ic_alarm_white_48dp))
- .setColor(getResources().getColor(R.color.colorPrimary))
+ .setColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary))
.setCategory(Notification.CATEGORY_REMINDER)
- .setPriority(Notification.PRIORITY_HIGH)
- .setVisibility(Notification.VISIBILITY_PUBLIC)
+ .setPriority(bigTextStyleReminderAppData.getPriority())
+ .setVisibility(bigTextStyleReminderAppData.getChannelLockscreenVisibility())
.addAction(snoozeAction)
.addAction(dismissAction);
diff --git a/wearable/wear/WearNotifications/Wearable/src/main/java/com/example/android/wearable/wear/wearnotifications/handlers/MessagingIntentService.java b/wearable/wear/WearNotifications/Wearable/src/main/java/com/example/android/wearable/wear/wearnotifications/handlers/MessagingIntentService.java
index 2268cfc..cf17fdd 100644
--- a/wearable/wear/WearNotifications/Wearable/src/main/java/com/example/android/wearable/wear/wearnotifications/handlers/MessagingIntentService.java
+++ b/wearable/wear/WearNotifications/Wearable/src/main/java/com/example/android/wearable/wear/wearnotifications/handlers/MessagingIntentService.java
@@ -21,16 +21,17 @@
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Bundle;
+import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationCompat.MessagingStyle;
import android.support.v4.app.NotificationManagerCompat;
import android.support.v4.app.RemoteInput;
-import android.support.v7.app.NotificationCompat;
+import android.support.v4.content.ContextCompat;
import android.util.Log;
import com.example.android.wearable.wear.wearnotifications.GlobalNotificationBuilder;
import com.example.android.wearable.wear.wearnotifications.R;
import com.example.android.wearable.wear.wearnotifications.StandaloneMainActivity;
-import com.example.android.wearable.wear.wearnotifications.mock.MockDatabase;
+import com.example.android.wearable.wear.common.mock.MockDatabase;
/**
* Asynchronously handles updating messaging app posts (and active Notification) with replies from
@@ -142,48 +143,38 @@
private NotificationCompat.Builder recreateBuilderWithMessagingStyle() {
// Main steps for building a MESSAGING_STYLE notification (for more detailed comments on
- // building this notification, check StandaloneMainActivity.java)::
+ // building this notification, check StandaloneMainActivity.java):
// 0. Get your data
- // 1. Build the MESSAGING_STYLE
- // 2. Add support for Wear 1.+
+ // 1. Retrieve Notification Channel for O and beyond devices (26+)
+ // 2. Build the MESSAGING_STYLE
// 3. Set up main Intent for notification
// 4. Set up RemoteInput (users can input directly from notification)
// 5. Build and issue the notification
- // 0. Get your data (everything unique per Notification)
+ // 0. Get your data (everything unique per Notification).
MockDatabase.MessagingStyleCommsAppData messagingStyleCommsAppData =
MockDatabase.getMessagingStyleData();
- // 1. Build the Notification.Style (MESSAGING_STYLE)
+ // 1. Retrieve Notification Channel for O and beyond devices (26+). We don't need to create
+ // the NotificationChannel, since it was created the first time this Notification was
+ // created.
+ String notificationChannelId = messagingStyleCommsAppData.getChannelId();
+
+
+ // 2. Build the Notification.Style (MESSAGING_STYLE).
String contentTitle = messagingStyleCommsAppData.getContentTitle();
MessagingStyle messagingStyle =
new NotificationCompat.MessagingStyle(messagingStyleCommsAppData.getReplayName())
.setConversationTitle(contentTitle);
- // Adds all Messages
+ // Adds all Messages.
for (MessagingStyle.Message message : messagingStyleCommsAppData.getMessages()) {
messagingStyle.addMessage(message);
}
- // 2. Add support for Wear 1.+.
- String fullMessageForWearVersion1 = messagingStyleCommsAppData.getFullConversation();
-
- Notification chatHistoryForWearV1 = new NotificationCompat.Builder(getApplicationContext())
- .setStyle(new NotificationCompat.BigTextStyle().bigText(fullMessageForWearVersion1))
- .setContentTitle(contentTitle)
- .setSmallIcon(R.drawable.ic_launcher)
- .setContentText(fullMessageForWearVersion1)
- .build();
-
- // Adds page with all text to support Wear 1.+.
- NotificationCompat.WearableExtender wearableExtenderForWearVersion1 =
- new NotificationCompat.WearableExtender()
- .setHintContentIntentLaunchesActivity(true)
- .addPage(chatHistoryForWearV1);
-
- // 3. Set up main Intent for notification
+ // 3. Set up main Intent for notification.
Intent notifyIntent = new Intent(this, MessagingMainActivity.class);
PendingIntent mainPendingIntent =
@@ -219,20 +210,22 @@
replyLabel,
replyActionPendingIntent)
.addRemoteInput(remoteInput)
- // Allows system to generate replies by context of conversation
+ // Allows system to generate replies by context of conversation.
.setAllowGeneratedReplies(true)
- // Add WearableExtender to enable inline actions
+ // Add WearableExtender to enable inline actions.
.extend(inlineActionForWear2_0)
.build();
- // 5. Build and issue the notification
+ // 5. Build and issue the notification.
+
+ // Notification Channel Id is ignored for Android pre O (26).
NotificationCompat.Builder notificationCompatBuilder =
- new NotificationCompat.Builder(getApplicationContext());
+ new NotificationCompat.Builder(
+ getApplicationContext(), notificationChannelId);
GlobalNotificationBuilder.setNotificationCompatBuilderInstance(notificationCompatBuilder);
- // Builds and issues notification
notificationCompatBuilder
.setStyle(messagingStyle)
.setContentTitle(contentTitle)
@@ -242,13 +235,12 @@
getResources(),
R.drawable.ic_person_black_48dp))
.setContentIntent(mainPendingIntent)
- .setColor(getResources().getColor(R.color.colorPrimary))
+ .setColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary))
.setSubText(Integer.toString(messagingStyleCommsAppData.getNumberOfNewMessages()))
.addAction(replyAction)
.setCategory(Notification.CATEGORY_MESSAGE)
- .setPriority(Notification.PRIORITY_HIGH)
- .setVisibility(Notification.VISIBILITY_PRIVATE)
- .extend(wearableExtenderForWearVersion1);
+ .setPriority(messagingStyleCommsAppData.getPriority())
+ .setVisibility(messagingStyleCommsAppData.getChannelLockscreenVisibility());
for (String name : messagingStyleCommsAppData.getParticipants()) {
notificationCompatBuilder.addPerson(name);
diff --git a/wearable/wear/WearNotifications/Wearable/src/main/java/com/example/android/wearable/wear/wearnotifications/mock/MockDatabase.java b/wearable/wear/WearNotifications/Wearable/src/main/java/com/example/android/wearable/wear/wearnotifications/mock/MockDatabase.java
deleted file mode 100644
index b552f6d..0000000
--- a/wearable/wear/WearNotifications/Wearable/src/main/java/com/example/android/wearable/wear/wearnotifications/mock/MockDatabase.java
+++ /dev/null
@@ -1,400 +0,0 @@
-package com.example.android.wearable.wear.wearnotifications.mock;
-
-import android.support.v4.app.NotificationCompat.MessagingStyle;
-
-import com.example.android.wearable.wear.wearnotifications.R;
-
-import java.util.ArrayList;
-
-/**
- * Mock data for each of the Notification Style Demos.
- */
-public final class MockDatabase {
-
- public static BigTextStyleReminderAppData getBigTextStyleData() {
- return BigTextStyleReminderAppData.getInstance();
- }
-
- public static BigPictureStyleSocialAppData getBigPictureStyleData() {
- return BigPictureStyleSocialAppData.getInstance();
- }
-
- public static InboxStyleEmailAppData getInboxStyleData() {
- return InboxStyleEmailAppData.getInstance();
- }
-
- public static MessagingStyleCommsAppData getMessagingStyleData() {
- return MessagingStyleCommsAppData.getInstance();
- }
-
- /**
- * Represents data needed for BigTextStyle Notification.
- */
- public static class BigTextStyleReminderAppData {
-
- private static BigTextStyleReminderAppData sInstance = null;
-
- // Standard notification values
- private String mContentTitle;
- private String mContentText;
-
- // Style notification values
- private String mBigContentTitle;
- private String mBigText;
- private String mSummaryText;
-
-
- public static BigTextStyleReminderAppData getInstance() {
- if (sInstance == null) {
- sInstance = getSync();
- }
-
- return sInstance;
- }
-
- private static synchronized BigTextStyleReminderAppData getSync() {
- if (sInstance == null) {
- sInstance = new BigTextStyleReminderAppData();
- }
-
- return sInstance;
- }
-
- private BigTextStyleReminderAppData() {
- // Standard Notification values
- // Title for API <16 (4.0 and below) devices
- mContentTitle = "Don't forget to...";
- // Content for API <24 (4.0 and below) devices
- mContentText = "Feed Dogs and check garage!";
-
- // BigText Style Notification values
- mBigContentTitle = "Don't forget to...";
- mBigText = "... feed the dogs before you leave for work, and check the garage to "
- + "make sure the door is closed.";
- mSummaryText = "Dogs and Garage";
- }
- public String getContentTitle() {
- return mContentTitle;
- }
-
- public String getContentText() {
- return mContentText;
- }
-
- public String getBigContentTitle() {
- return mBigContentTitle;
- }
-
- public String getBigText() {
- return mBigText;
- }
-
- public String getSummaryText() {
- return mSummaryText;
- }
-
- @Override
- public String toString() {
- return getBigContentTitle() + getBigText();
- }
- }
-
- /**
- * Represents data needed for BigPictureStyle Notification.
- */
- public static class BigPictureStyleSocialAppData {
- private static BigPictureStyleSocialAppData sInstance = null;
-
- // Standard notification values
- private String mContentTitle;
- private String mContentText;
-
- // Style notification values
- private int mBigImage;
- private String mBigContentTitle;
- private String mSummaryText;
-
- private CharSequence[] mPossiblePostResponses;
-
- private ArrayList<String> mParticipants;
-
-
- public static BigPictureStyleSocialAppData getInstance() {
- if (sInstance == null) {
- sInstance = getSync();
- }
- return sInstance;
- }
-
- private static synchronized BigPictureStyleSocialAppData getSync() {
- if (sInstance == null) {
- sInstance = new BigPictureStyleSocialAppData();
- }
-
- return sInstance;
- }
-
- private BigPictureStyleSocialAppData() {
- // Standard Notification values
- // Title/Content for API <16 (4.0 and below) devices
- mContentTitle = "Bob's Post";
- mContentText = "[Picture] Like my shot of Earth?";
-
- // Style notification values
- mBigImage = R.drawable.earth;
- mBigContentTitle = "Bob's Post";
- mSummaryText = "Like my shot of Earth?";
-
- // This would be possible responses based on the contents of the post
- mPossiblePostResponses = new CharSequence[]{"Yes", "No", "Maybe?"};
-
- mParticipants = new ArrayList<>();
- mParticipants.add("Bob Smith");
- }
-
- public String getContentTitle() {
- return mContentTitle;
- }
-
- public String getContentText() {
- return mContentText;
- }
-
- public int getBigImage() {
- return mBigImage;
- }
-
- public String getBigContentTitle() {
- return mBigContentTitle;
- }
-
- public String getSummaryText() {
- return mSummaryText;
- }
-
- public CharSequence[] getPossiblePostResponses() {
- return mPossiblePostResponses;
- }
-
- public ArrayList<String> getParticipants() {
- return mParticipants;
- }
-
- @Override
- public String toString() {
- return getContentTitle() + " - " + getContentText();
- }
- }
-
- /**
- * Represents data needed for InboxStyle Notification.
- */
- public static class InboxStyleEmailAppData {
- private static InboxStyleEmailAppData sInstance = null;
-
- // Standard notification values
- private String mContentTitle;
- private String mContentText;
- private int mNumberOfNewEmails;
-
- // Style notification values
- private String mBigContentTitle;
- private String mSummaryText;
- private ArrayList<String> mIndividualEmailSummary;
-
- private ArrayList<String> mParticipants;
-
- public static InboxStyleEmailAppData getInstance() {
- if (sInstance == null) {
- sInstance = getSync();
- }
- return sInstance;
- }
-
- private static synchronized InboxStyleEmailAppData getSync() {
- if (sInstance == null) {
- sInstance = new InboxStyleEmailAppData();
- }
-
- return sInstance;
- }
-
- private InboxStyleEmailAppData() {
- // Standard Notification values
- // Title/Content for API <16 (4.0 and below) devices
- mContentTitle = "5 new emails";
- mContentText = "from Jane, Jay, Alex +2 more";
- mNumberOfNewEmails = 5;
-
- // Style notification values
- mBigContentTitle = "5 new emails from Jane, Jay, Alex +2";
- mSummaryText = "New emails";
-
- // Add each summary line of the new emails, you can add up to 5
- mIndividualEmailSummary = new ArrayList<>();
- mIndividualEmailSummary.add("Jane Faab - Launch Party is here...");
- mIndividualEmailSummary.add("Jay Walker - There's a turtle on the server!");
- mIndividualEmailSummary.add("Alex Chang - Check this out...");
- mIndividualEmailSummary.add("Jane Johns - Check in code?");
- mIndividualEmailSummary.add("John Smith - Movies later....");
-
- // If the phone is in "Do not disturb mode, the user will still be notified if
- // the user(s) is starred as a favorite.
- mParticipants = new ArrayList<>();
- mParticipants.add("Jane Faab");
- mParticipants.add("Jay Walker");
- mParticipants.add("Alex Chang");
- mParticipants.add("Jane Johns");
- mParticipants.add("John Smith");
- }
-
- public String getContentTitle() {
- return mContentTitle;
- }
-
- public String getContentText() {
- return mContentText;
- }
-
- public int getNumberOfNewEmails() {
- return mNumberOfNewEmails;
- }
-
- public String getBigContentTitle() {
- return mBigContentTitle;
- }
-
- public String getSummaryText() {
- return mSummaryText;
- }
-
- public ArrayList<String> getIndividualEmailSummary() {
- return mIndividualEmailSummary;
- }
-
- public ArrayList<String> getParticipants() {
- return mParticipants;
- }
-
- @Override
- public String toString() {
- return getContentTitle() + " " + getContentText();
- }
- }
-
- /**
- * Represents data needed for MessagingStyle Notification.
- */
- public static class MessagingStyleCommsAppData {
-
- private static MessagingStyleCommsAppData sInstance = null;
-
- // Standard notification values
- private String mContentTitle;
- private String mContentText;
-
- // Style notification values
- private ArrayList<MessagingStyle.Message> mMessages;
- // Basically, String of all mMessages
- private String mFullConversation;
- // Name preferred when replying to chat
- private String mReplayName;
- private int mNumberOfNewMessages;
- private ArrayList<String> mParticipants;
-
- public static MessagingStyleCommsAppData getInstance() {
- if (sInstance == null) {
- sInstance = getSync();
- }
- return sInstance;
- }
-
- private static synchronized MessagingStyleCommsAppData getSync() {
- if (sInstance == null) {
- sInstance = new MessagingStyleCommsAppData();
- }
-
- return sInstance;
- }
-
- private MessagingStyleCommsAppData() {
- // Standard notification values
- // Content for API <24 (M and below) devices
- mContentTitle = "2 Messages w/ Famous McFamously";
- mContentText = "Dude! ... You know I am a Pesce-pescetarian. :P";
-
- // Style notification values
-
- // For each message, you need the timestamp, in this case, we are using arbitrary ones.
- long currentTime = System.currentTimeMillis();
-
- mMessages = new ArrayList<>();
- mMessages.add(new MessagingStyle.Message(
- "What are you doing tonight?", currentTime - 4000, "Famous"));
- mMessages.add(new MessagingStyle.Message(
- "I don't know, dinner maybe?", currentTime - 3000, null));
- mMessages.add(new MessagingStyle.Message(
- "Sounds good.", currentTime - 2000, "Famous"));
- mMessages.add(new MessagingStyle.Message(
- "How about BBQ?", currentTime - 1000, null));
- // Last two are the newest message (2) from friend
- mMessages.add(new MessagingStyle.Message(
- "Dude!", currentTime, "Famous"));
- mMessages.add(new MessagingStyle.Message(
- "You know I am a Pesce-pescetarian. :P", currentTime, "Famous"));
-
-
- // String version of the mMessages above
- mFullConversation = "Famous: What are you doing tonight?\n\n"
- + "Me: I don't know, dinner maybe?\n\n"
- + "Famous: Sounds good.\n\n"
- + "Me: How about BBQ?\n\n"
- + "Famous: Dude!\n\n"
- + "Famous: You know I am a Pesce-pescetarian. :P\n\n";
-
- mNumberOfNewMessages = 2;
-
- // Name preferred when replying to chat
- mReplayName = "Me";
-
- // If the phone is in "Do not disturb mode, the user will still be notified if
- // the user(s) is starred as a favorite.
- mParticipants = new ArrayList<>();
- mParticipants.add("Famous McFamously");
-
- }
-
- public String getContentTitle() {
- return mContentTitle;
- }
-
- public String getContentText() {
- return mContentText;
- }
-
- public ArrayList<MessagingStyle.Message> getMessages() {
- return mMessages;
- }
-
- public String getFullConversation() {
- return mFullConversation;
- }
-
- public String getReplayName() {
- return mReplayName;
- }
-
- public int getNumberOfNewMessages() {
- return mNumberOfNewMessages;
- }
-
- public ArrayList<String> getParticipants() {
- return mParticipants;
- }
-
- @Override
- public String toString() {
- return getFullConversation();
- }
- }
-}
\ No newline at end of file
diff --git a/wearable/wear/WearNotifications/Wearable/src/main/res/drawable-xxhdpi/ic_alarm_white_48dp.png b/wearable/wear/WearNotifications/Wearable/src/main/res/drawable-xxhdpi/ic_alarm_white_48dp.png
deleted file mode 100644
index f665286..0000000
--- a/wearable/wear/WearNotifications/Wearable/src/main/res/drawable-xxhdpi/ic_alarm_white_48dp.png
+++ /dev/null
Binary files differ
diff --git a/wearable/wear/WearNotifications/Wearable/src/main/res/drawable-xxhdpi/ic_cancel_white_48dp.png b/wearable/wear/WearNotifications/Wearable/src/main/res/drawable-xxhdpi/ic_cancel_white_48dp.png
deleted file mode 100644
index cf2822a..0000000
--- a/wearable/wear/WearNotifications/Wearable/src/main/res/drawable-xxhdpi/ic_cancel_white_48dp.png
+++ /dev/null
Binary files differ
diff --git a/wearable/wear/WearNotifications/Wearable/src/main/res/drawable-xxhdpi/ic_message_black_18dp.png b/wearable/wear/WearNotifications/Wearable/src/main/res/drawable-xxhdpi/ic_message_black_18dp.png
deleted file mode 100644
index e710dee..0000000
--- a/wearable/wear/WearNotifications/Wearable/src/main/res/drawable-xxhdpi/ic_message_black_18dp.png
+++ /dev/null
Binary files differ
diff --git a/wearable/wear/WearNotifications/Wearable/src/main/res/drawable-xxhdpi/ic_person_black_48dp.png b/wearable/wear/WearNotifications/Wearable/src/main/res/drawable-xxhdpi/ic_person_black_48dp.png
deleted file mode 100644
index 77e3a18..0000000
--- a/wearable/wear/WearNotifications/Wearable/src/main/res/drawable-xxhdpi/ic_person_black_48dp.png
+++ /dev/null
Binary files differ
diff --git a/wearable/wear/WearNotifications/Wearable/src/main/res/drawable-xxhdpi/ic_reply_white_18dp.png b/wearable/wear/WearNotifications/Wearable/src/main/res/drawable-xxhdpi/ic_reply_white_18dp.png
deleted file mode 100644
index eeb5d49..0000000
--- a/wearable/wear/WearNotifications/Wearable/src/main/res/drawable-xxhdpi/ic_reply_white_18dp.png
+++ /dev/null
Binary files differ
diff --git a/wearable/wear/WearNotifications/Wearable/src/main/res/layout/activity_main.xml b/wearable/wear/WearNotifications/Wearable/src/main/res/layout/activity_main.xml
index 5dc46fd..10528cf 100644
--- a/wearable/wear/WearNotifications/Wearable/src/main/res/layout/activity_main.xml
+++ b/wearable/wear/WearNotifications/Wearable/src/main/res/layout/activity_main.xml
@@ -22,12 +22,13 @@
android:layout_height="match_parent"
tools:context="com.example.android.wearable.wear.wearnotifications.StandaloneMainActivity">
- <android.support.wearable.view.WearableRecyclerView
+ <android.support.wear.widget.WearableRecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" />
+ <!-- Stacks the text field above the WearableRecyclerView at the top of the screen. -->
<TextView
android:id="@+id/header_text_view"
android:layout_width="match_parent"
diff --git a/wearable/wear/WearNotifications/Wearable/src/main/res/values/dimens.xml b/wearable/wear/WearNotifications/Wearable/src/main/res/values/dimens.xml
index e6d1996..3a2b9ca 100644
--- a/wearable/wear/WearNotifications/Wearable/src/main/res/values/dimens.xml
+++ b/wearable/wear/WearNotifications/Wearable/src/main/res/values/dimens.xml
@@ -18,7 +18,7 @@
<dimen name="activity_main_text_header_spacing">5dp</dimen>
<dimen name="recycler_row_padding">5dp</dimen>
- <dimen name="recycler_row_text_size">14sp</dimen>
+ <dimen name="recycler_row_text_size">10sp</dimen>
<dimen name="activity_notification_details_top_padding">5dp</dimen>
<dimen name="activity_notification_details_bottom_padding">5dp</dimen>
diff --git a/wearable/wear/WearNotifications/Wearable/src/main/res/values/styles.xml b/wearable/wear/WearNotifications/Wearable/src/main/res/values/styles.xml
deleted file mode 100644
index 1d68f73..0000000
--- a/wearable/wear/WearNotifications/Wearable/src/main/res/values/styles.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- ~ Copyright 2016 Google Inc.
- ~
- ~ 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>
- <style name="AppThemeOverride" parent="Theme.AppCompat.NoActionBar" />
-</resources>
\ No newline at end of file
diff --git a/wearable/wear/WearNotifications/settings.gradle b/wearable/wear/WearNotifications/settings.gradle
index f35b8cc..8c3a205 100644
--- a/wearable/wear/WearNotifications/settings.gradle
+++ b/wearable/wear/WearNotifications/settings.gradle
@@ -1,2 +1,2 @@
-include ':Application', ':Wearable'
+include ':Application', ':Wearable', ':Shared'
diff --git a/wearable/wear/WearNotifications/template-params.xml b/wearable/wear/WearNotifications/template-params.xml
index c112f13..699b760 100644
--- a/wearable/wear/WearNotifications/template-params.xml
+++ b/wearable/wear/WearNotifications/template-params.xml
@@ -20,19 +20,27 @@
<package>com.example.android.wearable.wear.wearnotifications</package>
<minSdk>18</minSdk>
- <targetSdkVersion>25</targetSdkVersion>
- <targetSdkVersionWear>25</targetSdkVersionWear>
+ <compileSdkVersion>26</compileSdkVersion>
+ <targetSdkVersion>26</targetSdkVersion>
+
+ <minSdkVersionWear>23</minSdkVersionWear>
+ <compileSdkVersionWear>26</compileSdkVersionWear>
+ <targetSdkVersionWear>26</targetSdkVersionWear>
+ <multiDexEnabled>true</multiDexEnabled>
<wearable>
<has_handheld_app>true</has_handheld_app>
</wearable>
- <dependency>com.android.support:appcompat-v7:25.3.1</dependency>
- <dependency>com.android.support:cardview-v7:25.3.1</dependency>
- <dependency>com.android.support:design:25.3.1</dependency>
+ <dependency>com.android.support:appcompat-v7:26.0.0</dependency>
+ <dependency>com.android.support:cardview-v7:26.0.0</dependency>
+ <dependency>com.android.support:design:26.0.0</dependency>
- <dependency_wearable>com.android.support:appcompat-v7:25.3.1</dependency_wearable>
- <dependency_wearable>com.android.support:design:25.3.1</dependency_wearable>
+ <dependency_shared>com.android.support:support-v4:26.0.0</dependency_shared>
+
+ <dependency_wearable>com.android.support:appcompat-v7:26.0.0</dependency_wearable>
+ <dependency_wearable>com.android.support:wear:26.0.0</dependency_wearable>
+ <dependency_wearable>com.android.support:design:26.0.0</dependency_wearable>
<!-- Include additional dependencies here.-->
<!-- dependency>com.google.android.gms:play-services:5.0.+</dependency -->
@@ -50,7 +58,7 @@
</strings>
<template src="base" />
- <template src="Wear" />
+ <template src="WearPlusShared" />
<metadata>
<!-- Values: {DRAFT | PUBLISHED | INTERNAL | DEPRECATED | SUPERCEDED} -->