Skip to content

Commit 4ecb008

Browse files
committed
add random name generator,
ui changes
1 parent 413bbc5 commit 4ecb008

File tree

9 files changed

+5987
-24
lines changed

9 files changed

+5987
-24
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
/build
88
/captures
99
.externalNativeBuild
10-
.idea
1110
libs
1211
.idea/compiler.xml
1312
.idea/copyright/

.idea/misc.xml

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/androidTest/java/io/gloop/drawed/ExampleInstrumentedTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import org.junit.Test;
88
import org.junit.runner.RunWith;
99

10-
import static org.junit.Assert.*;
10+
import static org.junit.Assert.assertEquals;
1111

1212
/**
1313
* Instrumentation test, which will execute on an Android device.

app/src/main/java/io/gloop/drawed/BoardListActivity.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import io.gloop.GloopOnChangeListener;
2828
import io.gloop.drawed.model.Board;
2929
import io.gloop.drawed.utils.ColorUtil;
30+
import io.gloop.drawed.utils.NameUtil;
3031

3132
/**
3233
* An activity representing a list of Items. This activity
@@ -55,6 +56,10 @@ protected void onCreate(Bundle savedInstanceState) {
5556

5657
showIntroOnFirstRun();
5758

59+
//set username
60+
TextView username = (TextView) findViewById(R.id.user_name);
61+
username.setText(NameUtil.randomUserName(getApplicationContext())); // TODO at the moment name is randomly generated every time the app starts
62+
5863
View recyclerView = findViewById(R.id.item_list);
5964
assert recyclerView != null;
6065
setupRecyclerView((RecyclerView) recyclerView);
@@ -71,8 +76,10 @@ protected void onCreate(Bundle savedInstanceState) {
7176
public void onClick(View view) {
7277

7378
Board board = new Board();
74-
board.setName("Test".toUpperCase()); // TODO set name of board
75-
board.setColor(ColorUtil.randomColor(getApplicationContext()));
79+
String colorName = NameUtil.randomColor(getApplicationContext());
80+
board.setName(NameUtil.randomAdjective(getApplicationContext()) + colorName + NameUtil.randomObject(getApplicationContext()));
81+
// board.setColor(ColorUtil.randomColor(getApplicationContext()));
82+
board.setColor(ColorUtil.getColorByName(getApplicationContext(), colorName));
7683
board.save();
7784

7885
if (mTwoPane) {
@@ -171,7 +178,7 @@ public void onBindViewHolder(final ViewHolder holder, final int position) {
171178

172179
final Board board = mValues.get(position);
173180

174-
holder.mContentView.setText(board.getName().toUpperCase());
181+
holder.mContentView.setText(board.getName());
175182
if (board.isPrivateBoard())
176183
holder.mImagePrivate.setVisibility(View.VISIBLE);
177184
else {

app/src/main/java/io/gloop/drawed/DrawingView.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ protected void onDraw(Canvas canvas) {
107107
canvas.drawPath(drawPath, drawPaint);
108108
}
109109

110-
111110
private List<Point> line;
112111

113112
//register user touches as drawing action
@@ -116,8 +115,6 @@ public boolean onTouchEvent(MotionEvent event) {
116115
float touchX = event.getX();
117116
float touchY = event.getY();
118117

119-
// if (touchX != 0 && touchY != 0) {
120-
121118
//respond to down, move and up events
122119
switch (event.getAction()) {
123120
case MotionEvent.ACTION_DOWN:
@@ -142,14 +139,13 @@ public boolean onTouchEvent(MotionEvent event) {
142139
}
143140
GloopLogger.i("BrushSize: " + brushSize);
144141
board.addLine(new Line(line, paintColor, (int) brushSize));
145-
board.save();
142+
board.save(); // TODO save in background
146143
line = null;
147144
GloopLogger.i("Action up");
148145
break;
149146
default:
150147
return false;
151148
}
152-
// }
153149
//redraw
154150
invalidate();
155151
return true;

app/src/main/java/io/gloop/drawed/utils/ColorUtil.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
import android.content.Context;
44
import android.content.res.TypedArray;
55
import android.graphics.Color;
6+
import android.support.v4.content.res.ResourcesCompat;
7+
8+
import java.lang.reflect.Field;
9+
10+
import io.gloop.drawed.R;
611

712
/**
813
* Util to get random generated colors.
@@ -11,6 +16,24 @@
1116
*/
1217
public class ColorUtil {
1318

19+
20+
public static int getColorByName(Context context, String name) {
21+
int colorId = 0;
22+
23+
try {
24+
Class res = R.color.class;
25+
Field field = res.getField(name);
26+
colorId = field.getInt(null);
27+
} catch (Exception e) {
28+
e.printStackTrace();
29+
}
30+
31+
if (colorId == 0)
32+
return randomColor(context);
33+
return ResourcesCompat.getColor(context.getResources(), colorId, null); //without theme
34+
35+
}
36+
1437
// TODO fix does not work
1538
private static int previousColor;
1639

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,44 @@
11
package io.gloop.drawed.utils;
22

3+
import android.content.Context;
4+
5+
import java.util.Random;
6+
7+
import io.gloop.drawed.R;
8+
39
/**
410
* Created by Alex Untertrifaller on 20.02.17.
511
*/
612

713
public class NameUtil {
814

9-
public static String randomUserName() {
10-
return randomAdjective() + randomColor() + randomAnimal();
11-
}
15+
private static final Random random = new Random();
1216

13-
public static String randomBoardName() {
14-
return randomAdjective() + randomColor() + randomObject();
17+
public static String randomUserName(Context context) {
18+
return randomAdjective(context) + randomColor(context) + randomAnimal(context);
1519
}
1620

17-
private static String randomAdjective() {
18-
return ""; // TODO impl
21+
// public static String randomBoardName(Context context) {
22+
// return randomAdjective(context) + randomColor(context) + randomObject(context);
23+
// }
24+
25+
public static String randomAdjective(Context context) {
26+
String[] myString = context.getResources().getStringArray(R.array.adjectives);
27+
return myString[random.nextInt(myString.length)];
1928
}
2029

21-
private static String randomColor() {
22-
return ""; // TODO impl
30+
public static String randomColor(Context context) {
31+
String[] myString = context.getResources().getStringArray(R.array.colors);
32+
return myString[random.nextInt(myString.length)];
2333
}
2434

25-
private static String randomAnimal() {
26-
return ""; // TODO impl
35+
public static String randomAnimal(Context context) {
36+
String[] myString = context.getResources().getStringArray(R.array.animals);
37+
return myString[random.nextInt(myString.length)];
2738
}
2839

29-
private static String randomObject() {
30-
return ""; // TODO impl
40+
public static String randomObject(Context context) {
41+
String[] myString = context.getResources().getStringArray(R.array.objects);
42+
return myString[random.nextInt(myString.length)];
3143
}
3244
}

app/src/main/res/values/colors.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,14 @@
1515
<color name="color4">#4251B2</color>
1616
<color name="color5">#79B049</color>
1717
<color name="color6">#D52A6D</color>
18+
19+
20+
<color name="Blue">#4354AF</color>
21+
<color name="Red">#E34346</color>
22+
<color name="Green">#7BAF4F</color>
23+
<color name="Yellow">#FDB12F</color>
24+
<color name="Purple">#8D38B2</color>
25+
<color name="Orange">#ffa100</color>
26+
<color name="Pink">#D52A6D</color>
27+
<color name="Violet">#6b0597</color>
1828
</resources>

0 commit comments

Comments
 (0)