Skip to content

Commit

Permalink
Project completed.
Browse files Browse the repository at this point in the history
  • Loading branch information
Antxl authored and Antxl committed Jun 18, 2020
1 parent b2cb66e commit 9ddbde0
Show file tree
Hide file tree
Showing 10 changed files with 376 additions and 314 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<application
android:name=".DHUGuiderApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:icon="@drawable/logo"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package dhu.cst.zhangxuhong171310126.dhuguider.activities;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.PointF;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.speech.tts.TextToSpeech;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -18,6 +21,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.drawerlayout.widget.DrawerLayout;

import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
import com.luck.picture.lib.PictureSelectionModel;
Expand All @@ -28,10 +32,12 @@
import com.xuexiang.xui.widget.actionbar.TitleBar;
import com.xuexiang.xui.widget.button.shadowbutton.ShadowButton;
import com.xuexiang.xui.widget.dialog.MiniLoadingDialog;
import com.xuexiang.xui.widget.guidview.GuideCaseView;
import com.xuexiang.xui.widget.searchview.MaterialSearchView;

import java.io.File;
import java.util.List;
import java.util.Locale;

import butterknife.BindView;
import butterknife.ButterKnife;
Expand All @@ -45,9 +51,13 @@
import dhu.cst.zhangxuhong171310126.dhuguider.utils.LocationResources;
import dhu.cst.zhangxuhong171310126.dhuguider.utils.Recorder;

public class MainActivity extends AppCompatActivity {
public class MainActivity extends AppCompatActivity implements TextToSpeech.OnInitListener{
@BindView(R.id.drawer)
DrawerLayout menu;
@BindView(R.id.cam_btn)
ShadowButton camBtn;
@BindView(R.id.que_btn)
ShadowButton qaBtn;
@BindView(R.id.voice_btn)
ImageButton voiceBtn;
@BindView(R.id.search_view)
Expand All @@ -68,6 +78,8 @@ public class MainActivity extends AppCompatActivity {
private BDPicSearchUtil util;
private MiniLoadingDialog dialog;
private ImageView pointer;
private TextToSpeech tts;
private boolean shouldAnswer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -82,11 +94,16 @@ protected void onCreate(Bundle savedInstanceState) {
handler=new ResponseHandler();
util=new BDPicSearchUtil();
pointer=null;
tts=new TextToSpeech(this,this);
shouldAnswer=false;
}

private void initComponents()
{
title.disableLeftView()
title.setLeftImageResource(R.drawable.ic_baseline_menu_24)
.setLeftClickListener(v -> {
menu.openDrawer(Gravity.LEFT);
})
.addAction(new TitleBar.ImageAction(R.drawable.ic_baseline_search_24) {
@Override
public void performAction(View view) {
Expand Down Expand Up @@ -148,38 +165,88 @@ private void doSearch(String keyword)
}
if (dialog.isLoading())
dialog.dismiss();
if (dest!=null){
final PointF target=dest.getCenterPF();
map.animateCenter(dest.getCenterPF())
.withDuration(500)
.withOnAnimationEventListener(new SubsamplingScaleImageView.OnAnimationEventListener() {
@Override
public void onComplete() {
if (pointer!=null)
pointer.setVisibility(View.GONE);
pointer=new ImageView(root.getContext());
pointer.setImageResource(R.drawable.ic_baseline_location_on_24);
PointF dest=map.sourceToViewCoord(target);
root.addView(pointer,new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
pointer.setX(dest.x);
pointer.setY(0);
pointer.animate()
.translationYBy(dest.y)
.setDuration(500)
.start();
}
if (shouldAnswer){
if (dest!=null){
if (keyword.contains("哪")||keyword.contains("介绍")||keyword.contains("讲")){
if (keyword.contains("哪"))
tts.speak(dest.getName()+"位于"+dest.getDirection(), TextToSpeech.QUEUE_FLUSH, null,"answerWhere");
if (keyword.contains("介绍")||keyword.contains("讲"))
tts.speak(getResources().getString(dest.getDescriptionResource()),TextToSpeech.QUEUE_FLUSH, null,"introduce");
}
else
tts.speak("我不太清楚您想问的是什么,能不能换一个简单一点的问法?",TextToSpeech.QUEUE_FLUSH, null,"introduce");
}
else
tts.speak("没有找到您想知道的地方,或许它还没有收录。",TextToSpeech.QUEUE_FLUSH, null,"introduce");
shouldAnswer=false;
}
else{
if (dest!=null){
final PointF target=dest.getCenterPF();
map.animateCenter(dest.getCenterPF())
.withDuration(500)
.withOnAnimationEventListener(new SubsamplingScaleImageView.OnAnimationEventListener() {
@Override
public void onComplete() {
if (pointer!=null)
pointer.setVisibility(View.GONE);
pointer=new ImageView(root.getContext());
pointer.setImageResource(R.drawable.ic_baseline_location_on_24);
PointF dest=map.sourceToViewCoord(target);
root.addView(pointer,new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
pointer.setX(dest.x);
pointer.setY(0);
pointer.animate()
.translationYBy(dest.y)
.setDuration(500)
.start();
}

@Override
public void onInterruptedByUser() {
}
@Override
public void onInterruptedByUser() {
}

@Override
public void onInterruptedByNewAnim() {
}
}).start();
@Override
public void onInterruptedByNewAnim() {
}
}).start();
}
else
Toast.makeText(this,"没有结果哦,可能这个地点还没收录呢",Toast.LENGTH_SHORT).show();
}
else
Toast.makeText(this,"没有结果哦,可能这个地点还没收录呢",Toast.LENGTH_SHORT).show();
}

public void click_btn1(View v){
int[] location=new int[2];
camBtn.getLocationOnScreen(location);
new GuideCaseView.Builder(this)
.focusRectAtPosition(location[0], (int)title.getY()+50, 230, 75)
.roundRectRadius(60)
.focusBorderColor(Color.GREEN)
.build()
.show();
}

public void click_btn2(View v) {
int[] location=new int[2];
camBtn.getLocationOnScreen(location);
new GuideCaseView.Builder(this)
.focusRectAtPosition(location[0], location[1], 230, 75)
.roundRectRadius(60)
.focusBorderColor(Color.GREEN)
.build()
.show();
}

public void click_btn3(View v) {
int[] location=new int[2];
qaBtn.getLocationOnScreen(location);
new GuideCaseView.Builder(this)
.focusRectAtPosition(location[0], location[1], 230, 75)
.roundRectRadius(60)
.focusBorderColor(Color.GREEN)
.build()
.show();
}

@OnTouch(R2.id.bgimg)
Expand Down Expand Up @@ -209,9 +276,11 @@ void onCameraClicked(View v)
model.forResult(2);//打开照片选择器
}

@OnTouch(R2.id.voice_btn)
@OnTouch({R2.id.voice_btn,R2.id.que_btn})
void onVoiceBtnStatusChanged(View v, MotionEvent e)
{
if (v.getId()==R.id.que_btn)
shouldAnswer=true;
switch (e.getAction()){
case MotionEvent.ACTION_DOWN:
lastRecordName=recorder.start();break;
Expand All @@ -225,6 +294,14 @@ void onVoiceBtnStatusChanged(View v, MotionEvent e)
}
}

public void onInit(int status) {
if (status == tts.SUCCESS) {
int result1 = tts.setLanguage(Locale.CHINA);
if (result1 == TextToSpeech.LANG_MISSING_DATA||result1==TextToSpeech.LANG_NOT_SUPPORTED)
Toast.makeText(this,"数据丢失或不支持:"+result1+";",Toast.LENGTH_SHORT).show();
}
}

class ResponseHandler extends Handler{
@Override
public void handleMessage(@NonNull Message msg) {
Expand Down Expand Up @@ -263,4 +340,14 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten
dialog.show();
util.parsePicLocation(l.get(0),handler);
}

protected void onDestroy() {
super.onDestroy();
if (tts != null) {
//停止
tts.stop();
//关闭
tts.shutdown();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,52 +1,37 @@
package dhu.cst.zhangxuhong171310126.dhuguider.activities;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.os.Handler;
import android.os.Message;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import com.xuexiang.xui.widget.guidview.GuideCaseView;

import dhu.cst.zhangxuhong171310126.dhuguider.R;

import static java.lang.Thread.sleep;

public class WelcomeActivity extends AppCompatActivity {
private Handler handler;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

public void click_use(View v){
finish();
}

public void click_btn1(View v){
new GuideCaseView.Builder(this)
.focusRectAtPosition(320, 650, 230, 75)
.roundRectRadius(60)
.focusBorderColor(Color.GREEN)
.build()
.show();
}

public void click_btn2(View v) {
new GuideCaseView.Builder(this)
.focusRectAtPosition(535, 650, 230, 75)
.roundRectRadius(60)
.focusBorderColor(Color.GREEN)
.build()
.show();
handler=new RedirectHandler();
new Thread(() -> {
try {
sleep(1000);
handler.sendMessage(new Message());
} catch (InterruptedException e) {
handler.sendMessage(new Message());
}
}).start();
}

public void click_btn3(View v) {
new GuideCaseView.Builder(this)
.focusRectAtPosition(320, 745, 230, 75)
.roundRectRadius(60)
.focusBorderColor(Color.GREEN)
.build()
.show();
private class RedirectHandler extends Handler{
@Override
public void handleMessage(@NonNull Message msg) {
finish();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@Data
public class Location implements Serializable {
private String name;
private String name,direction;
private PointF lowerBound,upperBound;
private int drawableResource,descriptionResource;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public static void init(Context context)
return;
Location l;
String[] names = {"一号学院楼", "东华大道", "图文信息中心", "北门"};
String[] dirs={"西边","图文信息中心的北侧","校园中心","北端"};
PointF[] lows = {new PointF(281, 1001),
new PointF(740, 669),
new PointF(708, 791), new PointF(562, 136)},
Expand All @@ -34,6 +35,7 @@ public static void init(Context context)
l.setUpperBound(ups[i]);
l.setName(names[i]);
l.setDescriptionResource(descriptions[i]);
l.setDirection(dirs[i]);
l.setDrawableResource(picR[i]);
resorts.put(names[i],l);
}
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_baseline_help_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FF16BF"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM13,19h-2v-2h2v2zM15.07,11.25l-0.9,0.92C13.45,12.9 13,13.5 13,15h-2v-0.5c0,-1.1 0.45,-2.1 1.17,-2.83l1.24,-1.26c0.37,-0.36 0.59,-0.86 0.59,-1.41 0,-1.1 -0.9,-2 -2,-2s-2,0.9 -2,2L8,9c0,-2.21 1.79,-4 4,-4s4,1.79 4,4c0,0.88 -0.36,1.68 -0.93,2.25z"/>
</vector>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_baseline_menu_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M3,18h18v-2L3,16v2zM3,13h18v-2L3,11v2zM3,6v2h18L21,6L3,6z"/>
</vector>
Loading

0 comments on commit 9ddbde0

Please sign in to comment.