forked from agenthun/ReadingRoutine
-
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
15 changed files
with
252 additions
and
14 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
35 changes: 35 additions & 0 deletions
35
reading_routine/src/main/java/com/agenthun/readingroutine/services/AlarmNoiser.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,35 @@ | ||
package com.agenthun.readingroutine.services; | ||
|
||
import android.app.AlarmManager; | ||
import android.app.PendingIntent; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.os.SystemClock; | ||
|
||
/** | ||
* @project ReadingRoutine | ||
* @authors agenthun | ||
* @date 15/12/16 下午8:30. | ||
*/ | ||
public class AlarmNoiser { | ||
public static void startAlarmNoiserService(Context context, int seconds, Class<?> cls, String action) { | ||
AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); | ||
|
||
Intent intent = new Intent(context, cls); | ||
intent.setAction(action); | ||
PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); | ||
|
||
long triggerAlarmTime = SystemClock.elapsedRealtime(); | ||
manager.setRepeating(AlarmManager.ELAPSED_REALTIME, triggerAlarmTime, seconds * 1000, pendingIntent); | ||
} | ||
|
||
public static void stopAlarmNoiserService(Context context, Class<?> cls, String action) { | ||
AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); | ||
|
||
Intent intent = new Intent(context, cls); | ||
intent.setAction(action); | ||
PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); | ||
|
||
manager.cancel(pendingIntent); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
reading_routine/src/main/java/com/agenthun/readingroutine/services/AlarmNoiserService.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,79 @@ | ||
package com.agenthun.readingroutine.services; | ||
|
||
import android.app.NotificationManager; | ||
import android.app.PendingIntent; | ||
import android.app.Service; | ||
import android.content.Intent; | ||
import android.os.IBinder; | ||
import android.support.v4.app.NotificationCompat; | ||
import android.support.v4.app.TaskStackBuilder; | ||
import android.util.Log; | ||
|
||
import com.agenthun.readingroutine.R; | ||
import com.agenthun.readingroutine.activities.MainActivity; | ||
|
||
public class AlarmNoiserService extends Service { | ||
private static final String TAG = "AlarmNoiserService"; | ||
public static final String ACTION = "com.agenthun.readingroutine.services.AlarmNoiserService"; | ||
|
||
NotificationCompat.Builder mBuilder; | ||
|
||
public AlarmNoiserService() { | ||
} | ||
|
||
@Override | ||
public IBinder onBind(Intent intent) { | ||
// TODO: Return the communication channel to the service. | ||
throw new UnsupportedOperationException("Not yet implemented"); | ||
} | ||
|
||
@Override | ||
public void onCreate() { | ||
Log.d(TAG, "AlarmNoiserService onCreate() returned: "); | ||
super.onCreate(); | ||
} | ||
|
||
private void initNotifiManager() { | ||
mBuilder = new NotificationCompat.Builder(this) | ||
.setSmallIcon(R.drawable.ic_reading_routine_white) | ||
.setContentTitle("阅读提醒") | ||
.setContentText("你的书该看了"); | ||
} | ||
|
||
@Override | ||
public int onStartCommand(Intent intent, int flags, int startId) { | ||
return super.onStartCommand(intent, flags, startId); | ||
} | ||
|
||
int count = 0; | ||
|
||
class AlarmNoiserThread extends Thread { | ||
@Override | ||
public void run() { | ||
Log.d(TAG, "run() returned: "); | ||
count++; | ||
if (count % 5 == 0) { | ||
showNotification(); | ||
Log.d(TAG, "run() returned: new message"); | ||
} | ||
} | ||
} | ||
|
||
private void showNotification() { | ||
Intent intent = new Intent(this, MainActivity.class); | ||
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); | ||
stackBuilder.addParentStack(MainActivity.class); | ||
stackBuilder.addNextIntent(intent); | ||
PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); | ||
mBuilder.setContentIntent(pendingIntent); | ||
NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); | ||
mNotificationManager.notify(0, mBuilder.build()); | ||
Log.d(TAG, "showNotification() returned: "); | ||
} | ||
|
||
@Override | ||
public void onDestroy() { | ||
super.onDestroy(); | ||
Log.d(TAG, "onDestroy() returned: "); | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
reading_routine/src/main/java/com/agenthun/readingroutine/services/MyIntentService.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,91 @@ | ||
package com.agenthun.readingroutine.services; | ||
|
||
import android.app.IntentService; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
|
||
/** | ||
* An {@link IntentService} subclass for handling asynchronous task requests in | ||
* a service on a separate handler thread. | ||
* <p/> | ||
* TODO: Customize class - update intent actions, extra parameters and static | ||
* helper methods. | ||
*/ | ||
public class MyIntentService extends IntentService { | ||
// TODO: Rename actions, choose action names that describe tasks that this | ||
// IntentService can perform, e.g. ACTION_FETCH_NEW_ITEMS | ||
private static final String ACTION_FOO = "com.agenthun.readingroutine.services.action.FOO"; | ||
private static final String ACTION_BAZ = "com.agenthun.readingroutine.services.action.BAZ"; | ||
|
||
// TODO: Rename parameters | ||
private static final String EXTRA_PARAM1 = "com.agenthun.readingroutine.services.extra.PARAM1"; | ||
private static final String EXTRA_PARAM2 = "com.agenthun.readingroutine.services.extra.PARAM2"; | ||
|
||
public MyIntentService() { | ||
super("MyIntentService"); | ||
} | ||
|
||
/** | ||
* Starts this service to perform action Foo with the given parameters. If | ||
* the service is already performing a task this action will be queued. | ||
* | ||
* @see IntentService | ||
*/ | ||
// TODO: Customize helper method | ||
public static void startActionFoo(Context context, String param1, String param2) { | ||
Intent intent = new Intent(context, MyIntentService.class); | ||
intent.setAction(ACTION_FOO); | ||
intent.putExtra(EXTRA_PARAM1, param1); | ||
intent.putExtra(EXTRA_PARAM2, param2); | ||
context.startService(intent); | ||
} | ||
|
||
/** | ||
* Starts this service to perform action Baz with the given parameters. If | ||
* the service is already performing a task this action will be queued. | ||
* | ||
* @see IntentService | ||
*/ | ||
// TODO: Customize helper method | ||
public static void startActionBaz(Context context, String param1, String param2) { | ||
Intent intent = new Intent(context, MyIntentService.class); | ||
intent.setAction(ACTION_BAZ); | ||
intent.putExtra(EXTRA_PARAM1, param1); | ||
intent.putExtra(EXTRA_PARAM2, param2); | ||
context.startService(intent); | ||
} | ||
|
||
@Override | ||
protected void onHandleIntent(Intent intent) { | ||
if (intent != null) { | ||
final String action = intent.getAction(); | ||
if (ACTION_FOO.equals(action)) { | ||
final String param1 = intent.getStringExtra(EXTRA_PARAM1); | ||
final String param2 = intent.getStringExtra(EXTRA_PARAM2); | ||
handleActionFoo(param1, param2); | ||
} else if (ACTION_BAZ.equals(action)) { | ||
final String param1 = intent.getStringExtra(EXTRA_PARAM1); | ||
final String param2 = intent.getStringExtra(EXTRA_PARAM2); | ||
handleActionBaz(param1, param2); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Handle action Foo in the provided background thread with the provided | ||
* parameters. | ||
*/ | ||
private void handleActionFoo(String param1, String param2) { | ||
// TODO: Handle action Foo | ||
throw new UnsupportedOperationException("Not yet implemented"); | ||
} | ||
|
||
/** | ||
* Handle action Baz in the provided background thread with the provided | ||
* parameters. | ||
*/ | ||
private void handleActionBaz(String param1, String param2) { | ||
// TODO: Handle action Baz | ||
throw new UnsupportedOperationException("Not yet implemented"); | ||
} | ||
} |
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
Binary file modified
BIN
+2.44 KB
(140%)
reading_routine/src/main/res/drawable-xxhdpi/avatar_17_raster.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+6.94 KB
(200%)
reading_routine/src/main/res/drawable-xxhdpi/avatar_18_raster.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+7.86 KB
(210%)
reading_routine/src/main/res/drawable-xxhdpi/avatar_19_raster.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-2.44 KB
(73%)
reading_routine/src/main/res/drawable-xxhdpi/avatar_1_raster.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-6.92 KB
(50%)
reading_routine/src/main/res/drawable-xxhdpi/avatar_2_raster.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-7.89 KB
(47%)
reading_routine/src/main/res/drawable-xxhdpi/avatar_3_raster.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.