Example usage for android.widget ImageButton ImageButton

List of usage examples for android.widget ImageButton ImageButton

Introduction

In this page you can find the example usage for android.widget ImageButton ImageButton.

Prototype

public ImageButton(Context context) 

Source Link

Usage

From source file:Main.java

public static ImageButton makeImageButton(Context context, int id, int resId, int width, int height,
        OnClickListener onClickListener, OnTouchListener onTouchListener) {
    Drawable icon;/*from w ww .  j ava  2 s.co  m*/
    ImageButton button = new ImageButton(context);
    button.setId(id);
    if (onClickListener != null)
        button.setOnClickListener(onClickListener);
    button.setBackgroundColor(Color.TRANSPARENT);
    icon = context.getResources().getDrawable(resId);
    icon.setBounds(0, 0, width, height);

    Bitmap iconBitmap = ((BitmapDrawable) icon).getBitmap();
    Bitmap bitmapResized = Bitmap.createScaledBitmap(iconBitmap, width, height, false);
    button.setImageBitmap(bitmapResized);
    button.setVisibility(View.VISIBLE);
    if (onTouchListener != null)
        button.setOnTouchListener(onTouchListener);
    return button;
}

From source file:bdlin.example.example.explorer.layout.PrefsFragment.java

public PrefsFragment(Context context, int imageID) {
    settingBtn = new ImageButton(context);
    settingBtn.setImageResource(imageID);
    this.menuRes = R.menu.customer_menu2;

}

From source file:bdlin.example.example.explorer.layout.SdcardListFragment.java

public SdcardListFragment(Context context, int img_id, int menuRes, ContentFragment content, String filePath) {
    this.menuRes = menuRes;
    mContent = content;//from  ww  w.  j a  v  a  2  s  .co  m
    rootPath = filePath;
    tempPath = filePath;
    array = new ArrayList<ComplexListItem>();
    iFileList = new ArrayList<IFile>();
    remoteBtn = new ImageButton(context);
    remoteBtn.setImageResource(img_id);
}

From source file:com.cmput301.recipebot.ui.adapters.EditableImagePagerAdapter.java

@Override
public Object instantiateItem(ViewGroup view, int position) {
    if (position < mImages.size()) {
        // Show the imageview
        return super.instantiateItem(view, position);
    }// ww w.  ja  v a  2 s  .co m
    final ImageButton imageButton = new ImageButton(mContext);
    ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    imageButton.setLayoutParams(lp);
    imageButton.setScaleType(ImageView.ScaleType.CENTER);
    if (position == mImages.size()) {
        // Set up an add button
        imageButton.setOnClickListener(galleryClickListener);
        imageButton.setImageResource(R.drawable.ic_action_gallery_blue);
    } else if (position == mImages.size() + 1) {
        // Set up a camera button
        imageButton.setOnClickListener(cameraClickListener);
        imageButton.setImageResource(R.drawable.ic_action_camera_blue);
    }
    ((ViewPager) view).addView(imageButton, 0);
    return imageButton;
}

From source file:com.tiancaicc.springfloatingactionmenu.MenuItemView.java

private void init(Context context, boolean hasMargin) {

    Resources resources = getResources();
    int diameterPX = Utils.dpToPx(mMenuItem.getDiameter(), resources);
    this.mDiameter = diameterPX;
    mBtn = new ImageButton(context);
    mBtn.setScaleType(ImageView.ScaleType.FIT_CENTER);
    if (hasMargin) {
        int p = Util.dpToPx(12, getResources());
        mBtn.setPadding(p, p, p, p);//  w  ww .  j  a v a  2 s .  c  o  m
    }
    LayoutParams btnLp = new LayoutParams(diameterPX, diameterPX);
    btnLp.gravity = Gravity.CENTER_HORIZONTAL;
    btnLp.bottomMargin = Util.dpToPx(mGapSize, resources);
    mBtn.setLayoutParams(btnLp);
    OvalShape ovalShape = new OvalShape();
    ShapeDrawable shapeDrawable = new ShapeDrawable(ovalShape);
    shapeDrawable.getPaint().setColor(resources.getColor(mMenuItem.getBgColor()));
    mBtn.setBackgroundDrawable(shapeDrawable);
    if (TextUtils.isEmpty(mMenuItem.getIconFilePath())) {
        mBtn.setImageResource(mMenuItem.getIcon());
    } else {
        mBtn.setImageURI(Uri.fromFile(new File(mMenuItem.getIconFilePath())));
    }
    mBtn.setClickable(false);
    addView(mBtn);

    mLabel = (com.github.omadahealth.typefaceview.TypefaceTextView) View.inflate(getContext(),
            R.layout.c_text_view, null);
    mLabel.setPaintFlags(mLabel.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
    mLabel.setTextIsSelectable(false);
    LayoutParams labelLp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    labelLp.gravity = Gravity.CENTER_HORIZONTAL;
    mLabel.setLayoutParams(labelLp);
    if (!TextUtils.isEmpty(mMenuItem.getLabel())) {
        mLabel.setPadding(0, Util.dpToPx(70, getResources()), 0, 0);
        Drawable bottomArrow = ContextCompat.getDrawable(getContext(), R.drawable.ic_arrow);
        mLabel.setCompoundDrawablesWithIntrinsicBounds(null, null, null, bottomArrow);
    }
    mLabel.setText(mMenuItem.getLabel());
    mLabel.setTextColor(resources.getColor(mMenuItem.getTextColor()));
    //        mLabel.setTextSize(TypedValue.COMPLEX_UNIT_SP, mTextSize);
    addView(mLabel);

    setOrientation(LinearLayout.VERTICAL);
    if (mAlphaAnimation) {
        setAlpha(0);
    }

    getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            getViewTreeObserver().removeGlobalOnLayoutListener(this);
            applyPressAnimation();
            ViewGroup parent = (ViewGroup) getParent();
            parent.setClipChildren(false);
            parent.setClipToPadding(false);
            setClipChildren(false);
            setClipToPadding(false);
        }
    });

}

From source file:com.cvte.LiZhiDemo.Activity.ImagePagerActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.lizhi_image_pager_layout);

    btCloss = new ImageButton(this);
    btCloss = (ImageButton) findViewById(R.id.close);
    btCloss.setOnClickListener(new OnClickListener() {

        @Override/* ww  w .  ja  va2  s . co m*/
        public void onClick(View v) {
            finish();

        }
    });

    ArrayList<String> imageUrls = getIntent().getStringArrayListExtra(Extra.IMAGES);
    // ??View?   
    int pagerPosition = getIntent().getIntExtra(Extra.IMAGE_POSITION, 0);

    // ??   
    if (savedInstanceState != null) {
        pagerPosition = savedInstanceState.getInt(STATE_POSITION);
    }

    /**
     * ????       */
    initPoint(imageUrls.size());

    options = new DisplayImageOptions.Builder().resetViewBeforeLoading(true).cacheInMemory(true)
            .imageScaleType(ImageScaleType.EXACTLY).bitmapConfig(Bitmap.Config.RGB_565)
            .displayer(new FadeInBitmapDisplayer(300)).build();

    pager = (ViewPager) findViewById(R.id.pager);
    pager.setAdapter(new ImagePagerAdapter(imageUrls));

    pager.setCurrentItem(pagerPosition);
    points[pagerPosition].setEnabled(true);
    pager.setOnPageChangeListener(new MyPageChangeListener());

}

From source file:com.garage.payless.fragment.FragmentList.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.list_fragment, container, false);

    DelayAutoCompleteTextView bookTitle = (DelayAutoCompleteTextView) rootView.findViewById(R.id.book_title);
    bookTitle.setThreshold(4);//w w w.  j av  a 2s  .com
    bookTitle.setAdapter(new GoodAutoCompleteAdapter(getActivity().getApplicationContext()));
    bookTitle.setLoadingIndicator((ProgressBar) rootView.findViewById(R.id.progress_bar));
    bookTitle.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
            LinearLayout basketList = (LinearLayout) rootView.findViewById(R.id.basket);
            LinearLayout row = new LinearLayout(getActivity().getApplicationContext());
            row.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT));
            row.setOrientation(LinearLayout.HORIZONTAL);
            TextView valueTV = new TextView(getActivity().getApplicationContext());
            valueTV.setText((String) adapterView.getItemAtPosition(position));
            valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT));
            row.addView(valueTV);
            ImageButton cancel = new ImageButton(getActivity().getApplicationContext());
            cancel.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT));
            cancel.setImageDrawable(Drawable.createFromPath("@android:drawable/ic_menu_close_clear_cancel"));
            row.addView(cancel);
            basketList.addView(row);
        }
    });
    rootView.findViewById(R.id.create_btn).setOnClickListener(this);
    return rootView;
}

From source file:com.shoutin.emojicons.EmojiconsView.java

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;//from ww  w  .  j a va 2  s .  c o m
    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);
        }
    });
}

From source file:org.borderstone.tagtags.widgets.BGPSWidget.java

public BGPSWidget(Context context, ColumnProperties props, int ROW, int COLUMN) {
    super(context);

    setProperties(ROW, COLUMN, props, context);
    initUI();//from  ww  w.  java 2  s . co  m

    lblCoordinates = new BInfoLabel(context);

    String data = Constants.csv.getValue(row, column);

    if (data.equals("") && props.recurring && props.lastValue != null) {
        data = props.lastValue;
        updateData(data);
    } else if (!data.equals("")) {
        hasSavedData = true;
    }

    lblCoordinates.setText(data);

    if (properties.gpsGlobal) {
        lblCoordinates.setGravity(Gravity.CENTER);
        this.addView(lblCoordinates);
    } else {
        RelativeLayout rl = new RelativeLayout(context);
        RelativeLayout.LayoutParams labelParams = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        RelativeLayout.LayoutParams buttonParams = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);

        labelParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        buttonParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);

        btnGPS = new ImageButton(context);
        btnGPS.setBackgroundResource(R.drawable.camera_button);

        btnGPS.setOnClickListener(this);
        btnGPS.setOnLongClickListener(this);

        rl.addView(lblCoordinates, labelParams);
        rl.addView(btnGPS, buttonParams);

        updateButtonDrawable();

        this.addView(rl);
    }
}

From source file:com.mishiranu.dashchan.content.service.AudioPlayerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    context = new ContextThemeWrapper(this, Preferences.getThemeResource());
    setVolumeControlStream(AudioManager.STREAM_MUSIC);
    float density = ResourceUtils.obtainDensity(this);
    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    int padding = getResources().getDimensionPixelSize(R.dimen.dialog_padding_view);
    linearLayout.setPadding(padding, padding, padding, C.API_LOLLIPOP ? (int) (8f * density) : padding);
    textView = new TextView(context, null, android.R.attr.textAppearanceListItem);
    linearLayout.addView(textView, LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    textView.setPadding(0, 0, 0, 0);/*from w  w  w . jav a  2 s .  c  om*/
    textView.setEllipsize(TextUtils.TruncateAt.END);
    textView.setSingleLine(true);
    LinearLayout horizontal = new LinearLayout(context);
    horizontal.setOrientation(LinearLayout.HORIZONTAL);
    horizontal.setGravity(Gravity.CENTER_VERTICAL);
    horizontal.setPadding(0, (int) (16f * density), 0, 0);
    linearLayout.addView(horizontal, LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    seekBar = new SeekBar(context);
    horizontal.addView(seekBar, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1));
    seekBar.setPadding((int) (8f * density), 0, (int) (16f * density), 0);
    seekBar.setOnSeekBarChangeListener(this);
    button = new ImageButton(context);
    horizontal.addView(button, (int) (48f * density), (int) (48f * density));
    button.setBackgroundResource(
            ResourceUtils.getResourceId(context, android.R.attr.listChoiceBackgroundIndicator, 0));
    setPlayState(false);
    button.setOnClickListener(this);
    alertDialog = new AlertDialog.Builder(context).setView(linearLayout).setOnCancelListener(this)
            .setPositiveButton(R.string.action_stop, this).show();
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(AudioPlayerService.ACTION_TOGGLE);
    intentFilter.addAction(AudioPlayerService.ACTION_CANCEL);
    LocalBroadcastManager.getInstance(this).registerReceiver(audioPlayerReceiver, intentFilter);
    bindService(new Intent(this, AudioPlayerService.class), this, 0);
}