Skip to content

Commit fef5628

Browse files
authored
Merge pull request #30 from MJIrobotics/feature/cleanup-codes
Clean up codes
2 parents 4a9275e + d1ec78a commit fef5628

27 files changed

+578
-1193
lines changed

tapia-sample/app/src/main/java/com/tapia/mji/demo/Actions/GiveDate.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,30 @@
99
*/
1010
public class GiveDate extends MyAction {
1111
public OnGiveDateListener onGiveDateListener;
12-
public GiveDate(OnGiveDateListener giveDateListener){
12+
13+
public GiveDate(OnGiveDateListener giveDateListener) {
1314
super(giveDateListener);
1415
onGiveDateListener = giveDateListener;
1516
type = MyActionType.GIVE_DATE;
1617
}
1718

18-
public Date getMood(){
19+
public Date getMood() {
1920
return onGiveDateListener.date;
2021
}
21-
public void setDate(Date date){
22+
23+
public void setDate(Date date) {
2224
onGiveDateListener.date = date;
2325
}
2426

2527

2628
static public abstract class OnGiveDateListener implements Action.OnActionListener {
2729
protected Date date;
30+
2831
@Override
2932
public void onAction() {
3033
onGiveDate(date);
3134
}
35+
3236
abstract public void onGiveDate(Date date);
3337
}
3438
}

tapia-sample/app/src/main/java/com/tapia/mji/demo/Actions/GiveTime.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,30 @@
99
*/
1010
public class GiveTime extends MyAction {
1111
public OnGiveTimeListener onGiveTimeListener;
12-
public GiveTime(OnGiveTimeListener giveTimeListener){
12+
13+
public GiveTime(OnGiveTimeListener giveTimeListener) {
1314
super(giveTimeListener);
1415
onGiveTimeListener = giveTimeListener;
1516
type = MyActionType.GIVE_TIME;
1617
}
1718

18-
public Date getTime(){
19+
public Date getTime() {
1920
return onGiveTimeListener.time;
2021
}
21-
public void setTime(Date time){
22+
23+
public void setTime(Date time) {
2224
onGiveTimeListener.time = time;
2325
}
2426

2527

2628
static public abstract class OnGiveTimeListener implements Action.OnActionListener {
2729
protected Date time;
30+
2831
@Override
2932
public void onAction() {
3033
onGiveTime(time);
3134
}
35+
3236
abstract public void onGiveTime(Date time);
3337
}
3438
}

tapia-sample/app/src/main/java/com/tapia/mji/demo/Actions/MyAction.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
/**
66
* Abstract class MyAction encapsulates data and methods mostly to facilitate
77
* the NLU's handling of user commands.
8-
*
8+
* <p>
99
* To add actions to Tapia, extend abstract class MyAction.
10-
*
10+
* <p>
1111
* Note: before to add your MyActionType to the enum class here when adding an action to Tapia.
12-
*
12+
* <p>
1313
* Created by Sami on 07-Jul-16.
1414
*/
1515
public abstract class MyAction extends Action {
@@ -18,14 +18,14 @@ public abstract class MyAction extends Action {
1818
*
1919
* @param onActionListener the listener object listening for calls to perform the action.
2020
*/
21-
protected MyAction(OnActionListener onActionListener){
21+
protected MyAction(OnActionListener onActionListener) {
2222
super(onActionListener);
2323
}
2424

2525
/**
2626
* Enum for entity type.
2727
*/
28-
enum MyEntity{
28+
enum MyEntity {
2929
LOCATION,
3030
AGE,
3131
DURATION,

tapia-sample/app/src/main/java/com/tapia/mji/demo/Actions/MySimpleAction.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@
44

55
/**
66
* MySimpleAction class encapsulates a variety of simple actions as public inner classes.
7-
*
7+
* <p>
88
* Many new simple actions can be handled by Tpaia by creating new inner classes here.
9-
*
9+
* <p>
1010
* Note: do not forget to add new actions to the enum class in MyAction.java
11-
*
11+
* <p>
1212
* Created by Sami on 21-Jul-16.
1313
*/
1414
public abstract class MySimpleAction extends MyAction {
1515

1616
public SimpleAction.OnSimpleActionListener onSimpleActionListener;
17-
public MySimpleAction(SimpleAction.OnSimpleActionListener simpleActionListener, ActionType actionType){
17+
18+
public MySimpleAction(SimpleAction.OnSimpleActionListener simpleActionListener, ActionType actionType) {
1819
super(simpleActionListener);
1920
onSimpleActionListener = simpleActionListener;
2021
type = actionType;

tapia-sample/app/src/main/java/com/tapia/mji/demo/Actions/Rotate.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
/**
66
* MyAction extension for rotating tapia.
7-
*
7+
* <p>
88
* Created by Sami on 12-Jul-16.
99
*/
1010
public class Rotate extends MyAction {
1111
public OnRotateListener onRotateListener;
1212

13-
public Rotate(OnRotateListener rotateListener){
13+
public Rotate(OnRotateListener rotateListener) {
1414
super(rotateListener);
1515
onRotateListener = rotateListener;
1616
type = MyActionType.ROTATE;
@@ -21,7 +21,7 @@ public Rotate(OnRotateListener rotateListener){
2121
*
2222
* @param degree the degree of rotation
2323
*/
24-
public void setDegree(int degree){
24+
public void setDegree(int degree) {
2525
onRotateListener.degree = degree;
2626
}
2727

tapia-sample/app/src/main/java/com/tapia/mji/demo/Activities/PhotoMenuActivity.java

+11-11
Original file line numberDiff line numberDiff line change
@@ -16,39 +16,39 @@ public class PhotoMenuActivity extends MenuActivity {
1616
static final int SLEEP = 2;
1717
static final int TAKE_PHOTO = 0;
1818
static final int SHOW_PHOTO = 1;
19-
static final int KeyBoard = 4;
19+
static final int KEY_BOARD = 4;
2020
static final int ROTATION = 5;
2121

2222
@Override
2323
public ArrayList<MenuItem> setMenuList() {
2424
ArrayList<MenuItem> menuItems = new ArrayList<>();
25-
menuItems.add(new MenuItem(TALK, "TALK"));
25+
menuItems.add(new MenuItem(TALK, "Talk"));
2626
menuItems.add(new MenuItem(SLEEP, "Sleep"));//add item with an id to easily find it.
27-
menuItems.add(new MenuItem(TAKE_PHOTO, "take \n photo"));
27+
menuItems.add(new MenuItem(TAKE_PHOTO, "Take \n photo"));
2828
//Can also adjust the size of the text to make it fit in the bubble
29-
menuItems.add(new MenuItem(SHOW_PHOTO, "show my photo", 16));
30-
menuItems.add(new MenuItem(KeyBoard, "KeyBoard", 16));//<<追加します。
29+
menuItems.add(new MenuItem(SHOW_PHOTO, "Show \nmy photo", 40));
30+
menuItems.add(new MenuItem(KEY_BOARD, "Keyboard", 40));//<<追加します。
3131
menuItems.add(new MenuItem(ROTATION, "Rotation", 40));
3232
return menuItems;
3333
}
3434

3535
@Override
3636
public void onItemClick(MenuItem item) {
37-
switch (item.id){
37+
switch (item.id) {
3838
case TAKE_PHOTO:
39-
startActivity(new Intent(TapiaApp.getAppContext(),PhotoTakeActivity.class));
39+
startActivity(new Intent(TapiaApp.getAppContext(), PhotoTakeActivity.class));
4040
break;
4141
case SHOW_PHOTO:
42-
startActivity(new Intent(TapiaApp.getAppContext(),PhotoShowActivity.class));
42+
startActivity(new Intent(TapiaApp.getAppContext(), PhotoShowActivity.class));
4343
break;
4444
case TALK:
45-
startActivity(new Intent(TapiaApp.getAppContext(),TalkActivity.class));
45+
startActivity(new Intent(TapiaApp.getAppContext(), TalkActivity.class));
4646
break;
4747
case SLEEP:
4848
finish();
4949
break;
50-
case KeyBoard:
51-
startActivity(new Intent(TapiaApp.getAppContext(),TestJapaneseKeyBoard.class));//<<追加します。
50+
case KEY_BOARD:
51+
startActivity(new Intent(TapiaApp.getAppContext(), TestJapaneseKeyBoard.class));//<<追加します。
5252
break;
5353
case ROTATION:
5454
startActivity(new Intent(TapiaApp.getAppContext(), RotationActivity.class));

tapia-sample/app/src/main/java/com/tapia/mji/demo/Activities/PhotoShowActivity.java

+38-50
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import android.graphics.drawable.Drawable;
44
import android.os.Bundle;
5-
import android.view.View;
65
import android.view.ViewGroup;
76
import android.widget.ImageButton;
87
import android.widget.ImageView;
@@ -28,7 +27,7 @@ public class PhotoShowActivity extends TapiaActivity {
2827

2928
PhotoShowAdapter photoAdapter;
3029
ListView photoList;
31-
int setcted=0;
30+
int setcted = 0;
3231
String fileName;
3332
File dest;
3433
String dirPath;
@@ -40,15 +39,15 @@ public class PhotoShowActivity extends TapiaActivity {
4039
public List<PhotoListItem> curPhotoList;
4140
public String selectedPhoto;
4241

43-
public class PhotoListItem{
42+
public class PhotoListItem {
4443
public String[] pictureNames;
4544
public ImageView[] picturesView;
4645

47-
PhotoListItem(String[] photosName){
46+
PhotoListItem(String[] photosName) {
4847
pictureNames = new String[PHOTO_BY_LINE];
4948
picturesView = new ImageView[PHOTO_BY_LINE];
5049
int index = 0;
51-
for (String pName:photosName) {
50+
for (String pName : photosName) {
5251
pictureNames[index] = pName;
5352
picturesView[index] = new ImageView(activity);
5453
index++;
@@ -60,90 +59,79 @@ public class PhotoListItem{
6059
protected void onCreate(Bundle savedInstanceState) {
6160
super.onCreate(savedInstanceState);
6261
setContentView(R.layout.activity_showphoto);
63-
local = (ImageButton)findViewById(R.id.localButton);
64-
sdcard = (ImageButton)findViewById(R.id.sdcardButton);
65-
home = (ImageButton)findViewById(R.id.homeButton);
66-
photoList = (ListView)findViewById(android.R.id.list);
62+
local = findViewById(R.id.localButton);
63+
sdcard = findViewById(R.id.sdcardButton);
64+
home = findViewById(R.id.homeButton);
65+
photoList = findViewById(android.R.id.list);
6766
// dirPath = CameraHelper.PICTURE_FOLDER;
6867
dirPathThumbnail = CameraHelper.SMALL_PICTURE_FOLDER;
6968
loadPictures(dirPathThumbnail);
70-
photoAdapter = new PhotoShowAdapter(activity,curPhotoList);
69+
photoAdapter = new PhotoShowAdapter(activity, curPhotoList);
7170
photoList.setAdapter(photoAdapter);
7271

7372
TapiaApp.setCustomViewBackground(((ViewGroup) findViewById(android.R.id.content)).getChildAt(0).getBackground());
7473

7574
local.setSelected(true);
7675
sdcard.setSelected(false);
7776

78-
sttProvider = TapiaApp.currentLanguage.getOnlineSTTProvider();
79-
ttsProvider = TapiaApp.currentLanguage.getTTSProvider();
80-
offlineNLUProvider = TapiaApp.currentLanguage.getOfflineNLUProvider();
81-
82-
home.setOnClickListener(new View.OnClickListener() {
83-
@Override
84-
public void onClick(View v) {
85-
finish();
86-
}
77+
sttProvider = TapiaApp.currentLanguage.getOnlineSTTProvider();
78+
ttsProvider = TapiaApp.currentLanguage.getTTSProvider();
79+
offlineNLUProvider = TapiaApp.currentLanguage.getOfflineNLUProvider();
80+
81+
home.setOnClickListener(v -> finish());
82+
sdcard.setOnClickListener(v -> {
83+
sdcard.setSelected(true);
84+
local.setSelected(false);
85+
dirPathThumbnail = "/storage/sdcard1/";//set to the sdcard path
86+
loadPictures(dirPathThumbnail);
87+
photoAdapter.refresh(curPhotoList);
8788
});
88-
sdcard.setOnClickListener(new View.OnClickListener() {
89-
@Override
90-
public void onClick(View v) {
91-
sdcard.setSelected(true);
92-
local.setSelected(false);
93-
dirPathThumbnail = "/storage/sdcard1/";//set to the sdcard path
94-
loadPictures(dirPathThumbnail);
95-
photoAdapter.refresh(curPhotoList);
96-
}
97-
});
98-
local.setOnClickListener(new View.OnClickListener() {
99-
@Override
100-
public void onClick(View v) {
101-
local.setSelected(true);
102-
sdcard.setSelected(false);
103-
dirPathThumbnail = CameraHelper.SMALL_PICTURE_FOLDER;
104-
loadPictures(dirPathThumbnail);
105-
photoAdapter.refresh(curPhotoList);
106-
}
89+
local.setOnClickListener(v -> {
90+
local.setSelected(true);
91+
sdcard.setSelected(false);
92+
dirPathThumbnail = CameraHelper.SMALL_PICTURE_FOLDER;
93+
loadPictures(dirPathThumbnail);
94+
photoAdapter.refresh(curPhotoList);
10795
});
10896

10997
}
11098

11199

112-
void loadPictures(String path){
100+
void loadPictures(String path) {
113101
File picFile = new File(path);
114102
curPhotoList = new ArrayList<>();
115103
String[] itemPictureList = new String[PHOTO_BY_LINE];
116104
int itemPicIndex = 0;
117-
if(picFile.exists() && picFile.isDirectory() && picFile.list() != null){
118-
for (String pName: picFile.list()) {
119-
if(pName.contains(".jpeg") || pName.contains(".jpg") || pName.contains(".png")){
105+
if (picFile.exists() && picFile.isDirectory() && picFile.list() != null) {
106+
for (String pName : picFile.list()) {
107+
if (pName.contains(".jpeg") || pName.contains(".jpg") || pName.contains(".png")) {
120108
itemPictureList[itemPicIndex] = path + pName;
121109
itemPicIndex++;
122-
if(itemPicIndex == PHOTO_BY_LINE){
110+
if (itemPicIndex == PHOTO_BY_LINE) {
123111
curPhotoList.add(new PhotoListItem(itemPictureList));
124112
itemPicIndex = 0;
125113
}
126114
}
127115
}
128116

129-
if(itemPicIndex > 0){
130-
for(int i = itemPicIndex; i<PHOTO_BY_LINE;i++) {
117+
if (itemPicIndex > 0) {
118+
for (int i = itemPicIndex; i < PHOTO_BY_LINE; i++) {
131119
itemPictureList[i] = null;
132120
}
133121
curPhotoList.add(new PhotoListItem(itemPictureList));
134122
}
135123
}
136124
}
137125

138-
public void refreshList(){
126+
public void refreshList() {
139127
loadPictures(dirPathThumbnail);
140128
photoAdapter.refresh(curPhotoList);
141129
}
142130

143-
public Drawable findImageView(String photoName){
144-
for (PhotoListItem photoItem: curPhotoList) {
145-
for(int i = 0; i < PHOTO_BY_LINE; i++){
146-
if(photoItem.pictureNames[i].equals(photoName))
131+
public Drawable findImageView(String photoName) {
132+
for (PhotoListItem photoItem : curPhotoList) {
133+
for (int i = 0; i < PHOTO_BY_LINE; i++) {
134+
if (photoItem.pictureNames[i].equals(photoName))
147135
return photoItem.picturesView[i].getDrawable();
148136
}
149137
}

0 commit comments

Comments
 (0)