| |
---|
| | import android.widget.Toast; |
---|
| | |
---|
| | import com.example.cosmosclient.R; |
---|
| | import com.example.cosmosclient.app.Cosmos; |
---|
| | import com.example.cosmosclient.entities.AreaInformation; |
---|
| | 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 java.io.FileDescriptor; |
---|
| | import java.io.IOException; |
---|
| | import java.io.PrintWriter; |
---|
| | import java.util.ArrayList; |
---|
| | import java.util.HashMap; |
---|
| | import java.util.List; |
---|
| | import java.util.TimeZone; |
---|
| | import java.util.Timer; |
---|
| | import java.util.TimerTask; |
---|
| |
---|
| | private List<Notification> notifications =null; |
---|
| | private CosmosLocation LOC = new CosmosLocation(); |
---|
| | private double leftLat,leftLon,rightLat,rightLon; //ここに計算予定 |
---|
| | private int count = 0; |
---|
| | |
---|
| | |
---|
| | private int areacount = 0; |
---|
| | private ArrayList<Feature> Electrical = new ArrayList<>(); |
---|
| | private ArrayList<Feature> Home = new ArrayList<>(); |
---|
| | private ArrayList<Feature> Phone = new ArrayList<>(); |
---|
| | private ArrayList<Feature> PC = new ArrayList<>(); |
---|
| | private ArrayList<Feature> Convenience = new ArrayList<>(); |
---|
| | private ArrayList<Feature> Supermarket = new ArrayList<>(); |
---|
| | private AreaInformation areaInfo = new AreaInformation(); |
---|
| | |
---|
| | public CosmosBackgroundService() { |
---|
| | super("CosmosBackgroundService"); |
---|
| | Log.d(TAG, "Constructor"); |
---|
| |
---|
| | settingsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
---|
| | startActivity(settingsIntent); |
---|
| | } |
---|
| | |
---|
| | private void updateAreaInformation(Location location){ |
---|
| | private void updateAreaInformation(final Location location){ |
---|
| | Cosmos app = (Cosmos) getApplication(); |
---|
| | count = 0; |
---|
| | LOC.setLatitude(location.getLatitude()); |
---|
| | LOC.setLongitude(location.getLongitude()); |
---|
| | for(int i = 0;i<app.AreaInfoGetKey().size();i++){ |
---|
| | if(LOC.hashCode() != app.AreaInfoGetKey().get(i)){ |
---|
| | count++; |
---|
| | if(app.AreaInfoGetKey().size() != 0) { |
---|
| | for (int i = 0; i < app.AreaInfoGetKey().size(); i++) { |
---|
| | if (LOC.hashCode() != app.AreaInfoGetKey().get(i)) { |
---|
| | count++; |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | if(count == 0) { |
---|
| | //retrofitの処理 |
---|
| |
---|
| | @Override |
---|
| | public void onResponse(Call<ArrayList<Feature>> call, Response<ArrayList<Feature>> response) { |
---|
| | if (response.isSuccessful()) { |
---|
| | ArrayList<Feature> result = response.body(); |
---|
| | for(int i = 0; i < result.size(); i++){ |
---|
| | switch (result.get(i).getCode()) { |
---|
| | case 203001: |
---|
| | Electrical.add(result.get(i)); |
---|
| | areaInfo.setFeature(Electrical.get(0).getCode(),Electrical); |
---|
| | break; |
---|
| | case 203002: |
---|
| | Home.add(result.get(i)); |
---|
| | areaInfo.setFeature(Home.get(0).getCode(),Home); |
---|
| | break; |
---|
| | case 203003: |
---|
| | Phone.add(result.get(i)); |
---|
| | areaInfo.setFeature(Phone.get(0).getCode(),Phone); |
---|
| | break; |
---|
| | case 203004: |
---|
| | PC.add(result.get(i)); |
---|
| | areaInfo.setFeature(PC.get(0).getCode(),PC); |
---|
| | break; |
---|
| | case 205001: |
---|
| | Convenience.add(result.get(i)); |
---|
| | areaInfo.setFeature(Convenience.get(0).getCode(),Convenience); |
---|
| | break; |
---|
| | case 205002: |
---|
| | Supermarket.add(result.get(i)); |
---|
| | areaInfo.setFeature(Supermarket.get(0).getCode(),Supermarket); |
---|
| | break; |
---|
| | default: |
---|
| | continue; |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | //app/Cosmosに情報保存 |
---|
| | Cosmos app = (Cosmos) getApplication(); |
---|
| | // app.setAreaInfo(); |
---|
| | |
---|
| | // areaInfo.setFeature(Electrical.get(0).getCode(),Electrical); |
---|
| | // areaInfo.setFeature(Home.get(0).getCode(),Home); |
---|
| | // areaInfo.setFeature(Phone.get(0).getCode(),Phone); |
---|
| | // areaInfo.setFeature(PC.get(0).getCode(),PC); |
---|
| | // areaInfo.setFeature(Convenience.get(0).getCode(),Convenience); |
---|
| | // areaInfo.setFeature(Supermarket.get(0).getCode(),Supermarket); |
---|
| | |
---|
| | app.setAreaInfo(areaInfo.getLocation().hashCode(),areaInfo); |
---|
| | |
---|
| | } else { |
---|
| | //onFailureでキャッチできないエラー用 |
---|
| | Toast.makeText(CosmosBackgroundService.this, |
---|
| | "通信エラー", Toast.LENGTH_LONG).show(); |
---|
| | "区画情報取得失敗", Toast.LENGTH_LONG).show(); |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | //失敗時 |
---|
| |
---|
| | |