Skip to content

Commit

Permalink
Updated Android plugin code to remove deprecation warning
Browse files Browse the repository at this point in the history
  • Loading branch information
magnatronus committed Oct 3, 2021
1 parent 9ae8ade commit 59cb6d9
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 29 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.5.0 - 03 Oct 2021

* Update Android code to remove deprecation warning

## 0.4.3 - 15 Sept 2021

* removed debug print statement
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ Since GNU/Linux and POSIX doesn't provide a standard API for getting the preferr

## Updates

### Oct 2021
Updated the code and APIs used by Flutter for an Android plugin - this was the source of the Deprecated API warning in the Android build.

### July 2021
Add beta support for Linux

Expand Down
9 changes: 9 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ rootProject.allprojects {
google()
jcenter()
}

/*
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:deprecation"
}
}
*/

}

apply plugin: 'com.android.library'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.example.devicelocale;

import androidx.annotation.NonNull;
import androidx.core.os.LocaleListCompat;

import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.PluginRegistry.Registrar;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.plugin.common.BinaryMessenger;

import androidx.core.os.LocaleListCompat;
import android.content.Context;
import android.content.ContextWrapper;
import java.util.ArrayList;
Expand All @@ -20,36 +20,19 @@
*/
public class DevicelocalePlugin implements MethodCallHandler, FlutterPlugin {

private Context applicationContext;
private MethodChannel methodChannel;

/**
* Plugin registration.
*/
public static void registerWith(Registrar registrar) {
final DevicelocalePlugin instance = new DevicelocalePlugin();
instance.onAttachedToEngine(registrar.context(), registrar.messenger());
}
private MethodChannel channel;

@Override
public void onAttachedToEngine(FlutterPluginBinding binding) {
onAttachedToEngine(binding.getApplicationContext(), binding.getBinaryMessenger());
public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "uk.spiralarm.flutter/devicelocale");
channel.setMethodCallHandler(this);
}

@Override
public void onDetachedFromEngine(FlutterPluginBinding binding) {
applicationContext = null;
methodChannel.setMethodCallHandler(null);
methodChannel = null;
channel.setMethodCallHandler(null);
}

private void onAttachedToEngine(Context applicationContext, BinaryMessenger messenger) {
this.applicationContext = applicationContext;
methodChannel = new MethodChannel(messenger, "uk.spiralarm.flutter/devicelocale");
methodChannel.setMethodCallHandler(this);
}


@Override
public void onMethodCall(MethodCall call, @NonNull Result result) {
String method = call.method;
Expand Down
2 changes: 1 addition & 1 deletion example/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>8.0</string>
<string>9.0</string>
</dict>
</plist>
2 changes: 1 addition & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
devicelocale: b22617f40038496deffba44747101255cee005b0
Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c
Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a

PODFILE CHECKSUM: 8e679eca47255a8ca8067c4c67aab20e64cb974d

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: devicelocale
description: A Flutter package that can be used to extract the locales that are currently defined on a device with the current locale set as the first in the list.
version: 0.4.3
version: 0.5.0
homepage: https://github.com/magnatronus/flutter-devicelocale

environment:
Expand Down

0 comments on commit 59cb6d9

Please sign in to comment.