Merge commit. TABS ARE NOT SPACES

This commit is contained in:
Joe Bowser 2012-06-04 15:20:00 -07:00
commit 0ad9ff0d87
4 changed files with 236 additions and 194 deletions

View File

@ -60,9 +60,9 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
// Media error codes
private static int MEDIA_ERR_NONE_ACTIVE = 0;
private static int MEDIA_ERR_ABORTED = 1;
// private static int MEDIA_ERR_NETWORK = 2;
// private static int MEDIA_ERR_DECODE = 3;
// private static int MEDIA_ERR_NONE_SUPPORTED = 4;
private static int MEDIA_ERR_NETWORK = 2;
private static int MEDIA_ERR_DECODE = 3;
private static int MEDIA_ERR_NONE_SUPPORTED = 4;
private AudioHandler handler; // The AudioHandler object
private String id; // The id of this player (used to identify Media object in JavaScript)
@ -85,7 +85,11 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
public AudioPlayer(AudioHandler handler, String id) {
this.handler = handler;
this.id = id;
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
this.tempFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "/tmprecording.mp3";
} else {
this.tempFile = "/data/data/" + handler.ctx.getPackageName() + "/cache/tmprecording.mp3";
}
}
/**
@ -117,7 +121,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
public void startRecording(String file) {
if (this.mPlayer != null) {
Log.d(LOG_TAG, "AudioPlayer Error: Can't record in play mode.");
this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', " + MEDIA_ERROR + ", { \"code\":" + MEDIA_ERR_ABORTED + "});");
this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});");
}
// Make sure we're not already recording
@ -138,11 +142,11 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
} catch (IOException e) {
e.printStackTrace();
}
this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', " + MEDIA_ERROR + ", { \"code\":" + MEDIA_ERR_ABORTED + "});");
this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});");
}
else {
Log.d(LOG_TAG, "AudioPlayer Error: Already recording.");
this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', " + MEDIA_ERROR + ", { \"code\":" + MEDIA_ERR_ABORTED + "});");
this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});");
}
}
@ -152,10 +156,15 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
* @param file
*/
public void moveFile(String file) {
/* this is a hack to save the file as the specified name */
File f = new File(this.tempFile);
f.renameTo(new File("/sdcard/" + file));
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
f.renameTo(new File(Environment.getExternalStorageDirectory().getAbsolutePath()
+ File.separator + file));
} else {
f.renameTo(new File("/data/data/" + handler.ctx.getPackageName() + "/cache/" + file));
}
}
/**

View File

@ -18,8 +18,7 @@ package org.apache.cordova;
import java.util.HashMap;
//import android.app.Activity;
//import android.content.Context;
import android.content.Context;
import android.util.Log;
import android.webkit.WebView;
@ -48,7 +47,7 @@ public abstract class ContactAccessor {
* @param map created by running buildPopulationSet.
* @return true if the key data is required
*/
protected boolean isRequired(String key, HashMap<String, Boolean> map) {
protected boolean isRequired(String key, HashMap<String,Boolean> map) {
Boolean retVal = map.get(key);
return (retVal == null) ? false : retVal.booleanValue();
}
@ -58,8 +57,8 @@ public abstract class ContactAccessor {
* @param fields the list of fields to populate
* @return the hash map of required data
*/
protected HashMap<String, Boolean> buildPopulationSet(JSONArray fields) {
HashMap<String, Boolean> map = new HashMap<String, Boolean>();
protected HashMap<String,Boolean> buildPopulationSet(JSONArray fields) {
HashMap<String,Boolean> map = new HashMap<String,Boolean>();
String key;
try {
@ -79,7 +78,7 @@ public abstract class ContactAccessor {
map.put("categories", true);
}
else {
for (int i = 0; i < fields.length(); i++) {
for (int i=0; i<fields.length(); i++) {
key = fields.getString(i);
if (key.startsWith("displayName")) {
map.put("displayName", true);
@ -123,7 +122,8 @@ public abstract class ContactAccessor {
}
}
}
} catch (JSONException e) {
}
catch (JSONException e) {
Log.e(LOG_TAG, e.getMessage(), e);
}
return map;
@ -148,7 +148,8 @@ public abstract class ContactAccessor {
value = null;
}
}
} catch (JSONException e) {
}
catch (JSONException e) {
Log.d(LOG_TAG, "Could not get = " + e.getMessage());
}
return value;
@ -182,19 +183,15 @@ public abstract class ContactAccessor {
class WhereOptions {
private String where;
private String[] whereArgs;
public void setWhere(String where) {
this.where = where;
}
public String getWhere() {
return where;
}
public void setWhereArgs(String[] whereArgs) {
this.whereArgs = whereArgs;
}
public String[] getWhereArgs() {
return whereArgs;
}

View File

@ -25,7 +25,10 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@ -112,7 +115,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
dbMap.put("organizations.name", ContactsContract.CommonDataKinds.Organization.COMPANY);
dbMap.put("organizations.department", ContactsContract.CommonDataKinds.Organization.DEPARTMENT);
dbMap.put("organizations.title", ContactsContract.CommonDataKinds.Organization.TITLE);
dbMap.put("birthday", ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE);
dbMap.put("birthday", ContactsContract.CommonDataKinds.Event.START_DATE);
dbMap.put("note", ContactsContract.CommonDataKinds.Note.NOTE);
dbMap.put("photos.value", ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE);
//dbMap.put("categories.value", null);
@ -578,26 +581,30 @@ public class ContactAccessorSdk5 extends ContactAccessor {
whereArgs.add(searchTerm);
whereArgs.add(ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE);
}
// else if (key.startsWith("birthday")) {
// where.add("(" + dbMap.get(key) + " LIKE ? AND "
// + ContactsContract.Data.MIMETYPE + " = ? )");
// }
else if (key.startsWith("birthday")) {
try {
SimpleDateFormat format = new SimpleDateFormat("EEEE, MMMM dd, yyyy");
Date searchDate = format.parse(searchTerm.substring(1, searchTerm.length()-1));
// Have to subtract one from the month as JavaScript's January is 01
// while Java's January is 00.
searchDate.setMonth(searchDate.getMonth()-1);
SimpleDateFormat newFormat = new SimpleDateFormat("yyyy-MM-dd");
where.add("(" + dbMap.get(key) + " = ? AND "
+ ContactsContract.Data.MIMETYPE + " = ? )");
whereArgs.add(newFormat.format(searchDate));
whereArgs.add(ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE);
}
catch (ParseException e) {
Log.d(LOG_TAG, "Bad romance format");
}
}
else if (key.startsWith("note")) {
where.add("(" + dbMap.get(key) + " LIKE ? AND "
+ ContactsContract.Data.MIMETYPE + " = ? )");
whereArgs.add(searchTerm);
whereArgs.add(ContactsContract.CommonDataKinds.Note.CONTENT_ITEM_TYPE);
}
else if (key.startsWith("urls")) {
where.add("(" + dbMap.get(key) + " LIKE ? AND "
+ ContactsContract.Data.MIMETYPE + " = ? )");
whereArgs.add(searchTerm);
whereArgs.add(ContactsContract.CommonDataKinds.Website.CONTENT_ITEM_TYPE);
}
}
} catch (JSONException e) {
Log.e(LOG_TAG, e.getMessage(), e);
}
// Creating the where string
StringBuffer selection = new StringBuffer();
@ -1133,13 +1140,42 @@ public class ContactAccessorSdk5 extends ContactAccessor {
ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
.withSelection(ContactsContract.Data.CONTACT_ID + "=? AND " +
ContactsContract.Data.MIMETYPE + "=?",
new String[] { id, ContactsContract.CommonDataKinds.Note.CONTENT_ITEM_TYPE })
new String[]{id,ContactsContract.CommonDataKinds.Note.CONTENT_ITEM_TYPE})
.withValue(ContactsContract.CommonDataKinds.Note.NOTE, note)
.build());
// Modify nickname
String nickname = getJsonString(contact, "nickname");
if (nickname != null) {
ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
.withSelection(ContactsContract.Data.CONTACT_ID + "=? AND " +
ContactsContract.Data.MIMETYPE + "=?",
new String[]{id,ContactsContract.CommonDataKinds.Nickname.CONTENT_ITEM_TYPE})
.withValue(ContactsContract.CommonDataKinds.Nickname.NAME, nickname)
.build());
}
// Modify urls
JSONArray websites = null;
try {
websites = contact.getJSONArray("urls");
if (websites != null) {
for (int i=0; i<websites.length(); i++) {
JSONObject website = (JSONObject)websites.get(i);
String websiteId = getJsonString(website, "id");
// This is a new website so do a DB insert
if (websiteId==null) {
ContentValues contentValues = new ContentValues();
contentValues.put(ContactsContract.Data.RAW_CONTACT_ID, rawId);
contentValues.put(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Website.CONTENT_ITEM_TYPE);
contentValues.put(ContactsContract.CommonDataKinds.Website.DATA, getJsonString(website, "value"));
contentValues.put(ContactsContract.CommonDataKinds.Website.TYPE, getContactType(getJsonString(website, "type")));
ops.add(ContentProviderOperation.newInsert(
ContactsContract.Data.CONTENT_URI).withValues(contentValues).build());
}
// This is an existing website so do a DB update
else {
ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
.withSelection(ContactsContract.Data.CONTACT_ID + "=? AND " +
ContactsContract.Data.MIMETYPE + "=?",

View File

@ -50,17 +50,17 @@ public class PluginResult {
public PluginResult(Status status, int i) {
this.status = status.ordinal();
this.message = "" + i;
this.message = ""+i;
}
public PluginResult(Status status, float f) {
this.status = status.ordinal();
this.message = "" + f;
this.message = ""+f;
}
public PluginResult(Status status, boolean b) {
this.status = status.ordinal();
this.message = "" + b;
this.message = ""+b;
}
public void setKeepCallback(boolean b) {
@ -80,15 +80,15 @@ public class PluginResult {
}
public String getJSONString() {
return "{status:" + this.status + ",message:" + this.message + ",keepCallback:" + this.keepCallback + "}";
return "{\"status\":" + this.status + ",\"message\":" + this.message + ",\"keepCallback\":" + this.keepCallback + "}";
}
public String toSuccessCallbackString(String callbackId) {
return "cordova.callbackSuccess('" + callbackId + "'," + this.getJSONString() + ");";
return "cordova.callbackSuccess('"+callbackId+"',"+this.getJSONString()+");";
}
public String toErrorCallbackString(String callbackId) {
return "cordova.callbackError('" + callbackId + "', " + this.getJSONString() + ");";
return "cordova.callbackError('"+callbackId+"', " + this.getJSONString()+ ");";
}
public static String[] StatusMessages = new String[] {