Back to project page frc-notebook.
The source code is released under:
GNU General Public License
If you think the Android project frc-notebook listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.plnyyanks.frcnotebook.activities; /* w w w . ja v a 2 s . co m*/ import android.app.ActionBar; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.os.Environment; import android.provider.MediaStore; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.ArrayAdapter; import android.widget.ProgressBar; import android.widget.Toast; import com.plnyyanks.frcnotebook.Constants; import com.plnyyanks.frcnotebook.R; import com.plnyyanks.frcnotebook.background.ShowLocalEvents; import com.plnyyanks.frcnotebook.database.DatabaseHandler; import com.plnyyanks.frcnotebook.database.PreferenceHandler; import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; /** * File created by phil on 3/1/14. * Copyright 2014, Phil Lopreiato * This file is part of FRC Notebook. * FRC Notebook is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * FRC Notebook is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. * You should have received a copy of the GNU General Public License along with FRC Notebook. If not, see http://www.gnu.org/licenses/. */ public class StartActivity extends Activity implements ActionBar.OnNavigationListener { private static final String STATE_SELECTED_NAVIGATION_ITEM = "selected_navigation_item"; public static Context startActivityContext; public static Activity activity; public static DatabaseHandler db; private static int currentTheme; static final int REQUEST_TAKE_PHOTO = 1; @Override protected void onCreate(Bundle savedInstanceState) { startActivityContext = this; activity = this; setTheme(PreferenceHandler.getTheme()); super.onCreate(savedInstanceState); setContentView(R.layout.activity_start); /*if (savedInstanceState == null) { getFragmentManager().beginTransaction() .commit(); }*/ getdb(); PreferenceHandler.setAppVersion(this); //configure action bar to show drop down navigation final ActionBar bar = getActionBar(); bar.setDisplayShowTitleEnabled(false); bar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); final String[] navigationValues = getResources().getStringArray(R.array.event_list_navi_options); //create an adapter for the spinner ArrayAdapter<String> adapter = new ArrayAdapter<String>(bar.getThemedContext(), android.R.layout.simple_spinner_item,android.R.id.text1,navigationValues); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); bar.setListNavigationCallbacks(adapter,this); if(savedInstanceState!=null) { bar.setSelectedNavigationItem(savedInstanceState.getInt(STATE_SELECTED_NAVIGATION_ITEM,0)); }else{ bar.setSelectedNavigationItem(0); } new ShowLocalEvents(bar.getSelectedNavigationIndex()).execute(this); } @Override protected void onResume() { checkThemeChanged(StartActivity.class); new ShowLocalEvents(getActionBar().getSelectedNavigationIndex()).execute(this); super.onResume(); } @Override public void onRestoreInstanceState(Bundle savedInstanceState) { // Restore the previously serialized current dropdown position. if (savedInstanceState.containsKey(STATE_SELECTED_NAVIGATION_ITEM)) { try{ getActionBar().setSelectedNavigationItem(savedInstanceState.getInt(STATE_SELECTED_NAVIGATION_ITEM)); }catch(IllegalStateException e){ Log.w(Constants.LOG_TAG, "Failed restoring action bar navegition state on resume. Oh well..."); } } } @Override public void onSaveInstanceState(Bundle outState) { // Serialize the current dropdown position. outState.putInt(STATE_SELECTED_NAVIGATION_ITEM, getActionBar() .getSelectedNavigationIndex()); } public void openDownloader(View view){ Intent intent = new Intent(this, EventDownloadActivity.class); startActivity(intent); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.start, menu); return true; } public void takePicture(){ Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(getPackageManager()) != null) { // Create the File where the photo should go File photoFile = null; try { photoFile = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File ///... } // Continue only if the File was successfully created if (photoFile != null) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(photoFile)); startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO); } } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Toast.makeText(this,"moo",Toast.LENGTH_SHORT); } private File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "JPEG_" + timeStamp + "_"; File storageDir = this.getExternalFilesDir(null); File image = File.createTempFile( imageFileName, /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents //mCurrentPhotoPath = "file:" + image.getAbsolutePath(); return image; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); switch(item.getItemId()) { case R.id.action_settings: Intent intent = new Intent(this, SettingsActivity.class); startActivity(intent); return false; case R.id.action_download_event: openDownloader(null); return false; case R.id.action_create_evnet: startActivity(new Intent(this, AddEvent.class)); return false; default: return super.onOptionsItemSelected(item); } } public DatabaseHandler getdb(){ if(db == null) db = new DatabaseHandler(this); return db; } public void closedb(){ if(db != null) db.close(); } public static void checkThemeChanged(Class<?> cls){ if(currentTheme != PreferenceHandler.getTheme() && startActivityContext != null){ currentTheme = PreferenceHandler.getTheme(); Intent intent = new Intent(startActivityContext, cls); startActivityContext.startActivity(intent); }else{ currentTheme = PreferenceHandler.getTheme(); } } @Override public boolean onNavigationItemSelected(int i, long l) { //show the progress bar while we load events ProgressBar prog = (ProgressBar) findViewById(R.id.event_list_loading_progress); prog.setVisibility(View.VISIBLE); new ShowLocalEvents(i).execute(this); return false; } }