From 8a7810d8fee109d47e2ea29a6fa172cbb2358232 Mon Sep 17 00:00:00 2001 From: SlaVcE <102253539+SlaVcE14@users.noreply.github.com> Date: Tue, 7 Nov 2023 20:34:41 +0100 Subject: [PATCH 1/8] Snackbar update --- app/src/main/res/values-night/themes.xml | 9 ++++++++- app/src/main/res/values/themes.xml | 10 ++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml index 740c111..fcdc74c 100644 --- a/app/src/main/res/values-night/themes.xml +++ b/app/src/main/res/values-night/themes.xml @@ -33,6 +33,8 @@ ?android:windowBackgroundFallback #000000 #000000 + @style/SnackbarStyle + @style/SnackbarStyle - + \ No newline at end of file diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index a2bcd74..4bac1e7 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -34,7 +34,8 @@ #ffffff true - + @style/SnackbarStyle + @style/SnackbarStyle @style/ButtonColor - + \ No newline at end of file From 977e71a2803b641b554c5abfa0e099345e55e113 Mon Sep 17 00:00:00 2001 From: SlaVcE <102253539+SlaVcE14@users.noreply.github.com> Date: Wed, 8 Nov 2023 23:21:14 +0100 Subject: [PATCH 2/8] update file reading - replace Scanner with BufferedReader --- .../java/com/sjapps/jsonlist/FileSystem.java | 34 +++++-------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/com/sjapps/jsonlist/FileSystem.java b/app/src/main/java/com/sjapps/jsonlist/FileSystem.java index e7fb928..696491b 100644 --- a/app/src/main/java/com/sjapps/jsonlist/FileSystem.java +++ b/app/src/main/java/com/sjapps/jsonlist/FileSystem.java @@ -4,10 +4,11 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import java.io.BufferedReader; import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStreamReader; import java.nio.file.Path; -import java.util.Scanner; public class FileSystem { @@ -30,39 +31,22 @@ public static String LoadDataFromFile(MainActivity mainActivity, Uri uri) { } StringBuilder sb = new StringBuilder(); - FileInputStream inputStream = null; - Scanner sc = null; try { - inputStream = (FileInputStream) mainActivity.getContentResolver().openInputStream(uri); - sc = new Scanner(inputStream, "UTF-8"); + FileInputStream inputStream = (FileInputStream) mainActivity.getContentResolver().openInputStream(uri); + BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); - while (sc.hasNextLine()) { - String line = sc.nextLine(); + String line; + while ((line = reader.readLine()) != null) { sb.append(line); } - if (sc.ioException() != null) { - throw sc.ioException(); - } - + inputStream.close(); + reader.close(); + return sb.toString(); } catch (IOException e) { e.printStackTrace(); return null; - } finally { - if (inputStream != null) { - try { - inputStream.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - if (sc != null) { - sc.close(); - } - return sb.toString(); - //todo fix this - } } } From 458cb63457569d66e6e96ce2502f6823a006dd24 Mon Sep 17 00:00:00 2001 From: SlaVcE <102253539+SlaVcE14@users.noreply.github.com> Date: Thu, 9 Nov 2023 01:26:59 +0100 Subject: [PATCH 3/8] Update loading animation --- .../com/sjapps/jsonlist/MainActivity.java | 27 ++++++---- app/src/main/res/anim/scale_in.xml | 16 ++++++ app/src/main/res/anim/scale_out.xml | 16 ++++++ .../res/drawable/background_transparent.xml | 6 +++ app/src/main/res/layout/activity_main.xml | 54 ++++++++++++------- 5 files changed, 91 insertions(+), 28 deletions(-) create mode 100644 app/src/main/res/anim/scale_in.xml create mode 100644 app/src/main/res/anim/scale_out.xml create mode 100644 app/src/main/res/drawable/background_transparent.xml diff --git a/app/src/main/java/com/sjapps/jsonlist/MainActivity.java b/app/src/main/java/com/sjapps/jsonlist/MainActivity.java index a6f2c1c..9fd6991 100644 --- a/app/src/main/java/com/sjapps/jsonlist/MainActivity.java +++ b/app/src/main/java/com/sjapps/jsonlist/MainActivity.java @@ -5,9 +5,12 @@ import androidx.activity.OnBackPressedCallback; import androidx.activity.result.ActivityResultLauncher; import androidx.activity.result.contract.ActivityResultContracts; +import androidx.annotation.AnimRes; +import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import android.app.Activity; +import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Bundle; @@ -17,8 +20,11 @@ import android.util.Log; import android.view.View; import android.view.ViewGroup; +import android.view.animation.Animation; +import android.view.animation.AnimationUtils; import android.widget.Button; import android.widget.ImageButton; +import android.widget.LinearLayout; import android.widget.ListView; import android.widget.ProgressBar; import android.widget.TextView; @@ -48,8 +54,8 @@ public class MainActivity extends AppCompatActivity { TextView titleTxt, emptyListTxt; ListView list; JsonData data = new JsonData(); + LinearLayout progressView; ProgressBar progressBar; - TextView loadingFileTxt; boolean isMenuOpen; ListAdapter adapter; View menu, dim_bg; @@ -147,8 +153,8 @@ private void initialize() { viewGroup = findViewById(R.id.content); menu = findViewById(R.id.menu); dim_bg = findViewById(R.id.dim_layout); + progressView = findViewById(R.id.loadingView); progressBar = findViewById(R.id.progressBar); - loadingFileTxt = findViewById(R.id.LoadFileTxt); dim_bg.bringToFront(); menu.bringToFront(); menuBtn.bringToFront(); @@ -196,17 +202,16 @@ private void LoadData(String Data) { return; } + loadingStarted("creating list"); try { if (element instanceof JsonObject) { Log.d(TAG, "run: Json object"); JsonObject object = FileSystem.loadDataToJsonObj(element); - Log.d(TAG, "LoadData: " + object); data.setRootList(getJsonObject(object)); } if (element instanceof JsonArray) { Log.d(TAG, "run: Json array"); JsonArray array = FileSystem.loadDataToJsonArray(element); - Log.d(TAG, "LoadData: " + array); data.setRootList(getJsonArrayRoot(array)); } } catch (Exception e){ @@ -228,7 +233,7 @@ private void LoadData(String Data) { } else data.setRootList(temp); - handler.post(() -> progressBar.setVisibility(View.GONE)); + handler.post(() -> loadingFinished(true)); }); readFileThread.start(); @@ -292,8 +297,7 @@ void ReadFile(Uri uri){ if (readFileThread != null && readFileThread.isAlive()){ return; } - progressBar.setVisibility(View.VISIBLE); - loadingFileTxt.setVisibility(View.VISIBLE); + loadingStarted("Reading file"); readFileThread = new Thread(() -> { @@ -304,8 +308,7 @@ void ReadFile(Uri uri){ return; } handler.post(() -> { - progressBar.setVisibility(View.GONE); - loadingFileTxt.setVisibility(View.GONE); + loadingFinished(false); LoadData(Data); }); @@ -314,6 +317,10 @@ void ReadFile(Uri uri){ } + public void updateProgress(int val){ + progressBar.setIndeterminate(false); + progressBar.setProgress(val); + } void fileTooLargeException(){ postMessageException("File is too large"); } @@ -326,7 +333,7 @@ void creatingListException(){ void postMessageException(String msg){ handler.post(() -> { Toast.makeText(MainActivity.this,msg, Toast.LENGTH_SHORT).show(); - progressBar.setVisibility(View.GONE); + loadingFinished(false); }); } } \ No newline at end of file diff --git a/app/src/main/res/anim/scale_in.xml b/app/src/main/res/anim/scale_in.xml new file mode 100644 index 0000000..7580a87 --- /dev/null +++ b/app/src/main/res/anim/scale_in.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/scale_out.xml b/app/src/main/res/anim/scale_out.xml new file mode 100644 index 0000000..b3440f4 --- /dev/null +++ b/app/src/main/res/anim/scale_out.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/background_transparent.xml b/app/src/main/res/drawable/background_transparent.xml new file mode 100644 index 0000000..79dbd43 --- /dev/null +++ b/app/src/main/res/drawable/background_transparent.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index aea940e..6a1cdab 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -109,26 +109,44 @@ android:layout_marginBottom="20dp" > - - - - + android:minWidth="150dp" + android:animateLayoutChanges="true" + android:background="@drawable/background_transparent" + + android:padding="10dp" + android:layout_marginBottom="20dp" + android:visibility="invisible" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintEnd_toEndOf="parent" + android:elevation="5dp" + android:orientation="vertical"> + + + + From d26c47dd6ff2459a05d0c3c300033ca5425647cf Mon Sep 17 00:00:00 2001 From: SlaVcE <102253539+SlaVcE14@users.noreply.github.com> Date: Thu, 9 Nov 2023 01:27:43 +0100 Subject: [PATCH 4/8] Update MainActivity.java --- app/src/main/java/com/sjapps/jsonlist/MainActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/sjapps/jsonlist/MainActivity.java b/app/src/main/java/com/sjapps/jsonlist/MainActivity.java index 9fd6991..dfa4d06 100644 --- a/app/src/main/java/com/sjapps/jsonlist/MainActivity.java +++ b/app/src/main/java/com/sjapps/jsonlist/MainActivity.java @@ -179,7 +179,7 @@ private void open_closeMenu() { private void LoadData(String Data) { - progressBar.setVisibility(View.VISIBLE); + loadingStarted("loading json"); emptyListTxt.setVisibility(View.GONE); readFileThread = new Thread(() -> { From eb1ff35a7a3e84d046fd222d5795c117a228dbf8 Mon Sep 17 00:00:00 2001 From: SlaVcE <102253539+SlaVcE14@users.noreply.github.com> Date: Tue, 19 Dec 2023 23:53:25 +0100 Subject: [PATCH 5/8] loading animation update --- .../java/com/sjapps/jsonlist/FileSystem.java | 8 ++++ .../com/sjapps/jsonlist/MainActivity.java | 44 +++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/app/src/main/java/com/sjapps/jsonlist/FileSystem.java b/app/src/main/java/com/sjapps/jsonlist/FileSystem.java index 696491b..d34a32f 100644 --- a/app/src/main/java/com/sjapps/jsonlist/FileSystem.java +++ b/app/src/main/java/com/sjapps/jsonlist/FileSystem.java @@ -1,9 +1,11 @@ package com.sjapps.jsonlist; +import android.content.res.AssetFileDescriptor; import android.net.Uri; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; + import java.io.BufferedReader; import java.io.FileInputStream; import java.io.IOException; @@ -35,9 +37,15 @@ public static String LoadDataFromFile(MainActivity mainActivity, Uri uri) { FileInputStream inputStream = (FileInputStream) mainActivity.getContentResolver().openInputStream(uri); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); + AssetFileDescriptor fileDescriptor = mainActivity.getContentResolver().openAssetFileDescriptor(uri , "r"); + + long currentBytes = 0; + long fileSize = fileDescriptor.getLength(); String line; while ((line = reader.readLine()) != null) { sb.append(line); + currentBytes += line.length(); + mainActivity.updateProgress((int)((currentBytes/(float)fileSize)*100)); } inputStream.close(); diff --git a/app/src/main/java/com/sjapps/jsonlist/MainActivity.java b/app/src/main/java/com/sjapps/jsonlist/MainActivity.java index dfa4d06..39a1cae 100644 --- a/app/src/main/java/com/sjapps/jsonlist/MainActivity.java +++ b/app/src/main/java/com/sjapps/jsonlist/MainActivity.java @@ -317,10 +317,54 @@ void ReadFile(Uri uri){ } + void loadingStarted(){ + loadingStarted("loading..."); + + } + + void loadingStarted(String txt){ + TextView text = progressView.findViewById(R.id.loadingTxt); + progressBar.setIndeterminate(true); + text.setText(txt); + handler.postDelayed(() -> { + setAnimation(this,progressView,R.anim.scale_in); + text.setVisibility(View.VISIBLE); + progressView.setVisibility(View.VISIBLE); + },300); + + } public void updateProgress(int val){ progressBar.setIndeterminate(false); progressBar.setProgress(val); } + + void loadingFinished(boolean isFinished){ + + if (!isFinished){ + setAnimation(this, progressView,R.anim.scale_out); + progressView.setVisibility(View.INVISIBLE); + return; + } + + progressBar.setIndeterminate(false); + progressBar.setProgress(100); + + TextView text = progressView.findViewById(R.id.loadingTxt); + handler.postDelayed(() -> text.setText( "finished"),500); + handler.postDelayed(() -> { + },700); + handler.postDelayed(() -> text.setVisibility(View.INVISIBLE),900); + handler.postDelayed(() -> { + setAnimation(this, progressView,R.anim.scale_out); + progressView.setVisibility(View.INVISIBLE); + },1000); + } + + public static void setAnimation(Context context, @NonNull View view, @AnimRes int animationRes) { + Animation animation = AnimationUtils.loadAnimation(context, animationRes); + view.startAnimation(animation); + } + void fileTooLargeException(){ postMessageException("File is too large"); } From c2d160df8f0e88a6f6d94cdc361ca3dd1513bee1 Mon Sep 17 00:00:00 2001 From: SlaVcE <102253539+SlaVcE14@users.noreply.github.com> Date: Tue, 19 Dec 2023 23:56:07 +0100 Subject: [PATCH 6/8] Update FileSystem.java --- app/src/main/java/com/sjapps/jsonlist/FileSystem.java | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/com/sjapps/jsonlist/FileSystem.java b/app/src/main/java/com/sjapps/jsonlist/FileSystem.java index d34a32f..2f8719c 100644 --- a/app/src/main/java/com/sjapps/jsonlist/FileSystem.java +++ b/app/src/main/java/com/sjapps/jsonlist/FileSystem.java @@ -48,6 +48,7 @@ public static String LoadDataFromFile(MainActivity mainActivity, Uri uri) { mainActivity.updateProgress((int)((currentBytes/(float)fileSize)*100)); } + fileDescriptor.close(); inputStream.close(); reader.close(); From 8b663efeb12350d20d00ab5316ccb54111582a6e Mon Sep 17 00:00:00 2001 From: SlaVcE <102253539+SlaVcE14@users.noreply.github.com> Date: Wed, 20 Dec 2023 15:42:44 +0100 Subject: [PATCH 7/8] loading animation update --- .../java/com/sjapps/jsonlist/MainActivity.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/sjapps/jsonlist/MainActivity.java b/app/src/main/java/com/sjapps/jsonlist/MainActivity.java index 39a1cae..6d28ad7 100644 --- a/app/src/main/java/com/sjapps/jsonlist/MainActivity.java +++ b/app/src/main/java/com/sjapps/jsonlist/MainActivity.java @@ -308,7 +308,6 @@ void ReadFile(Uri uri){ return; } handler.post(() -> { - loadingFinished(false); LoadData(Data); }); @@ -327,9 +326,11 @@ void loadingStarted(String txt){ progressBar.setIndeterminate(true); text.setText(txt); handler.postDelayed(() -> { - setAnimation(this,progressView,R.anim.scale_in); - text.setVisibility(View.VISIBLE); - progressView.setVisibility(View.VISIBLE); + if (progressView.getVisibility() != View.VISIBLE) { + setAnimation(this, progressView, R.anim.scale_in); + text.setVisibility(View.VISIBLE); + progressView.setVisibility(View.VISIBLE); + } },300); } @@ -341,8 +342,10 @@ public void updateProgress(int val){ void loadingFinished(boolean isFinished){ if (!isFinished){ - setAnimation(this, progressView,R.anim.scale_out); - progressView.setVisibility(View.INVISIBLE); + handler.postDelayed(()-> { + setAnimation(this, progressView,R.anim.scale_out); + progressView.setVisibility(View.INVISIBLE); + },300); return; } From 88ce83b7c0a4c4adb8ab3d9b34bc332b9e79e49e Mon Sep 17 00:00:00 2001 From: SlaVcE <102253539+SlaVcE14@users.noreply.github.com> Date: Wed, 20 Dec 2023 15:50:55 +0100 Subject: [PATCH 8/8] add start screen animation --- .../com/sjapps/jsonlist/MainActivity.java | 22 +++++++++ app/src/main/res/anim/button_pop.xml | 26 ++++++++++ app/src/main/res/anim/scale_in2.xml | 24 ++++++++++ app/src/main/res/anim/scale_in_file_img.xml | 47 +++++++++++++++++++ app/src/main/res/layout/activity_main.xml | 14 ++++++ 5 files changed, 133 insertions(+) create mode 100644 app/src/main/res/anim/button_pop.xml create mode 100644 app/src/main/res/anim/scale_in2.xml create mode 100644 app/src/main/res/anim/scale_in_file_img.xml diff --git a/app/src/main/java/com/sjapps/jsonlist/MainActivity.java b/app/src/main/java/com/sjapps/jsonlist/MainActivity.java index 6d28ad7..a75fc33 100644 --- a/app/src/main/java/com/sjapps/jsonlist/MainActivity.java +++ b/app/src/main/java/com/sjapps/jsonlist/MainActivity.java @@ -22,8 +22,12 @@ import android.view.ViewGroup; import android.view.animation.Animation; import android.view.animation.AnimationUtils; +import android.view.animation.DecelerateInterpolator; +import android.view.animation.Interpolator; +import android.view.animation.OvershootInterpolator; import android.widget.Button; import android.widget.ImageButton; +import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.ProgressBar; @@ -50,6 +54,7 @@ public class MainActivity extends AppCompatActivity { final String TAG = "MainActivity"; ImageButton backBtn, menuBtn; + ImageView fileImg; Button openFileBtn; TextView titleTxt, emptyListTxt; ListView list; @@ -75,6 +80,10 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initialize(); + + setAnimation(this,fileImg,R.anim.scale_in_file_img, new DecelerateInterpolator()); + setAnimation(this,openFileBtn,R.anim.button_pop, new OvershootInterpolator()); + autoTransition.setDuration(150); menuBtn.setOnClickListener(view -> open_closeMenu()); @@ -155,6 +164,7 @@ private void initialize() { dim_bg = findViewById(R.id.dim_layout); progressView = findViewById(R.id.loadingView); progressBar = findViewById(R.id.progressBar); + fileImg = findViewById(R.id.fileImg); dim_bg.bringToFront(); menu.bringToFront(); menuBtn.bringToFront(); @@ -225,7 +235,12 @@ private void LoadData(String Data) { TransitionManager.beginDelayedTransition(viewGroup, autoTransition); adapter = new ListAdapter(data.getRootList(), MainActivity.this, ""); list.setAdapter(adapter); + fileImg.clearAnimation(); + openFileBtn.clearAnimation(); + fileImg.setVisibility(View.GONE); openFileBtn.setVisibility(View.GONE); + setAnimation(MainActivity.this,list,R.anim.scale_in2,new DecelerateInterpolator()); + list.setVisibility(View.VISIBLE); backBtn.setVisibility(View.GONE); titleTxt.setText(""); data.clearPath(); @@ -363,8 +378,15 @@ void loadingFinished(boolean isFinished){ },1000); } + public static void setAnimation(Context context, @NonNull View view, @AnimRes int animationRes) { + setAnimation(context,view,animationRes,null); + } + + public static void setAnimation(Context context, @NonNull View view, @AnimRes int animationRes, Interpolator interpolator) { Animation animation = AnimationUtils.loadAnimation(context, animationRes); + if (interpolator != null) + animation.setInterpolator(interpolator); view.startAnimation(animation); } diff --git a/app/src/main/res/anim/button_pop.xml b/app/src/main/res/anim/button_pop.xml new file mode 100644 index 0000000..05b7596 --- /dev/null +++ b/app/src/main/res/anim/button_pop.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + diff --git a/app/src/main/res/anim/scale_in2.xml b/app/src/main/res/anim/scale_in2.xml new file mode 100644 index 0000000..11d602b --- /dev/null +++ b/app/src/main/res/anim/scale_in2.xml @@ -0,0 +1,24 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/scale_in_file_img.xml b/app/src/main/res/anim/scale_in_file_img.xml new file mode 100644 index 0000000..03f955c --- /dev/null +++ b/app/src/main/res/anim/scale_in_file_img.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 6a1cdab..18320d3 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -83,8 +83,22 @@ android:divider="@null" android:layout_below="@+id/titlePanel" android:listSelector="@drawable/transparent_drawable" + android:visibility="gone" /> + +