Search in sources :

Example 11 with ContextThemeWrapper

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;
}
Also used : ContextThemeWrapper(androidx.appcompat.view.ContextThemeWrapper) TypedArray(android.content.res.TypedArray)

Example 12 with ContextThemeWrapper

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();
        }*/
}
Also used : Context(android.content.Context) ContextThemeWrapper(androidx.appcompat.view.ContextThemeWrapper) PopupWindow(android.widget.PopupWindow) EditTextMenu(carbon.internal.EditTextMenu) TypedValue(android.util.TypedValue)

Example 13 with ContextThemeWrapper

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("&lt;/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;
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) Bundle(android.os.Bundle) R(me.ccrama.redditslide.R) NonNull(androidx.annotation.NonNull) MainActivity(me.ccrama.redditslide.Activities.MainActivity) MediaView(me.ccrama.redditslide.Activities.MediaView) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) PostMatch(me.ccrama.redditslide.PostMatch) ContentType(me.ccrama.redditslide.ContentType) UserRecordPaginator(net.dean.jraw.paginators.UserRecordPaginator) DataShare(me.ccrama.redditslide.DataShare) OnSingleClickListener(me.ccrama.redditslide.util.OnSingleClickListener) Fragment(androidx.fragment.app.Fragment) Drafts(me.ccrama.redditslide.Drafts) CommentSort(net.dean.jraw.models.CommentSort) ContextCompat(androidx.core.content.ContextCompat) ProUtil(me.ccrama.redditslide.util.ProUtil) Slider(com.rey.material.widget.Slider) Palette(me.ccrama.redditslide.Visuals.Palette) BlendModeUtil(me.ccrama.redditslide.util.BlendModeUtil) Profile(me.ccrama.redditslide.Activities.Profile) PopulateSubmissionViewHolder(me.ccrama.redditslide.SubmissionViews.PopulateSubmissionViewHolder) Layout(android.text.Layout) TextPaint(android.text.TextPaint) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) Related(me.ccrama.redditslide.Activities.Related) SubmissionParser(me.ccrama.redditslide.util.SubmissionParser) DoEditorActions(me.ccrama.redditslide.Views.DoEditorActions) Dialog(android.app.Dialog) CommentItem(me.ccrama.redditslide.Adapters.CommentItem) AccountManager(net.dean.jraw.managers.AccountManager) ArrayList(java.util.ArrayList) Calendar(java.util.Calendar) TumblrPager(me.ccrama.redditslide.Activities.TumblrPager) MiscUtil(me.ccrama.redditslide.util.MiscUtil) Toast(android.widget.Toast) UserSubscriptions(me.ccrama.redditslide.UserSubscriptions) ContextWrapper(android.content.ContextWrapper) SubmissionComments(me.ccrama.redditslide.Adapters.SubmissionComments) MultiRedditUpdateRequest(net.dean.jraw.http.MultiRedditUpdateRequest) CommentsScreen(me.ccrama.redditslide.Activities.CommentsScreen) TimePeriod(net.dean.jraw.paginators.TimePeriod) StringUtil(me.ccrama.redditslide.util.StringUtil) SettingsSubAdapter(me.ccrama.redditslide.ui.settings.SettingsSubAdapter) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) Reddit(me.ccrama.redditslide.Reddit) IOException(java.io.IOException) Submit(me.ccrama.redditslide.Activities.Submit) ColorPreferences(me.ccrama.redditslide.Visuals.ColorPreferences) ToolbarScrollHideHandler(me.ccrama.redditslide.handler.ToolbarScrollHideHandler) MultiRedditManager(net.dean.jraw.managers.MultiRedditManager) ContextThemeWrapper(androidx.appcompat.view.ContextThemeWrapper) CommentSearch(me.ccrama.redditslide.Activities.CommentSearch) EditText(android.widget.EditText) LinkUtil(me.ccrama.redditslide.util.LinkUtil) EXTRA_SUBMISSION_TITLE(me.ccrama.redditslide.Notifications.ImageDownloadNotificationService.EXTRA_SUBMISSION_TITLE) MultiSubreddit(net.dean.jraw.models.MultiSubreddit) TimeUtils(me.ccrama.redditslide.util.TimeUtils) WindowManager(android.view.WindowManager) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) Tumblr(me.ccrama.redditslide.Activities.Tumblr) Wiki(me.ccrama.redditslide.Activities.Wiki) CommentObject(me.ccrama.redditslide.Adapters.CommentObject) Locale(java.util.Locale) ShadowboxComments(me.ccrama.redditslide.Activities.ShadowboxComments) FloatingActionButton(com.google.android.material.floatingactionbutton.FloatingActionButton) View(android.view.View) Sorting(net.dean.jraw.paginators.Sorting) CommentNavType(me.ccrama.redditslide.Adapters.CommentNavType) PreCachingLayoutManagerComments(me.ccrama.redditslide.Views.PreCachingLayoutManagerComments) RecyclerView(androidx.recyclerview.widget.RecyclerView) SendMessage(me.ccrama.redditslide.Activities.SendMessage) CommentUrlObject(me.ccrama.redditslide.Adapters.CommentUrlObject) AsyncTask(android.os.AsyncTask) FullscreenVideo(me.ccrama.redditslide.Activities.FullscreenVideo) Album(me.ccrama.redditslide.Activities.Album) Authentication(me.ccrama.redditslide.Authentication) ApiException(net.dean.jraw.ApiException) ViewGroup(android.view.ViewGroup) AlbumPager(me.ccrama.redditslide.Activities.AlbumPager) OfflineSubreddit(me.ccrama.redditslide.OfflineSubreddit) List(java.util.List) NetworkUtil(me.ccrama.redditslide.util.NetworkUtil) TextView(android.widget.TextView) Toolbar(androidx.appcompat.widget.Toolbar) CommentOverflow(me.ccrama.redditslide.Views.CommentOverflow) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Snackbar(com.google.android.material.snackbar.Snackbar) LayoutUtils(me.ccrama.redditslide.util.LayoutUtils) Context(android.content.Context) StaticLayout(android.text.StaticLayout) SettingValues(me.ccrama.redditslide.SettingValues) KeyEvent(android.view.KeyEvent) AlertDialog(androidx.appcompat.app.AlertDialog) Submission(net.dean.jraw.models.Submission) Intent(android.content.Intent) HashMap(java.util.HashMap) Constants(me.ccrama.redditslide.Constants) MenuItem(android.view.MenuItem) HashSet(java.util.HashSet) UserRecord(net.dean.jraw.models.UserRecord) SubredditView(me.ccrama.redditslide.Activities.SubredditView) DialogInterface(android.content.DialogInterface) MultiReddit(net.dean.jraw.models.MultiReddit) LayoutInflater(android.view.LayoutInflater) ImageFlairs(me.ccrama.redditslide.ImageFlairs) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MoreChildItem(me.ccrama.redditslide.Adapters.MoreChildItem) DialogAction(com.afollestad.materialdialogs.DialogAction) Subreddit(net.dean.jraw.models.Subreddit) CommentAdapter(me.ccrama.redditslide.Adapters.CommentAdapter) Activity(android.app.Activity) NetworkException(net.dean.jraw.http.NetworkException) Resources(android.content.res.Resources) Slider(com.rey.material.widget.Slider) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MainActivity(me.ccrama.redditslide.Activities.MainActivity) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) Toast(android.widget.Toast) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) TextView(android.widget.TextView) MoreChildItem(me.ccrama.redditslide.Adapters.MoreChildItem) EditText(android.widget.EditText) Context(android.content.Context) CommentsScreen(me.ccrama.redditslide.Activities.CommentsScreen) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) ColorPreferences(me.ccrama.redditslide.Visuals.ColorPreferences) Calendar(java.util.Calendar) MediaView(me.ccrama.redditslide.Activities.MediaView) ImageView(android.widget.ImageView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) SubredditView(me.ccrama.redditslide.Activities.SubredditView) TextPaint(android.text.TextPaint) CommentObject(me.ccrama.redditslide.Adapters.CommentObject) LayoutInflater(android.view.LayoutInflater) FrameLayout(android.widget.FrameLayout)

Example 14 with ContextThemeWrapper

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);
    }
}
Also used : Context(android.content.Context) AlbumPager(me.ccrama.redditslide.Activities.AlbumPager) ContextThemeWrapper(androidx.appcompat.view.ContextThemeWrapper) PeekViewActivity(me.ccrama.redditslide.ForceTouch.PeekViewActivity) Activity(android.app.Activity) Album(me.ccrama.redditslide.Activities.Album) Intent(android.content.Intent) 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) ContextWrapper(android.content.ContextWrapper)

Example 15 with ContextThemeWrapper

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();
        }
    }
}
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) 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) ContextThemeWrapper(androidx.appcompat.view.ContextThemeWrapper) OnRemove(me.ccrama.redditslide.ForceTouch.callback.OnRemove) BottomSheet(com.cocosw.bottomsheet.BottomSheet) ContextWrapper(android.content.ContextWrapper) SimpleOnPeek(me.ccrama.redditslide.ForceTouch.callback.SimpleOnPeek)

Aggregations

ContextThemeWrapper (androidx.appcompat.view.ContextThemeWrapper)21 Context (android.content.Context)14 View (android.view.View)12 ColorPreferences (me.ccrama.redditslide.Visuals.ColorPreferences)10 TextView (android.widget.TextView)9 LayoutInflater (android.view.LayoutInflater)7 Intent (android.content.Intent)6 ImageView (android.widget.ImageView)6 ArrayList (java.util.ArrayList)6 DialogInterface (android.content.DialogInterface)5 AlertDialog (androidx.appcompat.app.AlertDialog)5 RecyclerView (androidx.recyclerview.widget.RecyclerView)5 Snackbar (com.google.android.material.snackbar.Snackbar)5 SpoilerRobotoTextView (me.ccrama.redditslide.SpoilerRobotoTextView)5 Activity (android.app.Activity)4 ContextWrapper (android.content.ContextWrapper)4 TypedArray (android.content.res.TypedArray)4 HorizontalScrollView (android.widget.HorizontalScrollView)4 NonNull (androidx.annotation.NonNull)4 DialogAction (com.afollestad.materialdialogs.DialogAction)4