Example usage for android.view ViewGroup setDescendantFocusability

List of usage examples for android.view ViewGroup setDescendantFocusability

Introduction

In this page you can find the example usage for android.view ViewGroup setDescendantFocusability.

Prototype

public void setDescendantFocusability(int focusability) 

Source Link

Document

Set the descendant focusability of this view group.

Usage

From source file:com.wellsandwhistles.android.redditsp.fragments.CommentListingFragment.java

@Override
public void onCommentListingRequestPostDownloaded(final RedditPreparedPost post) {

    final Context context = getActivity();

    if (mPost == null) {

        final SRThemeAttributes attr = new SRThemeAttributes(context);

        mPost = post;/* w ww . j av  a2s . c  o m*/
        isArchived = post.isArchived;

        final RedditPostHeaderView postHeader = new RedditPostHeaderView(getActivity(), this.mPost);

        mCommentListingManager.addPostHeader(postHeader);
        ((LinearLayoutManager) mRecyclerView.getLayoutManager()).scrollToPositionWithOffset(0, 0);

        if (post.src.getSelfText() != null) {
            final ViewGroup selfText = post.src.getSelfText().buildView(getActivity(), attr.srMainTextCol,
                    14f * mCommentFontScale, mShowLinkButtons);
            selfText.setFocusable(false);
            selfText.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);

            final int paddingPx = General.dpToPixels(context, 10);
            final FrameLayout paddingLayout = new FrameLayout(context);
            final TextView collapsedView = new TextView(context);
            collapsedView.setText("[ + ]  " + getActivity().getString(R.string.collapsed_self_post));
            collapsedView.setVisibility(View.GONE);
            collapsedView.setPadding(paddingPx, paddingPx, paddingPx, paddingPx);
            paddingLayout.addView(selfText);
            paddingLayout.addView(collapsedView);
            paddingLayout.setPadding(paddingPx, paddingPx, paddingPx, paddingPx);

            paddingLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (selfText.getVisibility() == View.GONE) {
                        selfText.setVisibility(View.VISIBLE);
                        collapsedView.setVisibility(View.GONE);
                    } else {
                        selfText.setVisibility(View.GONE);
                        collapsedView.setVisibility(View.VISIBLE);
                    }

                }
            });
            // TODO mListHeaderNotifications.setBackgroundColor(Color.argb(35, 128, 128, 128));

            mCommentListingManager.addPostSelfText(paddingLayout);
        }

        if (!General.isTablet(context, PreferenceManager.getDefaultSharedPreferences(context))) {
            getActivity().setTitle(post.src.getTitle());
        }

        if (mCommentListingManager.isSearchListing()) {
            final CommentSubThreadView searchCommentThreadView = new CommentSubThreadView(getActivity(),
                    mAllUrls.get(0).asPostCommentListURL(), R.string.comment_header_search_thread_title);

            mCommentListingManager.addNotification(searchCommentThreadView);
        } else if (!mAllUrls.isEmpty() && mAllUrls.get(0).pathType() == RedditURLParser.POST_COMMENT_LISTING_URL
                && mAllUrls.get(0).asPostCommentListURL().commentId != null) {

            final CommentSubThreadView specificCommentThreadView = new CommentSubThreadView(getActivity(),
                    mAllUrls.get(0).asPostCommentListURL(), R.string.comment_header_specific_thread_title);

            mCommentListingManager.addNotification(specificCommentThreadView);
        }

        // TODO pref (currently 10 mins)
        if (mCachedTimestamp != null && SRTime.since(mCachedTimestamp) > 10 * 60 * 1000) {

            final TextView cacheNotif = (TextView) LayoutInflater.from(getActivity())
                    .inflate(R.layout.cached_header, null, false);
            cacheNotif.setText(getActivity().getString(R.string.listing_cached,
                    SRTime.formatDateTime(mCachedTimestamp, getActivity())));
            mCommentListingManager.addNotification(cacheNotif);
        }
    }
}

From source file:org.quantumbadger.redreader.fragments.CommentListingFragment.java

@Override
public void onCommentListingRequestPostDownloaded(final RedditPreparedPost post) {

    final Context context = getActivity();

    if (mPost == null) {

        final RRThemeAttributes attr = new RRThemeAttributes(context);

        mPost = post;/*from w w  w  .  j  a v a 2s  .  c o  m*/
        isArchived = post.isArchived;

        final RedditPostHeaderView postHeader = new RedditPostHeaderView(getActivity(), this.mPost);

        mCommentListingManager.addPostHeader(postHeader);
        ((LinearLayoutManager) mRecyclerView.getLayoutManager()).scrollToPositionWithOffset(0, 0);

        if (post.src.getSelfText() != null) {
            final ViewGroup selfText = post.src.getSelfText().buildView(getActivity(), attr.rrMainTextCol,
                    14f * mCommentFontScale, mShowLinkButtons);
            selfText.setFocusable(false);
            selfText.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);

            final int paddingPx = General.dpToPixels(context, 10);
            final FrameLayout paddingLayout = new FrameLayout(context);
            final TextView collapsedView = new TextView(context);
            collapsedView.setText("[ + ]  " + getActivity().getString(R.string.collapsed_self_post));
            collapsedView.setVisibility(View.GONE);
            collapsedView.setPadding(paddingPx, paddingPx, paddingPx, paddingPx);
            paddingLayout.addView(selfText);
            paddingLayout.addView(collapsedView);
            paddingLayout.setPadding(paddingPx, paddingPx, paddingPx, paddingPx);

            paddingLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (selfText.getVisibility() == View.GONE) {
                        selfText.setVisibility(View.VISIBLE);
                        collapsedView.setVisibility(View.GONE);
                    } else {
                        selfText.setVisibility(View.GONE);
                        collapsedView.setVisibility(View.VISIBLE);
                    }

                }
            });
            // TODO mListHeaderNotifications.setBackgroundColor(Color.argb(35, 128, 128, 128));

            mCommentListingManager.addPostSelfText(paddingLayout);
        }

        if (!General.isTablet(context, PreferenceManager.getDefaultSharedPreferences(context))) {
            getActivity().setTitle(post.src.getTitle());
        }

        if (mCommentListingManager.isSearchListing()) {
            final CommentSubThreadView searchCommentThreadView = new CommentSubThreadView(getActivity(),
                    mAllUrls.get(0).asPostCommentListURL(), R.string.comment_header_search_thread_title);

            mCommentListingManager.addNotification(searchCommentThreadView);
        } else if (!mAllUrls.isEmpty() && mAllUrls.get(0).pathType() == RedditURLParser.POST_COMMENT_LISTING_URL
                && mAllUrls.get(0).asPostCommentListURL().commentId != null) {

            final CommentSubThreadView specificCommentThreadView = new CommentSubThreadView(getActivity(),
                    mAllUrls.get(0).asPostCommentListURL(), R.string.comment_header_specific_thread_title);

            mCommentListingManager.addNotification(specificCommentThreadView);
        }

        // TODO pref (currently 10 mins)
        if (mCachedTimestamp != null && RRTime.since(mCachedTimestamp) > 10 * 60 * 1000) {

            final TextView cacheNotif = (TextView) LayoutInflater.from(getActivity())
                    .inflate(R.layout.cached_header, null, false);
            cacheNotif.setText(getActivity().getString(R.string.listing_cached,
                    RRTime.formatDateTime(mCachedTimestamp, getActivity())));
            mCommentListingManager.addNotification(cacheNotif);
        }
    }
}

From source file:org.lol.reddit.fragments.CommentListingFragment.java

@Override
public void onCommentListingRequestPostDownloaded(final RedditPreparedPost post) {

    final Context context = getSupportActivity();

    if (mPost == null) {

        mPost = post;/*from w  w w .  j  a  v a  2 s  .c o m*/

        final RedditPostHeaderView postHeader = new RedditPostHeaderView(getSupportActivity(),
                CommentListingFragment.this.mPost);
        listHeaderPost.addView(postHeader);

        if (post.parsedSelfText != null) {
            final ViewGroup selfText = post.parsedSelfText.buildView(getSupportActivity(), null,
                    14f * commentFontScale, mShowLinkButtons);
            selfText.setFocusable(false);
            selfText.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);

            final int paddingPx = General.dpToPixels(context, 10);
            listHeaderSelftext.addView(selfText);
            listHeaderSelftext.setPadding(paddingPx, paddingPx, paddingPx, paddingPx);
            listHeaderNotifications.setBackgroundColor(Color.argb(35, 128, 128, 128));
        }

        if (!General.isTablet(context, PreferenceManager.getDefaultSharedPreferences(context))) {
            getSupportActivity().getSupportActionBar().setTitle(StringEscapeUtils.unescapeHtml4(post.title));
        }
    }
}

From source file:android.car.ui.provider.CarDrawerLayout.java

/**
 * Open the drawer view by animating it into view.
 *//* w w w  .ja  v  a2 s .co m*/
public void openDrawer() {
    ViewGroup drawerView = (ViewGroup) findDrawerView();
    mStartedOpen = false;

    if (hasWindowFocus()) {
        int left;
        LayoutParams drawerLp = (LayoutParams) drawerView.getLayoutParams();
        if (checkDrawerViewAbsoluteGravity(drawerView, Gravity.LEFT)) {
            left = drawerLp.getMarginStart();
        } else {
            left = drawerLp.getMarginStart() + getWidth() - drawerView.getWidth();
        }
        mDragger.smoothSlideViewTo(drawerView, left, drawerView.getTop());
        dispatchOnDrawerOpening(drawerView);
    } else {
        final LayoutParams lp = (LayoutParams) drawerView.getLayoutParams();
        lp.onScreen = 1.f;
        dispatchOnDrawerOpened(drawerView);
    }

    ViewGroup contentView = (ViewGroup) findContentView();
    contentView.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
    drawerView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);

    View focusable = drawerView.getChildAt(0);
    if (focusable != null) {
        focusable.requestFocus();
    }
    invalidate();
}

From source file:android.car.ui.provider.CarDrawerLayout.java

/**
 * Close the specified drawer view by animating it into view.
 *///from   w w w  .jav  a  2  s .co m
public void closeDrawer() {
    ViewGroup drawerView = (ViewGroup) findDrawerView();
    if (!isDrawerView(drawerView)) {
        throw new IllegalArgumentException("View " + drawerView + " is not a sliding drawer");
    }
    mStartedOpen = true;

    // Don't trigger the close drawer animation if drawer is not open.
    if (hasWindowFocus() && isDrawerOpen()) {
        int left;
        LayoutParams drawerLp = (LayoutParams) drawerView.getLayoutParams();
        if (checkDrawerViewAbsoluteGravity(drawerView, Gravity.LEFT)) {
            left = drawerLp.getMarginStart() - drawerView.getWidth();
        } else {
            left = drawerLp.getMarginStart() + getWidth();
        }
        mDragger.smoothSlideViewTo(drawerView, left, drawerView.getTop());
        dispatchOnDrawerClosing(drawerView);
    } else {
        final LayoutParams lp = (LayoutParams) drawerView.getLayoutParams();
        lp.onScreen = 0.f;
        dispatchOnDrawerClosed(drawerView);
    }

    ViewGroup contentView = (ViewGroup) findContentView();
    drawerView.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
    contentView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);

    if (!isInTouchMode()) {
        List<View> focusables = contentView.getFocusables(FOCUS_DOWN);
        if (focusables.size() > 0) {
            View candidate = focusables.get(0);
            candidate.requestFocus();
        }
    }
    invalidate();
}

From source file:com.ryan.ryanreader.fragments.CommentListingFragment.java

private void makeFirstRequest(final Context context) {

    final RedditAccount user = RedditAccountManager.getInstance(context).getDefaultAccount();
    final CacheManager cm = CacheManager.getInstance(context);

    // TODO parameterise limit
    request = new CacheRequest(url, user, session, Constants.Priority.API_COMMENT_LIST, 0, downloadType,
            Constants.FileType.COMMENT_LIST, true, true, false, context) {

        @Override/*from   w  w w  . jav  a  2  s  .  co m*/
        protected void onDownloadNecessary() {
            new Handler(Looper.getMainLooper()).post(new Runnable() {
                public void run() {
                    listFooter.addView(loadingView);
                    adapter.notifyDataSetChanged();
                }
            });
        }

        @Override
        protected void onDownloadStarted() {
            loadingView.setIndeterminate(context.getString(R.string.download_connecting));
        }

        @Override
        protected void onCallbackException(final Throwable t) {
            request = null;
            BugReportActivity.handleGlobalError(context, t);
        }

        @Override
        protected void onFailure(final RequestFailureType type, final Throwable t, final StatusLine status,
                final String readableMessage) {

            request = null;

            if (!isAdded())
                return;

            if (loadingView != null)
                loadingView.setDoneNoAnim(R.string.download_failed);
            final RRError error = General.getGeneralErrorForFailure(context, type, t, status);

            new Handler(Looper.getMainLooper()).post(new Runnable() {
                public void run() {
                    notifications.addView(new ErrorView(getSupportActivity(), error));
                }
            });
        }

        @Override
        protected void onProgress(final long bytesRead, final long totalBytes) {
        }

        @Override
        protected void onSuccess(final CacheManager.ReadableCacheFile cacheFile, final long timestamp,
                final UUID session, final boolean fromCache, final String mimetype) {
            request = null;
        }

        @Override
        public void onJsonParseStarted(final JsonValue value, final long timestamp, final UUID session,
                final boolean fromCache) {

            if (isAdded() && loadingView != null)
                loadingView.setIndeterminate("Downloading...");

            // TODO pref (currently 10 mins)
            // TODO xml
            if (fromCache && RRTime.since(timestamp) > 10 * 60 * 1000) {
                new Handler(Looper.getMainLooper()).post(new Runnable() {
                    public void run() {
                        if (isDetached())
                            return;
                        final TextView cacheNotif = new TextView(context);
                        cacheNotif.setText(context.getString(R.string.listing_cached) + " "
                                + RRTime.formatDateTime(timestamp, context));
                        final int paddingPx = General.dpToPixels(context, 6);
                        final int sidePaddingPx = General.dpToPixels(context, 10);
                        cacheNotif.setPadding(sidePaddingPx, paddingPx, sidePaddingPx, paddingPx);
                        cacheNotif.setTextSize(13f);
                        listHeaderNotifications.addView(cacheNotif);
                        adapter.notifyDataSetChanged();
                    }
                });
            }

            ((SessionChangeListener) getSupportActivity()).onSessionChanged(session,
                    SessionChangeListener.SessionChangeType.COMMENTS, timestamp);

            // TODO {"error": 403} is received for unauthorized subreddits

            try {

                // Download main post
                if (value.getType() == JsonValue.Type.ARRAY) {
                    // lol, reddit api
                    final JsonBufferedArray root = value.asArray();
                    final JsonBufferedObject thing = root.get(0).asObject();
                    final JsonBufferedObject listing = thing.getObject("data");
                    final JsonBufferedArray postContainer = listing.getArray("children");
                    final RedditThing postThing = postContainer.getObject(0, RedditThing.class);
                    final RedditPost post = postThing.asPost();

                    // TODO show upvote/downvote/etc buttons

                    final RedditSubreddit parentSubreddit = new RedditSubreddit("/r/" + post.subreddit,
                            post.subreddit, false);

                    CommentListingFragment.this.post = new RedditPreparedPost(context, cm, 0, post, timestamp,
                            true, parentSubreddit, false, false, false, user);

                    final ViewGroup selfText;

                    if (post.is_self && post.selftext != null && post.selftext.trim().length() > 0) {

                        selfText = RedditCommentTextParser.parse(StringEscapeUtils.unescapeHtml4(post.selftext))
                                .generate(context, 14f * commentFontScale, null,
                                        new ActiveTextView.OnLinkClickedListener() {
                                            public void onClickUrl(String url) {
                                                if (url != null)
                                                    LinkHandler.onLinkClicked(getSupportActivity(), url, false);
                                            }

                                            public void onClickText(Object attachment) {
                                            }
                                        }, CommentListingFragment.this.post);
                    } else {
                        selfText = null;
                    }

                    new Handler(Looper.getMainLooper()).post(new Runnable() {
                        public void run() {

                            final RedditPostHeaderView postHeader = new RedditPostHeaderView(
                                    getSupportActivity(), CommentListingFragment.this.post,
                                    CommentListingFragment.this);
                            listHeaderPost.addView(postHeader);

                            if (selfText != null) {
                                selfText.setFocusable(false);
                                selfText.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);

                                final int paddingPx = General.dpToPixels(context, 10);
                                listHeaderSelftext.addView(selfText);
                                listHeaderSelftext.setPadding(paddingPx, paddingPx, paddingPx, paddingPx);
                                listHeaderNotifications.setBackgroundColor(Color.argb(35, 128, 128, 128));
                            }

                            if (!General.isTablet(context,
                                    PreferenceManager.getDefaultSharedPreferences(context))) {
                                getSupportActivity().getSupportActionBar().setTitle(post.title);
                            }
                        }
                    });
                }

                // Download comments

                final JsonBufferedObject thing;

                if (value.getType() == JsonValue.Type.ARRAY) {
                    thing = value.asArray().get(1).asObject();
                } else {
                    thing = value.asObject();
                }

                final JsonBufferedObject listing = thing.getObject("data");
                final JsonBufferedArray topLevelComments = listing.getArray("children");

                final HashSet<String> needsChanging = RedditChangeDataManager.getInstance(context)
                        .getChangedForParent(parentPostIdAndType, user);

                for (final JsonValue commentThingValue : topLevelComments) {
                    buildComments(commentThingValue, null, timestamp, needsChanging);
                }

                commentHandler.sendMessage(General.handlerMessage(0, buffer));

            } catch (Throwable t) {
                notifyFailure(RequestFailureType.PARSE, t, null, "Parse failure");
                return;
            }

            if (isAdded() && loadingView != null)
                loadingView.setDoneNoAnim(R.string.download_done);
        }

        private ArrayList<RedditPreparedComment> buffer = new ArrayList<RedditPreparedComment>();

        private void buildComments(final JsonValue value, final RedditPreparedComment parent,
                final long timestamp, final HashSet<String> needsChanging)
                throws IOException, InterruptedException, IllegalAccessException,
                java.lang.InstantiationException, NoSuchMethodException, InvocationTargetException {

            final RedditThing commentThing = value.asObject(RedditThing.class);

            if (commentThing.getKind() != RedditThing.Kind.COMMENT)
                return;

            final RedditComment comment = commentThing.asComment();
            final RedditPreparedComment preparedComment = new RedditPreparedComment(context, comment, parent,
                    timestamp, needsChanging.contains(comment.name), post, user, headerItems);

            after = preparedComment.idAndType;

            buffer.add(preparedComment);
            if (buffer.size() >= 40) {
                commentHandler.sendMessage(General.handlerMessage(0, buffer));
                buffer = new ArrayList<RedditPreparedComment>();
            }

            if (comment.replies.getType() == JsonValue.Type.OBJECT) {
                final JsonBufferedObject replies = comment.replies.asObject();
                final JsonBufferedArray children = replies.getObject("data").getArray("children");

                for (final JsonValue v : children) {
                    buildComments(v, preparedComment, timestamp, needsChanging);
                }
            }
        }
    };

    cm.makeRequest(request);
}