-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
830 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions
152
app/src/main/java/com/sevtinge/hyperceiler/ui/HyperCeilerTabActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
package com.sevtinge.hyperceiler.ui; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.content.SharedPreferences; | ||
import android.os.Bundle; | ||
import android.os.Handler; | ||
|
||
import androidx.annotation.Nullable; | ||
|
||
import com.sevtinge.hyperceiler.R; | ||
import com.sevtinge.hyperceiler.callback.IResult; | ||
import com.sevtinge.hyperceiler.prefs.PreferenceHeader; | ||
import com.sevtinge.hyperceiler.safe.CrashData; | ||
import com.sevtinge.hyperceiler.ui.base.HyperCeilerTabBaseActivity; | ||
import com.sevtinge.hyperceiler.utils.BackupUtils; | ||
import com.sevtinge.hyperceiler.utils.Helpers; | ||
import com.sevtinge.hyperceiler.utils.LanguageHelper; | ||
import com.sevtinge.hyperceiler.utils.PropUtils; | ||
import com.sevtinge.hyperceiler.utils.ThreadPoolManager; | ||
import com.sevtinge.hyperceiler.utils.api.ProjectApi; | ||
import com.sevtinge.hyperceiler.utils.prefs.PrefsUtils; | ||
import com.sevtinge.hyperceiler.utils.search.SearchHelper; | ||
import com.sevtinge.hyperceiler.utils.shell.ShellInit; | ||
|
||
import java.util.ArrayList; | ||
|
||
import fan.appcompat.app.AlertDialog; | ||
|
||
public class HyperCeilerTabActivity extends HyperCeilerTabBaseActivity implements IResult { | ||
|
||
private Handler handler; | ||
private Context context; | ||
|
||
private ArrayList<String> appCrash = new ArrayList<>(); | ||
|
||
@Override | ||
protected void onCreate(Bundle bundle) { | ||
SharedPreferences mPrefs = PrefsUtils.mSharedPreferences; | ||
int count = Integer.parseInt(mPrefs.getString("prefs_key_settings_app_language", "-1")); | ||
if (count != -1) { | ||
LanguageHelper.setIndexLanguage(this, count, false); | ||
} | ||
handler = new Handler(this.getMainLooper()); | ||
context = this; | ||
int def = Integer.parseInt(PrefsUtils.mSharedPreferences.getString("prefs_key_log_level", "3")); | ||
super.onCreate(bundle); | ||
new Thread(() -> SearchHelper.getAllMods(this, bundle != null)).start(); | ||
Helpers.checkXposedActivateState(this); | ||
ShellInit.init(this); | ||
PropUtils.setProp("persist.hyperceiler.log.level", ProjectApi.isCanary() ? (def != 3 && def != 4 ? 3 : def) : def); | ||
appCrash = CrashData.toPkgList(); | ||
handler.postDelayed(() -> { | ||
if (haveCrashReport()) { | ||
new AlertDialog.Builder(this) | ||
.setTitle(R.string.safe_mode_later_title) | ||
.setMessage(appCrash.toString() + " " + getString(R.string.safe_mode_later_desc)) | ||
.setHapticFeedbackEnabled(true) | ||
.setCancelable(false) | ||
.setPositiveButton(R.string.safe_mode_cancel, (dialog, which) -> { | ||
ShellInit.getShell().run("setprop persist.hyperceiler.crash.report \"\"").sync(); | ||
dialog.dismiss(); | ||
}) | ||
.setNegativeButton(R.string.safe_mode_ok, (dialog, which) -> dialog.dismiss()) | ||
.show(); | ||
} | ||
}, 600); | ||
} | ||
|
||
@Override | ||
public void error(String reason) { | ||
handler.post(() -> new AlertDialog.Builder(context) | ||
.setCancelable(false) | ||
.setTitle(getResources().getString(R.string.tip)) | ||
.setMessage(getResources().getString(R.string.root)) | ||
.setHapticFeedbackEnabled(true) | ||
.setPositiveButton(android.R.string.ok, null) | ||
.show()); | ||
} | ||
|
||
private boolean haveCrashReport() { | ||
return !appCrash.isEmpty(); | ||
} | ||
|
||
@Override | ||
public void onDestroy() { | ||
ShellInit.destroy(); | ||
ThreadPoolManager.shutdown(); | ||
PreferenceHeader.mUninstallApp.clear(); | ||
PreferenceHeader.mDisableOrHiddenApp.clear(); | ||
super.onDestroy(); | ||
} | ||
|
||
public void test() { | ||
/*boolean ls = shellExec.append("ls").sync().isResult(); | ||
AndroidLogUtils.LogI(ITAG.TAG, "ls: " + ls); | ||
AndroidLogUtils.LogI(ITAG.TAG, shellExec.getOutPut().toString() + shellExec.getError().toString()); | ||
boolean f = shellExec.append("for i in $(seq 1 500); do echo $i; done").isResult(); | ||
AndroidLogUtils.LogI(ITAG.TAG, "for: " + f); | ||
AndroidLogUtils.LogI(ITAG.TAG, shellExec.getOutPut().toString()); | ||
boolean k = shellExec.append("for i in $(seq 1 500); do echo $i; done").sync().isResult(); | ||
AndroidLogUtils.LogI(ITAG.TAG, "fork: " + k); | ||
AndroidLogUtils.LogI(ITAG.TAG, shellExec.getOutPut().toString());*/ | ||
} | ||
|
||
private void requestCta() { | ||
/*if (!CtaUtils.isCtaEnabled(this)) { | ||
CtaUtils.showCtaDialog(this, REQUEST_CODE); | ||
}*/ | ||
} | ||
|
||
@Override | ||
protected void onNewIntent(Intent intent) { | ||
super.onNewIntent(intent); | ||
requestCta(); | ||
} | ||
|
||
@Override | ||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { | ||
super.onActivityResult(requestCode, resultCode, data); | ||
if (data == null) return; | ||
try { | ||
AlertDialog.Builder alert = new AlertDialog.Builder(this); | ||
switch (requestCode) { | ||
case BackupUtils.CREATE_DOCUMENT_CODE -> { | ||
BackupUtils.handleCreateDocument(this, data.getData()); | ||
alert.setTitle(R.string.backup_success); | ||
} | ||
case BackupUtils.OPEN_DOCUMENT_CODE -> { | ||
BackupUtils.handleReadDocument(this, data.getData()); | ||
alert.setTitle(R.string.rest_success); | ||
} | ||
default -> { | ||
return; | ||
} | ||
} | ||
alert.setPositiveButton(android.R.string.ok, (dialog, which) -> { | ||
}); | ||
alert.show(); | ||
} catch (Exception e) { | ||
AlertDialog.Builder alert = new AlertDialog.Builder(this); | ||
switch (requestCode) { | ||
case BackupUtils.CREATE_DOCUMENT_CODE -> alert.setTitle(R.string.backup_failed); | ||
case BackupUtils.OPEN_DOCUMENT_CODE -> alert.setTitle(R.string.rest_failed); | ||
} | ||
alert.setMessage(e.toString()); | ||
alert.setPositiveButton(android.R.string.ok, (dialog, which) -> { | ||
}); | ||
alert.show(); | ||
} | ||
} | ||
} |
108 changes: 108 additions & 0 deletions
108
app/src/main/java/com/sevtinge/hyperceiler/ui/base/HyperCeilerTabBaseActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package com.sevtinge.hyperceiler.ui.base; | ||
|
||
import android.os.Bundle; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import com.sevtinge.hyperceiler.R; | ||
import com.sevtinge.hyperceiler.ui.SubSettings; | ||
import com.sevtinge.hyperceiler.ui.page.ContentFragment; | ||
import com.sevtinge.hyperceiler.utils.SettingLauncherHelper; | ||
|
||
import fan.appcompat.app.Fragment; | ||
import fan.navigator.Navigator; | ||
import fan.navigator.NavigatorStrategy; | ||
import fan.navigator.app.NavigatorActivity; | ||
import fan.navigator.navigatorinfo.NavigatorInfoProvider; | ||
import fan.navigator.navigatorinfo.UpdateFragmentNavInfo; | ||
import fan.preference.Preference; | ||
import fan.preference.PreferenceFragment; | ||
import fan.preference.core.PreferenceFragmentCompat; | ||
|
||
public class HyperCeilerTabBaseActivity extends NavigatorActivity | ||
implements PreferenceFragment.OnPreferenceStartFragmentCallback { | ||
|
||
@Override | ||
public int getBottomTabMenu() { | ||
return R.menu.bottom_nav_menu; | ||
} | ||
|
||
@Override | ||
public NavigatorInfoProvider getBottomTabMenuNavInfoProvider() { | ||
Bundle bundle = new Bundle(); | ||
return i -> { | ||
if (i == 1000) { | ||
bundle.putInt("page", 0); | ||
} else if (i == 1001) { | ||
bundle.putInt("page", 1); | ||
} else if (i == 1002) { | ||
bundle.putInt("page", 2); | ||
} else { | ||
return null; | ||
} | ||
return new UpdateFragmentNavInfo(i, getDefaultContentFragment(), bundle); | ||
}; | ||
} | ||
|
||
@Override | ||
public Class<? extends Fragment> getDefaultContentFragment() { | ||
return ContentFragment.class; | ||
} | ||
|
||
@Override | ||
public int getNavigationOptionMenu() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public Bundle getNavigatorInitArgs() { | ||
NavigatorStrategy navigatorStrategy = new NavigatorStrategy(); | ||
navigatorStrategy.setLargeMode(Navigator.Mode.C); | ||
Bundle bundle = new Bundle(); | ||
bundle.putParcelable("miuix:navigatorStrategy", navigatorStrategy); | ||
return bundle; | ||
} | ||
|
||
@Override | ||
public void onCreateOtherNavigation(Navigator navigator, Bundle bundle) { | ||
|
||
} | ||
|
||
@Override | ||
public void onCreatePrimaryNavigation(Navigator navigator, Bundle bundle) { | ||
UpdateFragmentNavInfo updateFragmentNavInfoToHome = getUpdateFragmentNavInfoToHome(); | ||
UpdateFragmentNavInfo updateFragmentNavInfoToSettings = updateFragmentNavInfoToSettings(); | ||
UpdateFragmentNavInfo updateFragmentNavInfoToClock = getUpdateFragmentNavInfoToAbout(); | ||
newLabel(getString(R.string.home), updateFragmentNavInfoToHome); | ||
newLabel(getString(R.string.settings), updateFragmentNavInfoToSettings); | ||
newLabel(getString(R.string.about), updateFragmentNavInfoToClock); | ||
navigator.navigate(updateFragmentNavInfoToHome); | ||
} | ||
|
||
private UpdateFragmentNavInfo getUpdateFragmentNavInfoToHome() { | ||
Bundle bundle = new Bundle(); | ||
bundle.putInt("page", 0); | ||
return new UpdateFragmentNavInfo(1000, getDefaultContentFragment(), bundle); | ||
} | ||
|
||
private UpdateFragmentNavInfo updateFragmentNavInfoToSettings() { | ||
Bundle bundle = new Bundle(); | ||
bundle.putInt("page", 1); | ||
return new UpdateFragmentNavInfo(1001, getDefaultContentFragment(), bundle); | ||
} | ||
|
||
private UpdateFragmentNavInfo getUpdateFragmentNavInfoToAbout() { | ||
Bundle bundle = new Bundle(); | ||
bundle.putInt("page", 2); | ||
return new UpdateFragmentNavInfo(1002, getDefaultContentFragment(), bundle); | ||
} | ||
|
||
@Override | ||
public boolean onPreferenceStartFragment(@NonNull PreferenceFragmentCompat preferenceFragmentCompat, @NonNull Preference preference) { | ||
Bundle args = null; | ||
String mFragmentName = preference.getFragment(); | ||
String mTitle = preference.getTitle().toString(); | ||
SettingLauncherHelper.onStartSettingsForArguments(this, SubSettings.class, mFragmentName, args, mTitle); | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.