-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
24c9836
commit a0a3874
Showing
6 changed files
with
154 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 46 additions & 3 deletions
49
sample/src/main/java/com/madrapps/pickcolor/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,71 @@ | ||
package com.madrapps.pickcolor; | ||
|
||
import android.graphics.PorterDuff; | ||
import android.graphics.drawable.ColorDrawable; | ||
import android.os.Bundle; | ||
import android.support.v4.graphics.ColorUtils; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.ImageButton; | ||
import android.widget.ImageView; | ||
|
||
import com.madrapps.pikolo.HSLColorPicker; | ||
import com.madrapps.pikolo.listeners.SimpleColorSelectionListener; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
import java.util.Random; | ||
|
||
public class MainActivity extends AppCompatActivity implements View.OnClickListener { | ||
|
||
private HSLColorPicker colorPicker; | ||
private ImageView imageView; | ||
private Button randomColorButton; | ||
|
||
private Random random = new Random(); | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
final HSLColorPicker colorPicker = (HSLColorPicker) findViewById(R.id.colorPicker); | ||
final ImageView imageView = (ImageView) findViewById(R.id.imageView); | ||
colorPicker = (HSLColorPicker) findViewById(R.id.colorPicker); | ||
imageView = (ImageView) findViewById(R.id.imageView); | ||
|
||
colorPicker.setColorSelectionListener(new SimpleColorSelectionListener() { | ||
@Override | ||
public void onColorSelected(int color) { | ||
imageView.getBackground().setColorFilter(color, PorterDuff.Mode.MULTIPLY); | ||
} | ||
}); | ||
|
||
initializeColorButtons(); | ||
|
||
randomColorButton = (Button) findViewById(R.id.randomColorButton); | ||
randomColorButton.setOnClickListener(this); | ||
} | ||
|
||
private void initializeColorButtons() { | ||
findViewById(R.id.imageButton1).setOnClickListener(this); | ||
findViewById(R.id.imageButton2).setOnClickListener(this); | ||
findViewById(R.id.imageButton3).setOnClickListener(this); | ||
findViewById(R.id.imageButton4).setOnClickListener(this); | ||
findViewById(R.id.imageButton5).setOnClickListener(this); | ||
} | ||
|
||
@Override | ||
public void onClick(View v) { | ||
if(v.getId() == R.id.randomColorButton){ | ||
final int color = ColorUtils.HSLToColor(new float[]{random.nextInt(360), random.nextFloat(), random.nextFloat()}); | ||
final String hexColor = String.format("#%06X", (0xFFFFFF & color)); | ||
randomColorButton.setText(hexColor); | ||
randomColorButton.setBackgroundColor(color); | ||
imageView.getBackground().setColorFilter(color, PorterDuff.Mode.MULTIPLY); | ||
colorPicker.setColor(color); | ||
} | ||
if(v instanceof ImageButton){ | ||
final int color = ((ColorDrawable) ((ImageButton) v).getDrawable()).getColor(); | ||
imageView.getBackground().setColorFilter(color, PorterDuff.Mode.MULTIPLY); | ||
colorPicker.setColor(color); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters