List of usage examples for android.graphics Canvas translate
public void translate(float dx, float dy)
From source file:com.aliasapps.seq.scroller.TwoWayView.java
private boolean drawEndEdge(Canvas canvas) { if (mEndEdge.isFinished()) { return false; }/*from w w w . ja v a 2 s. co m*/ final int restoreCount = canvas.save(); final int width = getWidth() - getPaddingLeft() - getPaddingRight(); final int height = getHeight() - getPaddingTop() - getPaddingBottom(); if (mIsVertical) { canvas.translate(-width, height); canvas.rotate(180, width, 0); } else { canvas.translate(width, 0); canvas.rotate(90); } final boolean needsInvalidate = mEndEdge.draw(canvas); canvas.restoreToCount(restoreCount); return needsInvalidate; }
From source file:com.appunite.list.AbsHorizontalListView.java
@Override public void draw(Canvas canvas) { super.draw(canvas); if (mEdgeGlowLeft != null) { final int scrollX = getScrollX(); boolean needsInvalidate = false; if (!mEdgeGlowLeft.isFinished()) { final int restoreCount = canvas.save(); final int topPadding = mListPadding.top + mGlowPaddingTop; final int bottomPadding = mListPadding.bottom + mGlowPaddingBottom; final int height = getHeight() - topPadding - bottomPadding; int edgeX = Math.min(0, scrollX + mFirstPositionDistanceGuess); canvas.translate(edgeX, height + topPadding); canvas.rotate(-90, 0, 0);// ww w.j av a2 s. com mEdgeGlowLeft.setSize(height, getWidth()); if (mEdgeGlowLeft.draw(canvas)) { needsInvalidate = true; } canvas.restoreToCount(restoreCount); } if (!mEdgeGlowRight.isFinished()) { final int restoreCount = canvas.save(); final int topPadding = mListPadding.top + mGlowPaddingTop; final int bottomPadding = mListPadding.bottom + mGlowPaddingBottom; final int height = getHeight() - topPadding - bottomPadding; final int width = getWidth(); int edgeY = topPadding; int edgeX = Math.max(width, scrollX + mLastPositionDistanceGuess); canvas.translate(edgeX, edgeY); canvas.rotate(90, 0, 0); mEdgeGlowRight.setSize(height, width); if (mEdgeGlowRight.draw(canvas)) { needsInvalidate = true; } canvas.restoreToCount(restoreCount); } if (needsInvalidate) { invalidate(); } } }
From source file:com.appunite.list.AbsListView.java
@Override public void draw(Canvas canvas) { super.draw(canvas); if (mEdgeGlowTop != null) { final int scrollY = getScrollY(); boolean needsInvalidate = false; if (!mEdgeGlowTop.isFinished()) { final int restoreCount = canvas.save(); final int leftPadding = mListPadding.left + mGlowPaddingLeft; final int rightPadding = mListPadding.right + mGlowPaddingRight; final int width = getWidth() - leftPadding - rightPadding; int edgeY = Math.min(0, scrollY + mFirstPositionDistanceGuess); canvas.translate(leftPadding, edgeY); mEdgeGlowTop.setSize(width, getHeight()); if (mEdgeGlowTop.draw(canvas)) { needsInvalidate = true;//from w ww . ja v a 2 s . co m } canvas.restoreToCount(restoreCount); } if (!mEdgeGlowBottom.isFinished()) { final int restoreCount = canvas.save(); final int leftPadding = mListPadding.left + mGlowPaddingLeft; final int rightPadding = mListPadding.right + mGlowPaddingRight; final int width = getWidth() - leftPadding - rightPadding; final int height = getHeight(); int edgeX = -width + leftPadding; int edgeY = Math.max(height, scrollY + mLastPositionDistanceGuess); canvas.translate(edgeX, edgeY); canvas.rotate(180, width, 0); mEdgeGlowBottom.setSize(width, height); if (mEdgeGlowBottom.draw(canvas)) { needsInvalidate = true; } canvas.restoreToCount(restoreCount); } if (needsInvalidate) { invalidate(); } } if (mFastScroller != null) { final int scrollY = getScrollY(); if (scrollY != 0) { // Pin to the top/bottom during overscroll int restoreCount = canvas.save(); canvas.translate(0, (float) scrollY); mFastScroller.draw(canvas); canvas.restoreToCount(restoreCount); } else { mFastScroller.draw(canvas); } } }
From source file:com.wb.launcher3.Page.java
@Override protected void dispatchDraw(Canvas canvas) { int halfScreenSize = getViewportWidth() / 2; // mOverScrollX is equal to getScrollX() when we're within the normal scroll range. // Otherwise it is equal to the scaled overscroll position. int screenCenter = mOverScrollX + halfScreenSize; if (screenCenter != mLastScreenCenter || mForceScreenScrolled) { // set mForceScreenScrolled before calling screenScrolled so that screenScrolled can // set it for the next frame mForceScreenScrolled = false;/* w w w. j a v a2 s.c o m*/ screenScrolled(screenCenter); mLastScreenCenter = screenCenter; } // Find out which screens are visible; as an optimization we only call draw on them final int pageCount = getChildCount(); if (pageCount > 0) { //*/Modified by tyd Greg 2014-03-20,for transition effect boolean allowed = true; Workspace workspace = null; if (this instanceof Workspace) { workspace = (Workspace) this; allowed = !workspace.isSmall(); } if (TydtechConfig.TYDTECH_DEBUG_FLAG) { Log.d("Greg", "allowed: " + allowed); } /*/ if(!allowed || !TydtechConfig.TRANSITION_EFFECT_ENABLED){ getVisiblePages(mTempVisiblePagesRange); }else{ getVisiblePagesExt(mTempVisiblePagesRange); } //*/ getVisiblePages(mTempVisiblePagesRange); //*/ final int leftScreen = mTempVisiblePagesRange[0]; final int rightScreen = mTempVisiblePagesRange[1]; if (leftScreen != -1 && rightScreen != -1) { final long drawingTime = getDrawingTime(); // Clip to the bounds canvas.save(); canvas.clipRect(getScrollX(), getScrollY(), getScrollX() + getRight() - getLeft(), getScrollY() + getBottom() - getTop()); // Draw all the children, leaving the drag view for last for (int i = pageCount - 1; i >= 0; i--) { final View v = getPageAt(i); if (v == mDragView) continue; if (mForceDrawAllChildrenNextFrame || (leftScreen <= i && i <= rightScreen && shouldDrawChild(v))) { drawChild(canvas, v, drawingTime); } } // Draw the drag view on top (if there is one) if (mDragView != null) { drawChild(canvas, mDragView, drawingTime); } mForceDrawAllChildrenNextFrame = false; canvas.restore(); } //*/Added by TYD Theobald_Wu on 20130223 [begin] for cycle rolling pages if (TydtechConfig.CYCLE_ROLL_PAGES_ENABLED && allowed) { canvas.save(); int width = 0; final int pageW = getViewportWidth(); View v = null; int scrollOffset = (pageW - getChildWidth(0)) / 2; if (mOverScrollX < 0) { int index = pageCount - 1; v = getPageAt(index); width = getViewportOffsetX() - scrollOffset - v.getWidth(); } else if (mOverScrollX > mMaxScrollX) { v = getPageAt(0); width = getViewportOffsetX() + pageW * pageCount + scrollOffset; } if (TydtechConfig.TYDTECH_DEBUG_FLAG) { Log.d("Greg", "width: " + width); Log.d("Greg", "mOverScrollX: " + mOverScrollX); } if (v != null) { canvas.translate(width, v.getY()); canvas.concat(v.getMatrix()); final int w = v.getWidth(); final int h = v.getHeight(); final int sx = v.getScrollX(); final int sy = v.getScrollY(); Rect rect = new Rect(sx, sy, sx + w, sy + h); ///* zhangwuba mark this, user verison lead to screen flash 2014-5-12 //canvas.saveLayerAlpha(sx, sy, sx + w, sy + h, (int) (v.getAlpha() * 255), // Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.CLIP_TO_LAYER_SAVE_FLAG); //*/ v.draw(canvas); } canvas.restore(); } //*/ } }
From source file:com.anysoftkeyboard.keyboards.views.AnyKeyboardBaseView.java
private void onBufferDraw(Canvas canvas) { if (mKeyboardChanged) { invalidateAllKeys();// ww w . j av a 2s . c om mKeyboardChanged = false; } canvas.getClipBounds(mDirtyRect); if (mKeyboard == null) return; final boolean drawKeyboardNameText = (mKeyboardNameTextSize > 1f) && AnyApplication.getConfig().getShowKeyboardNameText(); final boolean drawHintText = (mHintTextSize > 1) && AnyApplication.getConfig().getShowHintTextOnKeys(); // TODO: calls to AnyApplication.getConfig().getXXXXX() functions are // not yet implemented, // but need to when allowing preferences to override theme settings of // these values // right now just using what should be the default values for these // unimplemented preferences final boolean useCustomKeyTextColor = false; // TODO: final boolean useCustomKeyTextColor = // AnyApplication.getConfig().getUseCustomTextColorOnKeys(); final ColorStateList keyTextColor = useCustomKeyTextColor ? new ColorStateList(new int[][] { { 0 } }, new int[] { 0xFF6666FF }) : mKeyTextColor; // TODO: ? AnyApplication.getConfig().getCustomKeyTextColorOnKeys() : // mKeyTextColor; final boolean useCustomHintColor = drawHintText && false; // TODO: final boolean useCustomHintColor = drawHintText && // AnyApplication.getConfig().getUseCustomHintColorOnKeys(); final ColorStateList hintColor = useCustomHintColor ? new ColorStateList(new int[][] { { 0 } }, new int[] { 0xFFFF6666 }) : mHintTextColor; // TODO: ? AnyApplication.getConfig().getCustomHintColorOnKeys() : // mHintTextColor; // allow preferences to override theme settings for hint text position final boolean useCustomHintAlign = drawHintText && AnyApplication.getConfig().getUseCustomHintAlign(); final int hintAlign = useCustomHintAlign ? AnyApplication.getConfig().getCustomHintAlign() : mHintLabelAlign; final int hintVAlign = useCustomHintAlign ? AnyApplication.getConfig().getCustomHintVAlign() : mHintLabelVAlign; final Paint paint = mPaint; final Drawable keyBackground = mKeyBackground; final Rect clipRegion = mClipRegion; final int kbdPaddingLeft = getPaddingLeft(); final int kbdPaddingTop = getPaddingTop(); final Key[] keys = mKeys; final Key invalidKey = mInvalidatedKey; boolean drawSingleKey = false; if (invalidKey != null && canvas.getClipBounds(clipRegion)) { // TODO we should use Rect.inset and Rect.contains here. // Is clipRegion completely contained within the invalidated key? if (invalidKey.x + kbdPaddingLeft - 1 <= clipRegion.left && invalidKey.y + kbdPaddingTop - 1 <= clipRegion.top && invalidKey.x + invalidKey.width + kbdPaddingLeft + 1 >= clipRegion.right && invalidKey.y + invalidKey.height + kbdPaddingTop + 1 >= clipRegion.bottom) { drawSingleKey = true; } } final int keyCount = keys.length; for (int i = 0; i < keyCount; i++) { final AnyKey key = (AnyKey) keys[i]; final boolean keyIsSpace = isSpaceKey(key); if (drawSingleKey && (invalidKey != key)) { continue; } if (!mDirtyRect.intersects(key.x + kbdPaddingLeft, key.y + kbdPaddingTop, key.x + key.width + kbdPaddingLeft, key.y + key.height + kbdPaddingTop)) { continue; } int[] drawableState = key.getCurrentDrawableState(mDrawableStatesProvider); if (keyIsSpace) paint.setColor(mKeyboardNameTextColor.getColorForState(drawableState, 0xFF000000)); else paint.setColor(keyTextColor.getColorForState(drawableState, 0xFF000000)); keyBackground.setState(drawableState); // Switch the character to uppercase if shift is pressed CharSequence label = key.label == null ? null : adjustCase(key).toString(); final Rect bounds = keyBackground.getBounds(); if ((key.width != bounds.right) || (key.height != bounds.bottom)) { keyBackground.setBounds(0, 0, key.width, key.height); } canvas.translate(key.x + kbdPaddingLeft, key.y + kbdPaddingTop); keyBackground.draw(canvas); if (TextUtils.isEmpty(label)) { Drawable iconToDraw = getIconToDrawForKey(key, false); if (iconToDraw != null/* && shouldDrawIcon */) { //http://developer.android.com/reference/android/graphics/drawable/Drawable.html#getCurrent() //http://stackoverflow.com/a/103600/1324235 final boolean is9Patch = iconToDraw.getCurrent() instanceof NinePatchDrawable; // Special handing for the upper-right number hint icons final int drawableWidth; final int drawableHeight; final int drawableX; final int drawableY; drawableWidth = is9Patch ? key.width : iconToDraw.getIntrinsicWidth(); drawableHeight = is9Patch ? key.height : iconToDraw.getIntrinsicHeight(); drawableX = (key.width + mKeyBackgroundPadding.left - mKeyBackgroundPadding.right - drawableWidth) / 2; drawableY = (key.height + mKeyBackgroundPadding.top - mKeyBackgroundPadding.bottom - drawableHeight) / 2; canvas.translate(drawableX, drawableY); iconToDraw.setBounds(0, 0, drawableWidth, drawableHeight); iconToDraw.draw(canvas); canvas.translate(-drawableX, -drawableY); if (keyIsSpace && drawKeyboardNameText) { // now a little hack, I'll set the label now, so it get // drawn. label = mKeyboardName; } } else { // ho... no icon. // I'll try to guess the text label = guessLabelForKey(key.codes[0]); if (TextUtils.isEmpty(label)) { Log.w(TAG, "That's unfortunate, for key " + key.codes[0] + " at (" + key.x + ", " + key.y + ") there is no icon nor label. Action ID is " + mKeyboardActionType); } } } if (label != null) { // For characters, use large font. For labels like "Done", use // small font. final FontMetrics fm; if (keyIsSpace) { paint.setTextSize(mKeyboardNameTextSize); paint.setTypeface(Typeface.DEFAULT_BOLD); if (mKeyboardNameFM == null) mKeyboardNameFM = paint.getFontMetrics(); fm = mKeyboardNameFM; } else if (label.length() > 1 && key.codes.length < 2) { paint.setTextSize(mLabelTextSize); paint.setTypeface(Typeface.DEFAULT_BOLD); if (mLabelFM == null) mLabelFM = paint.getFontMetrics(); fm = mLabelFM; } else { fm = setPaintToKeyText(paint); } final float labelHeight = -fm.top; // Draw a drop shadow for the text paint.setShadowLayer(mShadowRadius, mShadowOffsetX, mShadowOffsetY, mShadowColor); // (+)This is the trick to get RTL/LTR text correct // no matter what: StaticLayout // this should be in the top left corner of the key float textWidth = paint.measureText(label, 0, label.length()); // I'm going to try something if the key is too small for the // text: // 1) divide the text size by 1.5 // 2) if still too large, divide by 2.5 // 3) show no text if (textWidth > key.width) { Log.d(TAG, "Label '" + label + "' is too large for the key. Reducing by 1.5."); paint.setTextSize(mKeyTextSize / 1.5f); textWidth = paint.measureText(label, 0, label.length()); if (textWidth > key.width) { Log.d(TAG, "Label '" + label + "' is too large for the key. Reducing by 2.5."); paint.setTextSize(mKeyTextSize / 2.5f); textWidth = paint.measureText(label, 0, label.length()); if (textWidth > key.width) { Log.d(TAG, "Label '" + label + "' is too large for the key. Showing no text."); paint.setTextSize(0f); textWidth = paint.measureText(label, 0, label.length()); } } } // the center of the drawable space, which is value used // previously for vertically // positioning the key label final float centerY = mKeyBackgroundPadding.top + ((key.height - mKeyBackgroundPadding.top - mKeyBackgroundPadding.bottom) / (keyIsSpace ? 3 : 2));// the label on the space is a bit higher // the X coordinate for the center of the main label text is // unaffected by the hints final float centerX = mKeyBackgroundPadding.left + (key.width - mKeyBackgroundPadding.left - mKeyBackgroundPadding.right) / 2; final float textX = centerX; final float textY; // Some devices (mostly pre-Honeycomb, have issues with RTL text // drawing. // Of course, there is no issue with a single character :) // so, we'll use the RTL secured drawing (via StaticLayout) for // labels. if (label.length() > 1 && !AnyApplication.getConfig().workaround_alwaysUseDrawText()) { // calculate Y coordinate of top of text based on center // location textY = centerY - ((labelHeight - paint.descent()) / 2); canvas.translate(textX, textY); Log.d(TAG, "Using RTL fix for key draw '" + label + "'"); // RTL fix. But it costs, let do it when in need (more than // 1 character) StaticLayout labelText = new StaticLayout(label, new TextPaint(paint), (int) textWidth, Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); labelText.draw(canvas); } else { // to get Y coordinate of baseline from center of text, // first add half the height (to get to // bottom of text), then subtract the part below the // baseline. Note that fm.top is negative. textY = centerY + ((labelHeight - paint.descent()) / 2); canvas.translate(textX, textY); canvas.drawText(label, 0, label.length(), 0, 0, paint); } canvas.translate(-textX, -textY); // (-) // Turn off drop shadow paint.setShadowLayer(0, 0, 0, 0); } if (drawHintText) { if ((key.popupCharacters != null && key.popupCharacters.length() > 0) || (key.popupResId != 0) || (key.longPressCode != 0)) { Paint.Align oldAlign = paint.getTextAlign(); String hintText = null; if (key.hintLabel != null && key.hintLabel.length() > 0) { hintText = key.hintLabel.toString(); // it is the responsibility of the keyboard layout // designer to ensure that they do // not put too many characters in the hint label... } else if (key.longPressCode != 0) { if (Character.isLetterOrDigit(key.longPressCode)) hintText = Character.toString((char) key.longPressCode); } else if (key.popupCharacters != null) { final String hintString = key.popupCharacters.toString(); final int hintLength = hintString.length(); if (hintLength <= 3) hintText = hintString; } // if hintText is still null, it means it didn't fit one of // the above // cases, so we should provide the hint using the default if (hintText == null) { if (mHintOverflowLabel != null) hintText = mHintOverflowLabel.toString(); else { // theme does not provide a defaultHintLabel // use if hints are above, ... if hints are // below // (to avoid being too close to main label/icon) if (hintVAlign == Gravity.TOP) hintText = ""; else hintText = "..."; } } if (mKeyboard.isShifted()) hintText = hintText.toUpperCase(); // now draw hint paint.setTypeface(Typeface.DEFAULT); paint.setColor(hintColor.getColorForState(drawableState, 0xFF000000)); paint.setTextSize(mHintTextSize); // get the hint text font metrics so that we know the size // of the hint when // we try to position the main label (to try to make sure // they don't overlap) if (mHintTextFM == null) { mHintTextFM = paint.getFontMetrics(); } final float hintX; final float hintY; // the (float) 0.5 value is added or subtracted to just give // a little more room // in case the theme designer didn't account for the hint // label location if (hintAlign == Gravity.LEFT) { // left paint.setTextAlign(Paint.Align.LEFT); hintX = mKeyBackgroundPadding.left + (float) 0.5; } else if (hintAlign == Gravity.CENTER) { // center paint.setTextAlign(Paint.Align.CENTER); hintX = mKeyBackgroundPadding.left + (key.width - mKeyBackgroundPadding.left - mKeyBackgroundPadding.right) / 2; } else { // right paint.setTextAlign(Paint.Align.RIGHT); hintX = key.width - mKeyBackgroundPadding.right - (float) 0.5; } if (hintVAlign == Gravity.TOP) { // above hintY = mKeyBackgroundPadding.top - mHintTextFM.top + (float) 0.5; } else { // below hintY = key.height - mKeyBackgroundPadding.bottom - mHintTextFM.bottom - (float) 0.5; } canvas.drawText(hintText, hintX, hintY, paint); paint.setTextAlign(oldAlign); } } canvas.translate(-key.x - kbdPaddingLeft, -key.y - kbdPaddingTop); } mInvalidatedKey = null; // Overlay a dark rectangle to dim the keyboard if (mMiniKeyboard != null && mMiniKeyboardVisible) { paint.setColor((int) (mBackgroundDimAmount * 0xFF) << 24); canvas.drawRect(0, 0, getWidth(), getHeight(), paint); } if (FeaturesSet.DEBUG_LOG) { if (mShowTouchPoints) { for (PointerTracker tracker : mPointerTrackers) { int startX = tracker.getStartX(); int startY = tracker.getStartY(); int lastX = tracker.getLastX(); int lastY = tracker.getLastY(); paint.setAlpha(128); paint.setColor(0xFFFF0000); canvas.drawCircle(startX, startY, 3, paint); canvas.drawLine(startX, startY, lastX, lastY, paint); paint.setColor(0xFF0000FF); canvas.drawCircle(lastX, lastY, 3, paint); paint.setColor(0xFF00FF00); canvas.drawCircle((startX + lastX) / 2, (startY + lastY) / 2, 2, paint); } } } mDrawPending = false; mDirtyRect.setEmpty(); }
From source file:com.artifex.mupdflib.TwoWayView.java
private boolean drawEndEdge(Canvas canvas) { if (mEndEdge.isFinished()) { return false; }/*from w ww.j a va2s . c om*/ final int restoreCount = canvas.save(); final int width = getWidth(); final int height = getHeight(); if (mIsVertical) { canvas.translate(-width, height); canvas.rotate(180, width, 0); } else { canvas.translate(width, 0); canvas.rotate(90); } final boolean needsInvalidate = mEndEdge.draw(canvas); canvas.restoreToCount(restoreCount); return needsInvalidate; }
From source file:com.artifex.mupdflib.TwoWayView.java
private boolean drawStartEdge(Canvas canvas) { if (mStartEdge.isFinished()) { return false; }//from ww w . ja v a 2s . c om if (mIsVertical) { return mStartEdge.draw(canvas); } final int restoreCount = canvas.save(); final int height = getHeight(); canvas.translate(0, height); canvas.rotate(270); final boolean needsInvalidate = mStartEdge.draw(canvas); canvas.restoreToCount(restoreCount); return needsInvalidate; }
From source file:org.telegram.ui.ArticleViewer.java
public void setParentActivity(Activity activity) { if (parentActivity == activity) { return;//from ww w.ja v a 2 s.c om } parentActivity = activity; backgroundPaint = new Paint(); backgroundPaint.setColor(0xffffffff); layerShadowDrawable = activity.getResources().getDrawable(R.drawable.layer_shadow); slideDotDrawable = activity.getResources().getDrawable(R.drawable.slide_dot_small); slideDotBigDrawable = activity.getResources().getDrawable(R.drawable.slide_dot_big); scrimPaint = new Paint(); windowView = new WindowView(activity); windowView.setWillNotDraw(false); windowView.setClipChildren(true); windowView.setFocusable(false); containerView = new FrameLayout(activity); windowView.addView(containerView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT)); containerView.setFitsSystemWindows(true); if (Build.VERSION.SDK_INT >= 21) { containerView.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() { @SuppressLint("NewApi") @Override public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) { WindowInsets oldInsets = (WindowInsets) lastInsets; lastInsets = insets; if (oldInsets == null || !oldInsets.toString().equals(insets.toString())) { windowView.requestLayout(); } return insets.consumeSystemWindowInsets(); } }); } containerView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_FULLSCREEN); photoContainerBackground = new View(activity); photoContainerBackground.setVisibility(View.INVISIBLE); photoContainerBackground.setBackgroundDrawable(photoBackgroundDrawable); windowView.addView(photoContainerBackground, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT)); animatingImageView = new ClippingImageView(activity); animatingImageView.setAnimationValues(animationValues); animatingImageView.setVisibility(View.GONE); windowView.addView(animatingImageView, LayoutHelper.createFrame(40, 40)); photoContainerView = new FrameLayoutDrawer(activity) { @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); int y = bottom - top - captionTextView.getMeasuredHeight(); if (bottomLayout.getVisibility() == VISIBLE) { y -= bottomLayout.getMeasuredHeight(); } captionTextView.layout(0, y, captionTextView.getMeasuredWidth(), y + captionTextView.getMeasuredHeight()); } }; photoContainerView.setVisibility(View.INVISIBLE); photoContainerView.setWillNotDraw(false); windowView.addView(photoContainerView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT)); fullscreenVideoContainer = new FrameLayout(activity); fullscreenVideoContainer.setBackgroundColor(0xff000000); fullscreenVideoContainer.setVisibility(View.INVISIBLE); windowView.addView(fullscreenVideoContainer, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); fullscreenAspectRatioView = new AspectRatioFrameLayout(activity); fullscreenAspectRatioView.setVisibility(View.GONE); fullscreenVideoContainer.addView(fullscreenAspectRatioView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.CENTER)); fullscreenTextureView = new TextureView(activity); if (Build.VERSION.SDK_INT >= 21) { barBackground = new View(activity); barBackground.setBackgroundColor(0xff000000); windowView.addView(barBackground); } listView = new RecyclerListView(activity); listView.setLayoutManager( layoutManager = new LinearLayoutManager(parentActivity, LinearLayoutManager.VERTICAL, false)); listView.setAdapter(adapter = new WebpageAdapter(parentActivity)); listView.setClipToPadding(false); listView.setPadding(0, AndroidUtilities.dp(56), 0, 0); listView.setTopGlowOffset(AndroidUtilities.dp(56)); listView.setGlowColor(0xfff5f6f7); containerView.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); listView.setOnItemLongClickListener(new RecyclerListView.OnItemLongClickListener() { @Override public boolean onItemClick(View view, int position) { return false; } }); listView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() { @Override public void onItemClick(View view, int position) { if (position == blocks.size() && currentPage != null) { if (previewsReqId != 0) { return; } TLRPC.User user = MessagesController.getInstance().getUser("previews"); if (user != null) { openPreviewsChat(user, currentPage.id); } else { final long pageId = currentPage.id; showProgressView(true); TLRPC.TL_contacts_resolveUsername req = new TLRPC.TL_contacts_resolveUsername(); req.username = "previews"; previewsReqId = ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() { @Override public void run(final TLObject response, final TLRPC.TL_error error) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { if (previewsReqId == 0) { return; } previewsReqId = 0; showProgressView(false); if (response != null) { TLRPC.TL_contacts_resolvedPeer res = (TLRPC.TL_contacts_resolvedPeer) response; MessagesController.getInstance().putUsers(res.users, false); MessagesStorage.getInstance().putUsersAndChats(res.users, res.chats, false, true); if (!res.users.isEmpty()) { openPreviewsChat(res.users.get(0), pageId); } } } }); } }); } } } }); listView.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { if (listView.getChildCount() == 0) { return; } checkScroll(dy); } }); headerView = new FrameLayout(activity); headerView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); headerView.setBackgroundColor(0xff000000); containerView.addView(headerView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 56)); backButton = new ImageView(activity); backButton.setScaleType(ImageView.ScaleType.CENTER); backDrawable = new BackDrawable(false); backDrawable.setAnimationTime(200.0f); backDrawable.setColor(0xffb3b3b3); backDrawable.setRotated(false); backButton.setImageDrawable(backDrawable); backButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR)); headerView.addView(backButton, LayoutHelper.createFrame(54, 56)); backButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { /*if (collapsed) { uncollapse(); } else { collapse(); }*/ close(true, true); } }); shareContainer = new FrameLayout(activity); headerView.addView(shareContainer, LayoutHelper.createFrame(48, 56, Gravity.TOP | Gravity.RIGHT)); shareContainer.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (currentPage == null || parentActivity == null) { return; } showDialog(new ShareAlert(parentActivity, null, currentPage.url, false, currentPage.url, true)); hideActionBar(); } }); shareButton = new ImageView(activity); shareButton.setScaleType(ImageView.ScaleType.CENTER); shareButton.setImageResource(R.drawable.ic_share_article); shareButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR)); shareContainer.addView(shareButton, LayoutHelper.createFrame(48, 56)); progressView = new ContextProgressView(activity, 2); progressView.setVisibility(View.GONE); shareContainer.addView(progressView, LayoutHelper.createFrame(48, 56)); windowLayoutParams = new WindowManager.LayoutParams(); windowLayoutParams.height = WindowManager.LayoutParams.MATCH_PARENT; windowLayoutParams.format = PixelFormat.TRANSLUCENT; windowLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT; windowLayoutParams.gravity = Gravity.TOP | Gravity.LEFT; windowLayoutParams.type = WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; if (Build.VERSION.SDK_INT >= 21) { windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; } else { windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; } if (progressDrawables == null) { progressDrawables = new Drawable[4]; progressDrawables[0] = parentActivity.getResources().getDrawable(R.drawable.circle_big); progressDrawables[1] = parentActivity.getResources().getDrawable(R.drawable.cancel_big); progressDrawables[2] = parentActivity.getResources().getDrawable(R.drawable.load_big); progressDrawables[3] = parentActivity.getResources().getDrawable(R.drawable.play_big); } scroller = new Scroller(activity); blackPaint.setColor(0xff000000); actionBar = new ActionBar(activity); actionBar.setBackgroundColor(Theme.ACTION_BAR_PHOTO_VIEWER_COLOR); actionBar.setOccupyStatusBar(false); actionBar.setTitleColor(0xffffffff); actionBar.setItemsBackgroundColor(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR, false); actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setTitle(LocaleController.formatString("Of", R.string.Of, 1, 1)); photoContainerView.addView(actionBar, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override public void onItemClick(int id) { if (id == -1) { closePhoto(true); } else if (id == gallery_menu_save) { if (Build.VERSION.SDK_INT >= 23 && parentActivity.checkSelfPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { parentActivity .requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 4); return; } File f = getMediaFile(currentIndex); if (f != null && f.exists()) { MediaController.saveFile(f.toString(), parentActivity, isMediaVideo(currentIndex) ? 1 : 0, null, null); } else { AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null); builder.setMessage(LocaleController.getString("PleaseDownload", R.string.PleaseDownload)); showDialog(builder.create()); } } else if (id == gallery_menu_share) { onSharePressed(); } else if (id == gallery_menu_openin) { try { AndroidUtilities.openForView(getMedia(currentIndex), parentActivity); closePhoto(false); } catch (Exception e) { FileLog.e(e); } } } @Override public boolean canOpenMenu() { File f = getMediaFile(currentIndex); return f != null && f.exists(); } }); ActionBarMenu menu = actionBar.createMenu(); menu.addItem(gallery_menu_share, R.drawable.share); menuItem = menu.addItem(0, R.drawable.ic_ab_other); menuItem.setLayoutInScreen(true); menuItem.addSubItem(gallery_menu_openin, LocaleController.getString("OpenInExternalApp", R.string.OpenInExternalApp)); //menuItem.addSubItem(gallery_menu_share, LocaleController.getString("ShareFile", R.string.ShareFile), 0); menuItem.addSubItem(gallery_menu_save, LocaleController.getString("SaveToGallery", R.string.SaveToGallery)); bottomLayout = new FrameLayout(parentActivity); bottomLayout.setBackgroundColor(0x7f000000); photoContainerView.addView(bottomLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.BOTTOM | Gravity.LEFT)); captionTextViewOld = new TextView(activity); captionTextViewOld.setMaxLines(10); captionTextViewOld.setBackgroundColor(0x7f000000); captionTextViewOld.setPadding(AndroidUtilities.dp(20), AndroidUtilities.dp(8), AndroidUtilities.dp(20), AndroidUtilities.dp(8)); captionTextViewOld.setLinkTextColor(0xffffffff); captionTextViewOld.setTextColor(0xffffffff); captionTextViewOld.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT); captionTextViewOld.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); captionTextViewOld.setVisibility(View.INVISIBLE); photoContainerView.addView(captionTextViewOld, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | Gravity.LEFT)); captionTextView = captionTextViewNew = new TextView(activity); captionTextViewNew.setMaxLines(10); captionTextViewNew.setBackgroundColor(0x7f000000); captionTextViewNew.setPadding(AndroidUtilities.dp(20), AndroidUtilities.dp(8), AndroidUtilities.dp(20), AndroidUtilities.dp(8)); captionTextViewNew.setLinkTextColor(0xffffffff); captionTextViewNew.setTextColor(0xffffffff); captionTextViewNew.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT); captionTextViewNew.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); captionTextViewNew.setVisibility(View.INVISIBLE); photoContainerView.addView(captionTextViewNew, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | Gravity.LEFT)); radialProgressViews[0] = new RadialProgressView(activity, photoContainerView); radialProgressViews[0].setBackgroundState(0, false); radialProgressViews[1] = new RadialProgressView(activity, photoContainerView); radialProgressViews[1].setBackgroundState(0, false); radialProgressViews[2] = new RadialProgressView(activity, photoContainerView); radialProgressViews[2].setBackgroundState(0, false); videoPlayerSeekbar = new SeekBar(activity); videoPlayerSeekbar.setColors(0x66ffffff, 0xffffffff, 0xffffffff); videoPlayerSeekbar.setDelegate(new SeekBar.SeekBarDelegate() { @Override public void onSeekBarDrag(float progress) { if (videoPlayer != null) { videoPlayer.seekTo((int) (progress * videoPlayer.getDuration())); } } }); videoPlayerControlFrameLayout = new FrameLayout(activity) { @Override public boolean onTouchEvent(MotionEvent event) { int x = (int) event.getX(); int y = (int) event.getY(); if (videoPlayerSeekbar.onTouch(event.getAction(), event.getX() - AndroidUtilities.dp(48), event.getY())) { getParent().requestDisallowInterceptTouchEvent(true); invalidate(); return true; } return super.onTouchEvent(event); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); long duration; if (videoPlayer != null) { duration = videoPlayer.getDuration(); if (duration == C.TIME_UNSET) { duration = 0; } } else { duration = 0; } duration /= 1000; int size = (int) Math .ceil(videoPlayerTime.getPaint().measureText(String.format("%02d:%02d / %02d:%02d", duration / 60, duration % 60, duration / 60, duration % 60))); videoPlayerSeekbar.setSize(getMeasuredWidth() - AndroidUtilities.dp(48 + 16) - size, getMeasuredHeight()); } @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); float progress = 0; if (videoPlayer != null) { progress = videoPlayer.getCurrentPosition() / (float) videoPlayer.getDuration(); } videoPlayerSeekbar.setProgress(progress); } @Override protected void onDraw(Canvas canvas) { canvas.save(); canvas.translate(AndroidUtilities.dp(48), 0); videoPlayerSeekbar.draw(canvas); canvas.restore(); } }; videoPlayerControlFrameLayout.setWillNotDraw(false); bottomLayout.addView(videoPlayerControlFrameLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT)); videoPlayButton = new ImageView(activity); videoPlayButton.setScaleType(ImageView.ScaleType.CENTER); videoPlayerControlFrameLayout.addView(videoPlayButton, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP)); videoPlayButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (videoPlayer != null) { if (isPlaying) { videoPlayer.pause(); } else { videoPlayer.play(); } } } }); videoPlayerTime = new TextView(activity); videoPlayerTime.setTextColor(0xffffffff); videoPlayerTime.setGravity(Gravity.CENTER_VERTICAL); videoPlayerTime.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13); videoPlayerControlFrameLayout.addView(videoPlayerTime, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.RIGHT | Gravity.TOP, 0, 0, 8, 0)); gestureDetector = new GestureDetector(activity, this); gestureDetector.setOnDoubleTapListener(this); ImageReceiver.ImageReceiverDelegate imageReceiverDelegate = new ImageReceiver.ImageReceiverDelegate() { @Override public void didSetImage(ImageReceiver imageReceiver, boolean set, boolean thumb) { if (imageReceiver == centerImage && set && scaleToFill()) { if (!wasLayout) { dontResetZoomOnFirstLayout = true; } else { setScaleToFill(); } } } }; centerImage.setParentView(photoContainerView); centerImage.setCrossfadeAlpha((byte) 2); centerImage.setInvalidateAll(true); centerImage.setDelegate(imageReceiverDelegate); leftImage.setParentView(photoContainerView); leftImage.setCrossfadeAlpha((byte) 2); leftImage.setInvalidateAll(true); leftImage.setDelegate(imageReceiverDelegate); rightImage.setParentView(photoContainerView); rightImage.setCrossfadeAlpha((byte) 2); rightImage.setInvalidateAll(true); rightImage.setDelegate(imageReceiverDelegate); }
From source file:android.support.v7.widget.RecyclerViewEx.java
@Override public void draw(Canvas c) { super.draw(c); final int count = mItemDecorations.size(); for (int i = 0; i < count; i++) { mItemDecorations.get(i).onDrawOver(c, this, mState); }// ww w . j a v a2 s . c o m // TODO If padding is not 0 and chilChildrenToPadding is false, to draw glows properly, we // need find children closest to edges. Not sure if it is worth the effort. boolean needsInvalidate = false; if (mLeftGlow != null && !mLeftGlow.isFinished()) { final int restore = c.save(); final int padding = mClipToPadding ? getPaddingBottom() : 0; c.rotate(270); c.translate(-getHeight() + padding, 0); needsInvalidate = mLeftGlow != null && mLeftGlow.draw(c); c.restoreToCount(restore); } if (mTopGlow != null && !mTopGlow.isFinished()) { final int restore = c.save(); if (mClipToPadding) { c.translate(getPaddingLeft(), getPaddingTop()); } needsInvalidate |= mTopGlow != null && mTopGlow.draw(c); c.restoreToCount(restore); } if (mRightGlow != null && !mRightGlow.isFinished()) { final int restore = c.save(); final int width = getWidth(); final int padding = mClipToPadding ? getPaddingTop() : 0; c.rotate(90); c.translate(-padding, -width); needsInvalidate |= mRightGlow != null && mRightGlow.draw(c); c.restoreToCount(restore); } if (mBottomGlow != null && !mBottomGlow.isFinished()) { final int restore = c.save(); c.rotate(180); if (mClipToPadding) { c.translate(-getWidth() + getPaddingRight(), -getHeight() + getPaddingBottom()); } else { c.translate(-getWidth(), -getHeight()); } needsInvalidate |= mBottomGlow != null && mBottomGlow.draw(c); c.restoreToCount(restore); } // If some views are animating, ItemDecorators are likely to move/change with them. // Invalidate RecyclerViewEx to re-draw decorators. This is still efficient because children's // display lists are not invalidated. if (!needsInvalidate && mItemAnimator != null && mItemDecorations.size() > 0 && mItemAnimator.isRunning()) { needsInvalidate = true; } if (needsInvalidate) { ViewCompat.postInvalidateOnAnimation(this); } }
From source file:org.telegram.ui.PassportActivity.java
private void createAddressInterface(Context context) { languageMap = new HashMap<>(); try {//from w w w .j av a2 s . co m BufferedReader reader = new BufferedReader( new InputStreamReader(context.getResources().getAssets().open("countries.txt"))); String line; while ((line = reader.readLine()) != null) { String[] args = line.split(";"); languageMap.put(args[1], args[2]); } reader.close(); } catch (Exception e) { FileLog.e(e); } topErrorCell = new TextInfoPrivacyCell(context); topErrorCell.setBackgroundDrawable( Theme.getThemedDrawable(context, R.drawable.greydivider_top, Theme.key_windowBackgroundGrayShadow)); topErrorCell.setPadding(0, AndroidUtilities.dp(7), 0, 0); linearLayout2.addView(topErrorCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); checkTopErrorCell(true); if (currentDocumentsType != null) { if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeRentalAgreement) { actionBar.setTitle(LocaleController.getString("ActionBotDocumentRentalAgreement", R.string.ActionBotDocumentRentalAgreement)); } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeBankStatement) { actionBar.setTitle(LocaleController.getString("ActionBotDocumentBankStatement", R.string.ActionBotDocumentBankStatement)); } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeUtilityBill) { actionBar.setTitle(LocaleController.getString("ActionBotDocumentUtilityBill", R.string.ActionBotDocumentUtilityBill)); } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypePassportRegistration) { actionBar.setTitle(LocaleController.getString("ActionBotDocumentPassportRegistration", R.string.ActionBotDocumentPassportRegistration)); } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeTemporaryRegistration) { actionBar.setTitle(LocaleController.getString("ActionBotDocumentTemporaryRegistration", R.string.ActionBotDocumentTemporaryRegistration)); } headerCell = new HeaderCell(context); headerCell.setText(LocaleController.getString("PassportDocuments", R.string.PassportDocuments)); headerCell.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); linearLayout2.addView(headerCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); documentsLayout = new LinearLayout(context); documentsLayout.setOrientation(LinearLayout.VERTICAL); linearLayout2.addView(documentsLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); uploadDocumentCell = new TextSettingsCell(context); uploadDocumentCell.setBackgroundDrawable(Theme.getSelectorDrawable(true)); linearLayout2.addView(uploadDocumentCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); uploadDocumentCell.setOnClickListener(v -> { uploadingFileType = UPLOADING_TYPE_DOCUMENTS; openAttachMenu(); }); bottomCell = new TextInfoPrivacyCell(context); bottomCell.setBackgroundDrawable( Theme.getThemedDrawable(context, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow)); if (currentBotId != 0) { noAllDocumentsErrorText = LocaleController.getString("PassportAddAddressUploadInfo", R.string.PassportAddAddressUploadInfo); } else { if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeRentalAgreement) { noAllDocumentsErrorText = LocaleController.getString("PassportAddAgreementInfo", R.string.PassportAddAgreementInfo); } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeUtilityBill) { noAllDocumentsErrorText = LocaleController.getString("PassportAddBillInfo", R.string.PassportAddBillInfo); } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypePassportRegistration) { noAllDocumentsErrorText = LocaleController.getString("PassportAddPassportRegistrationInfo", R.string.PassportAddPassportRegistrationInfo); } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeTemporaryRegistration) { noAllDocumentsErrorText = LocaleController.getString("PassportAddTemporaryRegistrationInfo", R.string.PassportAddTemporaryRegistrationInfo); } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeBankStatement) { noAllDocumentsErrorText = LocaleController.getString("PassportAddBankInfo", R.string.PassportAddBankInfo); } else { noAllDocumentsErrorText = ""; } } CharSequence text = noAllDocumentsErrorText; if (documentsErrors != null) { String errorText; if ((errorText = documentsErrors.get("files_all")) != null) { SpannableStringBuilder stringBuilder = new SpannableStringBuilder(errorText); stringBuilder.append("\n\n"); stringBuilder.append(noAllDocumentsErrorText); text = stringBuilder; stringBuilder.setSpan( new ForegroundColorSpan(Theme.getColor(Theme.key_windowBackgroundWhiteRedText3)), 0, errorText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); errorsValues.put("files_all", ""); } } bottomCell.setText(text); linearLayout2.addView(bottomCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); if (currentDocumentsType.translation_required) { headerCell = new HeaderCell(context); headerCell.setText(LocaleController.getString("PassportTranslation", R.string.PassportTranslation)); headerCell.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); linearLayout2.addView(headerCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); translationLayout = new LinearLayout(context); translationLayout.setOrientation(LinearLayout.VERTICAL); linearLayout2.addView(translationLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); uploadTranslationCell = new TextSettingsCell(context); uploadTranslationCell.setBackgroundDrawable(Theme.getSelectorDrawable(true)); linearLayout2.addView(uploadTranslationCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); uploadTranslationCell.setOnClickListener(v -> { uploadingFileType = UPLOADING_TYPE_TRANSLATION; openAttachMenu(); }); bottomCellTranslation = new TextInfoPrivacyCell(context); bottomCellTranslation.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow)); if (currentBotId != 0) { noAllTranslationErrorText = LocaleController.getString("PassportAddTranslationUploadInfo", R.string.PassportAddTranslationUploadInfo); } else { if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeRentalAgreement) { noAllTranslationErrorText = LocaleController.getString( "PassportAddTranslationAgreementInfo", R.string.PassportAddTranslationAgreementInfo); } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeUtilityBill) { noAllTranslationErrorText = LocaleController.getString("PassportAddTranslationBillInfo", R.string.PassportAddTranslationBillInfo); } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypePassportRegistration) { noAllTranslationErrorText = LocaleController.getString( "PassportAddTranslationPassportRegistrationInfo", R.string.PassportAddTranslationPassportRegistrationInfo); } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeTemporaryRegistration) { noAllTranslationErrorText = LocaleController.getString( "PassportAddTranslationTemporaryRegistrationInfo", R.string.PassportAddTranslationTemporaryRegistrationInfo); } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeBankStatement) { noAllTranslationErrorText = LocaleController.getString("PassportAddTranslationBankInfo", R.string.PassportAddTranslationBankInfo); } else { noAllTranslationErrorText = ""; } } text = noAllTranslationErrorText; if (documentsErrors != null) { String errorText; if ((errorText = documentsErrors.get("translation_all")) != null) { SpannableStringBuilder stringBuilder = new SpannableStringBuilder(errorText); stringBuilder.append("\n\n"); stringBuilder.append(noAllTranslationErrorText); text = stringBuilder; stringBuilder.setSpan( new ForegroundColorSpan(Theme.getColor(Theme.key_windowBackgroundWhiteRedText3)), 0, errorText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); errorsValues.put("translation_all", ""); } } bottomCellTranslation.setText(text); linearLayout2.addView(bottomCellTranslation, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); } } else { actionBar.setTitle(LocaleController.getString("PassportAddress", R.string.PassportAddress)); } headerCell = new HeaderCell(context); headerCell.setText(LocaleController.getString("PassportAddressHeader", R.string.PassportAddressHeader)); headerCell.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); linearLayout2.addView(headerCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); inputFields = new EditTextBoldCursor[FIELD_ADDRESS_COUNT]; for (int a = 0; a < FIELD_ADDRESS_COUNT; a++) { final EditTextBoldCursor field = new EditTextBoldCursor(context); inputFields[a] = field; ViewGroup container = new FrameLayout(context) { private StaticLayout errorLayout; float offsetX; @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int width = MeasureSpec.getSize(widthMeasureSpec) - AndroidUtilities.dp(34); errorLayout = field.getErrorLayout(width); if (errorLayout != null) { int lineCount = errorLayout.getLineCount(); if (lineCount > 1) { int height = AndroidUtilities.dp(64) + (errorLayout.getLineBottom(lineCount - 1) - errorLayout.getLineBottom(0)); heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); } if (LocaleController.isRTL) { float maxW = 0; for (int a = 0; a < lineCount; a++) { float l = errorLayout.getLineLeft(a); if (l != 0) { offsetX = 0; break; } maxW = Math.max(maxW, errorLayout.getLineWidth(a)); if (a == lineCount - 1) { offsetX = width - maxW; } } } } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } @Override protected void onDraw(Canvas canvas) { if (errorLayout != null) { canvas.save(); canvas.translate(AndroidUtilities.dp(21) + offsetX, field.getLineY() + AndroidUtilities.dp(3)); errorLayout.draw(canvas); canvas.restore(); } } }; container.setWillNotDraw(false); linearLayout2.addView(container, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); container.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); if (a == FIELD_ADDRESS_COUNT - 1) { extraBackgroundView = new View(context); extraBackgroundView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); linearLayout2.addView(extraBackgroundView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 6)); } if (documentOnly && currentDocumentsType != null) { container.setVisibility(View.GONE); if (extraBackgroundView != null) { extraBackgroundView.setVisibility(View.GONE); } } inputFields[a].setTag(a); inputFields[a].setSupportRtlHint(true); inputFields[a].setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); inputFields[a].setHintColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText)); inputFields[a].setHeaderHintColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueHeader)); inputFields[a].setTransformHintToHeader(true); inputFields[a].setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText)); inputFields[a].setBackgroundDrawable(null); inputFields[a].setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText)); inputFields[a].setCursorSize(AndroidUtilities.dp(20)); inputFields[a].setCursorWidth(1.5f); inputFields[a].setLineColors(Theme.getColor(Theme.key_windowBackgroundWhiteInputField), Theme.getColor(Theme.key_windowBackgroundWhiteInputFieldActivated), Theme.getColor(Theme.key_windowBackgroundWhiteRedText3)); if (a == FIELD_COUNTRY) { inputFields[a].setOnTouchListener((v, event) -> { if (getParentActivity() == null) { return false; } if (event.getAction() == MotionEvent.ACTION_UP) { CountrySelectActivity fragment = new CountrySelectActivity(false); fragment.setCountrySelectActivityDelegate((name, shortName) -> { inputFields[FIELD_COUNTRY].setText(name); currentCitizeship = shortName; }); presentFragment(fragment); } return true; }); inputFields[a].setInputType(0); inputFields[a].setFocusable(false); } else { inputFields[a].setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES); inputFields[a].setImeOptions(EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NO_EXTRACT_UI); } String value; final String key; switch (a) { case FIELD_STREET1: inputFields[a].setHintText(LocaleController.getString("PassportStreet1", R.string.PassportStreet1)); key = "street_line1"; break; case FIELD_STREET2: inputFields[a].setHintText(LocaleController.getString("PassportStreet2", R.string.PassportStreet2)); key = "street_line2"; break; case FIELD_CITY: inputFields[a].setHintText(LocaleController.getString("PassportCity", R.string.PassportCity)); key = "city"; break; case FIELD_STATE: inputFields[a].setHintText(LocaleController.getString("PassportState", R.string.PassportState)); key = "state"; break; case FIELD_COUNTRY: inputFields[a].setHintText(LocaleController.getString("PassportCountry", R.string.PassportCountry)); key = "country_code"; break; case FIELD_POSTCODE: inputFields[a] .setHintText(LocaleController.getString("PassportPostcode", R.string.PassportPostcode)); key = "post_code"; break; default: continue; } setFieldValues(currentValues, inputFields[a], key); if (a == FIELD_POSTCODE) { inputFields[a].addTextChangedListener(new TextWatcher() { private boolean ignore; @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { if (ignore) { return; } ignore = true; boolean error = false; for (int a = 0; a < s.length(); a++) { char ch = s.charAt(a); if (!(ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch >= '0' && ch <= '9' || ch == '-' || ch == ' ')) { error = true; break; } } ignore = false; if (error) { field.setErrorText(LocaleController.getString("PassportUseLatinOnly", R.string.PassportUseLatinOnly)); } else { checkFieldForError(field, key, s, false); } } }); InputFilter[] inputFilters = new InputFilter[1]; inputFilters[0] = new InputFilter.LengthFilter(10); inputFields[a].setFilters(inputFilters); } else { inputFields[a].addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { checkFieldForError(field, key, s, false); } }); } inputFields[a].setSelection(inputFields[a].length()); inputFields[a].setPadding(0, 0, 0, 0); inputFields[a] .setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL); container.addView(inputFields[a], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 64, Gravity.LEFT | Gravity.TOP, 21, 0, 21, 0)); inputFields[a].setOnEditorActionListener((textView, i, keyEvent) -> { if (i == EditorInfo.IME_ACTION_NEXT) { int num = (Integer) textView.getTag(); num++; if (num < inputFields.length) { if (inputFields[num].isFocusable()) { inputFields[num].requestFocus(); } else { inputFields[num] .dispatchTouchEvent(MotionEvent.obtain(0, 0, MotionEvent.ACTION_UP, 0, 0, 0)); textView.clearFocus(); AndroidUtilities.hideKeyboard(textView); } } return true; } return false; }); } sectionCell = new ShadowSectionCell(context); linearLayout2.addView(sectionCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); if (documentOnly && currentDocumentsType != null) { headerCell.setVisibility(View.GONE); sectionCell.setVisibility(View.GONE); } if ((currentBotId != 0 || currentDocumentsType == null) && currentTypeValue != null && !documentOnly || currentDocumentsTypeValue != null) { if (currentDocumentsTypeValue != null) { addDocumentViews(currentDocumentsTypeValue.files); addTranslationDocumentViews(currentDocumentsTypeValue.translation); } sectionCell.setBackgroundDrawable( Theme.getThemedDrawable(context, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow)); TextSettingsCell settingsCell1 = new TextSettingsCell(context); settingsCell1.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText3)); settingsCell1.setBackgroundDrawable(Theme.getSelectorDrawable(true)); if (currentDocumentsType == null) { settingsCell1.setText(LocaleController.getString("PassportDeleteInfo", R.string.PassportDeleteInfo), false); } else { settingsCell1.setText( LocaleController.getString("PassportDeleteDocument", R.string.PassportDeleteDocument), false); } linearLayout2.addView(settingsCell1, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); settingsCell1.setOnClickListener(v -> createDocumentDeleteAlert()); sectionCell = new ShadowSectionCell(context); sectionCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow)); linearLayout2.addView(sectionCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); } else { sectionCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow)); if (documentOnly && currentDocumentsType != null) { bottomCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow)); } } updateUploadText(UPLOADING_TYPE_DOCUMENTS); updateUploadText(UPLOADING_TYPE_TRANSLATION); }