-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #102 from Onegini/develop
Develop
- Loading branch information
Showing
31 changed files
with
432 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
app/src/main/java/com/onegini/mobile/exampleapp/ExampleApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (c) 2016-2017 Onegini B.V. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.onegini.mobile.exampleapp; | ||
|
||
import android.support.multidex.MultiDexApplication; | ||
import com.onegini.mobile.exampleapp.view.helper.AppLifecycleListener; | ||
|
||
public class ExampleApplication extends MultiDexApplication { | ||
|
||
@Override | ||
public void onCreate () { | ||
super.onCreate(); | ||
registerActivityLifecycleCallbacks(new AppLifecycleListener()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
app/src/main/java/com/onegini/mobile/exampleapp/model/NotificationId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright (c) 2016-2017 Onegini B.V. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.onegini.mobile.exampleapp.model; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
public class NotificationId { | ||
|
||
private static final AtomicInteger integer = new AtomicInteger((int) System.currentTimeMillis()); | ||
|
||
public static int getId() { | ||
return integer.getAndIncrement(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
app/src/main/java/com/onegini/mobile/exampleapp/network/fcm/NotificationHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright (c) 2016-2017 Onegini B.V. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.onegini.mobile.exampleapp.network.fcm; | ||
|
||
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.graphics.Color; | ||
import android.os.Build; | ||
import android.support.annotation.RequiresApi; | ||
import android.support.v4.app.NotificationCompat; | ||
import com.onegini.mobile.exampleapp.R; | ||
import com.onegini.mobile.exampleapp.model.NotificationId; | ||
import com.onegini.mobile.exampleapp.view.helper.AppLifecycleListener; | ||
|
||
public class NotificationHelper { | ||
|
||
private static final String CHANNEL_ID = "transactions"; | ||
|
||
private final Context context; | ||
|
||
public NotificationHelper(final Context context) { | ||
this.context = context; | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
registerNotificationChannel(); | ||
} | ||
} | ||
|
||
public void handleIntent(final Intent intent, final String message) { | ||
if (AppLifecycleListener.isAppInForeground()) { | ||
context.startActivity(intent); | ||
} else { | ||
showNotification(intent, message); | ||
} | ||
} | ||
|
||
private void showNotification(final Intent intent, final String message) { | ||
final NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID) | ||
.setSmallIcon(R.mipmap.ic_launcher) | ||
.setContentTitle("Confirm the transaction") | ||
.setContentText(message) | ||
.setContentIntent(getPendingIntent(intent)) | ||
.setPriority(NotificationCompat.PRIORITY_MAX) | ||
.setAutoCancel(true); | ||
|
||
getManager().notify(NotificationId.getId(), builder.build()); | ||
} | ||
|
||
@RequiresApi(api = Build.VERSION_CODES.O) | ||
private void registerNotificationChannel() { | ||
final NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID, "Transactions", NotificationManager.IMPORTANCE_HIGH); | ||
notificationChannel.setDescription("Onegini SDK"); | ||
notificationChannel.enableLights(true); | ||
notificationChannel.setLightColor(Color.BLUE); | ||
notificationChannel.enableVibration(true); | ||
notificationChannel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE); | ||
|
||
getManager().createNotificationChannel(notificationChannel); | ||
} | ||
|
||
private NotificationManager getManager() { | ||
return (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); | ||
} | ||
|
||
private PendingIntent getPendingIntent(final Intent intent) { | ||
return PendingIntent.getActivity(context, 0, intent, 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.