ImportKeys: Move action buttons inside action bar
This commit is contained in:
@@ -24,7 +24,6 @@ import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
@@ -106,17 +105,6 @@ public class ImportKeysActivity extends BaseActivity implements ImportKeysListen
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestoreInstanceState(Bundle savedInstanceState) {
|
||||
super.onRestoreInstanceState(savedInstanceState);
|
||||
|
||||
// the only thing we need to take care of for restoring state is
|
||||
// that the top layout is shown iff it contains a fragment
|
||||
Fragment topFragment = getSupportFragmentManager().findFragmentByTag(TAG_FRAG_TOP);
|
||||
boolean hasTopFragment = topFragment != null;
|
||||
findViewById(R.id.import_keys_top_layout).setVisibility(hasTopFragment ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
protected void handleActions(@NonNull Intent intent) {
|
||||
String action = intent.getAction();
|
||||
Bundle extras = intent.getExtras();
|
||||
@@ -278,10 +266,8 @@ public class ImportKeysActivity extends BaseActivity implements ImportKeysListen
|
||||
}
|
||||
|
||||
private void startTopFileFragment() {
|
||||
findViewById(R.id.import_keys_top_layout).setVisibility(View.VISIBLE);
|
||||
Fragment importFileFragment = ImportKeysFileFragment.newInstance();
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
.replace(R.id.import_keys_top_container, importFileFragment, TAG_FRAG_TOP)
|
||||
getSupportFragmentManager().beginTransaction().add(importFileFragment, TAG_FRAG_TOP)
|
||||
.commit();
|
||||
}
|
||||
|
||||
@@ -296,11 +282,10 @@ public class ImportKeysActivity extends BaseActivity implements ImportKeysListen
|
||||
*/
|
||||
private void startTopCloudFragment(String query, boolean disableQueryEdit,
|
||||
Preferences.CloudSearchPrefs cloudSearchPrefs) {
|
||||
findViewById(R.id.import_keys_top_layout).setVisibility(View.VISIBLE);
|
||||
|
||||
Fragment importCloudFragment = ImportKeysCloudFragment.newInstance(query, disableQueryEdit,
|
||||
cloudSearchPrefs);
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
.replace(R.id.import_keys_top_container, importCloudFragment, TAG_FRAG_TOP)
|
||||
getSupportFragmentManager().beginTransaction().add(importCloudFragment, TAG_FRAG_TOP)
|
||||
.commit();
|
||||
}
|
||||
|
||||
|
||||
@@ -23,30 +23,22 @@ import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.KeyEvent;
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
import android.support.v4.view.MenuItemCompat.OnActionExpandListener;
|
||||
import android.support.v7.widget.SearchView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
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.keyimport.processing.ImportKeysListener;
|
||||
import org.sufficientlysecure.keychain.keyimport.processing.CloudLoaderState;
|
||||
import org.sufficientlysecure.keychain.util.ContactHelper;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
import org.sufficientlysecure.keychain.keyimport.processing.ImportKeysListener;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Consists of the search bar, search button, and search settings button
|
||||
*/
|
||||
@@ -59,8 +51,6 @@ public class ImportKeysCloudFragment extends Fragment {
|
||||
private Activity mActivity;
|
||||
private ImportKeysListener mCallback;
|
||||
|
||||
private AutoCompleteTextView mQueryEditText;
|
||||
|
||||
/**
|
||||
* Creates new instance of this fragment
|
||||
*
|
||||
@@ -84,73 +74,10 @@ public class ImportKeysCloudFragment extends Fragment {
|
||||
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);
|
||||
|
||||
mQueryEditText = (AutoCompleteTextView) view.findViewById(R.id.cloud_import_server_query);
|
||||
|
||||
ContactHelper contactHelper = new ContactHelper(getActivity());
|
||||
List<String> namesAndEmails = contactHelper.getContactNames();
|
||||
namesAndEmails.addAll(contactHelper.getContactMails());
|
||||
mQueryEditText.setThreshold(3);
|
||||
mQueryEditText.setAdapter(
|
||||
new ArrayAdapter<>
|
||||
(getActivity(), android.R.layout.simple_spinner_dropdown_item,
|
||||
namesAndEmails
|
||||
)
|
||||
);
|
||||
|
||||
View searchButton = view.findViewById(R.id.cloud_import_server_search);
|
||||
searchButton.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
search(mQueryEditText.getText().toString().trim());
|
||||
}
|
||||
});
|
||||
|
||||
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().trim());
|
||||
|
||||
// Don't return true to let the keyboard close itself after pressing search
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
// set displayed values
|
||||
if (getArguments() != null) {
|
||||
String query = getArguments().getString(ARG_QUERY);
|
||||
if (query != null) {
|
||||
mQueryEditText.setText(query, TextView.BufferType.EDITABLE);
|
||||
|
||||
Log.d(Constants.TAG, "query: " + query);
|
||||
} else {
|
||||
// open keyboard
|
||||
mQueryEditText.requestFocus();
|
||||
toggleKeyboard(true);
|
||||
}
|
||||
|
||||
if (getArguments().getBoolean(ARG_DISABLE_QUERY_EDIT, false)) {
|
||||
mQueryEditText.setEnabled(false);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -170,20 +97,52 @@ public class ImportKeysCloudFragment extends Fragment {
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.import_keys_cloud_fragment, menu);
|
||||
|
||||
MenuItem searchItem = menu.findItem(R.id.menu_import_keys_cloud_search);
|
||||
final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
|
||||
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
searchView.clearFocus();
|
||||
search(searchView.getQuery().toString().trim());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
MenuItemCompat.setOnActionExpandListener(searchItem, new OnActionExpandListener() {
|
||||
@Override
|
||||
public boolean onMenuItemActionExpand(MenuItem item) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemActionCollapse(MenuItem item) {
|
||||
mActivity.finish();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.import_cloud_settings:
|
||||
int itemId = item.getItemId();
|
||||
switch (itemId) {
|
||||
case R.id.menu_import_keys_cloud_settings:
|
||||
Intent intent = new Intent(mActivity, SettingsActivity.class);
|
||||
intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT, SettingsActivity.CloudSearchPrefsFragment.class.getName());
|
||||
intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT,
|
||||
SettingsActivity.CloudSearchPrefsFragment.class.getName());
|
||||
startActivity(intent);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
private void search(String query) {
|
||||
|
||||
@@ -24,6 +24,9 @@ import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
@@ -65,46 +68,10 @@ public class ImportKeysFileFragment extends Fragment {
|
||||
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_file_fragment, container, false);
|
||||
|
||||
mBrowse = view.findViewById(R.id.import_keys_file_browse);
|
||||
mBrowse.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
// open .asc or .gpg files
|
||||
// setting it to text/plain prevents Cyanogenmod's file manager from selecting asc
|
||||
// or gpg types!
|
||||
FileHelper.openDocument(ImportKeysFileFragment.this,
|
||||
Uri.fromFile(Constants.Path.APP_DIR), "*/*", false, REQUEST_CODE_FILE);
|
||||
}
|
||||
});
|
||||
|
||||
mClipboardButton = view.findViewById(R.id.import_clipboard_button);
|
||||
mClipboardButton.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
CharSequence clipboardText = ClipboardReflection.getClipboardText(getActivity());
|
||||
String sendText = "";
|
||||
if (clipboardText != null) {
|
||||
sendText = clipboardText.toString();
|
||||
sendText = PgpHelper.getPgpKeyContent(sendText);
|
||||
if (sendText == null) {
|
||||
Notify.create(mActivity, R.string.error_bad_data, Style.ERROR).show();
|
||||
return;
|
||||
}
|
||||
mCallback.loadKeys(new BytesLoaderState(sendText.getBytes(), null));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
return view;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -121,6 +88,42 @@ public class ImportKeysFileFragment extends Fragment {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.import_keys_file_fragment, menu);
|
||||
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
int itemId = item.getItemId();
|
||||
switch (itemId) {
|
||||
case R.id.menu_import_keys_file_open:
|
||||
// open .asc or .gpg files
|
||||
// setting it to text/plain prevents Cyanogenmod's file manager from selecting asc
|
||||
// or gpg types!
|
||||
FileHelper.openDocument(ImportKeysFileFragment.this,
|
||||
Uri.fromFile(Constants.Path.APP_DIR), "*/*", false, REQUEST_CODE_FILE);
|
||||
return true;
|
||||
case R.id.menu_import_keys_file_paste:
|
||||
CharSequence clipboardText = ClipboardReflection.getClipboardText(getActivity());
|
||||
String sendText = "";
|
||||
if (clipboardText != null) {
|
||||
sendText = clipboardText.toString();
|
||||
sendText = PgpHelper.getPgpKeyContent(sendText);
|
||||
if (sendText == null) {
|
||||
Notify.create(mActivity, R.string.error_bad_data, Style.ERROR).show();
|
||||
} else {
|
||||
mCallback.loadKeys(new BytesLoaderState(sendText.getBytes(), null));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
switch (requestCode) {
|
||||
|
||||
Reference in New Issue
Block a user