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:org.gots.seed.view.SeedWidgetLong.java

@SuppressWarnings("deprecation")
private void setupView() {

    if (mSeed == null)
        return;//from  w w  w  .  j  a v a2s .com

    int familyImageRessource = 0;
    if (mSeed.getFamily() != null)
        familyImageRessource = getResources()
                .getIdentifier("org.gots:drawable/family_" + mSeed.getFamily().toLowerCase(), null, null);

    if (familyImageRessource != 0)
        setBackgroundResource(familyImageRessource);
    else {
        int sdk = android.os.Build.VERSION.SDK_INT;
        if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
            setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.family_unknown));
        } else {
            setBackground(mContext.getResources().getDrawable(R.drawable.family_unknown));
        }
    }

    SeedWidget seedWidget = (SeedWidget) findViewById(R.id.idSeedWidget2);
    seedWidget.setSeed(mSeed);

    TextView seedSpecie = (TextView) findViewById(R.id.IdSeedSpecie);
    seedSpecie.setText(SeedUtil.translateSpecie(mContext, mSeed));
    if (GotsPreferences.DEBUG)
        seedSpecie.setText("(" + mSeed.getSeedId() + ")" + SeedUtil.translateSpecie(mContext, mSeed));

    TextView seedVariety = (TextView) findViewById(R.id.IdSeedVariety);
    seedVariety.setText(mSeed.getVariety());

    PlanningWidget planningSow = (PlanningWidget) findViewById(R.id.IdSeedSowingPlanning);
    planningSow.setAdapter(new PlanningSowAdapter(mSeed));
    //
    PlanningWidget planningHarvest = (PlanningWidget) findViewById(R.id.IdSeedHarvestPlanning);
    planningHarvest.setAdapter(new PlanningHarvestAdapter(mSeed));

    LinearLayout stock = (LinearLayout) findViewById(R.id.idSeedStock);
    stock.removeAllViews();
    for (int i = 0; i < mSeed.getNbSachet(); i++) {
        ImageView seedbag = new ImageView(mContext);
        seedbag.setImageDrawable(mContext.getResources().getDrawable(R.drawable.seed_bag));
        // seedbag.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.bg_planning_sow));

        LayoutParams params = new LinearLayout.LayoutParams(30, 30);
        seedbag.setLayoutParams(params);
        stock.addView(seedbag, i);
    }

    if (mSeed.getLanguage() != null && !"".equals(mSeed.getLanguage())) {
        ImageView flag = (ImageView) findViewById(R.id.IdSeedLanguage);
        int flagRessource = getResources()
                .getIdentifier("org.gots:drawable/" + mSeed.getLanguage().toLowerCase(), null, null);
        flag.setImageResource(flagRessource);
    }

    likeCount = (TextView) findViewById(R.id.textSeedLike);
    like = (ImageView) findViewById(R.id.ImageSeedLike);

    displayLikeStatus(mSeed.getLikeStatus());
    if (mSeed.getUUID() == null)
        like.setVisibility(View.GONE);

    like.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            new AsyncTask<Void, Void, LikeStatus>() {
                GotsException exception = null;

                @Override
                protected LikeStatus doInBackground(Void... params) {
                    GotsSeedManager manager = GotsSeedManager.getInstance().initIfNew(mContext);
                    try {
                        return manager.like(mSeed, mSeed.getLikeStatus().getUserLikeStatus() == 1);
                    } catch (GotsException e) {
                        exception = e;
                        return null;
                    } catch (Exception e) {
                        Log.e(getClass().getName(), "" + e.getMessage(), e);
                        return null;
                    }
                }

                protected void onPostExecute(LikeStatus result) {
                    if (result == null && exception != null) {
                        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mContext);

                        // set title
                        alertDialogBuilder.setTitle(exception.getMessage());
                        alertDialogBuilder.setMessage(exception.getMessageDescription()).setCancelable(false)
                                .setPositiveButton(mContext.getResources().getString(R.string.login_connect),
                                        new DialogInterface.OnClickListener() {
                                            public void onClick(DialogInterface dialog, int id) {
                                                // Intent loginIntent = new Intent(mContext, LoginDialogFragment.class);
                                                // mContext.startActivity(loginIntent);
                                                LoginDialogFragment dialogFragment = new LoginDialogFragment();
                                                dialogFragment.setStyle(DialogFragment.STYLE_NORMAL,
                                                        R.style.CustomDialog);
                                                dialogFragment.show(((FragmentActivity) mContext)
                                                        .getSupportFragmentManager(), "");
                                            }
                                        })
                                .setNegativeButton("No", new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int id) {
                                        dialog.cancel();
                                    }
                                });

                        AlertDialog alertDialog = alertDialogBuilder.create();

                        alertDialog.show();

                        return;
                    }
                    mSeed.setLikeStatus(result);
                    displayLikeStatus(result);
                    mContext.sendBroadcast(new Intent(BroadCastMessages.SEED_DISPLAYLIST));

                };
            }.execute();

        }
    });
}

From source file:org.telegram.ui.ChangePhoneHelpActivity.java

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);

    TLRPC.User user = UserConfig.getCurrentUser();
    String value;// ww  w.ja v  a2  s .  com
    if (user != null && user.phone != null && user.phone.length() != 0) {
        value = PhoneFormat.getInstance().format("+" + user.phone);
    } else {
        value = LocaleController.getString("NumberUnknown", R.string.NumberUnknown);
    }

    actionBar.setTitle(value);
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });

    fragmentView = new RelativeLayout(context);
    fragmentView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });

    RelativeLayout relativeLayout = (RelativeLayout) fragmentView;

    ScrollView scrollView = new ScrollView(context);
    relativeLayout.addView(scrollView);
    RelativeLayout.LayoutParams layoutParams3 = (RelativeLayout.LayoutParams) scrollView.getLayoutParams();
    layoutParams3.width = LayoutHelper.MATCH_PARENT;
    layoutParams3.height = LayoutHelper.WRAP_CONTENT;
    layoutParams3.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
    scrollView.setLayoutParams(layoutParams3);

    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setPadding(0, AndroidUtilities.dp(20), 0, AndroidUtilities.dp(20));
    scrollView.addView(linearLayout);
    ScrollView.LayoutParams layoutParams = (ScrollView.LayoutParams) linearLayout.getLayoutParams();
    layoutParams.width = ScrollView.LayoutParams.MATCH_PARENT;
    layoutParams.height = ScrollView.LayoutParams.WRAP_CONTENT;
    linearLayout.setLayoutParams(layoutParams);

    ImageView imageView = new ImageView(context);
    imageView.setImageResource(R.drawable.phone_change);
    linearLayout.addView(imageView);
    LinearLayout.LayoutParams layoutParams2 = (LinearLayout.LayoutParams) imageView.getLayoutParams();
    layoutParams2.width = LayoutHelper.WRAP_CONTENT;
    layoutParams2.height = LayoutHelper.WRAP_CONTENT;
    layoutParams2.gravity = Gravity.CENTER_HORIZONTAL;
    imageView.setLayoutParams(layoutParams2);

    TextView textView = new TextView(context);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    textView.setGravity(Gravity.CENTER_HORIZONTAL);
    //textView.setTextColor(0xff212121);

    try {
        textView.setText(AndroidUtilities
                .replaceTags(LocaleController.getString("PhoneNumberHelp", R.string.PhoneNumberHelp)));
    } catch (Exception e) {
        FileLog.e("tmessages", e);
        textView.setText(LocaleController.getString("PhoneNumberHelp", R.string.PhoneNumberHelp));
    }
    linearLayout.addView(textView);
    layoutParams2 = (LinearLayout.LayoutParams) textView.getLayoutParams();
    layoutParams2.width = LayoutHelper.WRAP_CONTENT;
    layoutParams2.height = LayoutHelper.WRAP_CONTENT;
    layoutParams2.gravity = Gravity.CENTER_HORIZONTAL;
    layoutParams2.leftMargin = AndroidUtilities.dp(20);
    layoutParams2.rightMargin = AndroidUtilities.dp(20);
    layoutParams2.topMargin = AndroidUtilities.dp(56);
    textView.setLayoutParams(layoutParams2);

    textView = new TextView(context);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    textView.setGravity(Gravity.CENTER_HORIZONTAL);
    textView.setTextColor(ContextCompat.getColor(context, R.color.colorAccent) /*0xff4d83b3*/);
    textView.setText(LocaleController.getString("PhoneNumberChange", R.string.PhoneNumberChange));
    textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    textView.setPadding(AndroidUtilities.dp(16), AndroidUtilities.dp(12), AndroidUtilities.dp(16),
            AndroidUtilities.dp(12));
    textView.setBackground(context.getDrawable(R.drawable.list_selector));
    linearLayout.addView(textView);
    layoutParams2 = (LinearLayout.LayoutParams) textView.getLayoutParams();
    layoutParams2.width = LayoutHelper.WRAP_CONTENT;
    layoutParams2.height = LayoutHelper.WRAP_CONTENT;
    layoutParams2.gravity = Gravity.CENTER_HORIZONTAL;
    layoutParams2.leftMargin = AndroidUtilities.dp(20);
    layoutParams2.rightMargin = AndroidUtilities.dp(20);
    layoutParams2.topMargin = AndroidUtilities.dp(46);
    textView.setLayoutParams(layoutParams2);

    textView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (getParentActivity() == null) {
                return;
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
            builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
            builder.setMessage(LocaleController.getString("PhoneNumberAlert", R.string.PhoneNumberAlert));
            builder.setPositiveButton(LocaleController.getString("OK", R.string.OK),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            presentFragment(new ChangePhoneActivity(), true);
                        }
                    });
            builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
            showDialog(builder.create());
        }
    });

    return fragmentView;
}

From source file:org.gots.seed.view.SeedWidgetTile.java

@SuppressWarnings("deprecation")
private void setupView() {

    if (mSeed == null)
        return;//from  w w  w  .  j  av a  2  s  . c  o  m

    // int familyImageRessource = 0;
    // if (mSeed.getFamily() != null)
    // familyImageRessource = getResources().getIdentifier(
    // "org.gots:drawable/family_" + mSeed.getFamily().toLowerCase(), null, null);
    //
    // if (familyImageRessource != 0)
    // setBackgroundResource(familyImageRessource);
    // else {
    // int sdk = android.os.Build.VERSION.SDK_INT;
    // if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
    // setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.family_unknown));
    // } else {
    // setBackground(mContext.getResources().getDrawable(R.drawable.family_unknown));
    // }
    // }

    SeedWidget seedWidget = (SeedWidget) findViewById(R.id.idSeedWidget2);
    seedWidget.setSeed(mSeed);

    TextView seedSpecie = (TextView) findViewById(R.id.IdSeedSpecie);
    seedSpecie.setText(SeedUtil.translateSpecie(mContext, mSeed));
    if (GotsPreferences.DEBUG)
        seedSpecie.setText("(" + mSeed.getSeedId() + ")" + SeedUtil.translateSpecie(mContext, mSeed));

    TextView seedVariety = (TextView) findViewById(R.id.IdSeedVariety);
    seedVariety.setText(mSeed.getVariety());

    state = (ImageView) findViewById(R.id.imageStateValidation);
    if ("approved".equals(mSeed.getState()))
        state.setVisibility(View.VISIBLE);
    else
        state.setVisibility(View.GONE);

    // PlanningWidget planningSow = (PlanningWidget) fidindViewById(R.id.IdSeedSowingPlanning);
    // planningSow.setAdapter(new PlanningSowAdapter(mSeed));
    // //
    // PlanningWidget planningHarvest = (PlanningWidget) findViewById(R.id.IdSeedHarvestPlanning);
    // planningHarvest.setAdapter(new PlanningHarvestAdapter(mSeed));

    LinearLayout stock = (LinearLayout) findViewById(R.id.idSeedStock);
    stock.removeAllViews();
    for (int i = 0; i < mSeed.getNbSachet(); i++) {
        ImageView seedbag = new ImageView(mContext);
        seedbag.setImageDrawable(mContext.getResources().getDrawable(R.drawable.seed_bag));
        // seedbag.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.bg_planning_sow));

        LayoutParams params = new LinearLayout.LayoutParams(30, 30);
        seedbag.setLayoutParams(params);
        stock.addView(seedbag, i);
    }

    if (mSeed.getLanguage() != null && !"".equals(mSeed.getLanguage())) {
        ImageView flag = (ImageView) findViewById(R.id.IdSeedLanguage);
        int flagRessource = getResources()
                .getIdentifier("org.gots:drawable/" + mSeed.getLanguage().toLowerCase(), null, null);
        flag.setImageResource(flagRessource);
    }

    likeCount = (TextView) findViewById(R.id.textSeedLike);
    like = (ImageView) findViewById(R.id.ImageSeedLike);

    displayLikeStatus(mSeed.getLikeStatus());
    if (mSeed.getUUID() == null)
        like.setVisibility(View.GONE);

    like.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            new AsyncTask<Void, Void, LikeStatus>() {
                GotsException exception = null;

                @Override
                protected LikeStatus doInBackground(Void... params) {
                    GotsSeedManager manager = GotsSeedManager.getInstance().initIfNew(mContext);
                    try {
                        return manager.like(mSeed, mSeed.getLikeStatus().getUserLikeStatus() == 1);
                    } catch (GotsException e) {
                        exception = e;
                        return null;
                    } catch (Exception e) {
                        Log.e(getClass().getName(), "" + e.getMessage(), e);
                        return null;
                    }
                }

                protected void onPostExecute(LikeStatus result) {
                    if (result == null && exception != null) {
                        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mContext);

                        // set title
                        alertDialogBuilder.setTitle(exception.getMessage());
                        alertDialogBuilder.setMessage(exception.getMessageDescription()).setCancelable(false)
                                .setPositiveButton(mContext.getResources().getString(R.string.login_connect),
                                        new DialogInterface.OnClickListener() {
                                            public void onClick(DialogInterface dialog, int id) {
                                                // Intent loginIntent = new Intent(mContext, LoginDialogFragment.class);
                                                // mContext.startActivity(loginIntent);
                                                LoginDialogFragment dialogFragment = new LoginDialogFragment();
                                                dialogFragment.setStyle(DialogFragment.STYLE_NORMAL,
                                                        R.style.CustomDialog);
                                                dialogFragment.show(((FragmentActivity) mContext)
                                                        .getSupportFragmentManager(), "");
                                            }
                                        })
                                .setNegativeButton("No", new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int id) {
                                        dialog.cancel();
                                    }
                                });

                        AlertDialog alertDialog = alertDialogBuilder.create();

                        alertDialog.show();

                        return;
                    }
                    mSeed.setLikeStatus(result);
                    displayLikeStatus(result);
                    mContext.sendBroadcast(new Intent(BroadCastMessages.SEED_DISPLAYLIST));

                };
            }.execute();

        }
    });
}

From source file:com.filemanager.free.adapters.DrawerAdapter.java

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    if (values.get(position).isSection()) {
        ImageView view = new ImageView(context);
        if (m.theme1 == 0)
            view.setImageResource(R.color.divider);
        else/* w  ww  .  ja  v a2  s.c o  m*/
            view.setImageResource(R.color.divider_dark);
        view.setClickable(false);
        view.setFocusable(false);
        if (m.theme1 == 0)
            view.setBackgroundColor(Color.WHITE);
        else
            view.setBackgroundResource(R.color.background_material_dark);
        view.setLayoutParams(new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, m.dpToPx(17)));
        view.setPadding(0, m.dpToPx(8), 0, m.dpToPx(8));
        return view;
    } else {
        View view = inflater.inflate(R.layout.drawerrow, parent, false);
        final TextView txtTitle = (TextView) view.findViewById(R.id.firstline);
        final ImageView imageView = (ImageView) view.findViewById(R.id.icon);
        if (m.theme1 == 0) {
            view.setBackgroundResource(R.drawable.safr_ripple_white);
        } else {
            view.setBackgroundResource(R.drawable.safr_ripple_black);
        }
        view.setOnClickListener(new View.OnClickListener() {

            public void onClick(View p1) {
                m.selectItem(position);
            }
            // TODO: Implement this method

        });
        view.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                if (!getItem(position).isSection())
                    // not to remove the first bookmark (storage) and permanent bookmarks
                    if (position > m.storage_count && position < values.size() - 7) {
                        EntryItem item = (EntryItem) getItem(position);
                        String path = (item).getPath();
                        if (DataUtils.containsBooks(new String[] { item.getTitle(), path }) != -1) {
                            m.renameBookmark((item).getTitle(), path);
                        } else if (path.startsWith("smb:/")) {
                            m.showSMBDialog(item.getTitle(), path, true);
                        }
                    } else if (position < m.storage_count) {
                        String path = ((EntryItem) getItem(position)).getPath();
                        if (!path.equals("/"))
                            new Futils().showProps(RootHelper.generateBaseFile(new File(path), true), m,
                                    m.theme1);
                    }

                // return true to denote no further processing
                return true;
            }
        });

        txtTitle.setText(((EntryItem) (values.get(position))).getTitle());
        imageView.setImageDrawable(getDrawable(position));
        imageView.clearColorFilter();
        if (myChecked.get(position)) {
            if (m.theme1 == 0)
                view.setBackgroundColor(Color.parseColor("#ffeeeeee"));
            else
                view.setBackgroundColor(Color.parseColor("#ff424242"));
            imageView.setColorFilter(fabskin);
            txtTitle.setTextColor(Color.parseColor(m.fabskin));
        } else {
            if (m.theme1 == 0) {
                imageView.setColorFilter(Color.parseColor("#666666"));
                txtTitle.setTextColor(ContextCompat.getColor(getContext(), android.R.color.black));
            } else {
                imageView.setColorFilter(Color.WHITE);
                txtTitle.setTextColor(ContextCompat.getColor(getContext(), android.R.color.white));
            }
        }

        return view;
    }
}

From source file:com.luke.lukef.lukeapp.fragments.NewSubmissionFragment.java

/**
 * Handles updating the categories on the submission screen, based on user selection
 *//*from   www .ja  v  a  2 s.  c om*/
private void updateCategoryThumbnails() {
    this.categoriesLinearLayout.removeAllViews();

    for (Category c : this.confirmedCategories) {
        ImageView categoryImg = new ImageView(this.getMainActivity());
        categoryImg.setImageBitmap(c.getImage());
        LinearLayout.LayoutParams make = new LinearLayout.LayoutParams(new LinearLayout.LayoutParams(
                this.categoriesLinearLayout.getHeight(), this.categoriesLinearLayout.getHeight()));
        categoryImg.setLayoutParams(make);
        this.categoriesLinearLayout.addView(categoryImg);
    }
}

From source file:com.retroteam.studio.retrostudio.MeasureEditor.java

/**
 * Draw the grid.//from  w  w  w . j  a  v a  2 s .c o  m
 */
private void drawGrid() {
    //draw the grid based on project info
    thisMeasure = theproject.track(trackNum).measure(measureNum);
    TableLayout notedraw = (TableLayout) findViewById(R.id.notedraw);
    int notedrawlen = notedraw.getChildCount();

    //get note scale
    final float dscale = getApplicationContext().getResources().getDisplayMetrics().density;
    int notewidth = (int) (144 * dscale + 0.5f);
    int noteheight = (int) (75 * dscale + 0.5f);

    for (int x = 0; x < notedrawlen; x++) {
        TableRow noterow = (TableRow) notedraw.getChildAt(x);
        List<List<Integer>> rangelist = numNotesFromGuiSnap();
        for (int i = 0; i < rangelist.size(); i++) {
            ImageView note = new ImageView(getApplicationContext());
            note.setLayoutParams(new TableRow.LayoutParams(notewidth, noteheight));

            note.setTag(R.id.TAG_ROW, x);
            note.setTag(R.id.TAG_COLUMN, i);
            note.setTag(R.id.TAG_NOTE, notesdisplay[x]);

            note.setTag(R.id.TAG_GUISNAPRANGE, rangelist.get(i));

            note.setImageResource(R.drawable.measure_outline);
            if (filledNotesFromIntent.size() > 0) {
                for (int z = 0; z < filledNotesFromIntent.size(); z++) {
                    if ((filledNotesFromIntent.get(z)[0] == x) && (filledNotesFromIntent.get(z)[1] == i)) {
                        note.setImageResource(R.drawable.note_filled);
                    }
                }
            }

            note.setBackgroundColor(getResources().getColor(R.color.note_rest));

            note.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    paintNote(v);

                }
            });

            noterow.addView(note);
        }
    }
}

From source file:de.uulm.graphicalpasswords.openuyi.UYICreatePasswordActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_uyi_create_password);
    // Show the Up button in the action bar.
    setupActionBar();/*from ww w  . j  av  a 2s . co  m*/

    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    length = Integer.parseInt(sharedPref.getString("uyi_length", "10"));

    originalViews = new ImageView[length];
    distortedViews = new ImageView[length];
    selectedPictures = new Picture[length];

    Bundle bundle = new Bundle();
    bundle.putInt("length", length);
    DialogFragment intro = new IntroDialogFragment();
    intro.setArguments(bundle);
    intro.show(getFragmentManager(), "intro");

    vibrator = (Vibrator) this.getSystemService(VIBRATOR_SERVICE);

    Arrays.fill(selectedPictures, null);

    gallery = (Gallery) findViewById(R.id.uyi_gallery_originals);
    gallery.setAdapter(new UYIImageAdapter(this));

    gallery.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            ImageView viewOriginal = new ImageView(UYICreatePasswordActivity.this);
            ImageView viewDistorted = new ImageView(UYICreatePasswordActivity.this);

            int i = 0;
            for (; i < selectedPictures.length; i++) {
                if (i == selectedPictures.length - 1 && selectedPictures[i] != null) {
                    removePicture(i);
                }
                if (selectedPictures[i] == null || i == selectedPictures.length - 1) {
                    viewOriginal = originalViews[i];
                    viewDistorted = distortedViews[i];
                    selectedPictures[i] = ((UYIImageAdapter) parent.getAdapter()).getPicture(position);
                    vibrator.vibrate(100);

                    ScrollView sv = (ScrollView) findViewById(R.id.uyi_choosepi_scrollview);
                    int height = originalViews[0].getMeasuredHeight();
                    sv.scrollTo(0, (i * height) - 200);

                    break;
                }
            }

            int originalImageResource = ((UYIImageAdapter) parent.getAdapter()).getImageResource(position);
            viewOriginal.setImageResource(originalImageResource);
            viewDistorted.setImageResource(
                    ((UYIImageAdapter) parent.getAdapter()).getDistortedImageResource(position));
            ((UYIImageAdapter) parent.getAdapter()).removePicture(position);

            OnLongClickListener listener = new OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    vibrator.vibrate(200);
                    int viewid = v.getId();
                    int index = -1;

                    for (int i = 0; i < originalViews.length; i++) {
                        if (originalViews[i].getId() == viewid) {
                            index = i;
                            break;
                        } else if (distortedViews[i].getId() == viewid) {
                            index = i;
                            break;
                        }
                    }
                    Bundle bundle = new Bundle();
                    bundle.putInt("index", index);
                    DialogFragment dialog = new DeleteImageDialogFragment();
                    dialog.setArguments(bundle);
                    dialog.show(getFragmentManager(), "delete");
                    return false;
                }
            };

            viewOriginal.setOnLongClickListener(listener);
            viewDistorted.setOnLongClickListener(listener);

            // Check
            int count = 0;
            for (int j = 0; j < selectedPictures.length; j++) {
                if (selectedPictures[j] != null) {
                    count++;
                }
            }
            if (count == selectedPictures.length) {
                findViewById(R.id.uyi_save).setClickable(true);
                findViewById(R.id.uyi_save).setEnabled(true);
            }
        }
    });

    table = (TableLayout) findViewById(R.id.uyi_choosepi_tablelayout);
    LayoutParams params = new LayoutParams(android.widget.TableRow.LayoutParams.WRAP_CONTENT,
            android.widget.TableRow.LayoutParams.WRAP_CONTENT);
    params.gravity = Gravity.CENTER;
    for (int i = 0; i < length; i++) {
        TableRow row = new TableRow(table.getContext());

        originalViews[i] = new ImageView(row.getContext());
        originalViews[i].setAdjustViewBounds(true);
        originalViews[i].setScaleType(ScaleType.FIT_XY);
        originalViews[i].setPadding(3, 3, 3, 3);
        originalViews[i].setImageResource(R.drawable.oempty);
        originalViews[i].setId(100 + i);

        distortedViews[i] = new ImageView(row.getContext());
        distortedViews[i].setAdjustViewBounds(true);
        distortedViews[i].setScaleType(ScaleType.FIT_XY);
        distortedViews[i].setPadding(3, 3, 3, 3);
        distortedViews[i].setImageResource(R.drawable.wempty);
        distortedViews[i].setId(1000 + i);

        ImageView arrow = new ImageView(row.getContext());
        arrow.setAdjustViewBounds(true);
        arrow.setScaleType(ScaleType.FIT_XY);
        arrow.setMaxWidth(80);
        arrow.setPadding(3, 3, 3, 3);
        arrow.setImageResource(R.drawable.arrow_active);
        arrow.setLayoutParams(params);

        row.addView(originalViews[i]);
        row.addView(arrow);
        row.addView(distortedViews[i]);
        table.addView(row);
    }
}

From source file:org.nativescript.widgets.TabLayout.java

/**
 * Create a default view to be used for tabs.
 *///from   ww  w.j  ava 2 s. c  o  m
protected View createDefaultTabView(Context context, TabItemSpec tabItem) {
    float density = getResources().getDisplayMetrics().density;
    int padding = (int) (TAB_VIEW_PADDING_DIPS * density);

    LinearLayout ll = new LinearLayout(context);
    ll.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    ll.setGravity(Gravity.CENTER);
    ll.setOrientation(LinearLayout.VERTICAL);
    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
    ll.setBackgroundResource(outValue.resourceId);

    ImageView imgView = new ImageView(context);
    imgView.setScaleType(ScaleType.FIT_CENTER);
    LinearLayout.LayoutParams imgLP = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    imgLP.gravity = Gravity.CENTER;
    imgView.setLayoutParams(imgLP);

    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setMaxWidth((int) (TEXT_MAX_WIDTH * density));
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setEllipsize(TextUtils.TruncateAt.END);
    textView.setAllCaps(true);
    textView.setMaxLines(2);
    textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    textView.setPadding(padding, 0, padding, 0);

    this.setupItem(ll, textView, imgView, tabItem);

    ll.addView(imgView);
    ll.addView(textView);
    return ll;
}

From source file:com.ushahidi.android.app.ui.phone.AddCheckinActivity.java

@Override
public View makeView() {

    ImageView i = new ImageView(this);
    i.setAdjustViewBounds(true);// www. jav a  2s  .  co m
    i.setScaleType(ImageView.ScaleType.FIT_XY);
    i.setLayoutParams(new ImageSwitcher.LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT,
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT));

    return i;
}

From source file:co.mrktplaces.android.ui.views.smarttablayout.SmartTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}./*from  w  w w.  j ava 2 s  .  co  m*/
 */
protected ImageView createDefaultTabView(int resource) {
    ImageView imageView = new ImageView(getContext());
    imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    imageView.setLayoutParams(new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1));
    imageView.setImageResource(resource);
    if (tabViewBackgroundResId != NO_ID) {
        imageView.setBackgroundResource(tabViewBackgroundResId);
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        imageView.setBackgroundResource(outValue.resourceId);
    }

    imageView.setPadding(tabViewTextHorizontalPadding, 0, tabViewTextHorizontalPadding, 0);

    if (tabViewTextMinWidth > 0) {
        imageView.setMinimumWidth(tabViewTextMinWidth);
    }

    return imageView;
}