Java Code Examples for android.view.MenuItem.getIntent()

The following are Jave code examples for showing how to use getIntent() of the android.view.MenuItem class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: kolibri-android   File: KolibriApp.java   View Source Code Vote up 6 votes
void logMenuItemToFirebase(@NonNull MenuItem item) {
  if (firebaseEnabled) {

    final Intent intent = item.getIntent();

    if (intent == null) {
      Log.i(TAG, "logMenuItemToFirebase: Invalid menu item. Intent must be supplied!");
      return;
    }

    final FirebaseAnalytics firebaseAnalytics = FirebaseAnalytics.getInstance(this);

    final Bundle bundle = new Bundle();
    bundle.putString(FirebaseAnalytics.Param.ITEM_ID, intent.getStringExtra(Kolibri.EXTRA_ID));

    if (intent.hasExtra(Intent.EXTRA_TITLE)) {
      bundle.putString(FirebaseAnalytics.Param.ITEM_NAME,
          intent.getStringExtra(Intent.EXTRA_TITLE));
    }

    bundle
        .putString(FirebaseAnalytics.Param.CONTENT_TYPE, intent.getStringExtra(Kolibri.EXTRA_ID));
    firebaseAnalytics.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle);
  }
}
 
Example 2
Project: kolibri-android   File: KolibriNavigationActivity.java   View Source Code Vote up 5 votes
@Override
public boolean onNavigationItemSelected(@NonNull final MenuItem item) {

  KolibriApp.getInstance().logMenuItemToFirebase(item);

  final MenuItem previouslySelected = getSelectedMenuItem();
  final Intent intent = item.getIntent();

  final PackageManager packageManager = getPackageManager();
  if (intent.resolveActivity(packageManager) != null) {
    // Notify custom components in case they are activities
    KolibriApp.getInstance().logEvent(null, intent.getData().toString());

    // Post to navigation view and select previously one menu item
    // because we won't to select components that are handled by activities.
    navigationView.post(new Runnable() {
      @Override
      public void run() {
        item.setChecked(false);
        previouslySelected.setChecked(true);
      }
    });

    return false;
  }

  notifyComponenets(intent);
  drawer.closeDrawer(GravityCompat.START);
  return true;
}
 
Example 3
Project: OpenHub   File: ActivityFragment.java   View Source Code Vote up 5 votes
@Override
public boolean onContextItemSelected(MenuItem item) {
    if (item.getIntent() != null) {
        startActivity(item.getIntent());
    }
    return true;
}