kopia lustrzana https://github.com/ryukoposting/Signal-Android
Update tooltip to a more material look.
rodzic
ffd60af3ff
commit
a50e49e4e6
|
@ -14,11 +14,13 @@ import android.widget.TextView;
|
|||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.Px;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.mms.GlideApp;
|
||||
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||
|
||||
/**
|
||||
* Class for creating simple tooltips to show throughout the app. Utilizes a popup window so you
|
||||
|
@ -36,7 +38,8 @@ public class TooltipPopup extends PopupWindow {
|
|||
|
||||
private final View anchor;
|
||||
private final ImageView arrow;
|
||||
private final int position;
|
||||
private final int position;
|
||||
private final int startMargin;
|
||||
|
||||
public static Builder forTarget(@NonNull View anchor) {
|
||||
return new Builder(anchor);
|
||||
|
@ -44,6 +47,7 @@ public class TooltipPopup extends PopupWindow {
|
|||
|
||||
private TooltipPopup(@NonNull View anchor,
|
||||
int rawPosition,
|
||||
@Px int startMargin,
|
||||
@NonNull String text,
|
||||
@ColorInt int backgroundTint,
|
||||
@ColorInt int textColor,
|
||||
|
@ -54,8 +58,9 @@ public class TooltipPopup extends PopupWindow {
|
|||
ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
|
||||
this.anchor = anchor;
|
||||
this.position = getRtlPosition(anchor.getContext(), rawPosition);
|
||||
this.anchor = anchor;
|
||||
this.position = getRtlPosition(anchor.getContext(), rawPosition);
|
||||
this.startMargin = startMargin;
|
||||
|
||||
switch (rawPosition) {
|
||||
case POSITION_ABOVE: arrow = getContentView().findViewById(R.id.tooltip_arrow_bottom); break;
|
||||
|
@ -140,6 +145,19 @@ public class TooltipPopup extends PopupWindow {
|
|||
throw new AssertionError("Invalid tooltip position!");
|
||||
}
|
||||
|
||||
switch (position) {
|
||||
case POSITION_ABOVE:
|
||||
xoffset += startMargin;
|
||||
case POSITION_BELOW:
|
||||
xoffset += startMargin;
|
||||
break;
|
||||
case POSITION_LEFT:
|
||||
xoffset += startMargin;
|
||||
break;
|
||||
case POSITION_RIGHT:
|
||||
xoffset -= startMargin;
|
||||
}
|
||||
|
||||
showAsDropDown(anchor, xoffset, yoffset);
|
||||
}
|
||||
|
||||
|
@ -192,6 +210,7 @@ public class TooltipPopup extends PopupWindow {
|
|||
private int textResId;
|
||||
private Object iconGlideModel;
|
||||
private OnDismissListener dismissListener;
|
||||
private int setStartMargin;
|
||||
|
||||
private Builder(@NonNull View anchor) {
|
||||
this.anchor = anchor;
|
||||
|
@ -222,9 +241,14 @@ public class TooltipPopup extends PopupWindow {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder setStartMargin(@Px int startMargin) {
|
||||
this.setStartMargin = startMargin;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TooltipPopup show(int position) {
|
||||
String text = anchor.getContext().getString(textResId);
|
||||
TooltipPopup tooltip = new TooltipPopup(anchor, position, text, backgroundTint, textColor, iconGlideModel, dismissListener);
|
||||
TooltipPopup tooltip = new TooltipPopup(anchor, position, setStartMargin, text, backgroundTint, textColor, iconGlideModel, dismissListener);
|
||||
|
||||
tooltip.show();
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ import androidx.fragment.app.setFragmentResultListener
|
|||
import androidx.fragment.app.viewModels
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import org.signal.core.util.DimensionUnit
|
||||
import org.thoughtcrime.securesms.R
|
||||
import org.thoughtcrime.securesms.components.ContactFilterView
|
||||
import org.thoughtcrime.securesms.components.TooltipPopup
|
||||
|
@ -374,6 +375,7 @@ class MultiselectForwardFragment :
|
|||
private fun displayTooltip(anchor: View, @StringRes text: Int) {
|
||||
TooltipPopup
|
||||
.forTarget(anchor)
|
||||
.setStartMargin(DimensionUnit.DP.toPixels(16f).toInt())
|
||||
.setText(text)
|
||||
.setTextColor(ContextCompat.getColor(requireContext(), R.color.signal_colorOnPrimaryContainer))
|
||||
.setBackgroundTint(ContextCompat.getColor(requireContext(), R.color.signal_colorPrimaryContainer))
|
||||
|
|
|
@ -18,7 +18,6 @@ import com.google.android.material.tabs.TabLayoutMediator
|
|||
import org.thoughtcrime.securesms.R
|
||||
import org.thoughtcrime.securesms.components.FixedRoundedCornerBottomSheetDialogFragment
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId
|
||||
import org.thoughtcrime.securesms.stories.viewer.page.StoryViewerPageFragment
|
||||
import org.thoughtcrime.securesms.stories.viewer.page.StoryViewerPageViewModel
|
||||
import org.thoughtcrime.securesms.stories.viewer.reply.BottomSheetBehaviorDelegate
|
||||
import org.thoughtcrime.securesms.stories.viewer.reply.StoryViewsAndRepliesPagerChild
|
||||
|
|
|
@ -1,58 +1,55 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false">
|
||||
android:clipToPadding="false"
|
||||
android:maxWidth="320dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/tooltip_arrow_start"
|
||||
android:layout_width="8dp"
|
||||
android:layout_height="16dp"
|
||||
android:visibility="gone"
|
||||
android:scaleType="fitXY"
|
||||
android:elevation="6dp"
|
||||
android:scaleType="fitXY"
|
||||
android:visibility="gone"
|
||||
app:srcCompat="@drawable/ic_triangle_left"
|
||||
tools:visibility="visible"
|
||||
tools:tint="@color/core_blue"/>
|
||||
tools:tint="@color/core_blue"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false">
|
||||
android:clipToPadding="false"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/tooltip_arrow_top"
|
||||
android:layout_width="16dp"
|
||||
android:layout_height="8dp"
|
||||
android:visibility="gone"
|
||||
android:scaleType="fitXY"
|
||||
android:elevation="6dp"
|
||||
android:scaleType="fitXY"
|
||||
android:visibility="gone"
|
||||
app:srcCompat="@drawable/ic_triangle_up"
|
||||
tools:visibility="visible"
|
||||
tools:tint="@color/core_blue"/>
|
||||
tools:tint="@color/core_blue"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/tooltip_bubble"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:paddingTop="6dp"
|
||||
android:paddingBottom="6dp"
|
||||
android:paddingStart="12dp"
|
||||
android:paddingEnd="12dp"
|
||||
android:background="@drawable/tooltip_background"
|
||||
android:gravity="center_vertical"
|
||||
android:elevation="6dp"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false">
|
||||
android:clipToPadding="false"
|
||||
android:elevation="6dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:padding="16dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/tooltip_icon"
|
||||
|
@ -62,13 +59,13 @@
|
|||
android:visibility="gone"
|
||||
tools:src="@drawable/ic_person_white_24dp"
|
||||
tools:tint="@color/core_blue"
|
||||
tools:visibility="visible"/>
|
||||
tools:visibility="visible" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tooltip_text"
|
||||
style="@style/Signal.Text.BodyMedium"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/Signal.Text.Body"
|
||||
tools:text="It is my gift. It is my curse." />
|
||||
|
||||
</LinearLayout>
|
||||
|
@ -77,12 +74,12 @@
|
|||
android:id="@+id/tooltip_arrow_bottom"
|
||||
android:layout_width="16dp"
|
||||
android:layout_height="8dp"
|
||||
android:visibility="gone"
|
||||
android:scaleType="fitXY"
|
||||
android:elevation="6dp"
|
||||
android:scaleType="fitXY"
|
||||
android:visibility="gone"
|
||||
app:srcCompat="@drawable/ic_triangle_down"
|
||||
tools:visibility="visible"
|
||||
tools:tint="@color/core_blue"/>
|
||||
tools:tint="@color/core_blue"
|
||||
tools:visibility="visible" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
@ -90,11 +87,11 @@
|
|||
android:id="@+id/tooltip_arrow_end"
|
||||
android:layout_width="8dp"
|
||||
android:layout_height="16dp"
|
||||
android:visibility="gone"
|
||||
android:scaleType="fitXY"
|
||||
android:elevation="6dp"
|
||||
android:scaleType="fitXY"
|
||||
android:visibility="gone"
|
||||
app:srcCompat="@drawable/ic_triangle_right"
|
||||
tools:visibility="visible"
|
||||
tools:tint="@color/core_blue"/>
|
||||
tools:tint="@color/core_blue"
|
||||
tools:visibility="visible" />
|
||||
|
||||
</LinearLayout>
|
||||
|
|
Ładowanie…
Reference in New Issue