Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 723f843f authored by Stefan Niedermann's avatar Stefan Niedermann
Browse files

Prototype of Single Note Widget

parent ef9f7035
Loading
Loading
Loading
Loading
+21 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
        android:supportsRtl="true"
        android:theme="@style/OwnCloud"
        >
        <!-- Apps -->
        <activity
            android:name="it.niedermann.owncloud.notes.android.activity.NotesListViewActivity"
            android:label="@string/app_name" >
@@ -58,6 +59,25 @@
            android:label="@string/menu_about"
            android:parentActivityName="it.niedermann.owncloud.notes.android.activity.NotesListViewActivity" >
        </activity>
    </application>

        <!-- Widget -->

        <receiver android:name="it.niedermann.owncloud.notes.android.widget.SingleNoteWidget">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
            </intent-filter>

            <meta-data
                android:name="android.appwidget.provider"
                android:resource="@xml/single_note_widget_provider_info" />
        </receiver>

        <activity
            android:name="it.niedermann.owncloud.notes.android.activity.SelectSingleNoteActivity"
            android:label="@string/action_select_note">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
            </intent-filter>
        </activity>
    </application>
</manifest>
 No newline at end of file
+89 −0
Original line number Diff line number Diff line
package it.niedermann.owncloud.notes.android.activity;

import android.appwidget.AppWidgetManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.RemoteViews;

import java.util.List;

import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.android.widget.SingleNoteWidget;
import it.niedermann.owncloud.notes.model.Note;
import it.niedermann.owncloud.notes.model.NoteAdapter;
import it.niedermann.owncloud.notes.persistence.NoteSQLiteOpenHelper;

/**
 * Configuration Activity to select a single note which should be displayed in the SingleNoteWidget
 * Created by stefan on 08.10.15.
 */
public class SelectSingleNoteActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {

    int appWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
    private NoteSQLiteOpenHelper db = null;
    private ListView listView = null;
    private NoteAdapter adapter = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setResult(RESULT_CANCELED);
        setContentView(R.layout.activity_select_single_note);

        Log.v("NoteWidget", "In Config Activity");
        // Display Data
        db = new NoteSQLiteOpenHelper(this);
        db.synchronizeWithServer();
        Log.v("NoteWidget", "Databasename: " + db.getDatabaseName());
        setListView(db.getNotes());


        Intent intent = getIntent();
        Bundle extras = intent.getExtras();
        if (extras != null) {
            appWidgetId = extras.getInt(
                    AppWidgetManager.EXTRA_APPWIDGET_ID,
                    AppWidgetManager.INVALID_APPWIDGET_ID);
        }

        // If they gave us an intent without the widget id, just bail.
        if (appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
            finish();
        }
    }

    /**
     * Allows other classes to set a List of Notes.
     *
     * @param noteList List&lt;Note&gt;
     */
    private void setListView(List<Note> noteList) {
        adapter = new NoteAdapter(getApplicationContext(), noteList);
        listView = (ListView) findViewById(R.id.select_single_note_list_view);
        listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(this);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        final Context context = SelectSingleNoteActivity.this;

        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);

        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_single_note);
        appWidgetManager.updateAppWidget(appWidgetId, views);
        SingleNoteWidget.updateAppWidget(adapter.getItem(position), context, appWidgetManager, appWidgetId);

        Intent resultValue = new Intent();
        resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        setResult(RESULT_OK, resultValue);
        finish();
    }
}
+8 −0
Original line number Diff line number Diff line
package it.niedermann.owncloud.notes.android.widget;

/**
 * Widget to display a List of all notes
 * Created by stefan on 08.10.15.
 */
public class AllNotesWidget {
}
+48 −0
Original line number Diff line number Diff line
package it.niedermann.owncloud.notes.android.widget;

import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.text.Html;
import android.util.Log;
import android.widget.RemoteViews;

import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.android.activity.NoteActivity;
import it.niedermann.owncloud.notes.android.activity.NotesListViewActivity;
import it.niedermann.owncloud.notes.model.Note;

/**
 * Widget which displays a single selected note.
 * Created by stefan on 08.10.15.
 */
public class SingleNoteWidget extends AppWidgetProvider {
    public static void updateAppWidget(Note note, Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
        RemoteViews updateViews = new RemoteViews(context.getPackageName(), R.layout.widget_single_note);
        if (note != null) {
            updateViews.setTextViewText(R.id.singleNoteContent, Html.fromHtml(note.getHtmlContent()));
        }
        appWidgetManager.updateAppWidget(appWidgetId, updateViews);

        //FIXME does not work!
        Intent intent = new Intent(context, NoteActivity.class);
        intent.putExtra(NotesListViewActivity.SELECTED_NOTE, note);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
        updateViews.setOnClickPendingIntent(R.id.singleNoteContent, pendingIntent);
    }

    @Override
    public void onEnabled(Context context) {
    }

    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
        for (int i : appWidgetIds) {
            int appWidgetId = appWidgetIds[i];
            Log.v("SingleNoteWidget", "onUpdate appWidgetId: " + appWidgetId);
            updateAppWidget(null, context, appWidgetManager, appWidgetId);
        }
    }
}
 No newline at end of file
+10 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ListView
        android:id="@+id/select_single_note_list_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</LinearLayout>
 No newline at end of file
Loading