-
Notifications
You must be signed in to change notification settings - Fork 14
/
EPPZ_Alert.java
102 lines (76 loc) · 2.99 KB
/
EPPZ_Alert.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//
// Copyright (c) 2016 eppz! mobile, Gergely Borbás (SP)
//
// http://www.twitter.com/_eppz
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
package com.eppz.plugins;
// Features.
import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
// Unity.
import com.unity3d.player.UnityPlayer;
// Debug.
import android.util.Log;
public class EPPZ_Alert extends Fragment
implements EPPZ_DialogFragment.Listener
{
// Constants.
public static final String TAG = "EPPZ_Alert_Fragment";
private static final String CALLBACK_METHOD_NAME = "AlertDidFinishWithResult";
// Singleton instance.
public static EPPZ_Alert instance;
// Unity context.
String gameObjectName;
// region Creation
public static void start(String gameObjectName)
{
// Instantiate and add to Unity Player Activity.
instance = new EPPZ_Alert();
instance.gameObjectName = gameObjectName; // Store `GameObject` reference
UnityPlayer.currentActivity.getFragmentManager().beginTransaction().add(instance, EPPZ_Alert.TAG).commit();
}
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setRetainInstance(true); // Retain between configuration changes (like device rotation)
}
// endregion
// region Plugin features
public void showAlertWithAttributes(String title, String message, String positiveButtonTitle, String negativeButtonTitle)
{
Log.i(TAG, TAG+".showAlertWithAttributes(`"+title+"`, `"+message+"`, `"+positiveButtonTitle+"`, `"+negativeButtonTitle+"`)");
// Create and show dialog.
EPPZ_DialogFragment dialogFragment = EPPZ_DialogFragment.newInstance(
title,
message,
positiveButtonTitle,
negativeButtonTitle
);
dialogFragment.show(getFragmentManager(), title);
}
@Override
public void dialogDidFinishWithResult(EPPZ_DialogFragment dialog, String selectedButtonTitle)
{
Log.i(TAG, TAG+".dialogDidFinishWithResult(selectedButtonTitle: `"+selectedButtonTitle+"`)");
// Call back to Unity.
SendUnityMessage(CALLBACK_METHOD_NAME, selectedButtonTitle);
}
// endregion
// region Utilities
void SendUnityMessage(String methodName, String parameter)
{
Log.i(TAG, TAG+"SendUnityMessage(`"+methodName+"`, `"+parameter+"`)");
UnityPlayer.UnitySendMessage(gameObjectName, methodName, parameter);
}
// endregion
}