-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
1,358 changed files
with
27,498 additions
and
0 deletions.
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,15 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx | ||
local.properties |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 @@ | ||
/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,46 @@ | ||
plugins { | ||
id 'com.android.application' | ||
id 'org.jetbrains.kotlin.android' | ||
} | ||
|
||
android { | ||
compileSdk 32 | ||
|
||
defaultConfig { | ||
applicationId "com.otamurod.alarmmanager" | ||
minSdk 16 | ||
targetSdk 32 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
buildFeatures{ | ||
viewBinding true | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
kotlinOptions { | ||
jvmTarget = '1.8' | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
implementation 'androidx.core:core-ktx:1.7.0' | ||
implementation 'androidx.appcompat:appcompat:1.5.0' | ||
implementation 'com.google.android.material:material:1.6.1' | ||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4' | ||
testImplementation 'junit:junit:4.13.2' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.3' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' | ||
} |
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 |
24 changes: 24 additions & 0 deletions
24
AlarmManager/app/src/androidTest/java/com/otamurod/alarmmanager/ExampleInstrumentedTest.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,24 @@ | ||
package com.otamurod.alarmmanager | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
|
||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals("com.otamurod.alarmmanager", appContext.packageName) | ||
} | ||
} |
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,32 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
package="com.otamurod.alarmmanager"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:dataExtractionRules="@xml/data_extraction_rules" | ||
android:fullBackupContent="@xml/backup_rules" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.AlarmManager" | ||
tools:targetApi="31"> | ||
<activity | ||
android:name=".DestinationActivity" | ||
android:exported="false" /> | ||
<activity | ||
android:name=".MainActivity" | ||
android:exported="true"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
|
||
<receiver android:name=".AlarmReceiver" /> | ||
</application> | ||
|
||
</manifest> |
29 changes: 29 additions & 0 deletions
29
AlarmManager/app/src/main/java/com/otamurod/alarmmanager/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,29 @@ | ||
package com.otamurod.alarmmanager | ||
|
||
import android.app.PendingIntent | ||
import android.content.BroadcastReceiver | ||
import android.content.Context | ||
import android.content.Intent | ||
import androidx.core.app.NotificationCompat | ||
import androidx.core.app.NotificationManagerCompat | ||
|
||
class AlarmReceiver : BroadcastReceiver() { | ||
override fun onReceive(context: Context?, intent: Intent?) { | ||
|
||
val i = Intent(context, DestinationActivity::class.java) | ||
intent!!.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK | ||
val pendingIntent = PendingIntent.getActivity(context, 0, i, 0) | ||
|
||
val builder = NotificationCompat.Builder(context!!, "channelId") | ||
.setSmallIcon(R.drawable.ic_launcher_foreground) | ||
.setContentTitle("Alarm Manager") | ||
.setContentText("Learn more about Android development") | ||
.setAutoCancel(true) | ||
.setDefaults(NotificationCompat.DEFAULT_ALL) | ||
.setPriority(NotificationCompat.PRIORITY_HIGH) | ||
.setContentIntent(pendingIntent) | ||
|
||
val notificationManager = NotificationManagerCompat.from(context) | ||
notificationManager.notify(123, builder.build()) | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
AlarmManager/app/src/main/java/com/otamurod/alarmmanager/DestinationActivity.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,38 @@ | ||
package com.otamurod.alarmmanager | ||
|
||
import android.app.AlarmManager | ||
import android.app.PendingIntent | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.widget.Toast | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.otamurod.alarmmanager.databinding.ActivityDestinationBinding | ||
|
||
class DestinationActivity : AppCompatActivity() { | ||
private lateinit var binding: ActivityDestinationBinding | ||
private lateinit var alarmManager: AlarmManager | ||
private lateinit var pendingIntent: PendingIntent | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
binding = ActivityDestinationBinding.inflate(layoutInflater) | ||
setContentView(binding.root) | ||
|
||
binding.cancelAlarmBtn.setOnClickListener { | ||
cancelAlarm() | ||
} | ||
} | ||
|
||
private fun cancelAlarm() { | ||
|
||
alarmManager = getSystemService(ALARM_SERVICE) as AlarmManager | ||
val intent = Intent(this, AlarmReceiver::class.java) | ||
|
||
pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0) | ||
|
||
alarmManager.cancel(pendingIntent) | ||
|
||
Toast.makeText(this, "Alarm Cancelled", Toast.LENGTH_SHORT).show() | ||
|
||
} | ||
|
||
} |
120 changes: 120 additions & 0 deletions
120
AlarmManager/app/src/main/java/com/otamurod/alarmmanager/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,120 @@ | ||
package com.otamurod.alarmmanager | ||
|
||
import android.app.AlarmManager | ||
import android.app.NotificationChannel | ||
import android.app.NotificationManager | ||
import android.app.PendingIntent | ||
import android.content.Intent | ||
import android.os.Build | ||
import android.os.Bundle | ||
import android.widget.Toast | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.google.android.material.timepicker.MaterialTimePicker | ||
import com.google.android.material.timepicker.TimeFormat | ||
import com.otamurod.alarmmanager.databinding.ActivityMainBinding | ||
import java.util.* | ||
|
||
class MainActivity : AppCompatActivity() { | ||
|
||
private lateinit var binding: ActivityMainBinding | ||
private lateinit var timePicker: MaterialTimePicker | ||
private lateinit var calendar: Calendar | ||
private lateinit var alarmManager: AlarmManager | ||
private lateinit var pendingIntent: PendingIntent | ||
|
||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
binding = ActivityMainBinding.inflate(layoutInflater) | ||
setContentView(binding.root) | ||
|
||
createNotificationChannel() | ||
|
||
calendar = Calendar.getInstance() | ||
|
||
binding.selectTimeBtn.setOnClickListener { | ||
showTimePicker() | ||
} | ||
|
||
binding.setAlarmBtn.setOnClickListener { | ||
setAlarm() | ||
} | ||
|
||
binding.cancelAlarmBtn.setOnClickListener { | ||
cancelAlarm() | ||
} | ||
} | ||
|
||
private fun cancelAlarm() { | ||
|
||
alarmManager = getSystemService(ALARM_SERVICE) as AlarmManager | ||
val intent = Intent(this, AlarmReceiver::class.java) | ||
|
||
pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0) | ||
|
||
alarmManager.cancel(pendingIntent) | ||
|
||
Toast.makeText(this, "Alarm Cancelled", Toast.LENGTH_SHORT).show() | ||
|
||
} | ||
|
||
private fun setAlarm() { | ||
|
||
alarmManager = getSystemService(ALARM_SERVICE) as AlarmManager | ||
val intent = Intent(this, AlarmReceiver::class.java) | ||
|
||
pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0) | ||
|
||
alarmManager.setRepeating( | ||
AlarmManager.RTC_WAKEUP, | ||
calendar.timeInMillis, | ||
AlarmManager.INTERVAL_DAY, | ||
pendingIntent | ||
) | ||
|
||
Toast.makeText(this, "Alarm Set Successfully", Toast.LENGTH_SHORT).show() | ||
|
||
} | ||
|
||
private fun showTimePicker() { | ||
timePicker = MaterialTimePicker.Builder() | ||
.setTimeFormat(TimeFormat.CLOCK_12H) | ||
.setHour(12) | ||
.setMinute(0) | ||
.setTitleText("Select Alarm Time") | ||
.build() | ||
|
||
timePicker.show(supportFragmentManager, "time") | ||
|
||
timePicker.addOnPositiveButtonClickListener { | ||
if (timePicker.hour > 12) { | ||
binding.selectedTime.text = | ||
String.format("%02d:%02d PM", timePicker.hour - 12, timePicker.minute) | ||
} else { | ||
binding.selectedTime.text = | ||
String.format("%02d:%02d AM", timePicker.hour, timePicker.minute) | ||
} | ||
|
||
calendar[Calendar.HOUR_OF_DAY] = timePicker.hour | ||
calendar[Calendar.MINUTE] = timePicker.minute | ||
calendar[Calendar.SECOND] = 0 | ||
calendar[Calendar.MILLISECOND] = 0 | ||
|
||
} | ||
} | ||
|
||
private fun createNotificationChannel() { | ||
|
||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
val name: CharSequence = "RemainderChannel" | ||
val description = "Channel for Alarm Manager" | ||
val importance = NotificationManager.IMPORTANCE_HIGH | ||
val channel = NotificationChannel("channelId", name, importance) | ||
channel.description = description | ||
val notificationManager = getSystemService(NotificationManager::class.java) | ||
|
||
notificationManager.createNotificationChannel(channel) | ||
|
||
} | ||
} | ||
} |
Oops, something went wrong.