List of usage examples for android.view Menu getItem
public MenuItem getItem(int index);
From source file:com.android.mail.ui.ActionBarController.java
public boolean onPrepareOptionsMenu(Menu menu) { // We start out with every option enabled. Based on the current view, we disable actions // that are possible. LogUtils.d(LOG_TAG, "ActionBarView.onPrepareOptionsMenu()."); if (mController.shouldHideMenuItems()) { // Shortcut: hide all menu items if the drawer is shown final int size = menu.size(); for (int i = 0; i < size; i++) { final MenuItem item = menu.getItem(i); item.setVisible(false);/*from w w w. j a v a 2 s. c o m*/ } return false; } validateVolatileMenuOptionVisibility(); switch (getMode()) { case ViewMode.CONVERSATION: case ViewMode.SEARCH_RESULTS_CONVERSATION: // We update the ActionBar options when we are entering conversation view because // waiting for the AbstractConversationViewFragment to do it causes duplicate icons // to show up during the time between the conversation is selected and the fragment // is added. setConversationModeOptions(menu); break; case ViewMode.CONVERSATION_LIST: // Show search if the account supports it Utils.setMenuItemVisibility(menu, R.id.search, mAccount.supportsSearch()); break; case ViewMode.SEARCH_RESULTS_LIST: // Hide compose and search Utils.setMenuItemVisibility(menu, R.id.compose, false); Utils.setMenuItemVisibility(menu, R.id.search, false); break; } return false; }
From source file:com.mobicage.rogerthat.plugins.messaging.FriendsThreadActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { for (int i = 0; i < menu.size(); i++) { MenuItem item = menu.getItem(i); switch (item.getItemId()) { case R.id.members: item.setVisible(!SystemUtils.isFlagEnabled(mFlags, MessagingPlugin.FLAG_DYNAMIC_CHAT)); break; case R.id.delete_conversation: item.setVisible(!SystemUtils.isFlagEnabled(mFlags, MessagingPlugin.FLAG_NOT_REMOVABLE)); break; case R.id.info: item.setVisible(SystemUtils.isFlagEnabled(mFlags, MessagingPlugin.FLAG_DYNAMIC_CHAT)); break; }/*from w w w .ja v a 2 s . c om*/ } return true; }
From source file:com.lastsoft.plog.GamesFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); menu.clear();/*from ww w. ja v a2 s. com*/ if (playListType != 2 && !((MainActivity) mActivity).mNavigationDrawerFragment.isDrawerOpen() && ((MainActivity) mActivity).currentFragmentCode != 0) { inflater.inflate(R.menu.games, menu); menuItem0 = menu.getItem(0); if (showExpansions) { menuItem0.setTitle(getString(R.string.hide_expansions)); menuItem0.setIcon(R.drawable.ic_visibility_off); } else { menuItem0.setTitle(getString(R.string.show_expansions)); menuItem0.setIcon(R.drawable.ic_visibility); } } else if (playListType == 2 && !((MainActivity) mActivity).mNavigationDrawerFragment.isDrawerOpen() && ((MainActivity) mActivity).currentFragmentCode != 0) { inflater.inflate(R.menu.bucketlist, menu); } }
From source file:org.cm.podd.report.activity.HomeActivity.java
private void updateRecordMenu() { Menu menu = navigationView.getMenu(); MenuItem menuItem = menu.getItem(0); menuItem.getSubMenu().clear();/*w ww .java 2s .c om*/ int cnt = 0; for (RecordSpec record : recordSpecDataSource.findRootRecords()) { menuItem.getSubMenu().add(0, (int) record.id, cnt, record.name); cnt++; } if (cnt == 0) { menuItem.setVisible(false); } else { menuItem.setVisible(true); } navigationView.invalidate(); mDrawerLayout.invalidate(); }
From source file:com.androidaq.AndroiDAQMain.java
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.option_menu, menu); mMenuItemConnect = menu.getItem(0); return true;//from w w w. ja va 2 s.c o m }
From source file:com.kircherelectronics.accelerationfilter.activity.AccelerationPlotActivity.java
/** * Manage the content of the options menu dynamically. *//*from w w w. ja v a 2s . c o m*/ @Override public boolean onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); if (logData) { menu.getItem(2).getSubMenu().getItem(0).setEnabled(false); } else { menu.getItem(2).getSubMenu().getItem(0).setEnabled(true); } return true; }
From source file:com.klinker.android.twitter.activities.tweet_viewer.TweetPager.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { final int MENU_SHARE = 0; final int MENU_DELETE_TWEET = 1; final int MENU_QUOTE = 2; final int MENU_COPY_TEXT = 3; final int MENU_SAVE_IMAGE = 4; final int MENU_SPAM = 5; if (!isMyTweet) { menu.getItem(MENU_DELETE_TWEET).setVisible(false); } else {/*from w ww .j av a2 s. co m*/ menu.getItem(MENU_QUOTE).setVisible(false); menu.getItem(MENU_SPAM).setVisible(false); } if (!picture) { menu.getItem(MENU_SAVE_IMAGE).setVisible(false); } return true; }
From source file:de.gebatzens.sia.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { setTheme(SIAApp.SIA_APP.school.getTheme()); super.onCreate(savedInstanceState); Log.w("ggvp", "CREATE NEW MAINACTIVITY"); //Debug.startMethodTracing("sia3"); SIAApp.SIA_APP.activity = this; savedState = savedInstanceState;//from w w w.j a v a2 s . c o m final FragmentData.FragmentList fragments = SIAApp.SIA_APP.school.fragments; Intent intent = getIntent(); if (intent != null && intent.getStringExtra("fragment") != null) { FragmentData frag = fragments .getByType(FragmentData.FragmentType.valueOf(intent.getStringExtra("fragment"))).get(0); SIAApp.SIA_APP.setFragmentIndex(fragments.indexOf(frag)); } if (intent != null && intent.getBooleanExtra("reload", false)) { SIAApp.SIA_APP.refreshAsync(null, true, fragments.get(SIAApp.SIA_APP.getFragmentIndex())); intent.removeExtra("reload"); } setContentView(R.layout.activity_main); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); mContent = getFragment(); transaction.replace(R.id.content_fragment, mContent, "gg_content_fragment"); transaction.commit(); Log.d("ggvp", "DATA: " + fragments.get(SIAApp.SIA_APP.getFragmentIndex()).getData()); if (fragments.get(SIAApp.SIA_APP.getFragmentIndex()).getData() == null) SIAApp.SIA_APP.refreshAsync(null, true, fragments.get(SIAApp.SIA_APP.getFragmentIndex())); if ("Summer".equals(SIAApp.SIA_APP.getCurrentThemeName())) { ImageView summerNavigationPalm = (ImageView) findViewById(R.id.summer_navigation_palm); summerNavigationPalm.setImageResource(R.drawable.summer_palm); ImageView summerBackgroundImage = (ImageView) findViewById(R.id.summer_background_image); summerBackgroundImage.setImageResource(R.drawable.summer_background); } mToolBar = (Toolbar) findViewById(R.id.toolbar); mToolBar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.action_refresh: ((SwipeRefreshLayout) mContent.getView().findViewById(R.id.refresh)).setRefreshing(true); SIAApp.SIA_APP.refreshAsync(new Runnable() { @Override public void run() { ((SwipeRefreshLayout) mContent.getView().findViewById(R.id.refresh)) .setRefreshing(false); } }, true, fragments.get(SIAApp.SIA_APP.getFragmentIndex())); return true; case R.id.action_settings: Intent i = new Intent(MainActivity.this, SettingsActivity.class); startActivityForResult(i, 1); return true; case R.id.action_addToCalendar: showExamDialog(); return true; case R.id.action_help: AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setTitle(getApplication().getString(R.string.help)); builder.setMessage(getApplication().getString(R.string.exam_explain)); builder.setPositiveButton(getApplication().getString(R.string.close), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.create().show(); return true; } return false; } }); updateToolbar(SIAApp.SIA_APP.school.name, fragments.get(SIAApp.SIA_APP.getFragmentIndex()).name); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { SIAApp.SIA_APP.setStatusBarColorTransparent(getWindow()); // because of the navigation drawer } mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolBar, R.string.drawer_open, R.string.drawer_close) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { super.onDrawerClosed(view); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } }; mDrawerLayout.addDrawerListener(mDrawerToggle); navigationView = (NavigationView) findViewById(R.id.navigation_view); mNavigationHeader = navigationView.getHeaderView(0); mNavigationSchoolpictureText = (TextView) mNavigationHeader.findViewById(R.id.drawer_image_text); mNavigationSchoolpictureText.setText(SIAApp.SIA_APP.school.name); mNavigationSchoolpicture = (ImageView) mNavigationHeader.findViewById(R.id.navigation_schoolpicture); mNavigationSchoolpicture.setImageBitmap(SIAApp.SIA_APP.school.loadImage()); mNavigationSchoolpictureLink = mNavigationHeader.findViewById(R.id.navigation_schoolpicture_link); mNavigationSchoolpictureLink.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View viewIn) { mDrawerLayout.closeDrawers(); Intent linkIntent = new Intent(Intent.ACTION_VIEW); linkIntent.setData(Uri.parse(SIAApp.SIA_APP.school.website)); startActivity(linkIntent); } }); final Menu menu = navigationView.getMenu(); menu.clear(); for (int i = 0; i < fragments.size(); i++) { MenuItem item = menu.add(R.id.fragments, Menu.NONE, i, fragments.get(i).name); item.setIcon(fragments.get(i).getIconRes()); } menu.add(R.id.settings, R.id.settings_item, fragments.size(), R.string.settings); menu.setGroupCheckable(R.id.fragments, true, true); menu.setGroupCheckable(R.id.settings, false, false); final Menu navMenu = navigationView.getMenu(); selectedItem = SIAApp.SIA_APP.getFragmentIndex(); if (selectedItem != -1) navMenu.getItem(selectedItem).setChecked(true); navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem menuItem) { if (menuItem.getItemId() == R.id.settings_item) { mDrawerLayout.closeDrawers(); Intent i = new Intent(MainActivity.this, SettingsActivity.class); startActivityForResult(i, 1); } else { final int index = menuItem.getOrder(); if (SIAApp.SIA_APP.getFragmentIndex() != index) { SIAApp.SIA_APP.setFragmentIndex(index); menuItem.setChecked(true); updateToolbar(SIAApp.SIA_APP.school.name, menuItem.getTitle().toString()); mContent = getFragment(); Animation fadeOut = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fade_out); fadeOut.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { FrameLayout contentFrame = (FrameLayout) findViewById(R.id.content_fragment); contentFrame.setVisibility(View.INVISIBLE); if (fragments.get(index).getData() == null) SIAApp.SIA_APP.refreshAsync(null, true, fragments.get(index)); //removeAllFragments(); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.replace(R.id.content_fragment, mContent, "gg_content_fragment"); transaction.commit(); snowView.updateSnow(); } @Override public void onAnimationRepeat(Animation animation) { } }); FrameLayout contentFrame = (FrameLayout) findViewById(R.id.content_fragment); contentFrame.startAnimation(fadeOut); mDrawerLayout.closeDrawers(); } else { mDrawerLayout.closeDrawers(); } } return true; } }); if (Build.VERSION.SDK_INT >= 25) { ShortcutManager shortcutManager = getSystemService(ShortcutManager.class); shortcutManager.removeAllDynamicShortcuts(); for (int i = 0; i < fragments.size(); i++) { Drawable drawable = getDrawable(fragments.get(i).getIconRes()); Bitmap icon; if (drawable instanceof VectorDrawable) { icon = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(icon); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); } else { icon = BitmapFactory.decodeResource(getResources(), fragments.get(i).getIconRes()); } Bitmap connectedIcon = Bitmap.createBitmap(icon.getWidth(), icon.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(connectedIcon); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(Color.parseColor("#f5f5f5")); canvas.drawCircle(icon.getWidth() / 2, icon.getHeight() / 2, icon.getWidth() / 2, paint); paint.setColorFilter( new PorterDuffColorFilter(SIAApp.SIA_APP.school.getColor(), PorterDuff.Mode.SRC_ATOP)); canvas.drawBitmap(icon, null, new RectF(icon.getHeight() / 4.0f, icon.getHeight() / 4.0f, icon.getHeight() - icon.getHeight() / 4.0f, icon.getHeight() - icon.getHeight() / 4.0f), paint); Intent newTaskIntent = new Intent(this, MainActivity.class); newTaskIntent.setAction(Intent.ACTION_MAIN); newTaskIntent.putExtra("fragment", fragments.get(i).type.toString()); ShortcutInfo shortcut = new ShortcutInfo.Builder(this, fragments.get(i).name) .setShortLabel(fragments.get(i).name).setLongLabel(fragments.get(i).name) .setIcon(Icon.createWithBitmap(connectedIcon)).setIntent(newTaskIntent).build(); shortcutManager.addDynamicShortcuts(Arrays.asList(shortcut)); } } if (SIAApp.SIA_APP.preferences.getBoolean("app_130_upgrade", true)) { if (!SIAApp.SIA_APP.preferences.getBoolean("first_use_filter", true)) { TextDialog.newInstance(R.string.upgrade1_3title, R.string.upgrade1_3) .show(getSupportFragmentManager(), "upgrade_dialog"); } SIAApp.SIA_APP.preferences.edit().putBoolean("app_130_upgrade", false).apply(); } snowView = (SnowView) findViewById(R.id.snow_view); shareToolbar = (Toolbar) findViewById(R.id.share_toolbar); shareToolbar.getMenu().clear(); shareToolbar.inflateMenu(R.menu.share_toolbar_menu); shareToolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { toggleShareToolbar(false); for (Shareable s : MainActivity.this.shared) { s.setMarked(false); } MainActivity.this.shared.clear(); mContent.updateFragment(); } }); shareToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { toggleShareToolbar(false); HashMap<Date, ArrayList<Shareable>> dates = new HashMap<Date, ArrayList<Shareable>>(); for (Shareable s : MainActivity.this.shared) { ArrayList<Shareable> list = dates.get(s.getDate()); if (list == null) { list = new ArrayList<Shareable>(); dates.put(s.getDate(), list); } list.add(s); s.setMarked(false); } MainActivity.this.shared.clear(); List<Date> dateList = new ArrayList<Date>(dates.keySet()); Collections.sort(dateList); String content = ""; for (Date key : dateList) { content += SubstListAdapter.translateDay(key) + "\n\n"; Collections.sort(dates.get(key)); for (Shareable s : dates.get(key)) { content += s.getShareContent() + "\n"; } content += "\n"; } content = content.substring(0, content.length() - 1); mContent.updateFragment(); if (item.getItemId() == R.id.action_copy) { ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText(getString(R.string.entries), content); clipboard.setPrimaryClip(clip); } else if (item.getItemId() == R.id.action_share) { Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, content); sendIntent.setType("text/plain"); startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_to))); } return true; } }); if (shared.size() > 0) { shareToolbar.setVisibility(View.VISIBLE); updateShareToolbarText(); } // if a fragment is opened via a notification or a shortcut reset the shared entries // delete extra fragment because the same intent is used when the device gets rotated and the user could have opened a new fragment if (intent != null && intent.hasExtra("fragment")) { resetShareToolbar(); intent.removeExtra("fragment"); } }
From source file:com.mifos.mifosxdroid.online.LoanAccountSummaryFragment.java
@Override public void onPrepareOptionsMenu(Menu menu) { menu.clear();/*from ww w . j a v a2s . c o m*/ menu.addSubMenu(Menu.NONE, MENU_ITEM_DATA_TABLES, Menu.NONE, Constants.DATA_TABLE_LOAN_NAME); menu.add(Menu.NONE, MENU_ITEM_LOAN_TRANSACTIONS, Menu.NONE, getResources().getString(R.string.transactions)); menu.add(Menu.NONE, MENU_ITEM_REPAYMENT_SCHEDULE, Menu.NONE, getResources().getString(R.string.loan_repayment_schedule)); menu.add(Menu.NONE, MENU_ITEM_DOCUMENTS, Menu.NONE, getResources().getString(R.string.documents)); menu.add(Menu.NONE, MENU_ITEM_CHARGES, Menu.NONE, getResources().getString(R.string.charges)); int SUBMENU_ITEM_ID = 0; // Create a Sub Menu that holds a link to all data tables SubMenu dataTableSubMenu = menu.getItem(1).getSubMenu(); if (dataTableSubMenu != null && loanDataTables != null && loanDataTables.size() > 0) { Iterator<DataTable> dataTableIterator = loanDataTables.iterator(); while (dataTableIterator.hasNext()) { dataTableSubMenu.add(Menu.NONE, SUBMENU_ITEM_ID, Menu.NONE, dataTableIterator.next().getRegisteredTableName()); SUBMENU_ITEM_ID++; } } super.onPrepareOptionsMenu(menu); }
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 w w . j a v a 2 s .c om*/ 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; } }); }