-
Notifications
You must be signed in to change notification settings - Fork 373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create launcher widget for todo, closes #1997 #2379
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
b47dfe3
create widget
ae94845
empty view
157678a
cleanups
e916454
click on widget to open todo, update widget
1229b66
color scheme
wshoy 205a851
restrict widget update
wshoy aa67dc3
cleanups
wshoy 08b9534
cursor on clicked line, temporary EXTRA workaround
wshoy de93a37
fix typo
wshoy 3f4577f
use Document and TodoTxtTask instead
wshoy 2173ae2
simplify
wshoy 4ee74e2
change size
wshoy dc0543b
add widget preview
wshoy 623e686
use absolute path
wshoy 141d258
Merge branch 'master' into todoWidget
wshoy 566ef4c
Merge branch 'master' into todoWidget
gsantner 6b0def6
Merge branch 'master' into todoWidget
harshad1 bcbbd23
fix too large widget
wshoy 19bfb24
Merge branch 'master' into todoWidget
wshoy 07be3ad
Merge branch 'master' into todoWidget
gsantner a404879
fix
gsantner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
70 changes: 70 additions & 0 deletions
70
app/src/main/java/net/gsantner/markor/widget/TodoWidgetProvider.java
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,70 @@ | ||
package net.gsantner.markor.widget; | ||
|
||
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.os.Build; | ||
import android.widget.RemoteViews; | ||
|
||
import net.gsantner.markor.ApplicationObject; | ||
import net.gsantner.markor.R; | ||
import net.gsantner.markor.activity.openeditor.OpenFromShortcutOrWidgetActivity; | ||
import net.gsantner.markor.model.AppSettings; | ||
import net.gsantner.markor.model.Document; | ||
|
||
public class TodoWidgetProvider extends AppWidgetProvider { | ||
|
||
@Override | ||
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { | ||
|
||
int requestCode = 1; | ||
final AppSettings appSettings = ApplicationObject.settings(); | ||
|
||
final int staticFlags = PendingIntent.FLAG_UPDATE_CURRENT | (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PendingIntent.FLAG_IMMUTABLE : 0); | ||
final int mutableFlags = PendingIntent.FLAG_UPDATE_CURRENT | (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ? PendingIntent.FLAG_MUTABLE : 0); | ||
|
||
for (int appWidgetId : appWidgetIds) { | ||
|
||
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.todo_widget_layout); | ||
|
||
final Intent intent = new Intent(context, TodoWidgetService.class); | ||
views.setRemoteAdapter(R.id.todo_widget_list_view, intent); | ||
views.setEmptyView(R.id.todo_widget_list_view, R.id.todo_widget_empty_view); | ||
views.setInt(R.id.todo_widget_list_view, "setBackgroundColor", appSettings.getEditorBackgroundColor()); | ||
|
||
final Intent openTodo = new Intent(context, OpenFromShortcutOrWidgetActivity.class) | ||
.setAction(Intent.ACTION_EDIT) | ||
.putExtra(Document.EXTRA_FILE, appSettings.getTodoFile()); | ||
views.setPendingIntentTemplate(R.id.todo_widget_list_view, PendingIntent.getActivity(context, requestCode++, openTodo, mutableFlags)); | ||
views.setOnClickPendingIntent(R.id.todo_widget_container, PendingIntent.getActivity(context, requestCode++, openTodo, staticFlags)); | ||
|
||
// Tell the AppWidgetManager to perform an update on the current app widget | ||
appWidgetManager.updateAppWidget(appWidgetId, views); | ||
} | ||
|
||
super.onUpdate(context, appWidgetManager, appWidgetIds); | ||
} | ||
|
||
// Update all widget lists and shortcuts for all widgets | ||
public static void updateTodoWidgets() { | ||
final Context context = ApplicationObject.get().getApplicationContext(); | ||
final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); | ||
if (appWidgetManager == null) { | ||
// The device does not support widgets. | ||
return; | ||
} | ||
final ComponentName comp = new ComponentName(context, TodoWidgetProvider.class); | ||
final int[] appWidgetIds = appWidgetManager.getAppWidgetIds(comp); | ||
|
||
// Update List | ||
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.todo_widget_list_view); | ||
|
||
// Trigger remote views update | ||
context.sendBroadcast(new Intent(context, TodoWidgetProvider.class) | ||
.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE) | ||
.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds)); | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
app/src/main/java/net/gsantner/markor/widget/TodoWidgetRemoteViewsFactory.java
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,89 @@ | ||
package net.gsantner.markor.widget; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.widget.RemoteViews; | ||
import android.widget.RemoteViewsService; | ||
|
||
import net.gsantner.markor.ApplicationObject; | ||
import net.gsantner.markor.R; | ||
import net.gsantner.markor.format.todotxt.TodoTxtTask; | ||
import net.gsantner.markor.model.AppSettings; | ||
import net.gsantner.markor.model.Document; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class TodoWidgetRemoteViewsFactory implements RemoteViewsService.RemoteViewsFactory { | ||
|
||
private final Context _context; | ||
private final AppSettings _appSettings; | ||
private final Document _document; | ||
private final List<TodoTxtTask> _tasks; | ||
|
||
public TodoWidgetRemoteViewsFactory(Context context, Intent intent) { | ||
_context = context; | ||
_appSettings = ApplicationObject.settings(); | ||
_document = new Document(_appSettings.getTodoFile()); | ||
_tasks = new ArrayList<>(); | ||
} | ||
|
||
@Override | ||
public void onCreate() { | ||
onDataSetChanged(); | ||
} | ||
|
||
@Override | ||
public void onDataSetChanged() { | ||
_tasks.clear(); | ||
final String content = _document.loadContent(_context); | ||
if (content == null) { | ||
return; | ||
} | ||
List<TodoTxtTask> tasks = TodoTxtTask.getAllTasks(content); | ||
_tasks.addAll(tasks); | ||
} | ||
|
||
@Override | ||
public void onDestroy() { | ||
_tasks.clear(); | ||
} | ||
|
||
@Override | ||
public int getCount() { | ||
return _tasks.size(); | ||
} | ||
|
||
@Override | ||
public RemoteViews getViewAt(int position) { | ||
RemoteViews views = new RemoteViews(_context.getPackageName(), R.layout.todo_widget_list_item); | ||
views.setTextViewText(R.id.todo_widget_item_text, _tasks.get(position).getDescription()); | ||
views.setInt(R.id.todo_widget_item_text, "setTextColor", _appSettings.getEditorForegroundColor()); | ||
|
||
final Intent fillInIntent = new Intent() | ||
.putExtra(Document.EXTRA_FILE_LINE_NUMBER, position); | ||
views.setOnClickFillInIntent(R.id.todo_widget_item_text, fillInIntent); | ||
|
||
return views; | ||
} | ||
|
||
@Override | ||
public RemoteViews getLoadingView() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public int getViewTypeCount() { | ||
return 1; | ||
} | ||
|
||
@Override | ||
public long getItemId(int position) { | ||
return position; | ||
} | ||
|
||
@Override | ||
public boolean hasStableIds() { | ||
return false; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
app/src/main/java/net/gsantner/markor/widget/TodoWidgetService.java
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,12 @@ | ||
|
||
package net.gsantner.markor.widget; | ||
|
||
import android.content.Intent; | ||
import android.widget.RemoteViewsService; | ||
|
||
public class TodoWidgetService extends RemoteViewsService { | ||
@Override | ||
public RemoteViewsFactory onGetViewFactory(Intent intent) { | ||
return (new TodoWidgetRemoteViewsFactory(getApplicationContext(), intent)); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/todo_widget_container" | ||
android:orientation="vertical" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:background="@color/background"> | ||
|
||
<ListView | ||
android:id="@+id/todo_widget_list_view" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:divider="@color/grey" | ||
android:dividerHeight="0.5dp" /> | ||
|
||
<TextView | ||
android:id="@+id/todo_widget_empty_view" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:text="Empty" | ||
android:gravity="center" | ||
android:visibility="gone" /> | ||
</LinearLayout> |
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,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<TextView xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/todo_widget_item_text" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:padding="3dp" | ||
android:textSize="15sp" | ||
android:textColor="@color/primary_text" /> |
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,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:initialLayout="@layout/todo_widget_layout" | ||
android:minWidth="120dp" | ||
android:minHeight="80dp" | ||
android:targetCellHeight="2" | ||
android:targetCellWidth="2" | ||
android:minResizeWidth="60dp" | ||
android:minResizeHeight="40dp" | ||
android:previewImage="@drawable/todo_widget_preview" | ||
android:resizeMode="horizontal|vertical" | ||
android:updatePeriodMillis="1800000" /> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be really good to also highlight this.
Can do this pretty easily. See getSttHighlighter in MarkorDialogFactory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it needs highlighting.
I have tried, but could not get it to work.
Using getSttHighlighter is seems to be limited to just highlighting patterns, which is good for editable text. I might be wrong.
A SpannableStringBuilder with TodoTxtTask would allow for parsing, choosing or changing elements shown.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Plaintext/no highlight would be enough for the first version. Especially if you anyway think about further changes
The widget is not meant to replicate whole-Markor-editor-in-a-widget.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean, that I should merge this PR and make further changes in another?
I also plan on making another widget for regular notes which would take some time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My plan would be to get a initial version that works well enough / not makes crashes. Preferred over full featured and half stuff bare works 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well... It works well on my machine 😅
I cannot find other ways to improve it beyond what I mentioned. Maybe you might find something?