Skip to content

Commit a279c5c

Browse files
committed
update soundActivity
1 parent b44959f commit a279c5c

15 files changed

+365
-64
lines changed

.idea/misc.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/AndroidManifest.xml

+4-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
android:supportsRtl="true"
2424
android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen"
2525
android:usesCleartextTraffic="true">
26-
<activity android:name=".InfoActivity"
27-
android:screenOrientation="landscape"></activity>
26+
<activity android:name=".PopUpActivity"></activity>
27+
<activity
28+
android:name=".InfoActivity"
29+
android:screenOrientation="landscape" />
2830
<activity
2931
android:name=".PhotoActivity"
3032
android:screenOrientation="landscape" />

app/src/main/java/com/example/gaid/InfoActivity.java

+36-3
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,22 @@
88
import android.widget.ImageView;
99
import android.widget.TextView;
1010

11+
import com.example.gaid.model.get_info.GetInfoRequestDTO;
12+
import com.example.gaid.model.get_info.GetInfoResponseDTO;
13+
import com.example.gaid.util.RestApiUtil;
14+
15+
import retrofit2.Call;
16+
import retrofit2.Callback;
17+
import retrofit2.Response;
18+
1119
public class InfoActivity extends Activity {
1220
private ImageView imgview;
1321
private TextView tv_profname,tv_etc,tv_tel,tv_dept;
1422
private Intent intent;
15-
private String user_text="";
23+
private String mRoomNumber="";
24+
25+
private RestApiUtil mRestApiUtil;
26+
private GetInfoRequestDTO mGetInfoRequestDTO;
1627
@Override
1728
protected void onCreate(Bundle savedInstanceState) {
1829
super.onCreate(savedInstanceState);
@@ -22,8 +33,30 @@ protected void onCreate(Bundle savedInstanceState) {
2233
tv_tel=(TextView)findViewById(R.id.tv_tel);
2334

2435
intent=getIntent();
25-
user_text=intent.getStringExtra("text");
26-
System.out.println("testtext :"+user_text );
36+
mRoomNumber=intent.getStringExtra("roomNo");
37+
System.out.println("roomNo :" + mRoomNumber);
2738
///형걸이형 여기야여기!
39+
mRestApiUtil = new RestApiUtil();
40+
mGetInfoRequestDTO = new GetInfoRequestDTO();
41+
getInfo();
42+
}
43+
44+
public void getInfo() {
45+
mRestApiUtil.getApi().get_info(mGetInfoRequestDTO).enqueue(new Callback<GetInfoResponseDTO>() {
46+
@Override
47+
public void onResponse(Call<GetInfoResponseDTO> call, Response<GetInfoResponseDTO> response) {
48+
if(response.isSuccessful()) {
49+
50+
}
51+
else {
52+
53+
}
54+
}
55+
56+
@Override
57+
public void onFailure(Call<GetInfoResponseDTO> call, Throwable t) {
58+
59+
}
60+
});
2861
}
2962
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package com.example.gaid;
2+
3+
import androidx.appcompat.app.AppCompatActivity;
4+
5+
import android.content.Intent;
6+
import android.os.Bundle;
7+
import android.speech.RecognizerIntent;
8+
import android.speech.SpeechRecognizer;
9+
import android.speech.tts.TextToSpeech;
10+
import android.util.Log;
11+
import android.view.MotionEvent;
12+
import android.view.View;
13+
import android.widget.Button;
14+
15+
import java.util.Locale;
16+
17+
public class PopUpActivity extends AppCompatActivity implements TextToSpeech.OnInitListener{
18+
19+
private TextToSpeech textToSpeech;
20+
private Button mButton_info;
21+
private Button mButton_map;
22+
private SpeechRecognizer mRecognizer;
23+
private Intent mIntent;
24+
25+
@Override
26+
protected void onCreate(Bundle savedInstanceState) {
27+
super.onCreate(savedInstanceState);
28+
setContentView(R.layout.activity_pop_up);
29+
30+
init();
31+
speakOut("어떤 기능을 원하시나요");
32+
initListener();
33+
}
34+
35+
public void init() {
36+
mButton_info = findViewById(R.id.btn_info);
37+
mButton_map = findViewById(R.id.btn_map);
38+
textToSpeech = new TextToSpeech(this, this);
39+
mIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
40+
mIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,getPackageName());
41+
mIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE,"ko-KR");
42+
// mRecognizer= SpeechRecognizer.createSpeechRecognizer(this);
43+
// mRecognizer.setRecognitionListener(listener);
44+
}
45+
46+
public void initListener() {
47+
mButton_info.setOnClickListener(new View.OnClickListener() {
48+
@Override
49+
public void onClick(View v) {
50+
speakOut("길 찾기 기능을 찾으셨군요");
51+
Intent intent = new Intent(getApplicationContext(), MapActivity.class);
52+
startActivity(intent);
53+
finish();
54+
}
55+
});
56+
57+
mButton_map.setOnClickListener(new View.OnClickListener() {
58+
@Override
59+
public void onClick(View v) {
60+
speakOut("안내 기능을 찾으셨군요");
61+
Intent intent = new Intent(getApplicationContext(), InfoActivity.class);
62+
startActivity(intent);
63+
finish();
64+
}
65+
});
66+
}
67+
68+
public void speakOut(String text) {
69+
textToSpeech.speak(text, TextToSpeech.QUEUE_FLUSH, null);
70+
boolean speakingEnd = textToSpeech.isSpeaking();
71+
Log.d("TTS", "SPOKE");
72+
do{
73+
speakingEnd = textToSpeech.isSpeaking();
74+
} while (speakingEnd);
75+
Log.d("done","spoke Done");
76+
// if(text.equals("안녕하세요 대양AI센터 입니다 무엇을 도와드릴까요?")) {
77+
// mRecognizer.startListening(mIntent);
78+
// }
79+
}
80+
81+
@Override
82+
public boolean onTouchEvent(MotionEvent event) {
83+
//바깥레이어 클릭시 안닫히게
84+
if(event.getAction() == MotionEvent.ACTION_OUTSIDE) {
85+
return false;
86+
}
87+
return true;
88+
}
89+
90+
@Override
91+
public void onInit(int status) {
92+
if (status == TextToSpeech.SUCCESS) {
93+
int result = textToSpeech.setLanguage(Locale.KOREA);
94+
// tts.setPitch(5); // set pitch level
95+
// tts.setSpeechRate(2); // set speech speed rate
96+
if (result == TextToSpeech.LANG_MISSING_DATA
97+
|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
98+
Log.e("TTS", "Language is not supported");
99+
}
100+
else {
101+
}
102+
}
103+
else {
104+
Log.e("TTS", "Initilization Failed");
105+
}
106+
}
107+
}

app/src/main/java/com/example/gaid/SoundActivity.java

+63-56
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
import android.widget.Toast;
1818

1919
import com.airbnb.lottie.LottieAnimationView;
20+
import com.example.gaid.model.get_case.GetCaseRequestDTO;
21+
import com.example.gaid.model.get_case.GetCaseResponseDTO;
22+
import com.example.gaid.util.RestApiUtil;
2023

2124
import java.util.ArrayList;
2225
import java.util.List;
@@ -25,6 +28,9 @@
2528
import kr.co.shineware.nlp.komoran.core.Komoran;
2629
import kr.co.shineware.nlp.komoran.model.KomoranResult;
2730
import kr.co.shineware.nlp.komoran.model.Token;
31+
import retrofit2.Call;
32+
import retrofit2.Callback;
33+
import retrofit2.Response;
2834

2935

3036
public class SoundActivity extends Activity implements TextToSpeech.OnInitListener{
@@ -36,6 +42,9 @@ public class SoundActivity extends Activity implements TextToSpeech.OnInitListen
3642
Intent intent;
3743
SpeechRecognizer mRecognizer;
3844

45+
private RestApiUtil mRestApiUtil;
46+
private GetCaseRequestDTO mGetCaseRequestDTO;
47+
private GetCaseResponseDTO mGetCaseResponseDTO;
3948
private String mCase;
4049
//Komoran 형태소 분석기
4150
private Komoran mKomoran;
@@ -81,8 +90,12 @@ public void init()
8190
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE,"ko-KR");
8291
mRecognizer= SpeechRecognizer.createSpeechRecognizer(this);
8392
mRecognizer.setRecognitionListener(listener);
93+
94+
mGetCaseRequestDTO = new GetCaseRequestDTO();
95+
mRestApiUtil = new RestApiUtil();
8496
}
85-
private void speakOut(String text) {
97+
98+
public void speakOut(String text) {
8699
textToSpeech.speak(text, TextToSpeech.QUEUE_FLUSH, null);
87100
boolean speakingEnd = textToSpeech.isSpeaking();
88101
Log.d("TTS", "SPOKE");
@@ -162,64 +175,39 @@ public void onError(int error) {
162175
public void onResults(Bundle results) {
163176
// 말을 하면 ArrayList에 단어를 넣고 textView에 단어를 이어줍니다.
164177

165-
mKomoran = new Komoran("models_full");
166-
mKomoran.setFWDic("user_data/fwd.user");
167-
mKomoran.setUserDic("user_data/dic.user");
168-
169178
String text = "";
170179
ArrayList<String> matches =
171180
results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
172181
animationView.cancelAnimation();
173182

174-
// for(int i = 0; i < matches.size() ; i++){
175-
// sttResultTextView.setText(matches.get(i));
176-
// }
183+
for(int i = 0; i < matches.size() ; i++){
184+
sttResultTextView.setText(matches.get(i));
185+
}
177186

178-
sttResultTextView.setText(matches.get(0));
179187
text = sttResultTextView.getText().toString();
180188

181-
KomoranResult analyzeResultList = mKomoran.analyze(text);
182-
//List<Token> tokenList = analyzeResultList.getTokenList();
183-
mCase = checkCase(analyzeResultList.getMorphesByTags("VV", "NP", "NNG", "SN")); //NNB
189+
mGetCaseRequestDTO.setMorph(text);
190+
mCase = getCase(mGetCaseRequestDTO);
184191

185-
186-
if (mCase.contains("MapActivity")) {
192+
if (mCase.contains("MapActivity")) { //길 찾기
187193
speakOut("길찾기기능을 찾으셨군요");
188194
Intent intent = new Intent(getApplicationContext(), MapActivity.class);
189195
startActivity(intent);
190-
<<<<<<< HEAD
191196
}
192-
else if (text.contains("소개")) {
193-
speakOut("소개 해달라구요?");
194-
195-
}
196-
else if (mCase.contains("TakepictureActivity")) {
197-
=======
198-
} else if (text.contains("소개")||text.contains("소계")||text.contains("속의")) {
199-
speakOut("소개 해달라구요?");
200-
Intent intent = new Intent(getApplicationContext(), InfoActivity.class);
201-
startActivity(intent);
202-
203-
} else if (text.contains("사진")) {
204-
>>>>>>> c2fbbb25dea3c83ee7c67cbef7574f326c204077
197+
else if (mCase.contains("TakepictureActivity")) { //기념 사진
205198
speakOut("기념사진찍어드릴게요");
206199
Intent intent = new Intent(getApplicationContext(), TakepictureActivity.class);
207200
startActivity(intent);
208201
}
209-
else if (text.contains("대양")) {
210-
speakOut("대양이를 불르셨어요?");
211-
Intent intent = new Intent(getApplicationContext(), SoundActivity.class);
202+
else if (mCase.contains("InfoActivity")) {
203+
speakOut("소개 해달라구요?");
204+
Intent intent = new Intent(getApplicationContext(), InfoActivity.class);
205+
intent.putExtra("roomNo", mGetCaseResponseDTO.getRoomNo());
212206
startActivity(intent);
213-
<<<<<<< HEAD
214-
=======
215-
} else {
216-
speakOut("다시 한번 말해주세요");
217-
mRecognizer.startListening(intent);
218-
219-
>>>>>>> c2fbbb25dea3c83ee7c67cbef7574f326c204077
220207
}
221208
else {
222-
speakOut("다시 한번 말해주세요.");
209+
speakOut("다시 한번 말해주세요");
210+
mRecognizer.startListening(intent);
223211
}
224212

225213
// if (text.contains("길")||text.contains("어떻게 가")||text.contains("어디에 있어")) {
@@ -274,30 +262,49 @@ public void onInit(int status) {
274262
}
275263
}
276264

277-
public String checkCase(List<String> analyzeResultList) {
265+
public String checkCase() {
278266
String checkCase = null;
279-
if (analyzeResultList.contains("가")) { //길 찾기
280-
checkCase = "MapActivity";
281-
} else if (analyzeResultList.contains("찾")) { //길 찾기
282-
checkCase = "MapActivity";
283-
} else if (analyzeResultList.contains("찍")) { //기념사진
284-
checkCase = "TakepictureActivity";
285-
}
286267

287-
if (analyzeResultList.contains("어디")) { //길 찾기
268+
if (mGetCaseResponseDTO.getFunction().contains("navi")) { //길 찾기 //MapActivity
288269
checkCase = "MapActivity";
289270
}
290-
291-
if (analyzeResultList.contains("길")) { //길 찾기
292-
checkCase = "MapActivity";
293-
} else if (analyzeResultList.contains("소개")) { //안내
294-
295-
} else if (analyzeResultList.contains("사진")) { // 기념사진
296-
checkCase = "TakepictureActivity";
297-
} else if (analyzeResultList.contains("촬영")) { //기념사진
271+
else if (mGetCaseResponseDTO.getFunction().contains("info")) { //안내 //InfoActivity
272+
checkCase = "InfoActivity";
273+
}
274+
else if (mGetCaseResponseDTO.getFunction().contains("cam")) { //기념사진 //TakepictureActivity
298275
checkCase = "TakepictureActivity";
299276
}
277+
//else if (mGetCaseResponseDTO) { //길찾기인가 안내인가 // navi_info
278+
// checkCase = "PopUpActivity";
279+
//}
300280

301281
return checkCase;
302282
}
283+
284+
public String getCase(GetCaseRequestDTO mGetCaseRequestDTO) {
285+
String activityCase = "";
286+
mRestApiUtil.getApi().get_case(mGetCaseRequestDTO).enqueue(new Callback<GetCaseResponseDTO>() {
287+
@Override
288+
public void onResponse(Call<GetCaseResponseDTO> call, Response<GetCaseResponseDTO> response) {
289+
if(response.isSuccessful()) {
290+
mGetCaseResponseDTO = response.body();
291+
checkCase();
292+
}
293+
else {
294+
System.out.println("onResponse 에서 에러남. not response.isSuccessful");
295+
speakOut("정확하게 다시 한번 말해주세요");
296+
mRecognizer.startListening(intent);
297+
}
298+
}
299+
300+
@Override
301+
public void onFailure(Call<GetCaseResponseDTO> call, Throwable t) {
302+
System.out.println("onFailure, t.getMessage : " + t.getMessage());
303+
speakOut("정확하게 다시 한번 말해주세요");
304+
mRecognizer.startListening(intent);
305+
}
306+
});
307+
308+
return activityCase;
309+
}
303310
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.example.gaid.data;
2+
3+
import com.example.gaid.model.get_case.GetCaseResponseDTO;
4+
5+
import retrofit2.Callback;
6+
7+
public interface CaseRepository {
8+
void getCaseResponseData(Callback<GetCaseResponseDTO> callback);
9+
}

app/src/main/java/com/example/gaid/data/LocationWeatherRepository.java

-2
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@ public class LocationWeatherRepository implements WeatherRepository {
99

1010
private WeatherUtil mWeatherUtil;
1111

12-
1312
public LocationWeatherRepository() {
1413
mWeatherUtil = new WeatherUtil();
1514
}
1615

17-
1816
@Override
1917
public boolean isAvailable() {
2018
return true;

0 commit comments

Comments
 (0)