Skip to content
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
19 changes: 19 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Opens one grouped pull request a month when AndroidX, the Android Gradle plugin
# or the GitHub Actions used by CI fall behind, so warnings like issue #7 don't pile up.
version: 2
updates:
- package-ecosystem: gradle
directory: /
schedule:
interval: monthly
groups:
gradle:
patterns: ["*"]

- package-ecosystem: github-actions
directory: /
schedule:
interval: monthly
groups:
github-actions:
patterns: ["*"]
14 changes: 7 additions & 7 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ name: Build
on:
push:
branches: [ main ]
# Every pull request, including ones stacked on another PR's branch
pull_request:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v7

- uses: actions/setup-java@v3
- uses: actions/setup-java@v6
with:
distribution: 'temurin'
java-version: 11
java-version: 21

- uses: gradle/gradle-build-action@v2
with:
arguments: build
- uses: gradle/actions/setup-gradle@v6

- run: ./gradlew build
43 changes: 20 additions & 23 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,37 +1,34 @@
apply plugin: 'com.android.application'
plugins {
alias(libs.plugins.android.application)
}

android {
compileSdkVersion 34
namespace = 'atorch.shortestpaths'
compileSdk = 36

defaultConfig {
applicationId "atorch.shortestpaths"
minSdkVersion 16
targetSdkVersion 34
versionCode 5
versionName "1.4"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
applicationId = 'atorch.shortestpaths'
// AndroidX (including AppCompat 1.8) now requires API 23 (Android 6.0) or higher
minSdk = 23
// Google Play requires API 36 for new apps and updates from August 31, 2026
targetSdk = 36
versionCode = 5
versionName = '1.4'
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
minifyEnabled = false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt')
}
}
namespace 'atorch.shortestpaths'

compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.navigation:navigation-fragment:2.0.0'
implementation 'androidx.navigation:navigation-ui:2.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
implementation fileTree(dir: 'libs', include: ['*.aar', '*.jar'], exclude: [])
implementation libs.androidx.appcompat
}
3 changes: 1 addition & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
Expand All @@ -22,6 +20,7 @@
<activity
android:name=".SolvePuzzle"
android:configChanges="orientation|keyboardHidden|screenSize"
android:windowSoftInputMode="adjustResize"
android:label="@string/title_activity_solve_puzzle"
android:parentActivityName="atorch.shortestpaths.MainActivity"
android:exported="false"
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/atorch/shortestpaths/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.text.HtmlCompat;

import java.io.BufferedReader;
import java.io.IOException;
Expand Down Expand Up @@ -167,6 +167,7 @@ public void startPuzzle(View view) {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SystemBars.setUp(this);

context = getApplicationContext();
mSQLiteHelper = new MySQLiteHelper(context);
Expand Down Expand Up @@ -208,7 +209,7 @@ private void updateCountriesVisited() {
String not_yet_visited = String.format(not_yet_visited_format, countries[0], countries[1], countries[2]);

text += "\n\n" + not_yet_visited;
statement.setText(Html.fromHtml(text));
statement.setText(HtmlCompat.fromHtml(text, HtmlCompat.FROM_HTML_MODE_LEGACY));

TextView repoLink = findViewById(R.id.repo_link);
repoLink.setMovementMethod(LinkMovementMethod.getInstance());
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/atorch/shortestpaths/SolvePuzzle.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.text.Html;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
Expand All @@ -29,6 +28,7 @@

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.text.HtmlCompat;

public class SolvePuzzle extends AppCompatActivity {

Expand Down Expand Up @@ -76,7 +76,7 @@ private void setPuzzleStatement(Resources res) {
String puzzle_statement_text = String.format(res.getString(R.string.puzzle_statement_format_string), country_from, country_to);
String path_length_statement_text = res.getQuantityString(R.plurals.path_length_statement, path_length_inner, path_length_inner);
TextView puzzle_statement = (TextView) findViewById(R.id.puzzle_statement);
puzzle_statement.setText(Html.fromHtml(puzzle_statement_text));
puzzle_statement.setText(HtmlCompat.fromHtml(puzzle_statement_text, HtmlCompat.FROM_HTML_MODE_LEGACY));
TextView path_length_statement = (TextView) findViewById(R.id.path_length_statement);
path_length_statement.setText(path_length_statement_text);
}
Expand Down Expand Up @@ -144,6 +144,7 @@ protected void onCreate(Bundle savedInstanceState) {
country_to = savedInstanceState.getString(COUNTRY_TO);
} else {
setContentView(R.layout.activity_solve_puzzle);
SystemBars.setUp(this);

user_progress = 0;

Expand Down
98 changes: 98 additions & 0 deletions app/src/main/java/atorch/shortestpaths/SystemBars.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package atorch.shortestpaths;

import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;

import androidx.activity.ComponentActivity;
import androidx.activity.EdgeToEdge;
import androidx.activity.SystemBarStyle;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

/**
* Edge-to-edge setup shared by every screen.
*
* <p>Apps targeting API 35+ are always drawn edge-to-edge on Android 15+ (and API 36 removed the opt-out),
* so the app now draws behind the status and navigation bars on every Android version.
* The AppCompat action bar keeps itself below the status bar, but the content doesn't: with edge-to-edge,
* AppCompat lays the content out from the top of the window and adds the action bar's height to the
* top inset instead. So content has to keep itself clear of the action bar, the navigation bar and display
* cutouts.
*
* <p>Edge-to-edge also means windowSoftInputMode="adjustResize" no longer resizes the window when the
* keyboard opens, so we do the resizing ourselves (see {@link #fitToSystemBarsAndKeyboard}).
*/
final class SystemBars {

// The same scrims androidx.activity uses by default
private static final int LIGHT_SCRIM = Color.argb(0xe6, 0xff, 0xff, 0xff);
private static final int DARK_SCRIM = Color.argb(0x80, 0x1b, 0x1b, 0x1b);

private SystemBars() {
}

/**
* Call right after setContentView. Draws behind the system bars with dark icons (our theme is
* always light, even when the phone is in dark mode), then fits the layout's root view between
* the action bar, the navigation bar, cutouts and the keyboard.
*/
static void setUp(ComponentActivity activity) {
EdgeToEdge.enable(activity,
SystemBarStyle.light(Color.TRANSPARENT, DARK_SCRIM),
SystemBarStyle.light(LIGHT_SCRIM, DARK_SCRIM));

ViewGroup content = activity.findViewById(android.R.id.content);
if (content != null && content.getChildCount() > 0) {
fitToSystemBarsAndKeyboard(content.getChildAt(0));
}
}

/**
* Keeps view clear of the action bar, the navigation bar, cutouts and the keyboard.
*
* <ul>
* <li>Status bar and action bar: a top margin, so content never scrolls up behind the transparent
* status bar above the action bar.</li>
* <li>Navigation bar and cutouts: padding, with clipToPadding off, so scrolling content still
* draws behind the (translucent) navigation bar, and its last item can scroll fully into view.</li>
* <li>Keyboard: a bottom margin, which shrinks the view to the area above the keyboard, just like
* adjustResize used to. A ScrollView then keeps the focused text field in view by itself
* (ScrollView#onSizeChanged, and the TextView requesting its cursor rectangle on screen).
* Padding wouldn't do that: ScrollView ignores its padding when deciding whether a child is
* already visible.</li>
* </ul>
*/
static void fitToSystemBarsAndKeyboard(View view) {
final int left = view.getPaddingLeft();
final int top = view.getPaddingTop();
final int right = view.getPaddingRight();
final int bottom = view.getPaddingBottom();
if (view instanceof ViewGroup) {
((ViewGroup) view).setClipToPadding(false);
}
ViewCompat.setOnApplyWindowInsetsListener(view, (v, insets) -> {
Insets bars = insets.getInsets(
WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout());
// Measured from the bottom of the window, so it includes the navigation bar while showing
int keyboard = insets.getInsets(WindowInsetsCompat.Type.ime()).bottom;

// The keyboard covers the navigation bar, so only pad for whatever part of it the keyboard doesn't cover
v.setPadding(left + bars.left, top, right + bars.right, bottom + Math.max(bars.bottom - keyboard, 0));

// bars.top includes the action bar (see the class comment)
ViewGroup.LayoutParams params = v.getLayoutParams();
if (params instanceof ViewGroup.MarginLayoutParams) {
ViewGroup.MarginLayoutParams margins = (ViewGroup.MarginLayoutParams) params;
if (margins.topMargin != bars.top || margins.bottomMargin != keyboard) {
margins.topMargin = bars.top;
margins.bottomMargin = keyboard;
v.setLayoutParams(margins);
}
}
return insets;
});
ViewCompat.requestApplyInsets(view);
}
}
32 changes: 4 additions & 28 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,29 +1,5 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

repositories {
google()
jcenter()

}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.2'


// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
google()
jcenter()

}
}

task clean(type: Delete) {
delete rootProject.buildDir
// Top-level build file. Plugin versions live in gradle/libs.versions.toml;
// repositories are declared in settings.gradle.
plugins {
alias(libs.plugins.android.application) apply false
}
4 changes: 1 addition & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
Expand All @@ -15,6 +15,4 @@ org.gradle.jvmargs=-Xmx1536m
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true

9 changes: 9 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[versions]
agp = "9.5.0"
appcompat = "1.8.0"

[libraries]
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
10 changes: 7 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#Tue Jan 10 12:42:35 PST 2023
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
distributionSha256Sum=21bd5da2de49b642904077f38c0efdc7778e92b3ed0889392dca61b97e389607
distributionUrl=https\://services.gradle.org/distributions/gradle-9.8.2-bin.zip
networkTimeout=10000
retries=0
retryBackOffMs=500
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading
Loading