Example usage for android.app ActionBar getThemedContext

List of usage examples for android.app ActionBar getThemedContext

Introduction

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

Prototype

public Context getThemedContext() 

Source Link

Document

Returns a Context with an appropriate theme for creating views that will appear in the action bar.

Usage

From source file:com.actionbarsherlock.sample.styled.MainActivityICS.java

/** Called when the activity is first created. */
@Override//from  ww w  .ja  v a2s  . c om
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_PROGRESS);

    setContentView(R.layout.main);
    final ActionBar ab = getActionBar();

    // set defaults for logo & home up
    ab.setDisplayHomeAsUpEnabled(showHomeUp);
    ab.setDisplayUseLogoEnabled(useLogo);

    // set up tabs nav
    for (int i = 1; i < 4; i++) {
        ab.addTab(ab.newTab().setText("Tab " + i).setTabListener(this));
    }

    // set up list nav
    ab.setListNavigationCallbacks(
            ArrayAdapter.createFromResource(ab.getThemedContext(), R.array.sections,
                    android.R.layout.simple_spinner_dropdown_item),
            //              .createFromResource(this, R.array.sections,
            //                      android.R.layout.simple_spinner_dropdown_item),
            new OnNavigationListener() {
                @Override
                public boolean onNavigationItemSelected(int itemPosition, long itemId) {
                    // FIXME add proper implementation
                    //rotateLeftFrag();
                    return false;
                }
            });

    // default to tab navigation
    showTabsNav();

    // create a couple of simple fragments as placeholders
    //        final int MARGIN = 16;
    //        leftFrag = new RoundedColourFragment(getResources().getColor(
    //                R.color.android_green), 1f, MARGIN, MARGIN / 2, MARGIN, MARGIN);
    //        rightFrag = new RoundedColourFragment(getResources().getColor(
    //                R.color.honeycombish_blue), 2f, MARGIN / 2, MARGIN, MARGIN,
    //                MARGIN);
    //
    //        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    //        ft.add(R.id.root, leftFrag);
    //        ft.add(R.id.root, rightFrag);
    //        ft.commit();

    ((Button) findViewById(R.id.start)).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mMode = startActionMode(new AnActionModeOfEpicProportions());
        }
    });
    ((Button) findViewById(R.id.cancel)).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mMode != null) {
                mMode.finish();
            }
        }
    });

    ((Button) findViewById(R.id.progress)).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mProgress == 100) {
                mProgress = 0;
                mProgressRunner.run();
            }
        }
    });

}

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 www  . j av a  2  s .  c o m
        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:org.bohrmeista.chan.ui.activity.BoardActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ChanApplication.getBoardManager().addListener(this);

    boardLoadable = new Loadable();
    threadLoadable = new Loadable();

    boardFragment = ThreadFragment.newInstance(this);
    setBoardFragmentViewMode();/*from  w  ww  .j  a v a 2s.  co m*/

    threadFragment = ThreadFragment.newInstance(this);

    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.replace(R.id.left_pane, boardFragment);
    ft.replace(R.id.right_pane, threadFragment);
    ft.commitAllowingStateLoss();

    final ActionBar actionBar = getActionBar();

    boardSpinner = new Spinner(actionBar.getThemedContext());
    spinnerAdapter = new BoardSpinnerAdapter(this, boardSpinner);
    boardSpinner.setAdapter(spinnerAdapter);
    boardSpinner.setOnItemSelectedListener(this);

    actionBar.setCustomView(boardSpinner);
    actionBar.setDisplayShowCustomEnabled(true);

    updatePaneState();

    Intent startIntent = getIntent();
    Uri startUri = startIntent.getData();

    if (savedInstanceState != null) {
        threadLoadable.readFromBundle(this, "thread", savedInstanceState);
        startLoadingThread(threadLoadable);

        // Reset page etc.
        Loadable tmp = new Loadable();
        tmp.readFromBundle(this, "board", savedInstanceState);
        startLoadingBoard(new Loadable(tmp.board));
    } else {
        if (startUri != null) {
            handleIntentURI(startUri);
        }

        if (boardLoadable.mode == Loadable.Mode.INVALID) {
            List<Board> savedValues = ChanApplication.getBoardManager().getSavedBoards();
            if (savedValues.size() > 0) {
                startLoadingBoard(new Loadable(savedValues.get(0).value));
            }
        }
    }

    if (startIntent.getExtras() != null) {
        handleExtraBundle(startIntent.getExtras());
    }

    ignoreNextOnItemSelected = true;
}

From source file:nrec.basil.wimuconsole.SensorSettingsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sensor_settings);

    // Set up the action bar to show a dropdown list which will
    // contain the various sensors that can be configured.  Some
    // sensors are local (camera) some are remote bluetooth devices
    // (IMU, Barometer etc.)
    final ActionBar actionBar = getActionBar();
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

    // Set up the dropdown list navigation in the action bar.
    actionBar.setListNavigationCallbacks(
            // Specify a SpinnerAdapter to populate the dropdown list.
            new ArrayAdapter<String>(actionBar.getThemedContext(), android.R.layout.simple_list_item_1,
                    android.R.id.text1, getResources().getStringArray(R.array.sensors_list)),
            this);

    // Specify a SpinnerAdapter to populate the wIMU list
    ArrayAdapter<CharSequence> imuAdapter = ArrayAdapter.createFromResource(this, R.array.wimu_list,
            android.R.layout.simple_spinner_item);
    imuAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    imuSpinner = (Spinner) findViewById(R.id.wimulist);
    imuSpinner.setAdapter(imuAdapter);//from   ww w. j  a v a  2  s. c om

    // Load the BASIL start/stop/reset commands
    InputStream input = getResources().openRawResource(R.raw.basilstart);
    try {
        input.read(basilStart, 0, 26);
    } catch (IOException e) {
        Log.e(TAG, "Could not read BASIL start command", e);
    }
    input = getResources().openRawResource(R.raw.basilstop);
    try {
        input.read(basilStop, 0, 26);
    } catch (IOException e) {
        Log.e(TAG, "Could not read BASIL stop command", e);
    }
    input = getResources().openRawResource(R.raw.basilreset);
    try {
        input.read(basilReset, 0, 26);
    } catch (IOException e) {
        Log.e(TAG, "Could not read BASIL reset command", e);
    }

    // Get the default filename for logging
    EditText logfilename = (EditText) findViewById(R.id.logfilename);
    mLogFileName = logfilename.toString();

    // Get local Bluetooth adapter
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    // If the adapter is null, then Bluetooth is not supported
    if (mBluetoothAdapter == null) {
        Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show();
        finish();
        return;
    }
}

From source file:com.geotrackin.gpslogger.GpsMainActivity.java

public void SetUpActionBar() {
    ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

    SpinnerAdapter spinnerAdapter = ArrayAdapter.createFromResource(actionBar.getThemedContext(),
            R.array.gps_main_views, android.R.layout.simple_spinner_dropdown_item);

    actionBar.setListNavigationCallbacks(spinnerAdapter, this);

    //Reload the user's previously selected view f73
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    actionBar.setSelectedNavigationItem(prefs.getInt("dropdownview", 0));

    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setTitle("");
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_HOME
            | ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_CUSTOM);
    actionBar.setCustomView(R.layout.actionbar);

    ImageButton helpButton = (ImageButton) actionBar.getCustomView().findViewById(R.id.imgHelp);
    helpButton.setOnClickListener(new View.OnClickListener() {
        @Override//  w  w w  .  j  a v a2  s.c  om
        public void onClick(View view) {
            Intent faqtivity = new Intent(getApplicationContext(), Faqtivity.class);
            startActivity(faqtivity);
        }
    });

}

From source file:de.vanita5.twittnuker.activity.support.HomeActivity.java

@Override
public boolean onPrepareOptionsMenu(final Menu menu) {
    if (mViewPager == null || mPagerAdapter == null)
        return false;
    final boolean useBottomActionItems = FlymeUtils.hasSmartBar() && isBottomComposeButton();
    setMenuItemAvailability(menu, MENU_ACTIONS, useBottomActionItems);
    setMenuItemAvailability(menu, MENU_PROGRESS, useBottomActionItems);
    if (useBottomActionItems) {
        final int icon, title;
        final int position = mViewPager.getCurrentItem();
        final SupportTabSpec tab = mPagerAdapter.getTab(position);
        if (tab == null) {
            title = R.string.compose;/*from   w w  w . ja v  a  2s.c  o m*/
            icon = R.drawable.ic_iconic_action_compose;
        } else {
            if (classEquals(DirectMessagesFragment.class, tab.cls)) {
                icon = R.drawable.ic_iconic_action_new_message;
                title = R.string.new_direct_message;
            } else if (classEquals(TrendsSuggectionsFragment.class, tab.cls)) {
                icon = R.drawable.ic_iconic_action_search;
                title = android.R.string.search_go;
            } else {
                icon = R.drawable.ic_iconic_action_compose;
                title = R.string.compose;
            }
        }
        final ActionBar actionBar = getActionBar();
        final MenuItem actionsItem = menu.findItem(MENU_ACTIONS);
        if (actionBar != null) {
            actionsItem.setIcon(actionBar.getThemedContext().getResources().getDrawable(icon));
        }
        actionsItem.setTitle(title);
    }
    return true;
}

From source file:org.getlantern.firetweet.util.Utils.java

public static int getActionBarHeight(@Nullable ActionBar actionBar) {
    if (actionBar == null)
        return 0;
    final Context context = actionBar.getThemedContext();
    final TypedValue tv = new TypedValue();
    final int height = actionBar.getHeight();
    if (height > 0)
        return height;
    if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
        return TypedValue.complexToDimensionPixelSize(tv.data, context.getResources().getDisplayMetrics());
    }// w  w w .  j a va2 s .  c om
    return 0;
}

From source file:org.getlantern.firetweet.util.Utils.java

public static int getActionBarHeight(@Nullable android.support.v7.app.ActionBar actionBar) {
    if (actionBar == null)
        return 0;
    final Context context = actionBar.getThemedContext();
    final TypedValue tv = new TypedValue();
    final int height = actionBar.getHeight();
    if (height > 0)
        return height;
    if (context.getTheme().resolveAttribute(R.attr.actionBarSize, tv, true)) {
        return TypedValue.complexToDimensionPixelSize(tv.data, context.getResources().getDisplayMetrics());
    }/*from   w  w w.  j a  va  2s. c  o m*/
    return 0;
}

From source file:com.chen.mail.ui.AbstractActivityController.java

/**
 * Initialize the action bar. This is not visible to OnePaneController and
 * TwoPaneController so they cannot override this behavior.
 *///from w  w  w  .  j  av a 2s. c om
private void initializeActionBar() {
    final ActionBar actionBar = mActivity.getActionBar();
    if (actionBar == null) {
        return;
    }

    // be sure to inherit from the ActionBar theme when inflating
    final LayoutInflater inflater = LayoutInflater.from(actionBar.getThemedContext());
    final boolean isSearch = mActivity.getIntent() != null
            && Intent.ACTION_SEARCH.equals(mActivity.getIntent().getAction());
    mActionBarView = (MailActionBarView) inflater
            .inflate(isSearch ? R.layout.search_actionbar_view : R.layout.actionbar_view, null);
    mActionBarView.initialize(mActivity, this, actionBar);

    // init the action bar to allow the 'up' affordance.
    // any configurations that disallow 'up' should do that later.
    mActionBarView.setBackButton();
}