-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba7c36f
commit df853a6
Showing
47 changed files
with
2,096 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.idea | ||
*.iml | ||
local.properties | ||
build | ||
.gradle | ||
# Eclipse project files | ||
.project | ||
.settings/ | ||
.classpath |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# How to become a contributor and submit your own code | ||
|
||
## Contributor License Agreements | ||
|
||
We'd love to accept your sample apps and patches! Before we can take them, we | ||
have to jump a couple of legal hurdles. | ||
|
||
Please fill out either the individual or corporate Contributor License Agreement | ||
(CLA). | ||
|
||
* If you are an individual writing original source code and you're sure you | ||
own the intellectual property, then you'll need to sign an [individual CLA] | ||
(https://developers.google.com/open-source/cla/individual). | ||
* If you work for a company that wants to allow you to contribute your work, | ||
then you'll need to sign a [corporate CLA] | ||
(https://developers.google.com/open-source/cla/corporate). | ||
|
||
Follow either of the two links above to access the appropriate CLA and | ||
instructions for how to sign and return it. Once we receive it, we'll be able to | ||
accept your pull requests. | ||
|
||
## Contributing A Patch | ||
|
||
1. Submit an issue describing your proposed change to the repo in question. | ||
1. The repo owner will respond to your issue promptly. | ||
1. If your proposed change is accepted, and you haven't already done so, sign a | ||
Contributor License Agreement (see details above). | ||
1. Fork the desired repo, develop and test your code changes. | ||
1. Ensure that your code adheres to the existing style in the sample to which | ||
you are contributing. Refer to the | ||
[Google Cloud Platform Samples Style Guide] | ||
(https://github.com/GoogleCloudPlatform/Template/wiki/style.html) for the | ||
recommended coding standards for this organization. | ||
1. Ensure that your code has an appropriate set of unit tests which all pass. | ||
1. Submit a pull request. |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Egg Timer | ||
|
||
A timer app for cooking eggs, using notifications. | ||
|
||
<!-- <p align="center"> | ||
<img src="screenshot.png" style="width:528px;max-width: 100%;"> | ||
</p> --> | ||
|
||
## Features | ||
|
||
- adding a notification to the starter app. | ||
- cancelling a notification. | ||
- creating channels for different types of notifications. | ||
- customizing the notifications. | ||
- adding quick actions to make the notification interactive. | ||
- turning off notification badges. | ||
|
||
Based on [Using Android Notifications](https://developer.android.com/codelabs/advanced-android-kotlin-training-notifications#0) by Google Codelabs (2022). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright (C) 2019 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. | ||
*/ | ||
|
||
apply plugin: 'com.android.application' | ||
apply plugin: 'kotlin-android' | ||
apply plugin: 'kotlin-kapt' | ||
|
||
android { | ||
compileSdkVersion 29 | ||
defaultConfig { | ||
applicationId "com.example.android.eggtimernotifications" | ||
minSdkVersion 19 | ||
targetSdkVersion 29 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
|
||
// Enables data binding. | ||
dataBinding { | ||
enabled = true | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | ||
implementation 'androidx.appcompat:appcompat:1.0.2' | ||
implementation 'androidx.core:core-ktx:1.0.2' | ||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3' | ||
|
||
implementation 'androidx.legacy:legacy-support-v4:1.0.0' | ||
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0-rc01' | ||
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.1.0-rc01' | ||
testImplementation 'junit:junit:4.12' | ||
androidTestImplementation 'androidx.test:runner:1.2.0' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' | ||
|
||
//for fcm | ||
implementation 'com.google.firebase:firebase-core:17.0.0' | ||
implementation 'com.google.firebase:firebase-iid:19.0.1' | ||
implementation 'com.google.firebase:firebase-messaging:19.0.1' | ||
implementation 'android.arch.work:work-runtime:1.0.1' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
~ Copyright (C) 2019 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. | ||
--> | ||
|
||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.example.android.eggtimernotifications"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@drawable/egg_icon" | ||
android:label="@string/app_name" | ||
android:roundIcon="@drawable/egg_notification" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
|
||
<activity android:name=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN"/> | ||
|
||
<category android:name="android.intent.category.LAUNCHER"/> | ||
</intent-filter> | ||
</activity> | ||
|
||
<receiver | ||
android:name=".receiver.AlarmReceiver" | ||
android:enabled="true" | ||
android:exported="false"> | ||
</receiver> | ||
<receiver | ||
android:name=".receiver.SnoozeReceiver" | ||
android:enabled="true" | ||
android:exported="false"> | ||
</receiver> | ||
|
||
</application> | ||
|
||
</manifest> |
35 changes: 35 additions & 0 deletions
35
20-egg-timer/app/src/main/java/com/example/android/eggtimernotifications/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (C) 2019 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. | ||
*/ | ||
|
||
package com.example.android.eggtimernotifications | ||
|
||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.example.android.eggtimernotifications.ui.EggTimerFragment | ||
|
||
class MainActivity : AppCompatActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
setContentView(R.layout.activity_main) | ||
if (savedInstanceState == null) { | ||
supportFragmentManager.beginTransaction() | ||
.replace(R.id.container, EggTimerFragment.newInstance()) | ||
.commitNow() | ||
} | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...mer/app/src/main/java/com/example/android/eggtimernotifications/receiver/AlarmReceiver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (C) 2019 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. | ||
*/ | ||
|
||
package com.example.android.eggtimernotifications.receiver | ||
|
||
import android.app.NotificationManager | ||
import android.content.BroadcastReceiver | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.widget.Toast | ||
import androidx.core.content.ContextCompat | ||
import com.example.android.eggtimernotifications.R | ||
import com.example.android.eggtimernotifications.util.sendNotification | ||
|
||
class AlarmReceiver: BroadcastReceiver() { | ||
|
||
override fun onReceive(context: Context, intent: Intent) { | ||
// Step 1.10 [Optional] remove toast | ||
// Toast.makeText(context, context.getText(R.string.eggs_ready), Toast.LENGTH_SHORT).show() | ||
|
||
// Step 1.9 add call to sendNotification | ||
val notificationManager = ContextCompat.getSystemService( | ||
context, | ||
NotificationManager::class.java | ||
) as NotificationManager | ||
|
||
notificationManager.sendNotification( | ||
context.getText(R.string.eggs_ready).toString(), | ||
context | ||
) | ||
|
||
} | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
...er/app/src/main/java/com/example/android/eggtimernotifications/receiver/SnoozeReceiver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (C) 2019 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. | ||
*/ | ||
|
||
package com.example.android.eggtimernotifications.receiver | ||
|
||
import android.app.AlarmManager | ||
import android.app.NotificationManager | ||
import android.app.PendingIntent | ||
import android.content.BroadcastReceiver | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.os.SystemClock | ||
import android.text.format.DateUtils | ||
import androidx.core.app.AlarmManagerCompat | ||
import androidx.core.content.ContextCompat | ||
|
||
class SnoozeReceiver: BroadcastReceiver() { | ||
private val REQUEST_CODE = 0 | ||
|
||
override fun onReceive(context: Context, intent: Intent) { | ||
val triggerTime = SystemClock.elapsedRealtime() + DateUtils.MINUTE_IN_MILLIS | ||
|
||
val notifyIntent = Intent(context, AlarmReceiver::class.java) | ||
val notifyPendingIntent = PendingIntent.getBroadcast( | ||
context, | ||
REQUEST_CODE, | ||
notifyIntent, | ||
PendingIntent.FLAG_UPDATE_CURRENT | ||
) | ||
val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager | ||
AlarmManagerCompat.setExactAndAllowWhileIdle( | ||
alarmManager, | ||
AlarmManager.ELAPSED_REALTIME_WAKEUP, | ||
triggerTime, | ||
notifyPendingIntent | ||
) | ||
|
||
val notificationManager = ContextCompat.getSystemService( | ||
context, | ||
NotificationManager::class.java | ||
) as NotificationManager | ||
notificationManager.cancelAll() | ||
} | ||
|
||
} |
Oops, something went wrong.