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:net.czlee.debatekeeper.PrepTimeBellsEditActivity.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_prep_time_bells_edit);

    // Open the preferences file and instantiate the PrepTimeBellsManager
    SharedPreferences prefs = getSharedPreferences(PrepTimeBellsManager.PREP_TIME_BELLS_PREFERENCES_NAME,
            MODE_PRIVATE);/*from   www. ja  v a  2  s  .  c  o m*/
    mPtbm = new PrepTimeBellsManager(this);
    mPtbm.loadFromPreferences(prefs);

    // Populate the list
    refreshBellsList();

    // Set the OnClickListeners
    ((Button) findViewById(R.id.prepTimeBellsEditor_addBellButton))
            .setOnClickListener(new AddButtonOnClickListener());
    ((Button) findViewById(R.id.prepTimeBellsEditor_clearAllButton))
            .setOnClickListener(new ClearButtonOnClickListener());

    // Register a context menu for the bells list items
    registerForContextMenu(findViewById(R.id.prepTimeBellsEditor_bellsList));

    // Register for the list to show a toast on non-long click
    ((ListView) findViewById(R.id.prepTimeBellsEditor_bellsList))
            .setOnItemClickListener(new OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
                    Toast.makeText(PrepTimeBellsEditActivity.this, R.string.prepTimeBellsEditor_contextMenu_tip,
                            Toast.LENGTH_SHORT).show();
                }
            });

    // Set the action bar
    ActionBar bar = getActionBar();
    if (bar != null)
        bar.setDisplayHomeAsUpEnabled(true);
}

From source file:us.cboyd.android.dicom.DcmBrowser.java

/** navigateUp replicates "Back" functionality for the Home/Up key. */
public boolean navigateUp() {
    File temp = mListFragment.getDir();
    if (mListFragment.isVisible()) {
        if (ExternalIO.isRoot(temp)) {
            ActionBar actionBar = getActionBar();
            actionBar.setHomeButtonEnabled(false);
            actionBar.setDisplayHomeAsUpEnabled(false);
            return false;
        } else {/*from  ww w . j  av a 2 s.com*/
            temp = temp.getParentFile();
            mListFragment.setDir(temp);
        }
    }
    onDirectorySelected(temp);
    return true;
}

From source file:com.lucapernini.misapp.Registration.java

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

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

    alert = new AlertDialog.Builder(this);

    usernameET = (EditText) findViewById(R.id.editUsername);
    nomeET = (EditText) findViewById(R.id.editNome);
    cognomeET = (EditText) findViewById(R.id.editCognome);
    emailET = (EditText) findViewById(R.id.editEmail);
    checkLicense = (CheckBox) findViewById(R.id.checklicense);
    OK = (Button) findViewById(R.id.buttonOK);
    OK.setEnabled(false);/* w w w .j a v a 2 s  . c  o  m*/
    checkLicense.setClickable(false);

    checkLicense.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                OK.setEnabled(true);
            } else {
                OK.setEnabled(false);
            }
        }
    });

    OK.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            username = usernameET.getText().toString();
            nome = nomeET.getText().toString();
            cognome = cognomeET.getText().toString();
            email = emailET.getText().toString();
            if (!username.isEmpty() && !nome.isEmpty() && !cognome.isEmpty() && !email.isEmpty()
                    && email.contains("@")) {
                sendPostRequestRegistrationStep1(username, nome, cognome, email);
            } else {
                showToast("Controlla i campi inseriti! Non lasciarli vuoti, ed inserisci la mail corretta");
            }
        }
    });

}

From source file:com.hro.museapp.map.ClusteringMapActivity.java

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

    listType = getIntent().getIntExtra("type", TYPE_ALL);

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

    FragmentManager fm = getSupportFragmentManager();
    SupportMapFragment f = (SupportMapFragment) fm.findFragmentById(R.id.map);
    map = f.getExtendedMap();/*from   w  ww  .  j  ava2  s  . co m*/

    gps = new GPSTracker(ClusteringMapActivity.this);
    //gps = PlacesLoader.getGPS();

    // mapView = (MapView) this.findViewById(R.id.map);

    float cameraZoom = 8;
    LatLng cameraLatLng = new LatLng(52.281602, 5.503235);
    if (savedInstanceState != null) {
        double savedLat = savedInstanceState.getDouble("lat");
        double savedLng = savedInstanceState.getDouble("lng");
        cameraLatLng = new LatLng(savedLat, savedLng);

        cameraZoom = savedInstanceState.getFloat("zoom", 12);
    }
    map.moveCamera(CameraUpdateFactory.newLatLngZoom(cameraLatLng, cameraZoom));

    map.setClustering(new ClusteringSettings().iconDataProvider(new DemoIconProvider(getResources()))
            .addMarkersDynamically(true));
    map.setMyLocationEnabled(true);

    map.setInfoWindowAdapter(new InfoWindowAdapter() {

        private TextView tv;
        {
            tv = new TextView(ClusteringMapActivity.this);
            tv.setTextColor(Color.BLACK);
        }

        private Collator collator = Collator.getInstance();
        private Comparator<Marker> comparator = new Comparator<Marker>() {
            public int compare(Marker lhs, Marker rhs) {
                String leftTitle = lhs.getTitle();
                String rightTitle = rhs.getTitle();
                if (leftTitle == null && rightTitle == null) {
                    return 0;
                }
                if (leftTitle == null) {
                    return 1;
                }
                if (rightTitle == null) {
                    return -1;
                }
                return collator.compare(leftTitle, rightTitle);
            }
        };

        @Override
        public View getInfoWindow(Marker marker) {
            return null;
        }

        @Override
        public View getInfoContents(Marker marker) {
            if (marker.isCluster()) {
                List<Marker> markers = marker.getMarkers();
                int i = 0;
                String text = "";
                while (i < 3 && markers.size() > 0) {
                    Marker m = Collections.min(markers, comparator);
                    String title = m.getTitle();
                    if (title == null) {
                        break;
                    }
                    text += title + "\n";
                    markers.remove(m);
                    i++;
                }
                if (text.length() == 0) {
                    text = "Markers with mutable data";
                } else if (markers.size() > 0) {
                    text += "and " + markers.size() + " more...";
                } else {
                    text = text.substring(0, text.length() - 1);
                }
                tv.setText(text);
                return tv;
            } else {
                String title = marker.getTitle();
                tv.setText(title);
                return tv;
            }
        }
    });

    map.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {

        @Override
        public void onInfoWindowClick(Marker marker) {
            if (marker.isCluster()) {
                List<Marker> markers = marker.getMarkers();
                Builder builder = LatLngBounds.builder();
                for (Marker m : markers) {
                    builder.include(m.getPosition());
                }
                LatLngBounds bounds = builder.build();
                map.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds,
                        getResources().getDimensionPixelSize(R.dimen.padding)));
            } else {
                // String title = marker.getTitle();
                // String mid = MarkerGenerator.mapPlaceToId.get(title);
                String mid = (String) marker.getData();

                Intent in = new Intent(getApplicationContext(), ShowPlaceActivity.class);
                // sending mid to next activity
                in.putExtra(MarkerGenerator.TAG_MID, mid);

                // starting new activity and expecting some response back
                startActivityForResult(in, 100);
            }
        }
    });

    // MarkerGenerator.addMarkers(map);
    new AddMarkersInBackground().execute();

}

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

/**
 * (non-Javadoc)//w  ww. j ava 2  s  . c o m
 *
 * @see android.support.v4.app.FragmentActivity#onCreate(android.os.Bundle)
 */
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    global = ((GlobalObjects) ViewRedditActivity.this.getApplicationContext());
    prefs = PreferenceManager.getDefaultSharedPreferences(ViewRedditActivity.this);
    // set window flags
    getWindow().requestFeature(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
    getWindow().requestFeature(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
    // request loading bar first
    getWindow().requestFeature(Window.FEATURE_PROGRESS);
    // get actionbar and set home button, pad the icon
    ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    ImageView view = (ImageView) findViewById(android.R.id.home);
    if (view != null) {
        view.setPadding(5, 0, 5, 0);
    }
    // set content view
    setContentView(R.layout.viewreddit);
    // Setup TabHost
    initialiseTabHost(savedInstanceState);
    if (savedInstanceState != null) {
        mTabHost.setCurrentTabByTag(savedInstanceState.getString("tab")); //set the tab as per the saved state
    }
    redditItemId = getIntent().getStringExtra(WidgetProvider.ITEM_ID);
    widgetId = getIntent().getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, 0);
    feedposition = getIntent().getIntExtra("itemposition", 0);
    // Get selected item from feed and user vote preference
    JSONObject currentFeedItem = global.getFeedObject(prefs, widgetId, feedposition, redditItemId);
    try {
        userLikes = currentFeedItem.getString("likes");
    } catch (JSONException e) {
        e.printStackTrace();
    }
    //System.out.println("User likes post: " + userLikes);
}

From source file:blackman.matt.infinitebrowser.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.
 *//* ww w .  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_drawer, /* 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 */
    ) {
        /**
         * Handles the drawer being closed.
         *
         * @param drawerView The drawer being closed.
         */
        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            if (!isAdded()) {
                return;
            }

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

        /**
         * Handles the drawer being opened.
         *
         * @param drawerView The drawer being opened.
         */
        @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();
            }

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

    mDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String boardRoot = "/tech/";
            if (view instanceof TextView) {
                boardRoot = ((TextView) view).getText().toString();
            }

            FragmentManager fragmentManager = getFragmentManager();
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

            Board newBoard = Board.newInstance(boardRoot);

            fragmentTransaction.replace(R.id.container, newBoard, boardRoot);
            fragmentTransaction.addToBackStack(null);

            fragmentTransaction.commit();

            closeDrawer();
        }
    });

    // 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:com.melbournestore.activities.PlateActivity.java

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

    SysApplication.initImageLoader(this);

    SysApplication.getInstance().addActivity(this);

    // 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);

    Intent intent = getIntent();//from   w  ww.  j  ava  2s . c o m
    mShopId = intent.getIntExtra("shopid", 0);
    mShopName = intent.getStringExtra("shopName");

    mItemThread = new ItemManagerThread(mHandler, this, mShopId);
    mItemThread.start();
    progress = new ProgressDialog(this, R.style.dialog_loading);
    progress.show();

    getActionBar().setTitle(mShopName);

    sumNumberPrice = MelbourneUtils.sum_item_number_price(PlateActivity.this);

    totalPrice = sumNumberPrice.getPrice();
    totalNum = sumNumberPrice.getNumber();

    mPlatesList = (ListView) findViewById(R.id.plates_list);

    options = new DisplayImageOptions.Builder().showStubImage(R.drawable.loading_ads) //ImageView
            .showImageForEmptyUri(R.drawable.loading_ads) //image?
            .showImageOnFail(R.drawable.loading_ads) //image
            .cacheInMemory(true) //
            .cacheOnDisc(true) //?
            .build();

    mPlateListAdapter = new PlateListAdapter(this, mHandler, options, mItems);
    mPlatesList.setAdapter(mPlateListAdapter);

    mConfirmChoice = (Button) findViewById(R.id.confirm_choice);
    mConfirmChoice.bringToFront();

    mConfirmChoice.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            Intent intent = new Intent(PlateActivity.this, ShoppingCartActivity.class);
            startActivity(intent);

        }

    });

    mTotalPrice = (TextView) findViewById(R.id.confirm_price);
    mTotalPrice.setText("$" + String.valueOf(totalPrice));

    mTotalNum = (TextView) findViewById(R.id.plate_num_total);
    mTotalNum.setText(String.valueOf(totalNum));

}

From source file:us.cboyd.android.dicom.DcmBrowser.java

@Override
public void onBackPressed() {
    File temp = mListFragment.getDir();
    if (!mListFragment.isVisible()) {
        // Assume we're jumping back to the ListFragment
        if (ExternalIO.isRoot(temp)) {
            ActionBar actionBar = getActionBar();
            actionBar.setHomeButtonEnabled(false);
            actionBar.setDisplayHomeAsUpEnabled(false);
        }//  ww  w.  ja v  a 2 s.c o m
        FragmentManager fm = getFragmentManager();
        if (fm.getBackStackEntryCount() > 0) {
            fm.popBackStack();
        } else {
            super.onBackPressed();
        }

        // If the directory is the external storage directory or there is no parent,
        // super.onBackPressed(). Else go to parent directory.
    } else if (ExternalIO.isRoot(temp)) {
        super.onBackPressed();
    } else {
        temp = temp.getParentFile();
        mListFragment.setDir(temp);
    }
    onDirectorySelected(temp);
}

From source file:us.cboyd.android.dicom.DcmBrowser.java

public void onFileSelected(int position, ArrayList<String> fileList, File currDir) {
    // The user selected a DICOM file from the DcmListFragment
    position -= 1;//from   w w  w .ja va2s. c o m
    if ((position < 0) || (position > fileList.size())) {
        // TODO: Error
        return;
    }

    if (mFragmented && mListFragment.isVisible()) {
        // If we're in the one-pane layout and need to swap fragments

        // Enable the Home/Up button to allow the user to go back to 
        ActionBar actionBar = getActionBar();
        actionBar.setHomeButtonEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);

        // Create fragment and give it an argument for the selected article
        Bundle args = new Bundle();
        args.putInt(DcmVar.POSITION, position);
        args.putStringArrayList(DcmVar.FILELIST, fileList);
        args.putString(DcmVar.CURRDIR, currDir.getPath());
        mInfoFragment.setArguments(args);
        FragmentTransaction transaction = getFragmentManager().beginTransaction();

        // Replace whatever is in the fragment_container view with this fragment,
        // and add the transaction to the back stack so the user can navigate back
        transaction.replace(R.id.fragment_container, mInfoFragment);
        transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        transaction.addToBackStack(null).commit();

        // set up the drawer's list view with items and click listener
        mDrawerList.setAdapter(mListFragment.getListAdapter());
    } else {
        // If we're in the two-pane layout or already displaying the DcmInfoFragment

        // Call a method in the DcmInfoFragment to update its content
        mInfoFragment.updateDicomInfo(position, fileList, currDir.getPath());
    }
    setTitle(fileList.get(position));
}

From source file:com.android.camera.settings.CameraSettingsActivity.java

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

    FatalErrorHandler fatalErrorHandler = new FatalErrorHandlerImpl(this);
    boolean hideAdvancedScreen = false;

    try {//from  w w w .ja  v a  2  s  . c om
        mOneCameraManager = OneCameraModule.provideOneCameraManager();
    } catch (OneCameraException e) {
        // Log error and continue. Modules requiring OneCamera should check
        // and handle if null by showing error dialog or other treatment.
        fatalErrorHandler.onGenericCameraAccessFailure();
    }

    // Check if manual exposure is available, so we can decide whether to
    // display Advanced screen.
    try {
        CameraId frontCameraId = mOneCameraManager.findFirstCameraFacing(Facing.FRONT);
        CameraId backCameraId = mOneCameraManager.findFirstCameraFacing(Facing.BACK);

        // The exposure compensation is supported when both of the following conditions meet
        //   - we have the valid camera, and
        //   - the valid camera supports the exposure compensation
        boolean isExposureCompensationSupportedByFrontCamera = (frontCameraId != null) && (mOneCameraManager
                .getOneCameraCharacteristics(frontCameraId).isExposureCompensationSupported());
        boolean isExposureCompensationSupportedByBackCamera = (backCameraId != null) && (mOneCameraManager
                .getOneCameraCharacteristics(backCameraId).isExposureCompensationSupported());

        // Hides the option if neither front and back camera support exposure compensation.
        if (!isExposureCompensationSupportedByFrontCamera && !isExposureCompensationSupportedByBackCamera) {
            hideAdvancedScreen = true;
        }
    } catch (OneCameraAccessException e) {
        fatalErrorHandler.onGenericCameraAccessFailure();
    }

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

    String prefKey = getIntent().getStringExtra(PREF_SCREEN_EXTRA);
    CameraSettingsFragment dialog = new CameraSettingsFragment();
    Bundle bundle = new Bundle(1);
    bundle.putString(PREF_SCREEN_EXTRA, prefKey);
    bundle.putBoolean(HIDE_ADVANCED_SCREEN, hideAdvancedScreen);
    dialog.setArguments(bundle);
    getFragmentManager().beginTransaction().replace(android.R.id.content, dialog).commit();
}