Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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
Show file tree
Hide file tree
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 Mar 9, 2023
556a6b4
Copy gradle-wrapper.properties
JeroenWeener Mar 10, 2023
cb85f4a
Register Android implementation in pubspec.yaml
JeroenWeener Mar 10, 2023
6d17da1
Update pubspec.yaml
JeroenWeener Mar 10, 2023
3b1dcdc
Add missing newline to `build.gradle`
JeroenWeener Mar 13, 2023
8f4ffe1
Configure CI to run on stable Flutter version
mvanbeusekom Mar 9, 2023
df9c316
Revert "Add platform interface"
mvanbeusekom Mar 9, 2023
ef76bcf
Move app-facing code to separate folder
JeroenWeener Mar 9, 2023
7959f39
Revert "Merge pull request #35 from Baseflow/revert-34-enhancement/pl...
JeroenWeener Mar 9, 2023
61d77a6
Update CONTRIBUTING.md
JeroenWeener Mar 9, 2023
aecc12e
Move `analysis_options.yaml` to root folder
JeroenWeener Mar 10, 2023
d59ea45
Move Android code to separate folder
JeroenWeener Mar 9, 2023
cf0435b
Copy gradle-wrapper.properties
JeroenWeener Mar 10, 2023
3b2e58e
Register Android implementation in pubspec.yaml
JeroenWeener Mar 10, 2023
de46616
Update pubspec.yaml
JeroenWeener Mar 10, 2023
d2b8639
Update build.gradle
JeroenWeener Mar 13, 2023
bfe99c4
Merge remote-tracking branch 'upstream/main' into enhancement/platfor...
JeroenWeener Mar 13, 2023
2ba97a8
Merge branch 'enhancement/platform-android' of github.com:jeroenweene...
JeroenWeener Mar 13, 2023
af356b4
Remove `example-directory` from google_api_availability_android.yaml
JeroenWeener Mar 13, 2023
029c540
Update google_api_availability_android.yaml
JeroenWeener Mar 13, 2023
fe69b63
Update google_api_availability.yaml
JeroenWeener Mar 13, 2023
ed948fb
Bump `actions/checkout` and `subosito/flutter-action` versions
JeroenWeener Mar 13, 2023
bcc4256
Update google_api_availability.yaml
JeroenWeener Mar 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions .github/workflows/google_api_availability.yaml
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ jobs:
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- uses: actions/checkout@v3

# Make sure the stable version of Flutter is available
- uses: subosito/flutter-action@v1
- uses: subosito/flutter-action@v2
with:
channel: 'stable'

Expand All @@ -53,19 +53,14 @@ jobs:
- name: Run Android build
run: flutter build apk --release
working-directory: ${{env.example-directory}}

# Build iOS version of the example app
- name: Run iOS build
run: flutter build ios --release --no-codesign
working-directory: ${{env.example-directory}}

# Run all unit-tests with code coverage
- name: Run unit tests
run: flutter test --coverage
working-directory: ${{env.source-directory}}

# Upload code coverage information
- uses: codecov/codecov-action@v1
- uses: codecov/codecov-action@v2
with:
file: ${{env.source-directory}}/coverage/lcov.info # optional
name: Google API Availability (App Facing Package) # optional
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/google_api_availability_android.yaml
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:

env:
source-directory: ./google_api_availability_android
example-directory: ./google_api_availability_android/example
example-directory: ./google_api_availability/example

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
Expand Down Expand Up @@ -54,4 +54,3 @@ jobs:
- name: Run Android build
run: flutter build apk --release
working-directory: ${{env.example-directory}}

View file Open in desktop
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
View file Open in desktop
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
View file Open in desktop
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
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# google_api_availability_android

[![style: flutter_lints](https://img.shields.io/badge/style-flutter_lints-40c4ff.svg)](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
View file Open in desktop
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
View file Open in desktop
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'
}
View file Open in desktop
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
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'google_api_availability'
View file Open in desktop
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>
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;
}
}
}
View file Open in desktop
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);
}
}
Loading

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /