Example usage for android.view MenuItem getItemId

List of usage examples for android.view MenuItem getItemId

Introduction

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

Prototype

public int getItemId();

Source Link

Document

Return the identifier for this menu item.

Usage

From source file:ota.otaupdates.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.action_refresh) {
        get_builds();/* w ww .j  ava  2 s. c o m*/
        pb.setVisibility(View.VISIBLE);
    } else if (item.getItemId() == R.id.action_settings) {
        Intent settings = new Intent(MainActivity.this, Settings.class);
        startActivityForResult(settings, RESULT_SETTINGS);
    }

    return true;
}

From source file:cc.siara.csv_ml_demo.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Context menu not used
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }/*w  w  w .  ja v a  2  s .c  om*/
    return super.onOptionsItemSelected(item);
}

From source file:com.microsoft.mimickeralarm.appcore.AlarmListFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        launchChildActivity(AlarmGlobalSettingsActivity.class);
        return true;
    } else if (id == R.id.action_learn_more) {
        launchChildActivity(LearnMoreActivity.class);
        return true;
    } else if (id == R.id.action_add_alarm) {
        addAlarm();//w  ww.  ja  v  a 2s  .co  m
    }
    return super.onOptionsItemSelected(item);
}

From source file:dtu.ds.warnme.app.activity.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.action_login) {
        Log.d(TAG, "Showing login dialog...");

        FragmentTransaction ft = getFragmentManager().beginTransaction();
        Fragment prev = getFragmentManager().findFragmentByTag(LoginDialog.class.getName());
        if (prev != null) {
            ft.remove(prev);//  w  ww  .jav  a  2  s.  co m
        }
        ft.addToBackStack(null);

        LoginDialog ld = new LoginDialog();
        ld.show(ft, LoginDialog.class.getName());
        return true;
    }
    if (id == R.id.action_register) {
        Log.d(TAG, "Showing register dialog...");

        FragmentTransaction ft = getFragmentManager().beginTransaction();
        Fragment prev = getFragmentManager().findFragmentByTag(RegisterDialog.class.getName());
        if (prev != null) {
            ft.remove(prev);
        }
        ft.addToBackStack(null);

        RegisterDialog rd = new RegisterDialog();
        rd.show(ft, RegisterDialog.class.getName());
        return true;
    }
    if (id == R.id.action_logout) {
        Log.d(TAG, "Logging out...");

        UserProfileHolder.clear();
        Prefs.setUsername(StringUtils.EMPTY);
        Prefs.setPasswordHash(StringUtils.EMPTY);

        updateUserInterface();
        return true;
    }
    if (id == R.id.action_settings) {
        Log.d(TAG, "Moving to Settings activity...");

        Intent settingsActivityIntent = new Intent(this, SettingsActivity.class);
        startActivity(settingsActivityIntent);
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:org.ubicompforall.cityexplorer.gui.PoiDetailsActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int itemID = item.getItemId();
    int editID = R.id.poiMenuEdit;
    int favID = R.id.poiMenufavorite;
    int dirID = R.id.poiMenuDirections;
    int mapID = R.id.poiMenuMap;

    //1: Edit//from  ww  w. ja  v  a  2s  .  c om
    if (itemID == editID) {
        debug(0, "Handle Edit-selection here!");
        Intent editIntent = new Intent(this, NewPoiActivity.class);
        editIntent.putExtra(IntentPassable.POI, poi); //setResult( Activity.RESULT_OK, resultIntent );
        startActivity(editIntent);
        finish(); // After editing, the details should be refreshed. This activity should thus be restarted.
    }
    //2: Favorite
    if (itemID == favID) {
        if (poi.isFavorite()) {
            poi = new Poi(poi.modify().favourite(false));
            DBFactory.getInstance(this).editPoi(poi);
            return true;
        }
        poi = poi.modify().favourite(true).build();
        DBFactory.getInstance(this).editPoi(poi);
        return true;
    }
    //3: Directions
    if (itemID == dirID) {
        userLocation = StartActivity.verifyUserLocation(userLocation, this);

        //Latitude and longitude for current position
        double slon = userLocation.getLongitude();
        double slat = userLocation.getLatitude();
        //Latitude and longitude for selected poi
        double dlon = poi.getGeoPoint().getLongitudeE6() / 1E6;
        double dlat = poi.getGeoPoint().getLatitudeE6() / 1E6;

        Intent navigate = new Intent(PoiDetailsActivity.this, NavigateFrom.class);
        navigate.putExtra("slon", slon);
        navigate.putExtra("slat", slat);
        navigate.putExtra("dlon", dlon);
        navigate.putExtra("dlat", dlat);
        startActivity(navigate);

        return true;
    }
    //4: Map
    if (itemID == mapID) {
        Intent showInMap = new Intent(PoiDetailsActivity.this, MapsActivity.class);
        ArrayList<Poi> selectedPois = new ArrayList<Poi>();
        selectedPois.add(poi);
        showInMap.putParcelableArrayListExtra(IntentPassable.POILIST, selectedPois);

        startActivity(showInMap);
        return true;
    }
    return true;
}

From source file:com.hichinaschool.flashcards.anki.StudyOptionsActivity.java

/** Handles item selections */
@Override//w  ww .j a  va  2 s .c  o  m
public boolean onOptionsItemSelected(MenuItem item) {
    Resources res = this.getResources();
    switch (item.getItemId()) {
    case android.R.id.home:
        closeStudyOptions();
        return true;

    case MENU_PREFERENCES:
        startActivityForResult(new Intent(this, Preferences.class), StudyOptionsFragment.PREFERENCES_UPDATE);
        if (AnkiDroidApp.SDK_VERSION > 4) {
            ActivityTransitionAnimation.slide(this, ActivityTransitionAnimation.FADE);
        }
        return true;

    case MENU_ROTATE:
        if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
            this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        } else {
            this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }
        return true;

    case MENU_NIGHT:
        SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(this);
        if (preferences.getBoolean("invertedColors", false)) {
            preferences.edit().putBoolean("invertedColors", false).commit();
            item.setIcon(R.drawable.ic_menu_night);
        } else {
            preferences.edit().putBoolean("invertedColors", true).commit();
            item.setIcon(R.drawable.ic_menu_night_checked);
        }
        return true;
    case DeckPicker.MENU_CREATE_DYNAMIC_DECK:
        StyledDialog.Builder builder = new StyledDialog.Builder(StudyOptionsActivity.this);
        builder.setTitle(res.getString(R.string.new_deck));

        mDialogEditText = new EditText(StudyOptionsActivity.this);
        ArrayList<String> names = AnkiDroidApp.getCol().getDecks().allNames();
        int n = 1;
        String cramDeckName = "Cram 1";
        while (names.contains(cramDeckName)) {
            n++;
            cramDeckName = "Cram " + n;
        }
        mDialogEditText.setText(cramDeckName);
        // mDialogEditText.setFilters(new InputFilter[] { mDeckNameFilter });
        builder.setView(mDialogEditText, false, false);
        builder.setPositiveButton(res.getString(R.string.create), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                long id;
                Bundle initialConfig = new Bundle();
                try {
                    initialConfig.putString("searchSuffix",
                            "'deck:" + AnkiDroidApp.getCol().getDecks().current().getString("name") + "'");
                    id = AnkiDroidApp.getCol().getDecks().newDyn(mDialogEditText.getText().toString());
                    AnkiDroidApp.getCol().getDecks().get(id);
                } catch (JSONException e) {
                    throw new RuntimeException(e);
                }
                loadContent(false, initialConfig);
            }
        });
        builder.setNegativeButton(res.getString(R.string.cancel), null);
        builder.create().show();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.github.opengarageapp.activity.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.action_settings) {
        startActivity(new Intent(this, ConfigurationActivity.class));
        return true;
    }//  w w w .jav  a 2  s .  c  om
    return super.onOptionsItemSelected(item);
}

From source file:com.example.android.rowanparkingpass.Activities.CreateVehicleActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Intent myIntent;//from www.  ja  v a2 s  . co m
    switch (item.getItemId()) {
    // action with ID action_delete was selected
    case R.id.action_delete:
        AlertDialog.Builder alertDialog = new AlertDialog.Builder(CreateVehicleActivity.this);
        alertDialog.setTitle("Delete Driver?");
        alertDialog.setMessage(vehicle.getCarInfo());
        alertDialog.setPositiveButton("Delete", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Intent myIntent = new Intent(CreateVehicleActivity.this, VehiclesActivity.class);
                myIntent.putExtra(MODE, mode.VEHICLES_LIST.name());
                if (SaveData.getSync()) {
                    SendInfoVehicle s = new SendInfoVehicle();
                    s.deleteVehicle(String.valueOf(vehicle.getVehicleId()));
                }
                // delete driver from database
                db.deleteVehicle(String.valueOf(vehicle.getVehicleId()));
                new DatabaseHandlerPasses(context)
                        .deleteRequestVehicleID(String.valueOf(vehicle.getVehicleId()));
                startActivity(myIntent);
                finish();
            }
        });
        alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                // Do nothing
            }
        });
        alertDialog.show();
        break;
    default:
        break;
    }
    return true;
}

From source file:com.seneca.android.senfitbeta.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_sidemenu_drawer);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/*from w w w  . java 2s. c o  m*/

    session = new Session(this);
    db = new DbHelper(this);

    if (!session.loggedin()) {
        logout();
    }
    /*************Shared Collector*/

    String email = session.getString();
    if (email != null) {
        textView = (TextView) findViewById(R.id.tvEmail);
        textView.setText("You Are Logged In As " + email);
    }

    /*btnLogout =(Button)findViewById(R.id.btnLogOut);
    btnLogout.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        logout();
    }
    });*/
    viewList = (Button) findViewById(R.id.allworkouts);
    viewList.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(new Intent(MainActivity.this, exlist.class));
        }
    });

    viewListOfBody = (Button) findViewById(R.id.allMuscle);
    viewListOfBody.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(MainActivity.this, musclelist.class));
        }
    });

    btnTimer = (Button) findViewById(R.id.breakTimer);
    btnTimer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(MainActivity.this, breakTimer.class));
        }
    });

    viewSetWork = (Button) findViewById(R.id.allBody);
    viewSetWork.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(new Intent(MainActivity.this, viewsetitems.class));
        }
    });

    nv = (NavigationView) findViewById(R.id.nav_view);
    nv.bringToFront();
    nv.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            switch (item.getItemId()) {
            case (R.id.workout2):
                startActivity(new Intent(MainActivity.this, exlist.class));
                break;
            case (R.id.breakTimer2):
                startActivity(new Intent(MainActivity.this, breakTimer.class));
                break;
            case (R.id.calendarView2):
                startActivity(new Intent(MainActivity.this, viewsetitems.class));
                break;

            case (R.id.logout):
                logout();
                break;
            case (R.id.share):
                Uri webpage = Uri.parse("https://www.facebook.com/");
                Intent intent = new Intent(Intent.ACTION_VIEW, webpage);
                startActivity(intent);
                break;

            }
            return true;
        }
    });

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);

    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    //navigationView.setNavigationItemSelectedListener(this);

    boolean ans = doesDatabaseExist(this, "myapp.db");

    if (!ans) {
        new GetFitt().execute();
    }

}

From source file:com.danielme.muspyforandroid.activities.base.AbstractActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.appsettings:
        defaultTransition(new Intent(this, AppSettingsActivity.class));
        return true;
    case R.id.about:
        defaultTransition(new Intent(this, AboutActivity.class));
        return true;
    case R.id.search:
        defaultTransition(new Intent(this, SearchArtistsActivity.class));
        return true;
    default://w ww.  j a  v  a 2 s .c  o m
        return false;
    }
}