Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
F43nd1r committed Feb 13, 2016
1 parent 0811d86 commit d6d1cf4
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.faendir.rhinotest">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_rhino"
android:label="@string/app_name"
android:supportsRtl="true">
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

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

</manifest>
43 changes: 43 additions & 0 deletions src/main/java/com/faendir/rhinotest/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.faendir.rhinotest;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.faendir.rhino_android.RhinoAndroidHelper;

import org.mozilla.javascript.Context;
import org.mozilla.javascript.ImporterTopLevel;
import org.mozilla.javascript.Scriptable;

public class MainActivity extends Activity {

private Context context;
private Scriptable scope;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_main);

context = RhinoAndroidHelper.prepareContext();
context.setOptimizationLevel(1);
scope = new ImporterTopLevel(context);
}

private void toastScript( String script) {
try {
Object result = context.evaluateString(scope, script, "<hello_world>", 1, null);
Toast.makeText(this, Context.toString(result), Toast.LENGTH_LONG).show();
} catch (Throwable t) {
t.printStackTrace();
}
}

public void button(View v){
toastScript(((EditText)findViewById(R.id.editText)).getText().toString());
}

}
39 changes: 39 additions & 0 deletions src/main/res/layout/content_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.faendir.rhinotest.MainActivity">

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_toast"
android:id="@+id/button"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:onClick="button"/>

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:ems="10"
android:id="@+id/editText"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_above="@+id/button"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:gravity="start"/>

</RelativeLayout>
Binary file added src/main/res/mipmap-xxxhdpi/ic_rhino.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions src/main/res/values-w820dp/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<resources>
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
(such as screen margins) for screens with more than 820dp of available width. This
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
<dimen name="activity_horizontal_margin">64dp</dimen>
</resources>
5 changes: 5 additions & 0 deletions src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>
5 changes: 5 additions & 0 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<resources>
<string name="app_name">RhinoTest</string>
<string name="title_activity_main">MainActivity</string>
<string name="button_toast">Toast</string>
</resources>

0 comments on commit d6d1cf4

Please sign in to comment.