2013-09-18 08:02:37 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 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.
|
|
|
|
*/
|
|
|
|
|
2014-05-14 10:32:00 +00:00
|
|
|
package com.android.inputmethod.keyboard.emoji;
|
2013-09-18 08:02:37 +00:00
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.graphics.Canvas;
|
|
|
|
import android.graphics.Paint;
|
|
|
|
import android.util.AttributeSet;
|
2014-05-16 01:32:04 +00:00
|
|
|
import android.view.View;
|
|
|
|
|
|
|
|
public final class EmojiCategoryPageIndicatorView extends View {
|
2014-05-14 03:35:40 +00:00
|
|
|
private static final float BOTTOM_MARGIN_RATIO = 1.0f;
|
2013-09-18 08:02:37 +00:00
|
|
|
private final Paint mPaint = new Paint();
|
|
|
|
private int mCategoryPageSize = 0;
|
|
|
|
private int mCurrentCategoryPageId = 0;
|
|
|
|
private float mOffset = 0.0f;
|
|
|
|
|
2014-05-16 01:32:04 +00:00
|
|
|
public EmojiCategoryPageIndicatorView(final Context context, final AttributeSet attrs) {
|
2014-05-23 07:04:39 +00:00
|
|
|
this(context, attrs, 0);
|
2013-09-18 08:02:37 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 01:32:04 +00:00
|
|
|
public EmojiCategoryPageIndicatorView(final Context context, final AttributeSet attrs,
|
|
|
|
final int defStyle) {
|
|
|
|
super(context, attrs, defStyle);
|
2014-05-23 07:04:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setColors(final int foregroundColor, final int backgroundColor) {
|
|
|
|
mPaint.setColor(foregroundColor);
|
|
|
|
setBackgroundColor(backgroundColor);
|
2013-09-18 08:02:37 +00:00
|
|
|
}
|
|
|
|
|
2013-12-13 08:09:16 +00:00
|
|
|
public void setCategoryPageId(final int size, final int id, final float offset) {
|
2013-09-18 08:02:37 +00:00
|
|
|
mCategoryPageSize = size;
|
|
|
|
mCurrentCategoryPageId = id;
|
|
|
|
mOffset = offset;
|
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-12-13 08:09:16 +00:00
|
|
|
protected void onDraw(final Canvas canvas) {
|
2013-10-01 07:24:58 +00:00
|
|
|
if (mCategoryPageSize <= 1) {
|
|
|
|
// If the category is not set yet or contains only one category,
|
|
|
|
// just clear and return.
|
2013-09-18 08:02:37 +00:00
|
|
|
canvas.drawColor(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final float height = getHeight();
|
|
|
|
final float width = getWidth();
|
|
|
|
final float unitWidth = width / mCategoryPageSize;
|
|
|
|
final float left = unitWidth * mCurrentCategoryPageId + mOffset * unitWidth;
|
|
|
|
final float top = 0.0f;
|
|
|
|
final float right = left + unitWidth;
|
|
|
|
final float bottom = height * BOTTOM_MARGIN_RATIO;
|
|
|
|
canvas.drawRect(left, top, right, bottom, mPaint);
|
|
|
|
}
|
|
|
|
}
|