Example usage for android.view Gravity CENTER_VERTICAL

List of usage examples for android.view Gravity CENTER_VERTICAL

Introduction

In this page you can find the example usage for android.view Gravity CENTER_VERTICAL.

Prototype

int CENTER_VERTICAL

To view the source code for android.view Gravity CENTER_VERTICAL.

Click Source Link

Document

Place object in the vertical center of its container, not changing its size.

Usage

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  ava2 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.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:com.hichinaschool.flashcards.anki.CardEditor.java

@Override
protected Dialog onCreateDialog(int id) {
    StyledDialog dialog = null;//from  w w w  .  jav  a  2 s.com
    Resources res = getResources();
    StyledDialog.Builder builder = new StyledDialog.Builder(this);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    return dialog;
}

From source file: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 {//from w  w w . ja  va  2 s  .co  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.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.android.incallui.widget.multiwaveview.GlowPadView.java

private void computeInsets(int dx, int dy) {
    final int layoutDirection = getLayoutDirection();
    final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity, layoutDirection);

    switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
    case Gravity.LEFT:
        mHorizontalInset = 0;//from www .j a va  2  s  .c  om
        break;
    case Gravity.RIGHT:
        mHorizontalInset = dx;
        break;
    case Gravity.CENTER_HORIZONTAL:
    default:
        mHorizontalInset = dx / 2;
        break;
    }
    switch (absoluteGravity & Gravity.VERTICAL_GRAVITY_MASK) {
    case Gravity.TOP:
        mVerticalInset = 0;
        break;
    case Gravity.BOTTOM:
        mVerticalInset = dy;
        break;
    case Gravity.CENTER_VERTICAL:
    default:
        mVerticalInset = dy / 2;
        break;
    }
}

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 {/*from ww w  . j  ava 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
        }
    }
}

From source file:android.support.design.widget.CoordinatorLayout.java

private void getDesiredAnchoredChildRectWithoutConstraints(View child, int layoutDirection, Rect anchorRect,
        Rect out, LayoutParams lp, int childWidth, int childHeight) {
    final int absGravity = GravityCompat.getAbsoluteGravity(resolveAnchoredChildGravity(lp.gravity),
            layoutDirection);/* w w w  . j a  va2s  .co  m*/
    final int absAnchorGravity = GravityCompat.getAbsoluteGravity(resolveGravity(lp.anchorGravity),
            layoutDirection);

    final int hgrav = absGravity & Gravity.HORIZONTAL_GRAVITY_MASK;
    final int vgrav = absGravity & Gravity.VERTICAL_GRAVITY_MASK;
    final int anchorHgrav = absAnchorGravity & Gravity.HORIZONTAL_GRAVITY_MASK;
    final int anchorVgrav = absAnchorGravity & Gravity.VERTICAL_GRAVITY_MASK;

    int left;
    int top;

    // Align to the anchor. This puts us in an assumed right/bottom child view gravity.
    // If this is not the case we will subtract out the appropriate portion of
    // the child size below.
    switch (anchorHgrav) {
    default:
    case Gravity.LEFT:
        left = anchorRect.left;
        break;
    case Gravity.RIGHT:
        left = anchorRect.right;
        break;
    case Gravity.CENTER_HORIZONTAL:
        left = anchorRect.left + anchorRect.width() / 2;
        break;
    }

    switch (anchorVgrav) {
    default:
    case Gravity.TOP:
        top = anchorRect.top;
        break;
    case Gravity.BOTTOM:
        top = anchorRect.bottom;
        break;
    case Gravity.CENTER_VERTICAL:
        top = anchorRect.top + anchorRect.height() / 2;
        break;
    }

    // Offset by the child view's gravity itself. The above assumed right/bottom gravity.
    switch (hgrav) {
    default:
    case Gravity.LEFT:
        left -= childWidth;
        break;
    case Gravity.RIGHT:
        // Do nothing, we're already in position.
        break;
    case Gravity.CENTER_HORIZONTAL:
        left -= childWidth / 2;
        break;
    }

    switch (vgrav) {
    default:
    case Gravity.TOP:
        top -= childHeight;
        break;
    case Gravity.BOTTOM:
        // Do nothing, we're already in position.
        break;
    case Gravity.CENTER_VERTICAL:
        top -= childHeight / 2;
        break;
    }

    out.set(left, top, left + childWidth, top + childHeight);
}

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

public void excecutePositiveButtonClick() {
    for (final ButtonTO button : mCurrentMessage.buttons) {
        if (Message.POSITIVE.equals(button.id)) {
            final LinearLayout container = (LinearLayout) getLayoutInflater()
                    .inflate(R.layout.message_button_detail, null);
            container.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);

            executeButtonClick(button, container, true);
            break;
        }//  w  w  w.  ja v a2s  .  c om
    }
}

From source file:com.android.incallui.widget.multiwaveview.GlowPadView.java

/**
 * Given the desired width and height of the ring and the allocated width and height, compute
 * how much we need to scale the ring.//from  w  w w .  j av a2 s .co m
 */
private float computeScaleFactor(int desiredWidth, int desiredHeight, int actualWidth, int actualHeight) {

    // Return unity if scaling is not allowed.
    if (!mAllowScaling)
        return 1f;

    final int layoutDirection = getLayoutDirection();
    final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity, layoutDirection);

    float scaleX = 1f;
    float scaleY = 1f;

    // We use the gravity as a cue for whether we want to scale on a particular axis.
    // We only scale to fit horizontally if we're not pinned to the left or right. Likewise,
    // we only scale to fit vertically if we're not pinned to the top or bottom. In these
    // cases, we want the ring to hang off the side or top/bottom, respectively.
    switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
    case Gravity.LEFT:
    case Gravity.RIGHT:
        break;
    case Gravity.CENTER_HORIZONTAL:
    default:
        if (desiredWidth > actualWidth) {
            scaleX = (1f * actualWidth - mMaxTargetWidth) / (desiredWidth - mMaxTargetWidth);
        }
        break;
    }
    switch (absoluteGravity & Gravity.VERTICAL_GRAVITY_MASK) {
    case Gravity.TOP:
    case Gravity.BOTTOM:
        break;
    case Gravity.CENTER_VERTICAL:
    default:
        if (desiredHeight > actualHeight) {
            scaleY = (1f * actualHeight - mMaxTargetHeight) / (desiredHeight - mMaxTargetHeight);
        }
        break;
    }
    return Math.min(scaleX, scaleY);
}

From source file:org.telepatch.ui.ChatActivity.java

public View createView(LayoutInflater inflater, ViewGroup container) {
    if (fragmentView == null) {
        actionBarLayer.setDisplayHomeAsUpEnabled(true, R.drawable.ic_ab_back);
        if (AndroidUtilities.isTablet()) {
            actionBarLayer.setExtraLeftMargin(4);
        }/*from  ww w .  ja v a2s  .  co m*/
        actionBarLayer.setBackOverlay(R.layout.updating_state_layout);
        actionBarLayer.setActionBarMenuOnItemClick(new ActionBarLayer.ActionBarMenuOnItemClick() {
            @Override
            public void onItemClick(int id) {
                if (id == -1) {
                    finishFragment();
                } else if (id == -2) {
                    selectedMessagesIds.clear();
                    selectedMessagesCanCopyIds.clear();
                    actionBarLayer.hideActionMode();
                    updateVisibleRows();
                } else if (id == attach_photo) {
                    try {
                        Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                        File image = Utilities.generatePicturePath();
                        if (image != null) {
                            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image));
                            currentPicturePath = image.getAbsolutePath();
                        }
                        startActivityForResult(takePictureIntent, 0);
                    } catch (Exception e) {
                        FileLog.e("tmessages", e);
                    }
                } else if (id == attach_gallery) {
                    PhotoPickerActivity fragment = new PhotoPickerActivity();
                    fragment.setDelegate(new PhotoPickerActivity.PhotoPickerActivityDelegate() {
                        @Override
                        public void didSelectPhotos(ArrayList<String> photos) {
                            SendMessagesHelper.prepareSendingPhotos(photos, null, dialog_id);
                        }

                        @Override
                        public void startPhotoSelectActivity() {
                            try {
                                Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
                                photoPickerIntent.setType("image/*");
                                startActivityForResult(photoPickerIntent, 1);
                            } catch (Exception e) {
                                FileLog.e("tmessages", e);
                            }
                        }
                    });
                    presentFragment(fragment);
                } else if (id == attach_video) {
                    try {
                        Intent pickIntent = new Intent();
                        pickIntent.setType("video/*");
                        pickIntent.setAction(Intent.ACTION_GET_CONTENT);
                        pickIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, (long) (1024 * 1024 * 1000));
                        Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
                        File video = Utilities.generateVideoPath();
                        if (video != null) {
                            if (Build.VERSION.SDK_INT >= 18) {
                                takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(video));
                            }
                            takeVideoIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, (long) (1024 * 1024 * 1000));
                            currentPicturePath = video.getAbsolutePath();
                        }
                        Intent chooserIntent = Intent.createChooser(pickIntent, "");
                        chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { takeVideoIntent });

                        startActivityForResult(chooserIntent, 2);
                    } catch (Exception e) {
                        FileLog.e("tmessages", e);
                    }
                } else if (id == attach_location) {
                    if (!isGoogleMapsInstalled()) {
                        return;
                    }
                    LocationActivity fragment = new LocationActivity();
                    fragment.setDelegate(new LocationActivity.LocationActivityDelegate() {
                        @Override
                        public void didSelectLocation(double latitude, double longitude) {
                            SendMessagesHelper.getInstance().sendMessage(latitude, longitude, dialog_id);
                            if (chatListView != null) {
                                chatListView.setSelectionFromTop(messages.size() - 1,
                                        -100000 - chatListView.getPaddingTop());
                            }
                            if (paused) {
                                scrollToTopOnResume = true;
                            }
                        }
                    });
                    presentFragment(fragment);
                } else if (id == attach_document) {
                    DocumentSelectActivity fragment = new DocumentSelectActivity();
                    fragment.setDelegate(new DocumentSelectActivity.DocumentSelectActivityDelegate() {
                        @Override
                        public void didSelectFile(DocumentSelectActivity activity, String path) {
                            activity.finishFragment();
                            SendMessagesHelper.prepareSendingDocument(path, path, dialog_id);
                        }

                        @Override
                        public void startDocumentSelectActivity() {
                            try {
                                Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
                                photoPickerIntent.setType("*/*");
                                startActivityForResult(photoPickerIntent, 21);
                            } catch (Exception e) {
                                FileLog.e("tmessages", e);
                            }
                        }
                    });
                    presentFragment(fragment);
                } else if (id == chat_menu_avatar) {
                    if (currentUser != null) {
                        Bundle args = new Bundle();
                        args.putInt("user_id", currentUser.id);
                        if (currentEncryptedChat != null) {
                            args.putLong("dialog_id", dialog_id);
                        }
                        presentFragment(new UserProfileActivity(args));
                    } else if (currentChat != null) {
                        if (info != null && info instanceof TLRPC.TL_chatParticipantsForbidden) {
                            return;
                        }
                        int count = currentChat.participants_count;
                        if (info != null) {
                            count = info.participants.size();
                        }
                        if (count == 0 || currentChat.left || currentChat instanceof TLRPC.TL_chatForbidden) {
                            return;
                        }
                        Bundle args = new Bundle();
                        args.putInt("chat_id", currentChat.id);
                        ChatProfileActivity fragment = new ChatProfileActivity(args);
                        fragment.setChatInfo(info);
                        presentFragment(fragment);
                    }
                } else if (id == copy) {
                    String str = "";
                    ArrayList<Integer> ids = new ArrayList<Integer>(selectedMessagesCanCopyIds.keySet());
                    if (currentEncryptedChat == null) {
                        Collections.sort(ids);
                    } else {
                        Collections.sort(ids, Collections.reverseOrder());
                    }
                    for (Integer messageId : ids) {
                        MessageObject messageObject = selectedMessagesCanCopyIds.get(messageId);
                        if (str.length() != 0) {
                            str += "\n";
                        }
                        if (messageObject.messageOwner.message != null) {
                            str += messageObject.messageOwner.message;
                        } else {
                            str += messageObject.messageText;
                        }
                    }
                    if (str.length() != 0) {
                        if (Build.VERSION.SDK_INT < 11) {
                            android.text.ClipboardManager clipboard = (android.text.ClipboardManager) ApplicationLoader.applicationContext
                                    .getSystemService(Context.CLIPBOARD_SERVICE);
                            clipboard.setText(str);
                        } else {
                            android.content.ClipboardManager clipboard = (android.content.ClipboardManager) ApplicationLoader.applicationContext
                                    .getSystemService(Context.CLIPBOARD_SERVICE);
                            android.content.ClipData clip = android.content.ClipData.newPlainText("label", str);
                            clipboard.setPrimaryClip(clip);
                        }
                    }
                    selectedMessagesIds.clear();
                    selectedMessagesCanCopyIds.clear();
                    actionBarLayer.hideActionMode();
                    updateVisibleRows();
                } else if (id == delete) {
                    ArrayList<Integer> ids = new ArrayList<Integer>(selectedMessagesIds.keySet());
                    ArrayList<Long> random_ids = null;
                    if (currentEncryptedChat != null) {
                        random_ids = new ArrayList<Long>();
                        for (HashMap.Entry<Integer, MessageObject> entry : selectedMessagesIds.entrySet()) {
                            MessageObject msg = entry.getValue();
                            if (msg.messageOwner.random_id != 0 && msg.type != 10) {
                                random_ids.add(msg.messageOwner.random_id);
                            }
                        }
                    }
                    //MessagesController.getInstance().deleteMessages(ids, random_ids, currentEncryptedChat);
                    //TODO qui utilizzo un mio metodo per cancellare i messaggi, cosi' prima mostro un alert
                    deleteMessages(ids, random_ids, currentEncryptedChat);
                    actionBarLayer.hideActionMode();
                } else if (id == forward) {
                    Bundle args = new Bundle();
                    args.putBoolean("onlySelect", true);
                    args.putBoolean("serverOnly", true);
                    args.putString("selectAlertString",
                            LocaleController.getString("ForwardMessagesTo", R.string.ForwardMessagesTo));
                    args.putString("selectAlertStringGroup", LocaleController
                            .getString("ForwardMessagesToGroup", R.string.ForwardMessagesToGroup));
                    MessagesActivity fragment = new MessagesActivity(args);
                    fragment.setDelegate(ChatActivity.this);
                    presentFragment(fragment);
                }
            }
        });

        updateSubtitle();

        if (currentEncryptedChat != null) {
            actionBarLayer.setTitleIcon(R.drawable.ic_lock_white, AndroidUtilities.dp(4));
        } else if (currentChat != null && currentChat.id < 0) {
            actionBarLayer.setTitleIcon(R.drawable.broadcast2, AndroidUtilities.dp(4));
        }

        ActionBarMenu menu = actionBarLayer.createMenu();

        if (currentEncryptedChat != null) {
            timeItem = menu.addItemResource(chat_enc_timer, R.layout.chat_header_enc_layout);
        }

        //TODO aggiungo il pulsante di ricerca
        item_search = menu.addItem(chat_menu_search, R.drawable.ic_ab_search);
        item_search.setIsSearchField(true)
                .setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
                    @Override
                    public void onSearchExpand() {
                        searching = true;
                    }

                    @Override
                    public void onSearchCollapse() {
                        searching = false;
                        //MessagesController.getInstance().loadMessages(dialog_id, 0, 20, maxMessageId, !cacheEndReaced, minDate, classGuid, false, false);
                        //NotificationCenter.getInstance().postNotificationName(dialogsNeedReload);

                    }

                    @Override
                    public void onTextChanged(final EditText editText) {
                        editText.requestFocus();
                        editText.setOnKeyListener(new View.OnKeyListener() {

                            public boolean onKey(View v, int keyCode, KeyEvent event) {
                                boolean result = false;
                                // se l'evento e' un "tasto premuto" sul tasto enter
                                if ((event.getAction() == KeyEvent.ACTION_DOWN)
                                        && (keyCode == KeyEvent.KEYCODE_ENTER)) {

                                    //fai azione
                                    if (!editText.getText().toString().equals("")) {
                                        searchMessages(dialog_id, editText.getText().toString(),
                                                new FutureSearch());
                                        try {
                                            presentFragment(new SearchResultsActivity(
                                                    doSearchAndBlock(dialog_id, editText.getText().toString()),
                                                    getArguments()));
                                        } catch (ExecutionException e) {
                                            e.printStackTrace();
                                        } catch (InterruptedException e) {
                                            e.printStackTrace();
                                        } catch (NullPointerException e) {
                                            Log.e("xela92",
                                                    "NullPointerException. Forse la connessione di rete e' assente? La ricerca  stata annullata. ");
                                            e.printStackTrace();
                                        }
                                    }
                                    result = true;
                                }
                                return result;
                            }
                        });
                    }

                });

        ActionBarMenuItem item = menu.addItem(chat_menu_attach, R.drawable.ic_ab_attach);
        item.addSubItem(attach_photo, LocaleController.getString("ChatTakePhoto", R.string.ChatTakePhoto),
                R.drawable.ic_attach_photo);
        item.addSubItem(attach_gallery, LocaleController.getString("ChatGallery", R.string.ChatGallery),
                R.drawable.ic_attach_gallery);
        item.addSubItem(attach_video, LocaleController.getString("ChatVideo", R.string.ChatVideo),
                R.drawable.ic_attach_video);
        item.addSubItem(attach_document, LocaleController.getString("ChatDocument", R.string.ChatDocument),
                R.drawable.ic_ab_doc);
        item.addSubItem(attach_location, LocaleController.getString("ChatLocation", R.string.ChatLocation),
                R.drawable.ic_attach_location);
        menuItem = item;

        actionModeViews.clear();

        final ActionBarMenu actionMode = actionBarLayer.createActionMode();
        actionModeViews.add(actionMode.addItem(-2, R.drawable.ic_ab_done_gray, R.drawable.bar_selector_mode));

        FrameLayout layout = new FrameLayout(actionMode.getContext());
        layout.setBackgroundColor(0xffe5e5e5);
        actionMode.addView(layout);
        LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) layout.getLayoutParams();
        layoutParams.width = AndroidUtilities.dp(1);
        layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT;
        layoutParams.topMargin = AndroidUtilities.dp(12);
        layoutParams.bottomMargin = AndroidUtilities.dp(12);
        layoutParams.gravity = Gravity.CENTER_VERTICAL;
        layout.setLayoutParams(layoutParams);
        actionModeViews.add(layout);

        selectedMessagesCountTextView = new TextView(actionMode.getContext());
        selectedMessagesCountTextView.setTextSize(18);
        selectedMessagesCountTextView.setTextColor(0xff000000);
        selectedMessagesCountTextView.setSingleLine(true);
        selectedMessagesCountTextView.setLines(1);
        selectedMessagesCountTextView.setEllipsize(TextUtils.TruncateAt.END);
        selectedMessagesCountTextView.setPadding(AndroidUtilities.dp(11), 0, 0, 0);
        selectedMessagesCountTextView.setGravity(Gravity.CENTER_VERTICAL);
        selectedMessagesCountTextView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return true;
            }
        });
        actionMode.addView(selectedMessagesCountTextView);
        layoutParams = (LinearLayout.LayoutParams) selectedMessagesCountTextView.getLayoutParams();
        layoutParams.weight = 1;
        layoutParams.width = 0;
        layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT;
        selectedMessagesCountTextView.setLayoutParams(layoutParams);

        if (currentEncryptedChat == null) {
            actionModeViews
                    .add(actionMode.addItem(copy, R.drawable.ic_ab_fwd_copy, R.drawable.bar_selector_mode));
            actionModeViews.add(
                    actionMode.addItem(forward, R.drawable.ic_ab_fwd_forward, R.drawable.bar_selector_mode));
            actionModeViews
                    .add(actionMode.addItem(delete, R.drawable.ic_ab_fwd_delete, R.drawable.bar_selector_mode));
        } else {
            actionModeViews
                    .add(actionMode.addItem(copy, R.drawable.ic_ab_fwd_copy, R.drawable.bar_selector_mode));
            actionModeViews
                    .add(actionMode.addItem(delete, R.drawable.ic_ab_fwd_delete, R.drawable.bar_selector_mode));
        }
        actionMode.getItem(copy)
                .setVisibility(selectedMessagesCanCopyIds.size() != 0 ? View.VISIBLE : View.GONE);

        View avatarLayout = menu.addItemResource(chat_menu_avatar, R.layout.chat_header_layout);
        avatarImageView = (BackupImageView) avatarLayout.findViewById(R.id.chat_avatar_image);
        avatarImageView.processDetach = false;
        checkActionBarMenu();

        fragmentView = inflater.inflate(R.layout.chat_layout, container, false);

        View contentView = fragmentView.findViewById(R.id.chat_layout);
        TextView emptyView = (TextView) fragmentView.findViewById(R.id.searchEmptyView);
        emptyViewContainer = fragmentView.findViewById(R.id.empty_view);
        emptyViewContainer.setVisibility(View.GONE);
        emptyViewContainer.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return true;
            }
        });
        emptyView.setText(LocaleController.getString("NoMessages", R.string.NoMessages));
        chatListView = (LayoutListView) fragmentView.findViewById(R.id.chat_list_view);
        chatListView.setAdapter(chatAdapter = new ChatAdapter(getParentActivity()));
        topPanel = fragmentView.findViewById(R.id.top_panel);
        topPlaneClose = (ImageView) fragmentView.findViewById(R.id.top_plane_close);
        topPanelText = (TextView) fragmentView.findViewById(R.id.top_panel_text);
        bottomOverlay = fragmentView.findViewById(R.id.bottom_overlay);
        bottomOverlayText = (TextView) fragmentView.findViewById(R.id.bottom_overlay_text);
        bottomOverlayChat = fragmentView.findViewById(R.id.bottom_overlay_chat);
        progressView = fragmentView.findViewById(R.id.progressLayout);
        pagedownButton = fragmentView.findViewById(R.id.pagedown_button);
        pagedownButton.setVisibility(View.GONE);

        View progressViewInner = progressView.findViewById(R.id.progressLayoutInner);

        updateContactStatus();

        SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig",
                Activity.MODE_PRIVATE);
        int selectedBackground = preferences.getInt("selectedBackground", 1000001);
        int selectedColor = preferences.getInt("selectedColor", 0);
        if (selectedColor != 0) {
            contentView.setBackgroundColor(selectedColor);
            chatListView.setCacheColorHint(selectedColor);
        } else {
            chatListView.setCacheColorHint(0);
            try {
                if (selectedBackground == 1000001) {
                    ((SizeNotifierRelativeLayout) contentView).setBackgroundImage(R.drawable.background_hd);
                } else {
                    File toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper.jpg");
                    if (toFile.exists()) {
                        if (ApplicationLoader.cachedWallpaper != null) {
                            ((SizeNotifierRelativeLayout) contentView)
                                    .setBackgroundImage(ApplicationLoader.cachedWallpaper);
                        } else {
                            Drawable drawable = Drawable.createFromPath(toFile.getAbsolutePath());
                            if (drawable != null) {
                                ((SizeNotifierRelativeLayout) contentView).setBackgroundImage(drawable);
                                ApplicationLoader.cachedWallpaper = drawable;
                            } else {
                                contentView.setBackgroundColor(-2693905);
                                chatListView.setCacheColorHint(-2693905);
                            }
                        }
                        isCustomTheme = true;
                    } else {
                        ((SizeNotifierRelativeLayout) contentView).setBackgroundImage(R.drawable.background_hd);
                    }
                }
            } catch (Exception e) {
                contentView.setBackgroundColor(-2693905);
                chatListView.setCacheColorHint(-2693905);
                FileLog.e("tmessages", e);
            }
        }

        if (currentEncryptedChat != null) {
            emptyView.setVisibility(View.GONE);
            View secretChatPlaceholder = contentView.findViewById(R.id.secret_placeholder);
            secretChatPlaceholder.setVisibility(View.VISIBLE);
            if (isCustomTheme) {
                secretChatPlaceholder.setBackgroundResource(R.drawable.system_black);
            } else {
                secretChatPlaceholder.setBackgroundResource(R.drawable.system_blue);
            }
            secretViewStatusTextView = (TextView) contentView.findViewById(R.id.invite_text);
            secretChatPlaceholder.setPadding(AndroidUtilities.dp(16), AndroidUtilities.dp(12),
                    AndroidUtilities.dp(16), AndroidUtilities.dp(12));

            View v = contentView.findViewById(R.id.secret_placeholder);
            v.setVisibility(View.VISIBLE);

            if (currentEncryptedChat.admin_id == UserConfig.getClientUserId()) {
                if (currentUser.first_name.length() > 0) {
                    secretViewStatusTextView
                            .setText(LocaleController.formatString("EncryptedPlaceholderTitleOutgoing",
                                    R.string.EncryptedPlaceholderTitleOutgoing, currentUser.first_name));
                } else {
                    secretViewStatusTextView
                            .setText(LocaleController.formatString("EncryptedPlaceholderTitleOutgoing",
                                    R.string.EncryptedPlaceholderTitleOutgoing, currentUser.last_name));
                }
            } else {
                if (currentUser.first_name.length() > 0) {
                    secretViewStatusTextView
                            .setText(LocaleController.formatString("EncryptedPlaceholderTitleIncoming",
                                    R.string.EncryptedPlaceholderTitleIncoming, currentUser.first_name));
                } else {
                    secretViewStatusTextView
                            .setText(LocaleController.formatString("EncryptedPlaceholderTitleIncoming",
                                    R.string.EncryptedPlaceholderTitleIncoming, currentUser.last_name));
                }
            }

            updateSecretStatus();
        }

        if (isCustomTheme) {
            progressViewInner.setBackgroundResource(R.drawable.system_loader2);
            emptyView.setBackgroundResource(R.drawable.system_black);
        } else {
            progressViewInner.setBackgroundResource(R.drawable.system_loader1);
            emptyView.setBackgroundResource(R.drawable.system_blue);
        }
        emptyView.setPadding(AndroidUtilities.dp(7), AndroidUtilities.dp(1), AndroidUtilities.dp(7),
                AndroidUtilities.dp(1));

        if (currentUser != null && (currentUser.id / 1000 == 333 || currentUser.id % 1000 == 0)) {
            emptyView.setText(LocaleController.getString("GotAQuestion", R.string.GotAQuestion));
        }

        chatListView.setOnItemLongClickListener(onItemLongClickListener);
        chatListView.setOnItemClickListener(onItemClickListener);

        final Rect scrollRect = new Rect();

        chatListView.setOnInterceptTouchEventListener(new LayoutListView.OnInterceptTouchEventListener() {
            @Override
            public boolean onInterceptTouchEvent(MotionEvent event) {
                if (actionBarLayer.isActionModeShowed()) {
                    return false;
                }
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    int x = (int) event.getX();
                    int y = (int) event.getY();
                    int count = chatListView.getChildCount();
                    Rect rect = new Rect();
                    for (int a = 0; a < count; a++) {
                        View view = chatListView.getChildAt(a);
                        int top = view.getTop();
                        int bottom = view.getBottom();
                        view.getLocalVisibleRect(rect);
                        if (top > y || bottom < y) {
                            continue;
                        }
                        if (!(view instanceof ChatMediaCell)) {
                            break;
                        }
                        final ChatMediaCell cell = (ChatMediaCell) view;
                        final MessageObject messageObject = cell.getMessageObject();
                        if (messageObject == null || !messageObject.isSecretPhoto()
                                || !cell.getPhotoImage().isInsideImage(x, y - top)) {
                            break;
                        }
                        File file = FileLoader.getPathToMessage(messageObject.messageOwner);
                        if (!file.exists()) {
                            break;
                        }
                        startX = x;
                        startY = y;
                        chatListView.setOnItemClickListener(null);
                        openSecretPhotoRunnable = new Runnable() {
                            @Override
                            public void run() {
                                if (openSecretPhotoRunnable == null) {
                                    return;
                                }
                                chatListView.requestDisallowInterceptTouchEvent(true);
                                chatListView.setOnItemLongClickListener(null);
                                chatListView.setLongClickable(false);
                                openSecretPhotoRunnable = null;
                                if (sendSecretMessageRead(messageObject)) {
                                    cell.invalidate();
                                }
                                SecretPhotoViewer.getInstance().setParentActivity(getParentActivity());
                                SecretPhotoViewer.getInstance().openPhoto(messageObject);
                            }
                        };
                        AndroidUtilities.RunOnUIThread(openSecretPhotoRunnable, 100);
                        return true;
                    }
                }
                return false;
            }
        });

        chatListView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (openSecretPhotoRunnable != null || SecretPhotoViewer.getInstance().isVisible()) {
                    if (event.getAction() == MotionEvent.ACTION_UP
                            || event.getAction() == MotionEvent.ACTION_CANCEL
                            || event.getAction() == MotionEvent.ACTION_POINTER_UP) {
                        AndroidUtilities.RunOnUIThread(new Runnable() {
                            @Override
                            public void run() {
                                chatListView.setOnItemClickListener(onItemClickListener);
                            }
                        }, 150);
                        if (openSecretPhotoRunnable != null) {
                            AndroidUtilities.CancelRunOnUIThread(openSecretPhotoRunnable);
                            openSecretPhotoRunnable = null;
                            try {
                                Toast.makeText(v.getContext(),
                                        LocaleController.getString("PhotoTip", R.string.PhotoTip),
                                        Toast.LENGTH_SHORT).show();
                            } catch (Exception e) {
                                FileLog.e("tmessages", e);
                            }
                        } else {
                            if (SecretPhotoViewer.getInstance().isVisible()) {
                                AndroidUtilities.RunOnUIThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        chatListView.setOnItemLongClickListener(onItemLongClickListener);
                                        chatListView.setLongClickable(true);
                                    }
                                });
                                SecretPhotoViewer.getInstance().closePhoto();
                            }
                        }
                    } else if (event.getAction() != MotionEvent.ACTION_DOWN) {
                        if (SecretPhotoViewer.getInstance().isVisible()) {
                            return true;
                        } else if (openSecretPhotoRunnable != null) {
                            if (event.getAction() == MotionEvent.ACTION_MOVE) {
                                if (Math.hypot(startX - event.getX(), startY - event.getY()) > AndroidUtilities
                                        .dp(5)) {
                                    AndroidUtilities.CancelRunOnUIThread(openSecretPhotoRunnable);
                                    openSecretPhotoRunnable = null;
                                }
                            } else {
                                AndroidUtilities.CancelRunOnUIThread(openSecretPhotoRunnable);
                                openSecretPhotoRunnable = null;
                            }
                        }
                    }
                }
                return false;
            }
        });

        chatListView.setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView absListView, int i) {

            }

            @Override
            public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount,
                    int totalItemCount) {
                if (visibleItemCount > 0) {
                    if (firstVisibleItem <= 10) {
                        if (!endReached && !loading) {
                            if (messagesByDays.size() != 0) {
                                MessagesController.getInstance().loadMessages(dialog_id, 20, maxMessageId,
                                        !cacheEndReaced, minDate, classGuid, false, false, null);
                            } else {
                                MessagesController.getInstance().loadMessages(dialog_id, 20, 0, !cacheEndReaced,
                                        minDate, classGuid, false, false, null);
                            }
                            loading = true;
                        }
                    }
                    if (firstVisibleItem + visibleItemCount >= totalItemCount - 6) {
                        if (!unread_end_reached && !loadingForward) {
                            MessagesController.getInstance().loadMessages(dialog_id, 20, minMessageId, true,
                                    maxDate, classGuid, false, true, null);
                            loadingForward = true;
                        }
                    }
                    if (firstVisibleItem + visibleItemCount == totalItemCount && unread_end_reached) {
                        showPagedownButton(false, true);
                    }
                }
                for (int a = 0; a < visibleItemCount; a++) {
                    View view = absListView.getChildAt(a);
                    if (view instanceof ChatMessageCell) {
                        ChatMessageCell messageCell = (ChatMessageCell) view;
                        messageCell.getLocalVisibleRect(scrollRect);
                        messageCell.setVisiblePart(scrollRect.top, scrollRect.bottom - scrollRect.top);
                    }
                }
            }
        });

        bottomOverlayChatText = (TextView) fragmentView.findViewById(R.id.bottom_overlay_chat_text);
        TextView textView = (TextView) fragmentView.findViewById(R.id.secret_title);
        textView.setText(
                LocaleController.getString("EncryptedDescriptionTitle", R.string.EncryptedDescriptionTitle));
        textView = (TextView) fragmentView.findViewById(R.id.secret_description1);
        textView.setText(LocaleController.getString("EncryptedDescription1", R.string.EncryptedDescription1));
        textView = (TextView) fragmentView.findViewById(R.id.secret_description2);
        textView.setText(LocaleController.getString("EncryptedDescription2", R.string.EncryptedDescription2));
        textView = (TextView) fragmentView.findViewById(R.id.secret_description3);
        textView.setText(LocaleController.getString("EncryptedDescription3", R.string.EncryptedDescription3));
        textView = (TextView) fragmentView.findViewById(R.id.secret_description4);
        textView.setText(LocaleController.getString("EncryptedDescription4", R.string.EncryptedDescription4));

        if (loading && messages.isEmpty()) {
            progressView.setVisibility(View.VISIBLE);
            chatListView.setEmptyView(null);
        } else {
            progressView.setVisibility(View.GONE);
            chatListView.setEmptyView(emptyViewContainer);
        }

        pagedownButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                scrollToLastMessage();
            }
        });

        bottomOverlayChat.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (getParentActivity() == null) {
                    return;
                }
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                if (currentUser != null && userBlocked) {
                    builder.setMessage(LocaleController.getString("AreYouSureUnblockContact",
                            R.string.AreYouSureUnblockContact));
                    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    MessagesController.getInstance().unblockUser(currentUser.id);
                                }
                            });
                } else {
                    builder.setMessage(LocaleController.getString("AreYouSureDeleteThisChat",
                            R.string.AreYouSureDeleteThisChat));
                    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    MessagesController.getInstance().deleteDialog(dialog_id, 0, false);
                                    finishFragment();
                                }
                            });
                }
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                showAlertDialog(builder);
            }
        });

        updateBottomOverlay();

        chatActivityEnterView.setContainerView(getParentActivity(), fragmentView);
    } else {
        ViewGroup parent = (ViewGroup) fragmentView.getParent();
        if (parent != null) {
            parent.removeView(fragmentView);
        }
    }
    return fragmentView;
}

From source file:com.tylz.jiaoyanglogistics.view.LazyViewPager.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    mInLayout = true;/* ww w . jav a 2s.  co m*/
    populate();
    mInLayout = false;

    final int count = getChildCount();
    int width = r - l;
    int height = b - t;
    int paddingLeft = getPaddingLeft();
    int paddingTop = getPaddingTop();
    int paddingRight = getPaddingRight();
    int paddingBottom = getPaddingBottom();
    final int scrollX = getScrollX();

    int decorCount = 0;

    for (int i = 0; i < count; i++) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            ItemInfo ii;
            int childLeft = 0;
            int childTop = 0;
            if (lp.isDecor) {
                final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
                final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;
                switch (hgrav) {
                default:
                    childLeft = paddingLeft;
                    break;
                case Gravity.LEFT:
                    childLeft = paddingLeft;
                    paddingLeft += child.getMeasuredWidth();
                    break;
                case Gravity.CENTER_HORIZONTAL:
                    childLeft = Math.max((width - child.getMeasuredWidth()) / 2, paddingLeft);
                    break;
                case Gravity.RIGHT:
                    childLeft = width - paddingRight - child.getMeasuredWidth();
                    paddingRight += child.getMeasuredWidth();
                    break;
                }
                switch (vgrav) {
                default:
                    childTop = paddingTop;
                    break;
                case Gravity.TOP:
                    childTop = paddingTop;
                    paddingTop += child.getMeasuredHeight();
                    break;
                case Gravity.CENTER_VERTICAL:
                    childTop = Math.max((height - child.getMeasuredHeight()) / 2, paddingTop);
                    break;
                case Gravity.BOTTOM:
                    childTop = height - paddingBottom - child.getMeasuredHeight();
                    paddingBottom += child.getMeasuredHeight();
                    break;
                }
                childLeft += scrollX;
                decorCount++;
                child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(),
                        childTop + child.getMeasuredHeight());
            } else if ((ii = infoForChild(child)) != null) {
                int loff = (width + mPageMargin) * ii.position;
                childLeft = paddingLeft + loff;
                childTop = paddingTop;
                if (DEBUG) {
                    Log.v(TAG, "Positioning #" + i + " " + child + " f=" + ii.object + ":" + childLeft + ","
                            + childTop + " " + child.getMeasuredWidth() + "x" + child.getMeasuredHeight());
                }
                child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(),
                        childTop + child.getMeasuredHeight());
            }
        }
    }
    mTopPageBounds = paddingTop;
    mBottomPageBounds = height - paddingBottom;
    mDecorChildCount = decorCount;
    mFirstLayout = false;
}