Commit a8e40ce6 authored by Jonathan Sharp's avatar Jonathan Sharp

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;
}
}
This diff is collapsed.
......@@ -7,23 +7,25 @@ import android.os.IBinder;
import android.util.Log;
public class AccountAuthenticatorService extends Service {
private AccountAuthenticator mAccountAuthenticator;
static final String TAG = LogConfig.getLogTag(AccountAuthenticatorService.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;
private AccountAuthenticator mAccountAuthenticator;
static final String TAG = LogConfig.getLogTag(AccountAuthenticatorService.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;
@Override
public void onCreate() {
if(VERBOSE) Log.v(TAG, "Service started ...");
mAccountAuthenticator = new AccountAuthenticator(this);
}
@Override
public void onCreate() {
if (VERBOSE)
Log.v(TAG, "Service started ...");
mAccountAuthenticator = new AccountAuthenticator(this);
}
@Override
public IBinder onBind(Intent intent) {
if(VERBOSE) Log.v(TAG, "IBinder returned for AccountAuthenticator implementation.");
return mAccountAuthenticator.getIBinder();
}
@Override
public IBinder onBind(Intent intent) {
if (VERBOSE)
Log.v(TAG, "IBinder returned for AccountAuthenticator implementation.");
return mAccountAuthenticator.getIBinder();
}
}
......@@ -7,36 +7,37 @@ import android.accounts.AccountManager;
import android.content.Context;
public class AccountUtils {
static final String TAG = LogConfig.getLogTag(AccountUtils.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 Account getAccount(Context context) {
AccountManager mAccountManager = AccountManager.get(context);
Account account = null;
// if ( periodic_sync != null && periodic_sync > 0 ) {
//
// 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];
static final String TAG = LogConfig.getLogTag(AccountUtils.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 Account getAccount(Context context) {
AccountManager mAccountManager = AccountManager.get(context);
Account account = null;
// if ( periodic_sync != null && periodic_sync > 0 ) {
//
// 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];
}
return account;
}
public static void deleteAccount(Context context) {
AccountManager mAccountManager = AccountManager.get(context);
Account[] mAccounts = mAccountManager.getAccountsByType(GlobalResources.ACCOUNT_TYPE);
for ( int i = 0; i < mAccounts.length; i++ ) {
mAccountManager.removeAccount(mAccounts[i], null, null);
}
public static void deleteAccount(Context context) {
AccountManager mAccountManager = AccountManager.get(context);
Account[] mAccounts = mAccountManager.getAccountsByType(GlobalResources.ACCOUNT_TYPE);
for (int i = 0; i < mAccounts.length; i++) {
mAccountManager.removeAccount(mAccounts[i], null, null);
}
}
}
}
/*
* Copyright (C) 2010 The Android Open Source Project
*
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
......@@ -16,10 +16,9 @@
package nz.net.catalyst.MaharaDroid.authenticator;
import nz.net.catalyst.MaharaDroid.authenticator.AuthenticatorActivity;
import nz.net.catalyst.MaharaDroid.data.SyncUtils;
import nz.net.catalyst.MaharaDroid.GlobalResources;
import nz.net.catalyst.MaharaDroid.LogConfig;
import nz.net.catalyst.MaharaDroid.data.SyncUtils;
import android.accounts.Account;
import android.accounts.AccountAuthenticatorActivity;
import android.accounts.AccountManager;
......@@ -33,19 +32,19 @@ import android.util.Log;
* Activity which displays login screen to the user.
*/
public class AuthenticatorActivity extends AccountAuthenticatorActivity {
static final String TAG = LogConfig.getLogTag(AuthenticatorActivity.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;
static final String TAG = LogConfig.getLogTag(AuthenticatorActivity.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;
private AccountManager mAccountManager;
/**
* If set we are just checking that the user knows their credentials; this
* doesn't cause the user's password to be changed on the device.
*/
//private Boolean mConfirmCredentials = false;
// private Boolean mConfirmCredentials = false;
/** for posting authentication attempts back to UI thread */
private final Handler mHandler = new Handler();
......@@ -61,23 +60,25 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
String mUsername = null;
mAccountManager = AccountManager.get(this);
//final Intent intent = getIntent();
// final Intent intent = getIntent();
mAccounts = mAccountManager.getAccountsByType(GlobalResources.ACCOUNT_TYPE);
if ( mAccounts.length > 0 ) {
// Just pick the first one .. support multiple accounts can come later.
mUsername = mAccounts[0].name;
if (mAccounts.length > 0) {
// Just pick the first one .. support multiple accounts can come
// later.
mUsername = mAccounts[0].name;
}
mRequestNewAccount = ( mUsername == null );
mRequestNewAccount = (mUsername == null);
if (DEBUG)
Log.d(TAG, "AuthenticatorActivity/onCreate request new: " + mRequestNewAccount);
if ( DEBUG ) Log.d(TAG, "AuthenticatorActivity/onCreate request new: " + mRequestNewAccount);
MaharaAuthHandler.attemptAuth(mUsername, mHandler, AuthenticatorActivity.this);
finish();
MaharaAuthHandler.attemptAuth(mUsername, mHandler, AuthenticatorActivity.this);
finish();
}
/**
......@@ -85,27 +86,31 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity {
*/
public void onAuthenticationResult(String username, String authToken) {
// If we have an auth token create the account
if ( DEBUG ) Log.d(TAG, "AuthenticatorActivity/onAuthenticationResult request new: " + mRequestNewAccount);
if (DEBUG)
Log.d(TAG, "AuthenticatorActivity/onAuthenticationResult request new: " + mRequestNewAccount);
if (authToken != null) {
final Account account = new Account(username, GlobalResources.ACCOUNT_TYPE);
if (mRequestNewAccount) {
Boolean newAccountCreated = mAccountManager.addAccountExplicitly(account, null, null);
if ( DEBUG ) Log.d(TAG, "onAuthenticationResult new account created: " + newAccountCreated);
if (DEBUG)
Log.d(TAG, "onAuthenticationResult new account created: " + newAccountCreated);
// Set contacts sync for this account.
ContentResolver.setSyncAutomatically(account, GlobalResources.SYNC_AUTHORITY, true);
ContentResolver.setIsSyncable(account, GlobalResources.SYNC_AUTHORITY, 1);
//TODO confirm but shouldn't have to force this - setSyncAutomatically should kick one off I believe
// ContentResolver.requestSync(account, GlobalResources.SYNC_AUTHORITY, null);
SyncUtils.setPeriodicSync(account, getApplicationContext());
// TODO confirm but shouldn't have to force this -
// setSyncAutomatically should kick one off I believe
// ContentResolver.requestSync(account,
// GlobalResources.SYNC_AUTHORITY, null);
SyncUtils.setPeriodicSync(account, getApplicationContext());
}
final Intent intent = new Intent();
intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, username);
intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, GlobalResources.ACCOUNT_TYPE);
......@@ -114,8 +119,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity {
finish();
}
}
public void isAuthenctiated() {
}
}
\ No newline at end of file
}
......@@ -13,99 +13,103 @@ import android.net.Uri;
public class SyncContentProvider extends ContentProvider {
private SQLiteDatabase sqlDB;
private DatabaseHelper dbHelper;
private static final String DATABASE_NAME = "maharadroid_sync.db";
private static final int DATABASE_VERSION = 1;
private static class DatabaseHelper extends SQLiteOpenHelper {
DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
// create table to store user names
for ( int i = 0; i < GlobalResources.SYNC_CONTENT_TABLES.length; i++ ) {
db.execSQL("Create table "
+ GlobalResources.SYNC_CONTENT_TABLES[i]
+ "( _id INTEGER PRIMARY KEY AUTOINCREMENT, ID TEXT, VALUE TEXT);");
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
for ( int i = 0; i < GlobalResources.SYNC_CONTENT_TABLES.length; i++ ) {
db.execSQL("DROP TABLE IF EXISTS " + GlobalResources.SYNC_CONTENT_TABLES[i]);
}
onCreate(db);
}
}
public SyncContentProvider() {
super();
}
public SyncContentProvider(Context context) {
super();