use of androidx.appcompat.view.ContextThemeWrapper in project Carbon by ZieIony.
the class Carbon method getThemedContext.
public static Context getThemedContext(Context context, AttributeSet attributeSet, int[] attrs, @AttrRes int defStyleAttr, int attr) {
TypedArray a = context.obtainStyledAttributes(attributeSet, attrs, defStyleAttr, 0);
if (a.hasValue(attr)) {
int themeId = a.getResourceId(attr, 0);
a.recycle();
return new ContextThemeWrapper(context, themeId);
}
return context;
}
use of androidx.appcompat.view.ContextThemeWrapper in project Carbon by ZieIony.
the class MarshmallowEditText method createMenu.
private void createMenu(Menu menu) {
TypedValue outValue = new TypedValue();
getContext().getTheme().resolveAttribute(R.attr.carbon_editMenuTheme, outValue, true);
int theme = outValue.resourceId;
Context themedContext = new ContextThemeWrapper(getContext(), theme);
popupMenu = new EditTextMenu(themedContext);
popupMenu.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
isShowingPopup = false;
}
});
popupMenu.initCopy(menu.findItem(ID_COPY));
popupMenu.initCut(menu.findItem(ID_CUT));
popupMenu.initPaste(menu.findItem(ID_PASTE));
popupMenu.initSelectAll(menu.findItem(ID_SELECT_ALL));
// menu.clear();
/*try {
mIgnoreActionUpEventField.set(editor, true);
} catch (IllegalAccessException e) {
e.printStackTrace();
}*/
}
use of androidx.appcompat.view.ContextThemeWrapper in project Slide by ccrama.
the class CommentPage method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
LayoutInflater localInflater = inflater.cloneInContext(contextThemeWrapper);
v = localInflater.inflate(R.layout.fragment_verticalcontenttoolbar, container, false);
rv = v.findViewById(R.id.vertical_content);
rv.setLayoutManager(mLayoutManager);
rv.getLayoutManager().scrollToPosition(0);
toolbar = v.findViewById(R.id.toolbar);
toolbar.setPopupTheme(new ColorPreferences(getActivity()).getFontStyle().getBaseId());
if (!SettingValues.fabComments || archived || np || locked) {
v.findViewById(R.id.comment_floating_action_button).setVisibility(View.GONE);
} else {
fab = v.findViewById(R.id.comment_floating_action_button);
if (SettingValues.fastscroll) {
FrameLayout.LayoutParams fabs = (FrameLayout.LayoutParams) fab.getLayoutParams();
fabs.setMargins(fabs.leftMargin, fabs.topMargin, fabs.rightMargin, fabs.bottomMargin * 3);
fab.setLayoutParams(fabs);
}
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final MaterialDialog replyDialog = new MaterialDialog.Builder(getActivity()).customView(R.layout.edit_comment, false).cancelable(false).build();
final View replyView = replyDialog.getCustomView();
// Make the account selector visible
replyView.findViewById(R.id.profile).setVisibility(View.VISIBLE);
final EditText e = replyView.findViewById(R.id.entry);
// Tint the replyLine appropriately if the base theme is Light or Sepia
if (SettingValues.currentTheme == 1 || SettingValues.currentTheme == 5) {
final int TINT = ContextCompat.getColor(getContext(), R.color.md_grey_600);
e.setHintTextColor(TINT);
BlendModeUtil.tintDrawableAsSrcIn(e.getBackground(), TINT);
}
DoEditorActions.doActions(e, replyView, getActivity().getSupportFragmentManager(), getActivity(), adapter.submission.isSelfPost() ? adapter.submission.getSelftext() : null, new String[] { adapter.submission.getAuthor() });
replyDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
replyView.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
replyDialog.dismiss();
}
});
final TextView profile = replyView.findViewById(R.id.profile);
final String[] changedProfile = { Authentication.name };
profile.setText("/u/" + changedProfile[0]);
profile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final HashMap<String, String> accounts = new HashMap<>();
for (String s : Authentication.authentication.getStringSet("accounts", new HashSet<String>())) {
if (s.contains(":")) {
accounts.put(s.split(":")[0], s.split(":")[1]);
} else {
accounts.put(s, "");
}
}
final ArrayList<String> keys = new ArrayList<>(accounts.keySet());
final int i = keys.indexOf(changedProfile[0]);
MaterialDialog.Builder builder = new MaterialDialog.Builder(getContext());
builder.title(getString(R.string.replies_switch_accounts));
builder.items(keys.toArray(new String[0]));
builder.itemsCallbackSingleChoice(i, new MaterialDialog.ListCallbackSingleChoice() {
@Override
public boolean onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
changedProfile[0] = keys.get(which);
profile.setText("/u/" + changedProfile[0]);
return true;
}
});
builder.alwaysCallSingleChoiceCallback();
builder.negativeText(R.string.btn_cancel);
builder.show();
}
});
replyView.findViewById(R.id.submit).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
adapter.dataSet.refreshLayout.setRefreshing(true);
adapter.new ReplyTaskComment(adapter.submission, changedProfile[0]).execute(e.getText().toString());
replyDialog.dismiss();
}
});
replyDialog.show();
}
});
}
if (fab != null)
fab.show();
resetScroll(false);
fastScroll = v.findViewById(R.id.commentnav);
if (!SettingValues.fastscroll) {
fastScroll.setVisibility(View.GONE);
} else {
if (!SettingValues.showCollapseExpand) {
v.findViewById(R.id.collapse_expand).setVisibility(View.GONE);
} else {
v.findViewById(R.id.collapse_expand).setVisibility(View.VISIBLE);
v.findViewById(R.id.collapse_expand).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (adapter != null) {
if (collapsed) {
adapter.expandAll();
} else {
adapter.collapseAll();
}
collapsed = !collapsed;
}
}
});
}
v.findViewById(R.id.down).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (adapter != null && adapter.keys != null && adapter.keys.size() > 0) {
goDown();
}
}
});
v.findViewById(R.id.up).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (adapter != null && adapter.keys != null && adapter.keys.size() > 0)
goUp();
}
});
v.findViewById(R.id.nav).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (adapter != null && adapter.currentComments != null) {
int parentCount = 0;
int opCount = 0;
int linkCount = 0;
int awardCount = 0;
String op = adapter.submission.getAuthor();
for (CommentObject o : adapter.currentComments) {
if (o.comment != null && !(o instanceof MoreChildItem)) {
if (o.comment.isTopLevel())
parentCount++;
if (o.comment.getComment().getTimesGilded() > 0 || o.comment.getComment().getTimesSilvered() > 0 || o.comment.getComment().getTimesPlatinized() > 0)
awardCount++;
if (o.comment.getComment().getAuthor() != null && o.comment.getComment().getAuthor().equals(op)) {
opCount++;
}
if (o.comment.getComment().getDataNode().has("body_html") && o.comment.getComment().getDataNode().get("body_html").asText().contains("</a")) {
linkCount++;
}
}
}
new AlertDialog.Builder(getActivity()).setTitle(R.string.set_nav_mode).setSingleChoiceItems(StringUtil.stringToArray("Parent comment (" + parentCount + ")" + "," + "Children comment (highlight child comment & navigate)" + "," + "OP (" + opCount + ")" + "," + "Time" + "," + "Link (" + linkCount + ")" + "," + ((Authentication.isLoggedIn) ? "You" + "," : "") + "Awarded (" + awardCount + ")").toArray(new String[Authentication.isLoggedIn ? 6 : 5]), getCurrentSort(), (dialog, which) -> {
switch(which) {
case 0:
currentSort = CommentNavType.PARENTS;
break;
case 1:
currentSort = CommentNavType.CHILDREN;
break;
case 2:
currentSort = CommentNavType.OP;
break;
case 3:
currentSort = CommentNavType.TIME;
LayoutInflater inflater1 = getActivity().getLayoutInflater();
final View dialoglayout = inflater1.inflate(R.layout.commenttime, null);
final Slider landscape = dialoglayout.findViewById(R.id.landscape);
final TextView since = dialoglayout.findViewById(R.id.time_string);
landscape.setValueRange(60, 18000, false);
landscape.setOnPositionChangeListener(new Slider.OnPositionChangeListener() {
@Override
public void onPositionChanged(Slider slider, boolean b, float v12, float v1, int i, int i1) {
Calendar c = Calendar.getInstance();
sortTime = c.getTimeInMillis() - i1 * 1000L;
int commentcount = 0;
for (CommentObject o : adapter.currentComments) {
if (o.comment != null && o.comment.getComment().getDataNode().has("created") && o.comment.getComment().getCreated().getTime() > sortTime) {
commentcount += 1;
}
}
since.setText(TimeUtils.getTimeAgo(sortTime, getActivity()) + " (" + commentcount + " comments)");
}
});
landscape.setValue(600, false);
new AlertDialog.Builder(getActivity()).setView(dialoglayout).setPositiveButton(R.string.btn_set, null).show();
break;
case 5:
currentSort = (Authentication.isLoggedIn ? CommentNavType.YOU : // gilded is 5 if not logged in
CommentNavType.GILDED);
break;
case 4:
currentSort = CommentNavType.LINK;
break;
case 6:
currentSort = CommentNavType.GILDED;
break;
}
}).show();
}
}
});
}
v.findViewById(R.id.up).setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
// Scroll to top
rv.getLayoutManager().scrollToPosition(1);
return true;
}
});
if (SettingValues.voteGestures) {
v.findViewById(R.id.up).setOnTouchListener(new OnFlingGestureListener() {
@Override
public void onRightToLeft() {
}
@Override
public void onLeftToRight() {
}
@Override
public void onBottomToTop() {
adapter.submissionViewHolder.upvote.performClick();
Context context = getContext();
int duration = Toast.LENGTH_SHORT;
CharSequence text;
if (!upvoted) {
text = getString(R.string.profile_upvoted);
downvoted = false;
} else {
text = getString(R.string.vote_removed);
}
upvoted = !upvoted;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
@Override
public void onTopToBottom() {
}
});
}
if (SettingValues.voteGestures) {
v.findViewById(R.id.down).setOnTouchListener(new OnFlingGestureListener() {
@Override
public void onRightToLeft() {
}
@Override
public void onLeftToRight() {
}
@Override
public void onBottomToTop() {
adapter.submissionViewHolder.downvote.performClick();
Context context = getContext();
int duration = Toast.LENGTH_SHORT;
CharSequence text;
if (!downvoted) {
text = getString(R.string.profile_downvoted);
upvoted = false;
} else {
text = getString(R.string.vote_removed);
}
downvoted = !downvoted;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
@Override
public void onTopToBottom() {
}
});
}
toolbar.setBackgroundColor(Palette.getColor(subreddit));
mSwipeRefreshLayout = v.findViewById(R.id.activity_main_swipe_refresh_layout);
mSwipeRefreshLayout.setColorSchemeColors(Palette.getColors(subreddit, getActivity()));
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
if (comments != null) {
comments.loadMore(adapter, subreddit, true);
} else {
mSwipeRefreshLayout.setRefreshing(false);
}
// TODO catch errors
}
});
toolbar.setTitle(subreddit);
toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_material);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getActivity().onBackPressed();
}
});
toolbar.inflateMenu(R.menu.menu_comment_items);
toolbar.setOnMenuItemClickListener(this);
toolbar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((LinearLayoutManager) rv.getLayoutManager()).scrollToPositionWithOffset(1, headerHeight);
resetScroll(false);
}
});
addClickFunctionSubName(toolbar);
doTopBar();
if (Authentication.didOnline && !NetworkUtil.isConnectedNoOverride(getActivity())) {
new AlertDialog.Builder(getActivity()).setTitle(R.string.err_title).setMessage(R.string.err_connection_failed_msg).setNegativeButton(R.string.btn_close, (dialog, which) -> {
if (!(getActivity() instanceof MainActivity)) {
getActivity().finish();
}
}).setPositiveButton(R.string.btn_offline, (dialog, which) -> {
Reddit.appRestart.edit().putBoolean("forceoffline", true).commit();
Reddit.forceRestart(getActivity(), false);
}).show();
}
doAdapter(!(getActivity() instanceof CommentsScreen) || ((CommentsScreen) getActivity()).currentPage == page);
return v;
}
use of androidx.appcompat.view.ContextThemeWrapper in project Slide by ccrama.
the class SpoilerRobotoTextView method onLinkClick.
@Override
public void onLinkClick(String url, int xOffset, String subreddit, URLSpan span) {
if (url == null) {
((View) getParent()).callOnClick();
return;
}
ContentType.Type type = ContentType.getContentType(url);
Context context = getContext();
Activity activity = null;
if (context instanceof Activity) {
activity = (Activity) context;
} else if (context instanceof ContextThemeWrapper) {
activity = (Activity) ((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) ((ContextThemeWrapper) context2).getBaseContext();
}
}
} else {
throw new RuntimeException("Could not find activity from context:" + context);
}
if (!PostMatch.openExternal(url) || type == ContentType.Type.VIDEO) {
switch(type) {
case DEVIANTART:
case IMGUR:
case XKCD:
if (SettingValues.image) {
Intent intent2 = new Intent(activity, MediaView.class);
intent2.putExtra(MediaView.EXTRA_URL, url);
intent2.putExtra(MediaView.SUBREDDIT, subreddit);
activity.startActivity(intent2);
} else {
LinkUtil.openExternally(url);
}
break;
case REDDIT:
OpenRedditLink.openUrl(activity, url, true);
break;
case LINK:
LogUtil.v("Opening link");
LinkUtil.openUrl(url, Palette.getColor(subreddit), activity);
break;
case SELF:
case NONE:
break;
case STREAMABLE:
openStreamable(url, subreddit);
break;
case ALBUM:
if (SettingValues.album) {
Intent i;
if (SettingValues.albumSwipe) {
i = new Intent(activity, AlbumPager.class);
i.putExtra(Album.EXTRA_URL, url);
i.putExtra(AlbumPager.SUBREDDIT, subreddit);
} else {
i = new Intent(activity, Album.class);
i.putExtra(Album.SUBREDDIT, subreddit);
i.putExtra(Album.EXTRA_URL, url);
}
activity.startActivity(i);
} else {
LinkUtil.openExternally(url);
}
break;
case TUMBLR:
if (SettingValues.image) {
Intent i = new Intent(activity, TumblrPager.class);
i.putExtra(Album.EXTRA_URL, url);
activity.startActivity(i);
} else {
LinkUtil.openExternally(url);
}
break;
case IMAGE:
openImage(url, subreddit);
break;
case VREDDIT_REDIRECT:
openVReddit(url, subreddit, activity);
break;
case GIF:
case VREDDIT_DIRECT:
openGif(url, subreddit, activity);
break;
case VIDEO:
if (!LinkUtil.tryOpenWithVideoPlugin(url)) {
LinkUtil.openUrl(url, Palette.getStatusBarColor(), activity);
}
case SPOILER:
spoilerClicked = true;
setOrRemoveSpoilerSpans(xOffset, span);
break;
case EXTERNAL:
LinkUtil.openExternally(url);
break;
}
} else {
LinkUtil.openExternally(url);
}
}
use of androidx.appcompat.view.ContextThemeWrapper 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 ContextThemeWrapper) {
activity = (Activity) ((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) ((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 = 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() {
ClipboardUtil.copyToClipboard(rootView.getContext(), "Link", url);
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);
}
});
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_new);
Drawable share = getResources().getDrawable(R.drawable.ic_share);
Drawable copy = getResources().getDrawable(R.drawable.ic_content_copy);
final List<Drawable> drawableSet = Arrays.asList(open, share, copy);
BlendModeUtil.tintDrawablesAsSrcAtop(drawableSet, color);
ta.recycle();
b.sheet(R.id.open_link, open, getResources().getString(R.string.open_externally));
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);
break;
case R.id.share_link:
Reddit.defaultShareText("", url, finalActivity);
break;
case R.id.copy_link:
LinkUtil.copyUrl(url, finalActivity);
break;
}
}
}).show();
}
}
}
Aggregations