AOSP/DeskClock - Apply lint formatting changes to Kotlin code
Test: none currently, DeskClockKotlin builds successfully, testing is a
work in progress
Change-Id: Ia1f42e993598f488fa54a04bd18473d832db7e39
diff --git a/src/com/android/alarmclock/DigitalAppWidgetCityViewsFactory.kt b/src/com/android/alarmclock/DigitalAppWidgetCityViewsFactory.kt
index 0f51f43..4eb42d1 100644
--- a/src/com/android/alarmclock/DigitalAppWidgetCityViewsFactory.kt
+++ b/src/com/android/alarmclock/DigitalAppWidgetCityViewsFactory.kt
@@ -93,7 +93,11 @@
val homeClockOffset = if (mShowHomeClock) -1 else 0
val leftIndex = position * 2 + homeClockOffset
val rightIndex = leftIndex + 1
- val left = if (leftIndex == -1) mHomeCity else if (leftIndex < mCities!!.size) mCities!![leftIndex] else null
+ val left = when {
+ leftIndex == -1 -> mHomeCity
+ leftIndex < mCities!!.size -> mCities!![leftIndex]
+ else -> null
+ }
val right = if (rightIndex < mCities!!.size) mCities!![rightIndex] else null
val rv = RemoteViews(mContext.getPackageName(), R.layout.world_clock_remote_list_item)
diff --git a/src/com/android/alarmclock/DigitalAppWidgetProvider.kt b/src/com/android/alarmclock/DigitalAppWidgetProvider.kt
index d5417d4..a4427d1 100644
--- a/src/com/android/alarmclock/DigitalAppWidgetProvider.kt
+++ b/src/com/android/alarmclock/DigitalAppWidgetProvider.kt
@@ -147,7 +147,12 @@
/**
* Called when the app widget changes sizes.
*/
- override fun onAppWidgetOptionsChanged(context: Context, wm: AppWidgetManager?, widgetId: Int, options: Bundle) {
+ override fun onAppWidgetOptionsChanged(
+ context: Context,
+ wm: AppWidgetManager?,
+ widgetId: Int,
+ options: Bundle
+ ) {
super.onAppWidgetOptionsChanged(context, wm, widgetId, options)
// Scale the fonts of the clock to fit inside the new size
@@ -180,7 +185,8 @@
val nextDay = Utils.getNextDay(Date(), zones)
// Schedule the next day-change callback; at least one city is displayed.
- val pi: PendingIntent = PendingIntent.getBroadcast(context, 0, DAY_CHANGE_INTENT, FLAG_UPDATE_CURRENT)
+ val pi: PendingIntent =
+ PendingIntent.getBroadcast(context, 0, DAY_CHANGE_INTENT, FLAG_UPDATE_CURRENT)
getAlarmManager(context).setExact(AlarmManager.RTC, nextDay.time, pi)
}
@@ -188,7 +194,8 @@
* Remove the existing day-change callback.
*/
private fun removeDayChangeCallback(context: Context) {
- val pi: PendingIntent? = PendingIntent.getBroadcast(context, 0, DAY_CHANGE_INTENT, FLAG_NO_CREATE)
+ val pi: PendingIntent? =
+ PendingIntent.getBroadcast(context, 0, DAY_CHANGE_INTENT, FLAG_NO_CREATE)
if (pi != null) {
getAlarmManager(context).cancel(pi)
pi.cancel()
@@ -199,7 +206,11 @@
* This class stores the target size of the widget as well as the measured size using a given
* clock font size. All other fonts and icons are scaled proportional to the clock font.
*/
- private class Sizes(val mTargetWidthPx: Int, val mTargetHeightPx: Int, val largestClockFontSizePx: Int) {
+ private class Sizes(
+ val mTargetWidthPx: Int,
+ val mTargetHeightPx: Int,
+ val largestClockFontSizePx: Int
+ ) {
val smallestClockFontSizePx = 1
var mIconBitmap: Bitmap? = null
@@ -265,7 +276,6 @@
builder.append(String.format(Locale.ENGLISH, format, *args))
}
}
-
}
companion object {
@@ -285,8 +295,12 @@
* Compute optimal font and icon sizes offscreen for both portrait and landscape orientations
* using the last known widget size and apply them to the widget.
*/
- private fun relayoutWidget(context: Context, wm: AppWidgetManager, widgetId: Int,
- options: Bundle) {
+ private fun relayoutWidget(
+ context: Context,
+ wm: AppWidgetManager,
+ widgetId: Int,
+ options: Bundle
+ ) {
val portrait: RemoteViews = relayoutWidget(context, wm, widgetId, options, true)
val landscape: RemoteViews = relayoutWidget(context, wm, widgetId, options, false)
val widget = RemoteViews(landscape, portrait)
@@ -297,8 +311,13 @@
/**
* Compute optimal font and icon sizes offscreen for the given orientation.
*/
- private fun relayoutWidget(context: Context, wm: AppWidgetManager, widgetId: Int,
- options: Bundle?, portrait: Boolean): RemoteViews {
+ private fun relayoutWidget(
+ context: Context,
+ wm: AppWidgetManager,
+ widgetId: Int,
+ options: Bundle?,
+ portrait: Boolean
+ ): RemoteViews {
// Create a remote view for the digital clock.
val packageName: String = context.getPackageName()
val rv = RemoteViews(packageName, R.layout.digital_widget)
@@ -336,7 +355,8 @@
val maxHeightPx = (density * options.getInt(OPTION_APPWIDGET_MAX_HEIGHT)).toInt()
val targetWidthPx = if (portrait) minWidthPx else maxWidthPx
val targetHeightPx = if (portrait) maxHeightPx else minHeightPx
- val largestClockFontSizePx: Int = resources.getDimensionPixelSize(R.dimen.widget_max_clock_font_size)
+ val largestClockFontSizePx: Int =
+ resources.getDimensionPixelSize(R.dimen.widget_max_clock_font_size)
// Create a size template that describes the widget bounds.
val template = Sizes(targetWidthPx, targetHeightPx, largestClockFontSizePx)
@@ -353,7 +373,8 @@
rv.setTextViewTextSize(R.id.nextAlarm, COMPLEX_UNIT_PX, sizes.mFontSizePx.toFloat())
rv.setTextViewTextSize(R.id.clock, COMPLEX_UNIT_PX, sizes.mClockFontSizePx.toFloat())
- val smallestWorldCityListSizePx: Int = resources.getDimensionPixelSize(R.dimen.widget_min_world_city_list_size)
+ val smallestWorldCityListSizePx: Int =
+ resources.getDimensionPixelSize(R.dimen.widget_min_world_city_list_size)
if (sizes.listHeight <= smallestWorldCityListSizePx) {
// Insufficient space; hide the world city list.
rv.setViewVisibility(R.id.world_city_list, GONE)
@@ -383,7 +404,8 @@
private fun optimizeSizes(context: Context, template: Sizes, nextAlarmTime: String): Sizes {
// Inflate a test layout to compute sizes at different font sizes.
val inflater: LayoutInflater = LayoutInflater.from(context)
- @SuppressLint("InflateParams") val sizer: View = inflater.inflate(R.layout.digital_widget_sizer, null /* root */)
+ @SuppressLint("InflateParams") val sizer: View =
+ inflater.inflate(R.layout.digital_widget_sizer, null /* root */)
// Configure the date to display the current date string.
val dateFormat: CharSequence = getDateFormat(context)
@@ -459,7 +481,8 @@
date.setTextSize(COMPLEX_UNIT_PX, measuredSizes.mFontSizePx.toFloat())
nextAlarm.setTextSize(COMPLEX_UNIT_PX, measuredSizes.mFontSizePx.toFloat())
nextAlarmIcon.setTextSize(COMPLEX_UNIT_PX, measuredSizes.mIconFontSizePx.toFloat())
- nextAlarmIcon.setPadding(measuredSizes.mIconPaddingPx, 0, measuredSizes.mIconPaddingPx, 0)
+ nextAlarmIcon
+ .setPadding(measuredSizes.mIconPaddingPx, 0, measuredSizes.mIconPaddingPx, 0)
// Measure and layout the sizer.
val widthSize: Int = View.MeasureSpec.getSize(measuredSizes.mTargetWidthPx)
@@ -487,7 +510,11 @@
* @return "11:59" or "23:59" in the current locale
*/
private fun getLongestTimeString(clock: TextClock): CharSequence {
- val format: CharSequence = if (clock.is24HourModeEnabled()) clock.getFormat24Hour() else clock.getFormat12Hour()
+ val format: CharSequence = if (clock.is24HourModeEnabled()) {
+ clock.getFormat24Hour()
+ } else {
+ clock.getFormat12Hour()
+ }
val longestPMTime = Calendar.getInstance()
longestPMTime[0, 0, 0, 23] = 59
return DateFormat.format(format, longestPMTime)
diff --git a/src/com/android/alarmclock/WidgetUtils.kt b/src/com/android/alarmclock/WidgetUtils.kt
index f227de3..c8ff7aa 100644
--- a/src/com/android/alarmclock/WidgetUtils.kt
+++ b/src/com/android/alarmclock/WidgetUtils.kt
@@ -28,9 +28,9 @@
fun getScaleRatio(context: Context, options: Bundle?, id: Int, cityCount: Int): Float {
var options: Bundle? = options
if (options == null) {
- val widgetManager: AppWidgetManager = AppWidgetManager.getInstance(context)
- ?: // no manager , do no scaling
- return 1f
+ val widgetManager: AppWidgetManager =
+ AppWidgetManager.getInstance(context) // no manager , do no scaling
+ ?: return 1f
options = widgetManager.getAppWidgetOptions(id)
}
options?.let {
@@ -41,7 +41,8 @@
}
val res: Resources = context.getResources()
val density: Float = res.getDisplayMetrics().density
- var ratio: Float = density * minWidth / res.getDimension(R.dimen.min_digital_widget_width)
+ var ratio: Float =
+ density * minWidth / res.getDimension(R.dimen.min_digital_widget_width)
ratio = Math.min(ratio, getHeightScaleRatio(context, it))
ratio *= .83f
diff --git a/src/com/android/deskclock/controller/ShortcutController.kt b/src/com/android/deskclock/controller/ShortcutController.kt
index 264f956..6b1e762 100644
--- a/src/com/android/deskclock/controller/ShortcutController.kt
+++ b/src/com/android/deskclock/controller/ShortcutController.kt
@@ -105,7 +105,11 @@
}
private fun createStopwatchShortcut(): ShortcutInfo {
- @StringRes val action: Int = if (DataModel.getDataModel().stopwatch.isRunning) R.string.action_pause else R.string.action_start
+ @StringRes val action: Int = if (DataModel.getDataModel().stopwatch.isRunning) {
+ R.string.action_pause
+ } else {
+ R.string.action_start
+ }
val shortcutId = UiDataModel.getUiDataModel()
.getShortcutId(R.string.category_stopwatch, action)
val shortcut: ShortcutInfo.Builder = ShortcutInfo.Builder(context, shortcutId)
diff --git a/src/com/android/deskclock/events/LogEventTracker.kt b/src/com/android/deskclock/events/LogEventTracker.kt
index 9a63388..c7cdedc 100644
--- a/src/com/android/deskclock/events/LogEventTracker.kt
+++ b/src/com/android/deskclock/events/LogEventTracker.kt
@@ -14,21 +14,25 @@
* limitations under the License.
*/
-package com.android.deskclock.events;
+package com.android.deskclock.events
-import android.content.Context;
-import androidx.annotation.StringRes;
+import android.content.Context
+import androidx.annotation.StringRes
-import com.android.deskclock.LogUtils;
+import com.android.deskclock.LogUtils
class LogEventTracker(val context: Context) : EventTracker {
- override fun sendEvent(@StringRes category: Int, @StringRes action: Int, @StringRes label: Int) {
+ override fun sendEvent(
+ @StringRes category: Int,
+ @StringRes action: Int,
+ @StringRes label: Int
+ ) {
if (label == 0) {
- LOGGER.d("[%s] [%s]", safeGetString(category), safeGetString(action));
+ LOGGER.d("[%s] [%s]", safeGetString(category), safeGetString(action))
} else {
LOGGER.d("[%s] [%s] [%s]", safeGetString(category), safeGetString(action),
- safeGetString(label));
+ safeGetString(label))
}
}
diff --git a/src/com/android/deskclock/events/ShortcutEventTracker.kt b/src/com/android/deskclock/events/ShortcutEventTracker.kt
index 67a26db..d2c85bf 100644
--- a/src/com/android/deskclock/events/ShortcutEventTracker.kt
+++ b/src/com/android/deskclock/events/ShortcutEventTracker.kt
@@ -28,7 +28,8 @@
@TargetApi(Build.VERSION_CODES.N_MR1)
class ShortcutEventTracker(context: Context) : EventTracker {
- private val mShortcutManager: ShortcutManager = context.getSystemService(ShortcutManager::class.java)
+ private val mShortcutManager: ShortcutManager =
+ context.getSystemService(ShortcutManager::class.java)
private val shortcuts: MutableSet<String> = ArraySet(5)
init {
@@ -40,7 +41,11 @@
shortcuts.add(uidm.getShortcutId(R.string.category_screensaver, R.string.action_show))
}
- override fun sendEvent(@StringRes category: Int, @StringRes action: Int, @StringRes label: Int) {
+ override fun sendEvent(
+ @StringRes category: Int,
+ @StringRes action: Int,
+ @StringRes label: Int
+ ) {
val shortcutId = UiDataModel.getUiDataModel().getShortcutId(category, action)
if (shortcuts.contains(shortcutId)) {
mShortcutManager.reportShortcutUsed(shortcutId)