Permalink
Browse files

notification phase 1

  • Loading branch information...
1 parent 54ead3e commit 7e0da30ba061b28990bfb09c1bcd50e7a3b9091c @mootoh committed Feb 25, 2012
View
@@ -51,6 +51,14 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
+
+ <service
+ android:name=".TouchService"
+ android:exported="false" >
+ <intent-filter>
+ <action android:name="net.mootoh.toggltouch.START_TASK" />
+ </intent-filter>
+ </service>
</application>
</manifest>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -61,6 +61,10 @@ private void setupSyncButton() {
Button syncButton = (Button)findViewById(R.id.syncButton);
syncButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
+ Intent intent = new Intent(TouchService.ACTION_START);
+ intent.putExtra(TouchService.TASK_DESCRIPTION, "aa");
+ startService(intent);
+
syncTasks();
}
});
@@ -7,13 +7,16 @@
import org.json.JSONException;
import android.app.Activity;
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
import android.content.ContentValues;
import android.content.Context;
+import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
-import android.widget.Toast;
public final class Tag {
public String id;
@@ -204,11 +207,7 @@ public void onSucceeded(Integer result) {
}
self.assignTask(touchedTask, activity);
Tag.setCurrent(activity, self);
- activity.runOnUiThread(new Runnable() {
- public void run() {
- Toast.makeText(activity, touchedTask.getDescription() + " start.", Toast.LENGTH_SHORT).show();
- }
- });
+ self.postNotification(touchedTask, true, activity);
}
public void onFailed(Exception e) {
@@ -225,11 +224,7 @@ public void onFailed(Exception e) {
public void onSucceeded(Integer result) {
Log.d("StopTimeEntryDelegate", "onSucceeded: " + result);
Tag.resetCurrent(activity);
- activity.runOnUiThread(new Runnable() {
- public void run() {
- Toast.makeText(activity, touchedTask.getDescription() + " end.", Toast.LENGTH_SHORT).show();
- }
- });
+ postNotification(touchedTask, false, activity);
}
public void onFailed(Exception e) {
@@ -248,11 +243,7 @@ public void onFailed(Exception e) {
public void onSucceeded(Integer result) {
Log.d("StopTimeEntryDelegate", "onSucceeded: " + result);
Tag.resetCurrent(activity);
- activity.runOnUiThread(new Runnable() {
- public void run() {
- Toast.makeText(activity, currentTask.getDescription() + " end.", Toast.LENGTH_SHORT).show();
- }
- });
+ postNotification(currentTask, false, activity);
try {
api.startTimeEntry(touchedTask, new ApiResponseDelegate<Integer>() {
@@ -266,11 +257,7 @@ public void onSucceeded(Integer result) {
}
self.assignTask(touchedTask, activity);
Tag.setCurrent(activity, self);
- activity.runOnUiThread(new Runnable() {
- public void run() {
- Toast.makeText(activity, touchedTask.getDescription() + " start.", Toast.LENGTH_SHORT).show();
- }
- });
+ postNotification(touchedTask, false, activity);
}
public void onFailed(Exception e) {
@@ -292,4 +279,10 @@ public void onFailed(Exception e) {
}
}
}
+
+ private void postNotification(Task task, boolean started, Activity activity) {
+ Intent intent = new Intent(started ? TouchService.ACTION_START : TouchService.ACTION_STOP);
+ intent.putExtra(TouchService.TASK_DESCRIPTION, task.getDescription());
+ activity.startService(intent);
+ }
}
@@ -0,0 +1,66 @@
+package net.mootoh.toggltouch;
+
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.app.Service;
+import android.content.Context;
+import android.content.Intent;
+import android.os.IBinder;
+import android.util.Log;
+
+public final class TouchService extends Service {
+ protected static final String ACTION_START = "net.mootoh.toggltouch.START_TASK";
+ protected static final String ACTION_STOP = "net.mootoh.toggltouch.STOP_TASK";
+ protected static final String TASK_DESCRIPTION = "TASK_DESCRIPTION";
+ private static final int TASK_NOTIFICATION_ID = 1;
+
+ NotificationManager notificationManager;
+
+ @Override
+ public void onCreate() {
+ Log.d(getClass().getSimpleName(), "Service created");
+ super.onCreate();
+
+ notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
+ }
+
+ @Override
+ public int onStartCommand(Intent intent, int flags, int startId) {
+ Log.d(getClass().getSimpleName(), "Service started");
+
+ String action = intent.getAction();
+ String taskDescription = intent.getExtras().getString(TASK_DESCRIPTION);
+
+ String msg = taskDescription + (action.equals(ACTION_START) ? " started." : " stopped.");
+ Notification.Builder nbuilder = new Notification.Builder(this)
+ .setTicker(msg)
+ .setAutoCancel(true)
+ .setSmallIcon(R.drawable.ic_notification)
+ .setContentTitle("TogglTouch")
+ .setContentText("Yey!");
+
+ Notification notification = nbuilder.getNotification();
+/*
+ Context context = getApplicationContext();
+ Intent notificationIntent = new Intent(context, SettingActivity.class);
+ PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
+ notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
+*/
+ notificationManager.notify(TASK_NOTIFICATION_ID, notification);
+
+ return START_STICKY;
+ }
+
+ @Override
+ public void onDestroy() {
+ Log.d(getClass().getSimpleName(), "destroying");
+ super.onDestroy();
+ }
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}

0 comments on commit 7e0da30

Please sign in to comment.