Commit 6827a944 authored by changwan@chromium.org's avatar changwan@chromium.org

Refactor SPen related code into a separate class

BUG=398169

Review URL: https://codereview.chromium.org/428883013

Cr-Commit-Position: refs/heads/master@{#288363}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288363 0039d316-1c4b-4281-b951-d872f2087c98
parent 6114502e
......@@ -1203,8 +1203,8 @@ public class ContentViewCore
cancelRequestToScrollFocusedEditableNodeIntoView();
}
if (isSPenSupported(mContext))
eventAction = convertSPenEventAction(eventAction);
if (SPenSupport.isSPenSupported(mContext))
eventAction = SPenSupport.convertSPenEventAction(eventAction);
if (!isValidTouchEventActionForNative(eventAction)) return false;
if (mNativeContentViewCore == 0) return false;
......
// 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;
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment