aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysCloudFragment.java
diff options
context:
space:
mode:
authorTim Bray <timbray@gmail.com>2014-09-12 08:34:51 -0700
committerTim Bray <timbray@gmail.com>2014-09-13 21:41:03 -0700
commit1c32d1df8801968ea6423ee4f1a9160e0c4ff0c3 (patch)
tree6571fc5b6aca0de6bd23e9acda38caf16d81cc30 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysCloudFragment.java
parent36ef8a9a62f32f0843c9e317d493a7f136624dce (diff)
downloadopen-keychain-1c32d1df8801968ea6423ee4f1a9160e0c4ff0c3.tar.gz
open-keychain-1c32d1df8801968ea6423ee4f1a9160e0c4ff0c3.tar.bz2
open-keychain-1c32d1df8801968ea6423ee4f1a9160e0c4ff0c3.zip
Add cloud search tab, lose Keybase/Keyserver tabs, re-organize prefs
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysCloudFragment.java')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysCloudFragment.java160
1 files changed, 160 insertions, 0 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysCloudFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysCloudFragment.java
new file mode 100644
index 000000000..6b4b833c6
--- /dev/null
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysCloudFragment.java
@@ -0,0 +1,160 @@
+/*
+ * Copyright (C) 2013-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.app.Activity;
+import android.content.Context;
+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.view.inputmethod.InputMethodManager;
+import android.widget.ArrayAdapter;
+import android.widget.AutoCompleteTextView;
+import android.widget.TextView;
+
+import org.sufficientlysecure.keychain.Constants;
+import org.sufficientlysecure.keychain.R;
+import org.sufficientlysecure.keychain.helper.ContactHelper;
+import org.sufficientlysecure.keychain.helper.Preferences;
+import org.sufficientlysecure.keychain.util.Log;
+
+import java.util.List;
+
+public class ImportKeysCloudFragment extends Fragment {
+ public static final String ARG_QUERY = "query";
+ public static final String ARG_DISABLE_QUERY_EDIT = "disable_query_edit";
+
+ private ImportKeysActivity mImportActivity;
+
+ private View mSearchButton;
+ private AutoCompleteTextView mQueryEditText;
+ private View mConfigButton;
+ private ArrayAdapter<String> mServerAdapter;
+
+ /**
+ * Creates new instance of this fragment
+ */
+ public static ImportKeysCloudFragment newInstance(String query, String keyserver, boolean doKeyserver, boolean doKeybase) {
+ ImportKeysCloudFragment frag = new ImportKeysCloudFragment();
+
+ Bundle args = new Bundle();
+ args.putString(ARG_QUERY, query);
+
+ frag.setArguments(args);
+
+ return frag;
+ }
+
+ /**
+ * Inflate the layout for this fragment
+ */
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.import_keys_cloud_fragment, container, false);
+
+ mSearchButton = view.findViewById(R.id.cloud_import_server_search);
+ mQueryEditText = (AutoCompleteTextView) view.findViewById(R.id.cloud_import_server_query);
+ mConfigButton = view.findViewById(R.id.cloud_import_server_config_button);
+
+ List<String> namesAndEmails = ContactHelper.getContactNames(getActivity());
+ namesAndEmails.addAll(ContactHelper.getContactMails(getActivity()));
+ mQueryEditText.setThreshold(3);
+ mQueryEditText.setAdapter(
+ new ArrayAdapter<String>
+ (getActivity(), android.R.layout.simple_spinner_dropdown_item,
+ namesAndEmails
+ )
+ );
+
+ mSearchButton.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ search(mQueryEditText.getText().toString());
+
+ // close keyboard after pressing search
+ InputMethodManager imm =
+ (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
+ imm.hideSoftInputFromWindow(mQueryEditText.getWindowToken(), 0);
+ }
+ });
+
+ mQueryEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
+ @Override
+ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
+ if (actionId == EditorInfo.IME_ACTION_SEARCH) {
+ search(mQueryEditText.getText().toString());
+
+ // Don't return true to let the keyboard close itself after pressing search
+ return false;
+ }
+ return false;
+ }
+ });
+
+ mConfigButton.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Intent i = new Intent(mImportActivity, PreferencesActivity.class);
+ // GRR, for some reason I can’t set the Action or I get an incomprehensible
+ // exception about “modern two-pane layouts”
+ // i.setAction(PreferencesActivity.ACTION_PREFS_CLOUD);
+ startActivity(i);
+ }
+ });
+
+ return view;
+ }
+
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+
+ // set displayed values
+ if (getArguments() != null) {
+ if (getArguments().containsKey(ARG_QUERY)) {
+ String query = getArguments().getString(ARG_QUERY);
+ mQueryEditText.setText(query, TextView.BufferType.EDITABLE);
+
+ Log.d(Constants.TAG, "query: " + query);
+ }
+
+ if (getArguments().getBoolean(ARG_DISABLE_QUERY_EDIT, false)) {
+ mQueryEditText.setEnabled(false);
+ }
+ }
+ }
+
+ @Override
+ public void onAttach(Activity activity) {
+ super.onAttach(activity);
+
+ mImportActivity = (ImportKeysActivity) activity;
+ }
+
+ private void search(String query) {
+ Preferences prefs = Preferences.getPreferences(getActivity());
+ mImportActivity.loadCallback(new ImportKeysListFragment.CloudLoaderState(query, prefs.getCloudSearchPrefs()));
+ }
+
+}