Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
e
os
Notes
Commits
0b8348cf
Commit
0b8348cf
authored
Mar 13, 2021
by
Stefan Niedermann
Committed by
Niedermann IT-Dienstleistungen
Mar 13, 2021
Browse files
#1085 Open app when clicking on the list widget header
parent
9c3023b7
Changes
6
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidget.java
View file @
0b8348cf
...
...
@@ -19,10 +19,6 @@ import it.niedermann.owncloud.notes.persistence.NotesDatabase;
public
class
NoteListWidget
extends
AppWidgetProvider
{
private
static
final
String
TAG
=
NoteListWidget
.
class
.
getSimpleName
();
public
static
final
int
PENDING_INTENT_NEW_NOTE_RQ
=
0
;
public
static
final
int
PENDING_INTENT_EDIT_NOTE_RQ
=
1
;
public
static
final
int
PENDING_INTENT_OPEN_APP_RQ
=
2
;
static
void
updateAppWidget
(
Context
context
,
AppWidgetManager
awm
,
int
[]
appWidgetIds
)
{
final
NotesDatabase
db
=
NotesDatabase
.
getInstance
(
context
);
...
...
@@ -32,19 +28,17 @@ public class NoteListWidget extends AppWidgetProvider {
try
{
final
NoteListsWidgetData
data
=
db
.
getNoteListWidgetData
(
appWidgetId
);
Intent
serviceIntent
=
new
Intent
(
context
,
NoteListWidgetService
.
class
);
final
Intent
serviceIntent
=
new
Intent
(
context
,
NoteListWidgetService
.
class
);
serviceIntent
.
putExtra
(
AppWidgetManager
.
EXTRA_APPWIDGET_ID
,
appWidgetId
);
serviceIntent
.
setData
(
Uri
.
parse
(
serviceIntent
.
toUri
(
Intent
.
URI_INTENT_SCHEME
)));
PendingIntent
templatePI
=
PendingIntent
.
getActivity
(
context
,
PENDING_INTENT_EDIT_NOTE_RQ
,
new
Intent
(
context
,
EditNoteActivity
.
class
),
PendingIntent
.
FLAG_UPDATE_CURRENT
);
final
PendingIntent
pendingIntent
=
PendingIntent
.
getActivity
(
context
,
0
,
new
Intent
(),
PendingIntent
.
FLAG_UPDATE_CURRENT
|
Intent
.
FILL_IN_COMPONENT
);
Log
.
v
(
TAG
,
"-- data - "
+
data
);
views
=
new
RemoteViews
(
context
.
getPackageName
(),
R
.
layout
.
widget_note_list
);
views
.
setPendingIntentTemplate
(
R
.
id
.
note_list_widget_lv
,
templatePI
);
views
.
setRemoteAdapter
(
R
.
id
.
note_list_widget_lv
,
serviceIntent
);
views
.
setPendingIntentTemplate
(
R
.
id
.
note_list_widget_lv
,
pendingIntent
);
views
.
setEmptyView
(
R
.
id
.
note_list_widget_lv
,
R
.
id
.
widget_note_list_placeholder_tv
);
awm
.
notifyAppWidgetViewDataChanged
(
appWidgetId
,
R
.
id
.
note_list_widget_lv
);
...
...
app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidgetFactory.java
View file @
0b8348cf
package
it.niedermann.owncloud.notes.widget.notelist
;
import
android.app.PendingIntent
;
import
android.appwidget.AppWidgetManager
;
import
android.content.ComponentName
;
import
android.content.Context
;
...
...
@@ -11,16 +10,13 @@ import android.util.Log;
import
android.widget.RemoteViews
;
import
android.widget.RemoteViewsService
;
import
androidx.annotation.ColorInt
;
import
androidx.annotation.NonNull
;
import
androidx.core.content.ContextCompat
;
import
java.util.ArrayList
;
import
java.util.List
;
import
it.niedermann.android.util.ColorUtil
;
import
it.niedermann.owncloud.notes.R
;
import
it.niedermann.owncloud.notes.branding.BrandingUtil
;
import
it.niedermann.owncloud.notes.edit.EditNoteActivity
;
import
it.niedermann.owncloud.notes.main.MainActivity
;
import
it.niedermann.owncloud.notes.persistence.NotesDatabase
;
...
...
@@ -100,20 +96,8 @@ public class NoteListWidgetFactory implements RemoteViewsService.RemoteViewsFact
if
(
position
==
0
)
{
final
LocalAccount
localAccount
=
db
.
getAccount
(
data
.
getAccountId
());
final
Intent
createIntent
=
new
Intent
();
// Launch application when user taps the header icon or app title
final
Intent
openIntent
=
new
Intent
(
Intent
.
ACTION_MAIN
);
openIntent
.
setComponent
(
new
ComponentName
(
context
.
getPackageName
(),
MainActivity
.
class
.
getName
()));
// Open the main app if the user taps the widget header
PendingIntent
openAppI
=
PendingIntent
.
getActivity
(
context
,
2
,
openIntent
,
PendingIntent
.
FLAG_UPDATE_CURRENT
);
final
Intent
openIntent
=
new
Intent
(
Intent
.
ACTION_MAIN
).
setComponent
(
new
ComponentName
(
context
.
getPackageName
(),
MainActivity
.
class
.
getName
()));
final
Intent
createIntent
=
new
Intent
(
context
,
EditNoteActivity
.
class
);
final
Bundle
extras
=
new
Bundle
();
String
category
=
null
;
...
...
@@ -129,8 +113,9 @@ public class NoteListWidgetFactory implements RemoteViewsService.RemoteViewsFact
createIntent
.
setData
(
Uri
.
parse
(
createIntent
.
toUri
(
Intent
.
URI_INTENT_SCHEME
)));
note_content
=
new
RemoteViews
(
context
.
getPackageName
(),
R
.
layout
.
widget_entry_add
);
note_content
.
setOnClickFillInIntent
(
R
.
id
.
widget_entry_content_tv
,
openIntent
);
note_content
.
setOnClickFillInIntent
(
R
.
id
.
widget_entry_fav_icon
,
createIntent
);
note_content
.
setTextViewText
(
R
.
id
.
widget_entry_content_tv
,
get
AddButtonText
(
context
,
data
.
getMode
(),
category
));
note_content
.
setTextViewText
(
R
.
id
.
widget_entry_content_tv
,
get
CategoryTitle
(
context
,
data
.
getMode
(),
category
));
note_content
.
setImageViewResource
(
R
.
id
.
widget_entry_fav_icon
,
R
.
drawable
.
ic_add_blue_24dp
);
note_content
.
setInt
(
R
.
id
.
widget_entry_fav_icon
,
"setColorFilter"
,
NotesColorUtil
.
contrastRatioIsSufficient
(
ContextCompat
.
getColor
(
context
,
R
.
color
.
widget_background
),
localAccount
.
getColor
())
?
localAccount
.
getColor
()
...
...
@@ -142,8 +127,8 @@ public class NoteListWidgetFactory implements RemoteViewsService.RemoteViewsFact
return
null
;
}
DBNote
note
=
dbNotes
.
get
(
position
);
final
Intent
fillInIntent
=
new
Intent
();
final
DBNote
note
=
dbNotes
.
get
(
position
);
final
Intent
fillInIntent
=
new
Intent
(
context
,
EditNoteActivity
.
class
);
final
Bundle
extras
=
new
Bundle
();
extras
.
putLong
(
EditNoteActivity
.
PARAM_NOTE_ID
,
note
.
getId
());
extras
.
putLong
(
EditNoteActivity
.
PARAM_ACCOUNT_ID
,
note
.
getAccountId
());
...
...
@@ -164,7 +149,7 @@ public class NoteListWidgetFactory implements RemoteViewsService.RemoteViewsFact
}
@NonNull
private
static
String
get
AddButtonText
(
@NonNull
Context
context
,
int
displayMode
,
String
category
)
{
private
static
String
get
CategoryTitle
(
@NonNull
Context
context
,
int
displayMode
,
String
category
)
{
switch
(
displayMode
)
{
case
MODE_DISPLAY_STARRED:
return
context
.
getString
(
R
.
string
.
label_favorites
);
...
...
app/src/main/res/layout/widget_entry.xml
View file @
0b8348cf
...
...
@@ -6,7 +6,10 @@
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:orientation=
"horizontal"
android:padding=
"@dimen/spacer_1x"
>
android:paddingTop=
"@dimen/spacer_1x"
android:paddingStart=
"@null"
android:paddingEnd=
"@dimen/spacer_1hx"
android:paddingBottom=
"@dimen/spacer_1x"
>
<ImageView
android:id=
"@+id/widget_entry_fav_icon"
...
...
@@ -22,7 +25,7 @@
<TextView
android:id=
"@+id/widget_entry_content_tv"
android:layout_width=
"0dp"
android:layout_height=
"
match_par
ent"
android:layout_height=
"
wrap_cont
ent"
android:layout_gravity=
"center_vertical"
android:layout_weight=
"1"
android:ellipsize=
"end"
...
...
app/src/main/res/layout/widget_entry_add.xml
View file @
0b8348cf
...
...
@@ -14,15 +14,15 @@
android:layout_gravity=
"center_vertical"
android:layout_weight=
"1"
android:ellipsize=
"middle"
android:paddingStart=
"3
8
dp"
android:paddingTop=
"@
dimen/spacer_1x
"
android:paddingStart=
"3
0
dp"
android:paddingTop=
"@
null
"
android:paddingEnd=
"@dimen/widget_note_list_outer_padding"
android:paddingBottom=
"@dimen/spacer_1x"
android:singleLine=
"true"
android:textColor=
"@color/widget_foreground"
android:textSize=
"1
4
sp"
android:textSize=
"1
6
sp"
android:textStyle=
"bold"
tools:text=
"@string/
widget_note_list_add
"
/>
tools:text=
"@string/
app_name
"
/>
<ImageView
...
...
@@ -32,7 +32,8 @@
android:layout_gravity=
"center_vertical"
android:contentDescription=
"@string/widget_entry_fav_contentDescription"
android:foregroundGravity=
"center_vertical"
android:paddingStart=
"@dimen/widget_note_list_inner_padding"
android:paddingEnd=
"12dp"
android:paddingStart=
"@dimen/spacer_1x"
android:paddingEnd=
"@dimen/spacer_1x"
android:paddingBottom=
"@dimen/spacer_1hx"
app:srcCompat=
"@drawable/ic_add_blue_24dp"
/>
</LinearLayout>
app/src/main/res/layout/widget_note_list.xml
View file @
0b8348cf
...
...
@@ -4,7 +4,11 @@
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:background=
"@drawable/widget_background"
android:orientation=
"vertical"
>
android:orientation=
"vertical"
android:paddingStart=
"@dimen/spacer_1x"
android:paddingTop=
"@dimen/spacer_1x"
android:paddingEnd=
"@dimen/spacer_1hx"
android:paddingBottom=
"@dimen/spacer_1x"
>
<ListView
android:id=
"@+id/note_list_widget_lv"
...
...
app/src/main/res/values/strings.xml
View file @
0b8348cf
...
...
@@ -82,9 +82,6 @@
<string
name=
"about_license_tab_title"
>
License
</string>
<string
name=
"widget_note_list_title"
>
Note list
</string>
<string
name=
"widget_note_list_add"
>
Add new note
</string>
<string
name=
"widget_note_list_add_favorite"
>
Add new note to favorites
</string>
<string
name=
"widget_note_list_add_to_category"
>
Add new note to %1$s
</string>
<string
name=
"widget_note_list_placeholder"
>
No notes
</string>
<string
name=
"widget_single_note_title"
>
Single note
</string>
<string
name=
"widget_single_note_placeholder_tv"
>
Note not found
</string>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment