List of usage examples for android.graphics Canvas getWidth
public int getWidth()
From source file:t3.giftbook.util.FlipViewPager.java
private Bitmap prepareBmp(Canvas canvas) { return Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Config.ARGB_8888); }
From source file:com.android.launcher3.ViewPager.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); width = canvas.getWidth() / 2; float currentPageSize = width / 10; float size = width / 10; float margin = width / 10; currentPage.setTextSize(currentPageSize); currentPage.setColor(Color.GREEN); p.setTextSize(size);/*from w ww. j a va2s .c om*/ p.setColor(Color.BLUE); width = width + (2 * width - 180) * off + 2 * (mPosition - initialization) * width; if (hideTitle) { canvas.drawText("", width - currentPageSize, 70, currentPage); return; } // Draw the margin drawable between pages if needed. //Log.i("ViewPager", off + "-" + mPosition + "-" + initialization + "- " + width); try { switch (mPosition) { case 0: currentPageSize += currentPageSize; canvas.drawText(name.get(0), width - currentPageSize, 70, currentPage); canvas.drawText(name.get(1), width + currentPageSize + margin, 70, p); canvas.drawText(name.get(2), width + currentPageSize + margin + size * 4 + margin, 70, p); canvas.drawText(name.get(3), width + currentPageSize + margin + size * 8 + margin * 2, 70, p); canvas.drawText(name.get(4), width + currentPageSize + margin + size * 12 + margin * 3, 70, p); canvas.drawText(name.get(5), width + currentPageSize + margin + size * 16 + margin * 4, 70, p); canvas.drawText(name.get(6), width + currentPageSize + margin + size * 20 + margin * 5, 70, p); break; case 1: currentPageSize += currentPageSize; canvas.drawText(name.get(0), width - currentPageSize - margin - size * 4, 70, p); canvas.drawText(name.get(1), width - currentPageSize, 70, currentPage); canvas.drawText(name.get(2), width + currentPageSize + margin, 70, p); canvas.drawText(name.get(3), width + currentPageSize + margin + size * 4 + margin, 70, p); canvas.drawText(name.get(4), width + currentPageSize + margin + size * 8 + margin * 2, 70, p); canvas.drawText(name.get(5), width + currentPageSize + margin + size * 12 + margin * 3, 70, p); canvas.drawText(name.get(6), width + currentPageSize + margin + size * 16 + margin * 4, 70, p); break; case 2: currentPageSize += currentPageSize; canvas.drawText(name.get(0), width - currentPageSize - 2 * (margin + size * 4), 70, p); canvas.drawText(name.get(1), width - currentPageSize - margin - size * 4, 70, p); canvas.drawText(name.get(2), width - currentPageSize, 70, currentPage); canvas.drawText(name.get(3), width + currentPageSize + margin, 70, p); canvas.drawText(name.get(4), width + currentPageSize + margin + size * 4 + margin, 70, p); canvas.drawText(name.get(5), width + currentPageSize + margin + size * 8 + margin * 2, 70, p); canvas.drawText(name.get(6), width + currentPageSize + margin + size * 12 + margin * 3, 70, p); break; case 3: currentPageSize += currentPageSize; canvas.drawText(name.get(0), width - currentPageSize - 3 * (margin + size * 4), 70, p); canvas.drawText(name.get(1), width - currentPageSize - 2 * (margin + size * 4), 70, p); canvas.drawText(name.get(2), width - currentPageSize - margin - size * 4, 70, p); canvas.drawText(name.get(3), width - currentPageSize, 70, currentPage); canvas.drawText(name.get(4), width + currentPageSize + margin, 70, p); canvas.drawText(name.get(5), width + currentPageSize + margin + size * 4 + margin, 70, p); canvas.drawText(name.get(6), width + currentPageSize + margin + size * 8 + margin * 2, 70, p); break; case 4: currentPageSize += currentPageSize; canvas.drawText(name.get(0), width - currentPageSize - 4 * (margin + size * 4), 70, p); canvas.drawText(name.get(1), width - currentPageSize - 3 * (margin + size * 4), 70, p); canvas.drawText(name.get(2), width - currentPageSize - 2 * (margin + size * 4), 70, p); canvas.drawText(name.get(3), width - currentPageSize - margin - size * 4, 70, p); canvas.drawText(name.get(4), width - currentPageSize, 70, currentPage); canvas.drawText(name.get(5), width + currentPageSize + margin, 70, p); canvas.drawText(name.get(6), width + currentPageSize + margin + size * 4 + margin, 70, p); break; case 5: currentPageSize += currentPageSize; canvas.drawText(name.get(0), width - currentPageSize - 5 * (margin + size * 4), 70, p); canvas.drawText(name.get(1), width - currentPageSize - 4 * (margin + size * 4), 70, p); canvas.drawText(name.get(2), width - currentPageSize - 3 * (margin + size * 4), 70, p); canvas.drawText(name.get(3), width - currentPageSize - 2 * (margin + size * 4), 70, p); canvas.drawText(name.get(4), width - currentPageSize - margin - size * 4, 70, p); canvas.drawText(name.get(5), width - currentPageSize, 70, currentPage); canvas.drawText(name.get(6), width + currentPageSize + margin, 70, p); break; case 6: currentPageSize += currentPageSize; canvas.drawText(name.get(0), width - currentPageSize - 6 * (margin + size * 4), 70, p); canvas.drawText(name.get(1), width - currentPageSize - 5 * (margin + size * 4), 70, p); canvas.drawText(name.get(2), width - currentPageSize - 4 * (margin + size * 4), 70, p); canvas.drawText(name.get(3), width - currentPageSize - 3 * (margin + size * 4), 70, p); canvas.drawText(name.get(4), width - currentPageSize - 2 * (margin + size * 4), 70, p); canvas.drawText(name.get(5), width - currentPageSize - margin - size * 4, 70, p); canvas.drawText(name.get(6), width - currentPageSize, 70, currentPage); break; default: break; } } catch (IndexOutOfBoundsException e) { } if (mPageMargin > 0 && mMarginDrawable != null && mItems.size() > 0 && mAdapter != null) { final int scrollX = getScrollX(); final int width = getWidth(); final float marginOffset = (float) mPageMargin / width; int itemIndex = 0; ItemInfo ii = mItems.get(0); float offset = ii.offset; final int itemCount = mItems.size(); final int firstPos = ii.position; final int lastPos = mItems.get(itemCount - 1).position; for (int pos = firstPos; pos < lastPos; pos++) { while (pos > ii.position && itemIndex < itemCount) { ii = mItems.get(++itemIndex); } float drawAt; if (pos == ii.position) { drawAt = (ii.offset + ii.widthFactor) * width; offset = ii.offset + ii.widthFactor + marginOffset; } else { float widthFactor = mAdapter.getPageWidth(pos); drawAt = (offset + widthFactor) * width; offset += widthFactor + marginOffset; } if (drawAt + mPageMargin > scrollX) { mMarginDrawable.setBounds((int) drawAt, mTopPageBounds, (int) (drawAt + mPageMargin + 0.5f), mBottomPageBounds); mMarginDrawable.draw(canvas); } if (drawAt > scrollX + width) { break; // No more visible, no sense in continuing } } } }
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 w w w.j a va 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:org.zywx.wbpalmstar.engine.universalex.EUExWindow.java
public void handleSetSlidingWin(String[] param) { String jsonStr = param[0];//w w w .j a va 2s .c o m EBrowserActivity activity = (EBrowserActivity) mContext; try { JSONObject jsonObject = new JSONObject(jsonStr); int with = 0; String url; int slidingMode = SlidingMenu.LEFT; boolean isAttach = false; JSONObject leftJsonObj = null; JSONObject rightJsonObj = null; View menuView; if (activity.globalSlidingMenu.getParent() != null) { return; } String animationId = jsonObject.optString("animationId"); if (jsonObject.has("leftSliding")) { leftJsonObj = new JSONObject(jsonObject.getString("leftSliding")); if (leftJsonObj != null) { slidingMode = SlidingMenu.LEFT; with = leftJsonObj.getInt("width"); url = leftJsonObj.getString("url"); if (with > 0) { activity.globalSlidingMenu.setBehindWidth(with); } menuView = LayoutInflater.from(mContext).inflate(finder.getLayoutId("menu_frame"), null); activity.globalSlidingMenu.setMenu(menuView); addBrowserWindowToSldingWin(url, EBrowserWindow.rootLeftSlidingWinName); isAttach = true; } } if (jsonObject.has("rightSliding")) { rightJsonObj = new JSONObject(jsonObject.getString("rightSliding")); if (rightJsonObj != null) { slidingMode = SlidingMenu.RIGHT; with = rightJsonObj.getInt("width"); url = rightJsonObj.getString("url"); if (with > 0) { activity.globalSlidingMenu.setBehindWidth(with); } menuView = LayoutInflater.from(mContext).inflate(finder.getLayoutId("menu_frame_two"), null); activity.globalSlidingMenu.setSecondaryMenu(menuView); activity.globalSlidingMenu.setSecondaryShadowDrawable(finder.getDrawable("shadowright")); addBrowserWindowToSldingWin(url, EBrowserWindow.rootRightSlidingWinName); isAttach = true; } } if ("1".equals(animationId)) { //QQ? activity.globalSlidingMenu.setBehindCanvasTransformer(new SlidingMenu.CanvasTransformer() { @Override public void transformCanvas(Canvas canvas, float percentOpen) { float scale = (float) (percentOpen * 0.25 + 0.75); canvas.scale(scale, scale, 0, canvas.getHeight() / 2); } }); activity.globalSlidingMenu.setAboveCanvasTransformer(new SlidingMenu.CanvasTransformer() { @Override public void transformCanvas(Canvas canvas, float percentOpen) { float scale = (float) (1 - percentOpen * 0.20); canvas.scale(scale, scale, canvas.getWidth() / 2, canvas.getHeight() / 2); } }); activity.globalSlidingMenu.setFadeEnabled(false); } else { activity.globalSlidingMenu.setShadowWidthRes(EUExUtil.getResDimenID("shadow_width")); if (!jsonObject.has("leftSliding") && jsonObject.has("rightSliding")) { activity.globalSlidingMenu.setShadowDrawable(EUExUtil.getResDrawableID("shadowright")); } else { activity.globalSlidingMenu.setShadowDrawable(EUExUtil.getResDrawableID("shadow")); } activity.globalSlidingMenu.setFadeDegree(0.35f); } String bg = jsonObject.optString("bg"); if (!TextUtils.isEmpty(bg)) { setViewBackground(activity.globalSlidingMenu, bg, mBrwView.getCurrentWidget().m_indexUrl); } if (leftJsonObj != null && rightJsonObj != null) { slidingMode = SlidingMenu.LEFT_RIGHT; } if (isAttach == true) { activity.globalSlidingMenu.setMode(slidingMode); activity.globalSlidingMenu.attachToActivity(activity, SlidingMenu.SLIDING_CONTENT); mBrwView.setBackgroundColor(Color.TRANSPARENT); } } catch (JSONException e) { } }
From source file:kr.wdream.ui.PhotoViewer.java
@SuppressLint("NewApi") private void onDraw(Canvas canvas) { if (animationInProgress == 1 || !isVisible && animationInProgress != 2) { return;//from w w w . j a v a 2s .co m } float currentTranslationY; float currentTranslationX; float currentScale; float aty = -1; if (imageMoveAnimation != null) { if (!scroller.isFinished()) { scroller.abortAnimation(); } float ts = scale + (animateToScale - scale) * animationValue; float tx = translationX + (animateToX - translationX) * animationValue; float ty = translationY + (animateToY - translationY) * animationValue; if (currentEditMode == 1) { photoCropView.setAnimationProgress(animationValue); } if (animateToScale == 1 && scale == 1 && translationX == 0) { aty = ty; } currentScale = ts; currentTranslationY = ty; currentTranslationX = tx; containerView.invalidate(); } else { if (animationStartTime != 0) { translationX = animateToX; translationY = animateToY; scale = animateToScale; animationStartTime = 0; if (currentEditMode == 1) { photoCropView.setAnimationProgress(1); } updateMinMax(scale); zoomAnimation = false; } if (!scroller.isFinished()) { if (scroller.computeScrollOffset()) { if (scroller.getStartX() < maxX && scroller.getStartX() > minX) { translationX = scroller.getCurrX(); } if (scroller.getStartY() < maxY && scroller.getStartY() > minY) { translationY = scroller.getCurrY(); } containerView.invalidate(); } } if (switchImageAfterAnimation != 0) { if (switchImageAfterAnimation == 1) { setImageIndex(currentIndex + 1, false); } else if (switchImageAfterAnimation == 2) { setImageIndex(currentIndex - 1, false); } switchImageAfterAnimation = 0; } currentScale = scale; currentTranslationY = translationY; currentTranslationX = translationX; if (!moving) { aty = translationY; } } if (currentEditMode == 0 && scale == 1 && aty != -1 && !zoomAnimation) { float maxValue = getContainerViewHeight() / 4.0f; backgroundDrawable .setAlpha((int) Math.max(127, 255 * (1.0f - (Math.min(Math.abs(aty), maxValue) / maxValue)))); } else { backgroundDrawable.setAlpha(255); } ImageReceiver sideImage = null; if (currentEditMode == 0) { if (scale >= 1.0f && !zoomAnimation && !zooming) { if (currentTranslationX > maxX + AndroidUtilities.dp(5)) { sideImage = leftImage; } else if (currentTranslationX < minX - AndroidUtilities.dp(5)) { sideImage = rightImage; } } changingPage = sideImage != null; } if (sideImage == rightImage) { float tranlateX = currentTranslationX; float scaleDiff = 0; float alpha = 1; if (!zoomAnimation && tranlateX < minX) { alpha = Math.min(1.0f, (minX - tranlateX) / canvas.getWidth()); scaleDiff = (1.0f - alpha) * 0.3f; tranlateX = -canvas.getWidth() - AndroidUtilities.dp(30) / 2; } if (sideImage.hasBitmapImage()) { canvas.save(); canvas.translate(getContainerViewWidth() / 2, getContainerViewHeight() / 2); canvas.translate(canvas.getWidth() + AndroidUtilities.dp(30) / 2 + tranlateX, 0); canvas.scale(1.0f - scaleDiff, 1.0f - scaleDiff); int bitmapWidth = sideImage.getBitmapWidth(); int bitmapHeight = sideImage.getBitmapHeight(); float scaleX = (float) getContainerViewWidth() / (float) bitmapWidth; float scaleY = (float) getContainerViewHeight() / (float) bitmapHeight; float scale = scaleX > scaleY ? scaleY : scaleX; int width = (int) (bitmapWidth * scale); int height = (int) (bitmapHeight * scale); sideImage.setAlpha(alpha); sideImage.setImageCoords(-width / 2, -height / 2, width, height); sideImage.draw(canvas); canvas.restore(); } canvas.save(); canvas.translate(tranlateX, currentTranslationY / currentScale); canvas.translate((canvas.getWidth() * (scale + 1) + AndroidUtilities.dp(30)) / 2, -currentTranslationY / currentScale); radialProgressViews[1].setScale(1.0f - scaleDiff); radialProgressViews[1].setAlpha(alpha); radialProgressViews[1].onDraw(canvas); canvas.restore(); } float translateX = currentTranslationX; float scaleDiff = 0; float alpha = 1; if (!zoomAnimation && translateX > maxX && currentEditMode == 0) { alpha = Math.min(1.0f, (translateX - maxX) / canvas.getWidth()); scaleDiff = alpha * 0.3f; alpha = 1.0f - alpha; translateX = maxX; } boolean drawTextureView = Build.VERSION.SDK_INT >= 16 && aspectRatioFrameLayout != null && aspectRatioFrameLayout.getVisibility() == View.VISIBLE; if (centerImage.hasBitmapImage()) { canvas.save(); canvas.translate(getContainerViewWidth() / 2 + getAdditionX(), getContainerViewHeight() / 2 + getAdditionY()); canvas.translate(translateX, currentTranslationY); canvas.scale(currentScale - scaleDiff, currentScale - scaleDiff); if (currentEditMode == 1) { photoCropView.setBitmapParams(currentScale, translateX, currentTranslationY); } int bitmapWidth = centerImage.getBitmapWidth(); int bitmapHeight = centerImage.getBitmapHeight(); if (drawTextureView && textureUploaded) { float scale1 = bitmapWidth / (float) bitmapHeight; float scale2 = videoTextureView.getMeasuredWidth() / (float) videoTextureView.getMeasuredHeight(); if (Math.abs(scale1 - scale2) > 0.01f) { bitmapWidth = videoTextureView.getMeasuredWidth(); bitmapHeight = videoTextureView.getMeasuredHeight(); } } float scaleX = (float) getContainerViewWidth() / (float) bitmapWidth; float scaleY = (float) getContainerViewHeight() / (float) bitmapHeight; float scale = scaleX > scaleY ? scaleY : scaleX; int width = (int) (bitmapWidth * scale); int height = (int) (bitmapHeight * scale); if (!drawTextureView || !textureUploaded || !videoCrossfadeStarted || videoCrossfadeAlpha != 1.0f) { centerImage.setAlpha(alpha); centerImage.setImageCoords(-width / 2, -height / 2, width, height); centerImage.draw(canvas); } if (drawTextureView) { if (!videoCrossfadeStarted && textureUploaded) { videoCrossfadeStarted = true; videoCrossfadeAlpha = 0.0f; videoCrossfadeAlphaLastTime = System.currentTimeMillis(); } canvas.translate(-width / 2, -height / 2); videoTextureView.setAlpha(alpha * videoCrossfadeAlpha); aspectRatioFrameLayout.draw(canvas); if (videoCrossfadeStarted && videoCrossfadeAlpha < 1.0f) { long newUpdateTime = System.currentTimeMillis(); long dt = newUpdateTime - videoCrossfadeAlphaLastTime; videoCrossfadeAlphaLastTime = newUpdateTime; videoCrossfadeAlpha += dt / 300.0f; containerView.invalidate(); if (videoCrossfadeAlpha > 1.0f) { videoCrossfadeAlpha = 1.0f; } } } canvas.restore(); } if (!drawTextureView && (videoPlayerControlFrameLayout == null || videoPlayerControlFrameLayout.getVisibility() != View.VISIBLE)) { canvas.save(); canvas.translate(translateX, currentTranslationY / currentScale); radialProgressViews[0].setScale(1.0f - scaleDiff); radialProgressViews[0].setAlpha(alpha); radialProgressViews[0].onDraw(canvas); canvas.restore(); } if (sideImage == leftImage) { if (sideImage.hasBitmapImage()) { canvas.save(); canvas.translate(getContainerViewWidth() / 2, getContainerViewHeight() / 2); canvas.translate( -(canvas.getWidth() * (scale + 1) + AndroidUtilities.dp(30)) / 2 + currentTranslationX, 0); int bitmapWidth = sideImage.getBitmapWidth(); int bitmapHeight = sideImage.getBitmapHeight(); float scaleX = (float) getContainerViewWidth() / (float) bitmapWidth; float scaleY = (float) getContainerViewHeight() / (float) bitmapHeight; float scale = scaleX > scaleY ? scaleY : scaleX; int width = (int) (bitmapWidth * scale); int height = (int) (bitmapHeight * scale); sideImage.setAlpha(1.0f); sideImage.setImageCoords(-width / 2, -height / 2, width, height); sideImage.draw(canvas); canvas.restore(); } canvas.save(); canvas.translate(currentTranslationX, currentTranslationY / currentScale); canvas.translate(-(canvas.getWidth() * (scale + 1) + AndroidUtilities.dp(30)) / 2, -currentTranslationY / currentScale); radialProgressViews[2].setScale(1.0f); radialProgressViews[2].setAlpha(1.0f); radialProgressViews[2].onDraw(canvas); canvas.restore(); } }
From source file:org.telegram.ui.ArticleViewer.java
private void drawContent(Canvas canvas) { if (photoAnimationInProgress == 1 || !isPhotoVisible && photoAnimationInProgress != 2) { return;// w w w . j av a 2 s .com } float currentTranslationY; float currentTranslationX; float currentScale; float aty = -1; if (imageMoveAnimation != null) { if (!scroller.isFinished()) { scroller.abortAnimation(); } float ts = scale + (animateToScale - scale) * animationValue; float tx = translationX + (animateToX - translationX) * animationValue; float ty = translationY + (animateToY - translationY) * animationValue; if (animateToScale == 1 && scale == 1 && translationX == 0) { aty = ty; } currentScale = ts; currentTranslationY = ty; currentTranslationX = tx; photoContainerView.invalidate(); } else { if (animationStartTime != 0) { translationX = animateToX; translationY = animateToY; scale = animateToScale; animationStartTime = 0; updateMinMax(scale); zoomAnimation = false; } if (!scroller.isFinished()) { if (scroller.computeScrollOffset()) { if (scroller.getStartX() < maxX && scroller.getStartX() > minX) { translationX = scroller.getCurrX(); } if (scroller.getStartY() < maxY && scroller.getStartY() > minY) { translationY = scroller.getCurrY(); } photoContainerView.invalidate(); } } if (switchImageAfterAnimation != 0) { if (switchImageAfterAnimation == 1) { setImageIndex(currentIndex + 1, false); } else if (switchImageAfterAnimation == 2) { setImageIndex(currentIndex - 1, false); } switchImageAfterAnimation = 0; } currentScale = scale; currentTranslationY = translationY; currentTranslationX = translationX; if (!moving) { aty = translationY; } } if (scale == 1 && aty != -1 && !zoomAnimation) { float maxValue = getContainerViewHeight() / 4.0f; photoBackgroundDrawable .setAlpha((int) Math.max(127, 255 * (1.0f - (Math.min(Math.abs(aty), maxValue) / maxValue)))); } else { photoBackgroundDrawable.setAlpha(255); } ImageReceiver sideImage = null; if (scale >= 1.0f && !zoomAnimation && !zooming) { if (currentTranslationX > maxX + AndroidUtilities.dp(5)) { sideImage = leftImage; } else if (currentTranslationX < minX - AndroidUtilities.dp(5)) { sideImage = rightImage; } } changingPage = sideImage != null; if (sideImage == rightImage) { float tranlateX = currentTranslationX; float scaleDiff = 0; float alpha = 1; if (!zoomAnimation && tranlateX < minX) { alpha = Math.min(1.0f, (minX - tranlateX) / canvas.getWidth()); scaleDiff = (1.0f - alpha) * 0.3f; tranlateX = -canvas.getWidth() - AndroidUtilities.dp(30) / 2; } if (sideImage.hasBitmapImage()) { canvas.save(); canvas.translate(getContainerViewWidth() / 2, getContainerViewHeight() / 2); canvas.translate(canvas.getWidth() + AndroidUtilities.dp(30) / 2 + tranlateX, 0); canvas.scale(1.0f - scaleDiff, 1.0f - scaleDiff); int bitmapWidth = sideImage.getBitmapWidth(); int bitmapHeight = sideImage.getBitmapHeight(); float scaleX = (float) getContainerViewWidth() / (float) bitmapWidth; float scaleY = (float) getContainerViewHeight() / (float) bitmapHeight; float scale = scaleX > scaleY ? scaleY : scaleX; int width = (int) (bitmapWidth * scale); int height = (int) (bitmapHeight * scale); sideImage.setAlpha(alpha); sideImage.setImageCoords(-width / 2, -height / 2, width, height); sideImage.draw(canvas); canvas.restore(); } canvas.save(); canvas.translate(tranlateX, currentTranslationY / currentScale); canvas.translate((canvas.getWidth() * (scale + 1) + AndroidUtilities.dp(30)) / 2, -currentTranslationY / currentScale); radialProgressViews[1].setScale(1.0f - scaleDiff); radialProgressViews[1].setAlpha(alpha); radialProgressViews[1].onDraw(canvas); canvas.restore(); } float translateX = currentTranslationX; float scaleDiff = 0; float alpha = 1; if (!zoomAnimation && translateX > maxX) { alpha = Math.min(1.0f, (translateX - maxX) / canvas.getWidth()); scaleDiff = alpha * 0.3f; alpha = 1.0f - alpha; translateX = maxX; } boolean drawTextureView = aspectRatioFrameLayout != null && aspectRatioFrameLayout.getVisibility() == View.VISIBLE; if (centerImage.hasBitmapImage()) { canvas.save(); canvas.translate(getContainerViewWidth() / 2, getContainerViewHeight() / 2); canvas.translate(translateX, currentTranslationY); canvas.scale(currentScale - scaleDiff, currentScale - scaleDiff); int bitmapWidth = centerImage.getBitmapWidth(); int bitmapHeight = centerImage.getBitmapHeight(); if (drawTextureView && textureUploaded) { float scale1 = bitmapWidth / (float) bitmapHeight; float scale2 = videoTextureView.getMeasuredWidth() / (float) videoTextureView.getMeasuredHeight(); if (Math.abs(scale1 - scale2) > 0.01f) { bitmapWidth = videoTextureView.getMeasuredWidth(); bitmapHeight = videoTextureView.getMeasuredHeight(); } } float scaleX = (float) getContainerViewWidth() / (float) bitmapWidth; float scaleY = (float) getContainerViewHeight() / (float) bitmapHeight; float scale = scaleX > scaleY ? scaleY : scaleX; int width = (int) (bitmapWidth * scale); int height = (int) (bitmapHeight * scale); if (!drawTextureView || !textureUploaded || !videoCrossfadeStarted || videoCrossfadeAlpha != 1.0f) { centerImage.setAlpha(alpha); centerImage.setImageCoords(-width / 2, -height / 2, width, height); centerImage.draw(canvas); } if (drawTextureView) { if (!videoCrossfadeStarted && textureUploaded) { videoCrossfadeStarted = true; videoCrossfadeAlpha = 0.0f; videoCrossfadeAlphaLastTime = System.currentTimeMillis(); } canvas.translate(-width / 2, -height / 2); videoTextureView.setAlpha(alpha * videoCrossfadeAlpha); aspectRatioFrameLayout.draw(canvas); if (videoCrossfadeStarted && videoCrossfadeAlpha < 1.0f) { long newUpdateTime = System.currentTimeMillis(); long dt = newUpdateTime - videoCrossfadeAlphaLastTime; videoCrossfadeAlphaLastTime = newUpdateTime; videoCrossfadeAlpha += dt / 300.0f; photoContainerView.invalidate(); if (videoCrossfadeAlpha > 1.0f) { videoCrossfadeAlpha = 1.0f; } } } canvas.restore(); } if (!drawTextureView && bottomLayout.getVisibility() != View.VISIBLE) { canvas.save(); canvas.translate(translateX, currentTranslationY / currentScale); radialProgressViews[0].setScale(1.0f - scaleDiff); radialProgressViews[0].setAlpha(alpha); radialProgressViews[0].onDraw(canvas); canvas.restore(); } if (sideImage == leftImage) { if (sideImage.hasBitmapImage()) { canvas.save(); canvas.translate(getContainerViewWidth() / 2, getContainerViewHeight() / 2); canvas.translate( -(canvas.getWidth() * (scale + 1) + AndroidUtilities.dp(30)) / 2 + currentTranslationX, 0); int bitmapWidth = sideImage.getBitmapWidth(); int bitmapHeight = sideImage.getBitmapHeight(); float scaleX = (float) getContainerViewWidth() / (float) bitmapWidth; float scaleY = (float) getContainerViewHeight() / (float) bitmapHeight; float scale = scaleX > scaleY ? scaleY : scaleX; int width = (int) (bitmapWidth * scale); int height = (int) (bitmapHeight * scale); sideImage.setAlpha(1.0f); sideImage.setImageCoords(-width / 2, -height / 2, width, height); sideImage.draw(canvas); canvas.restore(); } canvas.save(); canvas.translate(currentTranslationX, currentTranslationY / currentScale); canvas.translate(-(canvas.getWidth() * (scale + 1) + AndroidUtilities.dp(30)) / 2, -currentTranslationY / currentScale); radialProgressViews[2].setScale(1.0f); radialProgressViews[2].setAlpha(1.0f); radialProgressViews[2].onDraw(canvas); canvas.restore(); } }