ImportKeys: Move action buttons inside action bar
This commit is contained in:
parent
9469d6d6b2
commit
37f91e326c
|
@ -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) {
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 227 B |
Binary file not shown.
After Width: | Height: | Size: 157 B |
Binary file not shown.
After Width: | Height: | Size: 244 B |
Binary file not shown.
After Width: | Height: | Size: 340 B |
Binary file not shown.
After Width: | Height: | Size: 460 B |
|
@ -21,26 +21,6 @@
|
|||
|
||||
<include layout="@layout/notify_area" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/import_keys_top_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:visibility="gone">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/import_keys_top_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="64dp"
|
||||
android:orientation="vertical" />
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dip"
|
||||
android:background="?android:attr/listDivider" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/import_keys_list_container"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -50,7 +30,7 @@
|
|||
<RelativeLayout
|
||||
android:id="@+id/import_snackbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?android:attr/listPreferredItemHeight"
|
||||
android:orientation="horizontal"
|
||||
android:paddingLeft="8dp">
|
||||
|
||||
<AutoCompleteTextView
|
||||
android:id="@+id/cloud_import_server_query"
|
||||
android:layout_width="0dip"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_weight="1"
|
||||
android:gravity="top|left"
|
||||
android:hint="@string/hint_cloud_search_hint"
|
||||
android:imeOptions="actionSearch"
|
||||
android:inputType="textNoSuggestions"
|
||||
android:lines="1"
|
||||
android:maxLines="1"
|
||||
android:minLines="1"
|
||||
android:singleLine="true" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/cloud_import_server_search"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:background="?android:selectableItemBackground"
|
||||
android:padding="8dp"
|
||||
android:src="@drawable/ic_search_grey_24dp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
|
@ -1,66 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/import_keys_file_browse"
|
||||
android:paddingLeft="8dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?android:attr/listPreferredItemHeight"
|
||||
android:clickable="true"
|
||||
android:background="?android:selectableItemBackground"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:paddingLeft="8dp"
|
||||
android:paddingRight="8dp"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:layout_width="0dip"
|
||||
android:layout_height="match_parent"
|
||||
android:text="@string/filemanager_title_open"
|
||||
android:layout_weight="1"
|
||||
android:drawableRight="@drawable/ic_folder_grey_24dp"
|
||||
android:drawablePadding="8dp"
|
||||
android:gravity="center_vertical" />
|
||||
|
||||
<View
|
||||
android:layout_width="1dip"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="right"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:background="?android:attr/listDivider" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/import_clipboard_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="8dp"
|
||||
android:src="@drawable/ic_content_paste_grey_24dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:background="?android:selectableItemBackground" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/import_qrcode_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingRight="16dp"
|
||||
android:paddingTop="8dp"
|
||||
android:visibility="gone" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/import_qrcode_progress"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingRight="16dp"
|
||||
android:progress="0"
|
||||
android:visibility="gone" />
|
||||
|
||||
</LinearLayout>
|
|
@ -1,8 +1,16 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:id="@+id/import_cloud_settings"
|
||||
android:id="@+id/menu_import_keys_cloud_search"
|
||||
android:icon="@drawable/ic_search_white_24dp"
|
||||
android:title="@string/menu_search"
|
||||
app:actionViewClass="android.support.v7.widget.SearchView"
|
||||
app:showAsAction="collapseActionView|always" />
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_import_keys_cloud_settings"
|
||||
android:title="@string/menu_preferences" />
|
||||
|
||||
</menu>
|
17
OpenKeychain/src/main/res/menu/import_keys_file_fragment.xml
Normal file
17
OpenKeychain/src/main/res/menu/import_keys_file_fragment.xml
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_import_keys_file_paste"
|
||||
android:icon="@drawable/ic_content_paste_white_24dp"
|
||||
android:title="@string/menu_paste"
|
||||
app:showAsAction="always" />
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_import_keys_file_open"
|
||||
android:icon="@drawable/ic_folder_white_24dp"
|
||||
android:title="@string/menu_open"
|
||||
app:showAsAction="always" />
|
||||
|
||||
</menu>
|
|
@ -122,6 +122,8 @@
|
|||
<string name="menu_delete_key">"Delete key"</string>
|
||||
<string name="menu_manage_keys">"Manage my keys"</string>
|
||||
<string name="menu_search">"Search"</string>
|
||||
<string name="menu_open">"Open"</string>
|
||||
<string name="menu_paste">"Paste"</string>
|
||||
<string name="menu_nfc_preferences">"NFC settings"</string>
|
||||
<string name="menu_beam_preferences">"Beam settings"</string>
|
||||
<string name="menu_encrypt_to">"Encrypt to…"</string>
|
||||
|
|
Loading…
Reference in a new issue