コード例 #1
0
 @Override
 public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
   super.onCreateOptionsMenu(menu, inflater);
   if (Constants.DEBUG) {
     inflater.inflate(R.menu.backup_fragment_debug_menu, menu);
   }
 }
コード例 #2
0
 @Override
 public void onCreate(@Nullable Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   if (Constants.DEBUG) {
     setHasOptionsMenu(true);
   }
 }
コード例 #3
0
  @Override
  public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    if (savedInstanceState != null) {
      int savedBackStack = savedInstanceState.getInt(ARG_BACK_STACK);
      if (savedBackStack >= 0) {
        mBackStackLevel = savedBackStack;
        // unchecked use, we know that this one is available in onViewCreated
        getFragmentManager().addOnBackStackChangedListener(this);
      }
      BackupCodeState savedState =
          BackupCodeState.values()[savedInstanceState.getInt(ARG_CURRENT_STATE)];
      switchState(savedState, false);
    } else if (mCurrentState == BackupCodeState.STATE_UNINITIALIZED) {
      switchState(BackupCodeState.STATE_DISPLAY, true);
    }
  }
コード例 #4
0
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode != REQUEST_SAVE) {
      super.onActivityResult(requestCode, resultCode, data);
      return;
    }

    if (resultCode != FragmentActivity.RESULT_OK) {
      return;
    }

    FragmentActivity activity = getActivity();
    if (activity == null) {
      return;
    }
    try {
      Uri outputUri = data.getData();
      FileHelper.copyUriData(activity, mCachedBackupUri, outputUri);
      Notify.create(activity, R.string.snack_backup_saved, Style.OK).show();
    } catch (IOException e) {
      Notify.create(activity, R.string.snack_backup_error_saving, Style.ERROR).show();
    }
  }
コード例 #5
0
 @Override
 public void onSaveInstanceState(Bundle outState) {
   super.onSaveInstanceState(outState);
   outState.putInt(ARG_CURRENT_STATE, mCurrentState.ordinal());
   outState.putInt(ARG_BACK_STACK, mBackStackLevel == null ? -1 : mBackStackLevel);
 }
コード例 #6
0
  @Override
  public void onResume() {
    super.onResume();

    LinkedIdWizard wizard = (LinkedIdWizard) getActivity();
    mFingerprint = wizard.mFingerprint;
    mMasterKeyId = wizard.mMasterKeyId;

    final String oAuthCode = wizard.oAuthGetCode();
    final String oAuthState = wizard.oAuthGetState();
    if (oAuthCode == null) {
      Log.d(Constants.TAG, "no code");
      return;
    }

    final String gistText = GithubResource.generate(wizard, mFingerprint);

    Log.d(Constants.TAG, "got code: " + oAuthCode);

    new AsyncTask<Void, Void, JSONObject>() {
      @Override
      protected JSONObject doInBackground(Void... dummy) {
        try {

          long timer = System.currentTimeMillis();

          JSONObject params = new JSONObject();
          params.put("client_id", "7a011b66275f244d3f21");
          params.put("client_secret", "eaced8a6655719d8c6848396de97b3f5d7a89fec");
          params.put("code", oAuthCode);
          params.put("state", oAuthState);

          JSONObject result =
              jsonHttpRequest("https://github.com/login/oauth/access_token", params, null);

          // ux flow: this operation should take at last a second
          timer = System.currentTimeMillis() - timer;
          if (timer < 1000)
            try {
              Thread.sleep(1000 - timer);
            } catch (InterruptedException e) {
              // never mind
            }

          return result;

        } catch (IOException e) {
          Log.e(Constants.TAG, "error in request", e);
        } catch (JSONException e) {
          throw new AssertionError("json error, this is a bug!");
        }
        return null;
      }

      @Override
      protected void onPostExecute(JSONObject result) {
        super.onPostExecute(result);

        Log.d(Constants.TAG, "response: " + result);

        if (result == null || !result.has("access_token")) {
          mStatus1.setDisplayedChild(3);
          return;
        }

        mStatus1.setDisplayedChild(2);
        step2PostGist(result.optString("access_token"), gistText);
      }
    }.execute();
  }
コード例 #7
0
 @Override
 public void onCryptoOperationCancelled() {
   super.onCryptoOperationCancelled();
   mStatus3.setDisplayedChild(3);
 }