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

Commit 7598ae8f authored by Heemin Seog's avatar Heemin Seog Committed by Android (Google) Code Review
Browse files

Merge "DO NOT MERGE Make nav bar button click listeners overrideable" into qt-qpr1-dev

parents d439f54b 9203e45a
Loading
Loading
Loading
Loading
+18 −8
Original line number Diff line number Diff line
@@ -110,24 +110,34 @@ public class CarFacetButton extends LinearLayout {
                mComponentNames = componentNameString.split(FACET_FILTER_DELIMITER);
            }

            setOnClickListener(v -> {
                intent.putExtra(EXTRA_FACET_LAUNCH_PICKER, mSelected);
                mContext.startActivityAsUser(intent, UserHandle.CURRENT);
            });
            setOnClickListener(getButtonClickListener(intent));

            if (longPressIntentString != null) {
                final Intent longPressIntent = Intent.parseUri(longPressIntentString,
                        Intent.URI_INTENT_SCHEME);
                setOnLongClickListener(v -> {
                    mContext.startActivityAsUser(longPressIntent, UserHandle.CURRENT);
                    return true;
                });
                setOnLongClickListener(getButtonLongClickListener(longPressIntent));
            }
        } catch (Exception e) {
            throw new RuntimeException("Failed to attach intent", e);
        }
    }

    /** Defines the behavior of a button click. */
    protected OnClickListener getButtonClickListener(Intent toSend) {
        return v -> {
            toSend.putExtra(EXTRA_FACET_LAUNCH_PICKER, mSelected);
            mContext.startActivityAsUser(toSend, UserHandle.CURRENT);
        };
    }

    /** Defines the behavior of a long click. */
    protected OnLongClickListener getButtonLongClickListener(Intent toSend) {
        return v -> {
            mContext.startActivityAsUser(toSend, UserHandle.CURRENT);
            return true;
        };
    }

    private void setupIcons(TypedArray styledAttributes) {
        mSelectedAlpha = styledAttributes.getFloat(
                R.styleable.CarFacetButton_selectedAlpha, mSelectedAlpha);
+30 −20
Original line number Diff line number Diff line
@@ -90,38 +90,48 @@ public class CarNavigationButton extends com.android.keyguard.AlphaOptimizedImag
        try {
            if (mIntent != null) {
                final Intent intent = Intent.parseUri(mIntent, Intent.URI_INTENT_SCHEME);
                setOnClickListener(v -> {
                setOnClickListener(getButtonClickListener(intent));
            }
        } catch (URISyntaxException e) {
            throw new RuntimeException("Failed to attach intent", e);
        }

        try {
            if (mLongIntent != null) {
                final Intent intent = Intent.parseUri(mLongIntent, Intent.URI_INTENT_SCHEME);
                setOnLongClickListener(getButtonLongClickListener(intent));
            }
        } catch (URISyntaxException e) {
            throw new RuntimeException("Failed to attach long press intent", e);
        }
    }

    /** Defines the behavior of a button click. */
    protected OnClickListener getButtonClickListener(Intent toSend) {
        return v -> {
            try {
                if (mBroadcastIntent) {
                            mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT);
                    mContext.sendBroadcastAsUser(toSend, UserHandle.CURRENT);
                    return;
                }
                        mContext.startActivityAsUser(intent, UserHandle.CURRENT);
                mContext.startActivityAsUser(toSend, UserHandle.CURRENT);
            } catch (Exception e) {
                Log.e(TAG, "Failed to launch intent", e);
            }
                });
            }
        } catch (URISyntaxException e) {
            throw new RuntimeException("Failed to attach intent", e);
        };
    }

    /** Defines the behavior of a long click. */
    protected OnLongClickListener getButtonLongClickListener(Intent toSend) {
        return v -> {
            try {
            if (mLongIntent != null) {
                final Intent intent = Intent.parseUri(mLongIntent, Intent.URI_INTENT_SCHEME);
                setOnLongClickListener(v -> {
                    try {
                        mContext.startActivityAsUser(intent, UserHandle.CURRENT);
                mContext.startActivityAsUser(toSend, UserHandle.CURRENT);
            } catch (Exception e) {
                Log.e(TAG, "Failed to launch intent", e);
            }
            // consume event either way
            return true;
                });
            }
        } catch (URISyntaxException e) {
            throw new RuntimeException("Failed to attach long press intent", e);
        }
        };
    }

    /**