Example usage for android.view MenuItem getSubMenu

List of usage examples for android.view MenuItem getSubMenu

Introduction

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

Prototype

public SubMenu getSubMenu();

Source Link

Document

Get the sub-menu to be invoked when this item is selected, if it has one.

Usage

From source file:com.ruesga.rview.MainActivity.java

private void updateAccountsDrawerInfo() {
    // Remove all accounts and re-add them
    final DrawerNavigationMenu menu = (DrawerNavigationMenu) mBinding.drawerNavigationView.getMenu();
    int otherAccountGroupIndex = menu.findGroupIndex(R.id.category_other_accounts);
    MenuItem group = menu.getItem(otherAccountGroupIndex);
    SubMenu otherAccountsSubMenu = group.getSubMenu();
    int count = otherAccountsSubMenu.size() - 1;
    for (int i = count; i > 0; i--) {
        ((DrawerNavigationSubMenu) otherAccountsSubMenu).removeItemAt(i);
    }/*w  w  w  . java 2  s. co m*/
    int i = 0;
    for (Account account : mAccounts) {
        // Current account
        if (mAccount.isSameAs(account)) {
            i++;
            continue;
        }

        int id = OTHER_ACCOUNTS_GROUP_BASE_ID + i;
        String title = account.getAccountDisplayName() + DrawerNavigationView.SEPARATOR
                + account.getRepositoryDisplayName() + DrawerNavigationView.SEPARATOR + "ic_delete"
                + DrawerNavigationView.SEPARATOR + "false";
        MenuItem item = otherAccountsSubMenu.add(group.getGroupId(), id, Menu.NONE, title);

        PicassoHelper.bindAvatar(this, PicassoHelper.getPicassoClient(this), account, account.mAccount, item,
                PicassoHelper.getDefaultAvatar(this, R.color.primaryDarkForeground));
        i++;
    }

    if (mAccount != null) {
        updateAccountStatus();
    }
}

From source file:com.techno.jay.codingcontests.Home.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    FirebaseApp.initializeApp(this);

    FontChangeCrawler fontChanger = new FontChangeCrawler(getAssets(), "fonts/ProductSans-Regular.ttf");
    fontChanger.replaceFonts((ViewGroup) this.findViewById(android.R.id.content));
    //==2) for fragment hoy to====
    //== fontChanger.replaceFonts((ViewGroup) this.getView());
    //===3) for adepterview and handlerview na use mate====
    //==convertView = inflater.inflate(R.layout.listitem, null);
    //==fontChanger.replaceFonts((ViewGroup)convertView);

    bp = new BillingProcessor(Home.this, Const.LICENSE_KEY, Home.this);
    /*bp.consumeAsync(inventory.getPurchase(SKU_GAS),
        mConsumeFinishedListener);*/
    bp.consumePurchase(Const.Product_Plan_Unlimitedversion);

    Toolbar toolbar = (Toolbar) this.findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/*from w  ww  . j ava2s .  com*/

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setIcon(R.drawable.appicon);

    /*     if (Build.VERSION.SDK_INT >= 21) {
    Window window = getWindow();
    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    window.setStatusBarColor(Color.parseColor("#1976D2"));
    window.setNavigationBarColor(Color.parseColor("#1976D2"));
         }*/

    sharepref = getApplicationContext().getSharedPreferences("MyPref", MODE_PRIVATE);

    if (Build.VERSION.SDK_INT >= 23) {
        if (checkSelfPermission(
                android.Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
            requestPermissions(new String[] { android.Manifest.permission.READ_PHONE_STATE },
                    PERMISSIONS_REQUEST_READ_PHONE_STATE);
        } else {
            getDeviceImei();
        }
    } else {
        getDeviceImei();
    }

    databaseReferenceUser = FirebaseDatabase.getInstance().getReference("Users");
    //databaseReferenceUser.keepSynced(true);

    token = FirebaseInstanceId.getInstance().getToken();

    SimpleDateFormat format_diffrent = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
    Date now = new Date();
    date = format_diffrent.format(now);

    // creating connection detector class instance
    ConnectionDetector cd = new ConnectionDetector(getApplicationContext());
    // get Internet status
    isInternetPresent = cd.isConnectingToInternet();
    if (isInternetPresent) {
        // Internet Connection is Present
        // make HTTP requests
        //refreshedToken = FirebaseInstanceId.getInstance().getToken();
        databaseReferenceUser.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                // Get user value

                if (dataSnapshot.hasChild(str_IMEI)) {
                    String IMEI_no = dataSnapshot.child("IMEI").getValue(String.class);
                    String date_got = dataSnapshot.child("date").getValue(String.class);
                    Log.d("date got", date_got);
                    String status_got = dataSnapshot.child("status").getValue(String.class);

                    Toast.makeText(Home.this, "  Already registered. !   ", Toast.LENGTH_LONG).show();
                    SimpleDateFormat myFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");

                    try {
                        Date date1 = myFormat.parse(date_got);
                        Date date2 = myFormat.parse(date);
                        long diff = date2.getTime() - date1.getTime();
                        System.out.println("Days: " + TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS));

                        long days_count = TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS);

                        if (days_count > 10 && status_got.equalsIgnoreCase("inactive")) {
                            promptForUpgrade();
                        }

                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                }
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {
                //  Log.w("TAG", "getUser:onCancelled", databaseError.toException());
                // new Signup_async().execute();
            }
        });

    } else {

        Snackbar snackbar = Snackbar.make(findViewById(android.R.id.content), " Sorry! No Internet!!!",
                Snackbar.LENGTH_LONG);

        // Changing message text color
        snackbar.setActionTextColor(Color.BLUE);

        // Changing action button text color
        View sbView = snackbar.getView();
        TextView textView = (TextView) sbView.findViewById(android.support.design.R.id.snackbar_text);
        textView.setTextColor(Color.YELLOW);
        snackbar.show();

        Toast.makeText(Home.this, "  No Internet Connection!!!.  ", Toast.LENGTH_LONG).show();

    }

    Set<String> set = sharepref.getStringSet("arraylist", null);
    List<String> sposers = new ArrayList<String>(set);

    String[] apossor_arry = new String[sposers.size()];
    apossor_arry = sposers.toArray(apossor_arry);

    FragmentTransaction tx;
    tx = getSupportFragmentManager().beginTransaction();
    tx.replace(R.id.frame, new MainHomeFragmentFirebase());
    tx.commit();

    searchView = (MaterialSearchView) findViewById(R.id.search_view);
    searchView.setVoiceSearch(false);
    searchView.setHint("Enter Coding website/technology");
    searchView.setCursorDrawable(R.drawable.custome_cursor);
    searchView.setSuggestions(apossor_arry);
    searchView.setEllipsize(true);

    searchView.setOnQueryTextListener(new MaterialSearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            Snackbar.make(findViewById(android.R.id.content), "Query: " + query, Snackbar.LENGTH_LONG).show();
            Intent result = new Intent(Home.this, ResultContestLink.class);
            result.putExtra("query", query);

            startActivity(result);
            overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right);
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            //Do some magic
            return false;
        }
    });

    searchView.setOnSearchViewListener(new MaterialSearchView.SearchViewListener() {
        @Override
        public void onSearchViewShown() {
            //Do some magic
        }

        @Override
        public void onSearchViewClosed() {
            //Do some magic
        }
    });

    drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle Toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close) {

        @Override
        public void onDrawerClosed(View drawerView) {
            // Code here will be triggered once the drawer closes as we dont want anything to happen so we leave this blank
            super.onDrawerClosed(drawerView);
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            // Code here will be triggered once the drawer open as we dont want anything to happen so we leave this blank

            super.onDrawerOpened(drawerView);
        }
    };
    //Setting the actionbarToggle to drawer layout
    drawer.setDrawerListener(Toggle);
    //calling sync state is necessay or else your hamburger icon wont show up
    Toggle.syncState();

    databaseReferenceEventData = FirebaseDatabase.getInstance().getReference("Contest").child("objects");
    databaseReferenceEventData.keepSynced(true);

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

    Menu m = navigationView.getMenu();
    for (int i = 0; i < m.size(); i++) {
        MenuItem mi = m.getItem(i);

        //for aapplying a font to subMenu ...
        SubMenu subMenu = mi.getSubMenu();
        if (subMenu != null && subMenu.size() > 0) {
            for (int j = 0; j < subMenu.size(); j++) {
                MenuItem subMenuItem = subMenu.getItem(j);
                applyFontToMenuItem(subMenuItem);
            }
        }

        //the method we have create in activity
        applyFontToMenuItem(mi);
    }

    View header = navigationView.getHeaderView(0);
    tv_total_sponsers = (TextView) header.findViewById(R.id.tv_total_sponsers);
    tv_total_contests = (TextView) header.findViewById(R.id.tv_total_contests);

    tv_total_sponsers.setText("Total Contests websites : " + sharepref.getString("totalsposor", "NA"));

    // navigationView.setNavigationItemSelectedListener(this);

    //Setting Navigation View Item Selected Listener to handle the item click of the navigation menu
    assert navigationView != null;
    navigationView.setCheckedItem(R.id.nav_home);
    navigationView.getMenu().getItem(0).setChecked(true);
    navigationView.setItemIconTintList(null);

    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {

        // This method will trigger on item Click of navigation menu
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {

            navigationView.getMenu().getItem(0).setChecked(false);

            //Checking if the item is in checked state or not, if not make it in checked state
            if (activeMenuItem != null)
                activeMenuItem.setChecked(false);
            activeMenuItem = menuItem;
            menuItem.setChecked(true);
            //else menuItem.setChecked(true);

            //Closing drawer on item click
            drawer.closeDrawers();
            Fragment fragment = null;
            FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();

            //Check to see which item was being clicked and perform appropriate action
            switch (menuItem.getItemId()) {

            //Replacing the main content with ContentFragment Which is our Inbox View;
            case R.id.nav_home:
                // Toast.makeText(getApplicationContext(),"Shop",Toast.LENGTH_SHORT).show();
                fragment = new MainHomeFragmentFirebase();
                break;

            case R.id.nav_longcompetition:

                fragment = new LongtermCompetition();
                break;
            case R.id.nav_exit:
                System.exit(0);
                getIntent().setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

                break;
            case R.id.nav_running:
                // Toast.makeText(getApplicationContext(),"Shop",Toast.LENGTH_SHORT).show();
                fragment = new LiveContests();
                break;

            case R.id.nav_past:
                // Toast.makeText(getApplicationContext(),"Shop",Toast.LENGTH_SHORT).show();
                fragment = new CompletedContest();
                break;

            case R.id.nav_share:
                // Toast.makeText(getApplicationContext(),"Shop",Toast.LENGTH_SHORT).show();

                Intent intentshare = new Intent(Intent.ACTION_SEND);
                intentshare.setType("text/plain");
                intentshare.putExtra(Intent.EXTRA_TEXT,
                        "Best Competitive Programming news/reminder app for Coders.World wide coding competitions and hiring challenges.Solve the challenges and get chance to win awesome prizes and also hired by world famous MNCs(i.e AMAZON , IBM , intel , google , SAP many more...).\n\n\n"
                                + "https://play.google.com/store/apps/details?id=com.techno.jay.codingcontests&hl=en"
                                + "\n\n-developed by Technocrats Appware");
                startActivity(Intent.createChooser(intentshare, "Share"));

                break;
            case R.id.nav_feedback:
                final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object
                try {
                    startActivity(
                            new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
                } catch (Exception e) {
                    // Log.d("TAG","Message ="+e);
                    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(
                            "https://play.google.com/store/apps/details?id=com.techno.jay.codingcontests&hl=en")));
                }
                break;

            case R.id.nav_hiring:
                // Toast.makeText(getApplicationContext(),"Shop",Toast.LENGTH_SHORT).show();
                Intent result = new Intent(Home.this, ResultContestLink.class);
                result.putExtra("query", "hiring");

                startActivity(result);
                overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right);
                break;

            case R.id.nav_setting:
                Intent seting = new Intent(Home.this, Setting_app.class);
                startActivity(seting);
                overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right);
                break;

            case R.id.nav_aboutus:
                // Toast.makeText(getApplicationContext(),"Shop",Toast.LENGTH_SHORT).show();
                fragment = new Aboutus();
                break;

            /*case R.id.nav_aboutus:
                // Toast.makeText(getApplicationContext(),"Shop",Toast.LENGTH_SHORT).show();
                fragment= new Aboutus_fragment();
                break;
                    
            case R.id.spam:
                Toast.makeText(getApplicationContext(),"Spam Selected",Toast.LENGTH_SHORT).show();
                return true;*/
            default:
                Toast.makeText(getApplicationContext(), "Coming Soon...", Toast.LENGTH_SHORT).show();

                break;

            }

            if (fragment != null) {

                fragmentTransaction.replace(R.id.frame, fragment);
                //getSupportFragmentManager().beginTransaction().replace(R.id.frame, fragment).addToBackStack(null).commit();
                fragmentTransaction.addToBackStack(null).commit();

                getSupportActionBar().setTitle("Coding Contests");

            } else {
                menuItem.setChecked(false);
            }

            return true;
        }
    });

}

From source file:paulscode.android.mupen64plusae.GalleryActivity.java

@SuppressWarnings("deprecation")
@Override//from   w ww  .j a v  a  2  s.co m
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Get app data and user preferences
    mAppData = new AppData(this);
    mGlobalPrefs = new GlobalPrefs(this, mAppData);
    mGlobalPrefs.enforceLocale(this);

    final int lastVer = mAppData.getLastAppVersionCode();
    final int currVer = mAppData.appVersionCode;
    if (lastVer != currVer) {
        // First run after install/update, greet user with changelog, then help dialog
        Popups.showFaq(this);
        final ChangeLog log = new ChangeLog(getAssets());
        if (log.show(this, lastVer + 1, currVer)) {
            mAppData.putLastAppVersionCode(currVer);
        }
    }

    // Get the ROM path if it was passed from another activity/app
    final Bundle extras = getIntent().getExtras();
    if (extras != null) {
        final String givenRomPath = extras.getString(ActivityHelper.Keys.ROM_PATH);
        if (!TextUtils.isEmpty(givenRomPath)) {
            // Asynchronously compute MD5 and launch game when finished
            Notifier.showToast(this, getString(R.string.toast_loadingGameInfo));
            final ComputeMd5Task task = new ComputeMd5Task(new File(givenRomPath), new ComputeMd5Listener() {
                @Override
                public void onComputeMd5Finished(File file, String md5) {
                    final RomHeader header = new RomHeader(file);

                    final RomDatabase database = RomDatabase.getInstance();

                    if (!database.hasDatabaseFile()) {
                        database.setDatabaseFile(mAppData.mupen64plus_ini);
                    }

                    final RomDetail detail = database.lookupByMd5WithFallback(md5, file, header.crc);
                    launchGameActivity(file.getAbsolutePath(), null, true, md5, header.crc, header.name,
                            header.countryCode, null, detail.goodName, false);
                }
            });
            task.execute();
        }
    }

    // Lay out the content
    setContentView(R.layout.gallery_activity);
    mGridView = (RecyclerView) findViewById(R.id.gridview);
    refreshGrid();

    // Update the grid layout
    galleryMaxWidth = (int) getResources().getDimension(R.dimen.galleryImageWidth);
    galleryHalfSpacing = (int) getResources().getDimension(R.dimen.galleryHalfSpacing);
    galleryAspectRatio = galleryMaxWidth * 1.0f / getResources().getDimension(R.dimen.galleryImageHeight);

    final DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);

    final int width = metrics.widthPixels - galleryHalfSpacing * 2;
    galleryColumns = (int) Math.ceil(width * 1.0 / (galleryMaxWidth + galleryHalfSpacing * 2));
    galleryWidth = width / galleryColumns - galleryHalfSpacing * 2;

    final GridLayoutManager layoutManager = (GridLayoutManager) mGridView.getLayoutManager();
    layoutManager.setSpanCount(galleryColumns);
    mGridView.getAdapter().notifyDataSetChanged();
    mGridView.setFocusable(false);
    mGridView.setFocusableInTouchMode(false);

    // Add the toolbar to the activity (which supports the fancy menu/arrow animation)
    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle(R.string.app_name);
    final View firstGridChild = mGridView.getChildAt(0);

    if (firstGridChild != null) {
        toolbar.setNextFocusDownId(firstGridChild.getId());
    }

    setSupportActionBar(toolbar);

    // Configure the navigation drawer
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, 0, 0) {
        @Override
        public void onDrawerStateChanged(int newState) {
            // Intercepting the drawer open animation and re-closing it causes onDrawerClosed to
            // not fire,
            // So detect when this happens and wait until the drawer closes to handle it
            // manually
            if (newState == DrawerLayout.STATE_DRAGGING) {
                // INTERCEPTED!
                mDragging = true;
                hideSoftKeyboard();
            } else if (newState == DrawerLayout.STATE_IDLE) {
                if (mDragging && !mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
                    // onDrawerClosed from dragging it
                    mDragging = false;
                    mDrawerList.setVisibility(View.VISIBLE);
                    mGameSidebar.setVisibility(View.GONE);
                    mSelectedItem = null;
                }
            }
        }

        @Override
        public void onDrawerClosed(View drawerView) {
            // Hide the game information sidebar
            mDrawerList.setVisibility(View.VISIBLE);
            mGameSidebar.setVisibility(View.GONE);
            mSelectedItem = null;

            super.onDrawerClosed(drawerView);
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            hideSoftKeyboard();
            super.onDrawerOpened(drawerView);
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    // Configure the list in the navigation drawer
    mDrawerList = (MenuListView) findViewById(R.id.drawerNavigation);
    mDrawerList.setMenuResource(R.menu.gallery_drawer);

    //Remove touch screen profile configuration if in TV mode
    if (mGlobalPrefs.isBigScreenMode) {
        final MenuItem profileGroupItem = mDrawerList.getMenu().findItem(R.id.menuItem_profiles);
        profileGroupItem.getSubMenu().removeItem(R.id.menuItem_touchscreenProfiles);

        final MenuItem settingsGroupItem = mDrawerList.getMenu().findItem(R.id.menuItem_settings);
        settingsGroupItem.getSubMenu().removeItem(R.id.menuItem_categoryTouchscreen);
    }

    // Select the Library section
    mDrawerList.getMenu().getItem(0).setChecked(true);

    // Handle menu item selections
    mDrawerList.setOnClickListener(new MenuListView.OnClickListener() {
        @Override
        public void onClick(MenuItem menuItem) {
            GalleryActivity.this.onOptionsItemSelected(menuItem);
        }
    });

    // Configure the game information drawer
    mGameSidebar = (GameSidebar) findViewById(R.id.gameSidebar);

    // Handle events from the side bar
    mGameSidebar.setActionHandler(this, R.menu.gallery_game_drawer);

    if (savedInstanceState != null) {
        mSelectedItem = null;
        final String md5 = savedInstanceState.getString(STATE_SIDEBAR);
        if (md5 != null) {
            // Repopulate the game sidebar
            for (final GalleryItem item : mGalleryItems) {
                if (md5.equals(item.md5)) {
                    onGalleryItemClick(item);
                    break;
                }
            }
        }

        final String query = savedInstanceState.getString(STATE_QUERY);
        if (query != null)
            mSearchQuery = query;

        mRefreshNeeded = savedInstanceState.getBoolean(STATE_GALLERY_REFRESH_NEEDED);
    }

    // find the retained fragment on activity restarts
    final FragmentManager fm = getSupportFragmentManager();
    mCacheRomInfoFragment = (ScanRomsFragment) fm.findFragmentByTag(STATE_CACHE_ROM_INFO_FRAGMENT);
    mExtractTexturesFragment = (ExtractTexturesFragment) fm.findFragmentByTag(STATE_EXTRACT_TEXTURES_FRAGMENT);

    if (mCacheRomInfoFragment == null) {
        mCacheRomInfoFragment = new ScanRomsFragment();
        fm.beginTransaction().add(mCacheRomInfoFragment, STATE_CACHE_ROM_INFO_FRAGMENT).commit();
    }

    if (mExtractTexturesFragment == null) {
        mExtractTexturesFragment = new ExtractTexturesFragment();
        fm.beginTransaction().add(mExtractTexturesFragment, STATE_EXTRACT_TEXTURES_FRAGMENT).commit();
    }

    // Set the sidebar opacity on the two sidebars
    mDrawerList.setBackgroundDrawable(new DrawerDrawable(mGlobalPrefs.displayActionBarTransparency));
    mGameSidebar.setBackgroundDrawable(new DrawerDrawable(mGlobalPrefs.displayActionBarTransparency));
}

From source file:org.mariotaku.twidere.fragment.UserListDetailsFragment.java

@Override
public void onClick(final View view) {
    switch (view.getId()) {
    case R.id.follow_more: {
        if (mUserList == null)
            return;
        if (mAccountId != mUserId) {
            mFollowMoreButton.setVisibility(View.GONE);
            if (mUserList.isFollowing()) {
                mTwitterWrapper.destroyUserListSubscription(mAccountId, mUserList.getId());
            } else {
                mTwitterWrapper.createUserListSubscription(mAccountId, mUserList.getId());
            }//from w w  w  . j a  v  a 2s .  c  om
        } else {
            mPopupMenu = PopupMenu.getInstance(getActivity(), view);
            mPopupMenu.inflate(R.menu.action_user_list_details);
            final Menu menu = mPopupMenu.getMenu();
            final MenuItem extensions = menu.findItem(MENU_EXTENSIONS_SUBMENU);
            if (extensions != null) {
                final Intent intent = new Intent(INTENT_ACTION_EXTENSION_OPEN_USER_LIST);
                final Bundle extras = new Bundle();
                extras.putParcelable(INTENT_KEY_USER_LIST,
                        new ParcelableUserList(mUserList, mAccountId, mHiResProfileImage));
                intent.putExtras(extras);
                addIntentToSubMenu(getActivity(), extensions.getSubMenu(), intent);
            }

            mPopupMenu.setOnMenuItemClickListener(this);
            mPopupMenu.show();
        }
        break;
    }
    case R.id.retry: {
        reloadUserListInfo();
        break;
    }
    case R.id.profile_image_container: {
        if (mAccountId > 0 && (mUserId > 0 || mUserScreenName != null)) {
            openUserProfile(getActivity(),
                    new ParcelableUser(mUserList.getUser(), mAccountId, mHiResProfileImage));
        }
        break;
    }
    }

}

From source file:org.mariotaku.twidere.activity.ComposeActivity.java

@Override
public void onClick(final View view) {
    switch (view.getId()) {
    case R.id.image_thumbnail_preview: {
        if (mPopupMenu != null) {
            mPopupMenu.dismiss();//  w ww .  j av  a 2 s  .c o m
        }
        mPopupMenu = PopupMenu.getInstance(this, view);
        mPopupMenu.inflate(R.menu.action_attached_image);
        final Menu menu = mPopupMenu.getMenu();
        final MenuItem extensions = menu.findItem(MENU_EXTENSIONS_SUBMENU);
        if (extensions != null) {
            final Intent intent = new Intent(INTENT_ACTION_EXTENSION_EDIT_IMAGE);
            intent.setData(mImageUri);
            addIntentToSubMenu(this, extensions.getSubMenu(), intent);
        }
        mPopupMenu.setOnMenuItemClickListener(this);
        mPopupMenu.show();
        break;
    }
    }

}

From source file:com.nttec.everychan.ui.MainActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem drawerMenuItem = menu.findItem(R.id.menu_open_close_drawer);
    if (drawerMenuItem != null) {
        drawerMenuItem.setTitle(drawerLayout.isDrawerOpen(DRAWER_GRAVITY) ? R.string.menu_close_drawer
                : R.string.menu_open_drawer);
    }/*from w  ww .  ja  va 2s  .  c  o m*/
    MenuItem favoritesMenuItem = menu.findItem(R.id.menu_favorites);
    if (favoritesMenuItem != null && tabsAdapter != null && tabsAdapter.getSelectedItem() >= 0) {
        TabModel tab = tabsAdapter.getItem(tabsAdapter.getSelectedItem());
        favoritesMenuItem
                .setTitle(isFavorite(tab) ? R.string.menu_remove_favorites : R.string.menu_add_favorites);
    }
    MenuItem preferencesMenuItem = menu.findItem(R.id.menu_settings);
    MenuItem preferencesSubMenuItem = menu.findItem(R.id.menu_sub_settings);
    try {
        if (MainApplication.getInstance().settings.preferencesSubmenu()) {
            preferencesSubMenuItem.setVisible(true);
            preferencesMenuItem.setVisible(false);
            Menu subMenu = preferencesSubMenuItem.getSubMenu();
            subMenu.findItem(R.id.menu_sub_settings_suspend)
                    .setVisible(MainApplication.getInstance().settings.isAutoupdateEnabled());
            subMenu.findItem(R.id.menu_sub_settings_autoupdate)
                    .setChecked(MainApplication.getInstance().settings.isAutoupdateEnabled());
            subMenu.findItem(R.id.menu_sub_settings_maskpictures)
                    .setChecked(MainApplication.getInstance().settings.maskPictures());
        } else {
            preferencesMenuItem.setVisible(true);
            preferencesSubMenuItem.setVisible(false);
        }
    } catch (Exception e) {
        Logger.e(TAG, e);
    }
    return super.onPrepareOptionsMenu(menu);
}

From source file:org.totschnig.myexpenses.activity.MyExpenses.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    MenuItem balanceItem = menu.findItem(R.id.BALANCE_COMMAND);
    if (balanceItem != null) {
        boolean showBalanceCommand = false;
        if (mAccountId > 0 && mAccountsCursor != null && !mAccountsCursor.isClosed()
                && mAccountsCursor.moveToPosition(mCurrentPosition)) {
            try {
                if (AccountType.valueOf(mAccountsCursor
                        .getString(mAccountsCursor.getColumnIndexOrThrow(KEY_TYPE))) != AccountType.CASH) {
                    showBalanceCommand = true;
                }/*from w w w .  ja  v  a  2  s  . c  o  m*/
            } catch (IllegalArgumentException ex) {
                /*aggregate*/}
        }
        Utils.menuItemSetEnabledAndVisible(balanceItem, showBalanceCommand);
    }

    MenuItem groupingItem = menu.findItem(R.id.GROUPING_COMMAND);
    if (groupingItem != null) {
        SubMenu groupingMenu = groupingItem.getSubMenu();

        Account account = Account.getInstanceFromDb(mAccountId);
        if (account != null) {
            Utils.configureGroupingMenu(groupingMenu, account.grouping);
        }
    }
    return true;
}

From source file:org.mariotaku.twidere.fragment.UserProfileFragment.java

@Override
public void onClick(final View view) {
    if (getActivity() == null)
        return;/*ww w.j av  a 2s.c  om*/
    switch (view.getId()) {
    case R.id.edit_follow: {
        if (mUser == null || mAccountId <= 0)
            return;
        if (mAccountId == mUserId) {
            final Bundle bundle = getArguments();
            final Intent intent = new Intent(INTENT_ACTION_EDIT_USER_PROFILE);
            intent.setClass(getActivity(), EditUserProfileActivity.class);
            if (bundle != null) {
                intent.putExtras(bundle);
            }
            startActivity(intent);
        } else {
            if (mUser.is_follow_request_sent)
                return;
            if (mFriendship.isSourceFollowingTarget()) {
                mPopupMenu = PopupMenu.getInstance(getActivity(), view);
                mPopupMenu.inflate(R.menu.action_user_profile_follow);
                mPopupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {

                    @Override
                    public boolean onMenuItemClick(final MenuItem item) {
                        switch (item.getItemId()) {
                        case R.id.unfollow: {
                            mFollowProgress.setVisibility(View.VISIBLE);
                            mEditFollowButton.setVisibility(View.GONE);
                            mTwitterWrapper.destroyFriendship(mAccountId, mUser.user_id);
                            return true;
                        }
                        }
                        return false;
                    }
                });
                mPopupMenu.show();
            } else {
                mFollowProgress.setVisibility(View.VISIBLE);
                mEditFollowButton.setVisibility(View.GONE);
                mTwitterWrapper.createFriendship(mAccountId, mUser.user_id);
            }
        }
        break;
    }
    case R.id.retry: {
        getUserInfo(true);
        break;
    }
    case R.id.profile_image_container: {
        final Uri uri = Uri.parse(getOriginalTwitterProfileImage(mUser.profile_image_url));
        openImage(getActivity(), uri, false);
        break;
    }
    case R.id.tweets_container: {
        if (mUser == null)
            return;
        openUserTimeline(getActivity(), mAccountId, mUser.user_id, mUser.screen_name);
        break;
    }
    case R.id.followers_container: {
        if (mUser == null)
            return;
        openUserFollowers(getActivity(), mAccountId, mUser.user_id, mUser.screen_name);
        break;
    }
    case R.id.friends_container: {
        if (mUser == null)
            return;
        openUserFriends(getActivity(), mAccountId, mUser.user_id, mUser.screen_name);
        break;
    }
    case R.id.more_options: {
        if (mUser == null)
            return;
        mPopupMenu = PopupMenu.getInstance(getActivity(), view);
        mPopupMenu.inflate(R.menu.action_user_profile);
        final Menu menu = mPopupMenu.getMenu();
        if (mUser.user_id != mAccountId) {
            if (mFriendship == null)
                return;
            final MenuItem blockItem = menu.findItem(MENU_BLOCK);
            if (blockItem != null) {
                final Drawable blockIcon = blockItem.getIcon();
                if (mFriendship.isSourceBlockingTarget()) {
                    blockItem.setTitle(R.string.unblock);
                    blockIcon.mutate().setColorFilter(getResources().getColor(R.color.holo_blue_bright),
                            PorterDuff.Mode.MULTIPLY);
                } else {
                    blockItem.setTitle(R.string.block);
                    blockIcon.clearColorFilter();
                }
            }
            final MenuItem sendDirectMessageItem = menu.findItem(MENU_SEND_DIRECT_MESSAGE);
            if (sendDirectMessageItem != null) {
                sendDirectMessageItem.setVisible(mFriendship.isTargetFollowingSource());
            }
        } else {
            final int size = menu.size();
            for (int i = 0; i < size; i++) {
                final MenuItem item = menu.getItem(i);
                final int id = item.getItemId();
                item.setVisible(id == R.id.set_color_submenu || id == MENU_EXTENSIONS_SUBMENU);
            }
        }
        final MenuItem extensions = menu.findItem(MENU_EXTENSIONS_SUBMENU);
        if (extensions != null) {
            final Intent intent = new Intent(INTENT_ACTION_EXTENSION_OPEN_USER);
            final Bundle extras = new Bundle();
            extras.putParcelable(INTENT_KEY_USER, mUser);
            intent.putExtras(extras);
            addIntentToSubMenu(getActivity(), extensions.getSubMenu(), intent);
        }
        mPopupMenu.setOnMenuItemClickListener(this);
        mPopupMenu.show();
        break;
    }
    case R.id.name_container: {
        if (mUser == null || mAccountId != mUserId)
            return;
        startActivity(new Intent(getActivity(), EditUserProfileActivity.class));
        break;
    }
    }

}

From source file:com.mishiranu.dashchan.ui.navigator.NavigatorActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    if (searchMode) {
        return true;
    }//from  ww w .  j  a v a 2s.  c o m
    if (page != null && sendPrepareMenuToPage) {
        page.onPrepareOptionsMenu(menu);
    }
    MenuItem appearanceOptionsItem = menu.findItem(ListPage.OPTIONS_MENU_APPEARANCE);
    if (appearanceOptionsItem != null) {
        Menu appearanceOptionsMenu = appearanceOptionsItem.getSubMenu();
        appearanceOptionsMenu.findItem(ListPage.APPEARANCE_MENU_EXPANDED_SCREEN)
                .setChecked(Preferences.isExpandedScreen());
        appearanceOptionsMenu.findItem(ListPage.APPEARANCE_MENU_SPOILERS)
                .setChecked(Preferences.isShowSpoilers());
        appearanceOptionsMenu.findItem(ListPage.APPEARANCE_MENU_MY_POSTS)
                .setChecked(Preferences.isShowMyPosts());
        boolean lockable = ViewUtils.isDrawerLockable(getResources().getConfiguration());
        boolean locked = Preferences.isDrawerLocked();
        appearanceOptionsMenu.findItem(ListPage.APPEARANCE_MENU_DRAWER).setVisible(lockable).setChecked(locked);
        appearanceOptionsMenu.findItem(ListPage.APPEARANCE_MENU_THREADS_GRID)
                .setChecked(Preferences.isThreadsGridMode());
        appearanceOptionsMenu.findItem(ListPage.APPEARANCE_MENU_SFW_MODE).setChecked(Preferences.isSfwMode());
    }
    actionMenuConfigurator.onAfterPrepareOptionsMenu(menu);
    return true;
}

From source file:com.mishiranu.dashchan.ui.navigator.NavigatorActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if (searchMode) {
        currentMenu = null;// ww w .  ja  va  2s.co m
        menu.add(0, ListPage.OPTIONS_MENU_SEARCH_VIEW, 0, "").setActionView(getSearchView(true))
                .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    } else {
        currentMenu = menu;
        if (page != null) {
            page.onCreateOptionsMenu(menu);
            sendPrepareMenuToPage = true;
        }
        MenuItem appearanceOptionsItem = menu.findItem(ListPage.OPTIONS_MENU_APPEARANCE);
        if (appearanceOptionsItem != null) {
            Menu appearanceOptionsMenu = appearanceOptionsItem.getSubMenu();
            appearanceOptionsMenu.add(0, ListPage.APPEARANCE_MENU_CHANGE_THEME, 0,
                    R.string.action_change_theme);
            appearanceOptionsMenu
                    .add(0, ListPage.APPEARANCE_MENU_EXPANDED_SCREEN, 0, R.string.action_expanded_screen)
                    .setCheckable(true);
            appearanceOptionsMenu.add(0, ListPage.APPEARANCE_MENU_SPOILERS, 0, R.string.action_spoilers)
                    .setCheckable(true);
            appearanceOptionsMenu.add(0, ListPage.APPEARANCE_MENU_MY_POSTS, 0, R.string.action_my_posts)
                    .setCheckable(true);
            appearanceOptionsMenu.add(0, ListPage.APPEARANCE_MENU_DRAWER, 0, R.string.action_lock_drawer)
                    .setCheckable(true);
            appearanceOptionsMenu.add(0, ListPage.APPEARANCE_MENU_THREADS_GRID, 0, R.string.action_threads_grid)
                    .setCheckable(true);
            appearanceOptionsMenu.add(0, ListPage.APPEARANCE_MENU_SFW_MODE, 0, R.string.action_sfw_mode)
                    .setCheckable(true);
        }
        actionMenuConfigurator.onAfterCreateOptionsMenu(menu);
    }
    return true;
}