LongPressPopup
LongPressPopup copied to clipboard
setDismissOnLongPressStop don't work on my adapter
Thanks to release this useful library, unfortunately in my adapter setDismissOnLongPressStop
don't work, could you check this code please?
public class UserChannelsViewHolder extends RecyclerView.ViewHolder
implements PopupInflaterListener, View.OnClickListener, PopupStateListener, PopupOnHoverListener {
...
private LongPressPopup mPopup;
private ImageView mPopupImg;
private TextView mPopupTitle;
public UserChannelsViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
title.setTextSize(AndroidUtilities.dp(15));
description.setTextSize(AndroidUtilities.dp(11));
iconCafeWebUserCount.setTextSize(AndroidUtilities.dp(11));
iconVisitCafeWeb.setTextSize(AndroidUtilities.dp(11));
title.setTypeface(FontManager.getInstance(context).loadFont("fonts/vazir_bold.ttf"));
description.setTypeface(FontManager.getInstance(context).loadFont("fonts/vazir.ttf"));
mPopup = new LongPressPopupBuilder(itemView.getContext())
.setTarget(imageAvatar)
.setPopupView(R.layout.popup_layout, this)
.setAnimationType(LongPressPopup.ANIMATION_TYPE_FROM_CENTER)
.setPopupListener(this)
.setOnHoverListener(this)
.setLongPressDuration(750)
.setDismissOnLongPressStop(true)
.setDismissOnTouchOutside(true)
.setDismissOnBackPressed(true)
.setCancelTouchOnDragOutsideView(true)
.setLongPressReleaseListener(this)
.build();
mPopup.register();
}
@Override
public void onClick(View v) {
}
@Override
public void onHoverChanged(View view, boolean isHovered) {
if (isHovered) {
if (view.getId() == mPopupTitle.getId()) {
} else if (view.getId() == mPopupImg.getId()) {
}
}
}
@Override
public void onPopupShow(@Nullable String popupTag) {
if (mPopupImg != null) {
Picasso.with(context)
.load("http://cdn.time.ir/App_Themes/Default-fa-IR/Images/summerHeader.jpg")
.networkPolicy(NetworkPolicy.OFFLINE)
.into(mPopupImg);
}
if (mPopupTitle != null) {
mPopupTitle.setText(list.get(getAdapterPosition()).getCafeName());
}
}
@Override
public void onPopupDismiss(@Nullable String popupTag) {
}
@Override
public void onViewInflated(@Nullable String popupTag, View root) {
mPopupImg = (ImageView) root.findViewById(R.id.popup_img);
mPopupTitle = (TextView) root.findViewById(R.id.popup_title);
mPopupTitle.setOnClickListener(this);
}
}
}
Hi! Thanks for using this library!
Try to remove this four lines .setDismissOnLongPressStop(true) .setDismissOnTouchOutside(true) .setDismissOnBackPressed(true) .setCancelTouchOnDragOutsideView(true)
If I understood correctly, the behaviour you're trying to achieve is the default of this library, you don't need to set anything particular in the builder
If you set .setDismissOnTouchOutside(true) and/or .setDismissOnBackPressed(true) They override the .setDismissOnLongPressStop(true) setting it to false, because they can happen only if the popup isn't dismissed on long press stop
Let me know if this solves your problem
Riccardo
@RiccardoMoro thanks to reply, i'm not sure whats problem, i change code to
mPopup = new LongPressPopupBuilder(itemView.getContext())
.setTarget(imageAvatar)
.setPopupView(R.layout.popup_layout, this)
.setAnimationType(LongPressPopup.ANIMATION_TYPE_FROM_CENTER)
.setPopupListener(this)
.setOnHoverListener(this)
.setLongPressDuration(400)
.setLongPressReleaseListener(this)
.build();
mPopup.register();
problem is, after showing popup, i have to click outside dialog to dismiss that
I guess that if you just set .setDismissOnLongPressStop(true) the result is the same right?
@RiccardoMoro no, this link is my complete adapter source code
http://paste.debian.net/976931/
Mmm I can see that you did this -> .setDismissOnLongPressStop(false) Now I'm not sure what you're trying to achieve.. You want the popup to be dismissed when the long press action that creates it stops or not? ( in other words, you want the same behaviour in the initial list in the sample app of this library? )
@RiccardoMoro i added .setDismissOnLongPressStop(false)
after your comment, yes i would like to dismiss popup after stop touch, like with your sample code
You've also tried to set it to true but without the other setters? (Like it's now, but with true instead of false)
I've tried to replicate what happened to you, but if I paste the exact configuration ( the one without the setters and the one just with .setDismissOnLongPressStop(true) ) and it works as it should What is the container of your RecyclerView in the layout?
@RiccardoMoro
That's small image view as avatar. See this screen shot
http://rupload.ir/upload/6mr6nxa0p99barqdzw15.jpg
@RiccardoMoro setting true
for .setDismissOnLongPressStop
, dont any change, and popup dont close after stop and release touch, i have that on screen any time and i have to click on back button or touch out of popup to dismiss that, do you want to share simple screen capture by me?
@MahdiPishguy What is the parent of the RecyclerView? is there some custom touch-handling logic inside it?
@RiccardoMoro no sir, my xml layout is:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="-20dp"
android:layout_marginRight="-20dp"
android:background="#eeeeee">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="@drawable/content_background">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/userChannelsList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="45dp"/>
</LinearLayout>
</FrameLayout>
<TextView
android:id="@+id/defaultPort"
android:layout_width="match_parent"
android:layout_height="@dimen/default_textview_height"
android:visibility="gone"/>
</FrameLayout>
This is very strange... Later I'll try to replicate your issue using a layout just like yours
@RiccardoMoro i'm trying to separate this part of application and send it for you, yeah that's very strange
@RiccardoMoro problem is when i set itemView in ViewHolder, dismising dialog work fine when i set itemView on setTarget
, for example:
.setTarget(itemView)
that means i can't set other view in that, for example
.setTarget(page_thumbnail_avatar) //page_thumbnail_avatar is an imageView
dismising dialog don't work