Skip to content

Commit edce760

Browse files
committed
Added settings menu to customize colors
1 parent fe852f8 commit edce760

12 files changed

+129
-27
lines changed

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ A simple note widget for Android
33

44
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.
55

6+
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.
7+
68
## To do:
79
1. ~~Load and save a multi-line plain text message.~~
810
2. ~~Create a flexible launcher widget to display the message.~~
911
3. ~~Create an icon and widget preview.~~
10-
4. Extend functionality by adding appearance customization options.
11-
5. Consider publishing on Play Store or F-Droid, or announcing in /r/Android's APPreciation thread
12+
4. ~~Extend functionality by adding appearance customization options.~~
13+
5. Publish on F-Droid

app/build.gradle

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ dependencies {
2626
exclude group: 'com.android.support', module: 'support-annotations'
2727
})
2828
compile 'com.android.support.constraint:constraint-layout:1.0.2'
29-
testCompile 'junit:junit:4.12'
3029
compile 'com.android.support:appcompat-v7:26.1.0'
30+
compile 'com.android.support:support-v4:26.1.0'
31+
compile 'com.rarepebble:colorpicker:2.2.0'
32+
testCompile 'junit:junit:4.12'
3133
}

app/src/main/AndroidManifest.xml

+8-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99
android:roundIcon="@mipmap/ic_launcher_round"
1010
android:supportsRtl="true"
1111
android:theme="@android:style/Theme.Translucent.NoTitleBar">
12-
<activity android:name=".MainActivity" android:windowSoftInputMode="stateAlwaysVisible">
12+
<activity
13+
android:name=".MainActivity"
14+
android:windowSoftInputMode="stateAlwaysVisible">
1315
<intent-filter>
1416
<action android:name="android.intent.action.MAIN" />
17+
1518
<category android:name="android.intent.category.LAUNCHER" />
1619
</intent-filter>
1720
</activity>
@@ -25,6 +28,10 @@
2528
android:name="android.appwidget.provider"
2629
android:resource="@xml/widget_provider_info" />
2730
</receiver>
31+
32+
<activity
33+
android:name=".SettingsActivity"
34+
android:theme="@style/Theme.AppCompat.Light.DarkActionBar" />
2835
</application>
2936

3037
</manifest>

app/src/main/java/com/leapwill/plainnote/MainActivity.java

+24-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.content.Intent;
55
import android.content.SharedPreferences;
66
import android.os.Bundle;
7+
import android.preference.PreferenceManager;
78
import android.view.View;
89
import android.widget.EditText;
910

@@ -12,20 +13,32 @@ public class MainActivity extends Activity {
1213
EditText plainNoteEditText;
1314
SharedPreferences prefs;
1415

15-
1616
@Override
1717
protected void onCreate(Bundle savedInstanceState) {
1818
super.onCreate(savedInstanceState);
1919
setContentView(R.layout.activity_main);
20-
this.plainNoteEditText = (EditText) findViewById(R.id.plainNoteEditText);
21-
this.prefs = getSharedPreferences("com.leapwill.plainnote", 0);
20+
this.plainNoteEditText = findViewById(R.id.plainNoteEditText);
21+
this.prefs = PreferenceManager.getDefaultSharedPreferences(this);
22+
23+
//bring text from old preferences file to default
24+
String oldNote = getSharedPreferences("com.leapwill.plainnote", 0).getString("com.leapwill.plainnote.text", null);
25+
if (oldNote != null) {
26+
PreferenceManager.getDefaultSharedPreferences(this).edit().putString("plainNoteText", oldNote).commit();
27+
getSharedPreferences("com.leapwill.plainnote", 0).edit().putString("com.leapwill.plainnote.text", null).apply();
28+
}
29+
}
2230

23-
this.plainNoteEditText.setText(this.prefs.getString("com.leapwill.plainnote.text", ""));
31+
@Override
32+
protected void onResume() {
33+
super.onResume();
2434

35+
this.plainNoteEditText.setText(this.prefs.getString("plainNoteText", ""));
36+
this.plainNoteEditText.setBackgroundColor(this.prefs.getInt("plainNotePrefBGColor", 0xdd222222));
37+
this.plainNoteEditText.setTextColor(this.prefs.getInt("plainNotePrefTextColor", 0xffffffff));
2538
}
2639

2740
public void saveNote (View v) {
28-
this.prefs.edit().putString("com.leapwill.plainnote.text", this.plainNoteEditText.getText().toString()).apply();
41+
this.prefs.edit().putString("plainNoteText", this.plainNoteEditText.getText().toString()).apply();
2942
this.updateWidget();
3043
this.finish();
3144
}
@@ -35,4 +48,9 @@ public void updateWidget() {
3548
intent.putExtra("TEXT_STRING", this.plainNoteEditText.getText().toString());
3649
sendBroadcast(intent);
3750
}
38-
}
51+
52+
public void openSettings(View view) {
53+
Intent intent = new Intent(this, SettingsActivity.class);
54+
startActivity(intent);
55+
}
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.leapwill.plainnote;
2+
3+
import android.app.Activity;
4+
import android.os.Bundle;
5+
6+
public class SettingsActivity extends Activity {
7+
8+
@Override
9+
protected void onCreate(Bundle savedInstanceState) {
10+
super.onCreate(savedInstanceState);
11+
getFragmentManager().beginTransaction()
12+
.replace(android.R.id.content, SettingsFragment.newInstance())
13+
.commit();
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.leapwill.plainnote;
2+
3+
import android.content.Context;
4+
import android.content.res.Resources;
5+
import android.net.Uri;
6+
import android.os.Bundle;
7+
import android.preference.PreferenceFragment;
8+
import android.support.v4.app.Fragment;
9+
import android.util.Log;
10+
import android.view.ContextThemeWrapper;
11+
import android.view.LayoutInflater;
12+
import android.view.View;
13+
import android.view.ViewGroup;
14+
15+
public class SettingsFragment extends PreferenceFragment {
16+
17+
public SettingsFragment() {
18+
// Required empty public constructor
19+
}
20+
21+
public static SettingsFragment newInstance() {
22+
SettingsFragment fragment = new SettingsFragment();
23+
Bundle args = new Bundle();
24+
fragment.setArguments(args);
25+
return fragment;
26+
}
27+
28+
@Override
29+
public void onCreate(Bundle savedInstanceState) {
30+
super.onCreate(savedInstanceState);
31+
addPreferencesFromResource(R.xml.preferences);
32+
}
33+
}

app/src/main/java/com/leapwill/plainnote/WidgetProvider.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import android.content.ComponentName;
77
import android.content.Context;
88
import android.content.Intent;
9+
import android.content.SharedPreferences;
10+
import android.preference.PreferenceManager;
911
import android.widget.RemoteViews;
1012

1113
/**
@@ -16,9 +18,12 @@ public class WidgetProvider extends AppWidgetProvider {
1618
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
1719
int appWidgetId) {
1820

21+
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
1922
// Construct the RemoteViews object
2023
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_provider);
21-
views.setTextViewText(R.id.plainNoteWidgetTextView, context.getSharedPreferences("com.leapwill.plainnote", 0).getString("com.leapwill.plainnote.text", ""));
24+
views.setTextViewText(R.id.plainNoteWidgetTextView, sharedPreferences.getString("plainNoteText", ""));
25+
views.setInt(R.id.plainNoteWidgetTextView, "setBackgroundColor", sharedPreferences.getInt("plainNotePrefBGColor", 0xdd222222));
26+
views.setInt(R.id.plainNoteWidgetTextView, "setTextColor", sharedPreferences.getInt("plainNotePrefTextColor", 0xffffffff));
2227
views.setOnClickPendingIntent(R.id.plainNoteWidgetTextView, PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), 0));
2328

2429
// Instruct the widget manager to update the widget

app/src/main/res/layout/activity_main.xml

+12-12
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,24 @@
1111

1212
<EditText
1313
android:id="@+id/plainNoteEditText"
14-
android:layout_width="match_parent"
14+
android:layout_width="0dp"
1515
android:layout_height="160dp"
1616
android:padding="8dp"
1717
app:layout_constraintTop_toTopOf="parent"
1818
app:layout_constraintLeft_toLeftOf="parent"
1919
app:layout_constraintRight_toRightOf="parent"
2020
android:gravity="top|start"
21-
android:inputType="textMultiLine"
22-
android:background="#dd222222"
23-
android:textColor="@color/colorText"
24-
tools:layout_editor_absoluteY="0dp"
25-
tools:layout_editor_absoluteX="8dp" />
21+
android:inputType="textMultiLine" />
2622

2723
<LinearLayout
2824
android:id="@+id/plainNoteButtonLayout"
2925
android:layout_width="0dp"
3026
android:layout_height="80dp"
27+
android:layout_marginTop="0dp"
28+
app:layout_constraintHorizontal_bias="0.0"
3129
app:layout_constraintLeft_toLeftOf="@+id/plainNoteEditText"
32-
app:layout_constraintTop_toBottomOf="@+id/plainNoteEditText"
33-
app:layout_constraintRight_toRightOf="@+id/plainNoteEditText" >
30+
app:layout_constraintRight_toRightOf="@+id/plainNoteEditText"
31+
app:layout_constraintTop_toBottomOf="@+id/plainNoteEditText">
3432

3533
<Button
3634
android:id="@+id/plainNoteSaveButton"
@@ -40,16 +38,18 @@
4038
android:background="@drawable/save_button"
4139
android:onClick="saveNote"
4240
android:text="Save"
43-
android:textColor="@color/colorText" />
41+
android:textAppearance="@android:style/TextAppearance.Large"
42+
android:textColor="#ffffffff" />
4443

4544
<ImageButton
4645
android:id="@+id/plainNoteSettingsButton"
4746
android:layout_width="80dp"
4847
android:layout_height="match_parent"
49-
android:background="@color/colorPrimaryDark"
50-
android:src="@drawable/ic_settings_48dp"
48+
android:background="@drawable/settings_button"
5149
android:contentDescription="Settings"
52-
android:visibility="gone" />
50+
android:onClick="openSettings"
51+
android:src="@drawable/ic_settings_48dp"
52+
tools:clickable="true" />
5353

5454
</LinearLayout>
5555

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
tools:context="com.leapwill.plainnote.SettingsFragment" />

app/src/main/res/layout/widget_provider.xml

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,5 @@
33
android:layout_width="match_parent"
44
android:layout_height="match_parent"
55
android:layout_margin="@dimen/widget_margin"
6-
android:background="@android:color/background_dark"
76
android:clickable="true"
8-
android:padding="8dp"
9-
android:textColor="#FFFFFF" />
7+
android:padding="8dp" />

app/src/main/res/values/colors.xml

-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@
44
<color name="colorPrimaryLight">#96b4ee</color>
55
<color name="colorPrimaryDark">#34598b</color>
66
<color name="colorAccent">#2fbdd3</color>
7-
<color name="colorText">#ffffff</color>
87
</resources>

app/src/main/res/xml/preferences.xml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto">
4+
5+
<com.rarepebble.colorpicker.ColorPreference
6+
android:key="plainNotePrefBGColor"
7+
android:title="Background color"
8+
android:defaultValue="#dd222222"
9+
app:colorpicker_selectNoneButtonText="Default" />
10+
11+
<com.rarepebble.colorpicker.ColorPreference
12+
android:key="plainNotePrefTextColor"
13+
android:title="Text color"
14+
android:defaultValue="#ffffffff"
15+
app:colorpicker_selectNoneButtonText="Default"
16+
app:colorpicker_showAlpha="false" />
17+
18+
</PreferenceScreen>

0 commit comments

Comments
 (0)