io.flutter.plugin.common.EventChannel Java Examples

The following examples show how to use io.flutter.plugin.common.EventChannel. 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: FlutterIsolatePlugin.java    From flutter_isolate with MIT License 6 votes vote down vote up
@Override
public void onListen(Object o, EventChannel.EventSink sink) {

    IsolateHolder isolate = queuedIsolates.remove();
    sink.success(isolate.isolateId);
    sink.endOfStream();
    activeIsolates.put(isolate.isolateId, isolate);

    isolate.result.success(null);
    isolate.startupChannel = null;
    isolate.result = null;

    if (queuedIsolates.size() != 0)
        startNextIsolate();

}
 
Example #2
Source File: FlutterYoutubePlugin.java    From FlutterYoutube with Apache License 2.0 6 votes vote down vote up
/**
 * Plugin registration.
 */
public static void registerWith(Registrar registrar) {
  final MethodChannel channel = new MethodChannel(registrar.messenger(), "PonnamKarthik/flutter_youtube");
  channel.setMethodCallHandler(new FlutterYoutubePlugin(registrar.activity()));
  registrar.addActivityResultListener(new PluginRegistry.ActivityResultListener() {
    @Override
    public boolean onActivityResult(int i, int i1, Intent intent) {
      if(i == YOUTUBE_PLAYER_RESULT) {
        if(intent != null) {
          if(intent.getIntExtra("done", -1) == 0) {
            if(events != null) {
              events.success("done");
            }
          }
        }
      }
      return false;
    }
  });

  final EventChannel eventChannel = new EventChannel(registrar.messenger(), STREAM_CHANNEL_NAME);
  FlutterYoutubePlugin youtubeWithEventChannel = new FlutterYoutubePlugin(registrar.activity());
  eventChannel.setStreamHandler(youtubeWithEventChannel);
}
 
Example #3
Source File: FlutterFlipperkitPlugin.java    From flutter_flipperkit with MIT License 6 votes vote down vote up
private void setupChannel(BinaryMessenger messenger, Context context) {
    this.context = context;
    SoLoader.init(context.getApplicationContext(), false);
    if (BuildConfig.DEBUG && FlipperUtils.shouldEnableFlipper(context)) {
        flipperClient = AndroidFlipperClient.getInstance(context);
        networkFlipperPlugin = new NetworkFlipperPlugin();
        sharedPreferencesFlipperPlugin = new SharedPreferencesFlipperPlugin(context, "FlutterSharedPreferences");

        flipperDatabaseBrowserPlugin = new FlipperDatabaseBrowserPlugin();
        flipperReduxInspectorPlugin = new FlipperReduxInspectorPlugin();
    }

    this.channel = new MethodChannel(messenger, CHANNEL_NAME);
    this.channel.setMethodCallHandler(this);

    this.eventChannel = new EventChannel(messenger, EVENT_CHANNEL_NAME);
    this.eventChannel.setStreamHandler(this);
}
 
Example #4
Source File: AeyriumSensorPlugin.java    From aeyrium-sensor with MIT License 6 votes vote down vote up
SensorEventListener createSensorEventListener(final EventChannel.EventSink events) {
  return new SensorEventListener() {
    @Override
    public void onAccuracyChanged(Sensor sensor, int accuracy) {
      if (mLastAccuracy != accuracy) {
        mLastAccuracy = accuracy;
      }
    }

    @Override
    public void onSensorChanged(SensorEvent event) {
      if (mLastAccuracy == SensorManager.SENSOR_STATUS_UNRELIABLE) {
        return;
      }

      updateOrientation(event.values, events);
    }
  };
}
 
Example #5
Source File: SmsStateHandler.java    From flutter_sms with MIT License 5 votes vote down vote up
@Override
public void onListen(Object o, EventChannel.EventSink eventSink) {
    this.eventSink = eventSink;
    smsStateChangeReceiver = new SmsStateChangeReceiver(eventSink);
    if(permissions.checkAndRequestPermission(
            new String[]{Manifest.permission.RECEIVE_SMS},
            Permissions.BROADCAST_SMS)){
        registerDeliveredReceiver();
        registerSentReceiver();
    }
}
 
Example #6
Source File: NoiseMeterPlugin.java    From flutter-plugins with MIT License 5 votes vote down vote up
/**
 * The onListen() method is called when a NoiseLevel object creates a stream of NoiseEvents.
 * onListen starts recording and starts the listen method.
 */
@Override
@SuppressWarnings("unchecked")
public void onListen(Object obj, EventChannel.EventSink eventSink) {
    this.eventSink = eventSink;
    recording = true;
    streamMicData();
}
 
Example #7
Source File: LightPlugin.java    From flutter-plugins with MIT License 5 votes vote down vote up
SensorEventListener createSensorEventListener(final EventChannel.EventSink events) {
  return new SensorEventListener() {
    @Override
    public void onAccuracyChanged(Sensor sensor, int accuracy) {
    }

    @TargetApi(Build.VERSION_CODES.CUPCAKE)
    @Override
    public void onSensorChanged(SensorEvent event) {
      int lux = (int) event.values[0];
      events.success(lux);
    }
  };
}
 
Example #8
Source File: NativeDeviceOrientationPlugin.java    From flutter_native_device_orientation with MIT License 5 votes vote down vote up
/**
 * Plugin registration.
 */
public static void registerWith(Registrar registrar) {
    final MethodChannel methodChannel = new MethodChannel(registrar.messenger(), METHOD_CHANEL);
    final EventChannel eventChannel = new EventChannel(registrar.messenger(), EVENT_CHANNEL);
    final NativeDeviceOrientationPlugin instance = new NativeDeviceOrientationPlugin(registrar.activeContext());

    methodChannel.setMethodCallHandler(instance);
    eventChannel.setStreamHandler(instance);
}
 
Example #9
Source File: NativeDeviceOrientationPlugin.java    From flutter_native_device_orientation with MIT License 5 votes vote down vote up
@Override
public void onListen(Object parameters, final EventChannel.EventSink eventSink) {
    boolean useSensor = false;
    // used hashMap to send parameters to this method. This makes it easier in the future to add new parameters if needed.
    if(parameters instanceof Map){
        Map params = (Map) parameters;

        if(params.containsKey("useSensor")){
            Boolean useSensorNullable = (Boolean) params.get("useSensor");
            useSensor = useSensorNullable != null && useSensorNullable;
        }
    }

    // initialize the callback. It is the same for both listeners.
    IOrientationListener.OrientationCallback callback = new IOrientationListener.OrientationCallback() {
        @Override
        public void receive(OrientationReader.Orientation orientation) {
            eventSink.success(orientation.name());
        }
    };

    if(useSensor){
        Log.i("NDOP", "listening using sensor listener");
        listener = new SensorOrientationListener(reader, context, callback);
    }else{
        Log.i("NDOP", "listening using window listener");
        listener = new OrientationListener(reader, context, callback);
    }
    listener.startOrientationListener();
}
 
Example #10
Source File: OtaUpdatePlugin.java    From ota_update with MIT License 5 votes vote down vote up
/**
 * Plugin registration.
 */
public static void registerWith(Registrar registrar) {
    OtaUpdatePlugin plugin = new OtaUpdatePlugin(registrar);
    final EventChannel progressChannel = new EventChannel(registrar.messenger(), "sk.fourq.ota_update");
    progressChannel.setStreamHandler(plugin);
    registrar.addRequestPermissionsResultListener(plugin);
}
 
Example #11
Source File: WifiIotPlugin.java    From WiFiFlutter with MIT License 5 votes vote down vote up
/**
 * Plugin registration.
 */
public static void registerWith(Registrar registrar) {
    if (registrar.activity() == null) {
        // When a background flutter view tries to register the plugin, the registrar has no activity.
        // We stop the registration process as this plugin is foreground only.
        return;
    }
    final MethodChannel channel = new MethodChannel(registrar.messenger(), "wifi_iot");
    final EventChannel eventChannel = new EventChannel(registrar.messenger(), "plugins.wififlutter.io/wifi_scan");
    final WifiIotPlugin wifiIotPlugin = new WifiIotPlugin(registrar.activity());
    eventChannel.setStreamHandler(wifiIotPlugin);
    channel.setMethodCallHandler(wifiIotPlugin);

    registrar.addViewDestroyListener(new ViewDestroyListener() {
        @Override
        public boolean onViewDestroy(FlutterNativeView view) {
            if (!wifiIotPlugin.ssidsToBeRemovedOnExit.isEmpty()) {
                List<WifiConfiguration> wifiConfigList =
                        wifiIotPlugin.moWiFi.getConfiguredNetworks();
                for (String ssid : wifiIotPlugin.ssidsToBeRemovedOnExit) {
                    for (WifiConfiguration wifiConfig : wifiConfigList) {
                        if (wifiConfig.SSID.equals(ssid)) {
                            wifiIotPlugin.moWiFi.removeNetwork(wifiConfig.networkId);
                        }
                    }
                }
            }
            return false;
        }
    });
}
 
Example #12
Source File: WifiIotPlugin.java    From WiFiFlutter with MIT License 5 votes vote down vote up
@Override
public void onListen(Object o, EventChannel.EventSink eventSink) {
    int PERMISSIONS_REQUEST_CODE_ACCESS_COARSE_LOCATION = 65655434;
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && moContext.checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED){
        moActivity.requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, PERMISSIONS_REQUEST_CODE_ACCESS_COARSE_LOCATION);
    }
    receiver = createReceiver(eventSink);

    moContext.registerReceiver(receiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
}
 
Example #13
Source File: WifiIotPlugin.java    From WiFiFlutter with MIT License 5 votes vote down vote up
private BroadcastReceiver createReceiver(final EventChannel.EventSink eventSink){
    return new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            eventSink.success(handleNetworkScanResult().toString());
        }
    };
}
 
Example #14
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 #15
Source File: BackgroundLocationUpdatesPlugin.java    From background_location_updates with Apache License 2.0 5 votes vote down vote up
@Override
public void onListen(Object o, EventChannel.EventSink eventSink) {
  if (mContext.getSharedPreferences(SHARED_PREFS, Context.MODE_PRIVATE).contains(KEY_PERSISTED_REQUEST_INTERVAL)) {
    eventSink.success(true);
  } else {
    eventSink.success(false);
  }
  this.isTrackingActiveEventSink = eventSink;
}
 
Example #16
Source File: RequestPermissionsHandler.java    From background_location_updates with Apache License 2.0 5 votes vote down vote up
@Override
public void onListen(Object o, EventChannel.EventSink eventSink) {
    this.sink = eventSink;
    if (RequestPermissionsHandler.hasPermission(this.mContext)) {
        this.result = PermissionResult.GRANTED;
    } else {
        this.result = PermissionResult.DENIED;
    }
    Log.v(TAG, String.format("Permission Granted: %s", this.result));
    eventSink.success(this.result.result);
}
 
Example #17
Source File: NotificationsPlugin.java    From flutter-plugins with MIT License 5 votes vote down vote up
/** Plugin registration. */
public static void registerWith(Registrar registrar) {
    final EventChannel channel = new EventChannel(registrar.messenger(), EVENT_CHANNEL_NAME);
    Context context = registrar.activeContext();
    NotificationsPlugin plugin = new NotificationsPlugin(context);
    channel.setStreamHandler(plugin);
}
 
Example #18
Source File: LightPlugin.java    From flutter-plugins with MIT License 5 votes vote down vote up
/**
 * Plugin registration.
 */
public static void registerWith(Registrar registrar) {
  final EventChannel eventChannel =
          new EventChannel(registrar.messenger(), STEP_COUNT_CHANNEL_NAME);
  eventChannel.setStreamHandler(
          new LightPlugin(registrar.context(), Sensor.TYPE_LIGHT));
}
 
Example #19
Source File: ScreenStatePlugin.java    From flutter-plugins with MIT License 5 votes vote down vote up
@Override
public void onListen(Object o, EventChannel.EventSink eventSink) {
  IntentFilter filter = new IntentFilter();
  filter.addAction(Intent.ACTION_SCREEN_ON); // Turn on screen
  filter.addAction(Intent.ACTION_SCREEN_OFF); // Turn off Screen
  filter.addAction(Intent.ACTION_USER_PRESENT); // Unlock screen

  mReceiver = new ScreenReceiver(eventSink);
  context.registerReceiver(mReceiver, filter);
}
 
Example #20
Source File: PedometerPlugin.java    From flutter-plugins with MIT License 5 votes vote down vote up
SensorEventListener createSensorEventListener(final EventChannel.EventSink events) {
  return new SensorEventListener() {
    @Override
    public void onAccuracyChanged(Sensor sensor, int accuracy) {
    }

    @TargetApi(Build.VERSION_CODES.CUPCAKE)
    @Override
    public void onSensorChanged(SensorEvent event) {
      int stepCount = (int) event.values[0];
      events.success(stepCount);
    }
  };
}
 
Example #21
Source File: MovisensFlutterPlugin.java    From flutter-plugins with MIT License 5 votes vote down vote up
/**
 * Plugin registration.
 */
public static void registerWith(Registrar registrar) {
    // Set up plugin instance
    MovisensFlutterPlugin plugin = new MovisensFlutterPlugin(registrar);

    // Set up method channel
    final MethodChannel methodChannel = new MethodChannel(registrar.messenger(), "movisens.method_channel");
    methodChannel.setMethodCallHandler(plugin);

    // Set up event channel
    final EventChannel eventChannel = new EventChannel(registrar.messenger(), "movisens.event_channel");
    eventChannel.setStreamHandler(plugin);
}
 
Example #22
Source File: AeyriumSensorPlugin.java    From aeyrium-sensor with MIT License 5 votes vote down vote up
/** Plugin registration. */
public static void registerWith(Registrar registrar) {
  final EventChannel sensorChannel =
          new EventChannel(registrar.messenger(), SENSOR_CHANNEL_NAME);
  sensorChannel.setStreamHandler(
          new AeyriumSensorPlugin(registrar.context(), Sensor.TYPE_ROTATION_VECTOR, registrar));

}
 
Example #23
Source File: FlutterBarcodeScannerPlugin.java    From flutter_barcode_scanner with MIT License 5 votes vote down vote up
@Override
public void onListen(Object o, EventChannel.EventSink eventSink) {
    try {
        barcodeStream = eventSink;
    } catch (Exception e) {
    }
}
 
Example #24
Source File: FlutterBarcodeScannerPlugin.java    From flutter_barcode_scanner with MIT License 5 votes vote down vote up
/**
 * Setup method
 * Created after Embedding V2 API release
 *
 * @param messenger
 * @param applicationContext
 * @param activity
 * @param registrar
 * @param activityBinding
 */
private void createPluginSetup(
        final BinaryMessenger messenger,
        final Application applicationContext,
        final Activity activity,
        final PluginRegistry.Registrar registrar,
        final ActivityPluginBinding activityBinding) {


    this.activity = (FlutterActivity) activity;
    eventChannel =
            new EventChannel(messenger, "flutter_barcode_scanner_receiver");
    eventChannel.setStreamHandler(this);


    this.applicationContext = applicationContext;
    channel = new MethodChannel(messenger, CHANNEL);
    channel.setMethodCallHandler(this);
    if (registrar != null) {
        // V1 embedding setup for activity listeners.
        observer = new LifeCycleObserver(activity);
        applicationContext.registerActivityLifecycleCallbacks(
                observer); // Use getApplicationContext() to avoid casting failures.
        registrar.addActivityResultListener(this);
    } else {
        // V2 embedding setup for activity listeners.
        activityBinding.addActivityResultListener(this);
        lifecycle = FlutterLifecycleAdapter.getActivityLifecycle(activityBinding);
        observer = new LifeCycleObserver(activity);
        lifecycle.addObserver(observer);
    }
}
 
Example #25
Source File: AmapLocationPlugin.java    From location_plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Plugin registration.
 */
public static void registerWith(Registrar registrar) {
	final MethodChannel methodChannel = new MethodChannel(registrar.messenger(), "plugin.kinsomy.com/methodchannel");
	final EventChannel eventChannel = new EventChannel(registrar.messenger(), "plugin.kinsomy.com/eventchannel");
	final AmapLocationPlugin instance = new AmapLocationPlugin(registrar);
	methodChannel.setMethodCallHandler(instance);
	eventChannel.setStreamHandler(instance);
}
 
Example #26
Source File: PedometerPlugin.java    From flutter-plugins with MIT License 5 votes vote down vote up
/**
 * Plugin registration.
 */
public static void registerWith(Registrar registrar) {
  final EventChannel eventChannel =
          new EventChannel(registrar.messenger(), STEP_COUNT_CHANNEL_NAME);
  eventChannel.setStreamHandler(
          new PedometerPlugin(registrar.context(), Sensor.TYPE_STEP_COUNTER));
}
 
Example #27
Source File: AudioServiceBinder.java    From media_player with MIT License 5 votes vote down vote up
public void create(PluginRegistry.Registrar registrar, MethodCall call, Result result) {
    Log.i(TAG, "starting player in bakground");
    TextureRegistry.SurfaceTextureEntry handle = registrar.textures().createSurfaceTexture();

    EventChannel eventChannel = new EventChannel(registrar.messenger(), "media_player_event_channel" + handle.id());

    VideoPlayer player;

    player = new VideoPlayer(registrar.context(), eventChannel, handle, result);
    if ((boolean) call.argument("showNotification")) {
        PersistentNotification.create(service, player);
    }
    videoPlayers.put(handle.id(), player);

}
 
Example #28
Source File: FlutterIsolatePlugin.java    From flutter_isolate with MIT License 5 votes vote down vote up
private void startNextIsolate() {

        IsolateHolder isolate = queuedIsolates.peek();

        FlutterMain.ensureInitializationComplete(context, null);

        if (flutterPluginBinding == null)
            isolate.view = new FlutterNativeView(context, true);
        else
            isolate.engine = new FlutterEngine(context);


        FlutterCallbackInformation cbInfo = FlutterCallbackInformation.lookupCallbackInformation(isolate.entryPoint);
        FlutterRunArguments runArgs = new FlutterRunArguments();

        runArgs.bundlePath = FlutterMain.findAppBundlePath(context);
        runArgs.libraryPath = cbInfo.callbackLibraryPath;
        runArgs.entrypoint = cbInfo.callbackName;

        if (flutterPluginBinding == null) {
            isolate.controlChannel = new MethodChannel(isolate.view, NAMESPACE + "/control");
            isolate.startupChannel = new EventChannel(isolate.view, NAMESPACE + "/event");
        } else {
            isolate.controlChannel = new MethodChannel(isolate.engine.getDartExecutor().getBinaryMessenger(), NAMESPACE + "/control");
            isolate.startupChannel = new EventChannel(isolate.engine.getDartExecutor().getBinaryMessenger(), NAMESPACE + "/event");
        }
        isolate.startupChannel.setStreamHandler(this);
        isolate.controlChannel.setMethodCallHandler(this);
        if (flutterPluginBinding == null) {
            registerWithRegistrant(isolate.view.getPluginRegistry());
            isolate.view.runFromBundle(runArgs);
        } else {
            DartExecutor.DartCallback dartCallback = new DartExecutor.DartCallback(context.getAssets(), runArgs.bundlePath, cbInfo);
            isolate.engine.getDartExecutor().executeDartCallback(dartCallback);
        }
    }
 
Example #29
Source File: VideoPlayer.java    From media_player with MIT License 5 votes vote down vote up
VideoPlayer(Context context, EventChannel eventChannel, TextureRegistry.SurfaceTextureEntry textureEntry,
        MethodChannel.Result result) {
    Log.i(TAG, "VideoPlayer constuctor");
    this.context = context;
    this.eventChannel = eventChannel;
    this.textureEntry = textureEntry;

    TrackSelector trackSelector = new DefaultTrackSelector();

    exoPlayer = ExoPlayerFactory.newSimpleInstance(context, trackSelector);

    setupVideoPlayer(eventChannel, textureEntry, result);
}
 
Example #30
Source File: PluginExample.java    From streams_channel with Apache License 2.0 4 votes vote down vote up
@Override
public void onListen(Object o, final EventChannel.EventSink eventSink) {
  System.out.println("StreamHandler - onListen: " + o);
  this.eventSink = eventSink;
  runnable.run();
}