forked from flutter/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[path_provider]: Migrated path_provider for android to pigeon. (flutt…
- Loading branch information
Showing
10 changed files
with
760 additions
and
260 deletions.
There are no files selected for viewing
This file contains 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
241 changes: 241 additions & 0 deletions
241
...path_provider_android/android/src/main/java/io/flutter/plugins/pathprovider/Messages.java
This file contains 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,241 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
// Autogenerated from Pigeon (v3.1.5), do not edit directly. | ||
// See also: https://pub.dev/packages/pigeon | ||
|
||
package io.flutter.plugins.pathprovider; | ||
|
||
import android.util.Log; | ||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import io.flutter.plugin.common.BasicMessageChannel; | ||
import io.flutter.plugin.common.BinaryMessenger; | ||
import io.flutter.plugin.common.MessageCodec; | ||
import io.flutter.plugin.common.StandardMessageCodec; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** Generated class from Pigeon. */ | ||
@SuppressWarnings({"unused", "unchecked", "CodeBlock2Expr", "RedundantSuppression"}) | ||
public class Messages { | ||
|
||
public enum StorageDirectory { | ||
music(0), | ||
podcasts(1), | ||
ringtones(2), | ||
alarms(3), | ||
notifications(4), | ||
pictures(5), | ||
movies(6), | ||
downloads(7), | ||
dcim(8), | ||
documents(9); | ||
|
||
private int index; | ||
|
||
private StorageDirectory(final int index) { | ||
this.index = index; | ||
} | ||
} | ||
|
||
private static class PathProviderApiCodec extends StandardMessageCodec { | ||
public static final PathProviderApiCodec INSTANCE = new PathProviderApiCodec(); | ||
|
||
private PathProviderApiCodec() {} | ||
} | ||
|
||
/** Generated interface from Pigeon that represents a handler of messages from Flutter. */ | ||
public interface PathProviderApi { | ||
@Nullable | ||
String getTemporaryPath(); | ||
|
||
@Nullable | ||
String getApplicationSupportPath(); | ||
|
||
@Nullable | ||
String getApplicationDocumentsPath(); | ||
|
||
@Nullable | ||
String getExternalStoragePath(); | ||
|
||
@NonNull | ||
List<String> getExternalCachePaths(); | ||
|
||
@NonNull | ||
List<String> getExternalStoragePaths(@NonNull StorageDirectory directory); | ||
|
||
/** The codec used by PathProviderApi. */ | ||
static MessageCodec<Object> getCodec() { | ||
return PathProviderApiCodec.INSTANCE; | ||
} | ||
|
||
/** | ||
* Sets up an instance of `PathProviderApi` to handle messages through the `binaryMessenger`. | ||
*/ | ||
static void setup(BinaryMessenger binaryMessenger, PathProviderApi api) { | ||
{ | ||
BinaryMessenger.TaskQueue taskQueue = binaryMessenger.makeBackgroundTaskQueue(); | ||
BasicMessageChannel<Object> channel = | ||
new BasicMessageChannel<>( | ||
binaryMessenger, | ||
"dev.flutter.pigeon.PathProviderApi.getTemporaryPath", | ||
getCodec(), | ||
taskQueue); | ||
if (api != null) { | ||
channel.setMessageHandler( | ||
(message, reply) -> { | ||
Map<String, Object> wrapped = new HashMap<>(); | ||
try { | ||
String output = api.getTemporaryPath(); | ||
wrapped.put("result", output); | ||
} catch (Error | RuntimeException exception) { | ||
wrapped.put("error", wrapError(exception)); | ||
} | ||
reply.reply(wrapped); | ||
}); | ||
} else { | ||
channel.setMessageHandler(null); | ||
} | ||
} | ||
{ | ||
BinaryMessenger.TaskQueue taskQueue = binaryMessenger.makeBackgroundTaskQueue(); | ||
BasicMessageChannel<Object> channel = | ||
new BasicMessageChannel<>( | ||
binaryMessenger, | ||
"dev.flutter.pigeon.PathProviderApi.getApplicationSupportPath", | ||
getCodec(), | ||
taskQueue); | ||
if (api != null) { | ||
channel.setMessageHandler( | ||
(message, reply) -> { | ||
Map<String, Object> wrapped = new HashMap<>(); | ||
try { | ||
String output = api.getApplicationSupportPath(); | ||
wrapped.put("result", output); | ||
} catch (Error | RuntimeException exception) { | ||
wrapped.put("error", wrapError(exception)); | ||
} | ||
reply.reply(wrapped); | ||
}); | ||
} else { | ||
channel.setMessageHandler(null); | ||
} | ||
} | ||
{ | ||
BinaryMessenger.TaskQueue taskQueue = binaryMessenger.makeBackgroundTaskQueue(); | ||
BasicMessageChannel<Object> channel = | ||
new BasicMessageChannel<>( | ||
binaryMessenger, | ||
"dev.flutter.pigeon.PathProviderApi.getApplicationDocumentsPath", | ||
getCodec(), | ||
taskQueue); | ||
if (api != null) { | ||
channel.setMessageHandler( | ||
(message, reply) -> { | ||
Map<String, Object> wrapped = new HashMap<>(); | ||
try { | ||
String output = api.getApplicationDocumentsPath(); | ||
wrapped.put("result", output); | ||
} catch (Error | RuntimeException exception) { | ||
wrapped.put("error", wrapError(exception)); | ||
} | ||
reply.reply(wrapped); | ||
}); | ||
} else { | ||
channel.setMessageHandler(null); | ||
} | ||
} | ||
{ | ||
BinaryMessenger.TaskQueue taskQueue = binaryMessenger.makeBackgroundTaskQueue(); | ||
BasicMessageChannel<Object> channel = | ||
new BasicMessageChannel<>( | ||
binaryMessenger, | ||
"dev.flutter.pigeon.PathProviderApi.getExternalStoragePath", | ||
getCodec(), | ||
taskQueue); | ||
if (api != null) { | ||
channel.setMessageHandler( | ||
(message, reply) -> { | ||
Map<String, Object> wrapped = new HashMap<>(); | ||
try { | ||
String output = api.getExternalStoragePath(); | ||
wrapped.put("result", output); | ||
} catch (Error | RuntimeException exception) { | ||
wrapped.put("error", wrapError(exception)); | ||
} | ||
reply.reply(wrapped); | ||
}); | ||
} else { | ||
channel.setMessageHandler(null); | ||
} | ||
} | ||
{ | ||
BinaryMessenger.TaskQueue taskQueue = binaryMessenger.makeBackgroundTaskQueue(); | ||
BasicMessageChannel<Object> channel = | ||
new BasicMessageChannel<>( | ||
binaryMessenger, | ||
"dev.flutter.pigeon.PathProviderApi.getExternalCachePaths", | ||
getCodec(), | ||
taskQueue); | ||
if (api != null) { | ||
channel.setMessageHandler( | ||
(message, reply) -> { | ||
Map<String, Object> wrapped = new HashMap<>(); | ||
try { | ||
List<String> output = api.getExternalCachePaths(); | ||
wrapped.put("result", output); | ||
} catch (Error | RuntimeException exception) { | ||
wrapped.put("error", wrapError(exception)); | ||
} | ||
reply.reply(wrapped); | ||
}); | ||
} else { | ||
channel.setMessageHandler(null); | ||
} | ||
} | ||
{ | ||
BinaryMessenger.TaskQueue taskQueue = binaryMessenger.makeBackgroundTaskQueue(); | ||
BasicMessageChannel<Object> channel = | ||
new BasicMessageChannel<>( | ||
binaryMessenger, | ||
"dev.flutter.pigeon.PathProviderApi.getExternalStoragePaths", | ||
getCodec(), | ||
taskQueue); | ||
if (api != null) { | ||
channel.setMessageHandler( | ||
(message, reply) -> { | ||
Map<String, Object> wrapped = new HashMap<>(); | ||
try { | ||
ArrayList<Object> args = (ArrayList<Object>) message; | ||
StorageDirectory directoryArg = | ||
args.get(0) == null ? null : StorageDirectory.values()[(int) args.get(0)]; | ||
if (directoryArg == null) { | ||
throw new NullPointerException("directoryArg unexpectedly null."); | ||
} | ||
List<String> output = api.getExternalStoragePaths(directoryArg); | ||
wrapped.put("result", output); | ||
} catch (Error | RuntimeException exception) { | ||
wrapped.put("error", wrapError(exception)); | ||
} | ||
reply.reply(wrapped); | ||
}); | ||
} else { | ||
channel.setMessageHandler(null); | ||
} | ||
} | ||
} | ||
} | ||
|
||
private static Map<String, Object> wrapError(Throwable exception) { | ||
Map<String, Object> errorMap = new HashMap<>(); | ||
errorMap.put("message", exception.toString()); | ||
errorMap.put("code", exception.getClass().getSimpleName()); | ||
errorMap.put( | ||
"details", | ||
"Cause: " + exception.getCause() + ", Stacktrace: " + Log.getStackTraceString(exception)); | ||
return errorMap; | ||
} | ||
} |
Oops, something went wrong.