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();
}
}
}
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();
}
}
}
Aggregations