-
Notifications
You must be signed in to change notification settings - Fork 1
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
14 changed files
with
176 additions
and
102 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
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
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
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
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
77 changes: 19 additions & 58 deletions
77
app/src/main/java/com/sagycorp/greet/Helper/NotificationCreator.java
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 |
---|---|---|
@@ -1,77 +1,38 @@ | ||
package com.sagycorp.greet.Helper; | ||
|
||
import android.app.Notification; | ||
import android.app.NotificationManager; | ||
import android.app.AlarmManager; | ||
import android.app.PendingIntent; | ||
import android.content.BroadcastReceiver; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.graphics.Color; | ||
import android.media.RingtoneManager; | ||
import android.net.Uri; | ||
import android.support.v4.app.NotificationCompat; | ||
import android.support.v4.content.WakefulBroadcastReceiver; | ||
|
||
import com.sagycorp.greet.MainActivity; | ||
import com.sagycorp.greet.R; | ||
import com.sagycorp.greet.Services.AlarmService; | ||
|
||
import java.util.Random; | ||
import java.util.Calendar; | ||
|
||
/** | ||
* Created by Dzeko on 1/26/2016. | ||
*/ | ||
public class NotificationCreator extends BroadcastReceiver { | ||
|
||
NotificationManager nm; | ||
Uri uri; | ||
private String notification[] = {"Read today's astonishing story.", | ||
"Read surprising fact from Black Box.", | ||
"Your horoscope is quite interesting today.", | ||
"Get inspired today with a great thought.", | ||
"Visit this scenic place inside."}; | ||
private Random random = new Random(); | ||
@Override | ||
public void onReceive(Context context, Intent intent) { | ||
Integer randomNumber = random.nextInt(5); | ||
nm = (NotificationManager) context | ||
.getSystemService(Context.NOTIFICATION_SERVICE); | ||
|
||
uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); | ||
Intent notificationIntent = new Intent(context, MainActivity.class); | ||
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); | ||
|
||
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); | ||
public class NotificationCreator extends WakefulBroadcastReceiver { | ||
|
||
|
||
public static void setAlarm(Context context) | ||
{ | ||
Calendar calendar = Calendar.getInstance(); | ||
calendar.setTimeInMillis(System.currentTimeMillis()); | ||
calendar.set(Calendar.HOUR_OF_DAY, 9); | ||
|
||
Intent intent = new Intent(context, NotificationCreator.class); | ||
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0,intent, PendingIntent.FLAG_UPDATE_CURRENT); | ||
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); | ||
am.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent); | ||
|
||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) | ||
{ | ||
Notification.Builder mBuilder = new Notification.Builder(context) | ||
.setSmallIcon(R.mipmap.ic_launcher) | ||
.setContentTitle("Greet") | ||
.setContentText(notification[randomNumber]) | ||
.setContentIntent(pendingIntent) | ||
.setVibrate(new long[]{1000, 1000, 1000, 1000, 1000}) | ||
.setLights(Color.BLUE, 3000, 3000) | ||
.setSound(uri) | ||
.setAutoCancel(true); | ||
|
||
nm.notify(24392, mBuilder.build()); | ||
} | ||
else if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) | ||
{ | ||
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) | ||
.setSmallIcon(R.mipmap.ic_launcher) | ||
.setContentTitle("Greet") | ||
.setContentText(notification[randomNumber]) | ||
.setContentIntent(pendingIntent) | ||
.setVibrate(new long[]{1000, 1000, 1000, 1000, 1000}) | ||
.setLights(Color.BLUE, 3000, 3000) | ||
.setSound(uri) | ||
.setAutoCancel(true); | ||
} | ||
|
||
nm.notify(24392, mBuilder.build()); | ||
} | ||
@Override | ||
public void onReceive(Context context, Intent intent) { | ||
|
||
Intent startIntent = AlarmService.startNotificationServices(context); | ||
startWakefulService(context,startIntent); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
app/src/main/java/com/sagycorp/greet/Helper/ServiceStarter.java
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 @@ | ||
package com.sagycorp.greet.Helper; | ||
|
||
import android.content.BroadcastReceiver; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
|
||
/** | ||
* Created by Dzeko on 2/4/2016. | ||
*/ | ||
public class ServiceStarter extends BroadcastReceiver { | ||
@Override | ||
public void onReceive(Context context, Intent intent) { | ||
NotificationCreator.setAlarm(context); | ||
} | ||
} |
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
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
Oops, something went wrong.