Skip to content

Commit

Permalink
Night Mode πŸŽ‰πŸŽ‰
Browse files Browse the repository at this point in the history
Night Mode enabled, It remains persistent even if the app is restarted.

- Some minor bug fixes
- Animations improved
- Alert Dialog edits
  • Loading branch information
gouravkhunger committed May 1, 2021
1 parent fd2dba8 commit fb6ad28
Show file tree
Hide file tree
Showing 14 changed files with 163 additions and 34 deletions.
14 changes: 7 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ plugins {

android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
buildToolsVersion "30.0.3"

defaultConfig {
applicationId "app.web.gourav_khunger.textrecognizer"
minSdkVersion 23
targetSdkVersion 30
versionCode 1
versionName "1.0"
versionName "1.2.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -30,16 +30,16 @@ android {

dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'com.google.android.gms:play-services-mlkit-text-recognition:16.1.1'
implementation 'com.google.android.material:material:1.3.0' //1.2.1
implementation 'com.google.android.gms:play-services-mlkit-text-recognition:16.1.3'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.github.bumptech.glide:glide:4.11.0'
implementation 'com.github.bumptech.glide:glide:4.12.0'
implementation 'com.muddzdev:styleabletoast:2.2.4'
implementation 'com.github.javiersantos:AppUpdater:2.7'
api 'com.theartofdev.edmodo:android-image-cropper:2.8.0'

annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
testImplementation 'junit:junit:4.13.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
android:roundIcon="@drawable/logo"
android:supportsRtl="true"
android:theme="@style/Theme.TextRecogniser">
<activity android:name=".Home" />
<activity android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
android:theme="@style/Base.Theme.AppCompat"/>

Expand All @@ -32,6 +31,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Home" />
</application>

</manifest>
76 changes: 60 additions & 16 deletions app/src/main/java/app/web/gourav_khunger/textrecognizer/Home.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.appcompat.widget.Toolbar;
import androidx.cardview.widget.CardView;
import androidx.core.content.ContextCompat;

import android.Manifest;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.ActivityNotFoundException;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.provider.MediaStore;
import android.text.TextUtils;
import android.view.Menu;
Expand All @@ -32,7 +34,6 @@
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.github.javiersantos.appupdater.AppUpdater;
import com.github.javiersantos.appupdater.AppUpdaterUtils;
import com.github.javiersantos.appupdater.enums.AppUpdaterError;
import com.github.javiersantos.appupdater.enums.UpdateFrom;
Expand All @@ -56,6 +57,8 @@ public class Home extends AppCompatActivity {
Button captureImage, selectFromStorage, clearAll, processImage, crop;
TextView selectImageText;
Bitmap bitmap = null;
SharedPreferences preferences;
SharedPreferences.Editor editor;

private static final int PICK_IMAGE_CODE = 0;
private static final int CAPTURE_IMAGE_CODE = 1;
Expand All @@ -68,10 +71,25 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);

preferences = PreferenceManager.getDefaultSharedPreferences(this);

init();

}

@Override
protected void onStart() {
super.onStart();
boolean isDark = preferences.getBoolean("theme", false);
if(isDark){
AppCompatDelegate.setDefaultNightMode
(AppCompatDelegate.MODE_NIGHT_YES);
} else {
AppCompatDelegate.setDefaultNightMode
(AppCompatDelegate.MODE_NIGHT_NO);
}
}

private void init() {
AppUpdaterUtils appUpdaterUtils = new AppUpdaterUtils(this)
.setUpdateFrom(UpdateFrom.GITHUB)
Expand All @@ -80,7 +98,7 @@ private void init() {
@Override
public void onSuccess(Update update, Boolean isUpdateAvailable) {
if(isUpdateAvailable){
AlertDialog.Builder builder = new AlertDialog.Builder(Home.this);
AlertDialog.Builder builder = new AlertDialog.Builder(Home.this, R.style.AlertDialogTheme);
builder.setTitle("Wohhhooo!!!")
.setMessage("A new update of the app is available!!\n\nPlease Open the link and install latest APK")
.setCancelable(false)
Expand All @@ -106,7 +124,7 @@ public void onFailed(AppUpdaterError error) {
.text("Error checking update!")
.textColor(Color.RED)
.backgroundColor(ContextCompat.getColor(Home.this, R.color.green))
.font(R.font.google)
.font(R.font.font)
.show();
}
});
Expand All @@ -131,7 +149,7 @@ public void onFailed(AppUpdaterError error) {
.text("I'm confused :(")
.textColor(Color.WHITE)
.backgroundColor(Color.RED)
.font(R.font.google)
.font(R.font.font)
.show();
}

Expand Down Expand Up @@ -172,7 +190,7 @@ private void copyText(String text) {
.text("Text Copied!")
.textColor(Color.WHITE)
.backgroundColor(ContextCompat.getColor(this, R.color.green))
.font(R.font.google)
.font(R.font.font)
.show();
}
}
Expand Down Expand Up @@ -201,7 +219,7 @@ private void captureAnImage() {
.text("Error: ")
.textColor(Color.WHITE)
.backgroundColor(Color.RED)
.font(R.font.google)
.font(R.font.font)
.show();
}
}
Expand Down Expand Up @@ -237,7 +255,7 @@ private void processImage() {
String text = result.getText();
dialog.dismiss();
if (!TextUtils.isEmpty(text) && text != null) {
AlertDialog.Builder builder = new AlertDialog.Builder(Home.this);
AlertDialog.Builder builder = new AlertDialog.Builder(Home.this, R.style.AlertDialogTheme);
builder.setTitle("Text Recognized")
.setMessage(text)
.setCancelable(false)
Expand All @@ -252,7 +270,7 @@ private void processImage() {
});
alert.show();
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(Home.this);
AlertDialog.Builder builder = new AlertDialog.Builder(Home.this, R.style.AlertDialogTheme);
builder.setTitle("Ooof")
.setMessage("No Text Detected!")
.setCancelable(false)
Expand All @@ -273,7 +291,7 @@ private void processImage() {
.text("Error: " + e.getMessage())
.textColor(Color.WHITE)
.backgroundColor(Color.RED)
.font(R.font.google)
.font(R.font.font)
.show();
});
}
Expand Down Expand Up @@ -326,8 +344,6 @@ public void onActivityResult(int requestCode,
} else {
hideAll();
}


}

if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
Expand All @@ -351,7 +367,7 @@ public void onActivityResult(int requestCode,
.text("Saved storage by deleting unwanted image crop data :)")
.textColor(Color.WHITE)
.backgroundColor(ContextCompat.getColor(this, R.color.blue))
.font(R.font.google)
.font(R.font.font)
.length(Toast.LENGTH_LONG)
.show();
} else {
Expand All @@ -360,7 +376,7 @@ public void onActivityResult(int requestCode,
.text("Could not delete unwanted cropped image data :(")
.textColor(Color.WHITE)
.backgroundColor(Color.RED)
.font(R.font.google)
.font(R.font.font)
.length(Toast.LENGTH_LONG)
.show();
}
Expand All @@ -381,13 +397,20 @@ public void onActivityResult(int requestCode,
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);

if(isDarkTheme()){
menu.findItem(R.id.themeSwitcher).setIcon(R.drawable.day);
} else{
menu.findItem(R.id.themeSwitcher).setIcon(R.drawable.night);
}

return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.about) {
AlertDialog.Builder builder = new AlertDialog.Builder(Home.this);
AlertDialog.Builder builder = new AlertDialog.Builder(Home.this, R.style.AlertDialogTheme);
builder.setTitle("About")
.setMessage(getResources().getString(R.string.about))
.setCancelable(false)
Expand All @@ -398,7 +421,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
.text("Thank you :)")
.textColor(Color.WHITE)
.backgroundColor(ContextCompat.getColor(this, R.color.green))
.font(R.font.google)
.font(R.font.font)
.show();
});
AlertDialog alert = builder.create();
Expand All @@ -409,8 +432,29 @@ public boolean onOptionsItemSelected(MenuItem item) {
});
alert.show();
return true;
} else if(item.getItemId() == R.id.themeSwitcher) {
editor = preferences.edit();
if (isDarkTheme()) {
AppCompatDelegate.setDefaultNightMode
(AppCompatDelegate.MODE_NIGHT_NO);
item.setIcon(R.drawable.night);

editor.putBoolean("theme", false);
editor.apply();
} else {
AppCompatDelegate.setDefaultNightMode
(AppCompatDelegate.MODE_NIGHT_YES);
item.setIcon(R.drawable.day);

editor.putBoolean("theme", true);
editor.apply();
}
}
return super.onOptionsItemSelected(item);
}

public boolean isDarkTheme() {
return AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES;
}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package app.web.gourav_khunger.textrecognizer;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
Expand All @@ -14,11 +17,24 @@ public class Splash extends AppCompatActivity {
ImageView image;
TextView title, slogan;
Animation fade, zoom;
SharedPreferences preferences;
SharedPreferences.Editor editor;

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

preferences = PreferenceManager.getDefaultSharedPreferences(this);
boolean isDark = preferences.getBoolean("theme", false);
if(isDark){
AppCompatDelegate.setDefaultNightMode
(AppCompatDelegate.MODE_NIGHT_YES);
} else {
AppCompatDelegate.setDefaultNightMode
(AppCompatDelegate.MODE_NIGHT_NO);
}

setContentView(R.layout.activity_splash);

image = findViewById(R.id.image_splash);
Expand Down Expand Up @@ -56,4 +72,9 @@ public void onAnimationRepeat(Animation animation) {
title.startAnimation(zoom);
slogan.startAnimation(zoom);
}

public boolean isDarkTheme() {
return AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES;
}

}
6 changes: 6 additions & 0 deletions app/src/main/res/drawable/day.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<vector android:height="24dp" android:viewportHeight="512"
android:viewportWidth="512" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FFA600" android:pathData="M507.834,301.608l-54.769,-48.312l52.832,-50.399c1.941,-1.852 2.74,-4.591 2.099,-7.189c-0.642,-2.597 -2.629,-4.655 -5.211,-5.401l-70.316,-20.292l25.988,-68.056c0.955,-2.5 0.495,-5.316 -1.204,-7.389c-1.7,-2.072 -4.383,-3.085 -7.038,-2.657l-72.274,11.652l-5.878,-72.561c-0.216,-2.666 -1.846,-5.015 -4.275,-6.161c-2.429,-1.146 -5.291,-0.917 -7.504,0.601l-60.266,41.342L263.409,3.742C262.064,1.426 259.579,0 256.889,0c-2.69,0 -5.174,1.426 -6.519,3.742L208.347,76.11l-72.69,-41.953c-2.327,-1.343 -5.197,-1.349 -7.528,-0.018c-2.333,1.331 -3.773,3.799 -3.78,6.473l-0.176,72.795l-72.965,-6.014c-2.675,-0.22 -5.275,0.997 -6.807,3.194c-1.533,2.197 -1.771,5.041 -0.622,7.459l31.242,65.835L6.508,209.562c-2.516,0.943 -4.335,3.15 -4.773,5.789c-0.438,2.638 0.575,5.308 2.656,7.003l56.619,46.152l-50.813,52.41c-1.866,1.925 -2.559,4.694 -1.816,7.264c0.744,2.57 2.81,4.55 5.419,5.194l71.055,17.551L61.56,419.936c-0.856,2.535 -0.286,5.331 1.494,7.336c1.781,2.005 4.502,2.913 7.137,2.382l71.76,-14.443l8.721,72.278c0.319,2.655 2.041,4.938 4.513,5.99c2.474,1.052 5.323,0.712 7.475,-0.891l58.596,-43.647l39.055,59.566c1.382,2.179 3.789,3.492 6.367,3.492c0.098,0 0.196,-0.002 0.295,-0.006c2.687,-0.104 5.115,-1.626 6.368,-3.992l34.107,-62.405l61.839,38.974c2.273,1.432 5.137,1.55 7.522,0.31c2.382,-1.24 3.919,-3.65 4.03,-6.322l3.031,-72.734l72.674,8.84c2.664,0.324 5.31,-0.791 6.928,-2.927c1.618,-2.137 1.966,-4.969 0.914,-7.43l-28.636,-66.997l69.465,-23.003c2.552,-0.845 4.456,-2.979 4.997,-5.599C510.752,306.09 509.845,303.383 507.834,301.608z"/>
<path android:fillColor="#FFDB2D" android:pathData="M99.281,254.691a155.069,154.949 0,1 0,310.138 0a155.069,154.949 0,1 0,-310.138 0z"/>
<path android:fillColor="#FFCA00" android:pathData="M254.354,99.743c-3.884,0 -7.732,0.147 -11.543,0.428c80.25,5.901 143.525,72.825 143.525,154.521c0,81.695 -63.275,148.619 -143.525,154.521c3.811,0.28 7.66,0.428 11.543,0.428c85.641,0 155.068,-69.373 155.068,-154.948C409.422,169.116 339.995,99.743 254.354,99.743z"/>
</vector>
36 changes: 36 additions & 0 deletions app/src/main/res/drawable/night.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="512"
android:viewportHeight="512">
<path
android:pathData="M255.994,255.994m-255.994,0a255.994,255.994 0,1 1,511.988 0a255.994,255.994 0,1 1,-511.988 0"
android:fillColor="#27536B"/>
<path
android:pathData="M391.37,292.817c-48.362,48.362 -126.774,48.362 -175.136,0s-48.362,-126.774 0,-175.136c10.084,-10.084 21.476,-18.057 33.627,-23.935c-39.798,1.061 -79.279,16.774 -109.653,47.147c-62.946,62.946 -62.946,165.003 0,227.949s165.003,62.946 227.949,0c30.374,-30.374 46.086,-69.854 47.147,-109.653C409.427,271.341 401.454,282.733 391.37,292.817z"
android:fillColor="#FCD57E"/>
<path
android:pathData="M355.804,153.568l5.709,51.649l5.711,-51.649l51.649,-5.709l-51.649,-5.711l-5.711,-51.649l-5.709,51.649l-51.65,5.711z"
android:fillColor="#FFFFFF"/>
<path
android:pathData="M112.365,410.626l4.09,36.997l4.09,-36.997l36.997,-4.09l-36.997,-4.09l-4.09,-36.997l-4.09,36.997l-36.997,4.09z"
android:fillColor="#FFFFFF"/>
<path
android:pathData="M241.038,253.389l7.327,-7.327l7.327,7.327l-7.327,7.327z"
android:fillColor="#FFFFFF"/>
<path
android:pathData="M416.78,198.56l7.327,-7.327l7.327,7.327l-7.327,7.327z"
android:fillColor="#FFFFFF"/>
<path
android:pathData="M447.866,289.602l7.327,-7.327l7.327,7.327l-7.327,7.327z"
android:fillColor="#FFFFFF"/>
<path
android:pathData="M73.92,129.716l7.327,-7.327l7.327,7.327l-7.327,7.327z"
android:fillColor="#FFFFFF"/>
<path
android:pathData="M344.171,426.613l7.327,-7.327l7.327,7.327l-7.327,7.327z"
android:fillColor="#FFFFFF"/>
<path
android:pathData="M115.44,103.065l7.327,-7.327l7.327,7.327l-7.327,7.327z"
android:fillColor="#FFFFFF"/>
</vector>
File renamed without changes.
Loading

0 comments on commit fb6ad28

Please sign in to comment.