Merge pull request 'api' (#47) from api into master

Reviewed-on: #47
This commit is contained in:
Utahshi 2024-07-09 03:10:45 +00:00
commit 823fa8a2c4
12 changed files with 258 additions and 319 deletions

View File

@ -16,11 +16,11 @@ public class Converters {
// タイムスタンプを文字列(yyyy-mm-dd,日時)に変換
@TypeConverter
public static List<String> fromTimestampList(List<Timestamp> timestamps) {
List<String> strings = new ArrayList<>();
List<String> stringsList = new ArrayList<>();
for (Timestamp timestamp : timestamps) {
strings.add(format.format(timestamp.toDate()));
stringsList.add(format.format(timestamp.toDate()));
}
return strings;
return stringsList;
}
@TypeConverter

View File

@ -7,10 +7,10 @@ public class CreateUUID {
public static int generateUUID(List<Integer> classIdList ){
while (true){
int uuid = (int)(Math.random() * 1000000);
int uuidInt = (int)(Math.random() * 1000000);
boolean isDuplicate = false;
for(int classId : classIdList){
if(classId==uuid){
for(int classIdInt : classIdList){
if(classIdInt==uuidInt){
//重複があればフラグを立てループを抜ける
isDuplicate = true;
break;
@ -20,10 +20,10 @@ public class CreateUUID {
if (!isDuplicate) {
//firestoreに挿入処理
InsertClassIdforFirebase insertClassIdforFirebase = new InsertClassIdforFirebase();
insertClassIdforFirebase.insertClassId(uuid);
insertClassIdforFirebase.insertClassId(uuidInt);
//テスト用
uuid=100;
return uuid;
uuidInt=100;
return uuidInt;
}
}
}

View File

@ -7,8 +7,8 @@ import android.widget.DatePicker;
import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment;
import java.util.Calendar;
import java.util.Objects;
public class DatePick extends DialogFragment implements
DatePickerDialog.OnDateSetListener {
@ -19,16 +19,16 @@ public class DatePick extends DialogFragment implements
//デフォルトのタイムゾーンおよびロケールを使用してカレンダを取得
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
int yearInt = c.get(Calendar.YEAR);
int monthInt = c.get(Calendar.MONTH);
int dayInt = c.get(Calendar.DAY_OF_MONTH);
return new DatePickerDialog(requireActivity(), (DatePickerDialog.OnDateSetListener) getActivity(), year, month, day);
return new DatePickerDialog(requireActivity(), (DatePickerDialog.OnDateSetListener) getActivity(), yearInt, monthInt, dayInt);
}
@Override
public void onDateSet(DatePicker datePicker, int year, int month, int day) {
public void onDateSet(DatePicker datePicker, int yearInt, int monthInt, int dayInt) {
}
}

View File

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

View File

@ -1,59 +0,0 @@
package com.example.oplogy;
import android.content.Context;
import android.location.Address;
import android.location.Geocoder;
import android.util.Log;
import com.google.android.gms.maps.model.LatLng;
import com.google.firebase.Timestamp;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
import java.util.Map;
public class GeoCoder {
private Context context;
public void processData(Map<String, Object> data, Context context) {
try {
this.context = context;
//家庭訪問先の住所
List<String> address = (List<String>) data.get("address");
//家庭訪問の第一希望日(配列0が希望時間帯のはじめ配列1がおわり)
List<Timestamp> firstDay = (List<Timestamp>) data.get("firstDay");
//出席番号
Long studentNumber = (Long) data.get("studentNumber");
// 住所を緯度経度に変換
LatLng latLng = geocodeAddress(address.get(0));
//デバッグ用ログ
Log.d("FirestoreReception", "address: " + address.get(0));
Log.d("FirestoreReception", "firstDay: " + firstDay.get(0));
Log.d("FirestoreReception", "firstDay: " + firstDay.get(1));
Log.d("FirestoreReception", "studentNumber: " + studentNumber);
Log.d("FirestoreReception", "latLng: " + latLng);
} catch (NullPointerException e) {
Log.e("NullPointerException", "getの中身がnull" + e);
}
}
private LatLng geocodeAddress(String address) {
try {
Geocoder geocoder = new Geocoder(context, Locale.getDefault());
List<Address> addresses = geocoder.getFromLocationName(address, 1);
if (addresses != null && !addresses.isEmpty()) {
Address addressResult = addresses.get(0);
double latitude = addressResult.getLatitude();
double longitude = addressResult.getLongitude();
return new LatLng(latitude, longitude);
}
} catch (IOException e) {
Log.e("GeocodingException", "Error geocoding address: " + address, e);
}
return null;
}
}

View File

@ -51,7 +51,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
//取得するためのクラスID
private int classId;
private String address;
@Override
@ -196,12 +195,12 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
executor.execute(() -> {
AppDatabase db = getDatabaseInstance(); SetUpTableDao setUpTableDao = db.setUpTableDao();
int totalStudent = setUpTableDao.getTotalStudent();
int myDataListSize = firestoreReception.getMyDataListSize();
int totalStudentInt = setUpTableDao.getTotalStudent();
int myDataListSizeInt = firestoreReception.getMyDataListSize();
//総生徒数と提出済みになっている生徒の数が一致するかの確認
runOnUiThread(() -> {
if (totalStudent != myDataListSize) {
if (totalStudentInt != myDataListSizeInt) {
//未提出者がいることの警告ダイアログ
showRouteCreationDialog();
} else {
@ -272,10 +271,10 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
// MyDataListをJSON形式に変換
Gson gson = new Gson();
String json = gson.toJson(myDataList);
String jsonString = gson.toJson(myDataList);
// JSON形式のデータを共有プリファレンスに保存
editor.putString("myDataList", json);
editor.putString("myDataList", jsonString);
editor.apply();
}
@ -321,17 +320,17 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
// 1. Roomデータベースから全生徒数を取得
AppDatabase db = getDatabaseInstance();
SetUpTableDao setUpTableDao = db.setUpTableDao();
int totalStudent = setUpTableDao.getTotalStudent();
int totalStudentInt = setUpTableDao.getTotalStudent();
// 2. Firestoreから生徒番号のリストを取得
ArrayList<Integer> firestoreStudentNumbers = new ArrayList<>();
ArrayList<Integer> firestoreStudentNumbersList = new ArrayList<>();
for (MyDataClass myData : myDataList) {
int studentNumber = myData.getStudentNumber();
firestoreStudentNumbers.add(studentNumber);
int studentNumberInt = myData.getStudentNumber();
firestoreStudentNumbersList.add(studentNumberInt);
}
// 3. SubmissionStudentオブジェクトのリストを作成
for (int i = 1; i <= totalStudent; i++) {
boolean submitted = firestoreStudentNumbers.contains(i);
for (int i = 1; i <= totalStudentInt; i++) {
boolean submitted = firestoreStudentNumbersList.contains(i);
submissionStudents.add(new SubmissionStudent(i, submitted));
}

View File

@ -44,12 +44,9 @@ public class Maps extends FragmentActivity implements OnMapReadyCallback, View.O
ImageView backMain;
private GoogleMap mMap;
private MapsBinding binding;
private LinearLayout locationsName;
private Spinner dateSpinner;
//GoogleMapAPiで使用可能な色
private static final int[] COLORS = new int[]{
Color.parseColor("#007FFF"), // HUE_AZURE
private static final int[] COLORS = new int[]{Color.parseColor("#007FFF"), // HUE_AZURE
Color.parseColor("#0000FF"), // HUE_BLUE
Color.parseColor("#00FFFF"), // HUE_CYAN
Color.parseColor("#00FF00"), // HUE_GREEN
@ -61,36 +58,35 @@ public class Maps extends FragmentActivity implements OnMapReadyCallback, View.O
Color.parseColor("#FFFF00") // HUE_YELLOW
};
private int colorIndex = 0;
private List<LatLng> latLngList = new ArrayList<>();
private List<String> nameList = new ArrayList<>();
private List<Integer> colorList = new ArrayList<>();
private final List<LatLng> latLngList = new ArrayList<>();
private final List<String> nameList = new ArrayList<>();
private final List<Integer> colorList = new ArrayList<>();
private Map<String, Runnable> dateMap = new HashMap<>();
private AppDatabase db = null;
private final Map<String, Runnable> dateMap = new HashMap<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = MapsBinding.inflate(getLayoutInflater());
// バインディングの設定
com.example.oplogy.databinding.MapsBinding binding = MapsBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
// マップフラグメントの設定
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
// 各UI要素の設定
backMain = findViewById(R.id.BackMain);
backMain.setOnClickListener(this);
locationsName = findViewById(R.id.locationsName);
String dateData = formatDate(getSharedPreferencesData(0)) + "/" + formatDate(getSharedPreferencesData(1)) + "/" + formatDate(getSharedPreferencesData(2));
// スピナーの設定
String dateDataString = formatDate(getSharedPreferencesData(0)) + "/" + formatDate(getSharedPreferencesData(1)) + "/" + formatDate(getSharedPreferencesData(2));
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
String[] dates = dateData.split("/");
String[] dates = dateDataString.split("/");
for (String date : dates) {
adapter.add(date);
}
@ -100,22 +96,18 @@ public class Maps extends FragmentActivity implements OnMapReadyCallback, View.O
int finalI = i;
String dayString = getSharedPreferencesData(i);
String formattedDayString = formatDate(dayString);
if (i == 0) {
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)));
}
dateMap.put(formattedDayString, () -> loadMapAndNames(createlocationData(finalI), getscrollViewlData(finalI)));
}
dateSpinner = findViewById(R.id.date);
Spinner 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);
String selectedItemString = (String) parent.getItemAtPosition(position);
Runnable mapLoader = dateMap.get(selectedItemString);
if (mapLoader != null) {
mapLoader.run();
}
@ -128,16 +120,22 @@ public class Maps extends FragmentActivity implements OnMapReadyCallback, View.O
});
}
//ルート表示を押して最初に表示されるルート(3日間の家庭訪問における1日目)の設定
@Override
public void onMapReady(GoogleMap googleMap) {
//Google mapの定義
mMap = googleMap;
mMap.setOnMarkerClickListener(this);
String latlngString = createlocationData(0);
String homeVisitDataString = getData(0);
firstMapAndNames(latlngString, homeVisitDataString);
//家庭訪問1日目のスケジュール順に緯度経度の情報をString型の変数に格納
//35.1711355,136.88552149999998/35.1696089,136.884084/35.1732838,136.88832890000003/...
String locationDataString = createlocationData(0);
//家庭訪問1日目のスケジュール順に住所や出席番号家庭訪問の開始時間の情報をString型の変数に格納
//開始地点/出席番号2番:鈴木次郎<453-0015 愛知県名古屋市中村区椿町6 地下1階5階> 06月04日12時00分/...
String scrollViewlDataString = getscrollViewlData(0);
loadMapAndNames(locationDataString, scrollViewlDataString);
}
//家庭訪問の日目が何月何日かを返すメソッド
private String getSharedPreferencesData(int i) {
SharedPreferences sharedPreferences = getSharedPreferences("visitingDate", MODE_PRIVATE);
// SetUpで設定した8桁の数字表記の家庭訪問日を日付表記に変更
@ -152,49 +150,59 @@ public class Maps extends FragmentActivity implements OnMapReadyCallback, View.O
return dayString;
}
//家庭訪問の日付を8桁の整数表記から(2024070707月07日)表記に変更する
private String formatDate(String date) {
if (date == null || date.length() != 8) {
return "";
}
String month = date.substring(4, 6);
String day = date.substring(6, 8);
return month + "" + day + "";
String monthString = date.substring(4, 6);
String dayString = date.substring(6, 8);
return monthString + "" + dayString + "";
}
//家庭訪問1日目のスケジュール順に緯度経度の情報をString型の変数に格納
private String createlocationData(int i) {
//家庭訪問の開始地点の緯度経度
String startPointLatLngString = getIntent().getStringExtra("startPointLatLngString");
List<MyDataClass> myDataList = getMyDataList();
//家庭訪問の緯度経度情報をまとめる変数
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("/");
}
//mydataListから取り出した家庭訪問の各家庭の住所の緯度経度を追加
//この時点ではlongitude latitudeのような不要な文字があるのでformatLatLngメソッドで緯度経度だけのデータにする
latlngString.append(formatLatLng(myDataList.get(y)));
}
}
//各家庭の緯度経度をまとめたものを返す
return latlngString.toString();
}
//緯度と経度は(35.1711355,136.88552149999998)のように()の中に入っているのでそこだけを取り出す
private String formatLatLng(MyDataClass myData) {
String latlng = myData.getLatLngString();
int startIndex = latlng.indexOf("(") + 1;
int endIndex = latlng.indexOf(")");
return latlng.substring(startIndex, endIndex);
String latlngString = myData.getLatLngString();
int startIndex = latlngString.indexOf("(") + 1;
int endIndex = latlngString.indexOf(")");
return latlngString.substring(startIndex, endIndex);
}
private String getData(int i) {
//ScrollViewにて表示するdataの作成メソッド
private String getscrollViewlData(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()));
@ -203,12 +211,13 @@ public class Maps extends FragmentActivity implements OnMapReadyCallback, View.O
return homeVisitDataString;
}
//家庭訪問のscheduleを7桁の整数から(604120006月12日05時20分)に変換
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 + "";
String monthString = "0" + schedule.substring(0, 1);
String dayString = schedule.substring(1, 3);
String hourString = schedule.substring(3, 5);
String minuteString = schedule.substring(5, 7);
return monthString + "" + dayString + "" + hourString + "" + minuteString + "";
}
// 共有プリファレンスからMyDataListを取得するメソッド
@ -217,40 +226,22 @@ public class Maps extends FragmentActivity implements OnMapReadyCallback, View.O
SharedPreferences sharedPreferences = getSharedPreferences("MyDataList", MODE_PRIVATE);
// 共有プリファレンスからJSON形式のデータを取得
String json = sharedPreferences.getString("myDataList", "");
String jsonString = sharedPreferences.getString("myDataList", "");
// JSON形式のデータをMyDataListに変換
Gson gson = new Gson();
Type type = new TypeToken<List<MyDataClass>>() {
}.getType();
List<MyDataClass> myDataList = gson.fromJson(json, type);
List<MyDataClass> myDataList = gson.fromJson(jsonString, 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);
}
//mapやgetscrollViewlに値を渡すハブの役割のメソッド
private void loadMapAndNames(String locationData, String nameData) {
try {
//mapに関するすべてのデータをリセット
latLngList.clear();
nameList.clear();
colorList.clear();
@ -258,31 +249,31 @@ public class Maps extends FragmentActivity implements OnMapReadyCallback, View.O
mMap.clear();
// locationDataをスラッシュで分割して緯度経度リストを取得
String[] locArray = locationData.split("/");
String[] locArrayString = locationData.split("/");
// nameDataをスラッシュで分割して名前リストを取得
String[] nameArray = nameData.split("/");
String[] nameArrayString = nameData.split("/");
for (int i = 0; i < locArray.length; i++) {
for (int i = 0; i < locArrayString.length; i++) {
// 緯度経度をカンマで分割してLatLngオブジェクトを作成
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);
String[] latLngString = locArrayString[i].split(",");
if (latLngString.length == 2) {
double latitudeDouble = Double.parseDouble(latLngString[0]);
double longitudeDouble = Double.parseDouble(latLngString[1]);
LatLng position = new LatLng(latitudeDouble, longitudeDouble);
latLngList.add(position);
// 名前リストから対応する名前を取得
String name = nameArray.length > i ? nameArray[i] : "Unknown";
nameList.add(name);
String nameString = nameArrayString.length > i ? nameArrayString[i] : "Unknown";
nameList.add(nameString);
// 色リストから次の色を取得
int color = getNextColor();
colorList.add(color);
int colorInt = getNextColor();
colorList.add(colorInt);
// 地図にピンを追加
addPinToMap(name, position, color);
addPinToMap(nameString, position, colorInt);
// スクロールビューに場所を追加
addLocationToScrollView(name, color);
addLocationToScrollView(nameString, colorInt);
}
}
@ -292,10 +283,12 @@ public class Maps extends FragmentActivity implements OnMapReadyCallback, View.O
drawRoute(); // ルートを描画するメソッドを呼び出す
}
} catch (Exception e) {
Log.e("Maps", "Error loading maps and names", e);
Log.e("Maps", "エラーが発生しました。原因は以下", e);
}
}
// ルートを描画するメソッド
// Google マップの Directions API を使用してルート情報を取得しポリラインで描画
private void drawRoute() {
new Thread(() -> {
try {
@ -312,25 +305,27 @@ public class Maps extends FragmentActivity implements OnMapReadyCallback, View.O
}
}
urlBuilder.append("&mode=driving");
urlBuilder.append("&key=").append(getString(R.string.maps_api_key));
//APiキーの設定
urlBuilder.append("&key=").append("AIzaSyBQ1Ak-I2NL5TP4K59ZI0VgzKk6HNZuusw");
String urlString = urlBuilder.toString();
Log.d("Maps", "Directions API URL: " + urlString);
// Directions APIにリクエストを送信してレスポンスを取得
URL url = new URL(urlString);
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);
String lineString;
while ((lineString = br.readLine()) != null) {
jsonResults.append(lineString);
}
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) {
@ -343,36 +338,41 @@ public class Maps extends FragmentActivity implements OnMapReadyCallback, View.O
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());
Log.e("Maps", "エラーが発生しました。原因は以下: " + errorMessage.getAsString());
} else {
Log.e("Maps", "No routes found and no error message provided");
Log.e("Maps", "原因不明のエラー");
}
}
} catch (Exception e) {
Log.e("Maps", "Error drawing route", e);
Log.e("Maps", "ルートの描画に失敗しました", e);
}
}).start();
}
// エンコードされた文字列から座標情報をデコードするためのメソッド
private List<LatLng> decodePoly(String encoded) {
List<LatLng> poly = new ArrayList<>();
int index = 0, len = encoded.length();
int lat = 0, lng = 0;
List<LatLng> poly = new ArrayList<>(); // 座標情報を格納するリスト
int index = 0, len = encoded.length();// 文字列のインデックスと長さ
int latInt = 0, lng = 0; // 緯度と経度の初期値
// 文字列の長さに達するまで繰り返す
while (index < len) {
int b, shift = 0, result = 0;
// バイト値を取得しビットシフトとOR演算を行って座標値を復元する
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;
latInt += dlat;
shift = 0;
result = 0;
// バイト値を取得しビットシフトとOR演算を行って座標値を復元する
do {
b = encoded.charAt(index++) - 63;
result |= (b & 0x1f) << shift;
@ -380,34 +380,35 @@ public class Maps extends FragmentActivity implements OnMapReadyCallback, View.O
} while (b >= 0x20);
int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
lng += dlng;
LatLng p = new LatLng((((double) lat / 1E5)), (((double) lng / 1E5)));
// LatLngオブジェクトを作成してリストに追加する
LatLng p = new LatLng((((double) latInt / 1E5)), (((double) lng / 1E5)));
poly.add(p);
}
// 座標情報のリストを返す
return poly;
}
// Colorクラスを使用して与えられた色から色相値を計算するメソッド
private float getHueFromColor(int color) {
float[] hsv = new float[3];
Color.colorToHSV(color, hsv);
Color.colorToHSV(color, hsv);//整数の色値をHSV色相彩度明度の形式に変換し色相値を取得します
return hsv[0];
}
//mapにピンを追加するメソッド
private void addPinToMap(String locationName, LatLng position, int color) {
Marker marker = mMap.addMarker(new MarkerOptions()
.position(position)
.title(locationName)
.icon(BitmapDescriptorFactory.defaultMarker(getHueFromColor(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);
@ -416,7 +417,7 @@ public class Maps extends FragmentActivity implements OnMapReadyCallback, View.O
// テキストビューにクリックリスナーを追加
textView.setOnClickListener(v -> {
// 名前リストからインデックスを取得
// 名前リストから位置情報を取得
int index = nameList.indexOf(locationName);
if (index != -1) {
LatLng position = latLngList.get(index);
@ -425,15 +426,14 @@ public class Maps extends FragmentActivity implements OnMapReadyCallback, View.O
}
});
// 下線のビューの作成
View underline = new View(this);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
3
);
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) {
@ -455,13 +455,20 @@ public class Maps extends FragmentActivity implements OnMapReadyCallback, View.O
}
}
@Override
//マーカーがクリックされた際の処理を行うメソッド
public boolean onMarkerClick(Marker marker) {
// マーカーから場所の名前を取得します
String locationName = (String) marker.getTag();
// 場所の名前がnullではない場合に処理を実行します
if (locationName != null) {
// マーカーのタイトルとして場所の名前を設定します
marker.setTitle(locationName);
// マーカーの情報ウィンドウを表示します
marker.showInfoWindow();
}
// デフォルトの動作も実行するためにfalseを返します
return false;
}
}

View File

@ -31,17 +31,17 @@ import java.util.concurrent.Executors;
public class SetUpActivity extends FragmentActivity
implements TimePickerDialog.OnTimeSetListener, DatePickerDialog.OnDateSetListener {
String teacherName;
String startPoint;
String firstDay;
String secondDay;
String thirdDay;
String startTime;
String endTime;
String intervalTime;
String startBreakTime;
String endBreakTime;
int totalStudent;
String teacherNameString;
String startPointString;
String firstDayString;
String secondDayString;
String thirdDayString;
String startTimeString;
String endTimeString;
String intervalTimeString;
String startBreakTimeString;
String endBreakTimeString;
int totalStudentString;
private TextView setTeacherName;
private TextView setStartPoint;
private TextView setStartTime;
@ -49,16 +49,16 @@ public class SetUpActivity extends FragmentActivity
private TextView setStartBreakTime;
private TextView setEndBreakTime;
private TextView setTotalStudent;
private int isDateSelected;
private int isStartTimeSelected;
private int isDateSelectedInt;
private int isStartTimeSelectedInt;
String stringYear;
String stringMonth;
String stringDayOfMonth;
String stringYearString;
String stringMonthString;
String stringDayOfMonthString;
String stringHourOfDay;
String stringMinute;
String stringHourOfDayString;
String stringMinuteString;
Button setFirstDay;
Button setSecondDay;
@ -74,7 +74,7 @@ public class SetUpActivity extends FragmentActivity
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_set_up);
int classId= getIntent().getIntExtra("classId", 100000);
int classIdInt= getIntent().getIntExtra("classId", 100000);
setTeacherName = findViewById(R.id.teacherName); //先生の名前
setStartPoint = findViewById(R.id.startPoint); //開始地点
@ -110,29 +110,29 @@ public class SetUpActivity extends FragmentActivity
setUp.setOnClickListener(view -> {
teacherName = setTeacherName.getText().toString(); //各変数に値を挿入
Log.d(TAG, "Teacher Name: " + teacherName);
startPoint = setStartPoint.getText().toString();
Log.d(TAG, "Start Point: " + startPoint);
Log.d(TAG, "First Day:" + firstDay);
Log.d(TAG, "Second Day:" + secondDay);
Log.d(TAG, "Third Day:" + thirdDay);
Log.d(TAG, "Start Time" + startTime);
Log.d(TAG, "End Time" + endTime);
teacherNameString = setTeacherName.getText().toString(); //各変数に値を挿入
Log.d(TAG, "Teacher Name: " + teacherNameString);
startPointString = setStartPoint.getText().toString();
Log.d(TAG, "Start Point: " + startPointString);
Log.d(TAG, "First Day:" + firstDayString);
Log.d(TAG, "Second Day:" + secondDayString);
Log.d(TAG, "Third Day:" + thirdDayString);
Log.d(TAG, "Start Time" + startTimeString);
Log.d(TAG, "End Time" + endTimeString);
if (setTenMinute.isChecked()){ //ラジオボタンの状態を取得
intervalTime = "10";
intervalTimeString = "10";
} else if (setFifteenMinute.isChecked()) {
intervalTime = "15";
intervalTimeString = "15";
} else if (setThirtyMinute.isChecked()) {
intervalTime = "30";
intervalTimeString = "30";
} else {
intervalTime = "0";
intervalTimeString = "0";
}
Log.d(TAG, "Interval Time" + intervalTime);
Log.d(TAG, "Start Break Time" + startBreakTime);
Log.d(TAG, "End Break Time" + endBreakTime);
totalStudent = Integer.parseInt(setTotalStudent.getText().toString()); //数値型に変更
Log.d(TAG, "Total Student" + totalStudent);
Log.d(TAG, "Interval Time" + intervalTimeString);
Log.d(TAG, "Start Break Time" + startBreakTimeString);
Log.d(TAG, "End Break Time" + endBreakTimeString);
totalStudentString = Integer.parseInt(setTotalStudent.getText().toString()); //数値型に変更
Log.d(TAG, "Total Student" + totalStudentString);
Log.d(TAG, "onClick: できてるよ");
@ -147,19 +147,19 @@ public class SetUpActivity extends FragmentActivity
SetUpTableDao setUpTableDao = db.setUpTableDao();
// Roomの操作を行う
SetUpTable setUpTable = new SetUpTable(
teacherName,
startPoint,
startTime,
endTime,
intervalTime,
startBreakTime,
endBreakTime,
totalStudent,
classId
teacherNameString,
startPointString,
startTimeString,
endTimeString,
intervalTimeString,
startBreakTimeString,
endBreakTimeString,
totalStudentString,
classIdInt
);
// 同じ名前のエントリが存在するかどうかを確認
SetUpTable existingSetUpTable = setUpTableDao.findByName(teacherName);
SetUpTable existingSetUpTable = setUpTableDao.findByName(teacherNameString);
if (existingSetUpTable != null) {
// エントリが存在する場合はそのエントリを更新
setUpTable.setId(existingSetUpTable.getId()); // 既存のIDを設定
@ -175,9 +175,9 @@ public class SetUpActivity extends FragmentActivity
SharedPreferences sharedPreferences=getSharedPreferences("visitingDate",MODE_PRIVATE);
SharedPreferences.Editor editor= sharedPreferences.edit();
editor.putString("day1",firstDay);
editor.putString("day2",secondDay);
editor.putString("day3",thirdDay);
editor.putString("day1",firstDayString);
editor.putString("day2",secondDayString);
editor.putString("day3",thirdDayString);
editor.apply();
@ -187,37 +187,37 @@ public class SetUpActivity extends FragmentActivity
});
setFirstDay.setOnClickListener(v ->{
isDateSelected = 1;
isDateSelectedInt = 1;
showDatePickerDialog(); //DatePickerの表示
});
setSecondDay.setOnClickListener(v ->{
isDateSelected = 2;
isDateSelectedInt = 2;
showDatePickerDialog();
});
setThirdDay.setOnClickListener(v ->{
isDateSelected = 3;
isDateSelectedInt = 3;
showDatePickerDialog();
});
setStartTimeButton.setOnClickListener(v -> {
isStartTimeSelected = 1; //ボタンの判別
isStartTimeSelectedInt = 1; //ボタンの判別
showTimePickerDialog(); //TimePickerの表示
});
setEndTimeButton.setOnClickListener(v -> {
isStartTimeSelected = 2;
isStartTimeSelectedInt = 2;
showTimePickerDialog();
});
setStartBreakTime.setOnClickListener(v -> {
isStartTimeSelected = 3;
isStartTimeSelectedInt = 3;
showTimePickerDialog();
});
setEndBreakTime.setOnClickListener(v -> {
isStartTimeSelected = 4;
isStartTimeSelectedInt = 4;
showTimePickerDialog();
});
@ -247,25 +247,25 @@ public class SetUpActivity extends FragmentActivity
// DatePickerDialogで選択された日付を処理する
String str = String.format(Locale.JAPAN, "%02d/%02d", month + 1, dayOfMonth); // TextViewに表示する日付の形式を設定
if (isDateSelected == 1) {
stringYear = String.valueOf(year); //
stringMonth = String.format(Locale.JAPAN, "%02d", month + 1); //
stringDayOfMonth = String.format(Locale.JAPAN, "%02d", dayOfMonth); //
firstDay = stringYear + stringMonth + stringDayOfMonth;
if (isDateSelectedInt == 1) {
stringYearString = String.valueOf(year); //
stringMonthString = String.format(Locale.JAPAN, "%02d", month + 1); //
stringDayOfMonthString = String.format(Locale.JAPAN, "%02d", dayOfMonth); //
firstDayString = stringYearString + stringMonthString + stringDayOfMonthString;
setFirstDay.setText(str);
} else if (isDateSelected == 2) {
stringYear = String.valueOf(year);
stringMonth = String.format(Locale.JAPAN, "%02d", month + 1);
stringDayOfMonth = String.format(Locale.JAPAN, "%02d", dayOfMonth);
secondDay = stringYear + stringMonth + stringDayOfMonth;
} else if (isDateSelectedInt == 2) {
stringYearString = String.valueOf(year);
stringMonthString = String.format(Locale.JAPAN, "%02d", month + 1);
stringDayOfMonthString = String.format(Locale.JAPAN, "%02d", dayOfMonth);
secondDayString = stringYearString + stringMonthString + stringDayOfMonthString;
setSecondDay.setText(str);
} else if (isDateSelected == 3) {
stringYear = String.valueOf(year);
stringMonth = String.format(Locale.JAPAN, "%02d", month + 1);
stringDayOfMonth = String.format(Locale.JAPAN, "%02d", dayOfMonth);
thirdDay = stringYear + stringMonth + stringDayOfMonth;
} else if (isDateSelectedInt == 3) {
stringYearString = String.valueOf(year);
stringMonthString = String.format(Locale.JAPAN, "%02d", month + 1);
stringDayOfMonthString = String.format(Locale.JAPAN, "%02d", dayOfMonth);
thirdDayString = stringYearString + stringMonthString + stringDayOfMonthString;
setThirdDay.setText(str);
}
@ -276,28 +276,28 @@ public class SetUpActivity extends FragmentActivity
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
String str = String.format(Locale.JAPAN, "%02d:%02d", hourOfDay, minute); // Textviewに保存する形式を設定
if (isStartTimeSelected == 1) {
stringHourOfDay = String.format("%02d", hourOfDay);
stringMinute = String.format("%02d", minute);
startTime = stringHourOfDay + stringMinute;
if (isStartTimeSelectedInt == 1) {
stringHourOfDayString = String.format("%02d", hourOfDay);
stringMinuteString = String.format("%02d", minute);
startTimeString = stringHourOfDayString + stringMinuteString;
setStartTime.setText(str);
} else if (isStartTimeSelected == 2) {
stringHourOfDay = String.format("%02d", hourOfDay);
stringMinute = String.format("%02d", minute);
endTime = stringHourOfDay + stringMinute;
} else if (isStartTimeSelectedInt == 2) {
stringHourOfDayString = String.format("%02d", hourOfDay);
stringMinuteString = String.format("%02d", minute);
endTimeString = stringHourOfDayString + stringMinuteString;
setEndTime.setText(str);
} else if (isStartTimeSelected == 3) {
stringHourOfDay = String.format("%02d", hourOfDay);
stringMinute = String.format("%02d", minute);
startBreakTime =stringHourOfDay + stringMinute;
} else if (isStartTimeSelectedInt == 3) {
stringHourOfDayString = String.format("%02d", hourOfDay);
stringMinuteString = String.format("%02d", minute);
startBreakTimeString =stringHourOfDayString + stringMinuteString;
setStartBreakTime.setText(" " + str + " ");
} else if (isStartTimeSelected == 4) {
stringHourOfDay = String.format("%02d", hourOfDay);
stringMinute = String.format("%02d", minute);
endBreakTime = stringHourOfDay + stringMinute;
} else if (isStartTimeSelectedInt == 4) {
stringHourOfDayString = String.format("%02d", hourOfDay);
stringMinuteString = String.format("%02d", minute);
endBreakTimeString = stringHourOfDayString + stringMinuteString;
setEndBreakTime.setText(" " + str + " ");
}
}

View File

@ -1,13 +1,11 @@
package com.example.oplogy;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.os.Bundle;
import android.widget.ImageView;
import com.example.oplogy.databinding.SubmissionBinding;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import java.util.List;
@ -15,9 +13,8 @@ import java.util.List;
public class SubmissionActivity extends AppCompatActivity {
private RecyclerView recyclerView;
private SubmissionAdapter submissionAdapter;
private List<SubmissionStudent> students = new ArrayList<>();
ArrayList<Integer> studentNumbers = new ArrayList<>();
private int totalStudent = 10;
private final List<SubmissionStudent> studentsList = new ArrayList<>();
ArrayList<Integer> studentNumbersList = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -26,17 +23,15 @@ public class SubmissionActivity extends AppCompatActivity {
// 戻るボタンの処理
ImageView backButton = findViewById(R.id.BackMain_fromSubmission);
backButton.setOnClickListener(v -> {
finish();
});
backButton.setOnClickListener(v -> finish());
// インテントから提出状況の生徒の数を取得
studentNumbers=getIntent().getIntegerArrayListExtra("submissionStudents");
studentNumbersList=getIntent().getIntegerArrayListExtra("submissionStudents");
recyclerView = findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
submissionAdapter = new SubmissionAdapter(students);
submissionAdapter = new SubmissionAdapter(studentsList);
recyclerView.setAdapter(submissionAdapter);
// 生徒のリストを取得
@ -44,12 +39,10 @@ public class SubmissionActivity extends AppCompatActivity {
}
private void fetchStudents() {
// インテントから生徒のリストを取得
ArrayList<SubmissionStudent> submissionStudents = getIntent().getParcelableArrayListExtra("submissionStudents");
ArrayList<SubmissionStudent> submissionStudentsList = getIntent().getParcelableArrayListExtra("submissionStudents");
// 生徒のリストを反復処理しそれをRecyclerViewに表示
for (SubmissionStudent student : submissionStudents) {
students.add(student);
}
studentsList.addAll(submissionStudentsList);
// データが変更されたことをアダプターに通知
submissionAdapter.notifyDataSetChanged();

View File

@ -5,12 +5,14 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
public class SubmissionAdapter extends RecyclerView.Adapter<SubmissionAdapter.StudentViewHolder> {
private List<SubmissionStudent> students;
private final List<SubmissionStudent> studentsList;
public static class StudentViewHolder extends RecyclerView.ViewHolder {
public TextView studentNumberTextView;
@ -25,9 +27,10 @@ public class SubmissionAdapter extends RecyclerView.Adapter<SubmissionAdapter.St
}
public SubmissionAdapter(List<SubmissionStudent> students) {
this.students = students;
this.studentsList = students;
}
@NonNull
@Override
public StudentViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
@ -37,7 +40,7 @@ public class SubmissionAdapter extends RecyclerView.Adapter<SubmissionAdapter.St
@Override
public void onBindViewHolder(StudentViewHolder holder, int position) {
SubmissionStudent student = students.get(position);
SubmissionStudent student = studentsList.get(position);
holder.studentNumberTextView.setText(String.valueOf(student.getStudentNumber()));
// 提出済みかどうかで表示を変える
if (student.isSubmitted()) {
@ -57,6 +60,6 @@ public class SubmissionAdapter extends RecyclerView.Adapter<SubmissionAdapter.St
@Override
public int getItemCount() {
return students.size();
return studentsList.size();
}
}

View File

@ -3,16 +3,16 @@ import android.os.Parcel;
import android.os.Parcelable;
public class SubmissionStudent implements Parcelable {
private int studentNumber;
private int studentNumberInt;
private boolean submitted;
public SubmissionStudent(int studentNumber, boolean submitted) {
this.studentNumber = studentNumber;
this.studentNumberInt = studentNumber;
this.submitted = submitted;
}
protected SubmissionStudent(Parcel in) {
studentNumber = in.readInt();
studentNumberInt = in.readInt();
submitted = in.readByte() != 0;
}
@ -29,7 +29,7 @@ public class SubmissionStudent implements Parcelable {
};
public int getStudentNumber() {
return studentNumber;
return studentNumberInt;
}
public boolean isSubmitted() {
@ -43,7 +43,7 @@ public class SubmissionStudent implements Parcelable {
@Override
public void writeToParcel(Parcel parcel, int i) {
parcel.writeInt(studentNumber);
parcel.writeInt(studentNumberInt);
parcel.writeByte((byte) (submitted ? 1 : 0));
}
}

View File

@ -2,7 +2,6 @@ package com.example.oplogy;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.content.Context;
import android.os.Bundle;
import android.widget.TimePicker;
@ -18,14 +17,14 @@ public class TimePick extends DialogFragment implements
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) { // TimePeckerの生成
final Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
int hourInt = c.get(Calendar.HOUR_OF_DAY);
int minuteInt = c.get(Calendar.MINUTE);
return new TimePickerDialog((Context) getActivity(),
(TimePickerDialog.OnTimeSetListener) getActivity(), hour, minute, true);
return new TimePickerDialog(getActivity(),
(TimePickerDialog.OnTimeSetListener) getActivity(), hourInt, minuteInt, true);
}
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
public void onTimeSet(TimePicker view, int hourOfDayInt, int minuteInt) {
}
}