Example usage for android.widget ImageView setLayoutParams

List of usage examples for android.widget ImageView setLayoutParams

Introduction

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

Prototype

public void setLayoutParams(ViewGroup.LayoutParams params) 

Source Link

Document

Set the layout parameters associated with this view.

Usage

From source file:com.hichinaschool.flashcards.anki.CardEditor.java

@Override
protected Dialog onCreateDialog(int id) {
    StyledDialog dialog = null;//from ww  w.  ja  v  a 2 s.  c  o m
    Resources res = getResources();
    StyledDialog.Builder builder = new StyledDialog.Builder(this);

    switch (id) {
    case DIALOG_TAGS_SELECT:
        builder.setTitle(R.string.card_details_tags);
        builder.setPositiveButton(res.getString(R.string.select), new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (mAddNote) {
                    try {
                        JSONArray ja = new JSONArray();
                        for (String t : selectedTags) {
                            ja.put(t);
                        }
                        mCol.getModels().current().put("tags", ja);
                        mCol.getModels().setChanged();
                    } catch (JSONException e) {
                        throw new RuntimeException(e);
                    }
                    mEditorNote.setTags(selectedTags);
                }
                mCurrentTags = selectedTags;
                updateTags();
            }
        });
        builder.setNegativeButton(res.getString(R.string.cancel), null);

        mNewTagEditText = (EditText) new EditText(this);
        mNewTagEditText.setHint(R.string.add_new_tag);

        InputFilter filter = new InputFilter() {
            public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
                    int dend) {
                for (int i = start; i < end; i++) {
                    if (source.charAt(i) == ' ' || source.charAt(i) == ',') {
                        return "";
                    }
                }
                return null;
            }
        };
        mNewTagEditText.setFilters(new InputFilter[] { filter });

        ImageView mAddTextButton = new ImageView(this);
        mAddTextButton.setImageResource(R.drawable.ic_addtag);
        mAddTextButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String tag = mNewTagEditText.getText().toString();
                if (tag.length() != 0) {
                    if (mEditorNote.hasTag(tag)) {
                        mNewTagEditText.setText("");
                        return;
                    }
                    selectedTags.add(tag);
                    actualizeTagDialog(mTagsDialog);
                    mNewTagEditText.setText("");
                }
            }
        });

        FrameLayout frame = new FrameLayout(this);
        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.RIGHT | Gravity.CENTER_VERTICAL);
        params.rightMargin = 10;
        mAddTextButton.setLayoutParams(params);
        frame.addView(mNewTagEditText);
        frame.addView(mAddTextButton);

        builder.setView(frame, false, true);
        dialog = builder.create();
        mTagsDialog = dialog;
        break;

    case DIALOG_DECK_SELECT:
        ArrayList<CharSequence> dialogDeckItems = new ArrayList<CharSequence>();
        // Use this array to know which ID is associated with each
        // Item(name)
        final ArrayList<Long> dialogDeckIds = new ArrayList<Long>();

        ArrayList<JSONObject> decks = mCol.getDecks().all();
        Collections.sort(decks, new JSONNameComparator());
        builder.setTitle(R.string.deck);
        for (JSONObject d : decks) {
            try {
                if (d.getInt("dyn") == 0) {
                    dialogDeckItems.add(d.getString("name"));
                    dialogDeckIds.add(d.getLong("id"));
                }
            } catch (JSONException e) {
                throw new RuntimeException(e);
            }
        }
        // Convert to Array
        String[] items = new String[dialogDeckItems.size()];
        dialogDeckItems.toArray(items);

        builder.setItems(items, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int item) {
                long newId = dialogDeckIds.get(item);
                if (mCurrentDid != newId) {
                    if (mAddNote) {
                        try {
                            // TODO: mEditorNote.setDid(newId);
                            mEditorNote.model().put("did", newId);
                            mCol.getModels().setChanged();
                        } catch (JSONException e) {
                            throw new RuntimeException(e);
                        }
                    }
                    mCurrentDid = newId;
                    updateDeck();
                }
            }
        });

        dialog = builder.create();
        mDeckSelectDialog = dialog;
        break;

    case DIALOG_MODEL_SELECT:
        ArrayList<CharSequence> dialogItems = new ArrayList<CharSequence>();
        // Use this array to know which ID is associated with each
        // Item(name)
        final ArrayList<Long> dialogIds = new ArrayList<Long>();

        ArrayList<JSONObject> models = mCol.getModels().all();
        Collections.sort(models, new JSONNameComparator());
        builder.setTitle(R.string.note_type);
        for (JSONObject m : models) {
            try {
                dialogItems.add(m.getString("name"));
                dialogIds.add(m.getLong("id"));
            } catch (JSONException e) {
                throw new RuntimeException(e);
            }
        }
        // Convert to Array
        String[] items2 = new String[dialogItems.size()];
        dialogItems.toArray(items2);

        builder.setItems(items2, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int item) {
                long oldModelId;
                try {
                    oldModelId = mCol.getModels().current().getLong("id");
                } catch (JSONException e) {
                    throw new RuntimeException(e);
                }
                long newId = dialogIds.get(item);
                if (oldModelId != newId) {
                    mCol.getModels().setCurrent(mCol.getModels().get(newId));
                    JSONObject cdeck = mCol.getDecks().current();
                    try {
                        cdeck.put("mid", newId);
                    } catch (JSONException e) {
                        throw new RuntimeException(e);
                    }
                    mCol.getDecks().save(cdeck);
                    int size = mEditFields.size();
                    String[] oldValues = new String[size];
                    for (int i = 0; i < size; i++) {
                        oldValues[i] = mEditFields.get(i).getText().toString();
                    }
                    setNote();
                    resetEditFields(oldValues);
                    mTimerHandler.removeCallbacks(checkDuplicatesRunnable);
                    duplicateCheck(false);
                }
            }
        });
        dialog = builder.create();
        break;

    case DIALOG_RESET_CARD:
        builder.setTitle(res.getString(R.string.reset_card_dialog_title));
        builder.setMessage(res.getString(R.string.reset_card_dialog_message));
        builder.setPositiveButton(res.getString(R.string.yes), new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                // for (long cardId :
                // mDeck.getCardsFromFactId(mEditorNote.getId())) {
                // mDeck.cardFromId(cardId).resetCard();
                // }
                // mDeck.reset();
                // setResult(Reviewer.RESULT_EDIT_CARD_RESET);
                // mCardReset = true;
                // Themes.showThemedToast(CardEditor.this,
                // getResources().getString(
                // R.string.reset_card_dialog_confirmation), true);
            }
        });
        builder.setNegativeButton(res.getString(R.string.no), null);
        builder.setCancelable(true);
        dialog = builder.create();
        break;

    case DIALOG_INTENT_INFORMATION:
        dialog = createDialogIntentInformation(builder, res);
    }

    return dialog;
}

From source file:com.aapbd.utils.image.CacheImageDownloader.java

private void scaleImage1(ImageView view) {
    // Get the ImageView and its bitmap

    final Drawable drawing = view.getDrawable();
    if (drawing == null) {
        return; // Checking for null & return, as suggested in comments
    }/*from   www  .j  ava  2s  .com*/
    final Bitmap bitmap = ((BitmapDrawable) drawing).getBitmap();

    // Get current dimensions AND the desired bounding box
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    final int bounding = dpToPx(view.getContext(), 300);
    Log.i("Test", "original width = " + Integer.toString(width));
    Log.i("Test", "original height = " + Integer.toString(height));
    Log.i("Test", "bounding = " + Integer.toString(bounding));

    // Determine how much to scale: the dimension requiring less scaling is
    // closer to the its side. This way the image always stays inside your
    // bounding box AND either x/y axis touches it.
    final float xScale = ((float) bounding) / width;
    final float yScale = ((float) bounding) / height;
    final float scale = (xScale <= yScale) ? xScale : yScale;
    Log.i("Test", "xScale = " + Float.toString(xScale));
    Log.i("Test", "yScale = " + Float.toString(yScale));
    Log.i("Test", "scale = " + Float.toString(scale));

    // Create a matrix for the scaling and add the scaling data
    final Matrix matrix = new Matrix();
    matrix.postScale(scale, scale);

    // Create a new bitmap and convert it to a format understood by the
    // ImageView
    final Bitmap scaledBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
    width = scaledBitmap.getWidth(); // re-use
    height = scaledBitmap.getHeight(); // re-use
    final BitmapDrawable result = new BitmapDrawable(scaledBitmap);
    Log.i("Test", "scaled width = " + Integer.toString(width));
    Log.i("Test", "scaled height = " + Integer.toString(height));

    // Apply the scaled bitmap
    view.setImageDrawable(result);

    // Now change ImageView's dimensions to match the scaled image
    final LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) view.getLayoutParams();
    params.width = width;
    params.height = height;
    view.setLayoutParams(params);

    Log.i("Test", "done");
}

From source file:im.neon.adapters.VectorMessagesAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View view = super.getView(position, convertView, parent);

    if (null != view) {
        view.setBackgroundColor(Color.TRANSPARENT);
    }//w  w w . j  a va2  s.  c om

    ImageView e2eIconView = (ImageView) view.findViewById(R.id.message_adapter_e2e_icon);
    View senderMargin = view.findViewById(R.id.e2e_sender_margin);
    View senderNameView = view.findViewById(R.id.messagesAdapter_sender);

    // GA issue
    if (position >= getCount()) {
        return view;
    }

    MessageRow row = getItem(position);
    final Event event = row.getEvent();

    if (mE2eIconByEventId.containsKey(event.eventId)) {
        senderMargin.setVisibility(senderNameView.getVisibility());
        e2eIconView.setVisibility(View.VISIBLE);
        e2eIconView.setImageResource(mE2eIconByEventId.get(event.eventId));

        int type = getItemViewType(position);

        if ((type == ROW_TYPE_IMAGE) || (type == ROW_TYPE_VIDEO)) {
            View bodyLayoutView = view.findViewById(org.matrix.androidsdk.R.id.messagesAdapter_body_layout);
            ViewGroup.MarginLayoutParams bodyLayout = (ViewGroup.MarginLayoutParams) bodyLayoutView
                    .getLayoutParams();
            ViewGroup.MarginLayoutParams e2eIconViewLayout = (ViewGroup.MarginLayoutParams) e2eIconView
                    .getLayoutParams();

            e2eIconViewLayout.setMargins(bodyLayout.leftMargin, e2eIconViewLayout.topMargin,
                    e2eIconViewLayout.rightMargin, e2eIconViewLayout.bottomMargin);
            bodyLayout.setMargins(4, bodyLayout.topMargin, bodyLayout.rightMargin, bodyLayout.bottomMargin);
            e2eIconView.setLayoutParams(e2eIconViewLayout);
            bodyLayoutView.setLayoutParams(bodyLayout);
        }

        e2eIconView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != mVectorMessagesAdapterEventsListener) {
                    mVectorMessagesAdapterEventsListener.onE2eIconClick(event,
                            mE2eDeviceByEventId.get(event.eventId));
                }
            }
        });
    } else {
        e2eIconView.setVisibility(View.GONE);
        senderMargin.setVisibility(View.GONE);
    }

    return view;
}

From source file:com.htc.dotdesign.ToolBoxService.java

private void setSelectedColor(ImageView button) {
    Drawable select = getResources().getDrawable(R.drawable.dot_design_select);
    select.setColorFilter(getResources().getColor(R.color.overlay_color), Mode.SRC_IN);

    ImageView selectedIcon = (ImageView) mPalette.findViewById(R.id.selected);
    selectedIcon.setBackground(select);//w  ww  .ja v a 2s.co m

    Resources res = getResources();
    int id = button.getId();
    int buttonLeft = button.getLeft();
    int buttonTop = button.getTop();
    int m1 = res.getDimensionPixelSize(R.dimen.margin_l);
    int m2 = res.getDimensionPixelSize(R.dimen.margin_m);
    int colorSize = res.getDimensionPixelSize(R.dimen.hv01);
    if (id == R.id.btn_color_11 || id == R.id.btn_color_12 || id == R.id.btn_color_13
            || id == R.id.btn_color_14) {
        buttonTop = m2;
    } else if (id == R.id.btn_color_21 || id == R.id.btn_color_22 || id == R.id.btn_color_23
            || id == R.id.btn_color_24) {
        buttonTop = m2 + colorSize + m1;
    } else {
        buttonTop = m2 + 2 * colorSize + 2 * m1;
    }

    if (id == R.id.btn_color_11 || id == R.id.btn_color_21 || id == R.id.btn_color_31) {
        buttonLeft = m2;
    } else if (id == R.id.btn_color_12 || id == R.id.btn_color_22 || id == R.id.btn_color_32) {
        buttonLeft = 3 * m2 + colorSize;
    } else if (id == R.id.btn_color_13 || id == R.id.btn_color_23 || id == R.id.btn_color_33) {
        buttonLeft = 5 * m2 + 2 * colorSize;
    } else {
        buttonLeft = 7 * m2 + 3 * colorSize;
    }

    int widthDiff = res.getDimensionPixelSize(R.dimen.select_color_width) - colorSize;
    int heightDiff = res.getDimensionPixelSize(R.dimen.select_color_height) - colorSize;
    int marginLeft = buttonLeft - (widthDiff / 2);
    int marginTop = buttonTop - (heightDiff / 2);

    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) selectedIcon.getLayoutParams();
    params.setMargins(marginLeft, marginTop, 0, 0);
    selectedIcon.setLayoutParams(params);
    selectedIcon.setVisibility(View.VISIBLE);
}

From source file:com.wallerlab.compcellscope.Image_Gallery.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_image__gallery);
    counter = 0;/*from   w ww  .  j  a v a  2s. c o  m*/
    final ImageView currPic = new ImageView(this);

    DisplayMetrics metrics = this.getResources().getDisplayMetrics();
    final int screen_width = metrics.widthPixels;

    SharedPreferences settings = getSharedPreferences(Folder_Chooser.PREFS_NAME, 0);
    //SharedPreferences.Editor edit = settings.edit();
    String path = settings.getString(Folder_Chooser.location_name,
            Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString());

    //Log.d(LOG, "  |  " + path + " |  ");
    TextView text1 = (TextView) findViewById(R.id.text1);
    final TextView text2 = (TextView) findViewById(R.id.text2);

    text1.setText(path);

    File directory = new File(path);

    // get all the files from a directory
    File[] dump_files = directory.listFiles();
    Log.d(LOG, dump_files.length + " ");

    final File[] fList = removeElements(dump_files, "info.json");

    Log.d(LOG, "Filtered Length: " + fList.length);

    Arrays.sort(fList, new Comparator<File>() {
        @Override
        public int compare(File file, File file2) {
            String one = file.toString();
            String two = file2.toString();
            //Log.d(LOG, "one: " + one);
            //Log.d(LOG, "two: " + two);
            int num_one = Integer.parseInt(one.substring(one.lastIndexOf("(") + 1, one.lastIndexOf(")")));
            int num_two = Integer.parseInt(two.substring(two.lastIndexOf("(") + 1, two.lastIndexOf(")")));
            return num_one - num_two;
        }
    });

    try {
        writeJsonFile(fList);
    } catch (JSONException e) {
        Log.d(LOG, "JSON WRITE FAILED");
    }
    //List names programattically
    LinearLayout myLinearLayout = (LinearLayout) findViewById(R.id.linear_table);
    final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, screen_width + 4);

    myLinearLayout.setOrientation(LinearLayout.VERTICAL);

    if (fList != null) {
        File cur_pic = fList[0];

        BitmapFactory.Options opts = new BitmapFactory.Options();
        Log.d(LOG, "\n File Location: " + cur_pic.getAbsolutePath() + " \n" + " Parent: "
                + cur_pic.getParent().toString() + "\n");

        Bitmap myImage = BitmapFactory.decodeFile(cur_pic.getAbsolutePath(), opts);

        currPic.setLayoutParams(params);
        currPic.setImageBitmap(myImage);
        currPic.setId(View.generateViewId());
        text2.setText(cur_pic.getName());
    }

    myLinearLayout.addView(currPic);

    //Seekbar
    seekBar = (SeekBar) findViewById(R.id.seekBar);
    seekBar.setEnabled(true);
    seekBar.setMax(fList.length - 1);
    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        int progress = 0;
        int length = fList.length;

        @Override
        public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
            setCounter(i);
            if (getCounter() <= fList.length) {
                File cur_pic = fList[getCounter()];
                BitmapFactory.Options opts = new BitmapFactory.Options();
                opts.inJustDecodeBounds = true;
                Bitmap myImage = BitmapFactory.decodeFile(cur_pic.getAbsolutePath(), opts);
                int image_width = opts.outWidth;
                int image_height = opts.outHeight;
                int sampleSize = image_width / screen_width;
                opts.inSampleSize = sampleSize;

                text2.setText(cur_pic.getName());

                opts.inJustDecodeBounds = false;
                myImage = BitmapFactory.decodeFile(cur_pic.getAbsolutePath(), opts);

                currPic.setImageBitmap(myImage);
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });

    //Make Button Layout
    LinearLayout buttonLayout = new LinearLayout(this);
    buttonLayout.setOrientation(LinearLayout.HORIZONTAL);

    LinearLayout.LayoutParams LLParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT, 1.0f);
    buttonLayout.setLayoutParams(LLParams);
    buttonLayout.setId(View.generateViewId());

    //Button Layout Params
    LinearLayout.LayoutParams param_button = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT, 1.0f);

    //Prev Pic
    Button prevPic = new Button(this);
    prevPic.setText("Previous");
    prevPic.setId(View.generateViewId());
    prevPic.setLayoutParams(param_button);

    prevPic.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (fList != null) {
                decrementCounter();
                if (getCounter() >= 0) {
                    File cur_pic = fList[getCounter()];
                    BitmapFactory.Options opts = new BitmapFactory.Options();
                    opts.inJustDecodeBounds = true;
                    Bitmap myImage = BitmapFactory.decodeFile(cur_pic.getAbsolutePath(), opts);
                    int image_width = opts.outWidth;
                    int image_height = opts.outHeight;
                    int sampleSize = image_width / screen_width;
                    opts.inSampleSize = sampleSize;

                    text2.setText(cur_pic.getName());

                    opts.inJustDecodeBounds = false;
                    myImage = BitmapFactory.decodeFile(cur_pic.getAbsolutePath(), opts);
                    //Log.d(LOG, getCounter() + "");
                    seekBar.setProgress(getCounter());
                    currPic.setImageBitmap(myImage);

                } else {
                    setCounter(0);
                }

            } else {
                Toast.makeText(Image_Gallery.this, "There are no pictures in this folder", Toast.LENGTH_SHORT);
                setCounter(getCounter() - 1);
            }
        }
    });

    buttonLayout.addView(prevPic);

    // Next Picture  Button
    Button nextPic = new Button(this);
    nextPic.setText("Next");
    nextPic.setId(View.generateViewId());
    nextPic.setLayoutParams(param_button);

    buttonLayout.addView(nextPic);
    nextPic.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (fList != null) {
                incrementCounter();
                if (getCounter() < fList.length) {
                    File cur_pic = fList[getCounter()];
                    BitmapFactory.Options opts = new BitmapFactory.Options();
                    opts.inJustDecodeBounds = true;
                    Bitmap myImage = BitmapFactory.decodeFile(cur_pic.getAbsolutePath(), opts);
                    int image_width = opts.outWidth;
                    int image_height = opts.outHeight;
                    int sampleSize = image_width / screen_width;
                    opts.inSampleSize = sampleSize;

                    text2.setText(cur_pic.getName());

                    opts.inJustDecodeBounds = false;
                    myImage = BitmapFactory.decodeFile(cur_pic.getAbsolutePath(), opts);
                    //Log.d(LOG, getCounter() + "");
                    seekBar.setProgress(getCounter());

                    currPic.setImageBitmap(myImage);
                } else {
                    setCounter(getCounter() - 1);
                }

            } else {
                Toast.makeText(Image_Gallery.this, "There are no pictures in this folder", Toast.LENGTH_SHORT);
                setCounter(getCounter() - 1);
            }
        }
    });

    myLinearLayout.addView(buttonLayout);
}

From source file:com.haomee.chat.activity.ChatActivity.java

/**
 * ?//  w  ww  .j  a va 2  s .  c  om
 */

public void add_points(int total_number, View container) {
    // ?ViewGroup
    tips_anim_emoji = new ImageView[total_number];
    Map<String, ImageView[]> map = new HashMap<String, ImageView[]>();
    for (int i = 0; i < tips_anim_emoji.length; i++) {
        ImageView imageView = new ImageView(ChatActivity.this);
        LinearLayout.LayoutParams layout = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        layout.setMargins(10, 0, 10, 0);
        imageView.setTag(tab_emotions_tag);
        imageView.setLayoutParams(layout);
        tips_anim_emoji[i] = imageView;
        if (i == 0) {
            tips_anim_emoji[i].setBackgroundResource(R.drawable.dot);
        } else {
            tips_anim_emoji[i].setBackgroundResource(R.drawable.dot_normal);
        }

        ((LinearLayout) container).setGravity(Gravity.CENTER);
        ((ViewGroup) container).addView(imageView);
    }
}

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

public void bbar(final Main main) {
    final String text = main.CURRENT_PATH;
    try {/*from  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.filemanager.activities.MainActivity.java

public void bbar(final Main main) {
    final String text = main.CURRENT_PATH;
    try {// ww w.  jav  a2s.c  o m
        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.haomee.chat.activity.ChatActivity.java

/**
 * // w  ww  .ja  v  a  2 s  . co  m
 */
private void init_new_emotions(final String path) {
    File file = new File(emotions_base_path);
    File[] files = file.listFiles();// ?
    for (File f : files) {
        if (path == null) {
            return;
        }
        if (f == null) {
            return;
        }
        if (!file.exists() || !file.isDirectory()) {
            return;
        }
        // if (f.listFiles().length == 0) {
        // return;
        // }
        if (path.equals(f.getName())) {// ??
            File[] file_image_list = f.listFiles();
            image_path = new ArrayList<String>();
            image_name = new ArrayList<String>();
            if (file_image_list == null) {
                return;
            }
            for (int j = 0; j < file_image_list.length; j++) {
                File file_image = file_image_list[j];
                try {
                    String newFileName = new String(file_image.getName().getBytes(), "UTF-8");
                    if (newFileName.contains(big_cover_name) || newFileName.contains(simall_cover_name)) {
                        // 
                        final ImageView iv_bottom_emotion = new ImageView(ChatActivity.this);
                        Bitmap decodeFile = BitmapFactory.decodeFile(file_image.getAbsolutePath());
                        iv_bottom_emotion.setImageBitmap(decodeFile);
                        int screen_width = ViewUtil.getScreenWidth(ChatActivity.this);
                        layoutParams.width = screen_width / 8;
                        layoutParams.height = screen_width / 8;
                        iv_bottom_emotion.setLayoutParams(layoutParams);
                        iv_bottom_emotion.setBackgroundResource(R.drawable.grid_line);
                        iv_bottom_emotion.setTag(path);
                        // imag_list.add(iv_bottom_emotion);
                        imag_list.add(0, iv_bottom_emotion);
                        iv_bottom_emotion.setOnClickListener(new OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                // TODO Auto-generated method stub
                                selected_pager = (String) iv_bottom_emotion.getTag();
                                iv_expression_emoji.setBackgroundResource(R.drawable.grid_line);
                                for (ImageView iv : imag_list) {
                                    if (selected_pager.equals(iv.getTag())) {
                                        iv.setBackgroundResource(R.drawable.grid_line_press);
                                    } else {
                                        iv.setBackgroundResource(R.drawable.grid_line);
                                    }
                                }
                                search_selected_emotions((String) iv_bottom_emotion.getTag());
                            }
                        });

                        ll_emotions_content.addView(iv_bottom_emotion);
                        viewpager.setTag(tab_emotions_tag);// ?
                    }
                } catch (UnsupportedEncodingException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            }

        }
    }
}

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

public void bbar(final MainFragment mainFrag) {
    final String path = mainFrag.CURRENT_PATH;
    try {//from   ww w.  ja v a2s .c om
        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");
    }
}