菊池 #38

Merged
Utahshi merged 5 commits from AlsoMaps into master 2024-07-08 07:58:12 +00:00
22 changed files with 465 additions and 405 deletions

View File

@ -52,3 +52,11 @@ dependencies {
implementation "androidx.room:room-runtime:$room_version" implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version" annotationProcessor "androidx.room:room-compiler:$room_version"
} }
//Map用の依存関係の追加
dependencies {
implementation 'com.google.android.gms:play-services-maps:18.0.0'
implementation 'com.google.android.gms:play-services-location:18.0.0'
implementation 'com.squareup.okhttp3:okhttp:4.9.3'
implementation 'com.google.code.gson:gson:2.8.9' // Gsonライブラリの追加
}

View File

@ -3,6 +3,9 @@
xmlns:tools="http://schemas.android.com/tools"> xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION"
tools:ignore="CoarseFineLocation" />
<application <application
android:allowBackup="true" android:allowBackup="true"
@ -31,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="AIzaSyBQ1Ak-I2NL5TP4K59ZI0VgzKk6HNZuusw" /> android:value="AIzaSyBqLqPm76UFpwbpU8b3oiH0wbkhosrPWpU" />
<activity <activity
android:name=".Maps" android:name=".Maps"
@ -46,6 +49,9 @@
<activity <activity
android:name=".RootSearchActivity" android:name=".RootSearchActivity"
android:exported="false" /> android:exported="false" />
<activity
android:name=".CreateUUID"
android:exported="false" />
<activity <activity
android:name=".DialogFragment" android:name=".DialogFragment"
android:exported="false" /> android:exported="false" />

View File

@ -1,5 +1,4 @@
package com.example.oplogy; package com.example.oplogy;
import androidx.room.TypeConverter; import androidx.room.TypeConverter;
import com.google.firebase.Timestamp; import com.google.firebase.Timestamp;

View File

@ -22,7 +22,7 @@ public class CreateUUID {
InsertClassIdforFirebase insertClassIdforFirebase = new InsertClassIdforFirebase(); InsertClassIdforFirebase insertClassIdforFirebase = new InsertClassIdforFirebase();
insertClassIdforFirebase.insertClassId(uuid); insertClassIdforFirebase.insertClassId(uuid);
//テスト用 //テスト用
uuid = 100; uuid=100;
return uuid; return uuid;
} }
} }

View File

@ -7,8 +7,8 @@ import android.widget.DatePicker;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment; import androidx.fragment.app.DialogFragment;
import java.util.Calendar; import java.util.Calendar;
import java.util.Objects;
public class DatePick extends DialogFragment implements public class DatePick extends DialogFragment implements
DatePickerDialog.OnDateSetListener { DatePickerDialog.OnDateSetListener {

View File

@ -1,8 +1,7 @@
package com.example.oplogy; package com.example.oplogy;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class DialogFragment extends AppCompatActivity { public class DialogFragment extends AppCompatActivity {

View File

@ -4,6 +4,8 @@ import android.util.Log;
import com.google.android.gms.tasks.OnCompleteListener; import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task; import com.google.android.gms.tasks.Task;
import com.google.firebase.firestore.CollectionReference;
import com.google.firebase.firestore.DocumentSnapshot;
import com.google.firebase.firestore.FirebaseFirestore; import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.QueryDocumentSnapshot; import com.google.firebase.firestore.QueryDocumentSnapshot;
import com.google.firebase.firestore.QuerySnapshot; import com.google.firebase.firestore.QuerySnapshot;
@ -12,10 +14,10 @@ import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
public class FirestoreReception_classIdDatabase { public class FirestoreReception_classIdDatabase {
private FirebaseFirestore db; private FirebaseFirestore db;
private List<Integer> classIdList = new ArrayList<>(); private List<Integer> classIdList= new ArrayList<>();
public FirestoreReception_classIdDatabase() { public FirestoreReception_classIdDatabase() {
db = FirebaseFirestore.getInstance(); db = FirebaseFirestore.getInstance();

View File

@ -2,7 +2,6 @@ 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;
@ -15,17 +14,12 @@ 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;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
public class MainActivity extends AppCompatActivity implements View.OnClickListener { public class MainActivity extends AppCompatActivity implements View.OnClickListener {
@ -55,7 +49,8 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
//取得するためのクラスID //取得するためのクラスID
private int classId; private int classId;
private final AppDatabase appDatabase = null; private String address;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -89,7 +84,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
// firestoreの受信関連 // firestoreの受信関連
db = FirebaseFirestore.getInstance(); db = FirebaseFirestore.getInstance();
firestoreReception = new FirestoreReception(); firestoreReception = new FirestoreReception();
Log.d("MainActivity", "geocodeAddress"); Log.d("MainActivity","geocodeAddress");
ExecutorService executor = Executors.newSingleThreadExecutor(); ExecutorService executor = Executors.newSingleThreadExecutor();
@ -140,28 +135,9 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
// ルート作成のクリック処理 // ルート作成のクリック処理
if (view == root) { if (view == root) {
imageRoot.setImageResource(R.drawable.pin); imageRoot.setImageResource(R.drawable.pin);
if (isClassIdSet()) { fetchDataAndCreateRoute();
isSetupExists(classId).thenAccept(setupExists -> {
if (setupExists) {
fetchDataAndCreateRoute();
} else {
runOnUiThread(() -> {
Toast.makeText(this, "セットアップが設定されていません", Toast.LENGTH_SHORT).show();
});
}
}).exceptionally(ex -> {
ex.printStackTrace();
runOnUiThread(() -> {
Toast.makeText(this, "エラーが発生しました", Toast.LENGTH_SHORT).show();
});
return null;
});
} else {
Toast.makeText(this, "クラスIDが設定されていません", Toast.LENGTH_SHORT).show();
}
} }
if (view == imageRoot) { if (view == imageRoot) {
imageRoot.setImageResource(R.drawable.pin); imageRoot.setImageResource(R.drawable.pin);
fetchDataAndCreateRoute(); fetchDataAndCreateRoute();
@ -181,7 +157,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
} }
} }
//IDに関する処理 //UUIDを表示するかのダイアログ
private void showUUIDYesNoDialog() { private void showUUIDYesNoDialog() {
firestoreReception_classIdDatabase = new FirestoreReception_classIdDatabase(); firestoreReception_classIdDatabase = new FirestoreReception_classIdDatabase();
List<Integer> classIdList = firestoreReception_classIdDatabase.getAllDocumentsFromClassIdDatabase(); List<Integer> classIdList = firestoreReception_classIdDatabase.getAllDocumentsFromClassIdDatabase();
@ -189,30 +165,21 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("クラスID"); builder.setTitle("クラスID");
builder.setMessage("あなたのクラスIDを表示/もしくは新規で作成しますか?"); builder.setMessage("あなたのクラスIDを表示しますか?");
builder.setPositiveButton("作成", new DialogInterface.OnClickListener() { builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
classId = CreateUUID.generateUUID(classIdList); classId = CreateUUID.generateUUID(classIdList);
// 生成されたクラスIDを表示するメソッド Toast.makeText(MainActivity.this, "クラスID: " + classId, Toast.LENGTH_SHORT).show();
showClassIdDialog("生成されたクラスID",classId); imageUuid.setImageResource(R.drawable.checked_image);
} }
}); });
builder.setNegativeButton("表示", new DialogInterface.OnClickListener() { builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
//roomを扱うため非同期処理 Log.d("DialogNO", "DialogでNoが選ばれました");
ExecutorService executor = Executors.newSingleThreadExecutor(); imageUuid.setImageResource(R.drawable.checked_image);
executor.execute(() -> {
// 現在のクラスIDを取得
int currentClassId = getCurrentClassIdFromRoom();
runOnUiThread(() -> {
// 現在のクラスIDを表示するダイアログ
showClassIdDialog("現在のクラスID",currentClassId);
});
});
executor.shutdown();
} }
}); });
@ -220,47 +187,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
alertDialog.show(); alertDialog.show();
} }
private int getCurrentClassIdFromRoom() {
AppDatabase db = getDatabaseInstance();
SetUpTableDao setUpTableDao = db.setUpTableDao();
// 現在のクラスIDを取得
return setUpTableDao.getClassId();
}
//クラスIDを表示するダイアログ
private void showClassIdDialog(String title, int classId) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(title);
builder.setMessage("クラスID: " + classId);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
private boolean isClassIdSet() {
// classIdが0より大きい場合trueを返す
return classId > 0;
}
private CompletableFuture<Boolean> isSetupExists(int classId) {
final ExecutorService executorService = Executors.newSingleThreadExecutor();
return CompletableFuture.supplyAsync(() -> {
AppDatabase db = getDatabaseInstance();
SetUpTableDao setUpTableDao = db.setUpTableDao();
List<SetUpTable> checkData = setUpTableDao.getAll();
for (SetUpTable setUpTable : checkData) {
if (setUpTable.classId == classId) {
return true;
}
}
return false;
}, executorService).whenComplete((result, throwable) -> executorService.shutdown());
}
//ルート作成の非同期処理 //ルート作成の非同期処理
private void fetchDataAndCreateRoute() { private void fetchDataAndCreateRoute() {
@ -317,15 +243,13 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
//final宣言することによってスレッドセーフになる(ラムダ式内で使えるようにする) //final宣言することによってスレッドセーフになる(ラムダ式内で使えるようにする)
final List<MyDataClass> finalMyDataList = myDataList; final List<MyDataClass> finalMyDataList = myDataList;
CreateSchedule createSchedule = new CreateSchedule(MainActivity.this); CreateRoot createRoot = new CreateRoot(MainActivity.this);
String startPointLatLngString = createSchedule.receiveData(myDataList, getApplicationContext()); Boolean notDuplicates = createRoot.receiveData(finalMyDataList, getApplicationContext());
runOnUiThread(() -> { runOnUiThread(() -> {
if ( !startPointLatLngString.equals("")) { if (notDuplicates) {
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 {
//保護者の重複による警告ダイアログ //保護者の重複による警告ダイアログ
@ -337,19 +261,6 @@ 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<>();
@ -376,7 +287,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
private AppDatabase getDatabaseInstance() { private AppDatabase getDatabaseInstance() {
return Room.databaseBuilder(getApplicationContext(), AppDatabase.class, "SetUpTable").fallbackToDestructiveMigration().build(); return Room.databaseBuilder(getApplicationContext(), AppDatabase.class, "SetUpTable").build();
} }

View File

@ -1,32 +1,57 @@
package com.example.oplogy; package com.example.oplogy;
import android.content.Intent; import androidx.fragment.app.FragmentActivity;
import android.content.SharedPreferences; import android.graphics.Color;
import android.os.Bundle; import android.os.Bundle;
import android.os.Parcelable;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import android.webkit.WebSettings; import android.widget.AdapterView;
import android.webkit.WebView; import android.widget.ArrayAdapter;
import android.webkit.WebViewClient;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;
import androidx.fragment.app.FragmentActivity; import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.example.oplogy.databinding.MapsBinding; import com.example.oplogy.databinding.MapsBinding;
import com.google.common.reflect.TypeToken; import com.google.android.gms.maps.model.PolylineOptions;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import java.lang.reflect.Type; import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
public class Maps extends FragmentActivity implements View.OnClickListener { public class Maps extends FragmentActivity implements OnMapReadyCallback, View.OnClickListener, GoogleMap.OnMarkerClickListener {
private WebView webView;
ImageView backMain; ImageView backMain;
private GoogleMap mMap;
private MapsBinding binding; private MapsBinding binding;
private ArrayList<Parcelable> myDataList; private LinearLayout locationsName;
private Spinner dateSpinner;
private static final int[] COLORS = new int[]{
Color.BLUE, Color.RED, Color.GREEN, Color.MAGENTA, Color.CYAN, Color.YELLOW
};
private int colorIndex = 0;
private List<LatLng> latLngList = new ArrayList<>();
private List<String> nameList = new ArrayList<>();
private List<Integer> colorList = new ArrayList<>();
private Map<String, Runnable> dateMap = new HashMap<>();
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -35,91 +60,282 @@ public class Maps extends FragmentActivity implements View.OnClickListener {
binding = MapsBinding.inflate(getLayoutInflater()); binding = MapsBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot()); setContentView(binding.getRoot());
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
backMain = findViewById(R.id.BackMain); backMain = findViewById(R.id.BackMain);
backMain.setOnClickListener(this); backMain.setOnClickListener(this);
webView = findViewById(R.id.webView); locationsName = findViewById(R.id.locationsName);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient());
// startPointLatLngStringの取得 // 日付を入れる処理
String startPointLatLngString = getIntent().getStringExtra("startPointLatLngString"); String dateData = "6月3日/6月4日/6月5日/6月6日/6月7日";
//MyDataListの取得
List<MyDataClass> myDataList = getMyDataList();
String latlngString = ""; ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item);
for (int i = -1; i < myDataList.size(); i++) { adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
if (i < 0) { String[] dates = dateData.split("/");
//家庭訪問の開始地点の緯度経度 for (String date : dates) {
latlngString += startPointLatLngString + "/"; adapter.add(date);
} else { }
//各家庭の緯度経度
String latlng = myDataList.get(i).getLatLngString(); // 各日付に対応するRunnableを設定する
int startIndex = latlng.indexOf("(") + 1; dateMap.put("6月3日", this::firstMapAndNames);
int endIndex = latlng.indexOf(")"); dateMap.put("6月4日", this::secondMapAndNames);
String latlngOnly = latlng.substring(startIndex, endIndex); dateMap.put("6月5日", this::thirdMapAndNames);
latlngString += latlngOnly; // 必要に応じて追加の日付に対応するメソッドをここに追加
if (i < myDataList.size() - 1) { dateMap.put("6月6日", this::additionalMapAndNames);
latlngString += "/"; dateMap.put("6月7日", this::additionalMapAndNames2);
dateSpinner = findViewById(R.id.date);
dateSpinner.setAdapter(adapter);
dateSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String selectedItem = (String) parent.getItemAtPosition(position);
Runnable mapLoader = dateMap.get(selectedItem);
if (mapLoader != null) {
mapLoader.run();
} }
} }
@Override
public void onNothingSelected(AdapterView<?> parent) {
// Do nothing
}
});
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.setOnMarkerClickListener(this);
firstMapAndNames(); // 最初に表示するデータセットをロード
}
private void firstMapAndNames() {
String locationData = "35.09050879999539,136.87845379325216/35.091950716938875,136.8826598363985/35.09273643623442,136.88154941341296/35.09473643623442,136.88154941341296/35.09673643623442,136.88154941341296";
String nameData = "名古屋港水族館/2番目/3番目/4番目/5番目";
loadMapAndNames(locationData, nameData);
}
private void secondMapAndNames() {
String locationData2 = "35.09050879999539,136.87845379325216/35.091950716938875,136.8826598363985/35.09273643623442,136.88154941341296";
String nameData2 = "名古屋港水族館/2番目/3番目";
loadMapAndNames(locationData2, nameData2);
}
private void thirdMapAndNames() {
String locationData3 = "35.09050879999539,136.87845379325216/35.091950716938875,136.8826598363985";
String nameData3 = "名古屋港水族館/2番目";
loadMapAndNames(locationData3, nameData3);
}
// 追加の日付に対応するメソッド
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() {
String locationData5 = "35.09050879999539,136.87845379325216/35.091950716938875,136.8826598363985/35.09400000000000,136.88400000000000";
String nameData5 = "名古屋港水族館/2番目/3番目";
loadMapAndNames(locationData5, nameData5);
}
private void loadMapAndNames(String locationData, String nameData) {
try {
latLngList.clear();
nameList.clear();
colorList.clear();
locationsName.removeAllViews();
mMap.clear();
String[] locArray = locationData.split("/");
String[] nameArray = nameData.split("/");
for (int i = 0; i < locArray.length; i++) {
String[] latLng = locArray[i].split(",");
if (latLng.length == 2) {
double latitude = Double.parseDouble(latLng[0]);
double longitude = Double.parseDouble(latLng[1]);
LatLng position = new LatLng(latitude, longitude);
latLngList.add(position);
String name = nameArray.length > i ? nameArray[i] : "Unknown";
nameList.add(name);
int color = getNextColor();
colorList.add(color);
addPinToMap(name, position, color);
addLocationToScrollView(name, color);
}
}
if (!latLngList.isEmpty()) {
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLngList.get(0), 17));
drawRoute();
}
} catch (Exception e) {
Log.e("Maps", "Error loading maps and names", e);
} }
Log.d("Maps", "startPointLatLngString" + startPointLatLngString);
Log.d("Maps", "latlngString" + latlngString);
loadMapInWebView(latlngString);
} }
// 共有プリファレンスからMyDataListを取得するメソッド private void drawRoute() {
private List<MyDataClass> getMyDataList() { new Thread(() -> {
// 共有プリファレンスのインスタンスを取得 try {
SharedPreferences sharedPreferences = getSharedPreferences("MyDataList", MODE_PRIVATE); StringBuilder urlBuilder = new StringBuilder("https://maps.googleapis.com/maps/api/directions/json?");
urlBuilder.append("origin=").append(latLngList.get(0).latitude).append(",").append(latLngList.get(0).longitude);
// 共有プリファレンスからJSON形式のデータを取得 urlBuilder.append("&destination=").append(latLngList.get(latLngList.size() - 1).latitude).append(",").append(latLngList.get(latLngList.size() - 1).longitude);
String json = sharedPreferences.getString("myDataList", ""); if (latLngList.size() > 2) {
// JSON形式のデータをMyDataListに変換
Gson gson = new Gson();
Type type = new TypeToken<List<MyDataClass>>() {
}.getType();
List<MyDataClass> myDataList = gson.fromJson(json, type);
return myDataList;
}
// WebViewの処理ですMapの中の処理をやっています
private void loadMapInWebView(String locations) {
// 区切ることで追加の地点を入れて最終地点にピンを打ってある状態です
String[] locArray = locations.split("/");
// URLで経路案内での表示をしています
StringBuilder urlBuilder = new StringBuilder("https://www.google.com/maps/dir/?api=1&travelmode=driving");
if (locArray.length > 0) {
urlBuilder.append("&origin=").append(locArray[0]);
if (locArray.length > 1) {
urlBuilder.append("&destination=").append(locArray[locArray.length - 1]);
if (locArray.length > 2) {
urlBuilder.append("&waypoints="); urlBuilder.append("&waypoints=");
for (int i = 1; i < locArray.length - 1; i++) { for (int i = 1; i < latLngList.size() - 1; i++) {
urlBuilder.append(locArray[i]); urlBuilder.append("via:").append(latLngList.get(i).latitude).append(",").append(latLngList.get(i).longitude);
if (i < locArray.length - 2) { if (i < latLngList.size() - 2) {
urlBuilder.append("|"); urlBuilder.append("|");
} }
} }
} }
urlBuilder.append("&mode=driving");
urlBuilder.append("&key=").append(getString(R.string.maps_api_key));
URL url = new URL(urlBuilder.toString());
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
InputStreamReader isr = new InputStreamReader(conn.getInputStream());
BufferedReader br = new BufferedReader(isr);
StringBuilder jsonResults = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
jsonResults.append(line);
}
br.close();
Log.d("Maps", "API response: " + jsonResults.toString());
JsonObject jsonObject = new Gson().fromJson(jsonResults.toString(), JsonObject.class);
JsonArray routes = jsonObject.getAsJsonArray("routes");
if (routes.size() > 0) {
JsonObject route = routes.get(0).getAsJsonObject();
JsonObject polyline = route.getAsJsonObject("overview_polyline");
String encodedString = polyline.get("points").getAsString();
List<LatLng> points = decodePoly(encodedString);
Log.d("Maps", "Polyline points: " + points);
runOnUiThread(() -> mMap.addPolyline(new PolylineOptions().addAll(points).width(5).color(Color.BLUE)));
} else {
JsonPrimitive errorMessage = jsonObject.getAsJsonPrimitive("error_message");
if (errorMessage != null) {
Log.e("Maps", "Error: " + errorMessage.getAsString());
} else {
Log.e("Maps", "No routes found and no error message provided");
}
}
} catch (Exception e) {
Log.e("Maps", "Error drawing route", e);
} }
}).start();
}
private List<LatLng> decodePoly(String encoded) {
List<LatLng> poly = new ArrayList<>();
int index = 0, len = encoded.length();
int lat = 0, lng = 0;
while (index < len) {
int b, shift = 0, result = 0;
do {
b = encoded.charAt(index++) - 63;
result |= (b & 0x1f) << shift;
shift += 5;
} while (b >= 0x20);
int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
lat += dlat;
shift = 0;
result = 0;
do {
b = encoded.charAt(index++) - 63;
result |= (b & 0x1f) << shift;
shift += 5;
} while (b >= 0x20);
int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
lng += dlng;
LatLng p = new LatLng((((double) lat / 1E5)), (((double) lng / 1E5)));
poly.add(p);
} }
webView.loadUrl(urlBuilder.toString()); return poly;
}
private float getHueFromColor(int color) {
float[] hsv = new float[3];
Color.colorToHSV(color, hsv);
return hsv[0];
}
private void addPinToMap(String locationName, LatLng position, int color) {
Marker marker = mMap.addMarker(new MarkerOptions()
.position(position)
.title(locationName)
.icon(BitmapDescriptorFactory.defaultMarker(getHueFromColor(color)))
);
if (marker != null) {
marker.setTag(locationName);
}
}
private void addLocationToScrollView(String locationName, int color) {
runOnUiThread(() -> {
try {
TextView textView = new TextView(this);
textView.setText(locationName);
textView.setTextSize(20);
textView.setPadding(16, 16, 16, 16);
textView.setBackgroundColor(color);
View underline = new View(this);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
3
);
params.setMargins(0, 0, 0, 16);
underline.setLayoutParams(params);
underline.setBackgroundColor(Color.BLACK);
locationsName.addView(textView);
locationsName.addView(underline);
} catch (Exception e) {
Log.e("Maps", "Error adding location to scroll view", e);
}
});
}
private int getNextColor() {
int color = COLORS[colorIndex];
colorIndex = (colorIndex + 1) % COLORS.length;
return color;
} }
@Override @Override
public void onClick(View view) { public void onClick(View view) {
if (view == backMain) { if (view.getId() == R.id.BackMain) {
Intent backMain = new Intent(Maps.this, MainActivity.class); finish();
startActivity(backMain);
} }
} }
@Override
public boolean onMarkerClick(Marker marker) {
String locationName = (String) marker.getTag();
if (locationName != null) {
marker.setTitle(locationName);
marker.showInfoWindow();
}
return false;
}
} }

View File

@ -1,5 +1,6 @@
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;
@ -29,7 +30,7 @@ public class MyDataClass {
private Long secondDayTimezoneLong; private Long secondDayTimezoneLong;
private String secondDayParentStartTimeString; private String secondDayParentStartTimeString;
private String secondDayParentEndTimeString; private String secondDayParentEndTimeString;
private String latLngString; private LatLng latLng;
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) {
@ -238,11 +239,11 @@ public class MyDataClass {
return secondDayStartDateString; return secondDayStartDateString;
} }
public void setLatLngString(String latLng) { public void setLatLng(LatLng latLng) {
this.latLngString = latLng; this.latLng=latLng;
} }
public String getLatLngString() { public LatLng getLatLng() {
return latLngString; return latLng;
} }
} }

View File

@ -10,7 +10,6 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Paint; import android.graphics.Paint;
import android.os.Bundle; import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.widget.Button; import android.widget.Button;
import android.widget.DatePicker; import android.widget.DatePicker;
@ -25,7 +24,6 @@ import androidx.fragment.app.FragmentActivity;
import androidx.room.Room; import androidx.room.Room;
import java.util.Locale; import java.util.Locale;
import java.util.Objects;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
@ -44,15 +42,15 @@ public class SetUpActivity extends FragmentActivity
String startBreakTime; String startBreakTime;
String endBreakTime; String endBreakTime;
int totalStudent; int totalStudent;
private TextView textViewTeacherName; private TextView setTeacherName;
private TextView textViewStartPoint; private TextView setStartPoint;
private TextView textViewStartTime; private TextView setStartTime;
private TextView textViewEndTime; private TextView setEndTime;
private TextView textViewStartBreakTime; private TextView setStartBreakTime;
private TextView textViewEndBreakTime; private TextView setEndBreakTime;
private TextView textViewTotalStudent; private TextView setTotalStudent;
private int intIsDateSelected; private int isDateSelected;
private int intIsStartTimeSelected; private int isStartTimeSelected;
String stringYear; String stringYear;
String stringMonth; String stringMonth;
@ -62,11 +60,11 @@ public class SetUpActivity extends FragmentActivity
String stringHourOfDay; String stringHourOfDay;
String stringMinute; String stringMinute;
Button buttonFirstDay; Button setFirstDay;
Button buttonSecondDay; Button setSecondDay;
Button buttonThirdDay; Button setThirdDay;
Button buttonStartTimeButton; Button setStartTimeButton;
Button buttonEndTimeButton; Button setEndTimeButton;
@ -78,28 +76,28 @@ public class SetUpActivity extends FragmentActivity
int classId= getIntent().getIntExtra("classId", 100000); int classId= getIntent().getIntExtra("classId", 100000);
textViewTeacherName = findViewById(R.id.teacherName); //先生の名前 setTeacherName = findViewById(R.id.teacherName); //先生の名前
textViewStartPoint = findViewById(R.id.startPoint); //開始地点 setStartPoint = findViewById(R.id.startPoint); //開始地点
buttonFirstDay = findViewById(R.id.setFirstDayButton); //1日目の日付 setFirstDay = findViewById(R.id.setFirstDayButton); //1日目の日付
buttonSecondDay = findViewById(R.id.setSecondDayButton); //2日目の日付 setSecondDay = findViewById(R.id.setSecondDayButton); //2日目の日付
buttonThirdDay = findViewById(R.id.setThirdDayButton); //3日目の日付 setThirdDay = findViewById(R.id.setThirdDayButton); //3日目の日付
buttonStartTimeButton = findViewById(R.id.startTimeSetButton); //開始時刻を設定するボタン setStartTimeButton = findViewById(R.id.startTimeSetButton); //開始時刻を設定するボタン
textViewStartTime = findViewById(R.id.startTime); //開始時刻を出力するTextView setStartTime = findViewById(R.id.startTime); //開始時刻を出力するTextView
buttonEndTimeButton = findViewById(R.id.endTimeSetButton); //終了時刻を設定するボタン setEndTimeButton = findViewById(R.id.endTimeSetButton); //終了時刻を設定するボタン
textViewEndTime = findViewById(R.id.endTime); //終了時刻を出力するTextView setEndTime = findViewById(R.id.endTime); //終了時刻を出力するTextView
RadioButton radioButtonTenMinute = findViewById(R.id.tenMinute); //訪問間隔10分 RadioButton setTenMinute = findViewById(R.id.tenMinute); //訪問間隔10分
RadioButton radioButtonFifteenMinute = findViewById(R.id.fifteenMinute); //訪問間隔15分 RadioButton setFifteenMinute = findViewById(R.id.fifteenMinute); //訪問間隔15分
RadioButton radioButtonThirtyMinute = findViewById(R.id.thirtyMinute); //訪問間隔30分 RadioButton setThirtyMinute = findViewById(R.id.thirtyMinute); //訪問間隔30分
textViewStartBreakTime = findViewById(R.id.startBreakTime); //休憩開始時刻 setStartBreakTime = findViewById(R.id.startBreakTime); //休憩開始時刻
textViewStartBreakTime.setPaintFlags(Paint.UNDERLINE_TEXT_FLAG); setStartBreakTime.setPaintFlags(Paint.UNDERLINE_TEXT_FLAG);
textViewEndBreakTime = findViewById(R.id.endBreakTime); //休憩終了時刻 setEndBreakTime = findViewById(R.id.endBreakTime); //休憩終了時刻
textViewEndBreakTime.setPaintFlags(Paint.UNDERLINE_TEXT_FLAG); setEndBreakTime.setPaintFlags(Paint.UNDERLINE_TEXT_FLAG);
textViewTotalStudent = findViewById(R.id.totalStudent); //クラスの人数 setTotalStudent = findViewById(R.id.totalStudent); //クラスの人数
ImageView toMain = findViewById(R.id.toMain); ImageView toMain = findViewById(R.id.toMain);
Button setUp = findViewById(R.id.setUpButton); //画面下の設定ボタン Button setUp = findViewById(R.id.setUpButton); //画面下の設定ボタン
@ -112,20 +110,20 @@ public class SetUpActivity extends FragmentActivity
setUp.setOnClickListener(view -> { setUp.setOnClickListener(view -> {
teacherName = textViewTeacherName.getText().toString(); //各変数に値を挿入 teacherName = setTeacherName.getText().toString(); //各変数に値を挿入
Log.d(TAG, "Teacher Name: " + teacherName); Log.d(TAG, "Teacher Name: " + teacherName);
startPoint = textViewStartPoint.getText().toString(); startPoint = setStartPoint.getText().toString();
Log.d(TAG, "Start Point: " + startPoint); Log.d(TAG, "Start Point: " + startPoint);
Log.d(TAG, "First Day:" + firstDay); Log.d(TAG, "First Day:" + firstDay);
Log.d(TAG, "Second Day:" + secondDay); Log.d(TAG, "Second Day:" + secondDay);
Log.d(TAG, "Third Day:" + thirdDay); Log.d(TAG, "Third Day:" + thirdDay);
Log.d(TAG, "Start Time" + startTime); Log.d(TAG, "Start Time" + startTime);
Log.d(TAG, "End Time" + endTime); Log.d(TAG, "End Time" + endTime);
if (radioButtonTenMinute.isChecked()){ //ラジオボタンの状態を取得 if (setTenMinute.isChecked()){ //ラジオボタンの状態を取得
intervalTime = "10"; intervalTime = "10";
} else if (radioButtonFifteenMinute.isChecked()) { } else if (setFifteenMinute.isChecked()) {
intervalTime = "15"; intervalTime = "15";
} else if (radioButtonThirtyMinute.isChecked()) { } else if (setThirtyMinute.isChecked()) {
intervalTime = "30"; intervalTime = "30";
} else { } else {
intervalTime = "0"; intervalTime = "0";
@ -133,25 +131,10 @@ public class SetUpActivity extends FragmentActivity
Log.d(TAG, "Interval Time" + intervalTime); Log.d(TAG, "Interval Time" + intervalTime);
Log.d(TAG, "Start Break Time" + startBreakTime); Log.d(TAG, "Start Break Time" + startBreakTime);
Log.d(TAG, "End Break Time" + endBreakTime); Log.d(TAG, "End Break Time" + endBreakTime);
totalStudent = Integer.parseInt(setTotalStudent.getText().toString()); //数値型に変更
Log.d(TAG, "Total Student" + totalStudent); Log.d(TAG, "Total Student" + totalStudent);
Log.d(TAG, "onClick: できてるよ"); Log.d(TAG, "onClick: できてるよ");
// クラスの人数を数値に変換して取得
try {
totalStudent = Integer.parseInt(textViewTotalStudent.getText().toString());
} catch (NumberFormatException e) {
totalStudent = 0; // デフォルト値を設定するかエラー処理を追加することも考慮する必要があります
}
// 入力データのバリデーション
if (TextUtils.isEmpty(teacherName) || TextUtils.isEmpty(startPoint) || TextUtils.isEmpty(startTime)
|| TextUtils.isEmpty(firstDay) || TextUtils.isEmpty(secondDay) || TextUtils.isEmpty(thirdDay)
|| TextUtils.isEmpty(endTime) || Objects.equals(intervalTime, "0") || TextUtils.isEmpty(startBreakTime)
|| TextUtils.isEmpty(endBreakTime) || totalStudent <= 0) {
Toast.makeText(SetUpActivity.this, "必須項目を入力してください", Toast.LENGTH_SHORT).show();
return;
}
// データベースへの登録処理 // データベースへの登録処理
ExecutorService executor = Executors.newSingleThreadExecutor(); ExecutorService executor = Executors.newSingleThreadExecutor();
@ -192,10 +175,9 @@ public class SetUpActivity extends FragmentActivity
SharedPreferences sharedPreferences=getSharedPreferences("visitingDate",MODE_PRIVATE); SharedPreferences sharedPreferences=getSharedPreferences("visitingDate",MODE_PRIVATE);
SharedPreferences.Editor editor= sharedPreferences.edit(); SharedPreferences.Editor editor= sharedPreferences.edit();
//editorに値を渡す editor.putString("day1",firstDay);
editor.putString("day1",firstDay); //1日目 editor.putString("day2",secondDay);
editor.putString("day2",secondDay); //2日目 editor.putString("day3",thirdDay);
editor.putString("day3",thirdDay); //3日目
editor.apply(); editor.apply();
@ -204,71 +186,52 @@ public class SetUpActivity extends FragmentActivity
}); });
//DatePicker用 setFirstDay.setOnClickListener(v ->{
buttonFirstDay.setOnClickListener(v ->{ isDateSelected = 1;
intIsDateSelected = 1; //ボタンの判別Date
showDatePickerDialog(); //DatePickerの表示 showDatePickerDialog(); //DatePickerの表示
}); });
buttonSecondDay.setOnClickListener(v ->{ setSecondDay.setOnClickListener(v ->{
intIsDateSelected = 2; isDateSelected = 2;
showDatePickerDialog(); showDatePickerDialog();
}); });
buttonThirdDay.setOnClickListener(v ->{ setThirdDay.setOnClickListener(v ->{
intIsDateSelected = 3; isDateSelected = 3;
showDatePickerDialog(); showDatePickerDialog();
}); });
//TimePicker用 setStartTimeButton.setOnClickListener(v -> {
buttonStartTimeButton.setOnClickListener(v -> { isStartTimeSelected = 1; //ボタンの判別
intIsStartTimeSelected = 1; //ボタンの判別Time showTimePickerDialog(); //TimePickerの表示
showTimePickerDialog(); //TimePickerの表示
}); });
buttonEndTimeButton.setOnClickListener(v -> { setEndTimeButton.setOnClickListener(v -> {
intIsStartTimeSelected = 2; isStartTimeSelected = 2;
showTimePickerDialog(); showTimePickerDialog();
}); });
textViewStartBreakTime.setOnClickListener(v -> { setStartBreakTime.setOnClickListener(v -> {
intIsStartTimeSelected = 3; isStartTimeSelected = 3;
showTimePickerDialog(); showTimePickerDialog();
}); });
textViewEndBreakTime.setOnClickListener(v -> { setEndBreakTime.setOnClickListener(v -> {
intIsStartTimeSelected = 4; isStartTimeSelected = 4;
showTimePickerDialog(); showTimePickerDialog();
}); });
//リセットボタンの処理 //リセットボタンの処理
reset.setOnClickListener(v -> { //テキストとラジオボタンの選択を消去 reset.setOnClickListener(v -> { //テキストとラジオボタンの選択を消去
textViewTeacherName.setText(""); setTeacherName.setText("");
textViewStartPoint.setText(""); setStartPoint.setText("");
buttonFirstDay.setText(""); setTenMinute.setChecked(false);
buttonSecondDay.setText(""); setFifteenMinute.setChecked(false);
buttonThirdDay.setText(""); setThirtyMinute.setChecked(false);
radioButtonTenMinute.setChecked(false); setStartBreakTime.setText("");
radioButtonFifteenMinute.setChecked(false); setEndBreakTime.setText("");
radioButtonThirtyMinute.setChecked(false); setTotalStudent.setText("");
textViewStartTime.setText("");
textViewEndTime.setText("");
textViewStartBreakTime.setText("");
textViewEndBreakTime.setText("");
textViewTotalStudent.setText("");
teacherName = "";
startPoint = "";
firstDay = "";
secondDay = "";
thirdDay = "";
startTime = "";
endTime = "";
intervalTime = "";
startBreakTime = "";
endBreakTime ="" ;
ExecutorService executor = Executors.newSingleThreadExecutor(); ExecutorService executor = Executors.newSingleThreadExecutor();
executor.execute(() -> { executor.execute(() -> {
@ -284,27 +247,26 @@ public class SetUpActivity extends FragmentActivity
// DatePickerDialogで選択された日付を処理する // DatePickerDialogで選択された日付を処理する
String str = String.format(Locale.JAPAN, "%02d/%02d", month + 1, dayOfMonth); // TextViewに表示する日付の形式を設定 String str = String.format(Locale.JAPAN, "%02d/%02d", month + 1, dayOfMonth); // TextViewに表示する日付の形式を設定
if (intIsDateSelected == 1) { if (isDateSelected == 1) {
stringYear = String.valueOf(year); // stringYear = String.valueOf(year); //
stringMonth = String.format(Locale.JAPAN, "%02d", month + 1); // stringMonth = String.format(Locale.JAPAN, "%02d", month + 1); //
stringDayOfMonth = String.format(Locale.JAPAN, "%02d", dayOfMonth); // stringDayOfMonth = String.format(Locale.JAPAN, "%02d", dayOfMonth); //
firstDay = stringYear + stringMonth + stringDayOfMonth; //8桁の文字列を作成 )20240604 firstDay = stringYear + stringMonth + stringDayOfMonth;
buttonFirstDay.setText(str); //buttonにformatされた文字列を挿入 setFirstDay.setText(str);
} else if (isDateSelected == 2) {
} else if (intIsDateSelected == 2) {
stringYear = String.valueOf(year); stringYear = String.valueOf(year);
stringMonth = String.format(Locale.JAPAN, "%02d", month + 1); stringMonth = String.format(Locale.JAPAN, "%02d", month + 1);
stringDayOfMonth = String.format(Locale.JAPAN, "%02d", dayOfMonth); stringDayOfMonth = String.format(Locale.JAPAN, "%02d", dayOfMonth);
secondDay = stringYear + stringMonth + stringDayOfMonth; secondDay = stringYear + stringMonth + stringDayOfMonth;
buttonSecondDay.setText(str); setSecondDay.setText(str);
} else if (intIsDateSelected == 3) { } else if (isDateSelected == 3) {
stringYear = String.valueOf(year); stringYear = String.valueOf(year);
stringMonth = String.format(Locale.JAPAN, "%02d", month + 1); stringMonth = String.format(Locale.JAPAN, "%02d", month + 1);
stringDayOfMonth = String.format(Locale.JAPAN, "%02d", dayOfMonth); stringDayOfMonth = String.format(Locale.JAPAN, "%02d", dayOfMonth);
thirdDay = stringYear + stringMonth + stringDayOfMonth; thirdDay = stringYear + stringMonth + stringDayOfMonth;
buttonThirdDay.setText(str); setThirdDay.setText(str);
} }
} }
@ -314,38 +276,38 @@ public class SetUpActivity extends FragmentActivity
public void onTimeSet(TimePicker view, int hourOfDay, int minute) { public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
String str = String.format(Locale.JAPAN, "%02d:%02d", hourOfDay, minute); // Textviewに保存する形式を設定 String str = String.format(Locale.JAPAN, "%02d:%02d", hourOfDay, minute); // Textviewに保存する形式を設定
if (intIsStartTimeSelected == 1) { if (isStartTimeSelected == 1) {
stringHourOfDay = String.format("%02d", hourOfDay); // stringHourOfDay = String.format("%02d", hourOfDay);
stringMinute = String.format("%02d", minute); // stringMinute = String.format("%02d", minute);
startTime = stringHourOfDay + stringMinute; //4桁の文字列を作成 0930 startTime = stringHourOfDay + stringMinute;
textViewStartTime.setText(str); //textViewにformatされている文字列を挿入 setStartTime.setText(str);
} else if (intIsStartTimeSelected == 2) { } else if (isStartTimeSelected == 2) {
stringHourOfDay = String.format("%02d", hourOfDay); stringHourOfDay = String.format("%02d", hourOfDay);
stringMinute = String.format("%02d", minute); stringMinute = String.format("%02d", minute);
endTime = stringHourOfDay + stringMinute; endTime = stringHourOfDay + stringMinute;
textViewEndTime.setText(str); setEndTime.setText(str);
} else if (intIsStartTimeSelected == 3) { } else if (isStartTimeSelected == 3) {
stringHourOfDay = String.format("%02d", hourOfDay); stringHourOfDay = String.format("%02d", hourOfDay);
stringMinute = String.format("%02d", minute); stringMinute = String.format("%02d", minute);
startBreakTime =stringHourOfDay + stringMinute; startBreakTime =stringHourOfDay + stringMinute;
textViewStartBreakTime.setText(" " + str + " "); setStartBreakTime.setText(" " + str + " ");
} else if (intIsStartTimeSelected == 4) { } else if (isStartTimeSelected == 4) {
stringHourOfDay = String.format("%02d", hourOfDay); stringHourOfDay = String.format("%02d", hourOfDay);
stringMinute = String.format("%02d", minute); stringMinute = String.format("%02d", minute);
endBreakTime = stringHourOfDay + stringMinute; endBreakTime = stringHourOfDay + stringMinute;
textViewEndBreakTime.setText(" " + str + " "); setEndBreakTime.setText(" " + str + " ");
} }
} }
private void showDatePickerDialog() { //DatePickerDialogを表示する private void showDatePickerDialog() {
DialogFragment newFragment = new DatePick(); DialogFragment newFragment = new DatePick();
newFragment.show(getSupportFragmentManager(), "datePicker"); newFragment.show(getSupportFragmentManager(), "datePicker");
} }
private void showTimePickerDialog() { // TimePickerDialogを表示する private void showTimePickerDialog() { // Dialogを表示する
DialogFragment newFragment = new TimePick(); DialogFragment newFragment = new TimePick();
newFragment.show(getSupportFragmentManager(), "timePicker"); newFragment.show(getSupportFragmentManager(), "timePicker");
} }

View File

@ -1,5 +1,4 @@
package com.example.oplogy; package com.example.oplogy;
import androidx.room.Entity; import androidx.room.Entity;
import androidx.room.PrimaryKey; import androidx.room.PrimaryKey;
@ -22,7 +21,7 @@ public class SetUpTable {
//コンストラクタ //コンストラクタ
public SetUpTable(String teacherName, String startPoint, String startTime, String endTime, public SetUpTable(String teacherName, String startPoint, String startTime, String endTime,
String intervalTime, String startBreakTime, String endBreakTime, int totalStudent, int classId) { String intervalTime, String startBreakTime, String endBreakTime, int totalStudent,int classId) {
this.teacherName = teacherName; this.teacherName = teacherName;
this.startPoint = startPoint; this.startPoint = startPoint;
this.startTime = startTime; this.startTime = startTime;
@ -33,53 +32,41 @@ public class SetUpTable {
this.totalStudent = totalStudent; this.totalStudent = totalStudent;
this.classId = classId; this.classId = classId;
} }
//getter //getter
public int getId() { public int getId() {
return id; return id;
} }
public String getTeacherName() { public String getTeacherName() {
return teacherName; return teacherName;
} }
public String getStartPoint() { public String getStartPoint() {
return startPoint; return startPoint;
} }
public String getStartTime() { public String getStartTime() {
return startTime; return startTime;
} }
public String getEndTime() { public String getEndTime() {
return endTime; return endTime;
} }
public int getTotalStudent() { public int getTotalStudent() {
return totalStudent; return totalStudent;
} }
//setter //setter
public void setId(int id) { public void setId(int id) {
this.id = id; this.id = id;
} }
public void setTeacherName(String teacherName) { public void setTeacherName(String teacherName) {
this.teacherName = teacherName; this.teacherName = teacherName;
} }
public void setStartPoint(String startPoint) { public void setStartPoint(String startPoint) {
this.startPoint = startPoint; this.startPoint = startPoint;
} }
public void setStartTime(String startTime) { public void setStartTime(String startTime) {
this.startTime = startTime; this.startTime = startTime;
} }
public void setEndTime(String endTime) { public void setEndTime(String endTime) {
this.endTime = endTime; this.endTime = endTime;
} }
public void setTotalStudent(int totalStudent) { public void setTotalStudent(int totalStudent) {
this.totalStudent = totalStudent; this.totalStudent = totalStudent;
} }

View File

@ -1,5 +1,4 @@
package com.example.oplogy; package com.example.oplogy;
import androidx.room.Dao; import androidx.room.Dao;
import androidx.room.Insert; import androidx.room.Insert;
import androidx.room.Query; import androidx.room.Query;
@ -11,7 +10,6 @@ import java.util.List;
public interface SetUpTableDao { public interface SetUpTableDao {
@Insert @Insert
void insertAll(SetUpTable... setUpTables); void insertAll(SetUpTable... setUpTables);
//更新処理 //更新処理
@Update @Update
void update(SetUpTable setUpTable); void update(SetUpTable setUpTable);
@ -20,7 +18,6 @@ public interface SetUpTableDao {
//削除処理 //削除処理
@Query("DELETE FROM SetUpTable") @Query("DELETE FROM SetUpTable")
void deleteAll(); void deleteAll();
//全件取得 //全件取得
@Query("SELECT * FROM SetUpTable") @Query("SELECT * FROM SetUpTable")
List<SetUpTable> getAll(); List<SetUpTable> getAll();
@ -30,32 +27,21 @@ public interface SetUpTableDao {
@Query("SELECT totalStudent FROM SetUpTable") @Query("SELECT totalStudent FROM SetUpTable")
int getTotalStudent(); int getTotalStudent();
//開始時間と終了時間の取得 //開始時間と終了時間の取得
@Query("SELECT startTime FROM SetUpTable") @Query("SELECT startTime FROM SetUpTable")
String getStartTime(); String getStartTime();
@Query("SELECT endTime FROM SetUpTable") @Query("SELECT endTime FROM SetUpTable")
String getEndTime(); String getEndTime();
//教師名の取得 //教師名の取得
@Query("SELECT teacherName FROM SetUpTable") @Query("SELECT teacherName FROM SetUpTable")
String getTeacherName(); String getTeacherName();
@Query("SELECT intervalTime FROM SetUpTable") @Query("SELECT intervalTime FROM SetUpTable")
String getIntervalTime(); String getIntervalTime();
@Query("SELECT StartBreakTime FROM SetUpTable") @Query("SELECT StartBreakTime FROM SetUpTable")
String getStartBreakTime(); String getStartBreakTime();
@Query("SELECT EndBreakTime FROM SetUpTable") @Query("SELECT EndBreakTime FROM SetUpTable")
String getEndBreakTime(); String getEndBreakTime();
//クラス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

@ -1,12 +1,14 @@
package com.example.oplogy; package com.example.oplogy;
import android.os.Bundle;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import android.os.Bundle;
import android.widget.ImageView;
import com.example.oplogy.databinding.SubmissionBinding;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -30,7 +32,7 @@ public class SubmissionActivity extends AppCompatActivity {
// インテントから提出状況の生徒の数を取得 // インテントから提出状況の生徒の数を取得
studentNumbers = getIntent().getIntegerArrayListExtra("submissionStudents"); studentNumbers=getIntent().getIntegerArrayListExtra("submissionStudents");
recyclerView = findViewById(R.id.recyclerView); recyclerView = findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this)); recyclerView.setLayoutManager(new LinearLayoutManager(this));
@ -40,7 +42,6 @@ public class SubmissionActivity extends AppCompatActivity {
// 生徒のリストを取得 // 生徒のリストを取得
fetchStudents(); fetchStudents();
} }
private void fetchStudents() { private void fetchStudents() {
// インテントから生徒のリストを取得 // インテントから生徒のリストを取得
ArrayList<SubmissionStudent> submissionStudents = getIntent().getParcelableArrayListExtra("submissionStudents"); ArrayList<SubmissionStudent> submissionStudents = getIntent().getParcelableArrayListExtra("submissionStudents");

View File

@ -5,9 +5,7 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import java.util.List; import java.util.List;
public class SubmissionAdapter extends RecyclerView.Adapter<SubmissionAdapter.StudentViewHolder> { public class SubmissionAdapter extends RecyclerView.Adapter<SubmissionAdapter.StudentViewHolder> {

View File

@ -1,5 +1,4 @@
package com.example.oplogy; package com.example.oplogy;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;

View File

@ -12,7 +12,7 @@ import androidx.fragment.app.DialogFragment;
import java.util.Calendar; import java.util.Calendar;
public class TimePick extends DialogFragment implements public class TimePick extends DialogFragment implements
TimePickerDialog.OnTimeSetListener { TimePickerDialog.OnTimeSetListener{
@NonNull @NonNull
@Override @Override

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
@ -22,10 +23,9 @@
android:id="@+id/toMain" android:id="@+id/toMain"
android:layout_width="60dp" android:layout_width="60dp"
android:layout_height="60dp" android:layout_height="60dp"
android:layout_gravity="start" android:layout_gravity="left"
android:layout_marginStart="10dp" android:layout_marginLeft="10dp"
android:src="@drawable/back_button" android:src="@drawable/back_button"/>
android:contentDescription="@string/todo" />
<TextView <TextView
@ -52,7 +52,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:autofillHints="" android:autofillHints=""
android:inputType="text" android:inputType=""
tools:ignore="LabelFor" /> tools:ignore="LabelFor" />
</LinearLayout> </LinearLayout>
@ -76,7 +76,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/startpoint" android:hint="@string/startpoint"
android:autofillHints="" android:autofillHints=""
android:inputType="text" android:inputType=""
tools:ignore="LabelFor" /> tools:ignore="LabelFor" />
</LinearLayout> </LinearLayout>
@ -91,7 +91,7 @@
<TextView <TextView
android:layout_width="90sp" android:layout_width="90sp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/setUpDate" android:text="日付設定"
android:gravity="center"/> android:gravity="center"/>
<!-- <TextView--> <!-- <TextView-->
@ -109,7 +109,7 @@
android:id="@+id/setFirstDayButton" android:id="@+id/setFirstDayButton"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/firstDay" android:text="1日目"
android:layout_marginStart="7sp" android:layout_marginStart="7sp"
android:layout_marginEnd="7sp" android:layout_marginEnd="7sp"
tools:ignore="DuplicateIds" /> tools:ignore="DuplicateIds" />
@ -118,7 +118,7 @@
android:id="@+id/setSecondDayButton" android:id="@+id/setSecondDayButton"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/secondDay" android:text="2日目"
android:layout_marginStart="7sp" android:layout_marginStart="7sp"
android:layout_marginEnd="7sp" android:layout_marginEnd="7sp"
tools:ignore="DuplicateIds" /> tools:ignore="DuplicateIds" />
@ -127,7 +127,7 @@
android:id="@+id/setThirdDayButton" android:id="@+id/setThirdDayButton"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/threeDay" android:text="3日目"
android:layout_marginStart="7sp" android:layout_marginStart="7sp"
android:layout_marginEnd="7sp" android:layout_marginEnd="7sp"
tools:ignore="DuplicateIds" /> tools:ignore="DuplicateIds" />
@ -151,7 +151,7 @@
android:id="@+id/startTime" android:id="@+id/startTime"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/notSetUp" android:hint="未設定"
android:textSize="20sp" android:textSize="20sp"
android:textAlignment="center" android:textAlignment="center"
android:autofillHints="" android:autofillHints=""
@ -186,7 +186,7 @@
android:id="@+id/endTime" android:id="@+id/endTime"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/notSetUp" android:hint="未設定"
android:textSize="20sp" android:textSize="20sp"
android:textAlignment="center" android:textAlignment="center"
android:autofillHints="" android:autofillHints=""

View File

@ -72,6 +72,11 @@
</LinearLayout> </LinearLayout>
<Space
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3"/>
<!-- ルート表示のレイアウト--> <!-- ルート表示のレイアウト-->
<LinearLayout <LinearLayout
@ -102,11 +107,6 @@
android:layout_gravity="center"/> android:layout_gravity="center"/>
</LinearLayout> </LinearLayout>
<Space
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3"/>
<!-- 提出状況のレイアウト--> <!-- 提出状況のレイアウト-->
<LinearLayout <LinearLayout

View File

@ -20,28 +20,33 @@
android:layout_width="40dp" android:layout_width="40dp"
android:layout_height="90dp" android:layout_height="90dp"
android:src="@drawable/back_button" android:src="@drawable/back_button"
android:layout_weight="5" /> android:layout_weight="3" />
<TextView <Spinner
android:id="@+id/date" android:id="@+id/date"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="90dp"
android:layout_weight="4" android:layout_weight="7" />
android:hint="今日の日付"
android:textSize="40dp" />
</LinearLayout> </LinearLayout>
<!-- Webの処理 --> <fragment
<WebView android:id="@+id/map"
android:id="@+id/webView" android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_weight="6" /> android:layout_weight="6"
tools:context=".Maps" />
<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="wrap_content"
android:layout_weight="3" /> android:layout_weight="3">
<LinearLayout
android:id="@+id/locationsName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</ScrollView>
</LinearLayout> </LinearLayout>

View File

@ -1,5 +1,6 @@
<resources> <resources>
<string name="app_name">oplogy</string> <string name="app_name">Oplogy</string>
<string name="maps_api_key">AIzaSyBqLqPm76UFpwbpU8b3oiH0wbkhosrPWpU</string>
<string name="title_activity_maps">MapsActivity</string> <string name="title_activity_maps">MapsActivity</string>
<string name="setUp">設定</string> <string name="setUp">設定</string>
<string name="reset">リセット</string> <string name="reset">リセット</string>
@ -11,29 +12,8 @@
<string name="breakTime">休憩時間</string> <string name="breakTime">休憩時間</string>
<string name="totalStudent">生徒の人数</string> <string name="totalStudent">生徒の人数</string>
<string name="timeSet">時刻設定</string> <string name="timeSet">時刻設定</string>
<string name="Back">🔙</string>
<string name="startpoint">住所</string> <string name="startpoint">住所</string>
<string name="tenMinute">10分</string> <string name="tenMinute">10分</string>
<string name="fifteenMinute">15分</string> <string name="fifteenMinute">15分</string>
<string name="thirtyMinute">30分</string> <string name="thirtyMinute">30分</string>
<string name="todo">TODO</string>
<string name="setUpDate">日付設定</string>
<string name="firstDay">1日目</string>
<string name="secondDay">2日目</string>
<string name="threeDay">3日目</string>
<string name="notSetUp">未設定</string>
<string-array name="months_array">
<item>1月</item>
<item>2月</item>
<item>3月</item>
<item>4月</item>
<item>5月</item>
<item>6月</item>
<item>7月</item>
<item>8月</item>
<item>9月</item>
<item>10月</item>
<item>11月</item>
<item>12月</item>
</string-array>
</resources> </resources>