List of usage examples for android.view MenuItem setChecked
public MenuItem setChecked(boolean checked);
From source file:com.google.android.apps.forscience.whistlepunk.MainActivity.java
@Override public boolean onNavigationItemSelected(MenuItem menuItem) { if (menuItem == null) { return false; }/*from w w w .ja va2 s. c o m*/ if (menuItem.getGroupId() == R.id.navigation_top) { FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction transaction = fragmentManager.beginTransaction(); Fragment fragment; int itemId = menuItem.getItemId(); final String tag = String.valueOf(itemId); fragment = getFragmentManager().findFragmentByTag(tag); if (fragment == null) { fragment = createNewFragment(itemId); } adjustActivityForSelectedItem(itemId); mTitleToRestore = getTitleToRestore(menuItem); transaction.replace(R.id.content_container, fragment, tag).commit(); if (menuItem.isCheckable()) { menuItem.setChecked(true); } mDrawerLayout.closeDrawers(); restoreActionBar(); mSelectedItemId = itemId; } else if (menuItem.getGroupId() == R.id.navigation_bottom) { mDrawerLayout.closeDrawers(); // Launch intents Intent intent = null; int itemId = menuItem.getItemId(); if (itemId == R.id.navigation_item_website) { intent = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.website_url))); } else if (itemId == R.id.navigation_item_settings) { intent = SettingsActivity.getLaunchIntent(this, menuItem.getTitle(), SettingsActivity.TYPE_SETTINGS); } else if (itemId == R.id.navigation_item_about) { intent = SettingsActivity.getLaunchIntent(this, menuItem.getTitle(), SettingsActivity.TYPE_ABOUT); } else if (itemId == R.id.dev_testing_options) { intent = SettingsActivity.getLaunchIntent(this, menuItem.getTitle(), SettingsActivity.TYPE_DEV_OPTIONS); } else if (itemId == R.id.navigation_item_feedback) { mFeedbackProvider.sendFeedback(new LoggingConsumer<Boolean>(TAG, "Send feedback") { @Override public void success(Boolean value) { if (!value) { showFeedbackError(); } } @Override public void fail(Exception e) { super.fail(e); showFeedbackError(); } }); } if (intent != null) { startActivity(intent); } } return false; }
From source file:org.cm.podd.report.activity.HomeActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_home); updateUserStatus();/*from w w w .j a v a 2 s .c o m*/ final Context context = this; mMenuTitles = new String[] { getString(R.string.home_menu_reports), getString(R.string.home_menu_news), getString(R.string.home_menu_incidents) }; Toolbar myToolbar = findViewById(R.id.my_toolbar); setSupportActionBar(myToolbar); // notification receiver from gcm intent service registerReceiver(mNotificationReceiver, new IntentFilter(RECEIVE_MESSAGE_ACTION)); // initialize and create or upgrade db notificationDataSource = new NotificationDataSource(this); administrationDataSource = new AdministrationAreaDataSource(this); feedItemDataSource = new FeedItemDataSource(this); recordSpecDataSource = RecordSpecDataSource.Companion.getInstance(this); notifCountView = getLayoutInflater().inflate(R.layout.notif_count, null); // initialize prefs sharedPrefUtil = new SharedPrefUtil((getApplicationContext())); final TabLayout tabLayout = findViewById(R.id.tab_layout); activeIcons = new int[] { R.drawable.ic_new_report_active, R.drawable.ic_news_active, R.drawable.ic_feed_active }; defaultIcons = new int[] { R.drawable.ic_new_report, R.drawable.ic_news, R.drawable.ic_feed }; tabNewReport = tabLayout.newTab().setIcon(activeIcons[0]).setText(R.string.home_menu_reports); tabNews = tabLayout.newTab().setIcon(defaultIcons[1]).setText(R.string.home_menu_news); tabFeed = tabLayout.newTab().setIcon(defaultIcons[2]).setText(R.string.home_menu_incidents); tabLayout.addTab(tabNewReport); tabLayout.addTab(tabFeed); tabLayout.addTab(tabNews); tabLayout.setTabGravity(TabLayout.GRAVITY_FILL); tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { switch (tab.getPosition()) { case 0: if (mCurrentFragment instanceof DashboardFeedFragment) { ((DashboardFeedFragment) mCurrentFragment).onPauseRefresh(); } mCurrentFragment = new ReportListFragment(); setTitle(getAppTitle()); drawerPosition = 0; tabNewReport.setIcon(activeIcons[0]); tabNews.setIcon(defaultIcons[1]); tabFeed.setIcon(defaultIcons[2]); break; case 1: mCurrentFragment = new DashboardFeedFragment(); ((DashboardFeedFragment) mCurrentFragment).onRefresh(); drawerPosition = 1; tabNewReport.setIcon(defaultIcons[0]); tabNews.setIcon(defaultIcons[1]); tabFeed.setIcon(activeIcons[2]); break; case 2: if (mCurrentFragment instanceof DashboardFeedFragment) { ((DashboardFeedFragment) mCurrentFragment).onPauseRefresh(); } mCurrentFragment = new NotificationListFragment(); drawerPosition = 2; tabNewReport.setIcon(defaultIcons[0]); tabNews.setIcon(activeIcons[1]); tabFeed.setIcon(defaultIcons[2]); break; case 3: drawerPosition = 3; tabNewReport.setIcon(defaultIcons[0]); tabNews.setIcon(defaultIcons[1]); tabFeed.setIcon(defaultIcons[2]); break; } invalidateOptionsMenu(); changeFragment(); } @Override public void onTabUnselected(TabLayout.Tab tab) { } @Override public void onTabReselected(TabLayout.Tab tab) { } }); navigationView = findViewById(R.id.navigation_view); navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { item.setChecked(true); switch (item.getItemId()) { case R.id.user_profile: showSetting(); break; case R.id.user_password: showChangePassword(); break; case R.id.app_version_code: return true; case R.id.app_version_name: return true; case R.id.logout: new AlertDialog.Builder(context).setTitle(R.string.confirm_logout_title) .setMessage(getString(R.string.confirm_logout_text)) .setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { logout(); } }).setNegativeButton(R.string.btn_not_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }).create().show(); break; default: int recordId = item.getItemId(); RecordSpec spec = recordSpecDataSource.get(recordId); if (spec != null) { showRecordActivity(recordId); } } mDrawerLayout.closeDrawers(); changeFragment(); return true; } }); mDrawerLayout = findViewById(R.id.drawer_layout); updateProfile(); updateRecordMenu(); // Set the adapter for the list view setNotificationCount(); refreshDrawerMenu(); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, myToolbar, 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() } }; TextView appVersionCode = (TextView) navigationView.getMenu().findItem(R.id.app_version_code) .getActionView(); appVersionCode.setText(String.valueOf(BuildConfig.VERSION_CODE)); TextView appVersionName = (TextView) navigationView.getMenu().findItem(R.id.app_version_name) .getActionView(); appVersionName.setText(String.valueOf(BuildConfig.VERSION_NAME)); mDrawerToggle.setDrawerIndicatorEnabled(true); // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); getSupportActionBar().setHomeButtonEnabled(true); View drawerHeader = findViewById(R.id.drawer_header); FontUtil.overrideFonts(this, drawerHeader); localChangeConnectivityReceiver = new ConnectivityChangeReceiver(); LocalBroadcastManager.getInstance(getApplicationContext()).registerReceiver(localChangeConnectivityReceiver, new IntentFilter(DataSubmitService.ACTION_REPORT_SUBMIT)); /* return to last position after recreate activity */ if (savedInstanceState != null) { drawerPosition = savedInstanceState.getInt("drawerPosition"); } else { drawerPosition = 0; } drawerPosition = 0; selectItem(drawerPosition); onNewIntent(getIntent()); registerReceiver(recordSpecReceiver, new IntentFilter(SyncRecordSpecService.SYNC)); startSyncRecordSpec(); Intent getAreaIntent = new Intent(this, SyncAdministrationAreaService.class); startService(getAreaIntent); registerConnectivityChanged(); }
From source file:cz.maresmar.sfm.view.guide.WelcomeActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. switch (item.getItemId()) { case R.id.action_about: SfmApp.startAboutActivity(this); return true; case R.id.action_feedback: SfmApp app = (SfmApp) getApplication(); app.sendFeedback(this); return true; case R.id.advanced_check_box: // Android doesn't handle checked <-> unchecked behavior automatically // in popup menu mAdvSettings = !mAdvSettings;//from ww w .j a v a 2s .c om item.setChecked(mAdvSettings); // Make it survive inflate from fragments return true; default: return super.onOptionsItemSelected(item); } }
From source file:com.master.metehan.filtereagle.ActivityMain.java
@Override public boolean onOptionsItemSelected(MenuItem item) { Log.i(TAG, "Menu=" + item.getTitle()); // Handle item selection SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); switch (item.getItemId()) { case R.id.menu_app_user: item.setChecked(!item.isChecked()); prefs.edit().putBoolean("show_user", item.isChecked()).apply(); return true; case R.id.menu_app_system: item.setChecked(!item.isChecked()); prefs.edit().putBoolean("show_system", item.isChecked()).apply(); return true; case R.id.menu_app_nointernet: item.setChecked(!item.isChecked()); prefs.edit().putBoolean("show_nointernet", item.isChecked()).apply(); return true; case R.id.menu_app_disabled: item.setChecked(!item.isChecked()); prefs.edit().putBoolean("show_disabled", item.isChecked()).apply(); return true; case R.id.menu_sort_name: item.setChecked(true);//from w w w . j a va 2s.co m prefs.edit().putString("sort", "name").apply(); return true; case R.id.menu_sort_uid: item.setChecked(true); prefs.edit().putString("sort", "uid").apply(); return true; case R.id.menu_sort_data: item.setChecked(true); prefs.edit().putString("sort", "data").apply(); return true; case R.id.menu_log: if (IAB.isPurchased(ActivityPro.SKU_LOG, this)) startActivity(new Intent(this, ActivityLog.class)); else startActivity(new Intent(this, ActivityPro.class)); return true; case R.id.menu_settings: startActivity(new Intent(this, ActivitySettings.class)); return true; case R.id.menu_pro: startActivity(new Intent(ActivityMain.this, ActivityPro.class)); return true; case R.id.menu_invite: startActivityForResult(getIntentInvite(this), REQUEST_INVITE); return true; case R.id.menu_legend: menu_legend(); return true; case R.id.menu_support: startActivity(getIntentSupport()); return true; case R.id.menu_about: menu_about(); return true; default: return super.onOptionsItemSelected(item); } }
From source file:com.example.matt.bingeList.viewControllers.activities.movies.WatchlistActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. ArrayList<MovieWatchListFragment> movieWatchListFragments = new ArrayList<>(); movieWatchListFragments.add((MovieWatchListFragment) mAdapterViewPager.getItem(0)); movieWatchListFragments.add((MovieWatchListFragment) mAdapterViewPager.getItem(1)); switch (item.getItemId()) { case R.id.action_settings: return true; case R.id.card_view: PreferencesHelper.setRecyclerviewViewType(ViewType.CARD, getApplicationContext()); viewPager.setAdapter(mAdapterViewPager); viewPager.setCurrentItem(mViewPagerPosition); item.setChecked(true); tabs.setupWithViewPager(viewPager); setTabDrawables();/* www. j ava2 s . c om*/ return true; case R.id.compact_view: PreferencesHelper.setRecyclerviewViewType(ViewType.COMPACT_CARD, getApplicationContext()); viewPager.setAdapter(mAdapterViewPager); viewPager.setCurrentItem(mViewPagerPosition); item.setChecked(true); tabs.setupWithViewPager(viewPager); setTabDrawables(); return true; case R.id.list_view: PreferencesHelper.setRecyclerviewViewType(ViewType.LIST, getApplicationContext()); mAdapterViewPager.notifyDataSetChanged(); viewPager.setAdapter(mAdapterViewPager); viewPager.setCurrentItem(mViewPagerPosition); item.setChecked(true); tabs.setupWithViewPager(viewPager); setTabDrawables(); return true; case R.id.action_sort: return true; case R.id.light_theme: PreferencesHelper.setTheme(ThemeEnum.DAY_THEME, getApplicationContext()); item.setChecked(true); finish(); startActivity(getIntent()); ; return true; case R.id.dark_theme: PreferencesHelper.setTheme(ThemeEnum.NIGHT_THEME, getApplicationContext()); item.setChecked(true); finish(); startActivity(getIntent()); ; return true; case android.R.id.home: mNavigationDrawer.openDrawer(); return true; // Sorting case R.id.date_added_sort: PreferencesHelper.setMovieSort(MovieSort.DATE_ADDED, getApplicationContext()); for (MovieWatchListFragment fragment : movieWatchListFragments) { if (fragment != null) { fragment.sort(MovieSort.DATE_ADDED); } } item.setChecked(true); return true; case R.id.alphabetical_sort: PreferencesHelper.setMovieSort(MovieSort.ALPHABETICAL, getApplicationContext()); for (MovieWatchListFragment fragment : movieWatchListFragments) { if (fragment != null) { fragment.sort(MovieSort.ALPHABETICAL); } } item.setChecked(true); return true; case R.id.rating_sort: PreferencesHelper.setMovieSort(MovieSort.RATING, getApplicationContext()); for (MovieWatchListFragment fragment : movieWatchListFragments) { if (fragment != null) { fragment.sort(MovieSort.RATING); } } item.setChecked(true); return true; case R.id.runtime_sort: PreferencesHelper.setMovieSort(MovieSort.RUNTIME, getApplicationContext()); for (MovieWatchListFragment fragment : movieWatchListFragments) { if (fragment != null) { fragment.sort(MovieSort.RUNTIME); } } item.setChecked(true); return true; default: // If we got here, the user's action was not recognized. // Invoke the superclass to handle it. return super.onOptionsItemSelected(item); } }
From source file:com.khmelenko.lab.travisclient.activity.MainActivity.java
/** * Sets up navigation drawer layout// ww w .j a v a 2 s . co m */ private void setupDrawerLayout() { mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); final NavigationView view = (NavigationView) findViewById(R.id.navigation_view); view.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.drawer_login: Intent loginIntent = new Intent(MainActivity.this, AuthActivity.class); startActivityForResult(loginIntent, AUTH_ACTIVITY_CODE); break; case R.id.drawer_logout: getPresenter().userLogout(); finish(); startActivity(getIntent()); break; case R.id.drawer_licenses: LicensesDialogFragment dialog = LicensesDialogFragment.newInstance(); dialog.show(getSupportFragmentManager(), "LicensesDialog"); break; case R.id.drawer_about: Intent aboutIntent = new Intent(MainActivity.this, AboutActivity.class); startActivity(aboutIntent); break; } menuItem.setChecked(false); mDrawerLayout.closeDrawers(); return true; } }); }
From source file:net.grobas.blizzardleaderboards.app.ui.MainActivity.java
@Override public boolean onNavigationItemSelected(MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.menu_2v2: currentBracket = 0;// w ww . j a va 2 s . c o m setToolbarTitle(R.string.arena2v2); break; case R.id.menu_3v3: currentBracket = 1; setToolbarTitle(R.string.arena3v3); break; case R.id.menu_5v5: currentBracket = 2; setToolbarTitle(R.string.arena5v5); break; case R.id.menu_rbg: currentBracket = 3; setToolbarTitle(R.string.ratedbg); break; case R.id.menu_settings: startActivity(new Intent(this, SettingsActivity.class)); return true; case R.id.menu_license: //TODO return true; } selectedBracketId = menuItem.getItemId(); menuItem.setChecked(true); startLoading(); setDataFromService(false); closeNavDrawer(); return true; }
From source file:github.daneren2005.dsub.activity.SubsonicActivity.java
@Override public void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); int size = savedInstanceState.getInt(Constants.MAIN_BACK_STACK_SIZE); String[] ids = savedInstanceState.getStringArray(Constants.MAIN_BACK_STACK); FragmentManager fm = getSupportFragmentManager(); currentFragment = (SubsonicFragment) fm.findFragmentByTag(ids[0]); currentFragment.setPrimaryFragment(true); currentFragment.setSupportTag(ids[0]); supportInvalidateOptionsMenu();/*from w ww . j av a2 s. co m*/ FragmentTransaction trans = getSupportFragmentManager().beginTransaction(); for (int i = 1; i < size; i++) { SubsonicFragment frag = (SubsonicFragment) fm.findFragmentByTag(ids[i]); frag.setSupportTag(ids[i]); if (secondaryContainer != null) { frag.setPrimaryFragment(false, true); } trans.hide(frag); backStack.add(frag); } trans.commit(); // Current fragment is hidden in secondaryContainer if (secondaryContainer == null && !currentFragment.isVisible()) { trans = getSupportFragmentManager().beginTransaction(); trans.remove(currentFragment); trans.commit(); getSupportFragmentManager().executePendingTransactions(); trans = getSupportFragmentManager().beginTransaction(); trans.add(R.id.fragment_container, currentFragment, ids[0]); trans.commit(); } // Current fragment needs to be moved over to secondaryContainer else if (secondaryContainer != null && secondaryContainer.findViewById(currentFragment.getRootId()) == null && backStack.size() > 0) { trans = getSupportFragmentManager().beginTransaction(); trans.remove(currentFragment); trans.show(backStack.get(backStack.size() - 1)); trans.commit(); getSupportFragmentManager().executePendingTransactions(); trans = getSupportFragmentManager().beginTransaction(); trans.add(R.id.fragment_second_container, currentFragment, ids[0]); trans.commit(); secondaryContainer.setVisibility(View.VISIBLE); } lastSelectedPosition = savedInstanceState.getInt(Constants.FRAGMENT_POSITION); if (lastSelectedPosition != 0) { MenuItem item = drawerList.getMenu().findItem(lastSelectedPosition); if (item != null) { item.setChecked(true); } } recreateSpinner(); }
From source file:github.daneren2005.dsub.activity.SubsonicActivity.java
private void populateTabs() { drawerList.getMenu().clear();//from w w w .j av a 2 s.co m drawerList.inflateMenu(R.menu.drawer_navigation); SharedPreferences prefs = Util.getPreferences(this); boolean podcastsEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_PODCASTS_ENABLED, true); boolean bookmarksEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_BOOKMARKS_ENABLED, true) && !Util.isOffline(this) && ServerInfo.canBookmark(this); boolean sharedEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_SHARED_ENABLED, true) && !Util.isOffline(this); boolean chatEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_CHAT_ENABLED, true) && !Util.isOffline(this); boolean adminEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_ADMIN_ENABLED, true) && !Util.isOffline(this); MenuItem offlineMenuItem = drawerList.getMenu().findItem(R.id.drawer_offline); if (Util.isOffline(this)) { setDrawerItemVisible(R.id.drawer_home, false); if (lastSelectedPosition == 0 || lastSelectedPosition == R.id.drawer_home) { String newFragment = Util.openToTab(this); if (newFragment == null || "Home".equals(newFragment)) { newFragment = "Artist"; } lastSelectedPosition = getDrawerItemId(newFragment); drawerItemSelected(newFragment); } offlineMenuItem.setTitle(R.string.main_online); } else { offlineMenuItem.setTitle(R.string.main_offline); } if (!podcastsEnabled) { setDrawerItemVisible(R.id.drawer_podcasts, false); } if (!bookmarksEnabled) { setDrawerItemVisible(R.id.drawer_bookmarks, false); } if (!sharedEnabled) { setDrawerItemVisible(R.id.drawer_shares, false); } if (!chatEnabled) { setDrawerItemVisible(R.id.drawer_chat, false); } if (!adminEnabled) { setDrawerItemVisible(R.id.drawer_admin, false); } if (lastSelectedPosition != 0) { MenuItem item = drawerList.getMenu().findItem(lastSelectedPosition); if (item != null) { item.setChecked(true); } } drawerHeaderToggle.setImageResource(R.drawable.main_select_server_dark); showingTabs = true; }
From source file:ar.com.tristeslostrestigres.diasporanativewebapp.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); progressBar = findViewById(R.id.progressBar); pm = new PrefManager(MainActivity.this); SharedPreferences config = getSharedPreferences("PodSettings", MODE_PRIVATE); podDomain = config.getString("podDomain", null); fab = findViewById(R.id.multiple_actions); fab.setVisibility(View.GONE); Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar);/*from w w w.j ava 2s.com*/ getSupportActionBar().setTitle(null); txtTitle = (TextView) findViewById(R.id.toolbar_title); txtTitle.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (Helpers.isOnline(MainActivity.this)) { txtTitle.setText(R.string.jb_stream); webView.loadUrl("https://" + podDomain + "/stream"); } else { Snackbar.make(v, R.string.no_internet, Snackbar.LENGTH_SHORT).show(); } } }); webView = findViewById(R.id.webView); webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); webView.addJavascriptInterface(new JavaScriptInterface(), "NotificationCounter"); if (savedInstanceState != null) { webView.restoreState(savedInstanceState); } wSettings = webView.getSettings(); wSettings.setJavaScriptEnabled(true); wSettings.setUseWideViewPort(true); wSettings.setLoadWithOverviewMode(true); wSettings.setDomStorageEnabled(true); wSettings.setMinimumFontSize(pm.getMinimumFontSize()); wSettings.setLoadsImagesAutomatically(pm.getLoadImages()); if (android.os.Build.VERSION.SDK_INT >= 21) wSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); /* * WebViewClient */ webView.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { if (!url.contains(podDomain)) { Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(i); return true; } return false; } public void onPageFinished(WebView view, String url) { if (url.contains("/new") || url.contains("/sign_in")) { fab.setVisibility(View.GONE); } else { fab.setVisibility(View.VISIBLE); } } public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { new AlertDialog.Builder(MainActivity.this).setIcon(android.R.drawable.ic_dialog_alert) .setMessage(description).setPositiveButton("CLOSE", null).show(); } }); /* * WebChromeClient */ webView.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView wv, int progress) { progressBar.setProgress(progress); if (progress > 0 && progress <= 60) { Helpers.getNotificationCount(wv); } if (progress > 60) { Helpers.hideTopBar(wv); fab.setVisibility(View.VISIBLE); } if (progress == 100) { fab.collapse(); progressBar.setVisibility(View.GONE); } else { progressBar.setVisibility(View.VISIBLE); } } @Override public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) { if (mFilePathCallback != null) mFilePathCallback.onReceiveValue(null); mFilePathCallback = filePathCallback; Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(getPackageManager()) != null) { // Create the File where the photo should go File photoFile = null; try { photoFile = createImageFile(); takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath); } catch (IOException ex) { // Error occurred while creating the File Snackbar.make(getWindow().findViewById(R.id.drawer), "Unable to get image", Snackbar.LENGTH_SHORT).show(); } // Continue only if the File was successfully created if (photoFile != null) { mCameraPhotoPath = "file:" + photoFile.getAbsolutePath(); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); } else { takePictureIntent = null; } } Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT); contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE); contentSelectionIntent.setType("image/*"); Intent[] intentArray; if (takePictureIntent != null) { intentArray = new Intent[] { takePictureIntent }; } else { intentArray = new Intent[0]; } Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER); chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent); chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser"); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray); startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE); return true; } public boolean onJsAlert(WebView view, String url, String message, JsResult result) { return super.onJsAlert(view, url, message, result); } }); /* * NavigationView */ NavigationView navigationView = findViewById(R.id.navigation_view); navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) { if (menuItem.isChecked()) menuItem.setChecked(false); else menuItem.setChecked(true); drawerLayout.closeDrawers(); switch (menuItem.getItemId()) { default: Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); return true; case R.id.jb_stream: if (Helpers.isOnline(MainActivity.this)) { txtTitle.setText(R.string.jb_stream); webView.loadUrl("https://" + podDomain + "/stream"); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); return false; } case R.id.jb_public: setTitle(R.string.jb_public); if (Helpers.isOnline(MainActivity.this)) { webView.loadUrl("https://" + podDomain + "/public"); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); return false; } case R.id.jb_liked: txtTitle.setText(R.string.jb_liked); if (Helpers.isOnline(MainActivity.this)) { webView.loadUrl("https://" + podDomain + "/liked"); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); return false; } case R.id.jb_commented: txtTitle.setText(R.string.jb_commented); if (Helpers.isOnline(MainActivity.this)) { webView.loadUrl("https://" + podDomain + "/commented"); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); return false; } case R.id.jb_contacts: txtTitle.setText(R.string.jb_contacts); if (Helpers.isOnline(MainActivity.this)) { webView.loadUrl("https://" + podDomain + "/contacts"); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); return false; } case R.id.jb_mentions: txtTitle.setText(R.string.jb_mentions); if (Helpers.isOnline(MainActivity.this)) { webView.loadUrl("https://" + podDomain + "/mentions"); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); return false; } case R.id.jb_activities: txtTitle.setText(R.string.jb_activities); if (Helpers.isOnline(MainActivity.this)) { webView.loadUrl("https://" + podDomain + "/activity"); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); return false; } case R.id.jb_followed_tags: txtTitle.setText(R.string.jb_followed_tags); if (Helpers.isOnline(MainActivity.this)) { webView.loadUrl("https://" + podDomain + "/followed_tags"); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); return false; } case R.id.jb_manage_tags: txtTitle.setText(R.string.jb_manage_tags); if (Helpers.isOnline(MainActivity.this)) { webView.loadUrl("https://" + podDomain + "/tag_followings/manage"); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); return false; } case R.id.jb_license: txtTitle.setText(R.string.jb_license); new AlertDialog.Builder(MainActivity.this).setTitle(getString(R.string.license_title)) .setMessage(getString(R.string.license_text)) .setPositiveButton(getString(R.string.license_yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/mdev88/Diaspora-Native-WebApp")); startActivity(i); dialog.cancel(); } }) .setNegativeButton(getString(R.string.license_no), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }) .show(); return true; case R.id.jb_aspects: txtTitle.setText(R.string.jb_aspects); if (Helpers.isOnline(MainActivity.this)) { webView.loadUrl("https://" + podDomain + "/aspects"); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); return false; } case R.id.jb_settings: txtTitle.setText(R.string.jb_settings); if (Helpers.isOnline(MainActivity.this)) { webView.loadUrl("https://" + podDomain + "/user/edit"); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); return false; } case R.id.jb_pod: txtTitle.setText(R.string.jb_pod); if (Helpers.isOnline(MainActivity.this)) { new AlertDialog.Builder(MainActivity.this).setTitle(getString(R.string.confirmation)) .setMessage(getString(R.string.change_pod_warning)) .setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() { @TargetApi(11) public void onClick(DialogInterface dialog, int id) { webView.clearCache(true); dialog.cancel(); Intent i = new Intent(MainActivity.this, PodsActivity.class); startActivity(i); finish(); } }).setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() { @TargetApi(11) public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }).show(); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); return false; } } } }); /* * DrawerLayout */ drawerLayout = findViewById(R.id.drawer); ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.openDrawer, R.string.closeDrawer); drawerLayout.setDrawerListener(actionBarDrawerToggle); //calling sync state is necessary or else your hamburger icon wont show up actionBarDrawerToggle.syncState(); if (savedInstanceState == null) { if (Helpers.isOnline(MainActivity.this)) { webView.loadData("", "text/html", null); webView.loadUrl("https://" + podDomain); } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT) .show(); } } }