Skip to content
Open

$key #198

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,7 @@ dependencies {
compile 'com.github.florent37:singledateandtimepicker:1.0.8'
compile 'com.jakewharton.timber:timber:4.5.1'
compile 'com.google.android.gms:play-services:+'
compile 'com.scottyab:secure-preferences-lib:0.1.4'
compile 'com.github.gliechtenstein:PasscodeView:master'
compile 'com.android.support:multidex:1.0.1'
}
1 change: 1 addition & 0 deletions app/src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
android:name="com.commonsware.cwac.cam2.CameraActivity"
android:process=":cwac_cam2"
android:theme="@style/CameraTheme"/>
<activity android:name=".Lib.PasscodeActivity"/>

<!-- Uncomment below to support push notification -->
<!--
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
android:name="com.commonsware.cwac.cam2.CameraActivity"
android:process=":cwac_cam2"
android:theme="@style/CameraTheme"/>
<activity android:name=".Lib.PasscodeActivity"/>

<!-- Uncomment below line and add your Google Maps API key -->
<!--
Expand Down
73 changes: 73 additions & 0 deletions app/src/main/java/com/jasonette/seed/Action/JasonKeyAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.jasonette.seed.Action;
import android.content.Context;
import android.content.Intent;

import com.jasonette.seed.Helper.JasonHelper;
import com.jasonette.seed.Launcher.Launcher;
import com.jasonette.seed.Service.key.JasonKeyService;

import org.json.JSONObject;

public class JasonKeyAction {

public void request(final JSONObject action, final JSONObject data, final JSONObject event, final Context context) {
_forward("request", action, data, event, context);
}
public void add(final JSONObject action, final JSONObject data, final JSONObject event, final Context context) {
_forward("add", action, data, event, context);
}
public void remove(final JSONObject action, final JSONObject data, final JSONObject event, final Context context) {
_forward("remove", action, data, event, context);
}
public void update(final JSONObject action, final JSONObject data, final JSONObject event, final Context context) {
_forward("update", action, data, event, context);
}
public void clear(final JSONObject action, final JSONObject data, final JSONObject event, final Context context) {
_forward("clear", action, data, event, context);
}
public void password(final JSONObject action, final JSONObject data, final JSONObject event, final Context context) {
_forward("password", action, data, event, context);
}


// Called from dispatchIntent
// Called right after the user has successfully updated the password
public void on_register(Intent intent, final JSONObject options) {
try {
JSONObject action = options.getJSONObject("action");
JSONObject event = options.getJSONObject("event");
Context context = (Context) options.get("context");

// Password update was successful, therefore it's safe to go onto the next action
JasonHelper.next("success", action, new JSONObject(), event, context);
} catch (Exception e) {

}
}

// Called from dispatchIntent
// Called right after the user has successfully authenticated
public void on_authenticate(Intent intent, final JSONObject options) {
try {
JSONObject action = options.getJSONObject("action");
JSONObject data = options.getJSONObject("data");
JSONObject event = options.getJSONObject("event");
Context context = (Context) options.get("context");
String type = action.getString("type");
String name = type.split("\\.")[1];

// Call the JasonKeyService method one more time.
// The first time 'authenticated' was false and was redirected to _auth.
// but this time 'authenticated' will be true, therefore will execute the actual intended action
JasonKeyService keyService = (JasonKeyService)((Launcher)context.getApplicationContext()).services.get("JasonKeyService");
keyService.forward(name, action, data, event);

} catch (Exception e) {

}
}

private void _forward(String name, final JSONObject action, final JSONObject data, final JSONObject event, final Context context) {
((Launcher)context.getApplicationContext()).forward("JasonKeyService", name, action, data, event, context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,13 @@ public void run() {
final ArrayList<EditText> textFields = new ArrayList<EditText>();
if (action.has("options")) {
options = action.getJSONObject("options");
String title = options.getString("title");
String description = options.getString("description");

String title = "";
if (options.has("title")) title = options.getString("title");

String description = "";
if (options.has("description")) description = options.getString("description");

builder.setTitle(title);
builder.setMessage(description);

Expand Down
34 changes: 11 additions & 23 deletions app/src/main/java/com/jasonette/seed/Core/JasonViewActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,8 @@ protected void onCreate(Bundle savedInstanceState) {
}

}
private void setup_agents() {
private void setup_agents(JSONObject head) {
try {
JSONObject head = model.jason.getJSONObject("$jason").getJSONObject("head");
if (head.has("agents")) {
final JSONObject agents = head.getJSONObject("agents");
Iterator<String> iterator = agents.keys();
Expand Down Expand Up @@ -383,7 +382,8 @@ private void onSwitchTab(String newUrl, String newParams, Intent intent) {
} else {
// build
model = m;
setup_agents();
JSONObject head = model.jason.getJSONObject("$jason").getJSONObject("head");
setup_agents(head);
setup_body(m.rendered);
}
} catch (Exception e) {
Expand Down Expand Up @@ -470,6 +470,12 @@ protected void onResume() {
}

if (!firstResume) {
try {
JSONObject head = model.jason.getJSONObject("$jason").getJSONObject("head");
setup_agents(head);
} catch (Exception e) {

}
onShow();
}
firstResume = false;
Expand Down Expand Up @@ -1434,7 +1440,7 @@ public void href(final JSONObject action, JSONObject data, JSONObject event, Con
// 1. call dispatchIntent
// 2. the intent will return with JasonCallback.href
JSONObject callback = new JSONObject();
callback.put("class", "JasonCallback");
callback.put("class", "com.jasonette.seed.Core.JasonCallback");
callback.put("method", "href");
JasonHelper.dispatchIntent(action, data, event, context, intent, callback);
}
Expand Down Expand Up @@ -1573,25 +1579,7 @@ public void build(JSONObject jason){
if (jason.getJSONObject("$jason").has("head")) {
final JSONObject head = jason.getJSONObject("$jason").getJSONObject("head");

if (head.has("agents")) {
final JSONObject agents = head.getJSONObject("agents");
Iterator<String> iterator = agents.keys();
while (iterator.hasNext()) {
final String key = iterator.next();
runOnUiThread(new Runnable() {
@Override
public void run() {
try {
JasonAgentService agentService = (JasonAgentService)((Launcher)getApplicationContext()).services.get("JasonAgentService");
WebView agent = agentService.setup(JasonViewActivity.this, agents.getJSONObject(key), key);
rootLayout.addView(agent);
} catch (JSONException e) {
}
}
});
}

}
setup_agents(head);

if (head.has("data")) {
if (head.has("templates")) {
Expand Down
20 changes: 19 additions & 1 deletion app/src/main/java/com/jasonette/seed/Launcher/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import okhttp3.OkHttpClient;
import com.jasonette.seed.BuildConfig;
import com.jasonette.seed.Service.key.JasonKeyService;
import com.jasonette.seed.Service.agent.JasonAgentService;
import com.jasonette.seed.Service.websocket.JasonWebsocketService;

Expand All @@ -42,6 +43,7 @@ public class Launcher extends Application {
public JSONObject services;
private static Context currentContext;


public void call(String serviceName, String methodName, JSONObject action, Context context) {
try {
Object service = services.get(serviceName);
Expand All @@ -51,6 +53,15 @@ public void call(String serviceName, String methodName, JSONObject action, Conte
Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString());
}
}
public void forward(String serviceName, String methodName, final JSONObject action, final JSONObject data, final JSONObject event, final Context context) {
try {
Object service = services.get(serviceName);
Method method = service.getClass().getMethod(methodName, action.getClass(), data.getClass(), event.getClass(), Context.class);
method.invoke(service, action, data, event, context);
} catch (Exception e) {
Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString());
}
}

// get current context from anywhere
public static Context getCurrentContext() {
Expand Down Expand Up @@ -147,9 +158,12 @@ public void onCreate() {
JasonWebsocketService websocketService = new JasonWebsocketService(this);
JasonAgentService agentService = new JasonAgentService();
services.put("JasonWebsocketService", websocketService);
JasonKeyService keyService = new JasonKeyService(this);
services.put("JasonKeyService", keyService);
services.put("JasonAgentService", agentService);



// handler init
handlers = new JSONObject();

Expand Down Expand Up @@ -256,7 +270,11 @@ public void trigger(JSONObject intent_to_resolve, JasonViewActivity context) {
}

String classname = handler.getString("class");
classname = "com.jasonette.seed.Action." + classname;
if (classname.startsWith("com.jasonette")) {
// absolute path. don't touch
} else {
classname = "com.jasonette.seed.Action." + classname;
}
String methodname = handler.getString("method");

Object module;
Expand Down
117 changes: 117 additions & 0 deletions app/src/main/java/com/jasonette/seed/Lib/PasscodeActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package com.jasonette.seed.Lib;

import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.hanks.passcodeview.PasscodeView;
import com.jasonette.seed.Launcher.Launcher;
import com.jasonette.seed.Service.key.JasonKeyService;

import org.json.JSONObject;


public class PasscodeActivity extends AppCompatActivity {
String mode;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

class PView extends PasscodeView {
public PView(Context context) {
super(context);
}
@Override protected Boolean equals(String psd) {
try {
if (mode.equalsIgnoreCase("authenticate")) {
JasonKeyService keyService = (JasonKeyService)((Launcher)PasscodeActivity.this.getApplicationContext()).services.get("JasonKeyService");
return keyService.is_authenticated(psd);
} else if (mode.equalsIgnoreCase("register")) {
return getLocalPasscode().equals(psd);
}
} catch (Exception e) {
}
return false;
}
}
/*
1. Does this view already have a password set?
=> YES: Ask for password
=> NO: Call password() to ask for password
*/

PView passcodeView = new PView(PasscodeActivity.this);

Intent intent = getIntent();
if (intent.hasExtra("mode")) {
mode = intent.getStringExtra("mode");
if (mode.equalsIgnoreCase("authenticate")) {
// Doesn't matter what it's set to because we'll use a custom "equals()" logic from above (PView)
passcodeView.setPasscodeLength(4).setLocalPasscode("0000");
} else if (mode.equalsIgnoreCase("register")) {

}
}

// 1. Get password for the current url
passcodeView.setBackgroundColor(Color.parseColor("#468af6"));
FrameLayout.LayoutParams layout = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT);
passcodeView.setLayoutParams(layout);
setContentView(passcodeView);

/**
Customize the view to get rid of unnecessary graphics that come with the library
**/
for(int i = 0; i < passcodeView.getChildCount(); i++) {
View child = passcodeView.getChildAt(i);
if (child.getClass().equals(LinearLayout.class)) {
int index = 0;
for (int j=0; j<((LinearLayout)child).getChildCount(); j++) {
View grandchild = ((LinearLayout)child).getChildAt(j);
if (grandchild.getClass().equals(RelativeLayout.class)) {
index++;
if (index == 2) {
grandchild.setBackgroundColor(Color.WHITE);
break;
}
}
}
}
}


passcodeView.setListener(new PasscodeView.PasscodeViewListener() {
@Override
public void onFail() {

}

@Override
public void onSuccess(String number) {
// Set return intent with extras
try {
JasonKeyService keyService = (JasonKeyService)((Launcher)PasscodeActivity.this.getApplicationContext()).services.get("JasonKeyService");
if (mode.equalsIgnoreCase("register")) {
keyService.register(number);
}
Toast.makeText(getApplication(),"Success",Toast.LENGTH_SHORT).show();
} catch (Exception e) {

}
Intent intent = new Intent();
setResult(RESULT_OK, intent);
finish();
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ public void onFinished(JSONObject reduced_action) {
return false;
} else {
Intent intent = new Intent("call");
intent.putExtra("action", options.get("action").toString());
intent.putExtra("action", parsed.toString());
intent.putExtra("data", "{\"url\": \"" + url + "\"}");
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
return true;
Expand Down
Loading