Loading src/com/android/bluetooth/AlertActivity.java 0 → 100644 +115 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 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 android.bluetooth; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; import android.os.Bundle; import android.view.ViewGroup; import android.view.Window; import android.view.accessibility.AccessibilityEvent; /** * An activity that follows the visual style of an AlertDialog. * * @see #mAlert * @see #setupAlert() */ public abstract class AlertActivity extends Activity implements DialogInterface.OnDismissListener, DialogInterface.OnCancelListener { /** * The model for the alert. * */ protected AlertDialog.Builder mAlertBuilder; private AlertDialog mAlert; public AlertActivity() {} @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); mAlertBuilder = new AlertDialog.Builder(this); mAlertBuilder.setOnDismissListener(this); mAlertBuilder.setOnCancelListener(this); } @Override public void onDismiss(DialogInterface dialog) { if (!isFinishing()) { finish(); } } @Override public void onCancel(DialogInterface dialog) { if (!isFinishing()) { finish(); } } @Override public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { return dispatchPopulateAccessibilityEvent(this, event); } private static boolean dispatchPopulateAccessibilityEvent(Activity act, AccessibilityEvent event) { event.setClassName(Dialog.class.getName()); event.setPackageName(act.getPackageName()); ViewGroup.LayoutParams params = act.getWindow().getAttributes(); boolean isFullScreen = (params.width == ViewGroup.LayoutParams.MATCH_PARENT) && (params.height == ViewGroup.LayoutParams.MATCH_PARENT); event.setFullScreen(isFullScreen); return false; } protected void setupAlert() { mAlert = mAlertBuilder.create(); mAlert.show(); } protected void changeIconAttribute(int attrId) { if (mAlert == null) return; mAlert.setIconAttribute(attrId); } protected void changeTitle(CharSequence title) { if (mAlert == null) return; mAlert.setTitle(title); } protected void changeButtonVisibility(int identifier, int visibility) { if (mAlert == null) return; mAlert.getButton(identifier).setVisibility(visibility); } protected void changeButtonText(int identifier, CharSequence text) { if (mAlert == null) return; mAlert.getButton(identifier).setText(text); } protected void changeButtonEnabled(int identifier, boolean enable) { if (mAlert == null) return; mAlert.getButton(identifier).setEnabled(enable); } } src/com/android/bluetooth/opp/BluetoothOppBtEnableActivity.java +7 −10 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ package com.android.bluetooth.opp; import android.bluetooth.AlertActivity; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; Loading @@ -40,8 +41,6 @@ import android.widget.TextView; import android.widget.Toast; import com.android.bluetooth.R; import com.android.internal.app.AlertActivity; import com.android.internal.app.AlertController; /** * This class is designed to show BT enable confirmation dialog; Loading @@ -57,14 +56,12 @@ public class BluetoothOppBtEnableActivity extends AlertActivity // Set up the "dialog" mOppManager = BluetoothOppManager.getInstance(this); mOppManager.mSendingFlag = false; final AlertController.AlertParams p = mAlertParams; p.mIconAttrId = android.R.attr.alertDialogIcon; p.mTitle = getString(R.string.bt_enable_title); p.mView = createView(); p.mPositiveButtonText = getString(R.string.bt_enable_ok); p.mPositiveButtonListener = this; p.mNegativeButtonText = getString(R.string.bt_enable_cancel); p.mNegativeButtonListener = this; 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); setupAlert(); } Loading src/com/android/bluetooth/opp/BluetoothOppBtEnablingActivity.java +3 −6 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ package com.android.bluetooth.opp; import android.bluetooth.AlertActivity; import android.bluetooth.BluetoothAdapter; import android.content.BroadcastReceiver; import android.content.Context; Loading @@ -46,8 +47,6 @@ import android.view.View; import android.widget.TextView; import com.android.bluetooth.R; import com.android.internal.app.AlertActivity; import com.android.internal.app.AlertController; /** * This class is designed to show BT enabling progress. Loading Loading @@ -80,10 +79,8 @@ public class BluetoothOppBtEnablingActivity extends AlertActivity { registerReceiver(mBluetoothReceiver, filter); mRegistered = true; // Set up the "dialog" final AlertController.AlertParams p = mAlertParams; p.mTitle = getString(R.string.enabling_progress_title); p.mView = createView(); mAlertBuilder.setTitle(R.string.enabling_progress_title); mAlertBuilder.setView(createView()); setupAlert(); // Add timeout for enabling progress Loading src/com/android/bluetooth/opp/BluetoothOppBtErrorActivity.java +9 −14 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ package com.android.bluetooth.opp; import android.bluetooth.AlertActivity; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; Loading @@ -39,8 +40,6 @@ import android.view.View; import android.widget.TextView; import com.android.bluetooth.R; import com.android.internal.app.AlertActivity; import com.android.internal.app.AlertController; /** * This class is designed to show BT error messages; Loading @@ -48,30 +47,26 @@ import com.android.internal.app.AlertController; public class BluetoothOppBtErrorActivity extends AlertActivity implements DialogInterface.OnClickListener { private String mErrorContent; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = getIntent(); String mErrorTitle = intent.getStringExtra("title"); mErrorContent = intent.getStringExtra("content"); String errorTitle = intent.getStringExtra("title"); String errorContent = intent.getStringExtra("content"); // Set up the "dialog" final AlertController.AlertParams p = mAlertParams; p.mIconAttrId = android.R.attr.alertDialogIcon; p.mTitle = mErrorTitle; p.mView = createView(); p.mPositiveButtonText = getString(R.string.bt_error_btn_ok); p.mPositiveButtonListener = this; mAlertBuilder.setIconAttribute(android.R.attr.alertDialogIcon); mAlertBuilder.setTitle(errorTitle); mAlertBuilder.setView(createView(errorContent)); mAlertBuilder.setPositiveButton(R.string.bt_error_btn_ok, this); setupAlert(); } private View createView() { private View createView(String errorContent) { View view = getLayoutInflater().inflate(R.layout.confirm_dialog, null); TextView contentView = (TextView) view.findViewById(R.id.content); contentView.setText(mErrorContent); contentView.setText(errorContent); return view; } Loading src/com/android/bluetooth/opp/BluetoothOppIncomingFileConfirmActivity.java +14 −15 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ package com.android.bluetooth.opp; import android.bluetooth.AlertActivity; import android.content.BroadcastReceiver; import android.content.ContentValues; import android.content.Context; Loading @@ -50,8 +51,6 @@ import android.widget.TextView; import android.widget.Toast; import com.android.bluetooth.R; import com.android.internal.app.AlertActivity; import com.android.internal.app.AlertController; /** * This class is designed to ask user to confirm if accept incoming file; Loading Loading @@ -106,14 +105,11 @@ public class BluetoothOppIncomingFileConfirmActivity extends AlertActivity return; } // Set up the "dialog" final AlertController.AlertParams p = mAlertParams; p.mTitle = getString(R.string.incoming_file_confirm_content); p.mView = createView(); p.mPositiveButtonText = getString(R.string.incoming_file_confirm_ok); p.mPositiveButtonListener = this; p.mNegativeButtonText = getString(R.string.incoming_file_confirm_cancel); p.mNegativeButtonListener = this; 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); setupAlert(); if (V) { Log.v(TAG, "mTimeout: " + mTimeout); Loading Loading @@ -207,11 +203,14 @@ public class BluetoothOppIncomingFileConfirmActivity extends AlertActivity private void onTimeout() { mTimeout = true; mAlert.setTitle( getString(R.string.incoming_file_confirm_timeout_content, mTransInfo.mDeviceName)); mAlert.getButton(DialogInterface.BUTTON_NEGATIVE).setVisibility(View.GONE); mAlert.getButton(DialogInterface.BUTTON_POSITIVE) .setText(getString(R.string.incoming_file_confirm_timeout_ok)); changeTitle(getString( R.string.incoming_file_confirm_timeout_content, mTransInfo.mDeviceName)); changeButtonVisibility(DialogInterface.BUTTON_NEGATIVE, View.GONE); changeButtonText( DialogInterface.BUTTON_POSITIVE, getString(R.string.incoming_file_confirm_timeout_ok)); mTimeoutHandler.sendMessageDelayed(mTimeoutHandler.obtainMessage(DISMISS_TIMEOUT_DIALOG), DISMISS_TIMEOUT_DIALOG_VALUE); Loading Loading
src/com/android/bluetooth/AlertActivity.java 0 → 100644 +115 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 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 android.bluetooth; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; import android.os.Bundle; import android.view.ViewGroup; import android.view.Window; import android.view.accessibility.AccessibilityEvent; /** * An activity that follows the visual style of an AlertDialog. * * @see #mAlert * @see #setupAlert() */ public abstract class AlertActivity extends Activity implements DialogInterface.OnDismissListener, DialogInterface.OnCancelListener { /** * The model for the alert. * */ protected AlertDialog.Builder mAlertBuilder; private AlertDialog mAlert; public AlertActivity() {} @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); mAlertBuilder = new AlertDialog.Builder(this); mAlertBuilder.setOnDismissListener(this); mAlertBuilder.setOnCancelListener(this); } @Override public void onDismiss(DialogInterface dialog) { if (!isFinishing()) { finish(); } } @Override public void onCancel(DialogInterface dialog) { if (!isFinishing()) { finish(); } } @Override public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { return dispatchPopulateAccessibilityEvent(this, event); } private static boolean dispatchPopulateAccessibilityEvent(Activity act, AccessibilityEvent event) { event.setClassName(Dialog.class.getName()); event.setPackageName(act.getPackageName()); ViewGroup.LayoutParams params = act.getWindow().getAttributes(); boolean isFullScreen = (params.width == ViewGroup.LayoutParams.MATCH_PARENT) && (params.height == ViewGroup.LayoutParams.MATCH_PARENT); event.setFullScreen(isFullScreen); return false; } protected void setupAlert() { mAlert = mAlertBuilder.create(); mAlert.show(); } protected void changeIconAttribute(int attrId) { if (mAlert == null) return; mAlert.setIconAttribute(attrId); } protected void changeTitle(CharSequence title) { if (mAlert == null) return; mAlert.setTitle(title); } protected void changeButtonVisibility(int identifier, int visibility) { if (mAlert == null) return; mAlert.getButton(identifier).setVisibility(visibility); } protected void changeButtonText(int identifier, CharSequence text) { if (mAlert == null) return; mAlert.getButton(identifier).setText(text); } protected void changeButtonEnabled(int identifier, boolean enable) { if (mAlert == null) return; mAlert.getButton(identifier).setEnabled(enable); } }
src/com/android/bluetooth/opp/BluetoothOppBtEnableActivity.java +7 −10 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ package com.android.bluetooth.opp; import android.bluetooth.AlertActivity; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; Loading @@ -40,8 +41,6 @@ import android.widget.TextView; import android.widget.Toast; import com.android.bluetooth.R; import com.android.internal.app.AlertActivity; import com.android.internal.app.AlertController; /** * This class is designed to show BT enable confirmation dialog; Loading @@ -57,14 +56,12 @@ public class BluetoothOppBtEnableActivity extends AlertActivity // Set up the "dialog" mOppManager = BluetoothOppManager.getInstance(this); mOppManager.mSendingFlag = false; final AlertController.AlertParams p = mAlertParams; p.mIconAttrId = android.R.attr.alertDialogIcon; p.mTitle = getString(R.string.bt_enable_title); p.mView = createView(); p.mPositiveButtonText = getString(R.string.bt_enable_ok); p.mPositiveButtonListener = this; p.mNegativeButtonText = getString(R.string.bt_enable_cancel); p.mNegativeButtonListener = this; 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); setupAlert(); } Loading
src/com/android/bluetooth/opp/BluetoothOppBtEnablingActivity.java +3 −6 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ package com.android.bluetooth.opp; import android.bluetooth.AlertActivity; import android.bluetooth.BluetoothAdapter; import android.content.BroadcastReceiver; import android.content.Context; Loading @@ -46,8 +47,6 @@ import android.view.View; import android.widget.TextView; import com.android.bluetooth.R; import com.android.internal.app.AlertActivity; import com.android.internal.app.AlertController; /** * This class is designed to show BT enabling progress. Loading Loading @@ -80,10 +79,8 @@ public class BluetoothOppBtEnablingActivity extends AlertActivity { registerReceiver(mBluetoothReceiver, filter); mRegistered = true; // Set up the "dialog" final AlertController.AlertParams p = mAlertParams; p.mTitle = getString(R.string.enabling_progress_title); p.mView = createView(); mAlertBuilder.setTitle(R.string.enabling_progress_title); mAlertBuilder.setView(createView()); setupAlert(); // Add timeout for enabling progress Loading
src/com/android/bluetooth/opp/BluetoothOppBtErrorActivity.java +9 −14 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ package com.android.bluetooth.opp; import android.bluetooth.AlertActivity; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; Loading @@ -39,8 +40,6 @@ import android.view.View; import android.widget.TextView; import com.android.bluetooth.R; import com.android.internal.app.AlertActivity; import com.android.internal.app.AlertController; /** * This class is designed to show BT error messages; Loading @@ -48,30 +47,26 @@ import com.android.internal.app.AlertController; public class BluetoothOppBtErrorActivity extends AlertActivity implements DialogInterface.OnClickListener { private String mErrorContent; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = getIntent(); String mErrorTitle = intent.getStringExtra("title"); mErrorContent = intent.getStringExtra("content"); String errorTitle = intent.getStringExtra("title"); String errorContent = intent.getStringExtra("content"); // Set up the "dialog" final AlertController.AlertParams p = mAlertParams; p.mIconAttrId = android.R.attr.alertDialogIcon; p.mTitle = mErrorTitle; p.mView = createView(); p.mPositiveButtonText = getString(R.string.bt_error_btn_ok); p.mPositiveButtonListener = this; mAlertBuilder.setIconAttribute(android.R.attr.alertDialogIcon); mAlertBuilder.setTitle(errorTitle); mAlertBuilder.setView(createView(errorContent)); mAlertBuilder.setPositiveButton(R.string.bt_error_btn_ok, this); setupAlert(); } private View createView() { private View createView(String errorContent) { View view = getLayoutInflater().inflate(R.layout.confirm_dialog, null); TextView contentView = (TextView) view.findViewById(R.id.content); contentView.setText(mErrorContent); contentView.setText(errorContent); return view; } Loading
src/com/android/bluetooth/opp/BluetoothOppIncomingFileConfirmActivity.java +14 −15 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ package com.android.bluetooth.opp; import android.bluetooth.AlertActivity; import android.content.BroadcastReceiver; import android.content.ContentValues; import android.content.Context; Loading @@ -50,8 +51,6 @@ import android.widget.TextView; import android.widget.Toast; import com.android.bluetooth.R; import com.android.internal.app.AlertActivity; import com.android.internal.app.AlertController; /** * This class is designed to ask user to confirm if accept incoming file; Loading Loading @@ -106,14 +105,11 @@ public class BluetoothOppIncomingFileConfirmActivity extends AlertActivity return; } // Set up the "dialog" final AlertController.AlertParams p = mAlertParams; p.mTitle = getString(R.string.incoming_file_confirm_content); p.mView = createView(); p.mPositiveButtonText = getString(R.string.incoming_file_confirm_ok); p.mPositiveButtonListener = this; p.mNegativeButtonText = getString(R.string.incoming_file_confirm_cancel); p.mNegativeButtonListener = this; 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); setupAlert(); if (V) { Log.v(TAG, "mTimeout: " + mTimeout); Loading Loading @@ -207,11 +203,14 @@ public class BluetoothOppIncomingFileConfirmActivity extends AlertActivity private void onTimeout() { mTimeout = true; mAlert.setTitle( getString(R.string.incoming_file_confirm_timeout_content, mTransInfo.mDeviceName)); mAlert.getButton(DialogInterface.BUTTON_NEGATIVE).setVisibility(View.GONE); mAlert.getButton(DialogInterface.BUTTON_POSITIVE) .setText(getString(R.string.incoming_file_confirm_timeout_ok)); changeTitle(getString( R.string.incoming_file_confirm_timeout_content, mTransInfo.mDeviceName)); changeButtonVisibility(DialogInterface.BUTTON_NEGATIVE, View.GONE); changeButtonText( DialogInterface.BUTTON_POSITIVE, getString(R.string.incoming_file_confirm_timeout_ok)); mTimeoutHandler.sendMessageDelayed(mTimeoutHandler.obtainMessage(DISMISS_TIMEOUT_DIALOG), DISMISS_TIMEOUT_DIALOG_VALUE); Loading