Skip to content

Commit 8b8324c

Browse files
committed
some refactoring, no functionality change
1 parent 25d6493 commit 8b8324c

6 files changed

Lines changed: 92 additions & 79 deletions

File tree

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apply plugin: 'android-apt'
33

44
android {
55
compileSdkVersion 23
6-
buildToolsVersion "23.0.2"
6+
buildToolsVersion "23.0.3"
77

88
defaultConfig {
99
applicationId "com.simplemobiletools.draw"

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
android:supportsRtl="true"
1313
android:theme="@style/AppTheme">
1414
<activity
15-
android:name=".MainActivity"
15+
android:name=".activities.MainActivity"
1616
android:screenOrientation="portrait">
1717
<intent-filter>
1818
<action android:name="android.intent.action.MAIN"/>
@@ -22,12 +22,12 @@
2222
</activity>
2323

2424
<activity
25-
android:name=".AboutActivity"
25+
android:name=".activities.AboutActivity"
2626
android:label="@string/about"
2727
android:screenOrientation="portrait"/>
2828

2929
<activity
30-
android:name=".LicenseActivity"
30+
android:name=".activities.LicenseActivity"
3131
android:label="@string/third_party_licences"
3232
android:screenOrientation="portrait"/>
3333

app/src/main/java/com/simplemobiletools/draw/MyCanvas.java

Lines changed: 49 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -14,53 +14,54 @@
1414
import java.util.Map;
1515

1616
public class MyCanvas extends View {
17-
private Paint paint;
18-
private Path path;
19-
private Map<Path, Integer> paths;
20-
private int color;
21-
private float curX;
22-
private float curY;
23-
private float startX;
24-
private float startY;
25-
private PathsChangedListener listener;
17+
private Paint mPaint;
18+
private Path mPath;
19+
private Map<Path, Integer> mPaths;
20+
private PathsChangedListener mListener;
21+
22+
private int mColor;
23+
private float mCurX;
24+
private float mCurY;
25+
private float mStartX;
26+
private float mStartY;
2627

2728
public MyCanvas(Context context, AttributeSet attrs) {
2829
super(context, attrs);
2930

30-
path = new Path();
31-
paint = new Paint();
32-
paint.setColor(Color.BLACK);
33-
paint.setStyle(Paint.Style.STROKE);
34-
paint.setStrokeJoin(Paint.Join.ROUND);
35-
paint.setStrokeCap(Paint.Cap.ROUND);
36-
paint.setStrokeWidth(5f);
37-
paint.setAntiAlias(true);
38-
39-
paths = new LinkedHashMap<>();
40-
paths.put(path, paint.getColor());
31+
mPath = new Path();
32+
mPaint = new Paint();
33+
mPaint.setColor(Color.BLACK);
34+
mPaint.setStyle(Paint.Style.STROKE);
35+
mPaint.setStrokeJoin(Paint.Join.ROUND);
36+
mPaint.setStrokeCap(Paint.Cap.ROUND);
37+
mPaint.setStrokeWidth(5f);
38+
mPaint.setAntiAlias(true);
39+
40+
mPaths = new LinkedHashMap<>();
41+
mPaths.put(mPath, mPaint.getColor());
4142
pathsUpdated();
4243
}
4344

4445
public void setListener(PathsChangedListener listener) {
45-
this.listener = listener;
46+
this.mListener = listener;
4647
}
4748

4849
public void undo() {
49-
if (paths.size() <= 0)
50+
if (mPaths.size() <= 0)
5051
return;
5152

5253
Path lastKey = null;
53-
for (Path key : paths.keySet()) {
54+
for (Path key : mPaths.keySet()) {
5455
lastKey = key;
5556
}
5657

57-
paths.remove(lastKey);
58+
mPaths.remove(lastKey);
5859
pathsUpdated();
5960
invalidate();
6061
}
6162

6263
public void setColor(int newColor) {
63-
color = newColor;
64+
mColor = newColor;
6465
}
6566

6667
public Bitmap getBitmap() {
@@ -75,46 +76,46 @@ public Bitmap getBitmap() {
7576
protected void onDraw(Canvas canvas) {
7677
super.onDraw(canvas);
7778

78-
for (Map.Entry<Path, Integer> entry : paths.entrySet()) {
79-
paint.setColor(entry.getValue());
80-
canvas.drawPath(entry.getKey(), paint);
79+
for (Map.Entry<Path, Integer> entry : mPaths.entrySet()) {
80+
mPaint.setColor(entry.getValue());
81+
canvas.drawPath(entry.getKey(), mPaint);
8182
}
8283

83-
paint.setColor(color);
84-
canvas.drawPath(path, paint);
84+
mPaint.setColor(mColor);
85+
canvas.drawPath(mPath, mPaint);
8586
}
8687

8788
private void actionDown(float x, float y) {
88-
path.reset();
89-
path.moveTo(x, y);
90-
curX = x;
91-
curY = y;
89+
mPath.reset();
90+
mPath.moveTo(x, y);
91+
mCurX = x;
92+
mCurY = y;
9293
}
9394

9495
private void actionMove(float x, float y) {
95-
path.quadTo(curX, curY, (x + curX) / 2, (y + curY) / 2);
96-
curX = x;
97-
curY = y;
96+
mPath.quadTo(mCurX, mCurY, (x + mCurX) / 2, (y + mCurY) / 2);
97+
mCurX = x;
98+
mCurY = y;
9899
}
99100

100101
private void actionUp() {
101-
path.lineTo(curX, curY);
102+
mPath.lineTo(mCurX, mCurY);
102103

103104
// draw a dot on click
104-
if (startX == curX && startY == curY) {
105-
path.lineTo(curX, curY + 2);
106-
path.lineTo(curX + 1, curY + 2);
107-
path.lineTo(curX + 1, curY);
105+
if (mStartX == mCurX && mStartY == mCurY) {
106+
mPath.lineTo(mCurX, mCurY + 2);
107+
mPath.lineTo(mCurX + 1, mCurY + 2);
108+
mPath.lineTo(mCurX + 1, mCurY);
108109
}
109110

110-
paths.put(path, paint.getColor());
111+
mPaths.put(mPath, mPaint.getColor());
111112
pathsUpdated();
112-
path = new Path();
113+
mPath = new Path();
113114
}
114115

115116
private void pathsUpdated() {
116-
if (listener != null && paths != null) {
117-
listener.pathsChanged(paths.size());
117+
if (mListener != null && mPaths != null) {
118+
mListener.pathsChanged(mPaths.size());
118119
}
119120
}
120121

@@ -125,8 +126,8 @@ public boolean onTouchEvent(MotionEvent event) {
125126

126127
switch (event.getAction()) {
127128
case MotionEvent.ACTION_DOWN:
128-
startX = x;
129-
startY = y;
129+
mStartX = x;
130+
mStartY = y;
130131
actionDown(x, y);
131132
break;
132133
case MotionEvent.ACTION_MOVE:

app/src/main/java/com/simplemobiletools/draw/AboutActivity.java renamed to app/src/main/java/com/simplemobiletools/draw/activities/AboutActivity.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.simplemobiletools.draw;
1+
package com.simplemobiletools.draw.activities;
22

33
import android.content.Intent;
44
import android.content.res.Resources;
@@ -8,48 +8,52 @@
88
import android.text.method.LinkMovementMethod;
99
import android.widget.TextView;
1010

11+
import com.simplemobiletools.draw.BuildConfig;
12+
import com.simplemobiletools.draw.R;
13+
1114
import java.util.Calendar;
1215

1316
import butterknife.BindView;
1417
import butterknife.ButterKnife;
1518
import butterknife.OnClick;
1619

1720
public class AboutActivity extends AppCompatActivity {
18-
@BindView(R.id.about_copyright) TextView copyright;
19-
@BindView(R.id.about_version) TextView version;
20-
@BindView(R.id.about_email) TextView emailTV;
21-
private Resources res;
21+
@BindView(R.id.about_copyright) TextView mCopyright;
22+
@BindView(R.id.about_version) TextView mVersion;
23+
@BindView(R.id.about_email) TextView mEmailTV;
24+
25+
private Resources mRes;
2226

2327
@Override
2428
protected void onCreate(Bundle savedInstanceState) {
2529
super.onCreate(savedInstanceState);
2630
setContentView(R.layout.activity_about);
2731
ButterKnife.bind(this);
28-
res = getResources();
32+
mRes = getResources();
2933

3034
setupEmail();
3135
setupVersion();
3236
setupCopyright();
3337
}
3438

3539
private void setupEmail() {
36-
final String email = res.getString(R.string.email);
37-
final String appName = res.getString(R.string.app_name);
40+
final String email = mRes.getString(R.string.email);
41+
final String appName = mRes.getString(R.string.app_name);
3842
final String href = "<a href=\"mailto:" + email + "?subject=" + appName + "\">" + email + "</a>";
39-
emailTV.setText(Html.fromHtml(href));
40-
emailTV.setMovementMethod(LinkMovementMethod.getInstance());
43+
mEmailTV.setText(Html.fromHtml(href));
44+
mEmailTV.setMovementMethod(LinkMovementMethod.getInstance());
4145
}
4246

4347
private void setupVersion() {
4448
final String versionName = BuildConfig.VERSION_NAME;
45-
final String versionText = String.format(res.getString(R.string.version), versionName);
46-
version.setText(versionText);
49+
final String versionText = String.format(mRes.getString(R.string.version), versionName);
50+
mVersion.setText(versionText);
4751
}
4852

4953
private void setupCopyright() {
5054
final int year = Calendar.getInstance().get(Calendar.YEAR);
51-
final String copyrightText = String.format(res.getString(R.string.copyright), year);
52-
copyright.setText(copyrightText);
55+
final String copyrightText = String.format(mRes.getString(R.string.copyright), year);
56+
mCopyright.setText(copyrightText);
5357
}
5458

5559
@OnClick(R.id.about_license)

app/src/main/java/com/simplemobiletools/draw/LicenseActivity.java renamed to app/src/main/java/com/simplemobiletools/draw/activities/LicenseActivity.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
package com.simplemobiletools.draw;
1+
package com.simplemobiletools.draw.activities;
22

33
import android.content.Intent;
44
import android.net.Uri;
55
import android.os.Bundle;
66
import android.support.v7.app.AppCompatActivity;
77

8+
import com.simplemobiletools.draw.R;
9+
810
import butterknife.ButterKnife;
911
import butterknife.OnClick;
1012

1113
public class LicenseActivity extends AppCompatActivity {
14+
1215
@Override
1316
protected void onCreate(Bundle savedInstanceState) {
1417
super.onCreate(savedInstanceState);

app/src/main/java/com/simplemobiletools/draw/MainActivity.java renamed to app/src/main/java/com/simplemobiletools/draw/activities/MainActivity.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.simplemobiletools.draw;
1+
package com.simplemobiletools.draw.activities;
22

33
import android.Manifest;
44
import android.content.Intent;
@@ -21,6 +21,10 @@
2121
import android.widget.EditText;
2222
import android.widget.Toast;
2323

24+
import com.simplemobiletools.draw.MyCanvas;
25+
import com.simplemobiletools.draw.R;
26+
import com.simplemobiletools.draw.Utils;
27+
2428
import java.io.ByteArrayOutputStream;
2529
import java.io.File;
2630
import java.io.FileOutputStream;
@@ -38,19 +42,20 @@ public class MainActivity extends AppCompatActivity implements MyCanvas.PathsCha
3842
private static final String SAVE_FOLDER_NAME = "Simple Draw";
3943
private static final int STORAGE_PERMISSION = 1;
4044

41-
@BindView(R.id.my_canvas) MyCanvas myCanvas;
42-
@BindView(R.id.undo) View undoBtn;
43-
@BindView(R.id.color_picker) View colorPicker;
45+
@BindView(R.id.my_canvas) MyCanvas mMyCanvas;
46+
@BindView(R.id.undo) View mUndoBtn;
47+
@BindView(R.id.color_picker) View mColorPicker;
4448

45-
private int color;
4649
private String curFileName;
4750

51+
private int color;
52+
4853
@Override
4954
protected void onCreate(Bundle savedInstanceState) {
5055
super.onCreate(savedInstanceState);
5156
setContentView(R.layout.activity_main);
5257
ButterKnife.bind(this);
53-
myCanvas.setListener(this);
58+
mMyCanvas.setListener(this);
5459

5560
setColor(Color.BLACK);
5661
}
@@ -141,7 +146,7 @@ private boolean saveFile(final String fileName) {
141146
}
142147
}
143148

144-
final Bitmap bitmap = myCanvas.getBitmap();
149+
final Bitmap bitmap = mMyCanvas.getBitmap();
145150
FileOutputStream out = null;
146151
try {
147152
final File file = new File(directory, fileName);
@@ -166,7 +171,7 @@ private boolean saveFile(final String fileName) {
166171

167172
private void shareImage() {
168173
final String shareTitle = getResources().getString(R.string.share_via);
169-
final Bitmap bitmap = myCanvas.getBitmap();
174+
final Bitmap bitmap = mMyCanvas.getBitmap();
170175
final Intent sendIntent = new Intent();
171176
final Uri uri = getImageUri(bitmap);
172177
if (uri == null)
@@ -211,7 +216,7 @@ private Uri getImageUri(Bitmap bitmap) {
211216

212217
@OnClick(R.id.undo)
213218
public void undo() {
214-
myCanvas.undo();
219+
mMyCanvas.undo();
215220
}
216221

217222
@OnClick(R.id.color_picker)
@@ -232,12 +237,12 @@ public void onOk(AmbilWarnaDialog dialog, int pickedColor) {
232237

233238
private void setColor(int pickedColor) {
234239
color = pickedColor;
235-
colorPicker.setBackgroundColor(color);
236-
myCanvas.setColor(color);
240+
mColorPicker.setBackgroundColor(color);
241+
mMyCanvas.setColor(color);
237242
}
238243

239244
@Override
240245
public void pathsChanged(int cnt) {
241-
undoBtn.setVisibility(cnt > 0 ? View.VISIBLE : View.GONE);
246+
mUndoBtn.setVisibility(cnt > 0 ? View.VISIBLE : View.GONE);
242247
}
243248
}

0 commit comments

Comments
 (0)