Example usage for android.graphics Paint ANTI_ALIAS_FLAG

List of usage examples for android.graphics Paint ANTI_ALIAS_FLAG

Introduction

In this page you can find the example usage for android.graphics Paint ANTI_ALIAS_FLAG.

Prototype

int ANTI_ALIAS_FLAG

To view the source code for android.graphics Paint ANTI_ALIAS_FLAG.

Click Source Link

Document

Paint flag that enables antialiasing when drawing.

Usage

From source file:org.telegram.ui.Components.ChatActivityEnterView.java

public ChatActivityEnterView(Activity context, SizeNotifierFrameLayout parent, ChatActivity fragment,
        final boolean isChat) {
    super(context);

    dotPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    dotPaint.setColor(Theme.getColor(Theme.key_chat_emojiPanelNewTrending));
    setFocusable(true);/*w  w w .jav a 2s. c o  m*/
    setFocusableInTouchMode(true);
    setWillNotDraw(false);

    NotificationCenter.getInstance().addObserver(this, NotificationCenter.recordStarted);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.recordStartError);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.recordStopped);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.recordProgressChanged);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.closeChats);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioDidSent);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.emojiDidLoaded);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioRouteChanged);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioDidReset);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioProgressDidChanged);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.featuredStickersDidLoaded);
    parentActivity = context;
    parentFragment = fragment;
    sizeNotifierLayout = parent;
    sizeNotifierLayout.setDelegate(this);
    SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig",
            Activity.MODE_PRIVATE);
    sendByEnter = preferences.getBoolean("send_by_enter", false);

    textFieldContainer = new LinearLayout(context);
    textFieldContainer.setOrientation(LinearLayout.HORIZONTAL);
    addView(textFieldContainer, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT,
            Gravity.LEFT | Gravity.TOP, 0, 2, 0, 0));

    FrameLayout frameLayout = new FrameLayout(context);
    textFieldContainer.addView(frameLayout, LayoutHelper.createLinear(0, LayoutHelper.WRAP_CONTENT, 1.0f));

    emojiButton = new ImageView(context) {
        @Override
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            if (attachLayout != null && (emojiView == null || emojiView.getVisibility() != VISIBLE)
                    && !StickersQuery.getUnreadStickerSets().isEmpty() && dotPaint != null) {
                int x = canvas.getWidth() / 2 + AndroidUtilities.dp(4 + 5);
                int y = canvas.getHeight() / 2 - AndroidUtilities.dp(13 - 5);
                canvas.drawCircle(x, y, AndroidUtilities.dp(5), dotPaint);
            }
        }
    };
    emojiButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_messagePanelIcons),
            PorterDuff.Mode.MULTIPLY));
    emojiButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    emojiButton.setPadding(0, AndroidUtilities.dp(1), 0, 0);
    //        if (Build.VERSION.SDK_INT >= 21) {
    //            emojiButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.INPUT_FIELD_SELECTOR_COLOR));
    //        }
    setEmojiButtonImage();
    frameLayout.addView(emojiButton,
            LayoutHelper.createFrame(48, 48, Gravity.BOTTOM | Gravity.LEFT, 3, 0, 0, 0));
    emojiButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            if (!isPopupShowing() || currentPopupContentType != 0) {
                showPopup(1, 0);
                emojiView.onOpen(messageEditText.length() > 0
                        && !messageEditText.getText().toString().startsWith("@gif"));
            } else {
                openKeyboardInternal();
                removeGifFromInputField();
            }
        }
    });

    messageEditText = new EditTextCaption(context) {
        @Override
        public InputConnection onCreateInputConnection(EditorInfo editorInfo) {
            final InputConnection ic = super.onCreateInputConnection(editorInfo);
            EditorInfoCompat.setContentMimeTypes(editorInfo,
                    new String[] { "image/gif", "image/*", "image/jpg", "image/png" });

            final InputConnectionCompat.OnCommitContentListener callback = new InputConnectionCompat.OnCommitContentListener() {
                @Override
                public boolean onCommitContent(InputContentInfoCompat inputContentInfo, int flags,
                        Bundle opts) {
                    if (BuildCompat.isAtLeastNMR1()
                            && (flags & InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION) != 0) {
                        try {
                            inputContentInfo.requestPermission();
                        } catch (Exception e) {
                            return false;
                        }
                    }
                    ClipDescription description = inputContentInfo.getDescription();
                    if (description.hasMimeType("image/gif")) {
                        SendMessagesHelper.prepareSendingDocument(null, null, inputContentInfo.getContentUri(),
                                "image/gif", dialog_id, replyingMessageObject, inputContentInfo);
                    } else {
                        SendMessagesHelper.prepareSendingPhoto(null, inputContentInfo.getContentUri(),
                                dialog_id, replyingMessageObject, null, null, inputContentInfo);
                    }
                    if (delegate != null) {
                        delegate.onMessageSend(null);
                    }
                    return true;
                }
            };
            return InputConnectionCompat.createWrapper(ic, editorInfo, callback);
        }

        @Override
        public boolean onTouchEvent(MotionEvent event) {
            if (isPopupShowing() && event.getAction() == MotionEvent.ACTION_DOWN) {
                showPopup(AndroidUtilities.usingHardwareInput ? 0 : 2, 0);
                openKeyboardInternal();
            }
            try {
                return super.onTouchEvent(event);
            } catch (Exception e) {
                FileLog.e(e);
            }
            return false;
        }
    };
    updateFieldHint();
    messageEditText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
    messageEditText.setInputType(messageEditText.getInputType() | EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES
            | EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE);
    messageEditText.setSingleLine(false);
    messageEditText.setMaxLines(4);
    messageEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    messageEditText.setGravity(Gravity.BOTTOM);
    messageEditText.setPadding(0, AndroidUtilities.dp(11), 0, AndroidUtilities.dp(12));
    messageEditText.setBackgroundDrawable(null);
    messageEditText.setTextColor(Theme.getColor(Theme.key_chat_messagePanelText));
    messageEditText.setHintColor(Theme.getColor(Theme.key_chat_messagePanelHint));
    messageEditText.setHintTextColor(Theme.getColor(Theme.key_chat_messagePanelHint));
    frameLayout.addView(messageEditText, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM, 52, 0, isChat ? 50 : 2, 0));
    messageEditText.setOnKeyListener(new OnKeyListener() {

        boolean ctrlPressed = false;

        @Override
        public boolean onKey(View view, int i, KeyEvent keyEvent) {
            if (i == KeyEvent.KEYCODE_BACK && !keyboardVisible && isPopupShowing()) {
                if (keyEvent.getAction() == 1) {
                    if (currentPopupContentType == 1 && botButtonsMessageObject != null) {
                        SharedPreferences preferences = ApplicationLoader.applicationContext
                                .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
                        preferences.edit().putInt("hidekeyboard_" + dialog_id, botButtonsMessageObject.getId())
                                .commit();
                    }
                    showPopup(0, 0);
                    removeGifFromInputField();
                }
                return true;
            } else if (i == KeyEvent.KEYCODE_ENTER && (ctrlPressed || sendByEnter)
                    && keyEvent.getAction() == KeyEvent.ACTION_DOWN && editingMessageObject == null) {
                sendMessage();
                return true;
            } else if (i == KeyEvent.KEYCODE_CTRL_LEFT || i == KeyEvent.KEYCODE_CTRL_RIGHT) {
                ctrlPressed = keyEvent.getAction() == KeyEvent.ACTION_DOWN;
                return true;
            }
            return false;
        }
    });
    messageEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        boolean ctrlPressed = false;

        @Override
        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            if (i == EditorInfo.IME_ACTION_SEND) {
                sendMessage();
                return true;
            } else if (keyEvent != null && i == EditorInfo.IME_NULL) {
                if ((ctrlPressed || sendByEnter) && keyEvent.getAction() == KeyEvent.ACTION_DOWN
                        && editingMessageObject == null) {
                    sendMessage();
                    return true;
                } else if (i == KeyEvent.KEYCODE_CTRL_LEFT || i == KeyEvent.KEYCODE_CTRL_RIGHT) {
                    ctrlPressed = keyEvent.getAction() == KeyEvent.ACTION_DOWN;
                    return true;
                }
            }
            return false;
        }
    });
    messageEditText.addTextChangedListener(new TextWatcher() {
        boolean processChange = false;

        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int start, int before, int count) {
            if (innerTextChange == 1) {
                return;
            }
            checkSendButton(true);
            CharSequence message = AndroidUtilities.getTrimmedString(charSequence.toString());
            if (delegate != null) {
                if (!ignoreTextChange) {
                    if (count > 2 || charSequence == null || charSequence.length() == 0) {
                        messageWebPageSearch = true;
                    }
                    delegate.onTextChanged(charSequence, before > count + 1 || (count - before) > 2);
                }
            }
            if (innerTextChange != 2 && before != count && (count - before) > 1) {
                processChange = true;
            }
            if (editingMessageObject == null && !canWriteToChannel && message.length() != 0
                    && lastTypingTimeSend < System.currentTimeMillis() - 5000 && !ignoreTextChange) {
                int currentTime = ConnectionsManager.getInstance().getCurrentTime();
                TLRPC.User currentUser = null;
                if ((int) dialog_id > 0) {
                    currentUser = MessagesController.getInstance().getUser((int) dialog_id);
                }
                if (currentUser != null && (currentUser.id == UserConfig.getClientUserId()
                        || currentUser.status != null && currentUser.status.expires < currentTime
                                && !MessagesController.getInstance().onlinePrivacy
                                        .containsKey(currentUser.id))) {
                    return;
                }
                lastTypingTimeSend = System.currentTimeMillis();
                if (delegate != null) {
                    delegate.needSendTyping();
                }
            }
        }

        @Override
        public void afterTextChanged(Editable editable) {
            if (innerTextChange != 0) {
                return;
            }
            if (sendByEnter && editable.length() > 0 && editable.charAt(editable.length() - 1) == '\n'
                    && editingMessageObject == null) {
                sendMessage();
            }
            if (processChange) {
                ImageSpan[] spans = editable.getSpans(0, editable.length(), ImageSpan.class);
                for (int i = 0; i < spans.length; i++) {
                    editable.removeSpan(spans[i]);
                }
                Emoji.replaceEmoji(editable, messageEditText.getPaint().getFontMetricsInt(),
                        AndroidUtilities.dp(20), false);
                processChange = false;
            }
        }
    });

    if (isChat) {
        attachLayout = new LinearLayout(context);
        attachLayout.setOrientation(LinearLayout.HORIZONTAL);
        attachLayout.setEnabled(false);
        attachLayout.setPivotX(AndroidUtilities.dp(48));
        frameLayout.addView(attachLayout,
                LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 48, Gravity.BOTTOM | Gravity.RIGHT));

        botButton = new ImageView(context);
        botButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_messagePanelIcons),
                PorterDuff.Mode.MULTIPLY));
        botButton.setImageResource(R.drawable.bot_keyboard2);
        botButton.setScaleType(ImageView.ScaleType.CENTER);
        botButton.setVisibility(GONE);
        //            if (Build.VERSION.SDK_INT >= 21) {
        //                botButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.INPUT_FIELD_SELECTOR_COLOR));
        //            }
        attachLayout.addView(botButton, LayoutHelper.createLinear(48, 48));
        botButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (botReplyMarkup != null) {
                    if (!isPopupShowing() || currentPopupContentType != 1) {
                        showPopup(1, 1);
                        SharedPreferences preferences = ApplicationLoader.applicationContext
                                .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
                        preferences.edit().remove("hidekeyboard_" + dialog_id).commit();
                    } else {
                        if (currentPopupContentType == 1 && botButtonsMessageObject != null) {
                            SharedPreferences preferences = ApplicationLoader.applicationContext
                                    .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
                            preferences.edit()
                                    .putInt("hidekeyboard_" + dialog_id, botButtonsMessageObject.getId())
                                    .commit();
                        }
                        openKeyboardInternal();
                    }
                } else if (hasBotCommands) {
                    setFieldText("/");
                    messageEditText.requestFocus();
                    openKeyboard();
                }
            }
        });

        notifyButton = new ImageView(context);
        notifyButton.setImageResource(silent ? R.drawable.notify_members_off : R.drawable.notify_members_on);
        notifyButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_messagePanelIcons),
                PorterDuff.Mode.MULTIPLY));
        notifyButton.setScaleType(ImageView.ScaleType.CENTER);
        notifyButton.setVisibility(canWriteToChannel ? VISIBLE : GONE);
        //            if (Build.VERSION.SDK_INT >= 21) {
        //                notifyButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.INPUT_FIELD_SELECTOR_COLOR));
        //            }
        attachLayout.addView(notifyButton, LayoutHelper.createLinear(48, 48));
        notifyButton.setOnClickListener(new OnClickListener() {

            private Toast visibleToast;

            @Override
            public void onClick(View v) {
                silent = !silent;
                notifyButton.setImageResource(
                        silent ? R.drawable.notify_members_off : R.drawable.notify_members_on);
                ApplicationLoader.applicationContext
                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE).edit()
                        .putBoolean("silent_" + dialog_id, silent).commit();
                NotificationsController.updateServerNotificationsSettings(dialog_id);
                try {
                    if (visibleToast != null) {
                        visibleToast.cancel();
                    }
                } catch (Exception e) {
                    FileLog.e(e);
                }
                if (silent) {
                    visibleToast = Toast.makeText(parentActivity, LocaleController
                            .getString("ChannelNotifyMembersInfoOff", R.string.ChannelNotifyMembersInfoOff),
                            Toast.LENGTH_SHORT);
                } else {
                    visibleToast = Toast.makeText(parentActivity, LocaleController
                            .getString("ChannelNotifyMembersInfoOn", R.string.ChannelNotifyMembersInfoOn),
                            Toast.LENGTH_SHORT);
                }
                visibleToast.show();
                updateFieldHint();
            }
        });

        attachButton = new ImageView(context);
        attachButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_messagePanelIcons),
                PorterDuff.Mode.MULTIPLY));
        attachButton.setImageResource(R.drawable.ic_ab_attach);
        attachButton.setScaleType(ImageView.ScaleType.CENTER);
        //            if (Build.VERSION.SDK_INT >= 21) {
        //                attachButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.INPUT_FIELD_SELECTOR_COLOR));
        //            }
        attachLayout.addView(attachButton, LayoutHelper.createLinear(48, 48));
        attachButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                delegate.didPressedAttachButton();
            }
        });
    }

    recordedAudioPanel = new FrameLayout(context);
    recordedAudioPanel.setVisibility(audioToSend == null ? GONE : VISIBLE);
    recordedAudioPanel.setBackgroundColor(Theme.getColor(Theme.key_chat_messagePanelBackground));
    recordedAudioPanel.setFocusable(true);
    recordedAudioPanel.setFocusableInTouchMode(true);
    recordedAudioPanel.setClickable(true);
    frameLayout.addView(recordedAudioPanel,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.BOTTOM));

    recordDeleteImageView = new ImageView(context);
    recordDeleteImageView.setScaleType(ImageView.ScaleType.CENTER);
    recordDeleteImageView.setImageResource(R.drawable.ic_ab_delete);
    recordDeleteImageView.setColorFilter(new PorterDuffColorFilter(
            Theme.getColor(Theme.key_chat_messagePanelVoiceDelete), PorterDuff.Mode.MULTIPLY));
    recordedAudioPanel.addView(recordDeleteImageView, LayoutHelper.createFrame(48, 48));
    recordDeleteImageView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            MessageObject playing = MediaController.getInstance().getPlayingMessageObject();
            if (playing != null && playing == audioToSendMessageObject) {
                MediaController.getInstance().cleanupPlayer(true, true);
            }
            if (audioToSendPath != null) {
                new File(audioToSendPath).delete();
            }
            hideRecordedAudioPanel();
            checkSendButton(true);
        }
    });

    recordedAudioBackground = new View(context);
    recordedAudioBackground.setBackgroundDrawable(Theme.createRoundRectDrawable(AndroidUtilities.dp(16),
            Theme.getColor(Theme.key_chat_recordedVoiceBackground)));
    recordedAudioPanel.addView(recordedAudioBackground, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 32,
            Gravity.CENTER_VERTICAL | Gravity.LEFT, 48, 0, 0, 0));

    recordedAudioSeekBar = new SeekBarWaveformView(context);
    recordedAudioPanel.addView(recordedAudioSeekBar, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 32,
            Gravity.CENTER_VERTICAL | Gravity.LEFT, 48 + 44, 0, 52, 0));

    playDrawable = Theme.createSimpleSelectorDrawable(context, R.drawable.s_play,
            Theme.getColor(Theme.key_chat_recordedVoicePlayPause),
            Theme.getColor(Theme.key_chat_recordedVoicePlayPausePressed));
    pauseDrawable = Theme.createSimpleSelectorDrawable(context, R.drawable.s_pause,
            Theme.getColor(Theme.key_chat_recordedVoicePlayPause),
            Theme.getColor(Theme.key_chat_recordedVoicePlayPausePressed));

    recordedAudioPlayButton = new ImageView(context);
    recordedAudioPlayButton.setImageDrawable(playDrawable);
    recordedAudioPlayButton.setScaleType(ImageView.ScaleType.CENTER);
    recordedAudioPanel.addView(recordedAudioPlayButton,
            LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.BOTTOM, 48, 0, 0, 0));
    recordedAudioPlayButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (audioToSend == null) {
                return;
            }
            if (MediaController.getInstance().isPlayingAudio(audioToSendMessageObject)
                    && !MediaController.getInstance().isAudioPaused()) {
                MediaController.getInstance().pauseAudio(audioToSendMessageObject);
                recordedAudioPlayButton.setImageDrawable(playDrawable);
            } else {
                recordedAudioPlayButton.setImageDrawable(pauseDrawable);
                MediaController.getInstance().playAudio(audioToSendMessageObject);
            }
        }
    });

    recordedAudioTimeTextView = new TextView(context);
    recordedAudioTimeTextView.setTextColor(Theme.getColor(Theme.key_chat_messagePanelVoiceDuration));
    recordedAudioTimeTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
    recordedAudioPanel.addView(recordedAudioTimeTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT,
            LayoutHelper.WRAP_CONTENT, Gravity.RIGHT | Gravity.CENTER_VERTICAL, 0, 0, 13, 0));

    recordPanel = new FrameLayout(context);
    recordPanel.setVisibility(GONE);
    recordPanel.setBackgroundColor(Theme.getColor(Theme.key_chat_messagePanelBackground));
    frameLayout.addView(recordPanel, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.BOTTOM));

    slideText = new LinearLayout(context);
    slideText.setOrientation(LinearLayout.HORIZONTAL);
    recordPanel.addView(slideText, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT,
            LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 30, 0, 0, 0));

    recordCancelImage = new ImageView(context);
    recordCancelImage.setImageResource(R.drawable.slidearrow);
    recordCancelImage.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_recordVoiceCancel),
            PorterDuff.Mode.MULTIPLY));
    slideText.addView(recordCancelImage, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT,
            LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL, 0, 1, 0, 0));

    recordCancelText = new TextView(context);
    recordCancelText.setText(LocaleController.getString("SlideToCancel", R.string.SlideToCancel));
    recordCancelText.setTextColor(Theme.getColor(Theme.key_chat_recordVoiceCancel));
    recordCancelText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
    slideText.addView(recordCancelText, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT,
            LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL, 6, 0, 0, 0));

    recordTimeContainer = new LinearLayout(context);
    recordTimeContainer.setOrientation(LinearLayout.HORIZONTAL);
    recordTimeContainer.setPadding(AndroidUtilities.dp(13), 0, 0, 0);
    recordTimeContainer.setBackgroundColor(Theme.getColor(Theme.key_chat_messagePanelBackground));
    recordPanel.addView(recordTimeContainer, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT,
            LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL));

    recordDot = new RecordDot(context);
    recordTimeContainer.addView(recordDot,
            LayoutHelper.createLinear(11, 11, Gravity.CENTER_VERTICAL, 0, 1, 0, 0));

    recordTimeText = new TextView(context);
    recordTimeText.setText("00:00");
    recordTimeText.setTextColor(Theme.getColor(Theme.key_chat_recordTime));
    recordTimeText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    recordTimeContainer.addView(recordTimeText, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT,
            LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL, 6, 0, 0, 0));

    sendButtonContainer = new FrameLayout(context);
    textFieldContainer.addView(sendButtonContainer, LayoutHelper.createLinear(48, 48, Gravity.BOTTOM));

    audioVideoButtonContainer = new FrameLayout(context);
    audioVideoButtonContainer.setBackgroundColor(Theme.getColor(Theme.key_chat_messagePanelBackground));
    audioVideoButtonContainer.setSoundEffectsEnabled(false);
    sendButtonContainer.addView(audioVideoButtonContainer, LayoutHelper.createFrame(48, 48));
    audioVideoButtonContainer.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
                if (hasRecordVideo) {
                    recordAudioVideoRunnableStarted = true;
                    AndroidUtilities.runOnUIThread(recordAudioVideoRunnable, 150);
                } else {
                    recordAudioVideoRunnable.run();
                }
            } else if (motionEvent.getAction() == MotionEvent.ACTION_UP
                    || motionEvent.getAction() == MotionEvent.ACTION_CANCEL) {
                if (recordAudioVideoRunnableStarted) {
                    AndroidUtilities.cancelRunOnUIThread(recordAudioVideoRunnable);
                    setRecordVideoButtonVisible(videoSendButton.getTag() == null, true);
                } else {
                    startedDraggingX = -1;
                    if (hasRecordVideo && videoSendButton.getTag() != null) {
                        delegate.needStartRecordVideo(1);
                    } else {
                        MediaController.getInstance().stopRecording(1);
                    }
                    recordingAudioVideo = false;
                    updateRecordIntefrace();
                }
            } else if (motionEvent.getAction() == MotionEvent.ACTION_MOVE && recordingAudioVideo) {
                float x = motionEvent.getX();
                if (x < -distCanMove) {
                    if (hasRecordVideo && videoSendButton.getTag() != null) {
                        delegate.needStartRecordVideo(2);
                    } else {
                        MediaController.getInstance().stopRecording(0);
                    }
                    recordingAudioVideo = false;
                    updateRecordIntefrace();
                }

                x = x + audioVideoButtonContainer.getX();
                FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) slideText.getLayoutParams();
                if (startedDraggingX != -1) {
                    float dist = (x - startedDraggingX);
                    recordCircle.setTranslationX(dist);
                    params.leftMargin = AndroidUtilities.dp(30) + (int) dist;
                    slideText.setLayoutParams(params);
                    float alpha = 1.0f + dist / distCanMove;
                    if (alpha > 1) {
                        alpha = 1;
                    } else if (alpha < 0) {
                        alpha = 0;
                    }
                    slideText.setAlpha(alpha);
                }
                if (x <= slideText.getX() + slideText.getWidth() + AndroidUtilities.dp(30)) {
                    if (startedDraggingX == -1) {
                        startedDraggingX = x;
                        distCanMove = (recordPanel.getMeasuredWidth() - slideText.getMeasuredWidth()
                                - AndroidUtilities.dp(48)) / 2.0f;
                        if (distCanMove <= 0) {
                            distCanMove = AndroidUtilities.dp(80);
                        } else if (distCanMove > AndroidUtilities.dp(80)) {
                            distCanMove = AndroidUtilities.dp(80);
                        }
                    }
                }
                if (params.leftMargin > AndroidUtilities.dp(30)) {
                    params.leftMargin = AndroidUtilities.dp(30);
                    recordCircle.setTranslationX(0);
                    slideText.setLayoutParams(params);
                    slideText.setAlpha(1);
                    startedDraggingX = -1;
                }
            }
            view.onTouchEvent(motionEvent);
            return true;
        }
    });

    audioSendButton = new ImageView(context);
    audioSendButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    audioSendButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_messagePanelIcons),
            PorterDuff.Mode.MULTIPLY));
    audioSendButton.setImageResource(R.drawable.mic);
    audioSendButton.setPadding(0, 0, AndroidUtilities.dp(4), 0);
    audioVideoButtonContainer.addView(audioSendButton, LayoutHelper.createFrame(48, 48));

    if (hasRecordVideo) {
        videoSendButton = new ImageView(context);
        videoSendButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        videoSendButton.setColorFilter(new PorterDuffColorFilter(
                Theme.getColor(Theme.key_chat_messagePanelIcons), PorterDuff.Mode.MULTIPLY));
        videoSendButton.setImageResource(R.drawable.ic_msg_panel_video);
        videoSendButton.setPadding(0, 0, AndroidUtilities.dp(4), 0);
        audioVideoButtonContainer.addView(videoSendButton, LayoutHelper.createFrame(48, 48));
    }

    recordCircle = new RecordCircle(context);
    recordCircle.setVisibility(GONE);
    sizeNotifierLayout.addView(recordCircle,
            LayoutHelper.createFrame(124, 124, Gravity.BOTTOM | Gravity.RIGHT, 0, 0, -36, -38));

    cancelBotButton = new ImageView(context);
    cancelBotButton.setVisibility(INVISIBLE);
    cancelBotButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    cancelBotButton.setImageDrawable(progressDrawable = new CloseProgressDrawable2());
    progressDrawable.setColorFilter(new PorterDuffColorFilter(
            Theme.getColor(Theme.key_chat_messagePanelCancelInlineBot), PorterDuff.Mode.MULTIPLY));
    cancelBotButton.setSoundEffectsEnabled(false);
    cancelBotButton.setScaleX(0.1f);
    cancelBotButton.setScaleY(0.1f);
    cancelBotButton.setAlpha(0.0f);
    sendButtonContainer.addView(cancelBotButton, LayoutHelper.createFrame(48, 48));
    cancelBotButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            String text = messageEditText.getText().toString();
            int idx = text.indexOf(' ');
            if (idx == -1 || idx == text.length() - 1) {
                setFieldText("");
            } else {
                setFieldText(text.substring(0, idx + 1));
            }
        }
    });

    sendButton = new ImageView(context);
    sendButton.setVisibility(INVISIBLE);
    sendButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    sendButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_messagePanelSend),
            PorterDuff.Mode.MULTIPLY));
    sendButton.setImageResource(R.drawable.ic_send);
    sendButton.setSoundEffectsEnabled(false);
    sendButton.setScaleX(0.1f);
    sendButton.setScaleY(0.1f);
    sendButton.setAlpha(0.0f);
    sendButtonContainer.addView(sendButton, LayoutHelper.createFrame(48, 48));
    sendButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            sendMessage();
        }
    });

    doneButtonContainer = new FrameLayout(context);
    doneButtonContainer.setVisibility(GONE);
    textFieldContainer.addView(doneButtonContainer, LayoutHelper.createLinear(48, 48, Gravity.BOTTOM));
    //        if (Build.VERSION.SDK_INT >= 21) {
    //            doneButtonContainer.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.INPUT_FIELD_SELECTOR_COLOR));
    //        }
    doneButtonContainer.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            doneEditingMessage();
        }
    });

    doneButtonImage = new ImageView(context);
    doneButtonImage.setScaleType(ImageView.ScaleType.CENTER);
    doneButtonImage.setImageResource(R.drawable.edit_done);
    doneButtonImage.setColorFilter(
            new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_editDoneIcon), PorterDuff.Mode.MULTIPLY));
    doneButtonContainer.addView(doneButtonImage, LayoutHelper.createFrame(48, 48));

    doneButtonProgress = new ContextProgressView(context, 0);
    doneButtonProgress.setVisibility(View.INVISIBLE);
    doneButtonContainer.addView(doneButtonProgress,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));

    SharedPreferences sharedPreferences = ApplicationLoader.applicationContext.getSharedPreferences("emoji",
            Context.MODE_PRIVATE);
    keyboardHeight = sharedPreferences.getInt("kbd_height", AndroidUtilities.dp(200));
    keyboardHeightLand = sharedPreferences.getInt("kbd_height_land3", AndroidUtilities.dp(200));

    setRecordVideoButtonVisible(false, false);
    checkSendButton(false);
}

From source file:com.tr4android.support.extension.widget.CollapsingTextHelper.java

private void ensureExpandedTexture() {
    if (mExpandedTitleTexture != null || mExpandedBounds.isEmpty() || TextUtils.isEmpty(mTextToDraw)) {
        return;/*from ww w.  ja va 2 s  . c om*/
    }

    calculateOffsets(0f);
    mTextureAscent = mTextPaint.ascent();
    mTextureDescent = mTextPaint.descent();

    final int w = Math.round(mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()));
    final int h = Math.round(mTextureDescent - mTextureAscent);

    if (w <= 0 && h <= 0) {
        return; // If the width or height are 0, return
    }

    mExpandedTitleTexture = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);

    Canvas c = new Canvas(mExpandedTitleTexture);
    c.drawText(mTextToDraw, 0, mTextToDraw.length(), 0, h - mTextPaint.descent(), mTextPaint);

    if (mTexturePaint == null) {
        // Make sure we have a paint
        mTexturePaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
    }
}

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

private void ensureExpandedTexture() {
    if (mExpandedTitleTexture != null || mExpandedBounds.isEmpty() || TextUtils.isEmpty(mTextToDraw)) {
        return;/*from w ww  .j  a  v a 2  s  .  c  om*/
    }

    calculateOffsets(0f);
    mTextureAscent = mTextPaint.ascent();
    mTextureDescent = mTextPaint.descent();

    final int w = Math.round(mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()));
    final int h = Math.round(mTextureDescent - mTextureAscent);

    if (w <= 0 || h <= 0) {
        return; // If the width or height are 0, return
    }

    mExpandedTitleTexture = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);

    Canvas c = new Canvas(mExpandedTitleTexture);
    c.drawText(mTextToDraw, 0, mTextToDraw.length(), 0, h - mTextPaint.descent(), mTextPaint);

    if (mTexturePaint == null) {
        // Make sure we have a paint
        mTexturePaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
    }
}

From source file:org.buffer.android.buffertextinputlayout.util.CollapsingTextHelper.java

private void ensureExpandedTexture() {
    if (mExpandedTitleTexture != null || mExpandedBounds.isEmpty() || TextUtils.isEmpty(mTextToDraw)) {
        return;/*from   www. j a va 2s  .co m*/
    }
    calculateOffsets(0f);
    mTextureAscent = mTextPaint.ascent();
    mTextureDescent = mTextPaint.descent();
    final int w = Math.round(mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()));
    final int h = Math.round(mTextureDescent - mTextureAscent);
    if (w <= 0 || h <= 0) {
        return; // If the width or height are 0, return
    }
    mExpandedTitleTexture = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(mExpandedTitleTexture);
    c.drawText(mTextToDraw, 0, mTextToDraw.length(), 0, h - mTextPaint.descent(), mTextPaint);
    if (mTexturePaint == null) {
        // Make sure we have a paint
        mTexturePaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
    }
}

From source file:com.mylikes.likes.etchasketch.Slate.java

private void drawStrokeDebugInfo(Canvas c) {
    final int ROW_HEIGHT = 24;
    final int ROW_MARGIN = 6;
    final int COLUMN_WIDTH = 55;

    final float FIRM_PRESSURE_LOW = 0.85f;
    final float FIRM_PRESSURE_HIGH = 1.25f;

    if (mStrokeDebugGraph == null) {
        final int width = c.getWidth() - 128;
        final int height = ROW_HEIGHT * mStrokes.length + 2 * ROW_MARGIN;
        mStrokeDebugGraph = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        if (mStrokeDebugGraph == null) {
            throw new RuntimeException(
                    "drawStrokeDebugInfo: couldn't create debug bitmap (" + width + "x" + height + ")");
        }/*w w w  .j  av a 2 s .c o  m*/
        mGraphPaint1 = new Paint(Paint.ANTI_ALIAS_FLAG);
    }

    Canvas graph = new Canvas(mStrokeDebugGraph);
    graph.save();
    graph.clipRect(new Rect(0, 0, COLUMN_WIDTH, graph.getHeight()));
    graph.drawColor(0, PorterDuff.Mode.CLEAR);
    graph.restore();

    int left = 4;
    int bottom = graph.getHeight() - ROW_MARGIN;
    final int STEP = 4;
    for (MarkersPlotter st : mStrokes) {
        float r = st.getLastPressure();

        if (r >= FIRM_PRESSURE_LOW && r <= FIRM_PRESSURE_HIGH)
            mGraphPaint1.setColor(0xFF33FF33);
        else if (r < FIRM_PRESSURE_LOW)
            mGraphPaint1.setColor(0xFF808080);
        else
            mGraphPaint1.setColor(0xFFFF8000);

        String s = (r < 0) ? "--"
                : String.format("%s %.4f", ((st.getLastTool() == MotionEvent.TOOL_TYPE_STYLUS) ? "S" : "F"), r);

        graph.drawText(s, left, bottom - 2, mGraphPaint1);

        if (mGraphX + COLUMN_WIDTH > graph.getWidth()) {
            mGraphX = 0;
            graph.save();
            graph.clipRect(new Rect(30, 0, graph.getWidth(), graph.getHeight()));
            graph.drawColor(0, PorterDuff.Mode.CLEAR);
            graph.restore();
        }

        if (r >= 0) {
            int barsize = (int) (r * ROW_HEIGHT);
            graph.drawRect(mGraphX + COLUMN_WIDTH, bottom - barsize, mGraphX + COLUMN_WIDTH + STEP, bottom,
                    mGraphPaint1);
        } else {
            graph.drawPoint(mGraphX + COLUMN_WIDTH + STEP, bottom, mGraphPaint1);
        }
        bottom -= (ROW_HEIGHT + ROW_MARGIN);
    }

    mGraphX += STEP;

    final int x = 96;
    final int y = 64;

    c.drawBitmap(mStrokeDebugGraph, x, y, null);
    invalidate(new Rect(x, y, x + c.getWidth(), y + c.getHeight()));
}

From source file:com.wanikani.androidnotifier.DashboardFragment.java

/**
 * Apply a circular mask on the given bitmap. This method is
 * used to display the avatar.//w  w w  . j a v  a 2 s. c om
 * @param bmp an input bitmap
 * @param result the output (masked) bitmap
 */
private Bitmap mask(Bitmap bmp) {
    Bitmap result, mask;
    Drawable dmask;
    Canvas canvas;
    Paint paint;

    result = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), Bitmap.Config.ARGB_8888);
    canvas = new Canvas(result);

    dmask = getResources().getDrawable(R.drawable.gravatar_mask);
    mask = ((BitmapDrawable) dmask).getBitmap();

    paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
    canvas.drawBitmap(bmp, 0, 0, null);
    canvas.drawBitmap(mask, 0, 0, paint);

    return result;
}

From source file:com.android.leanlauncher.IconCache.java

private void renderIconBackground(Bitmap icon, Bitmap maskImage, Canvas tempCanvas, int w, int h,
        boolean drawOver) {
    // draw the scaled bitmap with mask
    Bitmap mutableMask = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);

    Canvas maskCanvas = new Canvas(mutableMask);
    maskCanvas.drawBitmap(maskImage, 0, 0, new Paint());

    // paint the bitmap with mask into the result
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setXfermode(new PorterDuffXfermode(drawOver ? DST_OUT : DST_IN));
    tempCanvas.drawBitmap(icon, (w - icon.getWidth()) / 2, (h - icon.getHeight()) / 2, null);
    tempCanvas.drawBitmap(mutableMask, 0, 0, paint);
    paint.setXfermode(null);//  w w w . j  a  v  a 2  s . c om
}

From source file:com.aniruddhc.acemusic.player.LauncherActivity.LauncherActivity.java

public void showTrialDialog(final boolean expired, int numDaysRemaining) {

    AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
    builder.setTitle(R.string.app_name);
    builder.setCancelable(false);/*w  w  w  .j ava 2  s  .  c  o  m*/

    View view = this.getLayoutInflater().inflate(R.layout.trial_expiry_dialog, null);
    TextView trialExpiredText = (TextView) view.findViewById(R.id.trial_message);
    TextView trialDaysRemaining = (TextView) view.findViewById(R.id.trial_days_remaining);
    TextView trialDaysCaps = (TextView) view.findViewById(R.id.days_caps);

    trialExpiredText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
    trialExpiredText
            .setPaintFlags(trialExpiredText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

    trialDaysRemaining.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));

    trialDaysCaps.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
    trialDaysCaps
            .setPaintFlags(trialDaysCaps.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

    if (expired) {
        trialDaysRemaining.setText(R.string.expired);
        trialExpiredText.setText(R.string.trial_expired);
        trialDaysRemaining.setTextColor(0xFFFF8800);
        trialDaysCaps.setVisibility(View.GONE);
        trialDaysRemaining.setTextSize(36);
        trialDaysRemaining.setPaintFlags(
                trialDaysRemaining.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
    } else {
        trialExpiredText.setText(R.string.trial_running);
        trialDaysRemaining.setText("" + numDaysRemaining);
        trialDaysCaps.setVisibility(View.VISIBLE);
        trialDaysRemaining.setTextColor(0xFF0099CC);
        trialDaysRemaining.setPaintFlags(trialDaysRemaining.getPaintFlags() | Paint.ANTI_ALIAS_FLAG
                | Paint.SUBPIXEL_TEXT_FLAG | Paint.FAKE_BOLD_TEXT_FLAG);
    }

    builder.setView(view);
    builder.setPositiveButton(R.string.upgrade, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            showUpgradeFragmentWithPromo();

        }

    });

    builder.setNegativeButton(R.string.later, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (expired) {
                finish();
            } else {
                launchMainActivity();
            }

        }

    });

    builder.create().show();
}

From source file:net.gsantner.opoc.util.ContextUtils.java

/**
 * Draw text in the center of the given {@link DrawableRes}
 * This may be useful for e.g. badge counts
 *//*www .  j  a v a  2 s. c o  m*/
public Bitmap drawTextOnDrawable(@DrawableRes int drawableRes, String text, int textSize) {
    Resources resources = _context.getResources();
    float scale = resources.getDisplayMetrics().density;
    Bitmap bitmap = drawableToBitmap(drawableRes);

    bitmap = bitmap.copy(bitmap.getConfig(), true);
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(Color.rgb(61, 61, 61));
    paint.setTextSize((int) (textSize * scale));
    paint.setShadowLayer(1f, 0f, 1f, Color.WHITE);

    Rect bounds = new Rect();
    paint.getTextBounds(text, 0, text.length(), bounds);
    int x = (bitmap.getWidth() - bounds.width()) / 2;
    int y = (bitmap.getHeight() + bounds.height()) / 2;
    canvas.drawText(text, x, y, paint);

    return bitmap;
}

From source file:de.mrapp.android.util.BitmapUtil.java

/**
 * Creates and returns a bitmap from a specific text. The text is centered.
 *
 * @param context/*  ww  w. j ava2  s.c  o m*/
 *         The context, which should be used, as an instance of the class {@link Context}. The
 *         context may not be null
 * @param width
 *         The width of the bitmap, which should be created, in pixels as an {@link Integer}
 *         value
 * @param height
 *         The height of the bitmap, which should be created, in pixels as an {@link Integer}
 *         value
 * @param backgroundColor
 *         The background color of the bitmap, which should be created, as an {@link Integer}
 *         value
 * @param text
 *         The text, the bitmap should be created from, as an instance of the type {@link
 *         CharSequence}. The text may neither be null, nor empty
 * @param textSize
 *         The text size, which should be used, in sp as an {@link Integer} value
 * @param textColor
 *         The text color, which should be used, as an {@link Integer} value The color of the
 *         text
 * @param typeface
 *         The typeface, which should be used, as a value of the enum {@link Typeface} or null,
 *         if the default typeface should be used
 * @return The bitmap, which has been created, as an instance of the class {@link Bitmap}
 */
public static Bitmap textToBitmap(@NonNull final Context context, final int width, final int height,
        @ColorInt final int backgroundColor, @NonNull final CharSequence text, final float textSize,
        @ColorInt final int textColor, @Nullable final Typeface typeface) {
    ensureNotNull(context, "The context may not be null");
    ensureNotNull(text, "The text may not be null");
    ensureNotEmpty(text, "The text may not be empty");
    ensureAtLeast(textSize, 1, "The text size must be at least 1");
    Bitmap bitmap = colorToBitmap(width, height, backgroundColor);
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(textColor);
    paint.setTextSize(textSize * getDensity(context));
    paint.setTextAlign(Align.CENTER);

    if (typeface != null) {
        paint.setTypeface(typeface);
    }

    int x = bitmap.getWidth() / 2;
    int y = (int) ((bitmap.getHeight() / 2) - ((paint.descent() + paint.ascent()) / 2));
    canvas.drawText(text.toString(), x, y, paint);
    return bitmap;
}