From abbdfd48dfef1a2cea5ac065bdbb4199e2b3b7de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Sat, 1 Feb 2014 18:13:26 +0100 Subject: Started working on integration of keyserver query into import activity --- .../keychain/service/KeychainIntentService.java | 16 ++- .../keychain/ui/ImportKeysActivity.java | 102 +++++++------- .../keychain/ui/ImportKeysClipboardFragment.java | 2 +- .../keychain/ui/ImportKeysFileFragment.java | 46 ++---- .../keychain/ui/ImportKeysListFragment.java | 156 ++++++++++++++------- .../keychain/ui/ImportKeysQrCodeFragment.java | 2 +- .../keychain/ui/ImportKeysServerFragment.java | 86 +++++++++++- .../keychain/ui/ViewKeyActivity.java | 4 +- .../main/res/layout/import_keys_file_fragment.xml | 23 +-- .../res/layout/import_keys_keyserver_fragment.xml | 43 ------ .../res/layout/import_keys_server_fragment.xml | 54 +++++++ 11 files changed, 324 insertions(+), 210 deletions(-) delete mode 100644 OpenPGP-Keychain/src/main/res/layout/import_keys_keyserver_fragment.xml create mode 100644 OpenPGP-Keychain/src/main/res/layout/import_keys_server_fragment.xml (limited to 'OpenPGP-Keychain') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java index b02e08dda..b23efb909 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java @@ -653,12 +653,18 @@ public class KeychainIntentService extends IntentService implements ProgressDial break; case TARGET_FILE: /* import key from file */ - String inputFile = data.getString(IMPORT_FILENAME); + // dataUri! - inStream = new FileInputStream(inputFile); - File file = new File(inputFile); - inLength = file.length(); - inputData = new InputData(inStream, inLength); + try { + inStream = getContentResolver().openInputStream(dataUri); + inLength = inStream.available(); + + inputData = new InputData(inStream, inLength); + } catch (FileNotFoundException e) { + Log.e(Constants.TAG, "FileNotFoundException!", e); + } catch (IOException e) { + Log.e(Constants.TAG, "IOException!", e); + } break; diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java index 26ebc8e79..aee894ab7 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java @@ -23,11 +23,10 @@ import java.util.Locale; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListEntry; -import org.sufficientlysecure.keychain.ui.dialog.DeleteFileDialogFragment; -import org.sufficientlysecure.keychain.ui.dialog.FileDialogFragment; import org.sufficientlysecure.keychain.util.Log; import android.annotation.SuppressLint; @@ -72,8 +71,9 @@ public class ImportKeysActivity extends DrawerActivity implements OnNavigationLi // only used by ACTION_IMPORT_KEY_FROM_KEYSERVER public static final String EXTRA_QUERY = "query"; - - protected boolean mDeleteAfterImport = false; + public static final String EXTRA_KEY_ID = "key_id"; + public static final String EXTRA_FINGERPRINT = "fingerprint"; +// public static final String RESULT_EXTRA_TEXT = "text"; // view private ImportKeysListFragment mListFragment; @@ -143,17 +143,12 @@ public class ImportKeysActivity extends DrawerActivity implements OnNavigationLi * Keychain's own Actions */ if (ACTION_IMPORT_KEY.equals(action)) { - if ("file".equals(intent.getScheme()) && intent.getDataString() != null) { - String importFilename = intent.getData().getPath(); - - // display selected filename - getSupportActionBar().setSelectedNavigationItem(1); - Bundle args = new Bundle(); - args.putString(ImportKeysFileFragment.ARG_PATH, importFilename); - loadFragment(ImportKeysFileFragment.class, args, mNavigationStrings[1]); + getSupportActionBar().setSelectedNavigationItem(1); + loadFragment(ImportKeysFileFragment.class, null, mNavigationStrings[1]); + if (dataUri != null) { // directly load data - startListFragment(savedInstanceState, null, importFilename); + startListFragment(savedInstanceState, null, dataUri); } else if (extras.containsKey(EXTRA_KEY_BYTES)) { byte[] importData = intent.getByteArrayExtra(EXTRA_KEY_BYTES); @@ -161,12 +156,29 @@ public class ImportKeysActivity extends DrawerActivity implements OnNavigationLi startListFragment(savedInstanceState, importData, null); } } else if (ACTION_IMPORT_KEY_FROM_KEYSERVER.equals(action)) { - if (!extras.containsKey(EXTRA_QUERY)) { - Log.e(Constants.TAG, "IMPORT_KEY_FROM_KEYSERVER action needs to contain the 'query' extra!"); + String query = null; + if (extras.containsKey(EXTRA_QUERY)) { + query = extras.getString(EXTRA_QUERY); + } else if (extras.containsKey(EXTRA_KEY_ID)) { + long keyId = intent.getLongExtra(EXTRA_KEY_ID, 0); + if (keyId != 0) { + query = "0x" + PgpKeyHelper.convertKeyToHex(keyId); + } + } else if (extras.containsKey(EXTRA_FINGERPRINT)) { + String fingerprint = intent.getStringExtra(EXTRA_FINGERPRINT); + if (fingerprint != null) { + query = "0x" + fingerprint; + } + } else { + Log.e(Constants.TAG, "IMPORT_KEY_FROM_KEYSERVER action needs to contain the 'query', 'key_id', or 'fingerprint' extra!"); return; } - String query = extras.getString(EXTRA_QUERY); + // search directly + getSupportActionBar().setSelectedNavigationItem(0); + Bundle args = new Bundle(); + args.putString(ImportKeysServerFragment.ARG_QUERY, query); + loadFragment(ImportKeysServerFragment.class, args, mNavigationStrings[0]); // TODO: implement KEYSERVER! @@ -188,7 +200,7 @@ public class ImportKeysActivity extends DrawerActivity implements OnNavigationLi } } - private void startListFragment(Bundle savedInstanceState, byte[] bytes, String filename) { + private void startListFragment(Bundle savedInstanceState, byte[] bytes, Uri dataUri) { // Check that the activity is using the layout version with // the fragment_container FrameLayout if (findViewById(R.id.import_keys_list_container) != null) { @@ -201,7 +213,7 @@ public class ImportKeysActivity extends DrawerActivity implements OnNavigationLi } // Create an instance of the fragment - mListFragment = ImportKeysListFragment.newInstance(bytes, filename); + mListFragment = ImportKeysListFragment.newInstance(bytes, dataUri, null); // Add the fragment to the 'fragment_container' FrameLayout // NOTE: We use commitAllowingStateLoss() to prevent weird crashes! @@ -217,24 +229,24 @@ public class ImportKeysActivity extends DrawerActivity implements OnNavigationLi public boolean onNavigationItemSelected(int itemPosition, long itemId) { // Create new fragment from our own Fragment class switch (itemPosition) { - case 0: - loadFragment(ImportKeysServerFragment.class, null, mNavigationStrings[itemPosition]); - break; - case 1: - loadFragment(ImportKeysFileFragment.class, null, mNavigationStrings[itemPosition]); - break; - case 2: - loadFragment(ImportKeysQrCodeFragment.class, null, mNavigationStrings[itemPosition]); - break; - case 3: - loadFragment(ImportKeysClipboardFragment.class, null, mNavigationStrings[itemPosition]); - break; - case 4: - loadFragment(ImportKeysNFCFragment.class, null, mNavigationStrings[itemPosition]); - break; - - default: - break; + case 0: + loadFragment(ImportKeysServerFragment.class, null, mNavigationStrings[itemPosition]); + break; + case 1: + loadFragment(ImportKeysFileFragment.class, null, mNavigationStrings[itemPosition]); + break; + case 2: + loadFragment(ImportKeysQrCodeFragment.class, null, mNavigationStrings[itemPosition]); + break; + case 3: + loadFragment(ImportKeysClipboardFragment.class, null, mNavigationStrings[itemPosition]); + break; + case 4: + loadFragment(ImportKeysNFCFragment.class, null, mNavigationStrings[itemPosition]); + break; + + default: + break; } return true; } @@ -267,8 +279,8 @@ public class ImportKeysActivity extends DrawerActivity implements OnNavigationLi startActivity(queryIntent); } - public void loadCallback(byte[] importData, String importFilename) { - mListFragment.loadNew(importData, importFilename); + public void loadCallback(byte[] importData, Uri dataUri, String serverQuery) { + mListFragment.loadNew(importData, dataUri, serverQuery); } // private void importAndSignOld(final long keyId, final String expectedFingerprint) { @@ -333,7 +345,7 @@ public class ImportKeysActivity extends DrawerActivity implements OnNavigationLi * Import keys with mImportData */ public void importKeys() { - if (mListFragment.getKeyBytes() != null || mListFragment.getImportFilename() != null) { + if (mListFragment.getKeyBytes() != null || mListFragment.getDataUri() != null) { Log.d(Constants.TAG, "importKeys started"); // Send all information needed to service to import key in other thread @@ -360,8 +372,7 @@ public class ImportKeysActivity extends DrawerActivity implements OnNavigationLi data.putByteArray(KeychainIntentService.IMPORT_BYTES, mListFragment.getKeyBytes()); } else { data.putInt(KeychainIntentService.TARGET, KeychainIntentService.TARGET_FILE); - data.putString(KeychainIntentService.IMPORT_FILENAME, - mListFragment.getImportFilename()); + intent.setData(mListFragment.getDataUri()); } intent.putExtra(KeychainIntentService.EXTRA_DATA, data); @@ -417,14 +428,11 @@ public class ImportKeysActivity extends DrawerActivity implements OnNavigationLi }); alert.setCancelable(true); alert.create().show(); - } else if (mDeleteAfterImport) { - // everything went well, so now delete, if that was turned on - DeleteFileDialogFragment deleteFileDialog = DeleteFileDialogFragment - .newInstance(mListFragment.getImportFilename()); - deleteFileDialog.show(getSupportFragmentManager(), "deleteDialog"); } } - }; + } + + ; }; // Create a new Messenger for the communication back diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysClipboardFragment.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysClipboardFragment.java index 04671587a..8aa07a5ab 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysClipboardFragment.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysClipboardFragment.java @@ -62,7 +62,7 @@ public class ImportKeysClipboardFragment extends Fragment { String sendText = ""; if (clipboardText != null) sendText = clipboardText.toString(); - mImportActivity.loadCallback(sendText.getBytes(), null); + mImportActivity.loadCallback(sendText.getBytes(), null, null); } }); diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysFileFragment.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysFileFragment.java index a02bfd678..288f3f7ea 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysFileFragment.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysFileFragment.java @@ -21,7 +21,6 @@ import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Id; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.helper.FileHelper; -import org.sufficientlysecure.keychain.util.Log; import android.app.Activity; import android.content.Intent; @@ -30,25 +29,20 @@ import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.EditText; import com.beardedhen.androidbootstrap.BootstrapButton; public class ImportKeysFileFragment extends Fragment { - public static final String ARG_PATH = "path"; - private ImportKeysActivity mImportActivity; - private EditText mFilename; private BootstrapButton mBrowse; /** * Creates new instance of this fragment */ - public static ImportKeysFileFragment newInstance(String path) { + public static ImportKeysFileFragment newInstance() { ImportKeysFileFragment frag = new ImportKeysFileFragment(); Bundle args = new Bundle(); - args.putString(ARG_PATH, path); frag.setArguments(args); return frag; @@ -61,7 +55,6 @@ public class ImportKeysFileFragment extends Fragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.import_keys_file_fragment, container, false); - mFilename = (EditText) view.findViewById(R.id.import_keys_file_input); mBrowse = (BootstrapButton) view.findViewById(R.id.import_keys_file_browse); mBrowse.setOnClickListener(new View.OnClickListener() { @@ -69,7 +62,7 @@ public class ImportKeysFileFragment extends Fragment { // open .asc or .gpg files // setting it to text/plain prevents Cynaogenmod's file manager from selecting asc // or gpg types! - FileHelper.openFile(ImportKeysFileFragment.this, mFilename.getText().toString(), + FileHelper.openFile(ImportKeysFileFragment.this, Constants.path.APP_DIR + "/", "*/*", Id.request.filename); } }); @@ -82,42 +75,25 @@ public class ImportKeysFileFragment extends Fragment { super.onActivityCreated(savedInstanceState); mImportActivity = (ImportKeysActivity) getActivity(); - - // set default path - String path = Constants.path.APP_DIR + "/"; - if (getArguments() != null && getArguments().containsKey(ARG_PATH)) { - path = getArguments().getString(ARG_PATH); - } - mFilename.setText(path); } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode & 0xFFFF) { - case Id.request.filename: { - if (resultCode == Activity.RESULT_OK && data != null) { - String path = null; - try { - path = data.getData().getPath(); - Log.d(Constants.TAG, "path=" + path); - - // set filename to edittext - mFilename.setText(path); - } catch (NullPointerException e) { - Log.e(Constants.TAG, "Nullpointer while retrieving path!", e); + case Id.request.filename: { + if (resultCode == Activity.RESULT_OK && data != null) { + + // load data + mImportActivity.loadCallback(null, data.getData(), null); } - // load data - mImportActivity.loadCallback(null, path); + break; } - break; - } - - default: - super.onActivityResult(requestCode, resultCode, data); + default: + super.onActivityResult(requestCode, resultCode, data); - break; + break; } } diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java index 18d9dc2ec..6b8472554 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java @@ -1,18 +1,18 @@ /* - * Copyright (C) 2012 Dominik Schürmann - * Copyright (C) 2010 Thialfihar + * Copyright (C) 2012-2014 Dominik Schürmann * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * 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. * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package org.sufficientlysecure.keychain.ui; @@ -20,6 +20,8 @@ package org.sufficientlysecure.keychain.ui; import java.io.ByteArrayInputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; import java.util.List; import org.sufficientlysecure.keychain.Constants; @@ -31,6 +33,7 @@ import org.sufficientlysecure.keychain.util.InputData; import org.sufficientlysecure.keychain.util.Log; import android.app.Activity; +import android.net.Uri; import android.os.Bundle; import android.support.v4.app.LoaderManager; import android.support.v4.content.Loader; @@ -41,21 +44,26 @@ import com.actionbarsherlock.app.SherlockListFragment; public class ImportKeysListFragment extends SherlockListFragment implements LoaderManager.LoaderCallbacks> { - private static final String ARG_FILENAME = "filename"; + private static final String ARG_DATA_URI = "uri"; private static final String ARG_BYTES = "bytes"; + private static final String ARG_SERVER_QUERY = "query"; private Activity mActivity; private ImportKeysAdapter mAdapter; private byte[] mKeyBytes; - private String mImportFilename; + private Uri mDataUri; + private String mServerQuery; + + private static final int LOADER_ID_BYTES = 0; + private static final int LOADER_ID_SERVER_QUERY = 1; public byte[] getKeyBytes() { return mKeyBytes; } - public String getImportFilename() { - return mImportFilename; + public Uri getDataUri() { + return mDataUri; } public List getData() { @@ -65,12 +73,13 @@ public class ImportKeysListFragment extends SherlockListFragment implements /** * Creates new instance of this fragment */ - public static ImportKeysListFragment newInstance(byte[] bytes, String filename) { + public static ImportKeysListFragment newInstance(byte[] bytes, Uri dataUri, String serverQuery) { ImportKeysListFragment frag = new ImportKeysListFragment(); Bundle args = new Bundle(); args.putByteArray(ARG_BYTES, bytes); - args.putString(ARG_FILENAME, filename); + args.putParcelable(ARG_DATA_URI, dataUri); + args.putString(ARG_SERVER_QUERY, serverQuery); frag.setArguments(args); @@ -87,8 +96,9 @@ public class ImportKeysListFragment extends SherlockListFragment implements mActivity = getActivity(); if (getArguments() != null) { - mImportFilename = getArguments().getString(ARG_FILENAME); + mDataUri = getArguments().getParcelable(ARG_DATA_URI); mKeyBytes = getArguments().getByteArray(ARG_BYTES); + mServerQuery = getArguments().getString(ARG_SERVER_QUERY); } // Give some text to display if there is no data. In a real @@ -105,7 +115,8 @@ public class ImportKeysListFragment extends SherlockListFragment implements // Prepare the loader. Either re-connect with an existing one, // or start a new one. // give arguments to onCreateLoader() - getLoaderManager().initLoader(0, null, this); + getLoaderManager().initLoader(LOADER_ID_BYTES, null, this); + getLoaderManager().initLoader(LOADER_ID_SERVER_QUERY, null, this); } @Override @@ -120,58 +131,101 @@ public class ImportKeysListFragment extends SherlockListFragment implements mAdapter.notifyDataSetChanged(); } - public void loadNew(byte[] importData, String importFilename) { - this.mKeyBytes = importData; - this.mImportFilename = importFilename; + public void loadNew(byte[] importData, Uri dataUri, String serverQuery) { + mKeyBytes = importData; + mDataUri = dataUri; + mServerQuery = serverQuery; + + if (mKeyBytes != null || mDataUri != null) + getLoaderManager().restartLoader(LOADER_ID_BYTES, null, this); - getLoaderManager().restartLoader(0, null, this); + if (mServerQuery != null) + getLoaderManager().restartLoader(LOADER_ID_SERVER_QUERY, null, this); } @Override public Loader> onCreateLoader(int id, Bundle args) { - InputData inputData = getInputData(mKeyBytes, mImportFilename); - return new ImportKeysListLoader(mActivity, inputData); - } + switch (id) { + case LOADER_ID_BYTES: { + InputData inputData = getInputData(mKeyBytes, mDataUri); - private InputData getInputData(byte[] importBytes, String importFilename) { - InputData inputData = null; - if (importBytes != null) { - inputData = new InputData(new ByteArrayInputStream(importBytes), importBytes.length); - } else if (importFilename != null) { - try { - inputData = new InputData(new FileInputStream(importFilename), - importFilename.length()); - } catch (FileNotFoundException e) { - Log.e(Constants.TAG, "Failed to init FileInputStream!", e); + return new ImportKeysListLoader(mActivity, inputData); } - } + case LOADER_ID_SERVER_QUERY: { - return inputData; + } + + default: + return null; + } } @Override public void onLoadFinished(Loader> loader, - List data) { - Log.d(Constants.TAG, "data: " + data); + List data) { + // Swap the new cursor in. (The framework will take care of closing the + // old cursor once we return.) + switch (loader.getId()) { + case LOADER_ID_BYTES: + Log.d(Constants.TAG, "data: " + data); - // swap in the real data! - mAdapter.setData(data); - mAdapter.notifyDataSetChanged(); + // swap in the real data! + mAdapter.setData(data); + mAdapter.notifyDataSetChanged(); - setListAdapter(mAdapter); + setListAdapter(mAdapter); + + // The list should now be shown. + if (isResumed()) { + setListShown(true); + } else { + setListShownNoAnimation(true); + } - // The list should now be shown. - if (isResumed()) { - setListShown(true); - } else { - setListShownNoAnimation(true); + break; + + case LOADER_ID_SERVER_QUERY: + break; + + default: + break; } } @Override public void onLoaderReset(Loader> loader) { - // Clear the data in the adapter. - mAdapter.clear(); + switch (loader.getId()) { + case LOADER_ID_BYTES: + // Clear the data in the adapter. + mAdapter.clear(); + break; + case LOADER_ID_SERVER_QUERY: + // Clear the data in the adapter. + mAdapter.clear(); + break; + default: + break; + } + } + + private InputData getInputData(byte[] importBytes, Uri dataUri) { + InputData inputData = null; + if (importBytes != null) { + inputData = new InputData(new ByteArrayInputStream(importBytes), importBytes.length); + } else if (dataUri != null) { + try { + InputStream inputStream = getActivity().getContentResolver().openInputStream(dataUri); + int length = inputStream.available(); + + inputData = new InputData(inputStream, length); + } catch (FileNotFoundException e) { + Log.e(Constants.TAG, "FileNotFoundException!", e); + } catch (IOException e) { + Log.e(Constants.TAG, "IOException!", e); + } + } + + return inputData; } } diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysQrCodeFragment.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysQrCodeFragment.java index e714c231d..fe55e2b5e 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysQrCodeFragment.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysQrCodeFragment.java @@ -190,7 +190,7 @@ public class ImportKeysQrCodeFragment extends Fragment { for (String in : mScannedContent) { result += in; } - mImportActivity.loadCallback(result.getBytes(), null); + mImportActivity.loadCallback(result.getBytes(), null, null); } } diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysServerFragment.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysServerFragment.java index 5d8885e2f..c8f4868a2 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysServerFragment.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysServerFragment.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 Dominik Schürmann + * Copyright (C) 2013-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 @@ -17,22 +17,36 @@ package org.sufficientlysecure.keychain.ui; +import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.helper.Preferences; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.Fragment; +import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; +import android.view.inputmethod.EditorInfo; +import android.widget.ArrayAdapter; +import android.widget.EditText; +import android.widget.Spinner; +import android.widget.TextView; import com.beardedhen.androidbootstrap.BootstrapButton; public class ImportKeysServerFragment extends Fragment { - private BootstrapButton mButton; + public static final String ARG_QUERY = "query"; - String mQuery; + private ImportKeysActivity mImportActivity; + + private BootstrapButton mOldButton; + + private BootstrapButton mSearchButton; + private EditText mQueryEditText; + private Spinner mServerSpinner; /** * Creates new instance of this fragment @@ -41,6 +55,8 @@ public class ImportKeysServerFragment extends Fragment { ImportKeysServerFragment frag = new ImportKeysServerFragment(); Bundle args = new Bundle(); + args.putString(ARG_QUERY, query); + frag.setArguments(args); return frag; @@ -51,14 +67,52 @@ public class ImportKeysServerFragment extends Fragment { */ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.import_keys_keyserver_fragment, container, false); + View view = inflater.inflate(R.layout.import_keys_server_fragment, container, false); - mButton = (BootstrapButton) view.findViewById(R.id.import_keyserver_button); - mButton.setOnClickListener(new OnClickListener() { + mSearchButton = (BootstrapButton) view.findViewById(R.id.import_server_button); + mQueryEditText = (EditText) view.findViewById(R.id.import_server_query); + mServerSpinner = (Spinner) view.findViewById(R.id.import_server_spinner); + + // add keyservers to spinner + ArrayAdapter adapter = new ArrayAdapter(getActivity(), + android.R.layout.simple_spinner_item, Preferences.getPreferences(getActivity()) + .getKeyServers()); + adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + mServerSpinner.setAdapter(adapter); + if (adapter.getCount() > 0) { + mServerSpinner.setSelection(0); + } else { + mSearchButton.setEnabled(false); + } + + mSearchButton.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + String query = mQueryEditText.getText().toString(); + + } + }); + // TODO: not supported by BootstrapButton +// mSearchButton.setOnEditorActionListener(new TextView.OnEditorActionListener() { +// @Override +// public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { +// if (actionId == EditorInfo.IME_ACTION_SEARCH) { +// String query = mQueryEditText.getText().toString(); +// search(query); +// // FIXME This is a hack to hide a keyboard after search +// // http://tinyurl.com/pwdc3q9 +// return false; +// } +// return false; +// } +// }); + + // TODO: remove: + mOldButton = (BootstrapButton) view.findViewById(R.id.import_server_button); + mOldButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - // TODO: use fragment instead of activity, handle onresult here! startActivityForResult(new Intent(getActivity(), KeyServerQueryActivity.class), 0); } }); @@ -66,4 +120,22 @@ public class ImportKeysServerFragment extends Fragment { return view; } + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + + mImportActivity = (ImportKeysActivity) getActivity(); + + // if query has been set on instantiation, search immediately! + if (getArguments() != null && getArguments().containsKey(ARG_QUERY)) { + String query = getArguments().getString(ARG_QUERY); + mQueryEditText.setText(query); + search(query); + } + } + + private void search(String query) { + + } + } diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java index 638036701..e1cefbed1 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java @@ -330,7 +330,7 @@ public class ViewKeyActivity extends SherlockFragmentActivity implements creationDate)); } - // get creation date from EXPIRY + // get expiry date from EXPIRY if (data.isNull(KEYS_INDEX_EXPIRY)) { mExpiry.setText(R.string.none); } else { @@ -346,7 +346,7 @@ public class ViewKeyActivity extends SherlockFragmentActivity implements byte[] fingerprintBlob = data.getBlob(KEYS_INDEX_FINGERPRINT); if (fingerprintBlob == null) { - // FALLBACK for old databases + // FALLBACK for old database entries fingerprintBlob = ProviderHelper.getFingerprint(this, mDataUri); } String fingerprint = PgpKeyHelper.convertFingerprintToHex(fingerprintBlob, true); diff --git a/OpenPGP-Keychain/src/main/res/layout/import_keys_file_fragment.xml b/OpenPGP-Keychain/src/main/res/layout/import_keys_file_fragment.xml index 126bcd8a6..0a49571d1 100644 --- a/OpenPGP-Keychain/src/main/res/layout/import_keys_file_fragment.xml +++ b/OpenPGP-Keychain/src/main/res/layout/import_keys_file_fragment.xml @@ -3,29 +3,16 @@ xmlns:bootstrapbutton="http://schemas.android.com/apk/res-auto" android:layout_width="fill_parent" android:layout_height="wrap_content" - android:orientation="horizontal" > - - + android:orientation="vertical"> diff --git a/OpenPGP-Keychain/src/main/res/layout/import_keys_keyserver_fragment.xml b/OpenPGP-Keychain/src/main/res/layout/import_keys_keyserver_fragment.xml deleted file mode 100644 index e866e05dc..000000000 --- a/OpenPGP-Keychain/src/main/res/layout/import_keys_keyserver_fragment.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/OpenPGP-Keychain/src/main/res/layout/import_keys_server_fragment.xml b/OpenPGP-Keychain/src/main/res/layout/import_keys_server_fragment.xml new file mode 100644 index 000000000..d5fa3e290 --- /dev/null +++ b/OpenPGP-Keychain/src/main/res/layout/import_keys_server_fragment.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + \ No newline at end of file -- cgit v1.2.3