mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
fix: partially revert 9126d01fb7 to fix tests
This commit is contained in:
@@ -50,7 +50,7 @@ class MainActivity : IDEActivity() {
|
||||
private var binding: ActivityMainBinding? = null
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
if (!BaseApplication.isAbiSupported) {
|
||||
if (!BaseApplication.isAbiSupported()) {
|
||||
showDeviceNotSupported()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -362,7 +362,7 @@ abstract class BaseEditorActivity :
|
||||
}
|
||||
|
||||
open fun showDaemonStatus() {
|
||||
val shell = app.newShell(callback = { t -> getDaemonStatusFragment().append(t) })
|
||||
val shell = app.newShell{ t -> getDaemonStatusFragment().append(t) }
|
||||
shell.bgAppend(String.format("echo '%s'", getString(string.msg_getting_daemom_status)))
|
||||
shell.bgAppend(
|
||||
String.format("cd '%s' && sh gradlew --status", Objects.requireNonNull(getProjectDirPath()))
|
||||
|
||||
@@ -68,7 +68,7 @@ private class GradleOptions(
|
||||
addPreference(GradleCommands())
|
||||
addPreference(GradleDistrubution())
|
||||
addPreference(GradleClearCache())
|
||||
if (BaseApplication.isAarch64 && VERSION.SDK_INT == VERSION_CODES.R) {
|
||||
if (BaseApplication.isAarch64() && VERSION.SDK_INT == VERSION_CODES.R) {
|
||||
addPreference(TagPointersFix())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,217 @@
|
||||
/*
|
||||
* This file is part of AndroidIDE.
|
||||
*
|
||||
* AndroidIDE 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.
|
||||
*
|
||||
* AndroidIDE 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 AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.itsaky.androidide.app;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.app.NotificationManagerCompat;
|
||||
import androidx.multidex.BuildConfig;
|
||||
import androidx.multidex.MultiDexApplication;
|
||||
|
||||
import com.blankj.utilcode.util.ThrowableUtils;
|
||||
import com.google.android.material.color.DynamicColors;
|
||||
import com.itsaky.androidide.resources.R;
|
||||
import com.itsaky.androidide.managers.PreferenceManager;
|
||||
import com.itsaky.androidide.managers.ToolsManager;
|
||||
import com.itsaky.androidide.shell.ShellServer;
|
||||
import com.itsaky.androidide.utils.Environment;
|
||||
import com.itsaky.androidide.utils.FileUtil;
|
||||
import com.itsaky.androidide.utils.ILogger;
|
||||
import com.itsaky.androidide.utils.JavaCharacter;
|
||||
import com.itsaky.toaster.ToastUtilsKt;
|
||||
import com.itsaky.toaster.Toaster;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
|
||||
public abstract class BaseApplication extends MultiDexApplication {
|
||||
|
||||
public static final String NOTIFICATION_GRADLE_BUILD_SERVICE = "17571";
|
||||
public static final String TELEGRAM_GROUP_URL = "https://t.me/androidide_discussions";
|
||||
public static final String TELEGRAM_CHANNEL_URL = "https://t.me/AndroidIDEOfficial";
|
||||
public static final String GITHUB_URL = "https://github.com/AndroidIDEOfficial/AndroidIDE";
|
||||
public static final String WEBSITE = "https://androidide.com";
|
||||
public static final String SPONSOR_URL = "https://androidide.com/donate.php";
|
||||
|
||||
// TODO Replace when available on website
|
||||
public static final String DOCS_URL = "https://github.com/AndroidIDEOfficial/AndroidIDE/tree/main/docs";
|
||||
public static final String EMAIL = "contact@androidide.com";
|
||||
private static BaseApplication instance;
|
||||
private PreferenceManager mPrefsManager;
|
||||
|
||||
private static final ILogger LOG = ILogger.newInstance("BaseApplication");
|
||||
|
||||
public static BaseApplication getBaseInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static boolean isAbiSupported() {
|
||||
return isAarch64() || isArmv7a();
|
||||
}
|
||||
|
||||
public static boolean isAarch64() {
|
||||
return Arrays.asList(Build.SUPPORTED_ABIS).contains("arm64-v8a");
|
||||
}
|
||||
|
||||
public static boolean isArmv7a() {
|
||||
return Arrays.asList(Build.SUPPORTED_ABIS).contains("armeabi-v7a");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getArch() {
|
||||
if (BaseApplication.isAarch64()) {
|
||||
return "arm64-v8a";
|
||||
} else if (BaseApplication.isArmv7a()) {
|
||||
return "armeabi-v7a";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
instance = this;
|
||||
Environment.init();
|
||||
ToastUtilsKt.init();
|
||||
super.onCreate();
|
||||
|
||||
mPrefsManager = new PreferenceManager(this);
|
||||
JavaCharacter.initMap();
|
||||
ToolsManager.init(this, null);
|
||||
|
||||
DynamicColors.applyToActivitiesIfAvailable(this);
|
||||
|
||||
createNotificationChannels();
|
||||
}
|
||||
|
||||
private void createNotificationChannels() {
|
||||
NotificationChannel buildNotificationChannel =
|
||||
new NotificationChannel(
|
||||
NOTIFICATION_GRADLE_BUILD_SERVICE,
|
||||
getString(R.string.title_gradle_service_notification_channel),
|
||||
NotificationManager.IMPORTANCE_LOW);
|
||||
NotificationManagerCompat.from(this).createNotificationChannel(buildNotificationChannel);
|
||||
}
|
||||
|
||||
public ShellServer newShell(ShellServer.Callback callback) {
|
||||
return newShell(callback, true);
|
||||
}
|
||||
|
||||
public ShellServer newShell(ShellServer.Callback callback, boolean redirectErrors) {
|
||||
ShellServer shellServer =
|
||||
new ShellServer(
|
||||
callback,
|
||||
"sh",
|
||||
Environment.mkdirIfNotExits(getRootDir()).getAbsolutePath(),
|
||||
Environment.getEnvironment(),
|
||||
redirectErrors);
|
||||
shellServer.start();
|
||||
return shellServer;
|
||||
}
|
||||
|
||||
public File getRootDir() {
|
||||
return new File(getIDEDataDir(), "home");
|
||||
}
|
||||
|
||||
@SuppressLint("SdCardPath")
|
||||
public File getIDEDataDir() {
|
||||
return Environment.mkdirIfNotExits(new File("/data/data/com.itsaky.androidide/files"));
|
||||
}
|
||||
|
||||
public void writeException(Throwable th) {
|
||||
FileUtil.writeFile(
|
||||
new File(FileUtil.getExternalStorageDir(), "idelog.txt").getAbsolutePath(),
|
||||
ThrowableUtils.getFullStackTrace(th));
|
||||
}
|
||||
|
||||
public final File getTempProjectDir() {
|
||||
return Environment.mkdirIfNotExits(new File(Environment.TMP_DIR, "tempProject"));
|
||||
}
|
||||
|
||||
public PreferenceManager getPrefManager() {
|
||||
return mPrefsManager;
|
||||
}
|
||||
|
||||
public File getProjectsDir() {
|
||||
return Environment.PROJECTS_DIR;
|
||||
}
|
||||
|
||||
public void openTelegramGroup() {
|
||||
openTelegram(BaseApplication.TELEGRAM_GROUP_URL);
|
||||
}
|
||||
|
||||
public void openTelegramChannel() {
|
||||
openTelegram(BaseApplication.TELEGRAM_CHANNEL_URL);
|
||||
}
|
||||
|
||||
public void openGitHub() {
|
||||
openUrl(GITHUB_URL);
|
||||
}
|
||||
|
||||
public void openWebsite() {
|
||||
openUrl(WEBSITE);
|
||||
}
|
||||
|
||||
public void openSponsors() {
|
||||
openUrl(SPONSOR_URL);
|
||||
}
|
||||
|
||||
public void openDocs() {
|
||||
openUrl(DOCS_URL);
|
||||
}
|
||||
|
||||
public void emailUs() {
|
||||
openUrl("mailto:" + EMAIL);
|
||||
}
|
||||
|
||||
|
||||
public void openUrl(String url) {
|
||||
openUrl(url, null);
|
||||
}
|
||||
|
||||
public void openTelegram(String url) {
|
||||
openUrl(url, "org.telegram.messenger");
|
||||
}
|
||||
|
||||
public void openUrl(String url, String pkg) {
|
||||
try {
|
||||
Intent open = new Intent();
|
||||
open.setAction(Intent.ACTION_VIEW);
|
||||
open.setData(Uri.parse(url));
|
||||
open.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
if (pkg != null) {
|
||||
open.setPackage(pkg);
|
||||
}
|
||||
startActivity(open);
|
||||
} catch (Throwable th) {
|
||||
if (pkg != null) {
|
||||
openUrl(url);
|
||||
} else {
|
||||
ToastUtilsKt.toast(th.getMessage(), Toaster.Type.ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,193 +0,0 @@
|
||||
/*
|
||||
* This file is part of AndroidIDE.
|
||||
*
|
||||
* AndroidIDE 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.
|
||||
*
|
||||
* AndroidIDE 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 AndroidIDE. If not, see <https:></https:>//www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.itsaky.androidide.app
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
import androidx.multidex.MultiDexApplication
|
||||
import com.blankj.utilcode.util.ThrowableUtils
|
||||
import com.google.android.material.color.DynamicColors
|
||||
import com.itsaky.androidide.managers.PreferenceManager
|
||||
import com.itsaky.androidide.managers.ToolsManager
|
||||
import com.itsaky.androidide.resources.R.string
|
||||
import com.itsaky.androidide.shell.ShellServer
|
||||
import com.itsaky.androidide.shell.ShellServer.Callback
|
||||
import com.itsaky.androidide.utils.Environment
|
||||
import com.itsaky.androidide.utils.FileUtil
|
||||
import com.itsaky.androidide.utils.JavaCharacter
|
||||
import com.itsaky.toaster.Toaster.Type.ERROR
|
||||
import com.itsaky.toaster.init
|
||||
import com.itsaky.toaster.toast
|
||||
import java.io.File
|
||||
|
||||
abstract class BaseApplication : MultiDexApplication() {
|
||||
lateinit var prefManager: PreferenceManager
|
||||
private set
|
||||
|
||||
override fun onCreate() {
|
||||
baseInstance = this
|
||||
Environment.init()
|
||||
init()
|
||||
super.onCreate()
|
||||
prefManager = PreferenceManager(this)
|
||||
JavaCharacter.initMap()
|
||||
ToolsManager.init(this, null)
|
||||
DynamicColors.applyToActivitiesIfAvailable(this)
|
||||
createNotificationChannels()
|
||||
}
|
||||
|
||||
private fun createNotificationChannels() {
|
||||
val buildNotificationChannel =
|
||||
NotificationChannel(
|
||||
NOTIFICATION_GRADLE_BUILD_SERVICE,
|
||||
getString(string.title_gradle_service_notification_channel),
|
||||
NotificationManager.IMPORTANCE_LOW
|
||||
)
|
||||
NotificationManagerCompat.from(this).createNotificationChannel(buildNotificationChannel)
|
||||
}
|
||||
|
||||
@JvmOverloads
|
||||
fun newShell(callback: Callback?, redirectErrors: Boolean = true): ShellServer {
|
||||
val shellServer =
|
||||
ShellServer(
|
||||
callback,
|
||||
"sh",
|
||||
Environment.mkdirIfNotExits(rootDir).absolutePath,
|
||||
Environment.getEnvironment(),
|
||||
redirectErrors
|
||||
)
|
||||
shellServer.start()
|
||||
return shellServer
|
||||
}
|
||||
|
||||
val rootDir: File
|
||||
get() = File(iDEDataDir, "home")
|
||||
|
||||
@get:SuppressLint("SdCardPath")
|
||||
val iDEDataDir: File
|
||||
get() = Environment.mkdirIfNotExits(File("/data/data/com.itsaky.androidide/files"))
|
||||
|
||||
fun writeException(th: Throwable?) {
|
||||
FileUtil.writeFile(
|
||||
File(FileUtil.getExternalStorageDir(), "idelog.txt").absolutePath,
|
||||
ThrowableUtils.getFullStackTrace(th)
|
||||
)
|
||||
}
|
||||
|
||||
val tempProjectDir: File
|
||||
get() = Environment.mkdirIfNotExits(File(Environment.TMP_DIR, "tempProject"))
|
||||
|
||||
val projectsDir: File
|
||||
get() = Environment.PROJECTS_DIR
|
||||
|
||||
fun openTelegramGroup() {
|
||||
openTelegram(TELEGRAM_GROUP_URL)
|
||||
}
|
||||
|
||||
fun openTelegramChannel() {
|
||||
openTelegram(TELEGRAM_CHANNEL_URL)
|
||||
}
|
||||
|
||||
fun openGitHub() {
|
||||
openUrl(GITHUB_URL)
|
||||
}
|
||||
|
||||
fun openWebsite() {
|
||||
openUrl(WEBSITE)
|
||||
}
|
||||
|
||||
fun openSponsors() {
|
||||
openUrl(SPONSOR_URL)
|
||||
}
|
||||
|
||||
fun openDocs() {
|
||||
openUrl(DOCS_URL)
|
||||
}
|
||||
|
||||
fun emailUs() {
|
||||
openUrl("mailto:$EMAIL")
|
||||
}
|
||||
|
||||
private fun openTelegram(url: String?) {
|
||||
openUrl(url, "org.telegram.messenger")
|
||||
}
|
||||
|
||||
@JvmOverloads
|
||||
fun openUrl(url: String?, pkg: String? = null) {
|
||||
try {
|
||||
val open = Intent()
|
||||
open.action = Intent.ACTION_VIEW
|
||||
open.data = Uri.parse(url)
|
||||
open.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
if (pkg != null) {
|
||||
open.setPackage(pkg)
|
||||
}
|
||||
startActivity(open)
|
||||
} catch (th: Throwable) {
|
||||
if (pkg != null) {
|
||||
openUrl(url)
|
||||
} else {
|
||||
toast(th.message, ERROR)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val NOTIFICATION_GRADLE_BUILD_SERVICE = "17571"
|
||||
const val TELEGRAM_GROUP_URL = "https://t.me/androidide_discussions"
|
||||
const val TELEGRAM_CHANNEL_URL = "https://t.me/AndroidIDEOfficial"
|
||||
const val GITHUB_URL = "https://github.com/AndroidIDEOfficial/AndroidIDE"
|
||||
const val WEBSITE = "https://androidide.com"
|
||||
const val SPONSOR_URL = "https://androidide.com/donate.php"
|
||||
|
||||
// TODO Replace when available on website
|
||||
const val DOCS_URL = "https://github.com/AndroidIDEOfficial/AndroidIDE/tree/main/docs"
|
||||
const val EMAIL = "contact@androidide.com"
|
||||
|
||||
private lateinit var baseInstance: BaseApplication
|
||||
private set
|
||||
|
||||
@JvmStatic fun getBaseInstance() = baseInstance
|
||||
|
||||
@JvmStatic
|
||||
val isAbiSupported: Boolean
|
||||
get() = isAarch64 || isArmv7a
|
||||
|
||||
@JvmStatic
|
||||
val isAarch64: Boolean
|
||||
get() = Build.SUPPORTED_ABIS.contains("arm64-v8a")
|
||||
val isArmv7a: Boolean
|
||||
get() = Build.SUPPORTED_ABIS.contains("armeabi-v7a")
|
||||
|
||||
@JvmStatic
|
||||
val arch: String?
|
||||
get() {
|
||||
if (isAarch64) {
|
||||
return "arm64-v8a"
|
||||
} else if (isArmv7a) {
|
||||
return "armeabi-v7a"
|
||||
}
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,10 +29,10 @@ import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat
|
||||
import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat.create
|
||||
import com.blankj.utilcode.util.SizeUtils
|
||||
import com.blankj.utilcode.util.ThreadUtils
|
||||
import com.itsaky.androidide.app.BaseApplication.Companion.getBaseInstance
|
||||
import com.itsaky.androidide.common.databinding.LayoutToastBinding
|
||||
import com.itsaky.androidide.app.BaseApplication.getBaseInstance
|
||||
import com.itsaky.androidide.resources.R.color
|
||||
import com.itsaky.androidide.resources.R.drawable
|
||||
import com.itsaky.androidide.common.databinding.LayoutToastBinding
|
||||
import com.itsaky.toaster.Toaster.Gravity.BOTTOM_LEFT
|
||||
import com.itsaky.toaster.Toaster.Gravity.BOTTOM_RIGHT
|
||||
import com.itsaky.toaster.Toaster.Gravity.TOP_LEFT
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
package com.itsaky.toaster
|
||||
|
||||
import com.itsaky.androidide.app.BaseApplication.Companion.getBaseInstance
|
||||
import com.itsaky.androidide.app.BaseApplication.getBaseInstance
|
||||
import com.itsaky.toaster.Toaster.Type
|
||||
import com.itsaky.toaster.Toaster.Type.ERROR
|
||||
import com.itsaky.toaster.Toaster.Type.INFO
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user