mirror of
https://github.com/SimpleMobileTools/Simple-Draw.git
synced 2025-06-05 21:59:17 +02:00
add a color picker
This commit is contained in:
@ -24,4 +24,5 @@ dependencies {
|
|||||||
testCompile 'junit:junit:4.12'
|
testCompile 'junit:junit:4.12'
|
||||||
compile 'com.android.support:appcompat-v7:23.1.1'
|
compile 'com.android.support:appcompat-v7:23.1.1'
|
||||||
compile 'com.jakewharton:butterknife:7.0.1'
|
compile 'com.jakewharton:butterknife:7.0.1'
|
||||||
|
compile 'com.github.yukuku:ambilwarna:2.0.1'
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,53 @@
|
|||||||
package draw.simplemobiletools.com;
|
package draw.simplemobiletools.com;
|
||||||
|
|
||||||
|
import android.graphics.Color;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
import butterknife.Bind;
|
import butterknife.Bind;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import butterknife.OnClick;
|
import butterknife.OnClick;
|
||||||
|
import yuku.ambilwarna.AmbilWarnaDialog;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
@Bind(R.id.my_canvas) MyCanvas myCanvas;
|
@Bind(R.id.my_canvas) MyCanvas myCanvas;
|
||||||
|
@Bind(R.id.color_picker) View colorPicker;
|
||||||
|
private int color;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
ButterKnife.bind(this);
|
ButterKnife.bind(this);
|
||||||
|
|
||||||
|
setColor(Color.BLACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.undo)
|
@OnClick(R.id.undo)
|
||||||
public void undo() {
|
public void undo() {
|
||||||
myCanvas.undo();
|
myCanvas.undo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OnClick(R.id.color_picker)
|
||||||
|
public void pickColor() {
|
||||||
|
AmbilWarnaDialog dialog = new AmbilWarnaDialog(this, color, new AmbilWarnaDialog.OnAmbilWarnaListener() {
|
||||||
|
@Override
|
||||||
|
public void onCancel(AmbilWarnaDialog dialog) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onOk(AmbilWarnaDialog dialog, int pickedColor) {
|
||||||
|
setColor(pickedColor);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
dialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setColor(int pickedColor) {
|
||||||
|
color = pickedColor;
|
||||||
|
colorPicker.setBackgroundColor(color);
|
||||||
|
myCanvas.setColor(color);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,10 @@ public class MyCanvas extends View {
|
|||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setColor(int color) {
|
||||||
|
paint.setColor(color);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDraw(Canvas canvas) {
|
protected void onDraw(Canvas canvas) {
|
||||||
super.onDraw(canvas);
|
super.onDraw(canvas);
|
||||||
|
@ -11,12 +11,19 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"/>
|
android:layout_height="match_parent"/>
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/color_picker"
|
||||||
|
android:layout_width="@dimen/icon_size"
|
||||||
|
android:layout_height="@dimen/icon_size"
|
||||||
|
android:layout_alignParentRight="true"/>
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/undo"
|
android:id="@+id/undo"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="@dimen/icon_size"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="@dimen/icon_size"
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
android:padding="@dimen/activity_margin"
|
android:layout_below="@id/color_picker"
|
||||||
|
android:padding="4dp"
|
||||||
android:src="@mipmap/undo"/>
|
android:src="@mipmap/undo"/>
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<dimen name="activity_margin">16dp</dimen>
|
<dimen name="activity_margin">16dp</dimen>
|
||||||
|
<dimen name="icon_size">48dp</dimen>
|
||||||
</resources>
|
</resources>
|
||||||
|
Reference in New Issue
Block a user