Reformat all source file

This commit is contained in:
Akash Yadav
2022-06-26 09:37:57 +05:30
parent 5115acc0d3
commit 051e2e4b02
780 changed files with 105201 additions and 100889 deletions
+6 -8
View File
@@ -1,9 +1,6 @@
---
name: Bug
about: Report a bug in the IDE.
title: ""
labels: bug
assignees: ''
name: Bug about: Report a bug in the IDE. title: ""
labels: bug assignees: ''
---
**Describe the bug**
@@ -20,9 +17,10 @@ Steps to reproduce the behavior:
<!-- If applicable, add screenshots to help explain your problem. -->
**Details (please complete the following information):**
- Device: [e.g. realme 3 Pro]
- OS: [e.g. Android 11]
- AndroidIDE Version [e.g. v1.0.3-alpha]
- Device: [e.g. realme 3 Pro]
- OS: [e.g. Android 11]
- AndroidIDE Version [e.g. v1.0.3-alpha]
**Additional context**
<!-- Add any other context about the problem here. -->
+2 -5
View File
@@ -1,9 +1,6 @@
---
name: Feature request
about: Suggest an idea for this project
title: "[FEATURE]: "
labels: feature
assignees: ''
name: Feature request about: Suggest an idea for this project title: "[FEATURE]: "
labels: feature assignees: ''
---
+56 -70
View File
@@ -2,124 +2,110 @@
## Our Pledge
We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, religion, or sexual identity
and orientation.
We as members, contributors, and leaders pledge to make participation in our community a
harassment-free experience for everyone, regardless of age, body size, visible or invisible
disability, ethnicity, sex characteristics, gender identity and expression, level of experience,
education, socio-economic status, nationality, personal appearance, race, religion, or sexual
identity and orientation.
We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and
healthy community.
## Our Standards
Examples of behavior that contributes to a positive environment for our
community include:
Examples of behavior that contributes to a positive environment for our community include:
* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the
overall community
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the
experience
* Focusing on what is best not just for us as individuals, but for the overall community
Examples of unacceptable behavior include:
* The use of sexualized language or imagery, and sexual attention or
advances of any kind
* The use of sexualized language or imagery, and sexual attention or advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email
address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
* Publishing others' private information, such as a physical or email address, without their
explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting
## Enforcement Responsibilities
Community leaders are responsible for clarifying and enforcing our standards of
acceptable behavior and will take appropriate and fair corrective action in
response to any behavior that they deem inappropriate, threatening, offensive,
or harmful.
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior
and will take appropriate and fair corrective action in response to any behavior that they deem
inappropriate, threatening, offensive, or harmful.
Community leaders have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct, and will communicate reasons for moderation
decisions when appropriate.
Community leaders have the right and responsibility to remove, edit, or reject comments, commits,
code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and
will communicate reasons for moderation decisions when appropriate.
## Scope
This Code of Conduct applies within all community spaces, and also applies when
an individual is officially representing the community in public spaces.
Examples of representing our community include using an official e-mail address,
posting via an official social media account, or acting as an appointed
representative at an online or offline event.
This Code of Conduct applies within all community spaces, and also applies when an individual is
officially representing the community in public spaces. Examples of representing our community
include using an official e-mail address, posting via an official social media account, or acting as
an appointed representative at an online or offline event.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement either by opening
an issue or writing me an email at [itsaky01@gmail.com](mailto:itsaky01@gmail.com).
All complaints will be reviewed and investigated promptly and fairly.
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community
leaders responsible for enforcement either by opening an issue or writing me an email
at [itsaky01@gmail.com](mailto:itsaky01@gmail.com). All complaints will be reviewed and investigated
promptly and fairly.
All community leaders are obligated to respect the privacy and security of the
reporter of any incident.
All community leaders are obligated to respect the privacy and security of the reporter of any
incident.
## Enforcement Guidelines
Community leaders will follow these Community Impact Guidelines in determining
the consequences for any action they deem in violation of this Code of Conduct:
Community leaders will follow these Community Impact Guidelines in determining the consequences for
any action they deem in violation of this Code of Conduct:
### 1. Correction
**Community Impact**: Use of inappropriate language or other behavior deemed
unprofessional or unwelcome in the community.
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or
unwelcome in the community.
**Consequence**: A private, written warning from community leaders, providing
clarity around the nature of the violation and an explanation of why the
behavior was inappropriate. A public apology may be requested.
**Consequence**: A private, written warning from community leaders, providing clarity around the
nature of the violation and an explanation of why the behavior was inappropriate. A public apology
may be requested.
### 2. Warning
**Community Impact**: A violation through a single incident or series
of actions.
**Community Impact**: A violation through a single incident or series of actions.
**Consequence**: A warning with consequences for continued behavior. No
interaction with the people involved, including unsolicited interaction with
those enforcing the Code of Conduct, for a specified period of time. This
includes avoiding interactions in community spaces as well as external channels
like social media. Violating these terms may lead to a temporary or
permanent ban.
**Consequence**: A warning with consequences for continued behavior. No interaction with the people
involved, including unsolicited interaction with those enforcing the Code of Conduct, for a
specified period of time. This includes avoiding interactions in community spaces as well as
external channels like social media. Violating these terms may lead to a temporary or permanent ban.
### 3. Temporary Ban
**Community Impact**: A serious violation of community standards, including
sustained inappropriate behavior.
**Community Impact**: A serious violation of community standards, including sustained inappropriate
behavior.
**Consequence**: A temporary ban from any sort of interaction or public
communication with the community for a specified period of time. No public or
private interaction with the people involved, including unsolicited interaction
with those enforcing the Code of Conduct, is allowed during this period.
Violating these terms may lead to a permanent ban.
**Consequence**: A temporary ban from any sort of interaction or public communication with the
community for a specified period of time. No public or private interaction with the people involved,
including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this
period. Violating these terms may lead to a permanent ban.
### 4. Permanent Ban
**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.
**Community Impact**: Demonstrating a pattern of violation of community standards, including
sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement
of classes of individuals.
**Consequence**: A permanent ban from any sort of public interaction within
the community.
**Consequence**: A permanent ban from any sort of public interaction within the community.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.0, available at
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, available at
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
Community Impact Guidelines were inspired by [Mozilla's code of conduct
enforcement ladder](https://github.com/mozilla/diversity).
Community Impact Guidelines were inspired
by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
[homepage]: https://www.contributor-covenant.org
+22 -8
View File
@@ -1,8 +1,12 @@
# Contributing
This document outlines how to propose a change to AndrodIDE. By contributing to this project, you agree to abide the terms specified in [CODE OF CONDUCT](./CODE_OF_CONDUCT.md).
This document outlines how to propose a change to AndrodIDE. By contributing to this project, you
agree to abide the terms specified in [CODE OF CONDUCT](./CODE_OF_CONDUCT.md).
## Propose a change
To contribute to this project,
- Fork the repo.
- Clone the forked repo to your local machine.
- Open the project in Android Studio.
@@ -10,19 +14,29 @@ To contribute to this project,
- Create a pull request.
## Note
`Java 11` is required to build the project.
Building AndroidIDE in AndroidIDE itself is also possible. But that might require some modifications.
Building AndroidIDE in AndroidIDE itself is also possible. But that might require some
modifications.
If you face `AAPT2` issue while building AndroidIDE in the IDE itself, specify the `android.aapt2FromMavenOverride` property in `gradle.properties` with location of `aapt2` binary from Android SDK. However, this is an **experimental** property.
If you face `AAPT2` issue while building AndroidIDE in the IDE itself, specify
the `android.aapt2FromMavenOverride` property in `gradle.properties` with location of `aapt2` binary
from Android SDK. However, this is an **experimental** property.
## Source code format
The source code must have `2-space` indentation (soft tab).
Java source code is formatted using `google-java-format` with `GOOGLE` style formatting.
You can execute `./gradlew formatJavaSources` in terminal to format all Java source files using Google Java Format.
The source code must have `2-space` indentation (soft tab). Java source code is formatted
using `google-java-format` with `GOOGLE` style formatting. You can
execute `./gradlew formatJavaSources` in terminal to format all Java source files using Google Java
Format.
**This will commit the changes as well**.
## Issues & Pull requests
Use the issue/PR templates when possible. Provide a proper title and a clear description for the issue/PR. For bug reports, provide a step-by-step procedure to reproduce the issue. Always put crash logs, build outputs, etc in `code blocks`.
If you want to discuss anything about the project, you can discuss it in the [Telegram group](https://t.me/androidide_discussions).
Use the issue/PR templates when possible. Provide a proper title and a clear description for the
issue/PR. For bug reports, provide a step-by-step procedure to reproduce the issue. Always put crash
logs, build outputs, etc in `code blocks`.
If you want to discuss anything about the project, you can discuss it in
the [Telegram group](https://t.me/androidide_discussions).
+27 -9
View File
@@ -10,6 +10,7 @@
</p><br>
## Features
- [x] Gradle support.
- [x] `JDK 11` and `JDK 17` available for use.
- [x] Terminal with necessary packages.
@@ -32,34 +33,50 @@
- [x] Git (*)
Items marked with `(*)` are partially implemented.
`XML` language server supports only code completion at the moment. Git is currently available only in the terminal i.e. no GUI interface for `git`.
`XML` language server supports only code completion at the moment. Git is currently available only
in the terminal i.e. no GUI interface for `git`.
## Installation
- Download the AndroidIDE APK from [releases](https://github.com/itsaky/AndroidIDE/releases). You can also download APKs from [GitHub actions](https://github.com/itsaky/AndroidIDE/actions).
- Follow the instructions [here](https://github.com/itsaky/androidide-build-tools#installing-in-androidide) to install the build tools.
- Download the AndroidIDE APK from [releases](https://github.com/itsaky/AndroidIDE/releases). You
can also download APKs from [GitHub actions](https://github.com/itsaky/AndroidIDE/actions).
- Follow the
instructions [here](https://github.com/itsaky/androidide-build-tools#installing-in-androidide) to
install the build tools.
## Limitations
- SDK Manager is already included in Android SDK and is accessible in AndroidIDE via its Terminal. But, you cannot use it to install some tools (like NDK) because those tools are not built for Android.
- SDK Manager is already included in Android SDK and is accessible in AndroidIDE via its Terminal.
But, you cannot use it to install some tools (like NDK) because those tools are not built for
Android.
- No official NDK support because we haven't built the NDK for Android.
The app is still being developed actively. It's in beta stage and may not be stable. if you have any issues using the app, please let us know.
The app is still being developed actively. It's in beta stage and may not be stable. if you have any
issues using the app, please let us know.
## Contributing
See the [contributing guide](./CONTRIBUTING.md).
## Thanks to
- [Rosemoe](https://github.com/Rosemoe) for the awesome [CodeEditor](https://github.com/Rosemoe/sora-editor)
- [Rosemoe](https://github.com/Rosemoe) for the
awesome [CodeEditor](https://github.com/Rosemoe/sora-editor)
- [Termux](https://github.com/termux) for [Terminal Emulator](https://github.com/termux/termux-app)
- [Bogdan Melnychuk](https://github.com/bmelnychuk) for [AndroidTreeView](https://github.com/bmelnychuk/AndroidTreeView)
- [George Fraser](https://github.com/georgewfraser) for the [Java Language Server](https://github.com/georgewfraser/java-language-server)
- [Bogdan Melnychuk](https://github.com/bmelnychuk)
for [AndroidTreeView](https://github.com/bmelnychuk/AndroidTreeView)
- [George Fraser](https://github.com/georgewfraser) for
the [Java Language Server](https://github.com/georgewfraser/java-language-server)
And all the developers who have contributed to this project.
## Contact Us
- [Website](https://androidide.com)
- [Telegram](https://t.me/androidide_discussions)
## License
```
AndroidIDE is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -75,4 +92,5 @@ You should have received a copy of the GNU General Public License
along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
```
Any violations to the license can be reported either by opening an issue or writing a mail to us directly.
Any violations to the license can be reported either by opening an issue or writing a mail to us
directly.
+2 -2
View File
@@ -29,7 +29,7 @@ android {
}
dependencies {
implementation project(':common')
implementation project (':common')
implementation common.editor
implementation common.utilcode
@@ -38,5 +38,5 @@ dependencies {
}
repositories {
mavenCentral()
mavenCentral ()
}
@@ -153,10 +153,10 @@ class DefaultActionsRegistry : ActionsRegistry() {
if (result == null || (result is Boolean && !result) || error != null) {
log.error(
"An error occurred when performing action '${it.title}'. Action failed in ${System.currentTimeMillis() - start}ms",
error)
error
)
} else {
log.info(
"Action '${it.title}' completed in ${System.currentTimeMillis() - start}ms")
log.info("Action '${it.title}' completed in ${System.currentTimeMillis() - start}ms")
}
ThreadUtils.runOnUiThread {
@@ -1,8 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/colorPrimary" />
+2 -4
View File
@@ -1,8 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent">
@@ -19,7 +17,7 @@
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"
app:popupOverlay="@style/ThemeOverlay.MaterialComponents.Light"/>
app:popupOverlay="@style/ThemeOverlay.MaterialComponents.Light" />
</com.google.android.material.appbar.AppBarLayout>
+2 -5
View File
@@ -1,11 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/menu_item1"
android:name="Menu Item"/>
android:name="Menu Item" />
</menu>
@@ -38,12 +38,6 @@ public class AboutActivity extends StudioActivity {
public static final String JDK_SOURCE = "https://github.com/itsaky/OpenJDK-Android";
private ActivityAboutBinding binding;
@Override
protected View bindLayout() {
binding = ActivityAboutBinding.inflate(getLayoutInflater());
return binding.getRoot();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -64,6 +58,12 @@ public class AboutActivity extends StudioActivity {
items.website.setOnClickListener(v -> getApp().openWebsite());
}
@Override
protected View bindLayout() {
binding = ActivityAboutBinding.inflate(getLayoutInflater());
return binding.getRoot();
}
private void setupTranslations() {
final var translations = createTranslationsList();
final var sb = new StringBuilder();
@@ -26,16 +26,9 @@ import com.itsaky.androidide.fragments.CrashReportFragment;
public class CrashHandlerActivity extends StudioActivity {
private ActivityCrashHandlerBinding binding;
public static final String REPORT_ACTION = "com.itsaky.androidide.REPORT_CRASH";
public static final String TRACE_KEY = "crash_trace";
@Override
protected View bindLayout() {
binding = ActivityCrashHandlerBinding.inflate(getLayoutInflater());
return binding.getRoot();
}
private ActivityCrashHandlerBinding binding;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -57,6 +50,12 @@ public class CrashHandlerActivity extends StudioActivity {
.commit();
}
@Override
protected View bindLayout() {
binding = ActivityCrashHandlerBinding.inflate(getLayoutInflater());
return binding.getRoot();
}
@Override
protected void onDestroy() {
super.onDestroy();
@@ -189,6 +189,12 @@ public class DesignerActivity extends StudioActivity
.show();
}
private void finishWithError() {
final var intent = new Intent();
setResult(-123, intent);
finish();
}
private void finishWithResult(String result) {
final var intent = new Intent();
intent.putExtra(KEY_GENERATED_CODE, result);
@@ -196,12 +202,6 @@ public class DesignerActivity extends StudioActivity
finish();
}
private void finishWithError() {
final var intent = new Intent();
setResult(-123, intent);
finish();
}
@Override
public void onDragStarted(View view) {
mBinding.getRoot().closeDrawer(GravityCompat.START);
@@ -429,12 +429,6 @@ public class EditorActivity extends StudioActivity
return openFile(file, null);
}
public void hideViewOptions() {
if (mEditorBottomSheet.getState() != BottomSheetBehavior.STATE_COLLAPSED) {
mEditorBottomSheet.setState(BottomSheetBehavior.STATE_COLLAPSED);
}
}
public CodeEditorView openFile(File file, com.itsaky.lsp.models.Range selection) {
if (selection == null) {
selection = com.itsaky.lsp.models.Range.NONE;
@@ -536,6 +530,12 @@ public class EditorActivity extends StudioActivity
return mFileOptionsFragment;
}
public void hideViewOptions() {
if (mEditorBottomSheet.getState() != BottomSheetBehavior.STATE_COLLAPSED) {
mEditorBottomSheet.setState(BottomSheetBehavior.STATE_COLLAPSED);
}
}
public ActivityEditorBinding getBinding() {
return mBinding;
}
@@ -790,17 +790,6 @@ public class EditorActivity extends StudioActivity
return saveAll(notify, false);
}
@NonNull
private CompletableFuture<ArrayList<String>> getResourceDirPaths() {
return getResourceDirs()
.thenApply(
files ->
files.stream()
.filter(Objects::nonNull)
.map(File::getAbsolutePath)
.collect(Collectors.toCollection(ArrayList::new)));
}
public boolean saveAll(boolean notify, boolean canProcessResources) {
SaveResult result = saveAllResult();
@@ -819,10 +808,6 @@ public class EditorActivity extends StudioActivity
return result.gradleSaved;
}
private CompletableFuture<List<File>> getResourceDirs() {
return ProjectManager.INSTANCE.getApplicationResDirectories();
}
public SaveResult saveAllResult() {
SaveResult result = new SaveResult();
for (int i = 0; i < mViewModel.getOpenedFileCount(); i++) {
@@ -832,15 +817,6 @@ public class EditorActivity extends StudioActivity
return result;
}
public void notifySyncNeeded() {
if (mBuildService != null && !mBuildService.isBuildInProgress()) {
getSyncBanner()
.setNegative(android.R.string.cancel, null)
.setPositive(android.R.string.ok, v -> initializeProject())
.show();
}
}
public void saveResult(int index, SaveResult result) {
if (index >= 0 && index < mViewModel.getOpenedFileCount()) {
var frag = getEditorAtIndex(index);
@@ -879,6 +855,15 @@ public class EditorActivity extends StudioActivity
ThreadUtils.runOnUiThread(() -> mViewModel.setFilesModified(finalModified));
}
public void notifySyncNeeded() {
if (mBuildService != null && !mBuildService.isBuildInProgress()) {
getSyncBanner()
.setNegative(android.R.string.cancel, null)
.setPositive(android.R.string.ok, v -> initializeProject())
.show();
}
}
public MaterialBanner getSyncBanner() {
return mBinding
.syncBanner
@@ -925,6 +910,18 @@ public class EditorActivity extends StudioActivity
setStatus(text, Gravity.CENTER);
}
public void setStatus(final CharSequence text, @GravityInt int gravity) {
try {
runOnUiThread(
() -> {
mBinding.bottomSheet.statusText.setGravity(gravity);
mBinding.bottomSheet.statusText.setText(text);
});
} catch (Throwable th) {
LOG.error("Failed to update status text", th);
}
}
protected void onProjectInitialized() {
ProjectManager.INSTANCE.notifyProjectUpdate();
ThreadUtils.runOnUiThread(
@@ -941,16 +938,47 @@ public class EditorActivity extends StudioActivity
});
}
public void setStatus(final CharSequence text, @GravityInt int gravity) {
private void initialSetup() {
getApp()
.getPrefManager()
.setOpenedProject(Objects.requireNonNull(ProjectManager.INSTANCE.getProjectDirPath()));
try {
runOnUiThread(
() -> {
mBinding.bottomSheet.statusText.setGravity(gravity);
mBinding.bottomSheet.statusText.setText(text);
});
} catch (Throwable th) {
LOG.error("Failed to update status text", th);
//noinspection ConstantConditions
final var rootProject = ProjectManager.INSTANCE.getRootProject();
var projectName = rootProject.getName().get();
if (projectName.isEmpty()) {
projectName = new File(ProjectManager.INSTANCE.getProjectDirPath()).getName();
getSupportActionBar().setSubtitle(projectName);
} else {
getSupportActionBar().setSubtitle(projectName);
}
} catch (Throwable th) {
// ignored
}
getResourceDirs()
.thenAccept(
dirs -> {
dirs.removeIf(Objects::isNull);
ValuesTableFactory.setupWithResDirectories(dirs.toArray(new File[0]));
});
}
private CompletableFuture<List<File>> getResourceDirs() {
return ProjectManager.INSTANCE.getApplicationResDirectories();
}
@NonNull
private CompletableFuture<ArrayList<String>> getResourceDirPaths() {
return getResourceDirs()
.thenApply(
files ->
files.stream()
.filter(Objects::nonNull)
.map(File::getAbsolutePath)
.collect(Collectors.toCollection(ArrayList::new)));
}
public void assembleDebug(boolean installApk) {
@@ -977,6 +1005,14 @@ public class EditorActivity extends StudioActivity
}));
}
public void appendBuildOut(final String str) {
final var frag = bottomSheetTabAdapter.getBuildOutputFragment();
if (frag != null) {
frag.appendOutput(str);
}
}
public Consumer<TaskExecutionResult> installableTaskResultConsumer(@NonNull String variantName) {
return result -> {
if (result != null && result.isSuccessful()) {
@@ -1026,14 +1062,6 @@ public class EditorActivity extends StudioActivity
};
}
public void appendBuildOut(final String str) {
final var frag = bottomSheetTabAdapter.getBuildOutputFragment();
if (frag != null) {
frag.appendOutput(str);
}
}
public void install(@NonNull File apk) {
runOnUiThread(
() -> {
@@ -1079,14 +1107,14 @@ public class EditorActivity extends StudioActivity
execTasks(null, "lintRelease");
}
public void cleanAndRebuild() {
execTasks(null, "clean", "build");
}
/////////////////////////////////////////////////
////////////// PRIVATE APIS /////////////////////
/////////////////////////////////////////////////
public void cleanAndRebuild() {
execTasks(null, "clean", "build");
}
public AlertDialog getFindInProjectDialog() {
return mFindInProjectDialog == null ? createFindInProjectDialog() : mFindInProjectDialog;
}
@@ -1232,18 +1260,6 @@ public class EditorActivity extends StudioActivity
}
}
private void dispatchOnResumeToEditors() {
CompletableFuture.runAsync(
() -> {
for (int i = 0; i < mViewModel.getOpenedFileCount(); i++) {
final var editor = getEditorAtIndex(i);
if (editor != null) {
editor.onResume();
}
}
});
}
private void showCompilerModuleInstallError(Throwable error) {
final var stacktrace = ThrowableUtils.getFullStackTrace(error);
final var builder = DialogUtils.newMaterialDialogBuilder(this);
@@ -1260,6 +1276,18 @@ public class EditorActivity extends StudioActivity
builder.show();
}
private void dispatchOnResumeToEditors() {
CompletableFuture.runAsync(
() -> {
for (int i = 0; i < mViewModel.getOpenedFileCount(); i++) {
final var editor = getEditorAtIndex(i);
if (editor != null) {
editor.onResume();
}
}
});
}
private void dispatchOnPauseToEditors() {
CompletableFuture.runAsync(
() -> {
@@ -1544,34 +1572,6 @@ public class EditorActivity extends StudioActivity
startActivity(intent);
}
private void initialSetup() {
getApp()
.getPrefManager()
.setOpenedProject(Objects.requireNonNull(ProjectManager.INSTANCE.getProjectDirPath()));
try {
//noinspection ConstantConditions
final var rootProject = ProjectManager.INSTANCE.getRootProject();
var projectName = rootProject.getName().get();
if (projectName.isEmpty()) {
projectName = new File(ProjectManager.INSTANCE.getProjectDirPath()).getName();
getSupportActionBar().setSubtitle(projectName);
} else {
getSupportActionBar().setSubtitle(projectName);
}
} catch (Throwable th) {
// ignored
}
getResourceDirs()
.thenAccept(
dirs -> {
dirs.removeIf(Objects::isNull);
ValuesTableFactory.setupWithResDirectories(dirs.toArray(new File[0]));
});
}
private void setupDiagnosticInfo() {
GradientDrawable gd = new GradientDrawable();
gd.setShape(GradientDrawable.RECTANGLE);
@@ -27,7 +27,6 @@ import android.view.View;
import androidx.annotation.NonNull;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.itsaky.androidide.app.StudioActivity;
import com.itsaky.androidide.databinding.ActivityMainBinding;
import com.itsaky.androidide.fragments.MainFragment;
@@ -42,19 +41,12 @@ import java.io.File;
public class MainActivity extends StudioActivity {
private ActivityMainBinding binding;
public void openProject(@NonNull File root) {
ProjectManager.INSTANCE.setProjectPath(root.getAbsolutePath());
startActivity(new Intent(this, EditorActivity.class));
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
openLastProject();
}
private void showMoveRequired() {}
private void openLastProject() {
binding
.getRoot()
@@ -90,12 +82,6 @@ public class MainActivity extends StudioActivity {
.commit();
}
@Override
protected View bindLayout() {
binding = ActivityMainBinding.inflate(getLayoutInflater());
return binding.getRoot();
}
private void askProjectOpenPermission(File root) {
final MaterialAlertDialogBuilder builder = DialogUtils.newMaterialDialogBuilder(this);
builder.setTitle(R.string.title_confirm_open_project);
@@ -106,6 +92,11 @@ public class MainActivity extends StudioActivity {
builder.show();
}
public void openProject(@NonNull File root) {
ProjectManager.INSTANCE.setProjectPath(root.getAbsolutePath());
startActivity(new Intent(this, EditorActivity.class));
}
@Override
protected void onStorageGranted() {}
@@ -115,9 +106,17 @@ public class MainActivity extends StudioActivity {
finishAffinity();
}
@Override
protected View bindLayout() {
binding = ActivityMainBinding.inflate(getLayoutInflater());
return binding.getRoot();
}
@Override
protected void onDestroy() {
super.onDestroy();
binding = null;
}
private void showMoveRequired() {}
}
@@ -34,12 +34,6 @@ public class PreferencesActivity extends StudioActivity {
private ActivityPreferencesBinding binding;
private IDEPreferences mPref;
@Override
protected View bindLayout() {
binding = ActivityPreferencesBinding.inflate(getLayoutInflater());
return binding.getRoot();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -53,6 +47,12 @@ public class PreferencesActivity extends StudioActivity {
loadFragment(getPrefsFragment());
}
@Override
protected View bindLayout() {
binding = ActivityPreferencesBinding.inflate(getLayoutInflater());
return binding.getRoot();
}
private IDEPreferences getPrefsFragment() {
return mPref == null ? mPref = new IDEPreferences() : mPref;
}
@@ -49,14 +49,14 @@ public class SplashActivity extends StudioActivity {
}
@Override
protected void onStorageAlreadyGranted() {
super.onStorageAlreadyGranted();
protected void onStorageGranted() {
super.onStorageGranted();
proceed();
}
@Override
protected void onStorageGranted() {
super.onStorageGranted();
protected void onStorageAlreadyGranted() {
super.onStorageAlreadyGranted();
proceed();
}
@@ -70,21 +70,196 @@ public class TerminalActivity extends StudioActivity
private static final ILogger LOG = ILogger.newInstance("TerminalActivity");
private static final byte[] SOURCES_LIST_CONTENT =
"deb https://androidide.com/packages/apt/termux-main/ stable main".getBytes();
private static final String KEY_FONT_SIZE = "terminal_fontSize";
private ActivityTerminalBinding binding;
private TerminalView terminal;
private TerminalSession session;
private boolean isVisible = false;
private KeyListener listener;
private int MIN_FONT_SIZE;
private int MAX_FONT_SIZE;
private int DEFAULT_FONT_SIZE;
private static final String KEY_FONT_SIZE = "terminal_fontSize";
public boolean isVisible() {
return isVisible;
}
@Override
protected View bindLayout() {
binding = ActivityTerminalBinding.inflate(getLayoutInflater());
return binding.getRoot();
public boolean onKeyUp(int keyCode, KeyEvent e) {
return false;
}
@Override
public void onTextChanged(TerminalSession changedSession) {
terminal.onScreenUpdated();
}
@Override
public void onTitleChanged(TerminalSession changedSession) {}
@Override
public void onSessionFinished(TerminalSession finishedSession) {
finish();
}
@Override
public void onCopyTextToClipboard(TerminalSession session, String text) {
ClipboardUtils.copyText("AndroidIDE Terminal", text);
}
@Override
public void onPasteTextFromClipboard(TerminalSession session) {
String clip = ClipboardUtils.getText().toString();
if (clip.trim().length() > 0 && terminal != null && terminal.mEmulator != null) {
terminal.mEmulator.paste(clip);
}
}
@Override
public void onBell(TerminalSession session) {}
@Override
public void onColorsChanged(TerminalSession session) {}
@Override
public void onTerminalCursorStateChange(boolean state) {}
@Override
public Integer getTerminalCursorStyle() {
return TerminalEmulator.DEFAULT_TERMINAL_CURSOR_STYLE;
}
@Override
public float onScale(float scale) {
if (scale < 0.9f || scale > 1.1f) {
boolean increase = scale > 1.f;
changeFontSize(increase);
return 1.0f;
}
return scale;
}
private void changeFontSize(final boolean increase) {
int fontSize = getFontSize();
fontSize += (increase ? 1 : -1) * 2;
fontSize = Math.max(MIN_FONT_SIZE, Math.min(fontSize, MAX_FONT_SIZE));
setFontSize(fontSize, true);
}
@Override
public void onSingleTapUp(MotionEvent e) {
KeyboardUtils.showSoftInput(terminal);
}
@Override
public boolean shouldBackButtonBeMappedToEscape() {
return false;
}
@Override
public boolean shouldEnforceCharBasedInput() {
return true;
}
@Override
public boolean shouldUseCtrlSpaceWorkaround() {
return false;
}
@Override
public boolean isTerminalViewSelected() {
return true;
}
@Override
public void copyModeChanged(boolean copyMode) {}
@Override
public boolean onKeyDown(int keyCode, KeyEvent e, TerminalSession session) {
if (keyCode == KeyEvent.KEYCODE_ENTER && !session.isRunning()) {
finish();
return true;
}
return false;
}
@Override
public boolean onLongPress(MotionEvent event) {
return false;
}
@Override
public boolean readControlKey() {
Boolean state = binding.virtualKeyTable.readSpecialButton(SpecialButton.CTRL, true);
return state != null && state;
}
@Override
public boolean readAltKey() {
Boolean state = binding.virtualKeyTable.readSpecialButton(SpecialButton.ALT, true);
return state != null && state;
}
@Override
public boolean readShiftKey() {
return false;
}
@Override
public boolean readFnKey() {
return false;
}
@Override
public boolean onCodePoint(int codePoint, boolean ctrlDown, TerminalSession session) {
return false;
}
@Override
public void onEmulatorSet() {
setTerminalCursorBlinkingState(true);
if (session != null) {
binding
.getRoot()
.setBackgroundColor(
session.getEmulator().mColors.mCurrentColors[TextStyle.COLOR_INDEX_BACKGROUND]);
}
}
@Override
public void logError(String tag, String message) {
LOG.error(tag + ":", message);
}
@Override
public void logWarn(String tag, String message) {
LOG.warn(tag + ":", message);
}
@Override
public void logInfo(String tag, String message) {
LOG.info(tag + ":", message);
}
@Override
public void logDebug(String tag, String message) {
LOG.debug(tag + ":", message);
}
@Override
public void logVerbose(String tag, String message) {
LOG.verbose(tag + ":", message);
}
@Override
public void logStackTraceWithMessage(String tag, String message, Exception e) {
LOG.error(tag + ":", message, e);
}
@Override
public void logStackTrace(String tag, Exception e) {
LOG.error(tag + ":", e);
}
@Override
@@ -140,6 +315,12 @@ public class TerminalActivity extends StudioActivity
}
}
@Override
protected View bindLayout() {
binding = ActivityTerminalBinding.inflate(getLayoutInflater());
return binding.getRoot();
}
private void showInstallationError(Throwable throwable) {
binding.virtualKeyTable.setVisibility(View.GONE);
@@ -198,41 +379,6 @@ public class TerminalActivity extends StudioActivity
return listener == null ? listener = new KeyListener(terminal) : listener;
}
@Override
protected void onResume() {
super.onResume();
setTerminalCursorBlinkingState(true);
}
@Override
protected void onStart() {
super.onStart();
isVisible = true;
}
@Override
protected void onStop() {
super.onStop();
isVisible = false;
setTerminalCursorBlinkingState(false);
}
@Override
protected void onDestroy() {
super.onDestroy();
binding = null;
}
public boolean isVisible() {
return isVisible;
}
private void setTerminalCursorBlinkingState(boolean start) {
if (terminal != null && terminal.mEmulator != null) {
terminal.setTerminalCursorBlinkerState(start, true);
}
}
private TerminalSession createSession(final String workingDirectory) {
final Map<String, String> environment = getEnvironment();
final String[] env = new String[environment.size()];
@@ -322,6 +468,60 @@ public class TerminalActivity extends StudioActivity
return sizes;
}
public void setFontSize(int value, boolean apply) {
getApp().getPrefManager().putString(KEY_FONT_SIZE, String.valueOf(value));
if (apply) {
terminal.setTextSize(getFontSize());
}
}
public int getFontSize() {
int fontSize;
try {
fontSize =
Integer.parseInt(
getApp()
.getPrefManager()
.getString(KEY_FONT_SIZE, String.valueOf(DEFAULT_FONT_SIZE)));
} catch (NumberFormatException | ClassCastException e) {
fontSize = DEFAULT_FONT_SIZE;
}
return Math.min(Math.max(fontSize, MIN_FONT_SIZE), MAX_FONT_SIZE);
}
@Override
protected void onResume() {
super.onResume();
setTerminalCursorBlinkingState(true);
}
private void setTerminalCursorBlinkingState(boolean start) {
if (terminal != null && terminal.mEmulator != null) {
terminal.setTerminalCursorBlinkerState(start, true);
}
}
@Override
protected void onStart() {
super.onStart();
isVisible = true;
}
@Override
protected void onStop() {
super.onStop();
isVisible = false;
setTerminalCursorBlinkingState(false);
}
@Override
protected void onDestroy() {
super.onDestroy();
binding = null;
}
private static final class KeyListener implements VirtualKeysView.IVirtualKeysView {
private final TerminalView terminal;
@@ -404,205 +604,4 @@ public class TerminalActivity extends StudioActivity
return false;
}
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent e) {
return false;
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent e, TerminalSession session) {
if (keyCode == KeyEvent.KEYCODE_ENTER && !session.isRunning()) {
finish();
return true;
}
return false;
}
@Override
public boolean onCodePoint(int codePoint, boolean ctrlDown, TerminalSession session) {
return false;
}
@Override
public void onTextChanged(TerminalSession changedSession) {
terminal.onScreenUpdated();
}
@Override
public void onTitleChanged(TerminalSession changedSession) {}
@Override
public void onSessionFinished(TerminalSession finishedSession) {
finish();
}
@Override
public void onCopyTextToClipboard(TerminalSession session, String text) {
ClipboardUtils.copyText("AndroidIDE Terminal", text);
}
@Override
public void onPasteTextFromClipboard(TerminalSession session) {
String clip = ClipboardUtils.getText().toString();
if (clip.trim().length() > 0 && terminal != null && terminal.mEmulator != null) {
terminal.mEmulator.paste(clip);
}
}
@Override
public void onBell(TerminalSession session) {}
@Override
public void onColorsChanged(TerminalSession session) {}
@Override
public void onTerminalCursorStateChange(boolean state) {}
@Override
public Integer getTerminalCursorStyle() {
return TerminalEmulator.DEFAULT_TERMINAL_CURSOR_STYLE;
}
@Override
public float onScale(float scale) {
if (scale < 0.9f || scale > 1.1f) {
boolean increase = scale > 1.f;
changeFontSize(increase);
return 1.0f;
}
return scale;
}
private void changeFontSize(final boolean increase) {
int fontSize = getFontSize();
fontSize += (increase ? 1 : -1) * 2;
fontSize = Math.max(MIN_FONT_SIZE, Math.min(fontSize, MAX_FONT_SIZE));
setFontSize(fontSize, true);
}
public int getFontSize() {
int fontSize;
try {
fontSize =
Integer.parseInt(
getApp()
.getPrefManager()
.getString(KEY_FONT_SIZE, String.valueOf(DEFAULT_FONT_SIZE)));
} catch (NumberFormatException | ClassCastException e) {
fontSize = DEFAULT_FONT_SIZE;
}
return Math.min(Math.max(fontSize, MIN_FONT_SIZE), MAX_FONT_SIZE);
}
public void setFontSize(int value, boolean apply) {
getApp().getPrefManager().putString(KEY_FONT_SIZE, String.valueOf(value));
if (apply) {
terminal.setTextSize(getFontSize());
}
}
@Override
public void onSingleTapUp(MotionEvent e) {
KeyboardUtils.showSoftInput(terminal);
}
@Override
public boolean shouldBackButtonBeMappedToEscape() {
return false;
}
@Override
public boolean shouldEnforceCharBasedInput() {
return true;
}
@Override
public boolean shouldUseCtrlSpaceWorkaround() {
return false;
}
@Override
public boolean isTerminalViewSelected() {
return true;
}
@Override
public void copyModeChanged(boolean copyMode) {}
@Override
public boolean onLongPress(MotionEvent event) {
return false;
}
@Override
public boolean readControlKey() {
Boolean state = binding.virtualKeyTable.readSpecialButton(SpecialButton.CTRL, true);
return state != null && state;
}
@Override
public boolean readAltKey() {
Boolean state = binding.virtualKeyTable.readSpecialButton(SpecialButton.ALT, true);
return state != null && state;
}
@Override
public boolean readFnKey() {
return false;
}
@Override
public boolean readShiftKey() {
return false;
}
@Override
public void onEmulatorSet() {
setTerminalCursorBlinkingState(true);
if (session != null) {
binding
.getRoot()
.setBackgroundColor(
session.getEmulator().mColors.mCurrentColors[TextStyle.COLOR_INDEX_BACKGROUND]);
}
}
@Override
public void logError(String tag, String message) {
LOG.error(tag + ":", message);
}
@Override
public void logWarn(String tag, String message) {
LOG.warn(tag + ":", message);
}
@Override
public void logInfo(String tag, String message) {
LOG.info(tag + ":", message);
}
@Override
public void logDebug(String tag, String message) {
LOG.debug(tag + ":", message);
}
@Override
public void logVerbose(String tag, String message) {
LOG.verbose(tag + ":", message);
}
@Override
public void logStackTraceWithMessage(String tag, String message, Exception e) {
LOG.error(tag + ":", message, e);
}
@Override
public void logStackTrace(String tag, Exception e) {
LOG.error(tag + ":", e);
}
}
@@ -29,8 +29,7 @@ abstract class BaseEditorAction : ActionItem {
override var visible: Boolean = true
override var enabled: Boolean = true
override var icon: Drawable? = null
override var requiresUIThread: Boolean =
true // all editor actions must be executed on UI thread
override var requiresUIThread: Boolean = true // all editor actions must be executed on UI thread
override var location: ActionItem.Location = ActionItem.Location.EDITOR_TEXT_ACTIONS
override fun prepare(data: ActionData) {
@@ -56,7 +55,8 @@ abstract class BaseEditorAction : ActionItem {
fun tintDrawable(context: Context, drawable: Drawable): Drawable {
drawable.setTint(
ContextCompat.getColor(context, com.itsaky.androidide.R.color.primaryIconColor))
ContextCompat.getColor(context, com.itsaky.androidide.R.color.primaryIconColor)
)
return drawable
}
}
@@ -55,7 +55,8 @@ class CancelBuildAction() : EditorActivityAction() {
log.warn(
"Unable to enqueue cancellation request",
result.failureReason,
result.failureReason!!.message)
result.failureReason!!.message
)
return@whenComplete
}
@@ -23,7 +23,6 @@ import com.itsaky.androidide.R
import com.itsaky.androidide.R.string
import com.itsaky.androidide.actions.ActionData
import com.itsaky.androidide.actions.BaseBuildAction
import com.itsaky.androidide.actions.EditorActivityAction
/**
* Triggers a project sync request.
@@ -18,7 +18,6 @@
package com.itsaky.androidide.actions.editor
import android.content.Context
import com.itsaky.androidide.R
import com.itsaky.androidide.actions.ActionData
import com.itsaky.androidide.actions.BaseEditorAction
@@ -18,7 +18,6 @@
package com.itsaky.androidide.actions.editor
import android.content.Context
import com.itsaky.androidide.R
import com.itsaky.androidide.actions.ActionData
import com.itsaky.androidide.actions.BaseEditorAction
@@ -18,7 +18,6 @@
package com.itsaky.androidide.actions.editor
import android.content.Context
import com.itsaky.androidide.R
import com.itsaky.androidide.actions.ActionData
import com.itsaky.androidide.actions.BaseEditorAction
@@ -49,8 +49,7 @@ class PreviewLayoutAction() : EditorRelatedAction() {
visible =
isXml &&
file.parentFile != null &&
Regex(FileOptionsHandler.LAYOUT_RES_PATH_REGEX)
.matches(file.parentFile!!.absolutePath)
Regex(FileOptionsHandler.LAYOUT_RES_PATH_REGEX).matches(file.parentFile!!.absolutePath)
enabled = visible
}
@@ -46,6 +46,20 @@ public class AttrListAdapter extends IconTextAdapter<Attr> {
this.attrs = attrs;
}
@Override
public int getItemCount() {
return attrs.size();
}
@Override
public void onBindViewHolder(@NonNull VH holder, int position) {
super.onBindViewHolder(holder, position);
if (clickConsumer != null) {
holder.binding.getRoot().setOnClickListener(v -> clickConsumer.accept(getItemAt(position)));
}
}
@NonNull
@Override
public Attr getItemAt(int index) {
@@ -62,18 +76,4 @@ public class AttrListAdapter extends IconTextAdapter<Attr> {
public String getItemText(int index) {
return getItemAt(index).name;
}
@Override
public int getItemCount() {
return attrs.size();
}
@Override
public void onBindViewHolder(@NonNull VH holder, int position) {
super.onBindViewHolder(holder, position);
if (clickConsumer != null) {
holder.binding.getRoot().setOnClickListener(v -> clickConsumer.accept(getItemAt(position)));
}
}
}
@@ -70,6 +70,29 @@ public class EditorBottomSheetTabAdapter extends FragmentStateAdapter {
return getFragmentById(getItemId(index));
}
@Nullable
public Fragment getFragmentById(long itemId) {
final var fragments = getFragments();
if (fragments != null) {
return fragments.get(itemId);
}
return null;
}
@Nullable
private LongSparseArray<Fragment> getFragments() {
try {
final var field = FragmentStateAdapter.class.getDeclaredField("mFragments");
field.setAccessible(true);
return (LongSparseArray<Fragment>) field.get(this);
} catch (Throwable th) {
LOG.error("Unable to reflect fragment list from adapter.");
}
return null;
}
@NonNull
@Override
public Fragment createFragment(int position) {
@@ -98,21 +121,6 @@ public class EditorBottomSheetTabAdapter extends FragmentStateAdapter {
return findFragmentByClass(SimpleOutputFragment.class);
}
@Nullable
public AppLogFragment getLogFragment() {
return findFragmentByClass(AppLogFragment.class);
}
@Nullable
public DiagnosticsListFragment getDiagnosticsFragment() {
return findFragmentByClass(DiagnosticsListFragment.class);
}
@Nullable
public SearchResultFragment getSearchResultFragment() {
return findFragmentByClass(SearchResultFragment.class);
}
@Nullable
private <T extends Fragment> T findFragmentByClass(Class<T> clazz) {
final var name = clazz.getName();
@@ -126,26 +134,18 @@ public class EditorBottomSheetTabAdapter extends FragmentStateAdapter {
}
@Nullable
public Fragment getFragmentById(long itemId) {
final var fragments = getFragments();
if (fragments != null) {
return fragments.get(itemId);
}
return null;
public AppLogFragment getLogFragment() {
return findFragmentByClass(AppLogFragment.class);
}
@Nullable
private LongSparseArray<Fragment> getFragments() {
try {
final var field = FragmentStateAdapter.class.getDeclaredField("mFragments");
field.setAccessible(true);
return (LongSparseArray<Fragment>) field.get(this);
} catch (Throwable th) {
LOG.error("Unable to reflect fragment list from adapter.");
public DiagnosticsListFragment getDiagnosticsFragment() {
return findFragmentByClass(DiagnosticsListFragment.class);
}
return null;
@Nullable
public SearchResultFragment getSearchResultFragment() {
return findFragmentByClass(SearchResultFragment.class);
}
public <T extends Fragment> int findIndexOfFragmentByClass(@NonNull Class<T> tClass) {
@@ -98,14 +98,6 @@ public abstract class IconTextAdapter<E> extends RecyclerView.Adapter<IconTextAd
@NonNull
public abstract String getItemText(int index);
public interface OnBindListener<T> {
default boolean onBind(T item, VH holder, int position) {
return false;
}
default void postBind(T item, VH holder, int position) {}
}
public static class VH extends RecyclerView.ViewHolder {
public final LayoutSimpleIconTextBinding binding;
@@ -115,4 +107,12 @@ public abstract class IconTextAdapter<E> extends RecyclerView.Adapter<IconTextAd
this.binding = binding;
}
}
public interface OnBindListener<T> {
default boolean onBind(T item, VH holder, int position) {
return false;
}
default void postBind(T item, VH holder, int position) {}
}
}
@@ -116,7 +116,11 @@ class LogLinesAdapter : RecyclerView.Adapter<VH>() {
else -> -0xa0a0b
}
spannable.setSpan(
ForegroundColorSpan(color), 0, spannable.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
ForegroundColorSpan(color),
0,
spannable.length,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
)
return LogWrapper(line, spannable).apply { visible = true }
}
@@ -36,7 +36,10 @@ public class SimpleIconTextAdapter extends IconTextAdapter<IconTextListItem> {
this.items = items;
}
@NonNull
@Override
public int getItemCount() {
return items.size();
} @NonNull
@Override
public IconTextListItem getItemAt(int index) {
return items.get(index);
@@ -53,8 +56,5 @@ public class SimpleIconTextAdapter extends IconTextAdapter<IconTextListItem> {
return getItemAt(index).getText();
}
@Override
public int getItemCount() {
return items.size();
}
}
@@ -33,6 +33,18 @@ import java.util.List;
public class SymbolInputAdapter extends RecyclerView.Adapter<SymbolInputAdapter.VH> {
private static final List<Character> pairs;
static {
pairs = new ArrayList<>();
pairs.add('}');
pairs.add(')');
pairs.add(']');
pairs.add('"');
pairs.add('\'');
pairs.add('>');
}
private final IDEEditor editor;
private Symbol[] symbols;
@@ -73,15 +85,6 @@ public class SymbolInputAdapter extends RecyclerView.Adapter<SymbolInputAdapter.
return symbols == null ? 0 : symbols.length;
}
public static class VH extends RecyclerView.ViewHolder {
LayoutSymbolItemBinding binding;
public VH(LayoutSymbolItemBinding binding) {
super(binding.getRoot());
this.binding = binding;
}
}
void insertSymbol(String text, int selectionOffset) {
if (selectionOffset < 0 || selectionOffset > text.length()) {
return;
@@ -108,15 +111,12 @@ public class SymbolInputAdapter extends RecyclerView.Adapter<SymbolInputAdapter.
}
}
private static final List<Character> pairs;
public static class VH extends RecyclerView.ViewHolder {
LayoutSymbolItemBinding binding;
static {
pairs = new ArrayList<>();
pairs.add('}');
pairs.add(')');
pairs.add(']');
pairs.add('"');
pairs.add('\'');
pairs.add('>');
public VH(LayoutSymbolItemBinding binding) {
super(binding.getRoot());
this.binding = binding;
}
}
}
@@ -1,8 +1,6 @@
package com.itsaky.androidide.adapters;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
@@ -13,23 +11,17 @@ import androidx.recyclerview.widget.RecyclerView;
import com.blankj.utilcode.util.ConvertUtils;
import com.google.android.material.imageview.ShapeableImageView;
import com.google.android.material.shape.CornerFamily;
import com.itsaky.androidide.databinding.WizardTemplateItemBinding;
import com.itsaky.androidide.models.ProjectTemplate;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class WizardTemplateAdapter extends RecyclerView.Adapter<WizardTemplateAdapter.ViewHolder> {
public interface OnItemClickListener {
void onItemClick(ProjectTemplate item, int position);
}
private final List<ProjectTemplate> mItems = new ArrayList<>();
private OnItemClickListener mListener;
public WizardTemplateAdapter() {}
public void setOnItemClickListener(OnItemClickListener listener) {
@@ -117,4 +109,8 @@ public class WizardTemplateAdapter extends RecyclerView.Adapter<WizardTemplateAd
.build());
}
}
public interface OnItemClickListener {
void onItemClick(ProjectTemplate item, int position);
}
}
@@ -88,10 +88,6 @@ public class XMLAttributeListAdapter extends RecyclerView.Adapter<XMLAttributeLi
return attributes.size();
}
public interface OnClickListener {
void onClick(LayoutAttrEditorSheetItemBinding binding, XMLAttribute attribute);
}
static class VH extends RecyclerView.ViewHolder {
LayoutAttrEditorSheetItemBinding binding;
@@ -100,4 +96,8 @@ public class XMLAttributeListAdapter extends RecyclerView.Adapter<XMLAttributeLi
this.binding = binding;
}
}
public interface OnClickListener {
void onClick(LayoutAttrEditorSheetItemBinding binding, XMLAttribute attribute);
}
}
@@ -34,12 +34,48 @@ import com.itsaky.androidide.R;
import com.itsaky.androidide.utils.ILogger;
public abstract class StudioActivity extends AppCompatActivity {
private boolean toRequestStorage = true;
public static final String TAG = "StudioActivity";
public static final int REQCODE_STORAGE = 1009;
protected static ILogger LOG = ILogger.newInstance("StudioActivity");
private boolean toRequestStorage = true;
public void loadFrament(Fragment frag, View view) {
loadFragment(frag, view.getId());
}
public void loadFragment(Fragment fragment, int id) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(id, fragment);
transaction.commit();
}
public StudioApp getApp() {
return (StudioApp) getApplication();
}
public int getColorPrimary() {
return getTypedValueForAttr(R.attr.colorPrimary).data;
}
public TypedValue getTypedValueForAttr(@AttrRes int attrRes) {
TypedValue typedValue = new TypedValue();
getTheme().resolveAttribute(attrRes, typedValue, true);
return typedValue;
}
public int getColorPrimaryDark() {
return getTypedValueForAttr(R.attr.colorPrimaryDark).data;
}
public int getColorAccent() {
return getTypedValueForAttr(R.attr.colorAccent).data;
}
public int dpToPx(int dp) {
return (int)
TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, dp, getResources().getDisplayMetrics());
}
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -65,10 +101,6 @@ public abstract class StudioActivity extends AppCompatActivity {
== PackageManager.PERMISSION_GRANTED;
}
protected void doNotRequestStorage() {
this.toRequestStorage = false;
}
protected void requestStorage() {
if (isStoragePermissionGranted()) {
onStorageGranted();
@@ -82,43 +114,7 @@ public abstract class StudioActivity extends AppCompatActivity {
REQCODE_STORAGE);
}
public void loadFrament(Fragment frag, View view) {
loadFragment(frag, view.getId());
}
public void loadFragment(Fragment fragment, int id) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(id, fragment);
transaction.commit();
}
public StudioApp getApp() {
return (StudioApp) getApplication();
}
public TypedValue getTypedValueForAttr(@AttrRes int attrRes) {
TypedValue typedValue = new TypedValue();
getTheme().resolveAttribute(attrRes, typedValue, true);
return typedValue;
}
public int getColorPrimary() {
return getTypedValueForAttr(R.attr.colorPrimary).data;
}
public int getColorPrimaryDark() {
return getTypedValueForAttr(R.attr.colorPrimaryDark).data;
}
public int getColorAccent() {
return getTypedValueForAttr(R.attr.colorAccent).data;
}
public int dpToPx(int dp) {
return (int)
TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, dp, getResources().getDisplayMetrics());
}
protected void onStorageGranted() {}
@Override
public void onRequestPermissionsResult(
@@ -134,11 +130,13 @@ public abstract class StudioActivity extends AppCompatActivity {
protected void onStorageAlreadyGranted() {}
protected void onStorageGranted() {}
protected void onStorageDenied() {}
protected void onSetContentView() {}
protected abstract View bindLayout();
protected void doNotRequestStorage() {
this.toRequestStorage = false;
}
}
@@ -94,110 +94,16 @@ public class IDEDocumentsProvider extends DocumentsProvider {
return new File(Environment.DEFAULT_HOME);
}
/**
* Get the document id given a file. This document id must be consistent across time as other
* applications may save the ID and use it to reference documents later.
*
* <p>The reverse of @{link #getFileForDocId}.
*/
private static String getDocIdForFile(File file) {
return file.getAbsolutePath();
}
/** Get the file given a document id (the reverse of {@link #getDocIdForFile(File)}). */
private static File getFileForDocId(String docId) throws FileNotFoundException {
final File f = new File(docId);
if (!f.exists()) throw new FileNotFoundException(f.getAbsolutePath() + " not found");
return f;
}
private static String getMimeType(File file) {
if (file.isDirectory()) {
return Document.MIME_TYPE_DIR;
} else {
final String name = file.getName();
final int lastDot = name.lastIndexOf('.');
if (lastDot >= 0) {
final String extension = name.substring(lastDot + 1).toLowerCase(Locale.ROOT);
final String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
if (mime != null) return mime;
}
return "application/octet-stream";
}
}
@Override
public Cursor queryRoots(String[] projection) {
final MatrixCursor result =
new MatrixCursor(projection != null ? projection : DEFAULT_ROOT_PROJECTION);
final String applicationName = getContext().getString(R.string.app_name);
final MatrixCursor.RowBuilder row = result.newRow();
LOG.debug("queryRoots() before all add");
row.add(Root.COLUMN_ROOT_ID, getDocIdForFile(BASE_DIR));
LOG.debug("queryRoots() before all add, 1");
row.add(Root.COLUMN_DOCUMENT_ID, getDocIdForFile(BASE_DIR));
LOG.debug("queryRoots() before all add, 2");
row.add(Root.COLUMN_SUMMARY, null);
LOG.debug("queryRoots() before all add, 3");
row.add(
Root.COLUMN_FLAGS,
Root.FLAG_SUPPORTS_CREATE | Root.FLAG_SUPPORTS_SEARCH | Root.FLAG_SUPPORTS_IS_CHILD);
LOG.debug("queryRoots() before all add, 4");
row.add(Root.COLUMN_TITLE, applicationName);
LOG.debug("queryRoots() before all add, 5");
row.add(Root.COLUMN_MIME_TYPES, ALL_MIME_TYPES);
LOG.debug("queryRoots() before all add, 6");
row.add(Root.COLUMN_AVAILABLE_BYTES, BASE_DIR.getFreeSpace());
LOG.debug("queryRoots() before all add, 7");
row.add(Root.COLUMN_ICON, R.mipmap.ic_launcher);
LOG.debug("queryRoots() before all add");
return result;
}
@Override
public Cursor queryDocument(String documentId, String[] projection) throws FileNotFoundException {
final MatrixCursor result =
new MatrixCursor(projection != null ? projection : DEFAULT_DOCUMENT_PROJECTION);
includeFile(result, documentId, null);
return result;
}
@Override
public Cursor queryChildDocuments(String parentDocumentId, String[] projection, String sortOrder)
throws FileNotFoundException {
final MatrixCursor result =
new MatrixCursor(projection != null ? projection : DEFAULT_DOCUMENT_PROJECTION);
final File parent = getFileForDocId(parentDocumentId);
for (File file : parent.listFiles()) {
includeFile(result, null, file);
}
return result;
}
@Override
public ParcelFileDescriptor openDocument(
final String documentId, String mode, CancellationSignal signal)
throws FileNotFoundException {
final File file = getFileForDocId(documentId);
final int accessMode = ParcelFileDescriptor.parseMode(mode);
return ParcelFileDescriptor.open(file, accessMode);
}
@Override
public AssetFileDescriptor openDocumentThumbnail(
String documentId, Point sizeHint, CancellationSignal signal) throws FileNotFoundException {
final File file = getFileForDocId(documentId);
final ParcelFileDescriptor pfd =
ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
return new AssetFileDescriptor(pfd, 0, file.length());
}
@Override
public boolean onCreate() {
return true;
}
@Override
public boolean isChildDocument(String parentDocumentId, String documentId) {
return documentId.startsWith(parentDocumentId);
}
@Override
public String createDocument(String parentDocumentId, String mimeType, String displayName)
throws FileNotFoundException {
@@ -231,9 +137,62 @@ public class IDEDocumentsProvider extends DocumentsProvider {
}
@Override
public String getDocumentType(String documentId) throws FileNotFoundException {
File file = getFileForDocId(documentId);
return getMimeType(file);
public Cursor queryRoots(String[] projection) {
final MatrixCursor result =
new MatrixCursor(projection != null ? projection : DEFAULT_ROOT_PROJECTION);
final String applicationName = getContext().getString(R.string.app_name);
final MatrixCursor.RowBuilder row = result.newRow();
LOG.debug("queryRoots() before all add");
row.add(Root.COLUMN_ROOT_ID, getDocIdForFile(BASE_DIR));
LOG.debug("queryRoots() before all add, 1");
row.add(Root.COLUMN_DOCUMENT_ID, getDocIdForFile(BASE_DIR));
LOG.debug("queryRoots() before all add, 2");
row.add(Root.COLUMN_SUMMARY, null);
LOG.debug("queryRoots() before all add, 3");
row.add(
Root.COLUMN_FLAGS,
Root.FLAG_SUPPORTS_CREATE | Root.FLAG_SUPPORTS_SEARCH | Root.FLAG_SUPPORTS_IS_CHILD);
LOG.debug("queryRoots() before all add, 4");
row.add(Root.COLUMN_TITLE, applicationName);
LOG.debug("queryRoots() before all add, 5");
row.add(Root.COLUMN_MIME_TYPES, ALL_MIME_TYPES);
LOG.debug("queryRoots() before all add, 6");
row.add(Root.COLUMN_AVAILABLE_BYTES, BASE_DIR.getFreeSpace());
LOG.debug("queryRoots() before all add, 7");
row.add(Root.COLUMN_ICON, R.mipmap.ic_launcher);
LOG.debug("queryRoots() before all add");
return result;
}
/**
* Get the document id given a file. This document id must be consistent across time as other
* applications may save the ID and use it to reference documents later.
*
* <p>The reverse of @{link #getFileForDocId}.
*/
private static String getDocIdForFile(File file) {
return file.getAbsolutePath();
}
@Override
public Cursor queryDocument(String documentId, String[] projection) throws FileNotFoundException {
final MatrixCursor result =
new MatrixCursor(projection != null ? projection : DEFAULT_DOCUMENT_PROJECTION);
includeFile(result, documentId, null);
return result;
}
@Override
public Cursor queryChildDocuments(String parentDocumentId, String[] projection, String sortOrder)
throws FileNotFoundException {
final MatrixCursor result =
new MatrixCursor(projection != null ? projection : DEFAULT_DOCUMENT_PROJECTION);
final File parent = getFileForDocId(parentDocumentId);
for (File file : parent.listFiles()) {
includeFile(result, null, file);
}
return result;
}
@Override
@@ -277,8 +236,27 @@ public class IDEDocumentsProvider extends DocumentsProvider {
}
@Override
public boolean isChildDocument(String parentDocumentId, String documentId) {
return documentId.startsWith(parentDocumentId);
public String getDocumentType(String documentId) throws FileNotFoundException {
File file = getFileForDocId(documentId);
return getMimeType(file);
}
@Override
public ParcelFileDescriptor openDocument(
final String documentId, String mode, CancellationSignal signal)
throws FileNotFoundException {
final File file = getFileForDocId(documentId);
final int accessMode = ParcelFileDescriptor.parseMode(mode);
return ParcelFileDescriptor.open(file, accessMode);
}
@Override
public AssetFileDescriptor openDocumentThumbnail(
String documentId, Point sizeHint, CancellationSignal signal) throws FileNotFoundException {
final File file = getFileForDocId(documentId);
final ParcelFileDescriptor pfd =
ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
return new AssetFileDescriptor(pfd, 0, file.length());
}
/**
@@ -317,4 +295,26 @@ public class IDEDocumentsProvider extends DocumentsProvider {
row.add(Document.COLUMN_FLAGS, flags);
row.add(Document.COLUMN_ICON, R.mipmap.ic_launcher);
}
/** Get the file given a document id (the reverse of {@link #getDocIdForFile(File)}). */
private static File getFileForDocId(String docId) throws FileNotFoundException {
final File f = new File(docId);
if (!f.exists()) throw new FileNotFoundException(f.getAbsolutePath() + " not found");
return f;
}
private static String getMimeType(File file) {
if (file.isDirectory()) {
return Document.MIME_TYPE_DIR;
} else {
final String name = file.getName();
final int lastDot = name.lastIndexOf('.');
if (lastDot >= 0) {
final String extension = name.substring(lastDot + 1).toLowerCase(Locale.ROOT);
final String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
if (mime != null) return mime;
}
return "application/octet-stream";
}
}
}
@@ -20,9 +20,6 @@
package com.itsaky.androidide.fragments;
import abhishekti7.unicorn.filepicker.UnicornFilePicker;
import abhishekti7.unicorn.filepicker.ui.FilePickerActivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Environment;
@@ -41,31 +38,12 @@ import com.itsaky.toaster.Toaster;
import java.io.File;
import java.util.ArrayList;
import abhishekti7.unicorn.filepicker.UnicornFilePicker;
import abhishekti7.unicorn.filepicker.ui.FilePickerActivity;
public class BaseFragment extends Fragment {
private FileChoserCallback dirCallback;
protected StudioActivity getStudioActivity() {
return (StudioActivity) getActivity();
}
protected void pickDirectory(FileChoserCallback dirCallback) {
this.dirCallback = dirCallback;
UnicornFilePicker.from(this)
.addConfigBuilder()
.addItemDivider(false)
.selectMultipleFiles(false)
.setRootDirectory(Environment.getExternalStorageDirectory().getAbsolutePath())
.showHiddenFiles(true)
.showOnlyDirectory(true)
.theme(R.style.AppTheme_FilePicker)
.build();
Intent intent = new Intent(requireActivity(), FilePickerActivity.class);
// .forResult(abhishekti7.unicorn.filepicker.utils.Constants.REQ_UNICORN_FILE);
startForResult.launch(intent);
}
ActivityResultLauncher<Intent> startForResult =
registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(),
@@ -95,6 +73,27 @@ public class BaseFragment extends Fragment {
}
});
protected StudioActivity getStudioActivity() {
return (StudioActivity) getActivity();
}
protected void pickDirectory(FileChoserCallback dirCallback) {
this.dirCallback = dirCallback;
UnicornFilePicker.from(this)
.addConfigBuilder()
.addItemDivider(false)
.selectMultipleFiles(false)
.setRootDirectory(Environment.getExternalStorageDirectory().getAbsolutePath())
.showHiddenFiles(true)
.showOnlyDirectory(true)
.theme(R.style.AppTheme_FilePicker)
.build();
Intent intent = new Intent(requireActivity(), FilePickerActivity.class);
// .forResult(abhishekti7.unicorn.filepicker.utils.Constants.REQ_UNICORN_FILE);
startForResult.launch(intent);
}
interface FileChoserCallback {
void picketDictionary(File file);
}
@@ -70,6 +70,14 @@ public class DiagnosticsListFragment extends Fragment {
unsavedAdapter = null;
}
@Override
public void onDestroyView() {
super.onDestroyView();
unsavedAdapter = null;
list = null;
emptyView = null;
}
public void setAdapter(@NonNull DiagnosticsAdapter adapter) {
if (list != null) {
list.setAdapter(adapter);
@@ -84,12 +92,4 @@ public class DiagnosticsListFragment extends Fragment {
list.setVisibility(error ? View.GONE : View.VISIBLE);
}
}
@Override
public void onDestroyView() {
super.onDestroyView();
unsavedAdapter = null;
list = null;
emptyView = null;
}
}
@@ -95,6 +95,14 @@ public class FileTreeFragment extends BottomSheetDialogFragment
}
}
@Override
public void onDestroyView() {
super.onDestroyView();
binding = null;
mFileTreeView = null;
mFileActionListener = null;
}
@Override
public View onCreateView(
@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
@@ -201,12 +209,6 @@ public class FileTreeFragment extends BottomSheetDialogFragment
__ -> finalWhenDone.run());
}
private void updateChevron(@NonNull TreeNode node) {
if (node.getViewHolder() instanceof FileTreeViewHolder) {
((FileTreeViewHolder) node.getViewHolder()).updateChevron(!node.isExpanded());
}
}
private void getNodeFromFiles(File[] files, TreeNode parent) {
Arrays.sort(files, new FileTreeCallable.SortFileName());
Arrays.sort(files, new FileTreeCallable.SortFolder());
@@ -217,6 +219,12 @@ public class FileTreeFragment extends BottomSheetDialogFragment
}
}
private void updateChevron(@NonNull TreeNode node) {
if (node.getViewHolder() instanceof FileTreeViewHolder) {
((FileTreeViewHolder) node.getViewHolder()).updateChevron(!node.isExpanded());
}
}
@Override
public boolean onLongClick(TreeNode node, Object value) {
if (mFileActionListener != null) {
@@ -332,14 +340,6 @@ public class FileTreeFragment extends BottomSheetDialogFragment
}
}
@Override
public void onDestroyView() {
super.onDestroyView();
binding = null;
mFileTreeView = null;
mFileActionListener = null;
}
public interface FileActionListener {
CodeEditorView openFile(File file);
@@ -1,34 +1,22 @@
package com.itsaky.androidide.fragments;
import abhishekti7.unicorn.filepicker.UnicornFilePicker;
import abhishekti7.unicorn.filepicker.ui.FilePickerActivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.itsaky.androidide.EditorActivity;
import com.itsaky.androidide.PreferencesActivity;
import com.itsaky.androidide.R;
import com.itsaky.androidide.TerminalActivity;
import com.itsaky.androidide.app.StudioApp;
import com.itsaky.androidide.databinding.FragmentMainBinding;
import com.itsaky.androidide.projects.ProjectManager;
import com.itsaky.androidide.utils.DialogUtils;
import com.itsaky.toaster.Toaster;
import java.io.File;
import java.util.ArrayList;
public class MainFragment extends BaseFragment
implements WizardFragment.OnProjectCreatedListener, View.OnClickListener {
@@ -97,13 +85,13 @@ public class MainFragment extends BaseFragment
.commit();
}
private void gotoSettings() {
startActivity(new Intent(requireActivity(), PreferencesActivity.class));
}
@Override
public void openProject(@NonNull File root) {
ProjectManager.INSTANCE.setProjectPath(root.getAbsolutePath());
startActivity(new Intent(requireActivity(), EditorActivity.class));
}
private void gotoSettings() {
startActivity(new Intent(requireActivity(), PreferencesActivity.class));
}
}
@@ -64,6 +64,12 @@ public abstract class NonEditableEditorFragment extends Fragment {
editor.setColorScheme(new SchemeAndroidIDE());
}
@Override
public void onDestroyView() {
super.onDestroyView();
binding = null;
}
@Nullable
public IDEEditor getEditor() {
if (binding == null) {
@@ -71,10 +77,4 @@ public abstract class NonEditableEditorFragment extends Fragment {
}
return binding.editor;
}
@Override
public void onDestroyView() {
super.onDestroyView();
binding = null;
}
}
@@ -68,6 +68,14 @@ public class SearchResultFragment extends Fragment {
unsavedAdapter = null;
}
@Override
public void onDestroyView() {
super.onDestroyView();
unsavedAdapter = null;
list = null;
emptyView = null;
}
public void setAdapter(@NonNull final SearchListAdapter adapter) {
if (list == null) {
unsavedAdapter = adapter;
@@ -82,12 +90,4 @@ public class SearchResultFragment extends Fragment {
list.setVisibility(error ? View.GONE : View.VISIBLE);
}
}
@Override
public void onDestroyView() {
super.onDestroyView();
unsavedAdapter = null;
list = null;
emptyView = null;
}
}
@@ -19,7 +19,6 @@ import androidx.transition.TransitionManager;
import com.google.android.material.transition.MaterialFadeThrough;
import com.google.android.material.transition.MaterialSharedAxis;
import com.itsaky.androidide.R;
import com.itsaky.androidide.adapters.WizardTemplateAdapter;
import com.itsaky.androidide.app.StudioApp;
@@ -68,9 +67,6 @@ public class WizardFragment extends BaseFragment {
private OnProjectCreatedListener mListener;
private boolean mLast;
private int minSdkIndex;
private int targetSdkIndex;
private final OnBackPressedCallback onBackPressedCallback =
new OnBackPressedCallback(true) {
@Override
@@ -78,6 +74,8 @@ public class WizardFragment extends BaseFragment {
onNavigateBack();
}
};
private int minSdkIndex;
private int targetSdkIndex;
@Nullable
@Override
@@ -171,12 +169,6 @@ public class WizardFragment extends BaseFragment {
initDetailsView();
}
@Override
public void onDestroy() {
super.onDestroy();
onBackPressedCallback.setEnabled(false);
}
@Override
public void onDestroyView() {
super.onDestroyView();
@@ -190,6 +182,28 @@ public class WizardFragment extends BaseFragment {
mProgressSheet = null;
}
@Override
public void onDestroy() {
super.onDestroy();
onBackPressedCallback.setEnabled(false);
}
public void onSuccess(File root) {
if (mProgressSheet != null && mProgressSheet.isShowing()) {
mProgressSheet.dismiss();
}
StudioApp.getInstance().toast(R.string.project_created_successfully, Toaster.Type.SUCCESS);
if (mListener != null) {
getParentFragmentManager().popBackStack();
mListener.openProject(root);
}
}
public void setOnProjectCreatedListener(OnProjectCreatedListener listener) {
mListener = listener;
}
private String getSelectedItem(int pos, AutoCompleteTextView view) {
return view.getAdapter().getItem(pos).toString();
}
@@ -516,18 +530,6 @@ public class WizardFragment extends BaseFragment {
setSaveLocation();
}
public void onSuccess(File root) {
if (mProgressSheet != null && mProgressSheet.isShowing()) {
mProgressSheet.dismiss();
}
StudioApp.getInstance().toast(R.string.project_created_successfully, Toaster.Type.SUCCESS);
if (mListener != null) {
getParentFragmentManager().popBackStack();
mListener.openProject(root);
}
}
private void createProgressSheet() {
mProgressSheet = new ProgressSheet();
mProgressSheet.setShowShadow(false);
@@ -554,8 +556,4 @@ public class WizardFragment extends BaseFragment {
public interface OnProjectCreatedListener {
void openProject(File project);
}
public void setOnProjectCreatedListener(OnProjectCreatedListener listener) {
mListener = listener;
}
}
@@ -41,15 +41,6 @@ public abstract class AbstractReferenceEditor extends BaseValueEditorFragment {
private static final ILogger LOG = ILogger.newInstance("ReferenceEditor");
public TextWatcherAdapter resInputWatcher;
@Override
protected void notifyValueChanged(@NonNull String newValue) {
try {
super.notifyValueChanged(newValue);
} catch (Throwable e) {
LOG.error("Unable to update resource value to '" + newValue + "'", e);
}
}
protected void setupReferenceInput(MaterialAutoCompleteTextView referenceInput) {
Objects.requireNonNull(referenceInput);
@@ -78,6 +69,15 @@ public abstract class AbstractReferenceEditor extends BaseValueEditorFragment {
.whenComplete((list, error) -> handleAutoCompleteResult(list, error, referenceInput));
}
@Override
protected void notifyValueChanged(@NonNull String newValue) {
try {
super.notifyValueChanged(newValue);
} catch (Throwable e) {
LOG.error("Unable to update resource value to '" + newValue + "'", e);
}
}
protected void handleAutoCompleteResult(
List<String> list, Throwable error, AutoCompleteTextView referenceInput) {
if (list == null || list.isEmpty()) {
@@ -18,7 +18,6 @@
package com.itsaky.androidide.fragments.attr;
import android.app.Dialog;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@@ -77,28 +76,6 @@ public class ColorEditor extends AbstractReferenceEditor {
}
}
@Override
protected List<String> computeReferenceItems() {
final var list = new ArrayList<String>();
final var tables = ValuesTableFactory.getAllTables();
for (var entry : tables.entrySet()) {
final var dimens = entry.getValue().getTable("color");
if (dimens != null) {
list.addAll(dimens.keySet().stream().map("@color/"::concat).collect(Collectors.toSet()));
}
}
list.addAll(
FrameworkValues.listColors().stream()
.map("@android:color/"::concat)
.collect(Collectors.toList()));
final var resTable = StudioApp.getInstance().getResourceTable();
list.addAll(resTable.listResourceNames("color"));
return list;
}
private Dialog getColorPickerDialog() {
if (colorPickerDialog == null) {
@@ -122,4 +99,26 @@ public class ColorEditor extends AbstractReferenceEditor {
return colorPickerDialog;
}
@Override
protected List<String> computeReferenceItems() {
final var list = new ArrayList<String>();
final var tables = ValuesTableFactory.getAllTables();
for (var entry : tables.entrySet()) {
final var dimens = entry.getValue().getTable("color");
if (dimens != null) {
list.addAll(dimens.keySet().stream().map("@color/"::concat).collect(Collectors.toSet()));
}
}
list.addAll(
FrameworkValues.listColors().stream()
.map("@android:color/"::concat)
.collect(Collectors.toList()));
final var resTable = StudioApp.getInstance().getResourceTable();
list.addAll(resTable.listResourceNames("color"));
return list;
}
}
@@ -63,6 +63,13 @@ public class FlagEditor extends FixedValueEditor {
// Does noting...
}
@Override
protected Chip newChip(String title, boolean checked) {
final var chip = super.newChip(title, checked);
chip.setOnCheckedChangeListener(this::onCheckChangedMultiple);
return chip;
}
protected void onCheckChangedMultiple(CompoundButton compoundButton, boolean b) {
final var items = new ArrayList<String>();
for (var id : this.chipGroup.getCheckedChipIds()) {
@@ -78,11 +85,4 @@ public class FlagEditor extends FixedValueEditor {
notifyValueChanged(TextUtils.join("|", items));
}
@Override
protected Chip newChip(String title, boolean checked) {
final var chip = super.newChip(title, checked);
chip.setOnCheckedChangeListener(this::onCheckChangedMultiple);
return chip;
}
}
@@ -31,6 +31,11 @@ import com.itsaky.androidide.managers.PreferenceManager;
public abstract class BasePreferenceFragment extends PreferenceFragmentCompat {
@Override
public void onCreatePreferences(Bundle p1, String p2) {
setPreferencesFromResource(com.itsaky.androidide.R.xml.ide_prefs, p2);
}
@Override
public View onCreateView(
@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
@@ -43,11 +48,6 @@ public abstract class BasePreferenceFragment extends PreferenceFragmentCompat {
return v;
}
@Override
public void onCreatePreferences(Bundle p1, String p2) {
setPreferencesFromResource(com.itsaky.androidide.R.xml.ide_prefs, p2);
}
protected PreferenceManager getPrefManager() {
return StudioApp.getInstance().getPrefManager();
}
@@ -120,15 +120,6 @@ public class BuildPreferences extends BasePreferenceFragment
return true;
}
@Override
public boolean onPreferenceChange(final Preference preference, final Object newValue) {
final var key = preference.getKey();
if (KEY_TP_FIX.equals(key)) {
getPrefManager().putBoolean(KEY_TP_FIX, ((boolean) newValue));
}
return true;
}
private void changeGradleDist() {
final var builder = DialogUtils.newMaterialDialogBuilder(getContext());
final var binding = LayoutDialogTextInputBinding.inflate(getLayoutInflater());
@@ -228,4 +219,13 @@ public class BuildPreferences extends BasePreferenceFragment
? progressSheet = new ProgressSheet().setMessage(getString(R.string.please_wait))
: progressSheet;
}
@Override
public boolean onPreferenceChange(final Preference preference, final Object newValue) {
final var key = preference.getKey();
if (KEY_TP_FIX.equals(key)) {
getPrefManager().putBoolean(KEY_TP_FIX, ((boolean) newValue));
}
return true;
}
}
@@ -123,20 +123,6 @@ public class IDEPreferences extends BasePreferenceFragment
: mBuildPreferences;
}
private void showChangelog() {
final var intent = new Intent(Intent.ACTION_VIEW);
intent.setData(
Uri.parse(
BaseApplication.GITHUB_URL.concat("/releases/tag/v").concat(BuildConfig.VERSION_NAME)));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
startActivity(intent);
} catch (Throwable th) {
LOG.error("Unable to start activity to show changelog", th);
StudioApp.getInstance().toast("Unable to start activity", Toaster.Type.ERROR);
}
}
@Override
public boolean onPreferenceClick(@NonNull Preference preference) {
final String key = preference.getKey();
@@ -156,4 +142,18 @@ public class IDEPreferences extends BasePreferenceFragment
}
return true;
}
private void showChangelog() {
final var intent = new Intent(Intent.ACTION_VIEW);
intent.setData(
Uri.parse(
BaseApplication.GITHUB_URL.concat("/releases/tag/v").concat(BuildConfig.VERSION_NAME)));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
startActivity(intent);
} catch (Throwable th) {
LOG.error("Unable to start activity to show changelog", th);
StudioApp.getInstance().toast("Unable to start activity", Toaster.Type.ERROR);
}
}
}
@@ -102,19 +102,6 @@ public class AttrEditorSheet extends BottomSheetDialogFragment
setupViewData();
}
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
mDeletionFailedListener = (OnViewDeletionFailedListener) context;
}
public AttrEditorSheet setLayout(File layout) {
Objects.requireNonNull(layout);
this.layout = layout;
return this;
}
private void setupViewData() {
binding.actionsList.setAdapter(new SimpleIconTextAdapter(VIEW_ACTIONS).setOnBindListener(this));
@@ -132,10 +119,6 @@ public class AttrEditorSheet extends BottomSheetDialogFragment
this::onAttrClick));
}
public void setSelectedView(IView view) {
this.selectedView = view;
}
private void onAttrClick(
LayoutAttrEditorSheetItemBinding binding, @NonNull XMLAttribute attribute) {
@@ -158,6 +141,42 @@ public class AttrEditorSheet extends BottomSheetDialogFragment
getValueEditorSheet(attribute).show(getChildFragmentManager(), "attr_value_editor_sheet");
}
@NonNull
public AttrValueEditorSheet getValueEditorSheet(@NonNull XMLAttribute attribute) {
if (mValueEditorSheet == null) {
mValueEditorSheet = AttrValueEditorSheet.newInstance(attribute);
}
mValueEditorSheet.setAttribute(attribute);
return mValueEditorSheet;
}
private boolean dismissIfSelectedNull() {
if (selectedView == null) {
dismiss();
return true;
}
return false;
}
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
mDeletionFailedListener = (OnViewDeletionFailedListener) context;
}
public AttrEditorSheet setLayout(File layout) {
Objects.requireNonNull(layout);
this.layout = layout;
return this;
}
public void setSelectedView(IView view) {
this.selectedView = view;
}
@Override
public void postBind(
IconTextListItem item, @NonNull SimpleIconTextAdapter.VH holder, int position) {
@@ -276,11 +295,6 @@ public class AttrEditorSheet extends BottomSheetDialogFragment
return new ArrayList<>(attributes);
}
@Override
public void accept(Attr attr) {
addNewAttribute(attr);
}
@NonNull
private AttributeListSheet getAttrListSheet() {
if (mAttrListSheet == null) {
@@ -291,15 +305,15 @@ public class AttrEditorSheet extends BottomSheetDialogFragment
return mAttrListSheet;
}
@NonNull
public AttrValueEditorSheet getValueEditorSheet(@NonNull XMLAttribute attribute) {
if (mValueEditorSheet == null) {
mValueEditorSheet = AttrValueEditorSheet.newInstance(attribute);
@Override
public void accept(Attr attr) {
addNewAttribute(attr);
}
mValueEditorSheet.setAttribute(attribute);
return mValueEditorSheet;
private void addNewAttribute(@NonNull Attr attr) {
final XMLAttribute attribute = new XMLAttribute(attr.namespace, attr.name, "", false);
attribute.setAttr(attr);
showValueEditorSheet(attribute);
}
@Override
@@ -320,20 +334,6 @@ public class AttrEditorSheet extends BottomSheetDialogFragment
}
}
private void addNewAttribute(@NonNull Attr attr) {
final XMLAttribute attribute = new XMLAttribute(attr.namespace, attr.name, "", false);
attribute.setAttr(attr);
showValueEditorSheet(attribute);
}
private boolean dismissIfSelectedNull() {
if (selectedView == null) {
dismiss();
return true;
}
return false;
}
/**
* A listener can be used to get notified when we fail to remove a view from its parent. This is
* used in {@link com.itsaky.androidide.DesignerActivity DesignerActivity}.
@@ -53,12 +53,6 @@ public class AttributeListSheet extends BottomSheetDialogFragment {
private Consumer<Attr> clickConsumer;
private List<Attr> mItems;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NORMAL, R.style.AppTheme_SheetAboveKeyboard);
}
@Nullable
@Override
public View onCreateView(
@@ -104,6 +98,16 @@ public class AttributeListSheet extends BottomSheetDialogFragment {
return true;
}
public void update() {
update(mItems);
}
public void update(List<Attr> items) {
if (binding != null) {
binding.attrList.setAdapter(new AttrListAdapter(clickConsumer, items));
}
}
public void setItems(@Nullable List<Attr> items) {
if (items == null) {
items = new ArrayList<>();
@@ -120,13 +124,9 @@ public class AttributeListSheet extends BottomSheetDialogFragment {
this.clickConsumer = (Consumer<Attr>) getParentFragment();
}
public void update() {
update(mItems);
}
public void update(List<Attr> items) {
if (binding != null) {
binding.attrList.setAdapter(new AttrListAdapter(clickConsumer, items));
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NORMAL, R.style.AppTheme_SheetAboveKeyboard);
}
}
@@ -47,6 +47,8 @@ public abstract class BaseBottomSheetFragment extends BottomSheetDialogFragment
return mDialog;
}
protected void onShow() {}
@Override
public View onCreateView(
@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
@@ -97,10 +99,6 @@ public abstract class BaseBottomSheetFragment extends BottomSheetDialogFragment
}
}
public boolean isShowing() {
return mDialog != null && mDialog.isShowing();
}
protected boolean shouldHideTitle() {
return !titleEnabled;
}
@@ -123,6 +121,12 @@ public abstract class BaseBottomSheetFragment extends BottomSheetDialogFragment
return this;
}
protected abstract void bind(LinearLayout container);
public boolean isShowing() {
return mDialog != null && mDialog.isShowing();
}
public void setShowShadow(boolean enabled) {
this.shadowEnabled = enabled;
}
@@ -131,10 +135,6 @@ public abstract class BaseBottomSheetFragment extends BottomSheetDialogFragment
this.titleEnabled = enabled;
}
protected void onShow() {}
protected abstract void bind(LinearLayout container);
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
@@ -42,13 +42,6 @@ public class OptionsListFragment extends BaseBottomSheetFragment {
private RecyclerView mList;
private OnOptionsClickListener listener;
@Override
protected void bind(@NonNull LinearLayout container) {
mList = new RecyclerView(requireContext());
container.removeAllViews();
container.addView(mList, new LinearLayout.LayoutParams(-1, -1));
}
@Override
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
@@ -64,6 +57,18 @@ public class OptionsListFragment extends BaseBottomSheetFragment {
}));
}
@Override
protected String getTitle() {
return getString(com.itsaky.androidide.R.string.file_options);
}
@Override
protected void bind(@NonNull LinearLayout container) {
mList = new RecyclerView(requireContext());
container.removeAllViews();
container.addView(mList, new LinearLayout.LayoutParams(-1, -1));
}
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
@@ -90,11 +95,6 @@ public class OptionsListFragment extends BaseBottomSheetFragment {
return this;
}
@Override
protected String getTitle() {
return getString(com.itsaky.androidide.R.string.file_options);
}
public static interface OnOptionsClickListener {
void onOptionsClick(SheetOption option);
}
@@ -41,12 +41,6 @@ public class ProgressSheet extends BaseBottomSheetFragment {
private boolean subMessageEnabled = false;
private boolean welcomeTextEnabled = false;
@Override
protected void bind(LinearLayout container) {
binding = LayoutProgressSheetBinding.inflate(LayoutInflater.from(getContext()));
container.addView(binding.getRoot());
}
@Override
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
@@ -85,6 +79,12 @@ public class ProgressSheet extends BaseBottomSheetFragment {
return true;
}
@Override
protected void bind(LinearLayout container) {
binding = LayoutProgressSheetBinding.inflate(LayoutInflater.from(getContext()));
container.addView(binding.getRoot());
}
public ProgressSheet setWelcomeTextEnabled(boolean enabled) {
this.welcomeTextEnabled = enabled;
return this;
@@ -40,34 +40,6 @@ public class TextSheetFragment extends BaseBottomSheetFragment {
return this;
}
@Override
protected void bind(@NonNull LinearLayout container) {
final IDEEditor e = getEditor();
container.setPadding(0, 0, 0, 0);
container.setPaddingRelative(0, 0, 0, 0);
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(-1, 0);
p.weight = 1.0f;
if (e.getParent() != null && e.getParent() instanceof ViewGroup) {
((ViewGroup) e.getParent()).removeView(e);
}
container.addView(getEditor(), p);
}
@Override
protected String getTitle() {
return getString(R.string.build_output);
}
@Override
protected void onShow() {
super.onShow();
editor.setText(getOutputBuilder());
}
private void scrollToBottom() {
if (getActivity() != null) getActivity().runOnUiThread(() -> editor.goToEnd());
}
public TextSheetFragment setTitleText(int res) {
super.setTitle(res);
return this;
@@ -111,6 +83,34 @@ public class TextSheetFragment extends BaseBottomSheetFragment {
});
}
private void scrollToBottom() {
if (getActivity() != null) getActivity().runOnUiThread(() -> editor.goToEnd());
}
@Override
protected String getTitle() {
return getString(R.string.build_output);
}
@Override
protected void onShow() {
super.onShow();
editor.setText(getOutputBuilder());
}
@Override
protected void bind(@NonNull LinearLayout container) {
final IDEEditor e = getEditor();
container.setPadding(0, 0, 0, 0);
container.setPaddingRelative(0, 0, 0, 0);
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(-1, 0);
p.weight = 1.0f;
if (e.getParent() != null && e.getParent() instanceof ViewGroup) {
((ViewGroup) e.getParent()).removeView(e);
}
container.addView(getEditor(), p);
}
private IDEEditor getEditor() {
return editor == null ? createEditor() : editor;
}
@@ -20,11 +20,6 @@ import androidx.annotation.NonNull;
import com.itsaky.androidide.app.StudioApp;
import com.itsaky.lsp.api.ILanguageServer;
import com.itsaky.lsp.models.DiagnosticItem;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import io.github.rosemoe.sora.lang.Language;
@@ -40,10 +35,6 @@ public abstract class IDELanguage implements Language {
return false;
}
public int getTabSize() {
return StudioApp.getInstance().getPrefManager().getEditorTabSize();
}
@Override
public CharSequence format(CharSequence text) {
final var server = getLanguageServer();
@@ -54,11 +45,15 @@ public abstract class IDELanguage implements Language {
return text;
}
public int getIndentAdvance(@NonNull String line) {
return 0;
}
protected ILanguageServer getLanguageServer() {
return null;
}
public int getTabSize() {
return StudioApp.getInstance().getPrefManager().getEditorTabSize();
}
public int getIndentAdvance(@NonNull String line) {
return 0;
}
}
@@ -26,13 +26,9 @@ import com.itsaky.androidide.utils.ILogger;
import java.lang.Override;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import io.github.rosemoe.sora.lang.analysis.AsyncIncrementalAnalyzeManager;
import io.github.rosemoe.sora.lang.styling.CodeBlock;
import io.github.rosemoe.sora.lang.styling.Span;
import io.github.rosemoe.sora.text.Content;
public class CppAnalyzer extends BaseIncrementalAnalyzeManager {
@@ -43,8 +39,10 @@ public class CppAnalyzer extends BaseIncrementalAnalyzeManager {
}
@Override
protected int[] getCodeBlockTokens() {
return new int[] {LeftBrace, RightBrace};
protected int[][] getMultilineTokenStartEndTypes() {
final var start = new int[] {Div, Star};
final var end = new int[] {Star, Div};
return new int[][] {start, end};
}
@Override
@@ -215,15 +213,13 @@ public class CppAnalyzer extends BaseIncrementalAnalyzeManager {
return spans;
}
@Override
protected int[][] getMultilineTokenStartEndTypes() {
final var start = new int[] {Div, Star};
final var end = new int[] {Star, Div};
return new int[][] {start, end};
}
@Override
protected void handleIncompleteToken(final IncrementalToken token) {
token.type = BlockComment;
}
@Override
protected int[] getCodeBlockTokens() {
return new int[] {LeftBrace, RightBrace};
}
}
@@ -43,42 +43,13 @@ import io.github.rosemoe.sora.widget.SymbolPairMatch;
public class CppLanguage extends IDELanguage {
private static final ILogger LOG = ILogger.newInstance("CppLanguage");
private CppAnalyzer analyzer;
private final NewlineHandler[] newlineHandlers = new NewlineHandler[] {new BraceHandler()};
private CppAnalyzer analyzer;
public CppLanguage() {
analyzer = new CppAnalyzer();
}
@Override
public int getIndentAdvance(@NonNull String line) {
try {
CPP14Lexer lexer = new CPP14Lexer(CharStreams.fromReader(new StringReader(line)));
Token token;
int advance = 0;
while (((token = lexer.nextToken()) != null && token.getType() != token.EOF)) {
switch (token.getType()) {
case CPP14Lexer.LeftBrace:
advance++;
break;
case CPP14Lexer.RightBrace:
advance--;
break;
}
}
advance = Math.max(0, advance);
return advance * getTabSize();
} catch (Throwable e) {
LOG.error("Error calculating indent advance", e);
}
return 0;
}
@Override
public SymbolPairMatch getSymbolPairs() {
return new CppSymbolPairs();
}
@NonNull
@Override
public AnalyzeManager getAnalyzeManager() {
@@ -107,8 +78,8 @@ public class CppLanguage extends IDELanguage {
}
@Override
public CharSequence format(CharSequence content) {
return content;
public SymbolPairMatch getSymbolPairs() {
return new CppSymbolPairs();
}
@Override
@@ -121,6 +92,35 @@ public class CppLanguage extends IDELanguage {
analyzer = null;
}
@Override
public CharSequence format(CharSequence content) {
return content;
}
@Override
public int getIndentAdvance(@NonNull String line) {
try {
CPP14Lexer lexer = new CPP14Lexer(CharStreams.fromReader(new StringReader(line)));
Token token;
int advance = 0;
while (((token = lexer.nextToken()) != null && token.getType() != token.EOF)) {
switch (token.getType()) {
case CPP14Lexer.LeftBrace:
advance++;
break;
case CPP14Lexer.RightBrace:
advance--;
break;
}
}
advance = Math.max(0, advance);
return advance * getTabSize();
} catch (Throwable e) {
LOG.error("Error calculating indent advance", e);
}
return 0;
}
private static class CppSymbolPairs extends SymbolPairMatch {
public CppSymbolPairs() {
super.putPair('{', new Replacement("{}", 1));
@@ -23,10 +23,8 @@ import com.itsaky.androidide.language.incremental.LineState
import com.itsaky.androidide.lexers.groovy.GroovyLexer
import com.itsaky.androidide.syntax.colorschemes.SchemeAndroidIDE
import io.github.rosemoe.sora.lang.analysis.IncrementalAnalyzeManager.LineTokenizeResult
import io.github.rosemoe.sora.lang.styling.CodeBlock
import io.github.rosemoe.sora.lang.styling.Span
import io.github.rosemoe.sora.lang.styling.TextStyle
import io.github.rosemoe.sora.text.Content
/** @author Akash Yadav */
class GroovyAnalyzer : BaseIncrementalAnalyzeManager(GroovyLexer::class.java) {
@@ -53,35 +53,6 @@ public class GroovyLanguage extends IDELanguage {
completer = new GroovyAutoComplete();
}
@Override
public int getIndentAdvance(@NonNull String p1) {
try {
GroovyLexer lexer = new GroovyLexer(CharStreams.fromReader(new StringReader(p1)));
Token token = null;
int advance = 0;
while (((token = lexer.nextToken()) != null && token.getType() != token.EOF)) {
switch (token.getType()) {
case GroovyLexer.LBRACE:
advance++;
break;
case GroovyLexer.RBRACE:
advance--;
break;
}
}
advance = Math.max(0, advance);
return advance * getTabSize();
} catch (Throwable e) {
LOG.error("Failed to calculate indent advance", e);
}
return 0;
}
@Override
public SymbolPairMatch getSymbolPairs() {
return new SymbolPairMatch.DefaultSymbolPairs();
}
@NonNull
@Override
public AnalyzeManager getAnalyzeManager() {
@@ -129,8 +100,8 @@ public class GroovyLanguage extends IDELanguage {
}
@Override
public CharSequence format(CharSequence content) {
return content;
public SymbolPairMatch getSymbolPairs() {
return new SymbolPairMatch.DefaultSymbolPairs();
}
@Override
@@ -141,6 +112,35 @@ public class GroovyLanguage extends IDELanguage {
@Override
public void destroy() {}
@Override
public CharSequence format(CharSequence content) {
return content;
}
@Override
public int getIndentAdvance(@NonNull String p1) {
try {
GroovyLexer lexer = new GroovyLexer(CharStreams.fromReader(new StringReader(p1)));
Token token = null;
int advance = 0;
while (((token = lexer.nextToken()) != null && token.getType() != token.EOF)) {
switch (token.getType()) {
case GroovyLexer.LBRACE:
advance++;
break;
case GroovyLexer.RBRACE:
advance--;
break;
}
}
advance = Math.max(0, advance);
return advance * getTabSize();
} catch (Throwable e) {
LOG.error("Failed to calculate indent advance", e);
}
return 0;
}
class BraceHandler implements NewlineHandler {
@Override
@@ -61,11 +61,11 @@ import kotlin.Pair;
public abstract class BaseIncrementalAnalyzeManager
extends AsyncIncrementalAnalyzeManager<LineState, IncrementalToken> {
private static final ILogger LOG = ILogger.newInstance("BaseIncrementalAnalyzeManager");
protected final Lexer lexer;
private final int[] multilineStartTypes;
private final int[] multilineEndTypes;
private final int[] blockTokens;
private static final ILogger LOG = ILogger.newInstance("BaseIncrementalAnalyzeManager");
public BaseIncrementalAnalyzeManager(final Class<? extends Lexer> lexer) {
Objects.requireNonNull(lexer, "Cannot create analyzer manager for null lexer");
@@ -92,6 +92,16 @@ public abstract class BaseIncrementalAnalyzeManager
}
}
@NonNull
protected CharStream createStream(@NonNull CharSequence source) {
Objects.requireNonNull(source);
try {
return CharStreams.fromReader(new CharSequenceReader(source));
} catch (IOException e) {
throw new RuntimeException("Cannot create CharStream for source", e);
}
}
private void verifyMultilineTypes(@NonNull final int[][] types) {
Preconditions.checkState(
types.length == 2, "There must be exact two inner int[] in multiline token types");
@@ -102,45 +112,6 @@ public abstract class BaseIncrementalAnalyzeManager
Preconditions.checkState(end.length > 0, "Invalid end token types");
}
@SuppressWarnings("UnstableApiUsage")
@NonNull
private Pair<EvictingQueue<IncrementalToken>, EvictingQueue<IncrementalToken>>
createEvictingQueueForTokens() {
return new Pair<>(
EvictingQueue.create(multilineStartTypes.length),
EvictingQueue.create(multilineEndTypes.length));
}
@SuppressWarnings("UnstableApiUsage")
protected boolean isIncompleteTokenStart(EvictingQueue<IncrementalToken> q) {
return matchTokenTypes(this.multilineStartTypes, q);
}
@SuppressWarnings("UnstableApiUsage")
protected boolean isIncompleteTokenEnd(EvictingQueue<IncrementalToken> q) {
return matchTokenTypes(this.multilineEndTypes, q);
}
@SuppressWarnings("UnstableApiUsage")
private boolean matchTokenTypes(
@NonNull int[] types, @NonNull EvictingQueue<IncrementalToken> tokens) {
final var arr = tokens.toArray(new IncrementalToken[0]);
for (int i = 0; i < types.length; i++) {
if (types[i] != arr[i].getType()) {
return false;
}
}
return true;
}
protected boolean isCodeBlockStart(IncrementalToken token) {
return blockTokens.length == 2 && token.getType() == blockTokens[0];
}
protected boolean isCodeBlockEnd(IncrementalToken token) {
return blockTokens.length == 2 && token.getType() == blockTokens[1];
}
/**
* Returns the token types which start and end a multiline token.
*
@@ -152,31 +123,6 @@ public abstract class BaseIncrementalAnalyzeManager
*/
protected abstract int[][] getMultilineTokenStartEndTypes();
/**
* Generate spans for the given {@link LineTokenizeResult}.
*
* @param tokens The tokenization result.
* @return The spans for the tokens.
*/
protected abstract List<Span> generateSpans(
final LineTokenizeResult<LineState, IncrementalToken> tokens);
/**
* Called when the analyzer finds an incomplete token in a lne.
*
* @param token The incomplete token.
*/
protected abstract void handleIncompleteToken(IncrementalToken token);
/**
* Gets the next token from lexer and return an {@link IncrementalToken}.
*
* @return The next {@link IncrementalToken}.
*/
protected IncrementalToken nextToken() {
return new IncrementalToken(lexer.nextToken());
}
/**
* Get the token types for left and right braces.
*
@@ -184,51 +130,6 @@ public abstract class BaseIncrementalAnalyzeManager
*/
protected abstract int[] getCodeBlockTokens();
/**
* Pop (remove) required number of tokens after an incomplete token has been encountered. <br>
*
* <p>For example: <br>
* When ['/', '*'] tokens are encountered, the '*' token must be removed. In this case, <code>
* incompleteToken</code> parameter will point to '/' token.
*
* <p>By default, this method removes only the last token.
*
* @param incompleteToken The token which is the start of the incomplete token.
* @param tokens The list of tokens from which extra tokens must be removed.
*/
protected void popTokensAfterIncomplete(
@NonNull IncrementalToken incompleteToken, @NonNull List<IncrementalToken> tokens) {
tokens.remove(tokens.size() - 1);
}
@NonNull
protected CharStream createStream(@NonNull CharSequence source) {
Objects.requireNonNull(source);
try {
return CharStreams.fromReader(new CharSequenceReader(source));
} catch (IOException e) {
throw new RuntimeException("Cannot create CharStream for source", e);
}
}
protected void handleLineCommentSpan(
@NonNull IncrementalToken token, @NonNull List<Span> spans, int offset) {
var commentType = SchemeAndroidIDE.COMMENT;
// highlight special line comments
var commentText = token.getText();
if (commentText.length() > 2) {
commentText = commentText.substring(2);
commentText = commentText.trim();
if ("todo".equalsIgnoreCase(commentText.substring(0, 4))) {
commentType = TODO_COMMENT;
} else if ("fixme".equalsIgnoreCase(commentText.substring(0, 5))) {
commentType = FIXME_COMMENT;
}
}
spans.add(Span.obtain(offset, withoutCompletion(commentType)));
}
@Override
public LineState getInitialState() {
return new LineState();
@@ -239,6 +140,52 @@ public abstract class BaseIncrementalAnalyzeManager
return state.equals(another);
}
@Override
public LineTokenizeResult<LineState, IncrementalToken> tokenizeLine(
final CharSequence line, final LineState state) {
final var tokens = new ArrayList<IncrementalToken>();
var newState = 0;
var stateObj = new LineState();
if (state.state == NORMAL) {
newState = tokenizeNormal(line, 0, tokens, stateObj, state.lexerMode);
} else if (state.state == INCOMPLETE) {
final var result = fillIncomplete(line, tokens, state.lexerMode);
newState = IntPair.getFirst(result);
if (newState == NORMAL) {
newState =
tokenizeNormal(line, IntPair.getSecond(result), tokens, stateObj, state.lexerMode);
} else {
newState = INCOMPLETE;
}
}
stateObj.state = newState;
stateObj.lexerMode = lexer._mode;
return new LineTokenizeResult<>(stateObj, tokens);
}
@Override
public List<Span> generateSpansForLine(
final LineTokenizeResult<LineState, IncrementalToken> tokens) {
var result = generateSpans(tokens);
Objects.requireNonNull(result);
if (result.isEmpty()) {
result.add(Span.obtain(0, TextStyle.makeStyle(SchemeAndroidIDE.TEXT_NORMAL)));
}
return result;
}
/**
* Generate spans for the given {@link LineTokenizeResult}.
*
* @param tokens The tokenization result.
* @return The spans for the tokens.
*/
protected abstract List<Span> generateSpans(
final LineTokenizeResult<LineState, IncrementalToken> tokens);
@Override
public List<CodeBlock> computeBlocks(
final Content text,
@@ -292,27 +239,73 @@ public abstract class BaseIncrementalAnalyzeManager
return blocks;
}
@Override
public LineTokenizeResult<LineState, IncrementalToken> tokenizeLine(
final CharSequence line, final LineState state) {
final var tokens = new ArrayList<IncrementalToken>();
var newState = 0;
var stateObj = new LineState();
if (state.state == NORMAL) {
newState = tokenizeNormal(line, 0, tokens, stateObj, state.lexerMode);
} else if (state.state == INCOMPLETE) {
final var result = fillIncomplete(line, tokens, state.lexerMode);
newState = IntPair.getFirst(result);
if (newState == NORMAL) {
newState =
tokenizeNormal(line, IntPair.getSecond(result), tokens, stateObj, state.lexerMode);
} else {
newState = INCOMPLETE;
protected boolean isCodeBlockStart(IncrementalToken token) {
return blockTokens.length == 2 && token.getType() == blockTokens[0];
}
protected boolean isCodeBlockEnd(IncrementalToken token) {
return blockTokens.length == 2 && token.getType() == blockTokens[1];
}
@SuppressWarnings("UnstableApiUsage")
protected boolean isIncompleteTokenStart(EvictingQueue<IncrementalToken> q) {
return matchTokenTypes(this.multilineStartTypes, q);
}
@SuppressWarnings("UnstableApiUsage")
protected boolean isIncompleteTokenEnd(EvictingQueue<IncrementalToken> q) {
return matchTokenTypes(this.multilineEndTypes, q);
}
/**
* Called when the analyzer finds an incomplete token in a lne.
*
* @param token The incomplete token.
*/
protected abstract void handleIncompleteToken(IncrementalToken token);
/**
* Gets the next token from lexer and return an {@link IncrementalToken}.
*
* @return The next {@link IncrementalToken}.
*/
protected IncrementalToken nextToken() {
return new IncrementalToken(lexer.nextToken());
}
/**
* Pop (remove) required number of tokens after an incomplete token has been encountered. <br>
*
* <p>For example: <br>
* When ['/', '*'] tokens are encountered, the '*' token must be removed. In this case, <code>
* incompleteToken</code> parameter will point to '/' token.
*
* <p>By default, this method removes only the last token.
*
* @param incompleteToken The token which is the start of the incomplete token.
* @param tokens The list of tokens from which extra tokens must be removed.
*/
protected void popTokensAfterIncomplete(
@NonNull IncrementalToken incompleteToken, @NonNull List<IncrementalToken> tokens) {
tokens.remove(tokens.size() - 1);
}
protected void handleLineCommentSpan(
@NonNull IncrementalToken token, @NonNull List<Span> spans, int offset) {
var commentType = SchemeAndroidIDE.COMMENT;
// highlight special line comments
var commentText = token.getText();
if (commentText.length() > 2) {
commentText = commentText.substring(2);
commentText = commentText.trim();
if ("todo".equalsIgnoreCase(commentText.substring(0, 4))) {
commentType = TODO_COMMENT;
} else if ("fixme".equalsIgnoreCase(commentText.substring(0, 5))) {
commentType = FIXME_COMMENT;
}
}
stateObj.state = newState;
stateObj.lexerMode = lexer._mode;
return new LineTokenizeResult<>(stateObj, tokens);
spans.add(Span.obtain(offset, withoutCompletion(commentType)));
}
/**
@@ -445,17 +438,24 @@ public abstract class BaseIncrementalAnalyzeManager
}
}
@Override
public List<Span> generateSpansForLine(
final LineTokenizeResult<LineState, IncrementalToken> tokens) {
var result = generateSpans(tokens);
Objects.requireNonNull(result);
if (result.isEmpty()) {
result.add(Span.obtain(0, TextStyle.makeStyle(SchemeAndroidIDE.TEXT_NORMAL)));
@SuppressWarnings("UnstableApiUsage")
@NonNull
private Pair<EvictingQueue<IncrementalToken>, EvictingQueue<IncrementalToken>>
createEvictingQueueForTokens() {
return new Pair<>(
EvictingQueue.create(multilineStartTypes.length),
EvictingQueue.create(multilineEndTypes.length));
}
return result;
@SuppressWarnings("UnstableApiUsage")
private boolean matchTokenTypes(
@NonNull int[] types, @NonNull EvictingQueue<IncrementalToken> tokens) {
final var arr = tokens.toArray(new IncrementalToken[0]);
for (int i = 0; i < types.length; i++) {
if (types[i] != arr[i].getType()) {
return false;
}
}
return true;
}
}
@@ -30,10 +30,8 @@ import com.itsaky.androidide.syntax.colorschemes.SchemeAndroidIDE.forKeyword
import com.itsaky.androidide.syntax.colorschemes.SchemeAndroidIDE.forString
import com.itsaky.androidide.utils.ILogger
import io.github.rosemoe.sora.lang.analysis.IncrementalAnalyzeManager.LineTokenizeResult
import io.github.rosemoe.sora.lang.styling.CodeBlock
import io.github.rosemoe.sora.lang.styling.Span
import io.github.rosemoe.sora.lang.styling.TextStyle.makeStyle
import io.github.rosemoe.sora.text.Content
/** @author Akash Yadav */
class JavaAnalyzer : BaseIncrementalAnalyzeManager(JavaLexer::class.java) {
@@ -63,36 +63,6 @@ public class JavaLanguage extends IDELanguage {
this.newlineHandlers[0] = new BraceHandler();
}
@Override
public int getIndentAdvance(@NonNull String line) {
try {
JavaLexer lexer = new JavaLexer(CharStreams.fromReader(new StringReader(line)));
Token token;
int advance = 0;
while (((token = lexer.nextToken()) != null && token.getType() != token.EOF)) {
switch (token.getType()) {
case JavaLexer.LBRACE:
advance++;
break;
case JavaParser.RBRACE:
advance--;
break;
}
}
advance = Math.max(0, advance);
return advance * getTabSize();
} catch (Throwable e) {
LOG.error("Error calculating indent advance", e);
}
return 0;
}
@Override
public SymbolPairMatch getSymbolPairs() {
return new JavaSymbolPairs();
}
@NonNull
@Override
public AnalyzeManager getAnalyzeManager() {
@@ -127,11 +97,41 @@ public class JavaLanguage extends IDELanguage {
return getIndentAdvance(content.getLine(line).substring(0, column));
}
@Override
public int getIndentAdvance(@NonNull String line) {
try {
JavaLexer lexer = new JavaLexer(CharStreams.fromReader(new StringReader(line)));
Token token;
int advance = 0;
while (((token = lexer.nextToken()) != null && token.getType() != token.EOF)) {
switch (token.getType()) {
case JavaLexer.LBRACE:
advance++;
break;
case JavaParser.RBRACE:
advance--;
break;
}
}
advance = Math.max(0, advance);
return advance * getTabSize();
} catch (Throwable e) {
LOG.error("Error calculating indent advance", e);
}
return 0;
}
@Override
protected ILanguageServer getLanguageServer() {
return StudioApp.getInstance().getJavaLanguageServer();
}
@Override
public SymbolPairMatch getSymbolPairs() {
return new JavaSymbolPairs();
}
@Override
public NewlineHandler[] getNewlineHandlers() {
return newlineHandlers;
@@ -29,10 +29,8 @@ import com.itsaky.androidide.syntax.colorschemes.SchemeAndroidIDE.forComment
import com.itsaky.androidide.syntax.colorschemes.SchemeAndroidIDE.forKeyword
import com.itsaky.androidide.syntax.colorschemes.SchemeAndroidIDE.forString
import io.github.rosemoe.sora.lang.analysis.IncrementalAnalyzeManager.LineTokenizeResult
import io.github.rosemoe.sora.lang.styling.CodeBlock
import io.github.rosemoe.sora.lang.styling.Span
import io.github.rosemoe.sora.lang.styling.TextStyle.makeStyle
import io.github.rosemoe.sora.text.Content
/**
* Incremental syntax analyzer for Kotlin.
@@ -22,15 +22,14 @@ import android.os.Bundle;
import androidx.annotation.NonNull;
import com.itsaky.androidide.language.IDELanguage;
import com.itsaky.androidide.lexers.kotlin.KotlinLexer;
import com.itsaky.androidide.lexers.kotlin.KotlinParser;
import com.itsaky.androidide.utils.ILogger;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.Token;
import java.io.StringReader;
import com.itsaky.androidide.lexers.kotlin.KotlinLexer;
import com.itsaky.androidide.lexers.kotlin.KotlinParser;
import io.github.rosemoe.sora.lang.analysis.AnalyzeManager;
import io.github.rosemoe.sora.lang.completion.CompletionCancelledException;
@@ -45,42 +44,13 @@ import io.github.rosemoe.sora.widget.SymbolPairMatch;
public class KotlinLanguage extends IDELanguage {
private static final ILogger LOG = ILogger.newInstance("KotlinLanguage");
private KotlinAnalyzer analyzer;
private final NewlineHandler[] newlineHandlers = new NewlineHandler[] {new BraceHandler()};
private KotlinAnalyzer analyzer;
public KotlinLanguage() {
analyzer = new KotlinAnalyzer();
}
@Override
public int getIndentAdvance(@NonNull String line) {
try {
KotlinLexer lexer = new KotlinLexer(CharStreams.fromReader(new StringReader(line)));
Token token;
int advance = 0;
while (((token = lexer.nextToken()) != null && token.getType() != token.EOF)) {
switch (token.getType()) {
case KotlinParser.LCURL:
advance++;
break;
case KotlinParser.RCURL:
advance--;
break;
}
}
advance = Math.max(0, advance);
return advance * getTabSize();
} catch (Throwable e) {
LOG.error("Error calculating indent advance", e);
}
return 0;
}
@Override
public SymbolPairMatch getSymbolPairs() {
return new KotlinSymbolPairs();
}
@NonNull
@Override
public AnalyzeManager getAnalyzeManager() {
@@ -109,8 +79,8 @@ public class KotlinLanguage extends IDELanguage {
}
@Override
public CharSequence format(CharSequence content) {
return content;
public SymbolPairMatch getSymbolPairs() {
return new KotlinSymbolPairs();
}
@Override
@@ -123,6 +93,35 @@ public class KotlinLanguage extends IDELanguage {
analyzer = null;
}
@Override
public CharSequence format(CharSequence content) {
return content;
}
@Override
public int getIndentAdvance(@NonNull String line) {
try {
KotlinLexer lexer = new KotlinLexer(CharStreams.fromReader(new StringReader(line)));
Token token;
int advance = 0;
while (((token = lexer.nextToken()) != null && token.getType() != token.EOF)) {
switch (token.getType()) {
case KotlinParser.LCURL:
advance++;
break;
case KotlinParser.RCURL:
advance--;
break;
}
}
advance = Math.max(0, advance);
return advance * getTabSize();
} catch (Throwable e) {
LOG.error("Error calculating indent advance", e);
}
return 0;
}
private static class KotlinSymbolPairs extends SymbolPairMatch {
public KotlinSymbolPairs() {
super.putPair('{', new Replacement("{}", 1));
@@ -57,38 +57,6 @@ public class XMLLanguage extends IDELanguage {
this.newlineHandlers = new NewlineHandler[0];
}
@Override
public int getIndentAdvance(@NonNull String content) {
try {
XMLLexer lexer = new XMLLexer(CharStreams.fromReader(new StringReader(content)));
Token token;
int advance = 0;
while (((token = lexer.nextToken()) != null && token.getType() != token.EOF)) {
switch (token.getType()) {
case XMLLexer.OPEN:
advance++;
break;
case XMLLexer.CLOSE:
case XMLLexer.SLASH_CLOSE:
advance--;
break;
default:
break;
}
}
advance = Math.max(0, advance);
return advance * getTabSize();
} catch (Throwable e) {
LOG.error("Failed to compute indent advance", e);
}
return 0;
}
@Override
public SymbolPairMatch getSymbolPairs() {
return new SymbolPairMatch.DefaultSymbolPairs();
}
@NonNull
@Override
public AnalyzeManager getAnalyzeManager() {
@@ -125,11 +93,43 @@ public class XMLLanguage extends IDELanguage {
return getIndentAdvance(text.trim());
}
@Override
public int getIndentAdvance(@NonNull String content) {
try {
XMLLexer lexer = new XMLLexer(CharStreams.fromReader(new StringReader(content)));
Token token;
int advance = 0;
while (((token = lexer.nextToken()) != null && token.getType() != token.EOF)) {
switch (token.getType()) {
case XMLLexer.OPEN:
advance++;
break;
case XMLLexer.CLOSE:
case XMLLexer.SLASH_CLOSE:
advance--;
break;
default:
break;
}
}
advance = Math.max(0, advance);
return advance * getTabSize();
} catch (Throwable e) {
LOG.error("Failed to compute indent advance", e);
}
return 0;
}
@Override
protected ILanguageServer getLanguageServer() {
return StudioApp.getInstance().getXMLLanguageServer();
}
@Override
public SymbolPairMatch getSymbolPairs() {
return new SymbolPairMatch.DefaultSymbolPairs();
}
@Override
public NewlineHandler[] getNewlineHandlers() {
return newlineHandlers;
@@ -19,7 +19,6 @@
*/
package com.itsaky.androidide.lsp;
import android.os.Trace;
import android.view.View;
import androidx.annotation.NonNull;
@@ -73,25 +72,20 @@ import io.github.rosemoe.sora.text.Content;
/** AndroidIDE specific implementation of the LanguageClient */
public class IDELanguageClientImpl implements ILanguageClient {
public static final int MAX_DIAGNOSTIC_FILES = 10;
public static final int MAX_DIAGNOSTIC_ITEMS_PER_FILE = 20;
protected static final Gson gson = new Gson();
protected static final ILogger LOG = ILogger.newInstance("AbstractLanguageClient");
private static IDELanguageClientImpl mInstance;
private final Map<File, List<DiagnosticItem>> diagnostics = new HashMap<>();
protected EditorActivityProvider activityProvider;
public static final int MAX_DIAGNOSTIC_FILES = 10;
public static final int MAX_DIAGNOSTIC_ITEMS_PER_FILE = 20;
private IDELanguageClientImpl(EditorActivityProvider provider) {
setActivityProvider(provider);
}
public static IDELanguageClientImpl getInstance() {
if (mInstance == null) {
throw new IllegalStateException("Client not initialized");
}
return mInstance;
public void setActivityProvider(EditorActivityProvider provider) {
this.activityProvider = provider;
}
public static IDELanguageClientImpl initialize(EditorActivityProvider provider) {
@@ -104,6 +98,14 @@ public class IDELanguageClientImpl implements ILanguageClient {
return getInstance();
}
public static IDELanguageClientImpl getInstance() {
if (mInstance == null) {
throw new IllegalStateException("Client not initialized");
}
return mInstance;
}
public static void shutdown() {
mInstance = null;
}
@@ -112,19 +114,6 @@ public class IDELanguageClientImpl implements ILanguageClient {
return mInstance != null;
}
public void setActivityProvider(EditorActivityProvider provider) {
this.activityProvider = provider;
}
protected EditorActivity activity() {
if (activityProvider == null) return null;
return activityProvider.provide();
}
private CodeEditorView findEditorByFile(File file) {
return activity().getEditorForFile(file);
}
public void hideDiagnostics() {
if (activity() == null || activity().getDiagnosticBinding() == null) {
return;
@@ -133,21 +122,6 @@ public class IDELanguageClientImpl implements ILanguageClient {
activity().getDiagnosticBinding().getRoot().setVisibility(View.GONE);
}
private void hideBottomDiagnosticView(final File file) {
if (activity() == null || file == null) {
return;
}
final var frag = findEditorByFile(file);
if (frag == null || frag.getBinding() == null) {
return;
}
frag.getBinding().diagnosticTextContainer.setVisibility(View.GONE);
frag.getBinding().diagnosticText.setVisibility(View.GONE);
frag.getBinding().diagnosticText.setClickable(false);
}
@Override
public void publishDiagnostics(DiagnosticResult result) {
boolean error = result == null;
@@ -181,66 +155,17 @@ public class IDELanguageClientImpl implements ILanguageClient {
activity().setDiagnosticsAdapter(newDiagnosticsAdapter());
}
protected EditorActivity activity() {
if (activityProvider == null) return null;
return activityProvider.provide();
}
@Nullable
@Override
public DiagnosticItem getDiagnosticAt(final File file, final int line, final int column) {
return DiagnosticUtil.binarySearchDiagnostic(this.diagnostics.get(file), line, column);
}
/** Called by {@link IDEEditor IDEEditor} to show locations in EditorActivity */
public void showLocations(List<Location> locations) {
// Cannot show anything if the activity() is null
if (activity() == null) {
return;
}
boolean error = locations == null || locations.isEmpty();
activity().handleSearchResultVisibility(error);
if (error) {
activity().setSearchResultAdapter(new SearchListAdapter(null, null, null));
return;
}
final Map<File, List<SearchResult>> results = new HashMap<>();
for (int i = 0; i < locations.size(); i++) {
try {
final Location loc = locations.get(i);
if (loc == null) {
continue;
}
final File file = loc.getFile().toFile();
if (!file.exists() || !file.isFile()) continue;
var frag = findEditorByFile(file);
Content content;
if (frag != null && frag.getEditor() != null) content = frag.getEditor().getText();
else content = new Content(FileIOUtils.readFile2String(file));
final List<SearchResult> matches =
results.containsKey(file) ? results.get(file) : new ArrayList<>();
Objects.requireNonNull(matches)
.add(
new SearchResult(
loc.getRange(),
file,
content.getLineString(loc.getRange().getStart().getLine()),
content
.subContent(
loc.getRange().getStart().getLine(),
loc.getRange().getStart().getColumn(),
loc.getRange().getEnd().getLine(),
loc.getRange().getEnd().getColumn())
.toString()));
results.put(file, matches);
} catch (Throwable th) {
LOG.error("Failed to show file location", th);
}
}
activity().handleSearchResults(results);
}
@Override
public void performCodeAction(File file, CodeActionItem actionItem) {
final var editor = activity().getEditorForFile(file);
@@ -289,6 +214,108 @@ public class IDELanguageClientImpl implements ILanguageClient {
});
}
private Boolean performCodeActionAsync(final IDEEditor editor, final CodeActionItem action) {
LOG.debug("Performing code action:", action);
final var changes = action.getChanges();
if (changes.isEmpty()) {
return Boolean.FALSE;
}
for (var change : changes) {
final var path = change.getFile();
if (path == null) {
continue;
}
final File file = path.toFile();
if (!file.exists()) {
continue;
}
for (TextEdit edit : change.getEdits()) {
final String editorFilepath =
editor.getFile() == null ? "" : editor.getFile().getAbsolutePath();
if (file.getAbsolutePath().equals(editorFilepath)) {
// Edit is in the same editor which requested the code action
editInEditor(editor, edit);
} else {
var openedFrag = findEditorByFile(file);
if (openedFrag != null && openedFrag.getEditor() != null) {
// Edit is in another 'opened' file
editInEditor(openedFrag.getEditor(), edit);
} else {
// Edit is in some other file which is not opened
// We should open that file and perform the edit
openedFrag = activity().openFile(file);
if (openedFrag != null && openedFrag.getEditor() != null) {
editInEditor(openedFrag.getEditor(), edit);
}
}
}
}
}
return Boolean.TRUE;
}
private void editInEditor(final IDEEditor editor, final TextEdit edit) {
final Range range = edit.getRange();
final int startLine = range.getStart().getLine();
final int startCol = range.getStart().getColumn();
final int endLine = range.getEnd().getLine();
final int endCol = range.getEnd().getColumn();
activity()
.runOnUiThread(
() -> {
if (startLine == endLine && startCol == endCol) {
editor.getText().insert(startLine, startCol, edit.getNewText());
} else {
editor.getText().replace(startLine, startCol, endLine, endCol, edit.getNewText());
}
});
}
@Override
public com.itsaky.lsp.models.ShowDocumentResult showDocument(
com.itsaky.lsp.models.ShowDocumentParams params) {
boolean success = false;
final var result = new com.itsaky.lsp.models.ShowDocumentResult(false);
if (activity() == null) {
return result;
}
if (params != null) {
File file = params.getFile().toFile();
if (file.exists() && file.isFile() && FileUtils.isUtf8(file)) {
final var range = params.getSelection();
var frag =
activity().getEditorAtIndex(activity().getBinding().tabs.getSelectedTabPosition());
if (frag != null
&& frag.getFile() != null
&& frag.getEditor() != null
&& frag.getFile().getAbsolutePath().equals(file.getAbsolutePath())) {
if (LSPUtils.isEqual(range.getStart(), range.getEnd())) {
frag.getEditor().setSelection(range.getStart().getLine(), range.getStart().getColumn());
} else {
frag.getEditor().setSelection(range);
}
} else {
activity().openFileAndSelect(file, range);
}
success = true;
}
}
result.setSuccess(success);
return result;
}
public DiagnosticsAdapter newDiagnosticsAdapter() {
return new DiagnosticsAdapter(mapAsGroup(this.diagnostics), activity());
}
private List<DiagnosticGroup> mapAsGroup(Map<File, List<DiagnosticItem>> map) {
final var groups = new ArrayList<DiagnosticGroup>();
var diagnosticMap = map;
@@ -364,6 +391,79 @@ public class IDELanguageClientImpl implements ILanguageClient {
return result;
}
/** Called by {@link IDEEditor IDEEditor} to show locations in EditorActivity */
public void showLocations(List<Location> locations) {
// Cannot show anything if the activity() is null
if (activity() == null) {
return;
}
boolean error = locations == null || locations.isEmpty();
activity().handleSearchResultVisibility(error);
if (error) {
activity().setSearchResultAdapter(new SearchListAdapter(null, null, null));
return;
}
final Map<File, List<SearchResult>> results = new HashMap<>();
for (int i = 0; i < locations.size(); i++) {
try {
final Location loc = locations.get(i);
if (loc == null) {
continue;
}
final File file = loc.getFile().toFile();
if (!file.exists() || !file.isFile()) continue;
var frag = findEditorByFile(file);
Content content;
if (frag != null && frag.getEditor() != null) content = frag.getEditor().getText();
else content = new Content(FileIOUtils.readFile2String(file));
final List<SearchResult> matches =
results.containsKey(file) ? results.get(file) : new ArrayList<>();
Objects.requireNonNull(matches)
.add(
new SearchResult(
loc.getRange(),
file,
content.getLineString(loc.getRange().getStart().getLine()),
content
.subContent(
loc.getRange().getStart().getLine(),
loc.getRange().getStart().getColumn(),
loc.getRange().getEnd().getLine(),
loc.getRange().getEnd().getColumn())
.toString()));
results.put(file, matches);
} catch (Throwable th) {
LOG.error("Failed to show file location", th);
}
}
activity().handleSearchResults(results);
}
private CodeEditorView findEditorByFile(File file) {
return activity().getEditorForFile(file);
}
private void hideBottomDiagnosticView(final File file) {
if (activity() == null || file == null) {
return;
}
final var frag = findEditorByFile(file);
if (frag == null || frag.getBinding() == null) {
return;
}
frag.getBinding().diagnosticTextContainer.setVisibility(View.GONE);
frag.getBinding().diagnosticText.setVisibility(View.GONE);
frag.getBinding().diagnosticText.setClickable(false);
}
private void showAvailableQuickfixes(IDEEditor editor, List<CodeActionItem> actions) {
final MaterialAlertDialogBuilder builder = DialogUtils.newMaterialDialogBuilder(activity());
builder.setTitle(R.string.msg_code_actions);
@@ -386,109 +486,7 @@ public class IDELanguageClientImpl implements ILanguageClient {
return arr;
}
private Boolean performCodeActionAsync(final IDEEditor editor, final CodeActionItem action) {
LOG.debug("Performing code action:", action);
final var changes = action.getChanges();
if (changes.isEmpty()) {
return Boolean.FALSE;
}
for (var change : changes) {
final var path = change.getFile();
if (path == null) {
continue;
}
final File file = path.toFile();
if (!file.exists()) {
continue;
}
for (TextEdit edit : change.getEdits()) {
final String editorFilepath =
editor.getFile() == null ? "" : editor.getFile().getAbsolutePath();
if (file.getAbsolutePath().equals(editorFilepath)) {
// Edit is in the same editor which requested the code action
editInEditor(editor, edit);
} else {
var openedFrag = findEditorByFile(file);
if (openedFrag != null && openedFrag.getEditor() != null) {
// Edit is in another 'opened' file
editInEditor(openedFrag.getEditor(), edit);
} else {
// Edit is in some other file which is not opened
// We should open that file and perform the edit
openedFrag = activity().openFile(file);
if (openedFrag != null && openedFrag.getEditor() != null) {
editInEditor(openedFrag.getEditor(), edit);
}
}
}
}
}
return Boolean.TRUE;
}
private void execCommand(IDEEditor editor, Command command) {
editor.executeCommand(command);
}
private void editInEditor(final IDEEditor editor, final TextEdit edit) {
final Range range = edit.getRange();
final int startLine = range.getStart().getLine();
final int startCol = range.getStart().getColumn();
final int endLine = range.getEnd().getLine();
final int endCol = range.getEnd().getColumn();
activity()
.runOnUiThread(
() -> {
if (startLine == endLine && startCol == endCol) {
editor.getText().insert(startLine, startCol, edit.getNewText());
} else {
editor.getText().replace(startLine, startCol, endLine, endCol, edit.getNewText());
}
});
}
public DiagnosticsAdapter newDiagnosticsAdapter() {
return new DiagnosticsAdapter(mapAsGroup(this.diagnostics), activity());
}
@Override
public com.itsaky.lsp.models.ShowDocumentResult showDocument(
com.itsaky.lsp.models.ShowDocumentParams params) {
boolean success = false;
final var result = new com.itsaky.lsp.models.ShowDocumentResult(false);
if (activity() == null) {
return result;
}
if (params != null) {
File file = params.getFile().toFile();
if (file.exists() && file.isFile() && FileUtils.isUtf8(file)) {
final var range = params.getSelection();
var frag =
activity().getEditorAtIndex(activity().getBinding().tabs.getSelectedTabPosition());
if (frag != null
&& frag.getFile() != null
&& frag.getEditor() != null
&& frag.getFile().getAbsolutePath().equals(file.getAbsolutePath())) {
if (LSPUtils.isEqual(range.getStart(), range.getEnd())) {
frag.getEditor().setSelection(range.getStart().getLine(), range.getStart().getColumn());
} else {
frag.getEditor().setSelection(range);
}
} else {
activity().openFileAndSelect(file, range);
}
success = true;
}
}
result.setSuccess(success);
return result;
}
}
@@ -143,6 +143,10 @@ public class ApkMetadata {
return elements;
}
public void setElements(List<Element> elements) {
this.elements = elements;
}
public ArtifactType getArtifactType() {
return artifactType;
}
@@ -151,10 +155,6 @@ public class ApkMetadata {
this.artifactType = artifactType;
}
public void setElements(List<Element> elements) {
this.elements = elements;
}
public int getVersion() {
return version;
}
@@ -21,10 +21,6 @@ import androidx.annotation.DrawableRes;
public interface IconTextListItem {
String getText();
int getIconResource();
public static IconTextListItem create(String name, @DrawableRes int icon) {
return new IconTextListItem() {
@Override
@@ -38,4 +34,8 @@ public interface IconTextListItem {
}
};
}
String getText();
int getIconResource();
}
@@ -46,17 +46,12 @@ public class NewProjectDetails {
this.savePath = savePath;
}
public NewProjectDetails setName(String name) {
this.name = name;
return this;
}
public String getName() {
return name;
}
public NewProjectDetails setPackageName(String packageName) {
this.packageName = packageName;
public NewProjectDetails setName(String name) {
this.name = name;
return this;
}
@@ -64,8 +59,8 @@ public class NewProjectDetails {
return packageName;
}
public NewProjectDetails setMinSdk(int minSdk) {
this.minSdk = minSdk;
public NewProjectDetails setPackageName(String packageName) {
this.packageName = packageName;
return this;
}
@@ -73,8 +68,8 @@ public class NewProjectDetails {
return minSdk;
}
public NewProjectDetails setTargetSdk(int targetSdk) {
this.targetSdk = targetSdk;
public NewProjectDetails setMinSdk(int minSdk) {
this.minSdk = minSdk;
return this;
}
@@ -82,12 +77,17 @@ public class NewProjectDetails {
return targetSdk;
}
public NewProjectDetails setCppFlags(String cppFlags) {
this.cppFlags = cppFlags;
public NewProjectDetails setTargetSdk(int targetSdk) {
this.targetSdk = targetSdk;
return this;
}
public String getCppFlags() {
return cppFlags;
}
public NewProjectDetails setCppFlags(String cppFlags) {
this.cppFlags = cppFlags;
return this;
}
}
@@ -42,39 +42,43 @@ public class ProjectTemplate {
this.imageId = imageId;
}
public int getId() {
return id;
}
public ProjectTemplate setId(int id) {
this.id = id;
return this;
}
public int getId() {
return id;
}
public ProjectTemplate setName(Context ctx, @StringRes int name) {
return setName(ctx.getString(name));
}
public String getName() {
return name;
}
public ProjectTemplate setName(String name) {
this.name = name;
return this;
}
public String getName() {
return name;
}
public ProjectTemplate setDescription(Context ctx, @StringRes int desc) {
return setDescription(ctx.getString(desc));
}
public String getDescription() {
return description;
}
public ProjectTemplate setDescription(String description) {
this.description = description;
return this;
}
public String getDescription() {
return description;
public int getImageId() {
return imageId;
}
public ProjectTemplate setImageId(@DrawableRes int imageId) {
@@ -82,10 +86,6 @@ public class ProjectTemplate {
return this;
}
public int getImageId() {
return imageId;
}
public boolean isSupportJava() {
return this.isSupportJava;
}
@@ -32,9 +32,20 @@ import java.util.Objects;
*/
public class UIWidget implements IconTextListItem, Parcelable {
public static final Creator<UIWidget> CREATOR =
new Creator<UIWidget>() {
@Override
public UIWidget createFromParcel(Parcel in) {
return new UIWidget(in);
}
@Override
public UIWidget[] newArray(int size) {
return new UIWidget[size];
}
};
private final String name;
private final int icon;
private final String clazz;
private UIWidget(Parcel in) {
@@ -49,25 +60,9 @@ public class UIWidget implements IconTextListItem, Parcelable {
this.clazz = clazz.getName();
}
public static final Creator<UIWidget> CREATOR =
new Creator<UIWidget>() {
@Override
public UIWidget createFromParcel(Parcel in) {
return new UIWidget(in);
}
@Override
public UIWidget[] newArray(int size) {
return new UIWidget[size];
}
};
public String getName() {
return name;
}
public int getIcon() {
return icon;
public int hashCode() {
return Objects.hash(getName(), getIcon(), clazz);
}
@Override
@@ -80,9 +75,12 @@ public class UIWidget implements IconTextListItem, Parcelable {
&& clazz.equals(widget.clazz);
}
@Override
public int hashCode() {
return Objects.hash(getName(), getIcon(), clazz);
public String getName() {
return name;
}
public int getIcon() {
return icon;
}
/**
@@ -38,27 +38,6 @@ import java.util.Objects;
*/
public class UIWidgetGroup implements IconTextListItem, Parcelable {
/** Name of this group. */
private final String name;
/** Children of this group. */
private final List<UIWidget> children;
/** Is this group currently selected in the group list? */
private boolean selected;
public UIWidgetGroup(String name) {
this.name = name;
this.selected = false;
this.children = new ArrayList<>();
}
protected UIWidgetGroup(@NonNull Parcel in) {
this.name = in.readString();
this.children = in.createTypedArrayList(UIWidget.CREATOR);
this.selected = in.readByte() != 0;
}
public static final Creator<UIWidgetGroup> CREATOR =
new Creator<UIWidgetGroup>() {
@@ -76,32 +55,23 @@ public class UIWidgetGroup implements IconTextListItem, Parcelable {
return new UIWidgetGroup[size];
}
};
/** Name of this group. */
private final String name;
/** Children of this group. */
private final List<UIWidget> children;
/** Is this group currently selected in the group list? */
private boolean selected;
/**
* Get the name of this group.
*
* @return The name of this group.
*/
public String getName() {
return name;
public UIWidgetGroup(String name) {
this.name = name;
this.selected = false;
this.children = new ArrayList<>();
}
/**
* Get the children of this group.
*
* @return The children.
*/
@NonNull
public List<UIWidget> getChildren() {
return children;
}
public void setSelected(boolean selected) {
this.selected = selected;
}
public boolean isSelected() {
return selected;
protected UIWidgetGroup(@NonNull Parcel in) {
this.name = in.readString();
this.children = in.createTypedArrayList(UIWidget.CREATOR);
this.selected = in.readByte() != 0;
}
/**
@@ -129,6 +99,11 @@ public class UIWidgetGroup implements IconTextListItem, Parcelable {
return children.get(index);
}
@Override
public int hashCode() {
return Objects.hash(getName(), getChildren(), isSelected());
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
@@ -139,9 +114,31 @@ public class UIWidgetGroup implements IconTextListItem, Parcelable {
&& getChildren().equals(group.getChildren());
}
@Override
public int hashCode() {
return Objects.hash(getName(), getChildren(), isSelected());
/**
* Get the name of this group.
*
* @return The name of this group.
*/
public String getName() {
return name;
}
/**
* Get the children of this group.
*
* @return The children.
*/
@NonNull
public List<UIWidget> getChildren() {
return children;
}
public boolean isSelected() {
return selected;
}
public void setSelected(boolean selected) {
this.selected = selected;
}
@Override
@@ -114,14 +114,6 @@ public class XMLAttribute extends UiAttribute implements Parcelable {
return new XMLAttribute(INamespace.ANDROID, name, "", false);
}
public int getFormat() {
return format;
}
public void setFormat(int format) {
this.format = format;
}
public int findFormat() {
if (getFormat() > 0) {
@@ -137,20 +129,18 @@ public class XMLAttribute extends UiAttribute implements Parcelable {
return getFormat();
}
public int getFormat() {
return format;
}
public void setFormat(int format) {
this.format = format;
}
public boolean hasFormat(int format) {
return (this.format & format) != 0;
}
public Attr getAttr() {
return attr;
}
public void setAttr(Attr attr) {
Objects.requireNonNull(attr);
this.attr = attr;
setFormat(attr.format);
}
@Override
public void apply(String value) {
super.apply(value);
@@ -175,4 +165,14 @@ public class XMLAttribute extends UiAttribute implements Parcelable {
dest.writeParcelable(getAttr(), flags);
dest.writeInt(this.format);
}
public Attr getAttr() {
return attr;
}
public void setAttr(Attr attr) {
Objects.requireNonNull(attr);
this.attr = attr;
setFormat(attr.format);
}
}
@@ -123,7 +123,8 @@ class CachingProject(val project: IProject) : IProject {
log.warn(
"Unable to get variant data for " +
"variant ${request.variantName} ('${request.projectPath}') from tooling server",
u)
u
)
return@whenComplete
}
@@ -75,8 +75,7 @@ object ProjectManager {
getApplicationModule().whenCompleteAsync { app, _ ->
if (app == null) {
log.warn(
"Cannot run resource and source generation task. No application module found.")
log.warn("Cannot run resource and source generation task. No application module found.")
return@whenCompleteAsync
}
@@ -98,12 +97,14 @@ object ProjectManager {
// If view binding is enabled, generate the view binding classes too
if (app.viewBindingOptions != null && app.viewBindingOptions!!.isEnabled)
"dataBindingGenBaseClassesDebug"
else "")
else ""
)
.whenComplete { result, taskErr ->
if (!result.isSuccessful || taskErr != null) {
log.warn(
"Execution for tasks '$genResourcesTask' and '$genSourcesTask' failed.",
taskErr ?: "")
taskErr ?: ""
)
} else {
notifyProjectUpdate()
}
@@ -113,8 +114,7 @@ object ProjectManager {
fun getApplicationModule(): CompletableFuture<IdeAndroidModule?> {
if (rootProject == null) {
log.error(
"No root project instance is set. Is the project initialization process finished?")
log.error("No root project instance is set. Is the project initialization process finished?")
return CompletableFuture.completedFuture(null)
}
@@ -80,56 +80,6 @@ public class ProjectResourceTable implements IResourceTable {
return value;
}
@Override
public String findBoolean(@NonNull String name) {
final var table = ValuesTableFactory.getTable(resDir);
if (table == null) {
return name;
}
final var resource = table.findBoolean(name);
if (resource == null) {
return name;
}
final var val = resource.getValue();
if (val.startsWith("@bool/")) {
final var ref = val.substring("@bool/".length());
if (ref.equals(name)) {
// recursive reference
return name;
}
}
return val;
}
@Override
public String findInteger(@NonNull String name) {
final var table = ValuesTableFactory.getTable(resDir);
if (table == null) {
return name;
}
final var resource = table.findInteger(name);
if (resource == null) {
return name;
}
final var val = resource.getValue();
if (val.startsWith("@integer/")) {
final var ref = val.substring("@integer/".length());
if (ref.equals(name)) {
// recursive reference
return name;
}
}
return val;
}
@Override
public String findColor(@NonNull String name) {
final var table = ValuesTableFactory.getTable(resDir);
@@ -193,6 +143,68 @@ public class ProjectResourceTable implements IResourceTable {
return value;
}
@Override
public String findBoolean(@NonNull String name) {
final var table = ValuesTableFactory.getTable(resDir);
if (table == null) {
return name;
}
final var resource = table.findBoolean(name);
if (resource == null) {
return name;
}
final var val = resource.getValue();
if (val.startsWith("@bool/")) {
final var ref = val.substring("@bool/".length());
if (ref.equals(name)) {
// recursive reference
return name;
}
}
return val;
}
@Override
public String findInteger(@NonNull String name) {
final var table = ValuesTableFactory.getTable(resDir);
if (table == null) {
return name;
}
final var resource = table.findInteger(name);
if (resource == null) {
return name;
}
final var val = resource.getValue();
if (val.startsWith("@integer/")) {
final var ref = val.substring("@integer/".length());
if (ref.equals(name)) {
// recursive reference
return name;
}
}
return val;
}
@Override
public void setInflatingFile(@NonNull File file) {
if (file.getParentFile() == null) {
throw new IllegalArgumentException("Invalid inflating file");
}
setupDirectories(
file // layout file
.getParentFile() // layout dir
.getParentFile()); // res dir
}
@NonNull
@Override
public Collection<String> listResourceNames(@Nullable String type) {
@@ -223,45 +235,6 @@ public class ProjectResourceTable implements IResourceTable {
}
}
private void listAndAddTo(HashSet<String> set, @NonNull File dir, String type) {
final var files = dir.listFiles();
if (files == null) {
return;
}
for (var file : files) {
var name = file.getName();
if (!name.contains(".")) {
continue;
}
name = name.substring(0, name.lastIndexOf('.'));
name = String.format(Locale.ROOT, "@%s/%s", type, name);
set.add(name);
}
}
@NonNull
private Collection<String> listAllResourceNames() {
final var set = new HashSet<>(listResourceNames("color"));
set.addAll(listResourceNames("drawable"));
set.addAll(listResourceNames("mipmap"));
set.addAll(listResourceNames("layout"));
return set;
}
@Override
public void setInflatingFile(@NonNull File file) {
if (file.getParentFile() == null) {
throw new IllegalArgumentException("Invalid inflating file");
}
setupDirectories(
file // layout file
.getParentFile() // layout dir
.getParentFile()); // res dir
}
private void setupDirectories(File resDir) {
if (resDir == null) {
@@ -296,6 +269,33 @@ public class ProjectResourceTable implements IResourceTable {
return null;
}
private void listAndAddTo(HashSet<String> set, @NonNull File dir, String type) {
final var files = dir.listFiles();
if (files == null) {
return;
}
for (var file : files) {
var name = file.getName();
if (!name.contains(".")) {
continue;
}
name = name.substring(0, name.lastIndexOf('.'));
name = String.format(Locale.ROOT, "@%s/%s", type, name);
set.add(name);
}
}
@NonNull
private Collection<String> listAllResourceNames() {
final var set = new HashSet<>(listResourceNames("color"));
set.addAll(listResourceNames("drawable"));
set.addAll(listResourceNames("mipmap"));
set.addAll(listResourceNames("layout"));
return set;
}
private static class NameStartsWith implements FileFilter {
private final String name;
@@ -55,9 +55,9 @@ interface BuildService {
*
* @param projectPath The path of the project. All the tasks will be executed in this project.
* @param tasks The tasks to execute. These may or may not be fully qualified names of the
* project. If the task name is not fully qualified, then it will be executed in the given
* project path. For example, if the project path is ':app' and the task is 'assembleDebug',
* then, ':app:assembleDebug' task will be executed.
* project. If the task name is not fully qualified, then it will be executed in the given project
* path. For example, if the project path is ':app' and the task is 'assembleDebug', then,
* ':app:assembleDebug' task will be executed.
* @return A [CompletableFuture] which returns a list of [TaskExecutionResult]. The result
* contains a list of tasks that were executed and the result of the whole execution.
*/
@@ -321,12 +321,6 @@ public class GradleBuildService extends Service implements BuildService, IToolin
.thenApply(this::markBuildAsFinished);
}
private String getGradleInstallationPath() {
return StudioApp.getInstance()
.getPrefManager()
.getString(BuildPreferences.KEY_CUSTOM_GRADLE_INSTALLATION, "");
}
@NonNull
@Override
public CompletableFuture<TaskExecutionResult> executeProjectTasks(
@@ -353,6 +347,12 @@ public class GradleBuildService extends Service implements BuildService, IToolin
return server.cancelCurrentBuild();
}
private String getGradleInstallationPath() {
return StudioApp.getInstance()
.getPrefManager()
.getString(BuildPreferences.KEY_CUSTOM_GRADLE_INSTALLATION, "");
}
private void checkServerStarted() {
if (!isToolingServerStarted) {
throw new IllegalStateException("Tooling API server has not been started");
@@ -29,12 +29,10 @@ import com.itsaky.androidide.utils.ILogger;
public class LogReceiver extends BroadcastReceiver {
private LogListener listener;
public static final String APPEND_LOG = "com.itsaky.androidide.logs.APPEND_LOG";
public static final String EXTRA_LINE = "log_line";
private final ILogger LOG = ILogger.newInstance("LogReceiver");
private LogListener listener;
public LogReceiver setLogListener(LogListener listener) {
this.listener = listener;
@@ -29,6 +29,14 @@ import java.io.FileFilter;
public class ListDirectoryCallable implements java.util.concurrent.Callable<String> {
private final FileFilter ARCHIVE_FILTER =
new FileFilter() {
@Override
public boolean accept(File p1) {
return p1.isFile() && (p1.getName().endsWith(".tar.xz") || p1.getName().endsWith(".zip"));
}
};
private File file;
public ListDirectoryCallable(File file) {
@@ -39,13 +47,4 @@ public class ListDirectoryCallable implements java.util.concurrent.Callable<Stri
public String call() throws Exception {
return TextUtils.join("\n", FileUtils.listFilesInDirWithFilter(file, ARCHIVE_FILTER, false));
}
private final FileFilter ARCHIVE_FILTER =
new FileFilter() {
@Override
public boolean accept(File p1) {
return p1.isFile() && (p1.getName().endsWith(".tar.xz") || p1.getName().endsWith(".zip"));
}
};
}
@@ -48,17 +48,14 @@ import org.jetbrains.annotations.Contract;
*/
public class WidgetDragListener implements View.OnDragListener {
public static final String ANDROID_NS = "android";
private static final ILogger LOG = ILogger.newInstance("WidgetDragListener");
private final IView placeholder;
private final IViewGroup viewGroup;
private final OnViewAddedListener addedListener;
private final int PLACEHOLDER_HEIGHT = 20; // in dp
private final int PLACEHOLDER_WIDTH = 40; // in dp
public static final String ANDROID_NS = "android";
private static final ILogger LOG = ILogger.newInstance("WidgetDragListener");
public WidgetDragListener(
@NonNull Context context, IViewGroup viewGroup, OnViewAddedListener addedListener) {
this.placeholder = new UiView("android.view.View", new View(context), true);
@@ -127,6 +124,18 @@ public class WidgetDragListener implements View.OnDragListener {
view.addAttribute(layoutHeightAttr());
}
@NonNull
@Contract(" -> new")
private IAttribute layoutHeightAttr() {
return new UiAttribute(INamespace.ANDROID, "layout_height", "wrap_content");
}
@NonNull
@Contract(" -> new")
private IAttribute layoutWidthAttr() {
return new UiAttribute(INamespace.ANDROID, "layout_width", "wrap_content");
}
/**
* Finds the index at which the placeholder will be added in the current view group.
*
@@ -180,30 +189,6 @@ public class WidgetDragListener implements View.OnDragListener {
return src;
}
private RectF leftHalf(RectF src) {
final RectF result = new RectF(src);
result.right -= result.width() / 2;
return src;
}
private RectF rightHalf(RectF src) {
final RectF result = new RectF(src);
result.left += result.width() / 2;
return src;
}
@NonNull
@Contract(" -> new")
private IAttribute layoutHeightAttr() {
return new UiAttribute(INamespace.ANDROID, "layout_height", "wrap_content");
}
@NonNull
@Contract(" -> new")
private IAttribute layoutWidthAttr() {
return new UiAttribute(INamespace.ANDROID, "layout_width", "wrap_content");
}
@NonNull
private IView createView(@NonNull UIWidget widget) {
try {
@@ -223,6 +208,18 @@ public class WidgetDragListener implements View.OnDragListener {
}
}
private RectF leftHalf(RectF src) {
final RectF result = new RectF(src);
result.right -= result.width() / 2;
return src;
}
private RectF rightHalf(RectF src) {
final RectF result = new RectF(src);
result.left += result.width() / 2;
return src;
}
public static interface OnViewAddedListener {
void onViewAdded(IView view);
}
@@ -62,11 +62,6 @@ public class WidgetTouchListener extends GestureDetector.SimpleOnGestureListener
return mGestureDetector.onTouchEvent(motionEvent);
}
@Override
public boolean onDown(MotionEvent e) {
return true; // We would like to get notified about further events.
}
// TODO Should we use onSingleTapConfirmed instead?
@Override
public boolean onSingleTapUp(MotionEvent e) {
@@ -90,6 +85,11 @@ public class WidgetTouchListener extends GestureDetector.SimpleOnGestureListener
}
}
@Override
public boolean onDown(MotionEvent e) {
return true; // We would like to get notified about further events.
}
/**
* A listener which is invoked when we detect a single click event.
*
@@ -34,18 +34,6 @@ import org.jetbrains.annotations.Contract;
*/
public class DialogUtils {
/**
* Creates a new MaterialAlertDialogBuilder with the app's default style.
*
* @param context The context for the dialog builder.
* @return The new MaterialAlertDialogBuilder instance.
*/
@NonNull
@Contract("_ -> new")
public static MaterialAlertDialogBuilder newMaterialDialogBuilder(Context context) {
return new MaterialAlertDialogBuilder(context, R.style.AppTheme_MaterialAlertDialog);
}
/**
* Create a new alert dialog with two buttons: <span>Yes</span> and <span>No</span>. This method
* simply calls {@link #newYesNoDialog(Context, String, String, DialogInterface.OnClickListener,
@@ -98,4 +86,16 @@ public class DialogUtils {
return builder;
}
/**
* Creates a new MaterialAlertDialogBuilder with the app's default style.
*
* @param context The context for the dialog builder.
* @return The new MaterialAlertDialogBuilder instance.
*/
@NonNull
@Contract("_ -> new")
public static MaterialAlertDialogBuilder newMaterialDialogBuilder(Context context) {
return new MaterialAlertDialogBuilder(context, R.style.AppTheme_MaterialAlertDialog);
}
}
@@ -31,8 +31,8 @@ import com.itsaky.androidide.databinding.LayoutEditorBottomSheetBinding;
public class EditorBottomSheetBehavior<V extends View> extends BottomSheetBehavior<V> {
private LayoutEditorBottomSheetBinding binding;
private static final ILogger LOG = ILogger.newInstance("EditorBottomSheetBehavior");
private LayoutEditorBottomSheetBinding binding;
public EditorBottomSheetBehavior(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
@@ -44,6 +44,7 @@ import java.util.List;
public class HighlightRangeHelper {
private static final ILogger LOG = ILogger.newInstance("HighlightRangeHelper");
private final List<HighlightToken> highlights;
public HighlightRangeHelper(List<HighlightToken> highlights) {
@@ -54,6 +55,36 @@ public class HighlightRangeHelper {
return isOfKind(line, column, ENUM_TYPE);
}
/**
* Check if the token at the given index has the given token kind.
*
* @param line The line to check.
* @param column The column to check.
* @param kind The kind to check.
* @return {@code true} if the token at the given position has the given kind, {@code false}
* otherwise.
*/
public boolean isOfKind(int line, int column, HighlightTokenKind kind) {
final var position = new Position(line, column);
int left = 0;
int right = this.highlights.size();
int mid;
while (left < right) {
mid = (left + right) / 2;
var token = this.highlights.get(mid);
var range = token.getRange();
var pos = range.getStart().compareTo(position);
if (pos < 0) {
left = mid + 1;
} else if (pos > 0) {
right = mid - 1;
} else {
return token.getKind() == kind;
}
}
return false;
}
public boolean isAnnotationType(int line, int column) {
return isOfKind(line, column, ANNOTATION);
}
@@ -121,36 +152,4 @@ public class HighlightRangeHelper {
public boolean isLocal(int line, int column) {
return isOfKind(line, column, LOCAL_VARIABLE);
}
/**
* Check if the token at the given index has the given token kind.
*
* @param line The line to check.
* @param column The column to check.
* @param kind The kind to check.
* @return {@code true} if the token at the given position has the given kind, {@code false}
* otherwise.
*/
public boolean isOfKind(int line, int column, HighlightTokenKind kind) {
final var position = new Position(line, column);
int left = 0;
int right = this.highlights.size();
int mid;
while (left < right) {
mid = (left + right) / 2;
var token = this.highlights.get(mid);
var range = token.getRange();
var pos = range.getStart().compareTo(position);
if (pos < 0) {
left = mid + 1;
} else if (pos > 0) {
right = mid - 1;
} else {
return token.getKind() == kind;
}
}
return false;
}
private static final ILogger LOG = ILogger.newInstance("HighlightRangeHelper");
}
@@ -19,8 +19,6 @@
**************************************************************************************/
package com.itsaky.androidide.utils;
import com.itsaky.lsp.models.DiagnosticItem;
import com.itsaky.lsp.models.DiagnosticSeverity;
import com.itsaky.lsp.models.Position;
import com.itsaky.lsp.models.Range;
@@ -31,19 +29,41 @@ public class LSPUtils {
public static final Position Position_ofZero;
public static final Range Range_ofZero;
public static final Comparator<Range> RANGE_START_COMPARATOR =
(r1, r2) -> {
// Check if ranges are null
if (r1 == null && r2 != null) {
return 1;
} else if (r1 != null && r2 == null) {
return -1;
} else if (r1 == null) {
return 0;
} else {
final int r1StartLine = r1.getStart().getLine();
final int r1StartCol = r1.getStart().getColumn();
final int r2StartLine = r2.getStart().getLine();
final int r2StartCol = r2.getStart().getColumn();
// Compare by lines
if (r1StartLine < r2StartLine) {
return -1;
} else if (r1StartLine > r2StartLine) {
return 1;
} else {
// Lines are same
// Compare by columns
// Both ranges have same start position
return Integer.compare(r1StartCol, r2StartCol);
}
}
};
static {
Position_ofZero = new Position(0, 0);
Range_ofZero = new Range(Position_ofZero, Position_ofZero);
}
public static boolean isEqual(Position p1, Position p2) {
if (p1 == null) return false;
if (p2 == null) return false;
return p1.getLine() == p2.getLine() && p1.getColumn() == p2.getColumn();
}
public static boolean isInRange(Range range, Position position) {
final int line = position.getLine();
final int column = position.getColumn();
@@ -67,6 +87,13 @@ public class LSPUtils {
&& LSPUtils.isEqual(r1.getEnd(), r2.getEnd());
}
public static boolean isEqual(Position p1, Position p2) {
if (p1 == null) return false;
if (p2 == null) return false;
return p1.getLine() == p2.getLine() && p1.getColumn() == p2.getColumn();
}
public static Range getSingleLineRange(int line, int column, int length) {
final Range range = new Range();
range.setStart(new Position(line, column));
@@ -102,34 +129,4 @@ public class LSPUtils {
return -1;
}
public static final Comparator<Range> RANGE_START_COMPARATOR =
(r1, r2) -> {
// Check if ranges are null
if (r1 == null && r2 != null) {
return 1;
} else if (r1 != null && r2 == null) {
return -1;
} else if (r1 == null) {
return 0;
} else {
final int r1StartLine = r1.getStart().getLine();
final int r1StartCol = r1.getStart().getColumn();
final int r2StartLine = r2.getStart().getLine();
final int r2StartCol = r2.getStart().getColumn();
// Compare by lines
if (r1StartLine < r2StartLine) {
return -1;
} else if (r1StartLine > r2StartLine) {
return 1;
} else {
// Lines are same
// Compare by columns
// Both ranges have same start position
return Integer.compare(r1StartCol, r2StartCol);
}
}
};
}
@@ -46,8 +46,6 @@ import java.util.zip.ZipInputStream;
public class ProjectWriter {
private static ProjectWriterCallback callback;
private static final String XML_TEMPLATE_PATH = "templates/xml";
private static final String SOURCE_PATH_REGEX = "/.*/src/.*/java|kt";
private static final String FILE_EXT_REGEX = ".*/java|kt|gradle|xml|txt|cpp";
@@ -58,6 +56,7 @@ public class ProjectWriter {
PACKAGE_NAME_CPP = "{$package_name_cpp}",
CPP_FLAGS = "$cpp_flags",
LIBRARY_NAME = "$library_name";
private static ProjectWriterCallback callback;
@NonNull
public static String createMenu() {
@@ -41,15 +41,6 @@ public class Symbols {
return new Symbol[0];
}
public static String createTabSpaces() {
int size = StudioApp.getInstance().getPrefManager().getEditorTabSize();
StringBuilder tab = new StringBuilder();
for (int i = 1; i <= size; i++) {
tab.append(" ");
}
return tab.toString();
}
public static Symbol[] javaSymbols() {
return new Symbol[] {
new Symbol("↹", "\t"),
@@ -105,4 +96,13 @@ public class Symbols {
new Symbol("-")
};
}
public static String createTabSpaces() {
int size = StudioApp.getInstance().getPrefManager().getEditorTabSize();
StringBuilder tab = new StringBuilder();
for (int i = 1; i <= size; i++) {
tab.append(" ");
}
return tab.toString();
}
}
@@ -8,14 +8,13 @@ import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import com.blankj.utilcode.util.CollectionUtils;
import com.itsaky.androidide.R;
import com.itsaky.androidide.interfaces.ProjectWriterCallback;
import com.itsaky.androidide.models.NewProjectDetails;
import com.itsaky.androidide.models.ProjectTemplate;
import com.itsaky.androidide.tasks.TaskExecutor;
import com.itsaky.androidide.tasks.callables.ProjectCreatorCallable;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
@@ -103,17 +103,17 @@ public class MaterialBanner extends CoordinatorLayout {
Animation anim =
new Animation() {
@Override
public boolean willChangeBounds() {
return true;
}
@Override
public void applyTransformation(float time, Transformation t) {
p.height = time == 1f ? -2 : (int) (height * time);
root.setLayoutParams(p);
root.requestLayout();
}
@Override
public boolean willChangeBounds() {
return true;
}
};
anim.setDuration(200);
@@ -126,6 +126,11 @@ public class MaterialBanner extends CoordinatorLayout {
final int initialHeight = getMeasuredHeight();
Animation animation =
new Animation() {
@Override
public boolean willChangeBounds() {
return true;
}
@Override
public void applyTransformation(float interpolatedTime, Transformation t) {
if (interpolatedTime == 1f) {
@@ -136,11 +141,6 @@ public class MaterialBanner extends CoordinatorLayout {
root.requestLayout();
}
}
@Override
public boolean willChangeBounds() {
return true;
}
};
animation.setDuration((long) (initialHeight / getResources().getDisplayMetrics().density));
root.startAnimation(animation);
@@ -150,40 +150,40 @@ public class MaterialBanner extends CoordinatorLayout {
return setIcon(ContextCompat.getDrawable(getContext(), icon));
}
public MaterialBanner setPositive(@StringRes int text, OnPositiveClickListener listener) {
return setPositive(getContext().getString(text), listener);
}
public MaterialBanner setNegative(@StringRes int text, OnNegativeClickListener listener) {
return setNegative(getContext().getString(text), listener);
}
public MaterialBanner setContentText(@StringRes int text) {
return setContentText(getContext().getString(text));
}
public MaterialBanner setContentText(String contentText) {
this.contentText = contentText;
return this;
}
public MaterialBanner setIcon(Drawable icon) {
this.iconDrawable = icon;
return this;
}
public MaterialBanner setPositive(@StringRes int text, OnPositiveClickListener listener) {
return setPositive(getContext().getString(text), listener);
}
public MaterialBanner setPositive(String text, OnPositiveClickListener listener) {
this.rightButtonText = text;
this.positiveListener = listener;
return this;
}
public MaterialBanner setNegative(@StringRes int text, OnNegativeClickListener listener) {
return setNegative(getContext().getString(text), listener);
}
public MaterialBanner setNegative(String text, OnNegativeClickListener listener) {
this.leftButtonText = text;
this.negativeListener = listener;
return this;
}
public MaterialBanner setContentText(@StringRes int text) {
return setContentText(getContext().getString(text));
}
public MaterialBanner setContentText(String contentText) {
this.contentText = contentText;
return this;
}
public MaterialBanner setBannerBackgroundColor(int backgroundColor) {
this.backgroundColor = backgroundColor;
return this;
@@ -1,4 +1,4 @@
package com.itsaky.androidide.views;
package com.itsaky.androidide.views
import android.content.Context
import android.util.AttributeSet
@@ -9,11 +9,11 @@ import com.google.android.material.tabs.TabLayout
class ScalableTabLayout : TabLayout {
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
context,
attrs,
defStyleAttr
)
constructor(
context: Context,
attrs: AttributeSet?,
defStyleAttr: Int
) : super(context, attrs, defStyleAttr)
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
val tabLayout = getChildAt(0) as ViewGroup
@@ -68,14 +68,14 @@ public class SymbolInputView extends RecyclerView {
this(both, both, offset);
}
public Symbol(String label, String commit) {
this(label, commit, 1);
}
public Symbol(String label, String commit, int offset) {
this.label = label;
this.commit = commit;
this.offset = offset;
}
public Symbol(String label, String commit) {
this(label, commit, 1);
}
}
}
@@ -83,8 +83,13 @@ public abstract class BaseEditorWindow extends EditorPopupWindow {
return text;
}
protected View getRootView() {
return this.text;
protected Drawable createBackground() {
GradientDrawable background = new GradientDrawable();
background.setShape(GradientDrawable.RECTANGLE);
background.setColor(0xff212121);
background.setStroke(1, 0xffffffff);
background.setCornerRadius(8);
return background;
}
public void displayWindow() {
@@ -99,13 +104,8 @@ public abstract class BaseEditorWindow extends EditorPopupWindow {
show();
}
protected Drawable createBackground() {
GradientDrawable background = new GradientDrawable();
background.setShape(GradientDrawable.RECTANGLE);
background.setColor(0xff212121);
background.setStroke(1, 0xffffffff);
background.setCornerRadius(8);
return background;
protected View getRootView() {
return this.text;
}
@NonNull
@@ -134,6 +134,11 @@ public class CodeEditorView extends FrameLayout {
return bundle;
}
@Nullable
public File getFile() {
return file;
}
private void handleContentChange(@NonNull ContentChangeEvent event) {
isModified = true;
@@ -157,96 +162,54 @@ public class CodeEditorView extends FrameLayout {
}
}
public boolean save() {
final var file = getFile();
if (file == null) {
LOG.error("Cannot save file. File instance is null.");
return false;
}
if (!isModified() && file.exists()) {
LOG.info(file.getName());
LOG.info("File was not modified. Skipping save operation.");
return false;
}
final var text = getEditor().getText().toString();
private void closeCurrentTag(String text, int line, int col) {
try {
FileUtil.writeFile(file, text);
notifySaved();
isModified = false;
return true;
} catch (IOException io) {
LOG.error("Failed to save file", file, io);
return false;
XMLLexer lexer = new XMLLexer(CharStreams.fromReader(new StringReader(text)));
Token token;
boolean wasSlash = false, wasOpen = false;
ArrayList<String> currentNames = new ArrayList<>();
while (((token = lexer.nextToken()) != null && token.getType() != token.EOF)) {
final int type = token.getType();
if (type == XMLLexer.OPEN) {
wasOpen = true;
} else if (type == XMLLexer.Name) {
if (wasOpen && wasSlash && currentNames.size() > 0) {
currentNames.remove(0);
} else if (wasOpen) {
currentNames.add(0, token.getText());
wasOpen = false;
}
} else if (type == XMLLexer.OPEN_SLASH) {
int l = token.getLine() - 1;
int c = token.getCharPositionInLine();
if (l == line && c == col) {
break;
} else if (currentNames.size() > 0) {
currentNames.remove(0);
}
} else if (type == XMLLexer.SLASH_CLOSE || type == XMLLexer.SPECIAL_CLOSE) {
if (currentNames.size() > 0 && token.getText().trim().endsWith("/>")) {
currentNames.remove(0);
}
} else if (type == XMLLexer.SLASH) {
wasSlash = true;
} else {
wasOpen = wasSlash = false;
}
}
@NonNull
private List<CharSequence> getLines(Content text) {
final var count = text.getLineCount();
final var result = new ArrayList<CharSequence>();
for (int i = 0; i < count; i++) {
result.add(text.getLine(i));
if (currentNames.size() > 0) {
binding.editor.getText().insert(line, col + 2, currentNames.get(0));
}
} catch (Throwable th) {
LOG.error("Unable to close current tag", th);
}
return result;
}
public IDEEditor getEditor() {
return binding.editor;
}
public LayoutCodeEditorBinding getBinding() {
return binding;
}
@Nullable
public File getFile() {
return file;
}
public String getText() {
return binding.editor.getText().toString();
}
public boolean isModified() {
return isModified;
}
public void onPause() {
// unimplemented
}
public void onResume() {
configureEditorIfNeeded();
}
public void onEditorSelected() {
final var editor = getEditor();
if (editor != null) {
editor.onEditorSelected();
}
}
public void undo() {
if (binding.editor.canUndo()) {
binding.editor.undo();
}
}
public void redo() {
if (binding.editor.canRedo()) {
binding.editor.redo();
}
}
public void beginSearch() {
binding.editor.beginSearchMode();
}
protected void postRead() {
binding.editor.setEditorLanguage(createLanguage(file));
binding.editor.setLanguageServer(createLanguageServer(file));
@@ -381,48 +344,34 @@ public class CodeEditorView extends FrameLayout {
isFirstCreate = false;
}
private void closeCurrentTag(String text, int line, int col) {
public boolean save() {
final var file = getFile();
if (file == null) {
LOG.error("Cannot save file. File instance is null.");
return false;
}
if (!isModified() && file.exists()) {
LOG.info(file.getName());
LOG.info("File was not modified. Skipping save operation.");
return false;
}
final var text = getEditor().getText().toString();
try {
XMLLexer lexer = new XMLLexer(CharStreams.fromReader(new StringReader(text)));
Token token;
boolean wasSlash = false, wasOpen = false;
ArrayList<String> currentNames = new ArrayList<>();
while (((token = lexer.nextToken()) != null && token.getType() != token.EOF)) {
final int type = token.getType();
if (type == XMLLexer.OPEN) {
wasOpen = true;
} else if (type == XMLLexer.Name) {
if (wasOpen && wasSlash && currentNames.size() > 0) {
currentNames.remove(0);
} else if (wasOpen) {
currentNames.add(0, token.getText());
wasOpen = false;
}
} else if (type == XMLLexer.OPEN_SLASH) {
int l = token.getLine() - 1;
int c = token.getCharPositionInLine();
if (l == line && c == col) {
break;
} else if (currentNames.size() > 0) {
currentNames.remove(0);
}
} else if (type == XMLLexer.SLASH_CLOSE || type == XMLLexer.SPECIAL_CLOSE) {
if (currentNames.size() > 0 && token.getText().trim().endsWith("/>")) {
currentNames.remove(0);
}
} else if (type == XMLLexer.SLASH) {
wasSlash = true;
} else {
wasOpen = wasSlash = false;
FileUtil.writeFile(file, text);
notifySaved();
isModified = false;
return true;
} catch (IOException io) {
LOG.error("Failed to save file", file, io);
return false;
}
}
if (currentNames.size() > 0) {
binding.editor.getText().insert(line, col + 2, currentNames.get(0));
}
} catch (Throwable th) {
LOG.error("Unable to close current tag", th);
}
public boolean isModified() {
return isModified;
}
private void notifySaved() {
@@ -433,9 +382,60 @@ public class CodeEditorView extends FrameLayout {
}
}
public LayoutCodeEditorBinding getBinding() {
return binding;
}
public String getText() {
return binding.editor.getText().toString();
}
public void onPause() {
// unimplemented
}
public void onResume() {
configureEditorIfNeeded();
}
public void onEditorSelected() {
final var editor = getEditor();
if (editor != null) {
editor.onEditorSelected();
}
}
public void undo() {
if (binding.editor.canUndo()) {
binding.editor.undo();
}
}
public void redo() {
if (binding.editor.canRedo()) {
binding.editor.redo();
}
}
public void beginSearch() {
binding.editor.beginSearchMode();
}
/** Mark this files as saved. Even if it not saved. */
public void markAsSaved() {
isModified = false;
notifySaved();
}
@NonNull
private List<CharSequence> getLines(Content text) {
final var count = text.getLineCount();
final var result = new ArrayList<CharSequence>();
for (int i = 0; i < count; i++) {
result.add(text.getLine(i));
}
return result;
}
}
@@ -121,49 +121,6 @@ public class IDEEditor extends CodeEditor {
getDiagnosticWindow().showDiagnostic(mLanguageClient.getDiagnosticAt(getFile(), line, column));
}
/**
* Notify the language server that the content of this file has been changed.
*
* @param event The content change event.
*/
private void handleContentChange(ContentChangeEvent event, Unsubscribe unsubscribe) {
if (getFile() == null || mLanguageServer == null) {
return;
}
CompletableFuture.runAsync(
() -> {
final var documentHandler = mLanguageServer.getDocumentHandler();
final var file = getFile().toPath();
if (documentHandler.accepts(file)) {
documentHandler.onContentChange(
new DocumentChangeEvent(file, getText(), mFileVersion + 1));
}
checkForSignatureHelp(event);
});
}
public static int createInputFlags() {
var flags =
EditorInfo.TYPE_CLASS_TEXT
| EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE
| EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
if (StudioApp.getInstance()
.getPrefManager()
.getBoolean(PreferenceManager.KEY_EDITOR_FLAG_PASSWORD, true)) {
flags |= EditorInfo.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
}
return flags;
}
@Nullable
private DiagnosticItem binarySearchDiagnostic(
@NonNull List<DiagnosticItem> diagnostics, int line, int column) {
return DiagnosticUtil.binarySearchDiagnostic(diagnostics, line, column);
}
private DiagnosticWindow getDiagnosticWindow() {
if (mDiagnosticWindow == null) {
mDiagnosticWindow = new DiagnosticWindow(this);
@@ -223,6 +180,29 @@ public class IDEEditor extends CodeEditor {
}
}
/**
* Notify the language server that the content of this file has been changed.
*
* @param event The content change event.
*/
private void handleContentChange(ContentChangeEvent event, Unsubscribe unsubscribe) {
if (getFile() == null || mLanguageServer == null) {
return;
}
CompletableFuture.runAsync(
() -> {
final var documentHandler = mLanguageServer.getDocumentHandler();
final var file = getFile().toPath();
if (documentHandler.accepts(file)) {
documentHandler.onContentChange(
new DocumentChangeEvent(file, getText(), mFileVersion + 1));
}
checkForSignatureHelp(event);
});
}
/**
* Checks if the content change event should trigger signature help. Signature help trigger
* characters are :
@@ -292,6 +272,20 @@ public class IDEEditor extends CodeEditor {
return mSignatureHelpWindow;
}
public static int createInputFlags() {
var flags =
EditorInfo.TYPE_CLASS_TEXT
| EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE
| EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
if (StudioApp.getInstance()
.getPrefManager()
.getBoolean(PreferenceManager.KEY_EDITOR_FLAG_PASSWORD, true)) {
flags |= EditorInfo.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
}
return flags;
}
/**
* Set the selection of this editor to the given position.
*
@@ -506,15 +500,6 @@ public class IDEEditor extends CodeEditor {
}
}
/**
* Dismisses the given dialog on the UI thread.
*
* @param dialog The dialog to dismiss.
*/
private void dismissOnUiThread(@NonNull final Dialog dialog) {
ThreadUtils.runOnUiThread(dialog::dismiss);
}
/**
* Checks if the given range is valid for this editor's text.
*
@@ -570,6 +555,15 @@ public class IDEEditor extends CodeEditor {
return column >= 0 && column < getText().getColumnCount(line);
}
/**
* Dismisses the given dialog on the UI thread.
*
* @param dialog The dialog to dismiss.
*/
private void dismissOnUiThread(@NonNull final Dialog dialog) {
ThreadUtils.runOnUiThread(dialog::dismiss);
}
/**
* If any language server instance is set, finds the references to of the token at the current
* cursor position.
@@ -850,4 +844,10 @@ public class IDEEditor extends CodeEditor {
LOG.error("Unable start search action mode. Activity must inherit AppCompatActivity.");
}
}
@Nullable
private DiagnosticItem binarySearchDiagnostic(
@NonNull List<DiagnosticItem> diagnostics, int line, int column) {
return DiagnosticUtil.binarySearchDiagnostic(diagnostics, line, column);
}
}
@@ -57,6 +57,58 @@ public class CubicBezierArc {
calculateControlPoints(angle, start, end);
}
private void calculateControlPoints(float angle, Point start, Point end) {
double angleRadians = Math.toRadians(angle);
float deltaX = start.x - end.x;
float deltaY = start.y - end.y;
float halfChordLength = (float) Math.sqrt(deltaX * deltaX + deltaY * deltaY) / 2;
float radius = halfChordLength / (float) Math.sin(angleRadians / 2.0f);
// The length of the line from the start or end point to the control point
float controlLength = (float) ((4f / 3f) * Math.tan(angleRadians / 4)) * radius;
float angleToControl = (float) Math.toDegrees(Math.atan(controlLength / radius));
// The mid point of the line from start to end
Point midPointChord = new Point((start.x + end.x) / 2, (start.y + end.y) / 2);
// Angle between line from circle centre to control point, and line between control points
float chordRadiusAngle = 180 - 90 - (angle / 2);
Point center = getTrianglePoint(chordRadiusAngle, midPointChord, end);
controlPoint2 = getTrianglePoint(angleToControl, end, center);
controlPoint1 = getReflectedPointAboutLine(center, midPointChord, controlPoint2);
// Get reflected control points
reflectedControlPoint1 = getReflectedPointAboutLine(start, end, controlPoint1);
reflectedControlPoint2 = getReflectedPointAboutLine(start, end, controlPoint2);
}
private Point getTrianglePoint(float angle, Point a, Point b) {
double angleRadians = Math.toRadians(angle);
Point thirdPoint = new Point();
thirdPoint.x = (float) Math.tan(angleRadians) * (b.y - a.y) * -1;
thirdPoint.y = (float) Math.tan(angleRadians) * (b.x - a.x);
thirdPoint.x = thirdPoint.x + a.x;
thirdPoint.y = thirdPoint.y + a.y;
return thirdPoint;
}
private Point getReflectedPointAboutLine(Point start, Point end, Point reflect) {
Point reflectedPoint = new Point();
if (start.x != end.x) {
float m = (start.y - end.y) / (start.x - end.x);
float c = end.y - (m * end.x);
float d = (reflect.x + (reflect.y - c) * m) / (1 + (m * m));
reflectedPoint.x = (2 * d) - reflect.x;
reflectedPoint.y = (2 * d * m) - reflect.y + (2 * c);
} else {
reflectedPoint.y = reflect.y;
reflectedPoint.x = start.x - (reflect.x - start.x);
}
return reflectedPoint;
}
/**
* Returns the start point
*
@@ -122,56 +174,4 @@ public class CubicBezierArc {
this.y = y;
}
}
private Point getTrianglePoint(float angle, Point a, Point b) {
double angleRadians = Math.toRadians(angle);
Point thirdPoint = new Point();
thirdPoint.x = (float) Math.tan(angleRadians) * (b.y - a.y) * -1;
thirdPoint.y = (float) Math.tan(angleRadians) * (b.x - a.x);
thirdPoint.x = thirdPoint.x + a.x;
thirdPoint.y = thirdPoint.y + a.y;
return thirdPoint;
}
private Point getReflectedPointAboutLine(Point start, Point end, Point reflect) {
Point reflectedPoint = new Point();
if (start.x != end.x) {
float m = (start.y - end.y) / (start.x - end.x);
float c = end.y - (m * end.x);
float d = (reflect.x + (reflect.y - c) * m) / (1 + (m * m));
reflectedPoint.x = (2 * d) - reflect.x;
reflectedPoint.y = (2 * d * m) - reflect.y + (2 * c);
} else {
reflectedPoint.y = reflect.y;
reflectedPoint.x = start.x - (reflect.x - start.x);
}
return reflectedPoint;
}
private void calculateControlPoints(float angle, Point start, Point end) {
double angleRadians = Math.toRadians(angle);
float deltaX = start.x - end.x;
float deltaY = start.y - end.y;
float halfChordLength = (float) Math.sqrt(deltaX * deltaX + deltaY * deltaY) / 2;
float radius = halfChordLength / (float) Math.sin(angleRadians / 2.0f);
// The length of the line from the start or end point to the control point
float controlLength = (float) ((4f / 3f) * Math.tan(angleRadians / 4)) * radius;
float angleToControl = (float) Math.toDegrees(Math.atan(controlLength / radius));
// The mid point of the line from start to end
Point midPointChord = new Point((start.x + end.x) / 2, (start.y + end.y) / 2);
// Angle between line from circle centre to control point, and line between control points
float chordRadiusAngle = 180 - 90 - (angle / 2);
Point center = getTrianglePoint(chordRadiusAngle, midPointChord, end);
controlPoint2 = getTrianglePoint(angleToControl, end, center);
controlPoint1 = getReflectedPointAboutLine(center, midPointChord, controlPoint2);
// Get reflected control points
reflectedControlPoint1 = getReflectedPointAboutLine(start, end, controlPoint1);
reflectedControlPoint2 = getReflectedPointAboutLine(start, end, controlPoint2);
}
}
@@ -45,6 +45,21 @@ public class ProgressTransition extends Transition {
}
};
@Override
public Animator createAnimator(
ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) {
if (startValues != null && endValues != null && endValues.view instanceof ProgressBar) {
ProgressBar progressBar = (ProgressBar) endValues.view;
int start = (Integer) startValues.values.get(PROPNAME_PROGRESS);
int end = (Integer) endValues.values.get(PROPNAME_PROGRESS);
if (start != end) {
progressBar.setProgress(start);
return ObjectAnimator.ofInt(progressBar, PROGRESS_PROPERTY, end);
}
}
return null;
}
@Override
public void captureStartValues(TransitionValues transitionValues) {
captureValues(transitionValues);
@@ -61,19 +76,4 @@ public class ProgressTransition extends Transition {
transitionValues.values.put(PROPNAME_PROGRESS, progressBar.getProgress());
}
}
@Override
public Animator createAnimator(
ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) {
if (startValues != null && endValues != null && endValues.view instanceof ProgressBar) {
ProgressBar progressBar = (ProgressBar) endValues.view;
int start = (Integer) startValues.values.get(PROPNAME_PROGRESS);
int end = (Integer) endValues.values.get(PROPNAME_PROGRESS);
if (start != end) {
progressBar.setProgress(start);
return ObjectAnimator.ofInt(progressBar, PROGRESS_PROPERTY, end);
}
}
return null;
}
}
@@ -55,17 +55,16 @@ open class IDEEditorSearcher(editor: IDEEditor) : EditorSearcher(editor) {
getEditor().context.getString(string.replaceAll),
getEditor().context.getString(string.msg_replacing),
true,
false)
return CompletableFuture.runAsync { replaceAll(replacement) }.thenAccept {
getEditor().post { dialog.dismiss() }
}
false
)
return CompletableFuture.runAsync { replaceAll(replacement) }
.thenAccept { getEditor().post { dialog.dismiss() } }
}
override fun replaceAll(replacement: String) {
checkState()
if (!isResultValid) {
Toast.makeText(getEditor().context, "Editor is still preparing", Toast.LENGTH_SHORT)
.show()
Toast.makeText(getEditor().context, "Editor is still preparing", Toast.LENGTH_SHORT).show()
return
}
@@ -86,9 +85,11 @@ open class IDEEditorSearcher(editor: IDEEditor) : EditorSearcher(editor) {
} else {
var fromIndex = 0
var foundIndex: Int
while (TextUtils.indexOf(sb, mPattern, mOptions.ignoreCase, fromIndex).also {
while (
TextUtils.indexOf(sb, mPattern, mOptions.ignoreCase, fromIndex).also {
foundIndex = it
} != -1) {
} != -1
) {
sb.replace(foundIndex, foundIndex + mPattern.length, replacement)
fromIndex = foundIndex + newLength
}
@@ -103,7 +104,8 @@ open class IDEEditorSearcher(editor: IDEEditor) : EditorSearcher(editor) {
0,
getEditor().lineCount - 1,
getEditor().text.getColumnCount(getEditor().lineCount - 1),
sb)
sb
)
getEditor().setSelectionAround(pos.line, pos.column)
}
} catch (e: Exception) {
+6 -6
View File
@@ -1,11 +1,11 @@
<set
xmlns:android="http://schemas.android.com/apk/res/android" >
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="0.0"
android:toAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
<alpha
android:duration="100"
android:repeatCount="0"/>
android:fromAlpha="0.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:repeatCount="0"
android:toAlpha="1.0" />
<scale
android:duration="100"
+6 -6
View File
@@ -1,11 +1,11 @@
<set
xmlns:android="http://schemas.android.com/apk/res/android" >
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="1.0"
android:toAlpha="0.0"
android:interpolator="@android:anim/accelerate_interpolator"
<alpha
android:duration="100"
android:repeatCount="0"/>
android:fromAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:repeatCount="0"
android:toAlpha="0.0" />
<scale
android:duration="100"

Some files were not shown because too many files have changed in this diff Show More