-
-
Notifications
You must be signed in to change notification settings - Fork 35
Extract Android implementation to separate folder #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mvanbeusekom
merged 23 commits into
Baseflow:main
from
JeroenWeener:enhancement/platform-android
Mar 13, 2023
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
968563c
Move Android code to separate folder
JeroenWeener 556a6b4
Copy gradle-wrapper.properties
JeroenWeener cb85f4a
Register Android implementation in pubspec.yaml
JeroenWeener 6d17da1
Update pubspec.yaml
JeroenWeener 3b1dcdc
Add missing newline to `build.gradle`
JeroenWeener 8f4ffe1
Configure CI to run on stable Flutter version
mvanbeusekom df9c316
Revert "Add platform interface"
mvanbeusekom ef76bcf
Move app-facing code to separate folder
JeroenWeener 7959f39
Revert "Merge pull request #35 from Baseflow/revert-34-enhancement/pl...
JeroenWeener 61d77a6
Update CONTRIBUTING.md
JeroenWeener aecc12e
Move `analysis_options.yaml` to root folder
JeroenWeener d59ea45
Move Android code to separate folder
JeroenWeener cf0435b
Copy gradle-wrapper.properties
JeroenWeener 3b2e58e
Register Android implementation in pubspec.yaml
JeroenWeener de46616
Update pubspec.yaml
JeroenWeener d2b8639
Update build.gradle
JeroenWeener bfe99c4
Merge remote-tracking branch 'upstream/main' into enhancement/platfor...
JeroenWeener 2ba97a8
Merge branch 'enhancement/platform-android' of github.com:jeroenweene...
JeroenWeener af356b4
Remove `example-directory` from google_api_availability_android.yaml
JeroenWeener 029c540
Update google_api_availability_android.yaml
JeroenWeener fe69b63
Update google_api_availability.yaml
JeroenWeener ed948fb
Bump `actions/checkout` and `subosito/flutter-action` versions
JeroenWeener bcc4256
Update google_api_availability.yaml
JeroenWeener File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
5 changes: 5 additions & 0 deletions
google_api_availability/android/gradle/wrapper/gradle-wrapper.properties
This file contains hidden or 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,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
3 changes: 3 additions & 0 deletions
google_api_availability_android/CHANGELOG.md
This file contains hidden or 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,3 @@ | ||
## 1.0.0 | ||
|
||
* Extracts the Android platform implementation from the google_api_availability package. |
21 changes: 21 additions & 0 deletions
google_api_availability_android/LICENSE
This file contains hidden or 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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Baseflow | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
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. |
26 changes: 26 additions & 0 deletions
google_api_availability_android/README.md
This file contains hidden or 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,26 @@ | ||
# google_api_availability_android | ||
|
||
[](https://pub.dev/packages/flutter_lints) | ||
|
||
The official Android implementation of the [`google_api_availability`][1] plugin by Baseflow. | ||
|
||
## Usage | ||
|
||
This plugin is not yet in use, but will become the endorsed Android implementation later, once `google_api_availability` is updated. | ||
More detailed instructions on using the API can be found in the [README.md][3] of the [`google_api_availability`][1] package. | ||
|
||
## Issues | ||
|
||
Please file any issues, bugs or feature requests as an issue on our [GitHub](https://github.com/Baseflow/flutter-google-api-availability/issues) page. Commercial support is available, you can contact us at <hello@baseflow.com>. | ||
|
||
## Want to contribute | ||
|
||
If you would like to contribute to the plugin (e.g. by improving the documentation, solving a bug or adding a cool new feature), please carefully review our [contribution guide](../CONTRIBUTING.md) and send us your [pull request](https://github.com/Baseflow/flutter-google-api-availability/pulls). | ||
|
||
## Author | ||
|
||
This Google API Availability plugin for Flutter is developed by [Baseflow](https://baseflow.com). | ||
|
||
[1]: ../google_api_availability | ||
[2]: lib/google_api_availability_platform_interface.dart | ||
[3]: ../README.md |
10 changes: 10 additions & 0 deletions
google_api_availability_android/analysis_options.yaml
This file contains hidden or 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,10 @@ | ||
include: package:flutter_lints/flutter.yaml | ||
|
||
analyzer: | ||
exclude: | ||
# Ignore generated files | ||
- '**/*.g.dart' | ||
- 'lib/src/generated/*.dart' | ||
linter: | ||
rules: | ||
- public_member_api_docs |
44 changes: 44 additions & 0 deletions
google_api_availability_android/android/build.gradle
This file contains hidden or 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,44 @@ | ||
group 'com.baseflow.googleapiavailability' | ||
version '1.0-SNAPSHOT' | ||
|
||
buildscript { | ||
repositories { | ||
google() | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
classpath 'com.android.tools.build:gradle:4.1.0' | ||
} | ||
} | ||
|
||
rootProject.allprojects { | ||
repositories { | ||
google() | ||
mavenCentral() | ||
} | ||
} | ||
|
||
apply plugin: 'com.android.library' | ||
|
||
android { | ||
compileSdkVersion 31 | ||
|
||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
|
||
defaultConfig { | ||
minSdkVersion 16 | ||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
lintOptions { | ||
disable 'InvalidPackage' | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation 'com.google.android.gms:play-services-base:18.1.0' | ||
implementation 'androidx.annotation:annotation:1.1.0' | ||
} |
5 changes: 5 additions & 0 deletions
google_api_availability_android/android/gradle/wrapper/gradle-wrapper.properties
This file contains hidden or 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,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
1 change: 1 addition & 0 deletions
google_api_availability_android/android/settings.gradle
This file contains hidden or 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 @@ | ||
rootProject.name = 'google_api_availability' |
3 changes: 3 additions & 0 deletions
google_api_availability_android/android/src/main/AndroidManifest.xml
This file contains hidden or 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,3 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.baseflow.googleapiavailability"> | ||
</manifest> |
59 changes: 59 additions & 0 deletions
...roid/src/main/java/com/baseflow/googleapiavailability/GoogleApiAvailabilityConstants.java
This file contains hidden or 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,59 @@ | ||
package com.baseflow.googleapiavailability; | ||
|
||
import androidx.annotation.IntDef; | ||
|
||
import com.google.android.gms.common.ConnectionResult; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
final class GoogleApiAvailabilityConstants { | ||
static final String LOG_TAG = "google_api_availability"; | ||
|
||
static final int REQUEST_GOOGLE_PLAY_SERVICES = 1000; | ||
|
||
//GOOGLE_PLAY_SERVICES_AVAILABILITY | ||
static final int GOOGLE_PLAY_SERVICES_AVAILABILITY_SUCCESS = 0; | ||
static final int GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_MISSING = 1; | ||
static final int GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_UPDATING = 2; | ||
static final int GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_VERSION_UPDATE_REQUIRED = 3; | ||
static final int GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_DISABLED = 4; | ||
static final int GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_INVALID = 5; | ||
static final int GOOGLE_PLAY_SERVICES_AVAILABILITY_NOT_AVAILABLE_ON_PLATFORM = 6; | ||
static final int GOOGLE_PLAY_SERVICES_AVAILABILITY_UNKNOWN = 7; | ||
|
||
|
||
@Retention(RetentionPolicy.SOURCE) | ||
@IntDef({ | ||
GOOGLE_PLAY_SERVICES_AVAILABILITY_SUCCESS, | ||
GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_MISSING, | ||
GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_UPDATING, | ||
GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_VERSION_UPDATE_REQUIRED, | ||
GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_DISABLED, | ||
GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_INVALID, | ||
GOOGLE_PLAY_SERVICES_AVAILABILITY_NOT_AVAILABLE_ON_PLATFORM, | ||
GOOGLE_PLAY_SERVICES_AVAILABILITY_UNKNOWN, | ||
}) | ||
@interface GooglePlayServicesAvailability { | ||
} | ||
|
||
@GooglePlayServicesAvailability | ||
static int toPlayServiceAvailability(int connectionResult) { | ||
switch (connectionResult) { | ||
case ConnectionResult.SUCCESS: | ||
return GOOGLE_PLAY_SERVICES_AVAILABILITY_SUCCESS; | ||
case ConnectionResult.SERVICE_MISSING: | ||
return GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_MISSING; | ||
case ConnectionResult.SERVICE_UPDATING: | ||
return GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_UPDATING; | ||
case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED: | ||
return GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_VERSION_UPDATE_REQUIRED; | ||
case ConnectionResult.SERVICE_DISABLED: | ||
return GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_DISABLED; | ||
case ConnectionResult.SERVICE_INVALID: | ||
return GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_INVALID; | ||
default: | ||
return GOOGLE_PLAY_SERVICES_AVAILABILITY_UNKNOWN; | ||
} | ||
} | ||
} |
149 changes: 149 additions & 0 deletions
...ndroid/src/main/java/com/baseflow/googleapiavailability/GoogleApiAvailabilityManager.java
This file contains hidden or 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,149 @@ | ||
package com.baseflow.googleapiavailability; | ||
|
||
import android.app.Activity; | ||
import android.app.Dialog; | ||
import android.app.PendingIntent; | ||
import android.content.Context; | ||
import android.util.Log; | ||
|
||
import com.google.android.gms.common.ConnectionResult; | ||
import com.google.android.gms.common.GoogleApiAvailability; | ||
import com.google.android.gms.tasks.Task; | ||
|
||
import java.util.List; | ||
|
||
public class GoogleApiAvailabilityManager { | ||
|
||
GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance(); | ||
|
||
@FunctionalInterface | ||
interface SuccessCallback { | ||
void onSuccess(int connectionResult); | ||
} | ||
|
||
@FunctionalInterface | ||
interface MakeGooglePlayServicesAvailableCallback { | ||
void onSuccess(Void v); | ||
} | ||
|
||
@FunctionalInterface | ||
interface getErrorStringCallback { | ||
void onSuccess(String errorString); | ||
} | ||
|
||
@FunctionalInterface | ||
interface isUserResolvableCallback { | ||
void onSuccess(boolean isUserResolvable); | ||
} | ||
|
||
@FunctionalInterface | ||
interface showErrorNotificationCallback { | ||
void onSuccess(Void v); | ||
} | ||
|
||
@FunctionalInterface | ||
interface showErrorDialogFragmentCallback { | ||
void onSuccess(boolean showErrorDialogFragmentCallback); | ||
} | ||
|
||
@FunctionalInterface | ||
interface ErrorCallback { | ||
void onError(String errorCode, String errorDescription); | ||
} | ||
|
||
void checkPlayServicesAvailability(Boolean showDialog, Activity activity, Context applicationContext, SuccessCallback successCallback, ErrorCallback errorCallback) { | ||
if (applicationContext == null) { | ||
Log.e(GoogleApiAvailabilityConstants.LOG_TAG, "The `ApplicationContext` cannot be null."); | ||
errorCallback.onError("GoogleApiAvailability.GoogleApiAvailabilityManager", "Android `ApplicationContext` cannot be null."); | ||
return; | ||
} | ||
|
||
final int connectionResult = googleApiAvailability | ||
.isGooglePlayServicesAvailable(applicationContext); | ||
|
||
if (activity == null) { | ||
if (showDialog != null && showDialog) { | ||
// Only log warning when `showDialog` property was `true`. | ||
Log.w(GoogleApiAvailabilityConstants.LOG_TAG, "Unable to show dialog as `Activity` is not available."); | ||
} | ||
showDialog = false; | ||
} | ||
|
||
if (showDialog != null && showDialog) { | ||
googleApiAvailability | ||
.showErrorDialogFragment(activity, connectionResult, GoogleApiAvailabilityConstants.REQUEST_GOOGLE_PLAY_SERVICES); | ||
} | ||
|
||
successCallback.onSuccess(GoogleApiAvailabilityConstants.toPlayServiceAvailability(connectionResult)); | ||
} | ||
|
||
void makeGooglePlayServicesAvailable(Activity activity, MakeGooglePlayServicesAvailableCallback successCallback, ErrorCallback errorCallback) { | ||
if (activity == null) { | ||
Log.e(GoogleApiAvailabilityConstants.LOG_TAG, "Activity cannot be null."); | ||
errorCallback.onError("GoogleApiAvailability.makeGooglePlayServicesAvailable", "Android Activity cannot be null."); | ||
return; | ||
} | ||
|
||
googleApiAvailability.makeGooglePlayServicesAvailable(activity) | ||
.addOnFailureListener((Exception e) -> errorCallback.onError("GoogleApiAvailability.makeGooglePlayServicesAvailable", e.getMessage())) | ||
.addOnSuccessListener((Void t) -> successCallback.onSuccess(null)); | ||
} | ||
|
||
void getErrorString(Context applicationContext, getErrorStringCallback successCallback, ErrorCallback errorCallback) { | ||
if (applicationContext == null) { | ||
Log.e(GoogleApiAvailabilityConstants.LOG_TAG, "Context cannot be null."); | ||
errorCallback.onError("GoogleApiAvailability.getErrorString", "Android context cannot be null."); | ||
return; | ||
} | ||
|
||
final String errorString = googleApiAvailability.getErrorString(googleApiAvailability.isGooglePlayServicesAvailable(applicationContext)); | ||
|
||
successCallback.onSuccess(errorString); | ||
} | ||
|
||
void isUserResolvable(Context applicationContext, isUserResolvableCallback successCallback, ErrorCallback errorCallback) { | ||
if (applicationContext == null) { | ||
Log.e(GoogleApiAvailabilityConstants.LOG_TAG, "Context cannot be null."); | ||
errorCallback.onError("GoogleApiAvailability.isUserResolvable", "Android context cannot be null."); | ||
return; | ||
} | ||
|
||
final int connectionResult = googleApiAvailability | ||
.isGooglePlayServicesAvailable(applicationContext); | ||
|
||
successCallback.onSuccess(googleApiAvailability.isUserResolvableError(connectionResult)); | ||
} | ||
|
||
void showErrorNotification(Context applicationContext, showErrorNotificationCallback successCallback, ErrorCallback errorCallback) { | ||
if (applicationContext == null) { | ||
Log.e(GoogleApiAvailabilityConstants.LOG_TAG, "Context cannot be null."); | ||
errorCallback.onError("GoogleApiAvailability.showErrorNotification", "Android context cannot be null."); | ||
return; | ||
} | ||
|
||
final int connectionResult = googleApiAvailability | ||
.isGooglePlayServicesAvailable(applicationContext); | ||
|
||
googleApiAvailability.showErrorNotification(applicationContext, connectionResult); | ||
|
||
successCallback.onSuccess(null); | ||
} | ||
|
||
void showErrorDialogFragment(Context applicationContext, Activity activity, showErrorDialogFragmentCallback successCallback, ErrorCallback errorCallback) { | ||
if (applicationContext == null) { | ||
Log.e(GoogleApiAvailabilityConstants.LOG_TAG, "Context cannot be null."); | ||
errorCallback.onError("GoogleApiAvailability.showErrorDialogFragment", "Android context cannot be null."); | ||
return; | ||
} | ||
|
||
final int errorCode = googleApiAvailability | ||
.isGooglePlayServicesAvailable(applicationContext); | ||
|
||
if (errorCode != GoogleApiAvailabilityConstants.GOOGLE_PLAY_SERVICES_AVAILABILITY_SUCCESS) { | ||
googleApiAvailability.showErrorDialogFragment(activity, errorCode, GoogleApiAvailabilityConstants.REQUEST_GOOGLE_PLAY_SERVICES); | ||
successCallback.onSuccess(true); | ||
} | ||
|
||
successCallback.onSuccess(false); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.