Skip to content
Snippets Groups Projects
Commit 70cedc20 authored by Maxime Graulich's avatar Maxime Graulich
Browse files

Android: Open the link associate to a model in a browser

parent 499f2ff3
No related branches found
No related tags found
No related merge requests found
......@@ -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);
......
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;
}
}
......@@ -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);
......
......@@ -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 {
......
......@@ -80,7 +80,7 @@ public class OptionsFragment extends Fragment{
});
return rootView;
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment