Skip to content

Commit

Permalink
Refactoring isBrightColor()
Browse files Browse the repository at this point in the history
  • Loading branch information
adrielcafe committed Aug 15, 2016
1 parent 91abb63 commit 9e61080
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public class AudioRecorderActivity extends AppCompatActivity {
private boolean isRecording;
private String filePath;
private int color;
private boolean isBright; //variable to check brightness
private RelativeLayout contentLayout;
private TextView timerView;
private ImageView micView;
Expand Down Expand Up @@ -68,8 +67,7 @@ protected void onCreate(Bundle savedInstanceState) {
contentLayout.setBackgroundColor(color);

// check to set tint of images
isBright = isBrightColor(color);
if(isBright) {
if(Util.isBrightColor(color)) {
micView.setColorFilter(Color.BLACK);
recordView.setColorFilter(Color.BLACK);
timerView.setTextColor(Color.BLACK);
Expand Down Expand Up @@ -189,26 +187,4 @@ public void run() {
}
});
}

/**
* Function to check brightness of background color
* @param color
* @return
*/
public boolean isBrightColor (int color) {
if(android.R.color.transparent == color) {
return true;
}

int [] rgb = {Color.red(color), Color.green(color), Color.blue(color)};

int brightness = (int) Math.sqrt(rgb[0]*rgb[0]*0.241
+ rgb[1]*rgb[1]*0.691 + rgb[2]*rgb[2]*0.068);

//color is bright
if(brightness >= 200) {
return true;
}
return false;
}
}
18 changes: 18 additions & 0 deletions lib/src/main/java/cafe/adriel/androidaudiorecorder/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,24 @@ public static AudioSource getMic() {
AUDIO_FREQUENCY);
}

/**
* Function to check brightness of background color
* @param color
* @return true if color is bright
*/
public static boolean isBrightColor(int color) {
if(android.R.color.transparent == color) {
return true;
}
int [] rgb = {Color.red(color), Color.green(color), Color.blue(color)};
int brightness = (int) Math.sqrt(
rgb[0] * rgb[0] * 0.241 +
rgb[1] * rgb[1] * 0.691 +
rgb[2] * rgb[2] * 0.068);
//color is bright
return brightness >= 200;
}

public static int getDarkerColor(int color) {
float factor = 0.8f;
int a = Color.alpha(color);
Expand Down

0 comments on commit 9e61080

Please sign in to comment.