diff --git a/.github/workflows/build-release-apk.yml b/.github/workflows/build-release-apk.yml index 4c52a99..63b368b 100644 --- a/.github/workflows/build-release-apk.yml +++ b/.github/workflows/build-release-apk.yml @@ -2,8 +2,6 @@ name: Latest build(release) on: workflow_dispatch: - branches: - - master jobs: build: diff --git a/.gitignore b/.gitignore index 8289955..c194e89 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,9 @@ /.gradle /.idea /*/build +/output /build /settings.json /app/app_config.json /app/libraries.json -/app/repositories.json \ No newline at end of file +/app/repositories.json diff --git a/README.md b/README.md index c2d9f4c..a6c4985 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ An useful tool for Android Developers & Reversers, which shows the package name and class name of current activity which you are in

-[![App](https://img.shields.io/badge/Current%20Activity-1.5.5-blue?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48ZyBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiIHN0cm9rZT0iI2ZmZmZmZiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIiBzdHJva2Utd2lkdGg9IjEuNSIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoMiAxLjUpIj48cG9seWxpbmUgcG9pbnRzPSI1LjI0NSAxMy4yODEgOC4yMzggOS4zOTEgMTEuNjUyIDEyLjA3MyAxNC41ODEgOC4yOTMiLz48Y2lyY2xlIGN4PSIxNy45OTUiIGN5PSIyLjciIHI9IjEuOTIyIi8+PHBhdGggZD0iTTEyLjkyNDQ4NTIsMS42MjAxMzczMSBMNS42NTY3NTA2LDEuNjIwMTM3MzEgQzIuNjQ1MzA4OTQsMS42MjAxMzczMSAwLjc3ODAzMjA0MSwzLjc1Mjg2MDQzIDAuNzc4MDMyMDQxLDYuNzY0MzAyMDkgTDAuNzc4MDMyMDQxLDE0Ljg0NjY4MiBDMC43NzgwMzIwNDEsMTcuODU4MTIzNyAyLjYwODY5NTY3LDE5Ljk4MTY5MzUgNS42NTY3NTA2LDE5Ljk4MTY5MzUgTDE0LjI2MDg2OTYsMTkuOTgxNjkzNSBDMTcuMjcyMzExMywxOS45ODE2OTM1IDE5LjEzOTU4ODIsMTcuODU4MTIzNyAxOS4xMzk1ODgyLDE0Ljg0NjY4MiBMMTkuMTM5NTg4Miw3LjgwNzc4MDM2Ii8+PC9nPjwvc3ZnPg==)](https://github.com/RatulHasan8/Current-Activity/releases/tag/app-n-source) +[![App](https://img.shields.io/badge/Current%20Activity-1.5.8-blue?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48ZyBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiIHN0cm9rZT0iI2ZmZmZmZiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIiBzdHJva2Utd2lkdGg9IjEuNSIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoMiAxLjUpIj48cG9seWxpbmUgcG9pbnRzPSI1LjI0NSAxMy4yODEgOC4yMzggOS4zOTEgMTEuNjUyIDEyLjA3MyAxNC41ODEgOC4yOTMiLz48Y2lyY2xlIGN4PSIxNy45OTUiIGN5PSIyLjciIHI9IjEuOTIyIi8+PHBhdGggZD0iTTEyLjkyNDQ4NTIsMS42MjAxMzczMSBMNS42NTY3NTA2LDEuNjIwMTM3MzEgQzIuNjQ1MzA4OTQsMS42MjAxMzczMSAwLjc3ODAzMjA0MSwzLjc1Mjg2MDQzIDAuNzc4MDMyMDQxLDYuNzY0MzAyMDkgTDAuNzc4MDMyMDQxLDE0Ljg0NjY4MiBDMC43NzgwMzIwNDEsMTcuODU4MTIzNyAyLjYwODY5NTY3LDE5Ljk4MTY5MzUgNS42NTY3NTA2LDE5Ljk4MTY5MzUgTDE0LjI2MDg2OTYsMTkuOTgxNjkzNSBDMTcuMjcyMzExMywxOS45ODE2OTM1IDE5LjEzOTU4ODIsMTcuODU4MTIzNyAxOS4xMzk1ODgyLDE0Ljg0NjY4MiBMMTkuMTM5NTg4Miw3LjgwNzc4MDM2Ii8+PC9nPjwvc3ZnPg==)](https://github.com/RatulHasan8/Current-Activity/releases/tag/app-n-source) [![SDK](https://img.shields.io/badge/Android-5.0%20and%20up-brightgreen?logo=android&logoColor=white)](https://github.com/RatulHasan8/Current-Activity/releases/tag/app-n-source) [![License](https://img.shields.io/badge/License-GPL-red?logo=gnu&logoColor=white)](https://github.com/RatulHasan8/Current-Activity/blob/main/LICENSE) [![Maintenance](https://img.shields.io/badge/Maintained-Yes-green?logo=data:image/svg+xml;base64,PHN2ZyBpZD0iQ2FwYV8xIiBlbmFibGUtYmFja2dyb3VuZD0ibmV3IDAgMCA1MTIuMjYgNTEyLjI2IiBoZWlnaHQ9IjUxMiIgdmlld0JveD0iMCAwIDUxMi4yNiA1MTIuMjYiIHdpZHRoPSI1MTIiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGcgZmlsbD0iI0ZGRkZGRiI+PHBhdGggZD0ibTM3MC4xMTkgMjgwLjYzNS0zNC4xMzkgMzQuMTM5LTM0LjE3NS0zNC4xNzUgODEuOTk2LTgxLjk5NmM5LjAxNCAyLjUzOCAxOC4yMTYgMy43NzkgMjcuMzY2IDMuNzc4IDI2LjMyOS0uMDAyIDUyLjE3OS0xMC4yODkgNzEuNDkxLTI5LjYwMSAyOC40MDctMjguNDA3IDM3LjI4OC03MC45NDggMjIuNjI2LTEwOC4zNzhsLTguMzYyLTIxLjM0OC01My42NjcgNTMuNjY4LTIxLjY2OS01LjgwNy01LjgwNy0yMS42NyA1My42NjYtNTMuNjY3LTIxLjM0NS04LjM2MWMtMzcuNDI3LTE0LjY2LTc5Ljk2OS01Ljc4LTEwOC4zNzggMjIuNjI3LTI2LjAyMyAyNi4wMjMtMzUuNjYgNjMuOTA2LTI1LjgyMiA5OC44NTZsLTgxLjk5NiA4MS45OTYtMTEwLjEwOS0xMTAuMTA5IDI5LjIxMy0yOS4yMTItOTAuNTQ1LTcxLjM2OS02MC40NjMgNjAuNDYyIDcxLjM2OCA5MC41NDYgMjkuMjE0LTI5LjIxMyAxMTAuMTA5IDExMC4xMDktNzIuMzg0IDcyLjM4NGMtMzcuNTkyLTExLjc3Ni03OC42MDUtMS45MzgtMTA2LjkgMjYuMzU3LTIwLjA5MyAyMC4wOTMtMzEuMTU5IDQ2LjgwOC0zMS4xNTkgNzUuMjIzczExLjA2NiA1NS4xMyAzMS4xNTkgNzUuMjIzYzIwLjczOSAyMC43MzkgNDcuOTggMzEuMTA4IDc1LjIyMyAzMS4xMDggMjcuMjQyIDAgNTQuNDg0LTEwLjM2OSA3NS4yMjMtMzEuMTA4IDI4LjI5NS0yOC4yOTUgMzguMTMzLTY5LjMwOSAyNi4zNTctMTA2LjlsNzIuMzg0LTcyLjM4NCAzNC4xNzUgMzQuMTc1LTM0LjEzOSAzNC4xMzkgMTIzLjU5MyAxMjMuNTkzYzExLjk1MiAxMS45NTIgMjcuODQzIDE4LjUzNCA0NC43NDYgMTguNTM0IDE2LjkwMiAwIDMyLjc5My02LjU4MiA0NC43NDUtMTguNTM0IDI0LjY3Mi0yNC42NzMgMjQuNjcyLTY0LjgxNyAwLTg5LjQ5em0tMzMwLjA1Ni0yMTcuODAyIDIyLjc2NS0yMi43NjUgNDMuMDkzIDMzLjk2Ny0zMS44OTEgMzEuODkxem0zMDguNTQ2IDczLjU4NC0zLjU4LTkuMTM5Yy0xMC4zMTMtMjYuMzI2LTQuMDctNTYuMjQ1IDE1LjkwNi03Ni4yMjIgMTMuODU5LTEzLjg1OCAzMi40OTctMjEuMTAzIDUxLjQxMi0yMC44MDVsLTMwLjAyOCAzMC4wMjkgMTQuNzcyIDU1LjEyOSA1NS4xMyAxNC43NzMgMzAuMDI3LTMwLjAyOGMuMzAzIDE4LjkxLTYuOTQ2IDM3LjU1NC0yMC44MDQgNTEuNDEyLTE5Ljk3NyAxOS45NzUtNDkuODk1IDI2LjIyLTc2LjIyMiAxNS45MDVsLTkuMTM4LTMuNTc5LTk1LjQ5MiA5NS40OTItMjcuNDc2LTI3LjQ3NnptLTE3NS41MDggMjMwLjQ2IDMuOTE4IDkuMjk4YzEyLjEyNiAyOC43NzQgNS42OTYgNjEuNjMyLTE2LjM4IDgzLjcwOC0xNC44OTMgMTQuODkyLTM0LjQ0OCAyMi4zMzctNTQuMDEgMjIuMzM1LTE5LjU1Ny0uMDAxLTM5LjEyMS03LjQ0Ni01NC4wMS0yMi4zMzUtMTQuNDI2LTE0LjQyNy0yMi4zNzItMzMuNjA3LTIyLjM3Mi01NC4wMXM3Ljk0NS0zOS41ODMgMjIuMzcyLTU0LjAxYzE0LjY3LTE0LjY2OSAzNC4wOTQtMjIuNDI5IDUzLjkyMy0yMi40MjkgMTAuMDEyIDAgMjAuMTMgMS45OCAyOS43ODQgNi4wNDlsOS4yOTggMy45MTggODYuMjc5LTg2LjI3OSAyNy40NzYgMjcuNDc2em0xOTcuMDE4LTQzLjgxNyAyNy40NzcgMjcuNDc3LTQ3LjA2NCA0Ny4wNjQtMjcuNDc2LTI3LjQ3NnptMTAyLjM4MiAxNDkuNDQ3Yy02LjI4NiA2LjI4NS0xNC42NDMgOS43NDctMjMuNTMyIDkuNzQ3cy0xNy4yNDctMy40NjItMjMuNTMyLTkuNzQ3bC01My42OTItNTMuNjkyIDQ3LjA2NC00Ny4wNjQgNTMuNjkyIDUzLjY5MmMxMi45NzUgMTIuOTc1IDEyLjk3NSAzNC4wODggMCA0Ny4wNjR6Ii8+PHBhdGggZD0ibTEwNi42MjkgMzU2LjQ0NGMtMTMuMjAzIDAtMjUuNjE2IDUuMTQyLTM0Ljk1MSAxNC40NzgtOS4zMzYgOS4zMzYtMTQuNDc4IDIxLjc0OC0xNC40NzggMzQuOTUxczUuMTQyIDI1LjYxNSAxNC40NzcgMzQuOTUxYzkuMzM2IDkuMzM2IDIxLjc0OSAxNC40NzggMzQuOTUyIDE0LjQ3OHMyNS42MTUtNS4xNDIgMzQuOTUyLTE0LjQ3OGMxOS4yNzEtMTkuMjcyIDE5LjI3MS01MC42MzEgMC02OS45MDItOS4zMzYtOS4zMzYtMjEuNzQ5LTE0LjQ3OC0zNC45NTItMTQuNDc4em0xMy43MzkgNjMuMTY3Yy0zLjY3IDMuNjY5LTguNTQ5IDUuNjktMTMuNzM4IDUuNjktNS4xOSAwLTEwLjA2OC0yLjAyMS0xMy43MzgtNS42OS0zLjY2OS0zLjY3LTUuNjktOC41NDktNS42OS0xMy43MzhzMi4wMjEtMTAuMDY4IDUuNjkxLTEzLjczOGMzLjY2OS0zLjY3IDguNTQ4LTUuNjkgMTMuNzM4LTUuNjkgNS4xODkgMCAxMC4wNjggMi4wMjEgMTMuNzM4IDUuNjkgNy41NzMgNy41NzUgNy41NzMgMTkuOTAxLS4wMDEgMjcuNDc2eiIvPjwvZz48L3N2Zz4=)](https://github.com/RatulHasan8/Current-Activity/graphs/commit-activity) diff --git a/app/build.gradle b/app/build.gradle index 69f1615..6370f31 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,7 +1,7 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 31 + compileSdkVersion 30 defaultConfig { applicationId "io.github.ratul.topactivity" minSdkVersion 21 @@ -27,9 +27,5 @@ android { } dependencies { - implementation 'androidx.appcompat:appcompat:1.4.1' - implementation 'com.google.android.material:material:1.6.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.0' - implementation 'androidx.preference:preference:1.2.0' - implementation 'androidx.core:core:1.7.0' + implementation 'com.android.support:support-v4:26.0.1' } diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index a27b1c0..aea3305 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -1,3 +1,6 @@ --keep public class io.github.ratul.topactivity.view.** { +-android +-microedition +-dontpreverify +-keep public class android.view.** { public private protected *; } diff --git a/app/src/main/java/io/github/ratul/topactivity/view/RegularTextView.java b/app/src/main/java/android/view/BoldTextView.java similarity index 53% rename from app/src/main/java/io/github/ratul/topactivity/view/RegularTextView.java rename to app/src/main/java/android/view/BoldTextView.java index e63bc0f..2059008 100644 --- a/app/src/main/java/io/github/ratul/topactivity/view/RegularTextView.java +++ b/app/src/main/java/android/view/BoldTextView.java @@ -14,36 +14,36 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.ratul.topactivity.view; +package android.view; import android.content.Context; import android.graphics.Canvas; import android.graphics.Typeface; import android.util.AttributeSet; -import com.google.android.material.textview.MaterialTextView; +import android.widget.TextView; -public class RegularTextView extends MaterialTextView { - public void setRegularFont(Context context) { - Typeface face = Typeface.createFromAsset(context.getAssets(), "fonts/google_sans_regular.ttf"); - super.setTypeface(face, 1); - } +public class BoldTextView extends TextView { + public void setBoldFont(Context context) { + Typeface face = Typeface.createFromAsset(context.getAssets(), "fonts/google_sans_bold.ttf"); + super.setTypeface(face); + } - public RegularTextView(Context context) { - super(context); - setRegularFont(context); - } + public BoldTextView(Context context) { + super(context); + setBoldFont(context); + } - public RegularTextView(Context context, AttributeSet attrs) { - super(context, attrs); - setRegularFont(context); - } + public BoldTextView(Context context, AttributeSet attrs) { + super(context, attrs); + setBoldFont(context); + } - public RegularTextView(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - setRegularFont(context); - } + public BoldTextView(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + setBoldFont(context); + } - protected void onDraw(Canvas canvas) { - super.onDraw(canvas); - } + protected void onDraw (Canvas canvas) { + super.onDraw(canvas); + } } diff --git a/app/src/main/java/io/github/ratul/topactivity/view/NormalTextView.java b/app/src/main/java/android/view/NormalTextView.java similarity index 90% rename from app/src/main/java/io/github/ratul/topactivity/view/NormalTextView.java rename to app/src/main/java/android/view/NormalTextView.java index 694ff50..fcdd720 100644 --- a/app/src/main/java/io/github/ratul/topactivity/view/NormalTextView.java +++ b/app/src/main/java/android/view/NormalTextView.java @@ -14,15 +14,16 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.ratul.topactivity.view; +package android.view; import android.content.Context; import android.graphics.Canvas; import android.graphics.Typeface; import android.util.AttributeSet; -import com.google.android.material.textview.MaterialTextView; +import android.widget.TextView; +import android.widget.Toast; -public class NormalTextView extends MaterialTextView { +public class NormalTextView extends TextView { public void setRegularFont(Context context) { Typeface face = Typeface.createFromAsset(context.getAssets(), "fonts/google_sans_regular.ttf"); super.setTypeface(face); diff --git a/app/src/main/java/io/github/ratul/topactivity/view/BoldTextView.java b/app/src/main/java/android/view/RegularTextView.java similarity index 51% rename from app/src/main/java/io/github/ratul/topactivity/view/BoldTextView.java rename to app/src/main/java/android/view/RegularTextView.java index 2add278..b6c1ee1 100644 --- a/app/src/main/java/io/github/ratul/topactivity/view/BoldTextView.java +++ b/app/src/main/java/android/view/RegularTextView.java @@ -14,36 +14,37 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package io.github.ratul.topactivity.view; +package android.view; import android.content.Context; import android.graphics.Canvas; import android.graphics.Typeface; import android.util.AttributeSet; -import com.google.android.material.textview.MaterialTextView; +import android.widget.TextView; +import android.widget.Toast; -public class BoldTextView extends MaterialTextView { - public void setBoldFont(Context context) { - Typeface face = Typeface.createFromAsset(context.getAssets(), "fonts/google_sans_bold.ttf"); - super.setTypeface(face); - } +public class RegularTextView extends TextView { + public void setRegularFont(Context context) { + Typeface face = Typeface.createFromAsset(context.getAssets(), "fonts/google_sans_regular.ttf"); + super.setTypeface(face, 1); + } - public BoldTextView(Context context) { - super(context); - setBoldFont(context); - } + public RegularTextView(Context context) { + super(context); + setRegularFont(context); + } - public BoldTextView(Context context, AttributeSet attrs) { - super(context, attrs); - setBoldFont(context); - } + public RegularTextView(Context context, AttributeSet attrs) { + super(context, attrs); + setRegularFont(context); + } - public BoldTextView(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - setBoldFont(context); - } + public RegularTextView(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + setRegularFont(context); + } - protected void onDraw(Canvas canvas) { - super.onDraw(canvas); - } + protected void onDraw (Canvas canvas) { + super.onDraw(canvas); + } } diff --git a/app/src/main/java/io/github/ratul/topactivity/App.java b/app/src/main/java/io/github/ratul/topactivity/App.java index a9e2846..5202047 100644 --- a/app/src/main/java/io/github/ratul/topactivity/App.java +++ b/app/src/main/java/io/github/ratul/topactivity/App.java @@ -29,35 +29,35 @@ import android.os.Environment; public class App extends Application { - - private static App sApp; - - @Override - protected void attachBaseContext(Context base) { - super.attachBaseContext(base); - sApp = this; - CrashHandler.getInstance(getApp()).init(); - } - - @Override - public void onCreate() { - super.onCreate(); - } - - public static String getCrashLogDir() { - return getCrashLogFolder().getAbsolutePath(); - } - - public static File getCrashLogFolder() { - return sApp.getExternalFilesDir(null); - } - - public static App getApp() { - return sApp; - } - - public static void showToast(String str, int length) { - Toast.makeText(getApp(), str, length).show(); - } + private static App sApp; + private Thread.UncaughtExceptionHandler defaultHandler = Thread.getDefaultUncaughtExceptionHandler(); + + @Override + protected void attachBaseContext(Context base) { + super.attachBaseContext(base); + new CrashHandler(this, defaultHandler).init(this.getFilesDir()); + } + + @Override + public void onCreate() { + super.onCreate(); + sApp = this; + } + + public static String getCrashLogDir() { + return getCrashLogFolder().getAbsolutePath(); + } + + public static File getCrashLogFolder() { + return sApp.getFilesDir(); + } + + public static App getApp() { + return sApp; + } + + public static void showToast(String str, int length) { + Toast.makeText(getApp(), str, length).show(); + } } diff --git a/app/src/main/java/io/github/ratul/topactivity/dialog/DialogTheme.java b/app/src/main/java/io/github/ratul/topactivity/dialog/DialogTheme.java new file mode 100644 index 0000000..92793a1 --- /dev/null +++ b/app/src/main/java/io/github/ratul/topactivity/dialog/DialogTheme.java @@ -0,0 +1,163 @@ +/* + * Copyright (C) 2022 Ratul Hasan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.github.ratul.topactivity.dialog; + +import android.content.*; +import android.content.res.*; + +/** + * Created by Ratul on 04/05/2022. + */ +public class DialogTheme { + public static int background = 0xFFFFFFFF; + public static int titleColor = 0xFF212121; + public static int messageColor = 0xFF616161; + public static int negativeButtonColor = 0xFFF5F5F5; + public static int negativeTextColor = 0xFF616161; + public static int positiveButtonColor = 0xFF6C63FF; + public static int positiveTextColor = 0xFFFFFFFF; + public static int strokeColor = 0xFFE0E0E0; + public static int pressedColor = 0xFFE0E0E0; + public static double round = 15; + + public static void setupColors(Context context, int theme) { + switch (theme) { + case FancyDialog.DARK_THEME : + DialogTheme.setupDarkColors(); + break; + case FancyDialog.LIGHT_THEME : + DialogTheme.setupLightColors(); + break; + case FancyDialog.DRACULA_THEME : + DialogTheme.setupDraculaColors(); + break; + case FancyDialog.SUCCESS_THEME : + DialogTheme.setupSuccessColors(); + break; + case FancyDialog.INFO_THEME : + DialogTheme.setupInfoColors(); + break; + case FancyDialog.WARNING_THEME : + DialogTheme.setupWarningColors(); + break; + case FancyDialog.ERROR_THMEE : + DialogTheme.setupErrorColors(); + break; + case FancyDialog.HOLO_THEME : + DialogTheme.setupHoloColors(); + break; + default : + setupLightColors(); + } + } + + public static void setupLightColors() { + background = 0xFFFFFFFF; + titleColor = 0xFF212121; + messageColor = 0xFF616161; + negativeButtonColor = 0xFFF5F5F5; + negativeTextColor = 0xFF616161; + positiveTextColor = 0xFFFAFAFA; + positiveButtonColor = 0xFF6C63FF; + strokeColor = 0xFFE0E0E0; + round = 15; + } + + public static void setupDarkColors() { + background = 0xFF2E3132; + titleColor = 0xFFFFFFFF; + messageColor = 0xFFFAFAFA; + negativeButtonColor = 0xFF8F9296; + negativeTextColor = 0xFFFAFAFA; + positiveButtonColor = 0xFF6C63FF; + positiveTextColor = 0xFFFAFAFA; + strokeColor = 0xFF8F9999; + round = 15; + } + + public static void setupErrorColors() { + background = 0xFFF6655A; + titleColor = 0xFFFEF6F5; + messageColor = 0xFFFEEBE9; + negativeButtonColor = 0xFFF44336; + negativeTextColor = 0xFFFDE4E3; + positiveTextColor = 0xFFC4291E; + positiveButtonColor = 0xFFC4271D; + strokeColor = 0x11A3B0C9; + round = 35; + } + + public static void setupHoloColors() { + background = 0xFF787885; + titleColor = 0xFFF8F8FB; + messageColor = 0xFFECECF1; + negativeButtonColor = 0xFF5A5B6A; + negativeTextColor = 0xFFEDEEF2; + positiveTextColor = 0xFF393A47; + positiveButtonColor = 0xFFF7F7FA; + strokeColor = 0x11A3B0C9; + round = 35; + } + + public static void setupSuccessColors() { + background = 0xFF65B168; + titleColor = 0xFFFAFAFA; + messageColor = 0xFFF1F8F2; + negativeButtonColor = 0xFF43A047; + negativeTextColor = 0xFFF8FBF8; + positiveTextColor = 0xFF2C7C31; + positiveButtonColor = 0xFFF5FAF5; + strokeColor = 0x11A3B0C9; + round = 35; + } + + public static void setupWarningColors() { + background = 0xFFDB9E35; + titleColor = 0xFFFAFAFA; + messageColor = 0xFFFEFEDC; + negativeButtonColor = 0xFFCF8401; + negativeTextColor = 0xFFFFFFFF; + positiveTextColor = 0xFFCF8401; + positiveButtonColor = 0xFFF5FAF5; + strokeColor = 0x11C2C9D5; + round = 35; + } + + public static void setupDraculaColors() { + background = 0xFF30303D; + titleColor = 0xFFF9F9F9; + messageColor = 0xFFB6B6B6; + negativeButtonColor = 0xFF494954; + negativeTextColor = 0xFFE9E9EB; + positiveTextColor = 0xFF2E2E45; + positiveButtonColor = 0xFFEAEAF0; + strokeColor = 0x1144475f; + round = 20; + } + + public static void setupInfoColors() { + background = 0xFF4F91FF; + titleColor = 0xFFFAFAFA; + messageColor = 0xFFEBF1FF; + negativeButtonColor = 0xFF2979FF; + negativeTextColor = 0xFFE1EBFF; + positiveTextColor = 0xFF2E6CD4; + positiveButtonColor = 0xFFF7F9FF; + strokeColor = 0x11E0E0E0; + round = 35; + } +} diff --git a/app/src/main/java/io/github/ratul/topactivity/dialog/FancyDialog.java b/app/src/main/java/io/github/ratul/topactivity/dialog/FancyDialog.java new file mode 100644 index 0000000..713c704 --- /dev/null +++ b/app/src/main/java/io/github/ratul/topactivity/dialog/FancyDialog.java @@ -0,0 +1,244 @@ +/* + * Copyright (C) 2022 Ratul Hasan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.github.ratul.topactivity.dialog; + +import android.content.*; +import android.app.*; +import android.view.*; +import android.widget.*; +import android.graphics.*; +import android.view.View.OnClickListener; +import android.graphics.drawable.*; +import android.content.res.*; +import io.github.ratul.topactivity.R; + +/** + * Created by Ratul on 04/05/2022. + */ +public class FancyDialog { + private Context thiz; + private AlertDialog dialog; + private String titleText; + private String mesaageText; + private LayoutInflater inflater; + private View inflate; + private Window window; + private WindowManager.LayoutParams wlp; + + private String positiveButtonText; + private String negativeButtonText; + private boolean cancelable; + + public TextView title; + public TextView message; + public TextView positiveButton; + public TextView negativeButton; + public LinearLayout main; + public LinearLayout middle; + + public static final int DARK_THEME = 1; + public static final int LIGHT_THEME = 0; + public static final int DEVICE_THEME = -1; + public static final int DRACULA_THEME = 2; + public static final int SUCCESS_THEME = 3; + public static final int WARNING_THEME = 4; + public static final int INFO_THEME = 5; + public static final int ERROR_THMEE = 6; + public static final int HOLO_THEME = 7; + + public FancyDialog(Context context) { + this(context, DEVICE_THEME); + } + + public FancyDialog(Context context, int theme) { + thiz = context; + dialog = new AlertDialog.Builder(new ContextThemeWrapper(thiz, R.style.FancyDialogThemeV1)).create(); + + DialogTheme.setupColors(thiz, theme); + + initializeInterface(); + } + + private void initializeInterface() { + setCancelable(false); + inflater = LayoutInflater.from(thiz); + inflate = inflater.inflate(R.layout.abc_alert_dialog, null); + dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent); + dialog.setView(inflate); + + title = (TextView) inflate.findViewById(R.id.t1); + message = (TextView) inflate.findViewById(R.id.t2); + positiveButton = (TextView) inflate.findViewById(R.id.b2); + negativeButton = (TextView) inflate.findViewById(R.id.b1); + main = (LinearLayout) inflate.findViewById(R.id.bg); + middle = (LinearLayout) inflate.findViewById(R.id.middle); + + middle.setVisibility(View.GONE); + window = dialog.getWindow(); + wlp = window.getAttributes(); + + title.setTextColor(DialogTheme.titleColor); + message.setTextColor(DialogTheme.messageColor); + positiveButton.setTextColor(DialogTheme.positiveTextColor); + negativeButton.setTextColor(DialogTheme.negativeTextColor); + + rippleRoundStroke(main, DialogTheme.background, DialogTheme.pressedColor, DialogTheme.round, 0, DialogTheme.strokeColor); + rippleRoundStroke(negativeButton, DialogTheme.negativeButtonColor, 0xFFE0E0E0, DialogTheme.round, 1, DialogTheme.strokeColor); + rippleRoundStroke(positiveButton, DialogTheme.positiveButtonColor, 0x40FFFFFF, DialogTheme.round, 0, DialogTheme.strokeColor); + } + + public void showAsBottomSheet(boolean bool) { + if (bool) { + wlp.windowAnimations = R.style.FancyDialogAnimationV2; + wlp.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL; + } else { + wlp.windowAnimations = 0; + wlp.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL; + } + } + + public void setView(View view) { + middle.addView(view); + middle.setVisibility(View.VISIBLE); + } + + public TextView getTitle() { + return title; + } + + public TextView getMessage() { + return message; + } + + public TextView getPositiveButton() { + return positiveButton; + } + + public TextView getNegativeButton() { + return negativeButton; + } + + public void showAnimation(boolean bool) { + if(bool) + wlp.windowAnimations = R.style.FancyDialogAnimationV1; + else + wlp.windowAnimations = 0; + } + + public LinearLayout getBaseView() { + return (LinearLayout) inflate.findViewById(R.id.bg); + } + + public void setBackgroundColor(int color) { + rippleRoundStroke(main, color, DialogTheme.pressedColor, DialogTheme.round, 0, DialogTheme.strokeColor); + } + + public void setTitleColor(int color) { + title.setTextColor(color); + } + + public void setMessageColor(int color) { + message.setTextColor(color); + } + + public void setPositiveButtonDrawable(GradientDrawable backgroundColor, int textColor, int pressedColor) { + rippleRoundStroke(positiveButton, backgroundColor, pressedColor); + positiveButton.setTextColor(textColor); + } + + public void setNegativeButtonDrawable(GradientDrawable backgroundColor, int textColor, int pressedColor) { + rippleRoundStroke(negativeButton, backgroundColor, pressedColor); + negativeButton.setTextColor(textColor); + } + + public void setPositiveButtonColor(int backgroundColor, int textColor, int pressedColor) { + rippleRoundStroke(positiveButton, backgroundColor, pressedColor, DialogTheme.round, 0, DialogTheme.strokeColor); + positiveButton.setTextColor(textColor); + } + + public void setNegativeButtonColor(int backgroundColor, int textColor, int pressedColor) { + rippleRoundStroke(negativeButton, backgroundColor, pressedColor, DialogTheme.round, 1, DialogTheme.strokeColor); + negativeButton.setTextColor(textColor); + } + + public AlertDialog getDialog() { + return dialog; + } + + public void setTitle(String str) { + titleText = str; + } + + public void setMessage(String str) { + mesaageText = str; + } + + public void setPositiveButton(String str, View.OnClickListener onClick) { + positiveButtonText = str; + positiveButton.setOnClickListener(onClick); + } + + public void setNegativeButton(String str, View.OnClickListener onClick) { + negativeButtonText = str; + negativeButton.setOnClickListener(onClick); + } + + public void setCancelable(boolean bool) { + cancelable = bool; + } + + public void dismiss() { + dialog.dismiss(); + } + + public void show() { + title.setText(titleText); + message.setText(mesaageText); + positiveButton.setText(positiveButtonText); + negativeButton.setText(negativeButtonText); + + if(titleText == null) + title.setVisibility(View.GONE); + if(mesaageText == null) + message.setVisibility(View.GONE); + if(positiveButtonText == null) + positiveButton.setVisibility(View.GONE); + if(negativeButtonText == null) + negativeButton.setVisibility(View.GONE); + if(positiveButtonText == null && negativeButtonText == null) + dialog.setCancelable(true); + else + dialog.setCancelable(cancelable); + + window.setAttributes(wlp); + dialog.show(); + } + + private void rippleRoundStroke(View view, GradientDrawable gg, int pressed) { + RippleDrawable RE = new RippleDrawable(new ColorStateList(new int[][]{new int[]{}}, new int[]{pressed}), gg, null); + view.setBackground(RE); + } + + private void rippleRoundStroke(View view, int focus, int pressed, double round, double stroke, int strokeclr) { + GradientDrawable GG = new GradientDrawable(); + GG.setColor(focus); + GG.setCornerRadius((float)round); + GG.setStroke((int) stroke, strokeclr); + RippleDrawable RE = new RippleDrawable(new ColorStateList(new int[][]{new int[]{}}, new int[]{pressed}), GG, null); + view.setBackground(RE); + } +} diff --git a/app/src/main/java/io/github/ratul/topactivity/model/CrashHandler.java b/app/src/main/java/io/github/ratul/topactivity/model/CrashHandler.java index 56cb554..2ac43fe 100644 --- a/app/src/main/java/io/github/ratul/topactivity/model/CrashHandler.java +++ b/app/src/main/java/io/github/ratul/topactivity/model/CrashHandler.java @@ -16,7 +16,6 @@ */ package io.github.ratul.topactivity.model; -import io.github.ratul.topactivity.App; import io.github.ratul.topactivity.ui.*; import android.app.*; import java.text.*; @@ -34,44 +33,43 @@ */ public class CrashHandler implements UncaughtExceptionHandler { - - private static UncaughtExceptionHandler DEFAULT = Thread.getDefaultUncaughtExceptionHandler(); - - public static CrashHandler getInstance(App app) { - return new CrashHandler(app); - } - - private App mApp; + private UncaughtExceptionHandler DEFAULT; + private Application mApp; private File crashDirectory; private String fullStackTrace, versionName; private long versionCode; - public CrashHandler(App app) { + public CrashHandler(Application app, UncaughtExceptionHandler defaultExceptionHandler) { mApp = app; - crashDirectory = app.getExternalFilesDir(null); - try { + DEFAULT = defaultExceptionHandler; + + try { PackageInfo packageInfo = mApp.getPackageManager().getPackageInfo(mApp.getPackageName(), 0); versionName = packageInfo.versionName; - versionCode = Build.VERSION.SDK_INT >= 28 ? packageInfo.getLongVersionCode() : packageInfo.versionCode; + versionCode = Build.VERSION.SDK_INT >= 28 ? packageInfo.getLongVersionCode() + : packageInfo.versionCode; } catch (PackageManager.NameNotFoundException ignored) { ignored.printStackTrace(); } } - public void init() { + public void init(File crashDir) { + crashDirectory = crashDir; Thread.setDefaultUncaughtExceptionHandler(this); } @Override public void uncaughtException(Thread main, Throwable mThrowable) { if (tryUncaughtException(main, mThrowable) || DEFAULT == null) { - try { - Thread.sleep(1000L); - } catch (InterruptedException e) { - e.printStackTrace(); - } - android.os.Process.killProcess(android.os.Process.myPid()); - System.exit(1); + + try { + Thread.sleep(1000L); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + android.os.Process.killProcess(android.os.Process.myPid()); + System.exit(1); } else { DEFAULT.uncaughtException(main, mThrowable); } @@ -99,7 +97,7 @@ public void run() { SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy HH:mm"); String time = format.format(new Date(timestamp)); - StringWriter sw = new StringWriter(); + StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); throwable.printStackTrace(pw); fullStackTrace = sw.toString(); @@ -124,15 +122,17 @@ public void run() { } catch (IOException ignored) { ignored.printStackTrace(); } - + gotoCrashActiviy: { Intent intent = new Intent(mApp, CrashActivity.class); intent.addFlags( - Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK); + Intent.FLAG_ACTIVITY_NEW_TASK + | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK + ); intent.putExtra(CrashActivity.EXTRA_CRASH_INFO, errorLog); mApp.startActivity(intent); } - + return errorLog != null; } @@ -151,3 +151,5 @@ private void writeFile(File file, String content) throws IOException { } } } + + diff --git a/app/src/main/java/io/github/ratul/topactivity/model/NotificationMonitor.java b/app/src/main/java/io/github/ratul/topactivity/model/NotificationMonitor.java index b9bf2e8..52a0dbc 100644 --- a/app/src/main/java/io/github/ratul/topactivity/model/NotificationMonitor.java +++ b/app/src/main/java/io/github/ratul/topactivity/model/NotificationMonitor.java @@ -23,8 +23,8 @@ import android.content.Context; import android.content.Intent; import android.os.Build; +import android.support.v4.app.NotificationCompat; -import androidx.core.app.NotificationCompat; import java.util.List; import javax.crypto.NullCipher; import io.github.ratul.topactivity.utils.DatabaseUtil; @@ -42,72 +42,77 @@ * Created by Ratul on 04/05/2022. */ public class NotificationMonitor extends BroadcastReceiver { - public static final int NOTIFICATION_ID = 696969691; - private static String CHANNEL_ID; - private static final int ACTION_STOP = 2; - private static final String EXTRA_NOTIFICATION_ACTION = "command"; - public static NotificationCompat.Builder builder; - public static NotificationManager notifManager; + public static final int NOTIFICATION_ID = 696969691; + private static String CHANNEL_ID; + private static final int ACTION_STOP = 2; + private static final String EXTRA_NOTIFICATION_ACTION = "command"; + public static NotificationCompat.Builder builder; + public static NotificationManager notifManager; - public static void showNotification(Context context, boolean isPaused) { - if (!DatabaseUtil.isNotificationToggleEnabled()) { - return; - } - notifManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); + public static void showNotification(Context context, boolean isPaused) { + if (!DatabaseUtil.isNotificationToggleEnabled()) { + return; + } + notifManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - CHANNEL_ID = context.getPackageName() + "_channel_007"; - CharSequence name = "Activity Info"; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + CHANNEL_ID = context.getPackageName() + "_channel_007"; + CharSequence name = "Activity Info"; - int importance = NotificationManager.IMPORTANCE_HIGH; - NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name, importance); - mChannel.setDescription("Shows current activity info"); - mChannel.enableLights(false); - mChannel.enableVibration(false); - mChannel.setShowBadge(false); - notifManager.createNotificationChannel(mChannel); - } + int importance = NotificationManager.IMPORTANCE_HIGH; + NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name, importance); + mChannel.setDescription("Shows current activity info"); + mChannel.enableLights(false); + mChannel.enableVibration(false); + mChannel.setShowBadge(false); + notifManager.createNotificationChannel(mChannel); + } - Intent intent = new Intent(context, MainActivity.class); - TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); - stackBuilder.addParentStack(MainActivity.class); - stackBuilder.addNextIntent(intent); - PendingIntent pIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); + Intent intent = new Intent(context, MainActivity.class); + TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); + stackBuilder.addParentStack(MainActivity.class); + stackBuilder.addNextIntent(intent); + PendingIntent pIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); - builder = new NotificationCompat.Builder(context, CHANNEL_ID) - .setContentTitle(context.getString(R.string.is_running, context.getString(R.string.app_name))) - .setSmallIcon(R.drawable.ic_shortcut).setPriority(NotificationCompat.PRIORITY_HIGH) - .setContentText(context.getString(R.string.touch_to_open)) - .setColor(context.getColor(R.color.layerColor)).setVisibility(NotificationCompat.VISIBILITY_SECRET) - .setOngoing(!isPaused); + builder = new NotificationCompat.Builder(context, CHANNEL_ID) + .setContentTitle(context.getString(R.string.is_running, + context.getString(R.string.app_name))) + .setSmallIcon(R.drawable.ic_shortcut) + .setPriority(NotificationCompat.PRIORITY_HIGH) + .setContentText(context.getString(R.string.touch_to_open)) + .setColor(context.getColor(R.color.layerColor)) + .setVisibility(NotificationCompat.VISIBILITY_SECRET) + .setOngoing(!isPaused); - builder.addAction(R.drawable.ic_launcher_foreground, context.getString(R.string.noti_action_stop), - getPendingIntent(context, ACTION_STOP)).setContentIntent(pIntent); + builder.addAction(R.drawable.ic_launcher_foreground, + context.getString(R.string.noti_action_stop), + getPendingIntent(context, ACTION_STOP)) + .setContentIntent(pIntent); - notifManager.notify(NOTIFICATION_ID, builder.build()); - } + notifManager.notify(NOTIFICATION_ID, builder.build()); + } - public static PendingIntent getPendingIntent(Context context, int command) { - Intent intent = new Intent(context, NotificationMonitor.class); - intent.setAction("io.github.ratul.topactivity.ACTION_NOTIFICATION_RECEIVER"); - intent.putExtra(EXTRA_NOTIFICATION_ACTION, command); - return PendingIntent.getBroadcast(context, 0, intent, 0); - } + public static PendingIntent getPendingIntent(Context context, int command) { + Intent intent = new Intent(context, NotificationMonitor.class); + intent.setAction("io.github.ratul.topactivity.ACTION_NOTIFICATION_RECEIVER"); + intent.putExtra(EXTRA_NOTIFICATION_ACTION, command); + return PendingIntent.getBroadcast(context, 0, intent, 0); + } - public static void cancelNotification(Context context) { - NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); - nm.cancel(NOTIFICATION_ID); - } + public static void cancelNotification(Context context) { + NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); + nm.cancel(NOTIFICATION_ID); + } - @Override - public void onReceive(Context context, Intent intent) { - int command = intent.getIntExtra(EXTRA_NOTIFICATION_ACTION, -1); - if (command == ACTION_STOP) { - WindowUtil.dismiss(context); - DatabaseUtil.setIsShowWindow(false); - cancelNotification(context); - context.sendBroadcast(new Intent(MainActivity.ACTION_STATE_CHANGED)); - } - context.sendBroadcast(new Intent(QuickSettingsService.ACTION_UPDATE_TITLE)); - } + @Override + public void onReceive(Context context, Intent intent) { + int command = intent.getIntExtra(EXTRA_NOTIFICATION_ACTION, -1); + if (command == ACTION_STOP) { + WindowUtil.dismiss(context); + DatabaseUtil.setIsShowWindow(false); + cancelNotification(context); + context.sendBroadcast(new Intent(MainActivity.ACTION_STATE_CHANGED)); + } + context.sendBroadcast(new Intent(QuickSettingsService.ACTION_UPDATE_TITLE)); + } } diff --git a/app/src/main/java/io/github/ratul/topactivity/service/AccessibilityMonitoringService.java b/app/src/main/java/io/github/ratul/topactivity/service/AccessibilityMonitoringService.java index 8176412..8fadbb5 100644 --- a/app/src/main/java/io/github/ratul/topactivity/service/AccessibilityMonitoringService.java +++ b/app/src/main/java/io/github/ratul/topactivity/service/AccessibilityMonitoringService.java @@ -34,60 +34,60 @@ * Refactored by Ratul on 04/05/2022. */ public class AccessibilityMonitoringService extends AccessibilityService { - private static AccessibilityMonitoringService sInstance; + private static AccessibilityMonitoringService sInstance; - public static AccessibilityMonitoringService getInstance() { - return sInstance; - } + public static AccessibilityMonitoringService getInstance() { + return sInstance; + } - public boolean isPackageInstalled(String packageName) { - final PackageManager packageManager = getPackageManager(); - Intent intent = packageManager.getLaunchIntentForPackage(packageName); - if (intent == null) { - return false; - } - List list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); - return list.size() > 0; - } + public boolean isPackageInstalled(String packageName) { + final PackageManager packageManager = getPackageManager(); + Intent intent = packageManager.getLaunchIntentForPackage(packageName); + if (intent == null) { + return false; + } + List list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); + return list.size() > 0; + } + + public boolean isSystemClass(String className) { + try { + ClassLoader.getSystemClassLoader().loadClass(className); + return true; + } catch (ClassNotFoundException e) { + return false; + } + } - public boolean isSystemClass(String className) { - try { - ClassLoader.getSystemClassLoader().loadClass(className); - return true; - } catch (ClassNotFoundException e) { - return false; - } - } + @Override + public void onAccessibilityEvent(AccessibilityEvent event) { + if (WindowUtil.viewAdded && DatabaseUtil.isShowWindow() && DatabaseUtil.hasAccess()) { + String act1 = event.getClassName().toString(); + String act2 = event.getPackageName().toString(); - @Override - public void onAccessibilityEvent(AccessibilityEvent event) { - if (WindowUtil.viewAdded && DatabaseUtil.isShowWindow() && DatabaseUtil.hasAccess()) { - String act1 = event.getClassName().toString(); - String act2 = event.getPackageName().toString(); + if (isSystemClass(act1)) + return; + WindowUtil.show(this, act2, act1); + } + } - if (isSystemClass(act1)) - return; - WindowUtil.show(this, act2, act1); - } - } + @Override + public void onInterrupt() { + sInstance = null; + } - @Override - public void onInterrupt() { - sInstance = null; - } + @Override + protected void onServiceConnected() { + sInstance = this; + super.onServiceConnected(); + } - @Override - protected void onServiceConnected() { - sInstance = this; - super.onServiceConnected(); - } - - @Override - public boolean onUnbind(Intent intent) { - sInstance = null; - WindowUtil.dismiss(this); - NotificationMonitor.cancelNotification(this); - sendBroadcast(new Intent(QuickSettingsService.ACTION_UPDATE_TITLE)); - return super.onUnbind(intent); - } + @Override + public boolean onUnbind(Intent intent) { + sInstance = null; + WindowUtil.dismiss(this); + NotificationMonitor.cancelNotification(this); + sendBroadcast(new Intent(QuickSettingsService.ACTION_UPDATE_TITLE)); + return super.onUnbind(intent); + } } diff --git a/app/src/main/java/io/github/ratul/topactivity/service/MonitoringService.java b/app/src/main/java/io/github/ratul/topactivity/service/MonitoringService.java index 69e7585..03977e2 100644 --- a/app/src/main/java/io/github/ratul/topactivity/service/MonitoringService.java +++ b/app/src/main/java/io/github/ratul/topactivity/service/MonitoringService.java @@ -35,96 +35,98 @@ * Refactored by Ratul on 04/05/2022. */ public class MonitoringService extends Service { - public boolean serviceAlive = false; - private boolean firstRun = true; - public static MonitoringService INSTANCE; - private UsageStatsManager usageStats; - public Handler mHandler = new Handler(); - private String text; - private String text1; + public boolean serviceAlive = false; + private boolean firstRun = true; + public static MonitoringService INSTANCE; + private UsageStatsManager usageStats; + public Handler mHandler = new Handler(); + private String text; + private String text1; - @Override - public void onCreate() { - super.onCreate(); - INSTANCE = this; + @Override + public void onCreate() { + super.onCreate(); + INSTANCE = this; - serviceAlive = true; - usageStats = (UsageStatsManager) getSystemService(Context.USAGE_STATS_SERVICE); - } + serviceAlive = true; + usageStats = (UsageStatsManager) getSystemService(Context.USAGE_STATS_SERVICE); + } - @Override - public void onDestroy() { - serviceAlive = false; - super.onDestroy(); - } + @Override + public void onDestroy() { + serviceAlive = false; + super.onDestroy(); + } - public void getActivityInfo() { - long currentTimeMillis = System.currentTimeMillis(); - UsageEvents queryEvents = usageStats.queryEvents(currentTimeMillis - (firstRun ? 600000 : 60000), - currentTimeMillis); - while (queryEvents.hasNextEvent()) { - UsageEvents.Event event = new UsageEvents.Event(); - queryEvents.getNextEvent(event); - int type = event.getEventType(); - if (type == UsageEvents.Event.MOVE_TO_FOREGROUND) { - text = event.getPackageName(); - text1 = event.getClassName(); - } else if (type == UsageEvents.Event.MOVE_TO_BACKGROUND) { - if (event.getPackageName().equals(text)) { - text = null; - text1 = null; - } - } - } - } + public void getActivityInfo() { + long currentTimeMillis = System.currentTimeMillis(); + UsageEvents queryEvents = usageStats.queryEvents(currentTimeMillis - (firstRun ? 600000 : 60000), currentTimeMillis); + while (queryEvents.hasNextEvent()) { + UsageEvents.Event event = new UsageEvents.Event(); + queryEvents.getNextEvent(event); + int type = event.getEventType(); + if (type == UsageEvents.Event.MOVE_TO_FOREGROUND) { + text = event.getPackageName(); + text1 = event.getClassName(); + } else if (type == UsageEvents.Event.MOVE_TO_BACKGROUND) { + if (event.getPackageName().equals(text)) { + text = null; + text1 = null; + } + } + } + } - @Override - public IBinder onBind(Intent intent) { - return null; - } + @Override + public IBinder onBind(Intent intent) { + return null; + } - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - INSTANCE = this; - Runnable runner = new Runnable() { - @Override - public void run() { - if (!DatabaseUtil.isShowWindow()) { - MonitoringService.INSTANCE.mHandler.removeCallbacks(this); - MonitoringService.INSTANCE.stopSelf(); - } + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + INSTANCE = this; + Runnable runner = new Runnable() { + @Override + public void run() { + if (!DatabaseUtil.isShowWindow()) { + MonitoringService.INSTANCE.mHandler.removeCallbacks(this); + MonitoringService.INSTANCE.stopSelf(); + } - getActivityInfo(); - if (MonitoringService.INSTANCE.text == null) - return; + getActivityInfo(); + if (MonitoringService.INSTANCE.text == null) + return; - MonitoringService.INSTANCE.firstRun = false; - if (DatabaseUtil.isShowWindow()) { - WindowUtil.show(MonitoringService.INSTANCE, MonitoringService.INSTANCE.text, - MonitoringService.INSTANCE.text1); - } else { - MonitoringService.INSTANCE.stopSelf(); - } - mHandler.postDelayed(this, 500); - } - }; + MonitoringService.INSTANCE.firstRun = false; + if (DatabaseUtil.isShowWindow()) { + WindowUtil.show(MonitoringService.INSTANCE, MonitoringService.INSTANCE.text, MonitoringService.INSTANCE.text1); + } else { + MonitoringService.INSTANCE.stopSelf(); + } + mHandler.postDelayed(this, 500); + } + }; - mHandler.postDelayed(runner, 500); - return super.onStartCommand(intent, flags, startId); - } + mHandler.postDelayed(runner, 500); + return super.onStartCommand(intent, flags, startId); + } - @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) - @Override - public void onTaskRemoved(Intent rootIntent) { - Intent restartServiceIntent = new Intent(getApplicationContext(), this.getClass()); - restartServiceIntent.setPackage(getPackageName()); + @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) + @Override + public void onTaskRemoved(Intent rootIntent) { + Intent restartServiceIntent = new Intent(getApplicationContext(), + this.getClass()); + restartServiceIntent.setPackage(getPackageName()); - PendingIntent restartServicePendingIntent = PendingIntent.getService(getApplicationContext(), 1, - restartServiceIntent, PendingIntent.FLAG_ONE_SHOT); - AlarmManager alarmService = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE); - alarmService.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 500, - restartServicePendingIntent); + PendingIntent restartServicePendingIntent = PendingIntent.getService( + getApplicationContext(), 1, restartServiceIntent, + PendingIntent.FLAG_ONE_SHOT); + AlarmManager alarmService = (AlarmManager) getApplicationContext() + .getSystemService(Context.ALARM_SERVICE); + alarmService.set(AlarmManager.ELAPSED_REALTIME, + SystemClock.elapsedRealtime() + 500, + restartServicePendingIntent); - super.onTaskRemoved(rootIntent); - } + super.onTaskRemoved(rootIntent); + } } diff --git a/app/src/main/java/io/github/ratul/topactivity/service/QuickSettingsService.java b/app/src/main/java/io/github/ratul/topactivity/service/QuickSettingsService.java index 99df124..3bde38a 100644 --- a/app/src/main/java/io/github/ratul/topactivity/service/QuickSettingsService.java +++ b/app/src/main/java/io/github/ratul/topactivity/service/QuickSettingsService.java @@ -39,81 +39,81 @@ */ @TargetApi(Build.VERSION_CODES.N) public class QuickSettingsService extends TileService { - public static final String ACTION_UPDATE_TITLE = "io.github.ratul.topactivity.ACTION.UPDATE_TITLE"; - private UpdateTileReceiver mReceiver; + public static final String ACTION_UPDATE_TITLE = "io.github.ratul.topactivity.ACTION.UPDATE_TITLE"; + private UpdateTileReceiver mReceiver; - public static void updateTile(Context context) { - TileService.requestListeningState(context, new ComponentName(context, QuickSettingsService.class)); - context.sendBroadcast(new Intent(QuickSettingsService.ACTION_UPDATE_TITLE)); - } + public static void updateTile(Context context) { + TileService.requestListeningState(context, new ComponentName(context, QuickSettingsService.class)); + context.sendBroadcast(new Intent(QuickSettingsService.ACTION_UPDATE_TITLE)); + } + + private void updateTile() { + getQsTile().setState(DatabaseUtil.isShowWindow() ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE); + getQsTile().updateTile(); + } - private void updateTile() { - getQsTile().setState(DatabaseUtil.isShowWindow() ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE); - getQsTile().updateTile(); - } + @Override + public void onCreate() { + super.onCreate(); + mReceiver = new UpdateTileReceiver(); + } - @Override - public void onCreate() { - super.onCreate(); - mReceiver = new UpdateTileReceiver(); - } + @Override + public void onTileAdded() { + DatabaseUtil.setQSTileAdded(true); + sendBroadcast(new Intent(MainActivity.ACTION_STATE_CHANGED)); + } - @Override - public void onTileAdded() { - DatabaseUtil.setQSTileAdded(true); - sendBroadcast(new Intent(MainActivity.ACTION_STATE_CHANGED)); - } + @Override + public void onTileRemoved() { + super.onTileRemoved(); + DatabaseUtil.setQSTileAdded(false); + sendBroadcast(new Intent(MainActivity.ACTION_STATE_CHANGED)); + } - @Override - public void onTileRemoved() { - super.onTileRemoved(); - DatabaseUtil.setQSTileAdded(false); - sendBroadcast(new Intent(MainActivity.ACTION_STATE_CHANGED)); - } + @Override + public void onStartListening() { + registerReceiver(mReceiver, new IntentFilter(ACTION_UPDATE_TITLE)); + super.onStartListening(); + updateTile(); + } - @Override - public void onStartListening() { - registerReceiver(mReceiver, new IntentFilter(ACTION_UPDATE_TITLE)); - super.onStartListening(); - updateTile(); - } + @Override + public void onStopListening() { + unregisterReceiver(mReceiver); + super.onStopListening(); + } - @Override - public void onStopListening() { - unregisterReceiver(mReceiver); - super.onStopListening(); - } + @Override + public void onClick() { + if (DatabaseUtil.isShowWindow()) + return; + if (!MainActivity.usageStats(this) || !Settings.canDrawOverlays(this)) { + Intent intent = new Intent(this, MainActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + intent.putExtra(MainActivity.EXTRA_FROM_QS_TILE, true); + startActivityAndCollapse(intent); + } else { + if (DatabaseUtil.hasAccess() && AccessibilityMonitoringService.getInstance() == null) + startService(new Intent().setClass(this, AccessibilityMonitoringService.class)); + DatabaseUtil.setIsShowWindow(!DatabaseUtil.isShowWindow()); + if (DatabaseUtil.isShowWindow()) { + if (WindowUtil.sWindowManager == null) + WindowUtil.init(this); + NotificationMonitor.showNotification(this, false); + startService(new Intent(this, MonitoringService.class)); + } else { + WindowUtil.dismiss(this); + NotificationMonitor.showNotification(this, true); + } + sendBroadcast(new Intent(MainActivity.ACTION_STATE_CHANGED)); + } + } - @Override - public void onClick() { - if (DatabaseUtil.isShowWindow()) - return; - if (!MainActivity.usageStats(this) || !Settings.canDrawOverlays(this)) { - Intent intent = new Intent(this, MainActivity.class); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - intent.putExtra(MainActivity.EXTRA_FROM_QS_TILE, true); - startActivityAndCollapse(intent); - } else { - if (DatabaseUtil.hasAccess() && AccessibilityMonitoringService.getInstance() == null) - startService(new Intent().setClass(this, AccessibilityMonitoringService.class)); - DatabaseUtil.setIsShowWindow(!DatabaseUtil.isShowWindow()); - if (DatabaseUtil.isShowWindow()) { - if (WindowUtil.sWindowManager == null) - WindowUtil.init(this); - NotificationMonitor.showNotification(this, false); - startService(new Intent(this, MonitoringService.class)); - } else { - WindowUtil.dismiss(this); - NotificationMonitor.showNotification(this, true); - } - sendBroadcast(new Intent(MainActivity.ACTION_STATE_CHANGED)); - } - } - - class UpdateTileReceiver extends BroadcastReceiver { - @Override - public void onReceive(Context context, Intent intent) { - updateTile(); - } - } + class UpdateTileReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + updateTile(); + } + } } diff --git a/app/src/main/java/io/github/ratul/topactivity/service/QuickSettingsTileService.java b/app/src/main/java/io/github/ratul/topactivity/service/QuickSettingsTileService.java index 67fa79c..a1615ef 100644 --- a/app/src/main/java/io/github/ratul/topactivity/service/QuickSettingsTileService.java +++ b/app/src/main/java/io/github/ratul/topactivity/service/QuickSettingsTileService.java @@ -39,81 +39,81 @@ */ @TargetApi(Build.VERSION_CODES.N) public class QuickSettingsTileService extends TileService { - public static final String ACTION_UPDATE_TITLE = "io.github.ratul.topactivity.ACTION.UPDATE_TITLE"; - private UpdateTileReceiver mReceiver; + public static final String ACTION_UPDATE_TITLE = "io.github.ratul.topactivity.ACTION.UPDATE_TITLE"; + private UpdateTileReceiver mReceiver; - public static void updateTile(Context context) { - TileService.requestListeningState(context, new ComponentName(context, QuickSettingsTileService.class)); - context.sendBroadcast(new Intent(QuickSettingsTileService.ACTION_UPDATE_TITLE)); - } + public static void updateTile(Context context) { + TileService.requestListeningState(context, new ComponentName(context, QuickSettingsTileService.class)); + context.sendBroadcast(new Intent(QuickSettingsTileService.ACTION_UPDATE_TITLE)); + } + + public void updateTile() { + getQsTile().setState(DatabaseUtil.isShowWindow() ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE); + getQsTile().updateTile(); + } - public void updateTile() { - getQsTile().setState(DatabaseUtil.isShowWindow() ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE); - getQsTile().updateTile(); - } + @Override + public void onCreate() { + super.onCreate(); + mReceiver = new UpdateTileReceiver(); + } - @Override - public void onCreate() { - super.onCreate(); - mReceiver = new UpdateTileReceiver(); - } + @Override + public void onTileAdded() { + DatabaseUtil.setQSTileAdded(true); + sendBroadcast(new Intent(MainActivity.ACTION_STATE_CHANGED)); + } - @Override - public void onTileAdded() { - DatabaseUtil.setQSTileAdded(true); - sendBroadcast(new Intent(MainActivity.ACTION_STATE_CHANGED)); - } + @Override + public void onTileRemoved() { + super.onTileRemoved(); + DatabaseUtil.setQSTileAdded(false); + sendBroadcast(new Intent(MainActivity.ACTION_STATE_CHANGED)); + } - @Override - public void onTileRemoved() { - super.onTileRemoved(); - DatabaseUtil.setQSTileAdded(false); - sendBroadcast(new Intent(MainActivity.ACTION_STATE_CHANGED)); - } + @Override + public void onStartListening() { + registerReceiver(mReceiver, new IntentFilter(ACTION_UPDATE_TITLE)); + super.onStartListening(); + updateTile(); + } - @Override - public void onStartListening() { - registerReceiver(mReceiver, new IntentFilter(ACTION_UPDATE_TITLE)); - super.onStartListening(); - updateTile(); - } + @Override + public void onStopListening() { + unregisterReceiver(mReceiver); + super.onStopListening(); + } - @Override - public void onStopListening() { - unregisterReceiver(mReceiver); - super.onStopListening(); - } + @Override + public void onClick() { + if (DatabaseUtil.isShowWindow()) + return; + if (!MainActivity.usageStats(this) || !Settings.canDrawOverlays(this)) { + Intent intent = new Intent(this, MainActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + intent.putExtra(MainActivity.EXTRA_FROM_QS_TILE, true); + startActivityAndCollapse(intent); + } else { + if (DatabaseUtil.hasAccess() && AccessibilityMonitoringService.getInstance() == null) + startService(new Intent().setClass(this, AccessibilityMonitoringService.class)); + DatabaseUtil.setIsShowWindow(!DatabaseUtil.isShowWindow()); + if (DatabaseUtil.isShowWindow()) { + if (WindowUtil.sWindowManager == null) + WindowUtil.init(this); + NotificationMonitor.showNotification(this, false); + startService(new Intent(this, MonitoringService.class)); + } else { + WindowUtil.dismiss(this); + NotificationMonitor.showNotification(this, true); + } + sendBroadcast(new Intent(MainActivity.ACTION_STATE_CHANGED)); + } + } - @Override - public void onClick() { - if (DatabaseUtil.isShowWindow()) - return; - if (!MainActivity.usageStats(this) || !Settings.canDrawOverlays(this)) { - Intent intent = new Intent(this, MainActivity.class); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - intent.putExtra(MainActivity.EXTRA_FROM_QS_TILE, true); - startActivityAndCollapse(intent); - } else { - if (DatabaseUtil.hasAccess() && AccessibilityMonitoringService.getInstance() == null) - startService(new Intent().setClass(this, AccessibilityMonitoringService.class)); - DatabaseUtil.setIsShowWindow(!DatabaseUtil.isShowWindow()); - if (DatabaseUtil.isShowWindow()) { - if (WindowUtil.sWindowManager == null) - WindowUtil.init(this); - NotificationMonitor.showNotification(this, false); - startService(new Intent(this, MonitoringService.class)); - } else { - WindowUtil.dismiss(this); - NotificationMonitor.showNotification(this, true); - } - sendBroadcast(new Intent(MainActivity.ACTION_STATE_CHANGED)); - } - } - - class UpdateTileReceiver extends BroadcastReceiver { - @Override - public void onReceive(Context context, Intent intent) { - updateTile(); - } - } + class UpdateTileReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + updateTile(); + } + } } diff --git a/app/src/main/java/io/github/ratul/topactivity/ui/BackgroundActivity.java b/app/src/main/java/io/github/ratul/topactivity/ui/BackgroundActivity.java index 867ed45..74c4d42 100644 --- a/app/src/main/java/io/github/ratul/topactivity/ui/BackgroundActivity.java +++ b/app/src/main/java/io/github/ratul/topactivity/ui/BackgroundActivity.java @@ -24,14 +24,13 @@ import android.provider.Settings; import android.content.ClipboardManager; import android.content.ClipData; -import androidx.appcompat.app.AppCompatActivity; import io.github.ratul.topactivity.App; /** * Created by Ratul on 04/05/2022. */ - @TargetApi(Build.VERSION_CODES.O) -public class BackgroundActivity extends AppCompatActivity { + @TargetApi(29) +public class BackgroundActivity extends Activity { public static String STRING_COPY = "io.github.ratul.topactivity.COPY_STRING"; public static String COPY_MSG = "io.github.ratul.topactivity.COPY_STRING_MSG"; diff --git a/app/src/main/java/io/github/ratul/topactivity/ui/CrashActivity.java b/app/src/main/java/io/github/ratul/topactivity/ui/CrashActivity.java index 27c0af6..c44515d 100644 --- a/app/src/main/java/io/github/ratul/topactivity/ui/CrashActivity.java +++ b/app/src/main/java/io/github/ratul/topactivity/ui/CrashActivity.java @@ -18,9 +18,8 @@ import android.app.Activity; import android.os.Bundle; -import com.google.android.material.textview.MaterialTextView; -import androidx.appcompat.app.AppCompatActivity; import io.github.ratul.topactivity.R; +import android.widget.TextView; import android.view.MenuItem; import android.content.ClipboardManager; import android.content.ClipData; @@ -28,103 +27,110 @@ import android.content.pm.PackageManager; import android.content.Intent; import android.content.Context; -import android.content.DialogInterface; import android.graphics.Typeface; import android.view.View; import android.widget.Toast; import android.text.SpannableString; -import androidx.appcompat.app.ActionBar; +import android.app.ActionBar; import android.text.Spannable; -import com.google.android.material.dialog.MaterialAlertDialogBuilder; +import io.github.ratul.topactivity.dialog.DialogTheme; +import io.github.ratul.topactivity.dialog.FancyDialog; import io.github.ratul.topactivity.model.TypefaceSpan; /** * Created by Ratul on 04/05/2022. */ -public class CrashActivity extends AppCompatActivity { - public static String EXTRA_CRASH_INFO = "crash"; - private String crashInfo; - private boolean restart; +public class CrashActivity extends Activity { + public static String EXTRA_CRASH_INFO = "crash"; + private String crashInfo; + private boolean restart; - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.crash_view); + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.crash_view); - SpannableString s = new SpannableString(getString(R.string.app_name)); - s.setSpan(new TypefaceSpan(this, "fonts/google_sans_bold.ttf"), 0, s.length(), - Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - ActionBar actionBar = getSupportActionBar(); - actionBar.setTitle(s); + SpannableString s = new SpannableString(getString(R.string.app_name)); + s.setSpan(new TypefaceSpan(this, "fonts/google_sans_bold.ttf"), 0, s.length(), + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + ActionBar actionBar = getActionBar(); + actionBar.setTitle(s); - restart = getIntent().getBooleanExtra("Restart", true); - String mLog = getIntent().getStringExtra(EXTRA_CRASH_INFO); - crashInfo = mLog; - MaterialTextView crashed = findViewById(R.id.crashed); - crashed.setText(mLog); - } + restart = getIntent().getBooleanExtra("Restart", true); + String mLog = getIntent().getStringExtra(EXTRA_CRASH_INFO); + crashInfo = mLog; + TextView crashed = findViewById(R.id.crashed); + crashed.setText(mLog); + } - @Override - public void onBackPressed() { - if (!restart) { - finish(); - return; - } - new MaterialAlertDialogBuilder(this).setTitle("Exit").setMessage("App will restart, are you sure to exit") - .setPositiveButton("Yes", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface di, int btn) { - di.dismiss(); - restart(); - } - }).setNegativeButton("No", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface di, int btn) { - di.dismiss(); - } - }).setCancelable(false).show(); - } + @Override + public void onBackPressed() { + if (!restart) { + finish(); + return; + } + final FancyDialog fancy = new FancyDialog(this, FancyDialog.DARK_THEME); + fancy.setTitle("Exit"); + fancy.setMessage("App will restart, are you sure to exit"); + fancy.setPositiveButton("Yes", new View.OnClickListener() { + @Override + public void onClick(View v) { + fancy.dismiss(); + restart(); + } + }); + fancy.setNegativeButton("No", new View.OnClickListener() { + @Override + public void onClick(View v) { + fancy.dismiss(); + } + }); + fancy.setCancelable(false); + fancy.show(); + } - private void restart() { - PackageManager pm = getPackageManager(); - Intent intent = pm.getLaunchIntentForPackage(getPackageName()); - if (intent != null) { - intent.addFlags( - Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK); - startActivity(intent); - } - finish(); - android.os.Process.killProcess(android.os.Process.myPid()); - System.exit(0); - } + private void restart() { + PackageManager pm = getPackageManager(); + Intent intent = pm.getLaunchIntentForPackage(getPackageName()); + if (intent != null) { + intent.addFlags( + Intent.FLAG_ACTIVITY_NEW_TASK + | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK + ); + startActivity(intent); + } + finish(); + android.os.Process.killProcess(android.os.Process.myPid()); + System.exit(0); + } - @Override - public boolean onOptionsItemSelected(MenuItem item) { - if (item.getItemId() == android.R.id.copy) { - ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); - cm.setPrimaryClip(ClipData.newPlainText(getPackageName(), crashInfo)); - Toast.makeText(this, "Copied", 0).show(); - } else if (item.getItemId() == android.R.id.redo) { - onBackPressed(); - } - return super.onOptionsItemSelected(item); - } + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (item.getItemId() == android.R.id.copy) { + ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); + cm.setPrimaryClip(ClipData.newPlainText(getPackageName(), crashInfo)); + Toast.makeText(this, "Copied", 0).show(); + } else if (item.getItemId() == android.R.id.redo) { + onBackPressed(); + } + return super.onOptionsItemSelected(item); + } - @Override - public boolean onCreateOptionsMenu(Menu menu) { - SpannableString s = new SpannableString("Copy Log"); - s.setSpan(new TypefaceSpan(this, "fonts/google_sans_regular.ttf"), 0, s.length(), - Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - menu.add(0, android.R.id.copy, 0, s); - if (restart) { - s = new SpannableString("Restart App"); - s.setSpan(new TypefaceSpan(this, "fonts/google_sans_regular.ttf"), 0, s.length(), - Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + @Override + public boolean onCreateOptionsMenu(Menu menu) { + SpannableString s = new SpannableString("Copy Log"); + s.setSpan(new TypefaceSpan(this, "fonts/google_sans_regular.ttf"), 0, s.length(), + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + menu.add(0, android.R.id.copy, 0, s); + if (restart) { + s = new SpannableString("Restart App"); + s.setSpan(new TypefaceSpan(this, "fonts/google_sans_regular.ttf"), 0, s.length(), + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - menu.add(1, android.R.id.redo, 1, s); - } - return super.onCreateOptionsMenu(menu); - } + menu.add(1, android.R.id.redo, 1, s); + } + return super.onCreateOptionsMenu(menu); + } } diff --git a/app/src/main/java/io/github/ratul/topactivity/ui/MainActivity.java b/app/src/main/java/io/github/ratul/topactivity/ui/MainActivity.java index f300737..6700aff 100644 --- a/app/src/main/java/io/github/ratul/topactivity/ui/MainActivity.java +++ b/app/src/main/java/io/github/ratul/topactivity/ui/MainActivity.java @@ -25,16 +25,13 @@ import android.widget.*; import android.widget.CompoundButton.OnCheckedChangeListener; import android.app.*; -import androidx.appcompat.app.ActionBar; import android.content.pm.*; import android.graphics.drawable.*; import android.graphics.*; import android.text.*; -import androidx.appcompat.app.AppCompatActivity; -import com.google.android.material.dialog.MaterialAlertDialogBuilder; -import com.google.android.material.switchmaterial.SwitchMaterial; import java.util.List; import io.github.ratul.topactivity.*; +import io.github.ratul.topactivity.dialog.*; import io.github.ratul.topactivity.utils.*; import io.github.ratul.topactivity.model.NotificationMonitor; import io.github.ratul.topactivity.service.*; @@ -46,301 +43,306 @@ * Created by Wen on 16/02/2017. * Refactored by Ratul on 04/05/2022. */ -public class MainActivity extends AppCompatActivity { - public static final String EXTRA_FROM_QS_TILE = "from_qs_tile"; - public static final String ACTION_STATE_CHANGED = "io.github.ratul.topactivity.ACTION_STATE_CHANGED"; - private SwitchMaterial mWindowSwitch, mNotificationSwitch, mAccessibilitySwitch; - private BroadcastReceiver mReceiver; - private MaterialAlertDialogBuilder fancy; - public static MainActivity INSTANCE; +public class MainActivity extends Activity { + public static final String EXTRA_FROM_QS_TILE = "from_qs_tile"; + public static final String ACTION_STATE_CHANGED = "io.github.ratul.topactivity.ACTION_STATE_CHANGED"; + CompoundButton mWindowSwitch, mNotificationSwitch, mAccessibilitySwitch; + private BroadcastReceiver mReceiver; + private FancyDialog fancy; + public static MainActivity INSTANCE; - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - INSTANCE = this; - if (AccessibilityMonitoringService.getInstance() == null && DatabaseUtil.hasAccess()) - startService(new Intent().setClass(this, AccessibilityMonitoringService.class)); + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + INSTANCE = this; + if (AccessibilityMonitoringService.getInstance() == null && DatabaseUtil.hasAccess()) + startService(new Intent().setClass(this, AccessibilityMonitoringService.class)); - DatabaseUtil.setDisplayWidth(getScreenWidth(this)); - fancy = new MaterialAlertDialogBuilder(this).setNegativeButton("Close", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface di, int btn) { - di.dismiss(); - } - }).setCancelable(false); + DatabaseUtil.setDisplayWidth(getScreenWidth(this)); + fancy = new FancyDialog(this, FancyDialog.DARK_THEME); + fancy.setNegativeButton("Close", new View.OnClickListener() { + @Override + public void onClick(View v) { + fancy.dismiss(); + } + }); + fancy.setCancelable(false); - SpannableString s = new SpannableString(getString(R.string.app_name)); - s.setSpan(new TypefaceSpan(this, "fonts/google_sans_bold.ttf"), 0, s.length(), - Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - ActionBar actionBar = getSupportActionBar(); - actionBar.setTitle(s); + SpannableString s = new SpannableString(getString(R.string.app_name)); + s.setSpan(new TypefaceSpan(this, "fonts/google_sans_bold.ttf"), 0, s.length(), + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + ActionBar actionBar = getActionBar(); + actionBar.setTitle(s); - mWindowSwitch = findViewById(R.id.sw_window); - mNotificationSwitch = findViewById(R.id.sw_notification); - mAccessibilitySwitch = findViewById(R.id.sw_accessibility); + mWindowSwitch = findViewById(R.id.sw_window); + mNotificationSwitch = findViewById(R.id.sw_notification); + mAccessibilitySwitch = findViewById(R.id.sw_accessibility); - if (Build.VERSION.SDK_INT < 24) { - mNotificationSwitch.setVisibility(View.INVISIBLE); - findViewById(R.id.divider_useNotificationPref).setVisibility(View.INVISIBLE); - } + if (Build.VERSION.SDK_INT < 24) { + mNotificationSwitch.setVisibility(View.INVISIBLE); + findViewById(R.id.divider_useNotificationPref).setVisibility(View.INVISIBLE); + } - mReceiver = new UpdateSwitchReceiver(); - registerReceiver(mReceiver, new IntentFilter(ACTION_STATE_CHANGED)); + mReceiver = new UpdateSwitchReceiver(); + registerReceiver(mReceiver, new IntentFilter(ACTION_STATE_CHANGED)); - mNotificationSwitch.setOnCheckedChangeListener(new SwitchMaterial.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton button, boolean isChecked) { - DatabaseUtil.setNotificationToggleEnabled(!isChecked); - } - }); - mAccessibilitySwitch.setOnCheckedChangeListener(new SwitchMaterial.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton button, boolean isChecked) { - DatabaseUtil.setHasAccess(isChecked); - if (isChecked && AccessibilityMonitoringService.getInstance() == null) - startService(new Intent().setClass(MainActivity.this, AccessibilityMonitoringService.class)); - } - }); - mWindowSwitch.setOnCheckedChangeListener(new SwitchMaterial.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton button, boolean isChecked) { - if (Build.VERSION.SDK_INT >= 23 && !Settings.canDrawOverlays(MainActivity.this)) { - fancy.setTitle("Overlay Permission") - .setMessage("Please enable overlay permission to show window over other apps") - .setPositiveButton("Settings", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface di, int btn) { - Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION); - intent.setData(Uri.parse("package:" + getPackageName())); - startActivity(intent); - di.dismiss(); - } - }).show(); - mWindowSwitch.setChecked(false); - } else if (DatabaseUtil.hasAccess() && AccessibilityMonitoringService.getInstance() == null) { - fancy.setTitle("Accessibility Permission").setMessage( - "As per your choice, please grant permission to use Accessibility Service for Current Activity app in order to get current activity info") - .setPositiveButton("Settings", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface di, int btn) { - Intent intent = new Intent(); - intent.setAction("android.settings.ACCESSIBILITY_SETTINGS"); - startActivity(intent); - di.dismiss(); - } - }).show(); - mWindowSwitch.setChecked(false); - } else if (!usageStats(MainActivity.this)) { - fancy.setTitle("Usage Access").setMessage( - "In order to monitor current task, please grant Usage Access permission for Current Activity app") - .setPositiveButton("Settings", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface di, int btn) { - Intent intent = new Intent(); - intent.setAction("android.settings.USAGE_ACCESS_SETTINGS"); - startActivity(intent); - di.dismiss(); - } - }).show(); - mWindowSwitch.setChecked(false); - } else { - DatabaseUtil.setAppInitiated(true); - DatabaseUtil.setIsShowWindow(isChecked); - if (!isChecked) { - WindowUtil.dismiss(MainActivity.this); - } else { - WindowUtil.show(MainActivity.this, getPackageName(), getClass().getName()); - startService(new Intent(MainActivity.this, MonitoringService.class)); - } - } - } - }); + mNotificationSwitch.setOnCheckedChangeListener(new Switch.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton button, boolean isChecked) { + DatabaseUtil.setNotificationToggleEnabled(!isChecked); + } + }); + mAccessibilitySwitch.setOnCheckedChangeListener(new Switch.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton button, boolean isChecked) { + DatabaseUtil.setHasAccess(isChecked); + if (isChecked && AccessibilityMonitoringService.getInstance() == null) + startService(new Intent().setClass(MainActivity.this, AccessibilityMonitoringService.class)); + } + }); + mWindowSwitch.setOnCheckedChangeListener(new Switch.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton button, boolean isChecked) { + if (Build.VERSION.SDK_INT >= 23 && !Settings.canDrawOverlays(MainActivity.this)) { + fancy.setTitle("Overlay Permission"); + fancy.setMessage("Please enable overlay permission to show window over other apps"); + fancy.setPositiveButton("Settings", new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION); + intent.setData(Uri.parse("package:" + getPackageName())); + startActivity(intent); + fancy.dismiss(); + } + }); + fancy.show(); + mWindowSwitch.setChecked(false); + } else if (DatabaseUtil.hasAccess() && AccessibilityMonitoringService.getInstance() == null) { + fancy.setTitle("Accessibility Permission"); + fancy.setMessage("As per your choice, please grant permission to use Accessibility Service for Current Activity app in order to get current activity info"); + fancy.setPositiveButton("Settings", new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(); + intent.setAction("android.settings.ACCESSIBILITY_SETTINGS"); + startActivity(intent); + fancy.dismiss(); + } + }); + fancy.show(); + mWindowSwitch.setChecked(false); + } else if (!usageStats(MainActivity.this)) { + fancy.setTitle("Usage Access"); + fancy.setMessage("In order to monitor current task, please grant Usage Access permission for Current Activity app"); + fancy.setPositiveButton("Settings", new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(); + intent.setAction("android.settings.USAGE_ACCESS_SETTINGS"); + startActivity(intent); + fancy.dismiss(); + } + }); + fancy.show(); + mWindowSwitch.setChecked(false); + } else { + DatabaseUtil.setAppInitiated(true); + DatabaseUtil.setIsShowWindow(isChecked); + if (!isChecked) { + WindowUtil.dismiss(MainActivity.this); + } else { + WindowUtil.show(MainActivity.this, getPackageName(), getClass().getName()); + startService(new Intent(MainActivity.this, MonitoringService.class)); + } + } + } + }); - if (getIntent().getBooleanExtra(EXTRA_FROM_QS_TILE, false)) - mWindowSwitch.setChecked(true); - } + if (getIntent().getBooleanExtra(EXTRA_FROM_QS_TILE, false)) + mWindowSwitch.setChecked(true); + } - public static int getScreenWidth(Activity activity) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { - WindowMetrics windowMetrics = activity.getWindowManager().getCurrentWindowMetrics(); - Insets insets = windowMetrics.getWindowInsets().getInsetsIgnoringVisibility(WindowInsets.Type.systemBars()); - return windowMetrics.getBounds().width() - insets.left - insets.right; - } else { - DisplayMetrics displayMetrics = new DisplayMetrics(); - activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); - return displayMetrics.widthPixels; - } - } + public static int getScreenWidth(Activity activity) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + WindowMetrics windowMetrics = activity.getWindowManager().getCurrentWindowMetrics(); + Insets insets = windowMetrics.getWindowInsets() + .getInsetsIgnoringVisibility(WindowInsets.Type.systemBars()); + return windowMetrics.getBounds().width() - insets.left - insets.right; + } else { + DisplayMetrics displayMetrics = new DisplayMetrics(); + activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); + return displayMetrics.widthPixels; + } + } - @Override - protected void onNewIntent(Intent intent) { - super.onNewIntent(intent); - if (getIntent().getBooleanExtra(EXTRA_FROM_QS_TILE, false)) { - mWindowSwitch.setChecked(true); - } - } + @Override + protected void onNewIntent(Intent intent) { + super.onNewIntent(intent); + if (getIntent().getBooleanExtra(EXTRA_FROM_QS_TILE, false)) { + mWindowSwitch.setChecked(true); + } + } - @Override - protected void onResume() { - super.onResume(); - refreshWindowSwitch(); - refreshNotificationSwitch(); - refreshAccessibilitySwitch(); - NotificationMonitor.cancelNotification(this); - } + @Override + protected void onResume() { + super.onResume(); + refreshWindowSwitch(); + refreshNotificationSwitch(); + refreshAccessibilitySwitch(); + NotificationMonitor.cancelNotification(this); + } - @Override - protected void onPause() { - super.onPause(); - if (DatabaseUtil.isShowWindow()) { - NotificationMonitor.showNotification(this, false); - } - } + @Override + protected void onPause() { + super.onPause(); + if (DatabaseUtil.isShowWindow()) { + NotificationMonitor.showNotification(this, false); + } + } - private void refreshWindowSwitch() { - mWindowSwitch.setChecked(DatabaseUtil.isShowWindow()); - if (DatabaseUtil.hasAccess() && AccessibilityMonitoringService.getInstance() == null) { - mWindowSwitch.setChecked(false); - } - } + private void refreshWindowSwitch() { + mWindowSwitch.setChecked(DatabaseUtil.isShowWindow()); + if (DatabaseUtil.hasAccess() && AccessibilityMonitoringService.getInstance() == null) { + mWindowSwitch.setChecked(false); + } + } - private void refreshAccessibilitySwitch() { - mAccessibilitySwitch.setChecked(DatabaseUtil.hasAccess()); - } + private void refreshAccessibilitySwitch() { + mAccessibilitySwitch.setChecked(DatabaseUtil.hasAccess()); + } - private void refreshNotificationSwitch() { - mNotificationSwitch.setChecked(!DatabaseUtil.isNotificationToggleEnabled()); - } + private void refreshNotificationSwitch() { + mNotificationSwitch.setChecked(!DatabaseUtil.isNotificationToggleEnabled()); + } - public void showToast(String str, int length) { - Toast.makeText(this, str, length).show(); - } + public void showToast(String str, int length) { + Toast.makeText(this, str, length).show(); + } - @Override - public boolean onCreateOptionsMenu(Menu menu) { - menu.add("GitHub Repo").setIcon(R.drawable.ic_github).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); - SpannableString span = new SpannableString("About App"); - span.setSpan(new TypefaceSpan(this, "fonts/google_sans_regular.ttf"), 0, span.length(), - Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - menu.add(span); - span = new SpannableString("Crash Log"); - span.setSpan(new TypefaceSpan(this, "fonts/google_sans_regular.ttf"), 0, span.length(), - Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - menu.add(span); - span = new SpannableString("Bug Report"); - span.setSpan(new TypefaceSpan(this, "fonts/google_sans_regular.ttf"), 0, span.length(), - Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - menu.add(span); - return super.onCreateOptionsMenu(menu); - } + @Override + public boolean onCreateOptionsMenu(Menu menu) { + menu.add("GitHub Repo").setIcon(R.drawable.ic_github).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); + SpannableString span = new SpannableString("About App"); + span.setSpan(new TypefaceSpan(this, "fonts/google_sans_regular.ttf"), 0, span.length(), + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + menu.add(span); + span = new SpannableString("Crash Log"); + span.setSpan(new TypefaceSpan(this, "fonts/google_sans_regular.ttf"), 0, span.length(), + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + menu.add(span); + span = new SpannableString("Bug Report"); + span.setSpan(new TypefaceSpan(this, "fonts/google_sans_regular.ttf"), 0, span.length(), + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + menu.add(span); + return super.onCreateOptionsMenu(menu); + } - public String readFile(File file) { - StringBuilder text = new StringBuilder(); - try { - BufferedReader br = new BufferedReader(new FileReader(file)); - String line = br.readLine(); - while (line != null) { - text.append(line); - text.append("\n"); - line = br.readLine(); - } + public String readFile(File file) { + StringBuilder text = new StringBuilder(); + try { + BufferedReader br = new BufferedReader(new FileReader(file)); + String line = br.readLine(); + while (line != null) { + text.append(line); + text.append("\n"); + line = br.readLine(); + } - new FileOutputStream(file).write(text.toString().getBytes()); - } catch (Exception e) { - e.printStackTrace(); - } - return text.toString(); - } + new FileOutputStream(file).write(text.toString().getBytes()); + } catch (Exception e) { + e.printStackTrace(); + } + return text.toString(); + } - @Override - public boolean onOptionsItemSelected(MenuItem item) { - String title = item.getTitle().toString(); - if (title.equals("About App")) { - fancy.setTitle("About App").setMessage( - "An useful open source tool for Android Developers, which shows the package name and class name of current activity\n\nHere are the main features of this app!\n● It provides a freely moveable popup window to view current activity info\n● It supports text copying from popup window\n● It supports quick settings and app shortcut for easy access to the popup window. Meaning you can get the popup window in your screen from anywhere") - .show(); - } else if (title.equals("Crash Log")) { - String errorLog = readFile(new File(App.getCrashLogDir(), "crash.txt")); - if (errorLog.isEmpty()) - showToast("No log was found", 0); - else { - Intent intent = new Intent(this, CrashActivity.class); - intent.putExtra(CrashActivity.EXTRA_CRASH_INFO, errorLog); - intent.putExtra("Restart", false); - startActivity(intent); - } - } else if (title.equals("GitHub Repo")) { - fancy.setTitle("GitHub Repo").setMessage( - "It is an open source project. Would you like to visit the official github repo of this app") - .setPositiveButton("Yes", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface di, int btn) { - di.dismiss(); - startActivity(new Intent().setAction(Intent.ACTION_VIEW) - .setData(Uri.parse("https://github.com/ratulhasanrahat/Current-Activity"))); - } - }).show(); - } else if (title.equals("Bug Report")) { - fancy.setTitle("Bug Report").setMessage( - "If you found a bug while using this app, please take a screenshot of it if possible. If it's a crash then you can find the crash log in this directory: " - + new File(App.getCrashLogDir(), "crash.txt").getAbsolutePath() - + "\n\nAfter you get all necessary things related to the bug, open an issue in github repo of this app with your bug report details") - .setPositiveButton("Create", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface di, int btn) { - di.dismiss(); - startActivity(new Intent().setAction(Intent.ACTION_VIEW).setData( - Uri.parse("https://github.com/ratulhasanrahat/Current-Activity/issues/new"))); - } - }).show(); - } - return super.onOptionsItemSelected(item); - } + @Override + public boolean onOptionsItemSelected(MenuItem item) { + String title = item.getTitle().toString(); + if (title.equals("About App")) { + fancy.setTitle("About App"); + fancy.setMessage("An useful open source tool for Android Developers, which shows the package name and class name of current activity\n\nHere are the main features of this app!\n● It provides a freely moveable popup window to view current activity info\n● It supports text copying from popup window\n● It supports quick settings and app shortcut for easy access to the popup window. Meaning you can get the popup window in your screen from anywhere"); + fancy.show(); + } else if (title.equals("Crash Log")) { + String errorLog = readFile(new File(App.getCrashLogDir(), "crash.txt")); + if (errorLog.isEmpty()) + showToast("No log was found", 0); + else { + Intent intent = new Intent(this, CrashActivity.class); + intent.putExtra(CrashActivity.EXTRA_CRASH_INFO, errorLog); + intent.putExtra("Restart", false); + startActivity(intent); + } + } else if (title.equals("GitHub Repo")) { + fancy.setTitle("GitHub Repo"); + fancy.setMessage("It is an open source project. Would you like to visit the official github repo of this app"); + fancy.setPositiveButton("Yes", new View.OnClickListener() { + @Override + public void onClick(View v) { + fancy.dismiss(); + startActivity(new Intent().setAction(Intent.ACTION_VIEW).setData(Uri.parse("https://github.com/ratulhasanrahat/Current-Activity"))); + } + }); + fancy.show(); + } else if (title.equals("Bug Report")) { + fancy.setTitle("Bug Report"); + fancy.setMessage("If you found a bug while using this app, please take a screenshot of it if possible. If it's a crash then you can find the crash log in this directory: " + new File(App.getCrashLogDir(), "crash.txt").getAbsolutePath() + "\n\nAfter you get all necessary things related to the bug, open an issue in github repo of this app with your bug report details"); + fancy.setPositiveButton("Create", new View.OnClickListener() { + @Override + public void onClick(View v) { + fancy.dismiss(); + startActivity(new Intent().setAction(Intent.ACTION_VIEW).setData(Uri.parse("https://github.com/ratulhasanrahat/Current-Activity/issues/new"))); + } + }); + fancy.show(); + } + return super.onOptionsItemSelected(item); + } - @Override - protected void onDestroy() { - super.onDestroy(); - unregisterReceiver(mReceiver); - } + @Override + protected void onDestroy() { + super.onDestroy(); + unregisterReceiver(mReceiver); + } - class UpdateSwitchReceiver extends BroadcastReceiver { - @Override - public void onReceive(Context context, Intent intent) { - refreshWindowSwitch(); - refreshNotificationSwitch(); - refreshAccessibilitySwitch(); - } - } + class UpdateSwitchReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + refreshWindowSwitch(); + refreshNotificationSwitch(); + refreshAccessibilitySwitch(); + } + } - public static boolean usageStats(Context context) { - boolean granted = false; - AppOpsManager appOps = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); - int mode = appOps.checkOpNoThrow(AppOpsManager.OPSTR_GET_USAGE_STATS, android.os.Process.myUid(), - context.getPackageName()); + public static boolean usageStats(Context context) { + boolean granted = false; + AppOpsManager appOps = (AppOpsManager) context. + getSystemService(Context.APP_OPS_SERVICE); + int mode = appOps.checkOpNoThrow(AppOpsManager.OPSTR_GET_USAGE_STATS, + android.os.Process.myUid(), context.getPackageName()); - if (mode == AppOpsManager.MODE_DEFAULT) { - granted = (context.checkCallingOrSelfPermission( - android.Manifest.permission.PACKAGE_USAGE_STATS) == PackageManager.PERMISSION_GRANTED); - } else { - granted = (mode == AppOpsManager.MODE_ALLOWED); - } - return granted; - } + if (mode == AppOpsManager.MODE_DEFAULT) { + granted = (context.checkCallingOrSelfPermission(android.Manifest.permission.PACKAGE_USAGE_STATS) == PackageManager.PERMISSION_GRANTED); + } else { + granted = (mode == AppOpsManager.MODE_ALLOWED); + } + return granted; + } - public void setupBattery() { - fancy.setTitle("Battery Optimizations").setMessage( - "Please remove battery optimization/restriction from this app in order to run in background with full functionality") - .setPositiveButton("Ok", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface di, int btn) { - di.dismiss(); - Intent intent = new Intent(); - intent.setAction("android.settings.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"); - intent.setData(Uri.parse("package:" + getPackageName())); - startActivity(intent); - } - }).show(); + public void setupBattery() { + fancy.setTitle("Battery Optimizations"); + fancy.setMessage("Please remove battery optimization/restriction from this app in order to run in background with full functionality"); + fancy.setPositiveButton("Ok", new View.OnClickListener() { + @Override + public void onClick(View v) { + fancy.dismiss(); + Intent intent = new Intent(); + intent.setAction("android.settings.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"); + intent.setData(Uri.parse("package:" + getPackageName())); + startActivity(intent); + } + }); + fancy.show(); - } + } } diff --git a/app/src/main/java/io/github/ratul/topactivity/ui/ShortcutHandlerActivity.java b/app/src/main/java/io/github/ratul/topactivity/ui/ShortcutHandlerActivity.java index a13e9cf..1f394ac 100644 --- a/app/src/main/java/io/github/ratul/topactivity/ui/ShortcutHandlerActivity.java +++ b/app/src/main/java/io/github/ratul/topactivity/ui/ShortcutHandlerActivity.java @@ -22,7 +22,6 @@ import android.os.Build; import android.os.Bundle; import android.provider.Settings; -import androidx.appcompat.app.AppCompatActivity; import io.github.ratul.topactivity.utils.DatabaseUtil; import io.github.ratul.topactivity.utils.WindowUtil; import io.github.ratul.topactivity.model.NotificationMonitor; @@ -34,31 +33,31 @@ * Refactored by Ratul on 04/05/2022. */ @TargetApi(Build.VERSION_CODES.N) -public class ShortcutHandlerActivity extends AppCompatActivity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - DatabaseUtil.setDisplayWidth(MainActivity.getScreenWidth(this)); +public class ShortcutHandlerActivity extends Activity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + DatabaseUtil.setDisplayWidth(MainActivity.getScreenWidth(this)); - if (!MainActivity.usageStats(this) || !Settings.canDrawOverlays(this)) { - Intent intent = new Intent(this, MainActivity.class); - intent.putExtra(MainActivity.EXTRA_FROM_QS_TILE, true); - startActivity(intent); - finish(); - } else if (AccessibilityMonitoringService.getInstance() == null && DatabaseUtil.hasAccess()) - startService(new Intent().setClass(this, AccessibilityMonitoringService.class)); + if (!MainActivity.usageStats(this) || !Settings.canDrawOverlays(this)) { + Intent intent = new Intent(this, MainActivity.class); + intent.putExtra(MainActivity.EXTRA_FROM_QS_TILE, true); + startActivity(intent); + finish(); + } else if (AccessibilityMonitoringService.getInstance() == null && DatabaseUtil.hasAccess()) + startService(new Intent().setClass(this, AccessibilityMonitoringService.class)); - boolean isShow = !DatabaseUtil.isShowWindow(); - DatabaseUtil.setIsShowWindow(isShow); - if (!isShow) { - WindowUtil.dismiss(this); - NotificationMonitor.showNotification(this, true); - } else { - WindowUtil.init(this); - NotificationMonitor.showNotification(this, false); - startService(new Intent(this, MonitoringService.class)); - } - sendBroadcast(new Intent(MainActivity.ACTION_STATE_CHANGED)); - finish(); - } + boolean isShow = !DatabaseUtil.isShowWindow(); + DatabaseUtil.setIsShowWindow(isShow); + if (!isShow) { + WindowUtil.dismiss(this); + NotificationMonitor.showNotification(this, true); + } else { + WindowUtil.init(this); + NotificationMonitor.showNotification(this, false); + startService(new Intent(this, MonitoringService.class)); + } + sendBroadcast(new Intent(MainActivity.ACTION_STATE_CHANGED)); + finish(); + } } diff --git a/app/src/main/java/io/github/ratul/topactivity/utils/DatabaseUtil.java b/app/src/main/java/io/github/ratul/topactivity/utils/DatabaseUtil.java index a57d6fe..f8b8b4c 100644 --- a/app/src/main/java/io/github/ratul/topactivity/utils/DatabaseUtil.java +++ b/app/src/main/java/io/github/ratul/topactivity/utils/DatabaseUtil.java @@ -18,6 +18,8 @@ import android.content.Context; import android.content.SharedPreferences; +import android.preference.PreferenceManager; +import android.widget.Toast; import io.github.ratul.topactivity.App; /** @@ -25,64 +27,64 @@ * Refactored by Ratul on 04/05/2022. */ public class DatabaseUtil { - private static SharedPreferences sp = App.getApp().getSharedPreferences("io.github.ratul.topactivity", 0); - - public static int getDisplayWidth() { - return sp.getInt("width", 720); - } - - public static void setDisplayWidth(int width) { - sp.edit().putInt("width", width).apply(); - } - - public static boolean isShowWindow() { - return sp.getBoolean("is_show_window", false); - } - - public static boolean hasBattery() { - return sp.getBoolean("hasBattery", false); - } - - public static void setHasBattery(boolean bool) { - sp.edit().putBoolean("hasBattery", bool).apply(); - } - - public static void setIsShowWindow(boolean isShow) { - sp.edit().putBoolean("is_show_window", isShow).apply(); - } - - public static boolean appInitiated() { - return sp.getBoolean("app_init", false); - } - - public static void setAppInitiated(boolean added) { - sp.edit().putBoolean("app_init", added).apply(); - } - - public static boolean hasAccess() { - return sp.getBoolean("has_access", true); - } - - public static void setHasAccess(boolean added) { - sp.edit().putBoolean("has_access", added).apply(); - } - - public static boolean hasQSTileAdded() { - return sp.getBoolean("has_qs_tile_added", false); - } - - public static void setQSTileAdded(boolean added) { - sp.edit().putBoolean("has_qs_tile_added", added).apply(); - } - - public static boolean isNotificationToggleEnabled() { - if (!hasQSTileAdded()) { - return true; - } - return sp.getBoolean("is_noti_toggle_enabled", true); - } - - public static void setNotificationToggleEnabled(boolean isEnabled) { - sp.edit().putBoolean("is_noti_toggle_enabled", isEnabled).apply(); - } + private static SharedPreferences sp = App.getApp().getSharedPreferences("io.github.ratul.topactivity", 0); + + public static int getDisplayWidth() { + return sp.getInt("width", 720); + } + + public static boolean setDisplayWidth(int width) { + return sp.edit().putInt("width", width).commit(); + } + + public static boolean isShowWindow() { + return sp.getBoolean("is_show_window", false); + } + + public static boolean hasBattery() { + return sp.getBoolean("hasBattery", false); + } + + public static boolean setHasBattery(boolean bool) { + return sp.edit().putBoolean("hasBattery", bool).commit(); + } + + public static void setIsShowWindow(boolean isShow) { + sp.edit().putBoolean("is_show_window", isShow).commit(); + } + + public static boolean appInitiated() { + return sp.getBoolean("app_init", false); + } + + public static void setAppInitiated(boolean added) { + sp.edit().putBoolean("app_init", added).commit(); + } + + public static boolean hasAccess() { + return sp.getBoolean("has_access", true); + } + + public static void setHasAccess(boolean added) { + sp.edit().putBoolean("has_access", added).commit(); + } + + public static boolean hasQSTileAdded() { + return sp.getBoolean("has_qs_tile_added", false); + } + + public static void setQSTileAdded(boolean added) { + sp.edit().putBoolean("has_qs_tile_added", added).commit(); + } + + public static boolean isNotificationToggleEnabled() { + if (!hasQSTileAdded()) { + return true; + } + return sp.getBoolean("is_noti_toggle_enabled", true); + } + + public static void setNotificationToggleEnabled(boolean isEnabled) { + sp.edit().putBoolean("is_noti_toggle_enabled", isEnabled).commit(); + } } diff --git a/app/src/main/java/io/github/ratul/topactivity/utils/WindowUtil.java b/app/src/main/java/io/github/ratul/topactivity/utils/WindowUtil.java index 96bb233..2839275 100644 --- a/app/src/main/java/io/github/ratul/topactivity/utils/WindowUtil.java +++ b/app/src/main/java/io/github/ratul/topactivity/utils/WindowUtil.java @@ -19,21 +19,22 @@ import android.content.Context; import android.graphics.PixelFormat; import android.os.Build; -import android.view.MotionEvent; -import android.view.View; import android.view.Gravity; import android.view.LayoutInflater; +import android.view.View; import android.view.WindowManager; +import android.widget.TextView; import android.content.ClipboardManager; import android.content.ClipData; import android.widget.Toast; import android.widget.LinearLayout; +import android.graphics.drawable.*; +import android.view.*; +import android.widget.*; import android.graphics.Typeface; import android.content.Intent; -import com.google.android.material.imageview.ShapeableImageView; import io.github.ratul.topactivity.R; import io.github.ratul.topactivity.model.NotificationMonitor; -import com.google.android.material.textview.MaterialTextView; import io.github.ratul.topactivity.ui.MainActivity; import io.github.ratul.topactivity.ui.BackgroundActivity; import io.github.ratul.topactivity.service.QuickSettingsService; @@ -46,152 +47,149 @@ * Created by Ratul on 04/05/2022. */ public class WindowUtil { - private static WindowManager.LayoutParams sWindowParams; - public static WindowManager sWindowManager; - private static View sView; - private static int xInitCord = 0; - private static int yInitCord = 0; - private static int xInitMargin = 0; - private static int yInitMargin = 0; - private static String text, text1; - private static MaterialTextView appName, packageName, className; - private static ClipboardManager clipboard; - public static boolean viewAdded = false; - - public static void init(final Context context) { - sWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); - - sWindowParams = new WindowManager.LayoutParams(WindowManager.LayoutParams.WRAP_CONTENT, - WindowManager.LayoutParams.WRAP_CONTENT, - Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY - : WindowManager.LayoutParams.TYPE_PHONE, - WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT); - - sWindowParams.gravity = Gravity.CENTER; - sWindowParams.width = (DatabaseUtil.getDisplayWidth() / 2) + 300; - sWindowParams.windowAnimations = android.R.style.Animation_Toast; - - sView = LayoutInflater.from(context).inflate(R.layout.window_tasks, null); - clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); - appName = sView.findViewById(R.id.text); - packageName = sView.findViewById(R.id.text1); - className = sView.findViewById(R.id.text2); - ShapeableImageView closeBtn = sView.findViewById(R.id.closeBtn); - - closeBtn.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - dismiss(context); - DatabaseUtil.setIsShowWindow(false); - NotificationMonitor.cancelNotification(context); - context.sendBroadcast(new Intent(MainActivity.ACTION_STATE_CHANGED)); - } - }); - - appName.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - copyString(context, text, "App name copied"); - } - }); - - packageName.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - copyString(context, text, "Package name copied"); - } - }); - - className.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - copyString(context, text1, "Class name copied"); - } - }); - - sView.setOnTouchListener(new View.OnTouchListener() { - public boolean onTouch(View view, MotionEvent event) { - WindowManager.LayoutParams layoutParams = sWindowParams; - - int xCord = (int) event.getRawX(); - int yCord = (int) event.getRawY(); - int xCordDestination; - int yCordDestination; - int action = event.getAction(); - - if (action == MotionEvent.ACTION_DOWN) { - xInitCord = xCord; - yInitCord = yCord; - xInitMargin = layoutParams.x; - yInitMargin = layoutParams.y; - } else if (action == MotionEvent.ACTION_MOVE) { - int xDiffMove = xCord - xInitCord; - int yDiffMove = yCord - yInitCord; - xCordDestination = xInitMargin + xDiffMove; - yCordDestination = yInitMargin + yDiffMove; - - layoutParams.x = xCordDestination; - layoutParams.y = yCordDestination; - sWindowManager.updateViewLayout(view, layoutParams); - } - return true; - } - }); - } - - private static void copyString(Context context, String str, String msg) { - if (Build.VERSION.SDK_INT < 29) { - ClipData clip = ClipData.newPlainText("Current Activity", str); - clipboard.setPrimaryClip(clip); - } else { - context.startActivity( - new Intent(context, BackgroundActivity.class).putExtra(BackgroundActivity.STRING_COPY, str) - .putExtra(BackgroundActivity.COPY_MSG, msg).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); - } - } - - public static String getAppName(Context context, String pkg) { - try { - PackageManager pm = context.getPackageManager(); - return pm.getApplicationLabel(pm.getApplicationInfo(pkg, 0)).toString(); - } catch (Exception e) { - // Ignored - e.printStackTrace(); - return ""; - } - } - - public static void show(Context context, String pkg, String clas) { - if (sWindowManager == null) { - init(context); - } - appName.setText(getAppName(context, pkg)); - packageName.setText(pkg); - className.setText(clas); - - if (!viewAdded) { - viewAdded = true; - if (DatabaseUtil.isShowWindow()) { - sWindowManager.addView(sView, sWindowParams); - } - } - - if (NotificationMonitor.builder != null) { - NotificationMonitor.builder.setContentTitle(text); - NotificationMonitor.builder.setContentText(text1); - NotificationMonitor.notifManager.notify(NotificationMonitor.NOTIFICATION_ID, - NotificationMonitor.builder.build()); - } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - QuickSettingsService.updateTile(context); - } - } - - public static void dismiss(Context context) { - viewAdded = false; - try { - sWindowManager.removeView(sView); - } catch (Exception e) { - e.printStackTrace(); - } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - QuickSettingsService.updateTile(context); - } - } + private static WindowManager.LayoutParams sWindowParams; + public static WindowManager sWindowManager; + private static View sView; + private static int xInitCord = 0; + private static int yInitCord = 0; + private static int xInitMargin = 0; + private static int yInitMargin = 0; + private static String text, text1; + private static TextView packageName, className, title; + private static ClipboardManager clipboard; + public static boolean viewAdded = false; + + public static void init(final Context context) { + sWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); + + sWindowParams = new WindowManager.LayoutParams( + WindowManager.LayoutParams.WRAP_CONTENT, + WindowManager.LayoutParams.WRAP_CONTENT, + Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY : WindowManager.LayoutParams.TYPE_PHONE, + WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, + PixelFormat.TRANSLUCENT); + + sWindowParams.gravity = Gravity.CENTER; + sWindowParams.width = (DatabaseUtil.getDisplayWidth() / 2) + 300; + sWindowParams.windowAnimations = android.R.style.Animation_Toast; + + sView = LayoutInflater.from(context).inflate(R.layout.window_tasks, + null); + clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); + packageName = sView.findViewById(R.id.text); + className = sView.findViewById(R.id.text1); + ImageView closeBtn = sView.findViewById(R.id.closeBtn); + title = sView.findViewById(R.id.title); + + closeBtn.setOnClickListener(new View.OnClickListener(){ + public void onClick(View v) { + dismiss(context); + DatabaseUtil.setIsShowWindow(false); + NotificationMonitor.cancelNotification(context); + context.sendBroadcast(new Intent(MainActivity.ACTION_STATE_CHANGED)); + } + }); + + packageName.setOnClickListener(new View.OnClickListener(){ + public void onClick(View v) { + copyString(context, text, "Package name copied"); + } + }); + + className.setOnClickListener(new View.OnClickListener(){ + public void onClick(View v) { + copyString(context, text1, "Class name copied"); + } + }); + + sView.setOnTouchListener(new View.OnTouchListener(){ + public boolean onTouch(View view, MotionEvent event) { + WindowManager.LayoutParams layoutParams = sWindowParams; + + int xCord = (int) event.getRawX(); + int yCord = (int) event.getRawY(); + int xCordDestination; + int yCordDestination; + int action = event.getAction(); + + if (action == MotionEvent.ACTION_DOWN) { + xInitCord = xCord; + yInitCord = yCord; + xInitMargin = layoutParams.x; + yInitMargin = layoutParams.y; + } else if (action == MotionEvent.ACTION_MOVE) { + int xDiffMove = xCord - xInitCord; + int yDiffMove = yCord - yInitCord; + xCordDestination = xInitMargin + xDiffMove; + yCordDestination = yInitMargin + yDiffMove; + + layoutParams.x = xCordDestination; + layoutParams.y = yCordDestination; + sWindowManager.updateViewLayout(view, layoutParams); + } + return true; + } + }); + } + + private static void copyString(Context context, String str, String msg) { + if (Build.VERSION.SDK_INT < 29) { + ClipData clip = ClipData.newPlainText("Current Activity", str); + clipboard.setPrimaryClip(clip); + } else { + context.startActivity(new Intent(context, BackgroundActivity.class) + .putExtra(BackgroundActivity.STRING_COPY, str) + .putExtra(BackgroundActivity.COPY_MSG, msg) + .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); + } + } + + public static String getAppName(Context context, String pkg) { + String appName = ""; + + try { + PackageManager pm = context.getPackageManager(); + appName = pm.getApplicationLabel(pm.getApplicationInfo(pkg, 0)).toString(); + } catch (Exception e) { + // Ignored + } + return appName + "-Activity Info"; + } + + public static void show(Context context, String pkg, String clas) { + if (sWindowManager == null) { + init(context); + } + text = pkg; + text1 = clas; + + title.setText(getAppName(context, pkg)); + packageName.setText(text); + className.setText(text1); + + if (!viewAdded) { + viewAdded = true; + if (DatabaseUtil.isShowWindow()) + sWindowManager.addView(sView, sWindowParams); + } + + if (NotificationMonitor.builder != null) { + NotificationMonitor.builder.setContentTitle(text); + NotificationMonitor.builder.setContentText(text1); + NotificationMonitor.notifManager.notify(NotificationMonitor.NOTIFICATION_ID, NotificationMonitor.builder.build()); + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + QuickSettingsService.updateTile(context); + } + + public static void dismiss(Context context) { + viewAdded = false; + try { + sWindowManager.removeView(sView); + } catch (Exception e) { + e.printStackTrace(); + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + QuickSettingsService.updateTile(context); + } } diff --git a/app/src/main/res/layout/abc_alert_dialog.xml b/app/src/main/res/layout/abc_alert_dialog.xml new file mode 100644 index 0000000..b47eab5 --- /dev/null +++ b/app/src/main/res/layout/abc_alert_dialog.xml @@ -0,0 +1,92 @@ + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 9629aa1..4f06945 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -14,7 +14,7 @@ android:gravity="center_vertical" android:padding="8dp"> - - - @@ -42,7 +42,7 @@ android:minHeight="48dp" android:padding="8dp"> - - - - - - - - - - - - - + + + + - - + - - + android:layout_marginRight="8dp" + android:layout_width="30dp" + android:layout_height="30dp" + android:src="@drawable/ic_close"/> + + + + + - - + - - - - - - - - - + - - - - - - - - - + android:textColor="#FFFFFF"/> + + + - \ No newline at end of file diff --git a/app/src/main/res/values-night/styles.xml b/app/src/main/res/values-night/styles.xml index 87d0148..ab35abd 100644 --- a/app/src/main/res/values-night/styles.xml +++ b/app/src/main/res/values-night/styles.xml @@ -1,6 +1,6 @@ - diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 61caf1b..9e0dca1 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,5 +1,5 @@ - diff --git a/gradle.properties b/gradle.properties index 079df3f..1bfba38 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,6 +15,6 @@ org.gradle.jvmargs=-Xmx1536m # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true -android.useAndroidX=true +#android.useAndroidX=true android.R8=true -android.enableJetifier=true +#android.enableJetifier=true