Skip to content
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

Checkboxes in Widget #1912

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
63 changes: 31 additions & 32 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,21 @@
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:targetApi="n">
<receiver
android:name=".reciever.WidgetCheckboxReciever"
android:enabled="true"
android:exported="true" />

<activity
android:name=".main.MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.App.Starting"
android:exported="true">
android:theme="@style/Theme.App.Starting">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

<action android:name="android.intent.action.SEARCH" />
</intent-filter>

Expand All @@ -39,97 +45,94 @@
android:name="android.app.default_searchable"
android:value=".android.activity.NotesListViewActivity" />
</activity>

<activity
android:name=".importaccount.ImportAccountActivity"
android:label="@string/add_account" />

<activity
android:name=".AppendToNoteActivity"
android:label="@string/append_to_note"
android:exported="true">
android:exported="true"
android:label="@string/append_to_note">
<intent-filter>
<action android:name="android.intent.action.SEND" />

<category android:name="android.intent.category.DEFAULT" />

<data android:mimeType="text/*" />
</intent-filter>
</activity>

<activity
android:name=".exception.ExceptionActivity"
android:label="@string/app_name" />

<activity
android:name=".FormattingHelpActivity"
android:label="@string/action_formatting_help"
android:parentActivityName=".main.MainActivity"
android:windowSoftInputMode="stateHidden" />

<activity
android:name=".manageaccounts.ManageAccountsActivity"
android:label="@string/manage_accounts"
android:parentActivityName=".main.MainActivity"
android:windowSoftInputMode="stateHidden" />

<activity
android:name=".preferences.PreferencesActivity"
android:label="@string/action_settings"
android:parentActivityName=".main.MainActivity"
android:windowSoftInputMode="stateHidden" />

<activity
android:name=".edit.EditNoteActivity"
android:exported="true"
android:label="@string/simple_edit"
android:launchMode="singleTask"
android:parentActivityName=".main.MainActivity"
android:windowSoftInputMode="stateHidden"
android:exported="true">
android:windowSoftInputMode="stateHidden">
<intent-filter android:label="@string/action_create">
<action android:name="android.intent.action.SEND" />

<category android:name="android.intent.category.DEFAULT" />

<data android:mimeType="text/plain" />
</intent-filter>
<!-- Voice command "note to self" in google search -->
<intent-filter android:label="@string/action_create">
<action android:name="com.google.android.gm.action.AUTO_SEND" />

<category android:name="android.intent.category.DEFAULT" />

<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter android:label="@string/app_name">
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />

<data android:scheme="content" />
<data android:host="*" />
<data android:mimeType="text/*" />
</intent-filter>
</activity>

<activity
android:name=".about.AboutActivity"
android:label="@string/simple_about"
android:parentActivityName=".main.MainActivity" />

<activity android:name=".widget.singlenote.SingleNoteWidgetConfigurationActivity"
<activity
android:name=".widget.singlenote.SingleNoteWidgetConfigurationActivity"
android:exported="true">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
</intent-filter>
</activity>

<activity android:name=".widget.notelist.NoteListWidgetConfigurationActivity"
<activity
android:name=".widget.notelist.NoteListWidgetConfigurationActivity"
android:exported="true">

<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
</intent-filter>
</activity>

<receiver
android:name=".widget.singlenote.SingleNoteWidget"
android:label="@string/widget_single_note_title"
android:exported="true">

android:exported="true"
android:label="@string/widget_single_note_title">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
Expand All @@ -138,12 +141,10 @@
android:name="android.appwidget.provider"
android:resource="@xml/single_note_widget_provider_info" />
</receiver>

<receiver
android:name=".widget.notelist.NoteListWidget"
android:label="@string/widget_note_list_title"
android:exported="true">

android:exported="true"
android:label="@string/widget_note_list_title">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
Expand All @@ -156,22 +157,20 @@
<service
android:name=".widget.singlenote.SingleNoteWidgetService"
android:permission="android.permission.BIND_REMOTEVIEWS" />

<service
android:name=".widget.notelist.NoteListWidgetService"
android:permission="android.permission.BIND_REMOTEVIEWS" />

<service
android:name=".quicksettings.NewNoteTileService"
android:description="@string/action_create"
android:exported="true"
android:icon="@drawable/ic_launcher_foreground_full"
android:label="@string/action_create"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE"
android:exported="true">
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE" />
</intent-filter>
</service>

</application>
</manifest>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package it.niedermann.owncloud.notes.reciever

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.util.Log

class WidgetCheckboxReciever : BroadcastReceiver() {

override fun onReceive(context: Context, intent: Intent) {
// This method is called when the BroadcastReceiver is receiving an Intent broadcast.
Log.e("RECIEVER", "Action: ${intent.action}")
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
package it.niedermann.owncloud.notes.widget.singlenote;

import static it.niedermann.android.markdown.remoteviews.RemoteViewElement.TYPE_CHECKBOX_CHECKED;
import static it.niedermann.android.markdown.remoteviews.RemoteViewElement.TYPE_CHECKBOX_UNCHECKED;
import static it.niedermann.android.markdown.remoteviews.RemoteViewElement.TYPE_TEXT;

import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.RemoteViews;
import android.widget.RemoteViewsService;
import android.widget.TextView;

import androidx.annotation.Nullable;

import java.util.ArrayList;

import it.niedermann.android.markdown.MarkdownUtil;
import it.niedermann.android.markdown.remoteviews.RemoteViewElement;
import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.edit.EditNoteActivity;
import it.niedermann.owncloud.notes.persistence.NotesRepository;
import it.niedermann.owncloud.notes.persistence.entity.Note;
import it.niedermann.owncloud.notes.persistence.entity.SingleNoteWidgetData;
import it.niedermann.owncloud.notes.reciever.WidgetCheckboxReciever;

public class SingleNoteWidgetFactory implements RemoteViewsService.RemoteViewsFactory {

Expand All @@ -26,6 +38,8 @@ public class SingleNoteWidgetFactory implements RemoteViewsService.RemoteViewsFa
@Nullable
private Note note;

private ArrayList<RemoteViewElement> noteElements = new ArrayList<>();

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

SingleNoteWidgetFactory(Context context, Intent intent) {
Expand Down Expand Up @@ -53,6 +67,7 @@ public void onDataSetChanged() {
} else {
Log.w(TAG, "Widget with ID " + appWidgetId + " seems to be not configured yet.");
}
noteElements = MarkdownUtil.getRenderedElementsForRemoteView(context, note.getContent());
}

@Override
Expand All @@ -66,7 +81,7 @@ public void onDestroy() {
*/
@Override
public int getCount() {
return (note != null) ? 1 : 0;
return (note != null) ? this.noteElements.size() : 0;
}

/**
Expand All @@ -89,9 +104,29 @@ public RemoteViews getViewAt(int position) {
args.putLong(EditNoteActivity.PARAM_ACCOUNT_ID, note.getAccountId());
fillInIntent.putExtras(args);

var item = noteElements.get(position);

final var note_content = new RemoteViews(context.getPackageName(), R.layout.widget_single_note_content);
note_content.setOnClickFillInIntent(R.id.single_note_content_tv, fillInIntent);
note_content.setTextViewText(R.id.single_note_content_tv, MarkdownUtil.renderForRemoteView(context, note.getContent()));
var content = item.getCurrentLineBlock();
int type = item.getType();


if (type == TYPE_TEXT || Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
note_content.setOnClickFillInIntent(R.id.single_note_content_tv, fillInIntent);
note_content.setTextViewText(R.id.single_note_content_tv, MarkdownUtil.renderForRemoteView(context, content).toString().trim());
note_content.setViewVisibility(R.id.single_note_content_tv, View.VISIBLE);
}

if (type == TYPE_CHECKBOX_CHECKED || type == TYPE_CHECKBOX_UNCHECKED ) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
note_content.setTextViewText(R.id.single_note_content_cb, content);
if(type == TYPE_CHECKBOX_CHECKED) {
note_content.setCompoundButtonChecked(R.id.single_note_content_cb, true);
}
note_content.setViewVisibility(R.id.single_note_content_cb, View.VISIBLE);
note_content.setOnClickPendingIntent(R.id.single_note_content_cb, getPendingIntent());
}
}

return note_content;
}
Expand All @@ -117,4 +152,12 @@ public long getItemId(int position) {
public boolean hasStableIds() {
return true;
}

private PendingIntent getPendingIntent() {
Intent checkboxIntent = new Intent(context, WidgetCheckboxReciever.class);
checkboxIntent.setAction("toggle");
return PendingIntent.getBroadcast(context, 0, checkboxIntent, PendingIntent.FLAG_IMMUTABLE);

}

}
25 changes: 25 additions & 0 deletions app/src/main/res/layout-v31/widget_single_note_content.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:id="@+id/single_note_content_tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lineSpacingMultiplier="@dimen/note_line_spacing"
android:textColor="@color/widget_foreground"
android:visibility="gone"
tools:text="@tools:sample/lorem/random" />

<CheckBox
android:id="@+id/single_note_content_cb"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:visibility="gone"
android:text="CheckBox" />

</LinearLayout>
2 changes: 2 additions & 0 deletions app/src/main/res/layout/widget_single_note.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
android:layout_height="match_parent"
android:paddingVertical="@dimen/widget_inner_padding_vertical"
android:paddingHorizontal="@dimen/widget_inner_padding_horizontal"
android:dividerHeight="0dp"
android:divider="@null"
tools:listitem="@layout/widget_single_note_content" />

<TextView
Expand Down
14 changes: 11 additions & 3 deletions app/src/main/res/layout/widget_single_note_content.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:id="@+id/single_note_content_tv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:lineSpacingMultiplier="@dimen/note_line_spacing"
android:textColor="@color/widget_foreground"
android:visibility="gone"
tools:text="@tools:sample/lorem/random" />

</LinearLayout>
Loading