Example usage for android.app ActionBar addTab

List of usage examples for android.app ActionBar addTab

Introduction

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

Prototype

@Deprecated
public abstract void addTab(Tab tab, int position);

Source Link

Document

Add a tab for use in tabbed navigation mode.

Usage

From source file:run.ace.TabBar.java

public void show(android.app.Activity activity) {
    //if (!(activity instanceof ActionBarActivity)) {
    android.app.ActionBar mainActionBar = activity.getActionBar();
    if (mainActionBar != null) {
        mainActionBar.show();/*from  w w  w . j  ava  2s. c om*/
        mainActionBar.setNavigationMode(android.app.ActionBar.NAVIGATION_MODE_TABS);
        if (_primaryCommands != null) {
            for (int i = 0; i < _primaryCommands.size(); i++) {
                android.app.ActionBar.Tab tab = mainActionBar.newTab();
                AppBarButton abb = (AppBarButton) _primaryCommands.get(i);
                if (abb.icon != null) {
                    tab.setCustomView(getCustomTabView(abb, mainActionBar.getThemedContext()));
                } else {
                    tab.setText(abb.label);
                }
                tab.setTabListener(this);
                mainActionBar.addTab(tab, i == 0);
            }
        }
        return;
    }
    throw new RuntimeException(
            "Cannot use TabBar on the main page in Android unless you set <preference name=\"ShowTitle\" value=\"true\"/> in config.xml.");
    //}
    //else {
    //    ActionBar actionBar = ((ActionBarActivity)activity).getSupportActionBar();
    //    if (actionBar != null) {
    //        actionBar.show();
    //        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    //        for (int i = 0; i < _primaryCommands.size(); i++) {
    //            ActionBar.Tab tab = actionBar.newTab();
    //            AppBarButton abb = (AppBarButton)_primaryCommands.get(i);
    //            if (abb.icon != null) {
    //                tab.setCustomView(getCustomTabView(abb, actionBar.getThemedContext()));
    //            }
    //            else {
    //                tab.setText(abb.label);
    //            }
    //            tab.setTabListener(this);
    //            actionBar.addTab(tab);
    //        }
    //        return;
    //    }
    //    throw new RuntimeException(
    //        "Unable to get TabBar from the current activity.");
    //}
}

From source file:com.native5.plugins.ActionBarPlugin.java

private boolean buildTabs(ActionBar bar, JSONArray definition, String menu_var) {
    try {/* ww  w  .  ja v  a  2s. co m*/
        for (int i = 0; i < definition.length(); ++i) {
            final JSONObject item_def = definition.getJSONObject(i);
            final String text = item_def.isNull("text") ? "" : item_def.getString("text");
            final Drawable icon = item_def.isNull("icon") ? null
                    : getDrawableForURI(item_def.getString("icon"));
            final boolean isSelected = item_def.optBoolean("selected", false);

            bar.addTab(bar.newTab().setText(text).setContentDescription(text).setTag(text).setIcon(icon)
                    .setTabListener(new TabListener(this, menu_var + "[" + i + "]")), isSelected);
        }
    } catch (JSONException e) {
        return false;
    }

    return true;
}

From source file:com.yohpapa.overlaymusicplayer.activity.MainActivity.java

private void setupActionBar() {
    ActionBar bar = getActionBar();
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    bar.setDisplayShowHomeEnabled(false);
    bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);

    int lastPosition = PrefUtils.getInt(this, R.string.pref_last_tab_position, 0);

    for (int i = 0; i < fragmentNames.length; i++) {

        ActionBar.Tab tab = bar.newTab();
        tab.setText(fragmentNames[i]);/*from w  w  w  .j  ava  2s  .  c  o m*/
        tab.setTabListener(new ActionBar.TabListener() {
            @Override
            public void onTabUnselected(Tab tab, FragmentTransaction ft) {
                Log.d(TAG, "onTabUnselected");
            }

            @Override
            public void onTabSelected(Tab tab, FragmentTransaction ft) {
                ViewPager pager = (ViewPager) findViewById(R.id.fragment_pager);
                pager.setCurrentItem(tab.getPosition());
                PrefUtils.setInt(MainActivity.this, R.string.pref_last_tab_position, tab.getPosition());
            }

            @Override
            public void onTabReselected(Tab tab, FragmentTransaction ft) {
                Fragment fragment = fragments[tab.getPosition()];
                if (fragment instanceof CommonListFragment) {
                    ((CommonListFragment) fragment).onTapWhenSelected();
                }
            }
        });
        boolean isSelected = false;
        if (i == lastPosition) {
            isSelected = true;
        }
        bar.addTab(tab, isSelected);
    }
}

From source file:com.android.settings.HWSettings.java

private void setupAll(ActionBar bar) {
    final Tab tab = bar.newTab();
    tab.setText(R.string.hw_all);/*  w ww. j a va  2s  .c  om*/
    tab.setTabListener(mTabListener);
    if (curTabIndex == TAB_INDEX_SYSTEM) {
        bar.addTab(tab, true);
    } else {
        bar.addTab(tab);
    }

}

From source file:com.android.settings.HWSettings.java

private void setupGeneral(ActionBar bar) {

    final Tab tab = bar.newTab();
    tab.setText(R.string.hw_general);//from  w w w.  ja va2 s  .  c  om
    tab.setTabListener(mTabListener);
    if (curTabIndex == TAB_INDEX_NETWORKS) {
        bar.addTab(tab, true);
    } else {
        bar.addTab(tab);
    }
}

From source file:com.nest5.businessClient.Initialactivity.java

/**
 * Begins the activity.//from   w  w w  .j  a  v  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");
       }
    }
            
       }
    });*/

}