Migrate android project to crosswalk+cordova bundle
This commit is contained in:
parent
c2dcd4f44b
commit
053718884a
855 changed files with 109265 additions and 0 deletions
37
mobile/src/com/bipay/copay/Copay.java
Normal file
37
mobile/src/com/bipay/copay/Copay.java
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you 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 License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
|
||||
package com.bipay.copay;
|
||||
|
||||
import android.os.Bundle;
|
||||
import org.apache.cordova.*;
|
||||
|
||||
public class Copay extends CordovaActivity
|
||||
{
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
super.init();
|
||||
// Set by <content src="index.html" /> in config.xml
|
||||
super.loadUrl(Config.getStartUrl());
|
||||
//super.loadUrl("file:///android_asset/www/index.html");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,169 @@
|
|||
/**
|
||||
* 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) Matt Kane 2010
|
||||
* Copyright (c) 2011, IBM Corporation
|
||||
* Copyright (c) 2013, Maciej Nux Jaros
|
||||
*/
|
||||
package com.phonegap.plugins.barcodescanner;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
import org.apache.cordova.CordovaPlugin;
|
||||
import org.apache.cordova.CallbackContext;
|
||||
import org.apache.cordova.PluginResult;
|
||||
|
||||
/**
|
||||
* This calls out to the ZXing barcode reader and returns the result.
|
||||
*
|
||||
* @sa https://github.com/apache/cordova-android/blob/master/framework/src/org/apache/cordova/CordovaPlugin.java
|
||||
*/
|
||||
public class BarcodeScanner extends CordovaPlugin {
|
||||
public static final int REQUEST_CODE = 0x0ba7c0de;
|
||||
|
||||
private static final String SCAN = "scan";
|
||||
private static final String ENCODE = "encode";
|
||||
private static final String CANCELLED = "cancelled";
|
||||
private static final String FORMAT = "format";
|
||||
private static final String TEXT = "text";
|
||||
private static final String DATA = "data";
|
||||
private static final String TYPE = "type";
|
||||
private static final String SCAN_INTENT = "com.phonegap.plugins.barcodescanner.SCAN";
|
||||
private static final String ENCODE_DATA = "ENCODE_DATA";
|
||||
private static final String ENCODE_TYPE = "ENCODE_TYPE";
|
||||
private static final String ENCODE_INTENT = "com.phonegap.plugins.barcodescanner.ENCODE";
|
||||
private static final String TEXT_TYPE = "TEXT_TYPE";
|
||||
private static final String EMAIL_TYPE = "EMAIL_TYPE";
|
||||
private static final String PHONE_TYPE = "PHONE_TYPE";
|
||||
private static final String SMS_TYPE = "SMS_TYPE";
|
||||
|
||||
private static final String LOG_TAG = "BarcodeScanner";
|
||||
|
||||
private CallbackContext callbackContext;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public BarcodeScanner() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the request.
|
||||
*
|
||||
* This method is called from the WebView thread. To do a non-trivial amount of work, use:
|
||||
* cordova.getThreadPool().execute(runnable);
|
||||
*
|
||||
* To run on the UI thread, use:
|
||||
* cordova.getActivity().runOnUiThread(runnable);
|
||||
*
|
||||
* @param action The action to execute.
|
||||
* @param args The exec() arguments.
|
||||
* @param callbackContext The callback context used when calling back into JavaScript.
|
||||
* @return Whether the action was valid.
|
||||
*
|
||||
* @sa https://github.com/apache/cordova-android/blob/master/framework/src/org/apache/cordova/CordovaPlugin.java
|
||||
*/
|
||||
@Override
|
||||
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
|
||||
this.callbackContext = callbackContext;
|
||||
|
||||
if (action.equals(ENCODE)) {
|
||||
JSONObject obj = args.optJSONObject(0);
|
||||
if (obj != null) {
|
||||
String type = obj.optString(TYPE);
|
||||
String data = obj.optString(DATA);
|
||||
|
||||
// If the type is null then force the type to text
|
||||
if (type == null) {
|
||||
type = TEXT_TYPE;
|
||||
}
|
||||
|
||||
if (data == null) {
|
||||
callbackContext.error("User did not specify data to encode");
|
||||
return true;
|
||||
}
|
||||
|
||||
encode(type, data);
|
||||
} else {
|
||||
callbackContext.error("User did not specify data to encode");
|
||||
return true;
|
||||
}
|
||||
} else if (action.equals(SCAN)) {
|
||||
scan();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts an intent to scan and decode a barcode.
|
||||
*/
|
||||
public void scan() {
|
||||
Intent intentScan = new Intent(SCAN_INTENT);
|
||||
intentScan.addCategory(Intent.CATEGORY_DEFAULT);
|
||||
|
||||
this.cordova.startActivityForResult((CordovaPlugin) this, intentScan, REQUEST_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the barcode scanner intent completes.
|
||||
*
|
||||
* @param requestCode The request code originally supplied to startActivityForResult(),
|
||||
* allowing you to identify who this result came from.
|
||||
* @param resultCode The integer result code returned by the child activity through its setResult().
|
||||
* @param intent An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
|
||||
*/
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
||||
if (requestCode == REQUEST_CODE) {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
JSONObject obj = new JSONObject();
|
||||
try {
|
||||
obj.put(TEXT, intent.getStringExtra("SCAN_RESULT"));
|
||||
obj.put(FORMAT, intent.getStringExtra("SCAN_RESULT_FORMAT"));
|
||||
obj.put(CANCELLED, false);
|
||||
} catch (JSONException e) {
|
||||
Log.d(LOG_TAG, "This should never happen");
|
||||
}
|
||||
//this.success(new PluginResult(PluginResult.Status.OK, obj), this.callback);
|
||||
this.callbackContext.success(obj);
|
||||
} else if (resultCode == Activity.RESULT_CANCELED) {
|
||||
JSONObject obj = new JSONObject();
|
||||
try {
|
||||
obj.put(TEXT, "");
|
||||
obj.put(FORMAT, "");
|
||||
obj.put(CANCELLED, true);
|
||||
} catch (JSONException e) {
|
||||
Log.d(LOG_TAG, "This should never happen");
|
||||
}
|
||||
//this.success(new PluginResult(PluginResult.Status.OK, obj), this.callback);
|
||||
this.callbackContext.success(obj);
|
||||
} else {
|
||||
//this.error(new PluginResult(PluginResult.Status.ERROR), this.callback);
|
||||
this.callbackContext.error("Unexpected error");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiates a barcode encode.
|
||||
*
|
||||
* @param type Endoiding type.
|
||||
* @param data The data to encode in the bar code.
|
||||
*/
|
||||
public void encode(String type, String data) {
|
||||
Intent intentEncode = new Intent(ENCODE_INTENT);
|
||||
intentEncode.putExtra(ENCODE_TYPE, type);
|
||||
intentEncode.putExtra(ENCODE_DATA, data);
|
||||
|
||||
this.cordova.getActivity().startActivity(intentEncode);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
Copyright 2013-2014 appPlant UG
|
||||
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you 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 License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
|
||||
package de.appplant.cordova.plugin.emailcomposer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
import android.content.ContentProvider;
|
||||
import android.content.ContentValues;
|
||||
import android.content.UriMatcher;
|
||||
import android.database.Cursor;
|
||||
import android.database.MatrixCursor;
|
||||
import android.net.Uri;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.provider.MediaStore;
|
||||
import android.webkit.MimeTypeMap;
|
||||
|
||||
public class AttachmentProvider extends ContentProvider {
|
||||
|
||||
public static final String AUTHORITY = ".plugin.emailcomposer.attachmentprovider";
|
||||
|
||||
private UriMatcher uriMatcher;
|
||||
|
||||
@Override
|
||||
public boolean onCreate() {
|
||||
String pkgName = this.getContext().getPackageName();
|
||||
|
||||
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
|
||||
|
||||
uriMatcher.addURI(pkgName + AUTHORITY, "*", 1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
|
||||
switch(uriMatcher.match(uri)) {
|
||||
case 1:
|
||||
String storage = getContext().getCacheDir() + EmailComposer.STORAGE_FOLDER;
|
||||
String path = storage + File.separator + uri.getLastPathSegment();
|
||||
|
||||
File file = new File(path);
|
||||
ParcelFileDescriptor pfd = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
|
||||
|
||||
return pfd;
|
||||
default:
|
||||
throw new FileNotFoundException("Unsupported uri: " + uri.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(Uri arg0, ContentValues arg1, String arg2, String[] arg3) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delete(Uri arg0, String arg1, String[] arg2) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uri insert(Uri arg0, ContentValues arg1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType(Uri arg0) {
|
||||
String fileExtension = MimeTypeMap.getFileExtensionFromUrl(arg0.getPath());
|
||||
String type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExtension);
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
|
||||
MatrixCursor result = new MatrixCursor(projection);
|
||||
Object[] row = new Object[projection.length];
|
||||
long fileSize = 0;
|
||||
|
||||
String fileLocation = getContext().getCacheDir() + File.separator + uri.getLastPathSegment();
|
||||
File tempFile = new File(fileLocation);
|
||||
fileSize = tempFile.length();
|
||||
|
||||
for (int i=0; i<projection.length; i++) {
|
||||
if (projection[i].compareToIgnoreCase(MediaStore.MediaColumns.DISPLAY_NAME) == 0) {
|
||||
row[i] = uri.getLastPathSegment();
|
||||
} else if (projection[i].compareToIgnoreCase(MediaStore.MediaColumns.SIZE) == 0) {
|
||||
row[i] = fileSize;
|
||||
}
|
||||
}
|
||||
|
||||
result.addRow(row);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,413 @@
|
|||
/*
|
||||
Copyright 2013-2014 appPlant UG
|
||||
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you 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 License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
|
||||
package de.appplant.cordova.plugin.emailcomposer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.res.AssetManager;
|
||||
import android.content.res.Resources;
|
||||
import android.net.Uri;
|
||||
import android.text.Html;
|
||||
import android.util.Base64;
|
||||
|
||||
import org.apache.cordova.CordovaPlugin;
|
||||
import org.apache.cordova.CallbackContext;
|
||||
import org.apache.cordova.PluginResult;
|
||||
|
||||
public class EmailComposer extends CordovaPlugin {
|
||||
|
||||
static protected final String STORAGE_FOLDER = File.separator + "email_composer";
|
||||
|
||||
private CallbackContext command;
|
||||
|
||||
@Override
|
||||
public boolean execute (String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
|
||||
|
||||
this.command = callbackContext;
|
||||
|
||||
// Eine E-Mail soll versendet werden
|
||||
if ("open".equals(action)) {
|
||||
open(args);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Es soll überprüft werden, ob ein Dienst zum Versenden der E-Mail zur Verfügung steht
|
||||
if ("isServiceAvailable".equals(action)) {
|
||||
isServiceAvailable();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Returning false results in a "MethodNotFound" error.
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Überprüft, ob Emails versendet werden können.
|
||||
*/
|
||||
private void isServiceAvailable () {
|
||||
Boolean available = isEmailAccountConfigured();
|
||||
PluginResult result = new PluginResult(PluginResult.Status.OK, available);
|
||||
|
||||
command.sendPluginResult(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Öffnet den Email-Kontroller mit vorausgefüllten Daten.
|
||||
*/
|
||||
private void open (JSONArray args) throws JSONException {
|
||||
JSONObject properties = args.getJSONObject(0);
|
||||
Intent draft = getDraftWithProperties(properties);
|
||||
|
||||
openDraft(draft);
|
||||
}
|
||||
|
||||
/**
|
||||
* Erstellt den ViewController für Mails und fügt die übergebenen Eigenschaften ein.
|
||||
*
|
||||
* @param {JSONObject} params (Subject, Body, Recipients, ...)
|
||||
*/
|
||||
private Intent getDraftWithProperties (JSONObject params) throws JSONException {
|
||||
Intent mail = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
|
||||
|
||||
if (params.has("subject"))
|
||||
setSubject(params.getString("subject"), mail);
|
||||
if (params.has("body"))
|
||||
setBody(params.getString("body"), params.optBoolean("isHtml"), mail);
|
||||
if (params.has("to"))
|
||||
setRecipients(params.getJSONArray("to"), mail);
|
||||
if (params.has("cc"))
|
||||
setCcRecipients(params.getJSONArray("cc"), mail);
|
||||
if (params.has("bcc"))
|
||||
setBccRecipients(params.getJSONArray("bcc"), mail);
|
||||
if (params.has("attachments"))
|
||||
setAttachments(params.getJSONArray("attachments"), mail);
|
||||
|
||||
mail.setType("application/octet-stream");
|
||||
|
||||
return mail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zeigt den ViewController zum Versenden/Bearbeiten der Mail an.
|
||||
*/
|
||||
private void openDraft (final Intent draft) {
|
||||
final EmailComposer plugin = this;
|
||||
|
||||
cordova.getThreadPool().execute( new Runnable() {
|
||||
public void run() {
|
||||
cordova.startActivityForResult(plugin, Intent.createChooser(draft, "Select Email App"), 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Setzt den Subject der Mail.
|
||||
*/
|
||||
private void setSubject (String subject, Intent draft) {
|
||||
draft.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setzt den Body der Mail.
|
||||
*/
|
||||
private void setBody (String body, Boolean isHTML, Intent draft) {
|
||||
if (isHTML) {
|
||||
draft.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(body));
|
||||
draft.setType("text/html");
|
||||
} else {
|
||||
draft.putExtra(android.content.Intent.EXTRA_TEXT, body);
|
||||
draft.setType("text/plain");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Setzt die Empfänger der Mail.
|
||||
*/
|
||||
private void setRecipients (JSONArray recipients, Intent draft) throws JSONException {
|
||||
String[] receivers = new String[recipients.length()];
|
||||
|
||||
for (int i = 0; i < recipients.length(); i++) {
|
||||
receivers[i] = recipients.getString(i);
|
||||
}
|
||||
|
||||
draft.putExtra(android.content.Intent.EXTRA_EMAIL, receivers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setzt die CC-Empfänger der Mail.
|
||||
*/
|
||||
private void setCcRecipients (JSONArray ccRecipients, Intent draft) throws JSONException {
|
||||
String[] receivers = new String[ccRecipients.length()];
|
||||
|
||||
for (int i = 0; i < ccRecipients.length(); i++) {
|
||||
receivers[i] = ccRecipients.getString(i);
|
||||
}
|
||||
|
||||
draft.putExtra(android.content.Intent.EXTRA_CC, receivers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setzt die BCC-Empfänger der Mail.
|
||||
*/
|
||||
private void setBccRecipients (JSONArray bccRecipients, Intent draft) throws JSONException {
|
||||
String[] receivers = new String[bccRecipients.length()];
|
||||
|
||||
for (int i = 0; i < bccRecipients.length(); i++) {
|
||||
receivers[i] = bccRecipients.getString(i);
|
||||
}
|
||||
|
||||
draft.putExtra(android.content.Intent.EXTRA_BCC, receivers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fügt die Anhände zur Mail hinzu.
|
||||
*/
|
||||
private void setAttachments (JSONArray attachments, Intent draft) throws JSONException {
|
||||
ArrayList<Uri> attachmentUris = new ArrayList<Uri>();
|
||||
|
||||
for (int i = 0; i < attachments.length(); i++) {
|
||||
Uri attachmentUri = getUriForPath(attachments.getString(i));
|
||||
|
||||
attachmentUris.add(attachmentUri);
|
||||
}
|
||||
|
||||
draft.putParcelableArrayListExtra(Intent.EXTRA_STREAM, attachmentUris);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt an, ob es eine Anwendung gibt, welche E-Mails versenden kann.
|
||||
*/
|
||||
private Boolean isEmailAccountConfigured () {
|
||||
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto","max@mustermann.com", null));
|
||||
Boolean available = cordova.getActivity().getPackageManager().queryIntentActivities(intent, 0).size() > 1;
|
||||
|
||||
return available;
|
||||
}
|
||||
|
||||
/**
|
||||
* The URI for an attachment path.
|
||||
*
|
||||
* @param {String} path
|
||||
* The given path to the attachment
|
||||
*
|
||||
* @return The URI pointing to the given path
|
||||
*/
|
||||
private Uri getUriForPath (String path) {
|
||||
if (path.startsWith("res:")) {
|
||||
return getUriForResourcePath(path);
|
||||
} else if (path.startsWith("file:")) {
|
||||
return getUriForAbsolutePath(path);
|
||||
} else if (path.startsWith("www:")) {
|
||||
return getUriForAssetPath(path);
|
||||
} else if (path.startsWith("base64:")) {
|
||||
return getUriForBase64Content(path);
|
||||
}
|
||||
|
||||
return Uri.parse(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* The URI for a file.
|
||||
*
|
||||
* @param {String} path
|
||||
* The given absolute path
|
||||
*
|
||||
* @return The URI pointing to the given path
|
||||
*/
|
||||
private Uri getUriForAbsolutePath (String path) {
|
||||
String absPath = path.replaceFirst("file://", "");
|
||||
File file = new File(absPath);
|
||||
|
||||
if (!file.exists()) {
|
||||
System.err.println("Attachment path not found: " + file.getAbsolutePath());
|
||||
}
|
||||
|
||||
return Uri.fromFile(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* The URI for an asset.
|
||||
*
|
||||
* @param {String} path
|
||||
* The given asset path
|
||||
*
|
||||
* @return The URI pointing to the given path
|
||||
*/
|
||||
private Uri getUriForAssetPath (String path) {
|
||||
String resPath = path.replaceFirst("www:/", "www");
|
||||
String fileName = resPath.substring(resPath.lastIndexOf('/') + 1);
|
||||
String storage = cordova.getActivity().getExternalCacheDir().toString() + STORAGE_FOLDER;
|
||||
|
||||
File file = new File(storage, fileName);
|
||||
|
||||
new File(storage).mkdir();
|
||||
|
||||
try {
|
||||
AssetManager assets = cordova.getActivity().getAssets();
|
||||
|
||||
FileOutputStream outStream = new FileOutputStream(file);
|
||||
InputStream inputStream = assets.open(resPath);
|
||||
|
||||
copyFile(inputStream, outStream);
|
||||
outStream.flush();
|
||||
outStream.close();
|
||||
} catch (Exception e) {
|
||||
System.err.println("Attachment asset not found: assets/" + resPath);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return Uri.fromFile(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* The URI for a resource.
|
||||
*
|
||||
* @param {String} path
|
||||
* The given relative path
|
||||
*
|
||||
* @return The URI pointing to the given path
|
||||
*/
|
||||
private Uri getUriForResourcePath (String path) {
|
||||
String resPath = path.replaceFirst("res://", "");
|
||||
String fileName = resPath.substring(resPath.lastIndexOf('/') + 1);
|
||||
String resName = fileName.substring(0, fileName.lastIndexOf('.'));
|
||||
String extension = resPath.substring(resPath.lastIndexOf('.'));
|
||||
String storage = cordova.getActivity().getExternalCacheDir().toString() + STORAGE_FOLDER;
|
||||
|
||||
int resId = getResId(resPath);
|
||||
File file = new File(storage, resName + extension);
|
||||
|
||||
if (resId == 0) {
|
||||
System.err.println("Attachment resource not found: " + resPath);
|
||||
}
|
||||
|
||||
new File(storage).mkdir();
|
||||
|
||||
try {
|
||||
Resources res = cordova.getActivity().getResources();
|
||||
FileOutputStream outStream = new FileOutputStream(file);
|
||||
InputStream inputStream = res.openRawResource(resId);
|
||||
|
||||
copyFile(inputStream, outStream);
|
||||
outStream.flush();
|
||||
outStream.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return Uri.fromFile(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* The URI for a base64 encoded content.
|
||||
*
|
||||
* @param {String} content
|
||||
* The given base64 encoded content
|
||||
*
|
||||
* @return The URI including the given content
|
||||
*/
|
||||
private Uri getUriForBase64Content (String content) {
|
||||
String resName = content.substring(content.indexOf(":") + 1, content.indexOf("//"));
|
||||
String resData = content.substring(content.indexOf("//") + 2);
|
||||
byte[] bytes = Base64.decode(resData, 0);
|
||||
String storage = this.cordova.getActivity().getCacheDir() + STORAGE_FOLDER;
|
||||
File file = new File(storage, resName);
|
||||
|
||||
new File(storage).mkdir();
|
||||
|
||||
try {
|
||||
FileOutputStream outStream = new FileOutputStream(file);
|
||||
|
||||
outStream.write(bytes);
|
||||
outStream.flush();
|
||||
outStream.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
String pkgName = getPackageName();
|
||||
String uriPath = pkgName + AttachmentProvider.AUTHORITY + "/" + resName;
|
||||
|
||||
return Uri.parse("content://" + uriPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes an InputStream to an OutputStream
|
||||
*
|
||||
* @param {InputStream} in
|
||||
* @param {OutputStream} out
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private void copyFile (InputStream in, OutputStream out) throws IOException {
|
||||
byte[] buffer = new byte[1024];
|
||||
int read;
|
||||
|
||||
while((read = in.read(buffer)) != -1){
|
||||
out.write(buffer, 0, read);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* The resource ID for the given resource.
|
||||
*/
|
||||
private int getResId (String resPath) {
|
||||
Resources res = cordova.getActivity().getResources();
|
||||
|
||||
String pkgName = getPackageName();
|
||||
String dirName = resPath.substring(0, resPath.lastIndexOf('/'));
|
||||
String fileName = resPath.substring(resPath.lastIndexOf('/') + 1);
|
||||
String resName = fileName.substring(0, fileName.lastIndexOf('.'));
|
||||
|
||||
int resId = res.getIdentifier(resName, dirName, pkgName);
|
||||
|
||||
return resId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* The name for the package.
|
||||
*/
|
||||
private String getPackageName () {
|
||||
return cordova.getActivity().getPackageName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
||||
super.onActivityResult(requestCode, resultCode, intent);
|
||||
|
||||
command.success();
|
||||
}
|
||||
}
|
||||
43
mobile/src/org/apache/cordova/splashscreen/SplashScreen.java
Normal file
43
mobile/src/org/apache/cordova/splashscreen/SplashScreen.java
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you 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 License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
|
||||
package org.apache.cordova.splashscreen;
|
||||
|
||||
import org.apache.cordova.CallbackContext;
|
||||
import org.apache.cordova.CordovaPlugin;
|
||||
import org.json.JSONArray;
|
||||
|
||||
public class SplashScreen extends CordovaPlugin {
|
||||
|
||||
@Override
|
||||
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
|
||||
if (action.equals("hide")) {
|
||||
this.webView.postMessage("splashscreen", "hide");
|
||||
} else if (action.equals("show")){
|
||||
this.webView.postMessage("splashscreen", "show");
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
|
||||
callbackContext.success();
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
124
mobile/src/org/apache/cordova/vibration/Vibration.java
Normal file
124
mobile/src/org/apache/cordova/vibration/Vibration.java
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
/*
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you 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 License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
package org.apache.cordova.vibration;
|
||||
|
||||
import org.apache.cordova.CallbackContext;
|
||||
import org.apache.cordova.CordovaPlugin;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import android.content.Context;
|
||||
import android.os.Vibrator;
|
||||
|
||||
/**
|
||||
* This class provides access to vibration on the device.
|
||||
*/
|
||||
public class Vibration extends CordovaPlugin {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public Vibration() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the request and returns PluginResult.
|
||||
*
|
||||
* @param action The action to execute.
|
||||
* @param args JSONArray of arguments for the plugin.
|
||||
* @param callbackContext The callback context used when calling back into JavaScript.
|
||||
* @return True when the action was valid, false otherwise.
|
||||
*/
|
||||
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
|
||||
if (action.equals("vibrate")) {
|
||||
this.vibrate(args.getLong(0));
|
||||
}
|
||||
else if (action.equals("vibrateWithPattern")) {
|
||||
JSONArray pattern = args.getJSONArray(0);
|
||||
int repeat = args.getInt(1);
|
||||
long[] patternArray = new long[pattern.length()];
|
||||
for (int i = 0; i < pattern.length(); i++) {
|
||||
patternArray[i] = pattern.getLong(i);
|
||||
}
|
||||
this.vibrateWithPattern(patternArray, repeat);
|
||||
}
|
||||
else if (action.equals("cancelVibration")) {
|
||||
this.cancelVibration();
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Only alert and confirm are async.
|
||||
callbackContext.success();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// LOCAL METHODS
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Vibrates the device for a given amount of time.
|
||||
*
|
||||
* @param time Time to vibrate in ms.
|
||||
*/
|
||||
public void vibrate(long time) {
|
||||
// Start the vibration, 0 defaults to half a second.
|
||||
if (time == 0) {
|
||||
time = 500;
|
||||
}
|
||||
Vibrator vibrator = (Vibrator) this.cordova.getActivity().getSystemService(Context.VIBRATOR_SERVICE);
|
||||
vibrator.vibrate(time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Vibrates the device with a given pattern.
|
||||
*
|
||||
* @param pattern Pattern with which to vibrate the device.
|
||||
* Pass in an array of longs that
|
||||
* are the durations for which to
|
||||
* turn on or off the vibrator in
|
||||
* milliseconds. The first value
|
||||
* indicates the number of milliseconds
|
||||
* to wait before turning the vibrator
|
||||
* on. The next value indicates the
|
||||
* number of milliseconds for which
|
||||
* to keep the vibrator on before
|
||||
* turning it off. Subsequent values
|
||||
* alternate between durations in
|
||||
* milliseconds to turn the vibrator
|
||||
* off or to turn the vibrator on.
|
||||
*
|
||||
* @param repeat Optional index into the pattern array at which
|
||||
* to start repeating, or -1 for no repetition (default).
|
||||
*/
|
||||
public void vibrateWithPattern(long[] pattern, int repeat) {
|
||||
Vibrator vibrator = (Vibrator) this.cordova.getActivity().getSystemService(Context.VIBRATOR_SERVICE);
|
||||
vibrator.vibrate(pattern, repeat);
|
||||
}
|
||||
|
||||
/**
|
||||
* Immediately cancels any currently running vibration.
|
||||
*/
|
||||
public void cancelVibration() {
|
||||
Vibrator vibrator = (Vibrator) this.cordova.getActivity().getSystemService(Context.VIBRATOR_SERVICE);
|
||||
vibrator.cancel();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue