Merge branch 'master' of https://github.com/open-keychain/open-keychain into improve-file
This commit is contained in:
@@ -18,9 +18,7 @@
|
||||
package org.sufficientlysecure.keychain.ui;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.nfc.NdefMessage;
|
||||
@@ -31,16 +29,12 @@ import android.os.Message;
|
||||
import android.os.Messenger;
|
||||
import android.os.Parcelable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.TypedValue;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
|
||||
import com.github.johnpersano.supertoasts.SuperCardToast;
|
||||
import com.github.johnpersano.supertoasts.SuperToast;
|
||||
@@ -51,7 +45,6 @@ import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.helper.OtherHelper;
|
||||
import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry;
|
||||
import org.sufficientlysecure.keychain.keyimport.KeybaseKeyserver;
|
||||
import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
|
||||
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
|
||||
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
||||
@@ -130,60 +123,13 @@ public class ImportKeysActivity extends ActionBarActivity {
|
||||
|
||||
mNavigationStrings = getResources().getStringArray(R.array.import_action_list);
|
||||
|
||||
if (ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN.equals(getIntent().getAction())) {
|
||||
setTitle(R.string.nav_import);
|
||||
} else {
|
||||
initTabs();
|
||||
}
|
||||
// TODO: add actionbar button for this action?
|
||||
// if (ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN.equals(getIntent().getAction())) {
|
||||
// }
|
||||
|
||||
handleActions(savedInstanceState, getIntent());
|
||||
}
|
||||
|
||||
private void initTabs() {
|
||||
mTabsAdapter = new PagerTabStripAdapter(this);
|
||||
mViewPager.setAdapter(mTabsAdapter);
|
||||
mSlidingTabLayout.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||
// resize view pager back to 64 if keyserver settings have been collapsed
|
||||
if (getViewPagerHeight() > VIEW_PAGER_HEIGHT) {
|
||||
resizeViewPager(VIEW_PAGER_HEIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int state) {
|
||||
}
|
||||
});
|
||||
|
||||
Bundle serverBundle = new Bundle();
|
||||
// serverBundle.putParcelable(ViewKeyMainFragment.ARG_DATA_URI, dataUri);
|
||||
mTabsAdapter.addTab(ImportKeysServerFragment.class,
|
||||
serverBundle, getString(R.string.import_tab_keyserver));
|
||||
|
||||
Bundle qrCodeBundle = new Bundle();
|
||||
// importBundle.putParcelable(ViewKeyMainFragment.ARG_DATA_URI, dataUri);
|
||||
mTabsAdapter.addTab(ImportKeysQrCodeFragment.class,
|
||||
qrCodeBundle, getString(R.string.import_tab_qr_code));
|
||||
|
||||
Bundle fileBundle = new Bundle();
|
||||
// importBundle.putParcelable(ViewKeyMainFragment.ARG_DATA_URI, dataUri);
|
||||
mTabsAdapter.addTab(ImportKeysFileFragment.class,
|
||||
fileBundle, getString(R.string.import_tab_direct));
|
||||
|
||||
Bundle keybaseBundle = new Bundle();
|
||||
// keybaseBundle.putParcelable(ViewKeyMainFragment.ARG_DATA_URI, dataUri);
|
||||
mTabsAdapter.addTab(ImportKeysKeybaseFragment.class,
|
||||
keybaseBundle, getString(R.string.import_tab_keybase));
|
||||
|
||||
// update layout after operations
|
||||
mSlidingTabLayout.setViewPager(mViewPager);
|
||||
}
|
||||
|
||||
protected void handleActions(Bundle savedInstanceState, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
Bundle extras = intent.getExtras();
|
||||
@@ -200,6 +146,8 @@ public class ImportKeysActivity extends ActionBarActivity {
|
||||
action = ACTION_IMPORT_KEY;
|
||||
}
|
||||
|
||||
Bundle serverBundle = null;
|
||||
boolean serverOnly = false;
|
||||
if (scheme != null && scheme.toLowerCase(Locale.ENGLISH).equals(Constants.FINGERPRINT_SCHEME)) {
|
||||
/* Scanning a fingerprint directly with Barcode Scanner */
|
||||
loadFromFingerprintUri(savedInstanceState, dataUri);
|
||||
@@ -240,10 +188,8 @@ public class ImportKeysActivity extends ActionBarActivity {
|
||||
|
||||
if (query != null && query.length() > 0) {
|
||||
// display keyserver fragment with query
|
||||
Bundle args = new Bundle();
|
||||
args.putString(ImportKeysServerFragment.ARG_QUERY, query);
|
||||
// loadNavFragment(NAV_SERVER, args);
|
||||
//TODO: load afterwards!
|
||||
serverBundle = new Bundle();
|
||||
serverBundle.putString(ImportKeysServerFragment.ARG_QUERY, query);
|
||||
mSwitchToTab = NAV_SERVER;
|
||||
|
||||
// action: search immediately
|
||||
@@ -259,7 +205,19 @@ public class ImportKeysActivity extends ActionBarActivity {
|
||||
*/
|
||||
|
||||
String fingerprint = intent.getStringExtra(EXTRA_FINGERPRINT);
|
||||
loadFromFingerprint(savedInstanceState, fingerprint);
|
||||
if (isFingerprintValid(fingerprint)) {
|
||||
String query = "0x" + fingerprint;
|
||||
|
||||
// display keyserver fragment with query
|
||||
serverBundle = new Bundle();
|
||||
serverBundle.putString(ImportKeysServerFragment.ARG_QUERY, query);
|
||||
serverBundle.putBoolean(ImportKeysServerFragment.ARG_DISABLE_QUERY_EDIT, true);
|
||||
serverOnly = true;
|
||||
mSwitchToTab = NAV_SERVER;
|
||||
|
||||
// action: search immediately
|
||||
startListFragment(savedInstanceState, null, null, query);
|
||||
}
|
||||
} else {
|
||||
Log.e(Constants.TAG,
|
||||
"IMPORT_KEY_FROM_KEYSERVER action needs to contain the 'query', 'key_id', or " +
|
||||
@@ -298,6 +256,44 @@ public class ImportKeysActivity extends ActionBarActivity {
|
||||
startListFragment(savedInstanceState, null, null, null);
|
||||
}
|
||||
|
||||
initTabs(serverBundle, serverOnly);
|
||||
}
|
||||
|
||||
private void initTabs(Bundle serverBundle, boolean serverOnly) {
|
||||
mTabsAdapter = new PagerTabStripAdapter(this);
|
||||
mViewPager.setAdapter(mTabsAdapter);
|
||||
mSlidingTabLayout.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||
// resize view pager back to 64 if keyserver settings have been collapsed
|
||||
if (getViewPagerHeight() > VIEW_PAGER_HEIGHT) {
|
||||
resizeViewPager(VIEW_PAGER_HEIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int state) {
|
||||
}
|
||||
});
|
||||
|
||||
mTabsAdapter.addTab(ImportKeysServerFragment.class,
|
||||
serverBundle, getString(R.string.import_tab_keyserver));
|
||||
if (!serverOnly) {
|
||||
mTabsAdapter.addTab(ImportKeysQrCodeFragment.class,
|
||||
null, getString(R.string.import_tab_qr_code));
|
||||
mTabsAdapter.addTab(ImportKeysFileFragment.class,
|
||||
null, getString(R.string.import_tab_direct));
|
||||
mTabsAdapter.addTab(ImportKeysKeybaseFragment.class,
|
||||
null, getString(R.string.import_tab_keybase));
|
||||
}
|
||||
|
||||
// update layout after operations
|
||||
mSlidingTabLayout.setViewPager(mViewPager);
|
||||
|
||||
mViewPager.setCurrentItem(mSwitchToTab);
|
||||
}
|
||||
|
||||
@@ -338,35 +334,52 @@ public class ImportKeysActivity extends ActionBarActivity {
|
||||
|
||||
Log.d(Constants.TAG, "fingerprint: " + fingerprint);
|
||||
|
||||
loadFromFingerprint(savedInstanceState, fingerprint);
|
||||
// TODO: reload fragment when coming from qr code!
|
||||
// loadFromFingerprint(savedInstanceState, fingerprint);
|
||||
|
||||
|
||||
// String query = "0x" + fingerprint;
|
||||
//
|
||||
// // display keyserver fragment with query
|
||||
// Bundle serverBundle = new Bundle();
|
||||
// serverBundle.putString(ImportKeysServerFragment.ARG_QUERY, query);
|
||||
// serverBundle.putBoolean(ImportKeysServerFragment.ARG_DISABLE_QUERY_EDIT, true);
|
||||
//
|
||||
// return serverBundle;
|
||||
}
|
||||
|
||||
public void loadFromFingerprint(Bundle savedInstanceState, String fingerprint) {
|
||||
private boolean isFingerprintValid(String fingerprint) {
|
||||
if (fingerprint == null || fingerprint.length() < 40) {
|
||||
SuperCardToast toast = SuperCardToast.create(this,
|
||||
getString(R.string.import_qr_code_too_short_fingerprint),
|
||||
SuperToast.Duration.LONG);
|
||||
toast.setBackground(SuperToast.Background.RED);
|
||||
toast.show();
|
||||
return;
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
String query = "0x" + fingerprint;
|
||||
|
||||
// display keyserver fragment with query
|
||||
Bundle args = new Bundle();
|
||||
args.putString(ImportKeysServerFragment.ARG_QUERY, query);
|
||||
args.putBoolean(ImportKeysServerFragment.ARG_DISABLE_QUERY_EDIT, true);
|
||||
// loadNavFragment(NAV_SERVER, args);
|
||||
|
||||
//TODO
|
||||
|
||||
// action: search directly
|
||||
startListFragment(savedInstanceState, null, null, query);
|
||||
}
|
||||
|
||||
public void loadCallback(byte[] importData, Uri dataUri, String serverQuery, String keyServer, String keybaseQuery) {
|
||||
mListFragment.loadNew(importData, dataUri, serverQuery, keyServer, keybaseQuery);
|
||||
/**
|
||||
* Scroll ViewPager left and right
|
||||
*
|
||||
* @param event
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
boolean result = super.onTouchEvent(event);
|
||||
|
||||
if (!result) {
|
||||
mViewPager.onTouchEvent(event);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void loadCallback(ImportKeysListFragment.LoaderState loaderState) {
|
||||
mListFragment.loadNew(loaderState);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -477,7 +490,8 @@ public class ImportKeysActivity extends ActionBarActivity {
|
||||
}
|
||||
};
|
||||
|
||||
if (mListFragment.getKeyBytes() != null || mListFragment.getDataUri() != null) {
|
||||
ImportKeysListFragment.LoaderState ls = mListFragment.getLoaderState();
|
||||
if (ls instanceof ImportKeysListFragment.BytesLoaderState) {
|
||||
Log.d(Constants.TAG, "importKeys started");
|
||||
|
||||
// Send all information needed to service to import key in other thread
|
||||
@@ -503,7 +517,9 @@ public class ImportKeysActivity extends ActionBarActivity {
|
||||
|
||||
// start service with intent
|
||||
startService(intent);
|
||||
} else if (mListFragment.getServerQuery() != null) {
|
||||
} else if (ls instanceof ImportKeysListFragment.KeyserverLoaderState) {
|
||||
ImportKeysListFragment.KeyserverLoaderState sls = (ImportKeysListFragment.KeyserverLoaderState) ls;
|
||||
|
||||
// Send all information needed to service to query keys in other thread
|
||||
Intent intent = new Intent(this, KeychainIntentService.class);
|
||||
|
||||
@@ -512,7 +528,7 @@ public class ImportKeysActivity extends ActionBarActivity {
|
||||
// fill values for this action
|
||||
Bundle data = new Bundle();
|
||||
|
||||
data.putString(KeychainIntentService.DOWNLOAD_KEY_SERVER, mListFragment.getKeyServer());
|
||||
data.putString(KeychainIntentService.DOWNLOAD_KEY_SERVER, sls.keyserver);
|
||||
|
||||
// get selected key entries
|
||||
ArrayList<ImportKeysListEntry> selectedEntries = mListFragment.getSelectedEntries();
|
||||
@@ -529,7 +545,7 @@ public class ImportKeysActivity extends ActionBarActivity {
|
||||
|
||||
// start service with intent
|
||||
startService(intent);
|
||||
} else if (mListFragment.getKeybaseQuery() != null) {
|
||||
} else if (ls instanceof ImportKeysListFragment.KeybaseLoaderState) {
|
||||
// Send all information needed to service to query keys in other thread
|
||||
Intent intent = new Intent(this, KeychainIntentService.class);
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ public class ImportKeysFileFragment extends Fragment {
|
||||
return;
|
||||
}
|
||||
}
|
||||
mImportActivity.loadCallback(sendText.getBytes(), null, null, null, null);
|
||||
mImportActivity.loadCallback(new ImportKeysListFragment.BytesLoaderState(sendText.getBytes(), null));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -107,7 +107,7 @@ public class ImportKeysFileFragment extends Fragment {
|
||||
if (resultCode == Activity.RESULT_OK && data != null) {
|
||||
|
||||
// load data
|
||||
mImportActivity.loadCallback(null, data.getData(), null, null, null);
|
||||
mImportActivity.loadCallback(new ImportKeysListFragment.BytesLoaderState(null, data.getData()));
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@@ -117,6 +117,6 @@ public class ImportKeysKeybaseFragment extends Fragment {
|
||||
}
|
||||
|
||||
private void search(String query) {
|
||||
mImportActivity.loadCallback(null, null, null, null, query);
|
||||
mImportActivity.loadCallback(new ImportKeysListFragment.KeybaseLoaderState(query));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,8 +27,6 @@ import android.support.v4.util.LongSparseArray;
|
||||
import android.view.View;
|
||||
import android.widget.ListView;
|
||||
|
||||
import com.devspark.appmsg.AppMsg;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.helper.Preferences;
|
||||
@@ -60,11 +58,7 @@ public class ImportKeysListFragment extends ListFragment implements
|
||||
private Activity mActivity;
|
||||
private ImportKeysAdapter mAdapter;
|
||||
|
||||
private byte[] mKeyBytes;
|
||||
private Uri mDataUri;
|
||||
private String mServerQuery;
|
||||
private String mKeyServer;
|
||||
private String mKeybaseQuery;
|
||||
private LoaderState mLoaderState;
|
||||
|
||||
private static final int LOADER_ID_BYTES = 0;
|
||||
private static final int LOADER_ID_SERVER_QUERY = 1;
|
||||
@@ -72,24 +66,8 @@ public class ImportKeysListFragment extends ListFragment implements
|
||||
|
||||
private LongSparseArray<ParcelableKeyRing> mCachedKeyData;
|
||||
|
||||
public byte[] getKeyBytes() {
|
||||
return mKeyBytes;
|
||||
}
|
||||
|
||||
public Uri getDataUri() {
|
||||
return mDataUri;
|
||||
}
|
||||
|
||||
public String getServerQuery() {
|
||||
return mServerQuery;
|
||||
}
|
||||
|
||||
public String getKeybaseQuery() {
|
||||
return mKeybaseQuery;
|
||||
}
|
||||
|
||||
public String getKeyServer() {
|
||||
return mKeyServer;
|
||||
public LoaderState getLoaderState() {
|
||||
return mLoaderState;
|
||||
}
|
||||
|
||||
public List<ImportKeysListEntry> getData() {
|
||||
@@ -124,6 +102,37 @@ public class ImportKeysListFragment extends ListFragment implements
|
||||
return frag;
|
||||
}
|
||||
|
||||
static public class LoaderState {
|
||||
}
|
||||
|
||||
static public class BytesLoaderState extends LoaderState {
|
||||
byte[] keyBytes;
|
||||
Uri dataUri;
|
||||
|
||||
BytesLoaderState(byte[] keyBytes, Uri dataUri) {
|
||||
this.keyBytes = keyBytes;
|
||||
this.dataUri = dataUri;
|
||||
}
|
||||
}
|
||||
|
||||
static public class KeyserverLoaderState extends LoaderState {
|
||||
String serverQuery;
|
||||
String keyserver;
|
||||
|
||||
KeyserverLoaderState(String serverQuery, String keyserver) {
|
||||
this.serverQuery = serverQuery;
|
||||
this.keyserver = keyserver;
|
||||
}
|
||||
}
|
||||
|
||||
static public class KeybaseLoaderState extends LoaderState {
|
||||
String keybaseQuery;
|
||||
|
||||
KeybaseLoaderState(String keybaseQuery) {
|
||||
this.keybaseQuery = keybaseQuery;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Define Adapter and Loader on create of Activity
|
||||
*/
|
||||
@@ -140,43 +149,20 @@ public class ImportKeysListFragment extends ListFragment implements
|
||||
mAdapter = new ImportKeysAdapter(mActivity);
|
||||
setListAdapter(mAdapter);
|
||||
|
||||
mDataUri = getArguments().getParcelable(ARG_DATA_URI);
|
||||
mKeyBytes = getArguments().getByteArray(ARG_BYTES);
|
||||
mServerQuery = getArguments().getString(ARG_SERVER_QUERY);
|
||||
|
||||
// TODO: this is used when scanning QR Code. Currently it simply uses keyserver nr 0
|
||||
mKeyServer = Preferences.getPreferences(getActivity())
|
||||
.getKeyServers()[0];
|
||||
|
||||
if (mDataUri != null || mKeyBytes != null) {
|
||||
// Start out with a progress indicator.
|
||||
setListShown(false);
|
||||
|
||||
// Prepare the loader. Either re-connect with an existing one,
|
||||
// or start a new one.
|
||||
// give arguments to onCreateLoader()
|
||||
getLoaderManager().initLoader(LOADER_ID_BYTES, null, this);
|
||||
if (getArguments().containsKey(ARG_DATA_URI) || getArguments().containsKey(ARG_BYTES)) {
|
||||
Uri dataUri = getArguments().getParcelable(ARG_DATA_URI);
|
||||
byte[] bytes = getArguments().getByteArray(ARG_BYTES);
|
||||
mLoaderState = new BytesLoaderState(bytes, dataUri);
|
||||
} else if (getArguments().containsKey(ARG_SERVER_QUERY)) {
|
||||
String query = getArguments().getString(ARG_SERVER_QUERY);
|
||||
// TODO: this is used when scanning QR Code or updating a key.
|
||||
// Currently it simply uses keyserver nr 0
|
||||
String keyserver = Preferences.getPreferences(getActivity())
|
||||
.getKeyServers()[0];
|
||||
mLoaderState = new KeyserverLoaderState(query, keyserver);
|
||||
}
|
||||
|
||||
if (mServerQuery != null && mKeyServer != null) {
|
||||
// Start out with a progress indicator.
|
||||
setListShown(false);
|
||||
|
||||
// Prepare the loader. Either re-connect with an existing one,
|
||||
// or start a new one.
|
||||
// give arguments to onCreateLoader()
|
||||
getLoaderManager().initLoader(LOADER_ID_SERVER_QUERY, null, this);
|
||||
}
|
||||
|
||||
if (mKeybaseQuery != null) {
|
||||
// Start out with a progress indicator.
|
||||
setListShown(false);
|
||||
|
||||
// Prepare the loader. Either re-connect with an existing one,
|
||||
// or start a new one.
|
||||
// give arguments to onCreateLoader()
|
||||
getLoaderManager().initLoader(LOADER_ID_KEYBASE, null, this);
|
||||
}
|
||||
restartLoaders();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -192,31 +178,33 @@ public class ImportKeysListFragment extends ListFragment implements
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void loadNew(byte[] keyBytes, Uri dataUri, String serverQuery, String keyServer, String keybaseQuery) {
|
||||
mKeyBytes = keyBytes;
|
||||
mDataUri = dataUri;
|
||||
mServerQuery = serverQuery;
|
||||
mKeyServer = keyServer;
|
||||
mKeybaseQuery = keybaseQuery;
|
||||
public void loadNew(LoaderState loaderState) {
|
||||
mLoaderState = loaderState;
|
||||
|
||||
if (mKeyBytes != null || mDataUri != null) {
|
||||
restartLoaders();
|
||||
}
|
||||
|
||||
private void restartLoaders() {
|
||||
if (mLoaderState instanceof BytesLoaderState) {
|
||||
// Start out with a progress indicator.
|
||||
setListShown(false);
|
||||
|
||||
getLoaderManager().restartLoader(LOADER_ID_BYTES, null, this);
|
||||
}
|
||||
|
||||
if (mServerQuery != null && mKeyServer != null) {
|
||||
getLoaderManager().destroyLoader(LOADER_ID_SERVER_QUERY);
|
||||
getLoaderManager().destroyLoader(LOADER_ID_KEYBASE);
|
||||
} else if (mLoaderState instanceof KeyserverLoaderState) {
|
||||
// Start out with a progress indicator.
|
||||
setListShown(false);
|
||||
|
||||
getLoaderManager().destroyLoader(LOADER_ID_BYTES);
|
||||
getLoaderManager().restartLoader(LOADER_ID_SERVER_QUERY, null, this);
|
||||
}
|
||||
|
||||
if (mKeybaseQuery != null) {
|
||||
getLoaderManager().destroyLoader(LOADER_ID_KEYBASE);
|
||||
} else if (mLoaderState instanceof KeybaseLoaderState) {
|
||||
// Start out with a progress indicator.
|
||||
setListShown(false);
|
||||
|
||||
getLoaderManager().destroyLoader(LOADER_ID_BYTES);
|
||||
getLoaderManager().destroyLoader(LOADER_ID_SERVER_QUERY);
|
||||
getLoaderManager().restartLoader(LOADER_ID_KEYBASE, null, this);
|
||||
}
|
||||
}
|
||||
@@ -226,14 +214,17 @@ public class ImportKeysListFragment extends ListFragment implements
|
||||
onCreateLoader(int id, Bundle args) {
|
||||
switch (id) {
|
||||
case LOADER_ID_BYTES: {
|
||||
InputData inputData = getInputData(mKeyBytes, mDataUri);
|
||||
BytesLoaderState ls = (BytesLoaderState) mLoaderState;
|
||||
InputData inputData = getInputData(ls.keyBytes, ls.dataUri);
|
||||
return new ImportKeysListLoader(mActivity, inputData);
|
||||
}
|
||||
case LOADER_ID_SERVER_QUERY: {
|
||||
return new ImportKeysListServerLoader(getActivity(), mServerQuery, mKeyServer);
|
||||
KeyserverLoaderState ls = (KeyserverLoaderState) mLoaderState;
|
||||
return new ImportKeysListServerLoader(getActivity(), ls.serverQuery, ls.keyserver);
|
||||
}
|
||||
case LOADER_ID_KEYBASE: {
|
||||
return new ImportKeysListKeybaseLoader(getActivity(), mKeybaseQuery);
|
||||
KeybaseLoaderState ls = (KeybaseLoaderState) mLoaderState;
|
||||
return new ImportKeysListKeybaseLoader(getActivity(), ls.keybaseQuery);
|
||||
}
|
||||
|
||||
default:
|
||||
@@ -280,7 +271,8 @@ public class ImportKeysListFragment extends ListFragment implements
|
||||
((ImportKeysListLoader.NonPgpPart) error).getCount() + " " + getResources().
|
||||
getQuantityString(R.plurals.error_import_non_pgp_part,
|
||||
((ImportKeysListLoader.NonPgpPart) error).getCount()),
|
||||
Notify.Style.OK);
|
||||
Notify.Style.OK
|
||||
);
|
||||
} else {
|
||||
Notify.showNotify(getActivity(), R.string.error_generic_report_bug, Notify.Style.ERROR);
|
||||
}
|
||||
@@ -289,7 +281,6 @@ public class ImportKeysListFragment extends ListFragment implements
|
||||
case LOADER_ID_SERVER_QUERY:
|
||||
case LOADER_ID_KEYBASE:
|
||||
|
||||
// TODO: possibly fine-tune message building for these two cases
|
||||
if (error == null) {
|
||||
// No error
|
||||
} else if (error instanceof Keyserver.QueryTooShortException) {
|
||||
|
||||
@@ -25,8 +25,6 @@ import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.google.zxing.integration.android.IntentResult;
|
||||
|
||||
@@ -36,18 +34,13 @@ import org.sufficientlysecure.keychain.util.IntentIntegratorSupportV4;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
import org.sufficientlysecure.keychain.util.Notify;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
|
||||
public class ImportKeysQrCodeFragment extends Fragment {
|
||||
private ImportKeysActivity mImportActivity;
|
||||
|
||||
private View mNfcButton;
|
||||
|
||||
private View mQrCodeButton;
|
||||
private TextView mQrCodeText;
|
||||
private ProgressBar mQrCodeProgress;
|
||||
|
||||
private String[] mQrCodeContent;
|
||||
|
||||
/**
|
||||
* Creates new instance of this fragment
|
||||
@@ -81,8 +74,6 @@ public class ImportKeysQrCodeFragment extends Fragment {
|
||||
});
|
||||
|
||||
mQrCodeButton = view.findViewById(R.id.import_qrcode_button);
|
||||
mQrCodeText = (TextView) view.findViewById(R.id.import_qrcode_text);
|
||||
mQrCodeProgress = (ProgressBar) view.findViewById(R.id.import_qrcode_progress);
|
||||
|
||||
mQrCodeButton.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@@ -120,16 +111,9 @@ public class ImportKeysQrCodeFragment extends Fragment {
|
||||
return;
|
||||
}
|
||||
|
||||
// look if it is the whole key
|
||||
String[] parts = scannedContent.split(",");
|
||||
if (parts.length == 3) {
|
||||
importParts(parts);
|
||||
return;
|
||||
}
|
||||
|
||||
// is this a full key encoded as qr code?
|
||||
if (scannedContent.startsWith("-----BEGIN PGP")) {
|
||||
mImportActivity.loadCallback(scannedContent.getBytes(), null, null, null, null);
|
||||
mImportActivity.loadCallback(new ImportKeysListFragment.BytesLoaderState(scannedContent.getBytes(), null));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -147,68 +131,8 @@ public class ImportKeysQrCodeFragment extends Fragment {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void importFingerprint(Uri dataUri) {
|
||||
mImportActivity.loadFromFingerprintUri(null, dataUri);
|
||||
}
|
||||
|
||||
private void importParts(String[] parts) {
|
||||
int counter = Integer.valueOf(parts[0]);
|
||||
int size = Integer.valueOf(parts[1]);
|
||||
String content = parts[2];
|
||||
|
||||
Log.d(Constants.TAG, "" + counter);
|
||||
Log.d(Constants.TAG, "" + size);
|
||||
Log.d(Constants.TAG, "" + content);
|
||||
|
||||
// first qr code -> setup
|
||||
if (counter == 0) {
|
||||
mQrCodeContent = new String[size];
|
||||
mQrCodeProgress.setMax(size);
|
||||
mQrCodeProgress.setVisibility(View.VISIBLE);
|
||||
mQrCodeText.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
if (mQrCodeContent == null || counter > mQrCodeContent.length) {
|
||||
Notify.showNotify(getActivity(), R.string.import_qr_code_start_with_one, Notify.Style.ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
// save scanned content
|
||||
mQrCodeContent[counter] = content;
|
||||
|
||||
// get missing numbers
|
||||
ArrayList<Integer> missing = new ArrayList<Integer>();
|
||||
for (int i = 0; i < mQrCodeContent.length; i++) {
|
||||
if (mQrCodeContent[i] == null) {
|
||||
missing.add(i);
|
||||
}
|
||||
}
|
||||
|
||||
// update progress and text
|
||||
int alreadyScanned = mQrCodeContent.length - missing.size();
|
||||
mQrCodeProgress.setProgress(alreadyScanned);
|
||||
|
||||
String missingString = "";
|
||||
for (int m : missing) {
|
||||
if (!missingString.equals("")) {
|
||||
missingString += ", ";
|
||||
}
|
||||
missingString += String.valueOf(m + 1);
|
||||
}
|
||||
|
||||
String missingText = getResources().getQuantityString(R.plurals.import_qr_code_missing,
|
||||
missing.size(), missingString);
|
||||
mQrCodeText.setText(missingText);
|
||||
|
||||
// finished!
|
||||
if (missing.size() == 0) {
|
||||
mQrCodeText.setText(R.string.import_qr_code_finished);
|
||||
String result = "";
|
||||
for (String in : mQrCodeContent) {
|
||||
result += in;
|
||||
}
|
||||
mImportActivity.loadCallback(result.getBytes(), null, null, null, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,8 +170,8 @@ public class ImportKeysServerFragment extends Fragment {
|
||||
mImportActivity = (ImportKeysActivity) activity;
|
||||
}
|
||||
|
||||
private void search(String query, String keyServer) {
|
||||
mImportActivity.loadCallback(null, null, query, keyServer, null);
|
||||
private void search(String query, String keyserver) {
|
||||
mImportActivity.loadCallback(new ImportKeysListFragment.KeyserverLoaderState(query, keyserver));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user