From: Reimar Döffinger Date: Sun, 13 Nov 2016 19:09:19 +0000 (+0100) Subject: Some improvements to keyboard navigation. X-Git-Url: http://gitweb.fperrin.net/?p=Dictionary.git;a=commitdiff_plain;h=e3a434becb9cc5e8bfa912a5241b66b6a24b65d1 Some improvements to keyboard navigation. --- diff --git a/res/layout/dictionary_activity.xml b/res/layout/dictionary_activity.xml index 3e38137..5e88bd7 100644 --- a/res/layout/dictionary_activity.xml +++ b/res/layout/dictionary_activity.xml @@ -43,6 +43,7 @@ android:id="@id/android:list" android:layout_width="fill_parent" android:layout_height="fill_parent" + android:nextFocusRight="@+id/floatSearchButton" android:choiceMode="singleChoice" android:clickable="true" android:fastScrollEnabled="true" @@ -71,6 +72,7 @@ android:layout_alignParentBottom="true" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:nextFocusLeft="@id/android:list" android:onClick="onSearchButtonClick" android:src="@drawable/ic_search_black_24dp" /> diff --git a/res/layout/dictionary_manager_header_row_on_device.xml b/res/layout/dictionary_manager_header_row_on_device.xml index 4577685..35ba68e 100644 --- a/res/layout/dictionary_manager_header_row_on_device.xml +++ b/res/layout/dictionary_manager_header_row_on_device.xml @@ -3,6 +3,7 @@ android:id="@+id/onDeviceHeaderLayout" android:layout_width="match_parent" android:layout_height="wrap_content" + android:focusable="false" android:background="@color/gray" android:orientation="horizontal" android:padding="10dip"> @@ -12,7 +13,8 @@ android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="1" + android:focusable="false" android:text="@string/dictionariesOnDevice" android:textAppearance="?android:attr/textAppearanceLarge" /> - \ No newline at end of file + diff --git a/res/values/ids.xml b/res/values/ids.xml new file mode 100644 index 0000000..587f875 --- /dev/null +++ b/res/values/ids.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/src/com/hughes/android/dictionary/DictionaryActivity.java b/src/com/hughes/android/dictionary/DictionaryActivity.java index 0a301ea..d2b4a92 100644 --- a/src/com/hughes/android/dictionary/DictionaryActivity.java +++ b/src/com/hughes/android/dictionary/DictionaryActivity.java @@ -20,6 +20,7 @@ import android.app.SearchManager; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.content.pm.PackageManager; import android.graphics.Color; import android.graphics.Typeface; import android.net.Uri; @@ -497,7 +498,7 @@ public class DictionaryActivity extends ActionBarActivity { saveOnlyFirstSubentry = prefs.getBoolean(getString(R.string.saveOnlyFirstSubentryKey), false); clickOpensContextMenu = prefs.getBoolean(getString(R.string.clickOpensContextMenuKey), - false); + !getPackageManager().hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN)); Log.d(LOG, "wordList=" + wordList + ", saveOnlyFirstSubentry=" + saveOnlyFirstSubentry); onCreateSetupActionBarAndSearchView(); @@ -551,6 +552,7 @@ public class DictionaryActivity extends ActionBarActivity { }); languageButton = new ImageButton(customSearchView.getContext()); + languageButton.setId(R.id.languageButton); languageButton.setScaleType(ScaleType.FIT_CENTER); languageButton.setOnClickListener(new OnClickListener() { @Override @@ -563,6 +565,7 @@ public class DictionaryActivity extends ActionBarActivity { customSearchView.addView(languageButton, lpb); searchView = new SearchView(getSupportActionBar().getThemedContext()); + searchView.setId(R.id.searchView); // Get rid of search icon, it takes up too much space. // There is still text saying "search" in the search field. @@ -605,6 +608,10 @@ public class DictionaryActivity extends ActionBarActivity { // Avoid wasting space on large left inset Toolbar tb = (Toolbar)customSearchView.getParent(); tb.setContentInsetsRelative(0, 0); + + getListView().setNextFocusLeftId(R.id.searchView); + findViewById(R.id.floatSwapButton).setNextFocusRightId(R.id.languageButton); + languageButton.setNextFocusLeftId(R.id.floatSwapButton); } @Override @@ -787,6 +794,7 @@ public class DictionaryActivity extends ActionBarActivity { button.setOnClickListener(intentLauncher); listView.addHeaderView(button); + listView.setItemsCanFocus(true); listView.setAdapter(new BaseAdapter() { @Override public View getView(int position, View convertView, ViewGroup parent) { diff --git a/src/com/hughes/android/dictionary/DictionaryManagerActivity.java b/src/com/hughes/android/dictionary/DictionaryManagerActivity.java index df9ab93..91d6030 100644 --- a/src/com/hughes/android/dictionary/DictionaryManagerActivity.java +++ b/src/com/hughes/android/dictionary/DictionaryManagerActivity.java @@ -324,6 +324,7 @@ public class DictionaryManagerActivity extends ActionBarActivity { setMyListAdapater(); registerForContextMenu(getListView()); + getListView().setItemsCanFocus(true); readableCheckAndError(true); @@ -657,6 +658,7 @@ public class DictionaryManagerActivity extends ActionBarActivity { } else { button.setEnabled(false); + button.setFocusable(false); } if (builder.length() != 0) { builder.append("; "); @@ -680,7 +682,8 @@ public class DictionaryManagerActivity extends ActionBarActivity { DictionaryActivity.getLaunchIntent(getApplicationContext(), application.getPath(dictionaryInfo.uncompressedFilename), dictionaryInfo.indexInfos.get(0).shortName, ""))); - row.setFocusable(true); + // do not setFocusable, for keyboard navigation + // offering only the index buttons is better. row.setLongClickable(true); } row.setBackgroundResource(android.R.drawable.menuitem_background);