PublishIntentService.java (3154B)
1 /** 2 * 3 */ 4 package de.openrat.android.client.service; 5 6 import java.io.IOException; 7 8 import android.app.IntentService; 9 import android.app.Notification; 10 import android.app.NotificationManager; 11 import android.app.PendingIntent; 12 import android.content.Context; 13 import android.content.Intent; 14 import android.util.Log; 15 import de.openrat.android.client.FolderActivity; 16 import de.openrat.android.client.R; 17 import de.openrat.client.OpenRatClient; 18 19 /** 20 * @author dankert 21 * 22 */ 23 public class PublishIntentService extends IntentService 24 { 25 26 public static final String EXTRA_REQUEST = "request"; 27 public static final String EXTRA_ID = "objectid"; 28 public static final String EXTRA_TYPE = "type"; 29 public static final String EXTRA_NAME = "name"; 30 private static final int NOTIFICATION_PUBLISH = 2; 31 32 public PublishIntentService() 33 { 34 super("PublishIntentService"); 35 } 36 37 /** 38 * 39 * {@inheritDoc} 40 * 41 * @see android.app.IntentService#onHandleIntent(android.content.Intent) 42 */ 43 @Override 44 protected void onHandleIntent(Intent intent) 45 { 46 final OpenRatClient client = (OpenRatClient) intent 47 .getSerializableExtra(EXTRA_REQUEST); 48 49 String type = intent.getStringExtra(EXTRA_TYPE); 50 String id = intent.getStringExtra(EXTRA_ID); 51 String name = intent.getStringExtra(EXTRA_NAME); 52 53 // Erstmal alles aktivieren was geht 54 // TODO: Abfrage der gewünschten Einstellungen über AlertDialog. 55 client.setParameter("subdirs", "1"); 56 client.setParameter("pages", "1"); 57 client.setParameter("files", "1"); 58 59 final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 60 61 final Intent notificationIntent = new Intent(this, 62 FolderActivity.class); 63 final PendingIntent contentIntent = PendingIntent.getActivity(this, 64 0, notificationIntent, 0); 65 66 final Notification notification = new Notification( 67 R.drawable.logo, getResources().getString( 68 R.string.publish_long), System.currentTimeMillis()); 69 notification.setLatestEventInfo(getApplicationContext(), 70 getResources().getString(R.string.publish), name, 71 contentIntent); 72 notification.flags = Notification.FLAG_ONGOING_EVENT 73 | Notification.FLAG_NO_CLEAR; 74 nm.notify(NOTIFICATION_PUBLISH, notification); 75 76 try 77 { 78 int old = client.setTimeout(3600000); // 1 Std. 79 client.publish(type, id); 80 client.setTimeout(old); 81 82 // Alles OK. 83 notification.setLatestEventInfo(getApplicationContext(), 84 getResources().getString(R.string.publish_ok), 85 name, contentIntent); 86 notification.tickerText = getResources().getString(R.string.publish_ok_long); 87 notification.flags = Notification.FLAG_AUTO_CANCEL; 88 nm.notify(NOTIFICATION_PUBLISH, notification); 89 } 90 catch (IOException e) 91 { 92 final String msgText = getResources().getString(R.string.publish_fail); 93 notification.tickerText = getResources().getString(R.string.publish_fail_long); 94 notification.setLatestEventInfo(getApplicationContext(), 95 msgText, 96 name, contentIntent); 97 notification.flags = Notification.FLAG_AUTO_CANCEL; 98 nm.notify(NOTIFICATION_PUBLISH, notification); 99 100 Log.e(this.getClass().getName(), msgText,e); 101 } 102 finally 103 { 104 } 105 } 106 107 }