下面列出了怎么用android.graphics.Color的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* 为 DrawerLayout 布局设置状态栏透明
*
* @param activity 需要设置的activity
* @param drawerLayout DrawerLayout
*/
public static void setTransparentForDrawerLayout(Activity activity, DrawerLayout drawerLayout) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
return;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
} else {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
// 内容布局不是 LinearLayout 时,设置padding top
if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0);
}
// 设置属性
setDrawerLayoutProperty(drawerLayout, contentLayout);
}
@Override
public void onBindContentView() {
if (element != null) {
textView.setText(element.getContent());
if (element.getColor() != null) {
try {
textView.setTextColor(Color.parseColor("#" + element.getColor()));
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
} else if (color != -1) {
textView.setTextColor(color);
}
} else if (!TextUtils.isEmpty(content)) {
textView.setText(content);
}
}
@Override
public void bindDataToItem(int index,
View itemView,
View detailsView,
ImageView imageViewOrAvatar,
ImageButton imageButton,
TextView... txt) {
DummyObject current = (DummyObject) objects[index];
itemView.setBackgroundColor(Color.parseColor("#F3F3F3"));
Picasso.with(getActivity()).load((Integer) current.getAvatar()).into(imageViewOrAvatar);
txt[0].setText(current.getName()); //1st text view's text
txt[1].setText(current.getDescription()); //2nd
imageButton.setImageDrawable(ContextCompat.getDrawable(getActivity(), IMAGE_BUTTON_RESID));
}
private void drawPlot(Canvas canvas, int width) {
float step = 10*(_drawableAreaHeight/((float)FULL_SCALE));
float lineLevel = PADDING_TOP + _drawableAreaHeight;
float left = PADDING_LEFT + _drawableAreaWidth/2 - 60;
float right = PADDING_LEFT + _drawableAreaWidth/2 + 100;
for (int i=0; i< FULL_SCALE/10 + 1; i++) {
paint.setColor(Color.BLACK);
if (i*10 == NOISE_THRESHOLD || i*10 == CLIPPING_THRESHOLD) {
paint.setStrokeWidth(3.0f);
canvas.drawLine(left, lineLevel, right, lineLevel, paint);
paint.setStrokeWidth(0);
} else {
canvas.drawLine(left, lineLevel, right, lineLevel, paint);
}
if (i%2 == 0) {
paint.setTextAlign(Paint.Align.RIGHT);
canvas.drawText(Integer.toString(i*10), left - 10, lineLevel, paint);
} else {
paint.setTextAlign(Paint.Align.LEFT);
canvas.drawText(Integer.toString(i*10), right + 10, lineLevel, paint);
}
lineLevel = lineLevel - step;
}
}
public void prepare()
{
super.prepare();
loadFingers();
highlightColour = Color.RED;
backgroundColour = Color.argb(255,0,243,243);
sharedLock = new ReentrantLock();
sharedCondition = sharedLock.newCondition();
pageNo = 0;
if (parameters.get("page") != null)
pageNo = Integer.parseInt(parameters.get("page"));
doArrowDemo = !OBUtils.coalesce(parameters.get("arrowdemo"),"true").equals("false");
initialised = true;
paragraphs = loadPageXML(getLocalPath("book.xml"));
loadTemplate();
int i = 1;
for (OBReadingPara para : paragraphs)
{
loadTimingsPara(para,getLocalPath(String.format("p%d_%d.etpa",pageNo,i)),false);
loadTimingsPara(para,getLocalPath(String.format("ps%d_%d.etpa",pageNo,i)),true);
i++;
}
//setButtons();
setUpScene();
}
protected void setStatusBarColor(ViewGroup drawerLayout) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
return;
}
if (isFullScreenMode())
return;
TypedArray a = getTheme().obtainStyledAttributes(new int[]{R.attr.colorPrimary});
int color = a.getColor(0, Color.TRANSPARENT);
a.recycle();
if (drawerLayout != null) {
StatusBarUtil.setColorForDrawerLayout(this, drawerLayout, color, 0);
} else {
StatusBarUtil.setColor(this, color, 0);
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case android.R.id.home:
finish();
return true;
case R.id.action_add_snackbar:
SnackbarManager.show(
Snackbar.with(SnackbarRecyclerViewSampleActivity.this)
.text("Woo, snackbar!")
.actionLabel("Close")
.actionColor(Color.parseColor("#FF8A80"))
.duration(Snackbar.SnackbarDuration.LENGTH_LONG)
.attachToRecyclerView(mRecyclerView));
return true;
default:
return super.onOptionsItemSelected(item);
}
}
public BorderCircleView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
if (isClickable()) {
setForeground(ViewUtils.getSelectableBackground(context));
}
mCheck = ContextCompat.getDrawable(context, R.drawable.ic_done);
DrawableCompat.setTint(mCheck, Color.WHITE);
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaint.setColor(ViewUtils.getThemeAccentColor(context));
mPaintBorder = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaintBorder.setColor(ViewUtils.getColorPrimaryColor(context));
mPaintBorder.setStrokeWidth((int) getResources().getDimension(R.dimen.circleview_border));
mPaintBorder.setStyle(Paint.Style.STROKE);
setWillNotDraw(false);
}
private ColorCircle findNearestByColor(int color) {
float[] hsv = new float[3];
Color.colorToHSV(color, hsv);
ColorCircle near = null;
double minDiff = Double.MAX_VALUE;
double x = hsv[1] * Math.cos(hsv[0] * Math.PI / 180);
double y = hsv[1] * Math.sin(hsv[0] * Math.PI / 180);
for (ColorCircle colorCircle : renderer.getColorCircleList()) {
float[] hsv1 = colorCircle.getHsv();
double x1 = hsv1[1] * Math.cos(hsv1[0] * Math.PI / 180);
double y1 = hsv1[1] * Math.sin(hsv1[0] * Math.PI / 180);
double dx = x - x1;
double dy = y - y1;
double dist = dx * dx + dy * dy;
if (dist < minDiff) {
minDiff = dist;
near = colorCircle;
}
}
return near;
}
/**
* <b>private void initializeViews()</b>
* <p>This function is used to initialize required views.</p>
* Created by - Rohit
*/
private void initializeViews() {
btnTryAgain = ((Button) progressLayout.findViewById(R.id.btnTryAgain));
btnTryAgain.setVisibility(View.GONE);
pbLoading = ((ProgressBar) progressLayout.findViewById(R.id.progressBar));
pbLoading.getIndeterminateDrawable().setColorFilter(ContextCompat.getColor(mContext, mProgressBarColor),
android.graphics.PorterDuff.Mode.MULTIPLY);
pbLoading.setVisibility(View.GONE);
tvApiError = ((TextView) progressLayout.findViewById(R.id.tvApiError));
tvApiError.setVisibility(View.GONE);
ivCancel = (ImageView) progressLayout.findViewById(R.id.imgCancel);
ivCancel.setVisibility(View.GONE);
tvEnableNetwork = (TextView) progressLayout.findViewById(R.id.tvEnableNetwork);
tvEnableNetwork.setVisibility(View.GONE);
RelativeLayout rlBaseLayout = (RelativeLayout) progressLayout.findViewById(R.id.rl_base_layout);
if (isTransparent) {
rlBaseLayout.setBackgroundColor(Color.TRANSPARENT);
} else {
rlBaseLayout.setBackgroundColor(Color.WHITE);
}
}
private Bitmap textAsBitmap(String text, float textSize, int textColor, Typeface typeface) {
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setTextSize(textSize);
paint.setColor(textColor);
paint.setAlpha(255);
if (typeface != null) paint.setTypeface(typeface);
paint.setTextAlign(Paint.Align.LEFT);
float baseline = -paint.ascent(); // ascent() is negative
int width = (int) (paint.measureText(text) + 0.5f); // round
int height = (int) (baseline + paint.descent() + 0.5f);
Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(image);
canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
canvas.drawText(text, 0, baseline, paint);
return image;
}
/**
* 初始化android 5.0以上状态栏和导航栏
*
* @param uiFlags the ui flags
* @return the int
*/
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private int initBarAboveLOLLIPOP(int uiFlags) {
uiFlags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; //Activity全屏显示,但状态栏不会被隐藏覆盖,状态栏依然可见,Activity顶端布局部分会被状态栏遮住。
if (mBarParams.fullScreen && mBarParams.navigationBarEnable) {
uiFlags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; //Activity全屏显示,但导航栏不会被隐藏覆盖,导航栏依然可见,Activity底部布局部分会被导航栏遮住。
}
mWindow.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
if (mConfig.hasNavigtionBar()) { //判断是否存在导航栏
mWindow.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
}
mWindow.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); //需要设置这个才能设置状态栏颜色
if (mBarParams.statusBarFlag)
mWindow.setStatusBarColor(ColorUtils.blendARGB(mBarParams.statusBarColor,
mBarParams.statusBarColorTransform, mBarParams.statusBarAlpha)); //设置状态栏颜色
else
mWindow.setStatusBarColor(ColorUtils.blendARGB(mBarParams.statusBarColor,
Color.TRANSPARENT, mBarParams.statusBarAlpha)); //设置状态栏颜色
if (mBarParams.navigationBarEnable)
mWindow.setNavigationBarColor(ColorUtils.blendARGB(mBarParams.navigationBarColor,
mBarParams.navigationBarColorTransform, mBarParams.navigationBarAlpha)); //设置导航栏颜色
return uiFlags;
}
/**
* 初始化绘图变量
*/
private void init() {
this.mHolder = getHolder();
this.mHolder.addCallback(this);
this.mHolder.setFormat(PixelFormat.TRANSPARENT);
setZOrderOnTop(true);
setZOrderMediaOverlay(true);
this.mPaint = new Paint();
this.mPaint.setAntiAlias(true);
this.mPaint.setColor(Color.WHITE);
this.mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
this.mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
this.mPaintLine = new Paint();
this.mPaintLine.setColor(Color.BLUE);
this.mPaintLine.setStrokeWidth(5.0F);
this.mTextPaint = new Paint();
this.mTextPaint.setColor(Color.WHITE);
this.mTextPaint.setStrokeWidth(3.0F);
setKeepScreenOn(true);
}
/**
* Creates a {@link CompositorView}. This can be called only after the native library is
* properly loaded.
* @param c The Context to create this {@link CompositorView} in.
* @param host The renderer host owning this view.
*/
public CompositorView(Context c, LayoutRenderHost host) {
super(c);
mRenderHost = host;
mCompositorSurfaceManager = new CompositorSurfaceManager(this, this);
// Cover the black surface before it has valid content. Set this placeholder view to
// visible, but don't yet make SurfaceView visible, in order to delay
// surfaceCreate/surfaceChanged calls until the native library is loaded.
setBackgroundColor(Color.WHITE);
super.setVisibility(View.VISIBLE);
// Request the opaque surface. We might need the translucent one, but
// we don't know yet. We'll switch back later if we discover that
// we're on a low memory device that always uses translucent.
mCompositorSurfaceManager.requestSurface(PixelFormat.OPAQUE);
}
/**
* Creates a new drawable, which allows to display the number of tabs, which are currently
* contained by a {@link TabSwitcher}.
*
* @param context
* The context, which should be used by the drawable, as an instance of the class {@link
* Context}. The context may not be null
*/
public TabSwitcherDrawable(@NonNull final Context context) {
Condition.INSTANCE.ensureNotNull(context, "The context may not be null");
Resources resources = context.getResources();
size = resources.getDimensionPixelSize(R.dimen.tab_switcher_drawable_size);
textSizeNormal =
resources.getDimensionPixelSize(R.dimen.tab_switcher_drawable_font_size_normal);
textSizeSmall =
resources.getDimensionPixelSize(R.dimen.tab_switcher_drawable_font_size_small);
background = ContextCompat.getDrawable(context, R.drawable.tab_switcher_drawable_background)
.mutate();
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.WHITE);
paint.setTextAlign(Align.CENTER);
paint.setTextSize(textSizeNormal);
paint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
label = Integer.toString(0);
int tint = ThemeUtil.getColor(context, android.R.attr.textColorPrimary);
setColorFilter(tint, PorterDuff.Mode.MULTIPLY);
}
/**
* 画圆点
* @param canvas
*/
public void drawPoints(Canvas canvas, Line line, Axis axisY, int moveX) {
if (line != null && line.isHasPoints() && isShow) {
List<PointValue> values = line.getValues();
float radius = LeafUtil.dp2px(mContext, line.getPointRadius());
float strokeWidth = LeafUtil.dp2px(mContext, 1);
PointValue point;
canvas.save(Canvas.CLIP_SAVE_FLAG);
canvas.clipRect(axisY.getStartX(), 0, mWidth, mHeight);
for (int i = 0, size = values.size(); i < size; i++) {
point = values.get(i);
labelPaint.setStyle(Paint.Style.FILL);
labelPaint.setColor(line.getPointColor());
canvas.drawCircle(point.getOriginX() + moveX, point.getOriginY(),
radius , labelPaint);
labelPaint.setStyle(Paint.Style.STROKE);
labelPaint.setColor(Color.WHITE);
labelPaint.setStrokeWidth(strokeWidth);
canvas.drawCircle(point.getOriginX() + moveX, point.getOriginY(),
radius , labelPaint);
}
canvas.restore();
}
}
private void initialize(Context context, AttributeSet attrs) {
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.RingProgressBar);
// 获取自定义属性值或默认值
progressMax = ta.getInteger(R.styleable.RingProgressBar_progressMax, 100);
dotColor = ta.getColor(R.styleable.RingProgressBar_dotColor, Color.WHITE);
dotBgColor = ta.getColor(R.styleable.RingProgressBar_dotBgColor, Color.GRAY);
showMode = ta.getInt(R.styleable.RingProgressBar_showMode, ProgressBarUtils.RingShowMode.SHOW_MODE_PERCENT);
if (showMode != ProgressBarUtils.RingShowMode.SHOW_MODE_NULL) {
percentTextSize = ta.getDimension(R.styleable.RingProgressBar_percentTextSize, ProgressBarUtils.dp2px(context,30));
percentTextColor = ta.getInt(R.styleable.RingProgressBar_percentTextColor, Color.WHITE);
percentThinPadding = ta.getInt(R.styleable.RingProgressBar_percentThinPadding, 0);
unitText = ta.getString(R.styleable.RingProgressBar_unitText);
unitTextSize = ta.getDimension(R.styleable.RingProgressBar_unitTextSize, percentTextSize);
unitTextColor = ta.getInt(R.styleable.RingProgressBar_unitTextColor, Color.BLACK);
unitTextAlignMode = ta.getInt(R.styleable.RingProgressBar_unitTextAlignMode, UNIT_TEXT_ALIGN_MODE_DEFAULT);
if (unitText == null) {
unitText = "%";
}
}
ta.recycle();
}
public LineChartRenderer(LineDataProvider chart, ChartAnimator animator,
ViewPortHandler viewPortHandler) {
super(animator, viewPortHandler);
mChart = chart;
mCirclePaintInner = new Paint(Paint.ANTI_ALIAS_FLAG);
mCirclePaintInner.setStyle(Paint.Style.FILL);
mCirclePaintInner.setColor(Color.WHITE);
}
@Override
protected void onClick() {
int[] colors = mColors.length != 0 ? mColors : new int[] {
Color.BLACK, Color.WHITE, Color
.RED, Color.GREEN, Color.BLUE
};
ColorPickerDialog d = ColorPickerDialog.newInstance(mTitle,
colors, mCurrentValue, mColumns,
ColorPickerDialog.SIZE_SMALL, mBackwardsOrder,
mStrokeWidth, mStrokeColor);
d.setOnColorSelectedListener(this);
d.show(((Activity) getContext()).getFragmentManager(), null);
}
public static Object addShadow(ViewGroup shadowContainer, boolean roundedCorners) {
initializeResources(shadowContainer.getResources());
if (roundedCorners) {
RoundedRectHelperApi21.setRoundedRectBackground(shadowContainer,
Color.TRANSPARENT);
} else {
shadowContainer.setOutlineProvider(sOutlineProvider);
}
shadowContainer.setZ(sNormalZ);
shadowContainer.setTransitionGroup(true);
return shadowContainer;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = ButterKnife.findById(this, R.id.my_awesome_toolbar);
setSupportActionBar(toolbar);
materialMenu = new MaterialMenuIconToolbar(this, Color.WHITE, MaterialMenuDrawable.Stroke.REGULAR) {
@Override public int getToolbarViewId() {
return R.id.my_awesome_toolbar;
}
};
getSupportFragmentManager().beginTransaction().replace(R.id.container_play_ctrl_bar, PlayCtrlBarFragment.instance())
.commitAllowingStateLoss();
}
@Override
protected void initDrawingTools() {
radarCirclePaint = new Paint();
radarCirclePaint.setAntiAlias(true);
radarCirclePaint.setStyle(Paint.Style.STROKE);
radarCirclePaint.setStrokeWidth(0.05f);
radarCirclePaint.setShader(new LinearGradient(0.40f, 0.0f, 0.60f, 1.0f,
Color.rgb(0xf0, 0xf5, 0xf0), Color.rgb(0x30, 0x31, 0x30),
Shader.TileMode.CLAMP));
radarOvalPaint = new Paint();
radarOvalPaint.setAntiAlias(true);
radarOvalPaint.setStyle(Paint.Style.FILL);
radarOvalPaint.setColor(Color.argb(100, 0, 0, 200));
}
public static Bitmap getPreviewBitmap(float density, String colorStr) {
int color = Color.GRAY;
try {
color = Color.parseColor(colorStr);
} catch (Exception e) {
}
return getPreviewBitmap(density, color);
}
/**
* Makes a new view that combines itemView and swipeLeftView to hold the
* data pointed to by position.
*
* @param context Interface to application's global information
* @param position The position from which to get the data.
* @param parent The View to which the new view is attached to
* @return
*/
private View newView(Context context, int position, ViewGroup parent) {
// get a new itemView and init it.
View itemView = newItemView(context, position, parent);
if (itemView == null)
throw new IllegalStateException("the itemView can't be null!");
// set a tag for the itemMainView which is used in CustomSwipeListView.
itemView.setTag(CustomSwipeListView.ITEMMAIN_LAYOUT_TAG);
// itemLayout indicates the outermost layout of the new view.
RelativeLayout itemLayout = new RelativeLayout(context);
itemLayout.setLayoutParams(new AbsListView.LayoutParams(
itemView.getLayoutParams().width, itemView.getLayoutParams().height));
itemLayout.addView(itemView);
// get a new swipeLeftView and init it.
View swipeLeftView = newSwipeLeftView(context, position, parent);
if (swipeLeftView == null)
return itemLayout;
// set a tag for the swipeLeftView which is used in CustomSwipeListView.
swipeLeftView.setTag(CustomSwipeListView.ITEMSWIPE_LAYOUT_TAG);
swipeLeftView.setVisibility(View.GONE);
// itemSwipeLeftLayout indicates the layout of the swipeLeftView.
RelativeLayout itemSwipeLeftLayout = new RelativeLayout(context);
itemSwipeLeftLayout.setLayoutParams(new AbsListView.LayoutParams(
itemView.getLayoutParams().width, itemView.getLayoutParams().height));
itemSwipeLeftLayout.setHorizontalGravity(Gravity.END);
itemSwipeLeftLayout.setBackgroundColor(Color.TRANSPARENT);
itemSwipeLeftLayout.addView(swipeLeftView);
itemLayout.addView(itemSwipeLeftLayout);
return itemLayout;
}
@Override
public int getAvatarBackgroundColor() {
if (type == Message.TYPE_STATUS && getCounterparts() != null && getCounterparts().size() > 1) {
return Color.TRANSPARENT;
} else {
return UIHelper.getColorForName(UIHelper.getMessageDisplayName(this));
}
}
private void init() {
mCirclePaint = new Paint();
mCirclePaint.setAntiAlias(true);
mCirclePaint.setColor(Color.parseColor("#ffffff"));
mCirclePaint.setAlpha(200);
mMaskPaint = new Paint();
mMaskPaint.setAntiAlias(true);
mMaskPaint.setColor(Color.parseColor("#40000000"));
mBitmapPaint = new Paint();
mBitmapPaint.setAntiAlias(true);
mTextPaint = new Paint();
mTextPaint.setAntiAlias(true);
mTextPaint.setColor(Color.parseColor("#90000000"));
mTextPaint.setTextSize(sp(12));
mTextPaint.setTypeface(Typeface.DEFAULT_BOLD);
rectF = new RectF();
mSelectPaint = new Paint();
mSelectPaint.setAntiAlias(true);
mSelectPaint.setStrokeWidth(dp(4));
mSelectPaint.setStyle(Paint.Style.STROKE);
try {
videoBitmap = ((BitmapDrawable) getResources().getDrawable(R.mipmap.picker_item_video)).getBitmap();
} catch (Exception ignored) {
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pager = (ViewPager) findViewById(R.id.pager);
tabLayout = (TabLayout) findViewById(R.id.tab_layout);
pager.setAdapter(new ExcelPagerAdapter(getSupportFragmentManager()));
tabLayout.setupWithViewPager(pager);
tabLayout.setTabTextColors(Color.WHITE,Color.WHITE);
}
public AppIconView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(Color.parseColor("#212121"));
paint.setDither(true);
animator = ValueAnimator.ofFloat(bgScale, 0.8f);
animator.setInterpolator(new OvershootInterpolator());
animator.setDuration(750);
animator.setStartDelay(250);
animator.addUpdateListener(animator -> {
bgScale = (float) animator.getAnimatedValue();
invalidate();
});
animator.start();
animator = ValueAnimator.ofFloat(rotation, 0);
animator.setInterpolator(new DecelerateInterpolator());
animator.setDuration(1000);
animator.setStartDelay(250);
animator.addUpdateListener(animator -> {
fgScale = animator.getAnimatedFraction() * 0.8f;
rotation = (float) animator.getAnimatedValue();
invalidate();
});
animator.start();
animator = ValueAnimator.ofFloat(bgRotation, 0);
animator.setInterpolator(new DecelerateInterpolator());
animator.setDuration(1250);
animator.setStartDelay(250);
animator.addUpdateListener(animator -> {
bgRotation = (float) animator.getAnimatedValue();
invalidate();
});
animator.start();
}
private void initOtherViews(){
RelativeLayout.LayoutParams captureButtonParams = new RelativeLayout.LayoutParams(3*screenWidth/10, screenHeight/8);
captureButtonParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
captureButtonParams.topMargin = screenHeight / 30;
captureButton.setLayoutParams(captureButtonParams);
captureText.setLayoutParams(captureButtonParams);
captureText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, screenHeight/40);
RelativeLayout.LayoutParams nameEditParams = new RelativeLayout.LayoutParams(3*screenWidth/10, screenHeight/8);
nameEditParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
nameEditParams.addRule(RelativeLayout.BELOW, captureButton.getId());
nameEditParams.topMargin = screenHeight / 30;
nameEdit.setLayoutParams(nameEditParams);
nameEdit.setTextSize(TypedValue.COMPLEX_UNIT_DIP, screenHeight/42);
nameEdit.setTextColor(Color.BLACK);
RelativeLayout.LayoutParams saveButtonParams = new RelativeLayout.LayoutParams(3*screenWidth/10, screenHeight/8);
saveButtonParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
saveButtonParams.addRule(RelativeLayout.BELOW, nameEdit.getId());
saveButtonParams.topMargin = screenHeight / 30;
saveButton.setLayoutParams(saveButtonParams);
saveButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, screenHeight/40);
if(!isTraining){
deleteButtonFirstPos = screenHeight / 8 + screenHeight /15;
deleteButtonSecondPos = 3*screenHeight / 8 + 2*screenHeight /15;
RelativeLayout.LayoutParams deleteButtonParams = new RelativeLayout.LayoutParams(3*screenWidth/10, screenHeight/8);
deleteButtonParams.topMargin = deleteButtonFirstPos;
deleteButtonParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
deleteButton.setLayoutParams(deleteButtonParams);
deleteButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, screenHeight/42);
}
}
private int getColorForGradient(float[] hsv) {
// fixed: 17-1-7 Equality tests should not be made with floating point values.
if ((int) hsv[2] != 1) {
float oldV = hsv[2];
hsv[2] = 1;
int color = Color.HSVToColor(hsv);
hsv[2] = oldV;
return color;
} else {
return Color.HSVToColor(hsv);
}
}