Commit a8e40ce6 authored by Jonathan Sharp's avatar Jonathan Sharp
Browse files

formatting etc updates

parent b7d0f67e
......@@ -17,32 +17,36 @@
package com.google.zxing.integration.android;
/**
* <p>Encapsulates the result of a barcode scan invoked through {@link IntentIntegrator}.</p>
* <p>
* Encapsulates the result of a barcode scan invoked through
* {@link IntentIntegrator}.
* </p>
*
* @author Sean Owen
*/
public final class IntentResult {
private final String contents;
private final String formatName;
private final String contents;
private final String formatName;
IntentResult(String contents, String formatName) {
this.contents = contents;
this.formatName = formatName;
}
IntentResult(String contents, String formatName) {
this.contents = contents;
this.formatName = formatName;
}
/**
* @return raw content of barcode
*/
public String getContents() {
return contents;
}
/**
* @return raw content of barcode
*/
public String getContents() {
return contents;
}
/**
* @return name of format, like "QR_CODE", "UPC_A". See <code>BarcodeFormat</code> for more format names.
*/
public String getFormatName() {
return formatName;
}
/**
* @return name of format, like "QR_CODE", "UPC_A". See
* <code>BarcodeFormat</code> for more format names.
*/
public String getFormatName() {
return formatName;
}
}
/*
/*
* MaharaDroid - Artefact uploader
*
*
* This file is part of MaharaDroid.
*
* Copyright [2010] [Catalyst IT Limited]
*
* This file is free software: you may copy, redistribute and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This file is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright [2010] [Catalyst IT Limited]
*
* This file is free software: you may copy, redistribute and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This file is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package nz.net.catalyst.MaharaDroid;
......@@ -37,33 +37,33 @@ import android.net.Uri;
*/
public class GlobalResources {
public static final String TRANSFER_TYPE_UPLOAD = "Upload";
public static final String CONFIG_SCAN_INTENT = "com.google.zxing.client.android.SCAN";
public static final String CONFIG_SCAN_MODE = "QR_CODE_MODE";
public static final String CONFIG_SCAN_INTENT = "com.google.zxing.client.android.SCAN";
public static final String CONFIG_SCAN_MODE = "QR_CODE_MODE";
public static int ERROR_DELAY_MS = 1000;
public static int ERROR_DELAY_MS = 1000;
public static Uri TEMP_PHOTO_URI;
public static Uri TEMP_PHOTO_URI;
public static final int UPLOADER_ID = 100;
public static final int UPLOADING_ID = UPLOADER_ID + 100;
public static final String ACCOUNT_TYPE = "nz.net.catalyst.MaharaDroid.account";
public static final String AUTHTOKEN_TYPE = "nz.net.catalyst.MaharaDroid.account";
public static final String SYNC_CONTENT_URL = "nz.net.catalyst.MaharaDroid.Sync";
public static final String ARTEFACT_CONTENT_URL = "nz.net.catalyst.MaharaDroid.Artefact";
public static final String SYNC_AUTHORITY = "nz.net.catalyst.MaharaDroid.Sync";
public static final String EXTRAS_SYNC_IS_PERIODIC = "nz.net.catalyst.MaharaDroid.periodic";
public static final String BROADCAST_ACTION = "nz.net.catalyst.MaharaDroid.UPLOAD_COMPLETED";
public static final int UPLOADER_ID = 100;
public static final int UPLOADING_ID = UPLOADER_ID + 100;
public static final String[] SYNC_CONTENT_TABLES = new String[] { "tag", "blog", "folder" };
public static final String[] SYNC_CONTENT_FIELDS = new String[] { "ID", "VALUE" };
public static final String ACCOUNT_TYPE = "nz.net.catalyst.MaharaDroid.account";
public static final String AUTHTOKEN_TYPE = "nz.net.catalyst.MaharaDroid.account";
public static final Map<Integer, String> NOTIFICATIONS;
public static final String SYNC_CONTENT_URL = "nz.net.catalyst.MaharaDroid.Sync";
public static final String ARTEFACT_CONTENT_URL = "nz.net.catalyst.MaharaDroid.Artefact";
public static final String SYNC_AUTHORITY = "nz.net.catalyst.MaharaDroid.Sync";
public static final String EXTRAS_SYNC_IS_PERIODIC = "nz.net.catalyst.MaharaDroid.periodic";
public static final String BROADCAST_ACTION = "nz.net.catalyst.MaharaDroid.UPLOAD_COMPLETED";
public static final String[] SYNC_CONTENT_TABLES = new String[] { "tag", "blog", "folder" };
public static final String[] SYNC_CONTENT_FIELDS = new String[] { "ID", "VALUE" };
public static final Map<Integer, String> NOTIFICATIONS;
static {
Map<Integer, String> tmpNOTIFICATIONS = new HashMap<Integer, String>();
tmpNOTIFICATIONS.put(R.string.pref_sync_notification_feedback_key, "feedback");
......@@ -72,12 +72,12 @@ public class GlobalResources {
tmpNOTIFICATIONS.put(R.string.pref_sync_notification_usermessage_key, "usermessage");
NOTIFICATIONS = Collections.unmodifiableMap(tmpNOTIFICATIONS);
}
public static final String TEMP_PHOTO_FILENAME = "maharadroid-tmp.jpg";
public static final int REQ_CAMERA_RETURN = 0;
public static final int REQ_GALLERY_RETURN = 1;
public static final int REQ_RECORD_AUDIO_RETURN = 2;
public static final String TEMP_PHOTO_FILENAME = "maharadroid-tmp.jpg";
public static final int REQ_CAMERA_RETURN = 0;
public static final int REQ_GALLERY_RETURN = 1;
public static final int REQ_RECORD_AUDIO_RETURN = 2;
public static final int REGISTRATION_TIMEOUT = 30 * 1000; // ms
}
\ No newline at end of file
}
/*
/*
* MaharaDroid - Artefact uploader
*
*
* This file is part of MaharaDroid.
*
* Copyright [2010] [Catalyst IT Limited]
*
* This file is free software: you may copy, redistribute and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This file is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright [2010] [Catalyst IT Limited]
*
* This file is free software: you may copy, redistribute and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This file is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package nz.net.catalyst.MaharaDroid;
......@@ -24,68 +24,69 @@ package nz.net.catalyst.MaharaDroid;
import android.util.Log;
/**
* Log configuration settings.
* Code that is guarded by a test of the LogConfig.VERBOSE constant
* will be stripped out by the compiler if the test can be determined at compile time
* to be false.<br/>
* Log configuration settings. Code that is guarded by a test of the
* LogConfig.VERBOSE constant will be stripped out by the compiler if the test
* can be determined at compile time to be false.<br/>
* e.g.<br/>
* <code>if (LogConfig.VERBOSE) Log.v(TAG, "a String to log");</code><br/>
* will be stripped out by the compiler if LogConfig.VERBOSE is false.
*
* @author Grant Patterson (grant.patterson@catalyst.net.nz)
*
* @author Grant Patterson (grant.patterson@catalyst.net.nz)
*/
public class LogConfig {
/**
* Whether the application should have all tags log at DEBUG level.
* When this is true, all tags will log at DEBUG level.
* When this is false, only tags that are explicitly enabled by the Android logging
* properties mechanism (see android.util.Log.isLoggable()) will log at DEBUG level.<br/>
* This should be false in release builds so that tags will only log at DEBUG
* level when they have been explicitly told to through Android's logging properties.
* Rather than checking this directly, classes should use LogConfig.isDebug(TAG) to
* determine whether to log a DEBUG level.
*/
private static final boolean DEBUG = true;
/**
* Whether the application should allow any tags to log at VERBOSE level.
* Make sure this is set this to false in release builds so the compiler will strip out
* VERBOSE log statements.<br/>
* In general, classes should check this constant rather than checking Log.isLoggable(TAG, Log.VERBOSE).
* The Java compiler is unable to strip out calls to Log.isLoggable()
* (although, maybe the Dalvik compiler, or the JIT can ???)
*/
public static final boolean VERBOSE = true;
private static final int MAX_LOG_TAG_LENGTH = 23;
/**
* When DEBUG logging isn't globally enabled for the application, this method
* defers to Android's logging properties mechanism (see android.util.Log.isLoggable()).
* @param logTag the log tag
* @return whether the log tag should log at DEBUG level
*/
public static boolean isDebug(String logTag) {
return DEBUG || Log.isLoggable(logTag, Log.DEBUG);
}
public static String getLogTag(Class<?> clazz) {
String tag = clazz.getSimpleName();
if (tag.length() > MAX_LOG_TAG_LENGTH) {
// trim tag
StringBuilder trimmed = new StringBuilder(MAX_LOG_TAG_LENGTH);
trimmed.append(tag.substring(0, MAX_LOG_TAG_LENGTH - 2));
trimmed.append("..");
tag = trimmed.toString();
}
return tag;
}
/**
* Whether the application should have all tags log at DEBUG level. When
* this is true, all tags will log at DEBUG level. When this is false, only
* tags that are explicitly enabled by the Android logging properties
* mechanism (see android.util.Log.isLoggable()) will log at DEBUG level.<br/>
* This should be false in release builds so that tags will only log at
* DEBUG level when they have been explicitly told to through Android's
* logging properties. Rather than checking this directly, classes should
* use LogConfig.isDebug(TAG) to determine whether to log a DEBUG level.
*/
private static final boolean DEBUG = true;
/**
* Whether the application should allow any tags to log at VERBOSE level.
* Make sure this is set this to false in release builds so the compiler
* will strip out VERBOSE log statements.<br/>
* In general, classes should check this constant rather than checking
* Log.isLoggable(TAG, Log.VERBOSE). The Java compiler is unable to strip
* out calls to Log.isLoggable() (although, maybe the Dalvik compiler, or
* the JIT can ???)
*/
public static final boolean VERBOSE = true;
private static final int MAX_LOG_TAG_LENGTH = 23;
/**
* When DEBUG logging isn't globally enabled for the application, this
* method defers to Android's logging properties mechanism (see
* android.util.Log.isLoggable()).
*
* @param logTag
* the log tag
* @return whether the log tag should log at DEBUG level
*/
public static boolean isDebug(String logTag) {
return DEBUG || Log.isLoggable(logTag, Log.DEBUG);
}
public static String getLogTag(Class<?> clazz) {
String tag = clazz.getSimpleName();
if (tag.length() > MAX_LOG_TAG_LENGTH) {
// trim tag
StringBuilder trimmed = new StringBuilder(MAX_LOG_TAG_LENGTH);
trimmed.append(tag.substring(0, MAX_LOG_TAG_LENGTH - 2));
trimmed.append("..");
tag = trimmed.toString();
}
return tag;
}
}
......@@ -44,135 +44,138 @@ import android.provider.MediaStore;
import android.util.Log;
public class Utils {
static final String TAG = LogConfig.getLogTag(Utils.class);
// whether DEBUG level logging is enabled (whether globally, or explicitly
// for this log tag)
static final boolean DEBUG = LogConfig.isDebug(TAG);
// whether VERBOSE level logging is enabled
static final boolean VERBOSE = LogConfig.VERBOSE;
public static boolean canUpload(Context context) {
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
static final String TAG = LogConfig.getLogTag(Utils.class);
// whether DEBUG level logging is enabled (whether globally, or explicitly
// for this log tag)
static final boolean DEBUG = LogConfig.isDebug(TAG);
// whether VERBOSE level logging is enabled
static final boolean VERBOSE = LogConfig.VERBOSE;
public static boolean canUpload(Context context) {
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean allowWiFi = false, allowMobile = false;
// Haven't confirmed upload conditions.
// TODO validate it's OK to have this here.
if ( ! mPrefs.getBoolean("Upload Conditions Confirmed", false) ) {
return false;
if (!mPrefs.getBoolean("Upload Conditions Confirmed", false)) {
return false;
}
String mSetting = mPrefs.getString(context.getResources().getString(R.string.pref_upload_connection_key), "");
// Check for no setting - default to phone
if ( mSetting.length() == 0 ) {
allowWiFi = allowMobile = true;
}
if ( mSetting.contains("wifi"))
allowWiFi = true;
if ( mSetting.contains("mobile"))
allowMobile = true;
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = cm.getActiveNetworkInfo();
if ( info != null ) {
int netType = info.getType();
if (netType == ConnectivityManager.TYPE_WIFI) {
if ( allowWiFi && info.isConnected() )
return true;
} else if (netType == ConnectivityManager.TYPE_MOBILE) {
if ( allowMobile && info.isConnected() )
return true;
}
} else {
// Assume we're a mobile (we're an Android after all)
return ( allowMobile );
}
if (mSetting.length() == 0) {
allowWiFi = allowMobile = true;
}
if (mSetting.contains("wifi"))
allowWiFi = true;
if (mSetting.contains("mobile"))
allowMobile = true;
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = cm.getActiveNetworkInfo();
if (info != null) {
int netType = info.getType();
if (netType == ConnectivityManager.TYPE_WIFI) {
if (allowWiFi && info.isConnected())
return true;
} else if (netType == ConnectivityManager.TYPE_MOBILE) {
if (allowMobile && info.isConnected())
return true;
}
} else {
// Assume we're a mobile (we're an Android after all)
return (allowMobile);
}
return false;
}
public static String getUploadURLPref(Context context) {
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 getUploadURLPref(Context context) {
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 updateTokenFromResult(JSONObject json, Context context) {
String newToken = null;
String newToken = null;
if (json == null || json.has("fail")) {
String err_str = null;
try {
err_str = (json == null) ? "Unknown Failure" : json.getString("fail");
} catch (JSONException e) {
err_str = "Unknown Failure";
}
Log.e(TAG, "Auth fail: " + err_str);
} else if ( json.has("success") ) {
try {
newToken = json.getString("success");
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
mPrefs.edit()
.putString(context.getResources().getString(R.string.pref_auth_token_key), newToken)
.commit()
;
// Here we want to check a check-sum for 'last-modified' and if newer content exists
// then process out new user-data
Log.i(TAG, "Token found, re-keying auth-token");
} catch (JSONException e) {
Log.e(TAG, "Failed to get success token from result.");
}
String err_str = null;
try {
err_str = (json == null) ? "Unknown Failure" : json.getString("fail");
} catch (JSONException e) {
err_str = "Unknown Failure";
}
Log.e(TAG, "Auth fail: " + err_str);
} else if (json.has("success")) {
try {
newToken = json.getString("success");
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
mPrefs.edit()
.putString(context.getResources().getString(R.string.pref_auth_token_key), newToken)
.commit();
// Here we want to check a check-sum for 'last-modified' and if
// newer content exists
// then process out new user-data
Log.i(TAG, "Token found, re-keying auth-token");
} catch (JSONException e) {
Log.e(TAG, "Failed to get success token from result.");
}
}
return newToken;
return newToken;
}
/**
* Show a notification while this service is running.
*/
public static void showNotification(int id, CharSequence title, CharSequence description, Intent intent, Context context) {
NotificationManager mNM = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationManager mNM = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
// Set the icon, scrolling text and timestamp
Notification notification = new Notification(R.drawable.icon_notify, title,
System.currentTimeMillis());
PendingIntent contentIntent = null;
// The PendingIntent to launch our activity if the user selects this notification
if ( intent == null ) {
contentIntent = PendingIntent.getActivity(context, 0, new Intent(context, ArtefactExpandableListAdapterActivity.class), 0);
// The PendingIntent to launch our activity if the user selects this
// notification
if (intent == null) {
contentIntent = PendingIntent.getActivity(context, 0, new Intent(context, ArtefactExpandableListAdapterActivity.class), 0);
} else {
contentIntent = PendingIntent.getActivity(context, 0, intent, 0);
contentIntent = PendingIntent.getActivity(context, 0, intent, 0);
}
if ( description == null ) {
description = title;
if (description == null) {
description = title;
}
// Set the info for the views that show in the notification panel.
notification.setLatestEventInfo(context, title, description, contentIntent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
......@@ -181,69 +184,75 @@ public class Utils {
mNM.notify(id, notification);