]> gitweb.fperrin.net Git - Dictionary.git/commitdiff
Some improvements to keyboard navigation.
authorReimar Döffinger <Reimar.Doeffinger@gmx.de>
Sun, 13 Nov 2016 19:09:19 +0000 (20:09 +0100)
committerReimar Döffinger <Reimar.Doeffinger@gmx.de>
Sun, 13 Nov 2016 19:09:19 +0000 (20:09 +0100)
res/layout/dictionary_activity.xml
res/layout/dictionary_manager_header_row_on_device.xml
res/values/ids.xml [new file with mode: 0644]
src/com/hughes/android/dictionary/DictionaryActivity.java
src/com/hughes/android/dictionary/DictionaryManagerActivity.java

index 3e381371e68176e0a98681b7c22fb2fc313cad0f..5e88bd7f6b1e79fe8c36ec9d6ffdd8a412a6cdd0 100644 (file)
@@ -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" />
 
index 45776856faa13d17765ab47fd3d62afa9b5ff15a..35ba68edc68bae3db8c206c1571c680c7be409ee 100644 (file)
@@ -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" />
 
-</LinearLayout>
\ No newline at end of file
+</LinearLayout>
diff --git a/res/values/ids.xml b/res/values/ids.xml
new file mode 100644 (file)
index 0000000..587f875
--- /dev/null
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <item name="searchView" type="id" />
+    <item name="languageButton" type="id" />
+</resources>
index 0a301eaf7d32598b98668458b3ea309401356467..d2b4a923623fa4534151baca54ce25655b220604 100644 (file)
@@ -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) {
index df9ab93be23fbae0c9b8f8d29f13ca234c30514c..91d603043f342fcbf7e9f3be2676ef7786edde11 100644 (file)
@@ -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);