io.flutter.view.FlutterNativeView Java Examples

The following examples show how to use io.flutter.view.FlutterNativeView. 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: AndroidJobScheduler.java    From android_job_scheduler with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onStartJob(JobParameters params) {
    PersistableBundle extras = params.getExtras();
    Context context = getApplicationContext();
    if (isApplicationRunning(context)) {
        if (callbackMethodChannel != null) {
            callbackMethodChannel.invokeMethod("firedWhileApplicationRunning", null);
        }
    } else {
        FlutterNativeView nativeView = new FlutterNativeView(context);
        if (AndroidJobScheduler.pluginRegistrantCallback != null) {
            AndroidJobScheduler.pluginRegistrantCallback.registerWith(nativeView.getPluginRegistry());
        }
        nativeView.runFromBundle(FlutterMain.findAppBundlePath(context), null,
                extras.getString(B_KEY_DART_CB), true);
    }
    if (!extras.containsKey(B_KEY_SCHEDULE_ONCE)) {
        AndroidJobScheduler.scheduleEvery(getApplicationContext(), AndroidJobSchedulerUtils.persistableBundleToJobInfo(extras));
    }
    jobFinished(params, false);
    return true;
}
 
Example #2
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 #3
Source File: AudioQueryDelegate.java    From flutter_audio_query with MIT License 5 votes vote down vote up
private AudioQueryDelegate(final PluginRegistry.Registrar registrar){

        m_artistLoader = new ArtistLoader(registrar.context() );
        m_albumLoader = new AlbumLoader(registrar.context() );
        m_songLoader = new SongLoader( registrar.context() );
        m_genreLoader = new GenreLoader( registrar.context() );
        m_playlistLoader = new PlaylistLoader( registrar.context() );

        m_permissionManager = new PermissionManager() {
            @Override
            public boolean isPermissionGranted(String permissionName) {

                return (ActivityCompat.checkSelfPermission( registrar.activity(), permissionName)
                    == PackageManager.PERMISSION_GRANTED);
            }

            @Override
            public void askForPermission(String permissionName, int requestCode) {
                ActivityCompat.requestPermissions(registrar.activity(), new String[] {permissionName}, requestCode);
            }
        };

        registrar.addRequestPermissionsResultListener(this);
        registrar.addViewDestroyListener(new PluginRegistry.ViewDestroyListener() {
            @Override
            public boolean onViewDestroy(FlutterNativeView flutterNativeView) {
                // ideal
                Log.i("MDBG", "onViewDestroy");
                return true;
            }
        });
    }
 
Example #4
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 #5
Source File: Flutter.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Creates a {@link FlutterView} linked to the specified {@link Activity} and {@link Lifecycle}.
 * The optional initial route string will be made available to the Dart code (via
 * {@code window.defaultRouteName}) and may be used to determine which widget should be displayed
 * in the view. The default initialRoute is "/".
 *
 * @param activity an {@link Activity}
 * @param lifecycle a {@link Lifecycle}
 * @param initialRoute an initial route {@link String}, or null
 * @return a {@link FlutterView}
 */
@NonNull
public static FlutterView createView(@NonNull final Activity activity, @NonNull final Lifecycle lifecycle, final String initialRoute) {
  FlutterMain.startInitialization(activity.getApplicationContext());
  FlutterMain.ensureInitializationComplete(activity.getApplicationContext(), null);
  final FlutterNativeView nativeView = new FlutterNativeView(activity);
  final FlutterView flutterView = new FlutterView(activity, null, nativeView) {
    private final BasicMessageChannel<String> lifecycleMessages = new BasicMessageChannel<>(this, "flutter/lifecycle", StringCodec.INSTANCE);
    @Override
    public void onFirstFrame() {
      super.onFirstFrame();
      setAlpha(1.0f);
    }

    @Override
    public void onPostResume() {
      // Overriding default behavior to avoid dictating system UI via PlatformPlugin.
      lifecycleMessages.send("AppLifecycleState.resumed");
    }
  };
  if (initialRoute != null) {
    flutterView.setInitialRoute(initialRoute);
  }
  lifecycle.addObserver(new LifecycleObserver() {
    @OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
    public void onCreate() {
      final FlutterRunArguments arguments = new FlutterRunArguments();
      arguments.bundlePath = FlutterMain.findAppBundlePath(activity.getApplicationContext());
      arguments.entrypoint = "main";
      flutterView.runFromBundle(arguments);
      GeneratedPluginRegistrant.registerWith(flutterView.getPluginRegistry());
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_START)
    public void onStart() {
      flutterView.onStart();
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
    public void onResume() {
      flutterView.onPostResume();
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
    public void onPause() {
      flutterView.onPause();
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
    public void onStop() {
      flutterView.onStop();
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
    public void onDestroy() {
      flutterView.destroy();
    }
  });
  flutterView.setAlpha(0.0f);
  return flutterView;
}
 
Example #6
Source File: MediaPlayerPlugin.java    From media_player with MIT License 4 votes vote down vote up
@Override
public boolean onViewDestroy(FlutterNativeView flutterNativeView) {
  Log.i(TAG,"onview destroy called");
  unBoundService();
  return false;
}
 
Example #7
Source File: XFlutterView.java    From hybrid_stack_manager with MIT License 4 votes vote down vote up
public XFlutterView(Context context, AttributeSet attrs, FlutterNativeView nativeView){
    super(context,attrs,nativeView);
}
 
Example #8
Source File: DeviceAppsPlugin.java    From flutter_plugin_device_apps with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onViewDestroy(FlutterNativeView flutterNativeView) {
    asyncWork.stop();
    return true;
}
 
Example #9
Source File: XFlutterView.java    From hybrid_stack_manager with MIT License 4 votes vote down vote up
public XFlutterView(Context context, AttributeSet attrs, FlutterNativeView nativeView){
    super(context,attrs,nativeView);
}
 
Example #10
Source File: Flutter.java    From CrazyDaily with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a {@link FlutterView} linked to the specified {@link Activity} and {@link Lifecycle}.
 * The optional initial route string will be made available to the Dart code (via
 * {@code window.defaultRouteName}) and may be used to determine which widget should be displayed
 * in the view. The default initialRoute is "/".
 *
 * @param activity an {@link Activity}
 * @param lifecycle a {@link Lifecycle}
 * @param initialRoute an initial route {@link String}, or null
 * @return a {@link FlutterView}
 */
@NonNull
public static FlutterView createView(@NonNull final Activity activity, @NonNull final Lifecycle lifecycle, final String initialRoute) {
  FlutterMain.startInitialization(activity.getApplicationContext());
  FlutterMain.ensureInitializationComplete(activity.getApplicationContext(), null);
  final FlutterNativeView nativeView = new FlutterNativeView(activity);
  final FlutterView flutterView = new FlutterView(activity, null, nativeView) {
    private final BasicMessageChannel<String> lifecycleMessages = new BasicMessageChannel<>(this, "flutter/lifecycle", StringCodec.INSTANCE);
    @Override
    public void onFirstFrame() {
      super.onFirstFrame();
      setAlpha(1.0f);
    }

    @Override
    public void onPostResume() {
      // Overriding default behavior to avoid dictating system UI via PlatformPlugin.
      lifecycleMessages.send("AppLifecycleState.resumed");
    }
  };
  if (initialRoute != null) {
    flutterView.setInitialRoute(initialRoute);
  }
  lifecycle.addObserver(new LifecycleObserver() {
    @OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
    public void onCreate() {
      final FlutterRunArguments arguments = new FlutterRunArguments();
      arguments.bundlePath = FlutterMain.findAppBundlePath(activity.getApplicationContext());
      arguments.entrypoint = "main";
      flutterView.runFromBundle(arguments);
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_START)
    public void onStart() {
      flutterView.onStart();
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
    public void onResume() {
      flutterView.onPostResume();
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
    public void onPause() {
      flutterView.onPause();
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
    public void onStop() {
      flutterView.onStop();
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
    public void onDestroy() {
      flutterView.destroy();
    }
  });
  flutterView.setAlpha(0.0f);
  return flutterView;
}
 
Example #11
Source File: AppFlutterActivity.java    From Aurora with Apache License 2.0 4 votes vote down vote up
public FlutterNativeView createFlutterNativeView() {
    return null;
}
 
Example #12
Source File: XFlutterActivityDelegate.java    From hybrid_stack_manager with MIT License votes vote down vote up
FlutterNativeView createFlutterNativeView(); 
Example #13
Source File: XFlutterActivityDelegate.java    From hybrid_stack_manager with MIT License votes vote down vote up
FlutterNativeView createFlutterNativeView();