Compare commits
	
		
			No commits in common. "c905b3242d37eb87bea19baf5666812bb0567287" and "1852f2d1987c210f2eacdfc92c8d49206d044684" have entirely different histories.
		
	
	
		
			c905b3242d
			...
			1852f2d198
		
	
		
| @ -27,7 +27,3 @@ Thanks to [ekasetiawans](https://github.com/ekasetiawans) for [flutter_backgroun | ||||
| was essentially the blueprint for the service and background service APIs. They were reimplemented | ||||
| to allow the root isolate to pass some additional data to the service, which `flutter_background_service` | ||||
| did not support. | ||||
| 
 | ||||
| Thanks to [nschairer](https://github.com/nschairer) for [flutter_keyboard_height](https://github.com/nschairer/keyboard_height_plugin), which was the base for keeping track of the keyboard height. | ||||
| Due to having an issue with the height calculation if the Android device uses gesture navigation, I | ||||
| [forked the package](https://git.polynom.me/moxxy/keyboard_height_plugin) and modified the height calculation. | ||||
|  | ||||
| @ -2,9 +2,6 @@ package org.moxxy.moxxy_native | ||||
| 
 | ||||
| const val TAG = "moxxy_native" | ||||
| 
 | ||||
| // The event channel name for the keyboard height | ||||
| const val KEYBOARD_HEIGHT_EVENT_CHANNEL_NAME = "org.moxxy.moxxyv2/notification_stream" | ||||
| 
 | ||||
| // The size of buffers to use for various operations | ||||
| const val BUFFER_SIZE = 4096 | ||||
| 
 | ||||
|  | ||||
| @ -29,7 +29,6 @@ import org.moxxy.moxxy_native.notifications.NotificationsImplementation | ||||
| import org.moxxy.moxxy_native.picker.FilePickerType | ||||
| import org.moxxy.moxxy_native.picker.MoxxyPickerApi | ||||
| import org.moxxy.moxxy_native.picker.PickerResultListener | ||||
| import org.moxxy.moxxy_native.platform.KeyboardStreamHandler | ||||
| import org.moxxy.moxxy_native.platform.MoxxyPlatformApi | ||||
| import org.moxxy.moxxy_native.platform.PlatformImplementation | ||||
| import org.moxxy.moxxy_native.service.BackgroundService | ||||
| @ -103,10 +102,6 @@ class MoxxyNativePlugin : FlutterPlugin, ActivityAware, ServiceAware, BroadcastR | ||||
|             IntentFilter(SERVICE_FOREGROUND_METHOD_CHANNEL_KEY), | ||||
|         ) | ||||
| 
 | ||||
|         // Special handling for the keyboard height | ||||
|         val keyboardChannel = EventChannel(flutterPluginBinding.getBinaryMessenger(), KEYBOARD_HEIGHT_EVENT_CHANNEL_NAME) | ||||
|         keyboardChannel?.setStreamHandler(KeyboardStreamHandler) | ||||
| 
 | ||||
|         // Register the picker handler | ||||
|         pickerListener = PickerResultListener(context!!) | ||||
|         Log.d(TAG, "Attached to engine") | ||||
| @ -123,24 +118,20 @@ class MoxxyNativePlugin : FlutterPlugin, ActivityAware, ServiceAware, BroadcastR | ||||
|     override fun onAttachedToActivity(binding: ActivityPluginBinding) { | ||||
|         activity = binding.activity | ||||
|         binding.addActivityResultListener(pickerListener) | ||||
|         KeyboardStreamHandler.activity = activity | ||||
|         Log.d(TAG, "Attached to activity") | ||||
|     } | ||||
| 
 | ||||
|     override fun onDetachedFromActivityForConfigChanges() { | ||||
|         activity = null | ||||
|         KeyboardStreamHandler.activity = null | ||||
|         Log.d(TAG, "Detached from activity") | ||||
|     } | ||||
| 
 | ||||
|     override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) { | ||||
|         activity = binding.activity | ||||
|         KeyboardStreamHandler.activity = activity | ||||
|     } | ||||
| 
 | ||||
|     override fun onDetachedFromActivity() { | ||||
|         activity = null | ||||
|         KeyboardStreamHandler.activity = null | ||||
|         Log.d(TAG, "Detached from activity") | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -164,7 +164,7 @@ class NotificationReceiver : BroadcastReceiver() { | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     private fun handleTap(context: Context, intent: Intent) { | ||||
|     fun handleTap(context: Context, intent: Intent) { | ||||
|         MoxxyEventChannels.notificationEventSink?.success( | ||||
|             NotificationEvent( | ||||
|                 intent.getLongExtra(NOTIFICATION_EXTRA_ID_KEY, -1), | ||||
|  | ||||
| @ -1,73 +0,0 @@ | ||||
| package org.moxxy.moxxy_native.platform | ||||
| 
 | ||||
| import android.app.Activity | ||||
| import android.graphics.Rect | ||||
| import android.util.Log | ||||
| import android.view.View | ||||
| import android.view.ViewTreeObserver | ||||
| import androidx.core.view.ViewCompat | ||||
| import androidx.core.view.WindowInsetsCompat | ||||
| import io.flutter.plugin.common.EventChannel | ||||
| import org.moxxy.moxxy_native.MoxxyEventChannels | ||||
| import org.moxxy.moxxy_native.TAG | ||||
| 
 | ||||
| object KeyboardStreamHandler : EventChannel.StreamHandler { | ||||
|     // The currently active activity. Set by @MoxxyNativePlugin. | ||||
|     var activity: Activity? = null | ||||
| 
 | ||||
|     // The current bottom inset. | ||||
|     private var bottomInset: Int = 0 | ||||
| 
 | ||||
|     // The current event sink to use for sending events to the UI. | ||||
|     private var sink: EventChannel.EventSink? = null | ||||
| 
 | ||||
|     private fun handleKeyboardHeightCheck(rootView: View?) { | ||||
|         rootView?.viewTreeObserver?.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener { | ||||
|             override fun onGlobalLayout() { | ||||
|                 val r = Rect() | ||||
|                 rootView.getWindowVisibleDisplayFrame(r) | ||||
| 
 | ||||
|                 val screenHeight = rootView.height | ||||
|                 // Also subtract the height of the bottom inset as the SafeArea with "bottom: false" | ||||
|                 // allows us to draw under the bottom system bar, if it is there. | ||||
|                 val keypadHeight = screenHeight - r.bottom - bottomInset | ||||
| 
 | ||||
|                 val displayMetrics = activity?.resources?.displayMetrics | ||||
|                 val logicalKeypadHeight = keypadHeight / (displayMetrics?.density ?: 1f) | ||||
| 
 | ||||
|                 if (keypadHeight > screenHeight * 0.15) { | ||||
|                     sink?.success(logicalKeypadHeight.toDouble()) | ||||
|                 } else { | ||||
|                     sink?.success(0.0) | ||||
|                 } | ||||
|             } | ||||
|         }) | ||||
|     } | ||||
| 
 | ||||
|     override fun onListen(arguments: Any?, events: EventChannel.EventSink?) { | ||||
|         // "register" the event sink | ||||
|         sink = events | ||||
| 
 | ||||
|         val rootView = activity?.window?.decorView?.rootView | ||||
|         handleKeyboardHeightCheck(rootView) | ||||
| 
 | ||||
|         if (rootView != null) { | ||||
|             ViewCompat.setOnApplyWindowInsetsListener(rootView!!) { _, windowInsets -> | ||||
|                 val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()) | ||||
|                 val triggerEvent = bottomInset != insets.bottom | ||||
|                 bottomInset = insets.bottom | ||||
| 
 | ||||
|                 // Notify in case the inset changed | ||||
|                 if (triggerEvent) handleKeyboardHeightCheck(rootView) | ||||
| 
 | ||||
|                 WindowInsetsCompat.CONSUMED | ||||
|             } | ||||
|         } | ||||
|         Log.d(TAG, "KeyboardStreamHandler: Attached stream") | ||||
|     } | ||||
| 
 | ||||
|     override fun onCancel(arguments: Any?) { | ||||
|         MoxxyEventChannels.notificationEventSink = null | ||||
|         Log.d(TAG, "KeyboardStreamHandler: Detached stream") | ||||
|     } | ||||
| } | ||||
| @ -1,5 +1,6 @@ | ||||
| // ignore_for_file: avoid_print | ||||
| import 'dart:io'; | ||||
| import 'dart:typed_data'; | ||||
| import 'package:flutter/material.dart'; | ||||
| import 'package:flutter/services.dart'; | ||||
| import 'package:get_it/get_it.dart'; | ||||
| @ -50,19 +51,6 @@ class TestEvent extends BackgroundEvent { | ||||
| class MyAppState extends State<MyApp> { | ||||
|   String? imagePath; | ||||
| 
 | ||||
|   @override | ||||
|   void initState() { | ||||
|     super.initState(); | ||||
| 
 | ||||
|     const EventChannel('org.moxxy.moxxyv2/notification_stream') | ||||
|         .receiveBroadcastStream() | ||||
|         .listen( | ||||
|       (event) { | ||||
|         print('Keyboard height: ${event as double}'); | ||||
|       }, | ||||
|     ); | ||||
|   } | ||||
| 
 | ||||
|   @override | ||||
|   Widget build(BuildContext context) { | ||||
|     return MaterialApp( | ||||
| @ -233,7 +221,6 @@ class MyAppState extends State<MyApp> { | ||||
|               }, | ||||
|               child: const Text('Share some text'), | ||||
|             ), | ||||
|             const TextField(), | ||||
|           ], | ||||
|         ), | ||||
|       ), | ||||
|  | ||||
| @ -1,6 +1,6 @@ | ||||
| name: moxxy_native | ||||
| description: Interactions with the system for Moxxy | ||||
| version: 0.3.0 | ||||
| version: 0.2.0 | ||||
| publish_to: https://git.polynom.me/api/packages/Moxxy/pub | ||||
| homepage:  | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user