提交 0a33fc55 编写于 作者: H huangziwei

加入文字功能

上级 4f7e9e87
......@@ -4,6 +4,8 @@ import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import cn.forward.androids.utils.LogUtil;
/**
* Created by Administrator on 2016/9/3.
*/
......@@ -91,4 +93,45 @@ public class DrawUtil {
}
}
}
/**
* 计算点p2绕p1顺时针旋转的角度
*
* @param px1
* @param py1
* @param px2
* @param py2
* @return 旋转的角度
*/
public static float computeAngle(float px1, float py1, float px2, float py2) {
float x = px2 - px1;
float y = py2 - py1;
float arc = (float) Math.atan(y / x);
float angle = (float) (arc / (Math.PI * 2) * 360);
if (x >= 0 && y == 0) {
angle = 0;
} else if (x < 0 && y == 0) {
angle = 180;
} else if (x == 0 && y > 0) {
angle = 90;
} else if (x == 0 && y < 0) {
angle = 270;
} else if (x > 0 && y > 0) { // 1
} else if (x < 0 && y > 0) { //2
angle = 180 + angle;
} else if (x < 0 && y < 0) { //3
angle = 180 + angle;
} else if (x > 0 && y < 0) { //4
angle = 360 + angle;
}
LogUtil.i("hzw", "[" + px1 + "," + py1 + "]:[" + px2 + "," + py2 + "] = " + angle);
return angle;
}
}
......@@ -119,6 +119,9 @@ public class GraffitiActivity extends Activity {
private final float mMinScale = 0.25f; // 最小缩放倍数
private final int TIME_SPAN = 40;
private View mBtnMovePic, mBtnHidePanel, mSettingsPanel;
private View mShapeModeContainer;
private View mSelectedTextEditContainer;
private View mEditContainer;
private int mTouchSlop;
......@@ -240,11 +243,46 @@ public class GraffitiActivity extends Activity {
@Override
public void onReady() {
mGraffitiView.setPaintSize(mGraffitiParams.mPaintSize > 0 ? mGraffitiParams.mPaintSize
: mGraffitiView.getPaintSize());
if (mGraffitiView.getPen() == GraffitiView.Pen.TEXT) {
mPaintSizeBar.setProgress((int) (mGraffitiView.getTextSize() + 0.5f));
} else {
mPaintSizeBar.setProgress((int) (mGraffitiView.getPaintSize() + 0.5f));
}
findViewById(R.id.btn_pen_hand).performClick();
findViewById(R.id.btn_hand_write).performClick();
}
@Override
public void onSelectedText(boolean selected) {
if (selected) {
mSelectedTextEditContainer.setVisibility(View.VISIBLE);
if (mGraffitiView.getSelectedTextColor().getType() == GraffitiView.GraffitiColor.Type.BITMAP) {
mBtnColor.setBackgroundDrawable(new BitmapDrawable(mGraffitiView.getSelectedTextColor().getBitmap()));
} else {
mBtnColor.setBackgroundColor(mGraffitiView.getSelectedTextColor().getColor());
}
mPaintSizeBar.setProgress((int) (mGraffitiView.getSelectedTextSize() + 0.5f));
} else {
mSelectedTextEditContainer.setVisibility(View.GONE);
mEditContainer.setVisibility(View.VISIBLE);
if (mGraffitiView.getColor().getType() == GraffitiView.GraffitiColor.Type.BITMAP) {
mBtnColor.setBackgroundDrawable(new BitmapDrawable(mGraffitiView.getColor().getBitmap()));
} else {
mBtnColor.setBackgroundColor(mGraffitiView.getColor().getColor());
}
mPaintSizeBar.setProgress((int) (mGraffitiView.getTextSize() + 0.5f));
}
}
@Override
public void onEditText(boolean showDialog, String string) {
}
});
mGraffitiView.setPaintSize(mGraffitiParams.mPaintSize);
mGraffitiView.setIsDrawableOutside(mGraffitiParams.mIsDrawableOutside);
mFrameLayout.addView(mGraffitiView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
mOnClickListener = new GraffitiOnClickListener();
......@@ -256,6 +294,7 @@ public class GraffitiActivity extends Activity {
findViewById(R.id.btn_pen_hand).setOnClickListener(mOnClickListener);
findViewById(R.id.btn_pen_copy).setOnClickListener(mOnClickListener);
findViewById(R.id.btn_pen_eraser).setOnClickListener(mOnClickListener);
findViewById(R.id.btn_pen_text).setOnClickListener(mOnClickListener);
findViewById(R.id.btn_hand_write).setOnClickListener(mOnClickListener);
findViewById(R.id.btn_arrow).setOnClickListener(mOnClickListener);
findViewById(R.id.btn_line).setOnClickListener(mOnClickListener);
......@@ -265,6 +304,11 @@ public class GraffitiActivity extends Activity {
findViewById(R.id.btn_fill_rect).setOnClickListener(mOnClickListener);
findViewById(R.id.btn_clear).setOnClickListener(mOnClickListener);
findViewById(R.id.btn_undo).setOnClickListener(mOnClickListener);
findViewById(R.id.graffiti_text_edit).setOnClickListener(mOnClickListener);
findViewById(R.id.graffiti_text_remove).setOnClickListener(mOnClickListener);
mShapeModeContainer = findViewById(R.id.bar_shape_mode);
mSelectedTextEditContainer = findViewById(R.id.graffiti_text_edit_container);
mEditContainer = findViewById(R.id.graffiti_edit_container);
mBtnHidePanel = findViewById(R.id.graffiti_btn_hide_panel);
mBtnHidePanel.setOnClickListener(mOnClickListener);
findViewById(R.id.graffiti_btn_finish).setOnClickListener(mOnClickListener);
......@@ -286,8 +330,18 @@ public class GraffitiActivity extends Activity {
mPaintSizeBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (progress == 0) {
mPaintSizeBar.setProgress(1);
return;
}
mPaintSizeView.setText("" + progress);
mGraffitiView.setPaintSize(progress);
if (mGraffitiView.isSelectedText()) {
mGraffitiView.setSelectedTextSize(progress);
} else if (mGraffitiView.getPen() == GraffitiView.Pen.TEXT) {
mGraffitiView.setTextSize(progress);
} else {
mGraffitiView.setPaintSize(progress);
}
}
public void onStartTrackingTouch(SeekBar seekBar) {
......@@ -296,7 +350,6 @@ public class GraffitiActivity extends Activity {
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
mPaintSizeBar.setProgress((int) mGraffitiView.getPaintSize());
ScaleOnTouchListener onTouchListener = new ScaleOnTouchListener();
findViewById(R.id.btn_amplifier).setOnTouchListener(onTouchListener);
......@@ -457,14 +510,25 @@ public class GraffitiActivity extends Activity {
public void onClick(View v) {
mDone = false;
if (v.getId() == R.id.btn_pen_hand) {
mPaintSizeBar.setProgress((int) (mGraffitiView.getPaintSize() + 0.5f));
mShapeModeContainer.setVisibility(View.VISIBLE);
mGraffitiView.setPen(GraffitiView.Pen.HAND);
mDone = true;
} else if (v.getId() == R.id.btn_pen_copy) {
mPaintSizeBar.setProgress((int) (mGraffitiView.getPaintSize() + 0.5f));
mShapeModeContainer.setVisibility(View.VISIBLE);
mGraffitiView.setPen(GraffitiView.Pen.COPY);
mDone = true;
} else if (v.getId() == R.id.btn_pen_eraser) {
mPaintSizeBar.setProgress((int) (mGraffitiView.getPaintSize() + 0.5f));
mShapeModeContainer.setVisibility(View.VISIBLE);
mGraffitiView.setPen(GraffitiView.Pen.ERASER);
mDone = true;
} else if (v.getId() == R.id.btn_pen_text) {
mPaintSizeBar.setProgress((int) (mGraffitiView.getTextSize() + 0.5f));
mShapeModeContainer.setVisibility(View.GONE);
mGraffitiView.setPen(GraffitiView.Pen.TEXT);
mDone = true;
}
if (mDone) {
if (mLastPenView != null) {
......@@ -495,13 +559,21 @@ public class GraffitiActivity extends Activity {
new ColorPickerDialog.OnColorChangedListener() {
public void colorChanged(int color) {
mBtnColor.setBackgroundColor(color);
mGraffitiView.setColor(color);
if (mGraffitiView.isSelectedText()) {
mGraffitiView.setSelectedTextColor(color);
} else {
mGraffitiView.setColor(color);
}
}
@Override
public void colorChanged(Drawable color) {
mBtnColor.setBackgroundDrawable(color);
mGraffitiView.setColor(ImageUtils.getBitmapFromDrawable(color));
if (mGraffitiView.isSelectedText()) {
mGraffitiView.setSelectedTextColor(ImageUtils.getBitmapFromDrawable(color));
} else {
mGraffitiView.setColor(ImageUtils.getBitmapFromDrawable(color));
}
}
}).show();
mDone = true;
......@@ -558,6 +630,18 @@ public class GraffitiActivity extends Activity {
return;
}
if (v.getId() == R.id.graffiti_text_edit) {
mGraffitiView.editSelectedText();
mDone = true;
} else if (v.getId() == R.id.graffiti_text_remove) {
mGraffitiView.removeSelectedText();
mDone = true;
}
if (mDone) {
return;
}
if (v.getId() == R.id.btn_hand_write) {
mGraffitiView.setShape(GraffitiView.Shape.HAND_WRITE);
} else if (v.getId() == R.id.btn_arrow) {
......@@ -774,9 +858,8 @@ public class GraffitiActivity extends Activity {
/**
* 初始化的画笔大小
* 默认为30px
*/
public float mPaintSize = 30;
public float mPaintSize = -1;
public static final Creator<GraffitiParams> CREATOR = new Creator<GraffitiParams>() {
@Override
......
package cn.hzw.graffiti;
/**
* Created by huangziwei on 2017/3/15.
*/
public interface Undoable {
}
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/SecondaryProgress" android:drawable="@drawable/graffiti_bar_dn" />
<item android:id="@+id/SecondaryProgress" android:drawable="@android:color/transparent" />
<item android:id="@+id/progress" android:drawable="@drawable/graffiti_bar_up" />
</layer-list>
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/graffiti_text_edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="50dp"
android:background="#88000000"
android:padding="10dp"
android:textColor="#ffffff"
android:textSize="26dp"
/>
<FrameLayout
android:layout_gravity="bottom"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#ffffff"
android:paddingLeft="5dp"
android:paddingRight="5dp"
>
<TextView
android:id="@+id/graffiti_text_cancel_btn"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="bottom|left"
android:gravity="center"
android:padding="10dp"
android:text="@string/graffiti_cancel"
android:textColor="#232323"
android:textSize="16dp"/>
<TextView
android:id="@+id/graffiti_text_enter_btn"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="bottom|right"
android:gravity="center"
android:padding="10dp"
android:text="@string/graffiti_enter"
android:textColor="#232323"
android:textSize="16dp"/>
</FrameLayout>
</FrameLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#232323"
android:orientation="vertical">
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#232323"
android:orientation="vertical">
<include
android:id="@+id/graffiti__title_bar"
layout="@layout/graffiti__title_bar" />
layout="@layout/graffiti__title_bar"/>
<FrameLayout
android:id="@+id/graffiti_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/graffiti__title_bar" />
android:layout_below="@id/graffiti__title_bar"/>
<RelativeLayout
android:id="@+id/graffiti_panel"
......@@ -46,7 +46,7 @@
android:text="手绘"
android:textColor="#000000"
android:textSize="13dp"
android:visibility="visible" />
android:visibility="visible"/>
<Button
android:id="@+id/btn_pen_copy"
......@@ -57,7 +57,7 @@
android:text="仿制"
android:textColor="#000000"
android:textSize="13dp"
android:visibility="visible" />
android:visibility="visible"/>
<Button
android:id="@+id/btn_pen_eraser"
......@@ -69,12 +69,23 @@
android:text="橡皮擦"
android:textColor="#000000"
android:textSize="13dp"
android:visibility="visible" />
android:visibility="visible"/>
<Button
android:id="@+id/btn_pen_text"
android:layout_width="50dp"
android:layout_height="match_parent"
android:background="@drawable/graffiti_btn_effect_round"
android:scaleType="centerCrop"
android:text="文字"
android:textColor="#000000"
android:textSize="13dp"
android:visibility="visible"/>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_weight="1" />
android:layout_weight="1"/>
<Button
android:id="@+id/btn_clear"
......@@ -83,7 +94,7 @@
android:background="@drawable/graffiti_btn_effect_round"
android:text="清屏"
android:textColor="#000000"
android:textSize="13dp" />
android:textSize="13dp"/>
<Button
android:id="@+id/btn_undo"
......@@ -92,7 +103,7 @@
android:background="@drawable/graffiti_btn_effect_round"
android:text="撤销"
android:textColor="#000000"
android:textSize="13dp" />
android:textSize="13dp"/>
</LinearLayout>
<LinearLayout
......@@ -114,7 +125,7 @@
android:text="手绘"
android:textColor="#000000"
android:textSize="10dp"
android:visibility="visible" />
android:visibility="visible"/>
<Button
android:id="@+id/btn_copy"
......@@ -126,7 +137,7 @@
android:text="仿制"
android:textColor="#000000"
android:textSize="10dp"
android:visibility="visible" />
android:visibility="visible"/>
</LinearLayout>
<LinearLayout
......@@ -146,7 +157,7 @@
android:text="手绘"
android:textColor="#000000"
android:textSize="10dp"
android:visibility="visible" />
android:visibility="visible"/>
<Button
android:id="@+id/btn_arrow"
......@@ -157,7 +168,7 @@
android:text="箭头"
android:textColor="#000000"
android:textSize="10dp"
android:visibility="visible" />
android:visibility="visible"/>
<Button
android:id="@+id/btn_line"
......@@ -168,7 +179,7 @@
android:text="直线"
android:textColor="#000000"
android:textSize="10dp"
android:visibility="visible" />
android:visibility="visible"/>
<Button
android:id="@+id/btn_holl_circle"
......@@ -180,7 +191,7 @@
android:text="空心圆"
android:textColor="#000000"
android:textSize="10dp"
android:visibility="visible" />
android:visibility="visible"/>
<Button
android:id="@+id/btn_fill_circle"
......@@ -192,7 +203,7 @@
android:text="实心圆"
android:textColor="#000000"
android:textSize="10dp"
android:visibility="visible" />
android:visibility="visible"/>
<Button
android:id="@+id/btn_holl_rect"
......@@ -204,7 +215,7 @@
android:text="空心矩形"
android:textColor="#000000"
android:textSize="10dp"
android:visibility="visible" />
android:visibility="visible"/>
<Button
android:id="@+id/btn_fill_rect"
......@@ -216,7 +227,7 @@
android:text="实心矩形"
android:textColor="#000000"
android:textSize="10dp"
android:visibility="visible" />
android:visibility="visible"/>
</LinearLayout>
......@@ -237,7 +248,7 @@
<ImageView
android:id="@+id/btn_set_color"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
android:layout_height="fill_parent"/>
</RelativeLayout>
<SeekBar
......@@ -250,7 +261,7 @@
android:paddingRight="10dp"
android:paddingTop="3dp"
android:progressDrawable="@drawable/graffiti_seekbar_bg"
android:thumb="@drawable/graffiti_thumb_seekbarr" />
android:thumb="@drawable/graffiti_thumb_seekbarr"/>
<TextView
android:id="@+id/paint_size_text"
......@@ -259,11 +270,12 @@
android:paddingLeft="2dp"
android:text=""
android:textColor="#ffffff"
android:textSize="14dp" />
android:textSize="14dp"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/graffiti_edit_container"
android:layout_width="fill_parent"
android:layout_height="@dimen/title_bar_height"
android:layout_alignParentBottom="true"
......@@ -281,7 +293,7 @@
android:text="M"
android:textColor="#ffffff"
android:textSize="16dp"
android:textStyle="bold" />
android:textStyle="bold"/>
<Button
android:id="@+id/btn_centre_pic"
......@@ -292,7 +304,7 @@
android:text="O"
android:textColor="#ffffff"
android:textSize="16dp"
android:textStyle="bold" />
android:textStyle="bold"/>
<ImageView
android:id="@+id/btn_amplifier"
......@@ -300,7 +312,7 @@
android:layout_height="@dimen/title_bar_height"
android:layout_marginBottom="5dp"
android:background="@drawable/graffiti_btn_effect_rect_pressed_black"
android:src="@drawable/graffiti_btn_add" />
android:src="@drawable/graffiti_btn_add"/>
<ImageView
android:id="@+id/btn_reduce"
......@@ -308,7 +320,7 @@
android:layout_height="@dimen/title_bar_height"
android:background="@drawable/graffiti_btn_effect_rect_pressed_black"
android:src="@drawable/graffiti_btn_sub"
android:textSize="20dp" />
android:textSize="20dp"/>
<ImageView
android:id="@+id/graffiti_btn_rotate"
......@@ -318,7 +330,40 @@
android:padding="5dp"
android:scaleType="fitXY"
android:src="@drawable/graffiti_rotate"
android:textSize="20dp" />
android:textSize="20dp"/>
</LinearLayout>
<LinearLayout
android:id="@+id/graffiti_text_edit_container"
android:layout_width="fill_parent"
android:layout_height="@dimen/title_bar_height"
android:layout_above="@+id/graffiti_edit_container"
android:background="#88000000"
android:gravity="center"
android:orientation="horizontal"
android:visibility="gone">
<TextView
android:id="@+id/graffiti_text_edit"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/graffiti_btn_effect_rect_pressed_black"
android:gravity="center"
android:text="编辑"
android:textColor="#ffffff"
android:textSize="16dp"/>
<TextView
android:id="@+id/graffiti_text_remove"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/graffiti_btn_effect_rect_pressed_black"
android:gravity="center"
android:text="移除"
android:textColor="#ffffff"
android:textSize="16dp"/>
</LinearLayout>
</RelativeLayout>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册