mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-09 11:28:34 +00:00
Deprecate some ViewUtil methods. Inline others. Remove some old API code.
This commit is contained in:
parent
75f3fe0cec
commit
959718618f
@ -90,9 +90,9 @@ public final class RecyclerViewFastScroller extends LinearLayout {
|
|||||||
final int action = event.getAction();
|
final int action = event.getAction();
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case MotionEvent.ACTION_DOWN:
|
case MotionEvent.ACTION_DOWN:
|
||||||
if (event.getX() < ViewUtil.getX(handle) - handle.getPaddingLeft() ||
|
if (event.getX() < handle.getX() - handle.getPaddingLeft() ||
|
||||||
event.getY() < ViewUtil.getY(handle) - handle.getPaddingTop() ||
|
event.getY() < handle.getY() - handle.getPaddingTop() ||
|
||||||
event.getY() > ViewUtil.getY(handle) + handle.getHeight() + handle.getPaddingBottom())
|
event.getY() > handle.getY() + handle.getHeight() + handle.getPaddingBottom())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -150,9 +150,9 @@ public final class RecyclerViewFastScroller extends LinearLayout {
|
|||||||
if (recyclerView != null) {
|
if (recyclerView != null) {
|
||||||
final int itemCount = recyclerView.getAdapter().getItemCount();
|
final int itemCount = recyclerView.getAdapter().getItemCount();
|
||||||
float proportion;
|
float proportion;
|
||||||
if (ViewUtil.getY(handle) == 0) {
|
if (handle.getY() == 0) {
|
||||||
proportion = 0f;
|
proportion = 0f;
|
||||||
} else if (ViewUtil.getY(handle) + handle.getHeight() >= height - TRACK_SNAP_RANGE) {
|
} else if (handle.getY() + handle.getHeight() >= height - TRACK_SNAP_RANGE) {
|
||||||
proportion = 1f;
|
proportion = 1f;
|
||||||
} else {
|
} else {
|
||||||
proportion = y / (float)height;
|
proportion = y / (float)height;
|
||||||
@ -169,10 +169,10 @@ public final class RecyclerViewFastScroller extends LinearLayout {
|
|||||||
final int handleHeight = handle.getHeight();
|
final int handleHeight = handle.getHeight();
|
||||||
final int bubbleHeight = bubble.getHeight();
|
final int bubbleHeight = bubble.getHeight();
|
||||||
final int handleY = Util.clamp((int)((height - handleHeight) * y), 0, height - handleHeight);
|
final int handleY = Util.clamp((int)((height - handleHeight) * y), 0, height - handleHeight);
|
||||||
ViewUtil.setY(handle, handleY);
|
handle.setY(handleY);
|
||||||
ViewUtil.setY(bubble, Util.clamp(handleY - bubbleHeight - bubble.getPaddingBottom() + handleHeight,
|
bubble.setY(Util.clamp(handleY - bubbleHeight - bubble.getPaddingBottom() + handleHeight,
|
||||||
0,
|
0,
|
||||||
height - bubbleHeight));
|
height - bubbleHeight));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showBubble() {
|
private void showBubble() {
|
||||||
|
@ -21,15 +21,6 @@ import android.app.Activity;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Build.VERSION;
|
|
||||||
import android.os.Build.VERSION_CODES;
|
|
||||||
import androidx.annotation.IdRes;
|
|
||||||
import androidx.annotation.LayoutRes;
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.core.view.ViewCompat;
|
|
||||||
import androidx.interpolator.view.animation.FastOutSlowInInterpolator;
|
|
||||||
|
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@ -39,63 +30,26 @@ import android.view.ViewStub;
|
|||||||
import android.view.animation.AlphaAnimation;
|
import android.view.animation.AlphaAnimation;
|
||||||
import android.view.animation.Animation;
|
import android.view.animation.Animation;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.LinearLayout.LayoutParams;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.IdRes;
|
||||||
|
import androidx.annotation.LayoutRes;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.core.view.ViewCompat;
|
||||||
|
import androidx.interpolator.view.animation.FastOutSlowInInterpolator;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.util.concurrent.ListenableFuture;
|
import org.thoughtcrime.securesms.util.concurrent.ListenableFuture;
|
||||||
import org.thoughtcrime.securesms.util.concurrent.SettableFuture;
|
import org.thoughtcrime.securesms.util.concurrent.SettableFuture;
|
||||||
import org.thoughtcrime.securesms.util.views.Stub;
|
import org.thoughtcrime.securesms.util.views.Stub;
|
||||||
|
|
||||||
public class ViewUtil {
|
public final class ViewUtil {
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
|
private ViewUtil() {
|
||||||
|
}
|
||||||
|
|
||||||
public static void setBackground(final @NonNull View v, final @Nullable Drawable drawable) {
|
public static void setBackground(final @NonNull View v, final @Nullable Drawable drawable) {
|
||||||
if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
|
v.setBackground(drawable);
|
||||||
v.setBackground(drawable);
|
|
||||||
} else {
|
|
||||||
v.setBackgroundDrawable(drawable);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setY(final @NonNull View v, final int y) {
|
|
||||||
if (VERSION.SDK_INT >= 11) {
|
|
||||||
ViewCompat.setY(v, y);
|
|
||||||
} else {
|
|
||||||
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams)v.getLayoutParams();
|
|
||||||
params.topMargin = y;
|
|
||||||
v.setLayoutParams(params);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float getY(final @NonNull View v) {
|
|
||||||
if (VERSION.SDK_INT >= 11) {
|
|
||||||
return ViewCompat.getY(v);
|
|
||||||
} else {
|
|
||||||
return ((ViewGroup.MarginLayoutParams)v.getLayoutParams()).topMargin;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setX(final @NonNull View v, final int x) {
|
|
||||||
if (VERSION.SDK_INT >= 11) {
|
|
||||||
ViewCompat.setX(v, x);
|
|
||||||
} else {
|
|
||||||
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams)v.getLayoutParams();
|
|
||||||
params.leftMargin = x;
|
|
||||||
v.setLayoutParams(params);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float getX(final @NonNull View v) {
|
|
||||||
if (VERSION.SDK_INT >= 11) {
|
|
||||||
return ViewCompat.getX(v);
|
|
||||||
} else {
|
|
||||||
return ((LayoutParams)v.getLayoutParams()).leftMargin;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void swapChildInPlace(ViewGroup parent, View toRemove, View toAdd, int defaultIndex) {
|
|
||||||
int childIndex = parent.indexOfChild(toRemove);
|
|
||||||
if (childIndex > -1) parent.removeView(toRemove);
|
|
||||||
parent.addView(toAdd, childIndex > -1 ? childIndex : defaultIndex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@ -103,18 +57,24 @@ public class ViewUtil {
|
|||||||
return (T)((ViewStub)parent.findViewById(stubId)).inflate();
|
return (T)((ViewStub)parent.findViewById(stubId)).inflate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
/**
|
||||||
|
* @deprecated Use {@link View#findViewById} directly.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public static <T extends View> T findById(@NonNull View parent, @IdRes int resId) {
|
public static <T extends View> T findById(@NonNull View parent, @IdRes int resId) {
|
||||||
return (T) parent.findViewById(resId);
|
return parent.findViewById(resId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
/**
|
||||||
|
* @deprecated Use {@link Activity#findViewById} directly.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public static <T extends View> T findById(@NonNull Activity parent, @IdRes int resId) {
|
public static <T extends View> T findById(@NonNull Activity parent, @IdRes int resId) {
|
||||||
return (T) parent.findViewById(resId);
|
return parent.findViewById(resId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends View> Stub<T> findStubById(@NonNull Activity parent, @IdRes int resId) {
|
public static <T extends View> Stub<T> findStubById(@NonNull Activity parent, @IdRes int resId) {
|
||||||
return new Stub<T>((ViewStub)parent.findViewById(resId));
|
return new Stub<>(parent.findViewById(resId));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Animation getAlphaAnimation(float from, float to, int duration) {
|
private static Animation getAlphaAnimation(float from, float to, int duration) {
|
||||||
@ -182,18 +142,15 @@ public class ViewUtil {
|
|||||||
|
|
||||||
@SuppressLint("RtlHardcoded")
|
@SuppressLint("RtlHardcoded")
|
||||||
public static void setTextViewGravityStart(final @NonNull TextView textView, @NonNull Context context) {
|
public static void setTextViewGravityStart(final @NonNull TextView textView, @NonNull Context context) {
|
||||||
if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1) {
|
if (DynamicLanguage.getLayoutDirection(context) == View.LAYOUT_DIRECTION_RTL) {
|
||||||
if (DynamicLanguage.getLayoutDirection(context) == View.LAYOUT_DIRECTION_RTL) {
|
textView.setGravity(Gravity.RIGHT);
|
||||||
textView.setGravity(Gravity.RIGHT);
|
} else {
|
||||||
} else {
|
textView.setGravity(Gravity.LEFT);
|
||||||
textView.setGravity(Gravity.LEFT);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void mirrorIfRtl(View view, Context context) {
|
public static void mirrorIfRtl(View view, Context context) {
|
||||||
if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1 &&
|
if (DynamicLanguage.getLayoutDirection(context) == View.LAYOUT_DIRECTION_RTL) {
|
||||||
DynamicLanguage.getLayoutDirection(context) == View.LAYOUT_DIRECTION_RTL) {
|
|
||||||
view.setScaleX(-1.0f);
|
view.setScaleX(-1.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user