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:im.ene.lab.toro.ext.layeredvideo.PlaybackControlLayer.java

/**
 * The action buttons are displayed in the top right of the video player. If the player is in
 * portrait mode, then display an overflow button which displays a dialog window containing the
 * possible actions. If the player is in landscape, then display the images for the actions in
 * the/*w  w w  .  j a v  a 2  s .  c o m*/
 * top right of the video player.
 */
public void updateActionButtons() {
    actionButtonsContainer.removeAllViews();

    if (isFullscreen) {
        for (ImageButton imageButton : actionButtons) {
            actionButtonsContainer.addView(imageButton);
        }
    } else {
        ImageButton overflowButton = new ImageButton(layerManager.getContainer().getContext());
        overflowButton.setContentDescription(layerManager.getActivity().getString(R.string.overflow));
        overflowButton.setImageDrawable(ContextCompat.getDrawable(layerManager.getContainer().getContext(),
                R.drawable.ic_action_overflow));

        AlertDialog.Builder builder = new AlertDialog.Builder(layerManager.getActivity());
        builder.setTitle(layerManager.getActivity().getString(R.string.select_an_action));
        final CharSequence[] actions = new CharSequence[actionButtons.size()];
        for (int i = 0; i < actionButtons.size(); i++) {
            actions[i] = actionButtons.get(i).getContentDescription();
        }
        builder.setItems(actions, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                actionButtons.get(i).performClick();
            }
        });

        final AlertDialog alertDialog = builder.create();

        overflowButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                alertDialog.show();
            }
        });

        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        // 5dp
        int margin = 5 * layerManager.getActivity().getResources().getDisplayMetrics().densityDpi;
        layoutParams.setMargins(margin, 0, margin, 0);

        overflowButton.setBackgroundColor(Color.TRANSPARENT);
        overflowButton.setLayoutParams(layoutParams);
        overflowButton.setColorFilter(controlColor);
        actionButtonsContainer.addView(overflowButton);
    }
}

From source file:com.amaze.filemanager.activities.MainActivity.java

public void bbar(final Main main) {
    final String text = main.CURRENT_PATH;
    try {//from  w  w w  . java  2 s.  c  om
        buttons.removeAllViews();
        buttons.setMinimumHeight(pathbar.getHeight());
        Drawable arrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_holo_dark);
        Bundle b = utils.getPaths(text, this);
        ArrayList<String> names = b.getStringArrayList("names");
        ArrayList<String> rnames = new ArrayList<String>();

        for (int i = names.size() - 1; i >= 0; i--) {
            rnames.add(names.get(i));
        }

        ArrayList<String> paths = b.getStringArrayList("paths");
        final ArrayList<String> rpaths = new ArrayList<String>();

        for (int i = paths.size() - 1; i >= 0; i--) {
            rpaths.add(paths.get(i));
        }
        View view = new View(this);
        LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(toolbar.getContentInsetLeft(),
                LinearLayout.LayoutParams.WRAP_CONTENT);
        view.setLayoutParams(params1);
        buttons.addView(view);
        for (int i = 0; i < names.size(); i++) {
            final int k = i;
            ImageView v = new ImageView(this);
            v.setImageDrawable(arrow);
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            params.gravity = Gravity.CENTER_VERTICAL;
            v.setLayoutParams(params);
            final int index = i;
            if (rpaths.get(i).equals("/")) {
                ImageButton ib = new ImageButton(this);
                ib.setImageDrawable(icons.getRootDrawable());
                ib.setBackgroundColor(Color.parseColor("#00ffffff"));
                ib.setOnClickListener(new View.OnClickListener() {

                    public void onClick(View p1) {
                        main.loadlist(("/"), false, main.openMode);
                        timer.cancel();
                        timer.start();
                    }
                });
                ib.setLayoutParams(params);
                buttons.addView(ib);
                if (names.size() - i != 1)
                    buttons.addView(v);
            } else if (isStorage(rpaths.get(i))) {
                ImageButton ib = new ImageButton(this);
                ib.setImageDrawable(icons.getSdDrawable());
                ib.setBackgroundColor(Color.parseColor("#00ffffff"));
                ib.setOnClickListener(new View.OnClickListener() {

                    public void onClick(View p1) {
                        main.loadlist((rpaths.get(k)), false, main.openMode);
                        timer.cancel();
                        timer.start();
                    }
                });
                ib.setLayoutParams(params);
                buttons.addView(ib);
                if (names.size() - i != 1)
                    buttons.addView(v);
            } else {
                Button button = new Button(this);
                button.setText(rnames.get(index));
                button.setTextColor(getResources().getColor(android.R.color.white));
                button.setTextSize(13);
                button.setLayoutParams(params);
                button.setBackgroundResource(0);
                button.setOnClickListener(new Button.OnClickListener() {

                    public void onClick(View p1) {
                        main.loadlist((rpaths.get(k)), false, main.openMode);
                        main.loadlist((rpaths.get(k)), false, main.openMode);
                        timer.cancel();
                        timer.start();
                    }
                });
                button.setOnLongClickListener(new View.OnLongClickListener() {
                    @Override
                    public boolean onLongClick(View view) {

                        File file1 = new File(rpaths.get(index));
                        copyToClipboard(MainActivity.this, file1.getPath());
                        Toast.makeText(MainActivity.this, getResources().getString(R.string.pathcopied),
                                Toast.LENGTH_SHORT).show();
                        return false;
                    }
                });

                buttons.addView(button);
                if (names.size() - i != 1)
                    buttons.addView(v);
            }
        }

        scroll.post(new Runnable() {
            @Override
            public void run() {
                sendScroll(scroll);
                sendScroll(scroll1);
            }
        });

        if (buttons.getVisibility() == View.VISIBLE) {
            timer.cancel();
            timer.start();
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("button view not available");
    }
}

From source file:com.filemanager.free.activities.MainActivity.java

public void bbar(final Main main) {
    final String text = main.CURRENT_PATH;
    try {/* w  w w.ja va 2  s  . c o  m*/
        buttons.removeAllViews();
        buttons.setMinimumHeight(pathbar.getHeight());
        Drawable arrow = ContextCompat.getDrawable(con, R.drawable.abc_ic_ab_back_holo_dark);
        Bundle b = utils.getPaths(text, this);
        ArrayList<String> names = b.getStringArrayList("names");
        ArrayList<String> rnames = new ArrayList<String>();

        assert names != null;
        for (int i = names.size() - 1; i >= 0; i--) {
            rnames.add(names.get(i));
        }

        ArrayList<String> paths = b.getStringArrayList("paths");
        final ArrayList<String> rpaths = new ArrayList<String>();

        assert paths != null;
        for (int i = paths.size() - 1; i >= 0; i--) {
            rpaths.add(paths.get(i));
        }
        View view = new View(this);
        LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(toolbar.getContentInsetLeft(),
                LinearLayout.LayoutParams.WRAP_CONTENT);
        view.setLayoutParams(params1);
        buttons.addView(view);
        for (int i = 0; i < names.size(); i++) {
            final int k = i;
            ImageView v = new ImageView(this);
            v.setImageDrawable(arrow);
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            params.gravity = Gravity.CENTER_VERTICAL;
            v.setLayoutParams(params);
            final int index = i;
            if (rpaths.get(i).equals("/")) {
                ImageButton ib = new ImageButton(this);
                ib.setImageDrawable(icons.getRootDrawable());
                ib.setBackgroundColor(Color.parseColor("#00ffffff"));
                ib.setOnClickListener(new View.OnClickListener() {

                    public void onClick(View p1) {
                        main.loadlist(("/"), false, main.openMode);
                        timer.cancel();
                        timer.start();
                    }
                });
                ib.setLayoutParams(params);
                buttons.addView(ib);
                if (names.size() - i != 1)
                    buttons.addView(v);
            } else if (isStorage(rpaths.get(i))) {
                ImageButton ib = new ImageButton(this);
                ib.setImageDrawable(icons.getSdDrawable());
                ib.setBackgroundColor(Color.parseColor("#00ffffff"));
                ib.setOnClickListener(new View.OnClickListener() {

                    public void onClick(View p1) {
                        main.loadlist((rpaths.get(k)), false, main.openMode);
                        timer.cancel();
                        timer.start();
                    }
                });
                ib.setLayoutParams(params);
                buttons.addView(ib);
                if (names.size() - i != 1)
                    buttons.addView(v);
            } else {
                Button button = new Button(this);
                button.setText(rnames.get(index));
                button.setTextColor(ContextCompat.getColor(con, android.R.color.white));
                button.setTextSize(13);
                button.setLayoutParams(params);
                button.setBackgroundResource(0);
                button.setOnClickListener(new Button.OnClickListener() {

                    public void onClick(View p1) {
                        main.loadlist((rpaths.get(k)), false, main.openMode);
                        main.loadlist((rpaths.get(k)), false, main.openMode);
                        timer.cancel();
                        timer.start();
                    }
                });
                button.setOnLongClickListener(new View.OnLongClickListener() {
                    @Override
                    public boolean onLongClick(View view) {
                        File file1 = new File(rpaths.get(index));
                        copyToClipboard(MainActivity.this, file1.getPath());
                        Toast.makeText(MainActivity.this, getResources().getString(R.string.pathcopied),
                                Toast.LENGTH_SHORT).show();
                        return false;
                    }
                });

                buttons.addView(button);
                if (names.size() - i != 1)
                    buttons.addView(v);
            }
        }

        scroll.post(new Runnable() {
            @Override
            public void run() {
                sendScroll(scroll);
                sendScroll(scroll1);
            }
        });

        if (buttons.getVisibility() == View.VISIBLE) {
            timer.cancel();
            timer.start();
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("button view not available");
    }
}

From source file:com.amaze.carbonfilemanager.activities.MainActivity.java

public void bbar(final MainFragment mainFrag) {
    final String path = mainFrag.CURRENT_PATH;
    try {//from   w ww.  j a  v  a2  s.c  o  m
        buttons.removeAllViews();
        buttons.setMinimumHeight(pathbar.getHeight());
        Drawable arrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_holo_dark);
        Bundle bundle = utils.getPaths(path, this);
        ArrayList<String> names = bundle.getStringArrayList("names");
        ArrayList<String> rnames = bundle.getStringArrayList("names");
        Collections.reverse(rnames);

        ArrayList<String> paths = bundle.getStringArrayList("paths");
        final ArrayList<String> rpaths = bundle.getStringArrayList("paths");
        Collections.reverse(rpaths);

        View view = new View(this);
        LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(toolbar.getContentInsetLeft(),
                LinearLayout.LayoutParams.WRAP_CONTENT);
        view.setLayoutParams(params1);
        buttons.addView(view);
        for (int i = 0; i < names.size(); i++) {
            final int k = i;
            ImageView v = new ImageView(this);
            v.setImageDrawable(arrow);
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            params.gravity = Gravity.CENTER_VERTICAL;
            v.setLayoutParams(params);
            final int index = i;
            if (rpaths.get(i).equals("/")) {
                ImageButton ib = new ImageButton(this);
                ib.setImageDrawable(icons.getRootDrawable());
                ib.setBackgroundColor(Color.TRANSPARENT);
                ib.setOnClickListener(new View.OnClickListener() {

                    public void onClick(View p1) {
                        mainFrag.loadlist(("/"), false, mainFrag.openMode);
                        timer.cancel();
                        timer.start();
                    }
                });
                ib.setLayoutParams(params);
                buttons.addView(ib);
                if (names.size() - i != 1)
                    buttons.addView(v);
            } else if (isStorage(rpaths.get(i))) {
                ImageButton ib = new ImageButton(this);
                ib.setImageDrawable(icons.getSdDrawable());
                ib.setBackgroundColor(Color.TRANSPARENT);
                ib.setOnClickListener(new View.OnClickListener() {

                    public void onClick(View p1) {
                        mainFrag.loadlist((rpaths.get(k)), false, mainFrag.openMode);
                        timer.cancel();
                        timer.start();
                    }
                });
                ib.setLayoutParams(params);
                buttons.addView(ib);
                if (names.size() - i != 1)
                    buttons.addView(v);
            } else {
                Button b = new Button(this);
                b.setText(rnames.get(index));
                b.setTextColor(Utils.getColor(this, android.R.color.white));
                b.setTextSize(13);
                b.setLayoutParams(params);
                b.setBackgroundResource(0);
                b.setOnClickListener(new Button.OnClickListener() {

                    public void onClick(View p1) {
                        mainFrag.loadlist((rpaths.get(k)), false, mainFrag.openMode);
                        mainFrag.loadlist((rpaths.get(k)), false, mainFrag.openMode);
                        timer.cancel();
                        timer.start();
                    }
                });
                b.setOnLongClickListener(new View.OnLongClickListener() {
                    @Override
                    public boolean onLongClick(View view) {

                        File file1 = new File(rpaths.get(index));
                        copyToClipboard(MainActivity.this, file1.getPath());
                        Toast.makeText(MainActivity.this, getResources().getString(R.string.pathcopied),
                                Toast.LENGTH_SHORT).show();
                        return false;
                    }
                });

                buttons.addView(b);
                if (names.size() - i != 1)
                    buttons.addView(v);
            }
        }

        scroll.post(new Runnable() {
            @Override
            public void run() {
                sendScroll(scroll);
                sendScroll(scroll1);
            }
        });

        if (buttons.getVisibility() == View.VISIBLE) {
            timer.cancel();
            timer.start();
        }
    } catch (Exception e) {
        e.printStackTrace();
        Log.d("BBar", "button view not available");
    }
}

From source file:com.skytree.epubtest.BookViewActivity.java

public ImageButton makeImageButton(int id, int resId, int width, int height) {
    RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); // width,height
    Drawable icon;/*w w  w  .  j  av a  2 s . c  om*/
    ImageButton button = new ImageButton(this);
    button.setAdjustViewBounds(true);
    button.setId(id);
    button.setOnClickListener(listener);
    button.setBackgroundColor(Color.TRANSPARENT);
    icon = 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);
    param.width = (int) (width);
    param.height = (int) (height);
    button.setLayoutParams(param);
    return button;
}