-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
the widgets are complete, they might look different depending on the android version and launcher used, previews are from API level 33 aka android 13.
- Loading branch information
Showing
24 changed files
with
476 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,6 +75,9 @@ android { | |
shrinkResources true | ||
} | ||
} | ||
buildFeatures { | ||
viewBinding true | ||
} | ||
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
android/app/src/main/java/com/moazsalem/notes/MidNoteWidget.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.moazsalem.notes | ||
|
||
import android.app.PendingIntent | ||
import android.appwidget.AppWidgetManager | ||
import android.appwidget.AppWidgetProvider | ||
import android.content.ComponentName | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.graphics.Color | ||
import android.widget.RemoteViews | ||
import es.antonborri.home_widget.HomeWidgetPlugin | ||
|
||
private var globalIndex: Int = 0 | ||
class MidNoteWidget : AppWidgetProvider() { | ||
override fun onUpdate( | ||
context: Context, | ||
appWidgetManager: AppWidgetManager, | ||
appWidgetIds: IntArray | ||
) { | ||
for (appWidgetId in appWidgetIds) { | ||
// Create an intent to handle widget click | ||
val intent = Intent(context, MidNoteWidget::class.java) | ||
intent.action = "widgetClicked" | ||
|
||
// Create a PendingIntent for the widget click | ||
val pendingIntent = PendingIntent.getBroadcast(context, 0, intent, | ||
PendingIntent.FLAG_IMMUTABLE) | ||
|
||
// Create RemoteViews | ||
val views = RemoteViews(context.packageName, R.layout.mid_note_widget).apply { | ||
val widgetData = HomeWidgetPlugin.getData(context) | ||
val titlesArray = widgetData.getString("titles", "No Notes")?.split("||S||") | ||
val contentsArray = widgetData.getString("contents", "Add Notes from App")?.split("||S||") | ||
val colorsArray = widgetData.getString("colors", "#ff8b34")?.split("||S||") | ||
val textCArray = widgetData.getString("textColors", "")?.split("||S||") | ||
val textColor = if(textCArray?.get(globalIndex) == "1") "#000000" else "#ffffff" | ||
setTextViewText(R.id.title, titlesArray?.get(globalIndex) ?: "No Title") | ||
setTextColor(R.id.title, Color.parseColor(textColor)) | ||
setTextViewText(R.id.content, contentsArray?.get(globalIndex) ?: "No Content") | ||
setTextColor(R.id.content, Color.parseColor(textColor)) | ||
setInt(R.id.background, "setBackgroundColor", Color.parseColor(colorsArray?.get(globalIndex) ?: "#ff8b34")) | ||
// Set the click action to increment globalIndex | ||
setOnClickPendingIntent(R.id.background, pendingIntent) | ||
} | ||
|
||
appWidgetManager.updateAppWidget(appWidgetId, views) | ||
} | ||
} | ||
|
||
override fun onReceive(context: Context, intent: Intent) { | ||
super.onReceive(context, intent) | ||
|
||
if (intent.action == "widgetClicked") { | ||
// Handle widget click | ||
val widgetData = HomeWidgetPlugin.getData(context) | ||
val titlesArray = widgetData.getString("titles", "")?.split("||S||") | ||
if (titlesArray != null && globalIndex < titlesArray.size - 1) { | ||
globalIndex++ | ||
} else { | ||
globalIndex = 0 | ||
} | ||
|
||
val appWidgetManager = AppWidgetManager.getInstance(context) | ||
val appWidgetIds = appWidgetManager.getAppWidgetIds(ComponentName(context, MidNoteWidget::class.java)) | ||
onUpdate(context, appWidgetManager, appWidgetIds) | ||
} | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
android/app/src/main/java/com/moazsalem/notes/SmallNoteWidget.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.moazsalem.notes | ||
|
||
import android.app.PendingIntent | ||
import android.appwidget.AppWidgetManager | ||
import android.appwidget.AppWidgetProvider | ||
import android.content.ComponentName | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.graphics.Color | ||
import android.widget.RemoteViews | ||
import es.antonborri.home_widget.HomeWidgetPlugin | ||
|
||
private var globalIndex: Int = 0 | ||
class SmallNoteWidget : AppWidgetProvider() { | ||
override fun onUpdate( | ||
context: Context, | ||
appWidgetManager: AppWidgetManager, | ||
appWidgetIds: IntArray | ||
) { | ||
for (appWidgetId in appWidgetIds) { | ||
// Create an intent to handle widget click | ||
val intent = Intent(context, SmallNoteWidget::class.java) | ||
intent.action = "widgetClicked" | ||
|
||
// Create a PendingIntent for the widget click | ||
val pendingIntent = PendingIntent.getBroadcast(context, 0, intent, | ||
PendingIntent.FLAG_IMMUTABLE) | ||
|
||
// Create RemoteViews | ||
val views = RemoteViews(context.packageName, R.layout.small_note_widget).apply { | ||
val widgetData = HomeWidgetPlugin.getData(context) | ||
val titlesArray = widgetData.getString("titles", "No Notes")?.split("||S||") | ||
val contentsArray = widgetData.getString("contents", "Add Notes from App")?.split("||S||") | ||
val colorsArray = widgetData.getString("colors", "#f77b85")?.split("||S||") | ||
val textCArray = widgetData.getString("textColors", "")?.split("||S||") | ||
val textColor = if(textCArray?.get(globalIndex) == "1") "#000000" else "#ffffff" | ||
setTextViewText(R.id.title, titlesArray?.get(globalIndex) ?: "No Title") | ||
setTextColor(R.id.title, Color.parseColor(textColor)) | ||
setTextViewText(R.id.content, contentsArray?.get(globalIndex) ?: "No Content") | ||
setTextColor(R.id.content, Color.parseColor(textColor)) | ||
setInt(R.id.background, "setBackgroundColor", Color.parseColor(colorsArray?.get(globalIndex) ?: "#f77b85")) | ||
// Set the click action to increment globalIndex | ||
setOnClickPendingIntent(R.id.background, pendingIntent) | ||
} | ||
|
||
appWidgetManager.updateAppWidget(appWidgetId, views) | ||
} | ||
} | ||
|
||
override fun onReceive(context: Context, intent: Intent) { | ||
super.onReceive(context, intent) | ||
|
||
if (intent.action == "widgetClicked") { | ||
// Handle widget click | ||
val widgetData = HomeWidgetPlugin.getData(context) | ||
val titlesArray = widgetData.getString("titles", "")?.split("||S||") | ||
if (titlesArray != null && globalIndex < titlesArray.size - 1) { | ||
globalIndex++ | ||
} else { | ||
globalIndex = 0 | ||
} | ||
|
||
val appWidgetManager = AppWidgetManager.getInstance(context) | ||
val appWidgetIds = appWidgetManager.getAppWidgetIds(ComponentName(context, SmallNoteWidget::class.java)) | ||
onUpdate(context, appWidgetManager, appWidgetIds) | ||
} | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
android/app/src/main/java/com/moazsalem/notes/WideNoteWidget.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.moazsalem.notes | ||
|
||
import android.app.PendingIntent | ||
import android.appwidget.AppWidgetManager | ||
import android.appwidget.AppWidgetProvider | ||
import android.content.ComponentName | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.graphics.Color | ||
import android.widget.RemoteViews | ||
import es.antonborri.home_widget.HomeWidgetPlugin | ||
|
||
private var globalIndex: Int = 0 | ||
class WideNoteWidget : AppWidgetProvider() { | ||
override fun onUpdate( | ||
context: Context, | ||
appWidgetManager: AppWidgetManager, | ||
appWidgetIds: IntArray | ||
) { | ||
for (appWidgetId in appWidgetIds) { | ||
// Create an intent to handle widget click | ||
val intent = Intent(context, WideNoteWidget::class.java) | ||
intent.action = "widgetClicked" | ||
|
||
// Create a PendingIntent for the widget click | ||
val pendingIntent = PendingIntent.getBroadcast(context, 0, intent, | ||
PendingIntent.FLAG_IMMUTABLE) | ||
|
||
// Create RemoteViews | ||
val views = RemoteViews(context.packageName, R.layout.wide_note_widget).apply { | ||
val widgetData = HomeWidgetPlugin.getData(context) | ||
val titlesArray = widgetData.getString("titles", "No Notes")?.split("||S||") | ||
val contentsArray = widgetData.getString("contents", "Add Notes from App")?.split("||S||") | ||
val colorsArray = widgetData.getString("colors", "#66c6c2")?.split("||S||") | ||
val textCArray = widgetData.getString("textColors", "")?.split("||S||") | ||
val textColor = if(textCArray?.get(globalIndex) == "1") "#000000" else "#ffffff" | ||
setTextViewText(R.id.title, titlesArray?.get(globalIndex) ?: "No Title") | ||
setTextColor(R.id.title, Color.parseColor(textColor)) | ||
setTextViewText(R.id.content, contentsArray?.get(globalIndex) ?: "No Content") | ||
setTextColor(R.id.content, Color.parseColor(textColor)) | ||
setInt(R.id.background, "setBackgroundColor", Color.parseColor(colorsArray?.get(globalIndex) ?: "#66c6c2")) | ||
// Set the click action to increment globalIndex | ||
setOnClickPendingIntent(R.id.background, pendingIntent) | ||
} | ||
|
||
appWidgetManager.updateAppWidget(appWidgetId, views) | ||
} | ||
} | ||
|
||
override fun onReceive(context: Context, intent: Intent) { | ||
super.onReceive(context, intent) | ||
|
||
if (intent.action == "widgetClicked") { | ||
// Handle widget click | ||
val widgetData = HomeWidgetPlugin.getData(context) | ||
val titlesArray = widgetData.getString("titles", "")?.split("||S||") | ||
if (titlesArray != null && globalIndex < titlesArray.size - 1) { | ||
globalIndex++ | ||
} else { | ||
globalIndex = 0 | ||
} | ||
|
||
val appWidgetManager = AppWidgetManager.getInstance(context) | ||
val appWidgetIds = appWidgetManager.getAppWidgetIds(ComponentName(context, WideNoteWidget::class.java)) | ||
onUpdate(context, appWidgetManager, appWidgetIds) | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed
BIN
-3.44 KB
android/app/src/main/res/drawable-nodpi/example_appwidget_preview.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:id="@+id/background" | ||
style="@style/Widget.Android.AppWidget.Container" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:background="#ff8b34" | ||
android:padding="0dp" | ||
android:theme="@style/Theme.Android.AppWidgetContainer"> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical"> | ||
|
||
<TextView | ||
android:id="@+id/title" | ||
android:layout_width="match_parent" | ||
android:layout_height="92dp" | ||
android:ellipsize="end" | ||
android:gravity="center|center_horizontal|center_vertical" | ||
android:maxLines="2" | ||
android:minWidth="80dp" | ||
android:paddingLeft="20dp" | ||
android:paddingTop="20dp" | ||
android:paddingRight="20dp" | ||
android:text="@string/title" | ||
android:textAlignment="center" | ||
android:textColor="#ffffff" | ||
android:textSize="26sp" | ||
android:textStyle="bold" /> | ||
|
||
<TextView | ||
android:id="@+id/content" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:ellipsize="end" | ||
android:gravity="start" | ||
android:minWidth="80dp" | ||
android:minLines="1" | ||
android:paddingLeft="20dp" | ||
android:paddingTop="10dp" | ||
android:paddingRight="20dp" | ||
android:paddingBottom="20dp" | ||
android:text="@string/content" | ||
android:textColor="#FFFFFF" | ||
android:textSize="16sp" /> | ||
</LinearLayout> | ||
</RelativeLayout> |
Oops, something went wrong.