Fixing fingerprint search, part 1

This commit is contained in:
Dominik Schürmann 2014-06-19 01:26:21 +02:00
parent 47edcacf61
commit 3d8e6b303c

View File

@ -123,72 +123,13 @@ public class ImportKeysActivity extends ActionBarActivity {
mNavigationStrings = getResources().getStringArray(R.array.import_action_list); mNavigationStrings = getResources().getStringArray(R.array.import_action_list);
if (ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN.equals(getIntent().getAction())) { // TODO: add actionbar button for this action?
setTitle(R.string.nav_import); // if (ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN.equals(getIntent().getAction())) {
} else { // }
initTabs();
}
handleActions(savedInstanceState, getIntent()); handleActions(savedInstanceState, getIntent());
} }
private void initTabs() {
mTabsAdapter = new PagerTabStripAdapter(this);
mViewPager.setAdapter(mTabsAdapter);
mSlidingTabLayout.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
// resize view pager back to 64 if keyserver settings have been collapsed
if (getViewPagerHeight() > VIEW_PAGER_HEIGHT) {
resizeViewPager(VIEW_PAGER_HEIGHT);
}
}
@Override
public void onPageSelected(int position) {
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
Bundle serverBundle = new Bundle();
// serverBundle.putParcelable(ViewKeyMainFragment.ARG_DATA_URI, dataUri);
mTabsAdapter.addTab(ImportKeysServerFragment.class,
serverBundle, getString(R.string.import_tab_keyserver));
Bundle qrCodeBundle = new Bundle();
// importBundle.putParcelable(ViewKeyMainFragment.ARG_DATA_URI, dataUri);
mTabsAdapter.addTab(ImportKeysQrCodeFragment.class,
qrCodeBundle, getString(R.string.import_tab_qr_code));
Bundle fileBundle = new Bundle();
// importBundle.putParcelable(ViewKeyMainFragment.ARG_DATA_URI, dataUri);
mTabsAdapter.addTab(ImportKeysFileFragment.class,
fileBundle, getString(R.string.import_tab_direct));
Bundle keybaseBundle = new Bundle();
// keybaseBundle.putParcelable(ViewKeyMainFragment.ARG_DATA_URI, dataUri);
mTabsAdapter.addTab(ImportKeysKeybaseFragment.class,
keybaseBundle, getString(R.string.import_tab_keybase));
// update layout after operations
mSlidingTabLayout.setViewPager(mViewPager);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
boolean result = super.onTouchEvent(event);
if (!result) {
mViewPager.onTouchEvent(event);
}
return result;
}
protected void handleActions(Bundle savedInstanceState, Intent intent) { protected void handleActions(Bundle savedInstanceState, Intent intent) {
String action = intent.getAction(); String action = intent.getAction();
Bundle extras = intent.getExtras(); Bundle extras = intent.getExtras();
@ -205,6 +146,8 @@ public class ImportKeysActivity extends ActionBarActivity {
action = ACTION_IMPORT_KEY; action = ACTION_IMPORT_KEY;
} }
Bundle serverBundle = null;
boolean serverOnly = false;
if (scheme != null && scheme.toLowerCase(Locale.ENGLISH).equals(Constants.FINGERPRINT_SCHEME)) { if (scheme != null && scheme.toLowerCase(Locale.ENGLISH).equals(Constants.FINGERPRINT_SCHEME)) {
/* Scanning a fingerprint directly with Barcode Scanner */ /* Scanning a fingerprint directly with Barcode Scanner */
loadFromFingerprintUri(savedInstanceState, dataUri); loadFromFingerprintUri(savedInstanceState, dataUri);
@ -245,10 +188,8 @@ 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
Bundle args = new Bundle(); serverBundle = new Bundle();
args.putString(ImportKeysServerFragment.ARG_QUERY, query); serverBundle.putString(ImportKeysServerFragment.ARG_QUERY, query);
// loadNavFragment(NAV_SERVER, args);
//TODO: load afterwards!
mSwitchToTab = NAV_SERVER; mSwitchToTab = NAV_SERVER;
// action: search immediately // action: search immediately
@ -264,7 +205,19 @@ public class ImportKeysActivity extends ActionBarActivity {
*/ */
String fingerprint = intent.getStringExtra(EXTRA_FINGERPRINT); String fingerprint = intent.getStringExtra(EXTRA_FINGERPRINT);
loadFromFingerprint(savedInstanceState, fingerprint); if (isFingerprintValid(fingerprint)) {
String query = "0x" + fingerprint;
// display keyserver fragment with query
serverBundle = new Bundle();
serverBundle.putString(ImportKeysServerFragment.ARG_QUERY, query);
serverBundle.putBoolean(ImportKeysServerFragment.ARG_DISABLE_QUERY_EDIT, true);
serverOnly = true;
mSwitchToTab = NAV_SERVER;
// action: search immediately
startListFragment(savedInstanceState, null, null, query);
}
} else { } else {
Log.e(Constants.TAG, Log.e(Constants.TAG,
"IMPORT_KEY_FROM_KEYSERVER action needs to contain the 'query', 'key_id', or " + "IMPORT_KEY_FROM_KEYSERVER action needs to contain the 'query', 'key_id', or " +
@ -303,6 +256,44 @@ public class ImportKeysActivity extends ActionBarActivity {
startListFragment(savedInstanceState, null, null, null); startListFragment(savedInstanceState, null, null, null);
} }
initTabs(serverBundle, serverOnly);
}
private void initTabs(Bundle serverBundle, boolean serverOnly) {
mTabsAdapter = new PagerTabStripAdapter(this);
mViewPager.setAdapter(mTabsAdapter);
mSlidingTabLayout.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
// resize view pager back to 64 if keyserver settings have been collapsed
if (getViewPagerHeight() > VIEW_PAGER_HEIGHT) {
resizeViewPager(VIEW_PAGER_HEIGHT);
}
}
@Override
public void onPageSelected(int position) {
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
mTabsAdapter.addTab(ImportKeysServerFragment.class,
serverBundle, getString(R.string.import_tab_keyserver));
if (!serverOnly) {
mTabsAdapter.addTab(ImportKeysQrCodeFragment.class,
null, getString(R.string.import_tab_qr_code));
mTabsAdapter.addTab(ImportKeysFileFragment.class,
null, getString(R.string.import_tab_direct));
mTabsAdapter.addTab(ImportKeysKeybaseFragment.class,
null, getString(R.string.import_tab_keybase));
}
// update layout after operations
mSlidingTabLayout.setViewPager(mViewPager);
mViewPager.setCurrentItem(mSwitchToTab); mViewPager.setCurrentItem(mSwitchToTab);
} }
@ -343,31 +334,48 @@ public class ImportKeysActivity extends ActionBarActivity {
Log.d(Constants.TAG, "fingerprint: " + fingerprint); Log.d(Constants.TAG, "fingerprint: " + fingerprint);
loadFromFingerprint(savedInstanceState, fingerprint); // TODO: reload fragment when coming from qr code!
// loadFromFingerprint(savedInstanceState, fingerprint);
// 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;
} }
public void loadFromFingerprint(Bundle savedInstanceState, String fingerprint) { private boolean isFingerprintValid(String fingerprint) {
if (fingerprint == null || fingerprint.length() < 40) { if (fingerprint == null || fingerprint.length() < 40) {
SuperCardToast toast = SuperCardToast.create(this, SuperCardToast toast = SuperCardToast.create(this,
getString(R.string.import_qr_code_too_short_fingerprint), getString(R.string.import_qr_code_too_short_fingerprint),
SuperToast.Duration.LONG); SuperToast.Duration.LONG);
toast.setBackground(SuperToast.Background.RED); toast.setBackground(SuperToast.Background.RED);
toast.show(); toast.show();
return; return false;
} else {
return true;
}
} }
String query = "0x" + fingerprint; /**
* Scroll ViewPager left and right
*
* @param event
* @return
*/
@Override
public boolean onTouchEvent(MotionEvent event) {
boolean result = super.onTouchEvent(event);
// display keyserver fragment with query if (!result) {
Bundle args = new Bundle(); mViewPager.onTouchEvent(event);
args.putString(ImportKeysServerFragment.ARG_QUERY, query); }
args.putBoolean(ImportKeysServerFragment.ARG_DISABLE_QUERY_EDIT, true);
// loadNavFragment(NAV_SERVER, args);
//TODO return result;
// action: search directly
startListFragment(savedInstanceState, null, null, query);
} }
public void loadCallback(ImportKeysListFragment.LoaderState loaderState) { public void loadCallback(ImportKeysListFragment.LoaderState loaderState) {