mirror of
https://github.com/moparisthebest/open-keychain
synced 2025-03-03 02:42:00 -05:00
Remove tabs from import keys activity
This commit is contained in:
parent
71e3fb5380
commit
c2e7c2416f
@ -483,8 +483,7 @@
|
|||||||
android:name=".ui.ImportKeysActivity"
|
android:name=".ui.ImportKeysActivity"
|
||||||
android:configChanges="orientation|screenSize|keyboardHidden|keyboard"
|
android:configChanges="orientation|screenSize|keyboardHidden|keyboard"
|
||||||
android:label="@string/title_import_keys"
|
android:label="@string/title_import_keys"
|
||||||
android:launchMode="singleTop"
|
android:launchMode="singleTop">
|
||||||
android:windowSoftInputMode="stateHidden">
|
|
||||||
|
|
||||||
<!-- VIEW with mimeType: Allows to import keys (attached to emails) from email apps -->
|
<!-- VIEW with mimeType: Allows to import keys (attached to emails) from email apps -->
|
||||||
<intent-filter android:label="@string/intent_import_key">
|
<intent-filter android:label="@string/intent_import_key">
|
||||||
|
@ -29,36 +29,30 @@ import android.os.Message;
|
|||||||
import android.os.Messenger;
|
import android.os.Messenger;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.view.ViewPager;
|
|
||||||
import android.support.v7.app.ActionBarActivity;
|
import android.support.v7.app.ActionBarActivity;
|
||||||
import android.view.MotionEvent;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.api.OpenKeychainIntents;
|
import org.sufficientlysecure.keychain.api.OpenKeychainIntents;
|
||||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
|
||||||
import org.sufficientlysecure.keychain.util.ParcelableFileCache.IteratorWithSize;
|
|
||||||
import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry;
|
import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry;
|
||||||
import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
|
import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
|
||||||
|
import org.sufficientlysecure.keychain.operations.results.ImportKeyResult;
|
||||||
|
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
||||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||||
import org.sufficientlysecure.keychain.operations.results.ImportKeyResult;
|
|
||||||
import org.sufficientlysecure.keychain.ui.adapter.PagerTabStripAdapter;
|
|
||||||
import org.sufficientlysecure.keychain.ui.widget.SlidingTabLayout;
|
|
||||||
import org.sufficientlysecure.keychain.util.ParcelableFileCache;
|
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
|
||||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||||
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
import org.sufficientlysecure.keychain.util.ParcelableFileCache;
|
||||||
|
import org.sufficientlysecure.keychain.util.ParcelableFileCache.IteratorWithSize;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
public class ImportKeysActivity extends ActionBarActivity {
|
public class ImportKeysActivity extends ActionBarActivity {
|
||||||
public static final String ACTION_IMPORT_KEY = OpenKeychainIntents.IMPORT_KEY;
|
public static final String ACTION_IMPORT_KEY = OpenKeychainIntents.IMPORT_KEY;
|
||||||
public static final String ACTION_IMPORT_KEY_FROM_QR_CODE = OpenKeychainIntents.IMPORT_KEY_FROM_QR_CODE;
|
|
||||||
public static final String ACTION_IMPORT_KEY_FROM_KEYSERVER = OpenKeychainIntents.IMPORT_KEY_FROM_KEYSERVER;
|
public static final String ACTION_IMPORT_KEY_FROM_KEYSERVER = OpenKeychainIntents.IMPORT_KEY_FROM_KEYSERVER;
|
||||||
public static final String ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN_RESULT =
|
public static final String ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN_RESULT =
|
||||||
Constants.INTENT_PREFIX + "IMPORT_KEY_FROM_KEY_SERVER_AND_RETURN_RESULT";
|
Constants.INTENT_PREFIX + "IMPORT_KEY_FROM_KEY_SERVER_AND_RETURN_RESULT";
|
||||||
@ -89,18 +83,8 @@ public class ImportKeysActivity extends ActionBarActivity {
|
|||||||
|
|
||||||
// view
|
// view
|
||||||
private ImportKeysListFragment mListFragment;
|
private ImportKeysListFragment mListFragment;
|
||||||
|
private Fragment mTopFragment;
|
||||||
private View mImportButton;
|
private View mImportButton;
|
||||||
private ViewPager mViewPager;
|
|
||||||
private SlidingTabLayout mSlidingTabLayout;
|
|
||||||
private PagerTabStripAdapter mTabsAdapter;
|
|
||||||
|
|
||||||
|
|
||||||
private static final int ALL_TABS = -1;
|
|
||||||
private static final int TAB_CLOUD = 0;
|
|
||||||
private static final int TAB_QR_CODE = 1;
|
|
||||||
private static final int TAB_FILE = 2;
|
|
||||||
|
|
||||||
private int mSwitchToTab = TAB_CLOUD;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -108,9 +92,6 @@ public class ImportKeysActivity extends ActionBarActivity {
|
|||||||
|
|
||||||
setContentView(R.layout.import_keys_activity);
|
setContentView(R.layout.import_keys_activity);
|
||||||
|
|
||||||
mViewPager = (ViewPager) findViewById(R.id.import_pager);
|
|
||||||
mSlidingTabLayout = (SlidingTabLayout) findViewById(R.id.import_sliding_tab_layout);
|
|
||||||
|
|
||||||
mImportButton = findViewById(R.id.import_import);
|
mImportButton = findViewById(R.id.import_import);
|
||||||
mImportButton.setOnClickListener(new OnClickListener() {
|
mImportButton.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -138,22 +119,9 @@ public class ImportKeysActivity extends ActionBarActivity {
|
|||||||
action = ACTION_IMPORT_KEY;
|
action = ACTION_IMPORT_KEY;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scheme != null && scheme.toLowerCase(Locale.ENGLISH).equals(Constants.FINGERPRINT_SCHEME)) {
|
|
||||||
/* Scanning a fingerprint directly with Barcode Scanner */
|
|
||||||
// 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;
|
|
||||||
int showTabOnly = TAB_CLOUD;
|
|
||||||
if (ACTION_IMPORT_KEY.equals(action)) {
|
if (ACTION_IMPORT_KEY.equals(action)) {
|
||||||
/* Keychain's own Actions */
|
/* Keychain's own Actions */
|
||||||
|
startFileFragment(savedInstanceState);
|
||||||
// display file fragment
|
|
||||||
showTabOnly = TAB_FILE;
|
|
||||||
mSwitchToTab = TAB_FILE;
|
|
||||||
|
|
||||||
if (dataUri != null) {
|
if (dataUri != null) {
|
||||||
// action: directly load data
|
// action: directly load data
|
||||||
@ -187,9 +155,7 @@ public class ImportKeysActivity extends ActionBarActivity {
|
|||||||
|
|
||||||
if (query != null && query.length() > 0) {
|
if (query != null && query.length() > 0) {
|
||||||
// display keyserver fragment with query
|
// display keyserver fragment with query
|
||||||
serverBundle = new Bundle();
|
startCloudFragment(savedInstanceState, query, false);
|
||||||
serverBundle.putString(ImportKeysCloudFragment.ARG_QUERY, query);
|
|
||||||
mSwitchToTab = TAB_CLOUD;
|
|
||||||
|
|
||||||
// action: search immediately
|
// action: search immediately
|
||||||
startListFragment(savedInstanceState, null, null, query);
|
startListFragment(savedInstanceState, null, null, query);
|
||||||
@ -208,12 +174,7 @@ public class ImportKeysActivity extends ActionBarActivity {
|
|||||||
String query = "0x" + fingerprint;
|
String query = "0x" + fingerprint;
|
||||||
|
|
||||||
// display keyserver fragment with query
|
// display keyserver fragment with query
|
||||||
serverBundle = new Bundle();
|
startCloudFragment(savedInstanceState, query, true);
|
||||||
serverBundle.putString(ImportKeysCloudFragment.ARG_QUERY, query);
|
|
||||||
serverBundle.putBoolean(ImportKeysCloudFragment.ARG_DISABLE_QUERY_EDIT, true);
|
|
||||||
// display server tab only
|
|
||||||
showTabOnly = TAB_CLOUD;
|
|
||||||
mSwitchToTab = TAB_CLOUD;
|
|
||||||
|
|
||||||
// action: search immediately
|
// action: search immediately
|
||||||
startListFragment(savedInstanceState, null, null, query);
|
startListFragment(savedInstanceState, null, null, query);
|
||||||
@ -227,91 +188,29 @@ public class ImportKeysActivity extends ActionBarActivity {
|
|||||||
}
|
}
|
||||||
} else if (ACTION_IMPORT_KEY_FROM_FILE.equals(action)) {
|
} else if (ACTION_IMPORT_KEY_FROM_FILE.equals(action)) {
|
||||||
// NOTE: this only displays the appropriate fragment, no actions are taken
|
// NOTE: this only displays the appropriate fragment, no actions are taken
|
||||||
showTabOnly = TAB_FILE;
|
startFileFragment(savedInstanceState);
|
||||||
mSwitchToTab = TAB_FILE;
|
|
||||||
|
|
||||||
// no immediate actions!
|
// no immediate actions!
|
||||||
startListFragment(savedInstanceState, null, null, null);
|
startListFragment(savedInstanceState, null, null, null);
|
||||||
} else if (ACTION_IMPORT_KEY_FROM_FILE_AND_RETURN.equals(action)) {
|
} else if (ACTION_IMPORT_KEY_FROM_FILE_AND_RETURN.equals(action)) {
|
||||||
// NOTE: this only displays the appropriate fragment, no actions are taken
|
// NOTE: this only displays the appropriate fragment, no actions are taken
|
||||||
mSwitchToTab = TAB_FILE;
|
startFileFragment(savedInstanceState);
|
||||||
// display file tab only
|
|
||||||
showTabOnly = TAB_FILE;
|
|
||||||
|
|
||||||
// no immediate actions!
|
|
||||||
startListFragment(savedInstanceState, null, null, null);
|
|
||||||
} else if (ACTION_IMPORT_KEY_FROM_QR_CODE.equals(action)) {
|
|
||||||
// also exposed in AndroidManifest
|
|
||||||
showTabOnly = ALL_TABS;
|
|
||||||
// NOTE: this only displays the appropriate fragment, no actions are taken
|
|
||||||
mSwitchToTab = TAB_QR_CODE;
|
|
||||||
|
|
||||||
// no immediate actions!
|
// no immediate actions!
|
||||||
startListFragment(savedInstanceState, null, null, null);
|
startListFragment(savedInstanceState, null, null, null);
|
||||||
} else if (ACTION_IMPORT_KEY_FROM_NFC.equals(action)) {
|
} else if (ACTION_IMPORT_KEY_FROM_NFC.equals(action)) {
|
||||||
showTabOnly = ALL_TABS;
|
|
||||||
// NOTE: this only displays the appropriate fragment, no actions are taken
|
// NOTE: this only displays the appropriate fragment, no actions are taken
|
||||||
mSwitchToTab = TAB_QR_CODE;
|
startFileFragment(savedInstanceState);
|
||||||
|
// TODO!!!!!
|
||||||
|
|
||||||
// no immediate actions!
|
// no immediate actions!
|
||||||
startListFragment(savedInstanceState, null, null, null);
|
startListFragment(savedInstanceState, null, null, null);
|
||||||
} else {
|
} else {
|
||||||
|
startCloudFragment(savedInstanceState, null, false);
|
||||||
startListFragment(savedInstanceState, null, null, null);
|
startListFragment(savedInstanceState, null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
initTabs(serverBundle, showTabOnly);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initTabs(Bundle serverBundle, int showTabOnly) {
|
|
||||||
mTabsAdapter = new PagerTabStripAdapter(this);
|
|
||||||
mViewPager.setAdapter(mTabsAdapter);
|
|
||||||
mSlidingTabLayout.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
|
||||||
@Override
|
|
||||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPageSelected(int position) {
|
|
||||||
// cancel loader and clear list
|
|
||||||
if (mListFragment != null) {
|
|
||||||
mListFragment.destroyLoader();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPageScrollStateChanged(int state) {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
switch (showTabOnly) {
|
|
||||||
case ALL_TABS:
|
|
||||||
// show default tabs
|
|
||||||
mTabsAdapter.addTab(ImportKeysCloudFragment.class,
|
|
||||||
serverBundle, getString(R.string.import_tab_cloud));
|
|
||||||
mTabsAdapter.addTab(ImportKeysQrCodeFragment.class,
|
|
||||||
null, getString(R.string.import_tab_qr_code));
|
|
||||||
mTabsAdapter.addTab(ImportKeysFileFragment.class,
|
|
||||||
null, getString(R.string.import_tab_direct));
|
|
||||||
break;
|
|
||||||
case TAB_CLOUD:
|
|
||||||
mTabsAdapter.addTab(ImportKeysCloudFragment.class,
|
|
||||||
serverBundle, getString(R.string.import_tab_cloud));
|
|
||||||
break;
|
|
||||||
case TAB_QR_CODE:
|
|
||||||
mTabsAdapter.addTab(ImportKeysQrCodeFragment.class,
|
|
||||||
null, getString(R.string.import_tab_qr_code));
|
|
||||||
break;
|
|
||||||
case TAB_FILE:
|
|
||||||
mTabsAdapter.addTab(ImportKeysFileFragment.class,
|
|
||||||
null, getString(R.string.import_tab_direct));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// update layout after operations
|
|
||||||
mSlidingTabLayout.setViewPager(mViewPager);
|
|
||||||
|
|
||||||
mViewPager.setCurrentItem(mSwitchToTab);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void startListFragment(Bundle savedInstanceState, byte[] bytes, Uri dataUri, String serverQuery) {
|
private void startListFragment(Bundle savedInstanceState, byte[] bytes, Uri dataUri, String serverQuery) {
|
||||||
// However, if we're being restored from a previous state,
|
// However, if we're being restored from a previous state,
|
||||||
@ -333,47 +232,44 @@ public class ImportKeysActivity extends ActionBarActivity {
|
|||||||
getSupportFragmentManager().executePendingTransactions();
|
getSupportFragmentManager().executePendingTransactions();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getFingerprintFromUri(Uri dataUri) {
|
private void startFileFragment(Bundle savedInstanceState) {
|
||||||
String fingerprint = dataUri.toString().split(":")[1].toLowerCase(Locale.ENGLISH);
|
// However, if we're being restored from a previous state,
|
||||||
Log.d(Constants.TAG, "fingerprint: " + fingerprint);
|
// then we don't need to do anything and should return or else
|
||||||
return fingerprint;
|
// we could end up with overlapping fragments.
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadFromFingerprint(String fingerprint) {
|
// Create an instance of the fragment
|
||||||
// String fingerprint = "0x" + getFingerprintFromUri(dataUri);
|
mTopFragment = ImportKeysFileFragment.newInstance();
|
||||||
|
|
||||||
// setCurrentItem does not work directly after onResume (from qr code scanner)
|
// Add the fragment to the 'fragment_container' FrameLayout
|
||||||
// see http://stackoverflow.com/q/19316729
|
// NOTE: We use commitAllowingStateLoss() to prevent weird crashes!
|
||||||
// so, reset adapter completely!
|
getSupportFragmentManager().beginTransaction()
|
||||||
// if (mViewPager.getAdapter() != null)
|
.replace(R.id.import_keys_top_container, mTopFragment)
|
||||||
// mViewPager.setAdapter(null);
|
.commitAllowingStateLoss();
|
||||||
// mViewPager.setAdapter(mTabsAdapter);
|
// do it immediately!
|
||||||
// mViewPager.setCurrentItem(TAB_CLOUD);
|
getSupportFragmentManager().executePendingTransactions();
|
||||||
|
|
||||||
// ImportKeysCloudFragment f = (ImportKeysCloudFragment)
|
|
||||||
// getActiveFragment(mViewPager, TAB_CLOUD);
|
|
||||||
|
|
||||||
Intent searchIntent = new Intent(this, ImportKeysActivity.class);
|
|
||||||
searchIntent.putExtra(ImportKeysActivity.EXTRA_FINGERPRINT, fingerprint);
|
|
||||||
startActivity(searchIntent);
|
|
||||||
|
|
||||||
// // search config
|
|
||||||
// Preferences prefs = Preferences.getPreferences(ImportKeysActivity.this);
|
|
||||||
// Preferences.CloudSearchPrefs cloudPrefs = new Preferences.CloudSearchPrefs(true, true, prefs.getPreferredKeyserver());
|
|
||||||
//
|
|
||||||
// // search directly
|
|
||||||
// loadCallback(new ImportKeysListFragment.CloudLoaderState(query, cloudPrefs));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// http://stackoverflow.com/a/9293207
|
private void startCloudFragment(Bundle savedInstanceState, String query, boolean disableQueryEdit) {
|
||||||
public Fragment getActiveFragment(ViewPager container, int position) {
|
// However, if we're being restored from a previous state,
|
||||||
String name = makeFragmentName(container.getId(), position);
|
// then we don't need to do anything and should return or else
|
||||||
return getSupportFragmentManager().findFragmentByTag(name);
|
// we could end up with overlapping fragments.
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// http://stackoverflow.com/a/9293207
|
// Create an instance of the fragment
|
||||||
private static String makeFragmentName(int viewId, int index) {
|
mTopFragment = ImportKeysCloudFragment.newInstance(query, disableQueryEdit);
|
||||||
return "android:switcher:" + viewId + ":" + index;
|
|
||||||
|
// Add the fragment to the 'fragment_container' FrameLayout
|
||||||
|
// NOTE: We use commitAllowingStateLoss() to prevent weird crashes!
|
||||||
|
getSupportFragmentManager().beginTransaction()
|
||||||
|
.replace(R.id.import_keys_top_container, mTopFragment)
|
||||||
|
.commitAllowingStateLoss();
|
||||||
|
// do it immediately!
|
||||||
|
getSupportFragmentManager().executePendingTransactions();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isFingerprintValid(String fingerprint) {
|
private boolean isFingerprintValid(String fingerprint) {
|
||||||
@ -385,26 +281,6 @@ public class ImportKeysActivity extends ActionBarActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Scroll ViewPager left and right
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean onTouchEvent(MotionEvent event) {
|
|
||||||
boolean result = super.onTouchEvent(event);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
try {
|
|
||||||
mViewPager.onTouchEvent(event);
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
// workaround for Android bug?
|
|
||||||
// http://stackoverflow.com/q/16459196
|
|
||||||
Log.d(Constants.TAG, "Workaround: Catched IllegalArgumentException");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void loadCallback(ImportKeysListFragment.LoaderState loaderState) {
|
public void loadCallback(ImportKeysListFragment.LoaderState loaderState) {
|
||||||
mListFragment.loadNew(loaderState);
|
mListFragment.loadNew(loaderState);
|
||||||
}
|
}
|
||||||
|
@ -55,11 +55,12 @@ public class ImportKeysCloudFragment extends Fragment {
|
|||||||
/**
|
/**
|
||||||
* Creates new instance of this fragment
|
* Creates new instance of this fragment
|
||||||
*/
|
*/
|
||||||
public static ImportKeysCloudFragment newInstance(String query, String keyserver, boolean doKeyserver, boolean doKeybase) {
|
public static ImportKeysCloudFragment newInstance(String query, boolean disableQueryEdit) {
|
||||||
ImportKeysCloudFragment frag = new ImportKeysCloudFragment();
|
ImportKeysCloudFragment frag = new ImportKeysCloudFragment();
|
||||||
|
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putString(ARG_QUERY, query);
|
args.putString(ARG_QUERY, query);
|
||||||
|
args.putBoolean(ARG_DISABLE_QUERY_EDIT, disableQueryEdit);
|
||||||
|
|
||||||
frag.setArguments(args);
|
frag.setArguments(args);
|
||||||
|
|
||||||
@ -91,11 +92,6 @@ public class ImportKeysCloudFragment extends Fragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
search(mQueryEditText.getText().toString());
|
search(mQueryEditText.getText().toString());
|
||||||
|
|
||||||
// close keyboard after pressing search
|
|
||||||
InputMethodManager imm =
|
|
||||||
(InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
||||||
imm.hideSoftInputFromWindow(mQueryEditText.getWindowToken(), 0);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -132,11 +128,19 @@ public class ImportKeysCloudFragment extends Fragment {
|
|||||||
|
|
||||||
// set displayed values
|
// set displayed values
|
||||||
if (getArguments() != null) {
|
if (getArguments() != null) {
|
||||||
if (getArguments().containsKey(ARG_QUERY)) {
|
|
||||||
String query = getArguments().getString(ARG_QUERY);
|
String query = getArguments().getString(ARG_QUERY);
|
||||||
|
if (query != null) {
|
||||||
mQueryEditText.setText(query, TextView.BufferType.EDITABLE);
|
mQueryEditText.setText(query, TextView.BufferType.EDITABLE);
|
||||||
|
|
||||||
Log.d(Constants.TAG, "query: " + query);
|
Log.d(Constants.TAG, "query: " + query);
|
||||||
|
} else {
|
||||||
|
// open keyboard
|
||||||
|
mQueryEditText.requestFocus();
|
||||||
|
InputMethodManager inputMethodManager = (InputMethodManager)
|
||||||
|
getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
|
if (inputMethodManager != null) {
|
||||||
|
inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getArguments().getBoolean(ARG_DISABLE_QUERY_EDIT, false)) {
|
if (getArguments().getBoolean(ARG_DISABLE_QUERY_EDIT, false)) {
|
||||||
|
@ -1,138 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.Intent;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.support.v4.app.Fragment;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
|
|
||||||
import com.google.zxing.integration.android.IntentResult;
|
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
|
||||||
import org.sufficientlysecure.keychain.R;
|
|
||||||
import org.sufficientlysecure.keychain.util.IntentIntegratorSupportV4;
|
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
|
||||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
public class ImportKeysQrCodeFragment extends Fragment {
|
|
||||||
private ImportKeysActivity mImportActivity;
|
|
||||||
|
|
||||||
private View mNfcButton;
|
|
||||||
private View mQrCodeButton;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates new instance of this fragment
|
|
||||||
*/
|
|
||||||
public static ImportKeysFileFragment newInstance() {
|
|
||||||
ImportKeysFileFragment frag = new ImportKeysFileFragment();
|
|
||||||
|
|
||||||
Bundle args = new Bundle();
|
|
||||||
|
|
||||||
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_qr_code_fragment, container, false);
|
|
||||||
|
|
||||||
mNfcButton = view.findViewById(R.id.import_nfc_button);
|
|
||||||
mNfcButton.setOnClickListener(new View.OnClickListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
// show nfc help
|
|
||||||
Intent intent = new Intent(getActivity(), HelpActivity.class);
|
|
||||||
intent.putExtra(HelpActivity.EXTRA_SELECTED_TAB, HelpActivity.TAB_NFC);
|
|
||||||
startActivityForResult(intent, 0);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
mQrCodeButton = view.findViewById(R.id.import_qrcode_button);
|
|
||||||
|
|
||||||
mQrCodeButton.setOnClickListener(new View.OnClickListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
// scan using xzing's Barcode Scanner
|
|
||||||
new IntentIntegratorSupportV4(ImportKeysQrCodeFragment.this).initiateScan();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAttach(Activity activity) {
|
|
||||||
super.onAttach(activity);
|
|
||||||
|
|
||||||
mImportActivity = (ImportKeysActivity) activity;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
||||||
switch (requestCode & 0xFFFF) {
|
|
||||||
case IntentIntegratorSupportV4.REQUEST_CODE: {
|
|
||||||
IntentResult scanResult = IntentIntegratorSupportV4.parseActivityResult(requestCode,
|
|
||||||
resultCode, data);
|
|
||||||
if (scanResult != null && scanResult.getFormatName() != null) {
|
|
||||||
String scannedContent = scanResult.getContents();
|
|
||||||
|
|
||||||
Log.d(Constants.TAG, "scannedContent: " + scannedContent);
|
|
||||||
|
|
||||||
// look if it's fingerprint only
|
|
||||||
if (scannedContent.toLowerCase(Locale.ENGLISH).startsWith(Constants.FINGERPRINT_SCHEME)) {
|
|
||||||
importFingerprint(Uri.parse(scanResult.getContents()));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// is this a full key encoded as qr code?
|
|
||||||
if (scannedContent.startsWith("-----BEGIN PGP")) {
|
|
||||||
mImportActivity.loadCallback(new ImportKeysListFragment.BytesLoaderState(scannedContent.getBytes(), null));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// fail...
|
|
||||||
Notify.showNotify(getActivity(), R.string.import_qr_code_wrong, Notify.Style.ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void importFingerprint(Uri dataUri) {
|
|
||||||
mImportActivity.loadFromFingerprint(ImportKeysActivity.getFingerprintFromUri(dataUri));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -6,15 +6,11 @@
|
|||||||
|
|
||||||
<include layout="@layout/notify_area" />
|
<include layout="@layout/notify_area" />
|
||||||
|
|
||||||
<org.sufficientlysecure.keychain.ui.widget.SlidingTabLayout
|
<FrameLayout
|
||||||
android:id="@+id/import_sliding_tab_layout"
|
android:id="@+id/import_keys_top_container"
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content" />
|
|
||||||
|
|
||||||
<android.support.v4.view.ViewPager
|
|
||||||
android:id="@+id/import_pager"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="64dp"
|
android:layout_height="64dp"
|
||||||
|
android:orientation="vertical"
|
||||||
android:background="@android:color/white" />
|
android:background="@android:color/white" />
|
||||||
|
|
||||||
<View
|
<View
|
||||||
|
Loading…
x
Reference in New Issue
Block a user