Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e5e7844b authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix NPE when registering gesture support"

parents f68bf1a8 e8a7568b
Loading
Loading
Loading
Loading
+68 −0
Original line number Diff line number Diff line
@@ -17,11 +17,15 @@
package com.android.systemui.statusbar.car;

import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;

import com.android.systemui.R;
import com.android.systemui.plugins.statusbar.phone.NavGesture;
import com.android.systemui.statusbar.phone.NavigationBarGestureHelper;
import com.android.systemui.statusbar.phone.NavigationBarView;

/**
@@ -72,4 +76,68 @@ class CarNavigationBarView extends NavigationBarView {
        // Calling setNavigationIconHints in the base class will result in a NPE as the car
        // navigation bar does not have a back button.
    }

    @Override
    public void onPluginConnected(NavGesture plugin, Context context) {
        // set to null version of the plugin ignoring incoming arg.
        super.onPluginConnected(new NullNavGesture(), context);
    }

    @Override
    public void onPluginDisconnected(NavGesture plugin) {
        // reinstall the null nav gesture plugin
        super.onPluginConnected(new NullNavGesture(), getContext());
    }

    /**
     * Null object pattern to work around expectations of the base class.
     * This is a temporary solution to have the car system ui working.
     * Already underway is a refactor of they car sys ui as to not use this class
     * hierarchy.
     */
    private static class NullNavGesture implements NavGesture {
        @Override
        public GestureHelper getGestureHelper() {
            return new GestureHelper() {
                @Override
                public boolean onTouchEvent(MotionEvent event) {
                    return false;
                }

                @Override
                public boolean onInterceptTouchEvent(MotionEvent event) {
                    return false;
                }

                @Override
                public void setBarState(boolean vertical, boolean isRtl) {
                }

                @Override
                public void onDraw(Canvas canvas) {
                }

                @Override
                public void onDarkIntensityChange(float intensity) {
                }

                @Override
                public void onLayout(boolean changed, int left, int top, int right, int bottom) {
                }
            };
        }

        @Override
        public int getVersion() {
            return 0;
        }

        @Override
        public void onCreate(Context sysuiContext, Context pluginContext) {
        }

        @Override
        public void onDestroy() {
        }
    }
}