diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml
deleted file mode 100644
index 7bd27ea..0000000
--- a/.idea/deploymentTargetDropDown.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/app/src/main/java/com/example/nemophila/MapsDialogFragment.java b/app/src/main/java/com/example/nemophila/MapsDialogFragment.java
index 2e68a31..676ea7e 100644
--- a/app/src/main/java/com/example/nemophila/MapsDialogFragment.java
+++ b/app/src/main/java/com/example/nemophila/MapsDialogFragment.java
@@ -4,26 +4,57 @@
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
+import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;
+import com.example.nemophila.entities.Shop;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+
public class MapsDialogFragment extends DialogFragment {
+ private Collection shops;
+ public MapsDialogFragment(Collection shops) {
+ this.shops = shops;
+ }
+
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
- AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+ String[] choices = new String[shops.size()];
+ //ArrayList choices = new ArrayList<>();
+ int j = 0;
+ for (Iterator i = shops.iterator(); i.hasNext(); j++) {
+ choices[j] = (String)i.next();
+ }
+
+ AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("投稿したいお店はこの中にありますか?")
- .setMessage("ここにメッセージを入力します")
- .setPositiveButton("OK", new DialogInterface.OnClickListener() {
+ .setPositiveButton("該当する店がありません(新規作成)", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// このボタンを押した時の処理を書きます。
}
})
- .setNegativeButton("キャンセル", null);
+ .setNeutralButton("キャンセル", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ // このボタンを押した時の処理を書きます。
+ }
+ })
+ .setItems(choices, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ Toast.makeText(getActivity(),
+ String.format("「%s」を選択しました。", choices[which]),
+ Toast.LENGTH_SHORT)
+ .show();
+ }
+ });
return builder.create();
}
}
diff --git a/app/src/main/java/com/example/nemophila/MapsFragment.java b/app/src/main/java/com/example/nemophila/MapsFragment.java
index 6c4c3e6..9c8dd94 100644
--- a/app/src/main/java/com/example/nemophila/MapsFragment.java
+++ b/app/src/main/java/com/example/nemophila/MapsFragment.java
@@ -62,11 +62,12 @@
private LatLng shopLatlng;
// private LatLng testLatlng;
// private LatLng testLatlng2;
-// private LatLng tapLatlng;
+ private LatLng tapLatlng;
// private CameraPosition nowCamera;
// private LatLng nowLatlng;
private Marker currentMarker;
private BitmapDescriptor bd;
+ private boolean isLongClick;
LocationManager locationManager;
@@ -79,27 +80,39 @@
nemophila = (Nemophila) getActivity().getApplication();
mMap = googleMap;
-
-
//ViewModelへのアクセス
shopsViewModel = new ViewModelProvider(getActivity()).get(ShopsViewModel.class);
// LiveDataへの購読
shopsViewModel.getShopsLiveData().observe(getActivity(), shops -> {
- //受け取ったshopsに対してMarkerが立っているかを確認
- //対応するMarkerがなければMarkerを立てる
- for (Shop shop : shops) {
- if (shopsViewModel.getMarker(shop) == null) {
-
- shopLatlng = new LatLng(shop.getLatitude(), shop.getLongitude());
- System.out.println(shopLatlng);
- Marker createMaker = mMap.addMarker(new MarkerOptions().position(shopLatlng).title(""));
- //マーカーに店情報を持たせる
- createMaker.setTag(shop);
- //ShopToMarkerに紐づけ
- shopsViewModel.setShopAndMarker(shop, createMaker);
+// Toast.makeText(getActivity(),
+// String.format("店確認しました"),
+// Toast.LENGTH_SHORT)
+// .show();
+//
+// if(isLongClick == true) {
+// Toast.makeText(getActivity(),
+// String.format("長押しは受け取れてるよ"),
+// Toast.LENGTH_SHORT)
+// .show();
+// //長押し時は周辺のピンを全て取得し、ダイアログに表示する
+// DialogFragment dialogFragment = new MapsDialogFragment(shops);
+// dialogFragment.show(getActivity().getSupportFragmentManager(),"mapsdialog");
+//
+// }
+ //受け取ったshopsに対してMarkerが立っているかを確認
+ //各shopに対応するMarkerがなければMarkerを立てる
+ for (Shop shop : shops) {
+ if (shopsViewModel.getMarker(shop) == null) {
+ shopLatlng = new LatLng(shop.getLatitude(), shop.getLongitude());
+ System.out.println(shopLatlng);
+ Marker createMaker = mMap.addMarker(new MarkerOptions().position(shopLatlng).title(""));
+ //マーカーに店情報を持たせる
+ createMaker.setTag(shop);
+ //ShopToMarkerに紐づけ
+ shopsViewModel.setShopAndMarker(shop, createMaker);
+ }
}
- }
});
//初期画面の座標(現在地をロードするまで表示)
@@ -112,34 +125,38 @@
//画面が動いたとき
mMap.setOnCameraIdleListener(() -> {
+ //長押し状態を解除
+ isLongClick = false;
//カメラの座標とZOOM倍率を保存
//nowCamera = mMap.getCameraPosition();
nemophila.setCameraLatitude(mMap.getCameraPosition().target.latitude);
nemophila.setCameraLongitude(mMap.getCameraPosition().target.longitude);
nemophila.setZoom(mMap.getCameraPosition().zoom);
-
- //nowLatlng = new LatLng(nowCamera.target.latitude, nowCamera.target.longitude);
- //nowZoom = nowCamera.zoom;
//Shopの描画範囲を指定
shopsViewModel.setViewArea(nemophila.getCameraLongitude() + 1, nemophila.getCameraLatitude() + 1, nemophila.getCameraLongitude() - 1, nemophila.getCameraLatitude() - 1);
});
- /*
- //多分使わない
+
+ // test用 座標を確認するため
// タップした時のリスナーをセット
mMap.setOnMapClickListener(tapLocation -> {
// map(ピン以外)をtapされた位置の緯度経度
tapLatlng = new LatLng(tapLocation.latitude, tapLocation.longitude);
- mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(tapLatlng, nowZoom));
- shopsViewModel.setViewArea(tapLatlng.longitude+1, tapLatlng.latitude+1, tapLatlng.longitude-1, tapLatlng.latitude-1);
+ Toast.makeText(getActivity(),
+ String.format("%s", tapLatlng),
+ Toast.LENGTH_SHORT)
+ .show();
});
- */
+
//長押し時に店を作成し、その座標にピンを立てる
//長押し時にその座標を保存し、投稿画面に移り、Shop作成完了時にはピンを立て、Shop画面に移行
mMap.setOnMapLongClickListener(longpushLocation -> {
//長押しされた位置の緯度経度を取得
//LatLng newlocation = new LatLng(longpushLocation.latitude, longpushLocation.longitude);
+
+ //長押し座標を画面中心にしておく
+ //zoomMap(longpushLocation.latitude, longpushLocation.longitude);
//Nemophilaに座標を保存
nemophila.setCurrentLatitude(longpushLocation.latitude);
nemophila.setCurrentLongitude(longpushLocation.longitude);
@@ -149,9 +166,11 @@
// Intent intent = new Intent(getActivity(), ShopCreateActivity.class);
// startActivity(intent);
- DialogFragment dialogFragment = new MapsDialogFragment();
- dialogFragment.show(getActivity().getSupportFragmentManager(),"mapsdialog");
-
+ //長押しでダイアログを表示
+ isLongClick = true; //長押ししたかどうかで動作を判定するため
+ shopsViewModel.setViewArea(longpushLocation.longitude+1, longpushLocation.latitude+1, longpushLocation.longitude-1, longpushLocation.latitude-1);
+ //本番環境は↓の範囲で
+ //shopsViewModel.setViewArea(longpushLocation.longitude+0.0007, longpushLocation.latitude+0.0007, longpushLocation.longitude-0.0007, longpushLocation.latitude-0.0007);
});
// ピンをクリックした場合