1 /* 2 * Copyright (C) 2010 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.deskclock; 18 19 import android.content.Context; 20 import android.graphics.Paint; 21 import android.graphics.Typeface; 22 import android.util.AttributeSet; 23 import android.widget.TextView; 24 25 /** 26 * Displays text using the special AndroidClock font. 27 */ 28 public class AndroidClockTextView extends TextView { 29 30 private static final String SYSTEM = "/system/fonts/"; 31 private static final String SYSTEM_FONT_TIME_BACKGROUND = SYSTEM + "AndroidClock.ttf"; 32 33 private static final String ATTR_USE_CLOCK_TYPEFACE = "useClockTypeface"; 34 35 private static Typeface sClockTypeface; 36 private static Typeface sStandardTypeface; 37 38 private boolean mUseClockTypeface; 39 40 public AndroidClockTextView(Context context) { 41 super(context); 42 } 43 44 public AndroidClockTextView(Context context, AttributeSet attrs) { 45 super(context, attrs); 46 47 mUseClockTypeface = attrs.getAttributeBooleanValue(null, ATTR_USE_CLOCK_TYPEFACE, true) 48 && !isInEditMode(); 49 50 sStandardTypeface = Typeface.DEFAULT; 51 if (sClockTypeface == null && mUseClockTypeface) { 52 sClockTypeface = Typeface.createFromFile(SYSTEM_FONT_TIME_BACKGROUND); 53 } 54 55 Paint paint = getPaint(); 56 paint.setTypeface(mUseClockTypeface ? sClockTypeface : sStandardTypeface); 57 } 58 } 59