笔锋有两种方案:自己画(计算复杂度高且实现效果差)、笔锋图片(存在重合区域)
消隐有两种方案:笔画结束时整体重画(过度绘制)、笔画结束时增加PorterDuff蒙层
计算手写板大小(全屏和半屏)、构造视图层次结构(Background、Margin)、扩展手写板大小:
/*--------------------------------SogouIME.java----------------------------------*/
Rect frame = new Rect();
mCandidateViewContainer.getWindowVisibleDisplayFrame(frame);
int statusBarHeight = frame.top; //Rect(0, 50, 720, 1280)
//left : 0.005, top : 0.0125, height : 0.83, width : 0.845
HandWritingRect hwRect = mKeyboardView.getKeyboard().getHandWritingRect();
int[] candidateViewContainerInWindow = new int[2]; //(0, 0)
mCandidateViewContainer.getLocationInWindow(candidateViewContainerInWindow);
Rect rect = new Rect();
if (isFullScreen) {
rect.left = 0;
rect.top = getHWWindowTop();
rect.right = mKeyboardView.getWidth();
rect.bottom = candidateViewContainerInWindow[1];
} else {
rect.left = (int)(mKeyboardView.getWidth() * hwRect.left);
rect.top = (int)(mKeyboardView.getKeyboard().getKeyboardRealHeight() * hwRect.top);
rect.right = (rect.left + (int)(mKeyboardView.getKeyboard().getMinWidth() * hwRect.width));
rect.bottom = rect.top + (int)(mKeyboardView.getKeyboard().getKeyboardRealHeight() * hwRect.height);
}
mHWGestureWindow = new HWGestureWindow(getApplicationContext(), mKeyboardView, !isFullScreen, rect, mode);
mHWGestureWindow.setGestureActionListener(mHWGestureListener);
mHWGestureWindow.showGestureWindow();
public int getHWWindowTop() {
int keyboardHeight = mKeyboardView.getHeight(); //230
int candidateHeight = mCandidateViewContainer.getHeight(); //88
Rect frame = calculateTitleBarHeight(); //Rect(0, 50, 720, 1280)
int totalHeight = keyboardHeight + candidateHeight - frame.height(); // totalHeight : -912
return totalHeight;
}
/*--------------------------------HWGestureWindow.java----------------------------------*/
public HWGestureWindow(Context context, View parent, boolean withInKeyboard, Rect viewRect, int mode) {
super(context);
mContext = context;
mParent = parent;
mWithinKeyboard = withInKeyboard;
mViewRect = viewRect;
mMode = mode;
setBackgroundDrawable(null);
setClippingEnabled(false);
mGesturePoints = new short[GESTURE_POINTS_NUM];
initGestureView(mWithinKeyboard);
}
//View hierarchy for fullScreen :
//PopupWindow -- mRootView -- mHwGestureView
//View hierarchy for halfScreen :
//mKeyboardView -- mHandwritingView -- mHwBgLayout -- mModeTextView(下) & mHwGestureView(上)
public void initGestureView(boolean withInKeyboard) {
mDensity = mContext.getResources().getDisplayMetrics().density;
mMinPadding = (int)(2 * mDensity);
mRootView = new RelativeLayout(mContext);
mHWGestureView = new HandWriteView(mContext, withInKeyboard, mViewRect);
if (!withInKeyboard) {
mRootView.addView(mHWGestureView);
setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.bg_color)));
} else {
LayoutInflater inflater = mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mHandWritingView = inflater.inflate(R.layout.hw_half_layout, null);
mModeTextView = (TextView) mHandWritingView.findViewById(R.id.hw_mode_tip);
mTextStyle = KeyboardManager.getInstance(mContext).getTextStyle();
mModeTextView.setTextColor(mTextStyle.color);
String contentText = mContext.getString(R.string.hw_mode_overlap);
mModeTextView.setText(contentText);
mHWBgLayout = mHandWritingView.findViewById(R.id.hw_bg_layout);
// 将mHWGestureView添加到mHWBgLayout中,并设置mHWBgLayout的背景
mHWBg = mKeyboardView.getKeyboard().getHandWritingBG();
mHWBgLayout.addView(mHWGestureView);
mHWBgLayout.setBackgroundDrawable(mHWBg);
// mHWGestureView相对mHWBgLayout的布局信息
mBGPaddingRect = mKeyboardView.getKeyboard().getHandWr