Skip to content
Snippets Groups Projects
Commit 1f81238f authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

removed manual opening of geo/pro files; added ability to import full model (zip) archives

parent 311723f6
No related branches found
No related tags found
No related merge requests found
......@@ -22,34 +22,33 @@
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ModelList"
android:label="@string/title_activity_main" />
<activity android:name=".AboutActivity"
android:label="@string/title_activity_about" />
<activity android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file"
android:host="*"
android:pathPattern=".*\\.msh"
android:mimeType="*/*" />
<data android:scheme="file"
android:host="*"
android:pathPattern=".*\\.geo"
android:mimeType="*/*" />
<data android:scheme="file"
android:host="*"
android:pathPattern=".*\\.pro"
android:mimeType="*/*" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file" />
<data android:mimeType="application/zip" />
<data android:pathPattern=".*\\.zip" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="content" />
<data android:mimeType="application/zip" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"
android:label="@string/title_activity_main"/>
<activity android:name=".ModelList"
android:label="@string/title_activity_main"/>
<activity android:name=".AboutActivity"
android:label="@string/title_activity_about"/>
<activity android:name=".PostProcessingActivity"
android:label="@string/title_activity_main"/>
<activity android:name=".OptionsActivity"
android:label="@string/title_activity_options" />
android:label="@string/title_activity_options">
</activity>
</application>
</manifest>
......@@ -6,8 +6,8 @@
<ImageView
android:id="@+id/icon"
android:layout_height="100dp"
android:layout_width="100dp"
android:layout_height="64dp"
android:layout_width="64dp"
android:layout_gravity="center"
android:contentDescription="preview"
android:src="@drawable/ic_launcher"
......
<resources>
<string name="app_name">Onelab</string>
<string name="button_open_file">Open file</string>
<string name="button_ok">OK</string>
<string name="button_recalculate_param">Recompute with new parameters</string>
<string name="dialog_title_choosefile">Choose a file</string>
<string name="error_nosdcard">No SDcard found on your device</string>
<string name="title_activity_main">Onelab</string>
<string name="title_activity_about">About</string>
<string name="title_activity_options">Parameters</string>
<string name="error_nomshfile">No compatible files or directories in this folder</string>
<string name="title_share">Share screenshot with &#8230;</string>
<string name="menu_share">Share screenshot</string>
<string name="menu_parameters">Parameters</string>
......
......@@ -57,13 +57,11 @@ public class MainActivity extends Activity{
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#64000000")));
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if(savedInstanceState != null);
else if(intent.getAction() != null &&
intent.getAction().equals(Intent.ACTION_VIEW)) {
String tmp = intent.getData().getPath();
_gmsh.load(tmp);
if(savedInstanceState != null){
// nothing
}
else if(extras != null) {
// request to load a file (from ModelList)
String name = extras.getString("name");
this.getActionBar().setTitle(name);
String tmp = extras.getString("file");
......
......@@ -26,6 +26,7 @@ import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Toast;
import android.util.Log;
public class ModelList extends Activity {
......@@ -35,6 +36,7 @@ public class ModelList extends Activity {
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
_modelArrayAdapter = new ModelArrayAdapter(this);
try {
this.getModels();
......@@ -108,28 +110,13 @@ public class ModelList extends Activity {
MenuItem about = menu.add("About");
about.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
// FIXME: should we keep this, only accept .zip files, and call it "import model" ?
//MenuItem loadFile = menu.add(R.string.button_open_file);
//loadFile.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item)
{
if(item.getTitle().equals(getString(R.string.button_open_file))) {
Intent fileBrowserIntent = new Intent();
fileBrowserIntent.setAction(Intent.ACTION_GET_CONTENT);
fileBrowserIntent.setType("file/*");
try {
startActivityForResult(fileBrowserIntent, 1);
}
catch(ActivityNotFoundException e) {
Toast.makeText(this, "No application found on your device to open the files.",
Toast.LENGTH_LONG).show();
}
}
else if(item.getTitle().equals("About")) {
if(item.getTitle().equals("About")) {
Intent intent = new Intent(ModelList.this, AboutActivity.class);
startActivity(intent);
}
......
package org.geuz.onelab;
import java.io.InputStream;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
......@@ -11,31 +12,18 @@ import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.ContentResolver;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
public class SplashScreen extends Activity{
private static final int SPLASHTIME = 1000; // duration for the splash screen in milliseconds
private static final int STOPSPLASH = 0;
private static final int EXITAPP = 1;
private Intent newIntent;
private final Handler handler = new Handler() {
public void handleMessage(Message msg) {
switch (msg.what) {
case STOPSPLASH:
startActivity(newIntent);
Intent i = new Intent(SplashScreen.this, ModelList.class);
startActivity(i);
finish();
break;
case EXITAPP:
finish();
break;
default:
break;
}
};
};
......@@ -43,15 +31,8 @@ public class SplashScreen extends Activity{
{
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Intent oldIntent = this.getIntent();
if(oldIntent != null && oldIntent.getAction() != null &&
oldIntent.getAction().equals(Intent.ACTION_VIEW)){
newIntent = new Intent(SplashScreen.this, MainActivity.class);
newIntent.setAction(oldIntent.getAction());
newIntent.setData(oldIntent.getData());
}
else
newIntent = new Intent(SplashScreen.this, ModelList.class);
// import built-in models
SharedPreferences sharedPref = getSharedPreferences(getPackageName(), Context.MODE_PRIVATE);
int codev = 0;
try {
......@@ -65,22 +46,37 @@ public class SplashScreen extends Activity{
SharedPreferences.Editor editor = sharedPref.edit();
editor.putInt("OnelabModelsVersion", codev);
editor.commit();
loadNative();
// import built-in models from from res/raw/
ImportZipArchive(new BufferedInputStream(getResources().openRawResource(R.raw.models)));
}
else{
Log.d("Models", "Leaving models as-is (version "+modelsv+")");
}
else Log.d("Models", "Leaving models as-is (version "+modelsv+")");
// import user model
Intent intent = getIntent();
String action = intent.getAction();
if(action != null && action.equals(Intent.ACTION_VIEW)) {
Log.d("Models", "Importing user model " + intent.getData());
try {
ImportZipArchive(getContentResolver().openInputStream(intent.getData()));
}
catch(IOException e1) {
e1.printStackTrace();
}
}
final Message msg = new Message();
msg.what = STOPSPLASH;
handler.sendMessageDelayed(msg, SPLASHTIME);
handler.sendMessageDelayed(msg, 500); // 500 milliseconds
}
/**
* Load file from res/raw/ directory to the files directory of the application.
* Uncompress zip archive into the files directory of the application.
*/
private void loadNative()
private void ImportZipArchive(InputStream stream)
{
try {
ZipInputStream zipStream = new ZipInputStream
(new BufferedInputStream(getResources().openRawResource(R.raw.models)));
ZipInputStream zipStream = new ZipInputStream(stream);
ZipEntry entry;
while ((entry = zipStream.getNextEntry()) != null) {
String name = entry.getName();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment