Skip to content

Commit 30112c6

Browse files
committed
UPDATE Flutter Site Plugin
1 parent 76df12e commit 30112c6

47 files changed

Lines changed: 4938 additions & 419 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

flutter-hms-location/CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
## 5.0.0+301
1+
## 5.0.0+301
22

3-
* Upgrade HMS Location Android SDK to 5.0.0.301.
3+
* Added the getNavigationContextState function.
4+
* Added the enableLogger and disableLogger methods.
45

56
## 4.0.4+1/4.0.4+300
67

76.9 KB
Loading

flutter-hms-site/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## 5.0.1+300
2+
3+
* Added the **siteSearchActivity** method.
4+
* Added the **SearchIntent** class to start site search activity.
5+
* Added the **SearchFilter** class, which is used in a SearchIntent object as **filter**.
6+
* Added the **streetNumber** attribute in the **AddressDetail** class, which is used for setting or obtaining the street number of a place.
7+
* Added the **HwLocationType** class, which contains constants of Huawei POI types.
8+
* Added the **enableLogger** and **disableLogger** methods.
9+
110
## 4.0.4
211

312
* Initial release.

flutter-hms-site/README.md

Lines changed: 2187 additions & 45 deletions
Large diffs are not rendered by default.

flutter-hms-site/android/build.gradle

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ buildscript {
99
}
1010

1111
dependencies {
12-
classpath 'com.android.tools.build:gradle:3.3.2'
12+
classpath 'com.android.tools.build:gradle:3.6.0'
1313
}
1414
}
1515

@@ -25,15 +25,24 @@ apply plugin: 'com.android.library'
2525

2626
android {
2727
compileSdkVersion 29
28+
buildToolsVersion "29.0.3"
2829

2930
defaultConfig {
3031
minSdkVersion 19
32+
targetSdkVersion 29
33+
}
34+
compileOptions {
35+
sourceCompatibility JavaVersion.VERSION_1_8
36+
targetCompatibility JavaVersion.VERSION_1_8
3137
}
3238
lintOptions {
3339
disable 'InvalidPackage'
3440
}
3541
}
3642

3743
dependencies {
38-
implementation 'com.huawei.hms:site:4.0.3.300'
44+
implementation 'com.huawei.hms:site:5.0.1.300'
45+
implementation 'androidx.appcompat:appcompat:1.2.0'
46+
implementation 'androidx.recyclerview:recyclerview:1.1.0'
47+
implementation "androidx.recyclerview:recyclerview-selection:1.0.0"
3948
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

flutter-hms-site/android/gradlew

Lines changed: 31 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flutter-hms-site/android/gradlew.bat

Lines changed: 20 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
22
package="com.huawei.hms.flutter.site">
3+
4+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
35
</manifest>

flutter-hms-site/android/src/main/java/com/huawei/hms/flutter/site/SitePlugin.java

Lines changed: 64 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,53 +16,93 @@
1616

1717
package com.huawei.hms.flutter.site;
1818

19+
import android.app.Activity;
1920
import android.content.Context;
2021
import android.net.Uri;
22+
2123
import androidx.annotation.NonNull;
24+
2225
import com.huawei.agconnect.config.AGConnectServicesConfig;
23-
import com.huawei.hms.flutter.site.handlers.MethodCallHandlerImpl;
26+
import com.huawei.hms.flutter.site.constants.Channel;
27+
import com.huawei.hms.flutter.site.handlers.ActivityAwareMethodCallHandlerImpl;
2428
import com.huawei.hms.site.api.SearchService;
2529
import com.huawei.hms.site.api.SearchServiceFactory;
2630

27-
import com.google.gson.Gson;
28-
2931
import io.flutter.embedding.engine.plugins.FlutterPlugin;
32+
import io.flutter.embedding.engine.plugins.activity.ActivityAware;
33+
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
3034
import io.flutter.plugin.common.BinaryMessenger;
3135
import io.flutter.plugin.common.MethodChannel;
3236
import io.flutter.plugin.common.PluginRegistry.Registrar;
3337

34-
public class SitePlugin implements FlutterPlugin {
35-
private Gson mGson;
36-
private MethodChannel mMethodChannel;
37-
private SearchService mSearchService;
38-
private MethodChannel.MethodCallHandler mMethodCallHandler;
38+
public class SitePlugin implements FlutterPlugin, ActivityAware {
39+
private SearchService searchService;
40+
private MethodChannel methodChannel;
41+
private ActivityAwareMethodCallHandlerImpl methodCallHandler;
3942

40-
public static void registerWith(Registrar registrar) {
43+
public static void registerWith(final Registrar registrar) {
4144
final SitePlugin instance = new SitePlugin();
45+
final Activity activity = registrar.activity();
46+
final Context context = registrar.context();
47+
48+
// When context is available
49+
// searchService and methodChannel are instantiated
4250
instance.onAttachedToEngine(registrar.context(), registrar.messenger());
51+
52+
// When activity is available
53+
// methodCallHandler is instantiated
54+
instance.methodCallHandler = new ActivityAwareMethodCallHandlerImpl(activity, instance.searchService,
55+
instance.getApiKey(context));
56+
instance.methodChannel.setMethodCallHandler(instance.methodCallHandler);
57+
}
58+
59+
private String getApiKey(Context context) {
60+
final String rawApiKey = AGConnectServicesConfig.fromContext(context).getString("client/api_key");
61+
return Uri.encode(rawApiKey);
62+
}
63+
64+
private void onAttachedToEngine(final Context context, final BinaryMessenger messenger) {
65+
searchService = SearchServiceFactory.create(context, getApiKey(context));
66+
methodChannel = new MethodChannel(messenger, Channel.METHOD_SEARCH_SERVICE);
67+
}
68+
69+
private void onDetachedFromEngine() {
70+
searchService = null;
71+
methodChannel = null;
4372
}
4473

4574
@Override
46-
public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
75+
public void onAttachedToEngine(@NonNull final FlutterPluginBinding binding) {
4776
onAttachedToEngine(binding.getApplicationContext(), binding.getBinaryMessenger());
4877
}
4978

5079
@Override
51-
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
52-
mMethodChannel.setMethodCallHandler(null);
53-
mMethodCallHandler = null;
54-
mMethodChannel = null;
55-
mSearchService = null;
56-
mGson = null;
80+
public void onDetachedFromEngine(@NonNull final FlutterPluginBinding binding) {
81+
onDetachedFromEngine();
5782
}
5883

59-
private void onAttachedToEngine(Context context, BinaryMessenger messenger) {
60-
final String apiKey = AGConnectServicesConfig.fromContext(context).getString("client/api_key");
61-
final String encodedApiKey = Uri.encode(apiKey);
62-
mGson = new Gson();
63-
mSearchService = SearchServiceFactory.create(context, encodedApiKey);
64-
mMethodChannel = new MethodChannel(messenger, "com.huawei.hms.flutter.site/method");
65-
mMethodCallHandler = new MethodCallHandlerImpl(mSearchService, mGson);
66-
mMethodChannel.setMethodCallHandler(mMethodCallHandler);
84+
@Override
85+
public void onAttachedToActivity(@NonNull final ActivityPluginBinding binding) {
86+
final Activity activity = binding.getActivity();
87+
methodCallHandler = new ActivityAwareMethodCallHandlerImpl(activity, searchService,
88+
getApiKey(activity.getApplicationContext()));
89+
methodChannel.setMethodCallHandler(methodCallHandler);
90+
binding.addActivityResultListener(methodCallHandler);
91+
}
92+
93+
@Override
94+
public void onDetachedFromActivityForConfigChanges() {
95+
onDetachedFromActivity();
96+
}
97+
98+
@Override
99+
public void onReattachedToActivityForConfigChanges(@NonNull final ActivityPluginBinding binding) {
100+
onAttachedToActivity(binding);
101+
}
102+
103+
@Override
104+
public void onDetachedFromActivity() {
105+
methodChannel.setMethodCallHandler(null);
106+
methodCallHandler = null;
67107
}
68108
}

0 commit comments

Comments
 (0)