Java Code Examples for android.widget.ImageButton#setScaleType()

The following examples show how to use android.widget.ImageButton#setScaleType() . 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: ImageViewButtonItem.java    From RichEditorView with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@NonNull
@Override
public ImageButton createView() {
    ImageButton imageViewButton = new ImageButton(getContext());
    if (!enableAutoSet) {
        //无边框的带有水波纹的按钮样式
        TypedArray typedArray = getContext().obtainStyledAttributes(new int[]{android.R.attr.selectableItemBackgroundBorderless});
        Drawable drawable = typedArray.getDrawable(0);
        imageViewButton.setBackgroundDrawable(drawable);
        typedArray.recycle();
    } else {
        imageViewButton.setBackgroundDrawable(null);
    }

    imageViewButton.setImageResource(idRes);
    imageViewButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    return imageViewButton;
}
 
Example 2
Source File: AppPickerPreference.java    From GravityBox with Apache License 2.0 6 votes vote down vote up
@Override
protected void onBindView(View view) {
    super.onBindView(view);

    LinearLayout widgetFrameView = ((LinearLayout) view.findViewById(android.R.id.widget_frame));
    mBtnAppIcon = new ImageButton(mContext);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(mAppIconPreviewSizePx, mAppIconPreviewSizePx);
    lp.gravity = Gravity.CENTER;
    mBtnAppIcon.setLayoutParams(lp);
    mBtnAppIcon.setScaleType(ScaleType.CENTER_CROP);
    mBtnAppIcon.setImageDrawable(mAppInfo.icon);
    mBtnAppIcon.setFocusable(false);
    if (mIconPickerEnabled) {
        mBtnAppIcon.setOnClickListener(this);
        mBtnAppIcon.setOnLongClickListener(this);
    } else {
        mBtnAppIcon.setEnabled(false);
    }
    widgetFrameView.addView(mBtnAppIcon);
    widgetFrameView.setVisibility(View.VISIBLE);
}
 
Example 3
Source File: NavBarHook.java    From XposedNavigationBar with GNU General Public License v3.0 6 votes vote down vote up
private static void initHomeNavbar(LinearLayout homeNavbar, final ViewPager vp) {
    XpLog.i("initHomeNavbar");
    Context context = homeNavbar.getContext();

    ImageButton btnCall = new ImageButton(context);
    btnCall.setImageBitmap(ImageUtil.byte2Bitmap(DataHook.mapImgRes.get(ConstantStr.FUNC_SMALL_POINT_CODE)));
    btnCall.setScaleType(ImageView.ScaleType.FIT_CENTER);
    btnCall.setBackgroundColor(Color.alpha(255));
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
    homeNavbar.addView(btnCall, params);

    setHomePointPosition(homeNavbar);

    btnCall.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            vp.setCurrentItem(2);
        }
    });
}
 
Example 4
Source File: EmojiconsView.java    From EmojiChat with Apache License 2.0 6 votes vote down vote up
private void addTabIcon(EmojiconPage page, int index) {
    ImageButton icon = new ImageButton(getContext());
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT);
    params.weight = 1;
    icon.setBackground(null);
    icon.setScaleType(ImageView.ScaleType.CENTER);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        icon.setImageDrawable(getContext().getResources().getDrawable(page.getIcon()));
    } else {
        icon.setImageDrawable(getContext().getDrawable(page.getIcon()));
    }
    mTabsContainer.addView(icon, mTabsContainer.getChildCount() - 2, params);
    mTabs[index] = icon;
    final int indexToMove = index;
    icon.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mViewPager.setCurrentItem(indexToMove, true);
        }
    });
}
 
Example 5
Source File: EmojiconsView.java    From emojicon with Apache License 2.0 6 votes vote down vote up
private void addTabIcon(EmojiconPage page, int index) {
    ImageButton icon = new ImageButton(getContext());
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT);
    params.weight = 1;
    icon.setBackground(null);
    icon.setScaleType(ImageView.ScaleType.CENTER);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        icon.setImageDrawable(getContext().getResources().getDrawable(page.getIcon()));
    } else {
        icon.setImageDrawable(getContext().getDrawable(page.getIcon()));
    }
    mTabsContainer.addView(icon, mTabsContainer.getChildCount() - 2, params);
    mTabs[index] = icon;
    final int indexToMove = index;
    icon.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mViewPager.setCurrentItem(indexToMove, true);
        }
    });
}
 
Example 6
Source File: TabsPagerTitleStrip.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void addIconTabWithCounter(final int position, int resId)
{
    ImageButton tab = new ImageButton(getContext());
    tab.setImageResource(resId);
    tab.setColorFilter(position == pager.getCurrentItem() ? tabTextIconSelectedColor : tabTextIconUnselectedColor, PorterDuff.Mode.SRC_IN);
    tab.setScaleType(ImageView.ScaleType.CENTER);
    addTabWithCounter(position, tab);
}
 
Example 7
Source File: TabsPagerTitleStrip.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void addIconTabWithCounter(final int position, int resId)
{
    ImageButton tab = new ImageButton(getContext());
    tab.setImageResource(resId);
    tab.setColorFilter(position == pager.getCurrentItem() ? tabTextIconSelectedColor : tabTextIconUnselectedColor, PorterDuff.Mode.SRC_IN);
    tab.setScaleType(ImageView.ScaleType.CENTER);
    addTabWithCounter(position, tab);
}
 
Example 8
Source File: LightAndVolumeController.java    From XposedNavigationBar with GNU General Public License v3.0 5 votes vote down vote up
private ViewGroup getPanel(Context context, int type) {
    final ViewGroup mViewGroup = new LinearLayout(context);
    LinearLayout.LayoutParams btnParam =
            new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    //   btnParam.weight = 1;
    btnParam.gravity = Gravity.CENTER_VERTICAL;
    LinearLayout.LayoutParams seekBarParam =
            new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    seekBarParam.weight = 1;
    seekBarParam.gravity = Gravity.CENTER;

    ImageButton btnBack = new ImageButton(context);
    btnBack.setImageBitmap(backBitmap);
    btnBack.setScaleType(ImageView.ScaleType.FIT_CENTER);
    btnBack.setBackgroundColor(Color.alpha(255));

    SeekBar seekBar = getSeekBar(context, type);

    ImageButton btnFunc = new ImageButton(context);
    btnFunc.setImageBitmap(funcBitmap);
    btnFunc.setScaleType(ImageView.ScaleType.FIT_CENTER);
    btnFunc.setBackgroundColor(Color.alpha(255));

    mViewGroup.addView(btnBack, btnParam);
    mViewGroup.addView(seekBar, seekBarParam);
    mViewGroup.addView(btnFunc, btnParam);

    final WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    mViewGroup.setBackgroundColor(Color.BLACK);
    btnBack.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            wm.removeView(mViewGroup);
        }
    });

    return mViewGroup;
}
 
Example 9
Source File: MenuItemView.java    From ticdesign with Apache License 2.0 5 votes vote down vote up
@Override
protected void onFinishInflate() {
    super.onFinishInflate();

    mImageIcon = (ImageButton) findViewById(android.R.id.icon);
    mTextTitle = (TextView) findViewById(android.R.id.title);

    mImageIcon.setScaleType(ScaleType.FIT_CENTER);
}
 
Example 10
Source File: InfoBarLayout.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a close button that can be inserted into an infobar.
 * @param context Context to grab resources from.
 * @return {@link ImageButton} that represents a close button.
 */
static ImageButton createCloseButton(Context context) {
    TypedArray a = context.obtainStyledAttributes(new int[] {R.attr.selectableItemBackground});
    Drawable closeButtonBackground = a.getDrawable(0);
    a.recycle();

    ImageButton closeButton = new ImageButton(context);
    closeButton.setId(R.id.infobar_close_button);
    closeButton.setImageResource(R.drawable.btn_close);
    closeButton.setBackground(closeButtonBackground);
    closeButton.setContentDescription(context.getString(R.string.infobar_close));
    closeButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE);

    return closeButton;
}
 
Example 11
Source File: QuestionWidget.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
private void addHelpPlaceholder() {
    if (!mPrompt.hasHelp()) {
        return;
    }

    helpPlaceholder = new FrameLayout(this.getContext());
    helpPlaceholder.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.WRAP_CONTENT));

    final ImageButton trigger = new ImageButton(getContext());
    trigger.setScaleType(ScaleType.FIT_CENTER);
    trigger.setImageResource(R.drawable.icon_info_outline_lightcool);
    trigger.setBackgroundDrawable(null);
    trigger.setOnClickListener(v -> {
        trigger.setImageResource(R.drawable.icon_info_fill_lightcool);
        fireHelpText(() -> {
            // back to the old icon
            trigger.setImageResource(R.drawable.icon_info_outline_lightcool);
        });
    });
    trigger.setId(847294011);
    LinearLayout triggerLayout = new LinearLayout(getContext());
    triggerLayout.setOrientation(LinearLayout.HORIZONTAL);
    triggerLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
    triggerLayout.setGravity(Gravity.RIGHT);
    triggerLayout.addView(trigger);

    MediaLayout helpLayout = createHelpLayout();
    helpLayout.setBackgroundResource(R.color.very_light_blue);
    helpPlaceholder.addView(helpLayout);

    this.addView(triggerLayout);
    this.addView(helpPlaceholder);
    helpPlaceholder.setVisibility(View.GONE);
}
 
Example 12
Source File: FloatingToolbar.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private ImageButton createOverflowButton() {
    final ImageButton overflowButton = new ImageButton(mContext);
    overflowButton.setLayoutParams(new ViewGroup.LayoutParams(AndroidUtilities.dp(56), AndroidUtilities.dp(48)));
    overflowButton.setPaddingRelative(AndroidUtilities.dp(16), AndroidUtilities.dp(12), AndroidUtilities.dp(16), AndroidUtilities.dp(12));
    overflowButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    overflowButton.setImageDrawable(mOverflow);
    int color;
    if (currentStyle == STYLE_DIALOG) {
        color = Theme.getColor(Theme.key_dialogTextBlack);
        overflowButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.getColor(Theme.key_listSelector), 1));
    } else if (currentStyle == STYLE_BLACK) {
        color = 0xfffafafa;
        overflowButton.setBackgroundDrawable(Theme.createSelectorDrawable(0x40ffffff, 1));
    } else {
        color = Theme.getColor(Theme.key_windowBackgroundWhiteBlackText);
        overflowButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.getColor(Theme.key_listSelector), 1));
    }
    mOverflow.setTint(color);
    mArrow.setTint(color);
    mToArrow.setTint(color);
    mToOverflow.setTint(color);
    overflowButton.setOnClickListener(v -> {
        if (mIsOverflowOpen) {
            overflowButton.setImageDrawable(mToOverflow);
            mToOverflow.start();
            closeOverflow();
        } else {
            overflowButton.setImageDrawable(mToArrow);
            mToArrow.start();
            openOverflow();
        }
    });
    return overflowButton;
}
 
Example 13
Source File: FloatingToolbar.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private ImageButton createOverflowButton() {
    final ImageButton overflowButton = new ImageButton(mContext);
    overflowButton.setLayoutParams(new ViewGroup.LayoutParams(AndroidUtilities.dp(56), AndroidUtilities.dp(48)));
    overflowButton.setPaddingRelative(AndroidUtilities.dp(16), AndroidUtilities.dp(12), AndroidUtilities.dp(16), AndroidUtilities.dp(12));
    overflowButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    overflowButton.setImageDrawable(mOverflow);
    int color;
    if (currentStyle == STYLE_DIALOG) {
        color = Theme.getColor(Theme.key_dialogTextBlack);
        overflowButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.getColor(Theme.key_listSelector), 1));
    } else if (currentStyle == STYLE_BLACK) {
        color = 0xfffafafa;
        overflowButton.setBackgroundDrawable(Theme.createSelectorDrawable(0x40ffffff, 1));
    } else {
        color = Theme.getColor(Theme.key_windowBackgroundWhiteBlackText);
        overflowButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.getColor(Theme.key_listSelector), 1));
    }
    mOverflow.setTint(color);
    mArrow.setTint(color);
    mToArrow.setTint(color);
    mToOverflow.setTint(color);
    overflowButton.setOnClickListener(v -> {
        if (mIsOverflowOpen) {
            overflowButton.setImageDrawable(mToOverflow);
            mToOverflow.start();
            closeOverflow();
        } else {
            overflowButton.setImageDrawable(mToArrow);
            mToArrow.start();
            openOverflow();
        }
    });
    return overflowButton;
}
 
Example 14
Source File: WebViewDialog.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
/***
 * 初始化需要的控件
 * @param context
 */
@JavascriptInterface
private void initView(final Context context) {
    //父控件
    mParent = new FrameLayout(context);
    //设置背景
    mParent.setBackgroundColor(Color.parseColor("#F0F0F0"));
    //大小参数
    FrameLayout.LayoutParams mParentParams =
            new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
                    FrameLayout.LayoutParams.MATCH_PARENT);
    //设置参数
    mParent.setLayoutParams(mParentParams);
    //添加子控件
    FrameLayout mTopLayout = new FrameLayout(context);
    //设置背景
    mTopLayout.setBackgroundColor(Color.parseColor("#2b2b2b"));
    int mTopHight = VenvyUIUtil.dip2px(context, 45);
    //大小参数
    FrameLayout.LayoutParams mTopParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, mTopHight);
    //TOP区域添加返回按钮
    ImageButton mBackView = new ImageButton(context);
    //设置点击事件
    mBackView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dismiss();
        }
    });
    //设置本地图片
    mBackView.setBackgroundResource(VenvyResourceUtil.getDrawableOrmipmapId(
            context, "venvy_os_outside_link_back"));
    //
    mBackView.setScaleType(ImageView.ScaleType.FIT_CENTER);
    //大小参数
    FrameLayout.LayoutParams mBackParams = new FrameLayout.LayoutParams(mTopHight, mTopHight);
    mTopLayout.addView(mBackView, mBackParams);
    //进度条区域
    final ProgressBar mProBarView = new ProgressBar(context, null,
            android.R.attr.progressBarStyleHorizontal);
    //进度清空
    mProBarView.setProgress(0);
    //设置加载进度的颜色
    mProBarView.setProgressDrawable(context.getResources().getDrawable(
            VenvyResourceUtil.getDrawableId(context,
                    "venvy_library_webview_load_bg")));// 设置
    //大小参数
    FrameLayout.LayoutParams mBarParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, VenvyUIUtil.dip2px(context, 3));
    //顶部位置
    mBarParams.topMargin = mTopHight;
    //创建WebView控件
    mWebView = WebViewFactory.createWebView(context);
    //大小参数
    final FrameLayout.LayoutParams mWebParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
    //距离顶部位置
    mWebParams.topMargin = mTopHight;
    //加载监听
    mWebView.setWebChromeClient(new IVenvyWebChromeClient() {
        @Override
        public void onProgressChanged(View view, int newProgress) {
            if (newProgress >= 100) {
                mParent.removeView(mProBarView);
            } else {
                mProBarView.setProgress(newProgress);
            }
        }
    });

    mParent.addView(mTopLayout, mTopParams);
    if (mWebView instanceof View) {
        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        ((View) mWebView).setLayoutParams(params);
        mParent.addView((View) mWebView);
    }
    //添加进度条
    mParent.addView(mProBarView, mBarParams);
    //加载布局
    setContentView(mParent);
}