示例#1
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) {
   // 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.  }   int id = item.getItemId();
   switch (item.getItemId()) {
       // Respond to the action bar's Up/Home button
     case android.R.id.home:
       Intent intent = NavUtils.getParentActivityIntent(this);
       intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
       startActivity(intent);
       overridePendingTransition(0, R.anim.slide_out_right);
       return true;
     case R.id.menu_item_picture:
       mWebView.loadUrl(
           "javascript:document.getElementsByClassName('jianshu_bar')[0].style.display = 'block'");
       this.handler.postDelayed(
           new Runnable() {
             @Override
             public void run() {
               scanContent();
             }
           },
           1000);
       this.scanLight.setVisibility(View.VISIBLE);
       this.scanLight.startAnimation(this.scanAnim);
       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();
   }
 }
示例#4
0
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   if (item.getItemId() == android.R.id.home) {
     Intent upIntent = NavUtils.getParentActivityIntent(this);
     NavUtils.navigateUpTo(this, upIntent);
     return true;
   }
   return super.onOptionsItemSelected(item);
 }
示例#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 viewIntent = NavUtils.getParentActivityIntent(this);
         viewIntent.setData(KeyRings.buildGenericKeyRingUri(mDataUri));
         NavUtils.navigateUpTo(this, viewIntent);
         return true;
       }
   }
   return super.onOptionsItemSelected(item);
 }
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   int id = item.getItemId();
   if (id == android.R.id.home) {
     Intent intent = NavUtils.getParentActivityIntent(this);
     Bundle bundle = new Bundle();
     bundle.putParcelable(ARG_POTENTIAL_HABIT_EDIT, detailFragment.getHabit());
     intent.putExtras(bundle);
     intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
     NavUtils.navigateUpTo(this, intent);
     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);
   }
 }
  @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.
    int id = item.getItemId();

    switch (id) {
      case android.R.id.home:
        Intent bacIntent = NavUtils.getParentActivityIntent(this);
        bacIntent.putExtra(FrontalActivity.EXTRA_OPENEDPAGE, 2);
        startActivity(bacIntent);
        return true;
    }

    return super.onOptionsItemSelected(item);
  }
示例#10
0
  @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);
  }
示例#11
0
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case android.R.id.home:
       // This ID represents the Home or Up button. In the case of this
       // activity, the Up button is shown. Use NavUtils to allow users
       // to navigate up one level in the application structure. For
       // more details, see the Navigation pattern on Android Design:
       //
       // http://developer.android.com/design/patterns/navigation.html#up-vs-back
       //
       Intent upIntent = NavUtils.getParentActivityIntent(this);
       upIntent.putExtra(SingleUnitActivity.EXTRA_DEVICE_ID, mDeviceId);
       upIntent.putExtra(SingleUnitActivity.EXTRA_HARDWARE_UNIT_ID, mHardwareUnit.getId());
       NavUtils.navigateUpTo(this, upIntent);
       return true;
   }
   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();
   }
 }
示例#13
0
  @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);
  }
 @Nullable
 public Intent getSupportParentActivityIntent() {
   return NavUtils.getParentActivityIntent(this);
 }