LatinIME/java/src/com/android/inputmethod/keyboard/internal/PreviewPlacerView.java
Ken Wakasa 52876bbefd Remove unnecessary setLayerType() calls
Calling up setLayerType(LAYER_TYPE_HARDWARE, ..) on non-HW accelerated
devices was ending up with having a drawing cache in View that is not
quite needed for PreviewPlacerView.

bug: 8967766

Change-Id: Ic8e6eeaf536530ff5f23eb353b0a8e5ba96fa0e2
2013-08-02 19:30:05 +09:00

83 lines
2.9 KiB
Java

/*
* 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;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.util.AttributeSet;
import android.widget.RelativeLayout;
import com.android.inputmethod.latin.utils.CollectionUtils;
import com.android.inputmethod.latin.utils.CoordinateUtils;
import java.util.ArrayList;
public final class PreviewPlacerView extends RelativeLayout {
private final int[] mKeyboardViewOrigin = CoordinateUtils.newInstance();
private final ArrayList<AbstractDrawingPreview> mPreviews = CollectionUtils.newArrayList();
public PreviewPlacerView(final Context context, final AttributeSet attrs) {
super(context, attrs);
setWillNotDraw(false);
}
public void setHardwareAcceleratedDrawingEnabled(final boolean enabled) {
if (!enabled) return;
final Paint layerPaint = new Paint();
layerPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));
setLayerType(LAYER_TYPE_HARDWARE, layerPaint);
}
public void addPreview(final AbstractDrawingPreview preview) {
mPreviews.add(preview);
}
public void setKeyboardViewGeometry(final int[] originCoords, final int width,
final int height) {
CoordinateUtils.copy(mKeyboardViewOrigin, originCoords);
final int count = mPreviews.size();
for (int i = 0; i < count; i++) {
mPreviews.get(i).setKeyboardGeometry(originCoords, width, height);
}
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
final int count = mPreviews.size();
for (int i = 0; i < count; i++) {
mPreviews.get(i).onDetachFromWindow();
}
}
@Override
public void onDraw(final Canvas canvas) {
super.onDraw(canvas);
final int originX = CoordinateUtils.x(mKeyboardViewOrigin);
final int originY = CoordinateUtils.y(mKeyboardViewOrigin);
canvas.translate(originX, originY);
final int count = mPreviews.size();
for (int i = 0; i < count; i++) {
mPreviews.get(i).drawPreview(canvas);
}
canvas.translate(-originX, -originY);
}
}