package com.example.cosmosclient.app; import android.app.Application; import android.content.ComponentCallbacks; import android.content.res.Configuration; import android.util.Log; import com.example.cosmosclient.entities.AreaInformation; import com.example.cosmosclient.entities.Group; import android.content.SharedPreferences; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; public class Cosmos extends Application { private String token=null; private Group curGroup=null; private HashMap<String, Group> groups = new HashMap<>(); private String uId=null; private HashMap<Integer, AreaInformation> areaInfo = new HashMap<>(); private ArrayList<Integer> areaInfoKey= new ArrayList<>(); private String TAG = Cosmos.class.getSimpleName(); public Cosmos() { super(); Log.d(TAG, " Constructor"); } @Override public void onCreate() { Log.d(TAG, " onCreate"); super.onCreate(); } @Override public void onTerminate() { Log.d(TAG, " onTerminate"); super.onTerminate(); } @Override public void onConfigurationChanged(Configuration newConfig) { Log.d(TAG, " onConfigurationChanged"); super.onConfigurationChanged(newConfig); } @Override public void onLowMemory() { Log.d(TAG, " onLowMemory"); super.onLowMemory(); } @Override public void onTrimMemory(int level) { Log.d(TAG, " onTrimMemory"); super.onTrimMemory(level); } @Override public void registerComponentCallbacks(ComponentCallbacks callback) { Log.d(TAG, " registerComponentCallbacks"); super.registerComponentCallbacks(callback); } @Override public void unregisterComponentCallbacks(ComponentCallbacks callback) { Log.d(TAG, " unregisterComponentCallbacks"); super.unregisterComponentCallbacks(callback); } @Override public void registerActivityLifecycleCallbacks(ActivityLifecycleCallbacks callback) { Log.d(TAG, " registerActivityLifecycleCallbacks"); super.registerActivityLifecycleCallbacks(callback); } @Override public void unregisterActivityLifecycleCallbacks(ActivityLifecycleCallbacks callback) { Log.d(TAG, " unregisterActivityLifecycleCallbacks"); super.unregisterActivityLifecycleCallbacks(callback); } @Override public void registerOnProvideAssistDataListener(OnProvideAssistDataListener callback) { Log.d(TAG, " registerOnProvideAssistDataListener"); super.registerOnProvideAssistDataListener(callback); } @Override public void unregisterOnProvideAssistDataListener(OnProvideAssistDataListener callback) { Log.d(TAG, " unregisterOnProvideAssistDataListener"); super.unregisterOnProvideAssistDataListener(callback); } //token処理 public void setToken(String 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; } //currentGroup処理 public void setCurrentGroup(Group g){ setGroup(g); curGroup = groups.get(g.getgId()); } public Group getCurentGroup(){ return curGroup; } //Group処理 public void setGroup(Group g) { if (!groups.containsKey(g.getgId())) { String newGid = g.getgId(); groups.put(newGid, g); } } public Group getGroup(String gId) { return groups.get(gId); } public Collection<Group> getGroups() { return groups.values(); } //uId処理 public void setuId(String 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; } //areaInfo処理 public void setAreaInfo(int areaId, AreaInformation AreaInfo){ this.areaInfo.put(areaId,AreaInfo); } public AreaInformation getAreaInfo(int areaId){ return areaInfo.get(areaId); } public ArrayList<Integer> AreaInfoGetKey(){ for(int key : areaInfo.keySet()){ areaInfoKey.add(key); } return areaInfoKey; } }