diff --git a/app/src/main/java/com/example/cosmosclient/entities/AreaInformation.java b/app/src/main/java/com/example/cosmosclient/entities/AreaInformation.java index 4a581ac..3dc2816 100644 --- a/app/src/main/java/com/example/cosmosclient/entities/AreaInformation.java +++ b/app/src/main/java/com/example/cosmosclient/entities/AreaInformation.java @@ -5,14 +5,14 @@ import java.util.HashMap; public class AreaInformation { - private Location location = new Location(); + private CosmosLocation location = new CosmosLocation(); private HashMap> feature = new HashMap<>(); private Time lastUpdated; - public void setLocation(Location location){ + public void setLocation(CosmosLocation location){ this.location = location; } - public Location getLocation(){ + public CosmosLocation getLocation(){ return this.location; } diff --git a/app/src/main/java/com/example/cosmosclient/entities/CosmosLocation.java b/app/src/main/java/com/example/cosmosclient/entities/CosmosLocation.java new file mode 100644 index 0000000..a13d9db --- /dev/null +++ b/app/src/main/java/com/example/cosmosclient/entities/CosmosLocation.java @@ -0,0 +1,24 @@ +package com.example.cosmosclient.entities; + +public class CosmosLocation { + private double latitude; + private double longitude; + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + public double getLatitude() { + return latitude; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + public double getLongitude() { + return longitude; + } + + public int hashCode(){ + return (int)((latitude+90)/0.1)+(int)((longitude/0.1)*1800); + } +} diff --git a/app/src/main/java/com/example/cosmosclient/entities/Feature.java b/app/src/main/java/com/example/cosmosclient/entities/Feature.java index 63c3374..4321e38 100644 --- a/app/src/main/java/com/example/cosmosclient/entities/Feature.java +++ b/app/src/main/java/com/example/cosmosclient/entities/Feature.java @@ -3,7 +3,7 @@ public class Feature { private String name; private int code; - private Location location = new Location(); + private CosmosLocation location = new CosmosLocation(); public void setName(String name){ this.name = name; @@ -19,10 +19,10 @@ return this.code; } - public void setLocation(Location location){ + public void setLocation(CosmosLocation location){ this.location = location; } - public Location getLocation(){ + public CosmosLocation getLocation(){ return this.location; } } diff --git a/app/src/main/java/com/example/cosmosclient/entities/Location.java b/app/src/main/java/com/example/cosmosclient/entities/Location.java deleted file mode 100644 index 113b555..0000000 --- a/app/src/main/java/com/example/cosmosclient/entities/Location.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.example.cosmosclient.entities; - -public class Location { - private double latitude; - private double longitude; - - public void setLatitude(double latitude) { - this.latitude = latitude; - } - public double getLatitude() { - return latitude; - } - - public void setLongitude(double longitude) { - this.longitude = longitude; - } - public double getLongitude() { - return longitude; - } - - public int hashCode(){ - return (int)((latitude+90)/0.1)+(int)((longitude/0.1)*1800); - } -} diff --git a/app/src/main/java/com/example/cosmosclient/resources/LocationRest.java b/app/src/main/java/com/example/cosmosclient/resources/LocationRest.java new file mode 100644 index 0000000..0e74d20 --- /dev/null +++ b/app/src/main/java/com/example/cosmosclient/resources/LocationRest.java @@ -0,0 +1,20 @@ +package com.example.cosmosclient.resources; + +import com.example.cosmosclient.entities.AreaInformation; +import com.example.cosmosclient.entities.Feature; + +import java.util.ArrayList; + +import retrofit2.Call; +import retrofit2.http.GET; +import retrofit2.http.Query; + + +public interface LocationRest { + + @GET("shops") + Call> LocationService(@Query("leftLatitude") String leftLat, + @Query("leftLongitude") String leftLon, + @Query("rightLatitude") String rightLat, + @Query("rightLongitude") String rightLon); +} \ No newline at end of file diff --git a/app/src/main/java/com/example/cosmosclient/resources/ShopRest.java b/app/src/main/java/com/example/cosmosclient/resources/ShopRest.java deleted file mode 100644 index 0d9a51c..0000000 --- a/app/src/main/java/com/example/cosmosclient/resources/ShopRest.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.example.cosmosclient.resources; - -import com.example.cosmosclient.entities.Feature; - -import retrofit2.Call; -import retrofit2.http.GET; -import retrofit2.http.Query; - -public interface ShopRest { - - @GET("rest") - Call ShopRequest(@Query("longitude") double longitude, - @Query("latitude") double latitude, - @Query("longitudeRange") double longitudeRange, - @Query("latitudeRange") double latitudeRange, - @Query("shop") int shop); -} diff --git a/app/src/main/java/com/example/cosmosclient/services/CosmosBackgroundService.java b/app/src/main/java/com/example/cosmosclient/services/CosmosBackgroundService.java index 8ea8e03..055ec70 100644 --- a/app/src/main/java/com/example/cosmosclient/services/CosmosBackgroundService.java +++ b/app/src/main/java/com/example/cosmosclient/services/CosmosBackgroundService.java @@ -22,18 +22,23 @@ import android.support.annotation.RequiresApi; import android.support.v4.app.ActivityCompat; import android.util.Log; +import android.widget.Toast; import com.example.cosmosclient.R; import com.example.cosmosclient.app.Cosmos; +import com.example.cosmosclient.entities.CosmosLocation; +import com.example.cosmosclient.entities.Feature; import com.example.cosmosclient.entities.Group; import com.example.cosmosclient.entities.GroupListResponse; import com.example.cosmosclient.entities.RequestList; import com.example.cosmosclient.entities.jsons.GroupJson; import com.example.cosmosclient.resources.GroupsRest; +import com.example.cosmosclient.resources.LocationRest; import java.io.FileDescriptor; import java.io.IOException; import java.io.PrintWriter; +import java.util.ArrayList; import java.util.List; import java.util.TimeZone; import java.util.Timer; @@ -54,6 +59,10 @@ private boolean isServiceRunning = false; //サービスが起動しているかを確認 private String TAG = CosmosBackgroundService.class.getSimpleName(); private List notifications =null; + private CosmosLocation LOC = new CosmosLocation(); + private double leftLat,leftLon,rightLat,rightLon; //ここに計算予定 + private int count = 0; + public CosmosBackgroundService() { @@ -354,6 +363,62 @@ } private void updateAreaInformation(Location location){ + Cosmos app = (Cosmos) getApplication(); + count = 0; + LOC.setLatitude(location.getLatitude()); + LOC.setLongitude(location.getLongitude()); + for(int i = 0;i> call = LocationService.LocationService(String.valueOf(leftLat), + String.valueOf(leftLon), String.valueOf(rightLat), String.valueOf(rightLon)); + + //サーバからデータ受け取り + call.enqueue(new Callback>() { + //成功時 + @Override + public void onResponse(Call> call, Response> response) { + if (response.isSuccessful()) { + ArrayList result = response.body(); + + //app/Cosmosに情報保存 + Cosmos app = (Cosmos) getApplication(); +// app.setAreaInfo(); + + } else { + //onFailureでキャッチできないエラー用 + Toast.makeText(CosmosBackgroundService.this, + "通信エラー", Toast.LENGTH_LONG).show(); + } + } + + //失敗時 + @Override + public void onFailure(Call> call, Throwable t) { + t.printStackTrace(); + Toast.makeText(CosmosBackgroundService.this, + "区画情報の更新に失敗しました", Toast.LENGTH_SHORT).show(); + } + }); + } } public List searchNotifications(Cosmos cosmos, Location location){