android-blogposter

Unnamed repository; edit this file 'description' to name the repository.
git clone http://git.code.weiherhei.de/android-blogposter.git
Log | Files | Refs

commit da7dd671262a2da0329a5f50819df5212799391a
parent 599511e40103592a41168e7b5a7ee84ab6dc1c23
Author: Jan Dankert <devnull@localhost>
Date:   Sun, 27 Nov 2011 17:31:44 +0100

Projekt umbenannt, Service verschoben.

Diffstat:
.project | 2+-
AndroidManifest.xml | 4++--
src/de/openrat/android/blog/Blog.java | 3+++
src/de/openrat/android/blog/MailIntentService.java | 99-------------------------------------------------------------------------------
src/de/openrat/android/blog/UploadIntentService.java | 103-------------------------------------------------------------------------------
src/de/openrat/android/blog/service/MailIntentService.java | 105+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/de/openrat/android/blog/service/UploadIntentService.java | 109+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 220 insertions(+), 205 deletions(-)

diff --git a/.project b/.project @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <projectDescription> - <name>Blog</name> + <name>Mini-Blog</name> <comment></comment> <projects> </projects> diff --git a/AndroidManifest.xml b/AndroidManifest.xml @@ -14,8 +14,8 @@ <activity android:name="PreferencesActivity"></activity> - <service android:name=".UploadIntentService"></service> - <service android:name=".MailIntentService"></service> + <service android:name=".service.UploadIntentService"></service> + <service android:name=".service.MailIntentService"></service> </application> diff --git a/src/de/openrat/android/blog/Blog.java b/src/de/openrat/android/blog/Blog.java @@ -4,6 +4,9 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; +import de.openrat.android.blog.service.MailIntentService; +import de.openrat.android.blog.service.UploadIntentService; + import android.app.Activity; import android.content.Context; import android.content.Intent; diff --git a/src/de/openrat/android/blog/MailIntentService.java b/src/de/openrat/android/blog/MailIntentService.java @@ -1,99 +0,0 @@ -/** - * - */ -package de.openrat.android.blog; - -import java.io.File; -import java.io.IOException; - -import android.app.IntentService; -import android.app.Notification; -import android.app.NotificationManager; -import android.app.PendingIntent; -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.preference.PreferenceManager; -import android.util.Log; - -/** - * @author dankert - * - */ -public class MailIntentService extends IntentService -{ - - private static final int NOTIFICATION_UPLOAD = 1; - - public MailIntentService() - { - super("UploadIntentService"); - } - - /** - * - * {@inheritDoc} - * - * @see android.app.IntentService#onHandleIntent(android.content.Intent) - */ - @Override - protected void onHandleIntent(Intent intent) - { - final String filePath = intent.getStringExtra(UploadIntentService.EXTRA_IMAGE); - - final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); - - final Intent notificationIntent = new Intent(this, Blog.class); - final PendingIntent contentIntent = PendingIntent.getActivity(this, 0, - notificationIntent, 0); - - final File file = new File(filePath); - final String tickerText = getResources() - .getString(R.string.upload_long); - final Notification notification = new Notification( - android.R.drawable.ic_menu_rotate, tickerText, System - .currentTimeMillis()); - notification.setLatestEventInfo(getApplicationContext(), getResources() - .getString(R.string.upload), file.getName(), contentIntent); - notification.flags = Notification.FLAG_ONGOING_EVENT - | Notification.FLAG_NO_CLEAR; - nm.notify(NOTIFICATION_UPLOAD, notification); - - SharedPreferences prefs = PreferenceManager - .getDefaultSharedPreferences(this); - - try - { - HTTPRequest request = new HTTPRequest(); - request.setFile(prefs.getString("param_image", "image"), FileUtils - .getBytesFromFile(file), "image.png", "image/png", "binary"); - // Alles OK. - final String msgText = getResources().getString(R.string.upload_ok); - notification.tickerText = getResources().getString( - R.string.upload_ok_long); - notification.setLatestEventInfo(getApplicationContext(), msgText, - file.getName(), contentIntent); - notification.flags = Notification.FLAG_AUTO_CANCEL; - nm.notify(NOTIFICATION_UPLOAD, notification); - Log.d(this.getClass().getName(), msgText); - } - catch (IOException e) - { - // Fehler ist aufgetreten. - final String msgText = getResources().getString( - R.string.upload_fail); - notification.tickerText = getResources().getString( - R.string.upload_fail_long); - notification.setLatestEventInfo(getApplicationContext(), msgText, e - .getMessage() - + ": " + file.getName(), contentIntent); - notification.flags = Notification.FLAG_AUTO_CANCEL; - nm.notify(NOTIFICATION_UPLOAD, notification); - - Log.e(this.getClass().getName(), msgText, e); - } - finally - { - } - } -} diff --git a/src/de/openrat/android/blog/UploadIntentService.java b/src/de/openrat/android/blog/UploadIntentService.java @@ -1,103 +0,0 @@ -/** - * - */ -package de.openrat.android.blog; - -import java.io.File; -import java.io.IOException; - -import android.app.IntentService; -import android.app.Notification; -import android.app.NotificationManager; -import android.app.PendingIntent; -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.preference.PreferenceManager; -import android.util.Log; - -/** - * @author dankert - * - */ -public class UploadIntentService extends IntentService -{ - - public static final String EXTRA_TITLE = "title"; - public static final String EXTRA_TEXT = "text"; - public static final String EXTRA_IMAGE = "image"; - - private static final int NOTIFICATION_UPLOAD = 1; - - public UploadIntentService() - { - super("UploadIntentService"); - } - - /** - * - * {@inheritDoc} - * - * @see android.app.IntentService#onHandleIntent(android.content.Intent) - */ - @Override - protected void onHandleIntent(Intent intent) - { - final String filePath = intent.getStringExtra(EXTRA_IMAGE); - - final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); - - final Intent notificationIntent = new Intent(this, Blog.class); - final PendingIntent contentIntent = PendingIntent.getActivity(this, 0, - notificationIntent, 0); - - final File file = new File(filePath); - final String tickerText = getResources() - .getString(R.string.upload_long); - final Notification notification = new Notification( - android.R.drawable.ic_menu_rotate, tickerText, System - .currentTimeMillis()); - notification.setLatestEventInfo(getApplicationContext(), getResources() - .getString(R.string.upload), file.getName(), contentIntent); - notification.flags = Notification.FLAG_ONGOING_EVENT - | Notification.FLAG_NO_CLEAR; - nm.notify(NOTIFICATION_UPLOAD, notification); - - SharedPreferences prefs = PreferenceManager - .getDefaultSharedPreferences(this); - - try - { - HTTPRequest request = new HTTPRequest(); - request.setFile(prefs.getString("param_image", "image"), FileUtils - .getBytesFromFile(file), "image.png", "image/png", "binary"); - // Alles OK. - final String msgText = getResources().getString(R.string.upload_ok); - notification.tickerText = getResources().getString( - R.string.upload_ok_long); - notification.setLatestEventInfo(getApplicationContext(), msgText, - file.getName(), contentIntent); - notification.flags = Notification.FLAG_AUTO_CANCEL; - nm.notify(NOTIFICATION_UPLOAD, notification); - Log.d(this.getClass().getName(), msgText); - } - catch (IOException e) - { - // Fehler ist aufgetreten. - final String msgText = getResources().getString( - R.string.upload_fail); - notification.tickerText = getResources().getString( - R.string.upload_fail_long); - notification.setLatestEventInfo(getApplicationContext(), msgText, e - .getMessage() - + ": " + file.getName(), contentIntent); - notification.flags = Notification.FLAG_AUTO_CANCEL; - nm.notify(NOTIFICATION_UPLOAD, notification); - - Log.e(this.getClass().getName(), msgText, e); - } - finally - { - } - } -} diff --git a/src/de/openrat/android/blog/service/MailIntentService.java b/src/de/openrat/android/blog/service/MailIntentService.java @@ -0,0 +1,105 @@ +/** + * + */ +package de.openrat.android.blog.service; + +import java.io.File; +import java.io.IOException; + +import de.openrat.android.blog.Blog; +import de.openrat.android.blog.FileUtils; +import de.openrat.android.blog.HTTPRequest; +import de.openrat.android.blog.R; +import de.openrat.android.blog.R.string; + +import android.app.IntentService; +import android.app.Notification; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; +import android.util.Log; + +/** + * @author dankert + * + */ +public class MailIntentService extends IntentService +{ + + private static final int NOTIFICATION_UPLOAD = 1; + + public MailIntentService() + { + super("UploadIntentService"); + } + + /** + * + * {@inheritDoc} + * + * @see android.app.IntentService#onHandleIntent(android.content.Intent) + */ + @Override + protected void onHandleIntent(Intent intent) + { + final String filePath = intent.getStringExtra(UploadIntentService.EXTRA_IMAGE); + + final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + + final Intent notificationIntent = new Intent(this, Blog.class); + final PendingIntent contentIntent = PendingIntent.getActivity(this, 0, + notificationIntent, 0); + + final File file = new File(filePath); + final String tickerText = getResources() + .getString(R.string.upload_long); + final Notification notification = new Notification( + android.R.drawable.ic_menu_rotate, tickerText, System + .currentTimeMillis()); + notification.setLatestEventInfo(getApplicationContext(), getResources() + .getString(R.string.upload), file.getName(), contentIntent); + notification.flags = Notification.FLAG_ONGOING_EVENT + | Notification.FLAG_NO_CLEAR; + nm.notify(NOTIFICATION_UPLOAD, notification); + + SharedPreferences prefs = PreferenceManager + .getDefaultSharedPreferences(this); + + try + { + HTTPRequest request = new HTTPRequest(); + request.setFile(prefs.getString("param_image", "image"), FileUtils + .getBytesFromFile(file), "image.png", "image/png", "binary"); + // Alles OK. + final String msgText = getResources().getString(R.string.upload_ok); + notification.tickerText = getResources().getString( + R.string.upload_ok_long); + notification.setLatestEventInfo(getApplicationContext(), msgText, + file.getName(), contentIntent); + notification.flags = Notification.FLAG_AUTO_CANCEL; + nm.notify(NOTIFICATION_UPLOAD, notification); + Log.d(this.getClass().getName(), msgText); + } + catch (IOException e) + { + // Fehler ist aufgetreten. + final String msgText = getResources().getString( + R.string.upload_fail); + notification.tickerText = getResources().getString( + R.string.upload_fail_long); + notification.setLatestEventInfo(getApplicationContext(), msgText, e + .getMessage() + + ": " + file.getName(), contentIntent); + notification.flags = Notification.FLAG_AUTO_CANCEL; + nm.notify(NOTIFICATION_UPLOAD, notification); + + Log.e(this.getClass().getName(), msgText, e); + } + finally + { + } + } +} diff --git a/src/de/openrat/android/blog/service/UploadIntentService.java b/src/de/openrat/android/blog/service/UploadIntentService.java @@ -0,0 +1,109 @@ +/** + * + */ +package de.openrat.android.blog.service; + +import java.io.File; +import java.io.IOException; + +import de.openrat.android.blog.Blog; +import de.openrat.android.blog.FileUtils; +import de.openrat.android.blog.HTTPRequest; +import de.openrat.android.blog.R; +import de.openrat.android.blog.R.string; + +import android.app.IntentService; +import android.app.Notification; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; +import android.util.Log; + +/** + * @author dankert + * + */ +public class UploadIntentService extends IntentService +{ + + public static final String EXTRA_TITLE = "title"; + public static final String EXTRA_TEXT = "text"; + public static final String EXTRA_IMAGE = "image"; + + private static final int NOTIFICATION_UPLOAD = 1; + + public UploadIntentService() + { + super("UploadIntentService"); + } + + /** + * + * {@inheritDoc} + * + * @see android.app.IntentService#onHandleIntent(android.content.Intent) + */ + @Override + protected void onHandleIntent(Intent intent) + { + final String filePath = intent.getStringExtra(EXTRA_IMAGE); + + final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + + final Intent notificationIntent = new Intent(this, Blog.class); + final PendingIntent contentIntent = PendingIntent.getActivity(this, 0, + notificationIntent, 0); + + final File file = new File(filePath); + final String tickerText = getResources() + .getString(R.string.upload_long); + final Notification notification = new Notification( + android.R.drawable.ic_menu_rotate, tickerText, System + .currentTimeMillis()); + notification.setLatestEventInfo(getApplicationContext(), getResources() + .getString(R.string.upload), file.getName(), contentIntent); + notification.flags = Notification.FLAG_ONGOING_EVENT + | Notification.FLAG_NO_CLEAR; + nm.notify(NOTIFICATION_UPLOAD, notification); + + SharedPreferences prefs = PreferenceManager + .getDefaultSharedPreferences(this); + + try + { + HTTPRequest request = new HTTPRequest(); + request.setFile(prefs.getString("param_image", "image"), FileUtils + .getBytesFromFile(file), "image.png", "image/png", "binary"); + // Alles OK. + final String msgText = getResources().getString(R.string.upload_ok); + notification.tickerText = getResources().getString( + R.string.upload_ok_long); + notification.setLatestEventInfo(getApplicationContext(), msgText, + file.getName(), contentIntent); + notification.flags = Notification.FLAG_AUTO_CANCEL; + nm.notify(NOTIFICATION_UPLOAD, notification); + Log.d(this.getClass().getName(), msgText); + } + catch (IOException e) + { + // Fehler ist aufgetreten. + final String msgText = getResources().getString( + R.string.upload_fail); + notification.tickerText = getResources().getString( + R.string.upload_fail_long); + notification.setLatestEventInfo(getApplicationContext(), msgText, e + .getMessage() + + ": " + file.getName(), contentIntent); + notification.flags = Notification.FLAG_AUTO_CANCEL; + nm.notify(NOTIFICATION_UPLOAD, notification); + + Log.e(this.getClass().getName(), msgText, e); + } + finally + { + } + } +}