bigger hitbox for alt indicator

closes sk22#353
This commit is contained in:
sk
2023-01-23 20:13:01 +01:00
committed by LucasGGamerM
parent ce6b928964
commit fff7949e51
2 changed files with 66 additions and 55 deletions

View File

@@ -12,7 +12,6 @@ import android.view.ViewTreeObserver;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ScrollView;
import android.widget.TextView; import android.widget.TextView;
import org.joinmastodon.android.GlobalUserPreferences; import org.joinmastodon.android.GlobalUserPreferences;
@@ -38,7 +37,7 @@ public class PhotoStatusDisplayItem extends ImageStatusDisplayItem{
} }
public static class Holder extends ImageStatusDisplayItem.Holder<PhotoStatusDisplayItem>{ public static class Holder extends ImageStatusDisplayItem.Holder<PhotoStatusDisplayItem>{
private final FrameLayout altTextWrapper; private final FrameLayout altTextWrapper, altTextOpen;
private final TextView altTextButton; private final TextView altTextButton;
private final ImageView noAltTextButton; private final ImageView noAltTextButton;
private final View altTextScroller; private final View altTextScroller;
@@ -52,14 +51,13 @@ public class PhotoStatusDisplayItem extends ImageStatusDisplayItem{
public Holder(Activity activity, ViewGroup parent){ public Holder(Activity activity, ViewGroup parent){
super(activity, R.layout.display_item_photo, parent); super(activity, R.layout.display_item_photo, parent);
altTextWrapper=findViewById(R.id.alt_text_wrapper); altTextWrapper=findViewById(R.id.alt_text_wrapper);
altTextOpen=findViewById(R.id.alt_text_open);
altTextButton=findViewById(R.id.alt_button); altTextButton=findViewById(R.id.alt_button);
noAltTextButton=findViewById(R.id.no_alt_button); noAltTextButton=findViewById(R.id.no_alt_button);
altTextScroller=findViewById(R.id.alt_text_scroller); altTextScroller=findViewById(R.id.alt_text_scroller);
altTextClose=findViewById(R.id.alt_text_close); altTextClose=findViewById(R.id.alt_text_close);
altText=findViewById(R.id.alt_text); altText=findViewById(R.id.alt_text);
altTextButton.setOnClickListener(this::onShowHideClick);
noAltTextButton.setOnClickListener(this::onShowHideClick);
altTextClose.setOnClickListener(this::onShowHideClick); altTextClose.setOnClickListener(this::onShowHideClick);
// altTextScroller.setNestedScrollingEnabled(true); // altTextScroller.setNestedScrollingEnabled(true);
} }
@@ -80,6 +78,7 @@ public class PhotoStatusDisplayItem extends ImageStatusDisplayItem{
altTextButton.setAlpha(1f); altTextButton.setAlpha(1f);
noAltTextButton.setAlpha(1f); noAltTextButton.setAlpha(1f);
altTextWrapper.setVisibility(View.VISIBLE); altTextWrapper.setVisibility(View.VISIBLE);
altTextOpen.setOnClickListener(this::onShowHideClick);
if (altTextMissing){ if (altTextMissing){
if (GlobalUserPreferences.showNoAltIndicator) { if (GlobalUserPreferences.showNoAltIndicator) {
@@ -106,7 +105,9 @@ public class PhotoStatusDisplayItem extends ImageStatusDisplayItem{
} }
private void onShowHideClick(View v){ private void onShowHideClick(View v){
boolean show=v.getId()==R.id.alt_button || v.getId()==R.id.no_alt_button; boolean show=v.getId()==R.id.alt_text_open;
altTextOpen.setOnClickListener(show ? null : this::onShowHideClick);
if(altTextShown==show) if(altTextShown==show)
return; return;
@@ -127,7 +128,8 @@ public class PhotoStatusDisplayItem extends ImageStatusDisplayItem{
// This is the current size... // This is the current size...
int prevLeft=altTextWrapper.getLeft(); int prevLeft=altTextWrapper.getLeft();
int prevRight=altTextWrapper.getRight(); int prevRight=altTextWrapper.getRight();
int prevTop=altTextWrapper.getTop(); int prevBottom=altTextWrapper.getBottom();
int prevTop=altTextOpen.getTop();
altTextWrapper.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener(){ altTextWrapper.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener(){
@Override @Override
public boolean onPreDraw(){ public boolean onPreDraw(){
@@ -144,7 +146,8 @@ public class PhotoStatusDisplayItem extends ImageStatusDisplayItem{
set.playTogether( set.playTogether(
ObjectAnimator.ofInt(altTextWrapper, "left", prevLeft, altTextWrapper.getLeft()), ObjectAnimator.ofInt(altTextWrapper, "left", prevLeft, altTextWrapper.getLeft()),
ObjectAnimator.ofInt(altTextWrapper, "right", prevRight, altTextWrapper.getRight()), ObjectAnimator.ofInt(altTextWrapper, "right", prevRight, altTextWrapper.getRight()),
ObjectAnimator.ofInt(altTextWrapper, "top", prevTop, altTextWrapper.getTop()), ObjectAnimator.ofInt(altTextWrapper, "bottom", prevBottom, altTextWrapper.getBottom()),
ObjectAnimator.ofInt(altTextOpen, "top", prevTop, altTextOpen.getTop()),
ObjectAnimator.ofFloat(altOrNoAltButton, View.ALPHA, show ? 1f : 0f, show ? 0f : 1f), ObjectAnimator.ofFloat(altOrNoAltButton, View.ALPHA, show ? 1f : 0f, show ? 0f : 1f),
ObjectAnimator.ofFloat(altTextScroller, View.ALPHA, show ? 0f : 1f, show ? 1f : 0f), ObjectAnimator.ofFloat(altTextScroller, View.ALPHA, show ? 0f : 1f, show ? 1f : 0f),
ObjectAnimator.ofFloat(altTextClose, View.ALPHA, show ? 0f : 1f, show ? 1f : 0f) ObjectAnimator.ofFloat(altTextClose, View.ALPHA, show ? 0f : 1f, show ? 1f : 0f)

View File

@@ -12,12 +12,18 @@
android:scaleType="centerCrop"/> android:scaleType="centerCrop"/>
<!-- This is hidden from screenreaders because that same alt text is set as content description on the ImageView --> <!-- This is hidden from screenreaders because that same alt text is set as content description on the ImageView -->
<FrameLayout
android:id="@+id/alt_text_open"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start|bottom"
android:padding="12dp">
<FrameLayout <FrameLayout
android:id="@+id/alt_text_wrapper" android:id="@+id/alt_text_wrapper"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="start|bottom" android:layout_gravity="start|bottom"
android:layout_margin="12dp"
android:importantForAccessibility="noHideDescendants" android:importantForAccessibility="noHideDescendants"
android:background="@drawable/bg_image_alt_overlay"> android:background="@drawable/bg_image_alt_overlay">
@@ -77,4 +83,6 @@
</FrameLayout> </FrameLayout>
</FrameLayout>
</org.joinmastodon.android.ui.views.ImageAttachmentFrameLayout> </org.joinmastodon.android.ui.views.ImageAttachmentFrameLayout>