diff --git a/contrib/mobile/Android/src/org/geuz/onelab/MainActivity.java b/contrib/mobile/Android/src/org/geuz/onelab/MainActivity.java index 79e945052c249dfe31ffbf89890e9e5800bd1769..7b93f7e320ea62031a8cc5cf9989dc5f1f70df26 100644 --- a/contrib/mobile/Android/src/org/geuz/onelab/MainActivity.java +++ b/contrib/mobile/Android/src/org/geuz/onelab/MainActivity.java @@ -50,7 +50,6 @@ public class MainActivity extends Activity implements OptionsDisplayFragment.OnO _gmsh.load(tmp); } else if(extras != null) { - //extras.getInt("model"); //extras.getString("name"); String tmp = extras.getString("file"); _gmsh.load(tmp); diff --git a/contrib/mobile/Android/src/org/geuz/onelab/Model.java b/contrib/mobile/Android/src/org/geuz/onelab/Model.java index 168936c19f1a3b0e9e125441fa55f27019de2ad6..8b1b1bc39d93529b83ce2ae59a0335191728ae35 100644 --- a/contrib/mobile/Android/src/org/geuz/onelab/Model.java +++ b/contrib/mobile/Android/src/org/geuz/onelab/Model.java @@ -1,6 +1,7 @@ package org.geuz.onelab; import java.io.File; +import android.net.Uri; import android.graphics.Bitmap; import android.graphics.BitmapFactory; @@ -10,6 +11,7 @@ class Model { private String _name, _summary; private File _file; private Bitmap _bitmap; + private Uri _url; public Model(String name, String summary, File file){ _name = name; @@ -28,7 +30,13 @@ class Model { public Bitmap getBitmap() { return _bitmap; } + public Uri getUrl() { + return _url; + } public void setBitmap(File f) { _bitmap = BitmapFactory.decodeFile(f.toString()); } + public void setUrl(Uri url) { + _url = url; + } } diff --git a/contrib/mobile/Android/src/org/geuz/onelab/ModelArrayAdapter.java b/contrib/mobile/Android/src/org/geuz/onelab/ModelArrayAdapter.java index 3e8f3615959037a2d06d5cc169abc984bc7a8fb4..3bc86f88d9c6157d822fa4861fe91080c693afec 100644 --- a/contrib/mobile/Android/src/org/geuz/onelab/ModelArrayAdapter.java +++ b/contrib/mobile/Android/src/org/geuz/onelab/ModelArrayAdapter.java @@ -30,17 +30,16 @@ public class ModelArrayAdapter extends ArrayAdapter<Model> { } @Override - public View getView(int position, View convertView, ViewGroup parent) { - LayoutInflater inflater = (LayoutInflater) parent.getContext() - .getSystemService(Context.LAYOUT_INFLATER_SERVICE); - + public View getView(int position, View convertView, final ViewGroup parent) { + LayoutInflater inflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); + final Model m = _models.get(position); View rowView = inflater.inflate(R.layout.model, parent, false); TextView title = (TextView) rowView.findViewById(R.id.title); TextView description = (TextView) rowView.findViewById(R.id.description); ImageView icon = (ImageView) rowView.findViewById(R.id.icon); - if(_models.get(position).getName() != null) title.setText(_models.get(position).getName()); - if(_models.get(position).getSummary() != null) description.setText(_models.get(position).getSummary()); - if(_models.get(position).getBitmap() != null) icon.setImageBitmap(_models.get(position).getBitmap()); + if(m.getName() != null) title.setText(m.getName()); + if(m.getSummary() != null) description.setText(m.getSummary()); + if(m.getBitmap() != null) icon.setImageBitmap(m.getBitmap()); else icon.setImageResource(R.drawable.ic_launcher); icon.setPadding(10, 10, 10, 10); diff --git a/contrib/mobile/Android/src/org/geuz/onelab/ModelList.java b/contrib/mobile/Android/src/org/geuz/onelab/ModelList.java index bb7ed63338966ef5406b4a093a747f5b7772f4a7..213a6bdfc384408a2f6631fb4cacf614de522710 100644 --- a/contrib/mobile/Android/src/org/geuz/onelab/ModelList.java +++ b/contrib/mobile/Android/src/org/geuz/onelab/ModelList.java @@ -16,6 +16,7 @@ import android.app.DialogFragment; import android.content.DialogInterface; import android.content.Intent; import android.graphics.Color; +import android.net.Uri; import android.os.Bundle; import android.os.Environment; import android.util.Xml; @@ -25,7 +26,6 @@ import android.widget.AdapterView; import android.widget.Button; import android.widget.LinearLayout; import android.widget.ListView; -import android.widget.AdapterView.OnItemClickListener; public class ModelList extends Activity { @@ -58,18 +58,55 @@ public class ModelList extends Activity { }); //TODO list.addFooterView(loadSD); list.setAdapter(_modelArrayAdapter); - list.setOnItemClickListener(new OnItemClickListener() { + list.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Model m = _modelArrayAdapter.getModel(position); Intent intent = new Intent(ModelList.this, MainActivity.class); - intent.putExtra("model", position); - intent.putExtra("file", m.getFile()); + intent.putExtra("file", m.getFile().toString()); intent.putExtra("name", m.getName()); startActivity(intent); } }); + list.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { + + public boolean onItemLongClick(AdapterView<?> parent, View view, + int position, long id) { + final Model m = _modelArrayAdapter.getModel(position); + CharSequence[] actions; + if(m.getUrl() != null) { + actions = new CharSequence[2]; + actions[0] = "Open this model"; + actions[1] = "More informations"; + } + else { + actions = new CharSequence[1]; + actions[0] = "Open this model"; + } + AlertDialog.Builder builder = new AlertDialog.Builder(parent.getContext()); + builder.setTitle(m.getName()); + builder.setItems(actions, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int position) { + switch (position) { + case 1: + Intent browserIntent = new Intent(Intent.ACTION_VIEW, m.getUrl()); + startActivity(browserIntent); + break; + default: + Intent intent = new Intent(ModelList.this, MainActivity.class); + intent.putExtra("file", m.getFile().toString()); + intent.putExtra("name", m.getName()); + startActivity(intent); + break; + } + } + }); + AlertDialog alert = builder.create(); + alert.show(); + return true; + } + }); layout.addView(list); this.setContentView(layout); layout.setPadding(15, 10, 10, 5); @@ -112,6 +149,7 @@ public class ModelList extends Activity { String summary = null; String file = null; String bitmap = null; + String url = null; while (parser.next() != XmlPullParser.END_TAG) { if (parser.getEventType() != XmlPullParser.START_TAG) continue; String name = parser.getName(); @@ -140,12 +178,19 @@ public class ModelList extends Activity { parser.nextTag(); } } + else if(name.equals("url")) { + if (parser.next() == XmlPullParser.TEXT) { + url = parser.getText(); + parser.nextTag(); + } + } else { skipTag(parser); } } Model newModel = new Model(title, summary, new File(dir+"/"+file)); if(bitmap != null) newModel.setBitmap(new File(dir+"/"+bitmap)); + if(url != null) newModel.setUrl(Uri.parse(url)); _modelArrayAdapter.add(newModel); } private void skipTag(XmlPullParser parser) throws XmlPullParserException, IOException { diff --git a/contrib/mobile/Android/src/org/geuz/onelab/OptionsFragment.java b/contrib/mobile/Android/src/org/geuz/onelab/OptionsFragment.java index f3aca46baad53ac8c0e567cbec099cb927394a89..496f3dbb9e52ac42dbf511b8e53168dad31dfa52 100644 --- a/contrib/mobile/Android/src/org/geuz/onelab/OptionsFragment.java +++ b/contrib/mobile/Android/src/org/geuz/onelab/OptionsFragment.java @@ -80,7 +80,7 @@ public class OptionsFragment extends Fragment{ }); return rootView; } - + @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState);