# mirrors / 1993hzw / graffiti 大约 3 小时 前同步成功

### 加入文字功能

 ... ... @@ -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 CREATOR = new Creator() { @Override ... ...
 package cn.hzw.graffiti; /** * Created by huangziwei on 2017/3/15. */ public interface Undoable { }

3.1 KB | W: | H:

3.3 KB | W: | H:

• 2-up
• Swipe
• Onion skin

330 字节

3.1 KB


 \ No newline at end of file
 android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#232323" android:orientation="vertical"> layout="@layout/graffiti__title_bar"/> android:layout_below="@id/graffiti__title_bar"/> android:visibility="visible"/>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.