Skip to content
This repository was archived by the owner on Jan 23, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.kamron.pogoiv.pokeflycomponents;

import android.app.IntentService;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.support.v7.app.NotificationCompat;
import android.support.v4.app.NotificationCompat;
import android.widget.RemoteViews;
import android.widget.Toast;

Expand All @@ -30,12 +31,14 @@ public class GoIVNotificationManager {

private static final int NOTIFICATION_REQ_CODE = 8959;

private static final String NOTIFICATION_CHANNEL_ID = "8959";

private static Pokefly pokefly;

public static final String ACTION_RECALIBRATE_SCANAREA = "com.kamron.pogoiv.ACTION_RECALIBRATE_SCANAREA";
private static final String ACTION_RECALIBRATE_SCANAREA = "com.kamron.pogoiv.ACTION_RECALIBRATE_SCANAREA";

public GoIVNotificationManager(Pokefly pokefly) {
this.pokefly = pokefly;
GoIVNotificationManager.pokefly = pokefly;
}


Expand Down Expand Up @@ -73,22 +76,31 @@ public void showPausedNotification() {
contentBigView.setOnClickPendingIntent(R.id.start, startServicePendingIntent);

// Build notification
Notification notification = new NotificationCompat.Builder(pokefly)
NotificationCompat.Builder notification = new NotificationCompat.Builder(pokefly, NOTIFICATION_CHANNEL_ID)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle(pokefly.getString(R.string.notification_title_goiv_stopped))
.setContentText(pokefly.getString(R.string.notification_title_tap_to_open))
.setColor(pokefly.getColorC(R.color.colorAccent))
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setCategory(NotificationCompat.CATEGORY_PROGRESS)
.setWhen(0)
.setContent(contentView)
.setCustomBigContentView(contentBigView)
.setOngoing(false)
.build();
.setOngoing(false);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
notification
.setCustomContentView(contentView)
.setStyle(new NotificationCompat.DecoratedCustomViewStyle());
}

NotificationManager notificationManager =
(NotificationManager) pokefly.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(NOTIFICATION_REQ_CODE, notification);

initNotificationChannel(notificationManager);

notificationManager.notify(NOTIFICATION_REQ_CODE, notification.build());
}

/**
Expand Down Expand Up @@ -129,20 +141,45 @@ public void showRunningNotification() {
contentBigView.setOnClickPendingIntent(R.id.pause, stopServicePendingIntent);

// Build notification
Notification notification = new NotificationCompat.Builder(pokefly)
NotificationCompat.Builder notification = new NotificationCompat.Builder(pokefly, NOTIFICATION_CHANNEL_ID)
.setSmallIcon(R.drawable.notification_icon_play)
.setContentTitle(pokefly.getString(R.string.notification_title, pokefly.getTrainerLevel()))
.setContentText(pokefly.getString(R.string.notification_title_tap_to_open))
.setColor(pokefly.getColorC(R.color.colorPrimary))
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setCategory(NotificationCompat.CATEGORY_PROGRESS)
.setWhen(0)
.setContent(contentView)
.setCustomBigContentView(contentBigView)
.setOngoing(true)
.build();
.setOngoing(false);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
notification
.setCustomContentView(contentView)
.setStyle(new NotificationCompat.DecoratedCustomViewStyle());
}

NotificationManager notificationManager =
(NotificationManager) pokefly.getSystemService(Context.NOTIFICATION_SERVICE);

initNotificationChannel(notificationManager);

pokefly.startForeground(NOTIFICATION_REQ_CODE, notification.build());
}

private void initNotificationChannel(NotificationManager notificationManager) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && notificationManager
.getNotificationChannel(NOTIFICATION_CHANNEL_ID) == null) {
// Create notification channel
NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID,
"GoIV", NotificationManager.IMPORTANCE_LOW);

pokefly.startForeground(NOTIFICATION_REQ_CODE, notification);
channel.setShowBadge(false);
channel.enableLights(false);

notificationManager.createNotificationChannel(channel);
}
}

/**
Expand Down Expand Up @@ -196,4 +233,4 @@ public void run() {
}
}
}
}
}
75 changes: 41 additions & 34 deletions app/src/main/res/layout/notification_pokefly_paused.xml
Original file line number Diff line number Diff line change
@@ -1,60 +1,67 @@
<LinearLayout
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="64dp"
android:paddingLeft="@dimen/notification_horizontal_padding"
android:paddingTop="8dp"
android:paddingRight="@dimen/notification_horizontal_padding"
android:paddingBottom="8dp">
android:paddingTop="@dimen/notification_vertical_padding"
android:paddingBottom="@dimen/notification_vertical_padding">

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/icon"
android:layout_width="@dimen/icon_size"
android:layout_height="@dimen/icon_size"
android:layout_marginEnd="8dp"
android:layout_gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:src="@mipmap/ic_launcher" />

<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
<TextView
style="@style/NotificationTitle"
android:id="@+id/notification_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical">
android:layout_toEndOf="@id/icon"
android:layout_toStartOf="@+id/settings"
android:text="@string/notification_title_goiv_stopped" />

<TextView
style="@style/NotificationTitle"
android:id="@+id/notification_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/notification_title_goiv_stopped" />

<TextView
style="@style/NotificationMessage"
android:id="@+id/notification_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/notification_title_tap_to_open" />

</LinearLayout>
<TextView
style="@style/NotificationMessage"
android:id="@+id/notification_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/icon"
android:layout_below="@id/notification_title"
android:text="@string/notification_title_tap_to_open" />

<ImageButton
style="@style/Base.Widget.AppCompat.Button.Borderless"
android:id="@+id/settings"
style="@style/Base.Widget.AppCompat.Button.Borderless"
android:layout_width="48dp"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:src="@drawable/ic_settings_24px"
android:contentDescription="@string/settings_page_title" />
android:layout_marginEnd="8dp"
android:layout_alignParentTop="true"
android:layout_toStartOf="@+id/start"
android:adjustViewBounds="true"
android:scaleType="centerInside"
android:layout_centerInParent="true"
android:contentDescription="@string/settings_page_title"
android:src="@drawable/ic_settings_24px"/>

<ImageButton
style="@style/Base.Widget.AppCompat.Button.Borderless"
android:id="@+id/start"
style="@style/Base.Widget.AppCompat.Button.Borderless"
android:layout_width="48dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:adjustViewBounds="true"
android:scaleType="centerInside"
android:layout_centerInParent="true"
android:layout_marginEnd="-12dp"
android:src="@drawable/ic_play_circle_outline_24px"
android:contentDescription="@string/main_start" />
android:contentDescription="@string/main_start"
android:src="@drawable/ic_play_circle_outline_24px"/>

</LinearLayout>
</RelativeLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingLeft="@dimen/notification_horizontal_padding"
android:paddingTop="8dp"
android:paddingTop="@dimen/notification_vertical_padding"
android:paddingRight="@dimen/notification_horizontal_padding"
android:paddingBottom="8dp">
android:paddingBottom="@dimen/notification_vertical_padding">

<ImageView
android:layout_width="wrap_content"
Expand Down
65 changes: 36 additions & 29 deletions app/src/main/res/layout/notification_pokefly_started.xml
Original file line number Diff line number Diff line change
@@ -1,61 +1,68 @@
<LinearLayout
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="64dp"
android:paddingLeft="@dimen/notification_horizontal_padding"
android:paddingTop="8dp"
android:paddingRight="@dimen/notification_horizontal_padding"
android:paddingBottom="8dp">
android:paddingTop="@dimen/notification_vertical_padding"
android:paddingBottom="@dimen/notification_vertical_padding">

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/icon"
android:layout_width="@dimen/icon_size"
android:layout_height="@dimen/icon_size"
android:layout_marginEnd="8dp"
android:layout_gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:src="@mipmap/ic_launcher" />

<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
<TextView
style="@style/NotificationTitle"
android:id="@+id/notification_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical">

<TextView
style="@style/NotificationTitle"
android:id="@+id/notification_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="@string/notification_title_short" />
android:layout_toEndOf="@id/icon"
android:layout_toStartOf="@+id/recalibrate"
tools:text="@string/notification_title_short" />

<TextView
style="@style/NotificationMessage"
android:id="@+id/notification_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/notification_title_tap_to_open" />

</LinearLayout>
<TextView
style="@style/NotificationMessage"
android:id="@+id/notification_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/icon"
android:layout_below="@id/notification_title"
android:text="@string/notification_title_tap_to_open" />

<ImageButton
style="@style/Base.Widget.AppCompat.Button.Borderless"
android:id="@+id/recalibrate"
android:layout_width="48dp"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:layout_marginEnd="8dp"
android:layout_alignParentTop="true"
android:layout_toStartOf="@+id/pause"
android:adjustViewBounds="true"
android:scaleType="centerInside"
android:layout_centerInParent="true"
android:src="@drawable/ic_recalibrate_24px"
android:contentDescription="@string/recalibrate_goiv_notification"/>
android:contentDescription="@string/recalibrate_goiv_notification" />

<ImageButton
style="@style/Base.Widget.AppCompat.Button.Borderless"
android:id="@+id/pause"
android:layout_width="48dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:adjustViewBounds="true"
android:scaleType="centerInside"
android:layout_centerInParent="true"
android:layout_marginEnd="-12dp"
android:src="@drawable/ic_pause_circle_outline_24px"
android:contentDescription="@string/pause_goiv_notification" />

</LinearLayout>
</RelativeLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingLeft="@dimen/notification_horizontal_padding"
android:paddingTop="8dp"
android:paddingTop="@dimen/notification_vertical_padding"
android:paddingRight="@dimen/notification_horizontal_padding"
android:paddingBottom="8dp">
android:paddingBottom="@dimen/notification_vertical_padding">

<ImageView
android:layout_width="wrap_content"
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/res/values-v24/dimens.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<resources>
<!-- Notification margins -->
<dimen name="notification_horizontal_padding">16dp</dimen>
<dimen name="notification_horizontal_padding">0dp</dimen>
<dimen name="notification_vertical_padding">0dp</dimen>
<!-- Notification icon size -->
<dimen name="icon_size">40dp</dimen>
</resources>
5 changes: 5 additions & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@

<!-- Notification margins -->
<dimen name="notification_horizontal_padding">8dp</dimen>
<dimen name="notification_vertical_padding">8dp</dimen>
<!-- Notification icon size -->
<dimen name="icon_size">@dimen/wrap_content</dimen>
<!-- wrap_content -->
<item name="wrap_content" format="integer" type="dimen">-2</item>
</resources>