List of usage examples for android.app ActionBar NAVIGATION_MODE_TABS
int NAVIGATION_MODE_TABS
To view the source code for android.app ActionBar NAVIGATION_MODE_TABS.
Click Source Link
From source file:ca.ramnansingh.randy.ibmwatsonspeechqa.AudioRecordTest.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Strictmode needed to run the http/wss request for devices > Gingerbread if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); }//ww w. j a va2 s . c o m //setContentView(R.layout.activity_main); setContentView(R.layout.activity_tab_text); ActionBar actionBar = getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); tabSTT = actionBar.newTab().setText("Speech to Text"); tabTTS = actionBar.newTab().setText("Text to Speech"); tabSTT.setTabListener(new MyTabListener(fragmentTabSTT)); tabTTS.setTabListener(new MyTabListener(fragmentTabTTS)); actionBar.addTab(tabSTT); actionBar.addTab(tabTTS); //actionBar.setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#B5C0D0"))); }
From source file:com.android.gpstest.GpsTestActivity.java
private void initActionBar(Bundle savedInstanceState) { // Set up the action bar. final android.support.v7.app.ActionBar actionBar = getSupportActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); actionBar.setTitle(getApplicationContext().getText(R.string.app_name)); // If we don't have a large screen, set up the tabs using the ViewPager if (!mIsLargeScreen) { // page adapter contains all the fragment registrations mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); // Set up the ViewPager with the sections adapter. mViewPager = (ViewPagerMapBevelScroll) findViewById(R.id.pager); mViewPager.setAdapter(mSectionsPagerAdapter); mViewPager.setOffscreenPageLimit(2); // When swiping between different sections, select the corresponding // tab. We can also use ActionBar.Tab#select() to do this if we have a // reference to the Tab. mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override/* w w w .ja va2 s . c o m*/ public void onPageSelected(int position) { actionBar.setSelectedNavigationItem(position); } }); // For each of the sections in the app, add a tab to the action bar. for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { // Create a tab with text corresponding to the page title defined by // the adapter. Also specify this Activity object, which implements // the TabListener interface, as the listener for when this tab is // selected. actionBar.addTab( actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this)); } } }
From source file:com.nest5.businessClient.Initialactivity.java
/** * Begins the activity.//from w w w . j av a 2 s .c om */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.savedInstanceState = savedInstanceState; getWindow().setFormat(PixelFormat.RGBA_8888); getWindow().addFlags(WindowManager.LayoutParams.FLAG_DITHER); BugSenseHandler.initAndStartSession(Initialactivity.this, "1a5a6af1"); setContentView(R.layout.swipe_view); checkLogin(); // add necessary intent values to be matched. intentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION); intentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION); intentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION); intentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION); manager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE); channel = manager.initialize(this, getMainLooper(), null); mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); dbHelper = new MySQLiteHelper(this); ingredientCategoryDatasource = new IngredientCategoryDataSource(dbHelper); db = ingredientCategoryDatasource.open(); ingredientCategories = ingredientCategoryDatasource.getAllIngredientCategory(); // ingredientCategoryDatasource.close(); productCategoryDatasource = new ProductCategoryDataSource(dbHelper); productCategoryDatasource.open(db); productsCategories = productCategoryDatasource.getAllProductCategory(); taxDataSource = new TaxDataSource(dbHelper); taxDataSource.open(db); taxes = taxDataSource.getAllTax(); unitDataSource = new UnitDataSource(dbHelper); unitDataSource.open(db); units = unitDataSource.getAllUnits(); ingredientDatasource = new IngredientDataSource(dbHelper); ingredientDatasource.open(db); ingredientes = ingredientDatasource.getAllIngredient(); productDatasource = new ProductDataSource(dbHelper); productDatasource.open(db); productos = productDatasource.getAllProduct(); comboDatasource = new ComboDataSource(dbHelper); comboDatasource.open(db); combos = comboDatasource.getAllCombos(); saleDataSource = new SaleDataSource(dbHelper); saleDataSource.open(db); saleList = saleDataSource.getAllSales(); syncRowDataSource = new SyncRowDataSource(dbHelper); syncRowDataSource.open(db); Calendar today = Calendar.getInstance(); Calendar tomorrow = Calendar.getInstance(); today.set(Calendar.HOUR, 0); today.set(Calendar.HOUR_OF_DAY, 0); today.set(Calendar.MINUTE, 0); today.set(Calendar.SECOND, 0); today.set(Calendar.MILLISECOND, 0); tomorrow.roll(Calendar.DATE, 1); tomorrow.set(Calendar.HOUR, 0); tomorrow.set(Calendar.HOUR_OF_DAY, 0); tomorrow.set(Calendar.MINUTE, 0); tomorrow.set(Calendar.SECOND, 0); tomorrow.set(Calendar.MILLISECOND, 0); init = today.getTimeInMillis(); end = tomorrow.getTimeInMillis(); //Log.d(TAG, today.toString()); //Log.d(TAG, tomorrow.toString()); Calendar now = Calendar.getInstance(); now.setTimeInMillis(System.currentTimeMillis()); //Log.d(TAG, now.toString()); //Log.d(TAG, "Diferencia entre tiempos: " + String.valueOf(end - init)); salesFromToday = saleDataSource.getAllSalesWithin(init, end); updateRegistrables(); // ingredientDatasource.close(); mDemoCollectionPagerAdapter = new DemoCollectionPagerAdapter(getSupportFragmentManager()); mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mDemoCollectionPagerAdapter); mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { // When swiping between pages, select the // corresponding tab. getActionBar().setSelectedNavigationItem(position); } }); final ActionBar actionBar = getActionBar(); // Specify that tabs should be displayed in the action bar. actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Create a tab listener that is called when the user changes tabs. ActionBar.TabListener tabListener = new ActionBar.TabListener() { @Override public void onTabReselected(Tab tab, FragmentTransaction ft) { // TODO Auto-generated method stub } @Override public void onTabSelected(Tab tab, FragmentTransaction ft) { mViewPager.setCurrentItem(tab.getPosition()); } @Override public void onTabUnselected(Tab tab, FragmentTransaction ft) { // TODO Auto-generated method stub } }; Tab homeTab = actionBar.newTab().setText("Inicio").setTabListener(tabListener); Tab ordersTab = actionBar.newTab().setText("rdenes").setTabListener(tabListener); /*Tab dailyTab = actionBar.newTab().setText("Registros") .setTabListener(tabListener); Tab inventoryTab = actionBar.newTab().setText("Inventarios") .setTabListener(tabListener);*/ Tab nest5ReadTab = actionBar.newTab().setText("Nest5").setTabListener(tabListener); actionBar.addTab(homeTab, true); actionBar.addTab(ordersTab, false); //actionBar.addTab(dailyTab, false); //actionBar.addTab(inventoryTab, false); actionBar.addTab(nest5ReadTab, false); currentOrder = new LinkedHashMap<Registrable, Integer>(); inTableRegistrable = new ArrayList<Registrable>(); savedOrders = new LinkedHashMap<String, LinkedHashMap<Registrable, Integer>>(); cookingOrders = new LinkedList<LinkedHashMap<Registrable, Integer>>(); //cookingOrdersMethods = new LinkedHashMap<LinkedHashMap<Registrable, Integer>, String>(); cookingOrdersDelivery = new LinkedHashMap<LinkedHashMap<Registrable, Integer>, Integer>(); cookingOrdersTogo = new LinkedHashMap<LinkedHashMap<Registrable, Integer>, Integer>(); //cookingOrdersTip = new LinkedHashMap<LinkedHashMap<Registrable, Integer>, Integer>(); //cookingOrdersDiscount = new LinkedHashMap<LinkedHashMap<Registrable, Integer>, Double>(); cookingOrdersTimes = new LinkedHashMap<LinkedHashMap<Registrable, Integer>, Long>(); cookingOrdersTable = new LinkedHashMap<LinkedHashMap<Registrable, Integer>, CurrentTable<Table, Integer>>(); openTables = new LinkedList<CurrentTable<Table, Integer>>(); //cookingOrdersReceived = new LinkedHashMap<LinkedHashMap<Registrable, Integer>, Double>(); frases = getResources().getStringArray(R.array.phrases); timer = new Timer(); deviceID = DeviceID.getDeviceId(mContext); //////Log.i("AACCCAAAID",deviceID); BebasFont = Typeface.createFromAsset(getAssets(), "fonts/BebasNeue.otf"); VarelaFont = Typeface.createFromAsset(getAssets(), "fonts/Varela-Regular.otf"); // Lector de tarjetas magnticas mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); //mReader = new ACR31Reader(mAudioManager); /* Initialize the reset progress dialog */ mResetProgressDialog = new ProgressDialog(mContext); // ACR31 RESET CALLBACK /*mReader.setOnResetCompleteListener(new ACR31Reader.OnResetCompleteListener() { //hola como estas @Override public void onResetComplete(ACR31Reader reader) { if (mSettingSleepTimeout) { mGettingStatus = true; mReader.setSleepTimeout(mSleepTimeout); mSettingSleepTimeout = false; } runOnUiThread(new Runnable() { @Override public void run() { mResetProgressDialog.dismiss(); }; }); } });*/ /* Set the raw data callback. */ /*mReader.setOnRawDataAvailableListener(new ACR31Reader.OnRawDataAvailableListener() { @Override public void onRawDataAvailable(ACR31Reader reader, byte[] rawData) { ////Log.i("MISPRUEBAS", "setOnRawDataAvailableListener"); final String hexString = toHexString(rawData) + (reader.verifyData(rawData) ? " (Checksum OK)" : " (Checksum Error)"); ////Log.i("MISPRUEBAS", hexString); if (reader.verifyData(rawData)) { runOnUiThread(new Runnable() { @Override public void run() { mResetProgressDialog .setMessage("Solicitando Informacin al Servidor..."); mResetProgressDialog.setCancelable(false); mResetProgressDialog.setIndeterminate(true); mResetProgressDialog.show(); } }); SharedPreferences prefs = Util .getSharedPreferences(mContext); restService = new RestService(recievePromoandUserHandler, mContext, Setup.PROD_URL + "/company/initMagneticStamp"); restService.addParam("company", prefs.getString(Setup.COMPANY_ID, "0")); restService.addParam("magnetic5", hexString); restService.setCredentials("apiadmin", Setup.apiKey); try { restService.execute(RestService.POST); } catch (Exception e) { e.printStackTrace(); ////Log.i("MISPRUEBAS", "Error empezando request"); } } } });*/ }
From source file:com.dsdar.thosearoundme.TeamViewActivity.java
/** * Method to get users team information and design action bar accordingly */// w w w. ja va 2 s. co m private void getAndLoadTeamInfo() { try { JSONObject aRequestJson = new JSONObject(); if (itsLoginUserId != null) { aRequestJson.put(MyAppConstants.MEMBER_ID, itsLoginUserId); } else { aRequestJson.put(MyAppConstants.MEMBER_ID, 0); return; } // AppAsyncTask aAsyncTask = new AppAsyncTask(TeamViewActivity.this, // MyAppConstants.GET_MY_TEAM, MyAppConstants.API_POST_TYPE, // MyAppConstants.TEAM_LOADING); AppAsyncTask aAsyncTask = new AppAsyncTask(TeamViewActivity.this, MyAppConstants.GET_MY_TEAM, MyAppConstants.API_POST_TYPE); aAsyncTask.setListener(new AppAsyncTask.AsyncTaskListener() { @Override public void onPreExecuteConcluded() { } @Override public void onPostExecuteConcluded(String theResult) { itsResult = theResult; Log.d("TVA", "getAndLoadTeamInfo=" + theResult); if (theResult != null) { loadTeamInfo(theResult); } else { // Toast.makeText(TeamViewActivity.this, // MyAppConstants.CONNECTION_ERROR, // Toast.LENGTH_LONG).show(); } } /** * Method to load action bar with team information * * @param theTeamJson */ @SuppressLint("NewApi") private void loadTeamInfo(String theTeamJson) { try { // Users team information in JSON format JSONObject aTeamJson = new JSONObject(theTeamJson); // Retrieving status from response JSON String aResponseStatus = aTeamJson.getString(MyAppConstants.STATUS); // If API response status is success if (aResponseStatus.equals(MyAppConstants.SUCCESS_STATUS)) { // String result_val = aTeamJson // .getString(MyAppConstants.RESULT); // String[] result = result_val.split("~"); int teamCount = Integer.parseInt(aTeamJson.getString(MyAppConstants.MESSAGE)); // MyAppConstants.TEAM_CNT_FIRST = teamCount; // String team_result = result[0]; itsTeamArrayJson = aTeamJson.getJSONArray(MyAppConstants.RESULT); String[] aTeamNameArray = getTeamNames(itsTeamArrayJson); itsTeamArray = aTeamNameArray; String[] aTeamIdArray = getTeamId(itsTeamArrayJson); itsTeamIdArray = aTeamIdArray; String[] aTeamStickyArray = getTeamSticky(itsTeamArrayJson); itsTeamStickyArray = aTeamStickyArray; String[] aTeamRecordStatusArray = getTeamRecordStatus(itsTeamArrayJson); itsTeamRecordStatusArray = aTeamRecordStatusArray; // create new tabs and display team name in tabs itsActionBar.removeAllTabs(); // int tabSelect = MyAppConstants.selTab; getTeams(itsTeamArrayJson); Log.d("TVA", "2=" + MyAppConstants.selTab); // for (Map.Entry<String, String> entry : hMap // .entrySet()) { // Tab tab = itsActionBar // .newTab() // .setText( // " " + entry.getKey() // + " ") // .setTabListener(TeamViewActivity.this); // if (entry.getValue().equals("true")) { // tab.setIcon(R.drawable.sticky_icon); // } // itsActionBar.addTab(tab); // } for (String aTabName : aTeamNameArray) { Tab tab = itsActionBar.newTab().setText(" " + aTabName + " ") // .setTabListener(TeamViewActivity.this); .setTabListener(new MyDummyTabListener()); String isSticky = hMap.get(aTabName); String recordingStatus = hMapRecord.get(aTabName); String memberid = hMapOwner.get(aTabName); if (isSticky.equals("true")) { tab.setIcon(R.drawable.pin); } tab.setContentDescription(recordingStatus); if (recordingStatus != null) { if (recordingStatus.equals("true")) { if (itsLoginUserId.equals(memberid)) { tab.setIcon(R.drawable.record); } } } itsActionBar.addTab(tab); } Log.d("TVA", "3=" + MyAppConstants.selTab); // // for (String aStickyTeam : aTeamStickyArray) { // if (aStickyTeam.equals("true")) { // itsActionBar.getSelectedTab().setIcon( // R.drawable.sticky_icon); // } // } itsActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); Log.d("TVA", "I am doing restart selecting tab" + MyAppConstants.selTab); // Log.d("TVA", "isTeamMemberCallFirstTime=" // + isTeamMemberCallFirstTime); Log.d("TVA", "I am doing after selecting tab" + MyAppConstants.selTab); // itsActionBar.getTabAt(MyAppConstants.selTab).setTabListener( // new MyDummyTabListener()); // Overriding this with shared pref int selTab = itsSharedPreference.getInt(MyAppConstants.USER_SEL_TAB, -1); Log.d("TVA", "itsSharedPreference selTab =" + selTab); if ((itsActionBar.getTabCount() > selTab) && (selTab != -1)) { itsActionBar.selectTab(itsActionBar.getTabAt(selTab)); } else if ((itsActionBar.getTabCount() > MyAppConstants.selTab) && (MyAppConstants.selTab != -1)) { itsActionBar.selectTab(itsActionBar.getTabAt(MyAppConstants.selTab)); } else { MyAppConstants.selTab = 0; itsActionBar.selectTab(itsActionBar.getTabAt(MyAppConstants.selTab)); } // itsActionBar.selectTab(itsActionBar // .getTabAt(MyAppConstants.selTab)); recordStatus = itsActionBar.getSelectedTab().getContentDescription(); // itsActionBar.getTabAt(MyAppConstants.selTab).setTabListener( // TeamViewActivity.this); int cnt = itsActionBar.getTabCount(); for (int i = 0; i < cnt; i++) { itsActionBar.getTabAt(i).setTabListener(TeamViewActivity.this); } if (isTeamMemberCallFirstTime) { // itsActionBar.selectTab(itsActionBar.getTabAt(0)); if ((itsActionBar.getTabCount() > selTab) && (selTab != -1)) { itsActionBar.selectTab(itsActionBar.getTabAt(selTab)); } else { itsActionBar.selectTab(itsActionBar.getTabAt(MyAppConstants.selTab)); } isTeamMemberCallFirstTime = false; } // Send logined user's current location to server // for every n minutes // if (itsLocationUpdates == null) { // itsLocationUpdates = new LocationUpdates( // TeamViewActivity.this, itsGoogleMap); // } } // If API response status is failure else if (aResponseStatus.equals(MyAppConstants.FAILURE_STATUS)) { String aResponseMsg = aTeamJson.getString(MyAppConstants.MESSAGE); } } catch (JSONException theJsonException) { theJsonException.printStackTrace(); Log.e(this.getClass().getName(), "JSON Exception while retrieving response from getMyTeam webservice"); } } }); aAsyncTask.execute(aRequestJson.toString()); } catch (JSONException theJsonException) { theJsonException.printStackTrace(); Log.e(this.getClass().getName(), "JSON Exception while constructing request for getMyTeam webservice"); } }
From source file:com.example.android.cardreader.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.alternate_main_fragment); //TODO Stop Executing Eden //Globals.executeEden(); getUsers(1);//from w ww . j a v a2s .c o m instance = this; final ActionBar actionBar = getActionBar(); actionBar.setTitle(" TartanHacks"); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); actionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar_bg)); actionBar.setStackedBackgroundDrawable(getResources().getDrawable(R.drawable.tab_bg)); actionBar.setDisplayShowHomeEnabled(true); frags.add(new PersonListFrag(Globals.pending)); frags.add(new PersonListFrag(Globals.allUsers)); frags.add(new PersonListFrag(Globals.checkedIn)); mAdapter = new FragmentAdapter(getFragmentManager()); fab = findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { View dialogView = View.inflate(instance, R.layout.dialog_signup, null); idField = (EditText) dialogView.findViewById(R.id.andrewIdField); pb = (ProgressBar) dialogView.findViewById(R.id.progress); nameField = (TextView) dialogView.findViewById(R.id.name); scanView = (TextView) dialogView.findViewById(R.id.scan_view); idField.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { String id = s.toString(); pb.setVisibility(View.VISIBLE); queryId(id); } @Override public void afterTextChanged(Editable s) { } }); AlertDialog.Builder builder; builder = new AlertDialog.Builder(instance); builder.setView(dialogView); builder.setCancelable(true); builder.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { Globals.adding = false; } }); signupDialog = builder.show(); } }); mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setOffscreenPageLimit(0); mViewPager.setAdapter(mAdapter); mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { // When swiping between different app sections, select the corresponding tab. // We can also use ActionBar.Tab#select() to do this if we have a reference to the // Tab. actionBar.setSelectedNavigationItem(position); } }); actionBar.addTab(actionBar.newTab().setText("Pending").setTabListener(this)); actionBar.addTab(actionBar.newTab().setText("All").setTabListener(this)); actionBar.addTab(actionBar.newTab().setText("Checked In").setTabListener(this)); mLoyaltyCardReader = new LoyaltyCardReader(this); // Disable Android Beam and register our card reader callback enableReaderMode(); new UpdateThread().executeOnExecutor(Executors.newSingleThreadExecutor()); }
From source file:com.ibm.watson.developer_cloud.android.examples.IBMSpeechToText.java
/** public static class TTSCommands extends AsyncTask<Void, Void, JSONObject> { //w w w . j av a 2 s .c o m protected JSONObject doInBackground(Void... none) { return TextToSpeech.sharedInstance().getVoices(); } }*/ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); StorageReference mStorageRef; mStorageRef = FirebaseStorage.getInstance().getReference(); // Strictmode needed to run the http/wss request for devices > Gingerbread if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); } //setContentView(R.layout.activity_main); setContentView(R.layout.activity_tab_text); ActionBar action = getActionBar(); action.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); tabSTT = action.newTab().setText("Meeting Recorder"); // tabTTS = actionBar.newTab().setText("Text to Speech"); tabSTT.setTabListener(new MyTabListener(fragmentTabSTT)); // tabTTS.setTabListener(new MyTabListener(fragmentTabTTS)); action.addTab(tabSTT); // actionBar.addTab(tabTTS); //actionBar.setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#B5C0D0"))); }
From source file:com.vonglasow.michael.satstat.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); defaultUEH = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { public void uncaughtException(Thread t, Throwable e) { Context c = getApplicationContext(); File dumpDir = c.getExternalFilesDir(null); File dumpFile = new File(dumpDir, "satstat-" + System.currentTimeMillis() + ".log"); PrintStream s;/*from w w w. jav a2 s . c om*/ try { InputStream buildInStream = getResources().openRawResource(R.raw.build); s = new PrintStream(dumpFile); s.append("SatStat build: "); int i; try { i = buildInStream.read(); while (i != -1) { s.write(i); i = buildInStream.read(); } buildInStream.close(); } catch (IOException e1) { e1.printStackTrace(); } s.append("\n\n"); e.printStackTrace(s); s.flush(); s.close(); } catch (FileNotFoundException e2) { e2.printStackTrace(); } defaultUEH.uncaughtException(t, e); } }); mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); mSharedPreferences.registerOnSharedPreferenceChangeListener(this); final ActionBar actionBar = getActionBar(); setContentView(R.layout.activity_main); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Find out default screen orientation Configuration config = getResources().getConfiguration(); WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE); int rot = wm.getDefaultDisplay().getRotation(); isWideScreen = (config.orientation == Configuration.ORIENTATION_LANDSCAPE && (rot == Surface.ROTATION_0 || rot == Surface.ROTATION_180) || config.orientation == Configuration.ORIENTATION_PORTRAIT && (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270)); Log.d("MainActivity", "isWideScreen=" + Boolean.toString(isWideScreen)); // compact action bar int dpX = (int) (this.getResources().getDisplayMetrics().widthPixels / this.getResources().getDisplayMetrics().density); /* * This is a crude way to ensure a one-line action bar with tabs * (not a drop-down list) and home (incon) and title only if there * is space, depending on screen width: * divide screen in units of 64 dp * each tab requires 1 unit, home and menu require slightly less, * title takes up approx. 2.5 units in portrait, * home and title are about 2 units wide in landscape */ if (dpX < 192) { // just enough space for drop-down list and menu actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayShowTitleEnabled(false); } else if (dpX < 320) { // not enough space for four tabs, but home will fit next to list actionBar.setDisplayShowHomeEnabled(true); actionBar.setDisplayShowTitleEnabled(false); } else if (dpX < 384) { // just enough space for four tabs actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayShowTitleEnabled(false); } else if ((dpX < 448) || ((config.orientation == Configuration.ORIENTATION_PORTRAIT) && (dpX < 544))) { // space for four tabs and home, but not title actionBar.setDisplayShowHomeEnabled(true); actionBar.setDisplayShowTitleEnabled(false); } else { // ample space for home, title and all four tabs actionBar.setDisplayShowHomeEnabled(true); actionBar.setDisplayShowTitleEnabled(true); } setEmbeddedTabs(actionBar, true); providerLocations = new HashMap<String, Location>(); mAvailableProviderStyles = new ArrayList<String>(Arrays.asList(LOCATION_PROVIDER_STYLES)); providerStyles = new HashMap<String, String>(); providerAppliedStyles = new HashMap<String, String>(); providerInvalidationHandler = new Handler(); providerInvalidators = new HashMap<String, Runnable>(); // Create the adapter that will return a fragment for each of the three // primary sections of the app. mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mSectionsPagerAdapter); mViewPager.setOnPageChangeListener(this); // Add tabs, specifying the tab's text and TabListener for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { actionBar.addTab(actionBar.newTab() //.setText(mSectionsPagerAdapter.getPageTitle(i)) .setIcon(mSectionsPagerAdapter.getPageIcon(i)).setTabListener(this)); } // This is needed by the mapsforge library. AndroidGraphicFactory.createInstance(this.getApplication()); // Get system services for event delivery mLocationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mOrSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION); mAccSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mGyroSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE); mMagSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); mLightSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT); mProximitySensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY); mPressureSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE); mHumiditySensor = mSensorManager.getDefaultSensor(Sensor.TYPE_RELATIVE_HUMIDITY); mTempSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_AMBIENT_TEMPERATURE); mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); mConnectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); mAccSensorRes = getSensorDecimals(mAccSensor, mAccSensorRes); mGyroSensorRes = getSensorDecimals(mGyroSensor, mGyroSensorRes); mMagSensorRes = getSensorDecimals(mMagSensor, mMagSensorRes); mLightSensorRes = getSensorDecimals(mLightSensor, mLightSensorRes); mProximitySensorRes = getSensorDecimals(mProximitySensor, mProximitySensorRes); mPressureSensorRes = getSensorDecimals(mPressureSensor, mPressureSensorRes); mHumiditySensorRes = getSensorDecimals(mHumiditySensor, mHumiditySensorRes); mTempSensorRes = getSensorDecimals(mTempSensor, mTempSensorRes); networkTimehandler = new Handler(); networkTimeRunnable = new Runnable() { @Override public void run() { int newNetworkType = mTelephonyManager.getNetworkType(); if (getNetworkGeneration(newNetworkType) != mLastNetworkGen) onNetworkTypeChanged(newNetworkType); else networkTimehandler.postDelayed(this, NETWORK_REFRESH_DELAY); } }; wifiTimehandler = new Handler(); wifiTimeRunnable = new Runnable() { @Override public void run() { mWifiManager.startScan(); wifiTimehandler.postDelayed(this, WIFI_REFRESH_DELAY); } }; updateLocationProviderStyles(); }
From source file:com.android.contacts.activities.DialtactsActivity.java
/** * Goes back to usual Phone UI with tags. Previously selected Tag and associated Fragment * should be automatically focused again. *///from w ww.ja va 2 s . com private void exitSearchUi() { final ActionBar actionBar = getActionBar(); // Hide the search fragment, if exists. if (mSearchFragment != null) { mSearchFragment.setUserVisibleHint(false); final FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.hide(mSearchFragment); transaction.commitAllowingStateLoss(); } // We want to hide SearchView and show Tabs. Also focus on previously selected one. actionBar.setDisplayShowCustomEnabled(false); actionBar.setDisplayShowHomeEnabled(false); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); for (int i = 0; i < TAB_INDEX_COUNT; i++) { sendFragmentVisibilityChange(i, i == mViewPager.getCurrentItem()); } // Before exiting the search screen, reset swipe state. mDuringSwipe = false; mUserTabClick = false; mViewPager.setVisibility(View.VISIBLE); hideInputMethod(getCurrentFocus()); // Request to update option menu. invalidateOptionsMenu(); // See comments in onActionViewExpanded() mSearchView.onActionViewCollapsed(); mInSearchUi = false; }
From source file:com.android.settings.Settings.java
private void setupTab() { mActionBar = getActionBar();/*from ww w .j a v a 2s .c o m*/ mActionBar.setAlternativeTabStyle(true); mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); int tabHeight = (int) getResources().getDimensionPixelSize(R.dimen.uui_tab_height); mActionBar.setTabHeight(tabHeight); setupNetWork(); setupDevice(); setupPersonal(); setupMore(); setCurrentTab(mCurrentTabIndex); }
From source file:com.android.settings.Settings.java
public void setCurrentTab(int position) { /* SPRD: tab title changed,bug 258557 @{ */ //mActionBar.setTitle(mTabTitle[position]); /* @} *//*from ww w .jav a 2 s .c om*/ mCurrentTabIndex = position; if ((mActionBar.getNavigationMode() == ActionBar.NAVIGATION_MODE_TABS) && (mCurrentTabIndex != mActionBar.getSelectedNavigationIndex())) { mActionBar.setSelectedNavigationItem(mCurrentTabIndex); } }