Skip to content

Commit

Permalink
Merge pull request #241 from vicolo-dev/release/0.5.0
Browse files Browse the repository at this point in the history
Release v0.5.0
  • Loading branch information
AhsanSarwar45 authored May 13, 2024
2 parents 12ef920 + f5c142f commit 9641115
Show file tree
Hide file tree
Showing 56 changed files with 1,422 additions and 322 deletions.
18 changes: 6 additions & 12 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
android:name="android.permission.VIBRATE" />
<uses-permission
android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<!-- For Android 12 and higher -->
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"
<!-- For before Android 12 -->
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"
android:maxSdkVersion="32" />
<!-- For before Android 12 -->
<!-- For Android 12 and higher -->
<uses-permission
android:name="android.permission.USE_EXACT_ALARM" />

Expand Down Expand Up @@ -65,6 +65,9 @@
<data android:scheme="id" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="es.antonborri.home_widget.action.LAUNCH" />
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
Expand Down Expand Up @@ -140,14 +143,5 @@
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/digital_clock_widget" />
</receiver>
<!-- <receiver android:name="DigitalClockDateWidgetProvider" android:exported="true" android:label="Digital with Date"> -->
<!-- <intent-filter> -->
<!-- <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> -->
<!-- </intent-filter> -->
<!-- <meta-data android:name="android.appwidget.provider" -->
<!-- android:resource="@xml/digital_clock_date_widget" /> -->
<!-- </receiver> -->


</application>
</manifest>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import android.appwidget.AppWidgetManager
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.graphics.Color
import android.net.Uri
import android.util.Log
import android.util.TypedValue
import android.view.View
import android.widget.RemoteViews
import android.graphics.Color
import es.antonborri.home_widget.HomeWidgetLaunchIntent
import es.antonborri.home_widget.HomeWidgetProvider
import android.view.ViewGroup.LayoutParams
import android.view.View
import android.util.TypedValue

class DigitalClockWidgetProvider : HomeWidgetProvider() {
override fun onUpdate(
Expand All @@ -21,7 +22,7 @@ class DigitalClockWidgetProvider : HomeWidgetProvider() {
widgetData: SharedPreferences,
) { // Perform this loop procedure for each widget that belongs to this
// provider.
Log.d("TAG", "Updating Digital Clock Widget");
Log.d("TAG", "Updating Digital Clock Widget")

appWidgetIds.forEach { appWidgetId ->
// Create an Intent to launch ExampleActivity.
Expand All @@ -42,25 +43,83 @@ class DigitalClockWidgetProvider : HomeWidgetProvider() {
)
val dateFormat = widgetData.getString("dateFormat", "EEE, d MMM")
val timeFormat = widgetData.getString("timeFormat", "HH:mm")
val dateSize = widgetData.getInt("dateSize", 25)
val timeSize = widgetData.getInt("timeSize", 100)
val textColor = widgetData.getString("textColor", "#FFFFFF")
val dateSize = widgetData.getInt("dateSize", 15)
val timeSize = widgetData.getInt("timeSize", 70)
val timeColor = widgetData.getString("timeColor", "#FFFFFF")
val dateColor = widgetData.getString("dateColor", "#FFFFFF")
val horizontalAlignment = widgetData.getInt("horizontalAlignment", 11)
val verticalAlignment = widgetData.getInt("verticalAlignment", 10)
val timeFontWeight = widgetData.getInt("timeFontWeight", 500)
val dateFontWeight = widgetData.getInt("dateFontWeight", 500)
// val shadowColor = widgetData.getString("shadowColor", "#000000")
// val shadowElevation = widgetData.getFloat("shadowElevation", 1.0f)
// val shadowBlur = widgetData.getFloat("shadowBlur", 1.0f)
val showDate = widgetData.getBoolean("showDate", true)
//
val timeFontWeightMap =
mapOf(
100 to R.id.widget_clock_100,
200 to R.id.widget_clock_200,
300 to R.id.widget_clock_300,
400 to R.id.widget_clock_400,
500 to R.id.widget_clock_500,
600 to R.id.widget_clock_600,
700 to R.id.widget_clock_700,
800 to R.id.widget_clock_800,
900 to R.id.widget_clock_900,
)

setCharSequence(R.id.widget_text_clock, "setFormat24Hour", timeFormat)
setCharSequence(R.id.widget_text_clock, "setFormat12Hour", timeFormat)
setCharSequence(R.id.widget_date, "setFormat24Hour", "EEE, d MMM")
setCharSequence(R.id.widget_date, "setFormat12Hour", "EEE, d MMM")
setColorInt(R.id.widget_text_clock, "setTextColor", Color.parseColor(textColor), Color.parseColor(textColor))
setColorInt(R.id.widget_date, "setTextColor", Color.parseColor(textColor), Color.parseColor(textColor))
// setFloat(R.id.widget_text_clock, "setTextSize", timeSize.toFloat())
// setFloat(R.id.widget_date, "setTextSize", dateSize.toFloat())
setViewLayoutHeight(R.id.widget_text_clock, timeSize.toFloat(), TypedValue.COMPLEX_UNIT_SP)
setViewLayoutHeight(R.id.widget_date, dateSize.toFloat(), TypedValue.COMPLEX_UNIT_SP)
setViewVisibility(R.id.widget_date, if(showDate) View.VISIBLE else View.GONE)
timeFontWeightMap.forEach { it ->
if (it.key != timeFontWeight) {
setViewVisibility(it.value, View.GONE)
} else {
setViewVisibility(it.value, View.VISIBLE)
}
}

val dateFontWeightMap =
mapOf(
100 to R.id.widget_date_100,
200 to R.id.widget_date_200,
300 to R.id.widget_date_300,
400 to R.id.widget_date_400,
500 to R.id.widget_date_500,
600 to R.id.widget_date_600,
700 to R.id.widget_date_700,
800 to R.id.widget_date_800,
900 to R.id.widget_date_900,
)

dateFontWeightMap.forEach { it ->
if (it.key != dateFontWeight) {
setViewVisibility(it.value, View.GONE)
} else {
setViewVisibility(it.value, View.VISIBLE)
}
}
val textClock = timeFontWeightMap[timeFontWeight] ?: R.id.widget_clock_500
val textDate = dateFontWeightMap[dateFontWeight] ?: R.id.widget_date_500
//
setCharSequence(textClock, "setFormat24Hour", timeFormat)
setCharSequence(textClock, "setFormat12Hour", timeFormat)
setCharSequence(textDate, "setFormat24Hour", "EEE, d MMM")
setCharSequence(textDate, "setFormat12Hour", "EEE, d MMM")
if (horizontalAlignment == 7) {
setInt(textClock, "setGravity", 1)
setInt(textDate, "setGravity", 1)
setInt(textClock, "setJustificationMode", 2)
setInt(textDate, "setJustificationMode", 2)
} else {
setInt(textClock, "setGravity", horizontalAlignment)
setInt(textDate, "setGravity", horizontalAlignment)
}
// setInt(R.id.digital_clock_holder, "setVerticalGravity", 10)

setColorInt(textClock, "setTextColor", Color.parseColor(timeColor), Color.parseColor(timeColor))
setColorInt(textDate, "setTextColor", Color.parseColor(dateColor), Color.parseColor(dateColor))
setViewLayoutHeight(textClock, timeSize.toFloat(), TypedValue.COMPLEX_UNIT_SP)
setViewLayoutHeight(textDate, dateSize.toFloat(), TypedValue.COMPLEX_UNIT_SP)
setViewVisibility(textDate, if (showDate) View.VISIBLE else View.GONE)
//
// R.layout.digital_clock_widget.findViewById(R.id.widget_text_clock).apply {
// val param =
Expand Down Expand Up @@ -107,11 +166,14 @@ class DigitalClockWidgetProvider : HomeWidgetProvider() {
// }
//
// // Detect App opened via Click inside Flutter
// val pendingIntentWithData = HomeWidgetLaunchIntent.getActivity(
// context,
// MainActivity::class.java,
// Uri.parse("homeWidgetExample://message?message=$message"))
// setOnClickPendingIntent(R.id.widget_message, pendingIntentWithData)
val pendingIntentWithData =
HomeWidgetLaunchIntent.getActivity(
context,
MainActivity::class.java,
Uri.parse("chrono://digitalClockClicked"),
)
setOnClickPendingIntent(textClock, pendingIntentWithData)
setOnClickPendingIntent(textDate, pendingIntentWithData)
}
// Get the layout for the widget and attach an onClick listener to
// the button.
Expand Down
25 changes: 25 additions & 0 deletions android/app/src/main/res/layout/digital_clock.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

<TextClock
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"

android:id="@+id/widget_clock"
android:layout_width="match_parent"
android:layout_height="70sp"
android:autoSizeMaxTextSize="100sp"
android:autoSizeMinTextSize="10sp"
android:autoSizeStepGranularity="1sp"
android:autoSizeTextType="uniform"
android:format12Hour="h:mm"
android:format24Hour="k:mm"
android:gravity="center"
android:includeFontPadding="false"
android:maxLines="1"
android:textColor="@android:color/white"
android:shadowColor="@android:color/black"
android:shadowDy="1"
android:shadowRadius="1"
android:textFontWeight="500"
android:visibility="visible"
tools:text="00:00" />

68 changes: 0 additions & 68 deletions android/app/src/main/res/layout/digital_clock_date_widget.xml

This file was deleted.

Loading

0 comments on commit 9641115

Please sign in to comment.