Example usage for android.app ActionBar newTab

List of usage examples for android.app ActionBar newTab

Introduction

In this page you can find the example usage for android.app ActionBar newTab.

Prototype

@Deprecated
public abstract Tab newTab();

Source Link

Document

Create and return a new Tab .

Usage

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   ww  w. j  a v a 2s.  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.nest5.businessClient.Initialactivity.java

/**
 * Begins the activity./*from w ww.ja va  2 s . co m*/
 */
@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");
       }
    }
            
       }
    });*/

}