Java Code Examples for android.view.ViewStub#inflate()

The following examples show how to use android.view.ViewStub#inflate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GraphObjectAdapter.java    From Abelana-Android with Apache License 2.0 6 votes vote down vote up
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 {
            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;
}
 
Example 2
Source File: GraphObjectAdapter.java    From platform-friends-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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 {
            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;
}
 
Example 3
Source File: GraphObjectAdapter.java    From FacebookImageShareIntent with MIT License 6 votes vote down vote up
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 {
            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;
}
 
Example 4
Source File: GraphObjectAdapter.java    From FacebookNewsfeedSample-Android with Apache License 2.0 6 votes vote down vote up
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 {
            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;
}
 
Example 5
Source File: ViewHelper.java    From Common with Apache License 2.0 6 votes vote down vote up
/**
 * 把 ViewStub inflate 之后在其中根据 id 找 View
 *
 * @param parentView     包含 ViewStub 的 View
 * @param viewStubId     要从哪个 ViewStub 来 inflate
 * @param inflatedViewId 最终要找到的 View 的 id
 * @return id 为 inflatedViewId 的 View
 */
public static View findViewFromViewStub(View parentView, int viewStubId, int inflatedViewId) {
    if (null == parentView) {
        return null;
    }
    View view = parentView.findViewById(inflatedViewId);
    if (null == view) {
        ViewStub vs = (ViewStub) parentView.findViewById(viewStubId);
        if (null == vs) {
            return null;
        }
        view = vs.inflate();
        if (null != view) {
            view = view.findViewById(inflatedViewId);
        }
    }
    return view;
}
 
Example 6
Source File: ViewHelper.java    From DMusic with Apache License 2.0 6 votes vote down vote up
/**
 * @param parentView
 * @param viewStubId
 * @param inflatedViewId
 * @param inflateLayoutResId
 * @return
 */
@SuppressLint("ResourceType")
public static View findViewFromViewStub(View parentView, int viewStubId, int inflatedViewId, int inflateLayoutResId) {
    if (null == parentView) {
        return null;
    }
    View view = parentView.findViewById(inflatedViewId);
    if (null == view) {
        ViewStub vs = (ViewStub) parentView.findViewById(viewStubId);
        if (null == vs) {
            return null;
        }
        if (vs.getLayoutResource() < 1 && inflateLayoutResId > 0) {
            vs.setLayoutResource(inflateLayoutResId);
        }
        view = vs.inflate();
        if (null != view) {
            view = view.findViewById(inflatedViewId);
        }
    }
    return view;
}
 
Example 7
Source File: BaseFragment.java    From CloudReader with Apache License 2.0 6 votes vote down vote up
protected void showEmptyView(String text) {
    // 需要这样处理,否则二次显示会失败
    ViewStub viewStub = getView(R.id.vs_empty);
    if (viewStub != null) {
        emptyView = viewStub.inflate();
        ((TextView) emptyView.findViewById(R.id.tv_tip_empty)).setText(text);
    }
    if (emptyView != null) {
        emptyView.setVisibility(View.VISIBLE);
    }

    if (loadingView != null && loadingView.getVisibility() != View.GONE) {
        loadingView.setVisibility(View.GONE);
    }
    // 停止动画
    if (mAnimationDrawable != null && mAnimationDrawable.isRunning()) {
        mAnimationDrawable.stop();
    }
    if (errorView != null) {
        errorView.setVisibility(View.GONE);
    }
    if (bindingView != null && bindingView.getRoot().getVisibility() != View.GONE) {
        bindingView.getRoot().setVisibility(View.GONE);
    }
}
 
Example 8
Source File: StatusHelper.java    From MeiBaseModule with Apache License 2.0 5 votes vote down vote up
private View inflateViewStub(@IdRes int stubId) {
    ViewStub viewStub = (ViewStub) mView.findViewById(stubId);
    if (viewStub != null && viewStub.getLayoutResource() != 0) {
        return viewStub.inflate();
    }
    return null;
}
 
Example 9
Source File: LinkShareViewHolder.java    From TestChat with Apache License 2.0 5 votes vote down vote up
public LinkShareViewHolder(View itemView) {
                super(itemView);
                ViewStub viewStub = (ViewStub) itemView.findViewById(R.id.vs_share_fragment_item_main);
                viewStub.setLayoutResource(R.layout.share_fragment_item_link_layout);
                viewStub.inflate();
//                display = (LinearLayout) viewStub.inflate().findViewById(R.id.ll_share_fragment_item_container);
        }
 
Example 10
Source File: TestActivity.java    From Android-skin-support with MIT License 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test);
    initToolbar();
    ViewStub viewStub = (ViewStub) findViewById(R.id.view_stub);
    viewStub.setLayoutResource(R.layout.fragment_view_stub);
    viewStub.inflate();
    MDFirstFragment fragment = (MDFirstFragment) getSupportFragmentManager().findFragmentById(R.id.md_fragment);
    Log.e("TestActivity", "fragment = " + fragment);
}
 
Example 11
Source File: ShareView.java    From ChinaShare with MIT License 5 votes vote down vote up
private void setUpView(Activity context) {
    shareView = View.inflate(context, R.layout.layout_share_view, null);
    fullMaskView = shareView.findViewById(R.id.full_mask);
    mViewStub = (ViewStub) shareView.findViewById(R.id.view_stub);
    mViewStub.inflate();
    llContent = (LinearLayout) shareView.findViewById(R.id.ll_content);
    mGirdView = (GridView) shareView.findViewById(R.id.gv_share);
    mTvClose = (TextView) shareView.findViewById(R.id.tv_close);
    // add shareView to activity's root view
    ((ViewGroup) context.getWindow().getDecorView()).addView(shareView);
    initListener();
}
 
Example 12
Source File: MainActivity.java    From HaoReader with GNU General Public License v3.0 5 votes vote down vote up
private void showRecentlyViewed(){
    if(recentlyViewedView == null){
        ViewStub viewStub = findViewById(R.id.view_stub_recently_viewed);
        recentlyViewedView = (RecentlyViewedView) viewStub.inflate();
    }

    recentlyViewedView.show();
}
 
Example 13
Source File: MovementTrackActivity.java    From RunMap with Apache License 2.0 5 votes vote down vote up
private void inflateDataUiLayout(){
    ViewStub viewStub = (ViewStub) findViewById(R.id.vs_data_ui_layout);
    if(viewStub == null){
        //already inflate
        return;
    }
    View dataUiRoot = viewStub.inflate();
    //初始化数据UI相关
    mViewGpsPower = dataUiRoot.findViewById(R.id.view_gps_power);
    mBtnChangeMapUi = (Button) dataUiRoot.findViewById(R.id.btn_change_to_map_ui);
    mTvDataMoveDistance = (TextView) dataUiRoot.findViewById(R.id.tv_data_ui_distance);
    mTvDataMoveTime = (TextView) dataUiRoot.findViewById(R.id.tv_data_ui_time);
    mBtnChangeMapUi.setOnClickListener(this);
}
 
Example 14
Source File: BaseFragment.java    From CloudReader with Apache License 2.0 5 votes vote down vote up
/**
 * 加载失败点击重新加载的状态
 */
protected void showError() {
    ViewStub viewStub = getView(R.id.vs_error_refresh);
    if (viewStub != null) {
        errorView = viewStub.inflate();
        // 点击加载失败布局
        errorView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showLoading();
                onRefresh();
            }
        });
    }
    if (errorView != null) {
        errorView.setVisibility(View.VISIBLE);
    }
    if (loadingView != null && loadingView.getVisibility() != View.GONE) {
        loadingView.setVisibility(View.GONE);
    }
    // 停止动画
    if (mAnimationDrawable != null && mAnimationDrawable.isRunning()) {
        mAnimationDrawable.stop();
    }
    if (bindingView.getRoot().getVisibility() != View.GONE) {
        bindingView.getRoot().setVisibility(View.GONE);
    }
    if (emptyView != null && emptyView.getVisibility() != View.GONE) {
        emptyView.setVisibility(View.GONE);
    }
}
 
Example 15
Source File: PickerFragment.java    From FacebookImageShareIntent with MIT License 4 votes vote down vote up
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);
        }

        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());
            }
        }
    }
}
 
Example 16
Source File: AuthenticateActivity.java    From andOTP with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setTitle(R.string.auth_activity_title);

    if (! settings.getScreenshotsEnabled())
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);

    setContentView(R.layout.activity_container);

    Toolbar toolbar = findViewById(R.id.container_toolbar);
    toolbar.setNavigationIcon(null);
    setSupportActionBar(toolbar);

    ViewStub stub = findViewById(R.id.container_stub);
    stub.setLayoutResource(R.layout.content_authenticate);
    View v = stub.inflate();

    Intent callingIntent = getIntent();
    int labelMsg = callingIntent.getIntExtra(Constants.EXTRA_AUTH_MESSAGE, R.string.auth_msg_authenticate);
    newEncryption = callingIntent.getStringExtra(Constants.EXTRA_AUTH_NEW_ENCRYPTION);

    TextView passwordLabel = v.findViewById(R.id.passwordLabel);
    TextInputLayout passwordLayout = v.findViewById(R.id.passwordLayout);
    passwordInput = v.findViewById(R.id.passwordEdit);

    if (settings.getBlockAccessibility())
        passwordLayout.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && settings.getBlockAutofill())
        passwordLayout.setImportantForAutofill(View.IMPORTANT_FOR_AUTOFILL_NO_EXCLUDE_DESCENDANTS);

    passwordLabel.setText(labelMsg);

    authMethod = settings.getAuthMethod();
    password = settings.getAuthCredentials();

    if (password.isEmpty()) {
        password = settings.getOldCredentials(authMethod);
        oldPassword = true;
    }

    if (authMethod == AuthMethod.PASSWORD) {
        if (password.isEmpty()) {
            Toast.makeText(this, R.string.auth_toast_password_missing, Toast.LENGTH_LONG).show();
            finishWithResult(true, null);
        } else {
            passwordLayout.setHint(getString(R.string.auth_hint_password));
            passwordInput.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
        }
    } else if (authMethod == AuthMethod.PIN) {
        if (password.isEmpty()) {
            Toast.makeText(this, R.string.auth_toast_pin_missing, Toast.LENGTH_LONG).show();
            finishWithResult(true, null);
        } else {
            passwordLayout.setHint(getString(R.string.auth_hint_pin));
            passwordInput.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
        }
    } else {
        finishWithResult(true, null);
    }

    passwordInput.setTransformationMethod(new PasswordTransformationMethod());
    passwordInput.setOnEditorActionListener(this);

    Button unlockButton = v.findViewById(R.id.buttonUnlock);
    unlockButton.setOnClickListener(this);

    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
 
Example 17
Source File: PickerFragment.java    From android-skeleton-project with MIT License 4 votes vote down vote up
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);
        }

        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());
            }
        }
    }
}
 
Example 18
Source File: ChromeActivity.java    From delion with Apache License 2.0 4 votes vote down vote up
/**
 * This function builds the {@link CompositorViewHolder}.  Subclasses *must* call
 * super.setContentView() before using {@link #getTabModelSelector()} or
 * {@link #getCompositorViewHolder()}.
 */
@Override
protected final void setContentView() {
    final long begin = SystemClock.elapsedRealtime();
    TraceEvent.begin("onCreate->setContentView()");

    enableHardwareAcceleration();
    setLowEndTheme();
    int controlContainerLayoutId = getControlContainerLayoutId();
    WarmupManager warmupManager = WarmupManager.getInstance();
    if (warmupManager.hasBuiltOrClearViewHierarchyWithToolbar(controlContainerLayoutId)) {
        View placeHolderView = new View(this);
        setContentView(placeHolderView);
        ViewGroup contentParent = (ViewGroup) placeHolderView.getParent();
        WarmupManager.getInstance().transferViewHierarchyTo(contentParent);
        contentParent.removeView(placeHolderView);
    } else {
        setContentView(R.layout.main);
        if (controlContainerLayoutId != NO_CONTROL_CONTAINER) {
            ViewStub toolbarContainerStub =
                    ((ViewStub) findViewById(R.id.control_container_stub));
            toolbarContainerStub.setLayoutResource(controlContainerLayoutId);
            toolbarContainerStub.inflate();
        }
    }
    TraceEvent.end("onCreate->setContentView()");
    mInflateInitialLayoutDurationMs = SystemClock.elapsedRealtime() - begin;

    // Set the status bar color to black by default. This is an optimization for
    // Chrome not to draw under status and navigation bars when we use the default
    // black status bar
    ApiCompatibilityUtils.setStatusBarColor(getWindow(), Color.BLACK);

    ViewGroup rootView = (ViewGroup) getWindow().getDecorView().getRootView();
    mCompositorViewHolder = (CompositorViewHolder) findViewById(R.id.compositor_view_holder);
    mCompositorViewHolder.setRootView(rootView);

    // Setting fitsSystemWindows to false ensures that the root view doesn't consume the insets.
    rootView.setFitsSystemWindows(false);

    // Add a custom view right after the root view that stores the insets to access later.
    // ContentViewCore needs the insets to determine the portion of the screen obscured by
    // non-content displaying things such as the OSK.
    mInsetObserverView = InsetObserverView.create(this);
    rootView.addView(mInsetObserverView, 0);
}
 
Example 19
Source File: SendTextHolder.java    From NewFastFrame with Apache License 2.0 4 votes vote down vote up
public SendTextHolder(View itemView) {
    super(itemView);
    ViewStub viewStub = (ViewStub) getView(R.id.vs_item_activity_chat_send_view_stub);
    viewStub.setLayoutResource(R.layout.item_activity_chat_send_text);
    viewStub.inflate();
}
 
Example 20
Source File: LayoutSelector.java    From Pocket-Plays-for-Twitch with GNU General Public License v3.0 4 votes vote down vote up
private void init() {
	layoutSelectorView = activity.getLayoutInflater().inflate(R.layout.stream_layout_preview, null);
	final RadioGroup rg = (RadioGroup) layoutSelectorView.findViewById(R.id.layouts_radiogroup);
	final FrameLayout previewWrapper = (FrameLayout) layoutSelectorView.findViewById(R.id.preview_wrapper);

	if (previewMaxHeightRes != -1) {
		LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
				ViewGroup.LayoutParams.MATCH_PARENT,
				(int) activity.getResources().getDimension(previewMaxHeightRes)
		);
		previewWrapper.setLayoutParams(lp);
		//previewWrapper.setMinimumHeight((int) activity.getResources().getDimension(previewMaxHeightRes));
	}

	ViewStub preview = (ViewStub) layoutSelectorView.findViewById(R.id.layout_stub);
	preview.setLayoutResource(previewLayout);
	final View inflated = preview.inflate();

	for (int i = 0; i < layoutTitles.length; i++) {
		final String layoutTitle = layoutTitles[i];

		final AppCompatRadioButton radioButton = new AppCompatRadioButton(activity);
		radioButton.setText(layoutTitle);

		final int finalI = i;
		radioButton.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				selectCallback.onSelected(layoutTitle, finalI, inflated);
			}
		});

		if (textColor != -1) {
			radioButton.setTextColor(Service.getColorAttribute(textColor, R.color.black_text, activity));

			ColorStateList colorStateList = new ColorStateList(
					new int[][]{
							new int[]{-android.R.attr.state_checked},
							new int[]{android.R.attr.state_checked}
					},
					new int[]{

							Color.GRAY, //Disabled
							Service.getColorAttribute(R.attr.colorAccent, R.color.accent, activity), //Enabled
					}
			);
			radioButton.setSupportButtonTintList(colorStateList);
		}


		radioButton.setLayoutParams(new ViewGroup.LayoutParams(
				ViewGroup.LayoutParams.MATCH_PARENT, // Width
				(int) activity.getResources().getDimension(R.dimen.layout_selector_height) // Height
		));


		rg.addView(radioButton, i);


		if ((selectedLayoutIndex != -1 && selectedLayoutIndex == i) || (selectedLayoutTitle != null && selectedLayoutTitle.equals(layoutTitle))) {
			radioButton.performClick();
		}
	}
}