Search in sources :

Example 26 with OnCancelListener

use of android.content.DialogInterface.OnCancelListener in project MWM-for-Android-Gen1 by MetaWatchOpenProjects.

the class DeviceSelection method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    context = this;
    pdWait = ProgressDialog.show(this, "Please wait", "Searching Bluetooth devices...");
    pdWait.setCancelable(true);
    pdWait.setOnCancelListener(new OnCancelListener() {

        public void onCancel(DialogInterface dialog) {
            Log.d(MetaWatch.TAG, "canceled");
            if (MetaWatchService.bluetoothAdapter.isDiscovering())
                MetaWatchService.bluetoothAdapter.cancelDiscovery();
            finish();
        }
    });
    pdWait.show();
    setContentView(R.layout.device_selection);
    // constructMenuList();
    listView = (ListView) findViewById(android.R.id.list);
    // listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, menuList));
    listView.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            Log.d(MetaWatch.TAG, "device selected: " + arg2);
            Map<String, String> map = list.get(arg2);
            String mac = map.get("mac");
            Log.d(MetaWatch.TAG, "mac selected: " + mac);
            MetaWatchService.Preferences.watchMacAddress = mac;
            MetaWatchService.saveMac(context, mac);
            sendToast("Selected watch set");
            finish();
        }
    });
    if (MetaWatchService.bluetoothAdapter == null)
        MetaWatchService.bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    Set<BluetoothDevice> pairedDevices = MetaWatchService.bluetoothAdapter.getBondedDevices();
    if (pairedDevices.size() > 0) {
        for (BluetoothDevice device : pairedDevices) {
            addToList(device.getAddress(), device.getName());
        }
    }
    Receiver receiver = new Receiver();
    IntentFilter intentFilter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
    intentFilter.addAction(BluetoothDevice.ACTION_FOUND);
    registerReceiver(receiver, intentFilter);
    MetaWatchService.bluetoothAdapter.startDiscovery();
}
Also used : IntentFilter(android.content.IntentFilter) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) BluetoothDevice(android.bluetooth.BluetoothDevice) DialogInterface(android.content.DialogInterface) BroadcastReceiver(android.content.BroadcastReceiver) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) HashMap(java.util.HashMap) Map(java.util.Map) OnCancelListener(android.content.DialogInterface.OnCancelListener)

Example 27 with OnCancelListener

use of android.content.DialogInterface.OnCancelListener in project smartmodule by carozhu.

the class MyWebChromeHelper method onJsConfirm.

/**
 * 覆盖默认的window.confirm展示界面,避免title里显示为“:来自file:////”
 */
@Override
public boolean onJsConfirm(WebView view, String url, String message, final JsResult result) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(view.getContext());
    builder.setTitle("lizongbo的Android webview测试confirm对话框").setMessage(message).setPositiveButton("确定", new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            result.confirm();
        }
    }).setNeutralButton("取消", new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            result.cancel();
        }
    });
    builder.setOnCancelListener(new OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {
            result.cancel();
        }
    });
    // 屏蔽keycode等于84之类的按键,避免按键后导致对话框消息而页面无法再弹出对话框的问题
    builder.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            Log.v("onJsConfirm", "keyCode==" + keyCode + "event=" + event);
            return true;
        }
    });
    // 禁止响应按back键的事件
    // builder.setCancelable(false);
    AlertDialog dialog = builder.create();
    dialog.show();
    return true;
// return super.onJsConfirm(view, url, message, result);
}
Also used : AlertDialog(android.app.AlertDialog) KeyEvent(android.view.KeyEvent) DialogInterface(android.content.DialogInterface) OnClickListener(android.content.DialogInterface.OnClickListener) OnKeyListener(android.content.DialogInterface.OnKeyListener) OnCancelListener(android.content.DialogInterface.OnCancelListener)

Example 28 with OnCancelListener

use of android.content.DialogInterface.OnCancelListener in project Android-DialogFragments by wada811.

the class AbstractDialogFragment method setOnCancelListener.

protected void setOnCancelListener(Dialog dialog) {
    useOnCancelListener = true;
    dialog.setOnCancelListener(new OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {
            bindCancelListener();
        }
    });
}
Also used : DialogInterface(android.content.DialogInterface) OnCancelListener(android.content.DialogInterface.OnCancelListener)

Example 29 with OnCancelListener

use of android.content.DialogInterface.OnCancelListener in project physical-web by google.

the class BluetoothSite method connect.

/**
 * Connects to the Gatt service of the device to download a web page and displays a progress bar
 * for the title.
 * @param deviceAddress The mac address of the bar
 * @param title The title of the web page being downloaded
 */
public void connect(String deviceAddress, String title) {
    running = true;
    String progressTitle = activity.getString(R.string.page_loading_title) + " " + title;
    progress = new ProgressDialog(activity);
    progress.setCancelable(true);
    progress.setOnCancelListener(new OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialogInterface) {
            Log.i(TAG, "Dialog box canceled");
            close();
        }
    });
    progress.setTitle(progressTitle);
    progress.setMessage(activity.getString(R.string.page_loading_message));
    progress.show();
    activity.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            mBluetoothGatt = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(deviceAddress).connectGatt(activity, false, BluetoothSite.this);
        }
    });
}
Also used : DialogInterface(android.content.DialogInterface) ProgressDialog(android.app.ProgressDialog) OnCancelListener(android.content.DialogInterface.OnCancelListener)

Example 30 with OnCancelListener

use of android.content.DialogInterface.OnCancelListener in project glimmr by brk3.

the class GetRequestToken method onPreExecute.

@Override
protected void onPreExecute() {
    super.onPreExecute();
    mProgressDialog = ProgressDialog.show(mActivity, "", mActivity.getString(R.string.just_a_moment));
    mProgressDialog.setCanceledOnTouchOutside(true);
    mProgressDialog.setCancelable(true);
    mProgressDialog.setOnCancelListener(new OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dlg) {
            GetRequestToken.this.cancel(true);
        }
    });
}
Also used : DialogInterface(android.content.DialogInterface) OnCancelListener(android.content.DialogInterface.OnCancelListener)

Aggregations

OnCancelListener (android.content.DialogInterface.OnCancelListener)58 DialogInterface (android.content.DialogInterface)54 AlertDialog (android.app.AlertDialog)23 OnClickListener (android.content.DialogInterface.OnClickListener)18 View (android.view.View)13 Context (android.content.Context)12 ProgressDialog (android.app.ProgressDialog)11 TextView (android.widget.TextView)11 Intent (android.content.Intent)10 OnDismissListener (android.content.DialogInterface.OnDismissListener)7 Dialog (android.app.Dialog)6 SharedPreferences (android.content.SharedPreferences)6 TypedArray (android.content.res.TypedArray)6 ArrayList (java.util.ArrayList)6 Drawable (android.graphics.drawable.Drawable)5 LocaleList (android.os.LocaleList)5 LayoutInflater (android.view.LayoutInflater)5 InputMethodInfo (android.view.inputmethod.InputMethodInfo)5 InputMethodSubtype (android.view.inputmethod.InputMethodSubtype)5 CompoundButton (android.widget.CompoundButton)5