Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transparent bars, Dynamic Color, some improvements. #115

Merged
merged 10 commits into from
Jun 27, 2022
7 changes: 3 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@
<application
android:name=".ApplicationLoader"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:largeHeap="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:resizeableActivity="true"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
android:theme="@style/Theme.JavaIde.NoActionBar">
<activity
android:name=".MainActivity"
android:exported="true"
android:theme="@style/AppTheme"
android:windowSoftInputMode="adjustResize" >
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/pranav/java/ide/ApplicationLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import android.content.Intent;
import android.util.Log;

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

import com.pranav.common.util.FileUtil;
import com.pranav.java.ide.ui.utils.dpToPx;

Expand All @@ -13,6 +15,7 @@ public final class ApplicationLoader extends Application {
@Override
public void onCreate() {
super.onCreate();
DynamicColors.applyToActivitiesIfAvailable(this);
final var mContext = getApplicationContext();
final var dataDirectory = mContext.getExternalFilesDir(null).getAbsolutePath();
FileUtil.setDataDirectory(dataDirectory);
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/com/pranav/java/ide/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.view.WindowCompat;
import androidx.drawerlayout.widget.DrawerLayout;

import com.google.android.material.dialog.MaterialAlertDialogBuilder;
Expand All @@ -38,6 +40,7 @@
import com.pranav.java.ide.compiler.CompileTask;
import com.pranav.java.ide.ui.TreeViewDrawer;
import com.pranav.java.ide.ui.treeview.helper.TreeCreateNewFileContent;
import com.pranav.java.ide.ui.utils.UiUtilsKt;

import io.github.rosemoe.sora.langs.textmate.TextMateColorScheme;
import io.github.rosemoe.sora.langs.textmate.TextMateLanguage;
Expand Down Expand Up @@ -79,6 +82,7 @@ public final class MainActivity extends AppCompatActivity {
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WindowCompat.setDecorFitsSystemWindows(getWindow(), false);

prefs = getSharedPreferences("compiler_settings", MODE_PRIVATE);

Expand Down Expand Up @@ -163,6 +167,8 @@ protected void onCreate(final Bundle savedInstanceState) {
findViewById(R.id.btn_smali).setOnClickListener(v -> smali());

editor.getText().addContentListener(new ProblemMarker(editor, currentWorkingFilePath));
HorizontalScrollView scrollView = findViewById(R.id.scrollview);
UiUtilsKt.addSystemWindowInsetToPadding(scrollView, false, false, false, true);
}

void reloadTreeView() {
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/com/pranav/java/ide/ui/TreeViewDrawer.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.PopupMenu;
import androidx.core.view.GravityCompat;
import androidx.core.view.ViewCompat;
import androidx.fragment.app.Fragment;

import com.google.android.material.button.MaterialButton;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.textview.MaterialTextView;

import com.pranav.common.util.FileUtil;
import com.pranav.java.ide.MainActivity;
import com.pranav.java.ide.R;
Expand All @@ -28,6 +30,7 @@
import com.pranav.java.ide.ui.treeview.file.TreeFile;
import com.pranav.java.ide.ui.treeview.helper.TreeCreateNewFileContent;
import com.pranav.java.ide.ui.treeview.model.TreeFolder;
import com.pranav.java.ide.ui.utils.UiUtilsKt;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -56,6 +59,9 @@ public View onCreateView(
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ViewCompat.requestApplyInsets(view);
UiUtilsKt.addSystemWindowInsetToPadding(view, false, true, false, true);

activity = ((MainActivity) getContext());

buildCreateFileDialog();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class TreeFileNodeViewBinder(
return this
}

/* Here I changed Images color so it will depends on the Day / Night Mode */
override fun bindView(treeNode: TreeNode<TreeFile>) {
viewHolder = ViewHolder(itemView)

Expand All @@ -33,7 +32,6 @@ class TreeFileNodeViewBinder(

with(viewHolder.arrow) {
setImageResource(R.drawable.arrow)
setColorFilter(context.getColor(R.color.md_theme_light_primary), PorterDuff.Mode.SRC_ATOP)
rotation = if (treeNode.isExpanded) 90F else 0F
visibility = if (treeNode.isLeaf) View.INVISIBLE else View.VISIBLE
}
Expand All @@ -44,7 +42,6 @@ class TreeFileNodeViewBinder(

with(viewHolder.icon) {
setImageDrawable(treeNode.content.getIcon(context))
setColorFilter(context.getColor(R.color.md_theme_light_primary), PorterDuff.Mode.SRC_ATOP)
}
}

Expand Down
47 changes: 47 additions & 0 deletions app/src/main/java/com/pranav/java/ide/ui/utils/UiUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.pranav.java.ide.ui.utils
import android.content.Context
import android.view.View
import android.view.ViewGroup
import androidx.core.view.*
import com.pranav.java.ide.ui.utils.dpToPx;

fun toDp(dp: Int) = dpToPx.dpToPx(dp.toFloat())
Expand All @@ -15,4 +16,50 @@ fun View.setMargins(left: Int? = null, top: Int? = null, right: Int? = null, bot
right ?: params.rightMargin,
bottom ?: params.bottomMargin)
layoutParams = params
}

@JvmOverloads
fun View.addSystemWindowInsetToPadding(
left: Boolean = false,
top: Boolean = false,
right: Boolean = false,
bottom: Boolean = false
) {
val (initialLeft, initialTop, initialRight, initialBottom) =
listOf(paddingLeft, paddingTop, paddingRight, paddingBottom)

ViewCompat.setOnApplyWindowInsetsListener(this) { view, windowInsets ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
view.updatePadding(
left = initialLeft + (if (left) insets.left else 0),
top = initialTop + (if (top) insets.top else 0),
right = initialRight + (if (right) insets.right else 0),
bottom = initialBottom + (if (bottom) insets.bottom else 0)
)
windowInsets
}
}

@JvmOverloads
fun View.addSystemWindowInsetToMargin(
left: Boolean = false,
top: Boolean = false,
right: Boolean = false,
bottom: Boolean = false
) {
val (initialLeft, initialTop, initialRight, initialBottom) =
listOf(marginLeft, marginTop, marginRight, marginBottom)

ViewCompat.setOnApplyWindowInsetsListener(this) { view, windowInsets ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
view.updateLayoutParams<ViewGroup.MarginLayoutParams> {
updateMargins(
left = initialLeft + (if (left) insets.left else 0),
top = initialTop + (if (top) insets.top else 0),
right = initialRight + (if (right) insets.right else 0),
bottom = initialBottom + (if (bottom) insets.bottom else 0)
)
}
windowInsets
}
}
3 changes: 1 addition & 2 deletions app/src/main/res/drawable/arrow.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<!-- drawable/arrow.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@color/md_theme_light_primary"
android:fillColor="?colorPrimary"
android:pathData="M8.59,16.58L13.17,12L8.59,7.41L10,6L16,12L10,18L8.59,16.58Z" />
</vector>
1 change: 0 additions & 1 deletion app/src/main/res/drawable/baseline_play_arrow_white_24.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<!-- drawable/baseline_play_arrow_white_24.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/drawable/folder.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<!-- drawable/folder.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@color/md_theme_light_primary"
android:fillColor="?colorPrimary"
android:pathData="M20,18H4V8H20M20,6H12L10,4H4C2.89,4 2,4.89 2,6V18A2,2 0 0,0 4,20H20A2,2 0 0,0 22,18V8C22,6.89 21.1,6 20,6Z" />
</vector>
3 changes: 1 addition & 2 deletions app/src/main/res/drawable/java_file.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<!-- drawable/java_file.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@color/md_theme_light_primary"
android:fillColor="?colorPrimary"
android:pathData="M14.6,16.6L19.2,12L14.6,7.4L16,6L22,12L16,18L14.6,16.6M9.4,16.6L4.8,12L9.4,7.4L8,6L2,12L8,18L9.4,16.6Z" />
</vector>
27 changes: 11 additions & 16 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:fitsSystemWindows="true">

<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/AppTheme.PopupOverlay" />
android:layout_height="?attr/actionBarSize" />
</com.google.android.material.appbar.AppBarLayout>

<androidx.coordinatorlayout.widget.CoordinatorLayout
Expand All @@ -43,12 +43,12 @@
android:id="@+id/scrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:background="#242424"
android:orientation="horizontal">

<LinearLayout
android:id="@+id/container"
android:layout_width="wrap_content"
android:layout_width="match_parent"
PranavPurwar marked this conversation as resolved.
Show resolved Hide resolved
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="8dp">
Expand All @@ -57,14 +57,11 @@
android:id="@+id/btn_smali"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="4dp"
android:layout_marginHorizontal="8dp"
android:layout_weight="1"
android:gravity="center_horizontal|center_vertical"
android:padding="8dp"
android:text="@string/smali"
android:textAppearance="@style/TextAppearance.MaterialComponents.Button"
android:textColor="#FFFFFF"
android:textSize="12sp"
app:backgroundTint="?attr/colorPrimary"
app:cornerRadius="8dp" />
Expand All @@ -73,13 +70,10 @@
android:id="@+id/btn_disassemble"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginEnd="8dp"
android:gravity="center_horizontal|center_vertical"
android:layout_weight="1"
android:padding="8dp"
android:text="@string/disassemble"
android:textAppearance="@style/TextAppearance.MaterialComponents.Button"
android:textColor="#FFFFFF"
android:textSize="12sp"
app:backgroundTint="?attr/colorPrimary"
app:cornerRadius="8dp" />
Expand All @@ -88,17 +82,18 @@
android:id="@+id/btn_smali2java"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="8dp"
android:layout_weight="1"
android:gravity="center_horizontal|center_vertical"
android:padding="8dp"
android:text="@string/smali2java"
android:textAppearance="@style/TextAppearance.MaterialComponents.Button"
android:textColor="#FFFFFF"
android:textSize="12sp"
app:backgroundTint="?attr/colorPrimary"
app:cornerRadius="8dp" />

</LinearLayout>
</HorizontalScrollView>

</LinearLayout>

<com.google.android.material.navigation.NavigationView
Expand All @@ -115,4 +110,4 @@
android:layout_marginTop="10dp" />

</com.google.android.material.navigation.NavigationView>
</androidx.drawerlayout.widget.DrawerLayout>
</androidx.drawerlayout.widget.DrawerLayout>
Loading