Commit 54093a9d authored by Alan McNatty's avatar Alan McNatty
Browse files

Renamed lib folder to libs which resolves our linking problem.

Reworked some of the application preferences and made some small refactoring changes as a result (moving methods to Utils to get base url and upload/sync built properly).
parent 800f8911
...@@ -18,17 +18,10 @@ ...@@ -18,17 +18,10 @@
<string name="context_menu_upload">Upload</string> <string name="context_menu_upload">Upload</string>
<string name="context_menu_view">View</string> <string name="context_menu_view">View</string>
<string name="context_menu_delete">Delete</string> <string name="context_menu_delete">Delete</string>
<string name="pref_upload_url_key">upload.uri</string>
<string name="pref_upload_url_title">Upload URI</string>
<string name="pref_upload_url_summary">Enter the URL to post files to Mahara</string>
<string name="pref_upload_url_default">http://solent-mahara.catalystdemo.co.uk/api/mobile/upload.php</string>
<string name="pref_sync_url_key">sync.uri</string> <!-- Authentication Details -->
<string name="pref_sync_url_title">Sync URI</string> <string name="prefcat_authentication">Mahara Authentication Details</string>
<string name="pref_sync_url_summary">Enter the sync URL to Mahara</string>
<string name="pref_sync_url_default">http://solent-mahara.catalystdemo.co.uk/api/mobile/sync.php</string>
<string name="pref_auth_username_key">auth.username</string> <string name="pref_auth_username_key">auth.username</string>
<string name="pref_auth_username_title">Username</string> <string name="pref_auth_username_title">Username</string>
<string name="pref_auth_username_summary">Enter your Mahara username</string> <string name="pref_auth_username_summary">Enter your Mahara username</string>
...@@ -37,6 +30,24 @@ ...@@ -37,6 +30,24 @@
<string name="pref_auth_token_title">Token</string> <string name="pref_auth_token_title">Token</string>
<string name="pref_auth_token_summary">Enter your Mahara mobile token</string> <string name="pref_auth_token_summary">Enter your Mahara mobile token</string>
<!-- Connection Details -->
<string name="prefcat_connection">Mahara Connection Details</string>
<string name="pref_base_url_key">upload.base_uri</string>
<string name="pref_base_url_title">Mahara Base URI</string>
<string name="pref_base_url_summary">Enter the Mahara base URL for file posts &amp; syncronisation</string>
<string name="pref_base_url_default">http://solent-mahara.catalystdemo.co.uk</string>
<string name="pref_upload_url_key">upload.uri</string>
<string name="pref_upload_url_title">Upload URI</string>
<string name="pref_upload_url_summary">Enter the URL to post files to Mahara</string>
<string name="pref_upload_url_default">/api/mobile/upload.php</string>
<string name="pref_sync_url_key">sync.uri</string>
<string name="pref_sync_url_title">Sync URI</string>
<string name="pref_sync_url_summary">Enter the sync URL to Mahara</string>
<string name="pref_sync_url_default">/api/mobile/sync.php</string>
<string name="pref_upload_connection_key">upload.connection</string> <string name="pref_upload_connection_key">upload.connection</string>
<string name="pref_upload_connection_title">Connection Type</string> <string name="pref_upload_connection_title">Connection Type</string>
<string name="pref_upload_connection_summary">Restrict upload to the following connection types (default is fall back to handset settings):</string> <string name="pref_upload_connection_summary">Restrict upload to the following connection types (default is fall back to handset settings):</string>
...@@ -50,9 +61,12 @@ ...@@ -50,9 +61,12 @@
<item>wifi</item> <item>wifi</item>
<item>mobile</item> <item>mobile</item>
</string-array> </string-array>
<string name="prefcat_advanced">Advanced</string>
<!-- Defaults -->
<string name="prefcat_defaults">Application Defaults</string>
<string name="prefcat_defaults_post">Default Post Settings</string>
<string name="pref_upload_journal_default_key">upload.journal.default</string> <string name="pref_upload_journal_default_key">upload.journal.default</string>
<string name="pref_upload_journal_default_title">Journal post by default</string> <string name="pref_upload_journal_default_title">Journal post by default</string>
<string name="pref_upload_journal_default_summary">Check to select a default journal to post to</string> <string name="pref_upload_journal_default_summary">Check to select a default journal to post to</string>
...@@ -76,7 +90,16 @@ ...@@ -76,7 +90,16 @@
<string name="pref_upload_tags_title">Tags</string> <string name="pref_upload_tags_title">Tags</string>
<string name="pref_upload_tags_summary">Select the default tag to add to all uploaded files/journals. <string name="pref_upload_tags_summary">Select the default tag to add to all uploaded files/journals.
Note: nothing will be shown until your first sync.</string> Note: nothing will be shown until your first sync.</string>
<string name="prefcat_defaults_notification">Default Notification Settings</string>
<!-- Notification defaults -->
<string name="pref_sync_notification_key">sync.notification</string>
<string name="pref_sync_notification_title">Enable Sync Notifications</string>
<string name="pref_sync_notification_summary">Raise notifications if new messages are found during syncronisation.</string>
<string name="prefcat_advanced">Advanced Settings</string>
<string name="pref_sync_periodic_key">sync.periodic</string> <string name="pref_sync_periodic_key">sync.periodic</string>
<string name="pref_sync_periodic_title">Periodic Sync</string> <string name="pref_sync_periodic_title">Periodic Sync</string>
<string name="pref_sync_periodic_summary">Enter the time in minutes to force a perioidc sync (0 or blank for none)</string> <string name="pref_sync_periodic_summary">Enter the time in minutes to force a perioidc sync (0 or blank for none)</string>
...@@ -105,7 +128,7 @@ ...@@ -105,7 +128,7 @@
<string name="uploadsaved">Upload saved</string> <string name="uploadsaved">Upload saved</string>
<string name="uploadnotavailable">Sorry you can only uploaded files.</string> <string name="uploadnotavailable">Sorry you can only uploaded files.</string>
<string name="capturefailed">Sorry there was a problem capturing that image.</string> <string name="capturefailed">Sorry there was a problem capturing that image.</string>
<string name="uploadingartifact">Uploading ...</string> <string name="uploadingartifact">Uploading #8230;</string>
<string name="uploading">Uploading</string> <string name="uploading">Uploading</string>
<string name="uploadnoconnection">Sorry you don\'t have a working data connection to upload at this time.</string> <string name="uploadnoconnection">Sorry you don\'t have a working data connection to upload at this time.</string>
<string name="uploadincomplete">Sorry you must enter a title and an entry for journal posts</string> <string name="uploadincomplete">Sorry you must enter a title and an entry for journal posts</string>
...@@ -136,7 +159,7 @@ ...@@ -136,7 +159,7 @@
<string name="load_config_success">Successfully loaded the configuration file.</string> <string name="load_config_success">Successfully loaded the configuration file.</string>
<string name="scan_not_available">Sorry you need to install ZXing Barcode Scanner for this.</string> <string name="scan_not_available">Sorry you need to install ZXing Barcode Scanner for this.</string>
<string name="login_authenticating">Authenticating...</string> <string name="login_authenticating">Authenticating #8230;</string>
<string name="only_one_account">Currently you may only have at most one account at any one time.</string> <string name="only_one_account">Currently you may only have at most one account at any one time.</string>
<string name="auth_result_no_connection">Server address or port number incorrect</string> <string name="auth_result_no_connection">Server address or port number incorrect</string>
......
...@@ -3,83 +3,172 @@ ...@@ -3,83 +3,172 @@
<PreferenceScreen <PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"> xmlns:android="http://schemas.android.com/apk/res/android">
<EditTextPreference <PreferenceCategory
android:key="@string/pref_upload_url_key" android:title="@string/prefcat_authentication">
android:title="@string/pref_upload_url_title" <EditTextPreference
android:summary="@string/pref_upload_url_summary" android:key="@string/pref_auth_username_key"
android:defaultValue="@string/pref_upload_url_default" /> android:title="@string/pref_auth_username_title"
<EditTextPreference android:summary="@string/pref_auth_username_summary" />
android:key="@string/pref_sync_url_key" <EditTextPreference
android:title="@string/pref_sync_url_title" android:key="@string/pref_auth_token_key"
android:summary="@string/pref_sync_url_summary" android:title="@string/pref_auth_token_title"
android:defaultValue="@string/pref_sync_url_default" /> android:summary="@string/pref_auth_token_summary" />
<EditTextPreference </PreferenceCategory>
android:key="@string/pref_auth_username_key"
android:title="@string/pref_auth_username_title" <PreferenceCategory
android:summary="@string/pref_auth_username_summary" /> android:title="@string/prefcat_connection">
<EditTextPreference
android:key="@string/pref_auth_token_key" <EditTextPreference
android:title="@string/pref_auth_token_title" android:key="@string/pref_base_url_key"
android:summary="@string/pref_auth_token_summary" /> android:title="@string/pref_base_url_title"
android:summary="@string/pref_base_url_summary"
<ListPreference android:defaultValue="@string/pref_base_url_default" />
android:key="@string/pref_upload_connection_key" <EditTextPreference
android:title="@string/pref_upload_connection_title" android:key="@string/pref_upload_url_key"
android:summary="@string/pref_upload_connection_summary" android:title="@string/pref_upload_url_title"
android:defaultValue="" android:summary="@string/pref_upload_url_summary"
android:entries="@array/pref_upload_connection_entry" android:defaultValue="@string/pref_upload_url_default" />
android:entryValues="@array/pref_upload_connection_entryValues" <EditTextPreference
android:dialogTitle="@string/pref_upload_connection_title" /> android:key="@string/pref_sync_url_key"
android:title="@string/pref_sync_url_title"
android:summary="@string/pref_sync_url_summary"
android:defaultValue="@string/pref_sync_url_default" />
<ListPreference
android:key="@string/pref_upload_connection_key"
android:title="@string/pref_upload_connection_title"
android:summary="@string/pref_upload_connection_summary"
android:defaultValue=""
android:entries="@array/pref_upload_connection_entry"
android:entryValues="@array/pref_upload_connection_entryValues"
android:dialogTitle="@string/pref_upload_connection_title" />
</PreferenceCategory>
<PreferenceCategory
android:title="@string/prefcat_defaults">
<PreferenceScreen android:title="@string/prefcat_defaults_post" xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference
android:key="@string/pref_upload_journal_default_key"
android:enabled="true"
android:defaultValue="false"
android:summary="@string/pref_upload_journal_default_summary"
android:title="@string/pref_upload_journal_default_title" />
<ListPreference
android:dependency="@string/pref_upload_journal_default_key"
android:key="@string/pref_upload_journal_key"
android:title="@string/pref_upload_journal_title"
android:summary="@string/pref_upload_journal_summary"
android:dialogTitle="@string/pref_upload_journal_title" />
<CheckBoxPreference
android:key="@string/pref_upload_folder_default_key"
android:enabled="true"
android:defaultValue="false"
android:summary="@string/pref_upload_folder_default_summary"
android:title="@string/pref_upload_folder_default_title" />
<ListPreference
android:dependency="@string/pref_upload_folder_default_key"
android:key="@string/pref_upload_folder_key"
android:title="@string/pref_upload_folder_title"
android:summary="@string/pref_upload_folder_summary"
android:dialogTitle="@string/pref_upload_folder_title" />
<CheckBoxPreference
android:key="@string/pref_upload_tags_default_key"
android:enabled="true"
android:defaultValue="false"
android:summary="@string/pref_upload_tags_default_summary"
android:title="@string/pref_upload_tags_default_title" />
<ListPreference
android:dependency="@string/pref_upload_tags_default_key"
android:key="@string/pref_upload_tags_key"
android:title="@string/pref_upload_tags_title"
android:summary="@string/pref_upload_tags_summary"
android:dialogTitle="@string/pref_upload_tags_title" />
</PreferenceScreen>
<PreferenceScreen android:title="@string/prefcat_defaults_notification" xmlns:android="http://schemas.android.com/apk/res/android">
<!--
<CheckBoxPreference
android:key="@string/pref_sync_notification_feedback_key"
android:enabled="true"
android:defaultValue="true"
android:summary="@string/pref_sync_notification_feedback_summary"
android:title="@string/pref_sync_notification_feedback_title" />
<CheckBoxPreference
android:key="@string/pref_sync_notification_newpost_key"
android:enabled="true"
android:defaultValue="true"
android:summary="@string/pref_sync_notification_newpost_summary"
android:title="@string/pref_sync_notification_newpost_title" />
<CheckBoxPreference
android:key="@string/pref_sync_notification_maharamessage_key"
android:enabled="true"
android:defaultValue="true"
android:summary="@string/pref_sync_notification_maharamessage_summary"
android:title="@string/pref_sync_notification_maharamessage_title" />
<CheckBoxPreference
android:key="@string/pref_sync_notification_usermessage_key"
android:enabled="true"
android:defaultValue="true"
android:summary="@string/pref_sync_notification_usermessage_summary"
android:title="@string/pref_sync_notification_usermessage_title" />
<CheckBoxPreference
android:key="@string/pref_sync_notification_groupmessage_key"
android:enabled="true"
android:defaultValue="true"
android:summary="@string/pref_sync_notification_groupmessage_summary"
android:title="@string/pref_sync_notification_groupmessage_title" />
<CheckBoxPreference
android:key="@string/pref_sync_notification_watchlist_key"
android:enabled="true"
android:defaultValue="true"
android:summary="@string/pref_sync_notification_watchlist_summary"
android:title="@string/pref_sync_notification_watchlist_title" />
<CheckBoxPreference
android:key="@string/pref_sync_notification_viewaccess_key"
android:enabled="true"
android:defaultValue="true"
android:summary="@string/pref_sync_notification_viewaccess_summary"
android:title="@string/pref_sync_notification_viewaccess_title" />
<CheckBoxPreference
android:key="@string/pref_sync_notification_contactus_key"
android:enabled="true"
android:defaultValue="true"
android:summary="@string/pref_sync_notification_contactus_summary"
android:title="@string/pref_sync_notification_contactus_title" />
<CheckBoxPreference
android:key="@string/pref_sync_notification_objectionable_key"
android:enabled="true"
android:defaultValue="true"
android:summary="@string/pref_sync_notification_objectionable_summary"
android:title="@string/pref_sync_notification_objectionable_title" />
<CheckBoxPreference
android:key="@string/pref_sync_notification_virusrepeat_key"
android:enabled="true"
android:defaultValue="true"
android:summary="@string/pref_sync_notification_virusrepeat_summary"
android:title="@string/pref_sync_notification_virusrepeat_title" />
<CheckBoxPreference
android:key="@string/pref_sync_notification_virusrelease_key"
android:enabled="true"
android:defaultValue="true"
android:summary="@string/pref_sync_notification_virusrelease_summary"
android:title="@string/pref_sync_notification_virusrelease_title" />
<CheckBoxPreference
android:key="@string/pref_sync_notification_institutionmessage_key"
android:enabled="true"
android:defaultValue="true"
android:summary="@string/pref_sync_notification_institutionmessage_summary"
android:title="@string/pref_sync_notification_institutionmessage_title" />
-->
</PreferenceScreen>
</PreferenceCategory>
<PreferenceCategory <PreferenceCategory
android:title="@string/prefcat_advanced"> android:title="@string/prefcat_advanced">
<EditTextPreference
<CheckBoxPreference android:key="@string/pref_sync_periodic_key"
android:key="@string/pref_upload_journal_default_key" android:title="@string/pref_sync_periodic_title"
android:enabled="true" android:summary="@string/pref_sync_periodic_summary"
android:defaultValue="false" android:defaultValue="0"
android:summary="@string/pref_upload_journal_default_summary" android:numeric="integer"
android:title="@string/pref_upload_journal_default_title" />
<ListPreference
android:dependency="@string/pref_upload_journal_default_key"
android:key="@string/pref_upload_journal_key"
android:title="@string/pref_upload_journal_title"
android:summary="@string/pref_upload_journal_summary"
android:dialogTitle="@string/pref_upload_journal_title" />
<CheckBoxPreference
android:key="@string/pref_upload_folder_default_key"
android:enabled="true"
android:defaultValue="false"
android:summary="@string/pref_upload_folder_default_summary"
android:title="@string/pref_upload_folder_default_title" />
<ListPreference
android:dependency="@string/pref_upload_folder_default_key"
android:key="@string/pref_upload_folder_key"
android:title="@string/pref_upload_folder_title"
android:summary="@string/pref_upload_folder_summary"
android:dialogTitle="@string/pref_upload_folder_title" />
<CheckBoxPreference
android:key="@string/pref_upload_tags_default_key"
android:enabled="true"
android:defaultValue="false"
android:summary="@string/pref_upload_tags_default_summary"
android:title="@string/pref_upload_tags_default_title" />
<ListPreference
android:dependency="@string/pref_upload_tags_default_key"
android:key="@string/pref_upload_tags_key"
android:title="@string/pref_upload_tags_title"
android:summary="@string/pref_upload_tags_summary"
android:dialogTitle="@string/pref_upload_tags_title" />
<EditTextPreference
android:key="@string/pref_sync_periodic_key"
android:title="@string/pref_sync_periodic_title"
android:summary="@string/pref_sync_periodic_summary"
android:defaultValue="0"
/> />
</PreferenceCategory>
</PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>
\ No newline at end of file
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
package nz.net.catalyst.MaharaDroid; package nz.net.catalyst.MaharaDroid;
import java.util.List;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -29,6 +31,7 @@ import nz.net.catalyst.MaharaDroid.R; ...@@ -29,6 +31,7 @@ import nz.net.catalyst.MaharaDroid.R;
import nz.net.catalyst.MaharaDroid.ui.ArtefactExpandableListAdapterActivity; import nz.net.catalyst.MaharaDroid.ui.ArtefactExpandableListAdapterActivity;
import nz.net.catalyst.MaharaDroid.ui.about.AboutActivity; import nz.net.catalyst.MaharaDroid.ui.about.AboutActivity;
import android.accounts.Account; import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Notification; import android.app.Notification;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
...@@ -37,6 +40,7 @@ import android.content.ContentResolver; ...@@ -37,6 +40,7 @@ import android.content.ContentResolver;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.PeriodicSync;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.database.Cursor; import android.database.Cursor;
import android.graphics.Bitmap; import android.graphics.Bitmap;
...@@ -58,9 +62,29 @@ public class Utils { ...@@ -58,9 +62,29 @@ public class Utils {
// whether VERBOSE level logging is enabled // whether VERBOSE level logging is enabled
static final boolean VERBOSE = LogConfig.VERBOSE; static final boolean VERBOSE = LogConfig.VERBOSE;
public static boolean canUpload(Context mContext) { public static void runSyncNow(Context context) {
AccountManager mAccountManager = AccountManager.get(context);
Account account;
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext); // TODO replicated from AuthenticatorActivity
Account[] mAccounts = mAccountManager.getAccountsByType(GlobalResources.ACCOUNT_TYPE);
if ( mAccounts.length > 0 ) {
// Just pick the first one .. support multiple accounts can come later.
account = mAccounts[0];
} else {
return;
}
Bundle bundle = new Bundle();
// bundle.putBoolean(GlobalResources.EXTRAS_SYNC_IS_PERIODIC, true);
ContentResolver.requestSync(account, GlobalResources.ACCOUNT_TYPE, bundle);
}
public static boolean canUpload(Context context) {
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean allowWiFi = false, allowMobile = false; boolean allowWiFi = false, allowMobile = false;
// Haven't confirmed upload conditions. // Haven't confirmed upload conditions.
...@@ -69,7 +93,7 @@ public class Utils { ...@@ -69,7 +93,7 @@ public class Utils {
return false; return false;
} }
String mSetting = mPrefs.getString(mContext.getResources().getString(R.string.pref_upload_connection_key), ""); String mSetting = mPrefs.getString(context.getResources().getString(R.string.pref_upload_connection_key), "");
// Check for no setting - default to phone // Check for no setting - default to phone
if ( mSetting.length() == 0 ) { if ( mSetting.length() == 0 ) {
...@@ -80,7 +104,7 @@ public class Utils { ...@@ -80,7 +104,7 @@ public class Utils {
if ( mSetting.contains("mobile")) if ( mSetting.contains("mobile"))
allowMobile = true; allowMobile = true;
ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = cm.getActiveNetworkInfo(); NetworkInfo info = cm.getActiveNetworkInfo();
if ( info != null ) { if ( info != null ) {
...@@ -100,8 +124,59 @@ public class Utils { ...@@ -100,8 +124,59 @@ public class Utils {
return false; return false;
} }
public static String getUploadURLPref(Context context) {
public static String updateTokenFromResult(JSONObject json, Context mContext) { SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
String upload_url = mPrefs.getString(context.getResources().getString(R.string.pref_upload_url_key),
context.getResources().getString(R.string.pref_upload_url_default)).trim();
// If the part overrides the whole - just go with the part.
if ( upload_url.startsWith("http://") ) {
if ( DEBUG ) Log.d(TAG, "setting upload url to '" + upload_url + "'");
return upload_url;
}
String base_url = mPrefs.getString(context.getResources().getString(R.string.pref_base_url_key),
context.getResources().getString(R.string.pref_base_url_default)).trim().toLowerCase();
if ( ! base_url.startsWith("http") )
base_url = "http://" + base_url;
if ( ! base_url.endsWith("/") && ! upload_url.startsWith("/") )
base_url = base_url + "/";
// multiple joining '//' are fine
upload_url = base_url + upload_url;
if ( DEBUG ) Log.d(TAG, "setting upload url to '" + upload_url + "'");
return upload_url;
}
public static String getSyncURLPref(Context context) {
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
String sync_url = mPrefs.getString(context.getResources().getString(R.string.pref_sync_url_key),
context.getResources().getString(R.string.pref_sync_url_default)).trim();
// If the part overrides the whole - just go with the part.
if ( sync_url.startsWith("http://") ) {
if ( DEBUG ) Log.d(TAG, "setting sync url to '" + sync_url + "'");
return sync_url;
}
String base_url = mPrefs.getString(context.getResources().getString(R.string.pref_base_url_key),
context.getResources().getString(R.string.pref_base_url_default)).trim().toLowerCase();
if ( ! base_url.startsWith("http") )
base_url = "http://" + base_url;
if ( ! base_url.endsWith("/") && ! sync_url.startsWith("/") )
base_url = base_url + "/";
// multiple joining '//' are fine
sync_url = base_url + sync_url;
if ( DEBUG ) Log.d(TAG, "setting sync url to '" + sync_url + "'");
return sync_url;
}
public static String updateTokenFromResult(JSONObject json, Context context) {
String newToken = null; String newToken = null;
if (json == null || json.has("fail")) { if (json == null || json.has("fail")) {
String err_str = null; String err_str = null;
...@@ -116,9 +191,9 @@ public class Utils { ...@@ -116,9 +191,9 @@ public class Utils {
try { try {
newToken = json.getString("success"); newToken = json.getString("success");
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext); SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
mPrefs.edit() mPrefs.edit()
.putString(mContext.getResources().getString(R.string.pref_auth_token_key), newToken) .putString(context.getResources().getString(R.string.pref_auth_token_key), newToken)
.commit() .commit()
; ;
...@@ -137,8 +212,8 @@ public class Utils { ...@@ -137,8 +212,8 @@ public class Utils {
/** /**
* Show a notification while this service is running. * Show a notification while this service is running.
*/ */
public static void showNotification(int id, CharSequence title, CharSequence description, Intent intent, Context mContext) { public static void showNotification(int id, CharSequence title, CharSequence description, Intent intent, Context context) {
NotificationManager mNM = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager mNM = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
// Set the icon, scrolling text and timestamp // Set the icon, scrolling text and timestamp
Notification notification = new Notification(R.drawable.icon_notify, title, Notification notification = new Notification(R.drawable.icon_notify, title,
...@@ -147,28 +222,28 @@ public class Utils { ...@@ -147,28 +222,28 @@ public class Utils {
PendingIntent contentIntent = null; PendingIntent contentIntent = null;
// The PendingIntent to launch our activity if the user selects this notification // The PendingIntent to launch our activity if the user selects this notification
if ( intent == null ) { if ( intent == null ) {
contentIntent = PendingIntent.getActivity(mContext, 0, new Intent(mContext, ArtefactExpandableListAdapterActivity.class), 0); contentIntent = PendingIntent.getActivity(context, 0, new Intent(context, ArtefactExpandableListAdapterActivity.class), 0);
} else { } else {
contentIntent = PendingIntent.getActivity(mContext, 0, intent, 0); contentIntent = PendingIntent.getActivity(context, 0, intent, 0);
} }
if ( description == null ) { if ( description == null ) {
description = title; description = title;
} }
// Set the info for the views that show in the notification panel. // Set the info for the views that show in the notification panel.
notification.setLatestEventInfo(mContext, title, description, contentIntent); notification.setLatestEventInfo(context, title, description, contentIntent);
notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.flags |= Notification.FLAG_AUTO_CANCEL;
// Send the notification. // Send the notification.
mNM.notify(id, notification); mNM.notify(id, notification);
} }
public static void cancelNotification(int id, Context mContext) { public static void cancelNotification(int id, Context context) {
NotificationManager mNM = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager mNM = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNM.cancel(id); mNM.cancel(id);
}