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

Commit 9fe3adc6 authored by Jakub Pawlowski's avatar Jakub Pawlowski
Browse files

Use lambdas instead of onClick callbacks

Found this pattern in permission controller, looks pretty.

Test: compilation
Change-Id: If65159213caf79831b60112de41f56e9bedb2ad4
parent ecf3381a
Loading
Loading
Loading
Loading
+13 −23
Original line number Diff line number Diff line
@@ -33,7 +33,6 @@
package com.android.bluetooth.opp;

import android.bluetooth.AlertActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
@@ -45,8 +44,7 @@ import com.android.bluetooth.R;
/**
 * This class is designed to show BT enable confirmation dialog;
 */
public class BluetoothOppBtEnableActivity extends AlertActivity
        implements DialogInterface.OnClickListener {
public class BluetoothOppBtEnableActivity extends AlertActivity {
    private BluetoothOppManager mOppManager;

    @Override
@@ -60,8 +58,9 @@ public class BluetoothOppBtEnableActivity extends AlertActivity
        mAlertBuilder.setIconAttribute(android.R.attr.alertDialogIcon);
        mAlertBuilder.setTitle(getString(R.string.bt_enable_title));
        mAlertBuilder.setView(createView());
        mAlertBuilder.setPositiveButton(R.string.bt_enable_ok, this);
        mAlertBuilder.setNegativeButton(R.string.bt_enable_cancel, this);
        mAlertBuilder.setPositiveButton(R.string.bt_enable_ok,
                (dialog, which) -> onEnableBluetooth());
        mAlertBuilder.setNegativeButton(R.string.bt_enable_cancel, (dialog, which) -> finish());
        setupAlert();
    }

@@ -75,10 +74,7 @@ public class BluetoothOppBtEnableActivity extends AlertActivity
        return view;
    }

    @Override
    public void onClick(DialogInterface dialog, int which) {
        switch (which) {
            case DialogInterface.BUTTON_POSITIVE:
    private void onEnableBluetooth() {
        mOppManager.enableBluetooth(); // this is an asyn call
        mOppManager.mSendingFlag = true;

@@ -90,12 +86,6 @@ public class BluetoothOppBtEnableActivity extends AlertActivity
        this.startActivity(in);

        finish();
                break;

            case DialogInterface.BUTTON_NEGATIVE:
                finish();
                break;
        }
    }

    @Override
+2 −11
Original line number Diff line number Diff line
@@ -33,7 +33,6 @@
package com.android.bluetooth.opp;

import android.bluetooth.AlertActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
@@ -44,8 +43,7 @@ import com.android.bluetooth.R;
/**
 * This class is designed to show BT error messages;
 */
public class BluetoothOppBtErrorActivity extends AlertActivity
        implements DialogInterface.OnClickListener {
public class BluetoothOppBtErrorActivity extends AlertActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
@@ -59,7 +57,7 @@ public class BluetoothOppBtErrorActivity extends AlertActivity
        mAlertBuilder.setIconAttribute(android.R.attr.alertDialogIcon);
        mAlertBuilder.setTitle(errorTitle);
        mAlertBuilder.setView(createView(errorContent));
        mAlertBuilder.setPositiveButton(R.string.bt_error_btn_ok, this);
        mAlertBuilder.setPositiveButton(R.string.bt_error_btn_ok, (dialog, which) -> {});
        setupAlert();
    }

@@ -70,11 +68,4 @@ public class BluetoothOppBtErrorActivity extends AlertActivity
        return view;
    }

    @Override
    public void onClick(DialogInterface dialog, int which) {
        switch (which) {
            case DialogInterface.BUTTON_POSITIVE:
                break;
        }
    }
}
+22 −26
Original line number Diff line number Diff line
@@ -55,8 +55,7 @@ import com.android.bluetooth.R;
/**
 * This class is designed to ask user to confirm if accept incoming file;
 */
public class BluetoothOppIncomingFileConfirmActivity extends AlertActivity
        implements DialogInterface.OnClickListener {
public class BluetoothOppIncomingFileConfirmActivity extends AlertActivity {
    private static final String TAG = "BluetoothIncomingFileConfirmActivity";
    private static final boolean D = Constants.DEBUG;
    private static final boolean V = Constants.VERBOSE;
@@ -107,8 +106,10 @@ public class BluetoothOppIncomingFileConfirmActivity extends AlertActivity

        mAlertBuilder.setTitle(getString(R.string.incoming_file_confirm_content));
        mAlertBuilder.setView(createView());
        mAlertBuilder.setPositiveButton(R.string.incoming_file_confirm_ok, this);
        mAlertBuilder.setNegativeButton(R.string.incoming_file_confirm_cancel, this);
        mAlertBuilder.setPositiveButton(R.string.incoming_file_confirm_ok,
                (dialog, which) -> onIncomingFileConfirmOk());
        mAlertBuilder.setNegativeButton(R.string.incoming_file_confirm_cancel,
                (dialog, which) -> onIncomingFileConfirmCancel());

        setupAlert();
        if (V) {
@@ -137,10 +138,7 @@ public class BluetoothOppIncomingFileConfirmActivity extends AlertActivity
        return view;
    }

    @Override
    public void onClick(DialogInterface dialog, int which) {
        switch (which) {
            case DialogInterface.BUTTON_POSITIVE:
    private void onIncomingFileConfirmOk() {
        if (!mTimeout) {
            // Update database
            mUpdateValues = new ContentValues();
@@ -150,16 +148,14 @@ public class BluetoothOppIncomingFileConfirmActivity extends AlertActivity

            Toast.makeText(this, getString(R.string.bt_toast_1), Toast.LENGTH_SHORT).show();
        }
                break;
    }

            case DialogInterface.BUTTON_NEGATIVE:
    private void onIncomingFileConfirmCancel() {
        // Update database
        mUpdateValues = new ContentValues();
        mUpdateValues.put(BluetoothShare.USER_CONFIRMATION,
                BluetoothShare.USER_CONFIRMATION_DENIED);
        this.getContentResolver().update(mUri, mUpdateValues, null, null);
                break;
        }
    }

    @Override
+9 −22
Original line number Diff line number Diff line
@@ -59,8 +59,7 @@ import com.android.bluetooth.R;
 * remote Bluetooth device.
 */
public class BluetoothPbapActivity extends AlertActivity
        implements DialogInterface.OnClickListener, Preference.OnPreferenceChangeListener,
        TextWatcher {
        implements Preference.OnPreferenceChangeListener, TextWatcher {
    private static final String TAG = "BluetoothPbapActivity";

    private static final boolean V = BluetoothPbapService.VERBOSE;
@@ -122,8 +121,10 @@ public class BluetoothPbapActivity extends AlertActivity
            case DIALOG_YES_NO_AUTH:
                mAlertBuilder.setTitle(getString(R.string.pbap_session_key_dialog_header));
                mAlertBuilder.setView(createView(DIALOG_YES_NO_AUTH));
                mAlertBuilder.setPositiveButton(android.R.string.ok, this);
                mAlertBuilder.setNegativeButton(android.R.string.cancel, this);
                mAlertBuilder.setPositiveButton(android.R.string.ok,
                        (dialog, which) -> onPositive());
                mAlertBuilder.setNegativeButton(android.R.string.cancel,
                        (dialog, which) -> onNegative());
                setupAlert();
                changeButtonEnabled(DialogInterface.BUTTON_POSITIVE, false);
                break;
@@ -160,6 +161,10 @@ public class BluetoothPbapActivity extends AlertActivity
    }

    private void onPositive() {
        if (mCurrentDialog == DIALOG_YES_NO_AUTH) {
            mSessionKey = mKeyView.getText().toString();
        }

        if (!mTimeout) {
            if (mCurrentDialog == DIALOG_YES_NO_AUTH) {
                sendIntentToReceiver(BluetoothPbapService.AUTH_RESPONSE_ACTION,
@@ -190,24 +195,6 @@ public class BluetoothPbapActivity extends AlertActivity
        sendBroadcast(intent);
    }

    @Override
    public void onClick(DialogInterface dialog, int which) {
        switch (which) {
            case DialogInterface.BUTTON_POSITIVE:
                if (mCurrentDialog == DIALOG_YES_NO_AUTH) {
                    mSessionKey = mKeyView.getText().toString();
                }
                onPositive();
                break;

            case DialogInterface.BUTTON_NEGATIVE:
                onNegative();
                break;
            default:
                break;
        }
    }

    private void onTimeout() {
        mTimeout = true;
        if (mCurrentDialog == DIALOG_YES_NO_AUTH) {