Skip to content

Commit 05407de

Browse files
authored
Fix: Makes service alert scrollable and fix text color (#1456)
fixes #1454 Makes service alert scrollable and fix text color
1 parent a8def4a commit 05407de

File tree

2 files changed

+82
-22
lines changed

2 files changed

+82
-22
lines changed

onebusaway-android/src/main/java/org/onebusaway/android/ui/SituationDialogFragment.java

Lines changed: 79 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,16 @@
1919
import android.content.ContentValues;
2020
import android.content.DialogInterface;
2121
import android.content.Intent;
22+
import android.content.res.Configuration;
23+
import android.graphics.Color;
2224
import android.net.Uri;
2325
import android.os.Bundle;
2426
import android.text.Html;
2527
import android.text.TextUtils;
2628
import android.text.style.ClickableSpan;
2729
import android.view.View;
30+
import android.view.ViewGroup;
31+
import android.widget.ScrollView;
2832
import android.widget.TextView;
2933

3034
import androidx.appcompat.app.AlertDialog;
@@ -53,6 +57,8 @@ public class SituationDialogFragment extends DialogFragment {
5357

5458
public static final String URL = ".Url";
5559

60+
private static final float MAX_DIALOG_HEIGHT_RATIO = 0.65f;
61+
5662
interface Listener {
5763

5864
/**
@@ -137,7 +143,7 @@ public void onClick(View v) {
137143

138144
// Show the snackbar
139145
Snackbar.make(getActivity().findViewById(R.id.fragment_arrivals_list),
140-
R.string.all_alert_hidden_snackbar_text, Snackbar.LENGTH_SHORT)
146+
R.string.all_alert_hidden_snackbar_text, Snackbar.LENGTH_SHORT)
141147
.show();
142148

143149
dialog.dismiss();
@@ -158,40 +164,93 @@ public void onClick(DialogInterface dialog, int which) {
158164
final AlertDialog dialog = builder.create();
159165
dialog.show();
160166

161-
// Set the title, description, and URL (if provided)
162-
TextView title = (TextView) dialog.findViewById(R.id.alert_title);
163-
title.setText(args.getString(TITLE));
167+
// Ensure the alert ScrollView has a max height so it becomes scrollable
168+
// when there is lots of content instead of expanding the dialog infinitely.
169+
ScrollView scrollView = (ScrollView) dialog.findViewById(R.id.alert_scrollview);
170+
if (scrollView != null) {
171+
// Capture screen height before posting to avoid accessing resources after
172+
// detachment.
173+
final int screenHeight = getResources().getDisplayMetrics().heightPixels;
174+
// Post to ensure views are measured before checking/setting height.
175+
scrollView.post(() -> {
176+
if (!isAdded())
177+
return;
178+
// Use ~65% of the screen height as a reasonable max dialog height.
179+
final int maxHeightPx = (int) (MAX_DIALOG_HEIGHT_RATIO * screenHeight);
180+
if (scrollView.getHeight() > maxHeightPx) {
181+
ViewGroup.LayoutParams lp = scrollView.getLayoutParams();
182+
lp.height = maxHeightPx;
183+
scrollView.setLayoutParams(lp);
184+
}
185+
});
186+
}
164187

165-
TextView descTxtView = (TextView) dialog.findViewById(R.id.alert_description);
188+
// --- START MANUAL DARK MODE CHECK ---
189+
190+
// 1. Get the current UI mode from the dialog's context
191+
int currentNightMode = dialog.getContext().getResources().getConfiguration().uiMode
192+
& Configuration.UI_MODE_NIGHT_MASK;
193+
194+
// 2. Define the colors based on the mode
195+
int textColor;
196+
int linkColor;
197+
198+
if (currentNightMode == Configuration.UI_MODE_NIGHT_YES) {
199+
// Dark Mode: Use light colors
200+
textColor = Color.WHITE;
201+
linkColor = Color.CYAN; // A light blue for links
202+
} else {
203+
// Light Mode: Use dark colors
204+
textColor = Color.BLACK;
205+
linkColor = Color.BLUE; // Standard dark blue for links
206+
}
207+
// --- END MANUAL DARK MODE CHECK ---
166208

167-
String desc = args.getString(DESCRIPTION);
209+
// 3. Apply the colors
210+
TextView title = (TextView) dialog.findViewById(R.id.alert_title);
211+
if (title != null) {
212+
title.setText(args.getString(TITLE));
213+
// The title's background (@color/theme_primary) is dark, so title text should
214+
// always be light.
215+
title.setTextColor(Color.WHITE);
216+
}
168217

218+
TextView descTxtView = (TextView) dialog.findViewById(R.id.alert_description);
169219
if (descTxtView != null) {
220+
descTxtView.setTextColor(textColor);
221+
descTxtView.setLinkTextColor(linkColor);
222+
223+
String desc = args.getString(DESCRIPTION);
170224
if (!TextUtils.isEmpty(desc)) {
171225
String htmlDescription = desc.replaceAll("\\r\\n|\\r|\\n", "<br>");
172226
descTxtView.setText(Html.fromHtml(htmlDescription));
173227
} else {
174228
descTxtView.setText(R.string.no_description_available);
175229
}
176230
}
231+
177232
TextView urlView = (TextView) dialog.findViewById(R.id.alert_url);
233+
if (urlView != null) {
234+
urlView.setTextColor(linkColor);
235+
urlView.setLinkTextColor(linkColor);
178236

179-
// Remove any previous clickable spans just to be safe
180-
UIUtils.removeAllClickableSpans(urlView);
237+
// Remove any previous clickable spans just to be safe
238+
UIUtils.removeAllClickableSpans(urlView);
181239

182-
final String url = args.getString(URL);
183-
if (!TextUtils.isEmpty(url)) {
184-
urlView.setVisibility(View.VISIBLE);
240+
final String url = args.getString(URL);
241+
if (!TextUtils.isEmpty(url)) {
242+
urlView.setVisibility(View.VISIBLE);
185243

186-
ClickableSpan urlClick = new ClickableSpan() {
187-
public void onClick(View v) {
188-
getActivity().startActivity(
189-
new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
190-
}
191-
};
192-
UIUtils.setClickableSpan(urlView, urlClick);
193-
} else {
194-
urlView.setVisibility(View.GONE);
244+
ClickableSpan urlClick = new ClickableSpan() {
245+
public void onClick(View v) {
246+
getActivity().startActivity(
247+
new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
248+
}
249+
};
250+
UIUtils.setClickableSpan(urlView, urlClick);
251+
} else {
252+
urlView.setVisibility(View.GONE);
253+
}
195254
}
196255

197256
// Update the database to indicate that this alert has been read

onebusaway-android/src/main/res/layout/situation.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
android:orientation="vertical"
2020
android:layout_width="match_parent"
2121
android:layout_height="wrap_content"
22-
android:background="@color/listview_background">
22+
android:background="?android:attr/colorBackground">
2323

2424
<LinearLayout
2525
android:id="@+id/situation_header"
@@ -42,7 +42,8 @@
4242
android:layout_width="fill_parent"
4343
android:layout_height="wrap_content"
4444
android:layout_below="@+id/situation_header"
45-
android:background="@color/listview_background">
45+
android:background="?android:attr/colorBackground">
46+
4647
<LinearLayout
4748
xmlns:android="http://schemas.android.com/apk/res/android"
4849
android:orientation="vertical"

0 commit comments

Comments
 (0)