mirror of
https://github.com/nextcloud/notes-android.git
synced 2024-11-28 19:39:07 +03:00
Create Note Widget
Addition of "Create Note" widget as referenced in https://github.com/stefan-niedermann/nextcloud-notes/issues/15.
This commit is contained in:
parent
22cb23b68a
commit
141a3373f3
12 changed files with 127 additions and 2 deletions
|
@ -82,5 +82,16 @@
|
|||
android:parentActivityName="it.niedermann.owncloud.notes.android.activity.NotesListViewActivity"
|
||||
/>
|
||||
|
||||
<receiver android:name=".android.activity.CreateNoteWidget"
|
||||
android:label="@string/widget_create_note">
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||
</intent-filter>
|
||||
|
||||
<meta-data
|
||||
android:name="android.appwidget.provider"
|
||||
android:resource="@xml/create_note_widget_provider" />
|
||||
</receiver>
|
||||
</application>
|
||||
</manifest>
|
|
@ -13,15 +13,24 @@ import com.yydcdut.rxmarkdown.factory.EditFactory;
|
|||
|
||||
import it.niedermann.owncloud.notes.R;
|
||||
import it.niedermann.owncloud.notes.persistence.NoteSQLiteOpenHelper;
|
||||
import it.niedermann.owncloud.notes.persistence.NoteServerSyncHelper;
|
||||
import it.niedermann.owncloud.notes.util.MarkDownUtil;
|
||||
import rx.Subscriber;
|
||||
|
||||
public class CreateNoteActivity extends AppCompatActivity {
|
||||
private final static int server_settings = 2;
|
||||
|
||||
private RxMDEditText editTextField = null;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (!NoteServerSyncHelper.isConfigured(this)) {
|
||||
Intent settingsIntent = new Intent(this, SettingsActivity.class);
|
||||
startActivityForResult(settingsIntent, server_settings);
|
||||
}
|
||||
|
||||
setContentView(R.layout.activity_create);
|
||||
editTextField = (RxMDEditText) findViewById(R.id.createContent);
|
||||
|
||||
|
@ -94,10 +103,22 @@ public class CreateNoteActivity extends AppCompatActivity {
|
|||
String content = editTextField.getText().toString();
|
||||
if(!implicit || !content.isEmpty()) {
|
||||
NoteSQLiteOpenHelper db = NoteSQLiteOpenHelper.getInstance(this);
|
||||
Intent data = new Intent();
|
||||
Intent data = new Intent(this, NotesListViewActivity.class);
|
||||
data.putExtra(NotesListViewActivity.CREATED_NOTE, db.getNote(db.addNoteAndSync(content)));
|
||||
setResult(RESULT_OK, data);
|
||||
}
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
if (requestCode == server_settings) {
|
||||
if (resultCode != RESULT_OK) {
|
||||
// User has not setup the server config and no note can be created
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package it.niedermann.owncloud.notes.android.activity;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.appwidget.AppWidgetManager;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Implementation of App Widget functionality.
|
||||
*/
|
||||
public class CreateNoteWidget extends AppWidgetProvider {
|
||||
|
||||
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
|
||||
int appWidgetId) {
|
||||
|
||||
// Construct the RemoteViews object
|
||||
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_create_note);
|
||||
Intent intent = new Intent(context, CreateNoteActivity.class);
|
||||
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
views.setOnClickPendingIntent(R.id.widget_create_note, pendingIntent);
|
||||
|
||||
// Instruct the widget manager to update the widget
|
||||
appWidgetManager.updateAppWidget(appWidgetId, views);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
||||
|
||||
// There may be multiple widgets active, so update all of them
|
||||
for (int appWidgetId : appWidgetIds) {
|
||||
updateAppWidget(context, appWidgetManager, appWidgetId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnabled(Context context) {
|
||||
// Enter relevant functionality for when the first widget is created
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisabled(Context context) {
|
||||
// Enter relevant functionality for when the last widget is disabled
|
||||
}
|
||||
}
|
||||
|
|
@ -164,6 +164,18 @@ public class SettingsActivity extends AppCompatActivity {
|
|||
password_wrapper.setHint(getString(unchangedHint ? R.string.settings_password_unchanged : R.string.settings_password));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
// Occurs in this scenario: User opens the app but doesn't configure the server settings, they then add the Create Note widget to home screen and configure
|
||||
// server settings there. The stale SettingsActivity is then displayed hence finish() here to close it down.
|
||||
if ((first_run) && (NoteServerSyncHelper.isConfigured(this))) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent pressing back button on first run
|
||||
*/
|
||||
|
|
BIN
app/src/main/res/drawable-hdpi/ic_widget_create.png
Normal file
BIN
app/src/main/res/drawable-hdpi/ic_widget_create.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
BIN
app/src/main/res/drawable-mdpi/ic_widget_create.png
Normal file
BIN
app/src/main/res/drawable-mdpi/ic_widget_create.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 817 B |
BIN
app/src/main/res/drawable-xhdpi/ic_widget_create.png
Normal file
BIN
app/src/main/res/drawable-xhdpi/ic_widget_create.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
BIN
app/src/main/res/drawable-xxhdpi/ic_widget_create.png
Normal file
BIN
app/src/main/res/drawable-xxhdpi/ic_widget_create.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.3 KiB |
16
app/src/main/res/layout/widget_create_note.xml
Normal file
16
app/src/main/res/layout/widget_create_note.xml
Normal file
|
@ -0,0 +1,16 @@
|
|||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/widget_create_note"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:clickable="true"
|
||||
android:orientation="vertical"
|
||||
android:padding="@dimen/widget_margin">
|
||||
|
||||
<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" />
|
||||
</LinearLayout>
|
|
@ -9,4 +9,5 @@
|
|||
<dimen name="button_padding">16dp</dimen>
|
||||
<dimen name="button_elevation">5dp</dimen>
|
||||
|
||||
<dimen name="widget_margin">0dp</dimen>
|
||||
</resources>
|
||||
|
|
|
@ -113,6 +113,7 @@
|
|||
|
||||
<string name="widget_all_notes_title">All notes</string>
|
||||
<string name="widget_single_note_title">Single note</string>
|
||||
<string name="widget_create_note">Create Note</string>
|
||||
|
||||
<!-- Shortcuts -->
|
||||
<string name="shortcut_create_long">Create a new note</string>
|
||||
|
|
12
app/src/main/res/xml/create_note_widget_provider.xml
Normal file
12
app/src/main/res/xml/create_note_widget_provider.xml
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:initialKeyguardLayout="@layout/widget_create_note"
|
||||
android:initialLayout="@layout/widget_create_note"
|
||||
android:minHeight="40dp"
|
||||
android:minWidth="40dp"
|
||||
android:previewImage="@drawable/ic_widget_create"
|
||||
android:updatePeriodMillis="86400000"
|
||||
android:widgetCategory="home_screen"
|
||||
android:text="@string/widget_create_note"
|
||||
android:resizeMode="none">
|
||||
</appwidget-provider>
|
Loading…
Reference in a new issue