Skip to content

Instantly share code, notes, and snippets.

@LarsWerkman
Created February 11, 2013 13:53

Revisions

  1. LarsWerkman created this gist Feb 11, 2013.
    38 changes: 38 additions & 0 deletions Main.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    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.
    }
    }
    53 changes: 53 additions & 0 deletions activity_main.xml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,53 @@
    <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>