diff --git a/app/build.gradle b/app/build.gradle index 68e9e47d..a38e5efe 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -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 { diff --git a/app/src/main/java/ch/logixisland/anuto/view/ApplySafeInsetsHandler.java b/app/src/main/java/ch/logixisland/anuto/view/ApplySafeInsetsHandler.java new file mode 100644 index 00000000..c0326508 --- /dev/null +++ b/app/src/main/java/ch/logixisland/anuto/view/ApplySafeInsetsHandler.java @@ -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; + } +} diff --git a/app/src/main/java/ch/logixisland/anuto/view/game/GameActivity.java b/app/src/main/java/ch/logixisland/anuto/view/game/GameActivity.java index 449c44b0..b9eeb45f 100755 --- a/app/src/main/java/ch/logixisland/anuto/view/game/GameActivity.java +++ b/app/src/main/java/ch/logixisland/anuto/view/game/GameActivity.java @@ -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; @@ -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 { @@ -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); diff --git a/app/src/main/java/ch/logixisland/anuto/view/load/LoadGameActivity.java b/app/src/main/java/ch/logixisland/anuto/view/load/LoadGameActivity.java index 37cf7b0f..356991c9 100644 --- a/app/src/main/java/ch/logixisland/anuto/view/load/LoadGameActivity.java +++ b/app/src/main/java/ch/logixisland/anuto/view/load/LoadGameActivity.java @@ -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; @@ -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; @@ -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(); @@ -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 @@ -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); - } - } } diff --git a/app/src/main/java/ch/logixisland/anuto/view/map/ChangeMapActivity.java b/app/src/main/java/ch/logixisland/anuto/view/map/ChangeMapActivity.java index 77ba8157..e831e7a5 100755 --- a/app/src/main/java/ch/logixisland/anuto/view/map/ChangeMapActivity.java +++ b/app/src/main/java/ch/logixisland/anuto/view/map/ChangeMapActivity.java @@ -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; @@ -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(); @@ -46,16 +41,16 @@ 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 @@ -63,29 +58,4 @@ 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); - } - } } diff --git a/app/src/main/java/ch/logixisland/anuto/view/setting/SettingsActivity.java b/app/src/main/java/ch/logixisland/anuto/view/setting/SettingsActivity.java index 8bae52e7..90f8f1c0 100755 --- a/app/src/main/java/ch/logixisland/anuto/view/setting/SettingsActivity.java +++ b/app/src/main/java/ch/logixisland/anuto/view/setting/SettingsActivity.java @@ -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 @@ -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()); } } diff --git a/app/src/main/java/ch/logixisland/anuto/view/stats/EnemyStatsActivity.java b/app/src/main/java/ch/logixisland/anuto/view/stats/EnemyStatsActivity.java index c0a6662b..55788dd0 100644 --- a/app/src/main/java/ch/logixisland/anuto/view/stats/EnemyStatsActivity.java +++ b/app/src/main/java/ch/logixisland/anuto/view/stats/EnemyStatsActivity.java @@ -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; @@ -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 { @@ -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)); } } diff --git a/app/src/main/res/drawable/select_map_arrow.xml b/app/src/main/res/drawable/select_map_arrow.xml deleted file mode 100644 index 904ae846..00000000 --- a/app/src/main/res/drawable/select_map_arrow.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/drawable/select_map_arrow_drawn.png b/app/src/main/res/drawable/select_map_arrow_drawn.png deleted file mode 100644 index 97e642fb..00000000 Binary files a/app/src/main/res/drawable/select_map_arrow_drawn.png and /dev/null differ diff --git a/app/src/main/res/layout/activity_change_map.xml b/app/src/main/res/layout/activity_change_map.xml index cd669f36..3386e071 100755 --- a/app/src/main/res/layout/activity_change_map.xml +++ b/app/src/main/res/layout/activity_change_map.xml @@ -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" /> - - - - diff --git a/app/src/main/res/layout/activity_enemy_stats.xml b/app/src/main/res/layout/activity_enemy_stats.xml index 29943f40..0bf40867 100644 --- a/app/src/main/res/layout/activity_enemy_stats.xml +++ b/app/src/main/res/layout/activity_enemy_stats.xml @@ -8,13 +8,10 @@ android:id="@+id/grid_enemies" android:layout_width="match_parent" android:layout_height="wrap_content" - android:numColumns="1" - android:paddingLeft="10dp" - android:paddingRight="10dp" - android:paddingTop="10dp" - android:paddingBottom="10dp" - android:horizontalSpacing="10dp" - android:verticalSpacing="10dp" + android:columnWidth="180dp" + android:numColumns="auto_fit" + android:verticalSpacing="20dp" + android:horizontalSpacing="20dp" android:clipToPadding="false" android:stretchMode="columnWidth" android:scrollbarStyle="outsideOverlay" /> diff --git a/app/src/main/res/layout/activity_game.xml b/app/src/main/res/layout/activity_game.xml index a4d8ba02..f3458130 100755 --- a/app/src/main/res/layout/activity_game.xml +++ b/app/src/main/res/layout/activity_game.xml @@ -2,7 +2,6 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - android:padding="0dp" tools:context=".view.game.GameActivity"> - - - - diff --git a/app/src/main/res/layout/item_enemy.xml b/app/src/main/res/layout/item_enemy.xml index d6afaad6..adb4abef 100644 --- a/app/src/main/res/layout/item_enemy.xml +++ b/app/src/main/res/layout/item_enemy.xml @@ -10,9 +10,8 @@ @@ -22,7 +21,8 @@ @android:style/Animation ?android:attr/textAppearanceSmallInverse #000000 - - @drawable/select_map_arrow_drawn diff --git a/app/src/main/res/values/theme_dark.xml b/app/src/main/res/values/theme_dark.xml index f26861b2..8bf411ad 100755 --- a/app/src/main/res/values/theme_dark.xml +++ b/app/src/main/res/values/theme_dark.xml @@ -77,7 +77,5 @@ @android:style/Animation ?android:attr/textAppearanceSmallInverse #ffffff - - @drawable/select_map_arrow diff --git a/app/src/main/res/values/theme_original.xml b/app/src/main/res/values/theme_original.xml index 81cb27a5..027e4579 100755 --- a/app/src/main/res/values/theme_original.xml +++ b/app/src/main/res/values/theme_original.xml @@ -77,7 +77,5 @@ @android:style/Animation ?android:attr/textAppearanceSmallInverse #000000 - - @drawable/select_map_arrow diff --git a/build.gradle b/build.gradle index ec06610a..593cd7b9 100755 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:8.5.2' + classpath 'com.android.tools.build:gradle:8.6.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files