Skip to content

Commit

Permalink
Added settings menu to customize colors
Browse files Browse the repository at this point in the history
  • Loading branch information
leapwill committed Oct 15, 2017
1 parent fe852f8 commit edce760
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 27 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
9 changes: 8 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@android:style/Theme.Translucent.NoTitleBar">
<activity android:name=".MainActivity" android:windowSoftInputMode="stateAlwaysVisible">
<activity
android:name=".MainActivity"
android:windowSoftInputMode="stateAlwaysVisible">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Expand All @@ -25,6 +28,10 @@
android:name="android.appwidget.provider"
android:resource="@xml/widget_provider_info" />
</receiver>

<activity
android:name=".SettingsActivity"
android:theme="@style/Theme.AppCompat.Light.DarkActionBar" />
</application>

</manifest>
30 changes: 24 additions & 6 deletions app/src/main/java/com/leapwill/plainnote/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
}
Expand All @@ -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);
}
}
15 changes: 15 additions & 0 deletions app/src/main/java/com/leapwill/plainnote/SettingsActivity.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
33 changes: 33 additions & 0 deletions app/src/main/java/com/leapwill/plainnote/SettingsFragment.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
7 changes: 6 additions & 1 deletion app/src/main/java/com/leapwill/plainnote/WidgetProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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
Expand Down
24 changes: 12 additions & 12 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,24 @@

<EditText
android:id="@+id/plainNoteEditText"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="160dp"
android:padding="8dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:gravity="top|start"
android:inputType="textMultiLine"
android:background="#dd222222"
android:textColor="@color/colorText"
tools:layout_editor_absoluteY="0dp"
tools:layout_editor_absoluteX="8dp" />
android:inputType="textMultiLine" />

<LinearLayout
android:id="@+id/plainNoteButtonLayout"
android:layout_width="0dp"
android:layout_height="80dp"
android:layout_marginTop="0dp"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="@+id/plainNoteEditText"
app:layout_constraintTop_toBottomOf="@+id/plainNoteEditText"
app:layout_constraintRight_toRightOf="@+id/plainNoteEditText" >
app:layout_constraintRight_toRightOf="@+id/plainNoteEditText"
app:layout_constraintTop_toBottomOf="@+id/plainNoteEditText">

<Button
android:id="@+id/plainNoteSaveButton"
Expand All @@ -40,16 +38,18 @@
android:background="@drawable/save_button"
android:onClick="saveNote"
android:text="Save"
android:textColor="@color/colorText" />
android:textAppearance="@android:style/TextAppearance.Large"
android:textColor="#ffffffff" />

<ImageButton
android:id="@+id/plainNoteSettingsButton"
android:layout_width="80dp"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDark"
android:src="@drawable/ic_settings_48dp"
android:background="@drawable/settings_button"
android:contentDescription="Settings"
android:visibility="gone" />
android:onClick="openSettings"
android:src="@drawable/ic_settings_48dp"
tools:clickable="true" />

</LinearLayout>

Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/layout/fragment_settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.leapwill.plainnote.SettingsFragment" />
4 changes: 1 addition & 3 deletions app/src/main/res/layout/widget_provider.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,5 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/widget_margin"
android:background="@android:color/background_dark"
android:clickable="true"
android:padding="8dp"
android:textColor="#FFFFFF" />
android:padding="8dp" />
1 change: 0 additions & 1 deletion app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
<color name="colorPrimaryLight">#96b4ee</color>
<color name="colorPrimaryDark">#34598b</color>
<color name="colorAccent">#2fbdd3</color>
<color name="colorText">#ffffff</color>
</resources>
18 changes: 18 additions & 0 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<com.rarepebble.colorpicker.ColorPreference
android:key="plainNotePrefBGColor"
android:title="Background color"
android:defaultValue="#dd222222"
app:colorpicker_selectNoneButtonText="Default" />

<com.rarepebble.colorpicker.ColorPreference
android:key="plainNotePrefTextColor"
android:title="Text color"
android:defaultValue="#ffffffff"
app:colorpicker_selectNoneButtonText="Default"
app:colorpicker_showAlpha="false" />

</PreferenceScreen>

0 comments on commit edce760

Please sign in to comment.