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

Fix edge to edge compatibility #223

Merged
merged 3 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ apply plugin: 'com.android.application'
android {
defaultConfig {
applicationId "ch.logixisland.anuto"
compileSdk 34
compileSdk 35
minSdkVersion 23
targetSdkVersion 35
versionCode 33
versionName "0.12"
versionCode 34
versionName "0.13"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
buildTypes {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package ch.logixisland.anuto.view;

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

public class ApplySafeInsetsHandler implements View.OnApplyWindowInsetsListener {
private final int mAdditionalPadding;

public ApplySafeInsetsHandler() {
this.mAdditionalPadding = 0;
}

public ApplySafeInsetsHandler(int mAdditionalPadding) {
this.mAdditionalPadding = mAdditionalPadding;
}

@Override
public WindowInsets onApplyWindowInsets(View view, WindowInsets windowInsets) {
if (Build.VERSION.SDK_INT >= 30) {
Insets systemBars = windowInsets.getInsets(WindowInsets.Type.systemBars());
Insets displayCutout = windowInsets.getInsets(WindowInsets.Type.displayCutout());

int top = Math.max(systemBars.top, displayCutout.top);
int bottom = Math.max(systemBars.bottom, displayCutout.bottom);
int left = Math.max(systemBars.left, displayCutout.left);
int right = Math.max(systemBars.right, displayCutout.right);

view.setPadding(
left + mAdditionalPadding,
top + mAdditionalPadding,
right + mAdditionalPadding,
bottom + mAdditionalPadding
);
}

return windowInsets;
}
}
18 changes: 18 additions & 0 deletions app/src/main/java/ch/logixisland/anuto/view/game/GameActivity.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
package ch.logixisland.anuto.view.game;

import android.content.res.Configuration;
import android.graphics.Insets;
import android.os.Build;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.DisplayCutout;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowInsets;
import android.view.WindowManager;
import android.widget.Toast;

Expand All @@ -14,6 +22,7 @@
import ch.logixisland.anuto.engine.logic.GameEngine;
import ch.logixisland.anuto.engine.theme.ActivityType;
import ch.logixisland.anuto.view.AnutoActivity;
import ch.logixisland.anuto.view.ApplySafeInsetsHandler;

public class GameActivity extends AnutoActivity {

Expand Down Expand Up @@ -48,6 +57,15 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_game);

findViewById(android.R.id.content).setOnApplyWindowInsetsListener(new ApplySafeInsetsHandler());

Configuration config = getResources().getConfiguration();

if ((config.screenLayout & Configuration.SCREENLAYOUT_LONG_MASK) == Configuration.SCREENLAYOUT_LONG_YES) {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

view_tower_defense = findViewById(R.id.view_tower_defense);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package ch.logixisland.anuto.view.load;

import android.os.Bundle;
import android.util.TypedValue;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.WindowInsets;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;

import ch.logixisland.anuto.AnutoApplication;
import ch.logixisland.anuto.GameFactory;
Expand All @@ -15,9 +15,9 @@
import ch.logixisland.anuto.business.game.SaveGameInfo;
import ch.logixisland.anuto.business.game.SaveGameRepository;
import ch.logixisland.anuto.view.AnutoActivity;
import ch.logixisland.anuto.view.ApplySafeInsetsHandler;

public class LoadGameActivity extends AnutoActivity implements AdapterView.OnItemClickListener,
ViewTreeObserver.OnScrollChangedListener {
public class LoadGameActivity extends AnutoActivity implements AdapterView.OnItemClickListener {

public static final int CONTEXT_MENU_DELETE_ID = 0;

Expand All @@ -26,11 +26,6 @@ public class LoadGameActivity extends AnutoActivity implements AdapterView.OnIte

private SaveGamesAdapter mAdapter;

private ImageView arrow_up;
private ImageView arrow_down;
private GridView grid_savegames;


public LoadGameActivity() {
GameFactory factory = AnutoApplication.getInstance().getGameFactory();
mGameLoader = factory.getGameLoader();
Expand All @@ -50,15 +45,15 @@ protected void onCreate(Bundle savedInstanceState) {

mAdapter = new SaveGamesAdapter(this, mSaveGameRepository);

arrow_up = findViewById(R.id.arrow_up);
arrow_down = findViewById(R.id.arrow_down);

grid_savegames = findViewById(R.id.grid_savegames);
GridView grid_savegames = findViewById(R.id.grid_savegames);
grid_savegames.setOnItemClickListener(this);
grid_savegames.getViewTreeObserver().addOnScrollChangedListener(this);
grid_savegames.post(this::updateArrowVisibility);
grid_savegames.setAdapter(mAdapter);
registerForContextMenu(grid_savegames);

int additionalPadding = (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, 20, getResources().getDisplayMetrics());

grid_savegames.setOnApplyWindowInsetsListener(new ApplySafeInsetsHandler(additionalPadding));
}

@Override
Expand All @@ -85,29 +80,4 @@ public boolean onContextItemSelected(MenuItem item) {

return false;
}

@Override
public void onScrollChanged() {
updateArrowVisibility();
}

private void updateArrowVisibility() {
if (grid_savegames.getChildCount() <= 0) {
arrow_up.setVisibility(View.INVISIBLE);
arrow_down.setVisibility(View.INVISIBLE);
return;
}

if (grid_savegames.getFirstVisiblePosition() == 0) {
arrow_up.setVisibility(grid_savegames.getChildAt(0).getTop() < -10 ? View.VISIBLE : View.INVISIBLE);
} else {
arrow_up.setVisibility(grid_savegames.getFirstVisiblePosition() > 0 ? View.VISIBLE : View.INVISIBLE);
}

if (grid_savegames.getLastVisiblePosition() == mAdapter.getCount() - 1) {
arrow_down.setVisibility(grid_savegames.getChildAt(grid_savegames.getChildCount() - 1).getBottom() > grid_savegames.getHeight() + 10 ? View.VISIBLE : View.INVISIBLE);
} else {
arrow_down.setVisibility(grid_savegames.getLastVisiblePosition() < mAdapter.getCount() - 1 ? View.VISIBLE : View.INVISIBLE);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ch.logixisland.anuto.view.map;

import android.os.Bundle;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.AdapterView;
Expand All @@ -15,20 +16,14 @@
import ch.logixisland.anuto.business.game.MapRepository;
import ch.logixisland.anuto.engine.theme.ActivityType;
import ch.logixisland.anuto.view.AnutoActivity;
import ch.logixisland.anuto.view.ApplySafeInsetsHandler;

public class ChangeMapActivity extends AnutoActivity implements AdapterView.OnItemClickListener,
ViewTreeObserver.OnScrollChangedListener {
public class ChangeMapActivity extends AnutoActivity implements AdapterView.OnItemClickListener {

private final GameLoader mGameLoader;
private final MapRepository mMapRepository;
private final HighScores mHighScores;

private MapsAdapter mAdapter;

private ImageView arrow_up;
private ImageView arrow_down;
private GridView grid_maps;

public ChangeMapActivity() {
GameFactory factory = AnutoApplication.getInstance().getGameFactory();
mGameLoader = factory.getGameLoader();
Expand All @@ -46,46 +41,21 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_change_map);

mAdapter = new MapsAdapter(this, mMapRepository, mHighScores);

arrow_up = findViewById(R.id.arrow_up);
arrow_down = findViewById(R.id.arrow_down);
MapsAdapter mAdapter = new MapsAdapter(this, mMapRepository, mHighScores);

grid_maps = findViewById(R.id.grid_maps);
GridView grid_maps = findViewById(R.id.grid_maps);
grid_maps.setOnItemClickListener(this);
grid_maps.getViewTreeObserver().addOnScrollChangedListener(this);
grid_maps.post(this::updateArrowVisibility);
grid_maps.setAdapter(mAdapter);

int additionalPadding = (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, 20, getResources().getDisplayMetrics());

grid_maps.setOnApplyWindowInsetsListener(new ApplySafeInsetsHandler(additionalPadding));
}

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
mGameLoader.loadMap(mMapRepository.getMapInfos().get(position).getMapId());
finish();
}

@Override
public void onScrollChanged() {
updateArrowVisibility();
}

private void updateArrowVisibility() {
if (grid_maps.getChildCount() <= 0) {
arrow_up.setVisibility(View.INVISIBLE);
arrow_down.setVisibility(View.INVISIBLE);
return;
}

if (grid_maps.getFirstVisiblePosition() == 0) {
arrow_up.setVisibility(grid_maps.getChildAt(0).getTop() < -10 ? View.VISIBLE : View.INVISIBLE);
} else {
arrow_up.setVisibility(grid_maps.getFirstVisiblePosition() > 0 ? View.VISIBLE : View.INVISIBLE);
}

if (grid_maps.getLastVisiblePosition() == mAdapter.getCount() - 1) {
arrow_down.setVisibility(grid_maps.getChildAt(grid_maps.getChildCount() - 1).getBottom() > grid_maps.getHeight() + 10 ? View.VISIBLE : View.INVISIBLE);
} else {
arrow_down.setVisibility(grid_maps.getLastVisiblePosition() < mAdapter.getCount() - 1 ? View.VISIBLE : View.INVISIBLE);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import ch.logixisland.anuto.engine.theme.ActivityType;
import ch.logixisland.anuto.view.AnutoActivity;
import ch.logixisland.anuto.view.ApplySafeInsetsHandler;

public class SettingsActivity extends AnutoActivity {
@Override
Expand All @@ -18,5 +19,7 @@ protected void onCreate(Bundle savedInstanceState) {
getFragmentManager().beginTransaction()
.replace(android.R.id.content, new SettingsFragment())
.commit();

findViewById(android.R.id.content).setOnApplyWindowInsetsListener(new ApplySafeInsetsHandler());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.os.Bundle;
import android.util.TypedValue;
import android.widget.GridView;

import ch.logixisland.anuto.AnutoApplication;
Expand All @@ -11,6 +12,7 @@
import ch.logixisland.anuto.engine.theme.Theme;
import ch.logixisland.anuto.engine.theme.ThemeManager;
import ch.logixisland.anuto.view.AnutoActivity;
import ch.logixisland.anuto.view.ApplySafeInsetsHandler;

public class EnemyStatsActivity extends AnutoActivity implements ThemeManager.Listener {

Expand All @@ -37,5 +39,10 @@ protected void onCreate(Bundle savedInstanceState) {

GridView grid_enemies = findViewById(R.id.grid_enemies);
grid_enemies.setAdapter(adapter);

int additionalPadding = (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, 20, getResources().getDisplayMetrics());

grid_enemies.setOnApplyWindowInsetsListener(new ApplySafeInsetsHandler(additionalPadding));
}
}
32 changes: 0 additions & 32 deletions app/src/main/res/drawable/select_map_arrow.xml

This file was deleted.

Binary file not shown.
24 changes: 0 additions & 24 deletions app/src/main/res/layout/activity_change_map.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,10 @@
android:layout_height="wrap_content"
android:columnWidth="150dp"
android:numColumns="auto_fit"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:verticalSpacing="20dp"
android:horizontalSpacing="20dp"
android:clipToPadding="false"
android:stretchMode="columnWidth"
android:scrollbarStyle="outsideOverlay" />

<ImageView
android:id="@+id/arrow_up"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_centerHorizontal="true"
android:background="@android:color/transparent"
android:layout_alignParentTop="true"
android:rotation="270"
android:src="@drawable/select_map_arrow" />

<ImageView
android:id="@+id/arrow_down"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_centerHorizontal="true"
android:background="@android:color/transparent"
android:layout_alignParentBottom="true"
android:rotation="90"
android:src="@drawable/select_map_arrow" />

</RelativeLayout>
Loading
Loading