Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(204)

Unified Diff: ui/android/java/src/org/chromium/ui/base/SPenSupport.java

Issue 2708613002: Add EventForwarder for routing touch events (Closed)
Patch Set: unittests Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/android/java/src/org/chromium/ui/base/SPenSupport.java
diff --git a/content/public/android/java/src/org/chromium/content/browser/SPenSupport.java b/ui/android/java/src/org/chromium/ui/base/SPenSupport.java
similarity index 72%
rename from content/public/android/java/src/org/chromium/content/browser/SPenSupport.java
rename to ui/android/java/src/org/chromium/ui/base/SPenSupport.java
index 62fb90c6fcea95734d7bdffe3878bb98eb98b21f..228958262c2bea8ebce88de6b36636ef52bd2892 100644
--- a/content/public/android/java/src/org/chromium/content/browser/SPenSupport.java
+++ b/ui/android/java/src/org/chromium/ui/base/SPenSupport.java
@@ -1,8 +1,8 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-package org.chromium.content.browser;
+package org.chromium.ui.base;
import android.content.Context;
import android.content.pm.FeatureInfo;
@@ -13,7 +13,6 @@ import android.view.MotionEvent;
* Support S-Pen event detection and conversion.
*/
public final class SPenSupport {
-
// These values are obtained from Samsung.
private static final int SPEN_ACTION_DOWN = 211;
private static final int SPEN_ACTION_UP = 212;
@@ -22,27 +21,28 @@ public final class SPenSupport {
private static Boolean sIsSPenSupported;
/**
- * @return Whether SPen is supported on the device.
+ * Initialize SPen support. The detection of the SPen should come before calling
+ * {@link #convertSPenEventAction(int)}.
+ * TODO(jinsukkim): Do this lazily.
+ *
+ * @param context {@link Context} object.
*/
- public static boolean isSPenSupported(Context context) {
- if (sIsSPenSupported == null) {
- sIsSPenSupported = detectSPenSupport(context);
- }
- return sIsSPenSupported.booleanValue();
- }
+ public static void detect(Context context) {
boliu 2017/03/02 20:58:14 you can just use ContextUtils.getApplicationContex
Khushal 2017/03/02 21:46:15 nit: initialize sounds better.
Jinsuk Kim 2017/03/03 06:29:21 Done.
Jinsuk Kim 2017/03/03 06:29:21 Ah. that was what I was looking for. Turned this t
+ if (sIsSPenSupported != null) return;
- private static boolean detectSPenSupport(Context context) {
if (!"SAMSUNG".equalsIgnoreCase(Build.MANUFACTURER)) {
- return false;
+ sIsSPenSupported = false;
+ return;
}
final FeatureInfo[] infos = context.getPackageManager().getSystemAvailableFeatures();
for (FeatureInfo info : infos) {
if ("com.sec.feature.spen_usp".equalsIgnoreCase(info.name)) {
- return true;
+ sIsSPenSupported = true;
+ return;
}
}
- return false;
+ sIsSPenSupported = false;
}
/**
@@ -53,6 +53,9 @@ public final class SPenSupport {
* @return Event action after the conversion.
*/
public static int convertSPenEventAction(int eventActionMasked) {
+ assert sIsSPenSupported != null;
+ if (!sIsSPenSupported.booleanValue()) return eventActionMasked;
+
// S-Pen support: convert to normal stylus event handling
switch (eventActionMasked) {
case SPEN_ACTION_DOWN:

Powered by Google App Engine
This is Rietveld 408576698