Skip to content

Commit

Permalink
Merge pull request #92 from axel358/cleanup
Browse files Browse the repository at this point in the history
Cleanup
  • Loading branch information
axel358 authored Sep 30, 2023
2 parents f1dad5e + 5b4c4ae commit 6e87cd5
Show file tree
Hide file tree
Showing 63 changed files with 5,145 additions and 5,415 deletions.
6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
android:theme="@style/AppTheme" >
<activity
android:name=".activities.MainActivity"
android:exported="true"
android:label="@string/app_name" >
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand All @@ -46,7 +45,6 @@
android:name=".activities.LauncherActivity"
android:excludeFromRecents="true"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/AppTheme.Launcher" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand All @@ -59,7 +57,6 @@
android:name=".activities.SecondaryLauncherActivity"
android:excludeFromRecents="true"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/AppTheme.Launcher" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
82 changes: 40 additions & 42 deletions app/src/main/java/cu/axel/smartdock/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,49 @@
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

import com.google.android.material.color.DynamicColors;

import cu.axel.smartdock.activities.DebugActivity;
import cu.axel.smartdock.utils.Utils;

public class App extends Application {
private Thread.UncaughtExceptionHandler uncaughtExceptionHandler;
@Override
public void onCreate() {
DynamicColors.applyToActivitiesIfAvailable(this);
uncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable exception) {

String report = "Exception: " + exception + "\n";

for (StackTraceElement element : exception.getStackTrace())
report += element.toString() + "\n";

Throwable cause = exception.getCause();

if (cause != null) {
report += "Cause: " + cause + "\n";
for (StackTraceElement element:cause.getStackTrace())
report += element.toString() + "\n";

}

String message=exception.getMessage();
if (message != null)
report += "Message: " + message;

Intent intent = new Intent(getApplicationContext(), DebugActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.putExtra("report", report);
//startActivity(intent);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 11111, intent, PendingIntent.FLAG_ONE_SHOT);
AlarmManager am = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, 1000, pendingIntent);
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(2);
uncaughtExceptionHandler.uncaughtException(thread, exception);
}
});
super.onCreate();
}
private Thread.UncaughtExceptionHandler uncaughtExceptionHandler;

@Override
public void onCreate() {
DynamicColors.applyToActivitiesIfAvailable(this);
uncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler((thread, exception) -> {

StringBuilder report = new StringBuilder("Exception: " + exception + "\n");

for (StackTraceElement element : exception.getStackTrace())
report.append(element.toString()).append("\n");

Throwable cause = exception.getCause();

if (cause != null) {
report.append("Cause: ").append(cause).append("\n");
for (StackTraceElement element : cause.getStackTrace())
report.append(element.toString()).append("\n");
}

String message = exception.getMessage();
if (message != null)
report.append("Message: ").append(message);

Intent intent = new Intent(getApplicationContext(), DebugActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.putExtra("report", report.toString());
//startActivity(intent);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 11111, intent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE);
AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, 1000, pendingIntent);
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(2);
uncaughtExceptionHandler.uncaughtException(thread, exception);
});
super.onCreate();
}

}
48 changes: 23 additions & 25 deletions app/src/main/java/cu/axel/smartdock/activities/DebugActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,34 @@
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import java.io.FileWriter;
import java.io.File;
import java.io.IOException;

import cu.axel.smartdock.R;
import cu.axel.smartdock.utils.Utils;

public class DebugActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

MaterialAlertDialogBuilder dialog = new MaterialAlertDialogBuilder(this);
dialog.setTitle(R.string.something_wrong);
final String report = getIntent().getStringExtra("report");
dialog.setMessage(report);
dialog.setPositiveButton(R.string.ok, (DialogInterface p1, int which) -> finish());

MaterialAlertDialogBuilder dialog = new MaterialAlertDialogBuilder(this);
dialog.setTitle(R.string.something_wrong);
final String report = getIntent().getStringExtra("report");
dialog.setMessage(report);
dialog.setPositiveButton(R.string.ok, (DialogInterface p1, int which) -> {
finish();
});

dialog.setNeutralButton(R.string.save_log, (DialogInterface p1, int p2) -> {
Utils.saveLog(DebugActivity.this, "crash_log", report);
finish();
});
dialog.setNegativeButton(R.string.open_again, (DialogInterface p1, int p2) -> {
startActivity(new Intent(DebugActivity.this, MainActivity.class));
finish();
});
dialog.setCancelable(false);
dialog.create().show();
}
dialog.setNeutralButton(R.string.save_log, (DialogInterface p1, int p2) -> {
Utils.saveLog(DebugActivity.this, "crash_log", report);
finish();
});
dialog.setNegativeButton(R.string.open_again, (DialogInterface p1, int p2) -> {
startActivity(new Intent(DebugActivity.this, MainActivity.class));
finish();
});
dialog.setCancelable(false);
dialog.create().show();
}
}
Original file line number Diff line number Diff line change
@@ -1,65 +1,53 @@
package cu.axel.smartdock.activities;

import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.graphics.Rect;
import android.content.pm.ShortcutInfo;
import android.net.Uri;
import android.os.Bundle;
import androidx.preference.PreferenceManager;
import android.provider.Settings;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.google.android.material.button.MaterialButton;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;

import cu.axel.smartdock.R;
import cu.axel.smartdock.adapters.AppActionsAdapter;
import cu.axel.smartdock.adapters.AppAdapter;
import cu.axel.smartdock.adapters.AppShortcutAdapter;
import cu.axel.smartdock.icons.IconParserUtilities;
import cu.axel.smartdock.models.Action;
import cu.axel.smartdock.models.App;
import cu.axel.smartdock.services.DockService;
import cu.axel.smartdock.utils.AppUtils;
import cu.axel.smartdock.utils.ColorUtils;
import cu.axel.smartdock.utils.DeepShortcutManager;
import cu.axel.smartdock.utils.DeviceUtils;
import cu.axel.smartdock.utils.Utils;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import android.content.pm.ShortcutInfo;
import cu.axel.smartdock.utils.DeepShortcutManager;
import cu.axel.smartdock.adapters.AppShortcutAdapter;
import android.widget.Adapter;

public class LauncherActivity extends AppCompatActivity implements AppAdapter.OnAppClickListener {
private LinearLayout backgroundLayout;
private MaterialButton serviceBtn;
private RecyclerView appsGv;
private EditText notesEt;
Expand All @@ -71,7 +59,7 @@ public class LauncherActivity extends AppCompatActivity implements AppAdapter.On
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_launcher);
backgroundLayout = findViewById(R.id.ll_background);
LinearLayout backgroundLayout = findViewById(R.id.ll_background);
serviceBtn = findViewById(R.id.service_btn);
appsGv = findViewById(R.id.desktop_apps_gv);
appsGv.setLayoutManager(new GridLayoutManager(this, 2));
Expand All @@ -80,15 +68,13 @@ protected void onCreate(Bundle savedInstanceState) {
iconParserUtilities = new IconParserUtilities(this);


serviceBtn.setOnClickListener((View p1) -> {
startActivity(new Intent(LauncherActivity.this, MainActivity.class));
});
serviceBtn.setOnClickListener((View p1) -> startActivity(new Intent(LauncherActivity.this, MainActivity.class)));

backgroundLayout.setOnLongClickListener((View v0) -> {
final View view = LayoutInflater.from(LauncherActivity.this).inflate(R.layout.task_list, null);
WindowManager.LayoutParams lp = Utils.makeWindowParams(-2, -2, LauncherActivity.this, false);
ColorUtils.applyMainColor(LauncherActivity.this, sp, view);
lp.gravity = Gravity.TOP | Gravity.LEFT;
lp.gravity = Gravity.TOP | Gravity.START;
lp.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
lp.x = (int) x;
Expand All @@ -103,7 +89,7 @@ protected void onCreate(Bundle savedInstanceState) {
return false;
});
final ListView actionsLv = view.findViewById(R.id.tasks_lv);
ArrayList<Action> actions = new ArrayList<Action>();
ArrayList<Action> actions = new ArrayList<>();
actions.add(new Action(R.drawable.ic_wallpaper, getString(R.string.change_wallpaper)));
actions.add(new Action(R.drawable.ic_fullscreen, getString(R.string.display_settings)));

Expand Down Expand Up @@ -187,13 +173,13 @@ public void loadNotes() {
File notes = new File(getExternalFilesDir(null), "notes.txt");
try {
BufferedReader br = new BufferedReader(new FileReader(notes));
String line = "";
String noteContent = "";
String line;
StringBuilder noteContent = new StringBuilder();
while ((line = br.readLine()) != null) {
noteContent += line + "\n";
noteContent.append(line).append("\n");
}
br.close();
notesEt.setText(noteContent);
notesEt.setText(noteContent.toString());
} catch (IOException e) {
}

Expand Down Expand Up @@ -222,7 +208,7 @@ public void launchApp(String mode, String app) {
}

public ArrayList<Action> getAppActions(String app) {
ArrayList<Action> actions = new ArrayList<Action>();
ArrayList<Action> actions = new ArrayList<>();
if (DeepShortcutManager.hasHostPermission(this)) {
if (DeepShortcutManager.getShortcuts(app, this).size() > 0)
actions.add(new Action(R.drawable.ic_shortcuts, getString(R.string.shortcuts)));
Expand All @@ -239,7 +225,7 @@ public void showAppContextMenu(final String app, View anchor) {
final View view = LayoutInflater.from(this).inflate(R.layout.task_list, null);
WindowManager.LayoutParams lp = Utils.makeWindowParams(-2, -2, this, false);
ColorUtils.applyMainColor(LauncherActivity.this, sp, view);
lp.gravity = Gravity.TOP | Gravity.LEFT;
lp.gravity = Gravity.TOP | Gravity.START;
lp.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;

int[] location = new int[2];
Expand All @@ -262,7 +248,7 @@ public void showAppContextMenu(final String app, View anchor) {
if (p1.getItemAtPosition(p3) instanceof Action) {
Action action = (Action) p1.getItemAtPosition(p3);
if (action.getText().equals(getString(R.string.manage))) {
ArrayList<Action> actions = new ArrayList<Action>();
ArrayList<Action> actions = new ArrayList<>();
actions.add(new Action(R.drawable.ic_arrow_back, ""));
actions.add(new Action(R.drawable.ic_info, getString(R.string.app_info)));
if (!AppUtils.isSystemApp(LauncherActivity.this, app)
Expand All @@ -278,7 +264,7 @@ public void showAppContextMenu(final String app, View anchor) {
} else if (action.getText().equals("")) {
actionsLv.setAdapter(new AppActionsAdapter(LauncherActivity.this, getAppActions(app)));
} else if (action.getText().equals(getString(R.string.open_in))) {
ArrayList<Action> actions = new ArrayList<Action>();
ArrayList<Action> actions = new ArrayList<>();
actions.add(new Action(R.drawable.ic_arrow_back, ""));
actions.add(new Action(R.drawable.ic_standard, getString(R.string.standard)));
actions.add(new Action(R.drawable.ic_maximized, getString(R.string.maximized)));
Expand Down
Loading

0 comments on commit 6e87cd5

Please sign in to comment.