diff --git a/app/src/main/java/com/example/cosmosclient/GPSresources/StoreLocationsMethods.java b/app/src/main/java/com/example/cosmosclient/GPSresources/StoreLocationsMethods.java new file mode 100644 index 0000000..51c215e --- /dev/null +++ b/app/src/main/java/com/example/cosmosclient/GPSresources/StoreLocationsMethods.java @@ -0,0 +1,88 @@ +package com.example.cosmosclient.GPSresources; + +import android.location.Location; + +import com.example.cosmosclient.entities.Feature; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +public class StoreLocationsMethods { + private double NowLat; + private double NowLon; + private HashMap> feature = new HashMap<>(); + /*戻り値となる通知が必要なお店情報を格納する連想配列を作成*/ + private ArrayList nearShops=new ArrayList<>(); + + public StoreLocationsMethods(double NowLat, double NowLon){ + this.NowLat=NowLat; + this.NowLon=NowLon; + } + public void updateLocations(double NowLat,double NowLon){ + this.NowLat=NowLat; + this.NowLon=NowLon; + } + public double getNowLat(){ + return this.NowLat; + } + public double getNowLon(){ + return this.NowLon; + } + + public void setNearShops(HashMap> feature){ + this.feature=feature; + //HashMapを順番に実行 + for(HashMap.Entry> e : feature.entrySet()) { + //ArrayList>を回していく + for(int i=0; i < e.getValue().size();i++) { + float[] distance = getDistance(this.NowLat, this.NowLon, e.getValue().get(i).getLocation().getLatitude(), e.getValue().get(i).getLocation().getLongitude()); + // distance[0] = [2点間の距離] + //m単位 + if (distance[0] <= 50) { + /*ここから通知に必要な近い店の情報を格納する処理を記述*/ + /*中身を作成*/ + Feature childFeature = new Feature(); + childFeature.setCode(e.getValue().get(i).getCode()); + childFeature.setLocation(e.getValue().get(i).getLocation()); + childFeature.setName(e.getValue().get(i).getName()); + if(nearShops.indexOf(childFeature)==-1){ + /*通知に必要な近い店の情報を格納する処理を格納*/ + nearShops.add(childFeature); + } + } + } + } + } + public ArrayList getNearShops() { + return nearShops; + } + + /*通知送信後、通知すべきショップ情報リストから削除する*/ + /*引数はArrayList型*/ + /*引数のArrayListと一致するものをnearShopsから削除する*/ + public void deleteNearShops(ArrayList deleteList) { + for(int i=0; i < deleteList.size();i++){ + if(nearShops.indexOf(deleteList)!=-1){ + /*ここで削除*/ + nearShops.remove(nearShops.indexOf(deleteList)); + } + + } + + } + + + public float[] getDistance(double x, double y, double x2, double y2) { + // 結果を格納するための配列を生成 + float[] results = new float[3]; + // results[0] = [2点間の距離] + // results[1] = [始点から見た方位角] + // results[2] = [終点から見た方位角] + + // 距離計算 + Location.distanceBetween(x, y, x2, y2, results); + + return results; + } +} diff --git a/app/src/main/java/com/example/cosmosclient/app/Cosmos.java b/app/src/main/java/com/example/cosmosclient/app/Cosmos.java index b7687e0..5fd0597 100644 --- a/app/src/main/java/com/example/cosmosclient/app/Cosmos.java +++ b/app/src/main/java/com/example/cosmosclient/app/Cosmos.java @@ -4,6 +4,7 @@ import com.example.cosmosclient.entities.AreaInformation; import com.example.cosmosclient.entities.Group; +import android.content.SharedPreferences; import java.util.Collection; import java.util.HashMap; @@ -17,10 +18,15 @@ //token処理 public void setToken(String token){ - this.token = token; + SharedPreferences prefData = getSharedPreferences("pref_data", MODE_PRIVATE); + SharedPreferences.Editor editor = prefData.edit(); + editor.putString("token", token); + editor.commit(); } public String getToken(){ + SharedPreferences prefData = getSharedPreferences("pref_data", MODE_PRIVATE); + String token = prefData.getString("token", ""); return token; } @@ -52,10 +58,15 @@ //uId処理 public void setuId(String uId){ - this.uId = uId; + SharedPreferences prefData = getSharedPreferences("pref_data", MODE_PRIVATE); + SharedPreferences.Editor editor = prefData.edit(); + editor.putString("uId", uId); + editor.commit(); } public String getuId(){ + SharedPreferences prefData = getSharedPreferences("pref_data", MODE_PRIVATE); + String uId = prefData.getString("uId", ""); return uId; } diff --git a/app/src/main/java/com/example/cosmosclient/services/Notification.java b/app/src/main/java/com/example/cosmosclient/services/Notification.java new file mode 100644 index 0000000..fbae871 --- /dev/null +++ b/app/src/main/java/com/example/cosmosclient/services/Notification.java @@ -0,0 +1,47 @@ +package com.example.cosmosclient.services; + +import com.example.cosmosclient.entities.Feature; +import com.example.cosmosclient.entities.Group; +import com.example.cosmosclient.entities.GroupListResponse; +import com.example.cosmosclient.entities.Request; +import com.example.cosmosclient.entities.RequestList; + +import java.util.List; + +public class Notification { + + private Request request=null; + private Group group=null; + private List features=null; + + public Notification(Request request, Group group, List features){ + this.request=request; + this.group=group; + this.features =features; + } + public Request getRequest() { + return request; + } + + public void setRequest(Request request) { + this.request = request; + } + + public Group getGroup() { + return group; + } + + public void setGroup(Group group) { + this.group = group; + } + + public List getFeatures() { + return features; + } + + public void setFeatures(List features) { + this.features = features; + } + + +} diff --git a/app/src/main/java/com/example/cosmosclient/views/GroupListActivity.java b/app/src/main/java/com/example/cosmosclient/views/GroupListActivity.java index 0ff3b5b..aa105e2 100644 --- a/app/src/main/java/com/example/cosmosclient/views/GroupListActivity.java +++ b/app/src/main/java/com/example/cosmosclient/views/GroupListActivity.java @@ -1,7 +1,6 @@ package com.example.cosmosclient.views; import android.content.Intent; -import android.content.SharedPreferences; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.nfc.Tag; @@ -347,10 +346,8 @@ startActivity(intent); } else if (id == R.id.signOutButton){ //トークン削除 - SharedPreferences prefData = getSharedPreferences("pref_data", MODE_PRIVATE); - SharedPreferences.Editor editor = prefData.edit(); - editor.remove("token"); - editor.commit(); + Cosmos app = (Cosmos) getApplication(); + app.setToken(""); gridView.stopEditMode(); Intent intent=new Intent(GroupListActivity.this, com.example.cosmosclient.views.SigninActivity.class); ActivityCompat.finishAffinity(GroupListActivity.this); diff --git a/app/src/main/java/com/example/cosmosclient/views/SigninActivity.java b/app/src/main/java/com/example/cosmosclient/views/SigninActivity.java index 400555d..5a1198d 100644 --- a/app/src/main/java/com/example/cosmosclient/views/SigninActivity.java +++ b/app/src/main/java/com/example/cosmosclient/views/SigninActivity.java @@ -7,7 +7,6 @@ import android.Manifest; import android.content.Context; import android.content.Intent; -import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.os.Build; import android.os.Handler; @@ -72,9 +71,8 @@ final EditText PasswordText = findViewById(R.id.PasswordText); Button ForgotPasswordButton = findViewById(R.id.ForgotPasswordButton); - // 「pref_data」という設定データファイルを読み込み - SharedPreferences prefData = getSharedPreferences("pref_data", MODE_PRIVATE); - String account = prefData.getString("account", ""); + Cosmos app = (Cosmos) getApplication(); + String account = app.getuId(); // 空チェック if (account != null && account.length() > 0) { @@ -133,13 +131,6 @@ app.setToken(result.token); app.setuId(UserIdText.getText().toString()); - //SharedPreferencesに情報保存 - SharedPreferences prefData = getSharedPreferences("pref_data", MODE_PRIVATE); - SharedPreferences.Editor editor = prefData.edit(); - editor.putString("account", UserIdText.getText().toString()); - editor.putString("token", result.token); - editor.commit(); - //画面遷移 Intent intent = new Intent(getApplication(), GroupListActivity.class); startActivity(intent); diff --git a/app/src/main/java/com/example/cosmosclient/views/SignupActivity.java b/app/src/main/java/com/example/cosmosclient/views/SignupActivity.java index afa76b9..bafa874 100644 --- a/app/src/main/java/com/example/cosmosclient/views/SignupActivity.java +++ b/app/src/main/java/com/example/cosmosclient/views/SignupActivity.java @@ -2,7 +2,6 @@ import android.content.Intent; -import android.content.SharedPreferences; import android.graphics.Bitmap; import android.net.Uri; import android.os.Handler; @@ -112,18 +111,6 @@ Cosmos app = (Cosmos) getApplication(); app.setToken(result.token); app.setuId(result.uId); - //データをprerefarenceに保存 - - // 「pref_data」という設定データファイルを読み込み - SharedPreferences prefData = getSharedPreferences("pref_data", MODE_PRIVATE); - SharedPreferences.Editor editor = prefData.edit(); - - // 入力されたログインIDとログインパスワード - editor.putString("account", result.uId); - editor.putString("token", result.token); - - // 保存 - editor.commit(); Intent intent = new Intent(getApplication(), GroupListActivity.class); startActivity(intent);