예제 #1
0
  /** Opens the specified list and closes the left drawer */
  void openList(final long id) {
    // Open list
    Intent i = new Intent(ActivityMain.this, ActivityMain_.class);
    i.setAction(Intent.ACTION_VIEW)
        .setData(TaskList.getUri(id))
        .addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

    // If editor is on screen, we need to reload fragments
    if (listOpener == null) {
      while (getSupportFragmentManager().popBackStackImmediate()) {
        // Need to pop the entire stack and then load
      }
      reverseAnimation = true;
      startActivity(i);
    } else {
      // If not popped, then send the call to the fragment
      // directly
      Log.d("nononsenseapps list", "calling listOpener");
      listOpener.openList(id);
    }

    // And then close drawer
    if (drawerLayout != null && leftDrawer != null) {
      drawerLayout.closeDrawer(leftDrawer);
    }
  }
예제 #2
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Pass the event to ActionBarDrawerToggle, if it returns
    // true, then it has handled the app icon touch event
    if (mDrawerToggle.onOptionsItemSelected(item)) {
      return true;
    }
    // Handle your other action bar items...
    int itemId = item.getItemId();
    if (itemId == android.R.id.home) {
      if (showingEditor) {
        // Only true in portrait mode
        final View focusView = ActivityMain.this.getCurrentFocus();
        if (inputManager != null && focusView != null) {
          inputManager.hideSoftInputFromWindow(
              focusView.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
        }

        // Should load the same list again
        // Try getting the list from the original intent
        final long listId = getListId(getIntent());

        final Intent intent =
            new Intent()
                .setAction(Intent.ACTION_VIEW)
                .setClass(ActivityMain.this, ActivityMain_.class);
        if (listId > 0) {
          intent.setData(TaskList.getUri(listId));
        }

        // Set the intent before, so we set the correct
        // action bar
        setIntent(intent);
        while (getSupportFragmentManager().popBackStackImmediate()) {
          // Need to pop the entire stack and then load
        }

        reverseAnimation = true;
        Log.d("nononsenseapps fragment", "starting activity");

        intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
      }
      // else
      // Handled by drawer
      return true;
    } else if (itemId == R.id.drawer_menu_createlist) {
      // Show fragment
      DialogEditList_ dialog = DialogEditList_.getInstance();
      dialog.setListener(
          new EditListDialogListener() {

            @Override
            public void onFinishEditDialog(long id) {
              openList(id);
            }
          });
      dialog.show(getSupportFragmentManager(), "fragment_create_list");
      return true;
    } else if (itemId == R.id.menu_preferences) {
      Intent intent = new Intent();
      intent.setClass(this, PrefsActivity.class);
      startActivity(intent);
      return true;
    } else if (itemId == R.id.menu_donate) {
      try {
        mBillingHelper.launchPurchaseFlow(
            this,
            SKU_INAPP_PREMIUM,
            SKU_DONATE_REQUEST_CODE,
            new IabHelper.OnIabPurchaseFinishedListener() {
              public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
                if (result.isFailure()) {
                  Log.d("nononsenseapps billing", "Error purchasing: " + result);
                  return;
                } else if (purchase.getSku().equals(SKU_INAPP_PREMIUM)) {
                  mHasPremiumAccess = true;
                  mDonatedInApp = true;
                  // Save in prefs
                  PreferenceManager.getDefaultSharedPreferences(ActivityMain.this)
                      .edit()
                      .putBoolean(SKU_INAPP_PREMIUM, true)
                      .putBoolean(PREMIUMSTATUS, true)
                      .commit();
                  // Update relevant parts of UI
                  updateUiDonate();
                  // Notify user of success
                  Toast.makeText(
                          ActivityMain.this,
                          R.string.premiums_unlocked_and_thanks,
                          Toast.LENGTH_SHORT)
                      .show();
                }
              }
            });
      } catch (Exception e) {
        Log.d("nononsenseapps billing", "Shouldnt start two purchases! " + e.getLocalizedMessage());
      }
      return true;
    } else if (itemId == R.id.menu_sync) {
      handleSyncRequest();
      return true;
    } else if (itemId == R.id.menu_delete) {
      return false;
    } else {
      return false;
    }
  }