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

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

Merge "Extract plugin interface for nav bar"

parents c1fa5d28 197f4db6
Loading
Loading
Loading
Loading
+51 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
 * except in compliance with the License. You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the
 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */

package com.android.systemui.plugins.statusbar.phone;

import android.annotation.DrawableRes;
import android.annotation.Nullable;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;

import com.android.systemui.plugins.Plugin;

public interface NavBarButtonProvider extends Plugin {

    public static final String ACTION = "com.android.systemui.action.PLUGIN_NAV_BUTTON";

    public static final int VERSION = 1;

    /**
     * Returns a view in the nav bar.  If the id is set "back", "home", "recent_apps", "menu",
     * or "ime_switcher", it is expected to implement ButtonInterface.
     */
    public View createView(String spec, ViewGroup parent);

    /**
     * Interface for button actions.
     */
    interface ButtonInterface {
        void setImageResource(@DrawableRes int resId);

        void setImageDrawable(@Nullable Drawable drawable);

        void abortCurrentGesture();

        void setLandscape(boolean landscape);

        void setCarMode(boolean carMode);
    }
}
+2 −16
Original line number Diff line number Diff line
@@ -14,11 +14,11 @@

package com.android.systemui.statusbar.phone;

import android.annotation.DrawableRes;
import android.annotation.Nullable;
import android.graphics.drawable.Drawable;
import android.view.View;

import com.android.systemui.plugins.statusbar.phone.NavBarButtonProvider.ButtonInterface;

import java.util.ArrayList;

/**
@@ -186,18 +186,4 @@ public class ButtonDispatcher {
        }
    }

    /**
     * Interface for button actions.
     */
    public interface ButtonInterface {
        void setImageResource(@DrawableRes int resId);

        void setImageDrawable(@Nullable Drawable drawable);

        void abortCurrentGesture();

        void setLandscape(boolean landscape);

        void setCarMode(boolean carMode);
    }
}
+55 −20
Original line number Diff line number Diff line
@@ -28,12 +28,19 @@ import android.widget.LinearLayout;
import android.widget.Space;

import com.android.systemui.R;
import com.android.systemui.plugins.PluginListener;
import com.android.systemui.plugins.PluginManager;
import com.android.systemui.plugins.statusbar.phone.NavBarButtonProvider;
import com.android.systemui.statusbar.policy.KeyButtonView;
import com.android.systemui.tuner.TunerService;
import com.android.systemui.tuner.TunerService.Tunable;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class NavigationBarInflaterView extends FrameLayout implements TunerService.Tunable {
public class NavigationBarInflaterView extends FrameLayout
        implements Tunable, PluginListener<NavBarButtonProvider> {

    private static final String TAG = "NavBarInflater";

@@ -57,6 +64,8 @@ public class NavigationBarInflaterView extends FrameLayout implements TunerServi
    public static final String KEY_IMAGE_DELIM = ":";
    public static final String KEY_CODE_END = ")";

    private final List<NavBarButtonProvider> mPlugins = new ArrayList<>();

    protected LayoutInflater mLayoutInflater;
    protected LayoutInflater mLandscapeInflater;
    private int mDensity;
@@ -129,6 +138,8 @@ public class NavigationBarInflaterView extends FrameLayout implements TunerServi
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        TunerService.get(getContext()).addTunable(this, NAV_BAR_VIEWS);
        PluginManager.getInstance(getContext()).addPluginListener(NavBarButtonProvider.ACTION, this,
                NavBarButtonProvider.VERSION, true /* Allow multiple */);
    }

    @Override
@@ -240,8 +251,36 @@ public class NavigationBarInflaterView extends FrameLayout implements TunerServi
            int indexInParent) {
        LayoutInflater inflater = landscape ? mLandscapeInflater : mLayoutInflater;
        float size = extractSize(buttonSpec);
        String button = extractButton(buttonSpec);
        View v = createView(buttonSpec, parent, inflater, landscape);
        if (v == null) return null;

        if (size != 0) {
            ViewGroup.LayoutParams params = v.getLayoutParams();
            params.width = (int) (params.width * size);
        }
        parent.addView(v);
        addToDispatchers(v, landscape);
        View lastView = landscape ? mLastRot90 : mLastRot0;
        if (lastView != null) {
            v.setAccessibilityTraversalAfter(lastView.getId());
        }
        if (landscape) {
            mLastRot90 = v;
        } else {
            mLastRot0 = v;
        }
        return v;
    }

    private View createView(String buttonSpec, ViewGroup parent, LayoutInflater inflater,
            boolean landscape) {
        View v = null;
        String button = extractButton(buttonSpec);
        // Let plugins go first so they can override a standard view if they want.
        for (NavBarButtonProvider provider : mPlugins) {
            v = provider.createView(buttonSpec, parent);
            if (v != null) return v;
        }
        if (HOME.equals(button)) {
            v = inflater.inflate(R.layout.home, parent, false);
            if (landscape && isSw600Dp()) {
@@ -271,24 +310,6 @@ public class NavigationBarInflaterView extends FrameLayout implements TunerServi
            if (uri != null) {
                ((KeyButtonView) v).loadAsync(uri);
            }
        } else {
            return null;
        }

        if (size != 0) {
            ViewGroup.LayoutParams params = v.getLayoutParams();
            params.width = (int) (params.width * size);
        }
        parent.addView(v);
        addToDispatchers(v, landscape);
        View lastView = landscape ? mLastRot90 : mLastRot0;
        if (lastView != null) {
            v.setAccessibilityTraversalAfter(lastView.getId());
        }
        if (landscape) {
            mLastRot90 = v;
        } else {
            mLastRot0 = v;
        }
        return v;
    }
@@ -374,4 +395,18 @@ public class NavigationBarInflaterView extends FrameLayout implements TunerServi
            ((ViewGroup) group.getChildAt(i)).removeAllViews();
        }
    }

    @Override
    public void onPluginConnected(NavBarButtonProvider plugin) {
        mPlugins.add(plugin);
        clearViews();
        inflateLayout(mCurrentLayout);
    }

    @Override
    public void onPluginDisconnected(NavBarButtonProvider plugin) {
        mPlugins.remove(plugin);
        clearViews();
        inflateLayout(mCurrentLayout);
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -44,12 +44,12 @@ import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.ImageView;

import com.android.systemui.R;
import com.android.systemui.statusbar.phone.ButtonDispatcher;
import com.android.systemui.plugins.statusbar.phone.NavBarButtonProvider.ButtonInterface;

import static android.view.accessibility.AccessibilityNodeInfo.ACTION_CLICK;
import static android.view.accessibility.AccessibilityNodeInfo.ACTION_LONG_CLICK;

public class KeyButtonView extends ImageView implements ButtonDispatcher.ButtonInterface {
public class KeyButtonView extends ImageView implements ButtonInterface {

    private int mContentDescriptionRes;
    private long mDownTime;