eventbus线路查询和在线购票的两个界面向一个界面传值
This commit is contained in:
parent
f0dcc21691
commit
442dce8043
|
@ -60,9 +60,6 @@ dependencies {
|
|||
|
||||
implementation ("com.belerweb:pinyin4j:2.5.1")
|
||||
|
||||
//androidX
|
||||
// implementation ("com.github.lzjin:ViewPagerGallery:1.2")
|
||||
// implementation ("com.github.lzjin:ViewPagerGallery:1.3")
|
||||
|
||||
implementation("org.greenrobot:eventbus:3.3.1")
|
||||
|
||||
}
|
|
@ -21,6 +21,8 @@ import com.bumptech.glide.Glide;
|
|||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -48,6 +50,7 @@ public class ChufaTable extends AppCompatActivity {
|
|||
public void onClick(View v) {
|
||||
Intent intent = new Intent(ChufaTable.this, SearchLine.class);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -179,9 +182,8 @@ public class ChufaTable extends AppCompatActivity {
|
|||
public void onClick(View v) {
|
||||
// Log.i("test","onClick");
|
||||
//TODO 跳转到新的activity
|
||||
Intent intent = new Intent(ChufaTable.this, SearchLine.class);
|
||||
intent.putExtra("start",dto.spotName);
|
||||
startActivity(intent);
|
||||
EventBus.getDefault().post(new StationSelectedEvent(dto.spotName, true, false));
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -21,6 +21,8 @@ import com.bumptech.glide.Glide;
|
|||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -167,6 +169,7 @@ public class DaonaTable extends AppCompatActivity {
|
|||
LineSearch_Item.DestinationDTO dto = destinationDTOS.get(position);
|
||||
holder.nameTextView.setText(dto.name);
|
||||
holder.detailTextView.setText(dto.didian);
|
||||
|
||||
if(position==0){
|
||||
Glide.with(DaonaTable.this)
|
||||
.load(R.drawable.train)
|
||||
|
@ -180,9 +183,8 @@ public class DaonaTable extends AppCompatActivity {
|
|||
public void onClick(View v) {
|
||||
// Log.i("test","onClick");
|
||||
//TODO 跳转到新的activity
|
||||
Intent intent = new Intent(DaonaTable.this, SearchLine.class);
|
||||
intent.putExtra("end",dto.name);
|
||||
startActivity(intent);
|
||||
EventBus.getDefault().post(new StationSelectedEvent(dto.name, false, true));
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -9,27 +9,39 @@ import android.view.View;
|
|||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
|
||||
public class OnlineBuy extends AppCompatActivity {
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
|
||||
public class OnlineBuy extends AppCompatActivity {
|
||||
EditText begin=null;
|
||||
EditText finish = null;
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_online_buy);
|
||||
|
||||
EventBus.getDefault().register(this);
|
||||
|
||||
//todo 选择路线
|
||||
EditText begin = findViewById(R.id.editText6);
|
||||
begin.setText(getIntent().getStringExtra("name"));
|
||||
begin = findViewById(R.id.editText6);
|
||||
finish = findViewById(R.id.finish);
|
||||
|
||||
begin.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(OnlineBuy.this,chooseLine.class);
|
||||
intent.putExtra("isbegin",true);
|
||||
intent.putExtra("isfinish",false);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
EditText finish = findViewById(R.id.finish);
|
||||
|
||||
finish.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(OnlineBuy.this,chooseLine.class);
|
||||
intent.putExtra("isfinish",true);
|
||||
intent.putExtra("isbegin",false);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
@ -52,4 +64,22 @@ public class OnlineBuy extends AppCompatActivity {
|
|||
}
|
||||
});
|
||||
}
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
EventBus.getDefault().unregister(this); // 注销EventBus
|
||||
}
|
||||
|
||||
// 事件接收方法
|
||||
@Subscribe
|
||||
public void onEvent(StationSelectedEvent event) {
|
||||
if (event != null) {
|
||||
|
||||
if (event.isForBegin()) {
|
||||
begin.setText(event.getStationName());
|
||||
} else if (event.isForFinish()) {
|
||||
finish.setText(event.getStationName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -26,16 +26,24 @@ import com.baidu.mapapi.search.geocode.GeoCoder;
|
|||
import com.baidu.mapapi.search.geocode.OnGetGeoCoderResultListener;
|
||||
import com.baidu.mapapi.search.geocode.ReverseGeoCodeResult;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
|
||||
|
||||
public class SearchLine extends AppCompatActivity {
|
||||
private MapView mMapView = null;
|
||||
private BaiduMap mBaiduMap = null;
|
||||
EditText chuFa ;
|
||||
EditText daoNa;
|
||||
EditText chuFa = null;
|
||||
EditText daoNa = null;
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_search_line);
|
||||
chuFa = findViewById(R.id.editText6);
|
||||
daoNa = findViewById(R.id.finish);
|
||||
EventBus.getDefault().register(this);
|
||||
|
||||
|
||||
// 同意百度地图隐私政策
|
||||
SDKInitializer.setAgreePrivacy(getApplicationContext(),true);
|
||||
//在使用SDK各组件之前初始化context信息,传入ApplicationContext
|
||||
|
@ -50,10 +58,10 @@ public class SearchLine extends AppCompatActivity {
|
|||
// mBaiduMap.setMapType(BaiduMap.MAP_TYPE_SATELLITE);
|
||||
//普通地图 ,mBaiduMap是地图控制器对象
|
||||
mBaiduMap.setMapType(BaiduMap.MAP_TYPE_NORMAL);
|
||||
//todo 接收返回表单传来的值
|
||||
String start = getIntent().getStringExtra("start");
|
||||
//todo 接收到哪表单传来的值
|
||||
String end = getIntent().getStringExtra("end");
|
||||
// //todo 接收返回表单传来的值
|
||||
// String start = getIntent().getStringExtra("start");
|
||||
// //todo 接收到哪表单传来的值
|
||||
// String end = getIntent().getStringExtra("end");
|
||||
|
||||
// setUpEditTextWatcher(chuFa, "start");
|
||||
// setUpEditTextWatcher(daoNa, "end");
|
||||
|
@ -66,7 +74,7 @@ public class SearchLine extends AppCompatActivity {
|
|||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
chuFa = findViewById(R.id.editText6);
|
||||
|
||||
chuFa.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
@ -94,10 +102,10 @@ public class SearchLine extends AppCompatActivity {
|
|||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
chuFa.setText(start);
|
||||
// chuFa.setText(start);
|
||||
|
||||
//todo 到哪表单
|
||||
daoNa = findViewById(R.id.finish);
|
||||
|
||||
daoNa.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@ -105,27 +113,27 @@ public class SearchLine extends AppCompatActivity {
|
|||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
daoNa.setText(end);
|
||||
// daoNa.setText(end);
|
||||
|
||||
}
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
//在activity执行onResume时必须调用mMapView. onResume ()
|
||||
mMapView.onResume();
|
||||
}
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
//在activity执行onPause时必须调用mMapView. onPause ()
|
||||
mMapView.onPause();
|
||||
}
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
//在activity执行onDestroy时必须调用mMapView.onDestroy()
|
||||
mMapView.onDestroy();
|
||||
}
|
||||
// @Override
|
||||
// protected void onResume() {
|
||||
// super.onResume();
|
||||
// //在activity执行onResume时必须调用mMapView. onResume ()
|
||||
// mMapView.onResume();
|
||||
// }
|
||||
// @Override
|
||||
// protected void onPause() {
|
||||
// super.onPause();
|
||||
// //在activity执行onPause时必须调用mMapView. onPause ()
|
||||
// mMapView.onPause();
|
||||
// }
|
||||
// @Override
|
||||
// protected void onDestroy() {
|
||||
// super.onDestroy();
|
||||
// //在activity执行onDestroy时必须调用mMapView.onDestroy()
|
||||
// mMapView.onDestroy();
|
||||
// }
|
||||
private boolean isInputComplete(CharSequence input) {
|
||||
return input.length() > 0;
|
||||
}
|
||||
|
@ -186,5 +194,23 @@ public class SearchLine extends AppCompatActivity {
|
|||
.title(type.equals("start") ? "起始地点" : "目的地点");
|
||||
mBaiduMap.addOverlay(markerOptions); // 添加新的标注
|
||||
}
|
||||
@Subscribe
|
||||
public void onLineSelectedEvent(StationSelectedEvent event) {
|
||||
if (event != null) {
|
||||
if(event.isForBegin()){
|
||||
chuFa.setText(event.getStationName());
|
||||
}else if(event.isForFinish()){
|
||||
daoNa.setText(event.getStationName());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
EventBus.getDefault().unregister(this); // 反注册 EventBus
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,36 +40,24 @@ public class ShouyeFragment extends Fragment {
|
|||
list.add("https://alifei03.cfp.cn/creative/vcg/800/new/VCG211366776934.jpg");
|
||||
list.add("https://alifei02.cfp.cn/creative/vcg/800/new/VCG211430222848.jpeg");
|
||||
Banner banner = view.findViewById(R.id.banner);
|
||||
CardView cardView = view.findViewById(R.id.cardview);
|
||||
ImageView imageView = view.findViewById(R.id.imageView41);
|
||||
CardView cardView = view.findViewById(R.id.cardView16);
|
||||
// ImageView imageView = view.findViewById(R.id.imageView41);
|
||||
banner.setAdapter(new BannerImageAdapter<String>(list) {
|
||||
@Override
|
||||
public void onBindView(BannerImageHolder holder, String data, int position, int size) {
|
||||
Glide.with(holder.itemView)
|
||||
.load(data)
|
||||
.apply(RequestOptions.bitmapTransform(new RoundedCorners(30)))
|
||||
.into(imageView);
|
||||
.apply(RequestOptions.bitmapTransform(new RoundedCorners(10)))
|
||||
.into(holder.imageView);
|
||||
}
|
||||
});
|
||||
|
||||
banner.setIndicator(new CircleIndicator(getContext()));
|
||||
banner.setIndicatorRadius(5);
|
||||
banner.setBannerGalleryEffect(10,10,3) ;
|
||||
banner.setBannerRound(10);
|
||||
// banner.setBannerGalleryEffect(10,10,3) ;
|
||||
banner.setScrollTime(800);
|
||||
|
||||
// banner.initBanner(urlList, true)//开启3D画廊效果
|
||||
// .addPageMargin(10, 50)//参数1page之间的间距,参数2中间item距离边界的间距
|
||||
// .addPointMargin(6)//指示器点间距
|
||||
// .addStartTimer(8)//自动轮播5秒间隔
|
||||
// .addPointBottom(7)//底部间距
|
||||
// .addRoundCorners(12)//圆角
|
||||
// .finishConfig()//这句必须加
|
||||
// .addBannerListener(new BannerViewPager.OnClickBannerListener() {
|
||||
// @Override
|
||||
// public void onBannerClick(int position) {
|
||||
// //点击item
|
||||
// }
|
||||
// });
|
||||
message.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
package com.hnucm.c25;
|
||||
|
||||
public class StationSelectedEvent {
|
||||
private String stationName;
|
||||
private boolean forBegin;
|
||||
private boolean forFinish;
|
||||
|
||||
public StationSelectedEvent(String stationName, boolean forBegin, boolean forFinish) {
|
||||
this.stationName = stationName;
|
||||
this.forBegin = forBegin;
|
||||
this.forFinish = forFinish;
|
||||
}
|
||||
|
||||
public String getStationName() {
|
||||
return stationName;
|
||||
}
|
||||
|
||||
public boolean isForBegin() {
|
||||
return forBegin;
|
||||
}
|
||||
|
||||
public boolean isForFinish() {
|
||||
return forFinish;
|
||||
}
|
||||
}
|
|
@ -21,6 +21,10 @@ import android.widget.Toast;
|
|||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import net.sourceforge.pinyin4j.PinyinHelper;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
@ -94,7 +98,7 @@ public class chooseLine extends AppCompatActivity {
|
|||
sort.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// Collections.sort(staion, new PinyinComparator());
|
||||
Collections.sort(staion, new PinyinComparator());
|
||||
|
||||
stationAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
@ -226,10 +230,10 @@ public class chooseLine extends AppCompatActivity {
|
|||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
//todo 站点信息
|
||||
Intent intent = new Intent(chooseLine.this,OnlineBuy.class);
|
||||
intent.putExtra("name",stationName);
|
||||
startActivity(intent);
|
||||
boolean isForBegin = getIntent().getBooleanExtra("isbegin", false);
|
||||
boolean isForFinish = getIntent().getBooleanExtra("isfinish", false);
|
||||
EventBus.getDefault().post(new StationSelectedEvent(stationName, isForBegin, isForFinish));
|
||||
finish(); // 关闭当前Activity
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -253,28 +257,42 @@ public class chooseLine extends AppCompatActivity {
|
|||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
// public class PinyinComparator implements Comparator<String> {
|
||||
// @Override
|
||||
// public int compare(String s1, String s2) {
|
||||
// String pinyin1 = getPinyin(s1);
|
||||
// String pinyin2 = getPinyin(s2);
|
||||
//
|
||||
// int minLen = Math.min(pinyin1.length(), pinyin2.length());
|
||||
// for (int i = 0; i < minLen; i++) {
|
||||
// int result = pinyin1.substring(i, i + 1).compareTo(pinyin2.substring(i, i + 1));
|
||||
// if (result != 0) {
|
||||
// return result;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // 如果所有比较过的字母都相同,则比较拼音长度
|
||||
// return Integer.compare(pinyin1.length(), pinyin2.length());
|
||||
// }
|
||||
|
||||
// private String getPinyin(String chinese) {
|
||||
// String pinyin = Pinyin4j.toPinyin(chinese, "");
|
||||
// // 移除拼音中的声调
|
||||
// return pinyin.replaceAll("[0-9]", "");
|
||||
// }
|
||||
public class PinyinComparator implements Comparator<String> {
|
||||
|
||||
@Override
|
||||
public int compare(String s1, String s2) {
|
||||
String pinyin1 = getPinyin(s1);
|
||||
String pinyin2 = getPinyin(s2);
|
||||
|
||||
int minLen = Math.min(pinyin1.length(), pinyin2.length());
|
||||
for (int i = 0; i < minLen; i++) {
|
||||
int result = pinyin1.charAt(i) - pinyin2.charAt(i);
|
||||
if (result != 0) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
// 如果所有比较过的字母都相同,则比较拼音长度
|
||||
return Integer.compare(pinyin1.length(), pinyin2.length());
|
||||
}
|
||||
|
||||
private String getPinyin(String chinese) {
|
||||
StringBuilder pinyinBuilder = new StringBuilder();
|
||||
for (char c : chinese.toCharArray()) {
|
||||
if (Character.toString(c).matches("[\\u4E00-\\u9FA5]+")) { // 汉字字符
|
||||
String[] temp = PinyinHelper.toHanyuPinyinStringArray(c);
|
||||
if (temp != null && temp.length > 0) {
|
||||
// 只需要第一个拼音,并且不考虑声调
|
||||
pinyinBuilder.append(temp[0].charAt(0)); // 取出拼音的第一个字符
|
||||
} else {
|
||||
pinyinBuilder.append(c); // 非汉字字符保持不变(或者可以选择忽略)
|
||||
}
|
||||
} else {
|
||||
pinyinBuilder.append(c); // 非汉字字符保持不变
|
||||
}
|
||||
}
|
||||
return pinyinBuilder.toString().replaceAll("[0-9]", "");
|
||||
}
|
||||
}
|
||||
//}
|
||||
}
|
|
@ -97,6 +97,7 @@
|
|||
android:layout_marginTop="16dp"
|
||||
android:layout_marginEnd="64dp"
|
||||
android:hint="在哪出发"
|
||||
android:textColor="@color/black"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
@ -110,6 +111,7 @@
|
|||
android:layout_marginStart="64dp"
|
||||
android:layout_marginEnd="64dp"
|
||||
android:hint="要去哪里"
|
||||
android:textColor="@color/black"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/editText6">
|
||||
|
|
|
@ -70,32 +70,36 @@
|
|||
android:background="#F3F3F3">
|
||||
|
||||
|
||||
<com.youth.banner.Banner
|
||||
android:id="@+id/banner"
|
||||
<androidx.cardview.widget.CardView
|
||||
android:id="@+id/cardView16"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="200dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:background="#F3F3F3"
|
||||
app:banner_radius="30dp"
|
||||
app:cardCornerRadius="10dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" >
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
android:id="@+id/cardview"
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:cardCornerRadius="10dp" >
|
||||
<ImageView
|
||||
android:id="@+id/imageView41"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.youth.banner.Banner
|
||||
android:id="@+id/banner"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:src="@drawable/out" />
|
||||
</androidx.cardview.widget.CardView>
|
||||
</com.youth.banner.Banner>
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
</com.youth.banner.Banner>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/constraintLayout3"
|
||||
|
@ -105,7 +109,7 @@
|
|||
android:background="@color/white"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/banner">
|
||||
app:layout_constraintTop_toBottomOf="@+id/cardView16">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView"
|
||||
|
|
Loading…
Reference in New Issue