@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = getIntent(); final String ID = intent.getStringExtra("ID"); final String name = intent.getStringExtra("Name"); final ActionBar actionBar = getSupportActionBar(); setContentView(R.layout.individual_colour_change_layout); SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); ColH = settings.getInt("houCol" + ID, getResources().getColor(R.color.clokH)); ColM = settings.getInt("minCol" + ID, getResources().getColor(R.color.clokM)); ColS = settings.getInt("secCol" + ID, getResources().getColor(R.color.clokS)); String currentTitle = name + ": " + getString(R.string.chsColour); if (actionBar != null) { actionBar.setTitle(currentTitle); actionBar.setDisplayUseLogoEnabled(false); } draw(); Button reset = (Button) findViewById(R.id.reset); reset.setOnClickListener( v -> { Editor editor = settings.edit(); ColH = IndividualColourChange.this.getResources().getColor(R.color.clokH); ColM = IndividualColourChange.this.getResources().getColor(R.color.clokM); ColS = IndividualColourChange.this.getResources().getColor(R.color.clokS); editor.putInt("houCol" + ID, ColH); editor.putInt("minCol" + ID, ColM); editor.putInt("secCol" + ID, ColS); editor.apply(); IndividualColourChange.this.draw(); }); ImageView colPickH = (ImageView) findViewById(R.id.colorHou); colPickH.setClickable(true); colPickH.setOnClickListener( v -> { ColorSelectorDialog dlg = new ColorSelectorDialog( context, color -> { ColH = color; Editor editor = settings.edit(); editor.putInt("houCol" + ID, ColH); editor.apply(); draw(); }, ColH); dlg.setTitle(IndividualColourChange.this.getString(R.string.hHandCol)); dlg.show(); }); ImageView colPickM = (ImageView) findViewById(R.id.colorMin); colPickM.setClickable(true); colPickM.setOnClickListener( v -> { ColorSelectorDialog dlg = new ColorSelectorDialog( context, color -> { ColM = color; Editor editor = settings.edit(); editor.putInt("minCol" + ID, ColM); editor.apply(); draw(); }, ColM); dlg.setTitle(IndividualColourChange.this.getString(R.string.mHandCol)); dlg.show(); }); ImageView colPickS = (ImageView) findViewById(R.id.colorSec); colPickS.setClickable(true); colPickS.setOnClickListener( v -> { ColorSelectorDialog dlg = new ColorSelectorDialog( context, color -> { ColS = color; Editor editor = settings.edit(); editor.putInt("minCol" + ID, ColS); editor.apply(); draw(); }, ColS); dlg.setTitle(IndividualColourChange.this.getString(R.string.sHandCol)); dlg.show(); }); }
public void draw() { Bitmap bitmap = Bitmap.createBitmap(200, 200, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); RectF rect = new RectF(8, 8, 192, 192); Paint p = new Paint(); p.setAntiAlias(true); p.setStyle(Paint.Style.STROKE); p.setColor(ColS); p.setStrokeWidth(16); int S = 162; int H = 300; // S canvas.drawArc(rect, -90, S, false, p); p.setStyle(Paint.Style.FILL); p.setColor(ColM); H -= 90; canvas.drawCircle(100, 100, 72, p); p.setColor(ColH); p.setStrokeWidth(2); float sx, sy; sx = (float) (72 * Math.cos(Math.PI * H / 180)); sy = (float) (72 * Math.sin(Math.PI * H / 180)); canvas.drawLine(100, 100, sx + 100, sy + 100, p); ImageView clokImg; clokImg = (ImageView) findViewById(R.id.clokImage); clokImg.setImageBitmap(bitmap); // Hour picker Bitmap ColPickBmp = Bitmap.createBitmap(80, 50, Bitmap.Config.ARGB_8888); Canvas ColPickCanvas = new Canvas(ColPickBmp); ImageView colPickImg = (ImageView) findViewById(R.id.colorHou); rect = new RectF(0, 0, 80, 50); p = new Paint(); p.setAntiAlias(true); p.setStyle(Paint.Style.FILL); p.setColor(ColH); ColPickCanvas.drawRect(rect, p); colPickImg.setImageBitmap(ColPickBmp); // Minute picker ColPickBmp = Bitmap.createBitmap(80, 50, Bitmap.Config.ARGB_8888); ColPickCanvas = new Canvas(ColPickBmp); colPickImg = (ImageView) findViewById(R.id.colorMin); rect = new RectF(0, 0, 80, 50); p = new Paint(); p.setAntiAlias(true); p.setStyle(Paint.Style.FILL); p.setColor(ColM); ColPickCanvas.drawRect(rect, p); colPickImg.setImageBitmap(ColPickBmp); // Second picker ColPickBmp = Bitmap.createBitmap(80, 50, Bitmap.Config.ARGB_8888); ColPickCanvas = new Canvas(ColPickBmp); colPickImg = (ImageView) findViewById(R.id.colorSec); rect = new RectF(0, 0, 80, 50); p = new Paint(); p.setAntiAlias(true); p.setStyle(Paint.Style.FILL); p.setColor(ColS); ColPickCanvas.drawRect(rect, p); colPickImg.setImageBitmap(ColPickBmp); }