Skip to content

Commit

Permalink
Merge pull request #2 from prakh25/TODO---IMAGE-TINT
Browse files Browse the repository at this point in the history
Tint Images
  • Loading branch information
adrielcafe authored Aug 15, 2016
2 parents 80d75d7 + b376a38 commit 91abb63
Showing 1 changed file with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package cafe.adriel.androidaudiorecorder;

import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
Expand Down Expand Up @@ -30,7 +32,7 @@ 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 @@ -59,7 +61,21 @@ protected void onCreate(Bundle savedInstanceState) {
micView = (ImageView) findViewById(R.id.mic);
recordView = (ImageButton) findViewById(R.id.record);

// to get drawable resources of check icon and clear icon
Drawable clear = getResources().getDrawable(R.drawable.ic_clear);
Drawable check = getResources().getDrawable(R.drawable.ic_check);

contentLayout.setBackgroundColor(color);

// check to set tint of images
isBright = isBrightColor(color);
if(isBright) {
micView.setColorFilter(Color.BLACK);
recordView.setColorFilter(Color.BLACK);
timerView.setTextColor(Color.BLACK);
clear.setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_ATOP);
check.setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_ATOP);
}
}

@Override
Expand Down Expand Up @@ -174,4 +190,25 @@ 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;
}
}

0 comments on commit 91abb63

Please sign in to comment.