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.android.contacts.list.DefaultContactBrowseListFragment.java

private View getEmptyAccountView(LayoutInflater inflater) {
    final View emptyAccountView = inflater.inflate(R.layout.empty_account_view, null);
    // Set image margins.
    final ImageView image = (ImageView) emptyAccountView.findViewById(R.id.empty_account_image);
    final LayoutParams params = (LayoutParams) image.getLayoutParams();
    final int height = getResources().getDisplayMetrics().heightPixels;
    final int divisor = getResources().getInteger(R.integer.empty_account_view_image_margin_divisor);
    final int offset = getResources().getDimensionPixelSize(R.dimen.empty_account_view_image_offset);
    params.setMargins(0, height / divisor + offset, 0, 0);
    params.gravity = Gravity.CENTER_HORIZONTAL;
    image.setLayoutParams(params);

    // Set up add contact button.
    final Button addContactButton = (Button) emptyAccountView.findViewById(R.id.add_contact_button);
    addContactButton.setOnClickListener(mAddContactListener);
    return emptyAccountView;
}

From source file:com.intel.xdk.base.Base.java

public void showSplashScreen() {
    cordova.getActivity().runOnUiThread(new Runnable() {
        public void run() {
            //treat displays larger than 6" as tablets
            DisplayMetrics dm = new DisplayMetrics();
            cordova.getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
            double x = Math.pow(dm.widthPixels / dm.xdpi, 2);
            double y = Math.pow(dm.heightPixels / dm.ydpi, 2);
            double screenInches = Math.sqrt(x + y);
            if (screenInches > 6) {
                isTablet = true;/* ww  w . j ava 2  s.co m*/
            }

            //used for calculating status bar height
            int deviceWidth = dm.widthPixels;
            int deviceHeight = dm.heightPixels;
            if (deviceWidth > deviceHeight) {
                deviceWidth = dm.heightPixels;
                deviceHeight = dm.widthPixels;
            }

            //get the splash screen image from asssets
            Bitmap bm = null;
            try {
                if (isTablet) {
                    bm = getBitmapFromAsset("www/intel.xdk.base/android/splash_screen_tablet.jpg");
                } else {
                    bm = getBitmapFromAsset("www/intel.xdk.base/android/splash_screen.jpg");
                }
            } catch (IOException ioe) {
            }

            //if the splash screen assets are missing, don't try to show the splash screen
            if (bm == null) {
                return;
            }

            if (Debug.isDebuggerConnected())
                Log.i("[intel.xdk]", "splash");

            ActivityInfo ai = null;
            int splashViewId = 0;
            try {
                ai = cordova.getActivity().getPackageManager().getActivityInfo(
                        cordova.getActivity().getComponentName(),
                        PackageManager.GET_ACTIVITIES | PackageManager.GET_META_DATA);

                if (isTablet) {
                    if (ai.screenOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
                        splashViewId = cordova.getActivity().getResources().getIdentifier("splash_tablet_ls",
                                "layout", cordova.getActivity().getPackageName());
                    } else {
                        splashViewId = cordova.getActivity().getResources().getIdentifier("splash_tablet",
                                "layout", cordova.getActivity().getPackageName());
                    }
                } else {
                    if (ai.screenOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
                        splashViewId = cordova.getActivity().getResources().getIdentifier("splash_ls", "layout",
                                cordova.getActivity().getPackageName());
                    } else {
                        splashViewId = cordova.getActivity().getResources().getIdentifier("splash", "layout",
                                cordova.getActivity().getPackageName());
                    }
                }
                LayoutInflater inflater = LayoutInflater.from(cordova.getActivity());
                splashView = inflater.inflate(splashViewId, null);

                //set the splash screen image
                //http://stackoverflow.com/questions/7776445/in-android-can-i-use-image-from-assets-in-layout-xml
                ImageView backgroundImage = (ImageView) splashView
                        .findViewById(cordova.getActivity().getResources().getIdentifier("background", "id",
                                cordova.getActivity().getPackageName()));
                backgroundImage.setImageBitmap(bm);
                ((ViewGroup) root.getParent()).addView(splashView);
                splashView.bringToFront();

                //hack to fix splash screen size when it is smaller than screen            
                ImageView splashImage = (ImageView) cordova.getActivity()
                        .findViewById(cordova.getActivity().getResources().getIdentifier("background", "id",
                                cordova.getActivity().getPackageName()));
                LayoutParams params = splashImage.getLayoutParams();
                Rect imgBounds = splashImage.getDrawable().getBounds();
                int splashHeight = params.height;
                int splashWidth = params.width;

                //make copies in case we have to switch for landscape - not sure if needed, this is a last minute hack
                int deviceWidthCopy, deviceHeightCopy;
                deviceWidthCopy = deviceWidth;
                deviceHeightCopy = deviceHeight;
                if (ai.screenOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
                    int temp = deviceWidthCopy;
                    deviceWidthCopy = deviceHeightCopy;
                    deviceHeightCopy = temp;
                }
                if (splashHeight < deviceHeightCopy || splashWidth < deviceWidthCopy) {
                    float scaleH = (float) deviceHeightCopy / splashHeight;
                    float scaleW = (float) deviceWidthCopy / splashWidth;
                    float scale = Math.max(scaleH, scaleW);
                    params.height *= scale;
                    params.width *= scale;
                    splashImage.setLayoutParams(params);
                }

                cordova.getActivity().setProgressBarIndeterminateVisibility(true);

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

}

From source file:org.egov.android.view.activity.ComplaintDetailActivity.java

/**
 * Function called when the activity was created to show the images attached
 * with the complaints Get the files from the complaint folder path and show
 * that images in horizontal scroll view
 */// www. j ava 2  s . c  o  m
private void _showComplaintImages() {
    File folder = new File(complaintFolderName);
    if (!folder.exists()) {
        return;
    }
    File[] listOfFiles = folder.listFiles();

    int imageidx = 0;

    for (int i = 0; i < listOfFiles.length; i++) {

        if (listOfFiles[i].isFile()) {
            Log.d("EGOV_JOB", "File path" + complaintFolderName + File.separator + listOfFiles[i].getName());

            if (listOfFiles[i].getName().startsWith("photo_")) {
                continue;
            }

            ImageView image = new ImageView(this);
            Bitmap bmp = _getBitmapImage(complaintFolderName + File.separator + listOfFiles[i].getName());
            image.setImageBitmap(bmp);
            image.setId(imageidx);
            imageidx = imageidx + 1;
            image.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent photo_viewer = new Intent(ComplaintDetailActivity.this, PhotoViewerActivity.class);
                    photo_viewer.putExtra("path", complaintFolderName);
                    photo_viewer.putExtra("complaintId", complaintId);
                    photo_viewer.putExtra("imageId", v.getId());
                    startActivity(photo_viewer);
                }
            });
            LinearLayout.LayoutParams inner_container_params = new LinearLayout.LayoutParams(_dpToPix(90),
                    _dpToPix(90));
            inner_container_params.setMargins(0, 0, 10, 0);
            image.setLayoutParams(inner_container_params);
            image.setPadding(2, 2, 2, 2);
            image.setBackgroundDrawable(getResources().getDrawable(R.drawable.edittext_border));
            image.setScaleType(ScaleType.CENTER_INSIDE);
            imageCntainer.addView(image);
        }
    }
}

From source file:com.mobicage.rogerthat.plugins.messaging.ServiceMessageDetailActivity.java

private RelativeLayout createParticipantView(MemberStatusTO ms) {
    RelativeLayout rl = new RelativeLayout(this);
    int rlW = UIUtils.convertDipToPixels(this, 55);
    rl.setLayoutParams(new RelativeLayout.LayoutParams(rlW, rlW));

    getLayoutInflater().inflate(R.layout.avatar, rl);
    ImageView avatar = (ImageView) rl.getChildAt(rl.getChildCount() - 1);
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(avatar.getLayoutParams());
    params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
    avatar.setLayoutParams(params);
    setAvatar(avatar, ms.member);/*w w  w  . j  a  va 2s .c  o m*/

    ImageView statusView = new ImageView(this);
    int w = UIUtils.convertDipToPixels(this, 12);
    RelativeLayout.LayoutParams iconParams = new RelativeLayout.LayoutParams(w, w);
    iconParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
    iconParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
    statusView.setLayoutParams(iconParams);
    statusView.setAdjustViewBounds(true);
    statusView.setScaleType(ScaleType.CENTER_CROP);
    setStatusIcon(statusView, ms);
    rl.addView(statusView);
    return rl;
}

From source file:com.near.chimerarevo.fragments.PostFragment.java

private void addYoutubeVideo(String url) {
    final String yturl;
    if (url.contains("embed")) {
        String temp = url.split("embed/")[1];
        if (url.contains("feature")) {
            temp = temp.split("feature=")[0];
            yturl = temp.substring(0, temp.length() - 1);
        } else//  www .  j  ava2s  .c  o m
            yturl = temp;
    } else if (url.contains("youtu.be")) {
        yturl = url.split("youtu.be/")[1];
    } else
        return;

    final RelativeLayout rl = new RelativeLayout(getActivity());
    YouTubeThumbnailView yt = new YouTubeThumbnailView(getActivity());
    ImageView icon = new ImageView(getActivity());

    try {
        yt.setTag(yturl);
        yt.initialize(Constants.YOUTUBE_API_TOKEN, new OnInitializedListener() {
            @Override
            public void onInitializationFailure(YouTubeThumbnailView thumbView,
                    YouTubeInitializationResult error) {
                rl.setVisibility(View.GONE);
            }

            @Override
            public void onInitializationSuccess(YouTubeThumbnailView thumbView,
                    YouTubeThumbnailLoader thumbLoader) {
                thumbLoader.setVideo(yturl);
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
    }

    RelativeLayout.LayoutParams obj_params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    obj_params.addRule(RelativeLayout.CENTER_HORIZONTAL);
    obj_params.addRule(RelativeLayout.CENTER_VERTICAL);
    yt.setLayoutParams(obj_params);

    icon.setImageResource(R.drawable.yt_play_button);
    icon.setLayoutParams(obj_params);

    RelativeLayout.LayoutParams rl_params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    rl_params.setMargins(0, 10, 0, 0);
    rl.setLayoutParams(rl_params);
    rl.setGravity(Gravity.CENTER_HORIZONTAL);
    rl.setClickable(true);

    rl.addView(yt);
    rl.addView(icon);

    rl.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent(getActivity(), YoutubeActivity.class);
            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            i.putExtra(Constants.KEY_VIDEO_URL, yturl);
            startActivity(i);
        }
    });

    lay.addView(rl);
}

From source file:com.fa.mastodon.activity.ComposeActivity.java

private void addMediaToQueue(QueuedMedia.Type type, Bitmap preview, Uri uri, long mediaSize) {
    final QueuedMedia item = new QueuedMedia(type, uri, new ImageView(this), mediaSize);
    ImageView view = item.preview;
    Resources resources = getResources();
    int side = resources.getDimensionPixelSize(R.dimen.compose_media_preview_side);
    int margin = resources.getDimensionPixelSize(R.dimen.compose_media_preview_margin);
    int marginBottom = resources.getDimensionPixelSize(R.dimen.compose_media_preview_margin_bottom);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(side, side);
    layoutParams.setMargins(margin, 0, margin, marginBottom);
    view.setLayoutParams(layoutParams);
    view.setScaleType(ImageView.ScaleType.CENTER_CROP);
    view.setImageBitmap(preview);/*from  w ww  . ja  v a 2  s .  c  om*/

    view.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            removeMediaFromQueue(item);
        }
    });
    mediaPreviewBar.addView(view);
    mediaQueued.add(item);
    int queuedCount = mediaQueued.size();
    if (queuedCount == 1) {
        /* The media preview bar is actually not inset in the EditText, it just overlays it and
         * is aligned to the bottom. But, so that text doesn't get hidden under it, extra
         * padding is added at the bottom of the EditText. */
        int totalHeight = side + margin + marginBottom;
        textEditor.setPadding(textEditor.getPaddingLeft(), textEditor.getPaddingTop(),
                textEditor.getPaddingRight(), totalHeight);
        // If there's one video in the queue it is full, so disable the button to queue more.
        if (item.type == QueuedMedia.Type.VIDEO) {
            disableMediaButtons();
        }
    } else if (queuedCount >= Status.MAX_MEDIA_ATTACHMENTS) {
        // Limit the total media attachments, also.
        disableMediaButtons();
    }
    if (queuedCount >= 1) {
        showMarkSensitive(true);
    }
    waitForMediaLatch.countUp();
    if (mediaSize > STATUS_MEDIA_SIZE_LIMIT && type == QueuedMedia.Type.IMAGE) {
        downsizeMedia(item);
    } else {
        uploadMedia(item);
    }
}

From source file:com.b44t.ui.Components.PasscodeView.java

public PasscodeView(final Context context) {
    super(context);

    setWillNotDraw(false);//  w  w w . ja v a2s  . c o m
    setVisibility(GONE);

    backgroundFrameLayout = new FrameLayout(context);
    addView(backgroundFrameLayout);
    LayoutParams layoutParams = (LayoutParams) backgroundFrameLayout.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    backgroundFrameLayout.setLayoutParams(layoutParams);

    passwordFrameLayout = new FrameLayout(context);
    addView(passwordFrameLayout);
    layoutParams = (LayoutParams) passwordFrameLayout.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
    passwordFrameLayout.setLayoutParams(layoutParams);

    ImageView imageView = new ImageView(context);
    imageView.setScaleType(ImageView.ScaleType.FIT_XY);
    imageView.setImageResource(R.drawable.ic_launcher /* EDIT BY MR -- was: passcode_logo */);
    passwordFrameLayout.addView(imageView);
    layoutParams = (LayoutParams) imageView.getLayoutParams();
    if (AndroidUtilities.density < 1) {
        layoutParams.width = AndroidUtilities.dp(30);
        layoutParams.height = AndroidUtilities.dp(30);
    } else {
        layoutParams.width = AndroidUtilities.dp(40);
        layoutParams.height = AndroidUtilities.dp(40);
    }
    layoutParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
    layoutParams.bottomMargin = AndroidUtilities.dp(100);
    imageView.setLayoutParams(layoutParams);

    passcodeTextView = new TextView(context);
    passcodeTextView.setTextColor(0xffffffff);
    passcodeTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    passcodeTextView.setGravity(Gravity.CENTER_HORIZONTAL);
    passwordFrameLayout.addView(passcodeTextView);
    layoutParams = (LayoutParams) passcodeTextView.getLayoutParams();
    layoutParams.width = LayoutHelper.WRAP_CONTENT;
    layoutParams.height = LayoutHelper.WRAP_CONTENT;
    layoutParams.bottomMargin = AndroidUtilities.dp(62);
    layoutParams.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
    passcodeTextView.setLayoutParams(layoutParams);

    passwordEditText = new EditText(context);
    passwordEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 36);
    passwordEditText.setTextColor(0xffffffff);
    passwordEditText.setMaxLines(1);
    passwordEditText.setLines(1);
    passwordEditText.setGravity(Gravity.CENTER_HORIZONTAL);
    passwordEditText.setSingleLine(true);
    passwordEditText.setImeOptions(EditorInfo.IME_ACTION_DONE);
    passwordEditText.setTypeface(Typeface.DEFAULT);
    passwordEditText.setBackgroundDrawable(null);
    AndroidUtilities.clearCursorDrawable(passwordEditText);
    passwordFrameLayout.addView(passwordEditText);
    layoutParams = (FrameLayout.LayoutParams) passwordEditText.getLayoutParams();
    layoutParams.height = LayoutHelper.WRAP_CONTENT;
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.leftMargin = AndroidUtilities.dp(70);
    layoutParams.rightMargin = AndroidUtilities.dp(70);
    layoutParams.bottomMargin = AndroidUtilities.dp(6);
    layoutParams.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
    passwordEditText.setLayoutParams(layoutParams);
    passwordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            if (i == EditorInfo.IME_ACTION_DONE) {
                processDone(false);
                return true;
            }
            return false;
        }
    });
    passwordEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            if (passwordEditText.length() == 4 && UserConfig.passcodeType == 0) {
                processDone(false);
            }
        }
    });
    passwordEditText.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        public void onDestroyActionMode(ActionMode mode) {
        }

        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            return false;
        }
    });

    checkImage = new ImageView(context);
    checkImage.setImageResource(R.drawable.passcode_check);
    checkImage.setScaleType(ImageView.ScaleType.CENTER);
    checkImage.setBackgroundResource(R.drawable.bar_selector_lock);
    passwordFrameLayout.addView(checkImage);
    layoutParams = (LayoutParams) checkImage.getLayoutParams();
    layoutParams.width = AndroidUtilities.dp(60);
    layoutParams.height = AndroidUtilities.dp(60);
    layoutParams.bottomMargin = AndroidUtilities.dp(4);
    layoutParams.rightMargin = AndroidUtilities.dp(10);
    layoutParams.gravity = Gravity.BOTTOM | Gravity.RIGHT;
    checkImage.setLayoutParams(layoutParams);
    checkImage.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            processDone(false);
        }
    });

    FrameLayout lineFrameLayout = new FrameLayout(context);
    lineFrameLayout.setBackgroundColor(0x26ffffff);
    passwordFrameLayout.addView(lineFrameLayout);
    layoutParams = (LayoutParams) lineFrameLayout.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = AndroidUtilities.dp(1);
    layoutParams.gravity = Gravity.BOTTOM | Gravity.LEFT;
    layoutParams.leftMargin = AndroidUtilities.dp(20);
    layoutParams.rightMargin = AndroidUtilities.dp(20);
    lineFrameLayout.setLayoutParams(layoutParams);

    numbersFrameLayout = new FrameLayout(context);
    addView(numbersFrameLayout);
    layoutParams = (LayoutParams) numbersFrameLayout.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
    numbersFrameLayout.setLayoutParams(layoutParams);

    lettersTextViews = new ArrayList<>(10);
    numberTextViews = new ArrayList<>(10);
    numberFrameLayouts = new ArrayList<>(10);
    for (int a = 0; a < 10; a++) {
        TextView textView = new TextView(context);
        textView.setTextColor(0xffffffff);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 36);
        textView.setGravity(Gravity.CENTER);
        textView.setText(String.format(Locale.US, "%d", a));
        numbersFrameLayout.addView(textView);
        layoutParams = (LayoutParams) textView.getLayoutParams();
        layoutParams.width = AndroidUtilities.dp(50);
        layoutParams.height = AndroidUtilities.dp(50);
        layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
        textView.setLayoutParams(layoutParams);
        numberTextViews.add(textView);

        textView = new TextView(context);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
        textView.setTextColor(0x7fffffff);
        textView.setGravity(Gravity.CENTER);
        numbersFrameLayout.addView(textView);
        layoutParams = (LayoutParams) textView.getLayoutParams();
        layoutParams.width = AndroidUtilities.dp(50);
        layoutParams.height = AndroidUtilities.dp(20);
        layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
        textView.setLayoutParams(layoutParams);
        switch (a) {
        case 0:
            textView.setText("+");
            break;
        case 2:
            textView.setText("ABC");
            break;
        case 3:
            textView.setText("DEF");
            break;
        case 4:
            textView.setText("GHI");
            break;
        case 5:
            textView.setText("JKL");
            break;
        case 6:
            textView.setText("MNO");
            break;
        case 7:
            textView.setText("PQRS");
            break;
        case 8:
            textView.setText("TUV");
            break;
        case 9:
            textView.setText("WXYZ");
            break;
        default:
            break;
        }
        lettersTextViews.add(textView);
    }
    eraseView = new ImageView(context);
    eraseView.setScaleType(ImageView.ScaleType.CENTER);
    eraseView.setImageResource(R.drawable.passcode_delete);
    numbersFrameLayout.addView(eraseView);
    layoutParams = (LayoutParams) eraseView.getLayoutParams();
    layoutParams.width = AndroidUtilities.dp(50);
    layoutParams.height = AndroidUtilities.dp(50);
    layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
    eraseView.setLayoutParams(layoutParams);
    for (int a = 0; a < 11; a++) {
        FrameLayout frameLayout = new FrameLayout(context);
        frameLayout.setBackgroundResource(R.drawable.bar_selector_lock);
        frameLayout.setTag(a);
        if (a == 10) {
            frameLayout.setOnLongClickListener(new OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    passwordEditText.setText("");
                    return true;
                }
            });
        }
        frameLayout.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                int tag = (Integer) v.getTag();
                switch (tag) {
                case 0:
                    appendCharacter("0");
                    break;
                case 1:
                    appendCharacter("1");
                    break;
                case 2:
                    appendCharacter("2");
                    break;
                case 3:
                    appendCharacter("3");
                    break;
                case 4:
                    appendCharacter("4");
                    break;
                case 5:
                    appendCharacter("5");
                    break;
                case 6:
                    appendCharacter("6");
                    break;
                case 7:
                    appendCharacter("7");
                    break;
                case 8:
                    appendCharacter("8");
                    break;
                case 9:
                    appendCharacter("9");
                    break;
                case 10:
                    String text = passwordEditText.getText().toString();
                    if (text.length() > 0) {
                        passwordEditText.setText(text.substring(0, text.length() - 1));
                    }
                    break;
                }
                if (passwordEditText.getText().toString().length() == 4) {
                    processDone(false);
                }
            }
        });
        numberFrameLayouts.add(frameLayout);
    }
    for (int a = 10; a >= 0; a--) {
        FrameLayout frameLayout = numberFrameLayouts.get(a);
        numbersFrameLayout.addView(frameLayout);
        layoutParams = (LayoutParams) frameLayout.getLayoutParams();
        layoutParams.width = AndroidUtilities.dp(100);
        layoutParams.height = AndroidUtilities.dp(100);
        layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
        frameLayout.setLayoutParams(layoutParams);
    }
}

From source file:com.example.android.recyclingbanks.MainActivity.java

private View prepareInfoView(final Marker marker) {
    // TODO change this to xml?
    //prepare InfoView programmatically
    final LinearLayout infoView = new LinearLayout(MainActivity.this);
    LinearLayout.LayoutParams infoViewParams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    infoView.setOrientation(LinearLayout.VERTICAL);
    // attach the above layout to the infoView
    infoView.setLayoutParams(infoViewParams);

    String markerLongitude = Double.toString(marker.getPosition().longitude);
    String markerLatitude = Double.toString(marker.getPosition().latitude);

    final String imageURL = "https://maps.googleapis.com/maps/api/streetview?size=" + "500x300&location="
            + markerLatitude + "," + markerLongitude + "&fov=120&heading=0&pitch=0";

    //create street view preview @ top
    ImageView streetViewPreviewIV = new ImageView(MainActivity.this);

    Log.wtf("comparing TAG", String.valueOf(marker.getTag()));

    if (marker.getTag() == null) {
        Log.i("prepareInfoView", "fetching image");
        Picasso.with(this).load(imageURL).fetch(new MarkerCallback(marker));
    } else {//from  w  w  w . ja v  a2 s  . c o  m
        Log.wtf("prepareInfoView", "building info window");

        // this scales the image to match parents WIDTH?, but retain image's height??
        LinearLayout.LayoutParams streetViewImageViewParams = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
        streetViewPreviewIV.setLayoutParams(streetViewImageViewParams);
        // TODO upon conversion to xml, the imageView needs these to scale image to box
        // android:scaleType="fitStart"
        // android:adjustViewBounds="true"
        Picasso.with(MainActivity.this).load(imageURL).into(streetViewPreviewIV);
        infoView.addView(streetViewPreviewIV);
        //Log.wtf("prepareInfoView, marker tag set?", String.valueOf(marker.getTag()));
        //Picasso.with(this).setLoggingEnabled(true);
    }

    // create text boxes
    LinearLayout subInfoView = new LinearLayout(MainActivity.this);
    LinearLayout.LayoutParams subInfoViewParams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    subInfoView.setOrientation(LinearLayout.VERTICAL);
    subInfoView.setLayoutParams(subInfoViewParams);

    TextView titleTextView = new TextView(MainActivity.this);
    titleTextView.setText(marker.getTitle());
    TextView snippetTextView = new TextView(MainActivity.this);
    snippetTextView.setText(marker.getSnippet());
    subInfoView.addView(titleTextView);
    subInfoView.addView(snippetTextView);
    infoView.addView(subInfoView);

    // add the image on the right
    ImageView streetViewIcon = new ImageView(MainActivity.this);
    // this scales the image to match parents height.
    LinearLayout.LayoutParams imageViewParams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
    streetViewIcon.setLayoutParams(imageViewParams);
    Drawable drawable = ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_streetview);
    streetViewIcon.setImageDrawable(drawable);
    infoView.addView(streetViewIcon);
    //Picasso.with(this).load(imageURL).into(streetViewPreviewIV, new MarkerCallback(marker));

    return infoView;
}

From source file:org.xingjitong.DialerFragment.java

@SuppressWarnings("deprecation")
@Override/*from ww w  . j a  v  a 2 s  .c o  m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    instance = this;
    handler = new Handler();
    MSG.getInstance().setFragment(this);
    if (view == null) {
        view = inflater.inflate(R.layout.dialer, container, false);

        list_ads = new ArrayList<View>();
        indicator = (CirclePageIndicator) view.findViewById(R.id.indicator);
        // ad view
        viewpager_dialer_ads = (AutoScrollViewPager) view.findViewById(R.id.viewpager_dialer_ads);
        final BitmapUtils utils = new BitmapUtils(getActivity(), "/sdcard/Download");
        utils.configDefaultLoadFailedImage(R.drawable.default_ad);
        // image ads config
        final ImageView view1 = new ImageView(getActivity());
        final ImageView view2 = new ImageView(getActivity());
        final ImageView view3 = new ImageView(getActivity());
        //         view1.setImageResource(R.drawable.ad1);
        //         view2.setImageResource(R.drawable.ad2);
        //         view3.setImageResource(R.drawable.ad3);
        //         final ImageView view4 = new ImageView(getActivity());
        //         final ImageView view5 = new ImageView(getActivity());

        view1.setScaleType(ScaleType.FIT_XY);
        view2.setScaleType(ScaleType.FIT_XY);
        view3.setScaleType(ScaleType.FIT_XY);
        //         view4.setScaleType(ScaleType.FIT_XY);
        //         view5.setScaleType(ScaleType.FIT_XY);

        android.view.ViewGroup.LayoutParams params = new LayoutParams(
                android.view.ViewGroup.LayoutParams.MATCH_PARENT, 200);

        view1.setLayoutParams(params);
        view2.setLayoutParams(params);
        view3.setLayoutParams(params);
        //         view4.setLayoutParams(params);
        //         view5.setLayoutParams(params);

        SharedPreferences prefs = getActivity().getSharedPreferences("ads", Context.MODE_PRIVATE);
        String adsString = prefs.getString("ads", null);
        if (adsString != null && adsString.length() > 0) {
            Map<String, Object> map = JsonToMapAds.getAdsList(adsString);
            if (map != null) {
                @SuppressWarnings("unchecked")
                List<Map<String, Object>> list_pau = (List<Map<String, Object>>) map.get("list");
                if (list_pau != null && list_pau.size() > 0) {
                    list2 = list_pau;
                    handler2.post(new Runnable() {

                        @Override
                        public void run() {
                            if (list2 != null && list2.size() >= 3) {
                                utils.display(view1, (String) list2.get(0).get("content"));
                                utils.display(view2, (String) list2.get(1).get("content"));
                                utils.display(view3, (String) list2.get(2).get("content"));
                                //                           view1.setOnClickListener(new MyClickListener(
                                //                                 getActivity(), (String) list2
                                //                                       .get(0).get("url")));
                                //                           view2.setOnClickListener(new MyClickListener(
                                //                                 getActivity(), (String) list2
                                //                                       .get(1).get("url")));
                                //                           view3.setOnClickListener(new MyClickListener(
                                //                                 getActivity(), (String) list2
                                //                                       .get(2).get("url")));
                            } else {
                                view1.setImageResource(R.drawable.default_ad);
                                view2.setImageResource(R.drawable.default_ad);
                                view3.setImageResource(R.drawable.default_ad);
                            }

                        }
                    });
                }
            }

        } else {
            view1.setImageResource(R.drawable.default_ad);
            view2.setImageResource(R.drawable.default_ad);
            view3.setImageResource(R.drawable.default_ad);
        }

        list_ads.add(view1);
        list_ads.add(view2);
        list_ads.add(view3);
        //         list_ads.add(view4);
        //         list_ads.add(view5);
        viewpager_dialer_ads.setAdapter(new MyAdPagerAdapter(list_ads));
        viewpager_dialer_ads.setOffscreenPageLimit(5);

        viewpager_dialer_ads.startAutoScroll();
        viewpager_dialer_ads.setInterval(5000);
        viewpager_dialer_ads.setSlideBorderMode(2);
        indicator.setViewPager(viewpager_dialer_ads);
        mAddress = (AddressText) view.findViewById(R.id.Adress);
        mAddress.setDialerFragment(this);
        mAddress.requestFocus();
        mAddress.setVisibility(View.VISIBLE);
        // yyppdial add
        dialhint = (TextView) view.findViewById(R.id.dialhint_tv);
        if (mAddress.length() == 0) {
            android.util.Log.v("yyyppdebug", "yyppdialaddress 000");
            mAddress.setVisibility(View.GONE);
            dialhint.setVisibility(View.VISIBLE);
        } else {
            android.util.Log.v("yyyppdebug", "yyppdialaddress 111");
            mAddress.requestFocus();
            mAddress.setVisibility(View.VISIBLE);
            dialhint.setVisibility(View.GONE);
        }
        // yyppdial end
        // yypp add
        Calendar c = Calendar.getInstance();
        // int month = c.get(Calendar.MONTH);
        // int date = c.get(Calendar.DATE);
        int week = c.get(Calendar.DAY_OF_WEEK);
        if (nongli == null)
            nongli = new Lunar(c);
        // nonglistr=nongli.toString();
        gonglistr = nongli.togongliString() + " ";
        nonglistr = "" + nongli.tonongliString() + " ";

        android.util.Log.v("yyppdebug", "yyppnotice dial 000");

        msg = MSG.getnewInstance(); // yyppnotice test

        android.util.Log.v("yyppdebug", "yyppnotice dialerfragment size:" + msg.msgs.size() + "");
        int drawid[] = {
                /*
                 * R.drawable.dial_notice0_img, R.drawable.dial_notice1_img,
                 * R.drawable.dial_notice2_img, R.drawable.dial_notice3_img,
                 * R.drawable.dial_notice4_img, R.drawable.dial_notice5_img,
                 * R.drawable.dial_notice6_img
                 */
        };
        // android.util.Log.v("yyppdebug", "yypp week="+week+"");
        /*
         * RelativeLayout rLayout = (RelativeLayout)
         * view.findViewById(R.id.dialer_notice_bg); Resources res =
         * getResources(); //resource handle Drawable drawable =
         * res.getDrawable(drawid[(week-1)%7]); //new Image that was added
         * to the res folder rLayout.setBackgroundDrawable(drawable);
         */

        // yypp end

        share = PreferenceManager.getDefaultSharedPreferences(getActivity());
        Bundle bundle = getArguments();
        if (bundle != null && mAddress != null) {
            int lBegin = mAddress.getSelectionStart();

            if (lBegin == -1) {
                lBegin = mAddress.length();
            }
            phone = bundle.getString("phone");
        }
        EraseButton erase = (EraseButton) view.findViewById(R.id.Erase);
        erase.setAddressWidget(mAddress);
        mCall = (CallButton) view.findViewById(R.id.Call);
        mCall.setAddressWidget(mAddress);
        if (LinphoneActivity.isInstanciated() && LinphoneManager.getLc().getCallsNb() > 0) {
            if (isCallTransferOngoing) {
                mCall.setImageResource(R.drawable.transfer_call);
            } else {
                mCall.setImageResource(R.drawable.add_call);
            }
        } else {
            mCall.setImageResource(R.drawable.call);
        }

        AddressAware numpad = (AddressAware) view.findViewById(R.id.Dialer);
        if (numpad != null) {
            numpad.setAddressWidget(mAddress);
        }

        addContactListener = new OnClickListener() {
            @Override
            public void onClick(View v) {
                //add person to contacts 
                mylistener.onClick(mAddress.getText().toString());
                LinphoneActivity.instance().displayContactsForEdition(mAddress.getText().toString());
            }
        };
        cancelListener = new OnClickListener() {
            @Override
            public void onClick(View v) {
                LinphoneActivity.instance().resetClassicMenuLayoutAndGoBackToCallIfStillRunning();
            }
        };
        transferListener = new OnClickListener() {
            @Override
            public void onClick(View v) {
                LinphoneCore lc = LinphoneManager.getLc();
                if (lc.getCurrentCall() == null) {
                    return;
                }
                lc.transferCall(lc.getCurrentCall(), mAddress.getText().toString());
                LinphoneActivity.instance().resetClassicMenuLayoutAndGoBackToCallIfStillRunning();
                isCallTransferOngoing = false;
            }
        };

        mAddContact = (ImageView) view.findViewById(R.id.addContact);
        mAddContact
                .setEnabled(!(LinphoneActivity.isInstanciated() && LinphoneManager.getLc().getCallsNb() > 0));
        resetLayout(isCallTransferOngoing);

        if (getArguments() != null) {
            shouldEmptyAddressField = false;
            String number = getArguments().getString("SipUri");
            String displayName = getArguments().getString("DisplayName");
            String photo = getArguments().getString("PhotoUri");
            mAddress.setText(number);
            if (displayName != null) {
                mAddress.setDisplayedName(displayName);
            }
            if (photo != null) {
                mAddress.setPictureUri(Uri.parse(photo));
            }
        }
        // MATCH_PARENT WRAP_CONTENT //yyppdial.test
        /*
         * pop = new PopupWindow((getActivity().getLayoutInflater().inflate(
         * R.layout.dialer_list, null)),
         * ViewGroup.LayoutParams.WRAP_CONTENT,
         * ViewGroup.LayoutParams.WRAP_CONTENT);
         */

        pop = new PopupWindow((getActivity().getLayoutInflater().inflate(R.layout.dialer_list, null)),
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);

        if (pop != null) {
            pop.setFocusable(true);
            pop.setBackgroundDrawable(new BitmapDrawable());
            listView = (ListView) pop.getContentView().findViewById(R.id.dialer_pop_list);
        }
        if (listView != null) {
            listView.setOnItemClickListener(new OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                    mAddress.setDisplayedName(list.get(arg2).num);
                    mAddress.setText(list.get(arg2).num);
                    pop.dismiss();
                }
            });
        }

        // SpannableString str=new SpannableString("1234567890");
        // str.setSpan(new ForegroundColorSpan(Color.MAGENTA), 12, 15,
        // Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        showInfor = (ImageView) view.findViewById(R.id.dialer_infor_showimg1);
        if (showInfor != null) {
            showInfor.setOnClickListener(new OnClickListener() {
                @SuppressWarnings("unchecked")
                @Override
                public void onClick(View v) {
                    if (pop.isShowing()) {
                        pop.dismiss();
                    } else {
                        list = new CallInfor().getCallInfor((List<Contact>) ContactDB.Instance().getAllOb()[2],
                                CallsLogUtils.instance().getCallsLogs(), text);
                        if (list.size() == 0) {
                            return;
                        }
                        // yyyppset //yyppdal del
                        listView.setAdapter(new DialerListViewAdapter(getActivity(), list, text));
                        // pop.setWidth(view.getWidth());
                        pop.setWidth(view.getWidth() - 70);
                        pop.showAsDropDown(mAddress);

                        // yyppcall //yyppset add
                        /*
                         * ListAdapter madapter=new
                         * DialerListViewAdapter(getActivity(), list, text);
                         * //listView.setAdapter(new
                         * DialerListViewAdapter(getActivity(), list,
                         * text)); listView.setAdapter(madapter);
                         * 
                         * if (madapter.getCount()> 9) {
                         * pop.setHeight(view.getHeight()-60); } else {
                         * 
                         * pop.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT)
                         * ; } pop.showAsDropDown(mAddress);
                         */
                        // yyppcall end

                    }
                }
            });
        }

        String tmpstr1 = "";
        if (UserConfig.getInstance().loginstatus == 0)
            tmpstr1 = "";
        else
            tmpstr1 = "";

        //

        /*
         * if (msc != null) { msc.setOnClickListener(new OnClickListener() {
         * 
         * @Override public void onClick(View v) { SettingHelp mes = new
         * SettingHelp(); Bundle bundle = new Bundle();
         * bundle.putInt("type", SettingHelp.NOTICE);
         * mes.setArguments(bundle);
         * mes.setStyle(DialogFragment.STYLE_NO_TITLE,
         * DialogFragment.STYLE_NORMAL);
         * mes.show(getActivity().getSupportFragmentManager(), "mes"); } });
         * }
         */
        // yyppdial end
    }
    ViewGroup parent = (ViewGroup) view.getParent();
    if (parent != null) {
        parent.removeView(view);
    }

    // android.util.Log.i("xushuang", "<<<<2"+list2.toString());
    // views for ads

    return view;
}

From source file:com.mobicage.rogerthat.util.ui.SendMessageView.java

private ImageView generateImageView(final int imageButton, final int visible) {
    ImageView iv = new ImageView(mActivity);
    iv.setVisibility(visible);//from   ww w  .ja  va 2 s  . co m
    final int imageResourse = getImageResourceForKey(imageButton);
    if (imageResourse != 0)
        iv.setImageResource(imageResourse);
    iv.setOnClickListener(new SafeViewOnClickListener() {
        @Override
        public void safeOnClick(View v) {
            processOnClickListenerForKey(imageButton);
        }
    });

    if (IMAGE_BUTTON_TEXT == imageButton) {
        iv.setColorFilter(UIUtils.imageColorFilter(ContextCompat.getColor(mActivity, R.color.mc_divider_gray)));
    }

    iv.setPadding(_5_DP_IN_PX, _5_DP_IN_PX, _5_DP_IN_PX, _5_DP_IN_PX);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(_30_DP_IN_PX, _30_DP_IN_PX, 1.0f);
    iv.setLayoutParams(lp);
    return iv;
}