Java tutorial
package com.normalexception.neobd; /************************************************************************ * NormalException.net Software, and other contributors * http://www.normalexception.net * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ************************************************************************/ import android.app.ActionBar; import android.content.Context; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import com.normalexception.neobd.db.NEODatabase; import com.normalexception.neobd.tabs.DTCTab; import com.normalexception.neobd.tabs.OBDTab; import com.normalexception.neobd.tabs.TabListener; import com.normalexception.neobd.tabs.WelcomeTab; public class NeobdActivity extends FragmentActivity { // Control for which item was selected private static final String STATE_SELECTED_NAVIGATION_ITEM = "selected_navigation_item"; // Main application context public static Context appContext = null; // Instance of the NEO database public static NEODatabase neod = null; /* * (non-Javadoc) * @see android.support.v4.app.FragmentActivity#onCreate(android.os.Bundle) */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_neobd); appContext = this; // Set up the action bar. final ActionBar actionBar = getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // For each of the sections in the app, add a tab to the action bar. actionBar.addTab(actionBar.newTab().setText(R.string.title_section_welcome) .setTabListener(new TabListener(new WelcomeTab()))); actionBar.addTab(actionBar.newTab().setText(R.string.title_section_obd2) .setTabListener(new TabListener(new OBDTab()))); actionBar.addTab(actionBar.newTab().setText(R.string.title_section_dtc) .setTabListener(new TabListener(new DTCTab()))); // Initialize the database neod = NEODatabase.getInstance(); } /* * (non-Javadoc) * @see android.app.Activity#onRestoreInstanceState(android.os.Bundle) */ @Override public void onRestoreInstanceState(Bundle savedInstanceState) { if (savedInstanceState.containsKey(STATE_SELECTED_NAVIGATION_ITEM)) { getActionBar().setSelectedNavigationItem(savedInstanceState.getInt(STATE_SELECTED_NAVIGATION_ITEM)); } } /* * (non-Javadoc) * @see android.support.v4.app.FragmentActivity#onSaveInstanceState(android.os.Bundle) */ @Override public void onSaveInstanceState(Bundle outState) { outState.putInt(STATE_SELECTED_NAVIGATION_ITEM, getActionBar().getSelectedNavigationIndex()); } }