aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java
diff options
context:
space:
mode:
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java69
1 files changed, 25 insertions, 44 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java
index 3441bb399..8c677199d 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java
@@ -17,7 +17,6 @@
package org.sufficientlysecure.keychain.ui.linked;
-import java.util.Random;
import android.content.Context;
import android.content.Intent;
@@ -25,19 +24,20 @@ import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
+import android.support.v4.app.NavUtils;
+import android.support.v4.app.TaskStackBuilder;
+import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
-import org.spongycastle.util.encoders.Hex;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
import org.sufficientlysecure.keychain.provider.KeychainContract;
+import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.ui.base.BaseActivity;
-import org.sufficientlysecure.keychain.ui.util.Notify;
-import org.sufficientlysecure.keychain.ui.util.Notify.Style;
import org.sufficientlysecure.keychain.util.Log;
public class LinkedIdWizard extends BaseActivity {
@@ -131,53 +131,34 @@ public class LinkedIdWizard extends BaseActivity {
inputManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
- private String mOAuthCode, mOAuthState;
-
@Override
- protected void onNewIntent(Intent intent) {
- super.onNewIntent(intent);
-
- Uri uri = intent.getData();
- Log.d(Constants.TAG, "received oauth uri: " + uri);
- if (mOAuthState != null && uri != null) {
- String state = uri.getQueryParameter("state");
- if (!mOAuthState.equalsIgnoreCase(state)) {
- Notify.create(this, "OAuth State Error!", Style.ERROR).show();
- return;
- }
- mOAuthCode = uri.getQueryParameter("code");
+ public void onBackPressed() {
+ if (!getFragmentManager().popBackStackImmediate()) {
+ navigateBack();
}
-
}
- public String oAuthGetCode() {
- try {
- return mOAuthCode;
- } finally {
- mOAuthCode = null;
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ // Respond to the action bar's Up/Home button
+ case android.R.id.home:
+ navigateBack();
+ return true;
}
+ return super.onOptionsItemSelected(item);
}
- public String oAuthGetState() {
- return mOAuthState;
- }
-
- public void oAuthRequest(String hostAndPath, String clientId, String scope) {
-
- byte[] buf = new byte[16];
- new Random().nextBytes(buf);
- mOAuthState = new String(Hex.encode(buf));
-
- Intent intent = new Intent(
- Intent.ACTION_VIEW,
- Uri.parse("https://" + hostAndPath +
- "?client_id=" + clientId +
- "&scope=" + scope +
- "&redirect_uri=oauth-openkeychain://linked/" +
- "&state=" + mOAuthState));
-
- startActivity(intent);
-
+ private void navigateBack() {
+ Intent upIntent = NavUtils.getParentActivityIntent(this);
+ upIntent.setData(KeyRings.buildGenericKeyRingUri(mMasterKeyId));
+ // 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();
}
}