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
9c3023b7
Commit
9c3023b7
authored
Mar 12, 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
1903c4c8
Changes
4
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidgetFactory.java
View file @
9c3023b7
package
it.niedermann.owncloud.notes.widget.notelist
;
import
android.app.PendingIntent
;
import
android.appwidget.AppWidgetManager
;
import
android.content.ComponentName
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.net.Uri
;
...
...
@@ -9,6 +11,7 @@ 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
;
...
...
@@ -19,6 +22,7 @@ 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
;
import
it.niedermann.owncloud.notes.shared.model.Category
;
import
it.niedermann.owncloud.notes.shared.model.DBNote
;
...
...
@@ -96,7 +100,20 @@ public class NoteListWidgetFactory implements RemoteViewsService.RemoteViewsFact
if
(
position
==
0
)
{
final
LocalAccount
localAccount
=
db
.
getAccount
(
data
.
getAccountId
());
final
Intent
fillInIntent
=
new
Intent
();
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
Bundle
extras
=
new
Bundle
();
String
category
=
null
;
...
...
@@ -108,11 +125,11 @@ public class NoteListWidgetFactory implements RemoteViewsService.RemoteViewsFact
extras
.
putSerializable
(
PARAM_CATEGORY
,
new
Category
(
category
,
data
.
getMode
()
==
MODE_DISPLAY_STARRED
));
extras
.
putLong
(
EditNoteActivity
.
PARAM_ACCOUNT_ID
,
data
.
getAccountId
());
fillIn
Intent
.
putExtras
(
extras
);
fillIn
Intent
.
setData
(
Uri
.
parse
(
fillIn
Intent
.
toUri
(
Intent
.
URI_INTENT_SCHEME
)));
create
Intent
.
putExtras
(
extras
);
create
Intent
.
setData
(
Uri
.
parse
(
create
Intent
.
toUri
(
Intent
.
URI_INTENT_SCHEME
)));
note_content
=
new
RemoteViews
(
context
.
getPackageName
(),
R
.
layout
.
widget_entry_add
);
note_content
.
setOnClickFillInIntent
(
R
.
id
.
widget_
note_list_entry
,
fillIn
Intent
);
note_content
.
setOnClickFillInIntent
(
R
.
id
.
widget_
entry_fav_icon
,
create
Intent
);
note_content
.
setTextViewText
(
R
.
id
.
widget_entry_content_tv
,
getAddButtonText
(
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
())
...
...
@@ -150,16 +167,14 @@ public class NoteListWidgetFactory implements RemoteViewsService.RemoteViewsFact
private
static
String
getAddButtonText
(
@NonNull
Context
context
,
int
displayMode
,
String
category
)
{
switch
(
displayMode
)
{
case
MODE_DISPLAY_STARRED:
return
context
.
getString
(
R
.
string
.
widget_note_list_add
_favorite
);
return
context
.
getString
(
R
.
string
.
label
_favorite
s
);
case
MODE_DISPLAY_CATEGORY:
if
(
""
.
equals
(
category
))
{
return
context
.
getString
(
R
.
string
.
widget_note_list_add
);
}
else
{
return
context
.
getString
(
R
.
string
.
widget_note_list_add_to_category
,
category
);
}
return
""
.
equals
(
category
)
?
context
.
getString
(
R
.
string
.
action_uncategorized
)
:
category
;
case
MODE_DISPLAY_ALL:
default
:
return
context
.
getString
(
R
.
string
.
widget_note_list_add
);
return
context
.
getString
(
R
.
string
.
app_name
);
}
}
...
...
app/src/main/res/layout/widget_entry_add.xml
View file @
9c3023b7
...
...
@@ -5,33 +5,34 @@
android:id=
"@+id/widget_note_list_entry"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:orientation=
"horizontal"
android:padding=
"@dimen/spacer_1x"
>
<ImageView
android:id=
"@+id/widget_entry_fav_icon"
android:layout_width=
"@dimen/widget_note_list_fav_icon_width"
android:layout_height=
"@dimen/widget_note_list_fav_icon_height"
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=
"@dimen/widget_note_list_outer_padding"
app:srcCompat=
"@drawable/ic_add_blue_24dp"
/>
android:orientation=
"horizontal"
>
<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=
"middle"
android:
gravity=
"center_vertical
"
android:padding
Start
=
"@dimen/
widget_note_list_inner_padding
"
android:
paddingStart=
"38dp
"
android:padding
Top
=
"@dimen/
spacer_1x
"
android:paddingEnd=
"@dimen/widget_note_list_outer_padding"
android:paddingBottom=
"@dimen/spacer_1x"
android:singleLine=
"true"
android:textColor=
"@color/widget_foreground"
android:textSize=
"14sp"
android:textStyle=
"bold"
tools:text=
"@string/widget_note_list_add"
/>
<ImageView
android:id=
"@+id/widget_entry_fav_icon"
android:layout_width=
"40dp"
android:layout_height=
"match_parent"
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"
app:srcCompat=
"@drawable/ic_add_blue_24dp"
/>
</LinearLayout>
app/src/main/res/layout/widget_note_list.xml
View file @
9c3023b7
...
...
@@ -10,8 +10,8 @@
android:id=
"@+id/note_list_widget_lv"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:divider=
"@
color/widget_divider
"
android:dividerHeight=
"@
dimen/widget_divider
"
android:divider=
"@
android:color/transparent
"
android:dividerHeight=
"@
null
"
android:textAppearance=
"?android:attr/textAppearanceMedium"
tools:listitem=
"@layout/widget_entry"
/>
...
...
app/src/main/res/values/dimens.xml
View file @
9c3023b7
...
...
@@ -42,6 +42,7 @@
<dimen
name=
"widget_note_list_outer_padding"
>
4dp
</dimen>
<dimen
name=
"widget_note_list_inner_padding"
>
4dp
</dimen>
<dimen
name=
"widget_note_list_entry_add_button"
>
34dp
</dimen>
<dimen
name=
"widget_note_list_fav_icon_width"
>
26dp
</dimen>
<dimen
name=
"widget_note_list_fav_icon_height"
>
20dp
</dimen>
</resources>
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