Search in sources :

Example 1 with PeekViewOptions

use of me.ccrama.redditslide.ForceTouch.builder.PeekViewOptions in project Slide by ccrama.

the class HeaderImageLinkView method onLinkLongClick.

public void onLinkLongClick(final String url, MotionEvent event) {
    popped = false;
    if (url == null) {
        return;
    }
    performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
    Activity activity = null;
    final Context context = getContext();
    if (context instanceof Activity) {
        activity = (Activity) context;
    } else if (context instanceof android.support.v7.view.ContextThemeWrapper) {
        activity = (Activity) ((android.support.v7.view.ContextThemeWrapper) context).getBaseContext();
    } else if (context instanceof ContextWrapper) {
        Context context1 = ((ContextWrapper) context).getBaseContext();
        if (context1 instanceof Activity) {
            activity = (Activity) context1;
        } else if (context1 instanceof ContextWrapper) {
            Context context2 = ((ContextWrapper) context1).getBaseContext();
            if (context2 instanceof Activity) {
                activity = (Activity) context2;
            } else if (context2 instanceof ContextWrapper) {
                activity = (Activity) ((android.support.v7.view.ContextThemeWrapper) context2).getBaseContext();
            }
        }
    } else {
        throw new RuntimeException("Could not find activity from context:" + context);
    }
    if (activity != null && !activity.isFinishing()) {
        if (SettingValues.peek) {
            Peek.into(R.layout.peek_view_submission, new SimpleOnPeek() {

                @Override
                public void onInflated(final PeekView peekView, final View rootView) {
                    // do stuff
                    TextView text = ((TextView) rootView.findViewById(R.id.title));
                    text.setText(url);
                    text.setTextColor(Color.WHITE);
                    ((PeekMediaView) rootView.findViewById(R.id.peek)).setUrl(url);
                    peekView.addButton((R.id.share), new OnButtonUp() {

                        @Override
                        public void onButtonUp() {
                            Reddit.defaultShareText("", url, rootView.getContext());
                        }
                    });
                    peekView.addButton((R.id.upvoteb), new OnButtonUp() {

                        @Override
                        public void onButtonUp() {
                            ((View) getParent()).findViewById(R.id.upvote).callOnClick();
                        }
                    });
                    peekView.setOnRemoveListener(new OnRemove() {

                        @Override
                        public void onRemove() {
                            ((PeekMediaView) rootView.findViewById(R.id.peek)).doClose();
                        }
                    });
                    peekView.addButton((R.id.comments), new OnButtonUp() {

                        @Override
                        public void onButtonUp() {
                            ((View) getParent().getParent()).callOnClick();
                        }
                    });
                    peekView.setOnPop(new OnPop() {

                        @Override
                        public void onPop() {
                            popped = true;
                            callOnClick();
                        }
                    });
                }
            }).with(new PeekViewOptions().setFullScreenPeek(true)).show((PeekViewActivity) activity, event);
        } else {
            BottomSheet.Builder b = new BottomSheet.Builder(activity).title(url).grid();
            int[] attrs = new int[] { R.attr.tintColor };
            TypedArray ta = getContext().obtainStyledAttributes(attrs);
            int color = ta.getColor(0, Color.WHITE);
            Drawable open = getResources().getDrawable(R.drawable.ic_open_in_browser);
            open.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
            Drawable share = getResources().getDrawable(R.drawable.ic_share);
            share.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
            Drawable copy = getResources().getDrawable(R.drawable.ic_content_copy);
            copy.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
            ta.recycle();
            b.sheet(R.id.open_link, open, getResources().getString(R.string.submission_link_extern));
            b.sheet(R.id.share_link, share, getResources().getString(R.string.share_link));
            b.sheet(R.id.copy_link, copy, getResources().getString(R.string.submission_link_copy));
            final Activity finalActivity = activity;
            b.listener(new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    switch(which) {
                        case R.id.open_link:
                            LinkUtil.openExternally(url, context);
                            break;
                        case R.id.share_link:
                            Reddit.defaultShareText("", url, finalActivity);
                            break;
                        case R.id.copy_link:
                            LinkUtil.copyUrl(url, finalActivity);
                            break;
                    }
                }
            }).show();
        }
    }
}
Also used : DialogInterface(android.content.DialogInterface) PeekViewActivity(me.ccrama.redditslide.ForceTouch.PeekViewActivity) Activity(android.app.Activity) PeekMediaView(me.ccrama.redditslide.Views.PeekMediaView) TypedArray(android.content.res.TypedArray) PeekView(me.ccrama.redditslide.ForceTouch.PeekView) TransparentTagTextView(me.ccrama.redditslide.Views.TransparentTagTextView) TextView(android.widget.TextView) OnPop(me.ccrama.redditslide.ForceTouch.callback.OnPop) PeekViewOptions(me.ccrama.redditslide.ForceTouch.builder.PeekViewOptions) Context(android.content.Context) Drawable(android.graphics.drawable.Drawable) ImageView(android.widget.ImageView) PeekView(me.ccrama.redditslide.ForceTouch.PeekView) View(android.view.View) TransparentTagTextView(me.ccrama.redditslide.Views.TransparentTagTextView) TextView(android.widget.TextView) PeekMediaView(me.ccrama.redditslide.Views.PeekMediaView) OnButtonUp(me.ccrama.redditslide.ForceTouch.callback.OnButtonUp) OnRemove(me.ccrama.redditslide.ForceTouch.callback.OnRemove) BottomSheet(com.cocosw.bottomsheet.BottomSheet) ContextWrapper(android.content.ContextWrapper) SimpleOnPeek(me.ccrama.redditslide.ForceTouch.callback.SimpleOnPeek)

Example 2 with PeekViewOptions

use of me.ccrama.redditslide.ForceTouch.builder.PeekViewOptions in project Slide by ccrama.

the class SpoilerRobotoTextView method onLinkLongClick.

@Override
public void onLinkLongClick(final String baseUrl, MotionEvent event) {
    if (baseUrl == null) {
        return;
    }
    final String url = StringEscapeUtils.unescapeHtml4(baseUrl);
    performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
    Activity activity = null;
    final Context context = getContext();
    if (context instanceof Activity) {
        activity = (Activity) context;
    } else if (context instanceof android.support.v7.view.ContextThemeWrapper) {
        activity = (Activity) ((android.support.v7.view.ContextThemeWrapper) context).getBaseContext();
    } else if (context instanceof ContextWrapper) {
        Context context1 = ((ContextWrapper) context).getBaseContext();
        if (context1 instanceof Activity) {
            activity = (Activity) context1;
        } else if (context1 instanceof ContextWrapper) {
            Context context2 = ((ContextWrapper) context1).getBaseContext();
            if (context2 instanceof Activity) {
                activity = (Activity) context2;
            } else if (context2 instanceof ContextWrapper) {
                activity = (Activity) ((android.support.v7.view.ContextThemeWrapper) context2).getBaseContext();
            }
        }
    } else {
        throw new RuntimeException("Could not find activity from context:" + context);
    }
    if (activity != null && !activity.isFinishing()) {
        if (SettingValues.peek) {
            Peek.into(R.layout.peek_view, new SimpleOnPeek() {

                @Override
                public void onInflated(final PeekView peekView, final View rootView) {
                    // do stuff
                    TextView text = ((TextView) rootView.findViewById(R.id.title));
                    text.setText(url);
                    text.setTextColor(Color.WHITE);
                    ((PeekMediaView) rootView.findViewById(R.id.peek)).setUrl(url);
                    peekView.addButton((R.id.copy), new OnButtonUp() {

                        @Override
                        public void onButtonUp() {
                            ClipboardManager clipboard = (ClipboardManager) rootView.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
                            ClipData clip = ClipData.newPlainText("Link", url);
                            clipboard.setPrimaryClip(clip);
                            Toast.makeText(rootView.getContext(), R.string.submission_link_copied, Toast.LENGTH_SHORT).show();
                        }
                    });
                    peekView.setOnRemoveListener(new OnRemove() {

                        @Override
                        public void onRemove() {
                            ((PeekMediaView) rootView.findViewById(R.id.peek)).doClose();
                        }
                    });
                    peekView.addButton((R.id.share), new OnButtonUp() {

                        @Override
                        public void onButtonUp() {
                            Reddit.defaultShareText("", url, rootView.getContext());
                        }
                    });
                    peekView.addButton((R.id.pop), new OnButtonUp() {

                        @Override
                        public void onButtonUp() {
                            Reddit.defaultShareText("", url, rootView.getContext());
                        }
                    });
                    peekView.addButton((R.id.external), new OnButtonUp() {

                        @Override
                        public void onButtonUp() {
                            LinkUtil.openExternally(url, context);
                        }
                    });
                    peekView.setOnPop(new OnPop() {

                        @Override
                        public void onPop() {
                            onLinkClick(url, 0, "", null);
                        }
                    });
                }
            }).with(new PeekViewOptions().setFullScreenPeek(true)).show((PeekViewActivity) activity, event);
        } else {
            BottomSheet.Builder b = new BottomSheet.Builder(activity).title(url).grid();
            int[] attrs = new int[] { R.attr.tintColor };
            TypedArray ta = getContext().obtainStyledAttributes(attrs);
            int color = ta.getColor(0, Color.WHITE);
            Drawable open = getResources().getDrawable(R.drawable.ic_open_in_browser);
            open.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
            Drawable share = getResources().getDrawable(R.drawable.ic_share);
            share.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
            Drawable copy = getResources().getDrawable(R.drawable.ic_content_copy);
            copy.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
            ta.recycle();
            b.sheet(R.id.open_link, open, getResources().getString(R.string.submission_link_extern));
            b.sheet(R.id.share_link, share, getResources().getString(R.string.share_link));
            b.sheet(R.id.copy_link, copy, getResources().getString(R.string.submission_link_copy));
            final Activity finalActivity = activity;
            b.listener(new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    switch(which) {
                        case R.id.open_link:
                            LinkUtil.openExternally(url, context);
                            break;
                        case R.id.share_link:
                            Reddit.defaultShareText("", url, finalActivity);
                            break;
                        case R.id.copy_link:
                            LinkUtil.copyUrl(url, finalActivity);
                            break;
                    }
                }
            }).show();
        }
    }
}
Also used : DialogInterface(android.content.DialogInterface) SpannableStringBuilder(android.text.SpannableStringBuilder) PeekViewActivity(me.ccrama.redditslide.ForceTouch.PeekViewActivity) Activity(android.app.Activity) PeekMediaView(me.ccrama.redditslide.Views.PeekMediaView) TypedArray(android.content.res.TypedArray) PeekView(me.ccrama.redditslide.ForceTouch.PeekView) TextView(android.widget.TextView) RobotoTextView(com.devspark.robototextview.widget.RobotoTextView) OnPop(me.ccrama.redditslide.ForceTouch.callback.OnPop) PeekViewOptions(me.ccrama.redditslide.ForceTouch.builder.PeekViewOptions) Context(android.content.Context) ClipboardManager(android.content.ClipboardManager) Drawable(android.graphics.drawable.Drawable) MediaView(me.ccrama.redditslide.Activities.MediaView) PeekView(me.ccrama.redditslide.ForceTouch.PeekView) View(android.view.View) TextView(android.widget.TextView) PeekMediaView(me.ccrama.redditslide.Views.PeekMediaView) RobotoTextView(com.devspark.robototextview.widget.RobotoTextView) OnButtonUp(me.ccrama.redditslide.ForceTouch.callback.OnButtonUp) TextPaint(android.text.TextPaint) OnRemove(me.ccrama.redditslide.ForceTouch.callback.OnRemove) BottomSheet(com.cocosw.bottomsheet.BottomSheet) ContextWrapper(android.content.ContextWrapper) ClipData(android.content.ClipData) SimpleOnPeek(me.ccrama.redditslide.ForceTouch.callback.SimpleOnPeek)

Aggregations

Activity (android.app.Activity)2 Context (android.content.Context)2 ContextWrapper (android.content.ContextWrapper)2 DialogInterface (android.content.DialogInterface)2 TypedArray (android.content.res.TypedArray)2 Drawable (android.graphics.drawable.Drawable)2 View (android.view.View)2 TextView (android.widget.TextView)2 BottomSheet (com.cocosw.bottomsheet.BottomSheet)2 PeekView (me.ccrama.redditslide.ForceTouch.PeekView)2 PeekViewActivity (me.ccrama.redditslide.ForceTouch.PeekViewActivity)2 PeekViewOptions (me.ccrama.redditslide.ForceTouch.builder.PeekViewOptions)2 OnButtonUp (me.ccrama.redditslide.ForceTouch.callback.OnButtonUp)2 OnPop (me.ccrama.redditslide.ForceTouch.callback.OnPop)2 OnRemove (me.ccrama.redditslide.ForceTouch.callback.OnRemove)2 SimpleOnPeek (me.ccrama.redditslide.ForceTouch.callback.SimpleOnPeek)2 PeekMediaView (me.ccrama.redditslide.Views.PeekMediaView)2 ClipData (android.content.ClipData)1 ClipboardManager (android.content.ClipboardManager)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1