Skip to content

Commit

Permalink
Merge pull request #1 from roshanrahman/working
Browse files Browse the repository at this point in the history
Added dark theme
  • Loading branch information
roshanrahman committed Oct 18, 2018
2 parents 07ba473 + abd391b commit 854b5b4
Show file tree
Hide file tree
Showing 23 changed files with 218 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ public class AboutActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(ThemeHelper.isDarkTheme(AboutActivity.this)) {
setTheme(R.style.AppThemeDark);
} else {
setTheme(R.style.AppTheme);
}
setContentView(R.layout.activity_about);
Toolbar toolbar = findViewById(R.id.appToolbar);
setSupportActionBar(toolbar);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public class EditNoteActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
boolean isNewNote = false;
super.onCreate(savedInstanceState);
if(ThemeHelper.isDarkTheme(EditNoteActivity.this)) {
setTheme(R.style.AppThemeDark);
} else {
setTheme(R.style.AppTheme);
}
setContentView(R.layout.activity_edit_note);
editNoteText = findViewById(R.id.noteText);
editNoteTitle = findViewById(R.id.noteTitle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
Expand Down Expand Up @@ -44,6 +45,11 @@ public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(ThemeHelper.isDarkTheme(MainActivity.this)) {
setTheme(R.style.AppThemeDark);
} else {
setTheme(R.style.AppTheme);
}
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.appToolbar);
toolbar.setOverflowIcon(getDrawable(R.drawable.ic_more_vert_24dp));
Expand Down Expand Up @@ -95,7 +101,10 @@ public Cursor runQuery(CharSequence s) {
public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
View currentItem = (View) notesList.getChildAt(position);
if(checked) {
currentItem.setBackgroundColor(getResources().getColor(R.color.pressed));
if(ThemeHelper.isDarkTheme(MainActivity.this))
currentItem.setBackgroundColor(getResources().getColor(R.color.pressedDark));
else
currentItem.setBackgroundColor(getResources().getColor(R.color.pressed));
Log.i("NOTESAPP: Checked", currentItem.getTag().toString());
selectedIds.add(currentItem.getTag().toString());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,30 @@

public class SettingsActivity extends AppCompatActivity {

RadioButton robotoSlab, roboto, montserrat, openSans, ptSerif;
RadioButton robotoSlab, roboto, montserrat, openSans, ptSerif, colorLight, colorDark, colorAutomatic;
SharedPreferences.Editor settingsEditor;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(ThemeHelper.isDarkTheme(SettingsActivity.this)) {
setTheme(R.style.AppThemeDark);
} else {
setTheme(R.style.AppTheme);
}
setContentView(R.layout.activity_settings);
SharedPreferences sharedPreferences = getSharedPreferences("com.example.roshan.quickwriter.FontPreference", Context.MODE_PRIVATE);
settingsEditor = sharedPreferences.edit();
String fontFamily = sharedPreferences.getString("fontFamily", "robotoSlab");
String colorTheme = sharedPreferences.getString("colorTheme", "automatic");
robotoSlab = findViewById(R.id.fontRadioRobotoSlab);
roboto = findViewById(R.id.fontRadioRoboto);
montserrat = findViewById(R.id.fontRadioMontserrat);
openSans = findViewById(R.id.fontRadioOpenSans);
ptSerif = findViewById(R.id.fontRadioPTSerif);
colorLight = findViewById(R.id.colorLight);
colorDark = findViewById(R.id.colorDark);
colorAutomatic = findViewById(R.id.colorAutomatic);

switch(fontFamily) {
case "robotoSlab":
robotoSlab.toggle();
Expand All @@ -45,7 +55,18 @@ protected void onCreate(Bundle savedInstanceState) {
break;

default:
}

switch(colorTheme) {
case "automatic":
colorAutomatic.toggle();
break;
case "light":
colorLight.toggle();
break;
case "dark":
colorDark.toggle();
default:
}

Toolbar toolbar = findViewById(R.id.appToolbar);
Expand Down Expand Up @@ -84,6 +105,25 @@ public void onRadioButtonClicked(View view) {
settingsEditor.commit();
break;

case R.id.colorAutomatic:
colorAutomatic.toggle();
settingsEditor.putString("colorTheme", "automatic");
settingsEditor.commit();
recreate();
break;
case R.id.colorLight:
colorLight.toggle();
settingsEditor.putString("colorTheme", "light");
settingsEditor.commit();
recreate();
break;
case R.id.colorDark:
colorDark.toggle();
settingsEditor.putString("colorTheme", "dark");
settingsEditor.commit();
recreate();
break;

}
}
}
29 changes: 29 additions & 0 deletions app/src/main/java/com/example/roshan/quickwriter/ThemeHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.example.roshan.quickwriter;

import android.content.Context;
import android.content.SharedPreferences;
import android.icu.text.SimpleDateFormat;
import android.icu.util.Calendar;
import android.util.Log;

public class ThemeHelper {
public static boolean isDarkTheme(Context context) {
SharedPreferences sharedPreferences = context.getSharedPreferences("com.example.roshan.quickwriter.FontPreference", Context.MODE_PRIVATE);
String colorTheme = sharedPreferences.getString("colorTheme", "automatic");
switch(colorTheme) {
case "automatic":
Calendar c = Calendar.getInstance();
SimpleDateFormat dateformat = new SimpleDateFormat("HH");
String time = dateformat.format(c.getTime());
Log.i("NOTESAPP: Time is " , time);
if(Integer.parseInt(time) >= 18) {
return true;
}
case "light":
return false;
case "dark":
return true;
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public class ViewNoteActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(ThemeHelper.isDarkTheme(ViewNoteActivity.this)) {
setTheme(R.style.AppThemeDark);
} else {
setTheme(R.style.AppTheme);
}
setContentView(R.layout.activity_view_note);
viewNoteTitle = findViewById(R.id.viewNoteTitle);
viewNoteContent = findViewById(R.id.viewNoteContent);
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/ic_create_24dp.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<vector android:height="24dp" android:tint="#2196F3"
<vector android:height="24dp" android:tint="?attr/toolbarTextColor"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83 3.75,3.75 1.83,-1.83z"/>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/ic_delete_black_24dp.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<vector android:height="24dp" android:tint="#2196F3"
<vector android:height="24dp" android:tint="?attr/toolbarTextColor"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2V7H6v12zM19,4h-3.5l-1,-1h-5l-1,1H5v2h14V4z"/>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/ic_done_24dp.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<vector android:height="24dp" android:tint="#2196F3"
<vector android:height="24dp" android:tint="?attr/toolbarTextColor"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M9,16.2L4.8,12l-1.4,1.4L9,19 21,7l-1.4,-1.4L9,16.2z"/>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/ic_info_24dp.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<vector android:height="24dp" android:tint="#2196F3"
<vector android:height="24dp" android:tint="?attr/toolbarTextColor"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM13,17h-2v-6h2v6zM13,9h-2L11,7h2v2z"/>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/ic_more_vert_24dp.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<vector android:height="24dp" android:tint="#2196F3"
<vector android:height="24dp" android:tint="?attr/toolbarTextColor"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M12,8c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2zM12,10c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2zM12,16c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2z"/>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/ic_report_black_24dp.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<vector android:height="36dp" android:tint="#A8A8A8"
<vector android:height="36dp" android:tint="?attr/toolbarTextColor"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="36dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M15.73,3L8.27,3L3,8.27v7.46L8.27,21h7.46L21,15.73L21,8.27L15.73,3zM12,17.3c-0.72,0 -1.3,-0.58 -1.3,-1.3 0,-0.72 0.58,-1.3 1.3,-1.3 0.72,0 1.3,0.58 1.3,1.3 0,0.72 -0.58,1.3 -1.3,1.3zM13,13h-2L11,7h2v6z"/>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/ic_search_24dp.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<vector android:height="24dp" android:tint="#2196F3"
<vector android:height="24dp" android:tint="?attr/toolbarTextColor"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M15.5,14h-0.79l-0.28,-0.27C15.41,12.59 16,11.11 16,9.5 16,5.91 13.09,3 9.5,3S3,5.91 3,9.5 5.91,16 9.5,16c1.61,0 3.09,-0.59 4.23,-1.57l0.27,0.28v0.79l5,4.99L20.49,19l-4.99,-5zM9.5,14C7.01,14 5,11.99 5,9.5S7.01,5 9.5,5 14,7.01 14,9.5 11.99,14 9.5,14z"/>
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/drawable/ic_settings_24dp.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<vector android:height="24dp" android:tint="#2196F3"
<vector android:height="24dp" android:tint="?attr/toolbarTextColor"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M19.43,12.98c0.04,-0.32 0.07,-0.64 0.07,-0.98s-0.03,-0.66 -0.07,-0.98l2.11,-1.65c0.19,-0.15 0.24,-0.42 0.12,-0.64l-2,-3.46c-0.12,-0.22 -0.39,-0.3 -0.61,-0.22l-2.49,1c-0.52,-0.4 -1.08,-0.73 -1.69,-0.98l-0.38,-2.65C14.46,2.18 14.25,2 14,2h-4c-0.25,0 -0.46,0.18 -0.49,0.42l-0.38,2.65c-0.61,0.25 -1.17,0.59 -1.69,0.98l-2.49,-1c-0.23,-0.09 -0.49,0 -0.61,0.22l-2,3.46c-0.13,0.22 -0.07,0.49 0.12,0.64l2.11,1.65c-0.04,0.32 -0.07,0.65 -0.07,0.98s0.03,0.66 0.07,0.98l-2.11,1.65c-0.19,0.15 -0.24,0.42 -0.12,0.64l2,3.46c0.12,0.22 0.39,0.3 0.61,0.22l2.49,-1c0.52,0.4 1.08,0.73 1.69,0.98l0.38,2.65c0.03,0.24 0.24,0.42 0.49,0.42h4c0.25,0 0.46,-0.18 0.49,-0.42l0.38,-2.65c0.61,-0.25 1.17,-0.59 1.69,-0.98l2.49,1c0.23,0.09 0.49,0 0.61,-0.22l2,-3.46c0.12,-0.22 0.07,-0.49 -0.12,-0.64l-2.11,-1.65zM12,15.5c-1.93,0 -3.5,-1.57 -3.5,-3.5s1.57,-3.5 3.5,-3.5 3.5,1.57 3.5,3.5 -1.57,3.5 -3.5,3.5z"/>
<path android:fillColor="?attr/colorPrimaryDark" android:pathData="M19.43,12.98c0.04,-0.32 0.07,-0.64 0.07,-0.98s-0.03,-0.66 -0.07,-0.98l2.11,-1.65c0.19,-0.15 0.24,-0.42 0.12,-0.64l-2,-3.46c-0.12,-0.22 -0.39,-0.3 -0.61,-0.22l-2.49,1c-0.52,-0.4 -1.08,-0.73 -1.69,-0.98l-0.38,-2.65C14.46,2.18 14.25,2 14,2h-4c-0.25,0 -0.46,0.18 -0.49,0.42l-0.38,2.65c-0.61,0.25 -1.17,0.59 -1.69,0.98l-2.49,-1c-0.23,-0.09 -0.49,0 -0.61,0.22l-2,3.46c-0.13,0.22 -0.07,0.49 0.12,0.64l2.11,1.65c-0.04,0.32 -0.07,0.65 -0.07,0.98s0.03,0.66 0.07,0.98l-2.11,1.65c-0.19,0.15 -0.24,0.42 -0.12,0.64l2,3.46c0.12,0.22 0.39,0.3 0.61,0.22l2.49,-1c0.52,0.4 1.08,0.73 1.69,0.98l0.38,2.65c0.03,0.24 0.24,0.42 0.49,0.42h4c0.25,0 0.46,-0.18 0.49,-0.42l0.38,-2.65c0.61,-0.25 1.17,-0.59 1.69,-0.98l2.49,1c0.23,0.09 0.49,0 0.61,-0.22l2,-3.46c0.12,-0.22 0.07,-0.49 -0.12,-0.64l-2.11,-1.65zM12,15.5c-1.93,0 -3.5,-1.57 -3.5,-3.5s1.57,-3.5 3.5,-3.5 3.5,1.57 3.5,3.5 -1.57,3.5 -3.5,3.5z"/>
</vector>
4 changes: 2 additions & 2 deletions app/src/main/res/drawable/ic_share_24dp.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<vector android:height="24dp" android:tint="#2196F3"
<vector android:height="24dp" android:tint="?attr/toolbarTextColor"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M18,16.08c-0.76,0 -1.44,0.3 -1.96,0.77L8.91,12.7c0.05,-0.23 0.09,-0.46 0.09,-0.7s-0.04,-0.47 -0.09,-0.7l7.05,-4.11c0.54,0.5 1.25,0.81 2.04,0.81 1.66,0 3,-1.34 3,-3s-1.34,-3 -3,-3 -3,1.34 -3,3c0,0.24 0.04,0.47 0.09,0.7L8.04,9.81C7.5,9.31 6.79,9 6,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3c0.79,0 1.5,-0.31 2.04,-0.81l7.12,4.16c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.61 1.31,2.92 2.92,2.92 1.61,0 2.92,-1.31 2.92,-2.92s-1.31,-2.92 -2.92,-2.92z"/>
<path android:fillColor="?attr/toolbarTextColor" android:pathData="M18,16.08c-0.76,0 -1.44,0.3 -1.96,0.77L8.91,12.7c0.05,-0.23 0.09,-0.46 0.09,-0.7s-0.04,-0.47 -0.09,-0.7l7.05,-4.11c0.54,0.5 1.25,0.81 2.04,0.81 1.66,0 3,-1.34 3,-3s-1.34,-3 -3,-3 -3,1.34 -3,3c0,0.24 0.04,0.47 0.09,0.7L8.04,9.81C7.5,9.31 6.79,9 6,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3c0.79,0 1.5,-0.31 2.04,-0.81l7.12,4.16c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.61 1.31,2.92 2.92,2.92 1.61,0 2.92,-1.31 2.92,-2.92s-1.31,-2.92 -2.92,-2.92z"/>
</vector>
34 changes: 26 additions & 8 deletions app/src/main/res/layout/activity_about.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
android:id="@+id/appToolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#FFF"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:title="About"
app:titleTextColor="@color/colorPrimaryDark"
app:titleTextColor="?attr/toolbarTextColor"
android:background="?attr/toolbarBackgroundColor"
style="@style/MyToolbarStyle"
app:popupTheme="@style/MyToolbarStyle"/>

Expand All @@ -27,29 +27,29 @@
android:paddingRight="16dp"
android:text="Quick Writer"
android:textAlignment="gravity"
android:textAllCaps="true"
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline6"
android:textColor="@color/colorPrimaryDark" />
android:textSize="26sp"
android:textColor="?attr/colorPrimaryDark" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:paddingTop="8dp"
android:paddingRight="16dp"
android:paddingBottom="16dp"
android:text="A simple and elegant notes app"
android:textAlignment="gravity"
android:textColor="@color/colorPrimaryDark" />
android:textColor="?attr/colorPrimaryDark" />


<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="48dp"
android:paddingTop="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="Developed by Roshan"
android:textColor="@color/colorPrimaryDark"
android:textColor="?attr/colorPrimaryDark"
android:textAlignment="gravity"
/>
<TextView
Expand All @@ -58,12 +58,30 @@
android:paddingTop="8dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingBottom="16dp"
android:text="https://www.github.com/roshanrahman"
android:textAlignment="gravity"
android:linksClickable="true"
android:autoLink="all"
android:textColor="#000" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Version 1.1"
android:padding="16dp"/>

<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Added Dark Theme functionality"/>

</ScrollView>



</LinearLayout>
6 changes: 3 additions & 3 deletions app/src/main/res/layout/activity_edit_note.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
android:id="@+id/appToolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#FFF"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:title="Edit Note"
app:titleTextColor="@color/colorPrimaryDark"
app:titleTextColor="?attr/toolbarTextColor"
android:background="?attr/toolbarBackgroundColor"
style="@style/MyToolbarStyle"
app:popupTheme="@style/MyToolbarStyle"
app:subtitle=""/>
Expand All @@ -42,7 +42,7 @@
android:hint="Enter the title here"
android:maxLines="2"
android:textAppearance="@style/TextAppearance.AppCompat.Title"
android:textColor="@color/colorPrimaryDark"
android:textColor="?attr/colorPrimaryDark"
android:textStyle="bold" />

<EditText
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
android:id="@+id/appToolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#FFF"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"

app:title="Your Notes"
app:titleTextColor="@color/colorPrimaryDark"
app:titleTextColor="?attr/toolbarTextColor"
android:background="?attr/toolbarBackgroundColor"
style="@style/MyToolbarStyle"
app:popupTheme="@style/MyToolbarStyle"/>

Expand Down

0 comments on commit 854b5b4

Please sign in to comment.