Example usage for android.widget ImageView getLayoutParams

List of usage examples for android.widget ImageView getLayoutParams

Introduction

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

Prototype

@ViewDebug.ExportedProperty(deepExport = true, prefix = "layout_")
public ViewGroup.LayoutParams getLayoutParams() 

Source Link

Document

Get the LayoutParams associated with this view.

Usage

From source file:mobisocial.musubi.objects.PictureObj.java

/**
 * Pass in one of raw or fd as the source of the image.
 * Not thread safe, only call on the ui thread.
 */// ww w.ja v  a 2 s.  c  o  m
protected static void bindImageToView(Context context, ImageView imageView, byte[] raw, FileDescriptor fd) {
    // recycle old images (vs. caching in ImageCache)
    if (imageView.getDrawable() != null) {
        BitmapDrawable d = (BitmapDrawable) imageView.getDrawable();
        if (d != null && d.getBitmap() != null) {
            d.getBitmap().recycle();
        }
    }

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    if (fd != null) {
        BitmapFactory.decodeFileDescriptor(fd, null, options);
    } else {
        BitmapFactory.decodeByteArray(raw, 0, raw.length, options);
    }
    Resources res = context.getResources();

    float scaleFactor;
    if (res.getBoolean(R.bool.is_tablet)) {
        scaleFactor = 3.0f;
    } else {
        scaleFactor = 2.0f;
    }
    DisplayMetrics dm = context.getResources().getDisplayMetrics();
    int pixels = dm.widthPixels;
    if (dm.heightPixels < pixels) {
        pixels = dm.heightPixels;
    }
    int width = (int) (pixels / scaleFactor);
    int height = (int) ((float) width / options.outWidth * options.outHeight);
    int max_height = (int) (AppStateObj.MAX_HEIGHT * dm.density);
    if (height > max_height) {
        width = width * max_height / height;
        height = max_height;
    }

    options.inJustDecodeBounds = false;
    options.inTempStorage = getTempData();
    options.inSampleSize = 1;
    //TODO: lame, can just compute
    while (options.outWidth / (options.inSampleSize + 1) >= width
            && options.outHeight / (options.inSampleSize + 1) >= height) {
        options.inSampleSize++;
    }
    options.inPurgeable = true;
    options.inInputShareable = true;

    Bitmap bm;
    if (fd != null) {
        bm = BitmapFactory.decodeFileDescriptor(fd, null, options);
    } else {
        bm = BitmapFactory.decodeByteArray(raw, 0, raw.length, options);
    }
    imageView.getLayoutParams().width = width + 13;
    imageView.getLayoutParams().height = height + 14;
    imageView.setImageBitmap(bm);
}

From source file:com.ndn.menurandom.ImageDownloader.java

private void makeFrameLayout(ImageView imageView) {
    boolean isExist = false;
    ViewGroup vg = (ViewGroup) imageView.getParent();
    if (vg instanceof FrameLayout) {
        FrameLayout frameLayout = (FrameLayout) vg;
        String tag = (String) frameLayout.getTag();
        if (tag != null && tag.equals("fl_imagedownloader")) {
            isExist = true;//from  www .j a  v a  2s .c o m
        }
    }

    if (!isExist) {
        int childCount = vg.getChildCount();
        int index = 0;
        while (index < childCount) {
            if (imageView == vg.getChildAt(index)) {
                break;
            }
            index++;
        }
        vg.removeViewAt(index);

        FrameLayout frameLayout = new FrameLayout(vg.getContext().getApplicationContext());
        frameLayout.setTag("fl_imagedownloader");
        ViewGroup.LayoutParams lpImageView = (ViewGroup.LayoutParams) imageView.getLayoutParams();
        frameLayout.setLayoutParams(lpImageView);
        imageView.setLayoutParams(new LayoutParams(lpImageView.width, lpImageView.height));
        frameLayout.setPadding(imageView.getPaddingLeft(), imageView.getPaddingTop(),
                imageView.getPaddingRight(), imageView.getPaddingBottom());
        imageView.setPadding(0, 0, 0, 0);
        frameLayout.addView(imageView);
        vg.addView(frameLayout, index);

        ProgressBar progressBar = new ProgressBar(frameLayout.getContext());
        progressBar.setTag("pb_imagedownloader");
        int leftRightPadding = (imageView.getLayoutParams().width - 50) / 2;
        int topBottomPadding = (imageView.getLayoutParams().height - 50) / 2;
        progressBar.setPadding(leftRightPadding, topBottomPadding, leftRightPadding, topBottomPadding);
        frameLayout.addView(progressBar);

    }
}

From source file:gidaibero.android.matsol.MatrixDisplayActivity.java

private TableRow decorateTableRow(TableRow tableRow, int height, int width, int row) {
    ImageView leftImageView = new ImageView(this);
    ImageView rightImageView = new ImageView(this);
    leftImageView.setBackgroundResource(R.drawable.left_edge);
    rightImageView.setBackgroundResource(R.drawable.right_edge);
    if (target == R.id.matrix_button) {
        // we need to allocate two more elements
        ImageView insideLeftImageView = new ImageView(this);
        ImageView insideRightImageView = new ImageView(this);
        if (row == 0) { // should change decorators for top decorators
            leftImageView.setBackgroundResource(R.drawable.top_left_edge);
            rightImageView.setBackgroundResource(R.drawable.top_right_edge);
            insideLeftImageView.setBackgroundResource(R.drawable.top_right_edge); // this is not a mistake
            insideRightImageView.setBackgroundResource(R.drawable.top_left_edge);
        } else if (row == this.height - 1) {
            leftImageView.setBackgroundResource(R.drawable.bottom_left_edge);
            rightImageView.setBackgroundResource(R.drawable.bottom_right_edge);
            insideLeftImageView.setBackgroundResource(R.drawable.bottom_right_edge); // this is not a mistake
            insideRightImageView.setBackgroundResource(R.drawable.bottom_left_edge);

        } else {//from  w  w w .  j  av  a  2  s . c  o m
            insideRightImageView.setBackgroundResource(R.drawable.left_edge);
            insideLeftImageView.setBackgroundResource(R.drawable.right_edge);
        }
        insideLeftImageView.setLayoutParams(new LayoutParams(height, width / 5));
        insideRightImageView.setLayoutParams(new LayoutParams(height, width / 5));
        insideRightImageView.getLayoutParams().height = height;
        insideLeftImageView.getLayoutParams().height = height;
        insideRightImageView.getLayoutParams().width = width / 5;
        insideLeftImageView.getLayoutParams().width = width / 5;
        tableRow.addView(insideLeftImageView, this.width - 1);
        tableRow.addView(insideRightImageView, this.width);

    } else {
        // this is a determinant button
    }
    leftImageView.setLayoutParams(new LayoutParams(height, width / 10));
    rightImageView.setLayoutParams(new LayoutParams(height, width / 10));
    leftImageView.getLayoutParams().height = height;
    rightImageView.getLayoutParams().height = height;
    leftImageView.getLayoutParams().width = width / 5;
    rightImageView.getLayoutParams().width = width / 5;
    tableRow.addView(leftImageView, 0);
    tableRow.addView(rightImageView);
    return tableRow;
}

From source file:com.mobicage.rogerthat.plugins.friends.ServiceActionMenuActivity.java

private void populateScreen(final ServiceMenu menu) {
    menuBrandingHash = menu.branding;/*from   ww w  .  j a v a 2 s  .c om*/
    final FriendsPlugin friendsPlugin = mService.getPlugin(FriendsPlugin.class);
    final MessagingPlugin messagingPlugin = mService.getPlugin(MessagingPlugin.class);
    final FriendStore store = friendsPlugin.getStore();

    List<Cell> usedCells = new ArrayList<Cell>();
    if (page == 0) {
        addAboutHandler(usedCells, menu.aboutLabel);
        addHistoryHandler(usedCells, store, menu.messagesLabel);
        addCallHandler(menu, usedCells, menu.callLabel);
        if (CloudConstants.isYSAAA()) {
            addScanHandler(menu, usedCells, null);
        } else {
            addShareHandler(menu, usedCells, menu.shareLabel);
        }
    }
    boolean[] rows = new boolean[] { false, false, false };
    if (page == 0)
        rows[0] = true;
    for (final ServiceMenuItem item : menu.itemList) {
        rows[(int) item.coords[1]] = true;
        final Cell cell = cells[(int) item.coords[0]][(int) item.coords[1]];
        View.OnClickListener onClickListener = new SafeViewOnClickListener() {
            @Override
            public void safeOnClick(View v) {
                pressMenuItem(menu, messagingPlugin, store, item);
            }
        };
        ((View) cell.icon.getParent()).setOnClickListener(onClickListener);
        cell.icon.setImageBitmap(BitmapFactory.decodeByteArray(item.icon, 0, item.icon.length));
        cell.icon.setVisibility(View.VISIBLE);
        cell.label.setText(item.label);
        cell.label.setVisibility(View.VISIBLE);
        usedCells.add(cell);
    }
    for (int i = 2; i >= 0; i--) {
        if (rows[i])
            break;
        tableRows[i].setVisibility(View.GONE);
    }
    boolean showBranded = false;
    boolean useDarkScheme = false;
    Integer menuItemColor = null;
    if (menu.branding != null) {
        try {
            BrandingMgr brandingMgr = messagingPlugin.getBrandingMgr();
            Friend friend = store.getExistingFriend(email);
            if (brandingMgr.isBrandingAvailable(menu.branding)) {
                BrandingResult br = brandingMgr.prepareBranding(menu.branding, friend, false);
                WebSettings settings = branding.getSettings();
                settings.setJavaScriptEnabled(false);
                settings.setBlockNetworkImage(false);
                branding.setVisibility(View.VISIBLE);
                branding.setVerticalScrollBarEnabled(false);

                final int displayWidth = UIUtils.getDisplayWidth(this);
                final int calculatedHeight = BrandingMgr.calculateHeight(br, displayWidth);
                final long start = System.currentTimeMillis();
                branding.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
                    @Override
                    public boolean onPreDraw() {
                        int height = branding.getMeasuredHeight();
                        if (height > calculatedHeight * 90 / 100 || System.currentTimeMillis() - start > 3000) {
                            if (calculatedHeight > 0) {
                                setBrandingHeight(height);
                            } else {
                                mService.postDelayedOnUIHandler(new SafeRunnable() {
                                    @Override
                                    protected void safeRun() throws Exception {
                                        setBrandingHeight(branding.getMeasuredHeight());
                                    }
                                }, 100);
                            }
                            branding.getViewTreeObserver().removeOnPreDrawListener(this);
                        }
                        return false;
                    }
                });
                branding.loadUrl("file://" + br.file.getAbsolutePath());

                if (br.color != null) {
                    branding.setBackgroundColor(br.color);
                    activity.setBackgroundColor(br.color);
                }
                if (br.scheme == ColorScheme.dark) {
                    for (Cell cell : usedCells) {
                        cell.label.setTextColor(darkSchemeTextColor);
                        cell.label.setShadowLayer(2, 1, 1, Color.BLACK);
                    }
                    useDarkScheme = true;
                }
                menuItemColor = br.menuItemColor;

                final ImageView watermarkView = (ImageView) findViewById(R.id.watermark);
                if (br.watermark != null) {
                    BitmapDrawable watermark = new BitmapDrawable(getResources(),
                            BitmapFactory.decodeFile(br.watermark.getAbsolutePath()));
                    watermark.setGravity(Gravity.BOTTOM | Gravity.RIGHT);

                    watermarkView.setImageDrawable(watermark);
                    final LayoutParams layoutParams = watermarkView.getLayoutParams();
                    layoutParams.width = layoutParams.height = displayWidth;
                } else {
                    watermarkView.setImageDrawable(null);
                }

                showBranded = true;
            } else {
                friend.actionMenu = menu;
                friend.actionMenu.items = menu.itemList.toArray(new ServiceMenuItemTO[] {});
                brandingMgr.queue(friend);
            }
        } catch (BrandingFailureException e) {
            L.bug("Could not display service action menu with branding.", e);
        }
    }
    if (!showBranded) {
        setNavigationBarVisible(AppConstants.SHOW_NAV_HEADER);
        setNavigationBarTitle(menu.name);
        title.setVisibility(View.GONE);
        title.setText(menu.name);
    }

    for (final Cell cell : usedCells) {
        final View p = (View) cell.icon.getParent();
        final Drawable d = getResources().getDrawable(
                useDarkScheme ? R.drawable.mc_smi_background_light : R.drawable.mc_smi_background_dark);
        p.setBackgroundDrawable(d);
    }

    if (menuItemColor == null)
        menuItemColor = Color.parseColor("#646464");

    for (Cell cell : new Cell[] { cells[0][0], cells[1][0], cells[2][0], cells[3][0] })
        cell.faIcon.setTextColor(menuItemColor);

    if (menu.maxPage > 0) {
        for (int i = 0; i <= menu.maxPage; i++) {
            ImageView bolleke = (ImageView) getLayoutInflater().inflate(R.layout.page, pages, false);
            if (page == i) {
                if (useDarkScheme) {
                    bolleke.setImageResource(R.drawable.current_page_dark);
                } else {
                    bolleke.setImageResource(R.drawable.current_page_light);
                }
            } else {
                if (useDarkScheme) {
                    bolleke.setImageResource(R.drawable.other_page_dark);
                } else {
                    bolleke.setImageResource(R.drawable.other_page_light);
                }
            }
            pages.addView(bolleke);
        }
        pages.setVisibility(View.VISIBLE);
    }
    final int leftPage = page - 1;
    final int rightPage = page + 1;
    final String service = email;
    Slider instance = new Slider(this, this, page == menu.maxPage ? null : new Slider.Swiper() {
        @Override
        public Intent onSwipe() {
            return new Intent(ServiceActionMenuActivity.this, ServiceActionMenuActivity.class)
                    .putExtra(SERVICE_EMAIL, service).putExtra(MENU_PAGE, rightPage);
        }
    }, page == 0 ? null : new Slider.Swiper() {
        @Override
        public Intent onSwipe() {
            return new Intent(ServiceActionMenuActivity.this, ServiceActionMenuActivity.class)
                    .putExtra(SERVICE_EMAIL, service).putExtra(MENU_PAGE, leftPage);
        }
    });
    mGestureScanner = new GestureDetector(this, instance);
}

From source file:jahirfiquitiva.iconshowcase.activities.ShowcaseActivity.java

@SuppressWarnings("ResourceAsColor")
private void setupDrawer(final Toolbar toolbar, Bundle savedInstanceState) {

    //Initialize PrimaryDrawerItem
    PrimaryDrawerItem home, previews, walls, requests, apply, faqs, zooper, kustom, creditsItem, settingsItem,
            donationsItem;//w w w.  ja  v  a  2s. c  o  m

    secondaryStart = primaryDrawerItems.length + 1; //marks the first identifier value that should be used

    DrawerBuilder drawerBuilder;

    if (themeMode) { //enabled theme mode, long press added
        drawerBuilder = new DrawerBuilder().withActivity(this).withToolbar(toolbar)
                .withFireOnInitialOnClick(true)
                .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {

                    @Override
                    public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
                        if (drawerItem != null) {
                            drawerItemClick(drawerItem.getIdentifier());
                        }
                        return false;
                    }
                }).withOnDrawerItemLongClickListener(new Drawer.OnDrawerItemLongClickListener() {

                    @Override
                    public boolean onItemLongClick(View view, int position, IDrawerItem drawerItem) {
                        if (drawerItem.getIdentifier() == iconsPickerIdentifier && mIsPremium) {
                            switchFragment(iconsPickerIdentifier, "Requests", context);
                            drawer.closeDrawer();
                        }
                        return false;
                    }
                });
    } else {
        drawerBuilder = new DrawerBuilder().withActivity(this).withToolbar(toolbar)
                .withFireOnInitialOnClick(true)
                .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {

                    @Override
                    public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
                        if (drawerItem != null) {
                            drawerItemClick(drawerItem.getIdentifier());
                        }
                        return false;
                    }
                });
    }

    for (int i = 0; i < primaryDrawerItems.length; i++) {
        switch (primaryDrawerItems[i]) {
        case "Main":
            home = new PrimaryDrawerItem().withName(thaHome)
                    .withIcon(Utils.getVectorDrawable(context, R.drawable.ic_home)).withIconTintingEnabled(true)
                    .withIdentifier(i + 1);
            drawerBuilder.addDrawerItems(home);
            break;

        case "Previews":
            iconsPickerEnabled = true;
            iconsPickerIdentifier = i + 1;
            previews = new PrimaryDrawerItem().withName(thaPreviews)
                    .withIcon(Utils.getVectorDrawable(context, R.drawable.ic_previews))
                    .withIconTintingEnabled(true).withIdentifier(iconsPickerIdentifier);
            drawerBuilder.addDrawerItems(previews);
            break;

        case "Wallpapers":
            wallsEnabled = true;
            wallsIdentifier = i + 1;
            walls = new PrimaryDrawerItem().withName(thaWalls)
                    .withIcon(Utils.getVectorDrawable(context, R.drawable.ic_wallpapers))
                    .withIconTintingEnabled(true).withIdentifier(wallsIdentifier);
            drawerBuilder.addDrawerItems(walls);
            break;

        case "Requests":
            requests = new PrimaryDrawerItem().withName(thaRequest)
                    .withIcon(Utils.getVectorDrawable(context, R.drawable.ic_request))
                    .withIconTintingEnabled(true).withIdentifier(i + 1);
            drawerBuilder.addDrawerItems(requests);
            break;

        case "Apply":
            applyIdentifier = i + 1;
            apply = new PrimaryDrawerItem().withName(thaApply)
                    .withIcon(Utils.getVectorDrawable(context, R.drawable.ic_apply))
                    .withIconTintingEnabled(true).withIdentifier(applyIdentifier);
            drawerBuilder.addDrawerItems(apply);
            break;

        case "FAQs":
            faqs = new PrimaryDrawerItem().withName(thaFAQs)
                    .withIcon(Utils.getVectorDrawable(context, R.drawable.ic_questions))
                    .withIconTintingEnabled(true).withIdentifier(i + 1);
            drawerBuilder.addDrawerItems(faqs);
            break;

        case "Zooper":
            WITH_ZOOPER_SECTION = true;
            zooper = new PrimaryDrawerItem().withName(thaZooper)
                    .withIcon(Utils.getVectorDrawable(context, R.drawable.ic_zooper_kustom))
                    .withIconTintingEnabled(true).withIdentifier(i + 1);
            drawerBuilder.addDrawerItems(zooper);
            break;

        case "Kustom":
            kustom = new PrimaryDrawerItem().withName(thaKustom)
                    .withIcon(Utils.getVectorDrawable(context, R.drawable.ic_zooper_kustom))
                    .withIconTintingEnabled(true).withIdentifier(i + 1);
            drawerBuilder.addDrawerItems(kustom);
        }
    }

    drawerBuilder.addDrawerItems(new DividerDrawerItem()); //divider between primary and secondary

    for (int i = 0; i < secondaryDrawerItems.length; i++) {
        switch (secondaryDrawerItems[i]) {
        case "Credits":
            creditsItem = new SecondaryDrawerItem().withName(thaCredits).withIdentifier(i + secondaryStart);
            drawerBuilder.addDrawerItems(creditsItem);
            break;
        case "Settings":
            settingsItem = new SecondaryDrawerItem().withName(thaSettings).withIdentifier(i + secondaryStart);
            drawerBuilder.addDrawerItems(settingsItem);
            break;
        case "Donations":
            donationsItem = new SecondaryDrawerItem().withName(thaDonate).withIdentifier(i + secondaryStart);
            drawerBuilder.addDrawerItems(donationsItem);
            break;
        }
    }

    drawerBuilder.withSavedInstance(savedInstanceState);

    String headerAppName = "", headerAppVersion = "";

    boolean withDrawerTexts;

    if (ENABLE_DEV_OPTIONS) {
        withDrawerTexts = mPrefs.getDevDrawerTexts();
    } else {
        withDrawerTexts = getResources().getBoolean(R.bool.with_drawer_texts);
    }

    if (withDrawerTexts) {
        headerAppName = getResources().getString(R.string.app_long_name);
        headerAppVersion = "v " + Utils.getAppVersion(this);
    }

    switch (drawerHeaderStyle) {
    case 1:
        AccountHeader drawerHeader = new AccountHeaderBuilder().withActivity(this)
                .withHeaderBackground(
                        ThemeUtils.darkTheme
                                ? ThemeUtils.transparent ? R.drawable.drawer_header_clear
                                        : R.drawable.drawer_header_dark
                                : R.drawable.drawer_header_light)
                .withSelectionFirstLine(headerAppName).withSelectionSecondLine(headerAppVersion)
                .withProfileImagesClickable(false).withResetDrawerOnProfileListClick(false)
                .withSelectionListEnabled(false).withSelectionListEnabledForSingleProfile(false)
                .withSavedInstance(savedInstanceState).build();

        drawerBuilder.withAccountHeader(drawerHeader);
        break;
    case 2:
        drawerBuilder.withHeader(R.layout.mini_drawer_header);
        break;
    case 3:
        break;
    }

    drawer = drawerBuilder.build();

    if (drawerHeaderStyle == 2) {
        ImageView miniHeader = (ImageView) drawer.getHeader().findViewById(R.id.mini_drawer_header);
        miniHeader.getLayoutParams().height = UIUtils.getActionBarHeight(this)
                + UIUtils.getStatusBarHeight(this);
        TextView appVersion = (TextView) drawer.getHeader().findViewById(R.id.text_app_version);
        TextView appName = (TextView) drawer.getHeader().findViewById(R.id.text_app_name);

        boolean miniHeaderSolidColor;

        if (ENABLE_DEV_OPTIONS) {
            miniHeaderSolidColor = !(mPrefs.getDevMiniDrawerHeaderPicture());
        } else {
            miniHeaderSolidColor = context.getResources().getBoolean(R.bool.mini_header_solid_color);
        }

        if (miniHeaderSolidColor) {
            int backgroundColor = ThemeUtils.darkTheme
                    ? ContextCompat.getColor(context, R.color.dark_theme_primary)
                    : ContextCompat.getColor(context, R.color.light_theme_primary);
            miniHeader.setBackgroundColor(backgroundColor);
            int iconsColor = ThemeUtils.darkTheme ? ContextCompat.getColor(this, R.color.toolbar_text_dark)
                    : ContextCompat.getColor(this, R.color.toolbar_text_light);
            appVersion.setTextColor(iconsColor);
            appName.setTextColor(iconsColor);
        } else {
            miniHeader.setImageDrawable(ThemeUtils.darkTheme
                    ? ThemeUtils.transparent
                            ? ContextCompat.getDrawable(context, R.drawable.drawer_header_clear)
                            : ContextCompat.getDrawable(context, R.drawable.drawer_header_dark)
                    : ContextCompat.getDrawable(context, R.drawable.drawer_header_light));
            appVersion.setTextColor(ContextCompat.getColor(context, android.R.color.white));
            appName.setTextColor(ContextCompat.getColor(context, android.R.color.white));
        }
        appName.setText(headerAppName);
        appVersion.setText(headerAppVersion);
    }

}

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);/*from www  . jav  a  2s  .co m*/
    setAvatar(avatar, ms.member);

    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:org.thoughtcrime.securesms.ProfileFragment.java

private void scaleImage(ImageView view, Bitmap bitmap) {
    Bitmap scaledBitmap = scaleCenterCrop(bitmap, dpToPx(350),
            getActivity().getWindowManager().getDefaultDisplay().getWidth());

    int width = scaledBitmap.getWidth();
    int height = scaledBitmap.getHeight();

    view.setImageDrawable(new BitmapDrawable(scaledBitmap));

    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) view.getLayoutParams();
    params.width = width;/*from ww w  .j  a  v a 2  s. co  m*/
    params.height = height;

    view.setLayoutParams(params);
}

From source file:ir.irani.telecam.ui.Components.PasscodeView.java

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

    setWillNotDraw(false);/*from ww  w  .j av  a2  s  .c om*/
    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.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);

    passwordEditText2 = new AnimatingTextView(context);
    passwordFrameLayout.addView(passwordEditText2);
    layoutParams = (FrameLayout.LayoutParams) passwordEditText2.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;
    passwordEditText2.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("");
                    passwordEditText2.eraseAllCharacters(true);
                    return true;
                }
            });
        }
        frameLayout.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                int tag = (Integer) v.getTag();
                switch (tag) {
                case 0:
                    passwordEditText2.appendCharacter("0");
                    break;
                case 1:
                    passwordEditText2.appendCharacter("1");
                    break;
                case 2:
                    passwordEditText2.appendCharacter("2");
                    break;
                case 3:
                    passwordEditText2.appendCharacter("3");
                    break;
                case 4:
                    passwordEditText2.appendCharacter("4");
                    break;
                case 5:
                    passwordEditText2.appendCharacter("5");
                    break;
                case 6:
                    passwordEditText2.appendCharacter("6");
                    break;
                case 7:
                    passwordEditText2.appendCharacter("7");
                    break;
                case 8:
                    passwordEditText2.appendCharacter("8");
                    break;
                case 9:
                    passwordEditText2.appendCharacter("9");
                    break;
                case 10:
                    passwordEditText2.eraseLastCharacter();
                    break;
                }
                if (passwordEditText2.lenght() == 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:ir.besteveryeverapp.ui.Components.PasscodeView.java

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

    setWillNotDraw(false);//from   w  w w . ja v a2 s . 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.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.setTypeface(FontManager.instance().getTypeface());
    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);

    passwordEditText2 = new AnimatingTextView(context);
    passwordFrameLayout.addView(passwordEditText2);
    layoutParams = (FrameLayout.LayoutParams) passwordEditText2.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;
    passwordEditText2.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.setTypeface(FontManager.instance().getTypeface());
        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.setTypeface(FontManager.instance().getTypeface());
        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("");
                    passwordEditText2.eraseAllCharacters(true);
                    return true;
                }
            });
        }
        frameLayout.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                int tag = (Integer) v.getTag();
                switch (tag) {
                case 0:
                    passwordEditText2.appendCharacter("0");
                    break;
                case 1:
                    passwordEditText2.appendCharacter("1");
                    break;
                case 2:
                    passwordEditText2.appendCharacter("2");
                    break;
                case 3:
                    passwordEditText2.appendCharacter("3");
                    break;
                case 4:
                    passwordEditText2.appendCharacter("4");
                    break;
                case 5:
                    passwordEditText2.appendCharacter("5");
                    break;
                case 6:
                    passwordEditText2.appendCharacter("6");
                    break;
                case 7:
                    passwordEditText2.appendCharacter("7");
                    break;
                case 8:
                    passwordEditText2.appendCharacter("8");
                    break;
                case 9:
                    passwordEditText2.appendCharacter("9");
                    break;
                case 10:
                    passwordEditText2.eraseLastCharacter();
                    break;
                }
                if (passwordEditText2.lenght() == 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:kr.wdream.ui.Components.PasscodeView.java

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

    setWillNotDraw(false);/*from  w  ww.  java 2s.  c  om*/
    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(kr.wdream.storyshop.R.drawable.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);

    passwordEditText2 = new AnimatingTextView(context);
    passwordFrameLayout.addView(passwordEditText2);
    layoutParams = (FrameLayout.LayoutParams) passwordEditText2.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;
    passwordEditText2.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(kr.wdream.storyshop.R.drawable.passcode_check);
    checkImage.setScaleType(ImageView.ScaleType.CENTER);
    checkImage.setBackgroundResource(kr.wdream.storyshop.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(kr.wdream.storyshop.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(kr.wdream.storyshop.R.drawable.bar_selector_lock);
        frameLayout.setTag(a);
        if (a == 10) {
            frameLayout.setOnLongClickListener(new OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    passwordEditText.setText("");
                    passwordEditText2.eraseAllCharacters(true);
                    return true;
                }
            });
        }
        frameLayout.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                int tag = (Integer) v.getTag();
                switch (tag) {
                case 0:
                    passwordEditText2.appendCharacter("0");
                    break;
                case 1:
                    passwordEditText2.appendCharacter("1");
                    break;
                case 2:
                    passwordEditText2.appendCharacter("2");
                    break;
                case 3:
                    passwordEditText2.appendCharacter("3");
                    break;
                case 4:
                    passwordEditText2.appendCharacter("4");
                    break;
                case 5:
                    passwordEditText2.appendCharacter("5");
                    break;
                case 6:
                    passwordEditText2.appendCharacter("6");
                    break;
                case 7:
                    passwordEditText2.appendCharacter("7");
                    break;
                case 8:
                    passwordEditText2.appendCharacter("8");
                    break;
                case 9:
                    passwordEditText2.appendCharacter("9");
                    break;
                case 10:
                    passwordEditText2.eraseLastCharacter();
                    break;
                }
                if (passwordEditText2.lenght() == 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);
    }
}