Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
gliechtenstein committed Apr 7, 2017
2 parents e8449b9 + b77d461 commit 049b843
Show file tree
Hide file tree
Showing 27 changed files with 2,823 additions and 301 deletions.
9 changes: 7 additions & 2 deletions app/build.gradle
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion '23.0.2'
buildToolsVersion '25.0.0'
defaultConfig {
applicationId "com.jasonette"
minSdkVersion 16
Expand Down Expand Up @@ -31,9 +31,14 @@ dependencies {
compile 'jp.wasabeef:glide-transformations:2.0.1'
compile 'com.eclipsesource.j2v8:j2v8:4.5.0@aar'
compile 'com.android.support:recyclerview-v7:25.0.1'
compile 'com.android.support:design:25.0.0'
compile 'com.android.support:design:25.0.1'
compile 'com.aurelhubert:ahbottomnavigation:2.0.2'
compile 'com.android.support:support-core-ui:25.0.1'
compile 'commons-lang:commons-lang:2.6'
compile 'com.github.scribejava:scribejava-apis:4.0.0'
compile 'com.yqritc:recyclerview-flexibledivider:1.4.0'
compile 'com.commonsware.cwac:cam2:0.7.4'
compile 'com.github.adrielcafe:AndroidAudioRecorder:0.2.0'
compile 'com.github.adrielcafe:AndroidAudioConverter:0.0.8'
compile 'com.github.florent37:singledateandtimepicker:1.0.8'
}
43 changes: 38 additions & 5 deletions app/src/main/AndroidManifest.xml
Expand Up @@ -12,10 +12,34 @@
<activity android:name=".Core.JasonViewActivity" android:windowSoftInputMode="adjustResize" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<!-- Uncomment below intent-filter to support custom url schemes -->
<!--
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="jason" />
</intent-filter>
-->

<!-- Uncomment below intent-filter to support url opening -->
<!--
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" android:host="oauth" />
</intent-filter>
-->
</activity>
<activity
android:name="com.commonsware.cwac.cam2.CameraActivity"
android:process=":cwac_cam2"
android:theme="@style/CameraTheme"/>

<!-- Uncomment below line and add your Google Maps API key -->
<!--
<meta-data android:name="com.google.android.geo.API_KEY" android:value="YOUR GOOGLE MAPS API KEY HERE"/>
Expand All @@ -25,14 +49,23 @@

<!-- Uncomment below line to enable $util.addressbook -->
<!--
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
-->

<!-- Uncomment below lines to enable $geo.get -->
<!--
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
-->

<!-- Uncomment below lines to enable $audio.record -->
<!--
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
-->


<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

</manifest>
3 changes: 1 addition & 2 deletions app/src/main/assets/parser
Expand Up @@ -22686,8 +22686,7 @@ var json = function(template, data, json){
}
}
}
//return JSON.parse(JSON.stringify(res));
return res; // using JSON.parse(JSON.stringify(res)) gets rid of $root but messes up binary data because they're not string
return JSON.parse(JSON.stringify(res)); // get rid of $root since we're done
}

function isObject(obj) {
Expand Down
238 changes: 238 additions & 0 deletions app/src/main/java/com/jasonette/seed/Action/JasonAudioAction.java
@@ -0,0 +1,238 @@
package com.jasonette.seed.Action;

import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Environment;
import android.util.Log;

import com.jasonette.seed.Core.JasonViewActivity;
import com.jasonette.seed.Helper.JasonHelper;

import org.json.JSONObject;

import java.io.File;

import cafe.adriel.androidaudioconverter.AndroidAudioConverter;
import cafe.adriel.androidaudioconverter.callback.IConvertCallback;
import cafe.adriel.androidaudioconverter.callback.ILoadCallback;
import cafe.adriel.androidaudioconverter.model.AudioFormat;
import cafe.adriel.androidaudiorecorder.AndroidAudioRecorder;
import cafe.adriel.androidaudiorecorder.model.AudioChannel;
import cafe.adriel.androidaudiorecorder.model.AudioSampleRate;
import cafe.adriel.androidaudiorecorder.model.AudioSource;

public class JasonAudioAction {
private MediaPlayer player;
public void play(final JSONObject action, JSONObject data, final JSONObject event, final Context context) {
try {
if (action.has("options")) {
JSONObject options = action.getJSONObject("options");
if(options.has("url")){
if(player == null) {
player = new MediaPlayer();
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
}

AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
((JasonViewActivity)context).setVolumeControlStream(AudioManager.STREAM_MUSIC);

String url = options.getString("url");
player.reset();
player.setDataSource(url);
player.prepare();
player.start();


}
}
JasonHelper.next("success", action, new JSONObject(), event, context);
} catch (SecurityException e){
JasonHelper.permission_exception("$audio.play", context);
} catch (Exception e) {
Log.d("Error", e.toString());
}
}
public void pause(final JSONObject action, JSONObject data, final JSONObject event, final Context context) {
if(player!=null){
player.pause();
}
JasonHelper.next("success", action, new JSONObject(), event, context);
}
public void stop(final JSONObject action, JSONObject data, final JSONObject event, final Context context) {
if(player!=null){
player.stop();
player.release();
player = null;
}
JasonHelper.next("success", action, new JSONObject(), event, context);
}
public void duration(final JSONObject action, JSONObject data, final JSONObject event, final Context context) {
if (player != null) {
try {
int duration = (int) (player.getDuration() / 1000);
JSONObject ret = new JSONObject();
ret.put("value", String.valueOf(duration));
JasonHelper.next("success", action, ret, event, context);
} catch (Exception e) {
Log.d("Error", e.toString());
try {
JSONObject err = new JSONObject();
err.put("message", "invalid position");
JasonHelper.next("error", action, err, event, context);
} catch (Exception e2){
Log.d("Error", e2.toString());
}
}
} else {
try {
JSONObject err = new JSONObject();
err.put("message", "player doesn't exist");
JasonHelper.next("error", action, err, event, context);
} catch (Exception e){
Log.d("Error", e.toString());
}
}
}
public void position(final JSONObject action, JSONObject data, final JSONObject event, final Context context) {
if (player != null) {
try {
int duration = player.getDuration();
int position = player.getCurrentPosition();
float ratio = position/duration;
JSONObject ret = new JSONObject();
ret.put("value", String.valueOf(ratio));
JasonHelper.next("success", action, ret, event, context);
} catch (Exception e) {
try {
JSONObject err = new JSONObject();
err.put("message", "invalid position or duration");
JasonHelper.next("error", action, err, event, context);
} catch (Exception e2){
Log.d("Error", e2.toString());
}
}
} else {
try {
JSONObject err = new JSONObject();
err.put("message", "player doesn't exist");
JasonHelper.next("error", action, err, event, context);
} catch (Exception e){
Log.d("Error", e.toString());
}
}
}
public void seek(final JSONObject action, JSONObject data, final JSONObject event, final Context context) {
if(player!=null) {
try {
if (action.has("options")) {
JSONObject options = action.getJSONObject("options");
if(options.has("position")){
float position = Float.parseFloat(options.getString("position"));
int duration = player.getDuration();
player.seekTo((int)position * duration);
}
}
} catch (Exception e) {
Log.d("Error", e.toString());
}
}
JasonHelper.next("success", action, new JSONObject(), event, context);
}

public void record(final JSONObject action, JSONObject data, final JSONObject event, final Context context) {
try {
int color = JasonHelper.parse_color("rgba(0,0,0,0.8)");
if (action.has("options")) {
JSONObject options = action.getJSONObject("options");
if (options.has("color")) {
color = JasonHelper.parse_color(options.getString("color"));
}
}
AndroidAudioConverter.load(context, new ILoadCallback() {
@Override
public void onSuccess() {
}
@Override
public void onFailure(Exception error) {
Log.d("Error", error.toString());
}
});

String filePath = Environment.getExternalStorageDirectory() + "/recorded_audio.wav";
int requestCode = (int)(System.currentTimeMillis() % 10000);
AndroidAudioRecorder.with((JasonViewActivity)context)
.setFilePath(filePath)
.setColor(color)
.setRequestCode(requestCode)

.setSource(AudioSource.MIC)

.setChannel(AudioChannel.STEREO)
.setSampleRate(AudioSampleRate.HZ_48000)
.setAutoStart(true)
.setKeepDisplayOn(true)

.record();

JSONObject callback = new JSONObject();
callback.put("class", "JasonAudioAction");
callback.put("method", "process");
JasonHelper.dispatchIntent(String.valueOf(requestCode), action, data, event, context, null, callback);
} catch (SecurityException e){
JasonHelper.permission_exception("$audio.record", context);
} catch (Exception e){
Log.d("Error", e.toString());
}
}


// util
public void process(Intent intent, final JSONObject options) {
convert(options);
}

private void convert(final JSONObject options){
File file = new File(Environment.getExternalStorageDirectory() + "/recorded_audio.wav");
try {
final JSONObject action = options.getJSONObject("action");
final JSONObject data = options.getJSONObject("data");
final JSONObject event = options.getJSONObject("event");
final Context context = (Context) options.get("context");

IConvertCallback callback = new IConvertCallback() {
@Override
public void onSuccess(File convertedFile) {
try {
JSONObject ret = new JSONObject();
String filePath = "file://" + convertedFile.getAbsolutePath();
ret.put("file_url", filePath);
ret.put("url", filePath);
ret.put("content_type", "audio/m4a");
JasonHelper.next("success", action, ret, event, context);
} catch (Exception e) {
Log.d("Error", e.toString());
}
}
@Override
public void onFailure(Exception error) {
try {
JSONObject err = new JSONObject();
err.put("message", error.toString());
JasonHelper.next("error", action, err, event, context);
} catch (Exception e){
Log.d("Error", e.toString());
}
}
};
AndroidAudioConverter.with(context)
.setFile(file)
.setFormat(AudioFormat.M4A)
.setCallback(callback)
.convert();
} catch (Exception e) {
Log.d("Error", e.toString());
}
}
}
Expand Up @@ -16,11 +16,12 @@
public class JasonConvertAction {
private JSONObject action;
private Context context;
private JSONObject event;
private JSONObject event_cache;

public void csv(final JSONObject action, final JSONObject data, final JSONObject event, final Context context){
this.action = action;
this.context = context;
event_cache = event;
try{
final JSONObject options = action.getJSONObject("options");
String result = "[]";
Expand Down Expand Up @@ -50,6 +51,7 @@ public void csv(final JSONObject action, final JSONObject data, final JSONObject
public void rss(final JSONObject action, final JSONObject data, final JSONObject event, final Context context){
this.action = action;
this.context = context;
event_cache = event;
try{
final JSONObject options = action.getJSONObject("options");
String rss_data = options.getString("data");
Expand Down Expand Up @@ -105,7 +107,7 @@ private void handle_exception(Exception exc){
try {
JSONObject error = new JSONObject();
error.put("data", exc.toString());
JasonHelper.next("error", action, error, event, context);
JasonHelper.next("error", action, error, event_cache, context);
} catch (Exception err){
Log.d("Error", err.toString());
}
Expand Down Expand Up @@ -137,7 +139,7 @@ public void invoke(V8Object receiver, V8Array parameters) {
V8Array rss_data = (V8Array) parameters.get(0);
String result = stringify(receiver.getRuntime(), rss_data);

JasonHelper.next("success", action, result, event, context);
JasonHelper.next("success", action, result, event_cache, context);
} catch (Exception e) {
handle_exception(e);
}
Expand Down
Expand Up @@ -39,6 +39,8 @@ public void onProviderDisabled(String provider) {
}
};
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener, Looper.getMainLooper());
} catch (SecurityException e){
JasonHelper.permission_exception("$geo.get", context);
} catch (Exception e) {
Log.d("Error", e.toString());
}
Expand Down

0 comments on commit 049b843

Please sign in to comment.