Skip to content

Commit 91abb63

Browse files
authored
Merge pull request adrielcafe#2 from prakh25/TODO---IMAGE-TINT
Tint Images
2 parents 80d75d7 + b376a38 commit 91abb63

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

lib/src/main/java/cafe/adriel/androidaudiorecorder/AudioRecorderActivity.java

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package cafe.adriel.androidaudiorecorder;
22

33
import android.graphics.Color;
4+
import android.graphics.PorterDuff;
45
import android.graphics.drawable.ColorDrawable;
6+
import android.graphics.drawable.Drawable;
57
import android.os.Bundle;
68
import android.support.v7.app.AppCompatActivity;
79
import android.view.Menu;
@@ -30,7 +32,7 @@ public class AudioRecorderActivity extends AppCompatActivity {
3032
private boolean isRecording;
3133
private String filePath;
3234
private int color;
33-
35+
private boolean isBright; //variable to check brightness
3436
private RelativeLayout contentLayout;
3537
private TextView timerView;
3638
private ImageView micView;
@@ -59,7 +61,21 @@ protected void onCreate(Bundle savedInstanceState) {
5961
micView = (ImageView) findViewById(R.id.mic);
6062
recordView = (ImageButton) findViewById(R.id.record);
6163

64+
// to get drawable resources of check icon and clear icon
65+
Drawable clear = getResources().getDrawable(R.drawable.ic_clear);
66+
Drawable check = getResources().getDrawable(R.drawable.ic_check);
67+
6268
contentLayout.setBackgroundColor(color);
69+
70+
// check to set tint of images
71+
isBright = isBrightColor(color);
72+
if(isBright) {
73+
micView.setColorFilter(Color.BLACK);
74+
recordView.setColorFilter(Color.BLACK);
75+
timerView.setTextColor(Color.BLACK);
76+
clear.setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_ATOP);
77+
check.setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_ATOP);
78+
}
6379
}
6480

6581
@Override
@@ -174,4 +190,25 @@ public void run() {
174190
});
175191
}
176192

177-
}
193+
/**
194+
* Function to check brightness of background color
195+
* @param color
196+
* @return
197+
*/
198+
public boolean isBrightColor (int color) {
199+
if(android.R.color.transparent == color) {
200+
return true;
201+
}
202+
203+
int [] rgb = {Color.red(color), Color.green(color), Color.blue(color)};
204+
205+
int brightness = (int) Math.sqrt(rgb[0]*rgb[0]*0.241
206+
+ rgb[1]*rgb[1]*0.691 + rgb[2]*rgb[2]*0.068);
207+
208+
//color is bright
209+
if(brightness >= 200) {
210+
return true;
211+
}
212+
return false;
213+
}
214+
}

0 commit comments

Comments
 (0)