Skip to content

Commit 85f6ffb

Browse files
authored
Changed Notifications for Android O.
Notification changes
2 parents 80a295c + f3bdfd8 commit 85f6ffb

File tree

5 files changed

+47
-51
lines changed

5 files changed

+47
-51
lines changed

app/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ android {
77
minSdkVersion 21
88
targetSdkVersion 26
99
versionCode 1
10-
versionName "1.0"
10+
versionName "1.3"
1111
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1212
}
1313
buildTypes {

app/src/main/java/com/pronoy/mukhe/todoapplication/Acitvities/AddTodoDialog.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public void onDateSet(DatePicker datePicker, int year, int monthOfYear, int dayO
9090
@Override
9191
public void onClick(View view) {
9292
Calendar calendar = Calendar.getInstance();
93-
new DatePickerDialog(AddTodoDialog.this, dateSetListener,
93+
new DatePickerDialog(AddTodoDialog.this, R.style.custom, dateSetListener,
9494
calendar.get(Calendar.YEAR),
9595
calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)).show();
9696
}
@@ -109,7 +109,7 @@ public void onTimeSet(TimePicker timePicker, int hour, int minute) {
109109
@Override
110110
public void onClick(View view) {
111111
Calendar calendar = Calendar.getInstance();
112-
new TimePickerDialog(AddTodoDialog.this, timeSetListener,
112+
new TimePickerDialog(AddTodoDialog.this, R.style.custom, timeSetListener,
113113
calendar.get(Calendar.HOUR),
114114
calendar.get(Calendar.MINUTE), true).show();
115115
}

app/src/main/java/com/pronoy/mukhe/todoapplication/Acitvities/SplashScreen.java

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package com.pronoy.mukhe.todoapplication.Acitvities;
22

3+
import android.app.NotificationChannel;
4+
import android.app.NotificationManager;
35
import android.content.Intent;
46
import android.content.SharedPreferences;
7+
import android.os.Build;
58
import android.os.Handler;
69
import android.support.v7.app.AppCompatActivity;
710
import android.os.Bundle;
@@ -17,6 +20,14 @@ protected void onCreate(Bundle savedInstanceState) {
1720
super.onCreate(savedInstanceState);
1821
setContentView(R.layout.activity_splash_screen);
1922
Constants.databaseController = new DatabaseController(getApplicationContext());
23+
Constants.NOTIFICATION_MANAGER = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
24+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
25+
Constants.NOTIFICATION_CHANNEL = new NotificationChannel(String
26+
.valueOf(Constants.NOTIFICATION_CHANNEL_ID),
27+
Constants.NOTIFICATION_CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);
28+
Constants.NOTIFICATION_CHANNEL.setDescription(Constants.NOTIFICATION_CHANNEL_DESCRIPTION);
29+
Constants.NOTIFICATION_MANAGER.createNotificationChannel(Constants.NOTIFICATION_CHANNEL);
30+
}
2031

2132
new Handler().postDelayed(new Runnable() {
2233
@Override
@@ -28,9 +39,11 @@ public void run() {
2839
SharedPreferences.Editor editor = sharedPreferences.edit();
2940
editor.putBoolean(Constants.LOG_IN_STATUS, true);
3041
editor.apply();
31-
changeActivityIntent = new Intent(SplashScreen.this, CategoryActivity.class);
42+
changeActivityIntent = new Intent(SplashScreen.this,
43+
CategoryActivity.class);
3244
} else {
33-
changeActivityIntent = new Intent(SplashScreen.this, TodoActivity.class);
45+
changeActivityIntent = new Intent(SplashScreen.this,
46+
TodoActivity.class);
3447
}
3548
startActivity(changeActivityIntent);
3649
finish();
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
package com.pronoy.mukhe.todoapplication.Helper;
22

33
import android.app.AlarmManager;
4-
import android.app.NotificationChannel;
5-
import android.app.NotificationManager;
64
import android.app.PendingIntent;
75
import android.content.BroadcastReceiver;
86
import android.content.Context;
97
import android.content.Intent;
108
import android.media.Ringtone;
119
import android.media.RingtoneManager;
1210
import android.net.Uri;
13-
import android.os.Build;
1411
import android.os.Bundle;
1512
import android.support.v4.app.NotificationCompat;
1613

@@ -40,40 +37,18 @@ public void onReceive(Context context, Intent intent) {
4037
0,
4138
todoIntent,
4239
0);
43-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
44-
NotificationChannel channel = new NotificationChannel(String
45-
.valueOf(Constants.NOTIFICATION_CHANNEL_ID),
46-
Constants.NOTIFICATION_CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);
47-
NotificationCompat.Builder builder = new NotificationCompat.Builder(context,
48-
channel.getId())
49-
.setSmallIcon(R.drawable.notification_event)
50-
.setContentTitle(title)
51-
.setContentText(desc)
52-
.setPriority(NotificationCompat.PRIORITY_HIGH)
53-
.setContentIntent(pendingIntent)
54-
.setChannelId(String.valueOf(Constants.NOTIFICATION_CHANNEL_ID))
55-
.setAutoCancel(true);
56-
NotificationManager notificationManager = (NotificationManager) context
57-
.getSystemService(Context.NOTIFICATION_SERVICE);
58-
notificationManager.notify(Constants.NOTIFICATION_ID, builder.build());
59-
Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
60-
Ringtone ringtone = RingtoneManager.getRingtone(context, uri);
61-
ringtone.play();
62-
} else {
63-
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
64-
.setSmallIcon(R.drawable.notification_event)
65-
.setContentTitle(title)
66-
.setContentText(desc)
67-
.setChannelId(String.valueOf(Constants.NOTIFICATION_CHANNEL_ID))
68-
.setPriority(NotificationCompat.PRIORITY_HIGH)
69-
.setContentIntent(pendingIntent)
70-
.setAutoCancel(true);
71-
NotificationManager notificationManager = (NotificationManager) context
72-
.getSystemService(Context.NOTIFICATION_SERVICE);
73-
notificationManager.notify(Constants.NOTIFICATION_ID, builder.build());
74-
Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
75-
Ringtone ringtone = RingtoneManager.getRingtone(context, uri);
76-
ringtone.play();
77-
}
40+
NotificationCompat.Builder builder = new NotificationCompat.Builder(context,
41+
String.valueOf(Constants.NOTIFICATION_CHANNEL_ID))
42+
.setSmallIcon(R.drawable.notification_event)
43+
.setContentTitle(title)
44+
.setContentText(desc)
45+
.setPriority(NotificationCompat.PRIORITY_HIGH)
46+
.setContentIntent(pendingIntent)
47+
.setChannelId(String.valueOf(Constants.NOTIFICATION_CHANNEL_ID))
48+
.setAutoCancel(true);
49+
Constants.NOTIFICATION_MANAGER.notify(Constants.NOTIFICATION_ID, builder.build());
50+
Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
51+
Ringtone ringtone = RingtoneManager.getRingtone(context, uri);
52+
ringtone.play();
7853
}
7954
}

app/src/main/java/com/pronoy/mukhe/todoapplication/Helper/Constants.java

+16-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package com.pronoy.mukhe.todoapplication.Helper;
22

3+
import android.app.NotificationChannel;
4+
import android.app.NotificationManager;
5+
import android.content.Context;
6+
import android.os.Build;
7+
38
/**
49
* Created by mukhe on 26-Apr-18.
510
* This is the class to Keep all the constants for the App.
@@ -52,12 +57,15 @@ public class Constants {
5257
/**
5358
* Drop Table.
5459
*/
55-
static final String DROP_TABLE_CATEGORY="DROP TABLE "+Constants.CATEGORY_TABLE_NAME;
56-
static final String DROP_TABLE_TODO="DROP TABLE "+Constants.TODO_TABLE_NAME;
57-
public static final String LOG_IN_STATUS="loginStatus";
58-
public static final int ADD_TODO_DIALOG_REQUEST_CODE =69;
59-
public static final int ADD_CATEGORY_DIALOG_REQUEST_CODE=169;
60-
public static final int NOTIFICATION_ID =269;
61-
public static final int NOTIFICATION_CHANNEL_ID=59;
62-
public static final String NOTIFICATION_CHANNEL_NAME="Todo Tasks";
60+
static final String DROP_TABLE_CATEGORY = "DROP TABLE " + Constants.CATEGORY_TABLE_NAME;
61+
static final String DROP_TABLE_TODO = "DROP TABLE " + Constants.TODO_TABLE_NAME;
62+
public static final String LOG_IN_STATUS = "loginStatus";
63+
public static final int ADD_TODO_DIALOG_REQUEST_CODE = 69;
64+
public static final int ADD_CATEGORY_DIALOG_REQUEST_CODE = 169;
65+
public static final int NOTIFICATION_ID = 269;
66+
public static final int NOTIFICATION_CHANNEL_ID = 59;
67+
public static final String NOTIFICATION_CHANNEL_NAME = "Todo Tasks";
68+
public static final String NOTIFICATION_CHANNEL_DESCRIPTION="Notifications for reminders or todo's";
69+
public static NotificationChannel NOTIFICATION_CHANNEL;
70+
public static NotificationManager NOTIFICATION_MANAGER;
6371
}

0 commit comments

Comments
 (0)