Java Code Examples for androidx.appcompat.widget.SwitchCompat#setSwitchPadding()

The following examples show how to use androidx.appcompat.widget.SwitchCompat#setSwitchPadding() . 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: SearchLayout.java    From MHViewer with Apache License 2.0 4 votes vote down vote up
@SuppressLint("InflateParams")
private void init(Context context) {
    Resources resources = context.getResources();
    mInflater = LayoutInflater.from(context);

    mLayoutManager = new LinearLayoutManager(context);
    mAdapter = new SearchAdapter();
    setLayoutManager(mLayoutManager);
    setAdapter(mAdapter);
    setHasFixedSize(true);
    setClipToPadding(false);
    int interval = resources.getDimensionPixelOffset(R.dimen.search_layout_interval);
    int paddingH = resources.getDimensionPixelOffset(R.dimen.search_layout_margin_h);
    int paddingV = resources.getDimensionPixelOffset(R.dimen.search_layout_margin_v);
    MarginItemDecoration decoration = new MarginItemDecoration(
            interval, paddingH, paddingV, paddingH, paddingV);
    addItemDecoration(decoration);
    decoration.applyPaddings(this);

    // Create normal view
    View normalView = mInflater.inflate(R.layout.search_normal, null);
    mNormalView = normalView;
    mCategoryTable = (CategoryTable) normalView.findViewById(R.id.search_category_table);
    mNormalSearchMode = (RadioGridGroup) normalView.findViewById(R.id.normal_search_mode);
    mNormalSearchModeHelp = (ImageView) normalView.findViewById(R.id.normal_search_mode_help);
    mEnableAdvanceSwitch = (SwitchCompat) normalView.findViewById(R.id.search_enable_advance);
    mNormalSearchModeHelp.setOnClickListener(this);
    Ripple.addRipple(mNormalSearchModeHelp, !AttrResources.getAttrBoolean(context, R.attr.isLightTheme));
    mEnableAdvanceSwitch.setOnCheckedChangeListener(SearchLayout.this);
    mEnableAdvanceSwitch.setSwitchPadding(resources.getDimensionPixelSize(R.dimen.switch_padding));

    // Create advance view
    mAdvanceView = mInflater.inflate(R.layout.search_advance, null);
    mTableAdvanceSearch = (AdvanceSearchTable) mAdvanceView.findViewById(R.id.search_advance_search_table);

    // Create image view
    mImageView = (ImageSearchLayout) mInflater.inflate(R.layout.search_image, null);
    mImageView.setHelper(this);

    // Create action view
    mActionView = mInflater.inflate(R.layout.search_action, null);
    mAction = (TextView) mActionView.findViewById(R.id.action);
    mAction.setOnClickListener(this);
}
 
Example 2
Source File: SearchLayout.java    From EhViewer with Apache License 2.0 4 votes vote down vote up
@SuppressLint("InflateParams")
private void init(Context context) {
    Resources resources = context.getResources();
    mInflater = LayoutInflater.from(context);

    mLayoutManager = new LinearLayoutManager(context);
    mAdapter = new SearchAdapter();
    setLayoutManager(mLayoutManager);
    setAdapter(mAdapter);
    setHasFixedSize(true);
    setClipToPadding(false);
    int interval = resources.getDimensionPixelOffset(R.dimen.search_layout_interval);
    int paddingH = resources.getDimensionPixelOffset(R.dimen.search_layout_margin_h);
    int paddingV = resources.getDimensionPixelOffset(R.dimen.search_layout_margin_v);
    MarginItemDecoration decoration = new MarginItemDecoration(
            interval, paddingH, paddingV, paddingH, paddingV);
    addItemDecoration(decoration);
    decoration.applyPaddings(this);

    // Create normal view
    View normalView = mInflater.inflate(R.layout.search_normal, null);
    mNormalView = normalView;
    mCategoryTable = (CategoryTable) normalView.findViewById(R.id.search_category_table);
    mNormalSearchMode = (RadioGridGroup) normalView.findViewById(R.id.normal_search_mode);
    mNormalSearchModeHelp = (ImageView) normalView.findViewById(R.id.normal_search_mode_help);
    mEnableAdvanceSwitch = (SwitchCompat) normalView.findViewById(R.id.search_enable_advance);
    mNormalSearchModeHelp.setOnClickListener(this);
    Ripple.addRipple(mNormalSearchModeHelp, !AttrResources.getAttrBoolean(context, R.attr.isLightTheme));
    mEnableAdvanceSwitch.setOnCheckedChangeListener(SearchLayout.this);
    mEnableAdvanceSwitch.setSwitchPadding(resources.getDimensionPixelSize(R.dimen.switch_padding));

    // Create advance view
    mAdvanceView = mInflater.inflate(R.layout.search_advance, null);
    mTableAdvanceSearch = (AdvanceSearchTable) mAdvanceView.findViewById(R.id.search_advance_search_table);

    // Create image view
    mImageView = (ImageSearchLayout) mInflater.inflate(R.layout.search_image, null);
    mImageView.setHelper(this);

    // Create action view
    mActionView = mInflater.inflate(R.layout.search_action, null);
    mAction = (TextView) mActionView.findViewById(R.id.action);
    mAction.setOnClickListener(this);
}