From 9e610807c54e137c2ac519b4fe5aa4630b6a8189 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adriel=20Caf=C3=A9?= Date: Mon, 15 Aug 2016 11:32:19 -0300 Subject: [PATCH] Refactoring isBrightColor() --- .../AudioRecorderActivity.java | 26 +------------------ .../adriel/androidaudiorecorder/Util.java | 18 +++++++++++++ 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/lib/src/main/java/cafe/adriel/androidaudiorecorder/AudioRecorderActivity.java b/lib/src/main/java/cafe/adriel/androidaudiorecorder/AudioRecorderActivity.java index e73241f..8aee3c1 100644 --- a/lib/src/main/java/cafe/adriel/androidaudiorecorder/AudioRecorderActivity.java +++ b/lib/src/main/java/cafe/adriel/androidaudiorecorder/AudioRecorderActivity.java @@ -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; @@ -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); @@ -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; - } } diff --git a/lib/src/main/java/cafe/adriel/androidaudiorecorder/Util.java b/lib/src/main/java/cafe/adriel/androidaudiorecorder/Util.java index f4fd0ac..f253832 100644 --- a/lib/src/main/java/cafe/adriel/androidaudiorecorder/Util.java +++ b/lib/src/main/java/cafe/adriel/androidaudiorecorder/Util.java @@ -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);