Example usage for android.view MenuItem getTitle

List of usage examples for android.view MenuItem getTitle

Introduction

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

Prototype

public CharSequence getTitle();

Source Link

Document

Retrieve the current title of the item.

Usage

From source file:task.application.com.colette.navigation.AppNavigationViewAsDrawerImpl.java

private void applyFontToMenuItem(MenuItem mi) {
    Typeface font = FontCache.getTypeface("Nunito-SemiBold.ttf", mActivity);
    SpannableString mNewTitle = new SpannableString(mi.getTitle());
    mNewTitle.setSpan(new CustomTypefaceSpan("", font), 0, mNewTitle.length(),
            Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    mi.setTitle(mNewTitle);/*  w ww .  ja v  a 2  s .  co m*/
}

From source file:jp.morimotor.beaconattend.HelpActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();

    //?????????//from   w ww .  java  2s.c o m
    if (id == android.R.id.home) {
        finish();
        return true;
    }

    // Licence
    if (item.getTitle().toString().equals("infoButton")) {

        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
        alertDialogBuilder.setTitle("Info");
        alertDialogBuilder
                .setMessage("??????\nViewPagerIndicator\n"
                        + "Copyright 2012 Jake Wharton\n" + "Copyright 2011 Patrik kerfeldt\n"
                        + "Copyright 2011 Francisco Figueiredo Jr.\n" + "\n"
                        + "Licensed under the Apache License, Version 2.0 (the \"License\");\n"
                        + "you may not use this file except in compliance with the License.\n"
                        + "You may obtain a copy of the License at\n" + "\n"
                        + "   http://www.apache.org/licenses/LICENSE-2.0\n" + "\n"
                        + "Unless required by applicable law or agreed to in writing, software\n"
                        + "distributed under the License is distributed on an \"AS IS\" BASIS,\n"
                        + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"
                        + "See the License for the specific language governing permissions and\n"
                        + "limitations under the License.");

        alertDialogBuilder.setPositiveButton("?", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
            }
        });

        AlertDialog alertDialog = alertDialogBuilder.create();
        alertDialog.show();

    }

    return super.onOptionsItemSelected(item);
}

From source file:in.codehex.facilis.MainActivity.java

@Override
public boolean onNavigationItemSelected(MenuItem item) {
    mDrawerLayout.closeDrawers();/*  w  w  w.j a  v a 2  s.co m*/
    return selectDrawerItem(item.getItemId(), item.getTitle().toString());
}

From source file:com.vrem.wifianalyzer.navigation.NavigationMenuViewTest.java

@Test
public void testNavigationMenuView() throws Exception {
    // execute/*from  w  ww.  j ava2 s  . c om*/
    final Menu menu = navigationView.getMenu();
    // validate
    assertEquals(NavigationMenu.values().length, menu.size());
    IterableUtils.forEach(EnumUtils.values(NavigationGroup.class), new Closure<NavigationGroup>() {
        @Override
        public void execute(final NavigationGroup navigationGroup) {
            IterableUtils.forEach(navigationGroup.getNavigationMenus(), new Closure<NavigationMenu>() {
                @Override
                public void execute(NavigationMenu navigationMenu) {
                    MenuItem actual = menu.getItem(navigationMenu.ordinal());
                    assertEquals(navigationGroup.ordinal(), actual.getGroupId());
                    assertEquals(mainActivity.getResources().getString(navigationMenu.getTitle()),
                            actual.getTitle());
                    assertEquals(navigationMenu.ordinal(), actual.getItemId());
                    assertEquals(navigationMenu.ordinal(), actual.getOrder());
                }
            });
        }
    });
}

From source file:com.brayanarias.alarmproject.activity.MainActivity.java

private void setupNavigationView() {
    navigationView = (NavigationView) findViewById(R.id.navigation);
    MenuItem item = navigationView.getMenu().findItem(actualItem);
    View nav_header = LayoutInflater.from(this).inflate(R.layout.nav_header, null);
    final NavigationView navigationView = (NavigationView) findViewById(R.id.navigation);
    navigationView.addHeaderView(nav_header);
    //salute//ww  w .ja  va2  s  .  c o m
    String salute = AlarmUtilities.getSalute(getApplicationContext());
    TextView tvWellcome = (TextView) nav_header.findViewById(R.id.tvWellcome);
    tvWellcome.setText(salute);
    if (item != null) {
        item.setChecked(true);
    }
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            CharSequence title = menuItem.getTitle();
            closeDrawer();
            switch (menuItem.getItemId()) {
            case R.id.itMyAlarms:
                showFragment(R.id.itMyAlarms);
                actualItem = menuItem.getItemId();
                menuItem.setChecked(true);
                getSupportActionBar().setTitle(title);
                return true;
            case R.id.itAddAlarm:
                Calendar calendar = Calendar.getInstance();
                int hour = calendar.get(Calendar.HOUR_OF_DAY);
                int minute = calendar.get(Calendar.MINUTE);
                TimePickerDialog timePickerDialog = TimePickerDialog
                        .newInstance(new TimePickerDialog.OnTimeSetListener() {
                            @Override
                            public void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute) {
                                Alarm alarm = AlarmUtilities.createDefaultAlarm();
                                String min = minute < 10 ? "0" + minute : "" + minute;
                                if (hourOfDay == 12) {
                                    alarm.setAmPm("PM");
                                    alarm.setHour(hourOfDay);
                                    alarm.setHourFormatted((hourOfDay) + ":" + min);
                                } else if (hourOfDay > 12) {
                                    alarm.setAmPm("PM");
                                    alarm.setHour(hourOfDay - 12);
                                    alarm.setHourFormatted((hourOfDay - 12) + ":" + min);
                                } else {
                                    if (hourOfDay == 0) {
                                        hourOfDay = 12;
                                    }
                                    alarm.setAmPm("AM");
                                    alarm.setHour(hourOfDay);
                                    alarm.setHourFormatted(hourOfDay + ":" + min);
                                }
                                alarm.setMinute(minute);
                                Intent intent = new Intent(getApplicationContext(), AddAlarmActivity.class);
                                intent.putExtra(Constant.actionAlarmKey, Constant.addAlarm);
                                intent.putExtra(Constant.alarmSerializableKey, alarm);
                                startActivity(intent);
                            }
                        }, hour, minute, false);
                timePickerDialog.show(getSupportFragmentManager(), "tag");
                return true;
            case R.id.itCurrentMonth:
                actualItem = menuItem.getItemId();
                menuItem.setChecked(true);
                showFragment(R.id.itCurrentMonth);
                getSupportActionBar().setTitle(title);
                return true;
            /*
            case R.id.itConfig:
                actualItem = menuItem.getItemId();
                menuItem.setChecked(true);
                showFragment(R.id.itConfig);
                getSupportActionBar().setTitle(title);
                closeDrawer();
                return true;
            */
            case R.id.itAbout:
                AlertDialog.Builder alertBuilder = new AlertDialog.Builder(MainActivity.this);
                WebView wvLegal = (WebView) LayoutInflater.from(getApplication())
                        .inflate(R.layout.web_view_legal, null);
                wvLegal.loadData(getString(R.string.html_legal), "text/html", "UTF-8");
                wvLegal.setWebChromeClient(new WebChromeClient());
                alertBuilder.setView(wvLegal);
                alertBuilder.setTitle(R.string.txt_about_app);
                alertBuilder.setCancelable(true).setPositiveButton(getString(R.string.txt_button_ok),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.dismiss();
                            }
                        });
                alertBuilder.show();
                return true;
            default:
                return false;
            }

        }
    });
}

From source file:cz.jaro.alarmmorning.AlarmMorningActivity.java

private void setupDrawerContent(NavigationView navigationView) {
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override/*  w w  w.  j a  v a2 s .  co  m*/
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            onOptionsItemSelected(menuItem);
            return true;
        }
    });

    MenuItem calendarMenuItem = mNavigationView.getMenu().getItem(0);
    setFragmentTitle(calendarMenuItem.getTitle());
}

From source file:org.mozilla.mozstumbler.client.serialize.KMLFragment.java

private void contextItemSelected(MenuItem item, final String filename) {
    final boolean isDeleteFile = item.getTitle().equals(getString(R.string.delete_file));
    boolean isLoadFile = item.getTitle().equals(getString(R.string.load_file));
    boolean isDeleteAll = item.getTitle().equals(getString(R.string.delete_all));
    boolean isShareFile = item.getTitle().equals(getString(R.string.share_file));

    if (filename == null && (isDeleteFile || isLoadFile || isShareFile)) {
        return;/*from www  . j  a v a  2s  .  co  m*/
    }

    if (isLoadFile) {
        showProgress(true, getString(R.string.loading_kml));
        ObservationPointSerializer obs = new ObservationPointSerializer(this,
                ObservationPointSerializer.Mode.READ,
                new File(getActivity().getExternalFilesDir(null), filename), mPointsToWrite);
        obs.execute();
        return;
    }

    if (isShareFile) {
        shareFile(new File(getActivity().getExternalFilesDir(null), filename));
        return;
    }

    if (!isDeleteFile && !isDeleteAll) {
        return;
    }

    new AlertDialog.Builder(getActivity()).setTitle(item.getTitle()).setMessage(R.string.are_you_sure)
            .setIcon(android.R.drawable.ic_dialog_alert)
            .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    if (isDeleteFile) {
                        File f = new File(getActivity().getExternalFilesDir(null), filename);
                        f.delete();
                    } else {
                        String[] files = getFileList();
                        if (files != null) {
                            for (String file : files) {
                                new File(getActivity().getExternalFilesDir(null), file).delete();
                            }
                        }
                    }
                }
            }).setNegativeButton(android.R.string.no, null).show();
}

From source file:com.truman.showtime.showtime.ui.fragment.MovieListFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    if (item.getTitle().equals(getString(R.string.share_movie))) {
        AdapterViewCompat.AdapterContextMenuInfo info = (AdapterViewCompat.AdapterContextMenuInfo) item
                .getMenuInfo();/*from   w  w w.  java  2 s.  co m*/
        Intent sendIntent = new Intent();
        sendIntent.setAction(Intent.ACTION_SEND);
        sendIntent.putExtra(Intent.EXTRA_TEXT, mSelectedMovie.name + "\n" + "http://google.com/movies?near="
                + mCity + "&mid=" + mSelectedMovie.id);
        sendIntent.setType("text/plain");
        startActivity(Intent.createChooser(sendIntent, getResources().getString(R.string.share_movie)));
    }
    return super.onContextItemSelected(item);
}

From source file:com.cullaboration.userhookdemo.MainActivity.java

public void loadStaticPages() {
    UserHook.fetchPageNames(new UHOperation.UHArrayListener<UHPage>() {
        @Override/*from   w  w w  .  j  a  v a 2 s.co m*/
        public void onSuccess(List<UHPage> items) {

            SubMenu staticMenu = navigationView.getMenu().addSubMenu("Static Pages");
            for (UHPage page : items) {
                // add page to menu
                staticMenu.add(page.getName());

                // store the page item for use in the click listener
                staticPages.put(page.getName(), page);
            }

            // hack to refresh menu
            MenuItem mi = navigationView.getMenu().getItem(navigationView.getMenu().size() - 1);
            mi.setTitle(mi.getTitle());
        }
    });
}

From source file:com.ibm.techathon.elven.smartpool.cards.SuggestedCard.java

public void init() {

    //Add a header
    SuggestedCardHeader header = new SuggestedCardHeader(getContext(), mTrip);

    if (mType == AVAILABLE_TRIPS) {
        int id = R.menu.trust_circle_available;
        header.setPopupMenu(id, new CardHeader.OnClickCardHeaderPopupMenuListener() {
            @Override//  w w w  .ja v  a  2 s.c o  m
            public void onMenuItemClick(BaseCard card, MenuItem item) {

                if (item.getTitle().toString().equals(mContext.getString(R.string.action_circle_unsubscribe))) {
                    Toast.makeText(getContext(), "Unsubscribing from the circle", Toast.LENGTH_SHORT).show();
                    //removeCircleMapping(mTrustCircle);
                } else if (item.getTitle().toString()
                        .equals(mContext.getString(R.string.action_circle_subscribe))) {
                    Toast.makeText(getContext(), "Submitting request for subscription", Toast.LENGTH_SHORT)
                            .show();
                    submitSubscriptionRequest();

                }
            }
        });

    }
    addCardHeader(header);

    // TODO make click listener only when lat and long is available
    //Set click listener
    setOnClickListener(new OnCardClickListener() {
        @Override
        public void onClick(Card card, View view) {
            if (!mTrip.getStartLocationLat().equals(DEFAULT_POINT_VALUE)
                    && !mTrip.getEndLocationLat().equals(DEFAULT_POINT_VALUE)
                    && !mTrip.getStartLocationLang().equals(DEFAULT_POINT_VALUE)
                    && !mTrip.getEndLocationLang().equals(DEFAULT_POINT_VALUE)) {
                // call Line Map activity to show the line between start and end location on map
                Intent intent = new Intent(mContext, LineMapActivity.class);
                intent.putExtra(LineMapActivity.START_LOCATION_LAT, mTrip.getStartLocationLat());
                intent.putExtra(LineMapActivity.START_LOCATION_LONG, mTrip.getStartLocationLang());
                intent.putExtra(LineMapActivity.END_LOCATION_LAT, mTrip.getEndLocationLat());
                intent.putExtra(LineMapActivity.END_LOCATION_LONG, mTrip.getEndLocationLang());

                boolean sameCity = false;
                if (mTrip.getStartLocationCity().equals(mTrip.getEndLocationCity())) {
                    sameCity = true;
                }
                intent.putExtra(LineMapActivity.LOCATION_SAME_CITY, sameCity);

                mContext.startActivity(intent);
            }
        }
    });

    //Set swipe on
    //setSwipeable(true);

    //Add thumbnail
    CardThumbnail thumb = new SuggestedCardThumb(getContext());
    thumb.setUrlResource(
            "https://lh5.googleusercontent.com/-N8bz9q4Kz0I/AAAAAAAAAAI/AAAAAAAAAAs/Icl2bQMyK7c/s265-c-k-no/photo.jpg");
    thumb.setErrorResource(R.drawable.ic_error_loadingorangesmall);
    addCardThumbnail(thumb);
}