• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 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.alarmclock;
18 
19 import android.appwidget.AppWidgetManager;
20 import android.content.Context;
21 import android.content.res.Resources;
22 import android.os.Bundle;
23 import android.util.Log;
24 import android.util.TypedValue;
25 import android.widget.RemoteViews;
26 
27 import com.android.deskclock.R;
28 
29 public class WidgetUtils {
30     static final String TAG = "WidgetUtils";
31 
setClockSize(Context context, RemoteViews clock, float scale)32     public static void setClockSize(Context context, RemoteViews clock, float scale) {
33         float fontSize = context.getResources().getDimension(R.dimen.widget_big_font_size);
34         clock.setTextViewTextSize(
35                 R.id.the_clock1, TypedValue.COMPLEX_UNIT_PX, fontSize * scale);
36         clock.setTextViewTextSize(
37                 R.id.the_clock2, TypedValue.COMPLEX_UNIT_PX, fontSize * scale);
38     }
39 
40     // Calculate the scale factor of the fonts in the widget
getScaleRatio(Context context, Bundle options, int id)41     public static float getScaleRatio(Context context, Bundle options, int id) {
42         AppWidgetManager widgetManager = AppWidgetManager.getInstance(context);
43         if (options == null) {
44             options = widgetManager.getAppWidgetOptions(id);
45         }
46         if (options != null) {
47             int minWidth = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH);
48             if (minWidth == 0) {
49                 // No data , do no scaling
50                 return 1f;
51             }
52             Resources res = context.getResources();
53             float ratio = minWidth / res.getDimension(R.dimen.def_digital_widget_width);
54             return (ratio > 1) ? 1 : ratio;
55         }
56         return 1;
57     }
58 
59     // Calculate the scale factor of the fonts in the list of  the widget using the widget height
getHeightScaleRatio(Context context, Bundle options, int id)60     public static float getHeightScaleRatio(Context context, Bundle options, int id) {
61         AppWidgetManager widgetManager = AppWidgetManager.getInstance(context);
62         if (options == null) {
63             options = widgetManager.getAppWidgetOptions(id);
64         }
65         if (options != null) {
66             int minHeight = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT);
67             if (minHeight == 0) {
68                 // No data , do no scaling
69                 return 1f;
70             }
71             Resources res = context.getResources();
72             float ratio = minHeight / res.getDimension(R.dimen.def_digital_widget_height);
73             return (ratio > 1) ? 1 : ratio;
74         }
75         return 1;
76     }
77 
78 
79     // Decide if to show the list of world clock.
80     // Check to see if the widget size is big enough, if it is return true.
showList(Context context, int id, float scale)81     public static boolean showList(Context context, int id, float scale) {
82         Bundle options = AppWidgetManager.getInstance(context).getAppWidgetOptions(id);
83         if (options == null) {
84             // no data to make the calculation, show the list anyway
85             return true;
86         }
87         int minHeight = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT);
88         int neededSize = (int) context.getResources().
89             getDimension(R.dimen.digital_widget_list_min_height);
90         return (minHeight > neededSize);
91     }
92 }
93 
94