Home | History | Annotate | Download | only in date
      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.datetimepicker.date;
     18 
     19 import android.content.Context;
     20 import android.content.res.Resources;
     21 import android.graphics.Canvas;
     22 import android.graphics.Paint;
     23 import android.graphics.Paint.Align;
     24 import android.graphics.Paint.Style;
     25 import android.util.AttributeSet;
     26 import android.widget.TextView;
     27 
     28 import com.android.datetimepicker.R;
     29 
     30 /**
     31  * A text view which, when pressed or activated, displays a blue circle around the text.
     32  *
     33  * @deprecated This module is deprecated. Do not use this class.
     34  */
     35 @Deprecated
     36 public class TextViewWithCircularIndicator extends TextView {
     37 
     38     private static final int SELECTED_CIRCLE_ALPHA = 60;
     39 
     40     Paint mCirclePaint = new Paint();
     41 
     42     private final int mRadius;
     43     private final int mCircleColor;
     44     private final String mItemIsSelectedText;
     45 
     46     private boolean mDrawCircle;
     47 
     48     public TextViewWithCircularIndicator(Context context, AttributeSet attrs) {
     49         super(context, attrs);
     50         Resources res = context.getResources();
     51         mCircleColor = res.getColor(R.color.blue);
     52         mRadius = res.getDimensionPixelOffset(R.dimen.month_select_circle_radius);
     53         mItemIsSelectedText = context.getResources().getString(R.string.item_is_selected);
     54 
     55         init();
     56     }
     57 
     58     private void init() {
     59         mCirclePaint.setFakeBoldText(true);
     60         mCirclePaint.setAntiAlias(true);
     61         mCirclePaint.setColor(mCircleColor);
     62         mCirclePaint.setTextAlign(Align.CENTER);
     63         mCirclePaint.setStyle(Style.FILL);
     64         mCirclePaint.setAlpha(SELECTED_CIRCLE_ALPHA);
     65     }
     66 
     67     public void drawIndicator(boolean drawCircle) {
     68         mDrawCircle = drawCircle;
     69     }
     70 
     71     @Override
     72     public void onDraw(Canvas canvas) {
     73         super.onDraw(canvas);
     74         if (mDrawCircle) {
     75             final int width = getWidth();
     76             final int height = getHeight();
     77             int radius = Math.min(width, height) / 2;
     78             canvas.drawCircle(width / 2, height / 2, radius, mCirclePaint);
     79         }
     80     }
     81 
     82     @Override
     83     public CharSequence getContentDescription() {
     84         CharSequence itemText = getText();
     85         if (mDrawCircle) {
     86             return String.format(mItemIsSelectedText, itemText);
     87         } else {
     88             return itemText;
     89         }
     90     }
     91 }
     92