Skip to content

Commit d132aa7

Browse files
committed
Method Call Setup
1 parent 4ce536d commit d132aa7

File tree

14 files changed

+225
-24
lines changed

14 files changed

+225
-24
lines changed

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

+36-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

android/.idea/.gitignore

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

android/.idea/.name

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
491 Bytes
Binary file not shown.

android/.idea/compiler.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

android/.idea/gradle.xml

+20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

android/.idea/jarRepositories.xml

+25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

android/.idea/misc.xml

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

android/.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

android/.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,76 @@
11
package com.hackthedeveloper.live_icon;
22

3+
import android.app.Activity;
4+
import android.content.Context;
5+
36
import androidx.annotation.NonNull;
47

58
import io.flutter.embedding.engine.plugins.FlutterPlugin;
6-
import io.flutter.plugin.common.MethodCall;
9+
import io.flutter.embedding.engine.plugins.activity.ActivityAware;
10+
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
11+
import io.flutter.plugin.common.BinaryMessenger;
712
import io.flutter.plugin.common.MethodChannel;
8-
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
9-
import io.flutter.plugin.common.MethodChannel.Result;
10-
import io.flutter.plugin.common.PluginRegistry.Registrar;
11-
12-
/** LiveIconPlugin */
13-
public class LiveIconPlugin implements FlutterPlugin, MethodCallHandler {
14-
/// The MethodChannel that will the communication between Flutter and native Android
15-
///
16-
/// This local reference serves to register the plugin with the Flutter Engine and unregister it
17-
/// when the Flutter Engine is detached from the Activity
13+
14+
public class LiveIconPlugin implements FlutterPlugin, ActivityAware {
15+
private static final String CHANNEL_ID = "com.hackthedeveloper.live_icon";
16+
private static final String TAG = "[Flutter Shortcuts]";
17+
18+
public static String getTAG() {
19+
return TAG;
20+
}
21+
22+
public static String getChannelId() {
23+
return CHANNEL_ID;
24+
}
25+
1826
private MethodChannel channel;
27+
private MethodCallImplementation handler;
1928

20-
@Override
21-
public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
22-
channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "live_icon");
23-
channel.setMethodCallHandler(this);
29+
@SuppressWarnings("deprecation")
30+
public static void registerWith(io.flutter.plugin.common.PluginRegistry.Registrar registrar) {
31+
final LiveIconPlugin plugin = new LiveIconPlugin();
32+
plugin.setupChannel(registrar.messenger(), registrar.context(), registrar.activity());
2433
}
2534

2635
@Override
27-
public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
28-
if (call.method.equals("getPlatformVersion")) {
29-
result.success("Android " + android.os.Build.VERSION.RELEASE);
30-
} else {
31-
result.notImplemented();
32-
}
36+
public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
37+
setupChannel(binding.getBinaryMessenger(), binding.getApplicationContext(), null);
3338
}
3439

3540
@Override
3641
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
42+
teardownChannel();
43+
}
44+
45+
@Override
46+
public void onAttachedToActivity(@NonNull ActivityPluginBinding binding) {
47+
handler.setActivity(binding.getActivity());
48+
}
49+
50+
@Override
51+
public void onDetachedFromActivity() {
52+
handler.setActivity(null);
53+
}
54+
55+
@Override
56+
public void onReattachedToActivityForConfigChanges(@NonNull ActivityPluginBinding binding) {
57+
onAttachedToActivity(binding);
58+
}
59+
60+
@Override
61+
public void onDetachedFromActivityForConfigChanges() {
62+
onDetachedFromActivity();
63+
}
64+
65+
private void setupChannel(BinaryMessenger messenger, Context context, Activity activity) {
66+
channel = new MethodChannel(messenger, CHANNEL_ID);
67+
handler = new MethodCallImplementation(context, activity);
68+
channel.setMethodCallHandler(handler);
69+
}
70+
71+
private void teardownChannel() {
3772
channel.setMethodCallHandler(null);
73+
channel = null;
74+
handler = null;
3875
}
39-
}
76+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.hackthedeveloper.live_icon;
2+
3+
import android.app.Activity;
4+
import android.content.Context;
5+
6+
import androidx.annotation.NonNull;
7+
import java.util.List;
8+
import java.util.Map;
9+
import io.flutter.plugin.common.MethodCall;
10+
import io.flutter.plugin.common.MethodChannel;
11+
12+
public class MethodCallImplementation implements MethodChannel.MethodCallHandler {
13+
private static final String TAG = LiveIconPlugin.getTAG();
14+
15+
private final Context context;
16+
private Activity activity;
17+
18+
19+
MethodCallImplementation(Context context, Activity activity) {
20+
this.context = context;
21+
this.activity = activity;
22+
}
23+
24+
void setActivity(Activity activity) {
25+
this.activity = activity;
26+
}
27+
28+
@Override
29+
public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
30+
31+
switch (call.method) {
32+
case "initialize":
33+
initialize(call);
34+
break;
35+
default:
36+
result.notImplemented();
37+
break;
38+
}
39+
}
40+
41+
private void initialize(MethodCall call) {
42+
List<Map<String, String>> args = call.arguments();
43+
final int numberOfIcons = args.size();
44+
}
45+
}

example/android/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
}
66

77
dependencies {
8-
classpath 'com.android.tools.build:gradle:4.1.0'
8+
classpath 'com.android.tools.build:gradle:4.1.3'
99
}
1010
}
1111

0 commit comments

Comments
 (0)