Skip to content

Instantly share code, notes, and snippets.

@LarsWerkman
Created February 11, 2013 13:53
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save LarsWerkman/4754528 to your computer and use it in GitHub Desktop.
Save LarsWerkman/4754528 to your computer and use it in GitHub Desktop.
A sample application which shows what the HoloColorPicker library can do.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res/com.larswerkman.demo.colorpicker"
android:id="@+id/LinearLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#222"
android:orientation="vertical"
tools:context=".Main" >
<com.larswerkman.colorpicker.ColorPicker
android:id="@+id/picker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
<com.larswerkman.colorpicker.SVBar
android:id="@+id/svbar"
android:layout_width="322dp"
android:layout_height="112dp"
android:layout_gravity="center"
android:layout_margin="8dip"/>
<com.larswerkman.colorpicker.OpacityBar
android:id="@+id/opacitybar"
android:layout_width="322dp"
android:layout_height="112dp"
android:layout_gravity="center"
android:layout_margin="8dip"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="2" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change Color"
android:layout_weight="1" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text Color"
android:textColor="@android:color/white"
android:textSize="20sp"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
public class Main extends Activity implements OnColorChangedListener {
private ColorPicker picker;
private SVBar svBar;
private OpacityBar opacityBar;
private Button button;
private TextView text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
picker = (ColorPicker) findViewById(R.id.picker);
svBar = (SVBar) findViewById(R.id.svbar);
opacityBar = (OpacityBar) findViewById(R.id.opacitybar);
button = (Button) findViewById(R.id.button1);
text = (TextView) findViewById(R.id.textView1);
picker.addSVBar(svBar);
picker.addOpacityBar(opacityBar);
picker.setOnColorChangedListener(this);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
text.setTextColor(picker.getColor());
picker.setOldCenterColor(picker.getColor());
}
});
}
@Override
public void onColorChanged(int color) {
//gives the color when it's changed.
}
}
@imandaliya
Copy link

Hello
i want to use this library in my project.
this is open source library ?
is any permission required for usage ?

developer can contact me on mandaliya.rahul@gmail.com

@XNepster
Copy link

I am having a running colorPickerDialogue.May be it help someOne.

public void showColorPickDialogue()
{
    AlertDialog.Builder colorPickAlert = new AlertDialog.Builder(context);

    colorPickAlert.setTitle("Choose Background Color");

    LayoutInflater inflater = getLayoutInflater();

    View dialoglayout = inflater.inflate(R.layout.color_pick_dialog, null);

    colorPickAlert.setView(dialoglayout);

    ColorPicker picker = (ColorPicker) dialoglayout.findViewById(R.id.picker);

    SVBar svBar = (SVBar) dialoglayout.findViewById(R.id.svbar);

    OpacityBar opacityBar = (OpacityBar) dialoglayout.findViewById(R.id.opacitybar);

    final TextView text = (TextView) dialoglayout.findViewById(R.id.textView1);

    Button colorSelectedBtn = (Button)dialoglayout.findViewById(R.id.button1);

    final AlertDialog colorDialog = colorPickAlert.show();

    colorSelectedBtn.setOnClickListener(new View.OnClickListener() 
    {   
        @Override
        public void onClick(View v) 
        {
            colorDialog.dismiss();
        }
    });

    picker.addSVBar(svBar);
    picker.addOpacityBar(opacityBar);

    picker.setOnColorChangedListener(new OnColorChangedListener() 
    {
        @Override
        public void onColorChanged(int color) 
        {
            text.setBackgroundColor(color);
        }
    });

}

And color_pick_dialog.xml

<larswerkman.holocolorpicker.ColorPicker
    android:id="@+id/picker"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center" />

<larswerkman.holocolorpicker.SVBar
    android:id="@+id/svbar"
    android:layout_width="322dp"
    android:layout_height="112dp"
    android:layout_gravity="center"
    android:layout_margin="8dip" />

<larswerkman.holocolorpicker.OpacityBar
    android:id="@+id/opacitybar"
    android:layout_width="322dp"
    android:layout_height="112dp"
    android:layout_gravity="center"
    android:layout_margin="8dip" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:weightSum="2" >

    <Button
        android:id="@+id/button1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Change Color" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Text Color"
        android:textColor="#FF0000"
        android:textSize="20sp" />
</LinearLayout>

@mahdiye-imanpanah
Copy link

hi...
Your code was great ...
Thank you...
How can I use the code from the selected color?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment