use of android.content.ClipData in project run-wallet-android by runplay.
the class SnTrFragment method hasClipboardAddress.
private boolean hasClipboardAddress() {
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData cd = clipboard.getPrimaryClip();
if (cd != null && cd.getItemCount() > 0) {
String address = cd.getItemAt(0).coerceToText(getActivity()).toString();
// Log.e("CLIPB","has add? : "+isValidAddress(address)+" -- "+address);
return isValidAddress(address);
}
return false;
}
use of android.content.ClipData in project Slide by ccrama.
the class InboxAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder viewHolder, int pos) {
int i = pos != 0 ? pos - 1 : pos;
if (!(viewHolder instanceof ContributionAdapter.EmptyViewHolder) && !(viewHolder instanceof SpacerViewHolder)) {
final MessageViewHolder messageViewHolder = (MessageViewHolder) viewHolder;
final Message comment = dataSet.posts.get(i);
messageViewHolder.time.setText(TimeUtils.getTimeAgo(comment.getCreated().getTime(), mContext));
SpannableStringBuilder titleString = new SpannableStringBuilder();
String author = comment.getAuthor();
String direction = "from ";
if (!dataSet.where.contains("mod") && comment.getDataNode().has("dest") && !Authentication.name.equalsIgnoreCase(comment.getDataNode().get("dest").asText()) && !comment.getDataNode().get("dest").asText().equals("reddit")) {
author = comment.getDataNode().get("dest").asText().replace("#", "/r/");
direction = "to ";
}
if (comment.getDataNode().has("subreddit") && author == null || author.isEmpty()) {
direction = "via /r/" + comment.getSubreddit();
}
titleString.append(direction);
if (author != null) {
titleString.append(author);
titleString.append(" ");
if (UserTags.isUserTagged(author)) {
SpannableStringBuilder pinned = new SpannableStringBuilder(" " + UserTags.getUserTag(author) + " ");
pinned.setSpan(new RoundedBackgroundSpan(mContext, R.color.white, R.color.md_blue_500, false), 0, pinned.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
titleString.append(pinned);
titleString.append(" ");
}
if (UserSubscriptions.friends.contains(author)) {
SpannableStringBuilder pinned = new SpannableStringBuilder(" " + mContext.getString(R.string.profile_friend) + " ");
pinned.setSpan(new RoundedBackgroundSpan(mContext, R.color.white, R.color.md_deep_orange_500, false), 0, pinned.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
titleString.append(pinned);
titleString.append(" ");
}
}
String spacer = mContext.getString(R.string.submission_properties_seperator);
if (comment.getDataNode().has("subreddit") && !comment.getDataNode().get("subreddit").isNull()) {
titleString.append(spacer);
String subname = comment.getDataNode().get("subreddit").asText();
SpannableStringBuilder subreddit = new SpannableStringBuilder("/r/" + subname);
if ((SettingValues.colorSubName && Palette.getColor(subname) != Palette.getDefaultColor())) {
subreddit.setSpan(new ForegroundColorSpan(Palette.getColor(subname)), 0, subreddit.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
subreddit.setSpan(new StyleSpan(Typeface.BOLD), 0, subreddit.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
titleString.append(subreddit);
}
messageViewHolder.user.setText(titleString);
SpannableStringBuilder b = new SpannableStringBuilder();
if (mContext instanceof Inbox && comment.getCreated().getTime() > ((Inbox) mContext).last && !comment.isRead()) {
SpannableStringBuilder tagNew = new SpannableStringBuilder("\u00A0NEW\u00A0");
tagNew.setSpan(new RoundedBackgroundSpan(Color.WHITE, mContext.getResources().getColor(R.color.md_green_400), true, mContext), 0, tagNew.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
b.append(tagNew);
b.append(" ");
}
b.append(comment.getSubject());
if (comment.getDataNode().has("link_title")) {
SpannableStringBuilder link = new SpannableStringBuilder(" " + Html.fromHtml(comment.getDataNode().get("link_title").asText()) + " ");
link.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), 0, link.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
link.setSpan(new RelativeSizeSpan(0.8f), 0, link.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
b.append(link);
}
messageViewHolder.title.setText(b);
if (comment.isRead()) {
messageViewHolder.title.setTextColor(messageViewHolder.content.getCurrentTextColor());
} else {
messageViewHolder.title.setTextColor(ContextCompat.getColor(mContext, R.color.md_red_400));
}
messageViewHolder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
int[] attrs = new int[] { R.attr.tintColor };
TypedArray ta = mContext.obtainStyledAttributes(attrs);
final int color = ta.getColor(0, Color.WHITE);
Drawable profile = mContext.getResources().getDrawable(R.drawable.profile);
final Drawable reply = mContext.getResources().getDrawable(R.drawable.reply);
Drawable unhide = mContext.getResources().getDrawable(R.drawable.ic_visibility);
Drawable hide = mContext.getResources().getDrawable(R.drawable.hide);
Drawable copy = mContext.getResources().getDrawable(R.drawable.ic_content_copy);
Drawable reddit = mContext.getResources().getDrawable(R.drawable.commentchange);
profile.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
hide.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
copy.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
reddit.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
reply.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
unhide.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
ta.recycle();
BottomSheet.Builder b = new BottomSheet.Builder((Activity) mContext).title(Html.fromHtml(comment.getSubject()));
String author = comment.getAuthor();
if (!dataSet.where.contains("mod") && comment.getDataNode().has("dest") && !Authentication.name.equalsIgnoreCase(comment.getDataNode().get("dest").asText()) && !comment.getDataNode().get("dest").asText().equals("reddit")) {
author = comment.getDataNode().get("dest").asText().replace("#", "/r/");
}
if (comment.getAuthor() != null) {
b.sheet(1, profile, "/u/" + author);
}
String read = mContext.getString(R.string.mail_mark_read);
Drawable rDrawable = hide;
if (comment.isRead()) {
read = mContext.getString(R.string.mail_mark_unread);
rDrawable = unhide;
}
b.sheet(2, rDrawable, read);
b.sheet(3, reply, mContext.getString(R.string.btn_reply));
b.sheet(25, copy, mContext.getString(R.string.misc_copy_text));
if (comment.isComment()) {
b.sheet(30, reddit, mContext.getString(R.string.mail_view_full_thread));
}
final String finalAuthor = author;
b.listener(new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch(which) {
case 1:
{
Intent i = new Intent(mContext, Profile.class);
i.putExtra(Profile.EXTRA_PROFILE, finalAuthor);
mContext.startActivity(i);
}
break;
case 2:
{
if (comment.isRead()) {
comment.read = false;
new AsyncSetRead(false).execute(comment);
messageViewHolder.title.setTextColor(ContextCompat.getColor(mContext, R.color.md_red_400));
} else {
comment.read = true;
new AsyncSetRead(true).execute(comment);
messageViewHolder.title.setTextColor(messageViewHolder.content.getCurrentTextColor());
}
}
break;
case 3:
{
doInboxReply(comment);
}
break;
case 25:
{
ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Message", comment.getBody());
clipboard.setPrimaryClip(clip);
Toast.makeText(mContext, mContext.getString(R.string.mail_message_copied), Toast.LENGTH_SHORT).show();
}
break;
case 30:
{
String context = comment.getDataNode().get("context").asText();
new OpenRedditLink(mContext, "https://reddit.com" + context.substring(0, context.lastIndexOf("/")));
}
break;
}
}
}).show();
return true;
}
});
messageViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (comment.isRead()) {
if (comment instanceof PrivateMessage) {
DataShare.sharedMessage = (PrivateMessage) comment;
Intent i = new Intent(mContext, SendMessage.class);
i.putExtra(SendMessage.EXTRA_NAME, comment.getAuthor());
i.putExtra(SendMessage.EXTRA_REPLY, true);
mContext.startActivity(i);
} else {
new OpenRedditLink(mContext, comment.getDataNode().get("context").asText());
}
} else {
comment.read = true;
new AsyncSetRead(true).execute(comment);
messageViewHolder.title.setTextColor(messageViewHolder.content.getCurrentTextColor());
{
SpannableStringBuilder b = new SpannableStringBuilder(comment.getSubject());
if (comment.getDataNode().has("link_title")) {
SpannableStringBuilder link = new SpannableStringBuilder(" " + Html.fromHtml(comment.getDataNode().get("link_title").asText()) + " ");
link.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), 0, link.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
link.setSpan(new RelativeSizeSpan(0.8f), 0, link.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
b.append(link);
}
messageViewHolder.title.setText(b);
}
}
}
});
// Set typeface for body
int type = new FontPreferences(mContext).getFontTypeComment().getTypeface();
Typeface typeface;
if (type >= 0) {
typeface = RobotoTypefaces.obtainTypeface(mContext, type);
} else {
typeface = Typeface.DEFAULT;
}
messageViewHolder.content.setTypeface(typeface);
setViews(comment.getDataNode().get("body_html").asText(), "FORCE_LINK_CLICK", messageViewHolder);
}
if (viewHolder instanceof SpacerViewHolder) {
viewHolder.itemView.findViewById(R.id.height).setLayoutParams(new LinearLayout.LayoutParams(viewHolder.itemView.getWidth(), ((Activity) mContext).findViewById(R.id.header).getHeight()));
}
}
use of android.content.ClipData in project Slide by ccrama.
the class SettingsAbout method onCreate.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
applyColorTheme();
setContentView(R.layout.activity_settings_about);
setupAppBar(R.id.toolbar, R.string.settings_title_about, true, true);
View report = findViewById(R.id.report);
View libs = findViewById(R.id.libs);
View changelog = findViewById(R.id.changelog);
final TextView version = (TextView) findViewById(R.id.version);
version.setText("Slide v" + BuildConfig.VERSION_NAME);
// Copy the latest stacktrace with a long click on the version number
if (BuildConfig.DEBUG) {
version.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
SharedPreferences prefs = getSharedPreferences("STACKTRACE", Context.MODE_PRIVATE);
String stacktrace = prefs.getString("stacktrace", null);
if (stacktrace != null) {
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Stacktrace", stacktrace);
clipboard.setPrimaryClip(clip);
}
prefs.edit().clear().apply();
return true;
}
});
}
version.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String versionNumber = version.getText().toString();
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Version", versionNumber);
clipboard.setPrimaryClip(clip);
Toast.makeText(SettingsAbout.this, R.string.settings_about_version_copied_toast, Toast.LENGTH_SHORT).show();
}
});
report.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LinkUtil.openExternally("https://github.com/ccrama/Slide/issues", SettingsAbout.this);
}
});
findViewById(R.id.sub).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new OpenRedditLink(SettingsAbout.this, "https://reddit.com/r/slideforreddit");
}
});
findViewById(R.id.rate).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=me.ccrama.redditslide")));
} catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=me.ccrama.redditslide")));
}
}
});
changelog.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LinkUtil.openExternally("https://github.com/ccrama/Slide/blob/master/CHANGELOG.md", SettingsAbout.this);
}
});
libs.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(SettingsAbout.this, SettingsLibs.class);
startActivity(i);
}
});
}
use of android.content.ClipData in project vlc-android by videolan.
the class UiTools method setOnDragListener.
public static void setOnDragListener(final Activity activity) {
final View view = AndroidUtil.isNougatOrLater ? activity.getWindow().peekDecorView() : null;
if (view != null)
view.setOnDragListener(new View.OnDragListener() {
@Override
public boolean onDrag(View v, DragEvent event) {
switch(event.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
return true;
case DragEvent.ACTION_DROP:
final ClipData clipData = event.getClipData();
if (clipData == null)
return false;
final int itemsCount = clipData.getItemCount();
for (int i = 0; i < itemsCount; i++) {
final DragAndDropPermissions permissions = activity.requestDragAndDropPermissions(event);
if (permissions != null) {
final ClipData.Item item = clipData.getItemAt(i);
if (item.getUri() != null)
MediaUtils.openUri(activity, item.getUri());
else if (item.getText() != null) {
final Uri uri = Uri.parse(item.getText().toString());
final MediaWrapper media = new MediaWrapper(uri);
if (!"file".equals(uri.getScheme()))
media.setType(MediaWrapper.TYPE_STREAM);
MediaUtils.openMedia(activity, media);
}
return true;
}
}
return false;
default:
return false;
}
}
});
}
use of android.content.ClipData in project Slide by ccrama.
the class LinkUtil method copyUrl.
public static void copyUrl(String url, Context context) {
url = StringEscapeUtils.unescapeHtml4(Html.fromHtml(url).toString());
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Link", url);
clipboard.setPrimaryClip(clip);
Toast.makeText(context, R.string.submission_link_copied, Toast.LENGTH_SHORT).show();
}
Aggregations