Home | History | Annotate | Download | only in keyboard
      1 /*
      2  * Copyright (C) 2013 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.inputmethod.keyboard;
     18 
     19 import com.android.inputmethod.latin.R;
     20 
     21 import android.content.Context;
     22 import android.graphics.Canvas;
     23 import android.graphics.Paint;
     24 import android.util.AttributeSet;
     25 import android.widget.LinearLayout;
     26 
     27 public class EmojiCategoryPageIndicatorView extends LinearLayout {
     28     private static final float BOTTOM_MARGIN_RATIO = 0.66f;
     29     private final Paint mPaint = new Paint();
     30     private int mCategoryPageSize = 0;
     31     private int mCurrentCategoryPageId = 0;
     32     private float mOffset = 0.0f;
     33 
     34     public EmojiCategoryPageIndicatorView(Context context) {
     35         this(context, null /* attrs */);
     36     }
     37 
     38     public EmojiCategoryPageIndicatorView(Context context, AttributeSet attrs) {
     39         super(context, attrs);
     40         mPaint.setColor(context.getResources().getColor(
     41                 R.color.emoji_category_page_id_view_foreground));
     42     }
     43 
     44     public void setCategoryPageId(int size, int id, float offset) {
     45         mCategoryPageSize = size;
     46         mCurrentCategoryPageId = id;
     47         mOffset = offset;
     48         invalidate();
     49     }
     50 
     51     @Override
     52     protected void onDraw(Canvas canvas) {
     53         if (mCategoryPageSize <= 1) {
     54             // If the category is not set yet or contains only one category,
     55             // just clear and return.
     56             canvas.drawColor(0);
     57             return;
     58         }
     59         final float height = getHeight();
     60         final float width = getWidth();
     61         final float unitWidth = width / mCategoryPageSize;
     62         final float left = unitWidth * mCurrentCategoryPageId + mOffset * unitWidth;
     63         final float top = 0.0f;
     64         final float right = left + unitWidth;
     65         final float bottom = height * BOTTOM_MARGIN_RATIO;
     66         canvas.drawRect(left, top, right, bottom, mPaint);
     67     }
     68 }
     69