From bebd72638460a2c6b27a9fb518326851d6019f23 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Thu, 12 Mar 2015 21:07:43 +0100 Subject: twitter Step3 -> Step2 --- .../linked/LinkedIdCreateTwitterStep1Fragment.java | 6 +- .../linked/LinkedIdCreateTwitterStep2Fragment.java | 149 ++++++++++++++++++++ .../linked/LinkedIdCreateTwitterStep3Fragment.java | 154 --------------------- 3 files changed, 151 insertions(+), 158 deletions(-) create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateTwitterStep2Fragment.java delete mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateTwitterStep3Fragment.java diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateTwitterStep1Fragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateTwitterStep1Fragment.java index 06ca32e2e..081b949d5 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateTwitterStep1Fragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateTwitterStep1Fragment.java @@ -27,8 +27,6 @@ import android.view.ViewGroup; import android.widget.EditText; import org.sufficientlysecure.keychain.R; -import org.sufficientlysecure.keychain.pgp.linked.RawLinkedIdentity; -import org.sufficientlysecure.keychain.pgp.linked.resources.TwitterResource; import org.sufficientlysecure.keychain.ui.util.Notify; import java.io.IOException; @@ -94,8 +92,8 @@ public class LinkedIdCreateTwitterStep1Fragment extends Fragment { return; } - LinkedIdCreateTwitterStep3Fragment frag = - LinkedIdCreateTwitterStep3Fragment.newInstance(handle); + LinkedIdCreateTwitterStep2Fragment frag = + LinkedIdCreateTwitterStep2Fragment.newInstance(handle); mLinkedIdWizard.loadFragment(null, frag, LinkedIdWizard.FRAG_ACTION_TO_RIGHT); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateTwitterStep2Fragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateTwitterStep2Fragment.java new file mode 100644 index 000000000..1074a8e61 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateTwitterStep2Fragment.java @@ -0,0 +1,149 @@ +/* + * Copyright (C) 2014 Dominik Schürmann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.sufficientlysecure.keychain.ui.linked; + +import android.content.Intent; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.View.OnClickListener; +import android.view.ViewGroup; +import android.widget.EditText; + +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.pgp.linked.LinkedCookieResource; +import org.sufficientlysecure.keychain.pgp.linked.LinkedIdentity; +import org.sufficientlysecure.keychain.pgp.linked.RawLinkedIdentity; +import org.sufficientlysecure.keychain.pgp.linked.resources.TwitterResource; +import org.sufficientlysecure.keychain.ui.util.Notify; + +import java.util.List; + +public class LinkedIdCreateTwitterStep2Fragment extends LinkedIdCreateFinalFragment { + + public static final String ARG_HANDLE = "handle"; + + EditText mEditTweetPreview; + + String mResourceHandle; + String mResourceString; + private int mNonce; + + public static LinkedIdCreateTwitterStep2Fragment newInstance + (String handle) { + + LinkedIdCreateTwitterStep2Fragment frag = new LinkedIdCreateTwitterStep2Fragment(); + + int proofNonce = RawLinkedIdentity.generateNonce(); + + Bundle args = new Bundle(); + args.putString(ARG_HANDLE, handle); + args.putInt(ARG_NONCE, proofNonce); + frag.setArguments(args); + + return frag; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + mNonce = LinkedIdentity.generateNonce(); + mResourceString = + TwitterResource.generate(getActivity(), mLinkedIdWizard.mFingerprint, mNonce); + + mResourceHandle = getArguments().getString(ARG_HANDLE); + + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View view = super.onCreateView(inflater, container, savedInstanceState); + + mEditTweetPreview = (EditText) view.findViewById(R.id.linked_create_twitter_preview); + mEditTweetPreview.setText(mResourceString); + + view.findViewById(R.id.button_send).setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + proofSend(); + } + }); + + view.findViewById(R.id.button_share).setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + proofShare(); + } + }); + + return view; + } + + @Override + LinkedCookieResource getResource() { + return TwitterResource.searchInTwitterStream(mResourceHandle, mResourceString); + } + + @Override + protected View newView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + return inflater.inflate(R.layout.linked_create_twitter_fragment_step3, container, false); + } + + private void proofShare() { + Intent sendIntent = new Intent(); + sendIntent.setAction(Intent.ACTION_SEND); + sendIntent.putExtra(Intent.EXTRA_TEXT, mResourceString); + sendIntent.setType("text/plain"); + startActivity(sendIntent); + } + + private void proofSend() { + + Intent tweetIntent = new Intent(Intent.ACTION_SEND); + tweetIntent.putExtra(Intent.EXTRA_TEXT, mResourceString); + tweetIntent.setType("text/plain"); + + PackageManager packManager = getActivity().getPackageManager(); + List resolvedInfoList = packManager.queryIntentActivities(tweetIntent, + PackageManager.MATCH_DEFAULT_ONLY); + + boolean resolved = false; + for(ResolveInfo resolveInfo : resolvedInfoList) { + if(resolveInfo.activityInfo.packageName.startsWith("com.twitter.android")) { + tweetIntent.setClassName( + resolveInfo.activityInfo.packageName, + resolveInfo.activityInfo.name ); + resolved = true; + break; + } + } + + if (resolved) { + startActivity(tweetIntent); + } else { + Notify.showNotify(getActivity(), + "Twitter app is not installed, please use the send intent!", + Notify.Style.ERROR); + } + + } + +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateTwitterStep3Fragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateTwitterStep3Fragment.java deleted file mode 100644 index ce0526efc..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateTwitterStep3Fragment.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright (C) 2014 Dominik Schürmann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package org.sufficientlysecure.keychain.ui.linked; - -import android.content.Intent; -import android.content.pm.PackageManager; -import android.content.pm.ResolveInfo; -import android.graphics.PorterDuff; -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.view.LayoutInflater; -import android.view.View; -import android.view.View.OnClickListener; -import android.view.ViewGroup; -import android.widget.EditText; -import android.widget.ImageView; -import android.widget.TextView; - -import org.sufficientlysecure.keychain.R; -import org.sufficientlysecure.keychain.pgp.linked.LinkedCookieResource; -import org.sufficientlysecure.keychain.pgp.linked.LinkedIdentity; -import org.sufficientlysecure.keychain.pgp.linked.LinkedResource; -import org.sufficientlysecure.keychain.pgp.linked.RawLinkedIdentity; -import org.sufficientlysecure.keychain.pgp.linked.resources.TwitterResource; -import org.sufficientlysecure.keychain.ui.util.Notify; - -import java.util.List; - -public class LinkedIdCreateTwitterStep3Fragment extends LinkedIdCreateFinalFragment { - - public static final String ARG_HANDLE = "handle"; - - EditText mEditTweetPreview; - - String mResourceHandle; - String mResourceString; - private int mNonce; - - public static LinkedIdCreateTwitterStep3Fragment newInstance - (String handle) { - - LinkedIdCreateTwitterStep3Fragment frag = new LinkedIdCreateTwitterStep3Fragment(); - - int proofNonce = RawLinkedIdentity.generateNonce(); - - Bundle args = new Bundle(); - args.putString(ARG_HANDLE, handle); - args.putInt(ARG_NONCE, proofNonce); - frag.setArguments(args); - - return frag; - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - mNonce = LinkedIdentity.generateNonce(); - mResourceString = - TwitterResource.generate(getActivity(), mLinkedIdWizard.mFingerprint, mNonce); - - mResourceHandle = getArguments().getString(ARG_HANDLE); - - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = super.onCreateView(inflater, container, savedInstanceState); - - mEditTweetPreview = (EditText) view.findViewById(R.id.linked_create_twitter_preview); - mEditTweetPreview.setText(mResourceString); - - view.findViewById(R.id.button_send).setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - proofSend(); - } - }); - - view.findViewById(R.id.button_share).setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - proofShare(); - } - }); - - return view; - } - - @Override - LinkedCookieResource getResource() { - return TwitterResource.searchInTwitterStream(mResourceHandle, mResourceString); - } - - @Override - protected View newView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - return inflater.inflate(R.layout.linked_create_twitter_fragment_step3, container, false); - } - - private void proofShare() { - Intent sendIntent = new Intent(); - sendIntent.setAction(Intent.ACTION_SEND); - sendIntent.putExtra(Intent.EXTRA_TEXT, mResourceString); - sendIntent.setType("text/plain"); - startActivity(sendIntent); - } - - private void proofSend() { - - Intent tweetIntent = new Intent(Intent.ACTION_SEND); - tweetIntent.putExtra(Intent.EXTRA_TEXT, mResourceString); - tweetIntent.setType("text/plain"); - - PackageManager packManager = getActivity().getPackageManager(); - List resolvedInfoList = packManager.queryIntentActivities(tweetIntent, - PackageManager.MATCH_DEFAULT_ONLY); - - boolean resolved = false; - for(ResolveInfo resolveInfo : resolvedInfoList) { - if(resolveInfo.activityInfo.packageName.startsWith("com.twitter.android")) { - tweetIntent.setClassName( - resolveInfo.activityInfo.packageName, - resolveInfo.activityInfo.name ); - resolved = true; - break; - } - } - - if (resolved) { - startActivity(tweetIntent); - } else { - Notify.showNotify(getActivity(), - "Twitter app is not installed, please use the send intent!", - Notify.Style.ERROR); - } - - } - -} -- cgit v1.2.3