diff --git a/app/build.gradle b/app/build.gradle index 8a5b3fa..f34f8ff 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -4,7 +4,7 @@ compileSdkVersion 28 defaultConfig { applicationId "com.example.cosmosclient" - minSdkVersion 15 + minSdkVersion 26 targetSdkVersion 28 versionCode 1 versionName "1.0" 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 c467f5f..08f8cc6 100644 --- a/app/src/main/java/com/example/cosmosclient/app/Cosmos.java +++ b/app/src/main/java/com/example/cosmosclient/app/Cosmos.java @@ -4,10 +4,10 @@ import android.app.Activity; import android.app.Application; import android.content.ComponentCallbacks; -import android.content.res.Configuration; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; +import android.content.res.Configuration; import android.os.Build; import android.os.Bundle; import android.support.annotation.RequiresApi; @@ -195,8 +195,8 @@ //currentGroup処理 public void setCurrentGroup(Group g){ - setGroup(g); - curGroup = groups.get(g.getgId()); + setGroup(g); + curGroup = groups.get(g.getgId()); } public Group getCurentGroup(){ 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 6565442..74be9d2 100644 --- a/app/src/main/java/com/example/cosmosclient/services/CosmosBackgroundService.java +++ b/app/src/main/java/com/example/cosmosclient/services/CosmosBackgroundService.java @@ -63,6 +63,7 @@ private CosmosLocation LOC = new CosmosLocation(); private double leftLat,leftLon,rightLat,rightLon; //ここに計算予定 private int count = 0; + private NotificationManager notificationManager; public CosmosBackgroundService() { super("CosmosBackgroundService"); @@ -82,6 +83,10 @@ context = getApplicationContext(); // LocationManager インスタンス生成 locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); + notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); + int importance = NotificationManager.IMPORTANCE_HIGH; + NotificationChannel mChannel = new NotificationChannel("cosmos", "cosmosChannel", importance); + notificationManager.createNotificationChannel(mChannel); } @Override @@ -249,6 +254,28 @@ updateAreaInformation(location); this.notifications=searchNotifications(cosmos,location); + sendNotifications(this, notifications); + + + } + + private void sendNotifications(CosmosBackgroundService cosmosBackgroundService, List notifications) { + int notificationId = 1; +// MainActivity→broadcastreseiver(?)に変更 +// Intent intent = new Intent(cosmosBackgroundService, MainActivity.class); +// 以下二行はボタンについてだよ +// PendingIntent pendingIntent = PendingIntent.getActivity(cosmosBackgroundService, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); +// android.app.Notification.Action action = new android.app.Notification.Action(R.drawable.notification_icon, "ボタンだよ", pendingIntent); + + android.app.Notification notification = new android.app.Notification.Builder(cosmosBackgroundService) + .setContentTitle("通知タイトル") + .setContentText("通知ないよう") + .setSmallIcon(R.drawable.icon_no) + .setChannelId("cosmos") +// .setGroup("") +// .addAction(action) + .build(); + notificationManager.notify(notificationId, notification); } @Override @@ -441,7 +468,7 @@ //notificationを作成 Notification notification = new Notification(groups.get(i).getRequestList().getRequests().get(j),groups.get(i),null); //指定したkey(業番)を持っているHashMapがなければ作成する。 - if(codeToNotification.get(groups.get(i).getRequestList().getRequests().get(j))==null){ + if(codeToNotification.get(groups.get(i).getRequestList().getRequests().get(j).getLocation())==null){ notifications.add(notification); codeToNotification.put(groups.get(i).getRequestList().getRequests().get(j).getLocation(),notifications); }else{ @@ -452,8 +479,12 @@ } } //cosmosから区画情報から取得 - int areaInfoId =(int)((NowLat+90)/0.1)+(int)((NowLon/0.1)*1800); - codeToFeature =cosmos.getAreaInfo(areaInfoId).getFeature(); + + CosmosLocation cosmosLocation = new CosmosLocation(); + cosmosLocation.setLatitude(NowLat); + cosmosLocation.setLongitude(NowLon); + int areaInfoId = cosmosLocation.hashCode(); + codeToFeature=cosmos.getAreaInfo(areaInfoId).getFeature(); //codeToFeatureの中の50m圏外Featureを削除していく。 //HashMapを順番に実行 for(HashMap.Entry> e : codeToFeature.entrySet()) { diff --git a/app/src/main/res/drawable/icon_no.png b/app/src/main/res/drawable/icon_no.png new file mode 100644 index 0000000..807f3e4 --- /dev/null +++ b/app/src/main/res/drawable/icon_no.png Binary files differ