Exemple #1
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case android.R.id.home:
        /* This is called when the Home (Up) button is pressed
         * in the Action Bar. http://goo.gl/lJxjA */
        Intent upIntent = new Intent(this, MainActivity.class);
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
          TaskStackBuilder.from(this).addNextIntent(upIntent).startActivities();
          finish();
        } else {
          NavUtils.navigateUpTo(this, upIntent);
        }
        return true;

      case R.id.menu_preferences:
        Intent preferencesActivity = new Intent(getBaseContext(), SettingsActivity.class);
        startActivity(preferencesActivity);
        return true;

      case R.id.menu_upload:
        if (Constants.PRO_VERSION) {
          Intent localPhotosActivity = new Intent(getBaseContext(), LocalPhotosActivity.class);
          startActivity(localPhotosActivity);
        } else {
          BuyProDialog.show(this);
        }
        return true;

      case R.id.menu_about:
        new AboutDialogFragment().show(getSupportFragmentManager(), "AboutDialogFragment");
        return true;
    }
    return super.onOptionsItemSelected(item);
  }
Exemple #2
0
 public static boolean navigateUp(@NonNull final Activity activity) {
   // first check if there is a parent declared in the manifest
   Intent upIntent = NavUtils.getParentActivityIntent(activity);
   // if there is no parent, and if this was not a new task, then just go back to simulate going to
   // a parent
   if (upIntent == null && !activity.isTaskRoot()) {
     activity.finish();
     return true;
   }
   // use the main activity, if there was no back stack and no manifest based parent
   if (upIntent == null) {
     upIntent = new Intent(CgeoApplication.getInstance(), MainActivity.class);
   }
   if (NavUtils.shouldUpRecreateTask(activity, upIntent) || activity.isTaskRoot()) {
     // This activity is NOT part of this app's task, so create a new task
     // when navigating up, with a synthesized back stack.
     TaskStackBuilder.create(activity)
         // Add all of this activity's parents to the back stack
         .addNextIntentWithParentStack(upIntent)
         // Navigate up to the closest parent
         .startActivities();
   } else {
     // This activity is part of this app's task, so simply
     // navigate up to the logical parent activity.
     NavUtils.navigateUpTo(activity, upIntent);
   }
   return true;
 }
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case android.R.id.home:
       // This is called when the Home (Up) button is pressed in the action bar.
       // Create a simple intent that starts the hierarchical parent activity and
       // use NavUtils in the Support Package to ensure proper handling of Up.
       Intent upIntent = new Intent(this, MainActivity.class);
       if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
         // This activity is not part of the application's task, so create a new task
         // with a synthesized back stack.
         TaskStackBuilder.from(this)
             // If there are ancestor activities, they should be added here.
             .addNextIntent(upIntent)
             .startActivities();
         finish();
       } else {
         // This activity is part of the application's task, so simply
         // navigate up to the hierarchical parent activity.
         NavUtils.navigateUpTo(this, upIntent);
       }
       return true;
   }
   return super.onOptionsItemSelected(item);
 }
 protected void onHomePressed() {
   Intent upIntent = NavUtils.getParentActivityIntent(this);
   if (upIntent != null && NavUtils.shouldUpRecreateTask(this, upIntent)) {
     TaskStackBuilder.create(this).addNextIntentWithParentStack(upIntent).startActivities();
   } else {
     finish();
   }
 }
Exemple #5
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case android.R.id.home:
        Intent upIntent = NavUtils.getParentActivityIntent(this);
        if (upIntent != null)
          if (NavUtils.shouldUpRecreateTask(this, upIntent))
            TaskStackBuilder.create(this).addNextIntentWithParentStack(upIntent).startActivities();
          else NavUtils.navigateUpTo(this, upIntent);

        return true;
      case R.id.menu_all:
        List<String> listRestriction = PrivacyManager.getRestrictions();

        // Get toggle
        boolean restricted = false;
        for (String restrictionName : listRestriction)
          if (PrivacyManager.getRestricted(
              null, this, mAppInfo.getUid(), restrictionName, null, false, false)) {
            restricted = true;
            break;
          }

        // Do toggle
        restricted = !restricted;
        for (String restrictionName : listRestriction)
          PrivacyManager.setRestricted(
              null, this, mAppInfo.getUid(), restrictionName, null, restricted);

        // Refresh display
        if (mPrivacyListAdapter != null) mPrivacyListAdapter.notifyDataSetChanged();

        return true;
      case R.id.menu_app_launch:
        Intent LaunchIntent =
            getPackageManager().getLaunchIntentForPackage(mAppInfo.getPackageName());
        startActivity(LaunchIntent);
        return true;
      case R.id.menu_app_settings:
        startActivity(
            new Intent(
                android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
                Uri.parse("package:" + mAppInfo.getPackageName())));
        return true;
      case R.id.menu_app_store:
        startActivity(
            new Intent(
                Intent.ACTION_VIEW, Uri.parse("market://details?id=" + mAppInfo.getPackageName())));
        return true;
      default:
        return super.onOptionsItemSelected(item);
    }
  }
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case android.R.id.home:
       Intent destIntent = new Intent(this, MainActivity.class);
       if (NavUtils.shouldUpRecreateTask(this, destIntent)) {
         startActivity(destIntent);
       } else {
         NavUtils.navigateUpFromSameTask(this);
       }
       return true;
   }
   return super.onOptionsItemSelected(item);
 }
 private void backToPictureMenu() {
   Intent upIntent = NavUtils.getParentActivityIntent(this);
   upIntent.putExtra("REDIRECT", true);
   if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
     // This activity is NOT part of this app's task, so create a new task
     // when navigating up, with a synthesized back stack.
     TaskStackBuilder.create(this)
         // Add all of this activity's parents to the back stack
         .addNextIntentWithParentStack(upIntent)
         // Navigate up to the closest parent
         .startActivities();
   } else {
     // This activity is part of this app's task, so simply
     // navigate up to the logical parent activity.
     NavUtils.navigateUpTo(this, upIntent);
   }
 }
  @SuppressWarnings("unchecked")
  @Override
  public boolean onMenuItemSelected(int featureId, MenuItem item) {
    switch (item.getItemId()) {
      case android.R.id.home:
        Intent upIntent = new Intent(this, SelectAccountActivity.class);
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
          TaskStackBuilder.create(this).addNextIntent(upIntent).startActivities();
        } else {
          NavUtils.navigateUpTo(this, upIntent);
        }
        return true;

      case R.id.menu_sync_now:

        // This is a convenient way of enabling and running the contact photo
        // sync.

        Account a = new Account(account, ACCOUNT_TYPE);
        ContentResolver.setSyncAutomatically(a, CONTACT_PHOTO_AUTHORITY, true);
        ContentResolver.requestSync(a, CONTACT_PHOTO_AUTHORITY, new Bundle());
        Toast.makeText(this, getResources().getString(R.string.sync_requested), Toast.LENGTH_LONG)
            .show();
        break;

      case R.id.menu_download_all:
      case R.id.menu_upload_all:
        new DownloadUploadTask(
                item.getItemId() == R.id.menu_download_all
                    ? DownloadUploadTask.TYPE_DOWNLOAD
                    : DownloadUploadTask.TYPE_UPLOAD)
            .execute(((ContactAdapter) contactList.getAdapter()).getBackingList());

        break;

      case R.id.menu_refresh:

        // XXX This is ugly and hackish. This of course doesn't stop us from being
        // lazy and using it here.

        onPause();
        onResume();
        break;
    }
    return super.onOptionsItemSelected(item);
  }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case android.R.id.home:
        Intent upIntent = new Intent(this, MainActivity.class);
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {

          TaskStackBuilder.from(this).addNextIntent(upIntent).startActivities();

          finish();
        } else {

          NavUtils.navigateUpTo(this, upIntent);
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
  }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();

    switch (id) {
      case R.id.action_settings:
        return true;
      case R.id.home:
        Intent upIntent = NavUtils.getParentActivityIntent(this);
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
          TaskStackBuilder.create(this).addNextIntentWithParentStack(upIntent).startActivities();
        } else {
          NavUtils.navigateUpTo(this, upIntent);
        }
        return true;
    }

    return super.onOptionsItemSelected(item);
  }
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   // TODO Auto-generated method stub
   switch (item.getItemId()) {
     case android.R.id.home:
       Intent upIntent = new Intent(this, MainActivity.class);
       if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
         TaskStackBuilder.from(this)
             // 如果这里有很多原始的Activity,它们应该被添加在这里
             .addNextIntent(upIntent)
             .startActivities();
         finish();
       } else {
         NavUtils.navigateUpTo(this, upIntent);
       }
       break;
   }
   return super.onOptionsItemSelected(item);
 }
 private void backToStagesMenu() {
   Intent upIntent = NavUtils.getParentActivityIntent(this);
   upIntent.putExtra(AssessmentStageListActivity.REDIRECT_FROM_REPORT, true);
   if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
     // This activity is NOT part of this app's task, so create a new task
     // when navigating up, with a synthesized back stack.
     TaskStackBuilder.create(this)
         // Add all of this activity's parents to the back stack
         .addNextIntentWithParentStack(upIntent)
         // Navigate up to the closest parent
         .startActivities();
   } else {
     // This activity is part of this app's task, so simply
     // navigate up to the logical parent activity.
     // NavUtils.navigateUpTo(this, upIntent) does not work on JellyBean
     // NavUtils.navigateUpTo(this, upIntent);
     upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
     startActivity(upIntent);
     finish();
   }
 }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection

    switch (item.getItemId()) {
      case android.R.id.home:
        Intent upIntent = new Intent(this, AChatActivity.class);
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
          TaskStackBuilder.from(this).addNextIntent(upIntent).startActivities();
          finish();
        } else {
          NavUtils.navigateUpTo(this, upIntent);
        }
        return true;

      case R.id.action_refresh:
        mXwalkView.load(url, null);
        return true;

      default:
        return super.onOptionsItemSelected(item);
    }
  }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        // Respond to the action bar's Up/Home button
      case android.R.id.home:
        android.content.Intent upIntent = NavUtils.getParentActivityIntent(this);
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
          TaskStackBuilder.create(this).addNextIntentWithParentStack(upIntent).startActivities();
        } else {
          NavUtils.navigateUpTo(this, upIntent);
        }
        return true;
      case R.id.action_from_gallery:
        ActionLog.log("gallery opened");
        openGallery();
        return true;
      case R.id.action_take_photo:
        ActionLog.log("camera opened");
        dispatchTakePictureIntent();
        return true;
    }

    return super.onOptionsItemSelected(item);
  }
  private void backToAssessmentList() {
    // Clear the current assessment, as this is a new stating point
    try {
      getSkavaContext().setAssessment(SkavaUtils.createInitialAssessment(getSkavaContext()));
    } catch (DAOException e) {
      throw new SkavaSystemException(e);
    }

    Intent upIntent = new Intent(this, AssessmentsListActivity.class);
    //        upIntent.putExtra("REDIRECT", true);
    if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
      // This activity is NOT part of this app's task, so create a new task
      // when navigating up, with a synthesized back stack.
      TaskStackBuilder.create(this)
          // Add all of this activity's parents to the back stack
          .addNextIntentWithParentStack(upIntent)
          // Navigate up to the closest parent
          .startActivities();
    } else {
      // This activity is part of this app's task, so simply
      // navigate up to the logical parent activity.
      NavUtils.navigateUpTo(this, upIntent);
    }
  }
 public boolean supportShouldUpRecreateTask(Intent targetIntent) {
   return NavUtils.shouldUpRecreateTask(this, targetIntent);
 }
 public boolean a(Intent paramIntent) {
   return NavUtils.shouldUpRecreateTask(this, paramIntent);
 }