Skip to content
This repository was archived by the owner on Oct 18, 2024. It is now read-only.

Various design improvements #1023

Merged
merged 18 commits into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
656e787
refactor: A bunch of (mostly XML) styling
Smooth-E Jun 4, 2023
63dc6c6
fix(Main Activity): Make use of a dedicated Splash Activity to enable…
Smooth-E Jun 4, 2023
58acfec
feat(edge-to-edge): Ground work to support edge-to-edge experiences t…
Smooth-E Jun 6, 2023
a5b4ec9
Merge barnch dev into design improvements
Smooth-E Jun 6, 2023
6aecfd0
fix(edge-to-edge): Manually set bottom padding for fragment containment
Smooth-E Jun 6, 2023
2349b09
feat(edge-to-edge): Allow full activity rebuild on configuration chan…
Smooth-E Jun 6, 2023
9ae9ad9
fix: Finish the Splash Activity after launching the Main one
Smooth-E Jun 6, 2023
8a766f3
fix(templates): The list of templates no longer disappears after an a…
Smooth-E Jun 6, 2023
4cac02a
fix(templates): Keep OnGlobalLayoutListener attached while the View i…
Smooth-E Jun 6, 2023
8ca6841
feat(design): Custom layout for MainActivity's main fragment in lands…
Smooth-E Jun 6, 2023
f3b8687
feat(edge-to-edge): Implement edge-to-edge for PreferencesActivity, m…
Smooth-E Jun 8, 2023
8133c5d
refactor(IDEPreferencesFragment.kt): Comply with the line-length rule…
Smooth-E Jun 8, 2023
14a45d4
refactor(edge-to-edge): Remove PaddingUtils.kt
Smooth-E Jun 8, 2023
c944efd
feat(edge-to-edge): Create a BottomInsetHeightDistributor view
Smooth-E Jun 8, 2023
a5a103c
fix(templates/design): Use OutlinedButton style for the *Exit* button…
Smooth-E Jun 8, 2023
edbcba6
refactor: Comply with AndroidIDE's code style
Smooth-E Jun 8, 2023
c0996d1
refactor: Make use of helper methods. Optimize XML
Smooth-E Jun 9, 2023
a232d62
fix(edge-to-edge): Wrong system bar coloring in Dark Mode
Smooth-E Jun 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(edge-to-edge): Implement edge-to-edge for PreferencesActivity, m…
…ove InsetUtils outside of the LimitlessIDEActivity.
  • Loading branch information
Smooth-E committed Jun 8, 2023
commit f3b868775c62dbad74ee26415f3dc8081f12409f
4 changes: 1 addition & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@
android:configChanges="orientation|screenSize"
android:launchMode="singleTop"
android:windowSoftInputMode="adjustResize" />
<activity
android:name=".activities.PreferencesActivity"
android:configChanges="orientation|screenSize" />
<activity android:name=".activities.PreferencesActivity" />
<activity
android:name=".activities.AboutActivity"
android:configChanges="orientation|screenSize" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@

package com.itsaky.androidide.activities;

import android.graphics.Rect;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
Expand All @@ -38,6 +40,10 @@ public class PreferencesActivity extends LimitlessIDEActivity {
private ActivityPreferencesBinding binding;
private IDEPreferencesFragment rootFragment;

public PreferencesActivity() {
super(true);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -47,7 +53,7 @@ protected void onCreate(Bundle savedInstanceState) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

binding.toolbar.setNavigationOnClickListener(v -> onBackPressed());

if (savedInstanceState != null) {
return;
}
Expand All @@ -59,13 +65,41 @@ protected void onCreate(Bundle savedInstanceState) {

final var args = new Bundle();
args.putParcelableArrayList(
IDEPreferencesFragment.EXTRA_CHILDREN, new ArrayList<>(prefs.getChildren()));
IDEPreferencesFragment.EXTRA_CHILDREN,
new ArrayList<>(prefs.getChildren())
);

final var root = getRootFragment();
root.setArguments(args);
loadFragment(root);
}


@Override
public void onInsetsUpdated(@NonNull Rect insets) {
super.onInsetsUpdated(insets);

View toolbar = binding.toolbar;
toolbar.setPadding(
toolbar.getPaddingLeft() + insets.left,
toolbar.getPaddingTop(),
toolbar.getPaddingRight() + insets.right,
toolbar.getPaddingBottom()
);

View fragmentContainer = binding.fragmentContainerParent;
fragmentContainer.setPadding(
fragmentContainer.getPaddingLeft() + insets.left,
fragmentContainer.getPaddingTop(),
fragmentContainer.getPaddingRight() + insets.right,
fragmentContainer.getPaddingBottom()
);

binding.paddingDistributor.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
insets.bottom
));
}

@Override
@NonNull
protected View bindLayout() {
Expand All @@ -77,8 +111,8 @@ private IDEPreferencesFragment getRootFragment() {
return rootFragment == null ? rootFragment = new IDEPreferencesFragment() : rootFragment;
}

private void loadFragment(Fragment frag) {
super.loadFragment(frag, binding.fragmentContainer.getId());
private void loadFragment(Fragment fragment) {
super.loadFragment(fragment, binding.fragmentContainer.getId());
}

@Override
Expand Down
78 changes: 39 additions & 39 deletions app/src/main/java/com/itsaky/androidide/app/LimitlessIDEActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,28 @@

package com.itsaky.androidide.app

import android.content.res.Configuration
import android.graphics.Color
import android.graphics.Insets
import android.graphics.Rect
import android.os.Build
import android.os.Bundle
import android.os.PersistableBundle
import android.view.View
import android.view.WindowInsets
import android.util.TypedValue
import android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
import androidx.core.view.WindowCompat
import androidx.core.view.doOnAttach
import com.itsaky.androidide.utils.NavigationBar
import com.itsaky.androidide.utils.getInsets

/**
* Same as IDEActivity but DecorFitsSystemWindows is set to false
* Useful for creating immersive experiences
* Useful for creating immersive edge-to-edge experiences
*
* @author Smooth E
*/
abstract class LimitlessIDEActivity : IDEActivity() {
abstract class LimitlessIDEActivity(
private val highlightNavigationBar: Boolean = false
) : IDEActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -51,8 +54,8 @@ abstract class LimitlessIDEActivity : IDEActivity() {

private fun makeLimitless() {
WindowCompat.setDecorFitsSystemWindows(window, false)
window.statusBarColor = Color.TRANSPARENT
window.navigationBarColor = Color.TRANSPARENT

paintNavigationBar()

// This removes a black strip on the side where the camera cutout is in landscape mode
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
Expand All @@ -61,42 +64,39 @@ abstract class LimitlessIDEActivity : IDEActivity() {
}

private fun installOnDecorViewAttachedListener() {
window.decorView.doOnAttach { decorView -> updateInsets(decorView) }
window.decorView.doOnAttach { decorView -> onInsetsUpdated(getInsets(decorView)) }
}

private fun updateInsets(decorView: View)
{
val insets: Rect
val rootWindowInsets = decorView.rootWindowInsets

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {

val receivedInsets: Insets = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val typeMask = WindowInsets.Type.systemBars() or WindowInsets.Type.displayCutout()
rootWindowInsets.getInsetsIgnoringVisibility(typeMask)
} else {
decorView.rootWindowInsets.stableInsets
}

insets = Rect(
receivedInsets.left,
receivedInsets.top,
receivedInsets.right,
receivedInsets.bottom
)
} else {
insets = Rect(
rootWindowInsets.stableInsetLeft,
rootWindowInsets.stableInsetTop,
rootWindowInsets.stableInsetRight,
rootWindowInsets.stableInsetBottom
)
/** Called whenever insets are updated */
open fun onInsetsUpdated(insets: Rect) { }

private fun paintNavigationBar() {
window.statusBarColor = Color.TRANSPARENT
window.navigationBarColor = Color.TRANSPARENT

if (!highlightNavigationBar) {
return
}

onInsetsUpdated(insets)
}
val refrainHighlighting =
NavigationBar.getInteractionMode(this) == NavigationBar.MODE_GESTURES ||
resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE

/** Called when insets are updated */
open fun onInsetsUpdated(insets: Rect) { }
if (refrainHighlighting) {
return
}

var id = com.google.android.material.R.attr.colorSurface
var typedValue = TypedValue()
theme.resolveAttribute(id, typedValue, true)
window.navigationBarColor = typedValue.data

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
id = com.google.android.material.R.attr.colorOutlineVariant
typedValue = TypedValue()
theme.resolveAttribute(id, typedValue, true)
window.navigationBarDividerColor = typedValue.data
}
}

}
35 changes: 31 additions & 4 deletions app/src/main/res/layout/activity_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,38 @@

</com.google.android.material.appbar.AppBarLayout>


<FrameLayout
android:id="@+id/fragmentContainer"
<androidx.core.widget.NestedScrollView
android:id="@+id/fragment_container_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior" />
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<FrameLayout
android:id="@+id/fragmentContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

<!--
TODO: Implement a custom view which is meant to be placed at the end of
a ScrollView and will have dimensions
of match_parent - [ navigation bar height ] (width / height)
-->
<!--
This view fills up the space on the bottom of the scroll for the content
above it to not be blocked by the navigation bar
-->
<FrameLayout
android:id="@+id/padding_distributor"
android:layout_width="match_parent"
android:layout_height="0dp" />

</LinearLayout>

</androidx.core.widget.NestedScrollView>

</androidx.coordinatorlayout.widget.CoordinatorLayout>
64 changes: 64 additions & 0 deletions common/src/main/java/com/itsaky/androidide/utils/InsetUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* This file is part of AndroidIDE.
*
* AndroidIDE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* AndroidIDE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
*/

package com.itsaky.androidide.utils

import android.graphics.Insets
import android.graphics.Rect
import android.os.Build
import android.view.View
import android.view.WindowInsets

/**
* Acquires screen insets
*
* @param view Any View that is currently attached to a Window
*
* @return [Rect] containing acquired insets
*
* @author Smooth E
*/
fun getInsets(view: View): Rect {
val insets: Rect
val rootWindowInsets = view.rootWindowInsets

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {

val receivedInsets: Insets = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val typeMask = WindowInsets.Type.systemBars() or WindowInsets.Type.displayCutout()
rootWindowInsets.getInsetsIgnoringVisibility(typeMask)
} else {
view.rootWindowInsets.stableInsets
}

insets = Rect(
receivedInsets.left,
receivedInsets.top,
receivedInsets.right,
receivedInsets.bottom
)
} else {
insets = Rect(
rootWindowInsets.stableInsetLeft,
rootWindowInsets.stableInsetTop,
rootWindowInsets.stableInsetRight,
rootWindowInsets.stableInsetBottom
)
}

return insets
}
7 changes: 0 additions & 7 deletions resources/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,6 @@
</style>

<style name="Theme.AndroidIDE" parent="Theme.AndroidIDE.Styled">
<!--
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:enforceNavigationBarContrast" tools:targetApi="29">false</item>
<item name="android:enforceStatusBarContrast" tools:targetApi="29">false</item>
-->
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
<item name="android:windowLightStatusBar">true</item>
Expand Down