Android Open Source - PinterestLikeApp Bluetooth Device List Dialog






From Project

Back to project page PinterestLikeApp.

License

The source code is released under:

MIT License

If you think the Android project PinterestLikeApp listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.dreamtale.pintrestlike.widget;
/* ww w  . j  ava 2  s. c  o  m*/
import java.util.Set;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.bluetooth.BluetoothDevice;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;

public class BluetoothDeviceListDialog extends DialogFragment
{
    private Set<BluetoothDevice> devices = null;
    
    private OnItemClickListener onItemClickListener;
    
    interface OnItemClickListener
    {
        void onitemClick(BluetoothDevice device);
    }
    
    public BluetoothDeviceListDialog(Set<BluetoothDevice> items)
    {
        devices = items;
    }
    
    public void setItemClickListener(OnItemClickListener listener)
    {
        onItemClickListener = listener;
    }
    
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState)
    {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setTitle("Pick a device");
        CharSequence[] items = new CharSequence[devices.size()];
        int i = 0;
        for (BluetoothDevice bluetoothDevice : devices)
        {
            items[i++] = bluetoothDevice.getName();
        }
        builder.setItems(items, onClickListener);
        builder.setNegativeButton("cancel", null);
        return builder.create();
    }
    
    private OnClickListener onClickListener = new OnClickListener()
    {
        @Override
        public void onClick(DialogInterface dialog, int which)
        {
            if (null != onItemClickListener)
            {
                int i = 0;
                for (BluetoothDevice device : devices)
                {
                    if (i== which)
                    {
                        onItemClickListener.onitemClick(device);
                        return;
                    }
                    i++;
                }
                onItemClickListener.onitemClick(null);
            }
        }
    };
}




Java Source Code List

com.dreamtale.pintrestlike.activity.BluetoothDeviceListActivity.java
com.dreamtale.pintrestlike.activity.DetailActivity.java
com.dreamtale.pintrestlike.activity.MainActivity.java
com.dreamtale.pintrestlike.activity.WelcomeActivity.java
com.dreamtale.pintrestlike.data.ImageAdapter.java
com.dreamtale.pintrestlike.data.ImageInfoProvider.java
com.dreamtale.pintrestlike.data.ImageInfo.java
com.dreamtale.pintrestlike.fragment.ImageDetailFragment.java
com.dreamtale.pintrestlike.parser.ImageParser.java
com.dreamtale.pintrestlike.share.BluetoothService.java
com.dreamtale.pintrestlike.utils.CacheManager.java
com.dreamtale.pintrestlike.utils.ImageDownloader.java
com.dreamtale.pintrestlike.utils.ImageUtils.java
com.dreamtale.pintrestlike.utils.IntentConstant.java
com.dreamtale.pintrestlike.utils.UIConfig.java
com.dreamtale.pintrestlike.widget.BluetoothDeviceListDialog.java
com.dreamtale.pintrestlike.widget.ItemView.java
com.dreamtale.pintrestlike.widget.PinterestScrollView.java
com.dreamtale.pintrestlike.widget.PintrestGridView.java