77 lines
3.2 KiB
Java
77 lines
3.2 KiB
Java
package io.flutter.embedding.engine.systemchannels;
|
|
|
|
import io.flutter.Log;
|
|
import io.flutter.embedding.engine.dart.DartExecutor;
|
|
import io.flutter.plugin.common.JSONMethodCodec;
|
|
import io.flutter.plugin.common.MethodCall;
|
|
import io.flutter.plugin.common.MethodChannel;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.Locale;
|
|
import org.json.JSONException;
|
|
import org.json.JSONObject;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class LocalizationChannel {
|
|
private static final String TAG = "LocalizationChannel";
|
|
public final MethodChannel channel;
|
|
public final MethodChannel.MethodCallHandler handler;
|
|
private LocalizationMessageHandler localizationMessageHandler;
|
|
|
|
/* loaded from: classes.dex */
|
|
public interface LocalizationMessageHandler {
|
|
String getStringResource(String str, String str2);
|
|
}
|
|
|
|
public void setLocalizationMessageHandler(LocalizationMessageHandler localizationMessageHandler) {
|
|
this.localizationMessageHandler = localizationMessageHandler;
|
|
}
|
|
|
|
public LocalizationChannel(DartExecutor dartExecutor) {
|
|
MethodChannel.MethodCallHandler methodCallHandler = new MethodChannel.MethodCallHandler(this) { // from class: io.flutter.embedding.engine.systemchannels.LocalizationChannel.1
|
|
final LocalizationChannel this$0;
|
|
|
|
{
|
|
this.this$0 = this;
|
|
}
|
|
|
|
@Override // io.flutter.plugin.common.MethodChannel.MethodCallHandler
|
|
public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
|
|
if (this.this$0.localizationMessageHandler == null) {
|
|
return;
|
|
}
|
|
String str = methodCall.method;
|
|
str.hashCode();
|
|
if (str.equals("Localization.getStringResource")) {
|
|
JSONObject jSONObject = (JSONObject) methodCall.arguments();
|
|
try {
|
|
result.success(this.this$0.localizationMessageHandler.getStringResource(jSONObject.getString("key"), jSONObject.has("locale") ? jSONObject.getString("locale") : null));
|
|
return;
|
|
} catch (JSONException e) {
|
|
result.error("error", e.getMessage(), null);
|
|
return;
|
|
}
|
|
}
|
|
result.notImplemented();
|
|
}
|
|
};
|
|
this.handler = methodCallHandler;
|
|
MethodChannel methodChannel = new MethodChannel(dartExecutor, "flutter/localization", JSONMethodCodec.INSTANCE);
|
|
this.channel = methodChannel;
|
|
methodChannel.setMethodCallHandler(methodCallHandler);
|
|
}
|
|
|
|
public void sendLocales(List<Locale> list) {
|
|
Log.v(TAG, "Sending Locales to Flutter.");
|
|
ArrayList arrayList = new ArrayList();
|
|
for (Locale locale : list) {
|
|
Log.v(TAG, "Locale (Language: " + locale.getLanguage() + ", Country: " + locale.getCountry() + ", Variant: " + locale.getVariant() + ")");
|
|
arrayList.add(locale.getLanguage());
|
|
arrayList.add(locale.getCountry());
|
|
arrayList.add(locale.getScript());
|
|
arrayList.add(locale.getVariant());
|
|
}
|
|
this.channel.invokeMethod("setLocale", arrayList);
|
|
}
|
|
}
|