Java Code Examples for io.flutter.plugin.common.PluginRegistry.Registrar#context()

The following examples show how to use io.flutter.plugin.common.PluginRegistry.Registrar#context() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OtaUpdatePlugin.java    From ota_update with MIT License 6 votes vote down vote up
private OtaUpdatePlugin(Registrar registrar) {
    this.registrar = registrar;
    context = (registrar.activity() != null) ? registrar.activity() : registrar.context();
    handler = new Handler(context.getMainLooper()) {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (progressSink != null) {
                Bundle data = msg.getData();
                if (data.containsKey(ERROR)) {
                    reportError(OtaStatus.DOWNLOAD_ERROR, data.getString(ERROR));
                } else {
                    long bytesDownloaded = data.getLong(BYTES_DOWNLOADED);
                    long bytesTotal = data.getLong(BYTES_TOTAL);
                    progressSink.success(Arrays.asList("" + OtaStatus.DOWNLOADING.ordinal(), "" + ((bytesDownloaded * 100) / bytesTotal)));
                }
            }
        }
    };
}
 
Example 2
Source File: AmapLocationPlugin.java    From location_plugin with Apache License 2.0 5 votes vote down vote up
AmapLocationPlugin(Registrar registrar) {
	this.registrar = registrar;
	//初始化定位
	mLocationClient = new AMapLocationClient(registrar.context());

	//设置定位回调监听
	mLocationClient.setLocationListener(mAMapLocationListener);
}
 
Example 3
Source File: FlutterImagePickCropPlugin.java    From FlutterImagePickCrop with Apache License 2.0 5 votes vote down vote up
/**
 * Plugin registration.
 */
public static void registerWith(Registrar registrar) {
    final MethodChannel channel = new MethodChannel(registrar.messenger(), "flutter_image_pick_crop");

    FlutterImagePickCropPlugin instance = new FlutterImagePickCropPlugin(registrar.activity(), registrar.context(), channel);

    registrar.addRequestPermissionsResultListener(instance);
    registrar.addActivityResultListener(instance);
    channel.setMethodCallHandler(instance);

}
 
Example 4
Source File: JmessageFlutterPlugin.java    From jmessage-flutter-plugin with MIT License 5 votes vote down vote up
private JmessageFlutterPlugin(Registrar registrar, MethodChannel channel) {

    this.registrar = registrar;
    this.channel = channel;
    JmessageFlutterPlugin.instance = this;
    mContext = registrar.context();
  }
 
Example 5
Source File: OpenFilePlugin.java    From open_file with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void registerWith(Registrar registrar) {
    OpenFilePlugin plugin = new OpenFilePlugin();
    plugin.activity = registrar.activity();
    plugin.context = registrar.context();
    plugin.channel = new MethodChannel(registrar.messenger(), "open_file");
    plugin.channel.setMethodCallHandler(plugin);
    registrar.addRequestPermissionsResultListener(plugin);
    registrar.addActivityResultListener(plugin);
}
 
Example 6
Source File: BackgroundLocationUpdatesPlugin.java    From background_location_updates with Apache License 2.0 5 votes vote down vote up
private BackgroundLocationUpdatesPlugin(Registrar registrar) {
  this.mContext = registrar.context();
  this.mActivity = registrar.activity();
  new EventChannel(registrar.messenger(), "plugins.gjg.io/background_location_updates/tracking_state")
      .setStreamHandler(this);

  RequestPermissionsHandler requestPermissionsHandler = new RequestPermissionsHandler(mContext);
  registrar.addRequestPermissionsResultListener(requestPermissionsHandler);
  new EventChannel(registrar.messenger(), "plugins.gjg.io/background_location_updates/permission_state")
    .setStreamHandler(requestPermissionsHandler);


}
 
Example 7
Source File: FlutterMultipleImagePickerPlugin.java    From FlutterMulti-ImagePicker with Apache License 2.0 4 votes vote down vote up
public static void registerWith(Registrar registrar) {
    final MethodChannel channel = new MethodChannel(registrar.messenger(), CHANNEL_NAME);
    FlutterMultipleImagePickerPlugin instance = new FlutterMultipleImagePickerPlugin(registrar.activity(), registrar.context(), channel);
    registrar.addActivityResultListener(instance);
    channel.setMethodCallHandler(instance);
}