Skip to content

Commit

Permalink
Merge pull request #4 from fundacaocerti/bugfix/set-background-gradient
Browse files Browse the repository at this point in the history
Bugfix/set background gradient
  • Loading branch information
lgr-certi authored Sep 6, 2019
2 parents f36c253 + 6041530 commit 75d652f
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 19 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 32 additions & 8 deletions SeekArc_library/src/com/triggertrap/seekarc/SeekArc.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
Expand Down Expand Up @@ -195,6 +196,7 @@ private void init(Context context, AttributeSet attrs, int defStyle) {
int thumbHalfheight = 0;
int thumbHalfWidth = 0;
mThumb = res.getDrawable(R.drawable.seek_arc_control_selector);
mThumb.mutate().setColorFilter(progressColor, PorterDuff.Mode.MULTIPLY);
// Convert progress width to pixels for current density
mProgressWidth = (int) (mProgressWidth * density);

Expand Down Expand Up @@ -322,14 +324,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);

float centerX = getWidth() / 2;
float centerY = getHeight() / 2;
for (GradientStorage gradientStorage: drawerGradientWaitList) {
int arcStart = mStartAngle + mAngleOffset + mRotation;
gradientStorage.setGradient(centerX, centerY, arcStart, mSweepAngle);
}
drawerGradientWaitList.clear();
executeDrawerGradientWaitList();
}

@Override
Expand Down Expand Up @@ -578,6 +573,7 @@ public int getProgressColor() {
}

public void setProgressColor(int color) {
mArcPaint.setShader(null);
mProgressPaint.setColor(color);
invalidate();
}
Expand All @@ -587,6 +583,7 @@ public int getArcColor() {
}

public void setArcColor(int color) {
mArcPaint.setShader(null);
mArcPaint.setColor(color);
invalidate();
}
Expand All @@ -602,6 +599,20 @@ public void setProgressGradient(int[] colors) {
private void setGradient(Paint paint, int[] colors) {
GradientStorage gradientStorage = new GradientStorage(paint, colors);
drawerGradientWaitList.add(gradientStorage);

if (getWidth() > 0 && getHeight() > 0) {
executeDrawerGradientWaitList();
}
}

private void executeDrawerGradientWaitList() {
float centerX = getWidth() / 2;
float centerY = getHeight() / 2;
for (GradientStorage gradientStorage: drawerGradientWaitList) {
int arcStart = mStartAngle + mAngleOffset + mRotation;
gradientStorage.setGradient(centerX, centerY, arcStart, mSweepAngle);
}
drawerGradientWaitList.clear();
}

public int getMax() {
Expand All @@ -611,4 +622,17 @@ public int getMax() {
public void setMax(int mMax) {
this.mMax = mMax;
}

public Drawable getThumb(){
return mThumb;
}

public void setThumb(Drawable thumb){
this.mThumb = thumb;
}

public void setThumbColor(int color) {
mThumb.mutate().setColorFilter(color, PorterDuff.Mode.MULTIPLY);
invalidate();
}
}
2 changes: 1 addition & 1 deletion SeekArc_sample/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

<activity
android:name="com.triggertrap.sample.ColorActivity"
android:label="@string/title_activity_simple" >
android:label="@string/title_activity_color" >
</activity>

<activity
Expand Down
18 changes: 15 additions & 3 deletions SeekArc_sample/res/layout/controls.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@

<CheckBox
android:id="@+id/clockwise"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true" />
</LinearLayout>
Expand All @@ -161,7 +161,7 @@

<CheckBox
android:id="@+id/touchInside"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true" />
</LinearLayout>
Expand All @@ -179,7 +179,19 @@

<CheckBox
android:id="@+id/enabled"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Change Color:" />

<CheckBox
android:id="@+id/changeColor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true" />
</LinearLayout>
Expand Down
22 changes: 15 additions & 7 deletions SeekArc_sample/res/values/color.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,22 @@
<color name="red">#ffe2231a</color>
<color name="dark_red">#ff510209</color>

<color name="alizarin_crimson">#e02020</color>
<color name="blaze_orange">#fa6400</color>
<color name="selective_yellow">#f7b500</color>
<color name="bright_green">#6dd400</color>
<color name="azure_radiance">#0091ff</color>
<color name="electric_violet">#6236ff</color>
<color name="purple_heart">#b620e0</color>

<array name="arc_gradient_colors">
<item>#e02020</item>
<item>#fa6400</item>
<item>#f7b500</item>
<item>#6dd400</item>
<item>#0091ff</item>
<item>#6236ff</item>
<item>#b620e0</item>
<item>@color/alizarin_crimson</item>
<item>@color/blaze_orange</item>
<item>@color/selective_yellow</item>
<item>@color/bright_green</item>
<item>@color/azure_radiance</item>
<item>@color/electric_violet</item>
<item>@color/purple_heart</item>
</array>

<array name="progress_gradient_colors">
Expand Down
17 changes: 17 additions & 0 deletions SeekArc_sample/src/com/triggertrap/sample/ColorActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package com.triggertrap.sample;

import android.os.Bundle;
import android.widget.CompoundButton;

/**
*
Expand All @@ -30,6 +31,22 @@ protected void onCreate(Bundle savedInstanceState) {

mSeekArc.setArcGradient(getResources().getIntArray(R.array.arc_gradient_colors));
mSeekArc.setProgressGradient(getResources().getIntArray(R.array.progress_gradient_colors));

mEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mSeekArc.setEnabled(isChecked);
mSeekArc.invalidate();

if (mChangeColor.isChecked()) {
if(isChecked) {
mSeekArc.setArcGradient(getResources().getIntArray(R.array.arc_gradient_colors));
} else {
mSeekArc.setArcColor(getResources().getColor(R.color.progress_gray));
}
}
}
});
}

}
14 changes: 14 additions & 0 deletions SeekArc_sample/src/com/triggertrap/sample/SimpleActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class SimpleActivity extends Activity {
public CheckBox mClockwise;
public TextView mSeekArcProgress;
public CheckBox mEnabled;
public CheckBox mChangeColor;

protected int getLayoutFile(){
return R.layout.holo_sample;
Expand All @@ -74,6 +75,7 @@ protected void onCreate(Bundle savedInstanceState) {
mTouchInside = (CheckBox) findViewById(R.id.touchInside);
mClockwise = (CheckBox) findViewById(R.id.clockwise);
mEnabled = (CheckBox) findViewById(R.id.enabled);
mChangeColor = (CheckBox) findViewById(R.id.changeColor);

mRotation.setProgress(mSeekArc.getArcRotation());
mStartAngle.setProgress(mSeekArc.getStartAngle());
Expand All @@ -85,6 +87,13 @@ protected void onCreate(Bundle savedInstanceState) {

@Override
public void onStopTrackingTouch(SeekArc seekArc) {
int thumbColor;
if(seekArc.getProgress() > 50) {
thumbColor = R.color.blaze_orange;
} else {
thumbColor = R.color.azure_radiance;
}
mSeekArc.setThumbColor(getResources().getColor(thumbColor));
}

@Override
Expand Down Expand Up @@ -207,6 +216,11 @@ public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mSeekArc.setEnabled(isChecked);
mSeekArc.invalidate();

if (mChangeColor.isChecked()) {
int color = getResources().getColor(isChecked ? R.color.progress_gray : R.color.dark_red);
mSeekArc.setArcColor(color);
}
}
});

Expand Down

0 comments on commit 75d652f

Please sign in to comment.