Skip to content

Commit 7af6680

Browse files
committed
apply format to java and c code
1 parent a7b8d55 commit 7af6680

29 files changed

Lines changed: 1100 additions & 1014 deletions

android/src/main/java/com/onesignal/flutter/FlutterMessengerResponder.java

Lines changed: 59 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -3,75 +3,72 @@
33
import android.content.Context;
44
import android.os.Handler;
55
import android.os.Looper;
6-
7-
import java.util.HashMap;
8-
96
import io.flutter.plugin.common.BinaryMessenger;
107
import io.flutter.plugin.common.MethodChannel;
8+
import java.util.HashMap;
119

1210
abstract class FlutterMessengerResponder {
13-
Context context;
14-
protected MethodChannel channel;
15-
BinaryMessenger messenger;
11+
Context context;
12+
protected MethodChannel channel;
13+
BinaryMessenger messenger;
1614

17-
/**
18-
* MethodChannel class is home to success() method used by Result class
19-
* It has the @UiThread annotation and must be run on UI thread, otherwise a RuntimeException will be thrown
20-
* This will communicate success back to Dart
21-
*/
22-
void replySuccess(final MethodChannel.Result reply, final Object response) {
23-
runOnMainThread(new Runnable() {
24-
@Override
25-
public void run() {
26-
reply.success(response);
27-
}
28-
});
29-
}
15+
/**
16+
* MethodChannel class is home to success() method used by Result class
17+
* It has the @UiThread annotation and must be run on UI thread, otherwise a RuntimeException will be thrown
18+
* This will communicate success back to Dart
19+
*/
20+
void replySuccess(final MethodChannel.Result reply, final Object response) {
21+
runOnMainThread(new Runnable() {
22+
@Override
23+
public void run() {
24+
reply.success(response);
25+
}
26+
});
27+
}
3028

31-
/**
32-
* MethodChannel class is home to error() method used by Result class
33-
* It has the @UiThread annotation and must be run on UI thread, otherwise a RuntimeException will be thrown
34-
* This will communicate error back to Dart
35-
*/
36-
void replyError(final MethodChannel.Result reply, final String tag, final String message, final Object response) {
37-
runOnMainThread(new Runnable() {
38-
@Override
39-
public void run() {
40-
reply.error(tag, message, response);
41-
}
42-
});
43-
}
29+
/**
30+
* MethodChannel class is home to error() method used by Result class
31+
* It has the @UiThread annotation and must be run on UI thread, otherwise a RuntimeException will be thrown
32+
* This will communicate error back to Dart
33+
*/
34+
void replyError(final MethodChannel.Result reply, final String tag, final String message, final Object response) {
35+
runOnMainThread(new Runnable() {
36+
@Override
37+
public void run() {
38+
reply.error(tag, message, response);
39+
}
40+
});
41+
}
4442

45-
/**
46-
* MethodChannel class is home to notImplemented() method used by Result class
47-
* It has the @UiThread annotation and must be run on UI thread, otherwise a RuntimeException will be thrown
48-
* This will communicate not implemented back to Dart
49-
*/
50-
void replyNotImplemented(final MethodChannel.Result reply) {
51-
runOnMainThread(new Runnable() {
52-
@Override
53-
public void run() {
54-
reply.notImplemented();
55-
}
56-
});
57-
}
43+
/**
44+
* MethodChannel class is home to notImplemented() method used by Result class
45+
* It has the @UiThread annotation and must be run on UI thread, otherwise a RuntimeException will be thrown
46+
* This will communicate not implemented back to Dart
47+
*/
48+
void replyNotImplemented(final MethodChannel.Result reply) {
49+
runOnMainThread(new Runnable() {
50+
@Override
51+
public void run() {
52+
reply.notImplemented();
53+
}
54+
});
55+
}
5856

59-
private void runOnMainThread(final Runnable runnable) {
60-
if (Looper.getMainLooper().getThread() == Thread.currentThread())
61-
runnable.run();
62-
else {
63-
Handler handler = new Handler(Looper.getMainLooper());
64-
handler.post(runnable);
65-
}
66-
}
57+
private void runOnMainThread(final Runnable runnable) {
58+
if (Looper.getMainLooper().getThread() == Thread.currentThread()) runnable.run();
59+
else {
60+
Handler handler = new Handler(Looper.getMainLooper());
61+
handler.post(runnable);
62+
}
63+
}
6764

68-
void invokeMethodOnUiThread(final String methodName, final HashMap map) {
69-
//final MethodChannel channel = this.channel;
70-
runOnMainThread(new Runnable() {
71-
@Override
72-
public void run() {
73-
channel.invokeMethod(methodName, map);
74-
}
75-
});
76-
}
65+
void invokeMethodOnUiThread(final String methodName, final HashMap map) {
66+
// final MethodChannel channel = this.channel;
67+
runOnMainThread(new Runnable() {
68+
@Override
69+
public void run() {
70+
channel.invokeMethod(methodName, map);
71+
}
72+
});
73+
}
7774
}

android/src/main/java/com/onesignal/flutter/OneSignalDebug.java

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22

33
import com.onesignal.OneSignal;
44
import com.onesignal.debug.LogLevel;
5-
65
import io.flutter.plugin.common.BinaryMessenger;
76
import io.flutter.plugin.common.MethodCall;
87
import io.flutter.plugin.common.MethodChannel;
98
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
109
import io.flutter.plugin.common.MethodChannel.Result;
1110

1211
public class OneSignalDebug extends FlutterMessengerResponder implements MethodCallHandler {
13-
14-
static void registerWith(BinaryMessenger messenger) {
12+
13+
static void registerWith(BinaryMessenger messenger) {
1514
OneSignalDebug controller = new OneSignalDebug();
1615
controller.messenger = messenger;
1716
controller.channel = new MethodChannel(messenger, "OneSignal#debug");
@@ -20,12 +19,9 @@ static void registerWith(BinaryMessenger messenger) {
2019

2120
@Override
2221
public void onMethodCall(MethodCall call, Result result) {
23-
if (call.method.contentEquals("OneSignal#setLogLevel"))
24-
this.setLogLevel(call, result);
25-
else if (call.method.contentEquals("OneSignal#setAlertLevel"))
26-
this.setAlertLevel(call, result);
27-
else
28-
replyNotImplemented(result);
22+
if (call.method.contentEquals("OneSignal#setLogLevel")) this.setLogLevel(call, result);
23+
else if (call.method.contentEquals("OneSignal#setAlertLevel")) this.setAlertLevel(call, result);
24+
else replyNotImplemented(result);
2925
}
3026

3127
private void setLogLevel(MethodCall call, Result reply) {
@@ -34,21 +30,19 @@ private void setLogLevel(MethodCall call, Result reply) {
3430
LogLevel consoleLogLevel = LogLevel.fromInt(console);
3531
OneSignal.getDebug().setLogLevel(consoleLogLevel);
3632
replySuccess(reply, null);
37-
}
38-
catch(ClassCastException e) {
33+
} catch (ClassCastException e) {
3934
replyError(reply, "OneSignal", "failed with error: " + e.getMessage() + "\n" + e.getStackTrace(), null);
40-
}
35+
}
4136
}
4237

43-
private void setAlertLevel(MethodCall call, Result reply) {
38+
private void setAlertLevel(MethodCall call, Result reply) {
4439
try {
4540
int visual = call.argument("visualLevel");
4641
LogLevel visualLogLevel = LogLevel.fromInt(visual);
4742
OneSignal.getDebug().setAlertLevel(visualLogLevel);
4843
replySuccess(reply, null);
49-
}
50-
catch(ClassCastException e) {
44+
} catch (ClassCastException e) {
5145
replyError(reply, "OneSignal", "failed with error: " + e.getMessage() + "\n" + e.getStackTrace(), null);
52-
}
46+
}
5347
}
5448
}

android/src/main/java/com/onesignal/flutter/OneSignalInAppMessages.java

Lines changed: 65 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,45 @@
22

33
import com.onesignal.OneSignal;
44
import com.onesignal.debug.internal.logging.Logging;
5-
import org.json.JSONException;
6-
7-
import com.onesignal.inAppMessages.IInAppMessageClickListener;
85
import com.onesignal.inAppMessages.IInAppMessageClickEvent;
9-
import com.onesignal.inAppMessages.IInAppMessageLifecycleListener;
10-
import com.onesignal.inAppMessages.IInAppMessageWillDisplayEvent;
6+
import com.onesignal.inAppMessages.IInAppMessageClickListener;
7+
import com.onesignal.inAppMessages.IInAppMessageDidDismissEvent;
118
import com.onesignal.inAppMessages.IInAppMessageDidDisplayEvent;
9+
import com.onesignal.inAppMessages.IInAppMessageLifecycleListener;
1210
import com.onesignal.inAppMessages.IInAppMessageWillDismissEvent;
13-
import com.onesignal.inAppMessages.IInAppMessageDidDismissEvent;
14-
import java.util.Collection;
15-
import java.util.Map;
16-
11+
import com.onesignal.inAppMessages.IInAppMessageWillDisplayEvent;
1712
import io.flutter.plugin.common.BinaryMessenger;
1813
import io.flutter.plugin.common.MethodCall;
1914
import io.flutter.plugin.common.MethodChannel;
2015
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
2116
import io.flutter.plugin.common.MethodChannel.Result;
17+
import java.util.Collection;
18+
import java.util.Map;
19+
import org.json.JSONException;
2220

23-
public class OneSignalInAppMessages extends FlutterMessengerResponder implements MethodCallHandler,
24-
IInAppMessageClickListener, IInAppMessageLifecycleListener{
21+
public class OneSignalInAppMessages extends FlutterMessengerResponder
22+
implements MethodCallHandler, IInAppMessageClickListener, IInAppMessageLifecycleListener {
2523

2624
static void registerWith(BinaryMessenger messenger) {
2725
OneSignalInAppMessages sharedInstance = new OneSignalInAppMessages();
2826

2927
sharedInstance.messenger = messenger;
3028
sharedInstance.channel = new MethodChannel(messenger, "OneSignal#inappmessages");
31-
sharedInstance.channel.setMethodCallHandler(sharedInstance);
29+
sharedInstance.channel.setMethodCallHandler(sharedInstance);
3230
}
3331

3432
@Override
3533
public void onMethodCall(MethodCall call, Result result) {
36-
if (call.method.contentEquals("OneSignal#addTrigger"))
37-
this.addTriggers(call, result);
38-
else if (call.method.contentEquals("OneSignal#addTriggers"))
39-
this.addTriggers(call, result);
40-
else if (call.method.contentEquals("OneSignal#removeTrigger"))
41-
this.removeTrigger(call, result);
42-
else if (call.method.contentEquals("OneSignal#removeTriggers"))
43-
this.removeTriggers(call, result);
44-
else if (call.method.contentEquals("OneSignal#clearTriggers"))
45-
this.clearTriggers(call, result);
34+
if (call.method.contentEquals("OneSignal#addTrigger")) this.addTriggers(call, result);
35+
else if (call.method.contentEquals("OneSignal#addTriggers")) this.addTriggers(call, result);
36+
else if (call.method.contentEquals("OneSignal#removeTrigger")) this.removeTrigger(call, result);
37+
else if (call.method.contentEquals("OneSignal#removeTriggers")) this.removeTriggers(call, result);
38+
else if (call.method.contentEquals("OneSignal#clearTriggers")) this.clearTriggers(call, result);
4639
else if (call.method.contentEquals("OneSignal#arePaused"))
4740
replySuccess(result, OneSignal.getInAppMessages().getPaused());
48-
else if (call.method.contentEquals("OneSignal#paused"))
49-
this.paused(call, result);
50-
else if (call.method.contentEquals("OneSignal#lifecycleInit"))
51-
this.lifecycleInit(result);
52-
else
53-
replyNotImplemented(result);
41+
else if (call.method.contentEquals("OneSignal#paused")) this.paused(call, result);
42+
else if (call.method.contentEquals("OneSignal#lifecycleInit")) this.lifecycleInit(result);
43+
else replyNotImplemented(result);
5444
}
5545

5646
private void addTriggers(MethodCall call, Result result) {
@@ -60,7 +50,11 @@ private void addTriggers(MethodCall call, Result result) {
6050
OneSignal.getInAppMessages().addTriggers((Map<String, String>) call.arguments);
6151
replySuccess(result, null);
6252
} catch (ClassCastException e) {
63-
replyError(result, "OneSignal", "Add triggers failed with error: " + e.getMessage() + "\n" + e.getStackTrace(), null);
53+
replyError(
54+
result,
55+
"OneSignal",
56+
"Add triggers failed with error: " + e.getMessage() + "\n" + e.getStackTrace(),
57+
null);
6458
}
6559
}
6660

@@ -76,7 +70,11 @@ private void removeTriggers(MethodCall call, Result result) {
7670
OneSignal.getInAppMessages().removeTriggers((Collection<String>) call.arguments);
7771
replySuccess(result, null);
7872
} catch (ClassCastException e) {
79-
replyError(result, "OneSignal", "Remove triggers for keys failed with error: " + e.getMessage() + "\n" + e.getStackTrace(), null);
73+
replyError(
74+
result,
75+
"OneSignal",
76+
"Remove triggers for keys failed with error: " + e.getMessage() + "\n" + e.getStackTrace(),
77+
null);
8078
}
8179
}
8280

@@ -99,56 +97,74 @@ public void lifecycleInit(Result result) {
9997
@Override
10098
public void onClick(IInAppMessageClickEvent event) {
10199
try {
102-
invokeMethodOnUiThread("OneSignal#onClickInAppMessage", OneSignalSerializer.convertInAppMessageClickEventToMap(event));
100+
invokeMethodOnUiThread(
101+
"OneSignal#onClickInAppMessage", OneSignalSerializer.convertInAppMessageClickEventToMap(event));
103102
} catch (JSONException e) {
104103
e.getStackTrace();
105-
Logging.error("Encountered an error attempting to convert IInAppMessageClickEvent object to hash map:" + e.toString(), null);
106-
}
104+
Logging.error(
105+
"Encountered an error attempting to convert IInAppMessageClickEvent object to hash map:"
106+
+ e.toString(),
107+
null);
108+
}
107109
}
108110

109111
@Override
110-
public void onWillDisplay(IInAppMessageWillDisplayEvent event) {
112+
public void onWillDisplay(IInAppMessageWillDisplayEvent event) {
111113
try {
112-
invokeMethodOnUiThread("OneSignal#onWillDisplayInAppMessage",
113-
OneSignalSerializer.convertInAppMessageWillDisplayEventToMap(event));
114+
invokeMethodOnUiThread(
115+
"OneSignal#onWillDisplayInAppMessage",
116+
OneSignalSerializer.convertInAppMessageWillDisplayEventToMap(event));
114117
} catch (JSONException e) {
115118
e.getStackTrace();
116-
Logging.error("Encountered an error attempting to convert IInAppMessageWillDisplayEvent object to hash map:" + e.toString(), null);
117-
}
118-
119+
Logging.error(
120+
"Encountered an error attempting to convert IInAppMessageWillDisplayEvent object to hash map:"
121+
+ e.toString(),
122+
null);
123+
}
119124
}
120125

121126
@Override
122127
public void onDidDisplay(IInAppMessageDidDisplayEvent event) {
123128
try {
124-
invokeMethodOnUiThread("OneSignal#onDidDisplayInAppMessage",
125-
OneSignalSerializer.convertInAppMessageDidDisplayEventToMap(event));
129+
invokeMethodOnUiThread(
130+
"OneSignal#onDidDisplayInAppMessage",
131+
OneSignalSerializer.convertInAppMessageDidDisplayEventToMap(event));
126132
} catch (JSONException e) {
127133
e.getStackTrace();
128-
Logging.error("Encountered an error attempting to convert IInAppMessageDidDisplayEvent object to hash map:" + e.toString(), null);
134+
Logging.error(
135+
"Encountered an error attempting to convert IInAppMessageDidDisplayEvent object to hash map:"
136+
+ e.toString(),
137+
null);
129138
}
130139
}
131140

132141
@Override
133142
public void onWillDismiss(IInAppMessageWillDismissEvent event) {
134143
try {
135-
invokeMethodOnUiThread("OneSignal#onWillDismissInAppMessage",
136-
OneSignalSerializer.convertInAppMessageWillDismissEventToMap(event));
144+
invokeMethodOnUiThread(
145+
"OneSignal#onWillDismissInAppMessage",
146+
OneSignalSerializer.convertInAppMessageWillDismissEventToMap(event));
137147
} catch (JSONException e) {
138148
e.getStackTrace();
139-
Logging.error("Encountered an error attempting to convert IInAppMessageWillDismissEvent object to hash map:" + e.toString(), null);
149+
Logging.error(
150+
"Encountered an error attempting to convert IInAppMessageWillDismissEvent object to hash map:"
151+
+ e.toString(),
152+
null);
140153
}
141154
}
142155

143156
@Override
144157
public void onDidDismiss(IInAppMessageDidDismissEvent event) {
145158
try {
146-
invokeMethodOnUiThread("OneSignal#onDidDismissInAppMessage",
147-
OneSignalSerializer.convertInAppMessageDidDismissEventToMap(event));
159+
invokeMethodOnUiThread(
160+
"OneSignal#onDidDismissInAppMessage",
161+
OneSignalSerializer.convertInAppMessageDidDismissEventToMap(event));
148162
} catch (JSONException e) {
149163
e.getStackTrace();
150-
Logging.error("Encountered an error attempting to convert IInAppMessageDidDismissEvent object to hash map:" + e.toString(), null);
164+
Logging.error(
165+
"Encountered an error attempting to convert IInAppMessageDidDismissEvent object to hash map:"
166+
+ e.toString(),
167+
null);
151168
}
152-
153169
}
154170
}

0 commit comments

Comments
 (0)