Skip to content

Commit

Permalink
fix: Allow Status card text to scroll horizontally
Browse files Browse the repository at this point in the history
This allows the user to scroll the card contents if the text overflows the right side of the screen, as is the case with users that use large fonts or devices with very narrow screens.

Unfortunately this breaks the ripple effect when tapping on the top card to copy the location to the clipboard :(, but the functionality to scroll is more important.

Closes #467
  • Loading branch information
barbeau committed Feb 11, 2021
1 parent 7982ed6 commit 84b299a
Show file tree
Hide file tree
Showing 2 changed files with 206 additions and 180 deletions.
39 changes: 25 additions & 14 deletions GPSTest/src/main/java/com/android/gpstest/GpsStatusFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@
import android.text.TextUtils;
import android.text.format.DateFormat;
import android.text.style.ClickableSpan;
import android.view.GestureDetector;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TableRow;
Expand All @@ -50,8 +53,8 @@
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AlertDialog;
import androidx.cardview.widget.CardView;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.core.view.GestureDetectorCompat;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
Expand Down Expand Up @@ -111,7 +114,7 @@ public class GpsStatusFragment extends Fragment implements GpsTestListener {
mPdopLabelView, mPdopView, mHvdopLabelView, mHvdopView, mGnssNotAvailableView,
mSbasNotAvailableView, mFixTimeErrorView;

private CardView mLocationCard;
private HorizontalScrollView locationScrollView;

private ViewGroup filterGroup;
private TextView filterTextView;
Expand Down Expand Up @@ -218,21 +221,29 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
mFlagEU = getResources().getDrawable(R.drawable.ic_flag_european_union);
mFlagICAO = getResources().getDrawable(R.drawable.ic_flag_icao);

mLocationCard = v.findViewById(R.id.status_location_card);
mLocationCard.setOnClickListener(view -> {
final Location location = mLocation;
// Copy location to clipboard
if (location != null) {
boolean includeAltitude = Application.getPrefs().getBoolean(Application.get().getString(R.string.pref_key_share_include_altitude), false);
String coordinateFormat = Application.getPrefs().getString(Application.get().getString(R.string.pref_key_coordinate_format), Application.get().getString(R.string.preferences_coordinate_format_dd_key));
String formattedLocation = UIUtils.formatLocationForDisplay(location, null, includeAltitude,
null, null, null, coordinateFormat);
if (!TextUtils.isEmpty(formattedLocation)) {
IOUtils.copyToClipboard(formattedLocation);
Toast.makeText(getActivity(), R.string.copied_to_clipboard, Toast.LENGTH_LONG).show();
GestureDetectorCompat detector = new GestureDetectorCompat(getContext(), new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onSingleTapUp(MotionEvent e) {
final Location location = mLocation;
// Copy location to clipboard
if (location != null) {
boolean includeAltitude = Application.getPrefs().getBoolean(Application.get().getString(R.string.pref_key_share_include_altitude), false);
String coordinateFormat = Application.getPrefs().getString(Application.get().getString(R.string.pref_key_coordinate_format), Application.get().getString(R.string.preferences_coordinate_format_dd_key));
String formattedLocation = UIUtils.formatLocationForDisplay(location, null, includeAltitude,
null, null, null, coordinateFormat);
if (!TextUtils.isEmpty(formattedLocation)) {
IOUtils.copyToClipboard(formattedLocation);
Toast.makeText(getActivity(), R.string.copied_to_clipboard, Toast.LENGTH_LONG).show();
}
}
return false;
}
});
locationScrollView = v.findViewById(R.id.status_location_scrollview);
locationScrollView.setOnTouchListener((view, motionEvent) -> {
detector.onTouchEvent(motionEvent);
return false;
});

// GNSS filter
filterGroup = v.findViewById(R.id.status_filter_group);
Expand Down
Loading

0 comments on commit 84b299a

Please sign in to comment.