2012-07-20 12:01:44 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.android.inputmethod.keyboard.internal;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.graphics.Canvas;
|
|
|
|
import android.graphics.Paint;
|
2012-09-06 03:12:10 +00:00
|
|
|
import android.graphics.PorterDuff;
|
|
|
|
import android.graphics.PorterDuffXfermode;
|
2012-08-20 02:24:16 +00:00
|
|
|
import android.util.AttributeSet;
|
2012-07-20 12:01:44 +00:00
|
|
|
import android.widget.RelativeLayout;
|
|
|
|
|
2013-06-23 16:11:32 +00:00
|
|
|
import com.android.inputmethod.latin.utils.CollectionUtils;
|
|
|
|
import com.android.inputmethod.latin.utils.CoordinateUtils;
|
2013-01-21 10:17:17 +00:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2012-07-20 12:01:44 +00:00
|
|
|
|
2012-09-27 09:16:16 +00:00
|
|
|
public final class PreviewPlacerView extends RelativeLayout {
|
2012-11-28 06:24:13 +00:00
|
|
|
private final int[] mKeyboardViewOrigin = CoordinateUtils.newInstance();
|
2012-07-20 12:01:44 +00:00
|
|
|
|
2013-01-21 10:17:17 +00:00
|
|
|
private final ArrayList<AbstractDrawingPreview> mPreviews = CollectionUtils.newArrayList();
|
2012-11-28 06:24:13 +00:00
|
|
|
|
2012-08-20 03:57:34 +00:00
|
|
|
public PreviewPlacerView(final Context context, final AttributeSet attrs) {
|
2013-01-21 10:17:17 +00:00
|
|
|
super(context, attrs);
|
2012-07-20 12:01:44 +00:00
|
|
|
setWillNotDraw(false);
|
2013-08-01 15:25:05 +00:00
|
|
|
}
|
2012-07-20 12:01:44 +00:00
|
|
|
|
2013-08-01 15:25:05 +00:00
|
|
|
public void setHardwareAcceleratedDrawingEnabled(final boolean enabled) {
|
|
|
|
if (!enabled) return;
|
2012-09-06 03:12:10 +00:00
|
|
|
final Paint layerPaint = new Paint();
|
|
|
|
layerPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));
|
|
|
|
setLayerType(LAYER_TYPE_HARDWARE, layerPaint);
|
2012-07-20 12:01:44 +00:00
|
|
|
}
|
|
|
|
|
2013-01-21 10:17:17 +00:00
|
|
|
public void addPreview(final AbstractDrawingPreview preview) {
|
|
|
|
mPreviews.add(preview);
|
|
|
|
}
|
|
|
|
|
2013-01-21 09:36:34 +00:00
|
|
|
public void setKeyboardViewGeometry(final int[] originCoords, final int width,
|
|
|
|
final int height) {
|
2012-11-28 06:24:13 +00:00
|
|
|
CoordinateUtils.copy(mKeyboardViewOrigin, originCoords);
|
2013-01-21 10:17:17 +00:00
|
|
|
final int count = mPreviews.size();
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
mPreviews.get(i).setKeyboardGeometry(originCoords, width, height);
|
|
|
|
}
|
2012-12-04 07:04:21 +00:00
|
|
|
}
|
|
|
|
|
2012-09-12 07:28:54 +00:00
|
|
|
@Override
|
|
|
|
protected void onDetachedFromWindow() {
|
2013-01-21 10:31:05 +00:00
|
|
|
super.onDetachedFromWindow();
|
2013-01-21 10:17:17 +00:00
|
|
|
final int count = mPreviews.size();
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
mPreviews.get(i).onDetachFromWindow();
|
|
|
|
}
|
2012-09-26 06:49:23 +00:00
|
|
|
}
|
|
|
|
|
2012-07-20 12:01:44 +00:00
|
|
|
@Override
|
2012-08-20 03:57:34 +00:00
|
|
|
public void onDraw(final Canvas canvas) {
|
2012-07-20 12:01:44 +00:00
|
|
|
super.onDraw(canvas);
|
2012-11-28 06:24:13 +00:00
|
|
|
final int originX = CoordinateUtils.x(mKeyboardViewOrigin);
|
|
|
|
final int originY = CoordinateUtils.y(mKeyboardViewOrigin);
|
2012-12-19 21:01:57 +00:00
|
|
|
canvas.translate(originX, originY);
|
2013-01-21 10:17:17 +00:00
|
|
|
final int count = mPreviews.size();
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
mPreviews.get(i).drawPreview(canvas);
|
|
|
|
}
|
2012-12-19 21:01:57 +00:00
|
|
|
canvas.translate(-originX, -originY);
|
2012-09-26 06:49:23 +00:00
|
|
|
}
|
2012-07-20 12:01:44 +00:00
|
|
|
}
|