Example usage for android.widget RelativeLayout ALIGN_BOTTOM

List of usage examples for android.widget RelativeLayout ALIGN_BOTTOM

Introduction

In this page you can find the example usage for android.widget RelativeLayout ALIGN_BOTTOM.

Prototype

int ALIGN_BOTTOM

To view the source code for android.widget RelativeLayout ALIGN_BOTTOM.

Click Source Link

Document

Rule that aligns a child's bottom edge with another child's bottom edge.

Usage

From source file:com.tmall.wireless.tangram.view.BannerView.java

private void init() {
    mUltraViewPager = new UltraViewPager(getContext());
    mUltraViewPager.setId(R.id.TANGRAM_BANNER_ID);
    mIndicator = new BannerIndicator(getContext());
    addView(mUltraViewPager);/*w  w w  .j  a  v  a2  s. c o m*/
    addView(mIndicator, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    mIndicatorLayoutParams = (LayoutParams) mIndicator.getLayoutParams();
    mIndicatorLayoutParams.addRule(RelativeLayout.ALIGN_BOTTOM, R.id.TANGRAM_BANNER_ID);
    mIndicator.setPadding(mIndicatorGap, 0, 0, 0);
}

From source file:com.tmall.wireless.tangram.view.BannerView.java

public void setIndicatorPos(String isInside) {
    if ("inside".equals(isInside)) {
        if (Build.VERSION.SDK_INT >= 17) {
            mIndicatorLayoutParams.removeRule(RelativeLayout.BELOW);
        }//from w  ww  .  j  ava 2  s  .  c om
        mIndicatorLayoutParams.addRule(RelativeLayout.ALIGN_BOTTOM, R.id.TANGRAM_BANNER_ID);
    } else if ("outside".equals(isInside)) {
        if (Build.VERSION.SDK_INT >= 17) {
            mIndicatorLayoutParams.removeRule(RelativeLayout.ALIGN_BOTTOM);
        }
        mIndicatorLayoutParams.addRule(RelativeLayout.BELOW, R.id.TANGRAM_BANNER_ID);
    } else {
        if (Build.VERSION.SDK_INT >= 17) {
            mIndicatorLayoutParams.removeRule(RelativeLayout.BELOW);
        }
        mIndicatorLayoutParams.addRule(RelativeLayout.ALIGN_BOTTOM, R.id.TANGRAM_BANNER_ID);
    }
}

From source file:edu.rowan.app.carousel.CarouselFeature.java

private void setupView() {
    imageView.setId(1);/*w  w w .  j  a  v  a 2 s  .  c o  m*/
    RelativeLayout.LayoutParams imageParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.FILL_PARENT);
    imageParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
    imageView.setLayoutParams(imageParams);
    //      imageView.setAdjustViewBounds(true);
    Resources r = context.getResources();
    int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, r.getDisplayMetrics());

    TextView descriptionView = new TextView(context);
    descriptionView.setId(2);
    descriptionView.setPadding(padding, 0, padding, padding);
    descriptionView.setText(description);
    descriptionView.setBackgroundColor(Color.argb(220, 63, 26, 10));
    descriptionView.setTextColor(Color.WHITE);
    RelativeLayout.LayoutParams descParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT);
    descParams.addRule(RelativeLayout.ALIGN_BOTTOM, imageView.getId());
    carouselView.addView(descriptionView, descParams);

    TextView titleView = new TextView(context);
    titleView.setText(title);
    titleView.setPadding(padding, 0, padding, 0);
    RelativeLayout.LayoutParams titleParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    titleParams.addRule(RelativeLayout.ABOVE, descriptionView.getId());
    titleView.setLayoutParams(titleParams);
    titleView.setTextColor(Color.WHITE);
    titleView.setShadowLayer(2, 3, 3, Color.argb(230, 0, 0, 0));
    titleView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 22);

    carouselView.addView(titleView);
}

From source file:com.nickandjerry.dynamiclayoutinflator.DynamicLayoutInflator.java

@SuppressLint("NewApi")
private static void applyAttributes(View view, Map<String, String> attrs, ViewGroup parent) {
    if (viewRunnables == null)
        createViewRunnables();//from   w ww.  ja v a  2s. com
    ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
    int layoutRule;
    int marginLeft = 0, marginRight = 0, marginTop = 0, marginBottom = 0, paddingLeft = 0, paddingRight = 0,
            paddingTop = 0, paddingBottom = 0;
    boolean hasCornerRadius = false, hasCornerRadii = false;
    for (Map.Entry<String, String> entry : attrs.entrySet()) {
        String attr = entry.getKey();
        if (viewRunnables.containsKey(attr)) {
            viewRunnables.get(attr).apply(view, entry.getValue(), parent, attrs);
            continue;
        }
        if (attr.startsWith("cornerRadius")) {
            hasCornerRadius = true;
            hasCornerRadii = !attr.equals("cornerRadius");
            continue;
        }
        layoutRule = NO_LAYOUT_RULE;
        boolean layoutTarget = false;
        switch (attr) {
        case "id":
            String idValue = parseId(entry.getValue());
            if (parent != null) {
                DynamicLayoutInfo info = getDynamicLayoutInfo(parent);
                int newId = highestIdNumberUsed++;
                view.setId(newId);
                info.nameToIdNumber.put(idValue, newId);
            }
            break;
        case "width":
        case "layout_width":
            switch (entry.getValue()) {
            case "wrap_content":
                layoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;
                break;
            case "fill_parent":
            case "match_parent":
                layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
                break;
            default:
                layoutParams.width = DimensionConverter.stringToDimensionPixelSize(entry.getValue(),
                        view.getResources().getDisplayMetrics(), parent, true);
                break;
            }
            break;
        case "height":
        case "layout_height":
            switch (entry.getValue()) {
            case "wrap_content":
                layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
                break;
            case "fill_parent":
            case "match_parent":
                layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
                break;
            default:
                layoutParams.height = DimensionConverter.stringToDimensionPixelSize(entry.getValue(),
                        view.getResources().getDisplayMetrics(), parent, false);
                break;
            }
            break;
        case "layout_gravity":
            if (parent != null && parent instanceof LinearLayout) {
                ((LinearLayout.LayoutParams) layoutParams).gravity = parseGravity(entry.getValue());
            } else if (parent != null && parent instanceof FrameLayout) {
                ((FrameLayout.LayoutParams) layoutParams).gravity = parseGravity(entry.getValue());
            }
            break;
        case "layout_weight":
            if (parent != null && parent instanceof LinearLayout) {
                ((LinearLayout.LayoutParams) layoutParams).weight = Float.parseFloat(entry.getValue());
            }
            break;
        case "layout_below":
            layoutRule = RelativeLayout.BELOW;
            layoutTarget = true;
            break;
        case "layout_above":
            layoutRule = RelativeLayout.ABOVE;
            layoutTarget = true;
            break;
        case "layout_toLeftOf":
            layoutRule = RelativeLayout.LEFT_OF;
            layoutTarget = true;
            break;
        case "layout_toRightOf":
            layoutRule = RelativeLayout.RIGHT_OF;
            layoutTarget = true;
            break;
        case "layout_alignBottom":
            layoutRule = RelativeLayout.ALIGN_BOTTOM;
            layoutTarget = true;
            break;
        case "layout_alignTop":
            layoutRule = RelativeLayout.ALIGN_TOP;
            layoutTarget = true;
            break;
        case "layout_alignLeft":
        case "layout_alignStart":
            layoutRule = RelativeLayout.ALIGN_LEFT;
            layoutTarget = true;
            break;
        case "layout_alignRight":
        case "layout_alignEnd":
            layoutRule = RelativeLayout.ALIGN_RIGHT;
            layoutTarget = true;
            break;
        case "layout_alignParentBottom":
            layoutRule = RelativeLayout.ALIGN_PARENT_BOTTOM;
            break;
        case "layout_alignParentTop":
            layoutRule = RelativeLayout.ALIGN_PARENT_TOP;
            break;
        case "layout_alignParentLeft":
        case "layout_alignParentStart":
            layoutRule = RelativeLayout.ALIGN_PARENT_LEFT;
            break;
        case "layout_alignParentRight":
        case "layout_alignParentEnd":
            layoutRule = RelativeLayout.ALIGN_PARENT_RIGHT;
            break;
        case "layout_centerHorizontal":
            layoutRule = RelativeLayout.CENTER_HORIZONTAL;
            break;
        case "layout_centerVertical":
            layoutRule = RelativeLayout.CENTER_VERTICAL;
            break;
        case "layout_centerInParent":
            layoutRule = RelativeLayout.CENTER_IN_PARENT;
            break;
        case "layout_margin":
            marginLeft = marginRight = marginTop = marginBottom = DimensionConverter
                    .stringToDimensionPixelSize(entry.getValue(), view.getResources().getDisplayMetrics());
            break;
        case "layout_marginLeft":
            marginLeft = DimensionConverter.stringToDimensionPixelSize(entry.getValue(),
                    view.getResources().getDisplayMetrics(), parent, true);
            break;
        case "layout_marginTop":
            marginTop = DimensionConverter.stringToDimensionPixelSize(entry.getValue(),
                    view.getResources().getDisplayMetrics(), parent, false);
            break;
        case "layout_marginRight":
            marginRight = DimensionConverter.stringToDimensionPixelSize(entry.getValue(),
                    view.getResources().getDisplayMetrics(), parent, true);
            break;
        case "layout_marginBottom":
            marginBottom = DimensionConverter.stringToDimensionPixelSize(entry.getValue(),
                    view.getResources().getDisplayMetrics(), parent, false);
            break;
        case "padding":
            paddingBottom = paddingLeft = paddingRight = paddingTop = DimensionConverter
                    .stringToDimensionPixelSize(entry.getValue(), view.getResources().getDisplayMetrics());
            break;
        case "paddingLeft":
            paddingLeft = DimensionConverter.stringToDimensionPixelSize(entry.getValue(),
                    view.getResources().getDisplayMetrics());
            break;
        case "paddingTop":
            paddingTop = DimensionConverter.stringToDimensionPixelSize(entry.getValue(),
                    view.getResources().getDisplayMetrics());
            break;
        case "paddingRight":
            paddingRight = DimensionConverter.stringToDimensionPixelSize(entry.getValue(),
                    view.getResources().getDisplayMetrics());
            break;
        case "paddingBottom":
            paddingBottom = DimensionConverter.stringToDimensionPixelSize(entry.getValue(),
                    view.getResources().getDisplayMetrics());
            break;

        }
        if (layoutRule != NO_LAYOUT_RULE && parent instanceof RelativeLayout) {
            if (layoutTarget) {
                int anchor = idNumFromIdString(parent, parseId(entry.getValue()));
                ((RelativeLayout.LayoutParams) layoutParams).addRule(layoutRule, anchor);
            } else if (entry.getValue().equals("true")) {
                ((RelativeLayout.LayoutParams) layoutParams).addRule(layoutRule);
            }
        }
    }
    // TODO: this is a giant mess; come up with a simpler way of deciding what to draw for the background
    if (attrs.containsKey("background") || attrs.containsKey("borderColor")) {
        String bgValue = attrs.containsKey("background") ? attrs.get("background") : null;
        if (bgValue != null && bgValue.startsWith("@drawable/")) {
            view.setBackground(getDrawableByName(view, bgValue));
        } else if (bgValue == null || bgValue.startsWith("#") || bgValue.startsWith("@color")) {
            if (view instanceof Button || attrs.containsKey("pressedColor")) {
                int bgColor = parseColor(view, bgValue == null ? "#00000000" : bgValue);
                int pressedColor;
                if (attrs.containsKey("pressedColor")) {
                    pressedColor = parseColor(view, attrs.get("pressedColor"));
                } else {
                    pressedColor = adjustBrightness(bgColor, 0.9f);
                }
                GradientDrawable gd = new GradientDrawable();
                gd.setColor(bgColor);
                GradientDrawable pressedGd = new GradientDrawable();
                pressedGd.setColor(pressedColor);
                if (hasCornerRadii) {
                    float radii[] = new float[8];
                    for (int i = 0; i < CORNERS.length; i++) {
                        String corner = CORNERS[i];
                        if (attrs.containsKey("cornerRadius" + corner)) {
                            radii[i * 2] = radii[i * 2 + 1] = DimensionConverter.stringToDimension(
                                    attrs.get("cornerRadius" + corner),
                                    view.getResources().getDisplayMetrics());
                        }
                        gd.setCornerRadii(radii);
                        pressedGd.setCornerRadii(radii);
                    }
                } else if (hasCornerRadius) {
                    float cornerRadius = DimensionConverter.stringToDimension(attrs.get("cornerRadius"),
                            view.getResources().getDisplayMetrics());
                    gd.setCornerRadius(cornerRadius);
                    pressedGd.setCornerRadius(cornerRadius);
                }
                if (attrs.containsKey("borderColor")) {
                    String borderWidth = "1dp";
                    if (attrs.containsKey("borderWidth")) {
                        borderWidth = attrs.get("borderWidth");
                    }
                    int borderWidthPx = DimensionConverter.stringToDimensionPixelSize(borderWidth,
                            view.getResources().getDisplayMetrics());
                    gd.setStroke(borderWidthPx, parseColor(view, attrs.get("borderColor")));
                    pressedGd.setStroke(borderWidthPx, parseColor(view, attrs.get("borderColor")));
                }
                StateListDrawable selector = new StateListDrawable();
                selector.addState(new int[] { android.R.attr.state_pressed }, pressedGd);
                selector.addState(new int[] {}, gd);
                view.setBackground(selector);
                getDynamicLayoutInfo(view).bgDrawable = gd;
            } else if (hasCornerRadius || attrs.containsKey("borderColor")) {
                GradientDrawable gd = new GradientDrawable();
                int bgColor = parseColor(view, bgValue == null ? "#00000000" : bgValue);
                gd.setColor(bgColor);
                if (hasCornerRadii) {
                    float radii[] = new float[8];
                    for (int i = 0; i < CORNERS.length; i++) {
                        String corner = CORNERS[i];
                        if (attrs.containsKey("cornerRadius" + corner)) {
                            radii[i * 2] = radii[i * 2 + 1] = DimensionConverter.stringToDimension(
                                    attrs.get("cornerRadius" + corner),
                                    view.getResources().getDisplayMetrics());
                        }
                        gd.setCornerRadii(radii);
                    }
                } else if (hasCornerRadius) {
                    float cornerRadius = DimensionConverter.stringToDimension(attrs.get("cornerRadius"),
                            view.getResources().getDisplayMetrics());
                    gd.setCornerRadius(cornerRadius);
                }
                if (attrs.containsKey("borderColor")) {
                    String borderWidth = "1dp";
                    if (attrs.containsKey("borderWidth")) {
                        borderWidth = attrs.get("borderWidth");
                    }
                    gd.setStroke(
                            DimensionConverter.stringToDimensionPixelSize(borderWidth,
                                    view.getResources().getDisplayMetrics()),
                            parseColor(view, attrs.get("borderColor")));
                }
                view.setBackground(gd);
                getDynamicLayoutInfo(view).bgDrawable = gd;
            } else {
                view.setBackgroundColor(parseColor(view, bgValue));
            }
        }
    }

    if (layoutParams instanceof ViewGroup.MarginLayoutParams) {
        ((ViewGroup.MarginLayoutParams) layoutParams).setMargins(marginLeft, marginTop, marginRight,
                marginBottom);
    }
    view.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
    view.setLayoutParams(layoutParams);
}

From source file:com.esri.squadleader.view.SquadLeaderActivity.java

private void adjustLayoutForOrientation(int orientation) {
    View displayView = findViewById(R.id.tableLayout_display);
    if (displayView.getLayoutParams() instanceof RelativeLayout.LayoutParams) {
        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) displayView.getLayoutParams();
        switch (orientation) {
        case Configuration.ORIENTATION_LANDSCAPE: {
            params.addRule(RelativeLayout.RIGHT_OF, R.id.toggleButton_grid);
            params.addRule(RelativeLayout.LEFT_OF, R.id.toggleButton_followMe);
            params.addRule(RelativeLayout.ALIGN_BOTTOM, R.id.imageButton_zoomOut);
            params.addRule(RelativeLayout.ABOVE, -1);
            break;
        }/*from w ww.  ja v a 2s  .  c o m*/
        case Configuration.ORIENTATION_PORTRAIT:
        default: {
            params.addRule(RelativeLayout.RIGHT_OF, -1);
            params.addRule(RelativeLayout.LEFT_OF, R.id.imageButton_zoomIn);
            params.addRule(RelativeLayout.ALIGN_BOTTOM, R.id.imageButton_zoomIn);
            params.addRule(RelativeLayout.ABOVE, R.id.toggleButton_grid);
        }
        }
        displayView.setLayoutParams(params);
    }
}

From source file:kr.wdream.ui.Components.PasscodeView.java

private void checkFingerprint() {
    Activity parentActivity = (Activity) getContext();
    if (Build.VERSION.SDK_INT >= 23 && parentActivity != null && UserConfig.useFingerprint
            && !ApplicationLoader.mainInterfacePaused) {
        try {//from  www.j a  v a2s  .  c  o m
            if (fingerprintDialog != null && fingerprintDialog.isShowing()) {
                return;
            }
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }
        try {
            FingerprintManagerCompat fingerprintManager = FingerprintManagerCompat
                    .from(ApplicationLoader.applicationContext);
            if (fingerprintManager.isHardwareDetected() && fingerprintManager.hasEnrolledFingerprints()) {
                RelativeLayout relativeLayout = new RelativeLayout(getContext());
                relativeLayout.setPadding(AndroidUtilities.dp(24), AndroidUtilities.dp(16),
                        AndroidUtilities.dp(24), AndroidUtilities.dp(8));

                TextView fingerprintTextView = new TextView(getContext());
                fingerprintTextView.setTextColor(0xff939393);
                fingerprintTextView.setId(id_fingerprint_textview);
                fingerprintTextView.setTextAppearance(android.R.style.TextAppearance_Material_Subhead);
                fingerprintTextView.setText(LocaleController.getString("FingerprintInfo",
                        kr.wdream.storyshop.R.string.FingerprintInfo));
                relativeLayout.addView(fingerprintTextView);
                RelativeLayout.LayoutParams layoutParams = LayoutHelper
                        .createRelative(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT);
                layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
                layoutParams.addRule(RelativeLayout.ALIGN_PARENT_START);
                fingerprintTextView.setLayoutParams(layoutParams);

                fingerprintImageView = new ImageView(getContext());
                fingerprintImageView.setImageResource(kr.wdream.storyshop.R.drawable.ic_fp_40px);
                fingerprintImageView.setId(id_fingerprint_imageview);
                relativeLayout.addView(fingerprintImageView,
                        LayoutHelper.createRelative(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, 0, 20,
                                0, 0, RelativeLayout.ALIGN_PARENT_START, RelativeLayout.BELOW,
                                id_fingerprint_textview));

                fingerprintStatusTextView = new TextView(getContext());
                fingerprintStatusTextView.setGravity(Gravity.CENTER_VERTICAL);
                fingerprintStatusTextView.setText(LocaleController.getString("FingerprintHelp",
                        kr.wdream.storyshop.R.string.FingerprintHelp));
                fingerprintStatusTextView.setTextAppearance(android.R.style.TextAppearance_Material_Body1);
                fingerprintStatusTextView.setTextColor(0x42000000);
                relativeLayout.addView(fingerprintStatusTextView);
                layoutParams = LayoutHelper.createRelative(LayoutHelper.WRAP_CONTENT,
                        LayoutHelper.WRAP_CONTENT);
                layoutParams.setMarginStart(AndroidUtilities.dp(16));
                layoutParams.addRule(RelativeLayout.ALIGN_BOTTOM, id_fingerprint_imageview);
                layoutParams.addRule(RelativeLayout.ALIGN_TOP, id_fingerprint_imageview);
                layoutParams.addRule(RelativeLayout.END_OF, id_fingerprint_imageview);
                fingerprintStatusTextView.setLayoutParams(layoutParams);

                AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
                builder.setTitle(LocaleController.getString("AppName", kr.wdream.storyshop.R.string.AppName));
                builder.setView(relativeLayout);
                builder.setNegativeButton(
                        LocaleController.getString("Cancel", kr.wdream.storyshop.R.string.Cancel), null);
                builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
                    @Override
                    public void onDismiss(DialogInterface dialog) {
                        if (cancellationSignal != null) {
                            selfCancelled = true;
                            cancellationSignal.cancel();
                            cancellationSignal = null;
                        }
                    }
                });
                if (fingerprintDialog != null) {
                    try {
                        if (fingerprintDialog.isShowing()) {
                            fingerprintDialog.dismiss();
                        }
                    } catch (Exception e) {
                        FileLog.e("tmessages", e);
                    }
                }
                fingerprintDialog = builder.show();

                cancellationSignal = new CancellationSignal();
                selfCancelled = false;
                fingerprintManager.authenticate(null, 0, cancellationSignal,
                        new FingerprintManagerCompat.AuthenticationCallback() {
                            @Override
                            public void onAuthenticationError(int errMsgId, CharSequence errString) {
                                if (!selfCancelled) {
                                    showFingerprintError(errString);
                                }
                            }

                            @Override
                            public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) {
                                showFingerprintError(helpString);
                            }

                            @Override
                            public void onAuthenticationFailed() {
                                showFingerprintError(LocaleController.getString("FingerprintNotRecognized",
                                        kr.wdream.storyshop.R.string.FingerprintNotRecognized));
                            }

                            @Override
                            public void onAuthenticationSucceeded(
                                    FingerprintManagerCompat.AuthenticationResult result) {
                                try {
                                    if (fingerprintDialog.isShowing()) {
                                        fingerprintDialog.dismiss();
                                    }
                                } catch (Exception e) {
                                    FileLog.e("tmessages", e);
                                }
                                fingerprintDialog = null;
                                processDone(true);
                            }
                        }, null);
            }
        } catch (Throwable e) {
            //ignore
        }
    }
}

From source file:ir.besteveryeverapp.ui.Components.PasscodeView.java

private void checkFingerprint() {
    Activity parentActivity = (Activity) getContext();
    if (Build.VERSION.SDK_INT >= 23 && parentActivity != null && UserConfig.useFingerprint
            && !ApplicationLoader.mainInterfacePaused) {
        try {//  ww w .j  av  a 2 s . com
            if (fingerprintDialog != null && fingerprintDialog.isShowing()) {
                return;
            }
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }
        try {
            FingerprintManagerCompat fingerprintManager = FingerprintManagerCompat
                    .from(ApplicationLoader.applicationContext);
            if (fingerprintManager.isHardwareDetected() && fingerprintManager.hasEnrolledFingerprints()) {
                RelativeLayout relativeLayout = new RelativeLayout(getContext());
                relativeLayout.setPadding(AndroidUtilities.dp(24), AndroidUtilities.dp(16),
                        AndroidUtilities.dp(24), AndroidUtilities.dp(8));

                TextView fingerprintTextView = new TextView(getContext());
                fingerprintTextView.setTypeface(FontManager.instance().getTypeface());
                fingerprintTextView.setTextColor(0xff939393);
                fingerprintTextView.setId(id_fingerprint_textview);
                fingerprintTextView.setTextAppearance(android.R.style.TextAppearance_Material_Subhead);
                fingerprintTextView
                        .setText(LocaleController.getString("FingerprintInfo", R.string.FingerprintInfo));
                relativeLayout.addView(fingerprintTextView);
                RelativeLayout.LayoutParams layoutParams = LayoutHelper
                        .createRelative(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT);
                layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
                layoutParams.addRule(RelativeLayout.ALIGN_PARENT_START);
                fingerprintTextView.setLayoutParams(layoutParams);

                fingerprintImageView = new ImageView(getContext());
                fingerprintImageView.setImageResource(R.drawable.ic_fp_40px);
                fingerprintImageView.setId(id_fingerprint_imageview);
                relativeLayout.addView(fingerprintImageView,
                        LayoutHelper.createRelative(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, 0, 20,
                                0, 0, RelativeLayout.ALIGN_PARENT_START, RelativeLayout.BELOW,
                                id_fingerprint_textview));

                fingerprintStatusTextView = new TextView(getContext());
                fingerprintStatusTextView.setTypeface(FontManager.instance().getTypeface());
                fingerprintStatusTextView.setGravity(Gravity.CENTER_VERTICAL);
                fingerprintStatusTextView
                        .setText(LocaleController.getString("FingerprintHelp", R.string.FingerprintHelp));
                fingerprintStatusTextView.setTextAppearance(android.R.style.TextAppearance_Material_Body1);
                fingerprintStatusTextView.setTextColor(0x42000000);
                relativeLayout.addView(fingerprintStatusTextView);
                layoutParams = LayoutHelper.createRelative(LayoutHelper.WRAP_CONTENT,
                        LayoutHelper.WRAP_CONTENT);
                layoutParams.setMarginStart(AndroidUtilities.dp(16));
                layoutParams.addRule(RelativeLayout.ALIGN_BOTTOM, id_fingerprint_imageview);
                layoutParams.addRule(RelativeLayout.ALIGN_TOP, id_fingerprint_imageview);
                layoutParams.addRule(RelativeLayout.END_OF, id_fingerprint_imageview);
                fingerprintStatusTextView.setLayoutParams(layoutParams);

                AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
                builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                builder.setView(relativeLayout);
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
                    @Override
                    public void onDismiss(DialogInterface dialog) {
                        if (cancellationSignal != null) {
                            selfCancelled = true;
                            cancellationSignal.cancel();
                            cancellationSignal = null;
                        }
                    }
                });
                if (fingerprintDialog != null) {
                    try {
                        if (fingerprintDialog.isShowing()) {
                            fingerprintDialog.dismiss();
                        }
                    } catch (Exception e) {
                        FileLog.e("tmessages", e);
                    }
                }
                fingerprintDialog = builder.show();

                cancellationSignal = new CancellationSignal();
                selfCancelled = false;
                fingerprintManager.authenticate(null, 0, cancellationSignal,
                        new FingerprintManagerCompat.AuthenticationCallback() {
                            @Override
                            public void onAuthenticationError(int errMsgId, CharSequence errString) {
                                if (!selfCancelled) {
                                    showFingerprintError(errString);
                                }
                            }

                            @Override
                            public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) {
                                showFingerprintError(helpString);
                            }

                            @Override
                            public void onAuthenticationFailed() {
                                showFingerprintError(LocaleController.getString("FingerprintNotRecognized",
                                        R.string.FingerprintNotRecognized));
                            }

                            @Override
                            public void onAuthenticationSucceeded(
                                    FingerprintManagerCompat.AuthenticationResult result) {
                                try {
                                    if (fingerprintDialog.isShowing()) {
                                        fingerprintDialog.dismiss();
                                    }
                                } catch (Exception e) {
                                    FileLog.e("tmessages", e);
                                }
                                fingerprintDialog = null;
                                processDone(true);
                            }
                        }, null);
            }
        } catch (Throwable e) {
            //ignore
        }
    }
}

From source file:com.goftagram.telegram.ui.Components.PasscodeView.java

private void checkFingerprint() {
    Activity parentActivity = (Activity) getContext();
    if (Build.VERSION.SDK_INT >= 23 && parentActivity != null && UserConfig.useFingerprint
            && !ApplicationLoader.mainInterfacePaused) {
        try {// w w w.j  a v a  2 s  . c  o m
            if (fingerprintDialog != null && fingerprintDialog.isShowing()) {
                return;
            }
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }
        try {
            FingerprintManagerCompat fingerprintManager = FingerprintManagerCompat
                    .from(ApplicationLoader.applicationContext);
            if (fingerprintManager.isHardwareDetected() && fingerprintManager.hasEnrolledFingerprints()) {
                RelativeLayout relativeLayout = new RelativeLayout(getContext());
                relativeLayout.setPadding(AndroidUtilities.dp(24), AndroidUtilities.dp(16),
                        AndroidUtilities.dp(24), AndroidUtilities.dp(8));

                TextView fingerprintTextView = new TextView(getContext());
                fingerprintTextView.setTextColor(0xff939393);
                fingerprintTextView.setId(id_fingerprint_textview);
                fingerprintTextView.setTextAppearance(android.R.style.TextAppearance_Material_Subhead);
                fingerprintTextView
                        .setText(LocaleController.getString("FingerprintInfo", R.string.FingerprintInfo));
                relativeLayout.addView(fingerprintTextView);
                RelativeLayout.LayoutParams layoutParams = LayoutHelper
                        .createRelative(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT);
                layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
                layoutParams.addRule(RelativeLayout.ALIGN_PARENT_START);
                fingerprintTextView.setLayoutParams(layoutParams);

                fingerprintImageView = new ImageView(getContext());
                fingerprintImageView.setImageResource(R.drawable.ic_fp_40px);
                fingerprintImageView.setId(id_fingerprint_imageview);
                relativeLayout.addView(fingerprintImageView,
                        LayoutHelper.createRelative(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, 0, 20,
                                0, 0, RelativeLayout.ALIGN_PARENT_START, RelativeLayout.BELOW,
                                id_fingerprint_textview));

                fingerprintStatusTextView = new TextView(getContext());
                fingerprintStatusTextView.setGravity(Gravity.CENTER_VERTICAL);
                fingerprintStatusTextView
                        .setText(LocaleController.getString("FingerprintHelp", R.string.FingerprintHelp));
                fingerprintStatusTextView.setTextAppearance(android.R.style.TextAppearance_Material_Body1);
                fingerprintStatusTextView.setTextColor(0x42000000);
                relativeLayout.addView(fingerprintStatusTextView);
                layoutParams = LayoutHelper.createRelative(LayoutHelper.WRAP_CONTENT,
                        LayoutHelper.WRAP_CONTENT);
                layoutParams.setMarginStart(AndroidUtilities.dp(16));
                layoutParams.addRule(RelativeLayout.ALIGN_BOTTOM, id_fingerprint_imageview);
                layoutParams.addRule(RelativeLayout.ALIGN_TOP, id_fingerprint_imageview);
                layoutParams.addRule(RelativeLayout.END_OF, id_fingerprint_imageview);
                fingerprintStatusTextView.setLayoutParams(layoutParams);

                AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
                builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                builder.setView(relativeLayout);
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
                    @Override
                    public void onDismiss(DialogInterface dialog) {
                        if (cancellationSignal != null) {
                            selfCancelled = true;
                            cancellationSignal.cancel();
                            cancellationSignal = null;
                        }
                    }
                });
                if (fingerprintDialog != null) {
                    try {
                        if (fingerprintDialog.isShowing()) {
                            fingerprintDialog.dismiss();
                        }
                    } catch (Exception e) {
                        FileLog.e("tmessages", e);
                    }
                }
                fingerprintDialog = builder.show();

                cancellationSignal = new CancellationSignal();
                selfCancelled = false;
                fingerprintManager.authenticate(null, 0, cancellationSignal,
                        new FingerprintManagerCompat.AuthenticationCallback() {
                            @Override
                            public void onAuthenticationError(int errMsgId, CharSequence errString) {
                                if (!selfCancelled) {
                                    showFingerprintError(errString);
                                }
                            }

                            @Override
                            public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) {
                                showFingerprintError(helpString);
                            }

                            @Override
                            public void onAuthenticationFailed() {
                                showFingerprintError(LocaleController.getString("FingerprintNotRecognized",
                                        R.string.FingerprintNotRecognized));
                            }

                            @Override
                            public void onAuthenticationSucceeded(
                                    FingerprintManagerCompat.AuthenticationResult result) {
                                try {
                                    if (fingerprintDialog.isShowing()) {
                                        fingerprintDialog.dismiss();
                                    }
                                } catch (Exception e) {
                                    FileLog.e("tmessages", e);
                                }
                                fingerprintDialog = null;
                                processDone(true);
                            }
                        }, null);
            }
        } catch (Throwable e) {
            //ignore
        }
    }
}