-
-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef9f703
commit 723f843
Showing
9 changed files
with
203 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...src/main/java/it/niedermann/owncloud/notes/android/activity/SelectSingleNoteActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
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<Note> | ||
*/ | ||
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 changes: 8 additions & 0 deletions
8
app/src/main/java/it/niedermann/owncloud/notes/android/widget/AllNotesWidget.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
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 changes: 48 additions & 0 deletions
48
app/src/main/java/it/niedermann/owncloud/notes/android/widget/SingleNoteWidget.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical"> | ||
|
||
<TextView | ||
android:id="@+id/singleNoteContent" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:background="@color/bg_highlighted" | ||
android:padding="10dp" | ||
android:textAppearance="?android:attr/textAppearanceMedium" | ||
android:textColor="@color/fg_default" /> | ||
|
||
</FrameLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:configure="it.niedermann.owncloud.notes.android.activity.SelectSingleNoteActivity" | ||
android:initialLayout="@layout/widget_single_note" | ||
android:minHeight="72dp" | ||
android:minWidth="146dp" | ||
android:resizeMode="horizontal|vertical" | ||
android:updatePeriodMillis="86400000" | ||
android:widgetCategory="keyguard|home_screen" /> |