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

Unified Diff: content/public/android/java/src/org/chromium/content/browser/SPenSupport.java

Issue 428883013: Refactor SPen related code into a separate class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed nits Created 6 years, 4 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
« no previous file with comments | « content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/public/android/java/src/org/chromium/content/browser/SPenSupport.java
diff --git a/content/public/android/java/src/org/chromium/content/browser/SPenSupport.java b/content/public/android/java/src/org/chromium/content/browser/SPenSupport.java
new file mode 100644
index 0000000000000000000000000000000000000000..62fb90c6fcea95734d7bdffe3878bb98eb98b21f
--- /dev/null
+++ b/content/public/android/java/src/org/chromium/content/browser/SPenSupport.java
@@ -0,0 +1,70 @@
+// Copyright 2014 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;
+
+import android.content.Context;
+import android.content.pm.FeatureInfo;
+import android.os.Build;
+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;
+ private static final int SPEN_ACTION_MOVE = 213;
+ private static final int SPEN_ACTION_CANCEL = 214;
+ private static Boolean sIsSPenSupported;
+
+ /**
+ * @return Whether SPen is supported on the device.
+ */
+ public static boolean isSPenSupported(Context context) {
+ if (sIsSPenSupported == null) {
+ sIsSPenSupported = detectSPenSupport(context);
+ }
+ return sIsSPenSupported.booleanValue();
+ }
+
+ private static boolean detectSPenSupport(Context context) {
+ if (!"SAMSUNG".equalsIgnoreCase(Build.MANUFACTURER)) {
+ return false;
+ }
+
+ final FeatureInfo[] infos = context.getPackageManager().getSystemAvailableFeatures();
+ for (FeatureInfo info : infos) {
+ if ("com.sec.feature.spen_usp".equalsIgnoreCase(info.name)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Convert SPen event action into normal event action.
+ *
+ * @param eventActionMasked Input event action. It is assumed that it is masked as the values
+ cannot be ORed.
+ * @return Event action after the conversion.
+ */
+ public static int convertSPenEventAction(int eventActionMasked) {
+ // S-Pen support: convert to normal stylus event handling
+ switch (eventActionMasked) {
+ case SPEN_ACTION_DOWN:
+ return MotionEvent.ACTION_DOWN;
+ case SPEN_ACTION_UP:
+ return MotionEvent.ACTION_UP;
+ case SPEN_ACTION_MOVE:
+ return MotionEvent.ACTION_MOVE;
+ case SPEN_ACTION_CANCEL:
+ return MotionEvent.ACTION_CANCEL;
+ default:
+ return eventActionMasked;
+ }
+ }
+}
« no previous file with comments | « content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698