\r
import net.sf.openrocket.R;\r
import net.sf.openrocket.android.filebrowser.SimpleFileBrowser;\r
-import net.sf.openrocket.android.motor.MotorHierarchicalBrowser;\r
-import android.app.Activity;\r
import android.content.ActivityNotFoundException;\r
import android.content.Intent;\r
+import android.content.SharedPreferences;\r
+import android.content.res.Resources;\r
import android.net.Uri;\r
import android.os.Bundle;\r
+import android.preference.PreferenceManager;\r
import android.view.View;\r
+import android.widget.Button;\r
\r
-public class Main extends Activity {\r
+import com.actionbarsherlock.app.SherlockFragmentActivity;\r
+import com.actionbarsherlock.view.Menu;\r
+import com.actionbarsherlock.view.MenuInflater;\r
+import com.actionbarsherlock.view.MenuItem;\r
+\r
+public class Main extends SherlockFragmentActivity {\r
\r
private static final int PICK_ORK_FILE_RESULT = 1;\r
\r
@Override\r
public void onCreate(Bundle icicle) {\r
super.onCreate(icicle);\r
+ setTitle("");\r
setContentView(R.layout.main);\r
+ ((Button) findViewById(R.id.main_open)).setOnClickListener(\r
+ new View.OnClickListener() {\r
+ @Override\r
+ public void onClick(View v) {\r
+ Main.this.pickOrkFiles();\r
+ }\r
+ });\r
+ ((Button) findViewById(R.id.main_browse)).setOnClickListener(\r
+ new View.OnClickListener() {\r
+ @Override\r
+ public void onClick(View v) {\r
+ ActivityHelpers.browseMotors(Main.this);\r
+ }\r
+ });\r
+ ((Button) findViewById(R.id.main_donate)).setOnClickListener(\r
+ new View.OnClickListener() {\r
+ @Override\r
+ public void onClick(View v) {\r
+ ActivityHelpers.donate(Main.this);\r
+ }\r
+ });\r
+ }\r
+\r
+ @Override\r
+ public boolean onCreateOptionsMenu(Menu menu) {\r
+ MenuInflater inflater = getSupportMenuInflater();\r
+ inflater.inflate(R.menu.main_menu, menu);\r
+ return true;\r
+ }\r
+\r
+ @Override\r
+ public boolean onOptionsItemSelected(MenuItem item) {\r
+ switch( item.getItemId() ) {\r
+ case R.id.main_menu_preferences:\r
+ ActivityHelpers.startPreferences(this);\r
+ return true;\r
+ case R.id.menu_about:\r
+ ActivityHelpers.showAbout(this);\r
+ return true;\r
+ }\r
+ return super.onOptionsItemSelected(item);\r
}\r
\r
/* (non-Javadoc)\r
super.onActivityResult(requestCode, resultCode, data);\r
}\r
\r
- public void pickOrkFiles( View v ) {\r
- try {\r
- Intent intent = new Intent(Intent.ACTION_GET_CONTENT);\r
- intent.setType("file/*");\r
- startActivityForResult(intent,PICK_ORK_FILE_RESULT);\r
- } catch ( ActivityNotFoundException ex ) { \r
- // No activity for ACTION_GET_CONTENT use internal file browser\r
+ private void pickOrkFiles( ) {\r
+ Resources resources = this.getResources();\r
+ String key = resources.getString(R.string.PreferenceUseInternalFileBrowserOption);\r
+ SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);\r
+\r
+ boolean useinternalbrowser = pref.getBoolean(key, false);\r
+\r
+ if ( useinternalbrowser ) {\r
Intent intent = new Intent(Main.this, SimpleFileBrowser.class);\r
startActivityForResult(intent,PICK_ORK_FILE_RESULT);\r
- }\r
+ } else {\r
+ try {\r
+ Intent intent = new Intent(Intent.ACTION_GET_CONTENT);\r
+ intent.setType("file/*");\r
+ startActivityForResult(intent,PICK_ORK_FILE_RESULT);\r
+ } catch ( ActivityNotFoundException ex ) { \r
+ // No activity for ACTION_GET_CONTENT use internal file browser\r
+ // update the preference value.\r
+ pref.edit().putBoolean(key, false).commit();\r
+ // fire our browser\r
+ Intent intent = new Intent(Main.this, SimpleFileBrowser.class);\r
+ startActivityForResult(intent,PICK_ORK_FILE_RESULT);\r
+ }\r
+ } \r
+ }\r
+ public void pickOrkFiles( View v ) {\r
+ pickOrkFiles();\r
}\r
\r
public void browseMotors( View v ) {\r
- Intent i = new Intent(Main.this, MotorHierarchicalBrowser.class);\r
- startActivity(i);\r
+ ActivityHelpers.browseMotors(this);\r
}\r
\r
}\r