Skip to content

Instantly share code, notes, and snippets.

@macdonst
macdonst / backup.js
Last active December 19, 2015 07:18
Backup, Remove and Restore your Contacts
function backupAllTheContacts() {
navigator.contacts.find(["*"], function(contacts) {
console.log("contacts.length = " + contacts.length);
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
fileSystem.root.getFile("contacts.bak", {create: true, exclusive: false}, function(fileEntry) {
fileEntry.createWriter(function(writer) {
writer.onwriteend = function() {
console.log("backup complete");
};
writer.write(JSON.stringify(contacts));
@macdonst
macdonst / gist:5746209
Created June 10, 2013 02:43
ChildBrowser.java for PhoneGap 2.7+, currently untested.
/*
* PhoneGap is available under *either* the terms of the modified BSD license *or* the
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
*
* Copyright (c) 2005-2011, Nitobi Software Inc.
* Copyright (c) 2010-2011, IBM Corporation
*/
package com.phonegap.plugins.childBrowser;
import java.io.IOException;
@macdonst
macdonst / save.js
Last active December 18, 2015 00:18
How to save all your contacts from backup.
function saveAllTheContacts(contacts) {
var saveContacts = function() {
// No contacts left, stop saving
if (contacts.length == 0) {
return;
}
var contactData = contacts.pop();
// if you are restoring from a backup make sure you remove the id's
@macdonst
macdonst / jqm.css
Created February 8, 2013 16:10
Some things you can do to have jQuery Mobile run a bit faster on Android devices. Basically you are disabling some CSS and other functions. YMMV
* {
text-shadow: none !important;
-webkit-box-shadow: none !important;
-webkit-border-radius:0 !important;
-webkit-border-top-left-radius:0 !important;
-webkit-border-bottom-left-radius:0 !important;
-webkit-border-bottom-right-radius:0 !important;
-webkit-border-top-right-radius:0 !important;
}
@macdonst
macdonst / GalleryPlugin.java
Last active December 12, 2015 00:58
Gallery Plugin example
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
final CallbackContext cbContext = callbackContext;
String imagePath = args.optString(0);
if ("".equals(imagePath)) {
Log.d(LOG_TAG, "No image path passed in");
cbContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, 0));
return true;
}
imagePath = stripFileProtocol(imagePath);
@macdonst
macdonst / inappbrowser.js
Created December 10, 2012 21:54
What's new in PhoneGap Android 2.3.0
var ref = window.open('http://google.com', '_blank');
ref.addEventListener('loadstart', function(event) { alert(event.type + ' - ' + event.url); } );
ref.addEventListener('loadstop', function(event) { alert(event.type + ' - ' + event.url); } );
ref.addEventListener('exit', function(event) { alert(event.type); } );
// also, you can do ref.removeEventListener('loadstart', myfunc) .. etc
@macdonst
macdonst / config.xml
Created December 6, 2012 04:25
PhoneGap Phone Number Discoverer
<plugin name="TelephoneNumber"
value="com.simonmacdonald.cordova.plugins.TelephoneNumber"/>
@macdonst
macdonst / menu.js
Created November 29, 2012 03:41
Cordova OptionsMenu example
var onSettings = function() {
console.log("settings");
};
var onHelp = function() {
console.log("help");
};
var optionsmenu = new OptionsMenu({
id: "optionsmenu",
@macdonst
macdonst / onContextItemSelected.java
Created November 9, 2012 20:29
Context Menu Example
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
switch (item.getItemId()) {
case R.id.settings:
this.startActivity(new Intent(android.provider.Settings.ACTION_SETTINGS));
return true;
case R.id.help:
this.appView.sendJavascript("navigator.notification.alert('No help')");
return true;
default:
@macdonst
macdonst / create_menu.java
Created November 5, 2012 03:22
PhoneGap Android Native Menu
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.example, menu);
return true;
}