@Override
 protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) {
   mMetrics.physicalWidth = width;
   mMetrics.physicalHeight = height;
   mSkyEngine.onViewportMetricsChanged(mMetrics);
   super.onSizeChanged(width, height, oldWidth, oldHeight);
 }
 @Override
 public final WindowInsets onApplyWindowInsets(WindowInsets insets) {
   mMetrics.physicalPaddingTop = insets.getSystemWindowInsetTop();
   mMetrics.physicalPaddingRight = insets.getSystemWindowInsetRight();
   mMetrics.physicalPaddingBottom = insets.getSystemWindowInsetBottom();
   mMetrics.physicalPaddingLeft = insets.getSystemWindowInsetLeft();
   mSkyEngine.onViewportMetricsChanged(mMetrics);
   return super.onApplyWindowInsets(insets);
 }
  public FlutterView(Context context, AttributeSet attrs) {
    super(context, attrs);

    // TODO(abarth): Remove this static and instead make everything that
    // depends on it into a view-associated service.
    ActivityImpl.setCurrentActivity((Activity) context);

    mMetrics = new ViewportMetrics();
    mMetrics.devicePixelRatio = context.getResources().getDisplayMetrics().density;
    setFocusable(true);
    setFocusableInTouchMode(true);

    attach();
    assert mNativePlatformView != 0;

    mSurfaceCallback =
        new SurfaceHolder.Callback() {
          @Override
          public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {}

          @Override
          public void surfaceCreated(SurfaceHolder holder) {
            assert mNativePlatformView != 0;
            nativeSurfaceCreated(mNativePlatformView, holder.getSurface());
          }

          @Override
          public void surfaceDestroyed(SurfaceHolder holder) {
            assert mNativePlatformView != 0;
            nativeSurfaceDestroyed(mNativePlatformView);
          }
        };
    getHolder().addCallback(mSurfaceCallback);

    mKeyboardState = new KeyboardViewState(this);
    mRawKeyboardState = new RawKeyboardServiceState();

    Core core = CoreImpl.getInstance();

    mPlatformServiceProvider = new ServiceProviderImpl(core, this, ServiceRegistry.SHARED);

    ServiceRegistry localRegistry = new ServiceRegistry();
    configureLocalServices(localRegistry);
    mViewServiceProvider = new ServiceProviderImpl(core, this, localRegistry);

    mAccessibilityManager =
        (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);

    mOnMessageListeners = new HashMap<String, OnMessageListener>();
    mAsyncOnMessageListeners = new HashMap<String, OnMessageListenerAsync>();
    mActivityLifecycleListeners = new ArrayList<ActivityLifecycleListener>();

    setLocale(getResources().getConfiguration().locale);

    if ((context.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
      discoveryReceiver = new DiscoveryReceiver();
      context.registerReceiver(discoveryReceiver, new IntentFilter(ACTION_DISCOVER));
    }
  }