1 package jarmos.app.activity;
8 import java.lang.reflect.Method;
9 import java.net.MalformedURLException;
12 import android.app.Activity;
13 import android.app.AlertDialog;
14 import android.app.Dialog;
15 import android.content.DialogInterface;
16 import android.content.Intent;
17 import android.content.SharedPreferences;
18 import android.os.Bundle;
19 import android.util.Log;
20 import android.view.Menu;
21 import android.view.MenuInflater;
22 import android.view.MenuItem;
23 import android.view.View;
24 import android.widget.Button;
25 import android.widget.EditText;
26 import android.widget.Toast;
61 private Dialog downloadDialog;
65 public void onCreate(Bundle savedInstanceState) {
66 super.onCreate(savedInstanceState);
67 setContentView(
R.layout.mainpage);
69 Const.APP_DATA_DIRECTORY = getApplicationInfo().dataDir +
"/files";
74 Button btn = (Button) findViewById(
R.id.btnAssets);
75 btn.setOnClickListener(
new View.OnClickListener() {
76 public void onClick(View view) {
80 startActivityForResult(intent, 0);
83 btn = (Button) findViewById(
R.id.btnSDCard);
84 btn.setOnClickListener(
new View.OnClickListener() {
85 public void onClick(View view) {
94 startActivityForResult(intent, 0);
97 Button ibtn = (Button) findViewById(
R.id.btnDownload);
98 ibtn.setOnClickListener(
new View.OnClickListener() {
99 public void onClick(View view) {
108 AlertDialog.Builder builder =
new AlertDialog.Builder(
this);
111 downloadDialog =
new Dialog(
this);
112 downloadDialog.setContentView(R.layout.download_dialog);
113 downloadDialog.setTitle(
"Connect to server");
114 downloadDialog.setCancelable(
false);
118 Button downloadButton = (Button) downloadDialog.findViewById(
R.id.downloadButton);
119 downloadButton.setOnClickListener(
new View.OnClickListener() {
121 public void onClick(View view) {
124 EditText urlEntry = (EditText) downloadDialog.findViewById(
R.id.urlEntry);
130 u =
new URL(urlEntry.getText().toString().trim());
131 }
catch (MalformedURLException e) {
132 Toast.makeText(MainActivity.this, R.string.invalidURL, Toast.LENGTH_SHORT);
141 intent.putExtra(
"URL", u);
142 intent.putExtra(
"modelCaching",
true);
144 startActivityForResult(intent, 0);
149 Button quitDownloadButton = (Button) downloadDialog.findViewById(
R.id.quitDownloadButton);
150 quitDownloadButton.setOnClickListener(
new View.OnClickListener() {
152 public void onClick(View view) {
158 dialog = downloadDialog;
161 builder.setMessage(
"Could not ensure rbappmit-SDcard folder.").setCancelable(
false)
162 .setNeutralButton(
"OK",
new DialogInterface.OnClickListener() {
163 public void onClick(DialogInterface dialog,
int id) {
167 dialog = builder.create();
174 builder =
new AlertDialog.Builder(MainActivity.this);
175 builder.setTitle(
"JaRMoSA options");
176 builder.setMultiChoiceItems(
new String[] {
"Enable model caching",
"Overwrite existing models" }, bools,
177 new DialogInterface.OnMultiChoiceClickListener() {
178 public void onClick(DialogInterface dialog,
int item,
boolean checked) {
186 builder.setNeutralButton(
"OK",
new DialogInterface.OnClickListener() {
187 public void onClick(DialogInterface dialog,
int item) {
191 dialog = builder.create();
207 if (item.getItemId() == R.id.mm_settings) {
211 return super.onMenuItemSelected(featureId, item);
219 MenuInflater inflater = getMenuInflater();
220 inflater.inflate(R.menu.main_menu, menu);
224 @SuppressWarnings(
"unused")
225 private
void testwas() {
228 m.useModel(
"aghdemo");
230 ClassLoader cl = m.getClassLoader();
231 Class<?> c = cl.loadClass(
"AffineFunctions");
232 c = cl.loadClass(
"AffineFunctions");
234 Object ci = c.newInstance();
237 Method meth = c.getMethod(
"get_n_F_functions");
238 Object res = meth.invoke(ci);
240 System.out.println(
"a=" + a);
243 ClassLoader cl2 = m.getClassLoader();
245 c = cl.loadClass(
"AffineFunctions");
246 ci = c.newInstance();
247 res = meth.invoke(ci);
249 System.out.println(
"a=" + a);
251 c = cl2.loadClass(
"AffineFunctions");
252 meth = c.getMethod(
"get_n_F_functions");
253 ci = c.newInstance();
254 res = meth.invoke(ci);
256 System.out.println(
"a=" + a);
258 }
catch (Exception e) {
259 Log.e(
"testwas",
"DOOMED!", e);
static final String PREF_MODELCACHING
The name for the preference storing information about whether models should be cached when loaded fro...
Class for model loading from the local SD card of the mobile device running android.
static final String PREFERENCES_FILENAME
The filename for the application preferences.
This is the main activity class and entry point of the app.
Class to load models from application assets.
void onCreate(Bundle savedInstanceState)
Called when the activity is first created.
boolean onMenuItemSelected(int featureId, MenuItem item)
This activity generates a simple ListView to allow selection of a model.
boolean onPrepareOptionsMenu(Menu menu)
static final String EXTRA_MODELMANAGER_CLASSNAME
The string describing the class name which denotes the corret AModelManager subclass to be instantiat...
static boolean ensureSDDir()
static final int NO_SD_ID
Dialog ID for the "no sd card access" dialog.
static final int DOWNLOAD_DIALOG_ID
Dialog ID for the model download url dialog.
Dialog onCreateDialog(int id)
Class that contains miscellaneous JaRMoS specific constants and static functions. ...
static final String PREF_MODELCACHING_OVERWRITE
The name for the preference storing information about whether existing model data is overwritten when...
static final int OPTIONS_ID
Options dialog ID.