diff options
author | Trevor Johns <trevorjohns@google.com> | 2017-05-16 00:45:47 -0700 |
---|---|---|
committer | Trevor Johns <trevorjohns@google.com> | 2017-05-17 01:35:57 -0700 |
commit | 91a8274b1b9f8ebd8276f0e0648ad24db858a9a7 (patch) | |
tree | bcda7d09074166813655ab251285b28d09899386 /notification | |
parent | 2ea5c823585f4fbc211a519548c9fc7a7758d1bd (diff) | |
download | android-91a8274b1b9f8ebd8276f0e0648ad24db858a9a7.tar.gz |
Add Kotlin version of NotificationChannels sample
Test: assembleDebug and ran on device
Change-Id: Ibe1877705ccf0206e1a41f0f34336a4e2aeb6937
Diffstat (limited to 'notification')
31 files changed, 998 insertions, 0 deletions
diff --git a/notification/NotificationChannels/kotlinApp/Application/build.gradle b/notification/NotificationChannels/kotlinApp/Application/build.gradle new file mode 100644 index 00000000..89d1fae8 --- /dev/null +++ b/notification/NotificationChannels/kotlinApp/Application/build.gradle @@ -0,0 +1,62 @@ +buildscript { + repositories { + jcenter() + } + ext.kotlin_version = '1.1.2-3' + dependencies { + classpath 'com.android.tools.build:gradle:2.3.0' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } +} + +apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' + +repositories { + jcenter() +} + +dependencies { + compile "com.android.support:support-v4:25.3.1" + compile "com.android.support:support-v13:25.3.1" + compile "com.android.support:cardview-v7:25.3.1" + compile "com.android.support:appcompat-v7:25.3.1" + compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" +} + +// The sample build uses multiple directories to +// keep boilerplate and common code separate from +// the main sample code. +List<String> dirs = [ + 'main', // main sample code; look here for the interesting stuff. + 'common', // components that are reused by multiple samples + 'template'] // boilerplate code that is generated by the sample template process + +android { + compileSdkVersion "android-O" + buildToolsVersion "25.0.3" + + defaultConfig { + minSdkVersion 21 + targetSdkVersion "android-O" + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_7 + targetCompatibility JavaVersion.VERSION_1_7 + } + + sourceSets { + main { + dirs.each { dir -> + java.srcDirs "src/${dir}/java" + res.srcDirs "src/${dir}/res" + } + } + androidTest.setRoot('tests') + androidTest.java.srcDirs = ['tests/src'] + + } + +} diff --git a/notification/NotificationChannels/kotlinApp/Application/src/main/AndroidManifest.xml b/notification/NotificationChannels/kotlinApp/Application/src/main/AndroidManifest.xml new file mode 100644 index 00000000..9365d918 --- /dev/null +++ b/notification/NotificationChannels/kotlinApp/Application/src/main/AndroidManifest.xml @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright 2017 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. +--> + +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.example.android.notificationchannels" + android:versionCode="1" + android:versionName="1.0"> + + <application android:allowBackup="true" + android:label="@string/app_name" + android:icon="@mipmap/ic_launcher" + android:theme="@style/AppTheme"> + + <activity android:name=".MainActivity" + android:label="@string/app_name"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + </application> +</manifest> diff --git a/notification/NotificationChannels/kotlinApp/Application/src/main/java/com/example/android/notificationchannels/MainActivity.kt b/notification/NotificationChannels/kotlinApp/Application/src/main/java/com/example/android/notificationchannels/MainActivity.kt new file mode 100644 index 00000000..faa8db6a --- /dev/null +++ b/notification/NotificationChannels/kotlinApp/Application/src/main/java/com/example/android/notificationchannels/MainActivity.kt @@ -0,0 +1,145 @@ +/* +* Copyright 2017 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package com.example.android.notificationchannels + +import android.app.Activity +import android.content.Intent +import android.os.Bundle +import android.provider.Settings +import android.util.Log +import android.view.View +import android.widget.Button +import kotlinx.android.synthetic.main.activity_main.* + +/** + * Display main screen for sample. Displays controls for sending test notifications. + */ +class MainActivity : Activity() { + + private lateinit var ui: MainUi + + /* + * Class for managing notifications + */ + private lateinit var helper: NotificationHelper + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + ui = MainUi(activity_main) + helper = NotificationHelper(this) + } + + /** + * Send activity notifications. + + * @param id The ID of the notification to create + * * + * @param title The title of the notification + */ + fun sendNotification(id: Int, title: String) { + when (id) { + NOTI_PRIMARY1 -> helper.notify( + id, helper.getNotification1(title, getString(R.string.primary1_body))) + NOTI_PRIMARY2 -> helper.notify( + id, helper.getNotification1(title, getString(R.string.primary2_body))) + NOTI_SECONDARY1 -> helper.notify( + id, helper.getNotification2(title, getString(R.string.secondary1_body))) + NOTI_SECONDARY2 -> helper.notify( + id, helper.getNotification2(title, getString(R.string.secondary2_body))) + } + } + + /** + * Send Intent to load system Notification Settings for this app. + */ + fun goToNotificationSettings() { + val i = Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS) + i.putExtra(Settings.EXTRA_APP_PACKAGE, packageName) + startActivity(i) + } + + /** + * Send intent to load system Notification Settings UI for a particular channel. + + * @param channel Name of channel to configure + */ + fun goToNotificationSettings(channel: String) { + val i = Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS) + i.putExtra(Settings.EXTRA_APP_PACKAGE, packageName) + i.putExtra(Settings.EXTRA_CHANNEL_ID, channel) + startActivity(i) + } + + /** + * View model for interacting with Activity UI elements. (Keeps core logic for sample + * seperate.) + */ + internal inner class MainUi (root: View) : View.OnClickListener { + + init { + main_primary_send1.setOnClickListener(this) + main_primary_send2.setOnClickListener(this) + main_primary_config.setOnClickListener(this) + + main_secondary_send1.setOnClickListener(this) + main_secondary_send2.setOnClickListener(this) + main_secondary_config.setOnClickListener(this) + + (root.findViewById<View>(R.id.btnA) as Button).setOnClickListener(this) + } + + private val titlePrimaryText: String + get() { + if (main_primary_title != null) { + return main_primary_title.text.toString() + } + return "" + } + + private val titleSecondaryText: String + get() { + if (main_primary_title != null) { + return main_secondary_title.text.toString() + } + return "" + } + + override fun onClick(view: View) { + when (view.id) { + R.id.main_primary_send1 -> sendNotification(NOTI_PRIMARY1, titlePrimaryText) + R.id.main_primary_send2 -> sendNotification(NOTI_PRIMARY2, titlePrimaryText) + R.id.main_primary_config -> goToNotificationSettings(NotificationHelper.PRIMARY_CHANNEL) + + R.id.main_secondary_send1 -> sendNotification(NOTI_SECONDARY1, titleSecondaryText) + R.id.main_secondary_send2 -> sendNotification(NOTI_SECONDARY2, titleSecondaryText) + R.id.main_secondary_config -> goToNotificationSettings(NotificationHelper.SECONDARY_CHANNEL) + R.id.btnA -> goToNotificationSettings() + else -> Log.e(TAG, "Unknown click event.") + } + } + } + + companion object { + private val TAG = MainActivity::class.java.simpleName + + private val NOTI_PRIMARY1 = 1100 + private val NOTI_PRIMARY2 = 1101 + private val NOTI_SECONDARY1 = 1200 + private val NOTI_SECONDARY2 = 1201 + } +} diff --git a/notification/NotificationChannels/kotlinApp/Application/src/main/java/com/example/android/notificationchannels/NotificationHelper.kt b/notification/NotificationChannels/kotlinApp/Application/src/main/java/com/example/android/notificationchannels/NotificationHelper.kt new file mode 100644 index 00000000..f758d844 --- /dev/null +++ b/notification/NotificationChannels/kotlinApp/Application/src/main/java/com/example/android/notificationchannels/NotificationHelper.kt @@ -0,0 +1,116 @@ +/* +* Copyright 2017 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package com.example.android.notificationchannels + +import android.app.Notification +import android.app.NotificationChannel +import android.app.NotificationManager +import android.content.Context +import android.content.ContextWrapper +import android.graphics.Color + +/** + * Helper class to manage notification channels, and create notifications. + */ +internal class NotificationHelper +/** + * Registers notification channels, which can be used later by individual notifications. + + * @param ctx The application context + */ +(ctx: Context) : ContextWrapper(ctx) { + private val manager: NotificationManager by lazy { + getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager + } + + init { + + val chan1 = NotificationChannel(PRIMARY_CHANNEL, + getString(R.string.noti_channel_default), NotificationManager.IMPORTANCE_DEFAULT) + chan1.lightColor = Color.GREEN + chan1.lockscreenVisibility = Notification.VISIBILITY_PRIVATE + manager.createNotificationChannel(chan1) + + val chan2 = NotificationChannel(SECONDARY_CHANNEL, + getString(R.string.noti_channel_second), NotificationManager.IMPORTANCE_HIGH) + chan2.lightColor = Color.BLUE + chan2.lockscreenVisibility = Notification.VISIBILITY_PUBLIC + manager.createNotificationChannel(chan2) + } + + /** + * Get a notification of type 1 + + * Provide the builder rather than the notification it's self as useful for making notification + * changes. + + * @param title the title of the notification + * * + * @param body the body text for the notification + * * + * @return the builder as it keeps a reference to the notification (since API 24) + */ + fun getNotification1(title: String, body: String): Notification.Builder { + return Notification.Builder(applicationContext, PRIMARY_CHANNEL) + .setContentTitle(title) + .setContentText(body) + .setSmallIcon(smallIcon) + .setAutoCancel(true) + } + + /** + * Build notification for secondary channel. + + * @param title Title for notification. + * * + * @param body Message for notification. + * * + * @return A Notification.Builder configured with the selected channel and details + */ + fun getNotification2(title: String, body: String): Notification.Builder { + return Notification.Builder(applicationContext, SECONDARY_CHANNEL) + .setContentTitle(title) + .setContentText(body) + .setSmallIcon(smallIcon) + .setAutoCancel(true) + } + + /** + * Send a notification. + + * @param id The ID of the notification + * * + * @param notification The notification object + */ + fun notify(id: Int, notification: Notification.Builder) { + manager.notify(id, notification.build()) + } + + /** + * Get the small icon for this app + + * @return The small icon resource id + */ + private val smallIcon: Int + get() = android.R.drawable.stat_notify_chat + + + companion object { + val PRIMARY_CHANNEL = "default" + val SECONDARY_CHANNEL = "second" + } +} diff --git a/notification/NotificationChannels/kotlinApp/Application/src/main/res/drawable-hdpi/tile.9.png b/notification/NotificationChannels/kotlinApp/Application/src/main/res/drawable-hdpi/tile.9.png Binary files differnew file mode 100644 index 00000000..13586288 --- /dev/null +++ b/notification/NotificationChannels/kotlinApp/Application/src/main/res/drawable-hdpi/tile.9.png diff --git a/notification/NotificationChannels/kotlinApp/Application/src/main/res/layout/activity_main.xml b/notification/NotificationChannels/kotlinApp/Application/src/main/res/layout/activity_main.xml new file mode 100644 index 00000000..6bf04024 --- /dev/null +++ b/notification/NotificationChannels/kotlinApp/Application/src/main/res/layout/activity_main.xml @@ -0,0 +1,112 @@ +<?xml version="1.0" encoding="utf-8"?> +<RelativeLayout 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" + android:id="@+id/activity_main" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:paddingBottom="@dimen/activity_vertical_margin" + android:paddingLeft="@dimen/activity_horizontal_margin" + android:paddingRight="@dimen/activity_horizontal_margin" + android:paddingTop="@dimen/activity_vertical_margin" + tools:context="com.example.android.notificationchannels.MainActivity"> + + <GridLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:rowCount="7" + android:columnCount="2" + android:orientation="horizontal"> + + <EditText + android:id="@+id/main_primary_title" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_columnSpan="2" + android:layout_gravity="fill_horizontal" + android:hint="@string/main_primary_title" + android:text="@string/main_primary_title" /> + + <Button + android:id="@+id/main_primary_send1" + android:layout_columnWeight="1" + android:layout_height="wrap_content" + + android:text="@string/main_primary_send1" /> + + <Button + android:id="@+id/main_primary_send2" + android:layout_columnWeight="1" + android:layout_height="wrap_content" + + android:text="@string/main_primary_send2" /> + + <ImageButton + android:id="@+id/main_primary_config" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_columnSpan="2" + android:layout_gravity="fill_horizontal" + + android:src="@android:drawable/ic_menu_preferences" + android:contentDescription="@string/main_primary_config" /> + + <Space + android:layout_width="match_parent" + android:layout_height="48dp" + android:layout_columnSpan="2" + android:layout_gravity="fill_horizontal" /> + + <EditText + android:id="@+id/main_secondary_title" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_columnSpan="2" + android:layout_gravity="fill_horizontal" + android:hint="@string/main_secondary_title" + android:text="@string/main_secondary_title" /> + + <Button + android:id="@+id/main_secondary_send1" + android:layout_columnWeight="1" + android:layout_height="wrap_content" + + android:text="@string/main_secondary_send1" /> + + <Button + android:id="@+id/main_secondary_send2" + android:layout_columnWeight="1" + android:layout_height="wrap_content" + + android:text="@string/main_secondary_send2"/> + + + <ImageButton + android:id="@+id/main_secondary_config" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_columnSpan="2" + android:layout_gravity="fill_horizontal" + + android:src="@android:drawable/ic_menu_preferences" + android:contentDescription="@string/main_secondary_config" /> + + </GridLayout> + + <LinearLayout + android:id="@+id/main_footer" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="horizontal" + android:layout_alignParentBottom="true"> + + <Button + android:text="@string/btnA_title" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:id="@+id/btnA" + android:layout_weight="1" /> + </LinearLayout> + + +</RelativeLayout> diff --git a/notification/NotificationChannels/kotlinApp/Application/src/main/res/mipmap-hdpi/ic_launcher.png b/notification/NotificationChannels/kotlinApp/Application/src/main/res/mipmap-hdpi/ic_launcher.png Binary files differnew file mode 100644 index 00000000..d9584e23 --- /dev/null +++ b/notification/NotificationChannels/kotlinApp/Application/src/main/res/mipmap-hdpi/ic_launcher.png diff --git a/notification/NotificationChannels/kotlinApp/Application/src/main/res/mipmap-mdpi/ic_launcher.png b/notification/NotificationChannels/kotlinApp/Application/src/main/res/mipmap-mdpi/ic_launcher.png Binary files differnew file mode 100644 index 00000000..3203a44a --- /dev/null +++ b/notification/NotificationChannels/kotlinApp/Application/src/main/res/mipmap-mdpi/ic_launcher.png diff --git a/notification/NotificationChannels/kotlinApp/Application/src/main/res/mipmap-xhdpi/ic_launcher.png b/notification/NotificationChannels/kotlinApp/Application/src/main/res/mipmap-xhdpi/ic_launcher.png Binary files differnew file mode 100644 index 00000000..8d2467fa --- /dev/null +++ b/notification/NotificationChannels/kotlinApp/Application/src/main/res/mipmap-xhdpi/ic_launcher.png diff --git a/notification/NotificationChannels/kotlinApp/Application/src/main/res/mipmap-xxhdpi/ic_launcher.png b/notification/NotificationChannels/kotlinApp/Application/src/main/res/mipmap-xxhdpi/ic_launcher.png Binary files differnew file mode 100644 index 00000000..2db9c8a2 --- /dev/null +++ b/notification/NotificationChannels/kotlinApp/Application/src/main/res/mipmap-xxhdpi/ic_launcher.png diff --git a/notification/NotificationChannels/kotlinApp/Application/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/notification/NotificationChannels/kotlinApp/Application/src/main/res/mipmap-xxxhdpi/ic_launcher.png Binary files differnew file mode 100644 index 00000000..319446bc --- /dev/null +++ b/notification/NotificationChannels/kotlinApp/Application/src/main/res/mipmap-xxxhdpi/ic_launcher.png diff --git a/notification/NotificationChannels/kotlinApp/Application/src/main/res/values-sw600dp/template-dimens.xml b/notification/NotificationChannels/kotlinApp/Application/src/main/res/values-sw600dp/template-dimens.xml new file mode 100644 index 00000000..22074a2b --- /dev/null +++ b/notification/NotificationChannels/kotlinApp/Application/src/main/res/values-sw600dp/template-dimens.xml @@ -0,0 +1,24 @@ +<!-- + 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. + --> + +<resources> + + <!-- Semantic definitions --> + + <dimen name="horizontal_page_margin">@dimen/margin_huge</dimen> + <dimen name="vertical_page_margin">@dimen/margin_medium</dimen> + +</resources> diff --git a/notification/NotificationChannels/kotlinApp/Application/src/main/res/values-sw600dp/template-styles.xml b/notification/NotificationChannels/kotlinApp/Application/src/main/res/values-sw600dp/template-styles.xml new file mode 100644 index 00000000..03d19741 --- /dev/null +++ b/notification/NotificationChannels/kotlinApp/Application/src/main/res/values-sw600dp/template-styles.xml @@ -0,0 +1,25 @@ +<!-- + 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. + --> + +<resources> + + <style name="Widget.SampleMessage"> + <item name="android:textAppearance">?android:textAppearanceLarge</item> + <item name="android:lineSpacingMultiplier">1.2</item> + <item name="android:shadowDy">-6.5</item> + </style> + +</resources> diff --git a/notification/NotificationChannels/kotlinApp/Application/src/main/res/values-v11/template-styles.xml b/notification/NotificationChannels/kotlinApp/Application/src/main/res/values-v11/template-styles.xml new file mode 100644 index 00000000..8c1ea66f --- /dev/null +++ b/notification/NotificationChannels/kotlinApp/Application/src/main/res/values-v11/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + 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. + --> + +<resources> + + <!-- Activity themes --> + <style name="Theme.Base" parent="android:Theme.Holo.Light" /> + +</resources> diff --git a/notification/NotificationChannels/kotlinApp/Application/src/main/res/values-v21/base-colors.xml b/notification/NotificationChannels/kotlinApp/Application/src/main/res/values-v21/base-colors.xml new file mode 100644 index 00000000..8b6ec3f8 --- /dev/null +++ b/notification/NotificationChannels/kotlinApp/Application/src/main/res/values-v21/base-colors.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> + +<resources> + + +</resources> diff --git a/notification/NotificationChannels/kotlinApp/Application/src/main/res/values-v21/base-template-styles.xml b/notification/NotificationChannels/kotlinApp/Application/src/main/res/values-v21/base-template-styles.xml new file mode 100644 index 00000000..c778e4f9 --- /dev/null +++ b/notification/NotificationChannels/kotlinApp/Application/src/main/res/values-v21/base-template-styles.xml @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> + +<resources> + + <!-- Activity themes --> + <style name="Theme.Base" parent="android:Theme.Material.Light"> + </style> + +</resources> diff --git a/notification/NotificationChannels/kotlinApp/Application/src/main/res/values-w820dp/dimens.xml b/notification/NotificationChannels/kotlinApp/Application/src/main/res/values-w820dp/dimens.xml new file mode 100644 index 00000000..63fc8164 --- /dev/null +++ b/notification/NotificationChannels/kotlinApp/Application/src/main/res/values-w820dp/dimens.xml @@ -0,0 +1,6 @@ +<resources> + <!-- Example customization of dimensions originally defined in res/values/dimens.xml + (such as screen margins) for screens with more than 820dp of available width. This + would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). --> + <dimen name="activity_horizontal_margin">64dp</dimen> +</resources> diff --git a/notification/NotificationChannels/kotlinApp/Application/src/main/res/values/base-strings.xml b/notification/NotificationChannels/kotlinApp/Application/src/main/res/values/base-strings.xml new file mode 100644 index 00000000..ace10008 --- /dev/null +++ b/notification/NotificationChannels/kotlinApp/Application/src/main/res/values/base-strings.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> + +<resources> + <string name="app_name">NotificationChannels</string> + <string name="intro_message"> + <![CDATA[ + + +Demonstration of using channels to categorize notifications by topic. This feature was added in +Android O, and allows users to have fine-grained control over their notificatin preferences. + + + ]]> + </string> +</resources> diff --git a/notification/NotificationChannels/kotlinApp/Application/src/main/res/values/colors.xml b/notification/NotificationChannels/kotlinApp/Application/src/main/res/values/colors.xml new file mode 100644 index 00000000..3ab3e9cb --- /dev/null +++ b/notification/NotificationChannels/kotlinApp/Application/src/main/res/values/colors.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <color name="colorPrimary">#3F51B5</color> + <color name="colorPrimaryDark">#303F9F</color> + <color name="colorAccent">#FF4081</color> +</resources> diff --git a/notification/NotificationChannels/kotlinApp/Application/src/main/res/values/dimens.xml b/notification/NotificationChannels/kotlinApp/Application/src/main/res/values/dimens.xml new file mode 100644 index 00000000..47c82246 --- /dev/null +++ b/notification/NotificationChannels/kotlinApp/Application/src/main/res/values/dimens.xml @@ -0,0 +1,5 @@ +<resources> + <!-- Default screen margins, per the Android Design guidelines. --> + <dimen name="activity_horizontal_margin">16dp</dimen> + <dimen name="activity_vertical_margin">16dp</dimen> +</resources> diff --git a/notification/NotificationChannels/kotlinApp/Application/src/main/res/values/strings.xml b/notification/NotificationChannels/kotlinApp/Application/src/main/res/values/strings.xml new file mode 100644 index 00000000..8d2e69f9 --- /dev/null +++ b/notification/NotificationChannels/kotlinApp/Application/src/main/res/values/strings.xml @@ -0,0 +1,28 @@ +<resources> + <string name="btn1_description">Start foreground service</string> + <string name="btn1_title" >Start</string> + <string name="simple_service_title">Simple Service</string> + <string name="simple_service_desc">Simple Service from the OTest app</string> + + <string name="main_create_noti2_btn">Send</string> + + <string name="btnA_title">Go to Settings</string> + <string name="noti_channel_default">Primary Channel</string> + <string name="noti1_title">Notification 1 Title</string> + <string name="primary1_body">The content</string> + <string name="noti2_title">Second notification</string> + <string name="secondary1_body">Notification body text.</string> + <string name="noti_channel_second">Secondary Channel</string> + + <string name="main_primary_title">Primary Channel</string> + <string name="main_primary_send1">Send 1</string> + <string name="main_primary_send2">Send 2</string> + <string name="main_primary_config">Go to primary settings</string> + + <string name="main_secondary_title">Secondary Channel</string> + <string name="main_secondary_send1">Send 1</string> + <string name="main_secondary_send2">Send 2</string> + <string name="main_secondary_config">Go to secondary settings</string> + <string name="primary2_body">Second Notification for Primary Channel</string> + <string name="secondary2_body">Second Notification for Secondary Channel</string> +</resources> diff --git a/notification/NotificationChannels/kotlinApp/Application/src/main/res/values/template-dimens.xml b/notification/NotificationChannels/kotlinApp/Application/src/main/res/values/template-dimens.xml new file mode 100644 index 00000000..39e710b5 --- /dev/null +++ b/notification/NotificationChannels/kotlinApp/Application/src/main/res/values/template-dimens.xml @@ -0,0 +1,32 @@ +<!-- + 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. + --> + +<resources> + + <!-- Define standard dimensions to comply with Holo-style grids and rhythm. --> + + <dimen name="margin_tiny">4dp</dimen> + <dimen name="margin_small">8dp</dimen> + <dimen name="margin_medium">16dp</dimen> + <dimen name="margin_large">32dp</dimen> + <dimen name="margin_huge">64dp</dimen> + + <!-- Semantic definitions --> + + <dimen name="horizontal_page_margin">@dimen/margin_medium</dimen> + <dimen name="vertical_page_margin">@dimen/margin_medium</dimen> + +</resources> diff --git a/notification/NotificationChannels/kotlinApp/Application/src/main/res/values/template-styles.xml b/notification/NotificationChannels/kotlinApp/Application/src/main/res/values/template-styles.xml new file mode 100644 index 00000000..6e7d593d --- /dev/null +++ b/notification/NotificationChannels/kotlinApp/Application/src/main/res/values/template-styles.xml @@ -0,0 +1,42 @@ +<!-- + 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. + --> + +<resources> + + <!-- Activity themes --> + + <style name="Theme.Base" parent="android:Theme.Light" /> + + <style name="Theme.Sample" parent="Theme.Base" /> + + <style name="AppTheme" parent="Theme.Sample" /> + <!-- Widget styling --> + + <style name="Widget" /> + + <style name="Widget.SampleMessage"> + <item name="android:textAppearance">?android:textAppearanceMedium</item> + <item name="android:lineSpacingMultiplier">1.1</item> + </style> + + <style name="Widget.SampleMessageTile"> + <item name="android:background">@drawable/tile</item> + <item name="android:shadowColor">#7F000000</item> + <item name="android:shadowDy">-3.5</item> + <item name="android:shadowRadius">2</item> + </style> + +</resources> diff --git a/notification/NotificationChannels/kotlinApp/build.gradle b/notification/NotificationChannels/kotlinApp/build.gradle new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/notification/NotificationChannels/kotlinApp/build.gradle diff --git a/notification/NotificationChannels/kotlinApp/gradle/wrapper/gradle-wrapper.jar b/notification/NotificationChannels/kotlinApp/gradle/wrapper/gradle-wrapper.jar Binary files differnew file mode 100644 index 00000000..8c0fb64a --- /dev/null +++ b/notification/NotificationChannels/kotlinApp/gradle/wrapper/gradle-wrapper.jar diff --git a/notification/NotificationChannels/kotlinApp/gradle/wrapper/gradle-wrapper.properties b/notification/NotificationChannels/kotlinApp/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..a5c72267 --- /dev/null +++ b/notification/NotificationChannels/kotlinApp/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Mon May 15 21:58:40 PDT 2017 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip diff --git a/notification/NotificationChannels/kotlinApp/gradlew b/notification/NotificationChannels/kotlinApp/gradlew new file mode 100755 index 00000000..91a7e269 --- /dev/null +++ b/notification/NotificationChannels/kotlinApp/gradlew @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# For Cygwin, ensure paths are in UNIX format before anything is touched. +if $cygwin ; then + [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +fi + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/notification/NotificationChannels/kotlinApp/gradlew.bat b/notification/NotificationChannels/kotlinApp/gradlew.bat new file mode 100644 index 00000000..aec99730 --- /dev/null +++ b/notification/NotificationChannels/kotlinApp/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windowz variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+if "%@eval[2+2]" == "4" goto 4NT_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+goto execute
+
+:4NT_args
+@rem Get arguments from the 4NT Shell from JP Software
+set CMD_LINE_ARGS=%$
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/notification/NotificationChannels/kotlinApp/screenshots/1-main.png b/notification/NotificationChannels/kotlinApp/screenshots/1-main.png Binary files differnew file mode 100755 index 00000000..dc3bc880 --- /dev/null +++ b/notification/NotificationChannels/kotlinApp/screenshots/1-main.png diff --git a/notification/NotificationChannels/kotlinApp/screenshots/icon-web.png b/notification/NotificationChannels/kotlinApp/screenshots/icon-web.png Binary files differnew file mode 100644 index 00000000..f9635804 --- /dev/null +++ b/notification/NotificationChannels/kotlinApp/screenshots/icon-web.png diff --git a/notification/NotificationChannels/kotlinApp/settings.gradle b/notification/NotificationChannels/kotlinApp/settings.gradle new file mode 100644 index 00000000..0a5c310b --- /dev/null +++ b/notification/NotificationChannels/kotlinApp/settings.gradle @@ -0,0 +1,2 @@ + +include 'Application' |