-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
F43nd1r
committed
Feb 13, 2016
1 parent
0811d86
commit d6d1cf4
Showing
7 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |