aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBrandon McAnsh <brandon.mcansh@gmail.com>2015-07-08 15:32:59 -0400
committerBrandon McAnsh <brandon.mcansh@gmail.com>2015-07-14 10:59:08 -0700
commit652fb4e2ec0e7fbd30c93709a1d8a28d8f40c19a (patch)
tree12922c64ca87952d054f5137e833dea3249f2998 /src
parentad1d777e7949d8e58b14d8f748f5e6ac1e267431 (diff)
downloadandroid_packages_apps_LockClock-652fb4e2ec0e7fbd30c93709a1d8a28d8f40c19a.tar.gz
android_packages_apps_LockClock-652fb4e2ec0e7fbd30c93709a1d8a28d8f40c19a.tar.bz2
android_packages_apps_LockClock-652fb4e2ec0e7fbd30c93709a1d8a28d8f40c19a.zip
LockClock: Only show timestamp if it can fit
* Currently in a 4x2 widget, the timestamp can be clipped at the bottom presenting a bad UX for the widget that a user will first see when booting into Trebuchet (at least on bacon, klte, and m7). * Check if the timestamp can fit based on the same logic as the calendar Change-Id: I4ae3d55ac9e27f95403d39c41266fd43fa5bcf82 Signed-off-by: Brandon McAnsh <brandon.mcansh@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/com/cyanogenmod/lockclock/ClockWidgetService.java13
-rw-r--r--src/com/cyanogenmod/lockclock/misc/WidgetUtils.java26
2 files changed, 36 insertions, 3 deletions
diff --git a/src/com/cyanogenmod/lockclock/ClockWidgetService.java b/src/com/cyanogenmod/lockclock/ClockWidgetService.java
index 6fa0ab2..8402194 100644
--- a/src/com/cyanogenmod/lockclock/ClockWidgetService.java
+++ b/src/com/cyanogenmod/lockclock/ClockWidgetService.java
@@ -155,9 +155,13 @@ public class ClockWidgetService extends IntentService {
refreshCalendar(remoteViews, id);
}
// Hide the calendar panel if not visible
- remoteViews.setViewVisibility(R.id.calendar_panel, showCalendar ? View.VISIBLE : View.GONE);
+ remoteViews.setViewVisibility(R.id.calendar_panel,
+ showCalendar ? View.VISIBLE : View.GONE);
- boolean canFitWeather = smallWidget || WidgetUtils.canFitWeather(this, id, digitalClock, isKeyguard);
+ boolean canFitWeather = smallWidget
+ || WidgetUtils.canFitWeather(this, id, digitalClock, isKeyguard);
+ boolean canFitTimestamp = smallWidget
+ || WidgetUtils.canFitTimestamp(this, id, digitalClock);
// Now, if we need to show the actual weather, do so
if (showWeather && canFitWeather) {
WeatherInfo weatherInfo = Preferences.getCachedWeatherInfo(this);
@@ -168,7 +172,10 @@ public class ClockWidgetService extends IntentService {
setNoWeatherData(remoteViews, smallWidget);
}
}
- remoteViews.setViewVisibility(R.id.weather_panel, (showWeather && canFitWeather) ? View.VISIBLE : View.GONE);
+ remoteViews.setViewVisibility(R.id.update_time,
+ (showWeather && canFitWeather && canFitTimestamp) ? View.VISIBLE : View.GONE);
+ remoteViews.setViewVisibility(R.id.weather_panel,
+ (showWeather && canFitWeather) ? View.VISIBLE : View.GONE);
// Resize the clock font if needed
if (digitalClock) {
diff --git a/src/com/cyanogenmod/lockclock/misc/WidgetUtils.java b/src/com/cyanogenmod/lockclock/misc/WidgetUtils.java
index e080793..f24f242 100644
--- a/src/com/cyanogenmod/lockclock/misc/WidgetUtils.java
+++ b/src/com/cyanogenmod/lockclock/misc/WidgetUtils.java
@@ -76,6 +76,32 @@ public class WidgetUtils {
}
/**
+ * Decide whether to show the timestamp
+ */
+ public static boolean canFitTimestamp(Context context, int id, boolean digitalClock) {
+ Bundle options = AppWidgetManager.getInstance(context).getAppWidgetOptions(id);
+ if (options == null) {
+ // no data to make the calculation, show the list anyway
+ return true;
+ }
+ Resources resources = context.getResources();
+ int minHeight = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT);
+ int minHeightPx = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, minHeight,
+ resources.getDisplayMetrics());
+ int neededSize = (int) resources.getDimension(digitalClock
+ ? R.dimen.min_digital_timestamp_height : R.dimen.min_analog_timestamp_height);
+
+ // Check to see if the widget size is big enough, if it is return true.
+ Boolean result = minHeightPx > neededSize;
+ if (D) {
+ Log.d(TAG, "canFitTimestamp: digital clock = " + digitalClock
+ + " with minHeightPx = " + minHeightPx + " and neededSize = " + neededSize);
+ Log.d(TAG, "canFitTimestamp result = " + result);
+ }
+ return result;
+ }
+
+ /**
* Decide whether to show the full Weather panel
*/
public static boolean canFitWeather(Context context, int id, boolean digitalClock, boolean isKeyguard) {