Back to project page konashi-android-sdk.
The source code is released under:
Apache License
If you think the Android project konashi-android-sdk listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.uxxu.konashi.lib; // ww w . ja va 2s .c om import android.app.Activity; import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.bluetooth.BluetoothDevice; import android.content.Context; import android.content.DialogInterface; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.AdapterView.OnItemClickListener; /** * ?????????BLE????????????????? * * @author monakaz, YUKAI Engineering * http://konashi.ux-xu.com * ======================================================================== * Copyright 2014 Yukai Engineering Inc. * * 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. * */ public class BleDeviceSelectionDialog implements OnItemClickListener { /** * ???????????????????????????BLE??????????????????????????????????????????????? */ private OnBleDeviceSelectListener mListener; /** * ??????? */ private AlertDialog mDialog; /** * ?konashi??????????????????????????Container */ private LinearLayout mFindingContainer = null; /** * ?konashi??????????????????????????????????????????????????Container */ private LinearLayout mNotFoundContainer = null; /** * ??????BLE???????????Adapter */ private BleDeviceListAdapter mAdapter; /** * ??????? * * @param adapter ??????BLE???????????Adapter * @param listener ???????????????????????????BLE?????????????????????????????????????????????? */ public BleDeviceSelectionDialog(BleDeviceListAdapter adapter, OnBleDeviceSelectListener listener){ mListener = listener; mAdapter = adapter; } /** * BLE??????????????????????? * @param activity ????????????????Activity */ public void show(Activity activity){ View view = LayoutInflater.from(activity).inflate(R.layout.dialog_device_list, null); ListView listView = (ListView)view.findViewById(R.id.konashi_lib_list); listView.setScrollingCacheEnabled(false); listView.setOnItemClickListener(this); listView.setAdapter(mAdapter); mFindingContainer = (LinearLayout)view.findViewById(R.id.konashi_lib_finding); mNotFoundContainer = (LinearLayout)view.findViewById(R.id.konashi_lib_not_found); Builder builder = new AlertDialog.Builder(activity); builder.setTitle(activity.getString(R.string.konashi_lib_dialog_device_list_title)); builder.setView(view); builder.setPositiveButton(activity.getString(R.string.konashi_lib_dialog_device_list_cancel_button), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if(mListener!=null){ mListener.onCancelSelectingBleDevice(); } } }); builder.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if(mListener!=null){ mListener.onCancelSelectingBleDevice(); } } }); mDialog = builder.show(); startFinding(); } /** * ?konashi???????????????????????????konashi??????????????????????????????????????????????????????? */ public void startFinding(){ if(mFindingContainer!=null){ mFindingContainer.setVisibility(View.VISIBLE); } if(mNotFoundContainer!=null){ mNotFoundContainer.setVisibility(View.GONE); } } /** * ?konashi??????????????????????????????konashi???????????????????????????????????????????????????? */ public void finishFinding(){ if(mFindingContainer!=null){ mFindingContainer.setVisibility(View.GONE); } if(mAdapter.getCount()==0 && mNotFoundContainer!=null){ mNotFoundContainer.setVisibility(View.VISIBLE); } } /** * ???????BLE???????????????????? * * @param adapterView AdapterView(?????????????) * @param view View??????????????) * @param position ???????????BLE?????????????? * @param id ??????BLE????????ID */ @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) { KonashiUtils.log("onItemClick"); if(mDialog!=null){ // Hide dialog mDialog.dismiss(); mDialog = null; } if(mListener!=null){ mListener.onSelectBleDevice(mAdapter.getDevice(position)); } } /** * ?????????BLE?????????????????????????????????????????????????????????????? */ public interface OnBleDeviceSelectListener { /** * BLE??????????????????????????????BLE???????????????????? * @param device ???????????BLE??????????? */ public void onSelectBleDevice(BluetoothDevice device); /** * BLE?????????????????????????????????? */ public void onCancelSelectingBleDevice(); } }