Skip to content

Commit ccc953b

Browse files
committed
Limit caption height in media viewer
1 parent 03a2070 commit ccc953b

File tree

4 files changed

+91
-11
lines changed

4 files changed

+91
-11
lines changed

app/src/main/java/org/thunderdog/challegram/mediaview/MediaCellView.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1594,7 +1594,8 @@ public boolean onInterceptTouchEvent (MotionEvent ev) {
15941594
if (canTouch(isDown)) {
15951595
detector.onTouchEvent(ev);
15961596
}
1597-
return interceptAnyEvents || super.onInterceptTouchEvent(ev);
1597+
boolean res = super.onInterceptTouchEvent(ev);
1598+
return res || interceptAnyEvents;
15981599
}
15991600

16001601
public boolean canZoom () {

app/src/main/java/org/thunderdog/challegram/mediaview/MediaViewController.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@
145145
import org.thunderdog.challegram.util.StringList;
146146
import org.thunderdog.challegram.util.text.Text;
147147
import org.thunderdog.challegram.util.text.TextEntity;
148+
import org.thunderdog.challegram.v.MaxHeightScrollView;
148149
import org.thunderdog.challegram.widget.AttachDelegate;
149150
import org.thunderdog.challegram.widget.CheckView;
150151
import org.thunderdog.challegram.widget.CustomTextView;
@@ -3133,7 +3134,7 @@ protected void onDraw (Canvas c) {
31333134
private StopwatchHeaderButton stopwatchButton;
31343135

31353136
private FrameLayoutFix bottomWrap;
3136-
private LinearLayout captionWrapView;
3137+
private ViewGroup captionWrapView;
31373138
private View captionView;
31383139
private InputView inputView;
31393140
private ImageView captionEmojiButton, captionDoneButton;
@@ -5197,14 +5198,21 @@ public boolean onTouchEvent (MotionEvent event) {
51975198
captionView.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
51985199
this.captionView = captionView;
51995200

5200-
captionWrapView = new LinearLayout(context);
5201-
captionWrapView.setOrientation(LinearLayout.VERTICAL);
5202-
captionWrapView.setBackgroundColor(Theme.getColor(ColorId.transparentEditor));
5203-
captionWrapView.setAlpha(0f);
5204-
captionWrapView.addView(captionView);
5205-
captionWrapView.setLayoutParams(FrameLayoutFix.newParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.BOTTOM));
52065201

5207-
bottomWrap.addView(captionWrapView);
5202+
LinearLayout captionWrap = new LinearLayout(context);
5203+
captionWrap.setOrientation(LinearLayout.VERTICAL);
5204+
captionWrap.addView(captionView);
5205+
captionWrap.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
5206+
5207+
MaxHeightScrollView scrollView = new MaxHeightScrollView(context);
5208+
scrollView.setMaxHeight(Text.getLineHeight(TGMessage.getTextStyleProvider(), true) * 10);
5209+
scrollView.addView(captionWrap);
5210+
scrollView.setAlpha(0f);
5211+
scrollView.setBackgroundColor(Theme.getColor(ColorId.transparentEditor));
5212+
scrollView.setLayoutParams(FrameLayoutFix.newParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.BOTTOM));
5213+
this.captionWrapView = scrollView;
5214+
5215+
bottomWrap.addView(this.captionWrapView);
52085216

52095217
videoSliderView = new VideoControlView(context);
52105218
videoSliderView.setOnPlayPauseClick(v -> {
@@ -8476,7 +8484,7 @@ public boolean showSlowModeRestriction (View v) {
84768484
private Args forceEditModeOld_arguments;
84778485
private FrameLayoutFix forceEditModeOld_bottomWrap;
84788486
private View forceEditModeOld_captionView;
8479-
private LinearLayout forceEditModeOld_captionWrapView;
8487+
private ViewGroup forceEditModeOld_captionWrapView;
84808488
private List<View> forceEditMode_views;
84818489

84828490
private boolean inForceEditMode () {
@@ -9009,7 +9017,7 @@ public void afterTextChanged (Editable s) {
90099017
captionEmojiButton.setEnabled(false);
90109018
captionEmojiButton.setLayoutParams(FrameLayoutFix.newParams(Screen.dp(55f), Screen.dp(52f), Gravity.LEFT | Gravity.BOTTOM));
90119019

9012-
captionWrapView = new LinearLayout(context) {
9020+
LinearLayout captionWrapView = new LinearLayout(context) {
90139021
@Override
90149022
public boolean onInterceptTouchEvent (MotionEvent ev) {
90159023
return getVisibility() != View.VISIBLE || getAlpha() != 1f;
@@ -9036,6 +9044,7 @@ public boolean onTouchEvent (MotionEvent event) {
90369044
captionWrapView.setBackgroundColor(Theme.getColor(ColorId.transparentEditor));
90379045
captionWrapView.addView(captionView);
90389046
captionWrapView.setLayoutParams(FrameLayoutFix.newParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.BOTTOM));
9047+
this.captionWrapView = captionWrapView;
90399048

90409049
if (!inProfilePhotoEditMode) {
90419050
bottomWrap.addView(captionWrapView);

app/src/main/java/org/thunderdog/challegram/util/text/Text.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2205,6 +2205,13 @@ int getAscent (float textSizePx) {
22052205
return -getFontMetrics(textSizePx).ascent;
22062206
}
22072207

2208+
2209+
public static int getLineHeight (TextStyleProvider textStyleProvider, boolean needPadding) {
2210+
TextPaint paint = textStyleProvider.getTextPaint();
2211+
Paint.FontMetricsInt fm = paint.getFontMetricsInt();
2212+
return (Math.abs(fm.descent - fm.ascent) + fm.leading) + (needPadding ? textStyleProvider.convertUnit(2f) : 0);
2213+
}
2214+
22082215
public int getLineHeight (boolean needPadding) {
22092216
Paint.FontMetricsInt fm = getFontMetrics();
22102217
return (Math.abs(fm.descent - fm.ascent) + fm.leading) + (needPadding ? getLineSpacing() : 0);
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package org.thunderdog.challegram.v;
2+
3+
import android.content.Context;
4+
import android.view.MotionEvent;
5+
import android.view.ViewParent;
6+
import android.widget.ScrollView;
7+
8+
public class MaxHeightScrollView extends ScrollView {
9+
public MaxHeightScrollView (Context context) {
10+
super(context);
11+
}
12+
13+
private int maxHeight;
14+
15+
public void setMaxHeight (int maxHeight) {
16+
if (this.maxHeight != maxHeight) {
17+
this.maxHeight = maxHeight;
18+
requestLayout();
19+
}
20+
}
21+
22+
private boolean isScrollable;
23+
24+
@Override
25+
protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) {
26+
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
27+
if (maxHeight != 0 && getMeasuredHeight() > maxHeight) {
28+
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(maxHeight, MeasureSpec.EXACTLY));
29+
isScrollable = true;
30+
} else {
31+
isScrollable = false;
32+
}
33+
}
34+
35+
@Override
36+
public boolean onTouchEvent (MotionEvent ev) {
37+
boolean res = super.onTouchEvent(ev) && (ev.getAction() != MotionEvent.ACTION_DOWN || isScrollable);
38+
switch (ev.getAction()) {
39+
case MotionEvent.ACTION_DOWN: {
40+
if (isScrollable) {
41+
ViewParent parent = getParent();
42+
if (parent != null) {
43+
parent.requestDisallowInterceptTouchEvent(true);
44+
}
45+
}
46+
break;
47+
}
48+
case MotionEvent.ACTION_UP:
49+
case MotionEvent.ACTION_CANCEL:
50+
ViewParent parent = getParent();
51+
if (parent != null) {
52+
parent.requestDisallowInterceptTouchEvent(false);
53+
}
54+
break;
55+
}
56+
return res;
57+
}
58+
59+
@Override
60+
public boolean onInterceptTouchEvent (MotionEvent ev) {
61+
return super.onInterceptTouchEvent(ev) && (ev.getAction() != MotionEvent.ACTION_DOWN || isScrollable);
62+
}
63+
}

0 commit comments

Comments
 (0)