List of usage examples for android.graphics Canvas restore
public void restore()
From source file:com.lt.adamlee.aagame.GameView.java
public void onDraw(Canvas c) { try {/*w w w. ja v a 2 s . c o m*/ if (mainpage == -1) { this.eg.exitdialog(c); } if (mainpage == 1) { if (bak2) { internalcounter2++; if (internalcounter2 % 10 == 0) { counter1234++; } if (counter1234 >= 2) { counter1234 = 0; internalcounter2 = 0; bak2 = false; } } if (bak4) { this.internalcounter4++; if (this.internalcounter4 % 10 == 0) { this.counter12346++; } if (this.counter12346 >= 2) { this.counter12346 = 0; this.internalcounter4 = 0; bak4 = false; } } c.drawBitmap(this.mainpageimage, 0.0f, 0.0f, null); c.drawBitmap(this.play, F.wf(110.0f), F.hf(175.0f), null); c.drawBitmap(this.moreapps, F.wf(45.0f), F.hf(340.0f), null); c.drawBitmap(this.help, F.wf(130.0f), F.hf(340.0f), null); c.drawBitmap(this.leaderboard, F.wf(215.0f), F.hf(340.0f), null); } if (mainpage == 5) { help(c); } if (mainpage == 6) { this.anim.levelanim(c); } if (mainpage == 7) { if (this.bakc) { this.internalcounterc++; if (this.internalcounterc % 10 == 0) { this.counterc++; } if (this.counterc >= 2) { this.counterc = 0; this.internalcounterc = 0; this.bakc = false; } } this.level.Level_Canvas(c); } if (mainpage == 3) { float[] fArr; if (baka) { this.internalcountera++; if (this.internalcountera % 10 == 0) { this.countera++; } if (this.countera >= 2) { this.countera = 0; this.internalcountera = 0; baka = false; } } view.drawRectangle(c); if (levelcounter % 3 == 0) { if (rotation[0] <= 0.0f && rotation[0] <= 0.0f) { changeangle = 2.0d; } if (rotation[0] > 0.0f && rotation[0] >= 360.0f) { changeangle = -2.0d; } } if (levelcounter % 3 == 1) { changeangle = 2.0d; } if (levelcounter % 3 == 2) { changeangle = -2.0d; } x = (int) F.wf(160.0f); y = (int) F.hf(159.0f); r = (int) F.wf(10.0f); int i = 0; while (i < blinedraw.length) { if (blinedraw[i]) { c.save(); c.rotate(rotation[i], (float) (screenW / 2), F.hf(272.0f)); c.drawLine((float) (screenW / 2), F.hf(272.0f), (float) (screenW / 2), F.hf(272.0f) - F.hf(105.0f), paint4); c.drawCircle((float) x, (float) y, (float) r, paint3); c.drawBitmap(this.cartoonbomb, new Rect(0, 0, this.cartoonbomb.getWidth(), this.cartoonbomb.getHeight()), new Rect(x - (this.cartoonbomb.getWidth() / 2), y - (this.cartoonbomb.getHeight() / 2), x + (this.cartoonbomb.getWidth() / 2), y + (this.cartoonbomb.getHeight() / 2)), null); if (i >= saveline) { c.drawText((Circle.var - (i - saveline) + ""), (float) x, (float) ((int) F.hf(163.0f)), this.innercircletext); } savex[i] = x; savey[i] = y; if (changeangle > 0.0d && rotation[i] >= 360.0f) { rotation[i] = 0.0f; } if (changeangle < 0.0d && rotation[i] <= -360.0f) { rotation[i] = 0.0f; } if (!(errorcircle || !GameActivity.isResume || circleblink)) { fArr = rotation; fArr[i] = (float) (((double) fArr[i]) + changeangle); } c.restore(); if (circleblink) { holdcounter++; if (holdcounter > 32000) { holdcounter = 0; } if (holdcounter % 5 == 0) { hcm++; } if (hcm > 32000) { hcm = 0; } if (hcm <= 9) { h = (int) F.wf(160.0f); j = (int) F.hf(159.0f); k = (int) F.wf(11.0f); paint7.setAlpha(a1); paint7.setColor(SupportMenu.CATEGORY_MASK); paint7.setAntiAlias(true); paint7.setFilterBitmap(true); paint7.setStrokeWidth(2.0f); c.drawCircle((float) h, (float) j, (float) k, paint7); c.drawCircle((float) x, (float) y, (float) r, paint3); if (i >= saveline) { c.drawText((Circle.var - (i - saveline) + ""), (float) x, (float) ((int) F.hf(163.0f)), this.innercircletext); } } if (hcm >= 11) { circleblink = false; mainpage = 6; // GameActivity.vimapad.isBottomAdVisible(true); // GameActivity.vimapad.isTopAdVisible(true); holdcounter = 0; hcm = 0; } } } i++; } i = 0; while (i < circledrawboolean.length) { if (circledrawboolean[i]) { c.save(); c.rotate(rotation[i], (float) (screenW / 2), F.hf(272.0f)); c.drawLine((float) (screenW / 2), F.hf(272.0f), (float) (screenW / 2), F.hf(272.0f) - F.hf(105.0f), paint4); c.drawCircle((float) x, (float) y, (float) r, paint3); if (i >= saveline) { c.drawText((Circle.var - (i - saveline) + ""), (float) x, (float) ((int) F.hf(163.0f)), this.innercircletext); } savex[i] = x; savey[i] = y; if (changeangle > 0.0d && rotation[i] >= 360.0f) { rotation[i] = 0.0f; } if (changeangle < 0.0d && rotation[i] <= -360.0f) { rotation[i] = 0.0f; } if (!(errorcircle || !GameActivity.isResume || circleblink)) { fArr = rotation; fArr[i] = (float) (((double) fArr[i]) + changeangle); } c.restore(); if (colcircle) { this.displaycount3++; textdisplayboolean = false; if (this.displaycount3 <= 70 || (this.displaycount3 >= 80 && this.displaycount3 <= 90)) { paint6.setAntiAlias(true); } paint6.setFilterBitmap(true); paint6.setColor(ViewCompat.MEASURED_STATE_MASK); c.drawCircle((float) (screenW / 2), F.hf(272.0f), F.wf(39.0f), paint6); paint6.setColor(SupportMenu.CATEGORY_MASK); paint6.setAntiAlias(true); paint6.setFilterBitmap(true); paint6.setTypeface(tf); paint6.setAlpha(Circle.a); paint6.setTextAlign(Paint.Align.CENTER); c.drawText(String.valueOf(levelcounter), F.wf(160.0f), F.hf(278.0f), paint6); paint6.setColor(getResources().getColor(R.color.common_signin_btn_default_background)); paint6.setAlpha(20); paint6.setAntiAlias(true); paint6.setFilterBitmap(true); c.drawRect(0.0f, 0.0f, (float) screenW, (float) screenH, paint6); if (this.displaycount3 <= 70 || this.displaycount3 >= 80) { } if (this.displaycount3 > 90) { int j; this.displaycount3 = 0; colcircle = false; circleblink = false; bak4 = true; reset(); levelcounter++; errorcircle = false; linecounter = NoOfInitialLines - 1; for (j = 0; j < NoOfInitialLines; j++) { blinedraw[j] = true; } for (j = 0; j < rotation.length; j++) { rotation[j] = 0.0f; } for (j = 0; j < NoOfInitialLines; j++) { rotation[j] = (float) ((j + 1) * (360 / NoOfInitialLines)); if (rotation[j] > 360.0f) { rotation[j] = rotation[j] - 360.0f; } } } } } i++; } this.paint21.setColor(-1); this.paint21.setTypeface(tf); this.paint21.setTextAlign(Paint.Align.CENTER); this.paint21.setAntiAlias(true); this.paint21.setFilterBitmap(true); if (textdisplayboolean) { c.drawText(String.valueOf(levelcounter), F.wf(160.0f), F.hf(278.0f), this.paint21); } } } catch (Exception e) { } }
From source file:com.skytree.epubtest.BookViewActivity.java
@SuppressLint({ "DrawAllocation", "DrawAllocation" }) @Override//from w ww .j a v a 2 s .com protected void onDraw(Canvas canvas) { Paint paint = new Paint(); float sl, sr, st, sb; sl = 0; sr = this.getWidth(); float ah = this.arrowHeight; // arrow Height; if (this.isArrowDown) { st = 0; sb = this.getHeight() - ah; } else { st = ah - 10; sb = this.getHeight() - 10; } Path boxPath = new Path(); boxPath.addRoundRect(new RectF(sl, st, sr, sb), 20, 20, Path.Direction.CW); if (arrowPosition <= arrowHeight * 1.5f) { arrowPosition = arrowHeight * 1.5f; } else if (arrowPosition >= this.getWidth() - arrowHeight * 1.5f) { arrowPosition = this.getWidth() - arrowHeight * 1.5f; } Path arrowPath = new Path(); if (isArrowDown) { arrowPath.moveTo(arrowPosition, sb + ah); arrowPath.lineTo((float) (arrowPosition - ah * 0.75), sb - 10); arrowPath.lineTo((float) (arrowPosition + ah * 0.75), sb - 10); arrowPath.close(); } else { arrowPath.moveTo(arrowPosition, 0); arrowPath.lineTo((float) (arrowPosition - ah * 0.75), ah + 10); arrowPath.lineTo((float) (arrowPosition + ah * 0.75), ah + 10); arrowPath.close(); } paint.setColor(this.strokeColor); paint.setStyle(Paint.Style.FILL); boxPath.addPath(arrowPath); canvas.drawPath(boxPath, paint); paint.setColor(this.boxColor); paint.setStyle(Paint.Style.FILL); boxPath.addPath(arrowPath); canvas.save(); float sf = 0.995f; float ox = (this.getWidth() - (this.getWidth() * sf)) / 2.0f; float oy = ((this.getHeight() - arrowHeight) - ((this.getHeight() - arrowHeight) * sf)) / 2.0f; canvas.translate(ox, oy); canvas.scale(sf, sf); canvas.drawPath(boxPath, paint); canvas.restore(); if (layoutChanged) { this.recalcLayout(); layoutChanged = false; } }
From source file:com.am.pagergradienttab.view.PagerGradientTabStrip.java
/** * // w w w. j a v a 2s . co m * * @param canvas */ private void drawTag(Canvas canvas) { // TODO if (mTagAdapter != null) { canvas.save(); float canvasOffset = 0; int x = getPaddingLeft(); int y = getPaddingTop(); float textTop = 0; mTextPaint.setColor(Color.WHITE); mTextPaint.setTextAlign(Align.LEFT); for (int position = 0; position < tabs.size(); position++) { canvas.translate(canvasOffset, 0); canvasOffset = itemWidth + intervalWidth; canvas.save(); if (mTagAdapter.isEnable(position)) { int textWidth; int textHeight; mTextPaint.setTextSize(mTagAdapter.getTextSize(position)); String tag = mTagAdapter.getTag(position) == null ? "" : mTagAdapter.getTag(position); textWidth = (int) Math.ceil(mTextPaint.measureText(tag)); FontMetrics fontMetrics = mTextPaint.getFontMetrics(); textHeight = (int) Math.ceil(fontMetrics.descent - fontMetrics.ascent); textTop = textHeight - (-fontMetrics.ascent - fontMetrics.descent + (fontMetrics.bottom - fontMetrics.descent) * density); textHeight += textTop; if ("".equals(tag)) { textHeight = 0; } final Drawable drawable = mTagAdapter.getBackground(position); int drawableWidth = drawable == null ? 0 : drawable.getMinimumWidth(); int drawableHeight = drawable == null ? 0 : drawable.getMinimumHeight(); float offsetX = Math.max(textWidth + mTagAdapter.getPaddingLeft(position) + mTagAdapter.getPaddingRight(position), drawableWidth); float offsetTextX = (offsetX - (textWidth + mTagAdapter.getPaddingLeft(position) + mTagAdapter.getPaddingRight(position))) * 0.5f; float offsetY = Math.max(textHeight + mTagAdapter.getPaddingBottom(position) + mTagAdapter.getPaddingTop(position), drawableHeight); float offsetTextY = (offsetY - (textHeight + mTagAdapter.getPaddingBottom(position) + mTagAdapter.getPaddingTop(position))) * 0.5f; mTextPaint.setTextSize(showTextScale ? textSize * (1 + magnification) : textSize); float myTextWidth = mTextPaint.measureText(tabs.get(position)); TagAlign ta = mTagAdapter.getTagAlign(position); switch (ta) { default: case LEFTTOP: canvas.translate(mTagAdapter.getMarginLeft(position), mTagAdapter.getMarginTop(position)); break; case LEFTCENTER: canvas.translate(mTagAdapter.getMarginLeft(position), (getHeight() - underLineHeight - offsetY) / 2); break; case LEFTBOTTOM: canvas.translate(mTagAdapter.getMarginLeft(position), getHeight() - offsetY - underLineHeight - mTagAdapter.getMarginBottom(position)); break; case RIGHTTOP: canvas.translate(itemWidth - offsetX - mTagAdapter.getMarginRight(position), mTagAdapter.getMarginTop(position)); break; case RIGHTCENTER: canvas.translate(itemWidth - offsetX - mTagAdapter.getMarginRight(position), (getHeight() - underLineHeight - offsetY) / 2); break; case RIGHTBOTTOM: canvas.translate(itemWidth - offsetX - mTagAdapter.getMarginRight(position), getHeight() - offsetY - underLineHeight - mTagAdapter.getMarginBottom(position)); break; case LEFTTOPTEXT: canvas.translate( (itemWidth - myTextWidth) / 2 - offsetX - mTagAdapter.getMarginRight(position), mTagAdapter.getMarginTop(position)); break; case LEFTCENTERTEXT: canvas.translate( (itemWidth - myTextWidth) / 2 - offsetX - mTagAdapter.getMarginRight(position), (getHeight() - underLineHeight - offsetY) / 2); break; case LEFTBOTTOMTEXT: canvas.translate( (itemWidth - myTextWidth) / 2 - offsetX - mTagAdapter.getMarginRight(position), getHeight() - offsetY - underLineHeight - mTagAdapter.getMarginBottom(position)); break; case RIGHTTOPTEXT: canvas.translate((itemWidth + myTextWidth) / 2 + mTagAdapter.getMarginLeft(position), mTagAdapter.getMarginTop(position)); break; case RIGHTCENTERTEXT: canvas.translate((itemWidth + myTextWidth) / 2 + mTagAdapter.getMarginLeft(position), (getHeight() - underLineHeight - offsetY) / 2); break; case RIGHTBOTTOMTEXT: canvas.translate((itemWidth + myTextWidth) / 2 + mTagAdapter.getMarginLeft(position), getHeight() - offsetY - underLineHeight - mTagAdapter.getMarginBottom(position)); break; } mTextPaint.setTextSize(mTagAdapter.getTextSize(position)); if (drawable != null) { drawable.setBounds(x, y, (int) (x + offsetX), (int) (y + offsetY)); drawable.draw(canvas); } canvas.drawText(tag, x + offsetTextX + mTagAdapter.getPaddingLeft(position), y + offsetY - textTop - offsetTextY - mTagAdapter.getPaddingTop(position), mTextPaint); } canvas.restore(); } canvas.restore(); } }
From source file:com.raibow.yamahaspk.filtershow.imageshow.ImageShow.java
public void drawImageAndAnimate(Canvas canvas, Bitmap image) { if (image == null) { return;// w ww.jav a 2 s . co m } MasterImage master = MasterImage.getImage(); Matrix m = master.computeImageToScreen(image, 0, false); if (m == null) { return; } canvas.save(); RectF d = new RectF(0, 0, image.getWidth(), image.getHeight()); m.mapRect(d); d.roundOut(mImageBounds); boolean showAnimatedImage = master.onGoingNewLookAnimation(); if (!showAnimatedImage && mDidStartAnimation) { // animation ended, but do we have the correct image to show? if (master.getPreset().equals(master.getCurrentPreset())) { // we do, let's stop showing the animated image mDidStartAnimation = false; MasterImage.getImage().resetAnimBitmap(); } else { showAnimatedImage = true; } } else if (showAnimatedImage) { mDidStartAnimation = true; } if (showAnimatedImage) { canvas.save(); // Animation uses the image before the change Bitmap previousImage = master.getPreviousImage(); Matrix mp = master.computeImageToScreen(previousImage, 0, false); RectF dp = new RectF(0, 0, previousImage.getWidth(), previousImage.getHeight()); mp.mapRect(dp); Rect previousBounds = new Rect(); dp.roundOut(previousBounds); float centerX = dp.centerX(); float centerY = dp.centerY(); boolean needsToDrawImage = true; if (master.getCurrentLookAnimation() == MasterImage.CIRCLE_ANIMATION) { float maskScale = MasterImage.getImage().getMaskScale(); if (maskScale >= 0.0f) { float maskW = sMask.getWidth() / 2.0f; float maskH = sMask.getHeight() / 2.0f; Point point = mActivity.hintTouchPoint(this); float maxMaskScale = 2 * Math.max(getWidth(), getHeight()) / Math.min(maskW, maskH); maskScale = maskScale * maxMaskScale; float x = point.x - maskW * maskScale; float y = point.y - maskH * maskScale; // Prepare the shader mShaderMatrix.reset(); mShaderMatrix.setScale(1.0f / maskScale, 1.0f / maskScale); mShaderMatrix.preTranslate(-x + mImageBounds.left, -y + mImageBounds.top); float scaleImageX = mImageBounds.width() / (float) image.getWidth(); float scaleImageY = mImageBounds.height() / (float) image.getHeight(); mShaderMatrix.preScale(scaleImageX, scaleImageY); mMaskPaint.reset(); mMaskPaint.setShader(createShader(image)); mMaskPaint.getShader().setLocalMatrix(mShaderMatrix); drawShadow(canvas, mImageBounds); // as needed canvas.drawBitmap(previousImage, m, mPaint); canvas.clipRect(mImageBounds); canvas.translate(x, y); canvas.scale(maskScale, maskScale); canvas.drawBitmap(sMask, 0, 0, mMaskPaint); needsToDrawImage = false; } } else if (master.getCurrentLookAnimation() == MasterImage.ROTATE_ANIMATION) { Rect d1 = computeImageBounds(master.getPreviousImage().getHeight(), master.getPreviousImage().getWidth()); Rect d2 = computeImageBounds(master.getPreviousImage().getWidth(), master.getPreviousImage().getHeight()); float finalScale = d1.width() / (float) d2.height(); finalScale = (1.0f * (1.0f - master.getAnimFraction())) + (finalScale * master.getAnimFraction()); canvas.rotate(master.getAnimRotationValue(), centerX, centerY); canvas.scale(finalScale, finalScale, centerX, centerY); } else if (master.getCurrentLookAnimation() == MasterImage.MIRROR_ANIMATION) { if (master.getCurrentFilterRepresentation() instanceof FilterMirrorRepresentation) { FilterMirrorRepresentation rep = (FilterMirrorRepresentation) master .getCurrentFilterRepresentation(); ImagePreset preset = master.getPreset(); ArrayList<FilterRepresentation> geometry = (ArrayList<FilterRepresentation>) preset .getGeometryFilters(); GeometryMathUtils.GeometryHolder holder = null; holder = GeometryMathUtils.unpackGeometry(geometry); if (holder.rotation.value() == 90 || holder.rotation.value() == 270) { if (rep.isHorizontal() && !rep.isVertical()) { canvas.scale(1, master.getAnimRotationValue(), centerX, centerY); } else if (rep.isVertical() && !rep.isHorizontal()) { canvas.scale(1, master.getAnimRotationValue(), centerX, centerY); } else if (rep.isHorizontal() && rep.isVertical()) { canvas.scale(master.getAnimRotationValue(), 1, centerX, centerY); } else { canvas.scale(master.getAnimRotationValue(), 1, centerX, centerY); } } else { if (rep.isHorizontal() && !rep.isVertical()) { canvas.scale(master.getAnimRotationValue(), 1, centerX, centerY); } else if (rep.isVertical() && !rep.isHorizontal()) { canvas.scale(master.getAnimRotationValue(), 1, centerX, centerY); } else if (rep.isHorizontal() && rep.isVertical()) { canvas.scale(1, master.getAnimRotationValue(), centerX, centerY); } else { canvas.scale(1, master.getAnimRotationValue(), centerX, centerY); } } } } if (needsToDrawImage) { drawShadow(canvas, previousBounds); // as needed canvas.drawBitmap(previousImage, mp, mPaint); } canvas.restore(); } else { drawShadow(canvas, mImageBounds); // as needed canvas.drawBitmap(image, m, mPaint); } canvas.restore(); }
From source file:org.telegram.ui.ArticleViewer.java
public void setParentActivity(Activity activity) { if (parentActivity == activity) { return;/*from ww w. j a va 2s .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:com.android.gallery3d.filtershow.imageshow.ImageShow.java
public void drawImageAndAnimate(Canvas canvas, Bitmap image) { if (image == null) { return;/*from ww w .j av a 2 s .co m*/ } MasterImage master = MasterImage.getImage(); Matrix m = master.computeImageToScreen(image, 0, false); if (m == null) { return; } canvas.save(); RectF d = new RectF(0, 0, image.getWidth(), image.getHeight()); m.mapRect(d); d.roundOut(mImageBounds); boolean showAnimatedImage = master.onGoingNewLookAnimation(); if (!showAnimatedImage && mDidStartAnimation) { // animation ended, but do we have the correct image to show? if (master.getPreset().equals(master.getCurrentPreset())) { // we do, let's stop showing the animated image mDidStartAnimation = false; MasterImage.getImage().resetAnimBitmap(); } else { showAnimatedImage = true; } } else if (showAnimatedImage) { mDidStartAnimation = true; } if (showAnimatedImage) { canvas.save(); // Animation uses the image before the change Bitmap previousImage = master.getPreviousImage(); Matrix mp = master.computeImageToScreen(previousImage, 0, false); RectF dp = new RectF(0, 0, previousImage.getWidth(), previousImage.getHeight()); mp.mapRect(dp); Rect previousBounds = new Rect(); dp.roundOut(previousBounds); float centerX = dp.centerX(); float centerY = dp.centerY(); boolean needsToDrawImage = true; if (master.getCurrentLookAnimation() == MasterImage.CIRCLE_ANIMATION) { float maskScale = MasterImage.getImage().getMaskScale(); if (maskScale >= 0.0f) { float maskW = sMask.getWidth() / 2.0f; float maskH = sMask.getHeight() / 2.0f; Point point = mActivity.hintTouchPoint(this); float maxMaskScale = 2 * Math.max(getWidth(), getHeight()) / Math.min(maskW, maskH); maskScale = maskScale * maxMaskScale; float x = point.x - maskW * maskScale; float y = point.y - maskH * maskScale; // Prepare the shader mShaderMatrix.reset(); mShaderMatrix.setScale(1.0f / maskScale, 1.0f / maskScale); mShaderMatrix.preTranslate(-x + mImageBounds.left, -y + mImageBounds.top); float scaleImageX = mImageBounds.width() / (float) image.getWidth(); float scaleImageY = mImageBounds.height() / (float) image.getHeight(); mShaderMatrix.preScale(scaleImageX, scaleImageY); mMaskPaint.reset(); Shader maskShader = createShader(image); maskShader.setLocalMatrix(mShaderMatrix); mMaskPaint.setShader(maskShader); drawShadow(canvas, mImageBounds); // as needed canvas.drawBitmap(previousImage, m, mPaint); canvas.clipRect(mImageBounds); canvas.translate(x, y); canvas.scale(maskScale, maskScale); canvas.drawBitmap(sMask, 0, 0, mMaskPaint); needsToDrawImage = false; } } else if (master.getCurrentLookAnimation() == MasterImage.ROTATE_ANIMATION) { Rect d1 = computeImageBounds(master.getPreviousImage().getHeight(), master.getPreviousImage().getWidth()); Rect d2 = computeImageBounds(master.getPreviousImage().getWidth(), master.getPreviousImage().getHeight()); float finalScale = d1.width() / (float) d2.height(); finalScale = (1.0f * (1.0f - master.getAnimFraction())) + (finalScale * master.getAnimFraction()); canvas.rotate(master.getAnimRotationValue(), centerX, centerY); canvas.scale(finalScale, finalScale, centerX, centerY); } else if (master.getCurrentLookAnimation() == MasterImage.MIRROR_ANIMATION) { if (master.getCurrentFilterRepresentation() instanceof FilterMirrorRepresentation) { FilterMirrorRepresentation rep = (FilterMirrorRepresentation) master .getCurrentFilterRepresentation(); ImagePreset preset = master.getPreset(); ArrayList<FilterRepresentation> geometry = (ArrayList<FilterRepresentation>) preset .getGeometryFilters(); GeometryMathUtils.GeometryHolder holder = null; holder = GeometryMathUtils.unpackGeometry(geometry); if (holder.rotation.value() == 90 || holder.rotation.value() == 270) { if (rep.isHorizontal() && !rep.isVertical()) { canvas.scale(1, master.getAnimRotationValue(), centerX, centerY); } else if (rep.isVertical() && !rep.isHorizontal()) { canvas.scale(1, master.getAnimRotationValue(), centerX, centerY); } else if (rep.isHorizontal() && rep.isVertical()) { canvas.scale(master.getAnimRotationValue(), 1, centerX, centerY); } else { canvas.scale(master.getAnimRotationValue(), 1, centerX, centerY); } } else { if (rep.isHorizontal() && !rep.isVertical()) { canvas.scale(master.getAnimRotationValue(), 1, centerX, centerY); } else if (rep.isVertical() && !rep.isHorizontal()) { canvas.scale(master.getAnimRotationValue(), 1, centerX, centerY); } else if (rep.isHorizontal() && rep.isVertical()) { canvas.scale(1, master.getAnimRotationValue(), centerX, centerY); } else { canvas.scale(1, master.getAnimRotationValue(), centerX, centerY); } } } } if (needsToDrawImage) { drawShadow(canvas, previousBounds); // as needed canvas.drawBitmap(previousImage, mp, mPaint); } canvas.restore(); } else { drawShadow(canvas, mImageBounds); // as needed canvas.drawBitmap(image, m, mPaint); } canvas.restore(); }
From source file:devlight.io.library.ArcProgressStackView.java
@Override protected void onDraw(final Canvas canvas) { super.onDraw(canvas); // Save and rotate to start angle canvas.save();//w w w . j ava2s .c o m final float radius = mSize * 0.5F; canvas.rotate(mStartAngle, radius, radius); // Draw all of progress for (int i = 0; i < mModels.size(); i++) { final Model model = mModels.get(i); // Get progress for current model float progressFraction = mIsAnimated && !isInEditMode() ? (model.mLastProgress + (mAnimatedFraction * (model.getProgress() - model.mLastProgress))) / MAX_PROGRESS : model.getProgress() / MAX_PROGRESS; if (i != mActionMoveModelIndex && mActionMoveModelIndex != ANIMATE_ALL_INDEX) progressFraction = model.getProgress() / MAX_PROGRESS; final float progress = progressFraction * mSweepAngle; // Check if model have gradient final boolean isGradient = model.getColors() != null; // Set width of progress mProgressPaint.setStrokeWidth(mProgressModelSize); // Set model arc progress model.mPath.reset(); model.mPath.addArc(model.mBounds, 0.0F, progress); // Draw gradient progress or solid resetShadowLayer(); mProgressPaint.setShader(null); mProgressPaint.setStyle(Paint.Style.STROKE); if (mIsModelBgEnabled) { //noinspection ResourceAsColor mProgressPaint.setColor(isInEditMode() ? mPreviewModelBgColor : model.getBgColor()); canvas.drawArc(model.mBounds, 0.0F, mSweepAngle, false, mProgressPaint); if (!isInEditMode()) mProgressPaint.clearShadowLayer(); } // Check if gradient for draw shadow at first and then gradient progress if (isGradient) { if (!mIsModelBgEnabled) { canvas.drawPath(model.mPath, mProgressPaint); if (!isInEditMode()) mProgressPaint.clearShadowLayer(); } mProgressPaint.setShader(model.mSweepGradient); } else mProgressPaint.setColor(model.getColor()); // Here we draw main progress mProgressPaint.setAlpha(255); canvas.drawPath(model.mPath, mProgressPaint); // Preview mode if (isInEditMode()) continue; // Get model title bounds mTextPaint.setTextSize(mProgressModelSize * 0.5F); mTextPaint.getTextBounds(model.getTitle(), 0, model.getTitle().length(), model.mTextBounds); // Draw title at start with offset final float titleHorizontalOffset = model.mTextBounds.height() * 0.5F; final float progressLength = (float) (Math.PI / 180.0F) * progress * model.mBounds.width() * 0.5F; final String title = (String) TextUtils.ellipsize(model.getTitle(), mTextPaint, progressLength - titleHorizontalOffset * 2, TextUtils.TruncateAt.END); canvas.drawTextOnPath(title, model.mPath, mIsRounded ? 0.0F : titleHorizontalOffset, titleHorizontalOffset, mTextPaint); // Get pos and tan at final path point model.mPathMeasure.setPath(model.mPath, false); model.mPathMeasure.getPosTan(model.mPathMeasure.getLength(), model.mPos, model.mTan); // Get title width final float titleWidth = model.mTextBounds.width(); // Create model progress like : 23% final String percentProgress = String.format("%d%%", (int) model.getProgress()); // Get progress text bounds mTextPaint.setTextSize(mProgressModelSize * 0.35f); mTextPaint.getTextBounds(percentProgress, 0, percentProgress.length(), model.mTextBounds); // Get pos tan with end point offset and check whether the rounded corners for offset final float progressHorizontalOffset = mIndicatorOrientation == IndicatorOrientation.VERTICAL ? model.mTextBounds.height() * 0.5F : model.mTextBounds.width() * 0.5F; final float indicatorProgressOffset = (mIsRounded ? progressFraction : 1.0F) * (-progressHorizontalOffset - titleHorizontalOffset - (mIsRounded ? model.mTextBounds.height() * 2.0F : 0.0F)); model.mPathMeasure.getPosTan(model.mPathMeasure.getLength() + indicatorProgressOffset, model.mPos, mIndicatorOrientation == IndicatorOrientation.VERTICAL && !mIsRounded ? new float[2] : model.mTan); // Check if there available place for indicator if ((titleWidth + model.mTextBounds.height() + titleHorizontalOffset * 2.0F) - indicatorProgressOffset < progressLength) { // Get rotate indicator progress angle for progress value float indicatorProgressAngle = (float) (Math.atan2(model.mTan[1], model.mTan[0]) * (180.0F / Math.PI)); // Get arc angle of progress indicator final float indicatorLengthProgressAngle = ((progressLength + indicatorProgressOffset) / (model.mBounds.width() * 0.5F)) * (float) (180.0F / Math.PI); // Detect progress indicator position : left or right and then rotate if (mIndicatorOrientation == IndicatorOrientation.VERTICAL) { // Get X point of arc angle progress indicator final float x = (float) (model.mBounds.width() * 0.5F * (Math.cos((indicatorLengthProgressAngle + mStartAngle) * Math.PI / 180.0F))) + model.mBounds.centerX(); indicatorProgressAngle += (x > radius) ? -90.0F : 90.0F; } else { // Get Y point of arc angle progress indicator final float y = (float) (model.mBounds.height() * 0.5F * (Math.sin((indicatorLengthProgressAngle + mStartAngle) * Math.PI / 180.0F))) + model.mBounds.centerY(); indicatorProgressAngle += (y > radius) ? 180.0F : 0.0F; } // Draw progress value canvas.save(); canvas.rotate(indicatorProgressAngle, model.mPos[0], model.mPos[1]); canvas.drawText(percentProgress, model.mPos[0] - model.mTextBounds.exactCenterX(), model.mPos[1] - model.mTextBounds.exactCenterY(), mTextPaint); canvas.restore(); } // Check if gradient and have rounded corners, because we must to create elevation effect // for start progress corner if ((isGradient || mIsLeveled) && mIsRounded && progress != 0) { model.mPathMeasure.getPosTan(0.0F, model.mPos, model.mTan); // Set paint for overlay rounded gradient with shadow setLevelShadowLayer(); //noinspection ResourceAsColor mLevelPaint.setColor(isGradient ? model.getColors()[0] : model.getColor()); // Get bounds of start pump final float halfSize = mProgressModelSize * 0.5F; final RectF arcRect = new RectF(model.mPos[0] - halfSize, model.mPos[1] - halfSize, model.mPos[0] + halfSize, model.mPos[1] + halfSize + 2.0F); canvas.drawArc(arcRect, 0.0F, -180.0F, true, mLevelPaint); } } // Restore after drawing canvas.restore(); }
From source file:org.telegram.ui.PassportActivity.java
private void createAddressInterface(Context context) { languageMap = new HashMap<>(); try {//from w w w . ja v a2 s.c o 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); }
From source file:org.telegram.ui.PassportActivity.java
private void createIdentityInterface(final Context context) { languageMap = new HashMap<>(); try {//from w w w . j a v a 2 s . com 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) { headerCell = new HeaderCell(context); if (documentOnly) { headerCell.setText(LocaleController.getString("PassportDocuments", R.string.PassportDocuments)); } else { headerCell.setText(LocaleController.getString("PassportRequiredDocuments", R.string.PassportRequiredDocuments)); } headerCell.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); linearLayout2.addView(headerCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); frontLayout = new LinearLayout(context); frontLayout.setOrientation(LinearLayout.VERTICAL); linearLayout2.addView(frontLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); uploadFrontCell = new TextDetailSettingsCell(context); uploadFrontCell.setBackgroundDrawable(Theme.getSelectorDrawable(true)); linearLayout2.addView(uploadFrontCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); uploadFrontCell.setOnClickListener(v -> { uploadingFileType = UPLOADING_TYPE_FRONT; openAttachMenu(); }); reverseLayout = new LinearLayout(context); reverseLayout.setOrientation(LinearLayout.VERTICAL); linearLayout2.addView(reverseLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); boolean divider = currentDocumentsType.selfie_required; uploadReverseCell = new TextDetailSettingsCell(context); uploadReverseCell.setBackgroundDrawable(Theme.getSelectorDrawable(true)); uploadReverseCell.setTextAndValue( LocaleController.getString("PassportReverseSide", R.string.PassportReverseSide), LocaleController.getString("PassportReverseSideInfo", R.string.PassportReverseSideInfo), divider); linearLayout2.addView(uploadReverseCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); uploadReverseCell.setOnClickListener(v -> { uploadingFileType = UPLOADING_TYPE_REVERSE; openAttachMenu(); }); if (currentDocumentsType.selfie_required) { selfieLayout = new LinearLayout(context); selfieLayout.setOrientation(LinearLayout.VERTICAL); linearLayout2.addView(selfieLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); uploadSelfieCell = new TextDetailSettingsCell(context); uploadSelfieCell.setBackgroundDrawable(Theme.getSelectorDrawable(true)); uploadSelfieCell.setTextAndValue( LocaleController.getString("PassportSelfie", R.string.PassportSelfie), LocaleController.getString("PassportSelfieInfo", R.string.PassportSelfieInfo), currentType.translation_required); linearLayout2.addView(uploadSelfieCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); uploadSelfieCell.setOnClickListener(v -> { uploadingFileType = UPLOADING_TYPE_SELFIE; openAttachMenu(); }); } bottomCell = new TextInfoPrivacyCell(context); bottomCell.setBackgroundDrawable( Theme.getThemedDrawable(context, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow)); bottomCell.setText( LocaleController.getString("PassportPersonalUploadInfo", R.string.PassportPersonalUploadInfo)); 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_secureValueTypePassport) { noAllTranslationErrorText = LocaleController.getString("PassportAddPassportInfo", R.string.PassportAddPassportInfo); } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeInternalPassport) { noAllTranslationErrorText = LocaleController.getString("PassportAddInternalPassportInfo", R.string.PassportAddInternalPassportInfo); } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeIdentityCard) { noAllTranslationErrorText = LocaleController.getString("PassportAddIdentityCardInfo", R.string.PassportAddIdentityCardInfo); } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeDriverLicense) { noAllTranslationErrorText = LocaleController.getString("PassportAddDriverLicenceInfo", R.string.PassportAddDriverLicenceInfo); } else { noAllTranslationErrorText = ""; } } CharSequence 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 if (Build.VERSION.SDK_INT >= 18) { scanDocumentCell = new TextSettingsCell(context); scanDocumentCell.setBackgroundDrawable(Theme.getSelectorDrawable(true)); scanDocumentCell.setText( LocaleController.getString("PassportScanPassport", R.string.PassportScanPassport), false); linearLayout2.addView(scanDocumentCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); scanDocumentCell.setOnClickListener(v -> { if (Build.VERSION.SDK_INT >= 23 && getParentActivity() .checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { getParentActivity().requestPermissions(new String[] { Manifest.permission.CAMERA }, 22); return; } MrzCameraActivity fragment = new MrzCameraActivity(); fragment.setDelegate(result -> { if (!TextUtils.isEmpty(result.firstName)) { inputFields[FIELD_NAME].setText(result.firstName); } if (!TextUtils.isEmpty(result.middleName)) { inputFields[FIELD_MIDNAME].setText(result.middleName); } if (!TextUtils.isEmpty(result.lastName)) { inputFields[FIELD_SURNAME].setText(result.lastName); } if (result.gender != MrzRecognizer.Result.GENDER_UNKNOWN) { switch (result.gender) { case MrzRecognizer.Result.GENDER_MALE: currentGender = "male"; inputFields[FIELD_GENDER] .setText(LocaleController.getString("PassportMale", R.string.PassportMale)); break; case MrzRecognizer.Result.GENDER_FEMALE: currentGender = "female"; inputFields[FIELD_GENDER] .setText(LocaleController.getString("PassportFemale", R.string.PassportFemale)); break; } } if (!TextUtils.isEmpty(result.nationality)) { currentCitizeship = result.nationality; String country = languageMap.get(currentCitizeship); if (country != null) { inputFields[FIELD_CITIZENSHIP].setText(country); } } if (!TextUtils.isEmpty(result.issuingCountry)) { currentResidence = result.issuingCountry; String country = languageMap.get(currentResidence); if (country != null) { inputFields[FIELD_RESIDENCE].setText(country); } } if (result.birthDay > 0 && result.birthMonth > 0 && result.birthYear > 0) { inputFields[FIELD_BIRTHDAY].setText(String.format(Locale.US, "%02d.%02d.%d", result.birthDay, result.birthMonth, result.birthYear)); } }); presentFragment(fragment); }); bottomCell = new TextInfoPrivacyCell(context); bottomCell.setBackgroundDrawable( Theme.getThemedDrawable(context, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow)); bottomCell.setText( LocaleController.getString("PassportScanPassportInfo", R.string.PassportScanPassportInfo)); linearLayout2.addView(bottomCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); } headerCell = new HeaderCell(context); if (documentOnly) { headerCell.setText(LocaleController.getString("PassportDocument", R.string.PassportDocument)); } else { headerCell.setText(LocaleController.getString("PassportPersonal", R.string.PassportPersonal)); } headerCell.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); linearLayout2.addView(headerCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); int count = currentDocumentsType != null ? FIELD_IDENTITY_COUNT : FIELD_IDENTITY_NODOC_COUNT; inputFields = new EditTextBoldCursor[count]; for (int a = 0; a < count; a++) { final EditTextBoldCursor field = new EditTextBoldCursor(context); inputFields[a] = field; ViewGroup container = new FrameLayout(context) { private StaticLayout errorLayout; private 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, 64)); container.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); if (a == 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 && a < FIELD_CARDNUMBER) { 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].setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText)); inputFields[a].setHeaderHintColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueHeader)); inputFields[a].setTransformHintToHeader(true); 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_CITIZENSHIP || a == FIELD_RESIDENCE) { 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) -> { int field12 = (Integer) v.getTag(); final EditTextBoldCursor editText = inputFields[field12]; if (field12 == FIELD_CITIZENSHIP) { currentCitizeship = shortName; } else { currentResidence = shortName; } editText.setText(name); }); presentFragment(fragment); } return true; }); inputFields[a].setInputType(0); } else if (a == FIELD_BIRTHDAY || a == FIELD_EXPIRE) { inputFields[a].setOnTouchListener((v, event) -> { if (getParentActivity() == null) { return false; } if (event.getAction() == MotionEvent.ACTION_UP) { Calendar calendar = Calendar.getInstance(); int year = calendar.get(Calendar.YEAR); int monthOfYear = calendar.get(Calendar.MONTH); int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH); try { final EditTextBoldCursor field1 = (EditTextBoldCursor) v; int num = (Integer) field1.getTag(); int minYear; int maxYear; int currentYearDiff; String title; if (num == FIELD_EXPIRE) { title = LocaleController.getString("PassportSelectExpiredDate", R.string.PassportSelectExpiredDate); minYear = 0; maxYear = 20; currentYearDiff = 0; } else { title = LocaleController.getString("PassportSelectBithdayDate", R.string.PassportSelectBithdayDate); minYear = -120; maxYear = 0; currentYearDiff = -18; } int selectedDay = -1; int selectedMonth = -1; int selectedYear = -1; String args[] = field1.getText().toString().split("\\."); if (args.length == 3) { selectedDay = Utilities.parseInt(args[0]); selectedMonth = Utilities.parseInt(args[1]); selectedYear = Utilities.parseInt(args[2]); } AlertDialog.Builder builder = AlertsCreator.createDatePickerDialog(context, minYear, maxYear, currentYearDiff, selectedDay, selectedMonth, selectedYear, title, num == FIELD_EXPIRE, (year1, month, dayOfMonth1) -> { if (num == FIELD_EXPIRE) { currentExpireDate[0] = year1; currentExpireDate[1] = month + 1; currentExpireDate[2] = dayOfMonth1; } field1.setText(String.format(Locale.US, "%02d.%02d.%d", dayOfMonth1, month + 1, year1)); }); if (num == FIELD_EXPIRE) { builder.setNegativeButton(LocaleController.getString("PassportSelectNotExpire", R.string.PassportSelectNotExpire), (dialog, which) -> { currentExpireDate[0] = currentExpireDate[1] = currentExpireDate[2] = 0; field1.setText(LocaleController.getString("PassportNoExpireDate", R.string.PassportNoExpireDate)); }); } showDialog(builder.create()); } catch (Exception e) { FileLog.e(e); } } return true; }); inputFields[a].setInputType(0); inputFields[a].setFocusable(false); } else if (a == FIELD_GENDER) { inputFields[a].setOnTouchListener((v, event) -> { if (getParentActivity() == null) { return false; } if (event.getAction() == MotionEvent.ACTION_UP) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle( LocaleController.getString("PassportSelectGender", R.string.PassportSelectGender)); builder.setItems( new CharSequence[] { LocaleController.getString("PassportMale", R.string.PassportMale), LocaleController.getString("PassportFemale", R.string.PassportFemale) }, (dialogInterface, i) -> { if (i == 0) { currentGender = "male"; inputFields[FIELD_GENDER].setText( LocaleController.getString("PassportMale", R.string.PassportMale)); } else if (i == 1) { currentGender = "female"; inputFields[FIELD_GENDER].setText(LocaleController .getString("PassportFemale", R.string.PassportFemale)); } }); builder.setPositiveButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } 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; HashMap<String, String> values; switch (a) { case FIELD_NAME: if (currentType.native_names) { inputFields[a].setHintText( LocaleController.getString("PassportNameLatin", R.string.PassportNameLatin)); } else { inputFields[a].setHintText(LocaleController.getString("PassportName", R.string.PassportName)); } key = "first_name"; values = currentValues; break; case FIELD_MIDNAME: if (currentType.native_names) { inputFields[a].setHintText( LocaleController.getString("PassportMidnameLatin", R.string.PassportMidnameLatin)); } else { inputFields[a] .setHintText(LocaleController.getString("PassportMidname", R.string.PassportMidname)); } key = "middle_name"; values = currentValues; break; case FIELD_SURNAME: if (currentType.native_names) { inputFields[a].setHintText( LocaleController.getString("PassportSurnameLatin", R.string.PassportSurnameLatin)); } else { inputFields[a] .setHintText(LocaleController.getString("PassportSurname", R.string.PassportSurname)); } key = "last_name"; values = currentValues; break; case FIELD_BIRTHDAY: inputFields[a] .setHintText(LocaleController.getString("PassportBirthdate", R.string.PassportBirthdate)); key = "birth_date"; values = currentValues; break; case FIELD_GENDER: inputFields[a].setHintText(LocaleController.getString("PassportGender", R.string.PassportGender)); key = "gender"; values = currentValues; break; case FIELD_CITIZENSHIP: inputFields[a].setHintText( LocaleController.getString("PassportCitizenship", R.string.PassportCitizenship)); key = "country_code"; values = currentValues; break; case FIELD_RESIDENCE: inputFields[a] .setHintText(LocaleController.getString("PassportResidence", R.string.PassportResidence)); key = "residence_country_code"; values = currentValues; break; case FIELD_CARDNUMBER: inputFields[a].setHintText( LocaleController.getString("PassportDocumentNumber", R.string.PassportDocumentNumber)); key = "document_no"; values = currentDocumentValues; break; case FIELD_EXPIRE: inputFields[a].setHintText(LocaleController.getString("PassportExpired", R.string.PassportExpired)); key = "expiry_date"; values = currentDocumentValues; break; default: continue; } setFieldValues(values, inputFields[a], key); inputFields[a].setSelection(inputFields[a].length()); if (a == FIELD_NAME || a == FIELD_SURNAME || a == FIELD_MIDNAME) { 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; } int num = (Integer) field.getTag(); boolean error = false; for (int a = 0; a < s.length(); a++) { char ch = s.charAt(a); if (!(ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch == ' ' || ch == '\'' || ch == ',' || ch == '.' || ch == '&' || ch == '-' || ch == '/')) { error = true; break; } } if (error && !allowNonLatinName) { field.setErrorText(LocaleController.getString("PassportUseLatinOnly", R.string.PassportUseLatinOnly)); } else { nonLatinNames[num] = error; checkFieldForError(field, key, s, false); } } }); } 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, values == currentDocumentValues); int field12 = (Integer) field.getTag(); final EditTextBoldCursor editText = inputFields[field12]; if (field12 == FIELD_RESIDENCE) { checkNativeFields(true); } } }); } 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, LayoutHelper.MATCH_PARENT, 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; }); } sectionCell2 = new ShadowSectionCell(context); linearLayout2.addView(sectionCell2, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); headerCell = new HeaderCell(context); headerCell.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); linearLayout2.addView(headerCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); inputExtraFields = new EditTextBoldCursor[FIELD_NATIVE_COUNT]; for (int a = 0; a < FIELD_NATIVE_COUNT; a++) { final EditTextBoldCursor field = new EditTextBoldCursor(context); inputExtraFields[a] = field; ViewGroup container = new FrameLayout(context) { private StaticLayout errorLayout; private 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, 64)); container.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); if (a == FIELD_NATIVE_COUNT - 1) { extraBackgroundView2 = new View(context); extraBackgroundView2.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); linearLayout2.addView(extraBackgroundView2, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 6)); } inputExtraFields[a].setTag(a); inputExtraFields[a].setSupportRtlHint(true); inputExtraFields[a].setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); inputExtraFields[a].setHintColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText)); inputExtraFields[a].setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText)); inputExtraFields[a].setHeaderHintColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueHeader)); inputExtraFields[a].setTransformHintToHeader(true); inputExtraFields[a].setBackgroundDrawable(null); inputExtraFields[a].setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText)); inputExtraFields[a].setCursorSize(AndroidUtilities.dp(20)); inputExtraFields[a].setCursorWidth(1.5f); inputExtraFields[a].setLineColors(Theme.getColor(Theme.key_windowBackgroundWhiteInputField), Theme.getColor(Theme.key_windowBackgroundWhiteInputFieldActivated), Theme.getColor(Theme.key_windowBackgroundWhiteRedText3)); inputExtraFields[a].setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES); inputExtraFields[a].setImeOptions(EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NO_EXTRACT_UI); String value; final String key; HashMap<String, String> values; switch (a) { case FIELD_NATIVE_NAME: key = "first_name_native"; values = currentValues; break; case FIELD_NATIVE_MIDNAME: key = "middle_name_native"; values = currentValues; break; case FIELD_NATIVE_SURNAME: key = "last_name_native"; values = currentValues; break; default: continue; } setFieldValues(values, inputExtraFields[a], key); inputExtraFields[a].setSelection(inputExtraFields[a].length()); if (a == FIELD_NATIVE_NAME || a == FIELD_NATIVE_SURNAME || a == FIELD_NATIVE_MIDNAME) { inputExtraFields[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; } checkFieldForError(field, key, s, false); } }); } inputExtraFields[a].setPadding(0, 0, 0, 0); inputExtraFields[a] .setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL); container.addView(inputExtraFields[a], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 21, 0, 21, 0)); inputExtraFields[a].setOnEditorActionListener((textView, i, keyEvent) -> { if (i == EditorInfo.IME_ACTION_NEXT) { int num = (Integer) textView.getTag(); num++; if (num < inputExtraFields.length) { if (inputExtraFields[num].isFocusable()) { inputExtraFields[num].requestFocus(); } else { inputExtraFields[num] .dispatchTouchEvent(MotionEvent.obtain(0, 0, MotionEvent.ACTION_UP, 0, 0, 0)); textView.clearFocus(); AndroidUtilities.hideKeyboard(textView); } } return true; } return false; }); } nativeInfoCell = new TextInfoPrivacyCell(context); linearLayout2.addView(nativeInfoCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); if ((currentBotId != 0 || currentDocumentsType == null) && currentTypeValue != null && !documentOnly || currentDocumentsTypeValue != null) { if (currentDocumentsTypeValue != null) { addDocumentViews(currentDocumentsTypeValue.files); if (currentDocumentsTypeValue.front_side instanceof TLRPC.TL_secureFile) { addDocumentViewInternal((TLRPC.TL_secureFile) currentDocumentsTypeValue.front_side, UPLOADING_TYPE_FRONT); } if (currentDocumentsTypeValue.reverse_side instanceof TLRPC.TL_secureFile) { addDocumentViewInternal((TLRPC.TL_secureFile) currentDocumentsTypeValue.reverse_side, UPLOADING_TYPE_REVERSE); } if (currentDocumentsTypeValue.selfie instanceof TLRPC.TL_secureFile) { addDocumentViewInternal((TLRPC.TL_secureFile) currentDocumentsTypeValue.selfie, UPLOADING_TYPE_SELFIE); } addTranslationDocumentViews(currentDocumentsTypeValue.translation); } 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()); nativeInfoCell.setBackgroundDrawable( Theme.getThemedDrawable(context, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow)); 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 { nativeInfoCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow)); } updateInterfaceStringsForDocumentType(); checkNativeFields(false); }
From source file:net.droidsolutions.droidcharts.core.plot.CategoryPlot.java
/** * Draws the plot on a Java 2D graphics device (such as the screen or a * printer).// w w w.j a v a 2s. c om * <P> * At your option, you may supply an instance of {@link PlotRenderingInfo}. * If you do, it will be populated with information about the drawing, * including various plot dimensions and tooltip info. * * @param g2 * the graphics device. * @param area * the area within which the plot (including axes) should be * drawn. * @param anchor * the anchor point (<code>null</code> permitted). * @param parentState * the state from the parent plot, if there is one. * @param state * collects info as the chart is drawn (possibly * <code>null</code>). */ public void draw(Canvas g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo state) { // if the plot area is too small, just return... boolean b1 = (area.getWidth() <= MINIMUM_WIDTH_TO_DRAW); boolean b2 = (area.getHeight() <= MINIMUM_HEIGHT_TO_DRAW); if (b1 || b2) { return; } // record the plot area... if (state == null) { // if the incoming state is null, no information will be passed // back to the caller - but we create a temporary state to record // the plot area, since that is used later by the axes state = new PlotRenderingInfo(null); } state.setPlotArea(area); // adjust the drawing area for the plot insets (if any)... RectangleInsets insets = getInsets(); insets.trim(area); // calculate the data area... AxisSpace space = calculateAxisSpace(g2, area); Rectangle2D dataArea = space.shrink(area, null); this.axisOffset.trim(dataArea); state.setDataArea(dataArea); createAndAddEntity((Rectangle2D) dataArea.clone(), state, null, null); // if there is a renderer, it draws the background, otherwise use the // default background... if (getRenderer() != null) { getRenderer().drawBackground(g2, this, dataArea); } else { drawBackground(g2, dataArea); } Map axisStateMap = drawAxes(g2, area, dataArea, state); // the anchor point is typically the point where the mouse last // clicked - the crosshairs will be driven off this point... if (anchor != null && !dataArea.contains(anchor)) { anchor = ShapeUtilities.getPointInRectangle(anchor.getX(), anchor.getY(), dataArea); } CategoryCrosshairState crosshairState = new CategoryCrosshairState(); crosshairState.setCrosshairDistance(Double.POSITIVE_INFINITY); crosshairState.setAnchor(anchor); // specify the anchor X and Y coordinates in Java2D space, for the // cases where these are not updated during rendering (i.e. no lock // on data) crosshairState.setAnchorX(Double.NaN); crosshairState.setAnchorY(Double.NaN); if (anchor != null) { ValueAxis rangeAxis = getRangeAxis(); if (rangeAxis != null) { double y; if (getOrientation() == PlotOrientation.VERTICAL) { y = rangeAxis.java2DToValue(anchor.getY(), dataArea, getRangeAxisEdge()); } else { y = rangeAxis.java2DToValue(anchor.getX(), dataArea, getRangeAxisEdge()); } crosshairState.setAnchorY(y); } } crosshairState.setRowKey(getDomainCrosshairRowKey()); crosshairState.setColumnKey(getDomainCrosshairColumnKey()); crosshairState.setCrosshairY(getRangeCrosshairValue()); // don't let anyone draw outside the data area g2.save(); g2.clipRect((float) dataArea.getMinX(), (float) dataArea.getMaxY(), (float) dataArea.getMaxX(), (float) dataArea.getMinY()); drawDomainGridlines(g2, dataArea); AxisState rangeAxisState = (AxisState) axisStateMap.get(getRangeAxis()); if (rangeAxisState == null) { if (parentState != null) { rangeAxisState = (AxisState) parentState.getSharedAxisStates().get(getRangeAxis()); } } if (rangeAxisState != null) { drawRangeGridlines(g2, dataArea, rangeAxisState.getTicks()); drawZeroRangeBaseline(g2, dataArea); } // draw the markers... for (int i = 0; i < this.renderers.size(); i++) { drawDomainMarkers(g2, dataArea, i, Layer.BACKGROUND); } for (int i = 0; i < this.renderers.size(); i++) { drawRangeMarkers(g2, dataArea, i, Layer.BACKGROUND); } // now render data items... boolean foundData = false; // set up the alpha-transparency... // TODO TRANSPARENCY /* * pa Composite originalComposite = g2.getComposite(); * g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, * getForegroundAlpha())); */ DatasetRenderingOrder order = getDatasetRenderingOrder(); if (order == DatasetRenderingOrder.FORWARD) { for (int i = 0; i < this.datasets.size(); i++) { foundData = render(g2, dataArea, i, state, crosshairState) || foundData; } } else { // DatasetRenderingOrder.REVERSE for (int i = this.datasets.size() - 1; i >= 0; i--) { foundData = render(g2, dataArea, i, state, crosshairState) || foundData; } } // draw the foreground markers... for (int i = 0; i < this.renderers.size(); i++) { drawDomainMarkers(g2, dataArea, i, Layer.FOREGROUND); } for (int i = 0; i < this.renderers.size(); i++) { drawRangeMarkers(g2, dataArea, i, Layer.FOREGROUND); } // draw the annotations (if any)... drawAnnotations(g2, dataArea); g2.restore(); if (!foundData) { drawNoDataMessage(g2, dataArea); } int datasetIndex = crosshairState.getDatasetIndex(); setCrosshairDatasetIndex(datasetIndex, false); // draw domain crosshair if required... Comparable rowKey = crosshairState.getRowKey(); Comparable columnKey = crosshairState.getColumnKey(); setDomainCrosshairRowKey(rowKey, false); setDomainCrosshairColumnKey(columnKey, false); if (isDomainCrosshairVisible() && columnKey != null) { Paint paint = getDomainCrosshairPaint(); float stroke = getDomainCrosshairStroke(); drawDomainCrosshair(g2, dataArea, this.orientation, datasetIndex, rowKey, columnKey, stroke, paint); } // draw range crosshair if required... ValueAxis yAxis = getRangeAxisForDataset(datasetIndex); RectangleEdge yAxisEdge = getRangeAxisEdge(); if (!this.rangeCrosshairLockedOnData && anchor != null) { double yy; if (getOrientation() == PlotOrientation.VERTICAL) { yy = yAxis.java2DToValue(anchor.getY(), dataArea, yAxisEdge); } else { yy = yAxis.java2DToValue(anchor.getX(), dataArea, yAxisEdge); } crosshairState.setCrosshairY(yy); } setRangeCrosshairValue(crosshairState.getCrosshairY(), false); if (isRangeCrosshairVisible()) { double y = getRangeCrosshairValue(); Paint paint = getRangeCrosshairPaint(); float stroke = getRangeCrosshairStroke(); drawRangeCrosshair(g2, dataArea, getOrientation(), y, yAxis, stroke, paint); } // draw an outline around the plot area... if (isOutlineVisible()) { if (getRenderer() != null) { getRenderer().drawOutline(g2, this, dataArea); } else { drawOutline(g2, dataArea); } } }