Example #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) {
   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);
 }
Example #3
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);
  }
 protected void onHomePressed() {
   Intent upIntent = NavUtils.getParentActivityIntent(this);
   if (upIntent != null && NavUtils.shouldUpRecreateTask(this, upIntent)) {
     TaskStackBuilder.create(this).addNextIntentWithParentStack(upIntent).startActivities();
   } else {
     finish();
   }
 }
Example #5
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);
 }
Example #6
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);
    }
  }
Example #7
0
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case android.R.id.home:
       if (NavUtils.getParentActivityName(this) != null) {
         NavUtils.navigateUpFromSameTask(this);
       }
       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) {
    switch (item.getItemId()) {
      case android.R.id.home:
        NavUtils.navigateUpTo(this, new Intent(this, Main.class));
        return true;

      case R.id.action_go_back:
        NavUtils.navigateUpTo(this, new Intent(this, Main.class));
        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);
 }
 @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);
 }
 @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);
 }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case android.R.id.home:
        // Navigate "up" the demo structure to the launchpad activity.
        // See http://developer.android.com/design/patterns/navigation.html for more.
        NavUtils.navigateUpTo(this, new Intent(this, ChooseFairyTale.class));
        return true;

        //            case R.id.action_previous:
        // Go to the previous step in the wizard. If there is no previous step,
        // setCurrentItem will do nothing.
        //                mPager.setCurrentItem(mPager.getCurrentItem() - 1);
        //                return true;

        //            case R.id.action_next:
        //                // Advance to the next step in the wizard. If there is no next step,
        // setCurrentItem
        //                // will do nothing.
        //                mPager.setCurrentItem(mPager.getCurrentItem() + 1);
        //                return true;
    }

    return super.onOptionsItemSelected(item);
  }
  public void rateStory(View view) {

    RatingBar ratingBar = (RatingBar) findViewById(R.id.rating_bar);
    int rating = (int) Math.round(ratingBar.getRating());
    System.out.println(rating);

    // Update rating if user hit like button
    try {
      // Store json object with value of user rating
      JSONObject storyRate = getStoryObj();
      storyRate.put("rating", rating);

      System.out.println(storyRate.toString());

      // Post json data with rating to server
      Utility.postJsonData(
          storyRate.toString(), getResources().getString(R.string.server_rate_story));

    } catch (Exception e) {
      getResources().getString(R.string.server_error);
      e.printStackTrace();
    }
    // Go back to main activity after sending rating
    NavUtils.navigateUpFromSameTask(this);
  }
  @SuppressWarnings("StatementWithEmptyBody")
  @Override
  public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();
    if (id == R.id.nav_home) {
      Intent intent = new Intent(getApplicationContext(), MainActivity.class);
      startActivity(intent);
    } else if (id == R.id.nav_house) {
      // Handle the home action
      NavUtils.navigateUpFromSameTask(
          this); // GOES UP FROM THIS ACTIVITY TO THE PARENT ACTIVITY - PROPERTYACTIVITY. This
                 // should make navigation faster
    } /*else if (id == R.id.nav_gallery) {

      } else if (id == R.id.nav_slideshow) {

      } else if (id == R.id.nav_manage) {

      } else if (id == R.id.nav_share) {

      } else if (id == R.id.nav_send) {

      }*/

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout_property_list);
    drawer.closeDrawer(GravityCompat.START);
    return true;
  }
Example #16
0
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case android.R.id.home:
       Intent upIntent = new Intent(this, MainActivity.class);
       // 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
       //
       NavUtils.navigateUpTo(this, upIntent);
       return true;
     case R.id.frag1:
       if (!isfrag1) {
         getSupportFragmentManager().beginTransaction().replace(R.id.text_container, one).commit();
         isfrag1 = true;
         supportInvalidateOptionsMenu();
       }
       return true;
     case R.id.frag2:
       if (isfrag1) {
         getSupportFragmentManager().beginTransaction().replace(R.id.text_container, two).commit();
         isfrag1 = false;
         supportInvalidateOptionsMenu();
       }
       return true;
   }
   return super.onOptionsItemSelected(item);
 }
Example #17
0
  @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();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
      Toast.makeText(
              getApplicationContext(),
              "Sept 17,18,19 @\n"
                  + "SJCET, Choondacherry P.O,\n"
                  + "Palai-686 579, \n"
                  + "Kottayam DISTRICT\n"
                  + "Kerala,India",
              Toast.LENGTH_LONG)
          .show();
    }

    if (id == android.R.id.home) {
      NavUtils.navigateUpFromSameTask(this);
    }

    return super.onOptionsItemSelected(item);
  }
  @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
        //
        NavUtils.navigateUpFromSameTask(this);
        return true;

      case R.id.menu_sign_out:
        try {
          dbAdapter.clearAllTables();
        } catch (Exception e) {
          e.printStackTrace();
        }
        finish();
        Intent intent = new Intent(this.getApplicationContext(), LoginActivity.class);
        startActivity(intent);
        break;
      default:
        break;
    }

    return super.onOptionsItemSelected(item);
  }
Example #19
0
 /*
  * Wird aufgerufen, wenn auf einen ActionBar Knopf gedrückt wird
  */
 @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
       //
       NavUtils.navigateUpFromSameTask(this);
       return true;
     case R.id.action_search:
       openSearch();
       return true;
     case R.id.action_settings:
       openSettings();
       return true;
     case R.id.action_map:
       openLiveKarte();
       return true;
     default:
       return super.onOptionsItemSelected(item);
   }
 }
  @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
        //
        NavUtils.navigateUpFromSameTask(this);
        return true;

      case R.id.action_send:
        ParseObject message = createMessage();

        if (message == null) {
          AlertDialog.Builder builder = new AlertDialog.Builder(this);
          builder
              .setMessage(R.string.error_file_selected)
              .setTitle(R.string.error_title)
              .setPositiveButton(android.R.string.ok, null);
          AlertDialog dialog = builder.create();
          dialog.show();

        } else {
          send(message);
          finish();
        }

        return true;
    }
    return super.onOptionsItemSelected(item);
  }
  private void selectItem(int position) {

    Activity activity = null;

    switch (position) {
        // Campus Select
      case 0:
        // startActivity(new Intent(this, CamSelTest.class));
        NavUtils.navigateUpFromSameTask(this);
        mDrawerLayout.closeDrawer(mDrawerList);

        break;
        // Help
      case 1:
        startActivity(new Intent(this, Help.class));
        mDrawerLayout.closeDrawer(mDrawerList);
        break;
        // About Us
      case 2:
        startActivity(new Intent(this, AboutUs.class));
        mDrawerLayout.closeDrawer(mDrawerList);
        break;

      default:
        break;
    }
  }
  @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);
  }
 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(android.view.MenuItem item) {
   if (item.getItemId() == android.R.id.home) {
     NavUtils.navigateUpFromSameTask(this);
     return true;
   }
   return super.onOptionsItemSelected(item);
 }
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case android.R.id.home:
       if (templateStory) {
         NavUtils.navigateUpTo(this, new Intent(this, StoryTemplateActivity.class));
       } else {
         NavUtils.navigateUpFromSameTask(this);
       }
       return true;
     case R.id.itemForward:
       int idx = getSupportActionBar().getSelectedNavigationIndex();
       getSupportActionBar().setSelectedNavigationItem(Math.min(2, idx + 1));
       return true;
   }
   return super.onOptionsItemSelected(item);
 }
Example #26
0
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case android.R.id.home:
       NavUtils.navigateUpFromSameTask(this);
       return true;
   }
   return super.onOptionsItemSelected(item);
 }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
      NavUtils.navigateUpTo(this, new Intent(this, ArticleListActivity.class));
      return true;
    }

    return super.onOptionsItemSelected(item);
  }
Example #28
0
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   if (item.getItemId() == android.R.id.home) {
     Intent intent = new Intent(this, LicenseActivity.class);
     NavUtils.navigateUpTo(this, intent);
     return true;
   }
   return false;
 }
 @Override
 public void onBackPressed() {
   super.onBackPressed();
   String value = emailLogin.getText().toString();
   ActivityManager.setSharedStringValue(
       ForgetPasswordActivity.this, SELECTED_EMAIL, (null == value ? "" : value));
   NavUtils.navigateUpFromSameTask(this);
   overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
 }
  @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);
  }