diff --git a/README.md b/README.md index 201d284..70b02bd 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,11 @@ A simple note widget for Android Based on [Jot by hellos3b](https://play.google.com/store/apps/details?id=com.simplidget.jot). I decided to make my own to be more customizable so it can better fit my homescreen styling. +Using the [color picker from martin-stone](https://github.com/martin-stone/hsv-alpha-color-picker-android) under the [Apache 2.0 license](http://www.apache.org/licenses/LICENSE-2.0), Copyright 2015 Martin Stone. + ## To do: 1. ~~Load and save a multi-line plain text message.~~ 2. ~~Create a flexible launcher widget to display the message.~~ 3. ~~Create an icon and widget preview.~~ -4. Extend functionality by adding appearance customization options. -5. Consider publishing on Play Store or F-Droid, or announcing in /r/Android's APPreciation thread +4. ~~Extend functionality by adding appearance customization options.~~ +5. Publish on F-Droid diff --git a/app/build.gradle b/app/build.gradle index a5a3f3d..fb60044 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -26,6 +26,8 @@ dependencies { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support.constraint:constraint-layout:1.0.2' - testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:26.1.0' + compile 'com.android.support:support-v4:26.1.0' + compile 'com.rarepebble:colorpicker:2.2.0' + testCompile 'junit:junit:4.12' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 21a15bc..1fb50ae 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -9,9 +9,12 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@android:style/Theme.Translucent.NoTitleBar"> - + + @@ -25,6 +28,10 @@ android:name="android.appwidget.provider" android:resource="@xml/widget_provider_info" /> + + \ No newline at end of file diff --git a/app/src/main/java/com/leapwill/plainnote/MainActivity.java b/app/src/main/java/com/leapwill/plainnote/MainActivity.java index ab209ad..990c740 100644 --- a/app/src/main/java/com/leapwill/plainnote/MainActivity.java +++ b/app/src/main/java/com/leapwill/plainnote/MainActivity.java @@ -4,6 +4,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; +import android.preference.PreferenceManager; import android.view.View; import android.widget.EditText; @@ -12,20 +13,32 @@ public class MainActivity extends Activity { EditText plainNoteEditText; SharedPreferences prefs; - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - this.plainNoteEditText = (EditText) findViewById(R.id.plainNoteEditText); - this.prefs = getSharedPreferences("com.leapwill.plainnote", 0); + this.plainNoteEditText = findViewById(R.id.plainNoteEditText); + this.prefs = PreferenceManager.getDefaultSharedPreferences(this); + + //bring text from old preferences file to default + String oldNote = getSharedPreferences("com.leapwill.plainnote", 0).getString("com.leapwill.plainnote.text", null); + if (oldNote != null) { + PreferenceManager.getDefaultSharedPreferences(this).edit().putString("plainNoteText", oldNote).commit(); + getSharedPreferences("com.leapwill.plainnote", 0).edit().putString("com.leapwill.plainnote.text", null).apply(); + } + } - this.plainNoteEditText.setText(this.prefs.getString("com.leapwill.plainnote.text", "")); + @Override + protected void onResume() { + super.onResume(); + this.plainNoteEditText.setText(this.prefs.getString("plainNoteText", "")); + this.plainNoteEditText.setBackgroundColor(this.prefs.getInt("plainNotePrefBGColor", 0xdd222222)); + this.plainNoteEditText.setTextColor(this.prefs.getInt("plainNotePrefTextColor", 0xffffffff)); } public void saveNote (View v) { - this.prefs.edit().putString("com.leapwill.plainnote.text", this.plainNoteEditText.getText().toString()).apply(); + this.prefs.edit().putString("plainNoteText", this.plainNoteEditText.getText().toString()).apply(); this.updateWidget(); this.finish(); } @@ -35,4 +48,9 @@ public void updateWidget() { intent.putExtra("TEXT_STRING", this.plainNoteEditText.getText().toString()); sendBroadcast(intent); } -} + + public void openSettings(View view) { + Intent intent = new Intent(this, SettingsActivity.class); + startActivity(intent); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/leapwill/plainnote/SettingsActivity.java b/app/src/main/java/com/leapwill/plainnote/SettingsActivity.java new file mode 100644 index 0000000..eac7469 --- /dev/null +++ b/app/src/main/java/com/leapwill/plainnote/SettingsActivity.java @@ -0,0 +1,15 @@ +package com.leapwill.plainnote; + +import android.app.Activity; +import android.os.Bundle; + +public class SettingsActivity extends Activity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + getFragmentManager().beginTransaction() + .replace(android.R.id.content, SettingsFragment.newInstance()) + .commit(); + } +} diff --git a/app/src/main/java/com/leapwill/plainnote/SettingsFragment.java b/app/src/main/java/com/leapwill/plainnote/SettingsFragment.java new file mode 100644 index 0000000..1742000 --- /dev/null +++ b/app/src/main/java/com/leapwill/plainnote/SettingsFragment.java @@ -0,0 +1,33 @@ +package com.leapwill.plainnote; + +import android.content.Context; +import android.content.res.Resources; +import android.net.Uri; +import android.os.Bundle; +import android.preference.PreferenceFragment; +import android.support.v4.app.Fragment; +import android.util.Log; +import android.view.ContextThemeWrapper; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +public class SettingsFragment extends PreferenceFragment { + + public SettingsFragment() { + // Required empty public constructor + } + + public static SettingsFragment newInstance() { + SettingsFragment fragment = new SettingsFragment(); + Bundle args = new Bundle(); + fragment.setArguments(args); + return fragment; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + addPreferencesFromResource(R.xml.preferences); + } +} diff --git a/app/src/main/java/com/leapwill/plainnote/WidgetProvider.java b/app/src/main/java/com/leapwill/plainnote/WidgetProvider.java index 8d7393a..05e5c14 100644 --- a/app/src/main/java/com/leapwill/plainnote/WidgetProvider.java +++ b/app/src/main/java/com/leapwill/plainnote/WidgetProvider.java @@ -6,6 +6,8 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; import android.widget.RemoteViews; /** @@ -16,9 +18,12 @@ public class WidgetProvider extends AppWidgetProvider { static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) { + SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); // Construct the RemoteViews object RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_provider); - views.setTextViewText(R.id.plainNoteWidgetTextView, context.getSharedPreferences("com.leapwill.plainnote", 0).getString("com.leapwill.plainnote.text", "")); + views.setTextViewText(R.id.plainNoteWidgetTextView, sharedPreferences.getString("plainNoteText", "")); + views.setInt(R.id.plainNoteWidgetTextView, "setBackgroundColor", sharedPreferences.getInt("plainNotePrefBGColor", 0xdd222222)); + views.setInt(R.id.plainNoteWidgetTextView, "setTextColor", sharedPreferences.getInt("plainNotePrefTextColor", 0xffffffff)); views.setOnClickPendingIntent(R.id.plainNoteWidgetTextView, PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), 0)); // Instruct the widget manager to update the widget diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 01d27fe..b53c42d 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -11,26 +11,24 @@ + android:inputType="textMultiLine" /> + app:layout_constraintRight_toRightOf="@+id/plainNoteEditText" + app:layout_constraintTop_toBottomOf="@+id/plainNoteEditText">