Skip to content

Commit

Permalink
EdgeTOEdge
Browse files Browse the repository at this point in the history
  • Loading branch information
oers committed Nov 19, 2024
1 parent b5b59b7 commit 8fd8f1b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;

import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.shurik.droidzebra.CandidateMove;
import com.shurik.droidzebra.InvalidMove;
import com.shurik.droidzebra.Move;
Expand Down
24 changes: 24 additions & 0 deletions project/src/main/java/de/earthlingz/oerszebra/DroidZebra.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.view.menu.MenuBuilder;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;

Expand Down Expand Up @@ -296,6 +299,8 @@ public void onDebug(String message) {
Log.i("Intent", type + " " + action);
engine.setOnErrorListener(this); //TODO don't forget to remove later to avoid memory leak



engine.onReady(() -> {
setContentView(R.layout.board_layout);
showActionBar();
Expand All @@ -305,6 +310,25 @@ public void onDebug(String message) {
mBoardView.setOnMakeMoveListener(this);
mBoardView.requestFocus();

//https://developer.android.com/develop/ui/views/layout/edge-to-edge?hl=de#java
ViewCompat.setOnApplyWindowInsetsListener(mBoardView, (v, windowInsets) -> {
Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars());
// Apply the insets as a margin to the view. This solution sets only the
// bottom, left, and right dimensions, but you can apply whichever insets are
// appropriate to your layout. You can also update the view padding if that's
// more appropriate.
ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
mlp.topMargin = insets.top;
mlp.leftMargin = insets.left;
mlp.bottomMargin = insets.bottom;
mlp.rightMargin = insets.right;
v.setLayoutParams(mlp);

// Return CONSUMED if you don't want want the window insets to keep passing
// down to descendant views.
return WindowInsetsCompat.CONSUMED;
});

resetStatusView();

if (Intent.ACTION_SEND.equals(action) && type != null) {
Expand Down
1 change: 0 additions & 1 deletion project/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme" parent="Theme.AppCompat">
<item name="android:windowOptOutEdgeToEdgeEnforcement">true</item>
<item name="actionBarStyle">@style/MyActionBar</item>
<item name="android:textColor">@color/statustextcolor</item>test
<item name="android:actionButtonStyle">@style/ActionButton</item>
Expand Down

0 comments on commit 8fd8f1b

Please sign in to comment.