List of usage examples for android.graphics Canvas drawCircle
public void drawCircle(float cx, float cy, float radius, @NonNull Paint paint)
From source file:com.albedinsky.android.ui.widget.SeekBarWidget.java
/** * Draws discrete interval, its thick marks depending on the current {@link #mDiscreteIntervalRatio} * value./*ww w . j a va 2s .c o m*/ * * @param canvas Canvas on which to draw discrete interval. */ private void drawDiscreteInterval(Canvas canvas) { if (mDiscreteIntervalRatio == 0 || mProgressDrawable == null) { return; } final Rect trackBounds = mProgressDrawable.getBounds(); final int trackLeft = getPaddingLeft(); final int cy = trackBounds.centerY(); float trackWidth = trackBounds.width(); final float discreteInterval = mDiscreteIntervalRatio * trackWidth; trackWidth += DISCRETE_INTERVAL_TICK_MARK_INFO.radius; final Rect thumbBounds = mThumb != null ? mThumb.getBounds() : null; final int thumbOffset = getThumbOffset(); float cx = 0; while (cx <= trackWidth) { // Ensure to not draw over thumb if it is not expected behaviour. final boolean isAtThumbPosition = thumbBounds != null && trackLeft + cx >= thumbBounds.left + thumbOffset && trackLeft + cx <= thumbBounds.right + thumbOffset; if (CAN_DRAW_DISCRETE_INTERVAL_OVER_THUMB || !isAtThumbPosition) { canvas.drawCircle(trackLeft + cx, cy, DISCRETE_INTERVAL_TICK_MARK_INFO.radius, DISCRETE_INTERVAL_TICK_MARK_INFO.paint); } cx += discreteInterval; } }
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);/*from ww w.j a va2s . 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.lyue.aw_jitpack_aar.app.zxing.zxing.view.ViewfinderView.java
@Override public void onDraw(Canvas canvas) { //CameraManager Rect frame = CameraManager.get().getFramingRect(); if (frame == null) { return;//w w w . j av a2 s .co m } // if (!isFirst) { isFirst = true; slideTop = frame.top; slideBottom = frame.bottom; } // int width = canvas.getWidth(); int height = canvas.getHeight(); paint.setColor(resultBitmap != null ? resultColor : maskColor); // // canvas.drawRect(0, 0, width, frame.top, paint); canvas.drawRect(0, frame.top, frame.left, frame.bottom + 1, paint); canvas.drawRect(frame.right + 1, frame.top, width, frame.bottom + 1, paint); canvas.drawRect(0, frame.bottom + 1, width, height, paint); if (resultBitmap != null) { // Draw the opaque result bitmap over the scanning rectangle paint.setAlpha(OPAQUE); canvas.drawBitmap(resultBitmap, frame.left, frame.top, paint); } else { //8 paint.setColor(Color.GREEN); canvas.drawRect(frame.left, frame.top, frame.left + ScreenRate, frame.top + CORNER_WIDTH, paint); canvas.drawRect(frame.left, frame.top, frame.left + CORNER_WIDTH, frame.top + ScreenRate, paint); canvas.drawRect(frame.right - ScreenRate, frame.top, frame.right, frame.top + CORNER_WIDTH, paint); canvas.drawRect(frame.right - CORNER_WIDTH, frame.top, frame.right, frame.top + ScreenRate, paint); canvas.drawRect(frame.left, frame.bottom - CORNER_WIDTH, frame.left + ScreenRate, frame.bottom, paint); canvas.drawRect(frame.left, frame.bottom - ScreenRate, frame.left + CORNER_WIDTH, frame.bottom, paint); canvas.drawRect(frame.right - ScreenRate, frame.bottom - CORNER_WIDTH, frame.right, frame.bottom, paint); canvas.drawRect(frame.right - CORNER_WIDTH, frame.bottom - ScreenRate, frame.right, frame.bottom, paint); //,SPEEN_DISTANCE slideTop += SPEEN_DISTANCE; if (slideTop >= frame.bottom) { slideTop = frame.top; } Rect lineRect = new Rect(); lineRect.left = frame.left; lineRect.right = frame.right; lineRect.top = slideTop; lineRect.bottom = slideTop + 18; canvas.drawBitmap( ((BitmapDrawable) (getResources().getDrawable(R.drawable.aar_qrcode_scan_line))).getBitmap(), null, lineRect, paint); // paint.setColor(Color.WHITE); paint.setTextSize(TEXT_SIZE * density); paint.setAlpha(0x40); paint.setTypeface(Typeface.create("System", Typeface.BOLD)); String text = getResources().getString(R.string.scan_text); float textWidth = paint.measureText(text); canvas.drawText(text, (width - textWidth) / 2, (float) (frame.bottom + (float) TEXT_PADDING_TOP * density), paint); Collection<ResultPoint> currentPossible = possibleResultPoints; Collection<ResultPoint> currentLast = lastPossibleResultPoints; if (currentPossible.isEmpty()) { lastPossibleResultPoints = null; } else { possibleResultPoints = new HashSet<ResultPoint>(5); lastPossibleResultPoints = currentPossible; paint.setAlpha(OPAQUE); paint.setColor(resultPointColor); for (ResultPoint point : currentPossible) { canvas.drawCircle(frame.left + point.getX(), frame.top + point.getY(), 6.0f, paint); } } if (currentLast != null) { paint.setAlpha(OPAQUE / 2); paint.setColor(resultPointColor); for (ResultPoint point : currentLast) { canvas.drawCircle(frame.left + point.getX(), frame.top + point.getY(), 3.0f, paint); } } // postInvalidateDelayed(ANIMATION_DELAY, frame.left, frame.top, frame.right, frame.bottom); } }
From source file:com.bolaa.medical.view.banner.LoopCirclePageIndicator.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mViewPager == null) { return;/* w w w. j a v a 2 s .c o m*/ } final int count = mViewPager.getAdapter().getCount(); if (count == 0) { return; } if (mCurrentPage >= count) { setCurrentItem(count - 1); return; } int longSize; int longPaddingBefore; int longPaddingAfter; int shortPaddingBefore; if (mOrientation == HORIZONTAL) { longSize = getWidth(); longPaddingBefore = getPaddingLeft(); longPaddingAfter = getPaddingRight(); shortPaddingBefore = getPaddingTop(); } else { longSize = getHeight(); longPaddingBefore = getPaddingTop(); longPaddingAfter = getPaddingBottom(); shortPaddingBefore = getPaddingLeft(); } final float threeRadius = mRadius * 3; final float shortOffset = shortPaddingBefore + mRadius; float longOffset = longPaddingBefore + mRadius; int longPaddingRight = realCount * 15; if (mRight) { //todo longOffset += ((longSize - longPaddingBefore - (longPaddingAfter + longPaddingRight))) - ((realCount * threeRadius) / 2.0f); } else { longOffset += ((longSize - longPaddingBefore - longPaddingAfter) / 2.0f) - ((realCount * threeRadius) / 2.0f); } float dX; float dY; float pageFillRadius = mRadius + 1; // if (mPaintStroke.getStrokeWidth() > 0) { // pageFillRadius -= mPaintStroke.getStrokeWidth() / 2.0f; // } //Draw stroked circle // for (int iLoop = 0; iLoop < realCount; iLoop++) { // float drawLong = longOffset + (iLoop * threeRadius); // if (mOrientation == HORIZONTAL) { // dX = drawLong; // dY = shortOffset; // } else { // dX = shortOffset; // dY = drawLong; // } // // Only paint fill if not completely transparent // if (mPaintPageFill.getAlpha() > 0 && isNeedCircle) { //// canvas.drawRect(dX, dY, dX + mRadius, dY + mRadius, mPaintPageFill); //// canvas.drawCircle(dX, dY, pageFillRadius, mPaintPageFill); // } // // // Only paint stroke if a stroke width was non-zero // if (pageFillRadius != mRadius && isNeedCircle) { //// canvas.drawRect(dX, dY, dX + mRadius, dY + mRadius, mPaintStroke); //// canvas.drawCircle(dX, dY, mRadius, mPaintStroke); // } // } //Draw the filled rect according to the current scroll float cx = ((mSnap ? mSnapPage : mCurrentPage) % realCount) * threeRadius; if (!mSnap && (mPageSize != 0)) { cx += (mCurrentOffset /** 1.0f*/ / mPageSize) * threeRadius;//1.0f ?dx != dX?mPaintFill?? } if (mOrientation == HORIZONTAL) { dX = longOffset + cx; dY = shortOffset; } else { dX = shortOffset; dY = longOffset + cx; } float dx; if (isNeedCircle) { for (int i = 0; i < realCount; i++) { dx = longOffset + (i * threeRadius); if (dx != dX) { canvas.drawCircle(dx, dY, mRadius, mPaintFill);//?n-1 } canvas.drawCircle(dX, dY, pageFillRadius, mPaintPageFill);//???n } } }
From source file:com.google.zxing.client.android.ViewfinderView.java
@SuppressLint("DrawAllocation") @Override//w w w . j a v a 2 s . c o m public void onDraw(Canvas canvas) { if (cameraManager == null) { return; // not ready yet, early draw before done configuring } Rect frame = cameraManager.getFramingRect(); Rect previewFrame = cameraManager.getFramingRectInPreview(); if (frame == null || previewFrame == null) { return; } int width = canvas.getWidth(); int height = canvas.getHeight(); // Draw the exterior (i.e. outside the framing rect) darkened paint.setColor(resultBitmap != null ? resultColor : maskColor); canvas.drawRect(0, 0, width, frame.top, paint); canvas.drawRect(0, frame.top, frame.left, frame.bottom, paint); canvas.drawRect(frame.right, frame.top, width, frame.bottom, paint); canvas.drawRect(0, frame.bottom, width, height, paint); /// // paint.setColor(getResources().getColor(R.color.encode_view)); int w = 16; int h = 2; int margin = 2; // canvas.drawRect(frame.left - margin - h, frame.top - margin - h, frame.left - margin + w - h, frame.top - margin + h - h, paint); canvas.drawRect(frame.left - margin - h, frame.top - margin - h, frame.left - margin + h - h, frame.top - margin + w - h, paint); // ? canvas.drawRect(frame.right + margin - w + h, frame.top - margin - h, frame.right + margin + h, frame.top - margin + h - h, paint); canvas.drawRect(frame.right + margin - h + h, frame.top - margin - h, frame.right + margin + h, frame.top - margin + w - h, paint); // canvas.drawRect(frame.left - margin - h, frame.bottom + margin - h + h, frame.left - margin + w - h, frame.bottom + margin + h, paint); canvas.drawRect(frame.left - margin - h, frame.bottom + margin - w + h, frame.left - margin + h - h, frame.bottom + margin + h, paint); // ? canvas.drawRect(frame.right + margin - w + h, frame.bottom + margin - h + h, frame.right + margin + h, frame.bottom + margin + h, paint); canvas.drawRect(frame.right + margin - h + h, frame.bottom + margin - w + h, frame.right + margin + h, frame.bottom + margin + h, paint); ///? drawLineRound(canvas, frame, paint); if (statusText != null) { RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) statusText.getLayoutParams(); lp.topMargin = frame.top - statusText.getMeasuredHeight() - 28; statusText.setLayoutParams(lp); statusText.setVisibility(View.VISIBLE); } if (resultBitmap != null) { // Draw the opaque result bitmap over the scanning rectangle if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { paint.setAlpha(CURRENT_POINT_OPACITY); } canvas.drawBitmap(resultBitmap, null, frame, paint); } else { // ?? if ((i += 5) < frame.bottom - frame.top) { /* ?? */ mRect.set(frame.left, frame.top + i - 1, frame.right, frame.top + i + 1); lineDrawable.setBounds(mRect); lineDrawable.draw(canvas); // invalidate(); } else { i = 0; } float scaleX = frame.width() / (float) previewFrame.width(); float scaleY = frame.height() / (float) previewFrame.height(); List<ResultPoint> currentPossible = possibleResultPoints; List<ResultPoint> currentLast = lastPossibleResultPoints; int frameLeft = frame.left; int frameTop = frame.top; if (currentPossible.isEmpty()) { lastPossibleResultPoints = null; } else { possibleResultPoints = new ArrayList<>(5); lastPossibleResultPoints = currentPossible; if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { paint.setAlpha(CURRENT_POINT_OPACITY); } paint.setColor(resultPointColor); synchronized (currentPossible) { for (ResultPoint point : currentPossible) { canvas.drawCircle(frameLeft + (int) (point.getX() * scaleX), frameTop + (int) (point.getY() * scaleY), POINT_SIZE, paint); } } } if (currentLast != null) { if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { paint.setAlpha(CURRENT_POINT_OPACITY / 2); } paint.setColor(resultPointColor); synchronized (currentLast) { float radius = POINT_SIZE / 2.0f; for (ResultPoint point : currentLast) { canvas.drawCircle(frameLeft + (int) (point.getX() * scaleX), frameTop + (int) (point.getY() * scaleY), radius, paint); } } } // Request another update at the animation interval, but only repaint the laser line, // not the entire viewfinder mask. postInvalidateDelayed(ANIMATION_DELAY, frame.left - POINT_SIZE, frame.top - POINT_SIZE, frame.right + POINT_SIZE, frame.bottom + POINT_SIZE); } }
From source file:com.tmall.ultraviewpager.UltraViewPagerIndicator.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (viewPager == null || viewPager.getAdapter() == null) return;/*from w ww . j a v a 2 s . c om*/ final int count = ((UltraViewPagerAdapter) viewPager.getAdapter()).getRealCount(); if (count == 0) return; int longSize; int shortSize; int longPaddingBefore; int longPaddingAfter; int shortPaddingBefore; int shortPaddingAfter; if (orientation == UltraViewPager.Orientation.HORIZONTAL) { longSize = viewPager.getWidth(); shortSize = viewPager.getHeight(); longPaddingBefore = getPaddingLeft() + marginLeft; longPaddingAfter = getPaddingRight() + marginRight; shortPaddingBefore = getPaddingTop() + marginTop; shortPaddingAfter = (int) paintStroke.getStrokeWidth() + getPaddingBottom() + marginBottom; } else { longSize = viewPager.getHeight(); shortSize = viewPager.getWidth(); longPaddingBefore = getPaddingTop() + marginTop; longPaddingAfter = (int) paintStroke.getStrokeWidth() + getPaddingBottom() + marginBottom; shortPaddingBefore = getPaddingLeft() + marginLeft; shortPaddingAfter = getPaddingRight() + marginRight; } final float itemWidth = getItemWidth(); final int widthRatio = isDrawResIndicator() ? 1 : 2; //bitmap resource X1 : circle X2 if (indicatorPadding == 0) { indicatorPadding = (int) itemWidth; } float shortOffset = shortPaddingBefore; float longOffset = longPaddingBefore; final float indicatorLength = (count - 1) * (itemWidth * widthRatio + indicatorPadding); final int horizontalGravityMask = gravity & Gravity.HORIZONTAL_GRAVITY_MASK; final int verticalGravityMask = gravity & Gravity.VERTICAL_GRAVITY_MASK; switch (horizontalGravityMask) { case Gravity.CENTER_HORIZONTAL: longOffset = (longSize - longPaddingBefore - longPaddingAfter - indicatorLength) / 2.0f; break; case Gravity.RIGHT: if (orientation == UltraViewPager.Orientation.HORIZONTAL) { longOffset = longSize - longPaddingAfter - indicatorLength - itemWidth; } if (orientation == UltraViewPager.Orientation.VERTICAL) { shortOffset = shortSize - shortPaddingAfter - itemWidth; } break; case Gravity.LEFT: longOffset += itemWidth; default: break; } switch (verticalGravityMask) { case Gravity.CENTER_VERTICAL: shortOffset = (shortSize - shortPaddingAfter - shortPaddingBefore - itemWidth) / 2; break; case Gravity.BOTTOM: if (orientation == UltraViewPager.Orientation.HORIZONTAL) { shortOffset = shortSize - shortPaddingAfter - getItemHeight(); } if (orientation == UltraViewPager.Orientation.VERTICAL) { longOffset = longSize - longPaddingAfter - indicatorLength; } break; case Gravity.TOP: shortOffset += itemWidth; default: break; } if (horizontalGravityMask == Gravity.CENTER_HORIZONTAL && verticalGravityMask == Gravity.CENTER_VERTICAL) { shortOffset = (shortSize - shortPaddingAfter - shortPaddingBefore - itemWidth) / 2; } float dX; float dY; float pageFillRadius = radius; if (paintStroke.getStrokeWidth() > 0) { pageFillRadius -= paintStroke.getStrokeWidth() / 2.0f; //TODO may not/2 } //Draw stroked circles for (int iLoop = 0; iLoop < count; iLoop++) { float drawLong = longOffset + (iLoop * (itemWidth * widthRatio + indicatorPadding)); if (orientation == UltraViewPager.Orientation.HORIZONTAL) { dX = drawLong; dY = shortOffset; } else { dX = shortOffset; dY = drawLong; } if (isDrawResIndicator()) { if (iLoop == viewPager.getCurrentItem()) continue; canvas.drawBitmap(normalBitmap, dX, dY, paintFill); } else { // Only paint fill if not completely transparent if (paintFill.getAlpha() > 0) { paintFill.setColor(normalColor); canvas.drawCircle(dX, dY, pageFillRadius, paintFill); } // Only paint stroke if a stroke width was non-zero if (pageFillRadius != radius) { canvas.drawCircle(dX, dY, radius, paintStroke); } } } //Draw the filled circle according to the current scroll float cx = (viewPager.getCurrentItem()) * (itemWidth * widthRatio + indicatorPadding); if (animateIndicator) cx += pageOffset * itemWidth; if (orientation == UltraViewPager.Orientation.HORIZONTAL) { dX = longOffset + cx; dY = shortOffset; } else { dX = shortOffset; dY = longOffset + cx; } if (isDrawResIndicator()) { canvas.drawBitmap(focusBitmap, dX, dY, paintStroke); } else { paintFill.setColor(focusColor); canvas.drawCircle(dX, dY, radius, paintFill); } }
From source file:com.qs.qswlw.view.Mypager.UltraViewPagerIndicator.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (viewPager == null || viewPager.getAdapter() == null) return;//from ww w. ja va 2 s. c o m final int count = ((UltraViewPagerAdapter) viewPager.getAdapter()).getRealCount(); if (count == 0) return; int longSize; int shortSize; int longPaddingBefore; int longPaddingAfter; int shortPaddingBefore; int shortPaddingAfter; if (orientation == UltraViewPager.Orientation.HORIZONTAL) { longSize = viewPager.getWidth(); shortSize = viewPager.getHeight(); longPaddingBefore = (int) (getItemWidth() + getPaddingLeft() + marginLeft); longPaddingAfter = getPaddingRight() + marginRight; shortPaddingBefore = (int) (getItemWidth() + getPaddingTop() + marginTop); shortPaddingAfter = (int) paintStroke.getStrokeWidth() + getPaddingBottom() + marginBottom; } else { longSize = viewPager.getHeight(); shortSize = viewPager.getWidth(); longPaddingBefore = (int) (getItemWidth() + getPaddingTop() + marginTop); longPaddingAfter = (int) paintStroke.getStrokeWidth() + getPaddingBottom() + marginBottom; shortPaddingBefore = (int) (getItemWidth() + getPaddingLeft() + marginLeft); shortPaddingAfter = getPaddingRight() + marginRight; } final float itemWidth = getItemWidth(); final int widthRatio = isDrawResIndicator() ? 1 : 2; //bitmap resource X1 : circle X2 if (indicatorPadding == 0) { indicatorPadding = (int) itemWidth; } float shortOffset = shortPaddingBefore; float longOffset = longPaddingBefore; final float indicatorLength = count * itemWidth * widthRatio + (count - 1) * indicatorPadding; final int horizontalGravityMask = gravity & Gravity.HORIZONTAL_GRAVITY_MASK; final int verticalGravityMask = gravity & Gravity.VERTICAL_GRAVITY_MASK; switch (horizontalGravityMask) { case Gravity.CENTER_HORIZONTAL: longOffset = (longSize - longPaddingBefore - longPaddingAfter - indicatorLength) / 2.0f; break; case Gravity.RIGHT: if (orientation == UltraViewPager.Orientation.HORIZONTAL) { longOffset = longSize - longPaddingAfter - indicatorLength; } if (orientation == UltraViewPager.Orientation.VERTICAL) { shortOffset = shortSize - shortPaddingAfter - itemWidth; } break; case Gravity.LEFT: default: break; } switch (verticalGravityMask) { case Gravity.CENTER_VERTICAL: shortOffset = (shortSize - shortPaddingAfter - shortPaddingBefore - itemWidth) / 2; break; case Gravity.BOTTOM: if (orientation == UltraViewPager.Orientation.HORIZONTAL) { shortOffset = shortSize - shortPaddingAfter - getItemHeight(); } if (orientation == UltraViewPager.Orientation.VERTICAL) { longOffset = longSize - longPaddingAfter - indicatorLength; } break; case Gravity.TOP: default: break; } if (horizontalGravityMask == Gravity.CENTER_HORIZONTAL && verticalGravityMask == Gravity.CENTER_VERTICAL) { shortOffset = (shortSize - shortPaddingAfter - shortPaddingBefore - itemWidth) / 2; } float dX; float dY; float pageFillRadius = radius; if (paintStroke.getStrokeWidth() > 0) { pageFillRadius -= paintStroke.getStrokeWidth() / 2.0f; //TODO may not/2 } //Draw stroked circles for (int iLoop = 0; iLoop < count; iLoop++) { float drawLong = longOffset + (iLoop * (itemWidth * widthRatio + indicatorPadding)); if (orientation == UltraViewPager.Orientation.HORIZONTAL) { dX = drawLong; dY = shortOffset; } else { dX = shortOffset; dY = drawLong; } if (isDrawResIndicator()) { if (iLoop == viewPager.getCurrentItem()) continue; canvas.drawBitmap(normalBitmap, dX, dY, paintFill); } else { // Only paint fill if not completely transparent if (paintFill.getAlpha() > 0) { paintFill.setColor(normalColor); canvas.drawCircle(dX, dY, pageFillRadius, paintFill); } // Only paint stroke if a stroke width was non-zero if (pageFillRadius != radius) { canvas.drawCircle(dX, dY, radius, paintStroke); } } } //Draw the filled circle according to the current scroll float cx = (viewPager.getCurrentItem()) * (itemWidth * widthRatio + indicatorPadding); if (animateIndicator) cx += pageOffset * itemWidth; if (orientation == UltraViewPager.Orientation.HORIZONTAL) { dX = longOffset + cx; dY = shortOffset; } else { dX = shortOffset; dY = longOffset + cx; } if (isDrawResIndicator()) { canvas.drawBitmap(focusBitmap, dX, dY, paintStroke); } else { paintFill.setColor(focusColor); canvas.drawCircle(dX, dY, radius, paintFill); } }
From source file:com.google.android.apps.forscience.whistlepunk.RunReviewOverlay.java
public void onDraw(Canvas canvas) { if (mIsCropping) { boolean cropStartOnChart = isXScreenPointInChart(mCropStartData.screenPoint); boolean cropEndOnChart = isXScreenPointInChart(mCropEndData.screenPoint); // Draw grey overlays first, behind everything if (cropStartOnChart) { canvas.drawRect(mChartMarginLeft, mHeight - mChartHeight - mPaddingBottom, mCropStartData.screenPoint.x, mHeight, mCropBackgroundPaint); // We can handle crop seekbar visibility in onDraw because the Seekbar Group is // in charge of receiving touch events, and that is always visible during cropping. mCropSeekbarGroup.getStartSeekBar().showThumb(); } else {/*from ww w. j a va 2s. co m*/ mCropSeekbarGroup.getStartSeekBar().hideThumb(); } if (cropEndOnChart) { canvas.drawRect(mCropEndData.screenPoint.x, mHeight - mChartHeight - mPaddingBottom, mWidth - mChartMarginRight, mHeight, mCropBackgroundPaint); mCropSeekbarGroup.getEndSeekBar().showThumb(); } else { mCropSeekbarGroup.getEndSeekBar().hideThumb(); } // Draw the flags themselves if (cropStartOnChart) { // Drawing the start flag sets mFlagMeasurements to have the start flag's bounding // box. This will allow us to place the end flag appropriately. drawFlag(canvas, mCropStartData, mFlagMeasurements, true); } else { // Clear flag measurements when the left hand flag is offscreen, so that // drawFlagAfter does not see another flag to avoid. // This means pushing the expected previous flag measurements, stored in // mFlagMeasurements, off screen by at least the amount of the flag buffer, which // allows the next flag to start drawing at 0. // In drawFlagAfter we will use mFlagMeasurements.boxEnd to determine what to // avoid. mFlagMeasurements.boxEnd = -mCropFlagBufferX; mCropStartData.labelRect.set(OFFSCREEN, OFFSCREEN, OFFSCREEN, OFFSCREEN); } if (cropEndOnChart) { drawFlagAfter(canvas, mCropEndData, mFlagMeasurements, mFlagMeasurements.boxEnd, true); } else { mCropEndData.labelRect.set(OFFSCREEN, OFFSCREEN, OFFSCREEN, OFFSCREEN); } // Neither flag can be drawn, but we might be in a region that can be cropped out // so the whole thing should be colored grey. if (!cropEndOnChart && !cropStartOnChart) { if (mCropStartData.timestamp > mExternalAxis.mXMax || mCropEndData.timestamp < mExternalAxis.mXMin) { canvas.drawRect(mChartMarginLeft, mHeight - mChartHeight - mPaddingBottom, mWidth - mChartMarginRight, mHeight, mCropBackgroundPaint); } } } else { boolean xOnChart = isXScreenPointInChart(mPointData.screenPoint); boolean yOnChart = isYScreenPointInChart(mPointData.screenPoint); if (xOnChart && yOnChart) { // We are not cropping. Draw a standard flag. drawFlag(canvas, mPointData, mFlagMeasurements, false); // Draw the vertical line from the point to the bottom of the flag float nudge = mDotRadius / 2; float cy = mHeight - mChartHeight - mPaddingBottom + mPointData.screenPoint.y - 2 * mDotBackgroundRadius + nudge; mPath.reset(); mPath.moveTo(mPointData.screenPoint.x, mFlagMeasurements.notchBottom); mPath.lineTo(mPointData.screenPoint.x, cy); canvas.drawPath(mPath, mLinePaint); // Draw the selected point float cySmall = cy + 1.5f * mDotBackgroundRadius; canvas.drawCircle(mPointData.screenPoint.x, cySmall, mDotBackgroundRadius, mDotBackgroundPaint); canvas.drawCircle(mPointData.screenPoint.x, cySmall, mDotRadius, mDotPaint); } else { mPointData.labelRect.set(OFFSCREEN, OFFSCREEN, OFFSCREEN, OFFSCREEN); } } }
From source file:com.lt.adamlee.aagame.GameView.java
public void onDraw(Canvas c) { try {/*from w w w . j a va 2 s .c o m*/ if (mainpage == -1) { this.eg.exitdialog(c); } if (mainpage == 1) { if (bak2) { internalcounter2++; if (internalcounter2 % 10 == 0) { counter1234++; } if (counter1234 >= 2) { counter1234 = 0; internalcounter2 = 0; bak2 = false; } } if (bak4) { this.internalcounter4++; if (this.internalcounter4 % 10 == 0) { this.counter12346++; } if (this.counter12346 >= 2) { this.counter12346 = 0; this.internalcounter4 = 0; bak4 = false; } } c.drawBitmap(this.mainpageimage, 0.0f, 0.0f, null); c.drawBitmap(this.play, F.wf(110.0f), F.hf(175.0f), null); c.drawBitmap(this.moreapps, F.wf(45.0f), F.hf(340.0f), null); c.drawBitmap(this.help, F.wf(130.0f), F.hf(340.0f), null); c.drawBitmap(this.leaderboard, F.wf(215.0f), F.hf(340.0f), null); } if (mainpage == 5) { help(c); } if (mainpage == 6) { this.anim.levelanim(c); } if (mainpage == 7) { if (this.bakc) { this.internalcounterc++; if (this.internalcounterc % 10 == 0) { this.counterc++; } if (this.counterc >= 2) { this.counterc = 0; this.internalcounterc = 0; this.bakc = false; } } this.level.Level_Canvas(c); } if (mainpage == 3) { float[] fArr; if (baka) { this.internalcountera++; if (this.internalcountera % 10 == 0) { this.countera++; } if (this.countera >= 2) { this.countera = 0; this.internalcountera = 0; baka = false; } } view.drawRectangle(c); if (levelcounter % 3 == 0) { if (rotation[0] <= 0.0f && rotation[0] <= 0.0f) { changeangle = 2.0d; } if (rotation[0] > 0.0f && rotation[0] >= 360.0f) { changeangle = -2.0d; } } if (levelcounter % 3 == 1) { changeangle = 2.0d; } if (levelcounter % 3 == 2) { changeangle = -2.0d; } x = (int) F.wf(160.0f); y = (int) F.hf(159.0f); r = (int) F.wf(10.0f); int i = 0; while (i < blinedraw.length) { if (blinedraw[i]) { c.save(); c.rotate(rotation[i], (float) (screenW / 2), F.hf(272.0f)); c.drawLine((float) (screenW / 2), F.hf(272.0f), (float) (screenW / 2), F.hf(272.0f) - F.hf(105.0f), paint4); c.drawCircle((float) x, (float) y, (float) r, paint3); c.drawBitmap(this.cartoonbomb, new Rect(0, 0, this.cartoonbomb.getWidth(), this.cartoonbomb.getHeight()), new Rect(x - (this.cartoonbomb.getWidth() / 2), y - (this.cartoonbomb.getHeight() / 2), x + (this.cartoonbomb.getWidth() / 2), y + (this.cartoonbomb.getHeight() / 2)), null); if (i >= saveline) { c.drawText((Circle.var - (i - saveline) + ""), (float) x, (float) ((int) F.hf(163.0f)), this.innercircletext); } savex[i] = x; savey[i] = y; if (changeangle > 0.0d && rotation[i] >= 360.0f) { rotation[i] = 0.0f; } if (changeangle < 0.0d && rotation[i] <= -360.0f) { rotation[i] = 0.0f; } if (!(errorcircle || !GameActivity.isResume || circleblink)) { fArr = rotation; fArr[i] = (float) (((double) fArr[i]) + changeangle); } c.restore(); if (circleblink) { holdcounter++; if (holdcounter > 32000) { holdcounter = 0; } if (holdcounter % 5 == 0) { hcm++; } if (hcm > 32000) { hcm = 0; } if (hcm <= 9) { h = (int) F.wf(160.0f); j = (int) F.hf(159.0f); k = (int) F.wf(11.0f); paint7.setAlpha(a1); paint7.setColor(SupportMenu.CATEGORY_MASK); paint7.setAntiAlias(true); paint7.setFilterBitmap(true); paint7.setStrokeWidth(2.0f); c.drawCircle((float) h, (float) j, (float) k, paint7); c.drawCircle((float) x, (float) y, (float) r, paint3); if (i >= saveline) { c.drawText((Circle.var - (i - saveline) + ""), (float) x, (float) ((int) F.hf(163.0f)), this.innercircletext); } } if (hcm >= 11) { circleblink = false; mainpage = 6; // GameActivity.vimapad.isBottomAdVisible(true); // GameActivity.vimapad.isTopAdVisible(true); holdcounter = 0; hcm = 0; } } } i++; } i = 0; while (i < circledrawboolean.length) { if (circledrawboolean[i]) { c.save(); c.rotate(rotation[i], (float) (screenW / 2), F.hf(272.0f)); c.drawLine((float) (screenW / 2), F.hf(272.0f), (float) (screenW / 2), F.hf(272.0f) - F.hf(105.0f), paint4); c.drawCircle((float) x, (float) y, (float) r, paint3); if (i >= saveline) { c.drawText((Circle.var - (i - saveline) + ""), (float) x, (float) ((int) F.hf(163.0f)), this.innercircletext); } savex[i] = x; savey[i] = y; if (changeangle > 0.0d && rotation[i] >= 360.0f) { rotation[i] = 0.0f; } if (changeangle < 0.0d && rotation[i] <= -360.0f) { rotation[i] = 0.0f; } if (!(errorcircle || !GameActivity.isResume || circleblink)) { fArr = rotation; fArr[i] = (float) (((double) fArr[i]) + changeangle); } c.restore(); if (colcircle) { this.displaycount3++; textdisplayboolean = false; if (this.displaycount3 <= 70 || (this.displaycount3 >= 80 && this.displaycount3 <= 90)) { paint6.setAntiAlias(true); } paint6.setFilterBitmap(true); paint6.setColor(ViewCompat.MEASURED_STATE_MASK); c.drawCircle((float) (screenW / 2), F.hf(272.0f), F.wf(39.0f), paint6); paint6.setColor(SupportMenu.CATEGORY_MASK); paint6.setAntiAlias(true); paint6.setFilterBitmap(true); paint6.setTypeface(tf); paint6.setAlpha(Circle.a); paint6.setTextAlign(Paint.Align.CENTER); c.drawText(String.valueOf(levelcounter), F.wf(160.0f), F.hf(278.0f), paint6); paint6.setColor(getResources().getColor(R.color.common_signin_btn_default_background)); paint6.setAlpha(20); paint6.setAntiAlias(true); paint6.setFilterBitmap(true); c.drawRect(0.0f, 0.0f, (float) screenW, (float) screenH, paint6); if (this.displaycount3 <= 70 || this.displaycount3 >= 80) { } if (this.displaycount3 > 90) { int j; this.displaycount3 = 0; colcircle = false; circleblink = false; bak4 = true; reset(); levelcounter++; errorcircle = false; linecounter = NoOfInitialLines - 1; for (j = 0; j < NoOfInitialLines; j++) { blinedraw[j] = true; } for (j = 0; j < rotation.length; j++) { rotation[j] = 0.0f; } for (j = 0; j < NoOfInitialLines; j++) { rotation[j] = (float) ((j + 1) * (360 / NoOfInitialLines)); if (rotation[j] > 360.0f) { rotation[j] = rotation[j] - 360.0f; } } } } } i++; } this.paint21.setColor(-1); this.paint21.setTypeface(tf); this.paint21.setTextAlign(Paint.Align.CENTER); this.paint21.setAntiAlias(true); this.paint21.setFilterBitmap(true); if (textdisplayboolean) { c.drawText(String.valueOf(levelcounter), F.wf(160.0f), F.hf(278.0f), this.paint21); } } } catch (Exception e) { } }
From source file:com.skytree.epubtest.BookViewActivity.java
@Override public void draw(Canvas canvas) { int lvl = getLevel(); Rect b = getBounds();/*from w w w. j a v a 2 s . c o m*/ float x = (float) b.width() * (float) lvl / 10000.0f; float y = (b.height() - mPaint.getStrokeWidth()) / 2; mPaint.setStyle(Paint.Style.FILL); for (int cx = 10; cx < b.width(); cx += 30) { float cr = (float) ((float) (cx - 10) / (float) (b.width() - 10)) * 100; if (cr <= this.value) { mPaint.setColor(color); if (color != inactiveColor) { canvas.drawCircle(cx, y, 6, mPaint); } else { canvas.drawCircle(cx, y, 4, mPaint); } } else { mPaint.setColor(inactiveColor); canvas.drawCircle(cx, y, 4, mPaint); } } }