Example usage for android.view ViewStub inflate

List of usage examples for android.view ViewStub inflate

Introduction

In this page you can find the example usage for android.view ViewStub inflate.

Prototype

public View inflate() 

Source Link

Document

Inflates the layout resource identified by #getLayoutResource() and replaces this StubbedView in its parent by the inflated layout resource.

Usage

From source file:org.catnut.fragment.ProfileFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    // ??*_*?view?
    String query = CatnutUtils.buildQuery(PROJECTION, User.screen_name + "=" + CatnutUtils.quote(mScreenName),
            User.TABLE, null, null, null);
    new AsyncQueryHandler(getActivity().getContentResolver()) {
        @Override// ww w  . ja  v  a2s.c  om
        protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
            if (cursor.moveToNext()) {
                injectProfile(cursor);
            } else {
                // fall back to load from network...
                mApp.getRequestQueue().add(new CatnutRequest(getActivity(), UserAPI.profile(mScreenName),
                        new UserProcessor.UserProfileProcessor(), new Response.Listener<JSONObject>() {
                            @Override
                            public void onResponse(JSONObject response) {
                                injectProfile(response);
                            }
                        }, new Response.ErrorListener() {
                            @Override
                            public void onErrorResponse(VolleyError error) {
                                Toast.makeText(getActivity(), getString(R.string.user_not_found),
                                        Toast.LENGTH_SHORT).show();
                            }
                        }));
            }
            cursor.close();
        }
    }.startQuery(0, null, CatnutProvider.parse(User.MULTIPLE), null, query, null, null);
    // ??
    if (mApp.getPreferences().getBoolean(getString(R.string.pref_show_latest_tweet), true)) {
        String queryLatestTweet = CatnutUtils.buildQuery(new String[] { Status.columnText,
                //                     Status.thumbnail_pic,
                Status.bmiddle_pic, Status.comments_count, Status.reposts_count, Status.retweeted_status,
                Status.attitudes_count, Status.source, Status.created_at, },
                new StringBuilder("uid=(select _id from ").append(User.TABLE).append(" where ")
                        .append(User.screen_name).append("=").append(CatnutUtils.quote(mScreenName)).append(")")
                        .append(" and ").append(Status.TYPE).append(" in(").append(Status.HOME).append(",")
                        .append(Status.RETWEET).append(",").append(Status.OTHERS).append(")").toString(),
                Status.TABLE, null, BaseColumns._ID + " desc", "1");
        new AsyncQueryHandler(getActivity().getContentResolver()) {
            @Override
            protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
                if (cursor.moveToNext()) {
                    mTweetLayout.setOnClickListener(tweetsOnclickListener);
                    ViewStub viewStub = (ViewStub) mTweetLayout.findViewById(R.id.latest_tweet);
                    View tweet = viewStub.inflate();
                    mRetweetLayout = tweet.findViewById(R.id.retweet);
                    tweet.findViewById(R.id.timeline).setVisibility(View.GONE);
                    tweet.findViewById(R.id.verified).setVisibility(View.GONE);
                    tweet.findViewById(R.id.tweet_overflow).setVisibility(View.GONE);
                    CatnutUtils.setText(tweet, R.id.nick, getString(R.string.latest_statues))
                            .setTextColor(getResources().getColor(R.color.actionbar_background));
                    String tweetText = cursor.getString(cursor.getColumnIndex(Status.columnText));
                    TweetImageSpan tweetImageSpan = new TweetImageSpan(getActivity());
                    TweetTextView text = (TweetTextView) CatnutUtils.setText(tweet, R.id.text,
                            tweetImageSpan.getImageSpan(tweetText));
                    CatnutUtils.vividTweet(text, null);
                    CatnutUtils.setTypeface(text, mTypeface);
                    text.setLineSpacing(0, mLineSpacing);

                    String thumbsUrl = cursor.getString(cursor.getColumnIndex(Status.bmiddle_pic));
                    if (!TextUtils.isEmpty(thumbsUrl)) {
                        View thumbs = tweet.findViewById(R.id.thumbs);
                        Picasso.with(getActivity()).load(thumbsUrl).placeholder(R.drawable.error)
                                .error(R.drawable.error).into((ImageView) thumbs);
                        thumbs.setVisibility(View.VISIBLE);
                    }

                    int replyCount = cursor.getInt(cursor.getColumnIndex(Status.comments_count));
                    CatnutUtils.setText(tweet, R.id.reply_count, CatnutUtils.approximate(replyCount));
                    int retweetCount = cursor.getInt(cursor.getColumnIndex(Status.reposts_count));
                    CatnutUtils.setText(tweet, R.id.reteet_count, CatnutUtils.approximate(retweetCount));
                    int favoriteCount = cursor.getInt(cursor.getColumnIndex(Status.attitudes_count));
                    CatnutUtils.setText(tweet, R.id.like_count, CatnutUtils.approximate(favoriteCount));
                    String source = cursor.getString(cursor.getColumnIndex(Status.source));
                    CatnutUtils.setText(tweet, R.id.source, Html.fromHtml(source).toString());
                    String create_at = cursor.getString(cursor.getColumnIndex(Status.created_at));
                    CatnutUtils
                            .setText(tweet, R.id.create_at,
                                    DateUtils.getRelativeTimeSpanString(DateTime.getTimeMills(create_at)))
                            .setVisibility(View.VISIBLE);
                    // retweet
                    final String jsonString = cursor.getString(cursor.getColumnIndex(Status.retweeted_status));
                    try {
                        JSONObject jsonObject = new JSONObject(jsonString);
                        TweetTextView retweet = (TweetTextView) mRetweetLayout.findViewById(R.id.retweet_text);
                        retweet.setText(jsonObject.optString(Status.text));
                        CatnutUtils.vividTweet(retweet, tweetImageSpan);
                        CatnutUtils.setTypeface(retweet, mTypeface);
                        retweet.setLineSpacing(0, mLineSpacing);
                        long mills = DateTime.getTimeMills(jsonObject.optString(Status.created_at));
                        TextView tv = (TextView) mRetweetLayout.findViewById(R.id.retweet_create_at);
                        tv.setText(DateUtils.getRelativeTimeSpanString(mills));
                        TextView retweetUserScreenName = (TextView) mRetweetLayout
                                .findViewById(R.id.retweet_nick);
                        JSONObject user = jsonObject.optJSONObject(User.SINGLE);
                        if (user == null) {
                            retweetUserScreenName.setText(getString(R.string.unknown_user));
                        } else {
                            retweetUserScreenName.setText(user.optString(User.screen_name));
                            mRetweetLayout.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    Intent intent = new Intent(getActivity(), TweetActivity.class);
                                    intent.putExtra(Constants.JSON, jsonString);
                                    startActivity(intent);
                                }
                            });
                        }
                    } catch (Exception e) {
                        mRetweetLayout.setVisibility(View.GONE);
                    }
                }
                cursor.close();
            }
        }.startQuery(0, null, CatnutProvider.parse(Status.MULTIPLE), null, queryLatestTweet, null, null);
    }
}

From source file:io.plaidapp.ui.HomeActivity.java

private void checkConnectivity() {
    final ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(
            Context.CONNECTIVITY_SERVICE);
    final NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    connected = activeNetworkInfo != null && activeNetworkInfo.isConnected();
    if (!connected) {
        loading.setVisibility(View.GONE);
        if (noConnection == null) {
            final ViewStub stub = (ViewStub) findViewById(R.id.stub_no_connection);
            noConnection = (ImageView) stub.inflate();
        }/*from   ww  w.j ava2  s . c  o  m*/
        final AnimatedVectorDrawable avd = (AnimatedVectorDrawable) getDrawable(R.drawable.avd_no_connection);
        if (noConnection != null && avd != null) {
            noConnection.setImageDrawable(avd);
            avd.start();
        }

        connectivityManager.registerNetworkCallback(
                new NetworkRequest.Builder().addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET).build(),
                connectivityCallback);
        monitoringConnectivity = true;
    }
}

From source file:io.plaidapp.ui.HomeActivity.java

private void setNoFiltersEmptyTextVisibility(int visibility) {
    if (visibility == View.VISIBLE) {
        if (noFiltersEmptyText == null) {
            // create the no filters empty text
            ViewStub stub = (ViewStub) findViewById(R.id.stub_no_filters);
            noFiltersEmptyText = (TextView) stub.inflate();
            String emptyText = getString(R.string.no_filters_selected);
            int filterPlaceholderStart = emptyText.indexOf('\u08B4');
            int altMethodStart = filterPlaceholderStart + 3;
            SpannableStringBuilder ssb = new SpannableStringBuilder(emptyText);
            // show an image of the filter icon
            ssb.setSpan(new ImageSpan(this, R.drawable.ic_filter_small, ImageSpan.ALIGN_BASELINE),
                    filterPlaceholderStart, filterPlaceholderStart + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            // make the alt method (swipe from right) less prominent and italic
            ssb.setSpan(new ForegroundColorSpan(ContextCompat.getColor(this, R.color.text_secondary_light)),
                    altMethodStart, emptyText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            ssb.setSpan(new StyleSpan(Typeface.ITALIC), altMethodStart, emptyText.length(),
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            noFiltersEmptyText.setText(ssb);
            noFiltersEmptyText.setOnClickListener(new View.OnClickListener() {
                @Override//w w  w  .j a v  a2  s .  c  om
                public void onClick(View v) {
                    drawer.openDrawer(GravityCompat.END);
                }
            });
        }
        noFiltersEmptyText.setVisibility(visibility);
    } else if (noFiltersEmptyText != null) {
        noFiltersEmptyText.setVisibility(visibility);
    }

}

From source file:com.facebook.GraphObjectListFragment.java

private void inflateTitleBar(ViewGroup view) {
    ViewStub stub = (ViewStub) view.findViewById(R.id.com_facebook_picker_title_bar_stub);
    if (stub != null) {
        View titleBar = stub.inflate();

        final RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
        layoutParams.addRule(RelativeLayout.BELOW, R.id.com_facebook_picker_title_bar);
        listView.setLayoutParams(layoutParams);

        if (titleBarBackground != null) {
            titleBar.setBackgroundDrawable(titleBarBackground);
        }// w w  w .j  a  v  a2  s. com

        doneButton = (Button) view.findViewById(R.id.com_facebook_picker_done_button);
        if (doneButton != null) {
            doneButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (onDoneButtonClickedListener != null) {
                        onDoneButtonClickedListener.onDoneButtonClicked();
                    }
                }
            });

            if (doneButtonText == null) {
                doneButtonText = getDefaultDoneButtonText();
            }
            if (doneButtonText != null) {
                doneButton.setText(doneButtonText);
            }

            if (doneButtonBackground != null) {
                doneButton.setBackgroundDrawable(doneButtonBackground);
            }
        }

        titleTextView = (TextView) view.findViewById(R.id.com_facebook_picker_title);
        if (titleTextView != null) {
            if (titleText == null) {
                titleText = getDefaultTitleText();
            }
            if (titleText != null) {
                titleTextView.setText(titleText);
            }
        }
    }
}

From source file:com.google.samples.apps.ourstreets.fragment.GalleryFragment.java

private void setupAndInflate(ViewStub failedStub) {
    failedStub.setOnInflateListener(new ViewStub.OnInflateListener() {
        @Override/* w w  w  . ja  v  a  2 s .  co m*/
        public void onInflate(ViewStub stub, final View inflated) {
            inflated.findViewById(R.id.try_again).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    new GalleryPresenter(GalleryFragment.this).getData();
                    mEmptyView.setVisibility(View.VISIBLE);
                    inflated.setVisibility(View.GONE);
                }
            });
        }
    });
    failedStub.inflate();
}

From source file:com.facebook.GraphObjectAdapter.java

protected View createGraphObjectView(T graphObject, View convertView) {
    View result = inflater.inflate(getGraphObjectRowLayoutId(graphObject), null);

    ViewStub checkboxStub = (ViewStub) result.findViewById(R.id.com_facebook_picker_checkbox_stub);
    if (checkboxStub != null) {
        if (!getShowCheckbox()) {
            checkboxStub.setVisibility(View.GONE);
        } else {/*from www  .  ja  va 2 s  .  com*/
            CheckBox checkBox = (CheckBox) checkboxStub.inflate();
            updateCheckboxState(checkBox, false);
        }
    }

    ViewStub profilePicStub = (ViewStub) result.findViewById(R.id.com_facebook_picker_profile_pic_stub);
    if (!getShowPicture()) {
        profilePicStub.setVisibility(View.GONE);
    } else {
        ImageView imageView = (ImageView) profilePicStub.inflate();
        imageView.setVisibility(View.VISIBLE);
    }

    return result;
}

From source file:com.eutectoid.dosomething.picker.GraphObjectAdapter.java

protected View createGraphObjectView(JSONObject graphObject) {
    View result = inflater.inflate(getGraphObjectRowLayoutId(graphObject), null);

    ViewStub checkboxStub = (ViewStub) result.findViewById(R.id.com_facebook_picker_checkbox_stub);
    if (checkboxStub != null) {
        if (!getShowCheckbox()) {
            checkboxStub.setVisibility(View.GONE);
        } else {/*from   w w w. ja v a 2 s.  c o  m*/
            CheckBox checkBox = (CheckBox) checkboxStub.inflate();
            updateCheckboxState(checkBox, false);
        }
    }

    ViewStub profilePicStub = (ViewStub) result.findViewById(R.id.com_facebook_picker_profile_pic_stub);
    if (!getShowPicture()) {
        profilePicStub.setVisibility(View.GONE);
    } else {
        ImageView imageView = (ImageView) profilePicStub.inflate();
        imageView.setVisibility(View.VISIBLE);
    }

    return result;
}

From source file:com.facebook.widget.GraphObjectAdapter.java

protected View createGraphObjectView(T graphObject) {
    View result = inflater.inflate(getGraphObjectRowLayoutId(graphObject), null);

    ViewStub checkboxStub = (ViewStub) result.findViewById(R.id.com_facebook_picker_checkbox_stub);
    if (checkboxStub != null) {
        if (!getShowCheckbox()) {
            checkboxStub.setVisibility(View.GONE);
        } else {/*w  w w .j a  va 2s .  c  om*/
            CheckBox checkBox = (CheckBox) checkboxStub.inflate();
            updateCheckboxState(checkBox, false);
        }
    }

    ViewStub profilePicStub = (ViewStub) result.findViewById(R.id.com_facebook_picker_profile_pic_stub);
    if (!getShowPicture()) {
        profilePicStub.setVisibility(View.GONE);
    } else {
        ImageView imageView = (ImageView) profilePicStub.inflate();
        imageView.setVisibility(View.VISIBLE);
    }

    return result;
}

From source file:com.trk.aboutme.facebook.widget.PickerFragment.java

private void inflateTitleBar(ViewGroup view) {
    ViewStub stub = (ViewStub) view.findViewById(R.id.com_facebook_picker_title_bar_stub);
    if (stub != null) {
        View titleBar = stub.inflate();

        final RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
        layoutParams.addRule(RelativeLayout.BELOW, R.id.com_facebook_picker_title_bar);
        listView.setLayoutParams(layoutParams);

        if (titleBarBackground != null) {
            titleBar.setBackgroundDrawable(titleBarBackground);
        }//from  ww  w  .j  av  a  2  s . c o m

        doneButton = (Button) view.findViewById(R.id.com_facebook_picker_done_button);
        if (doneButton != null) {
            doneButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (onDoneButtonClickedListener != null) {
                        onDoneButtonClickedListener.onDoneButtonClicked(PickerFragment.this);
                    }
                }
            });

            if (getDoneButtonText() != null) {
                doneButton.setText(getDoneButtonText());
            }

            if (doneButtonBackground != null) {
                doneButton.setBackgroundDrawable(doneButtonBackground);
            }
        }

        titleTextView = (TextView) view.findViewById(R.id.com_facebook_picker_title);
        if (titleTextView != null) {
            if (getTitleText() != null) {
                titleTextView.setText(getTitleText());
            }
        }
    }
}

From source file:com.eutectoid.dosomething.picker.PickerFragment.java

private void inflateTitleBar(ViewGroup view) {
    ViewStub stub = (ViewStub) view.findViewById(R.id.com_facebook_picker_title_bar_stub);
    if (stub != null) {
        View titleBar = stub.inflate();

        final RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
        layoutParams.addRule(RelativeLayout.BELOW, R.id.com_facebook_picker_title_bar);
        listView.setLayoutParams(layoutParams);

        if (titleBarBackground != null) {
            titleBar.setBackgroundDrawable(titleBarBackground);
        }//from w w w.java 2 s .  com

        doneButton = (Button) view.findViewById(R.id.com_facebook_picker_done_button);
        if (doneButton != null) {
            doneButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    logAppEvents(true);
                    appEventsLogged = true;

                    if (onDoneButtonClickedListener != null) {
                        onDoneButtonClickedListener.onDoneButtonClicked(PickerFragment.this);
                    }
                }
            });

            if (getDoneButtonText() != null) {
                doneButton.setText(getDoneButtonText());
            }

            if (doneButtonBackground != null) {
                doneButton.setBackgroundDrawable(doneButtonBackground);
            }
        }

        titleTextView = (TextView) view.findViewById(R.id.com_facebook_picker_title);
        if (titleTextView != null) {
            if (getTitleText() != null) {
                titleTextView.setText(getTitleText());
            }
        }
    }
}