diff options
Diffstat (limited to 'OpenKeychain')
16 files changed, 510 insertions, 63 deletions
diff --git a/OpenKeychain/src/main/AndroidManifest.xml b/OpenKeychain/src/main/AndroidManifest.xml index 48677431c..c6e528f4d 100644 --- a/OpenKeychain/src/main/AndroidManifest.xml +++ b/OpenKeychain/src/main/AndroidManifest.xml @@ -85,6 +85,11 @@ android:label="@string/title_edit_key" android:windowSoftInputMode="stateHidden" /> <activity + android:name=".ui.EditKeyActivityNew" + android:configChanges="orientation|screenSize|keyboardHidden|keyboard" + android:label="@string/title_edit_key" + android:windowSoftInputMode="stateHidden" /> + <activity android:name=".ui.ViewKeyActivity" android:configChanges="orientation|screenSize|keyboardHidden|keyboard" android:label="@string/title_key_details" diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivityNew.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivityNew.java new file mode 100644 index 000000000..f2b5e68eb --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivityNew.java @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +package org.sufficientlysecure.keychain.ui; + +import android.net.Uri; +import android.os.Bundle; +import android.support.v7.app.ActionBarActivity; +import android.view.View; +import android.view.View.OnClickListener; + +import org.sufficientlysecure.keychain.Constants; +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.helper.ActionBarHelper; +import org.sufficientlysecure.keychain.remote.ui.AccountsListFragment; +import org.sufficientlysecure.keychain.util.Log; + +public class EditKeyActivityNew extends ActionBarActivity { + + private Uri mDataUri; + + private EditKeyFragment mEditKeyFragment; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + setContentView(R.layout.edit_key_activity_new); + +// // Inflate a "Done"/"Cancel" custom action bar view +// ActionBarHelper.setTwoButtonView(getSupportActionBar(), +// R.string.btn_save, R.drawable.ic_action_save, +// new OnClickListener() { +// @Override +// public void onClick(View v) { +// // Save +// +// } +// }, R.string.menu_key_edit_cancel, R.drawable.ic_action_cancel, +// new OnClickListener() { +// @Override +// public void onClick(View v) { +// // Cancel +// +// } +// } +// ); + + Uri dataUri = getIntent().getData(); + if (dataUri == null) { + Log.e(Constants.TAG, "Data missing. Should be Uri of key!"); + finish(); + return; + } + + loadFragment(savedInstanceState, dataUri); + } + + private void loadFragment(Bundle savedInstanceState, Uri dataUri) { + // However, if we're being restored from a previous state, + // then we don't need to do anything and should return or else + // we could end up with overlapping fragments. + if (savedInstanceState != null) { + return; + } + + // Create an instance of the fragment + mEditKeyFragment = EditKeyFragment.newInstance(dataUri); + + // Add the fragment to the 'fragment_container' FrameLayout + // NOTE: We use commitAllowingStateLoss() to prevent weird crashes! + getSupportFragmentManager().beginTransaction() + .replace(R.id.edit_key_fragment_container, mEditKeyFragment) + .commitAllowingStateLoss(); + // do it immediately! + getSupportFragmentManager().executePendingTransactions(); + } + +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java new file mode 100644 index 000000000..9231ce142 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java @@ -0,0 +1,200 @@ +/* + * Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +package org.sufficientlysecure.keychain.ui; + +import android.database.Cursor; +import android.net.Uri; +import android.os.Bundle; +import android.support.v4.app.LoaderManager; +import android.support.v4.content.CursorLoader; +import android.support.v4.content.Loader; +import android.support.v7.app.ActionBarActivity; +import android.view.LayoutInflater; +import android.view.View; +import android.view.View.OnClickListener; +import android.view.ViewGroup; +import android.widget.ListView; + +import org.sufficientlysecure.keychain.Constants; +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.helper.ActionBarHelper; +import org.sufficientlysecure.keychain.provider.KeychainContract; +import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; +import org.sufficientlysecure.keychain.ui.adapter.ViewKeyKeysAdapter; +import org.sufficientlysecure.keychain.ui.adapter.ViewKeyUserIdsAdapter; +import org.sufficientlysecure.keychain.util.Log; + +public class EditKeyFragment extends LoaderFragment implements + LoaderManager.LoaderCallbacks<Cursor> { + + public static final String ARG_DATA_URI = "uri"; + + private ListView mUserIds; + private ListView mKeys; + + private static final int LOADER_ID_USER_IDS = 0; + private static final int LOADER_ID_KEYS = 1; + + private ViewKeyUserIdsAdapter mUserIdsAdapter; + private ViewKeyKeysAdapter mKeysAdapter; + + private Uri mDataUri; + + /** + * Creates new instance of this fragment + */ + public static EditKeyFragment newInstance(Uri dataUri) { + EditKeyFragment frag = new EditKeyFragment(); + + Bundle args = new Bundle(); + args.putParcelable(ARG_DATA_URI, dataUri); + + frag.setArguments(args); + + return frag; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup superContainer, Bundle savedInstanceState) { + View root = super.onCreateView(inflater, superContainer, savedInstanceState); + View view = inflater.inflate(R.layout.edit_key_fragment, getContainer()); + + mUserIds = (ListView) view.findViewById(R.id.edit_key_user_ids); + mKeys = (ListView) view.findViewById(R.id.edit_key_keys); +// mActionEdit = view.findViewById(R.id.view_key_action_edit); + + return root; + } + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + + + // Inflate a "Done"/"Cancel" custom action bar view + ActionBarHelper.setTwoButtonView(((ActionBarActivity) getActivity()).getSupportActionBar(), + R.string.btn_save, R.drawable.ic_action_save, + new OnClickListener() { + @Override + public void onClick(View v) { + // Save + save(); + } + }, R.string.menu_key_edit_cancel, R.drawable.ic_action_cancel, + new OnClickListener() { + @Override + public void onClick(View v) { + // Cancel + getActivity().finish(); + } + } + ); + + Uri dataUri = getArguments().getParcelable(ARG_DATA_URI); + if (dataUri == null) { + Log.e(Constants.TAG, "Data missing. Should be Uri of key!"); + getActivity().finish(); + return; + } + + loadData(dataUri); + } + + private void loadData(Uri dataUri) { + mDataUri = dataUri; + + Log.i(Constants.TAG, "mDataUri: " + mDataUri.toString()); + +// mActionEncrypt.setOnClickListener(new View.OnClickListener() { +// @Override +// public void onClick(View v) { +// encrypt(mDataUri); +// } +// }); + + + mUserIdsAdapter = new ViewKeyUserIdsAdapter(getActivity(), null, 0); + mUserIds.setAdapter(mUserIdsAdapter); + mKeysAdapter = new ViewKeyKeysAdapter(getActivity(), null, 0); + mKeys.setAdapter(mKeysAdapter); + + // Prepare the loaders. Either re-connect with an existing ones, + // or start new ones. + getLoaderManager().initLoader(LOADER_ID_USER_IDS, null, this); + getLoaderManager().initLoader(LOADER_ID_KEYS, null, this); + } + + public Loader<Cursor> onCreateLoader(int id, Bundle args) { + setContentShown(false); + + switch (id) { + case LOADER_ID_USER_IDS: { + Uri baseUri = KeychainContract.UserIds.buildUserIdsUri(mDataUri); + return new CursorLoader(getActivity(), baseUri, + ViewKeyUserIdsAdapter.USER_IDS_PROJECTION, null, null, null); + } + + case LOADER_ID_KEYS: { + Uri baseUri = KeychainContract.Keys.buildKeysUri(mDataUri); + return new CursorLoader(getActivity(), baseUri, + ViewKeyKeysAdapter.KEYS_PROJECTION, null, null, null); + } + + default: + return null; + } + } + + public void onLoadFinished(Loader<Cursor> loader, Cursor 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_USER_IDS: + mUserIdsAdapter.swapCursor(data); + break; + + case LOADER_ID_KEYS: + mKeysAdapter.swapCursor(data); + break; + + } + setContentShown(true); + } + + /** + * This is called when the last Cursor provided to onLoadFinished() above is about to be closed. + * We need to make sure we are no longer using it. + */ + public void onLoaderReset(Loader<Cursor> loader) { + switch (loader.getId()) { + case LOADER_ID_USER_IDS: + mUserIdsAdapter.swapCursor(null); + break; + case LOADER_ID_KEYS: + mKeysAdapter.swapCursor(null); + break; + } + } + + private void save() { + getActivity().finish(); + // TODO + } + + +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java index 8f3851e84..f7455905d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java @@ -28,6 +28,7 @@ import android.os.Bundle; import android.os.Message; import android.os.Messenger; import android.os.Parcelable; +import android.support.v4.app.Fragment; import android.support.v4.view.ViewPager; import android.support.v7.app.ActionBarActivity; import android.view.MotionEvent; @@ -43,6 +44,7 @@ import com.github.johnpersano.supertoasts.util.Style; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.helper.OtherHelper; +import org.sufficientlysecure.keychain.helper.Preferences; import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry; import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; @@ -94,12 +96,12 @@ public class ImportKeysActivity extends ActionBarActivity { public static final int VIEW_PAGER_HEIGHT = 64; // dp - private static final int NAV_SERVER = 0; - private static final int NAV_QR_CODE = 1; - private static final int NAV_FILE = 2; - private static final int NAV_KEYBASE = 3; + private static final int TAB_KEYSERVER = 0; + private static final int TAB_QR_CODE = 1; + private static final int TAB_FILE = 2; + private static final int TAB_KEYBASE = 3; - private int mSwitchToTab = NAV_SERVER; + private int mSwitchToTab = TAB_KEYSERVER; @Override protected void onCreate(Bundle savedInstanceState) { @@ -118,10 +120,6 @@ public class ImportKeysActivity extends ActionBarActivity { } }); - // TODO: add actionbar button for this action? -// if (ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN.equals(getIntent().getAction())) { -// } - handleActions(savedInstanceState, getIntent()); } @@ -137,26 +135,31 @@ public class ImportKeysActivity extends ActionBarActivity { if (Intent.ACTION_VIEW.equals(action)) { // Android's Action when opening file associated to Keychain (see AndroidManifest.xml) - // override action to delegate it to Keychain's ACTION_IMPORT_KEY + // delegate action to ACTION_IMPORT_KEY 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); - } else if (ACTION_IMPORT_KEY.equals(action)) { + // delegate action to ACTION_IMPORT_KEY_FROM_KEYSERVER + String fingerprint = getFingerprintFromUri(dataUri); + action = ACTION_IMPORT_KEY_FROM_KEYSERVER; + extras.putString(EXTRA_FINGERPRINT, fingerprint); + } + + Bundle serverBundle = null; + boolean serverOnly = false; + if (ACTION_IMPORT_KEY.equals(action)) { /* Keychain's own Actions */ // display file fragment - mViewPager.setCurrentItem(NAV_FILE); + mViewPager.setCurrentItem(TAB_FILE); if (dataUri != null) { // action: directly load data startListFragment(savedInstanceState, null, dataUri, null); } else if (extras.containsKey(EXTRA_KEY_BYTES)) { - byte[] importData = intent.getByteArrayExtra(EXTRA_KEY_BYTES); + byte[] importData = extras.getByteArray(EXTRA_KEY_BYTES); // action: directly load data startListFragment(savedInstanceState, importData, null, null); @@ -175,7 +178,7 @@ public class ImportKeysActivity extends ActionBarActivity { 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); + long keyId = extras.getLong(EXTRA_KEY_ID, 0); if (keyId != 0) { query = PgpKeyHelper.convertKeyIdToHex(keyId); } @@ -185,7 +188,7 @@ public class ImportKeysActivity extends ActionBarActivity { // display keyserver fragment with query serverBundle = new Bundle(); serverBundle.putString(ImportKeysServerFragment.ARG_QUERY, query); - mSwitchToTab = NAV_SERVER; + mSwitchToTab = TAB_KEYSERVER; // action: search immediately startListFragment(savedInstanceState, null, null, query); @@ -199,7 +202,7 @@ public class ImportKeysActivity extends ActionBarActivity { * if the right key has been downloaded */ - String fingerprint = intent.getStringExtra(EXTRA_FINGERPRINT); + String fingerprint = extras.getString(EXTRA_FINGERPRINT); if (isFingerprintValid(fingerprint)) { String query = "0x" + fingerprint; @@ -209,7 +212,7 @@ public class ImportKeysActivity extends ActionBarActivity { serverBundle.putBoolean(ImportKeysServerFragment.ARG_DISABLE_QUERY_EDIT, true); // display server tab only serverOnly = true; - mSwitchToTab = NAV_SERVER; + mSwitchToTab = TAB_KEYSERVER; // action: search immediately startListFragment(savedInstanceState, null, null, query); @@ -223,7 +226,7 @@ public class ImportKeysActivity extends ActionBarActivity { } } else if (ACTION_IMPORT_KEY_FROM_FILE.equals(action)) { // NOTE: this only displays the appropriate fragment, no actions are taken - mSwitchToTab = NAV_FILE; + mSwitchToTab = TAB_FILE; // no immediate actions! startListFragment(savedInstanceState, null, null, null); @@ -231,20 +234,20 @@ public class ImportKeysActivity extends ActionBarActivity { // also exposed in AndroidManifest // NOTE: this only displays the appropriate fragment, no actions are taken - mSwitchToTab = NAV_QR_CODE; + mSwitchToTab = TAB_QR_CODE; // no immediate actions! startListFragment(savedInstanceState, null, null, null); } else if (ACTION_IMPORT_KEY_FROM_NFC.equals(action)) { // NOTE: this only displays the appropriate fragment, no actions are taken - mSwitchToTab = NAV_QR_CODE; + mSwitchToTab = TAB_QR_CODE; // no immediate actions! startListFragment(savedInstanceState, null, null, null); } else if (ACTION_IMPORT_KEY_FROM_KEYBASE.equals(action)) { // NOTE: this only displays the appropriate fragment, no actions are taken - mSwitchToTab = NAV_KEYBASE; + mSwitchToTab = TAB_KEYBASE; // no immediate actions! startListFragment(savedInstanceState, null, null, null); @@ -269,6 +272,8 @@ public class ImportKeysActivity extends ActionBarActivity { @Override public void onPageSelected(int position) { + // cancel loader and clear list + mListFragment.destroyLoader(); } @Override @@ -325,23 +330,45 @@ public class ImportKeysActivity extends ActionBarActivity { return OtherHelper.pxToDp(this, params.height); } - public void loadFromFingerprintUri(Bundle savedInstanceState, Uri dataUri) { + private String getFingerprintFromUri(Uri dataUri) { String fingerprint = dataUri.toString().split(":")[1].toLowerCase(Locale.ENGLISH); - Log.d(Constants.TAG, "fingerprint: " + fingerprint); + return fingerprint; + } + + public void loadFromFingerprintUri(Uri dataUri) { + String query = "0x" + getFingerprintFromUri(dataUri); + + // setCurrentItem does not work directly after onResume (from qr code scanner) + // see http://stackoverflow.com/q/19316729 + // so, reset adapter completely! + if (mViewPager.getAdapter() != null) + mViewPager.setAdapter(null); + mViewPager.setAdapter(mTabsAdapter); + mViewPager.setCurrentItem(TAB_KEYSERVER); - // TODO: reload fragment when coming from qr code! -// loadFromFingerprint(savedInstanceState, fingerprint); + ImportKeysServerFragment f = (ImportKeysServerFragment) + getActiveFragment(mViewPager, TAB_KEYSERVER); + // TODO: Currently it simply uses keyserver nr 0 + String keyserver = Preferences.getPreferences(ImportKeysActivity.this) + .getKeyServers()[0]; + + // set fields of ImportKeysServerFragment + f.setQueryAndKeyserver(query, keyserver); + // search directly + loadCallback(new ImportKeysListFragment.KeyserverLoaderState(query, keyserver)); + } + + // http://stackoverflow.com/a/9293207 + public Fragment getActiveFragment(ViewPager container, int position) { + String name = makeFragmentName(container.getId(), position); + return getSupportFragmentManager().findFragmentByTag(name); + } -// 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; + // http://stackoverflow.com/a/9293207 + private static String makeFragmentName(int viewId, int index) { + return "android:switcher:" + viewId + ":" + index; } private boolean isFingerprintValid(String fingerprint) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysFileFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysFileFragment.java index 60e5324c5..ce885c419 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysFileFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysFileFragment.java @@ -81,7 +81,7 @@ public class ImportKeysFileFragment extends Fragment { if (clipboardText != null) { sendText = clipboardText.toString(); if (sendText.toLowerCase(Locale.ENGLISH).startsWith(Constants.FINGERPRINT_SCHEME)) { - mImportActivity.loadFromFingerprintUri(null, Uri.parse(sendText)); + mImportActivity.loadFromFingerprintUri(Uri.parse(sendText)); return; } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java index 45c44803c..d77e3a452 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java @@ -24,7 +24,9 @@ import android.support.v4.app.ListFragment; import android.support.v4.app.LoaderManager; import android.support.v4.content.Loader; import android.support.v4.util.LongSparseArray; +import android.view.MotionEvent; import android.view.View; +import android.view.View.OnTouchListener; import android.widget.ListView; import org.sufficientlysecure.keychain.Constants; @@ -156,13 +158,23 @@ public class ImportKeysListFragment extends ListFragment implements if (dataUri != null || bytes != null) { mLoaderState = new BytesLoaderState(bytes, dataUri); } else if (query != null) { - // TODO: this is used when scanning QR Code or updating a key. + // TODO: this is used when updating a key. // Currently it simply uses keyserver nr 0 String keyserver = Preferences.getPreferences(getActivity()) .getKeyServers()[0]; mLoaderState = new KeyserverLoaderState(query, keyserver); } + getListView().setOnTouchListener(new OnTouchListener() { + @Override + public boolean onTouch(View v, MotionEvent event) { + if (!mAdapter.isEmpty()) { + mActivity.onTouchEvent(event); + } + return false; + } + }); + restartLoaders(); } @@ -185,27 +197,34 @@ public class ImportKeysListFragment extends ListFragment implements restartLoaders(); } + public void destroyLoader() { + if (getLoaderManager().getLoader(LOADER_ID_BYTES) != null) { + getLoaderManager().destroyLoader(LOADER_ID_BYTES); + } + if (getLoaderManager().getLoader(LOADER_ID_SERVER_QUERY) != null) { + getLoaderManager().destroyLoader(LOADER_ID_SERVER_QUERY); + } + if (getLoaderManager().getLoader(LOADER_ID_KEYBASE) != null) { + getLoaderManager().destroyLoader(LOADER_ID_KEYBASE); + } + setListShown(true); + } + private void restartLoaders() { if (mLoaderState instanceof BytesLoaderState) { // Start out with a progress indicator. setListShown(false); getLoaderManager().restartLoader(LOADER_ID_BYTES, null, this); - 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); - 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); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysQrCodeFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysQrCodeFragment.java index 5766fc189..5f54daa3c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysQrCodeFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysQrCodeFragment.java @@ -132,7 +132,7 @@ public class ImportKeysQrCodeFragment extends Fragment { } public void importFingerprint(Uri dataUri) { - mImportActivity.loadFromFingerprintUri(null, dataUri); + mImportActivity.loadFromFingerprintUri(dataUri); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysServerFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysServerFragment.java index c7467d789..d339bc132 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysServerFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysServerFragment.java @@ -40,7 +40,7 @@ import org.sufficientlysecure.keychain.util.Log; public class ImportKeysServerFragment extends Fragment { public static final String ARG_QUERY = "query"; - public static final String ARG_KEY_SERVER = "key_server"; + public static final String ARG_KEYSERVER = "keyserver"; public static final String ARG_DISABLE_QUERY_EDIT = "disable_query_edit"; private ImportKeysActivity mImportActivity; @@ -55,12 +55,12 @@ public class ImportKeysServerFragment extends Fragment { /** * Creates new instance of this fragment */ - public static ImportKeysServerFragment newInstance(String query, String keyServer) { + public static ImportKeysServerFragment newInstance(String query, String keyserver) { ImportKeysServerFragment frag = new ImportKeysServerFragment(); Bundle args = new Bundle(); args.putString(ARG_QUERY, query); - args.putString(ARG_KEY_SERVER, keyServer); + args.putString(ARG_KEYSERVER, keyserver); frag.setArguments(args); @@ -149,12 +149,12 @@ public class ImportKeysServerFragment extends Fragment { Log.d(Constants.TAG, "query: " + query); } - if (getArguments().containsKey(ARG_KEY_SERVER)) { - String keyServer = getArguments().getString(ARG_KEY_SERVER); - int keyServerPos = mServerAdapter.getPosition(keyServer); - mServerSpinner.setSelection(keyServerPos); + if (getArguments().containsKey(ARG_KEYSERVER)) { + String keyserver = getArguments().getString(ARG_KEYSERVER); + int keyserverPos = mServerAdapter.getPosition(keyserver); + mServerSpinner.setSelection(keyserverPos); - Log.d(Constants.TAG, "keyServer: " + keyServer); + Log.d(Constants.TAG, "keyserver: " + keyserver); } if (getArguments().getBoolean(ARG_DISABLE_QUERY_EDIT, false)) { @@ -174,4 +174,10 @@ public class ImportKeysServerFragment extends Fragment { mImportActivity.loadCallback(new ImportKeysListFragment.KeyserverLoaderState(query, keyserver)); } + public void setQueryAndKeyserver(String query, String keyserver) { + mQueryEditText.setText(query, TextView.BufferType.EDITABLE); + int keyServerPos = mServerAdapter.getPosition(keyserver); + mServerSpinner.setSelection(keyServerPos); + } + } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyKeysFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyKeysFragment.java index f4a44f526..e01a0140c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyKeysFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyKeysFragment.java @@ -83,17 +83,11 @@ public class ViewKeyKeysFragment extends LoaderFragment implements getLoaderManager().initLoader(0, null, this); } - static final String[] KEYS_PROJECTION = new String[] { - Keys._ID, - Keys.KEY_ID, Keys.RANK, Keys.ALGORITHM, Keys.KEY_SIZE, Keys.HAS_SECRET, - Keys.CAN_CERTIFY, Keys.CAN_ENCRYPT, Keys.CAN_SIGN, Keys.IS_REVOKED, - Keys.CREATION, Keys.EXPIRY, Keys.FINGERPRINT - }; - public Loader<Cursor> onCreateLoader(int id, Bundle args) { setContentShown(false); Uri baseUri = Keys.buildKeysUri(mDataUri); - return new CursorLoader(getActivity(), baseUri, KEYS_PROJECTION, null, null, null); + return new CursorLoader(getActivity(), baseUri, + ViewKeyKeysAdapter.KEYS_PROJECTION, null, null, null); } public void onLoadFinished(Loader<Cursor> loader, Cursor data) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java index ae7cef70c..bd29f3820 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java @@ -49,6 +49,7 @@ public class ViewKeyMainFragment extends LoaderFragment implements public static final String ARG_DATA_URI = "uri"; private View mActionEdit; + private View mActionEditNew; private View mActionEditDivider; private View mActionEncrypt; private View mActionCertify; @@ -73,6 +74,7 @@ public class ViewKeyMainFragment extends LoaderFragment implements mUserIds = (ListView) view.findViewById(R.id.view_key_user_ids); mActionEdit = view.findViewById(R.id.view_key_action_edit); + mActionEditNew = view.findViewById(R.id.view_key_action_edit_new); mActionEditDivider = view.findViewById(R.id.view_key_action_edit_divider); mActionEncrypt = view.findViewById(R.id.view_key_action_encrypt); mActionCertify = view.findViewById(R.id.view_key_action_certify); @@ -116,6 +118,11 @@ public class ViewKeyMainFragment extends LoaderFragment implements editKey(mDataUri); } }); + mActionEditNew.setOnClickListener(new View.OnClickListener() { + public void onClick(View view) { + editKeyNew(mDataUri); + } + }); mUserIdsAdapter = new ViewKeyUserIdsAdapter(getActivity(), null, 0); mUserIds.setAdapter(mUserIdsAdapter); @@ -256,4 +263,12 @@ public class ViewKeyMainFragment extends LoaderFragment implements startActivityForResult(editIntent, 0); } + private void editKeyNew(Uri dataUri) { + Intent editIntent = new Intent(getActivity(), EditKeyActivityNew.class); +// editIntent.setData(KeychainContract.KeyRingData.buildSecretKeyRingUri(dataUri)); + editIntent.setData(KeychainContract.KeyRingData.buildSecretKeyRingUri(dataUri)); + editIntent.setAction(EditKeyActivity.ACTION_EDIT_KEY); + startActivityForResult(editIntent, 0); + } + } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java index 233b1fca8..a44d32e5b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java @@ -170,7 +170,7 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> { } else { holder.userIdsList.setVisibility(View.VISIBLE); - // clear view from holder + // destroyLoader view from holder holder.userIdsList.removeAllViews(); Iterator<String> it = entry.getUserIds().iterator(); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListServerLoader.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListServerLoader.java index 4eb6f158b..d62c2db43 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListServerLoader.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListServerLoader.java @@ -47,7 +47,6 @@ public class ImportKeysListServerLoader @Override public AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>> loadInBackground() { - mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, null); if (mServerQuery == null) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ViewKeyKeysAdapter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ViewKeyKeysAdapter.java index f4942a2a0..dae287bbc 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ViewKeyKeysAdapter.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ViewKeyKeysAdapter.java @@ -53,6 +53,22 @@ public class ViewKeyKeysAdapter extends CursorAdapter { private ColorStateList mDefaultTextColor; + public static final String[] KEYS_PROJECTION = new String[] { + Keys._ID, + Keys.KEY_ID, + Keys.RANK, + Keys.ALGORITHM, + Keys.KEY_SIZE, + Keys.HAS_SECRET, + Keys.CAN_CERTIFY, + Keys.CAN_ENCRYPT, + Keys.CAN_SIGN, + Keys.IS_REVOKED, + Keys.CREATION, + Keys.EXPIRY, + Keys.FINGERPRINT + }; + public ViewKeyKeysAdapter(Context context, Cursor c, int flags) { super(context, c, flags); diff --git a/OpenKeychain/src/main/res/layout/edit_key_activity_new.xml b/OpenKeychain/src/main/res/layout/edit_key_activity_new.xml new file mode 100644 index 000000000..f96b993c5 --- /dev/null +++ b/OpenKeychain/src/main/res/layout/edit_key_activity_new.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <FrameLayout + android:id="@+id/edit_key_fragment_container" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" /> + +</LinearLayout>
\ No newline at end of file diff --git a/OpenKeychain/src/main/res/layout/edit_key_fragment.xml b/OpenKeychain/src/main/res/layout/edit_key_fragment.xml new file mode 100644 index 000000000..dbc0c3941 --- /dev/null +++ b/OpenKeychain/src/main/res/layout/edit_key_fragment.xml @@ -0,0 +1,44 @@ +<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical" + android:paddingLeft="16dp" + android:paddingRight="16dp"> + + <TextView + style="@style/SectionHeader" + android:layout_width="wrap_content" + android:layout_height="0dp" + android:layout_marginBottom="4dp" + android:layout_marginTop="8dp" + android:text="@string/section_user_ids" + android:layout_weight="1" /> + + <org.sufficientlysecure.keychain.ui.widget.FixedListView + android:id="@+id/edit_key_user_ids" + android:layout_width="match_parent" + android:layout_height="0dp" + android:layout_marginBottom="4dp" + android:layout_weight="1" /> + + <TextView + style="@style/SectionHeader" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginBottom="4dp" + android:layout_marginTop="8dp" + android:text="@string/section_keys" /> + + <org.sufficientlysecure.keychain.ui.widget.FixedListView + android:id="@+id/edit_key_keys" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginBottom="8dp" /> + + </LinearLayout> + +</ScrollView> diff --git a/OpenKeychain/src/main/res/layout/view_key_main_fragment.xml b/OpenKeychain/src/main/res/layout/view_key_main_fragment.xml index d93420a99..96871aacf 100644 --- a/OpenKeychain/src/main/res/layout/view_key_main_fragment.xml +++ b/OpenKeychain/src/main/res/layout/view_key_main_fragment.xml @@ -74,6 +74,22 @@ android:drawablePadding="8dp" android:gravity="center_vertical" /> + <TextView + android:id="@+id/view_key_action_edit_new" + android:paddingLeft="8dp" + android:paddingRight="8dp" + android:textAppearance="?android:attr/textAppearanceMedium" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:minHeight="?android:attr/listPreferredItemHeight" + android:clickable="true" + style="@style/SelectableItem" + android:text="NEW EDIT" + android:layout_weight="1" + android:drawableRight="@drawable/ic_action_edit" + android:drawablePadding="8dp" + android:gravity="center_vertical" /> + <View android:id="@+id/view_key_action_edit_divider" android:layout_width="match_parent" |