Enable running JS from debug interface
This commit is contained in:
parent
5e25ebe083
commit
65f5308854
@ -52,8 +52,18 @@
|
|||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="fill_parent"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
|
android:imeActionLabel="@string/debug_run"
|
||||||
android:imeOptions="actionGo"
|
android:imeOptions="actionGo"
|
||||||
android:inputType="textNoSuggestions"/>
|
android:inputType="textMultiLine|textNoSuggestions"
|
||||||
|
android:lines="1"/>
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
android:background="@android:color/transparent"
|
||||||
|
android:contentDescription="@string/debug_run"
|
||||||
|
android:onClick="onBtnRunCodeClick"
|
||||||
|
android:src="@android:drawable/ic_menu_send"/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
<string name="app_name">IITC Mobile</string>
|
<string name="app_name">IITC Mobile</string>
|
||||||
<string name="toggle_map">Toggle map visibility</string>
|
<string name="toggle_map">Toggle map visibility</string>
|
||||||
|
<string name="debug_run">Run</string>
|
||||||
<string name="activity_settings">IITC Mobile Settings</string>
|
<string name="activity_settings">IITC Mobile Settings</string>
|
||||||
<string name="activity_plugins">IITC Plugins</string>
|
<string name="activity_plugins">IITC Plugins</string>
|
||||||
<string name="activity_share">Share using…</string>
|
<string name="activity_share">Share using…</string>
|
||||||
|
@ -18,20 +18,27 @@ import android.os.Bundle;
|
|||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.KeyEvent;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
|
import android.view.inputmethod.EditorInfo;
|
||||||
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.webkit.CookieManager;
|
import android.webkit.CookieManager;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.SearchView;
|
import android.widget.SearchView;
|
||||||
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.cradle.iitc_mobile.IITC_NavigationHelper.Pane;
|
import com.cradle.iitc_mobile.IITC_NavigationHelper.Pane;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
@ -89,6 +96,20 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
|||||||
mViewDebug = findViewById(R.id.viewDebug);
|
mViewDebug = findViewById(R.id.viewDebug);
|
||||||
mBtnToggleMap = (ImageButton) findViewById(R.id.btnToggleMapVisibility);
|
mBtnToggleMap = (ImageButton) findViewById(R.id.btnToggleMapVisibility);
|
||||||
mEditCommand = (EditText) findViewById(R.id.editCommand);
|
mEditCommand = (EditText) findViewById(R.id.editCommand);
|
||||||
|
mEditCommand.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||||
|
if (EditorInfo.IME_ACTION_GO == actionId) {
|
||||||
|
onBtnRunCodeClick(v);
|
||||||
|
|
||||||
|
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
|
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
mLvDebug.setAdapter(new IITC_LogAdapter(this));
|
mLvDebug.setAdapter(new IITC_LogAdapter(this));
|
||||||
|
|
||||||
@ -654,6 +675,26 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onBtnRunCodeClick(View v) {
|
||||||
|
String code = mEditCommand.getText().toString();
|
||||||
|
JSONObject obj = new JSONObject();
|
||||||
|
try {
|
||||||
|
obj.put("code", code);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// throwing an exception will be reported by WebView
|
||||||
|
String js = "(function(obj){var result;" +
|
||||||
|
"console.log('>>> ' + obj.code);" +
|
||||||
|
"try{result=eval(obj.code);}catch(e){if(e.stack) console.error(e.stack);throw e;}" +
|
||||||
|
"if(result!==undefined) console.log(result.toString());" +
|
||||||
|
"})(" + obj.toString() + ");";
|
||||||
|
|
||||||
|
mIitcWebView.loadJS(js);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* onClick handler for R.id.btnToggleMapVisibility, assigned in activity_main.xml
|
* onClick handler for R.id.btnToggleMapVisibility, assigned in activity_main.xml
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user