Example usage for android.app ActionBar setDisplayHomeAsUpEnabled

List of usage examples for android.app ActionBar setDisplayHomeAsUpEnabled

Introduction

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

Prototype

public abstract void setDisplayHomeAsUpEnabled(boolean showHomeAsUp);

Source Link

Document

Set whether home should be displayed as an "up" affordance.

Usage

From source file:com.opensource.bitmapfun.ui.ImageDetailActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.image_detail_pager);

    // Fetch screen height and width, to use as our max size when loading images as this
    // activity runs full screen
    final DisplayMetrics displaymetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);

    // The ImageWorker takes care of loading images into our ImageView children asynchronously
    mImageWorker = new ImageFetcher(this, displaymetrics.widthPixels, displaymetrics.heightPixels);
    File cachePath = null;/* ww w . jav  a  2s.  com*/
    if (Utils.hasExternalStorage()) {
        File appRoot = new File(Environment.getExternalStorageDirectory(), "BitmapFun");
        cachePath = new File(appRoot, ".cache");
    }
    //        mImageWorker = new ImageResizer(this, displaymetrics.widthPixels, displaymetrics.heightPixels);
    mImageWorker.setAdapter(Images.imageWorkerUrlsAdapter);
    mImageWorker.setImageCache(ImageCache.findOrCreateCache(this, cachePath, IMAGE_CACHE_DIR));
    mImageWorker.setImageFadeIn(false);

    // Set up ViewPager and backing adapter
    mAdapter = new ImagePagerAdapter(getSupportFragmentManager(), mImageWorker.getAdapter().getSize());
    mPager = (ViewPager) findViewById(R.id.pager);
    mPager.setAdapter(mAdapter);
    mPager.setPageMargin((int) getResources().getDimension(R.dimen.image_detail_pager_margin));

    // Set up activity to go full screen
    getWindow().addFlags(LayoutParams.FLAG_FULLSCREEN);

    // Enable some additional newer visibility and ActionBar features to create a more immersive
    // photo viewing experience
    if (Utils.hasActionBar()) {
        final ActionBar actionBar = getActionBar();

        // Enable "up" navigation on ActionBar icon and hide title text
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayShowTitleEnabled(false);

        // Start low profile mode and hide ActionBar
        mPager.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
        actionBar.hide();

        // Hide and show the ActionBar as the visibility changes
        mPager.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
            @Override
            public void onSystemUiVisibilityChange(int vis) {
                if ((vis & View.SYSTEM_UI_FLAG_LOW_PROFILE) != 0) {
                    actionBar.hide();
                } else {
                    actionBar.show();
                }
            }
        });
    }

    // Set the current item based on the extra passed in to this activity
    final int extraCurrentItem = getIntent().getIntExtra(EXTRA_IMAGE, -1);
    if (extraCurrentItem != -1) {
        mPager.setCurrentItem(extraCurrentItem);
    }
}

From source file:com.amagi82.kerbalspaceapp.Settings.java

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

    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayShowTitleEnabled(true);
    getActionBar().setTitle(R.string.title_activity_settings);

    SeekBar clearance = (SeekBar) findViewById(R.id.seekBarClearance);
    SeekBar margins = (SeekBar) findViewById(R.id.seekBarMargins);
    SeekBar inclination = (SeekBar) findViewById(R.id.seekBarInclination);
    mClearance = (TextView) findViewById(R.id.tvClearance);
    mMargins = (TextView) findViewById(R.id.tvMargins);
    mInclination = (TextView) findViewById(R.id.tvInclination);
    chooseLanguage = (Spinner) findViewById(R.id.spinnerLanguages);

    SharedPreferences prefs = getSharedPreferences("settings", MODE_PRIVATE);
    mClearanceValue = prefs.getInt("mClearanceValue", 1000);
    mMarginsValue = prefs.getInt("mMarginsValue", 10);
    mInclinationValue = prefs.getInt("mInclinationValue", 30);
    chooseLanguage.setSelection(prefs.getInt("language", 0));

    // Set up spinner
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActionBar().getThemedContext(),
            R.array.languages, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    chooseLanguage.setAdapter(adapter);//from  w ww  . j  ava2  s  . c o m
    // @formatter:off
    if (Locale.getDefault().getLanguage().equals("en"))
        chooseLanguage.setSelection(0);
    if (Locale.getDefault().getLanguage().equals("fr"))
        chooseLanguage.setSelection(1);
    if (Locale.getDefault().getLanguage().equals("de"))
        chooseLanguage.setSelection(2);
    if (Locale.getDefault().getLanguage().equals("es"))
        chooseLanguage.setSelection(3);
    if (Locale.getDefault().getLanguage().equals("ru"))
        chooseLanguage.setSelection(4);

    // Set seekbar progress
    clearance.setProgress(mClearanceValue);
    margins.setProgress(mMarginsValue);
    inclination.setProgress(mInclinationValue);

    // Display values
    mClearance.setText(mClearanceValue + "m");
    mMargins.setText(mMarginsValue + "%");
    setInclinationText();

    clearance.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            String value = NumberFormat.getNumberInstance(Locale.getDefault()).format(progress);
            mClearance.setText(value + "m");
            mClearanceValue = progress;
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });
    margins.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            mMargins.setText(progress + "%");
            mMarginsValue = progress;
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });
    inclination.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            mInclinationValue = progress;
            setInclinationText();
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });
    chooseLanguage.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            language = langCode[chooseLanguage.getSelectedItemPosition()];
            onConfigurationChanged(getResources().getConfiguration());
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });

}

From source file:com.ijunes.transitions.StoryDetailActivity.java

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

    if (savedInstanceState == null) {
        // Load the data from the intent on first pass
        Intent intent = getIntent();/*from   w  w  w  . j a  v  a2s  .  c o  m*/
        String story_id = intent.getStringExtra(ARG_STORY_ID);
        mItem = StoryContent.STORY_MAP.get(story_id);
    }

    // Get hold of some relevant content
    final ViewGroup container = (ViewGroup) findViewById(R.id.container);

    // What are the layouts we should be able to transition between
    List<Integer> sceneLayouts = Arrays.asList(R.layout.content_scene_00, R.layout.content_scene_01,
            R.layout.content_scene_02);
    // Create the scenes
    sceneList = new ArrayList<Scene>();
    for (int layout : sceneLayouts) {
        // Create the scene
        Scene scene = Scene.getSceneForLayout(container, layout, this);
        // Just before the transition starts, ensure that the content has been loaded
        scene.setEnterAction(new Runnable() {
            @Override
            public void run() {
                addContentToViewGroup(container);
            }
        });
        // Save the scene into
        sceneList.add(scene);
    }

    // Build the transition manager
    TransitionInflater transitionInflater = TransitionInflater.from(this);
    mTransitionManager = transitionInflater.inflateTransitionManager(R.transition.story_transition_manager,
            container);

    // Show the Up button in the action bar.
    final ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);

        // Specify we want some tabs
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        // Create a listener to cope with tab changes
        tabListener = new ActionBar.TabListener() {
            @Override
            public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
                // If there's a scene for this tab index, then transition to it

                if (tab.getPosition() <= sceneList.size()) {
                    tabPosition = tab.getPosition();
                    performTransitionToScene(sceneList.get(tab.getPosition()));
                }
            }

            @Override
            public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
                // Can ignore this event
            }

            @Override
            public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
                // Can ignore this event
            }

            public void performTransitionToScene(Scene scene) {
                mTransitionManager.transitionTo(scene);
            }
        };

        // Add some tabs
        for (int i = 0; i < sceneList.size(); i++) {
            actionBar.addTab(actionBar.newTab().setText("Scene " + i).setTabListener(tabListener));
        }
    }

    // Load the first scene
    sceneList.get(0).enter();
}

From source file:com.gmail.emerssso.srbase.EditSRActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.edit_sr_activity);

    ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setTitle(R.string.edit_sr);
    }/*from  w w  w.ja  v  a 2 s. co m*/

    mSRNumber = (EditText) findViewById(R.id.SRNumber);
    mCustomer = (EditText) findViewById(R.id.customerName);
    mModelNumber = (EditText) findViewById(R.id.modelNumber);
    mSerialNumber = (EditText) findViewById(R.id.serialNumber);
    mDescription = (EditText) findViewById(R.id.description);
    mBusinessName = (EditText) findViewById(R.id.businessName);
    /* The Daily Button opens a dialog to add a new daily
    associated with this SR. */
    Button mDaily = (Button) findViewById(R.id.add_daily);
    /* The Part Button opens a new dialog to add a new part
    associated with this SR.. */
    Button mPart = (Button) findViewById(R.id.add_part);
    /* The Confirm Button saves the SR to the database. */
    Button mEnter = (Button) findViewById(R.id.confirm);

    Bundle extras = getIntent().getExtras();

    savedUri = (savedInstanceState == null) ? null
            : (Uri) savedInstanceState.getParcelable(SRContentProvider.SR_CONTENT_ITEM_TYPE);

    if (extras != null) {
        savedUri = extras.getParcelable(SRContentProvider.SR_CONTENT_ITEM_TYPE);
        fillData(savedUri);
    }

    if (savedUri != null) {
        myId = savedUri.getLastPathSegment();
    }

    mEnter.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mSRNumber.getText().toString().length() == 0) {
                Toast.makeText(EditSRActivity.this, "SR Number missing", Toast.LENGTH_LONG).show();
            } else {
                saveState();
                setResult(RESULT_OK);
                finish();
            }
        }
    });

    mPart.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            saveState();
            addPart();
        }
    });

    mDaily.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            saveState();
            addDaily();
        }
    });
}

From source file:com.vmihalachi.turboeditor.activity.HomeActivity.java

/**
 * Setup the navigation drawer/*from   ww w.j  a va 2s.c om*/
 */
private void setupNavigationDrawer() {
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    /* Action Bar */
    final ActionBar ab = getActionBar();
    ab.setDisplayHomeAsUpEnabled(true);
    ab.setHomeButtonEnabled(true);
    /* Navigation drawer */
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer,
            R.string.nome_app_turbo_editor, R.string.nome_app_turbo_editor) {

        /**
         * {@inheritDoc}
         */
        @Override
        public void onDrawerClosed(View view) {
            invalidateOptionsMenu();
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public void onDrawerOpened(View drawerView) {
            invalidateOptionsMenu();
        }
    };
    /* link the mDrawerToggle to the Drawer Layout */
    mDrawerLayout.setDrawerListener(mDrawerToggle);
}

From source file:au.com.wallaceit.reddinator.ViewAllSubredditsActivity.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    global = ((GlobalObjects) getApplicationContext());
    ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }//from   w  w  w  .ja  v a  2  s  .c o  m
    setContentView(R.layout.viewallsubreddit);
    // setup list view
    listview = getListView();
    listview.setTextFilterEnabled(true);
    listview.setEmptyView(findViewById(R.id.subredditload));
    listview.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent intent = new Intent(); // update subreddit without adding to list
            intent.putExtra("subreddit", sreddits.get(position));
            setResult(RESULT_SET_SUBREDDIT, intent);
            finish();
        }
    });
    // get empty view text for easy access later
    emptyview = (TextView) findViewById(R.id.poploadtxt);
    // setup search buttons
    searchbox = (EditText) this.findViewById(R.id.searchbox);
    searchbox.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_UP) {
                search(v.getText().toString());
            }
            return true;
        }

    });
    ImageView searchbtn = (ImageView) this.findViewById(R.id.searchbutton);
    searchbtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            String query = searchbox.getText().toString();
            if (!query.equals("")) {
                search(query);
            } else {
                new AlertDialog.Builder(ViewAllSubredditsActivity.this).setTitle("No Query")
                        .setMessage("Please enter something to search for").show();
            }
        }
    });
}

From source file:com.herasymc.cmput301counter.CounterSummaryActivity.java

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

    list = CounterList.getInstance(getApplicationContext());
    id = (int) getIntent().getLongExtra("id", -1); // if id is -1, summarize all counters

    // Set up the action bar to show a dropdown list.
    final ActionBar actionBar = getActionBar();
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    // Show the Up button in the action bar.
    actionBar.setDisplayHomeAsUpEnabled(true);

    // 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,/*from   w  w  w  .j  a v a  2s . com*/
                    new String[] { getString(R.string.title_summary_minute),
                            getString(R.string.title_summary_hour), getString(R.string.title_summary_day),
                            getString(R.string.title_summary_week), getString(R.string.title_summary_month) }),
            this);
}

From source file:org.catnut.ui.PluginsActivity.java

private void injectPager(ActionBar bar, Bundle savedInstanceState) {
    // not show the bar, but not hide, u known what i mean?
    bar.setDisplayHomeAsUpEnabled(false);
    bar.setDisplayShowHomeEnabled(false);
    bar.setDisplayShowTitleEnabled(false);
    setContentView(R.layout.pager);// w  w w  .  j  a va  2s  . c  o m

    mIds = getIntent().getIntegerArrayListExtra(PLUGINS);
    if (savedInstanceState == null) {
        mIds.add(0); // add an alt one...
    }
    Collections.shuffle(mIds); // shuffle it :-)
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setOffscreenPageLimit(2);
    mViewPager.setPageMargin(10);

    mViewPager.setPageMarginDrawable(new ColorDrawable(getResources().getColor(R.color.tab_selected)));
    mViewPager.setAdapter(new FragmentPagerAdapter(getFragmentManager()) {
        @Override
        public Fragment getItem(int position) {
            Fragment fragment;
            switch (mIds.get(position)) {
            case PluginsPrefFragment.ZHIHU:
                fragment = ZhihuItemsFragment.getFragment();
                break;
            case PluginsPrefFragment.FANTASY:
                fragment = FantasyFallFragment.getFragment();
                break;
            default:
                fragment = new PlaceHolderFragment();
                break;
            }
            return fragment;
        }

        @Override
        public int getCount() {
            return mIds.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            switch (mIds.get(position)) {
            case PluginsPrefFragment.ZHIHU:
                return getString(R.string.read_zhihu);
            case PluginsPrefFragment.FANTASY:
                return getString(R.string.fantasy);
            default:
                return "more plugins...";
            }
        }
    });
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            getActionBar().setSelectedNavigationItem(position);
        }
    });
    for (int i = 0; i < mViewPager.getAdapter().getCount(); i++) {
        bar.addTab(bar.newTab().setText(mViewPager.getAdapter().getPageTitle(i)).setTabListener(this));
    }
}

From source file:com.rastating.droidbeard.fragments.NavigationDrawerFragment.java

/**
 * Users of this fragment must call this method to set up the navigation drawer interactions.
 *
 * @param fragmentId   The android:id of this fragment in its activity's layout.
 * @param drawerLayout The DrawerLayout containing this fragment's UI.
 *///  w ww  .ja v  a  2 s  . c  o m
public void setUp(int fragmentId, DrawerLayout drawerLayout) {
    mFragmentContainerView = getActivity().findViewById(fragmentId);
    mDrawerLayout = drawerLayout;

    // set a custom shadow that overlays the main content when the drawer opens
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    // set up the drawer's list view with items and click listener

    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);

    // ActionBarDrawerToggle ties together the the proper interactions
    // between the navigation drawer and the action bar app icon.
    mDrawerToggle = new ActionBarDrawerToggle(getActivity(), /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.ic_menu_white_24dp, /* nav drawer image to replace 'Up' caret */
            R.string.navigation_drawer_open, /* "open drawer" description for accessibility */
            R.string.navigation_drawer_close /* "close drawer" description for accessibility */
    ) {
        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            if (!isAdded()) {
                return;
            }

            getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu()
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            if (!isAdded()) {
                return;
            }

            if (!mUserLearnedDrawer) {
                // The user manually opened the drawer; store this flag to prevent auto-showing
                // the navigation drawer automatically in the future.
                mUserLearnedDrawer = true;
                SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
                sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply();
            }

            getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu()
        }
    };

    // If the user hasn't 'learned' about the drawer, open it to introduce them to the drawer,
    // per the navigation drawer design guidelines.
    if (!mUserLearnedDrawer && !mFromSavedInstanceState) {
        mDrawerLayout.openDrawer(mFragmentContainerView);
    }

    // Defer code dependent on restoration of previous instance state.
    mDrawerLayout.post(new Runnable() {
        @Override
        public void run() {
            mDrawerToggle.syncState();
        }
    });

    mDrawerLayout.setDrawerListener(mDrawerToggle);
}

From source file:org.ounl.lifelonglearninghub.nfcecology.swipe.TimeLineActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_collection_demo);

    Bundle extras = getIntent().getExtras();

    if (extras != null) {
        sGoalId = extras.getString(Goal.KEY_NAME);
    }/*w  w  w .  ja v a 2s.  com*/

    System.out.println(" RECIBIDO GOAL ID " + sGoalId);

    // BTB HACER CONSULTA DEL TAG_ID PARA ESE GOAL_ID
    // BTB HACER CONSULTA DE ACTIVITIES PARA ESE TAG ID
    // BTB AGRUPAR DATOS POR DIA EN SUMA DE MINUTOS EN UN ARRAY
    // Ahora le estas pasando los tagactivity a cholon
    // EL ARRAY SE LO PASAS EN DayFragmentStatePagerAdapter(getSupportFragmentManager());

    list = new ArrayList<Tagctivity>();
    populateList();

    // Create an adapter that when requested, will return a fragment representing an object in
    // the collection.
    // 
    // ViewPager and its adapters use support library fragments, so we must use
    // getSupportFragmentManager.
    mDemoCollectionPagerAdapter = new DayFragmentStatePagerAdapter(getSupportFragmentManager(), list);

    // Set up action bar.
    final ActionBar actionBar = getActionBar();

    // Specify that the Home button should show an "Up" caret, indicating that touching the
    // button will take the user one step up in the application's hierarchy.
    actionBar.setDisplayHomeAsUpEnabled(true);

    // Set up the ViewPager, attaching the adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mDemoCollectionPagerAdapter);
}