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

feat(#362): support Android 15 #364

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def getVersionName = {
}

android {
compileSdk 34
compileSdkPreview "VanillaIceCream"
packagingOptions {
resources {
excludes += ['META-INF/LICENSE', 'META-INF/NOTICE']
Expand All @@ -114,7 +114,7 @@ android {

defaultConfig {
//noinspection OldTargetApi
targetSdkVersion 34
targetSdkPreview "VanillaIceCream"
minSdkVersion 21 // Android 5.0
versionCode getVersionCode()
versionName getVersionName()
Expand Down
1 change: 1 addition & 0 deletions src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<application android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:allowBackup="false"
android:allowCrossUidActivitySwitchFromBelow="false"
android:fullBackupContent="@xml/backup_rules_sdk_30_and_lower"
android:dataExtractionRules="@xml/backup_rules"
android:largeHeap="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.webkit.ConsoleMessage;
import android.webkit.GeolocationPermissions;
Expand All @@ -33,6 +35,9 @@
import android.widget.Toast;

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

import java.util.Arrays;
import java.util.Optional;
Expand Down Expand Up @@ -83,26 +88,31 @@ public void onReceiveValue(String result) {

this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
View webviewContainer = findViewById(R.id.lytWebView);
// TODO: replace `UPSIDE_DOWN_CAKE` with `VANILLA_ICE_CREAM` when SDK 35 comes out of preview
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
ViewCompat.requestApplyInsets(webviewContainer.getRootView());
// ((View) webviewContainer.getParent()).requestApplyInsets();
}

// Add an alarming red border if using configurable (i.e. dev)
// app with a medic production server.
if (settings.allowsConfiguration() && appUrl != null && appUrl.contains("app.medicmobile.org")) {
View webviewContainer = findViewById(R.id.lytWebView);
webviewContainer.setPadding(10, 10, 10, 10);
webviewContainer.setBackgroundResource(R.drawable.warning_background);
}

// Add a noticeable border to easily identify a training app
if (BuildConfig.IS_TRAINING_APP) {
View webviewContainer = findViewById(R.id.lytWebView);
webviewContainer.setPadding(10, 10, 10, 10);
webviewContainer.setBackgroundResource(R.drawable.training_background);
}

container = findViewById(R.id.wbvMain);

getFragmentManager()
.beginTransaction()
.add(new OpenSettingsDialogFragment(container), OpenSettingsDialogFragment.class.getName())
.add(new OpenSettingsDialogFragment(), OpenSettingsDialogFragment.class.getName())
.commit();

configureUserAgent();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.medicmobile.webapp.mobile;

import static org.medicmobile.webapp.mobile.MedicLog.trace;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Fragment;
Expand All @@ -16,7 +18,7 @@
@SuppressLint("ValidFragment")
public class OpenSettingsDialogFragment extends Fragment {

private final View view;
private View view;
private int fingerTapCount = 0;
private long lastTimeTap = 0;
private GestureHandler swipeGesture;
Expand All @@ -32,14 +34,11 @@ public boolean onTouch(View view, MotionEvent event) {
}
};

public OpenSettingsDialogFragment(View view) {
this.view = view;
}

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
view.setOnTouchListener(onTouchListener);
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
this.view = view.findViewById(R.id.wbvMain);
this.view.setOnTouchListener(onTouchListener);
}

private void countTaps(MotionEvent event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
Expand All @@ -19,6 +20,7 @@
import android.widget.ListView;
import android.widget.TextView;

import androidx.core.view.ViewCompat;
import androidx.fragment.app.FragmentActivity;

import org.medicmobile.webapp.mobile.adapters.FilterableListAdapter;
Expand Down Expand Up @@ -60,10 +62,16 @@ private void displayServerSelectList() {

setContentView(R.layout.server_select_list);

ListView list = findViewById(R.id.lstServers);
// TODO: replace `UPSIDE_DOWN_CAKE` with `VANILLA_ICE_CREAM` when SDK 35 comes out of preview
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
View view = findViewById(R.id.serverSelectListLayout);
ViewCompat.requestApplyInsets(view.getRootView());
// ((View) view.getParent()).requestApplyInsets();
}

List<ServerMetadata> servers = serverRepo.getServers();
ServerMetadataAdapter adapter = ServerMetadataAdapter.createInstance(this, servers);
ListView list = findViewById(R.id.lstServers);
list.setAdapter(adapter);
list.setOnItemClickListener(new ServerClickListener(adapter));

Expand All @@ -80,6 +88,12 @@ private void displayCustomServerForm() {
state = STATE_FORM;

setContentView(R.layout.custom_server_form);
// TODO: replace `UPSIDE_DOWN_CAKE` with `VANILLA_ICE_CREAM` when SDK 35 comes out of preview
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
View view = findViewById(R.id.customServerFormLayout);
ViewCompat.requestApplyInsets(view.getRootView());
// ((View) view.getParent()).requestApplyInsets();
}

if(!this.settings.hasWebappSettings()) {
cancelButton().setVisibility(View.GONE);
Expand Down
64 changes: 35 additions & 29 deletions src/main/res/layout/custom_server_form.xml
Original file line number Diff line number Diff line change
@@ -1,36 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:orientation="vertical">
<EditText android:id="@+id/txtAppUrl"
android:hint="@string/txtAppUrl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textUri"
android:autofillHints=""
android:padding="32dp"/>
<!-- OnClick is ignored because lint generates error
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/customServerFormLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp">

<EditText
android:id="@+id/txtAppUrl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autofillHints=""
android:hint="@string/txtAppUrl"
android:inputType="textUri"
android:padding="32dp" />
<!-- OnClick is ignored because lint generates error
incorrectly. Test with future build tool versions
to see if this exception can be removed -->
<Button android:id="@+id/btnCancelSettings"
style="@style/standardButton"
android:layout_toStartOf="@+id/btnSaveSettings"
android:layout_alignParentBottom="true"
android:onClick="cancelSettingsEdit"
android:text="@string/btnCancel"
tools:ignore="OnClick" />
<!-- OnClick is ignored because lint generates error
<Button
android:id="@+id/btnCancelSettings"
style="@style/standardButton"
android:layout_alignParentBottom="true"
android:layout_toStartOf="@+id/btnSaveSettings"
android:onClick="cancelSettingsEdit"
android:text="@string/btnCancel"
tools:ignore="OnClick" />
<!-- OnClick is ignored because lint generates error
incorrectly. Test with future build tool versions
to see if this exception can be removed -->
<Button android:id="@+id/btnSaveSettings"
style="@style/standardButton"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:onClick="verifyAndSave"
android:text="@string/btnSave"
tools:ignore="OnClick" />
<Button
android:id="@+id/btnSaveSettings"
style="@style/standardButton"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:onClick="verifyAndSave"
android:text="@string/btnSave"
tools:ignore="OnClick" />
</RelativeLayout>
3 changes: 2 additions & 1 deletion src/main/res/layout/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/lytWebView"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
android:layout_height="fill_parent"
android:fitsSystemWindows="true">
<WebView android:id="@+id/wbvMain"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
Expand Down
11 changes: 7 additions & 4 deletions src/main/res/layout/server_select_list.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/serverSelectListLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fitsSystemWindows="true"
android:orientation="vertical">

<EditText android:id="@+id/instanceSearchBox"
android:hint="@string/instancesSearch"
<EditText
android:id="@+id/instanceSearchBox"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textUri"
android:autofillHints=""
android:padding="32dp"/>
android:hint="@string/instancesSearch"
android:inputType="textUri"
android:padding="32dp" />

<ListView
android:id="@+id/lstServers"
Expand Down
Loading