Use config_screen_metrics resource in BogusMoveEventDetector

Change-Id: I6b957b43c6dd7ce4f639e46d248179662c1ee669
This commit is contained in:
Tadashi G. Takaoka 2013-12-20 16:43:15 +09:00
parent db6d9b0ab4
commit 9c4de1e5f7
6 changed files with 25 additions and 36 deletions

View File

@ -19,11 +19,6 @@
-->
<resources>
<!-- Screen metrics for logging.
0 = "small phone screen"
1 = "large phone screen"
2 = "large tablet screen"
3 = "small tablet screen"
-->
<integer name="log_screen_metrics">1</integer>
<!-- Must be aligned with {@link Constants#SCREEN_METRICS_LARGE_PHONE}. -->
<integer name="config_screen_metrics">1</integer>
</resources>

View File

@ -19,11 +19,6 @@
-->
<resources>
<!-- Screen metrics for logging.
0 = "small phone screen"
1 = "large phone screen"
2 = "large tablet screen"
3 = "small tablet screen"
-->
<integer name="log_screen_metrics">3</integer>
<!-- Must be aligned with {@link Constants#SCREEN_METRICS_SMALL_TABLET}. -->
<integer name="config_screen_metrics">3</integer>
</resources>

View File

@ -19,11 +19,6 @@
-->
<resources>
<!-- Screen metrics for logging.
0 = "small phone screen"
1 = "large phone screen"
2 = "large tablet screen"
3 = "small tablet screen"
-->
<integer name="log_screen_metrics">2</integer>
<!-- Must be aligned with {@link Constants#SCREEN_METRICS_LARGE_TABLET}. -->
<integer name="config_screen_metrics">2</integer>
</resources>

View File

@ -19,11 +19,6 @@
-->
<resources>
<!-- Screen metrics for logging.
0 = "small phone screen"
1 = "large phone screen"
2 = "large tablet screen"
3 = "small tablet screen"
-->
<integer name="log_screen_metrics">0</integer>
<!-- Must be aligned with {@link Constants#SCREEN_METRICS_SMALL_PHONE}. -->
<integer name="config_screen_metrics">0</integer>
</resources>

View File

@ -20,7 +20,9 @@ import android.content.res.Resources;
import android.util.DisplayMetrics;
import android.util.Log;
import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.R;
// This hack is applied to certain classes of tablets.
public final class BogusMoveEventDetector {
@ -32,9 +34,6 @@ public final class BogusMoveEventDetector {
private static final float BOGUS_MOVE_ACCUMULATED_DISTANCE_THRESHOLD = 0.53f;
private static final float BOGUS_MOVE_RADIUS_THRESHOLD = 1.14f;
private static final int SMALL_TABLET_SMALLEST_WIDTH = 600; // dp
private static final int LARGE_TABLET_SMALLEST_WIDTH = 768; // dp
private static boolean sNeedsProximateBogusDownMoveUpEventHack;
public static void init(final Resources res) {
@ -43,16 +42,17 @@ public final class BogusMoveEventDetector {
// Though it seems odd to use screen density as criteria of the quality of the touch
// screen, the small table that has a less density screen than hdpi most likely has been
// made with the touch screen that needs the hack.
final int sw = res.getConfiguration().smallestScreenWidthDp;
final boolean isLargeTablet = (sw >= LARGE_TABLET_SMALLEST_WIDTH);
final boolean isSmallTablet =
(sw >= SMALL_TABLET_SMALLEST_WIDTH && sw < LARGE_TABLET_SMALLEST_WIDTH);
final int screenMetrics = res.getInteger(R.integer.config_screen_metrics);
final boolean isLargeTablet = (screenMetrics == Constants.SCREEN_METRICS_LARGE_TABLET);
final boolean isSmallTablet = (screenMetrics == Constants.SCREEN_METRICS_SMALL_TABLET);
final int densityDpi = res.getDisplayMetrics().densityDpi;
final boolean hasLowDensityScreen = (densityDpi < DisplayMetrics.DENSITY_HIGH);
final boolean needsTheHack = isLargeTablet || (isSmallTablet && hasLowDensityScreen);
if (DEBUG_MODE) {
final int sw = res.getConfiguration().smallestScreenWidthDp;
Log.d(TAG, "needsProximateBogusDownMoveUpEventHack=" + needsTheHack
+ " smallestScreenWidthDp=" + sw + " densityDpi=" + densityDpi);
+ " smallestScreenWidthDp=" + sw + " densityDpi=" + densityDpi
+ " screenMetrics=" + screenMetrics);
}
sNeedsProximateBogusDownMoveUpEventHack = needsTheHack;
}

View File

@ -248,6 +248,15 @@ public final class Constants {
public static final int MAX_INT_BIT_COUNT = 32;
/**
* Screen metrics (a.k.a. Device form factor) constants of
* {@link R.integer#config_screen_metrics}.
*/
public static final int SCREEN_METRICS_SMALL_PHONE = 0;
public static final int SCREEN_METRICS_LARGE_PHONE = 1;
public static final int SCREEN_METRICS_LARGE_TABLET = 2;
public static final int SCREEN_METRICS_SMALL_TABLET = 3;
private Constants() {
// This utility class is not publicly instantiable.
}