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

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

Merge "Make onClickListener and onLongClickListener overridable"

parents c7ce0f2d 7e39da03
Loading
Loading
Loading
Loading
+41 −33
Original line number Diff line number Diff line
@@ -177,25 +177,7 @@ public class CarNavigationButton extends LinearLayout {
        try {
            if (mIntent != null) {
                final Intent intent = Intent.parseUri(mIntent, Intent.URI_INTENT_SCHEME);
                setOnClickListener(v -> {
                    try {
                        if (mBroadcastIntent) {
                            mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT);
                            mContext.sendBroadcastAsUser(
                                    new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS),
                                    UserHandle.CURRENT);
                            return;
                        }
                        ActivityOptions options = ActivityOptions.makeBasic();
                        options.setLaunchDisplayId(mContext.getDisplayId());
                        mContext.startActivityAsUser(intent, options.toBundle(),
                                UserHandle.CURRENT);
                        mContext.sendBroadcastAsUser(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS),
                                UserHandle.CURRENT);
                    } catch (Exception e) {
                        Log.e(TAG, "Failed to launch intent", e);
                    }
                });
                setOnClickListener(getButtonClickListener(intent));
                if (packageString != null) {
                    mButtonPackages = packageString.split(BUTTON_FILTER_DELIMITER);
                    intent.putExtra(EXTRA_BUTTON_PACKAGES, mButtonPackages);
@@ -215,26 +197,52 @@ public class CarNavigationButton extends LinearLayout {
        try {
            if (mLongIntent != null && (Build.IS_ENG || Build.IS_USERDEBUG)) {
                final Intent intent = Intent.parseUri(mLongIntent, Intent.URI_INTENT_SCHEME);
                setOnLongClickListener(v -> {
                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 -> {
            mContext.sendBroadcastAsUser(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS),
                    UserHandle.CURRENT);
            try {
                if (mBroadcastIntent) {
                    mContext.sendBroadcastAsUser(toSend, UserHandle.CURRENT);
                    return;
                }
                ActivityOptions options = ActivityOptions.makeBasic();
                options.setLaunchDisplayId(mContext.getDisplayId());
                        mContext.startActivityAsUser(intent, options.toBundle(),
                mContext.startActivityAsUser(toSend, options.toBundle(),
                        UserHandle.CURRENT);
            } catch (Exception e) {
                Log.e(TAG, "Failed to launch intent", e);
            }
        };
    }

    /** Defines the behavior of a long click. */
    protected OnLongClickListener getButtonLongClickListener(Intent toSend) {
        return v -> {
            mContext.sendBroadcastAsUser(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS),
                    UserHandle.CURRENT);
            try {
                ActivityOptions options = ActivityOptions.makeBasic();
                options.setLaunchDisplayId(mContext.getDisplayId());
                mContext.startActivityAsUser(toSend, options.toBundle(),
                        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);
        }
        };
    }


    /**
     * Initializes view-related aspects of the button.
     */