Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.RemoteViews;

import it.niedermann.owncloud.notes.R;
Expand All @@ -15,8 +14,8 @@
*/
public class CreateNoteWidget extends AppWidgetProvider {

static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
int appWidgetId) {
private static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
int appWidgetId) {

// Construct the RemoteViews object
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_create_note);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

public class NoteListWidget extends AppWidgetProvider {

static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
int appWidgetId) {
private static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
int appWidgetId) {
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_note_list);

// Launch application when user taps the header icon or app title
Expand Down Expand Up @@ -58,7 +58,7 @@ static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
serviceIntent.setData(Uri.parse(serviceIntent.toUri(Intent.URI_INTENT_SCHEME)));
views.setPendingIntentTemplate(R.id.note_list_widget_lv, templatePI);
views.setRemoteAdapter(R.id.note_list_widget_lv, serviceIntent);
views.setEmptyView(R.id.note_list_widget_lv, R.id.widget_entry_content_tv);
views.setEmptyView(R.id.note_list_widget_lv, R.id.widget_note_list_placeholder_tv);

appWidgetManager.updateAppWidget(appWidgetId, views);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] a

PendingIntent templatePendingIntent = PendingIntent.getActivity(
context,
0,
appWidgetId,
templateIntent,
PendingIntent.FLAG_UPDATE_CURRENT);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package it.niedermann.owncloud.notes.model;

import android.appwidget.AppWidgetManager;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
Expand All @@ -20,15 +19,12 @@
*/

public class NoteListWidgetFactory implements RemoteViewsService.RemoteViewsFactory {
private Context mContext;
private int mAppWidgetId;
private final Context mContext;
private NoteSQLiteOpenHelper db;
private List<DBNote> dbNotes;

public NoteListWidgetFactory(Context context, Intent intent) {
mContext = context;
mAppWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
}

@Override
Expand All @@ -55,6 +51,10 @@ public void onDestroy() {
*/
@Override
public int getCount() {
if (dbNotes == null) {
return 0;
}

return dbNotes.size();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@
import it.niedermann.owncloud.notes.persistence.NoteSQLiteOpenHelper;

public class SingleNoteWidgetFactory implements RemoteViewsService.RemoteViewsFactory {
private Context mContext;
private int mAppWidgetId;

private final Context mContext;
private final int mAppWidgetId;

private NoteSQLiteOpenHelper db;
private DBNote note;

private static final String TAG = SingleNoteWidget.class.getSimpleName();

public SingleNoteWidgetFactory(Context context, Intent intent) {
Expand All @@ -28,14 +33,15 @@ public SingleNoteWidgetFactory(Context context, Intent intent) {

@Override
public void onCreate() {

db = NoteSQLiteOpenHelper.getInstance(mContext);
}

@Override
public boolean hasStableIds() {
return true;
}

// TODO Set loading view
@Override
public RemoteViews getLoadingView() {
return null;
Expand All @@ -48,7 +54,16 @@ public int getViewTypeCount() {

@Override
public void onDataSetChanged() {
SharedPreferences sharedprefs = PreferenceManager.getDefaultSharedPreferences(mContext);
long noteID = sharedprefs.getLong(SingleNoteWidget.WIDGET_KEY + mAppWidgetId, -1);

if (noteID >= 0) {
note = db.getNote(noteID);

if (note == null) {
Log.e(TAG, "Error: note not found");
}
}
}

@Override
Expand All @@ -57,48 +72,37 @@ public void onDestroy() {
}

/**
* getCount() always runs 1 because the list view only ever has a
* single note displayed
* @return
* Returns the number of items in the data set. In this case, always 1 as a single note is
* being displayed. Will return 0 when the note can't be displayed.
*/
@Override
public int getCount() {
return 1;
return (note != null) ? 1 : 0;
}

/**
* getViewAt - Returns a RemoteView containing the note content in a TextView and
* a fillInIntent to handle the user tapping on the item in the list
* view.
* Returns a RemoteView containing the note content in a TextView and
* a fillInIntent to handle the user tapping on the item in the list view.
*
* @param position The position of the item in the list
* @return The RemoteView at the specified position in the list
*/
@Override
public RemoteViews getViewAt(int position) {
if (note == null) {
return null;
}

RemoteViews note_content = new RemoteViews(mContext.getPackageName(),
R.layout.widget_single_note_content);

SharedPreferences sharedprefs = PreferenceManager.getDefaultSharedPreferences(mContext);
long noteID = sharedprefs.getLong(SingleNoteWidget.WIDGET_KEY + mAppWidgetId, -1);

if (noteID >= 0) {
NoteSQLiteOpenHelper db = NoteSQLiteOpenHelper.getInstance(mContext);
DBNote note = db.getNote(noteID);

final Intent fillInIntent = new Intent();
final Bundle extras = new Bundle();

extras.putSerializable(EditNoteActivity.PARAM_NOTE, note);

fillInIntent.putExtras(extras);
fillInIntent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
note_content.setOnClickFillInIntent(R.id.single_note_content_tv, fillInIntent);
note_content.setTextViewText(R.id.single_note_content_tv, note.getContent());
} else {
Log.e(TAG, "Note not found");
note_content.setTextViewText(R.id.single_note_content_tv, "Note not found");
}
final Intent fillInIntent = new Intent();
final Bundle extras = new Bundle();

extras.putSerializable(EditNoteActivity.PARAM_NOTE, note);
fillInIntent.putExtras(extras);
fillInIntent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
note_content.setOnClickFillInIntent(R.id.single_note_content_tv, fillInIntent);
note_content.setTextViewText(R.id.single_note_content_tv, note.getContent());

return note_content;
}
Expand Down
Binary file modified app/src/main/res/drawable/note_list_widget_preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions app/src/main/res/layout/widget_create_note.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
android:layout_gravity="center_vertical"
android:clickable="true"
android:orientation="vertical"
android:padding="@dimen/widget_margin">
android:padding="@dimen/widget_margin"
android:focusable="true">

<ImageView
android:id="@+id/ivCreateNoteBadge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:background="@drawable/ic_widget_create" />
android:background="@drawable/ic_widget_create"
android:contentDescription="@string/widget_create_note" />
</LinearLayout>
23 changes: 14 additions & 9 deletions app/src/main/res/layout/widget_entry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,34 @@
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="horizontal"
android:padding="4dp">
android:padding="@dimen/widget_note_list_padding">

<TextView
android:id="@+id/widget_entry_content_tv"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="match_parent"
android:paddingLeft="6dp"
android:paddingStart="@dimen/widget_note_list_outer_padding"
android:paddingEnd="@dimen/widget_note_list_inner_padding"
android:paddingLeft="@dimen/widget_note_list_outer_padding"
android:paddingRight="@dimen/widget_note_list_inner_padding"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:layout_weight="1"
android:textColor="@color/fg_default"
android:lines="1"
android:ellipsize="end"
/>
android:ellipsize="end" />

<ImageView
android:id="@+id/widget_entry_fav_icon"
android:layout_width="26dp"
android:layout_height="20dp"
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:foregroundGravity="center_vertical"
android:paddingRight="6dp"
android:paddingStart="@dimen/widget_note_list_inner_padding"
android:paddingEnd="@dimen/widget_note_list_outer_padding"
android:paddingLeft="@dimen/widget_note_list_inner_padding"
android:paddingRight="@dimen/widget_note_list_outer_padding"
android:src="@drawable/ic_star_grey600_24dp"
/>
android:contentDescription="@string/widget_entry_fav_contentDescription" />

</LinearLayout>
41 changes: 31 additions & 10 deletions app/src/main/res/layout/widget_note_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,29 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:orientation="vertical"
android:background="@color/widget_background">

<!-- Widget header -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="36dp"
android:layout_height="@dimen/widget_note_list_header_height"
android:background="@color/primary"
android:padding="2dp">
android:padding="@dimen/widget_note_list_hdr_padding">

<ImageView
android:id="@+id/widget_note_header_icon"
android:layout_width="30dp"
android:layout_width="@dimen/widget_note_list_icon_width"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:paddingLeft="6dp"/>
android:paddingStart="@dimen/widget_note_list_outer_padding"
android:paddingEnd="@dimen/widget_note_list_inner_padding"
android:paddingLeft="@dimen/widget_note_list_outer_padding"
android:paddingRight="@dimen/widget_note_list_inner_padding"
android:contentDescription="@string/widget_app_launcher_contentDescription" />

<TextView
android:id="@+id/widget_note_list_title"
Expand All @@ -29,17 +35,25 @@
android:textStyle="bold"
android:textSize="18sp"
android:layout_toRightOf="@id/widget_note_header_icon"
android:layout_toEndOf="@id/widget_note_header_icon"
android:gravity="center_vertical"
android:paddingLeft="6dp"
/>
android:paddingStart="@dimen/widget_note_list_outer_padding"
android:paddingEnd="@dimen/widget_note_list_inner_padding"
android:paddingLeft="@dimen/widget_note_list_outer_padding"
android:paddingRight="@dimen/widget_note_list_inner_padding" />

<ImageView
android:id="@+id/widget_note_list_create_icon"
android:layout_width="30dp"
android:layout_width="@dimen/widget_note_list_icon_width"
android:layout_height="match_parent"
android:src="@drawable/ic_action_new"
android:layout_alignParentRight="true"
android:paddingRight="6dp"/>
android:layout_alignParentEnd="true"
android:paddingStart="@dimen/widget_note_list_inner_padding"
android:paddingEnd="@dimen/widget_note_list_outer_padding"
android:paddingLeft="@dimen/widget_note_list_inner_padding"
android:paddingRight="@dimen/widget_note_list_outer_padding"
android:contentDescription="@string/widget_create_note" />

</RelativeLayout>
<!-- End header -->
Expand All @@ -48,8 +62,15 @@
android:id="@+id/note_list_widget_lv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/widget_background"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/fg_default" />

<TextView
android:id="@+id/widget_note_list_placeholder_tv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/widget_note_list_placeholder"
android:textColor="@color/fg_default_high" />

</LinearLayout>
15 changes: 9 additions & 6 deletions app/src/main/res/layout/widget_single_note.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,24 @@
android:id="@+id/widget_single_note"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
android:background="@color/widget_background">

<ListView
android:id="@+id/single_note_widget_lv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/widget_background"
android:padding="@dimen/widget_single_note_padding"
/>
android:padding="@dimen/widget_single_note_padding" />

<TextView
android:id="@+id/widget_single_note_placeholder_tv"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"/>
android:gravity="center"
android:text="@string/widget_single_note_placeholder_tv"
android:textColor="@color/fg_default_high"
android:textAlignment="center"
android:padding="@dimen/widget_single_note_padding" />

</RelativeLayout>
<!--
TODO: Markdown support
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/widget_single_note_content.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
android:id="@+id/single_note_content_tv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="@color/fg_default"
/>
14 changes: 10 additions & 4 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@
<dimen name="widget_single_note_padding">10dp</dimen>
<dimen name="widget_create_note_padding">0dp</dimen>

<!-- Used to pad each entry in the note list -->
<dimen name="widget_note_list_header_padding">4dp</dimen>
<dimen name="widget_note_list_entry_top_bottom">6dp</dimen>
<dimen name="widget_note_list_entry_sides">6dp</dimen>
<dimen name="widget_note_list_hdr_padding">2dp</dimen>
<dimen name="widget_note_list_padding">4dp</dimen>
<dimen name="widget_note_list_header_height">36dp</dimen>
<dimen name="widget_note_list_icon_width">30dp</dimen>

<dimen name="widget_note_list_outer_padding">6dp</dimen>
<dimen name="widget_note_list_inner_padding">0dp</dimen>

<dimen name="widget_note_list_fav_icon_width">26dp</dimen>
<dimen name="widget_note_list_fav_icon_height">20dp</dimen>
</resources>
Loading