以下の機能を追加 #46

Merged
Utahshi merged 1 commits from finishing into master 2024-07-08 22:47:57 +00:00
7 changed files with 231 additions and 62 deletions
Showing only changes of commit c8af823a46 - Show all commits

View File

@ -34,7 +34,7 @@
--> -->
<meta-data <meta-data
android:name="com.google.android.geo.API_KEY" android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyBqLqPm76UFpwbpU8b3oiH0wbkhosrPWpU" /> android:value="AIzaSyBQ1Ak-I2NL5TP4K59ZI0VgzKk6HNZuusw" />
<activity <activity
android:name=".Maps" android:name=".Maps"

View File

@ -44,7 +44,7 @@ public class CreateSchedule {
boolean notSecondDuplicatesBoolean = true;//スケジュールの重複の有無(第一希望日のみで通った場合も考えて初期はtrue) boolean notSecondDuplicatesBoolean = true;//スケジュールの重複の有無(第一希望日のみで通った場合も考えて初期はtrue)
String[] date; String[] homeVisitDaysString;
public CreateSchedule(AppCompatActivity activity) { public CreateSchedule(AppCompatActivity activity) {
@ -55,7 +55,7 @@ public class CreateSchedule {
String secondDay = sharedPreferences.getString("day2", null); String secondDay = sharedPreferences.getString("day2", null);
String thirdDay = sharedPreferences.getString("day3", null); String thirdDay = sharedPreferences.getString("day3", null);
date = new String[]{firstDay, secondDay, thirdDay}; homeVisitDaysString = new String[]{firstDay, secondDay, thirdDay};
} }
@ -102,18 +102,22 @@ public class CreateSchedule {
boolean notDuplicatesBoolean = createSchedule(myDataList, intervalArrayInt); boolean notDuplicatesBoolean = createSchedule(myDataList, intervalArrayInt);
//スケジュールの重複の確認 //スケジュールの重複の確認
if (!notDuplicatesBoolean) { if (notDuplicatesBoolean) {
//スケジュールを基準にソートする
sortSchedule(myDataList);
}else{
//第二希望日で同じ処理を行う //第二希望日で同じ処理を行う
Log.d("CreateSchedule", "第二希望"); Log.d("CreateSchedule", "第二希望");
secondSetData(myDataList); secondSetData(myDataList);
secondTimeZoneSort(myDataList); secondTimeZoneSort(myDataList);
notSecondDuplicatesBoolean = secondCreateSchedule(myDataList, intervalArrayInt); notSecondDuplicatesBoolean = secondCreateSchedule(myDataList, intervalArrayInt);
//スケジュールを基準にソートする
sortSchedule(myDataList);
} }
}); });
//重複がなければ開始地点の緯度経度を返す //重複がなければ開始地点の緯度経度を返す
if (notSecondDuplicatesBoolean) { if (notSecondDuplicatesBoolean) {
//スケジュールを基準にソートする //保護者の住所を緯度経度に変換する
sortSchedule(myDataList);
String startPointLatLngString = geocodeAddress(myDataList, context); String startPointLatLngString = geocodeAddress(myDataList, context);
Log.d("CreateSchedule", "startPointLatLngString" + startPointLatLngString); Log.d("CreateSchedule", "startPointLatLngString" + startPointLatLngString);
outPutLogSchedule(myDataList); outPutLogSchedule(myDataList);
@ -313,8 +317,8 @@ public class CreateSchedule {
for (int x = 0; x < 3; x++) { for (int x = 0; x < 3; x++) {
//家庭訪問の日目が保護者の第一希望日かを判定する //家庭訪問の日目が保護者の第一希望日かを判定する
//まだスケジュールを割り当てていない保護者かを判定する //まだスケジュールを割り当てていない保護者かを判定する
if (date[x].equals(myDataList.get(i).getStartDateString()) && myDataList.get(i).getSchedule() == 0) { if (homeVisitDaysString[x].equals(myDataList.get(i).getStartDateString()) && myDataList.get(i).getSchedule() == 0) {
checkSchedule(myDataList, intervalArrayInt, i, j, x, myDataList.get(i).getStartDateString()); checkSchedule(myDataList, intervalArrayInt, i, j, x, myDataList.get(i).getStartDateString(),homeVisitDaysString);
break; break;
} }
} }
@ -336,8 +340,8 @@ public class CreateSchedule {
for (int x = 0; x < 3; x++) { for (int x = 0; x < 3; x++) {
//家庭訪問の日目が保護者の第一希望日かを判定する //家庭訪問の日目が保護者の第一希望日かを判定する
//まだスケジュールを割り当てていない保護者かを判定する //まだスケジュールを割り当てていない保護者かを判定する
if (date[x].equals(myDataList.get(i).getSecondDayStartDateString()) && myDataList.get(i).getSchedule() == 0) { if (homeVisitDaysString[x].equals(myDataList.get(i).getSecondDayStartDateString()) && myDataList.get(i).getSchedule() == 0) {
checkSchedule(myDataList, intervalArrayInt, i, j, x, myDataList.get(i).getSecondDayStartDateString()); checkSchedule(myDataList, intervalArrayInt, i, j, x, myDataList.get(i).getSecondDayStartDateString(),homeVisitDaysString);
} }
} }
} }
@ -351,11 +355,12 @@ public class CreateSchedule {
return true; return true;
} }
private void checkSchedule(List<MyDataClass> myDataList, int[][][] intervalArrayInt, int i, int j, int x, String desiredDateString) { private void checkSchedule(List<MyDataClass> myDataList, int[][][] intervalArrayInt, int i, int j, int x, String desiredDateString, String[] homeVisitDaysString) {
//保護者の希望時間の開始と終了の間にまだ保護者の割り当てがされていないスケジュールの空き時間があるかの判定 //保護者の希望時間の開始と終了の間にまだ保護者の割り当てがされていないスケジュールの空き時間があるかの判定
if (intervalArrayInt[x][j][0] >= Integer.parseInt(myDataList.get(i).getParentStartTimeString()) && intervalArrayInt[x][j + 1][0] <= Integer.parseInt(myDataList.get(i).getParentEndTimeString()) && intervalArrayInt[x][j][1] == 0) { if (intervalArrayInt[x][j][0] >= Integer.parseInt(myDataList.get(i).getParentStartTimeString()) && intervalArrayInt[x][j + 1][0] <= Integer.parseInt(myDataList.get(i).getParentEndTimeString()) && intervalArrayInt[x][j][1] == 0) {
intervalArrayInt[x][j][1] += 1;//その時間が割り当て済みでありこと intervalArrayInt[x][j][1] += 1;//その時間が割り当て済みでありこと
myDataList.get(i).setSchedule(Integer.parseInt(desiredDateString.substring(4, 8) + intervalArrayInt[x][j][0]));//スケジュールをmyDataListに入れる(:6041240(6月4日12時40分)) myDataList.get(i).setSchedule(Integer.parseInt(desiredDateString.substring(4, 8) + intervalArrayInt[x][j][0]));//スケジュールをmyDataListに入れる(:6041240(6月4日12時40分))
myDataList.get(i).setScheduleDay(homeVisitDaysString[x]);
} }
} }

View File

@ -2,6 +2,7 @@ package com.example.oplogy;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
@ -14,6 +15,7 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.room.Room; import androidx.room.Room;
import com.google.firebase.firestore.FirebaseFirestore; import com.google.firebase.firestore.FirebaseFirestore;
import com.google.gson.Gson;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -243,13 +245,15 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
//final宣言することによってスレッドセーフになる(ラムダ式内で使えるようにする) //final宣言することによってスレッドセーフになる(ラムダ式内で使えるようにする)
final List<MyDataClass> finalMyDataList = myDataList; final List<MyDataClass> finalMyDataList = myDataList;
CreateRoot createRoot = new CreateRoot(MainActivity.this); CreateSchedule createSchedule = new CreateSchedule(MainActivity.this);
Boolean notDuplicates = createRoot.receiveData(finalMyDataList, getApplicationContext()); String startPointLatLngString = createSchedule.receiveData(myDataList, getApplicationContext());
runOnUiThread(() -> { runOnUiThread(() -> {
if (notDuplicates) { if ( !startPointLatLngString.equals("")) {
Log.d("MainActivity", "スケジュール作成成功"); Log.d("MainActivity", "スケジュール作成成功");
saveMyDataList(finalMyDataList);
Intent toRoot = new Intent(MainActivity.this, Maps.class); Intent toRoot = new Intent(MainActivity.this, Maps.class);
toRoot.putExtra("startPointLatLngString", startPointLatLngString);
startActivity(toRoot); startActivity(toRoot);
} else { } else {
//保護者の重複による警告ダイアログ //保護者の重複による警告ダイアログ
@ -261,6 +265,19 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
executor.shutdown(); executor.shutdown();
}); });
} }
private void saveMyDataList(List<MyDataClass> myDataList) {
// 共有プリファレンスのインスタンスを取得
SharedPreferences sharedPreferences = getSharedPreferences("MyDataList", MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
// MyDataListをJSON形式に変換
Gson gson = new Gson();
String json = gson.toJson(myDataList);
// JSON形式のデータを共有プリファレンスに保存
editor.putString("myDataList", json);
editor.apply();
}
private void showErrorDialog(List<MyDataClass> myDataList) { private void showErrorDialog(List<MyDataClass> myDataList) {
List<Integer> studentNumbers = new ArrayList<>(); List<Integer> studentNumbers = new ArrayList<>();

View File

@ -1,6 +1,6 @@
package com.example.oplogy; package com.example.oplogy;
import androidx.fragment.app.FragmentActivity; import android.content.SharedPreferences;
import android.graphics.Color; import android.graphics.Color;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
@ -12,6 +12,9 @@ import android.widget.LinearLayout;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
import androidx.fragment.app.FragmentActivity;
import com.example.oplogy.databinding.MapsBinding;
import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback; import com.google.android.gms.maps.OnMapReadyCallback;
@ -20,8 +23,8 @@ import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker; import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions; import com.google.android.gms.maps.model.MarkerOptions;
import com.example.oplogy.databinding.MapsBinding;
import com.google.android.gms.maps.model.PolylineOptions; import com.google.android.gms.maps.model.PolylineOptions;
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
@ -29,6 +32,7 @@ import com.google.gson.JsonPrimitive;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.lang.reflect.Type;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
@ -43,8 +47,18 @@ public class Maps extends FragmentActivity implements OnMapReadyCallback, View.O
private MapsBinding binding; private MapsBinding binding;
private LinearLayout locationsName; private LinearLayout locationsName;
private Spinner dateSpinner; private Spinner dateSpinner;
//GoogleMapAPiで使用可能な色
private static final int[] COLORS = new int[]{ private static final int[] COLORS = new int[]{
Color.BLUE, Color.RED, Color.GREEN, Color.MAGENTA, Color.CYAN, Color.YELLOW Color.parseColor("#007FFF"), // HUE_AZURE
Color.parseColor("#0000FF"), // HUE_BLUE
Color.parseColor("#00FFFF"), // HUE_CYAN
Color.parseColor("#00FF00"), // HUE_GREEN
Color.parseColor("#FF00FF"), // HUE_MAGENTA
Color.parseColor("#FFA500"), // HUE_ORANGE
Color.parseColor("#FF0000"), // HUE_RED
Color.parseColor("#FF007F"), // HUE_ROSE
Color.parseColor("#8A2BE2"), // HUE_VIOLET
Color.parseColor("#FFFF00") // HUE_YELLOW
}; };
private int colorIndex = 0; private int colorIndex = 0;
private List<LatLng> latLngList = new ArrayList<>(); private List<LatLng> latLngList = new ArrayList<>();
@ -53,6 +67,9 @@ public class Maps extends FragmentActivity implements OnMapReadyCallback, View.O
private Map<String, Runnable> dateMap = new HashMap<>(); private Map<String, Runnable> dateMap = new HashMap<>();
private AppDatabase db = null;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -69,8 +86,7 @@ public class Maps extends FragmentActivity implements OnMapReadyCallback, View.O
locationsName = findViewById(R.id.locationsName); locationsName = findViewById(R.id.locationsName);
// 日付を入れる処理 String dateData = formatDate(getSharedPreferencesData(0)) + "/" + formatDate(getSharedPreferencesData(1)) + "/" + formatDate(getSharedPreferencesData(2));
String dateData = "6月3日/6月4日/6月5日/6月6日/6月7日";
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item); ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
@ -80,13 +96,18 @@ public class Maps extends FragmentActivity implements OnMapReadyCallback, View.O
} }
// 各日付に対応するRunnableを設定する // 各日付に対応するRunnableを設定する
dateMap.put("6月3日", this::firstMapAndNames); for (int i = 0; i < 3; i++) {
dateMap.put("6月4日", this::secondMapAndNames); int finalI = i;
dateMap.put("6月5日", this::thirdMapAndNames); String dayString = getSharedPreferencesData(i);
// 必要に応じて追加の日付に対応するメソッドをここに追加 String formattedDayString = formatDate(dayString);
dateMap.put("6月6日", this::additionalMapAndNames); if (i == 0) {
dateMap.put("6月7日", this::additionalMapAndNames2); dateMap.put(formattedDayString, () -> firstMapAndNames(createlocationData(finalI), getData(finalI)));
} else if (i == 1) {
dateMap.put(formattedDayString, () -> secondMapAndNames(createlocationData(finalI), getData(finalI)));
} else {
dateMap.put(formattedDayString, () -> thirdMapAndNames(createlocationData(finalI), getData(finalI)));
}
}
dateSpinner = findViewById(R.id.date); dateSpinner = findViewById(R.id.date);
dateSpinner.setAdapter(adapter); dateSpinner.setAdapter(adapter);
@ -107,44 +128,127 @@ public class Maps extends FragmentActivity implements OnMapReadyCallback, View.O
}); });
} }
@Override @Override
public void onMapReady(GoogleMap googleMap) { public void onMapReady(GoogleMap googleMap) {
mMap = googleMap; mMap = googleMap;
mMap.setOnMarkerClickListener(this); mMap.setOnMarkerClickListener(this);
firstMapAndNames(); // 最初に表示するデータセットをロード String latlngString = createlocationData(0);
String homeVisitDataString = getData(0);
firstMapAndNames(latlngString, homeVisitDataString);
} }
private void firstMapAndNames() { private String getSharedPreferencesData(int i) {
String locationData = "35.09050879999539,136.87845379325216/35.091950716938875,136.8826598363985/35.09273643623442,136.88154941341296/35.09473643623442,136.88154941341296/35.09673643623442,136.88154941341296"; SharedPreferences sharedPreferences = getSharedPreferences("visitingDate", MODE_PRIVATE);
String nameData = "名古屋港水族館/2番目/3番目/4番目/5番目"; // SetUpで設定した8桁の数字表記の家庭訪問日を日付表記に変更
loadMapAndNames(locationData, nameData); String dayString;
if (i == 0) {
dayString = sharedPreferences.getString("day1", null);
} else if (i == 1) {
dayString = sharedPreferences.getString("day2", null);
} else {
dayString = sharedPreferences.getString("day3", null);
}
return dayString;
} }
private void secondMapAndNames() {
String locationData2 = "35.09050879999539,136.87845379325216/35.091950716938875,136.8826598363985/35.09273643623442,136.88154941341296"; private String formatDate(String date) {
String nameData2 = "名古屋港水族館/2番目/3番目"; if (date == null || date.length() != 8) {
loadMapAndNames(locationData2, nameData2); return "";
}
String month = date.substring(4, 6);
String day = date.substring(6, 8);
return month + "" + day + "";
} }
private void thirdMapAndNames() { private String createlocationData(int i) {
String locationData3 = "35.09050879999539,136.87845379325216/35.091950716938875,136.8826598363985"; String startPointLatLngString = getIntent().getStringExtra("startPointLatLngString");
String nameData3 = "名古屋港水族館/2番目"; List<MyDataClass> myDataList = getMyDataList();
loadMapAndNames(locationData3, nameData3); StringBuilder latlngString = new StringBuilder();
for (int y = -1; y < myDataList.size(); y++) {
if (y < 0) {
latlngString.append(startPointLatLngString);
} else if (myDataList.get(y).getScheduleDay().equals(getSharedPreferencesData(i))) {
if (latlngString.length() > 0) {
latlngString.append("/");
}
latlngString.append(formatLatLng(myDataList.get(y)));
}
} }
// 追加の日付に対応するメソッド return latlngString.toString();
private void additionalMapAndNames() {
String locationData4 = "35.09050879999539,136.87845379325216/35.091950716938875,136.8826598363985/35.09300000000000,136.88300000000000";
String nameData4 = "名古屋港水族館/2番目/3番目";
loadMapAndNames(locationData4, nameData4);
} }
private void additionalMapAndNames2() { private String formatLatLng(MyDataClass myData) {
String locationData5 = "35.09050879999539,136.87845379325216/35.091950716938875,136.8826598363985/35.09400000000000,136.88400000000000"; String latlng = myData.getLatLngString();
String nameData5 = "名古屋港水族館/2番目/3番目"; int startIndex = latlng.indexOf("(") + 1;
loadMapAndNames(locationData5, nameData5); int endIndex = latlng.indexOf(")");
return latlng.substring(startIndex, endIndex);
} }
private String getData(int i) {
List<MyDataClass> myDataList = getMyDataList();
String homeVisitDataString = "";
for (int y = -1; y < myDataList.size(); y++) {
if (y < 0) {
homeVisitDataString += "開始地点/";
} else if (myDataList.get(y).getScheduleDay().equals(getSharedPreferencesData(i)) && y + 1 < myDataList.size()) {
homeVisitDataString += "出席番号" + String.valueOf(myDataList.get(y).getStudentNumber()) + "番:" + myDataList.get(y).getChildName() + "<" + myDataList.get(y).getAddress().get(0) + "> " + formatSchedule(String.valueOf(myDataList.get(y).getSchedule())) + "/";
} else if (myDataList.get(y).getScheduleDay().equals(getSharedPreferencesData(i))) {
homeVisitDataString += "出席番号" + String.valueOf(myDataList.get(y).getStudentNumber()) + "番:" + myDataList.get(y).getChildName() + " <" + myDataList.get(y).getAddress().get(0) + "> " + formatSchedule(String.valueOf(myDataList.get(y).getSchedule()));
}
}
return homeVisitDataString;
}
private String formatSchedule(String schedule) {
String month = "0" + schedule.substring(0, 1);
String day = schedule.substring(1, 3);
String hour = schedule.substring(3, 5);
String minute = schedule.substring(5, 7);
return month + "" + day + "" + hour + "" + minute + "";
}
// 共有プリファレンスからMyDataListを取得するメソッド
private List<MyDataClass> getMyDataList() {
// 共有プリファレンスのインスタンスを取得
SharedPreferences sharedPreferences = getSharedPreferences("MyDataList", MODE_PRIVATE);
// 共有プリファレンスからJSON形式のデータを取得
String json = sharedPreferences.getString("myDataList", "");
// JSON形式のデータをMyDataListに変換
Gson gson = new Gson();
Type type = new TypeToken<List<MyDataClass>>() {
}.getType();
List<MyDataClass> myDataList = gson.fromJson(json, type);
return myDataList;
}
private void firstMapAndNames(String latlngStringFirstDay, String homeVisitDataString) {
String locationData = latlngStringFirstDay;
String labelData = homeVisitDataString;
Log.d("maps", "locationData" + locationData);
Log.d("maps", "labelData" + labelData);
loadMapAndNames(locationData, labelData);
}
private void secondMapAndNames(String latlngStringSeconfDay, String homeVisitDataString) {
String locationData = latlngStringSeconfDay;
String labelData = homeVisitDataString;
loadMapAndNames(locationData, labelData);
}
private void thirdMapAndNames(String latlngStringThirdDay, String homeVisitDataString) {
String locationData = latlngStringThirdDay;
String labelData = homeVisitDataString;
loadMapAndNames(locationData, labelData);
}
private void loadMapAndNames(String locationData, String nameData) { private void loadMapAndNames(String locationData, String nameData) {
try { try {
latLngList.clear(); latLngList.clear();
@ -153,10 +257,13 @@ public class Maps extends FragmentActivity implements OnMapReadyCallback, View.O
locationsName.removeAllViews(); locationsName.removeAllViews();
mMap.clear(); mMap.clear();
// locationDataをスラッシュで分割して緯度経度リストを取得
String[] locArray = locationData.split("/"); String[] locArray = locationData.split("/");
// nameDataをスラッシュで分割して名前リストを取得
String[] nameArray = nameData.split("/"); String[] nameArray = nameData.split("/");
for (int i = 0; i < locArray.length; i++) { for (int i = 0; i < locArray.length; i++) {
// 緯度経度をカンマで分割してLatLngオブジェクトを作成
String[] latLng = locArray[i].split(","); String[] latLng = locArray[i].split(",");
if (latLng.length == 2) { if (latLng.length == 2) {
double latitude = Double.parseDouble(latLng[0]); double latitude = Double.parseDouble(latLng[0]);
@ -164,20 +271,25 @@ public class Maps extends FragmentActivity implements OnMapReadyCallback, View.O
LatLng position = new LatLng(latitude, longitude); LatLng position = new LatLng(latitude, longitude);
latLngList.add(position); latLngList.add(position);
// 名前リストから対応する名前を取得
String name = nameArray.length > i ? nameArray[i] : "Unknown"; String name = nameArray.length > i ? nameArray[i] : "Unknown";
nameList.add(name); nameList.add(name);
// 色リストから次の色を取得
int color = getNextColor(); int color = getNextColor();
colorList.add(color); colorList.add(color);
// 地図にピンを追加
addPinToMap(name, position, color); addPinToMap(name, position, color);
// スクロールビューに場所を追加
addLocationToScrollView(name, color); addLocationToScrollView(name, color);
} }
} }
// 最初の位置にカメラを移動しルートを描画
if (!latLngList.isEmpty()) { if (!latLngList.isEmpty()) {
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLngList.get(0), 17)); mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLngList.get(0), 17));
drawRoute(); drawRoute(); // ルートを描画するメソッドを呼び出す
} }
} catch (Exception e) { } catch (Exception e) {
Log.e("Maps", "Error loading maps and names", e); Log.e("Maps", "Error loading maps and names", e);
@ -202,7 +314,10 @@ public class Maps extends FragmentActivity implements OnMapReadyCallback, View.O
urlBuilder.append("&mode=driving"); urlBuilder.append("&mode=driving");
urlBuilder.append("&key=").append(getString(R.string.maps_api_key)); urlBuilder.append("&key=").append(getString(R.string.maps_api_key));
URL url = new URL(urlBuilder.toString()); String urlString = urlBuilder.toString();
Log.d("Maps", "Directions API URL: " + urlString);
URL url = new URL(urlString);
HttpURLConnection conn = (HttpURLConnection) url.openConnection(); HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET"); conn.setRequestMethod("GET");
InputStreamReader isr = new InputStreamReader(conn.getInputStream()); InputStreamReader isr = new InputStreamReader(conn.getInputStream());
@ -269,10 +384,10 @@ public class Maps extends FragmentActivity implements OnMapReadyCallback, View.O
LatLng p = new LatLng((((double) lat / 1E5)), (((double) lng / 1E5))); LatLng p = new LatLng((((double) lat / 1E5)), (((double) lng / 1E5)));
poly.add(p); poly.add(p);
} }
return poly; return poly;
} }
private float getHueFromColor(int color) { private float getHueFromColor(int color) {
float[] hsv = new float[3]; float[] hsv = new float[3];
Color.colorToHSV(color, hsv); Color.colorToHSV(color, hsv);
@ -299,6 +414,17 @@ public class Maps extends FragmentActivity implements OnMapReadyCallback, View.O
textView.setPadding(16, 16, 16, 16); textView.setPadding(16, 16, 16, 16);
textView.setBackgroundColor(color); textView.setBackgroundColor(color);
// テキストビューにクリックリスナーを追加
textView.setOnClickListener(v -> {
// 名前リストからインデックスを取得
int index = nameList.indexOf(locationName);
if (index != -1) {
LatLng position = latLngList.get(index);
// カメラを該当ピンの位置に移動
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(position, 17));
}
});
View underline = new View(this); View underline = new View(this);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT,

View File

@ -1,6 +1,5 @@
package com.example.oplogy; package com.example.oplogy;
import com.google.android.gms.maps.model.LatLng;
import com.google.firebase.Timestamp; import com.google.firebase.Timestamp;
import java.util.List; import java.util.List;
@ -30,7 +29,9 @@ public class MyDataClass {
private Long secondDayTimezoneLong; private Long secondDayTimezoneLong;
private String secondDayParentStartTimeString; private String secondDayParentStartTimeString;
private String secondDayParentEndTimeString; private String secondDayParentEndTimeString;
private LatLng latLng; private String latLngString;
private String ScheduleDayString;
public MyDataClass(String patronName, int classId, List<String> address, List<Timestamp> firstDay, int studentNumber, String childName, List<Timestamp> thirdDay, List<Timestamp> secondDay) { public MyDataClass(String patronName, int classId, List<String> address, List<Timestamp> firstDay, int studentNumber, String childName, List<Timestamp> thirdDay, List<Timestamp> secondDay) {
@ -239,11 +240,20 @@ public class MyDataClass {
return secondDayStartDateString; return secondDayStartDateString;
} }
public void setLatLng(LatLng latLng) { public void setLatLngString(String latLng) {
this.latLng=latLng; this.latLngString = latLng;
} }
public LatLng getLatLng() { public String getLatLngString() {
return latLng; return latLngString;
}
public void setScheduleDay(String ScheduleDayString) {
this.ScheduleDayString = ScheduleDayString;
}
public String getScheduleDay() {
return ScheduleDayString;
} }
} }

View File

@ -44,4 +44,9 @@ public interface SetUpTableDao {
//クラスIDの取得 //クラスIDの取得
@Query("SELECT classId FROM SetUpTable") @Query("SELECT classId FROM SetUpTable")
int getClassId(); int getClassId();
@Query("SELECT startPoint FROM setuptable")
String getStartPoint();
} }

View File

@ -36,17 +36,23 @@
android:layout_height="0dp" android:layout_height="0dp"
android:layout_weight="6" android:layout_weight="6"
tools:context=".Maps" /> tools:context=".Maps" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:orientation="horizontal"
>
<ScrollView <ScrollView
android:id="@+id/scrollable" android:id="@+id/scrollable"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="300dp"
android:layout_weight="3"> >
<LinearLayout <LinearLayout
android:id="@+id/locationsName" android:id="@+id/locationsName"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:orientation="vertical" /> android:orientation="vertical" />
</ScrollView> </ScrollView>
</LinearLayout> </LinearLayout>
</LinearLayout>