Example usage for android.view MenuItem setIcon

List of usage examples for android.view MenuItem setIcon

Introduction

In this page you can find the example usage for android.view MenuItem setIcon.

Prototype

public MenuItem setIcon(@DrawableRes int iconRes);

Source Link

Document

Change the icon associated with this item.

Usage

From source file:de.grobox.liberario.activities.MapStationsActivity.java

private void toggleGPS() {
    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                Manifest.permission.ACCESS_FINE_LOCATION)) {
            Toast.makeText(this,
                    "You need to grant the location permission in order to see your current position on the map.",
                    Toast.LENGTH_LONG).show();
        } else {//  w  w  w  .  j  a  v a  2 s  .co  m
            ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION },
                    MainActivity.PR_ACCESS_FINE_LOCATION_MAPS);
        }
        return;
    }

    if (mLocProvider == null)
        setupGPS(null);

    MenuItem gpsItem = mMenu.findItem(R.id.action_use_gps);

    if (mGps) {
        mGps = false;
        mLocProvider.stopLocationProvider();
        gpsItem.setIcon(R.drawable.ic_gps);
    } else {
        mGps = true;
        mLocProvider.startLocationProvider(mMyLocationOverlay);
        gpsItem.setIcon(R.drawable.ic_gps_off);
    }
}

From source file:com.artur.softwareproject.Main.java

private void stopRecording() {
    final Context context = this;

    AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
        @Override//  w  w  w.j av a 2 s.c  o m
        protected void onPreExecute() {
            pd = new ProgressDialog(context);
            pd.setTitle("Processing...");
            pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);
            pd.setMessage("Please wait.");
            pd.setCancelable(false);
            pd.setIndeterminate(true);
            pd.show();
        }

        @Override
        protected Void doInBackground(Void... params) {
            modelConstructed = rService.create3dModel();

            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            if (pd != null) {
                pd.dismiss();
            }

            if (rBound) {
                unbindService(mConnection);
                rBound = false;
            }

            MenuItem item = mainMenu.findItem(R.id.record_data);

            item.setIcon(R.drawable.ic_action_save);

            Animation a = AnimationUtils.loadAnimation(context, R.anim.textupslide);
            TextView tv = (TextView) findViewById(R.id.recordClock);
            tv.startAnimation(a);

            recordClock.setVisibility(View.GONE);

            recording = false;

            if (modelConstructed) {
                Toast.makeText(getApplicationContext(), "Recording stopped.\n3D model created.",
                        Toast.LENGTH_LONG).show();
            } else {
                Toast.makeText(getApplicationContext(), "Recording stopped.\n3D model creation failed.",
                        Toast.LENGTH_LONG).show();
            }
        }
    };

    task.execute((Void[]) null);

}

From source file:com.velli.passwordmanager.ActivityMain.java

public void setupDrawerGroups() {
    PasswordDatabaseHandler.getInstance().getLastLoginDate(new OnGetLastLoginDateListener() {
        @Override/*from  www  .j av a  2 s .co  m*/
        public void onLastLoginDate(long millis) {
            if (mNavigationDrawerFragment != null && mNavigationDrawerFragment.getHeaderView(0) != null) {
                RobotoTextView text = (RobotoTextView) mNavigationDrawerFragment.getHeaderView(0)
                        .findViewById(R.id.navigation_drawer_header_last_login);
                if (text != null) {
                    text.setText(Utils.getDateTimeString(millis));
                }
            }
        }
    });
    PasswordDatabaseHandler.getInstance().getGroups(new OnGetGroupsListener() {
        @Override
        public void onGetValues(ArrayList<String> list) {
            if (mNavigationDrawerFragment != null && mNavigationDrawerFragment.getMenu() != null
                    && list != null) {
                Menu menu = mNavigationDrawerFragment.getMenu().findItem(R.id.navigation_item_custom_group)
                        .getSubMenu();
                int i = 0;
                MenuItem item;
                for (String group : list) {
                    item = menu.add(R.id.navigation_group_groups, R.id.navigation_item_custom_group, i, group);
                    item.setIcon(R.drawable.ic_type_group);
                    i++;
                }
            }
        }
    });

}

From source file:com.example.tj.weather.WeatherActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the toolbar/actionbar, if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);

    MenuItem searchItem = menu.findItem(R.id.city_search);
    Drawable searchIcon = searchItem.getIcon();
    searchIcon.mutate().setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN);
    searchItem.setIcon(searchIcon);

    MenuItem locationSearchItem = menu.findItem(R.id.location_search);
    Drawable locationSearchIcon = locationSearchItem.getIcon();
    locationSearchIcon.mutate().setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN);
    searchItem.setIcon(searchIcon);// w w w. j a va2 s . co m

    return true;
}

From source file:com.google.android.apps.iosched.ui.MyScheduleFragment.java

@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
    MenuInflater inflater = mode.getMenuInflater();
    inflater.inflate(R.menu.sessions_context, menu);
    MenuItem starMenuItem = menu.findItem(R.id.menu_star);
    starMenuItem.setTitle(R.string.description_remove_schedule);
    starMenuItem.setIcon(R.drawable.ic_action_remove_schedule);
    return true;//from w w w  . j  a  v  a  2  s  . com
}

From source file:org.geometerplus.android.fbreader.network.NetworkLibraryActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);

    if (myOptionsMenuActions.isEmpty()) {
        fillOptionsMenuList();//from  w ww.  j a v  a 2  s. com
    }

    for (Action a : myOptionsMenuActions) {
        final MenuItem item = menu.add(0, a.Code, Menu.NONE, "");
        if (a.IconId != -1) {
            item.setIcon(a.IconId);
        }
    }
    return true;
}

From source file:t0mm13b.dmesglog.ui.DMesgViewer.java

private void handlePause(MenuItem item) {
    if (this.mDmesgLogHandler.getIsPaused())
        return;/*from   www  . j  ava  2s.  c  o m*/
    this.mDmesgLogHandler.Pause();
    item.setIcon(R.drawable.ic_media_play);
    item.setTitle(getString(R.string.menu_resume));
    fixUpTitle(true);
}

From source file:t0mm13b.dmesglog.ui.DMesgViewer.java

private void handleResume(MenuItem item) {
    if (!this.mDmesgLogHandler.getIsPaused())
        return;/*w  w w .  j  a  v a 2s .  c om*/
    this.mDmesgLogHandler.Resume();
    item.setIcon(R.drawable.ic_media_pause);
    item.setTitle(getString(R.string.menu_pause));
    fixUpTitle(false);
}

From source file:com.ibm.mf.geofence.demo.MapsActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu, menu);
    MenuItem item = menu.findItem(R.id.action_tracking);
    item.setIcon(trackingEnabled ? R.mipmap.on : R.mipmap.off);
    return true;//from  www. j av  a 2  s  . c  o  m
}

From source file:uk.org.openseizuredetector.MainActivity.java

/**
 * Start the SdServer service/*from w  w w  .j ava2  s . co  m*/
 */
private void startServer() {
    // Start the server
    sdServerIntent = new Intent(MainActivity.this, SdServer.class);
    sdServerIntent.setData(Uri.parse("Start"));
    getApplicationContext().startService(sdServerIntent);

    // Change the action bar icon to show the option to stop the service.
    if (mOptionsMenu != null) {
        Log.v(TAG, "Changing menu icons");
        MenuItem menuItem = mOptionsMenu.findItem(R.id.action_start_stop);
        menuItem.setIcon(R.drawable.stop_server);
        menuItem.setTitle("Stop Server");
    } else {
        Log.v(TAG, "mOptionsMenu is null - not changing icons!");
    }
}