Commit 54631d6c by onuma

#47941 HW連携 @FormからBluetoothのソースを移植 続き

parent 79136c8b
...@@ -183,4 +183,14 @@ public class Constant { ...@@ -183,4 +183,14 @@ public class Constant {
int CloseCameraActivity = 0; int CloseCameraActivity = 0;
int ThetaConnectError = 1; int ThetaConnectError = 1;
} }
// 連携機器の区分
public interface DeviceType {
int centerThermomete = 1; // 中心温度計
int sensor = 2; // 置くだけセンサー
int barcode = 3; // バーコード
int radiationThermomete = 4; // 放射温度計
int sppBluetoothMachine = 5; // SPP通信機器
int nfc = 6; // nfc機器
}
} }
package jp.agentec.abook.abv.bl.dto;
/**
* bluetoothペアリング情報を扱うDto
* デバイス名、デバイスアドレス
*/
public class BluetoothPairingDeviceInfoDto {
/** デバイス名 */
public String deviceName;
/** デバイスアドレス*/
public String deviceAddress;
/** デバイスタイプ*/
public Integer deviceType;
}
...@@ -2,8 +2,10 @@ package jp.agentec.abook.abv.launcher.android; ...@@ -2,8 +2,10 @@ package jp.agentec.abook.abv.launcher.android;
import java.util.ArrayList; import java.util.ArrayList;
import jp.agentec.abook.abv.bl.common.Constant;
import jp.agentec.abook.abv.bl.common.Constant.ReportType; import jp.agentec.abook.abv.bl.common.Constant.ReportType;
import jp.agentec.abook.abv.bl.common.log.Logger; import jp.agentec.abook.abv.bl.common.log.Logger;
import jp.agentec.abook.abv.bl.dto.BluetoothPairingDeviceInfoDto;
import jp.agentec.abook.abv.bl.dto.OperationGroupMasterDto; import jp.agentec.abook.abv.bl.dto.OperationGroupMasterDto;
import jp.agentec.abook.abv.cl.util.PreferenceUtil; import jp.agentec.abook.abv.cl.util.PreferenceUtil;
import jp.agentec.abook.abv.ui.common.appinfo.AppDefType; import jp.agentec.abook.abv.ui.common.appinfo.AppDefType;
...@@ -179,4 +181,111 @@ public class ABVUIDataCache { ...@@ -179,4 +181,111 @@ public class ABVUIDataCache {
returnContentIdList.clear(); returnContentIdList.clear();
} }
} }
/**
* アプリ内で保存されてるbluetoothのペアリング情報の
* BluetoothPairingDeviceInfoDtoで返す。
*
* 情報が存在しない場合はnullで返す。
*
* @param bluetoothDeviceType 取得するbluetoothのデバイスタイプ
* @return BluetoothPairingDeviceInfoDto ペアリング情報
*/
public BluetoothPairingDeviceInfoDto getPairingBluetoothDeviceInfo(int bluetoothDeviceType) {
BluetoothPairingDeviceInfoDto dto = new BluetoothPairingDeviceInfoDto();
String deviceName = null;
String deviceAddress = null;
if (bluetoothDeviceType == Constant.DeviceType.centerThermomete) {
// 中心温度計
deviceName = PreferenceUtil.getUserPref(context, UserPrefKey.BLE_DEVICE_CENTER_TEMPERATURE_NAME, "");
deviceAddress = PreferenceUtil.getUserPref(context, UserPrefKey.BLE_DEVICE_CENTER_TEMPERATURE_ADDRESS, "");
} else if (bluetoothDeviceType == Constant.DeviceType.radiationThermomete) {
// 放射温度計
deviceName = PreferenceUtil.getUserPref(context, UserPrefKey.BLE_DEVICE_RADIATION_TEMPERATURE_NAME, "");
deviceAddress = PreferenceUtil.getUserPref(context, UserPrefKey.BLE_DEVICE_RADIATION_TEMPERATURE_ADDRESS, "");
}
// deviceNameとdeviceAddressがセットなので、どっちかの値が存在しないとnullで返す。
if (StringUtil.isNullOrEmpty(deviceName) || StringUtil.isNullOrEmpty(deviceAddress)) {
return null;
}
dto.deviceName = deviceName;
dto.deviceAddress = deviceAddress;
dto.deviceType = bluetoothDeviceType;
return dto;
}
/**
* 引数のデバイスタイプでローカルに保存されてるbluetoothのデバイスアドレス取得
* @param bluetoothDeviceType
* @return
*/
public String getPairingBluetoothDeviceAddress(int bluetoothDeviceType) {
String deviceAddressKey = null;
if (bluetoothDeviceType == Constant.DeviceType.centerThermomete) {
deviceAddressKey = UserPrefKey.BLE_DEVICE_CENTER_TEMPERATURE_ADDRESS;
} else if (bluetoothDeviceType == Constant.DeviceType.radiationThermomete) {
deviceAddressKey = UserPrefKey.BLE_DEVICE_RADIATION_TEMPERATURE_ADDRESS;
}
if (deviceAddressKey == null) {
// 引数のデバイスタイプが定義した以外の値が入った場合
return null;
}
return PreferenceUtil.getUserPref(context, deviceAddressKey, "");
}
/**
* 引数であるデバイスタイプリストに対するアプリ内で保存されてる
* bluetoothのペアリング情報リストを返す。
* @param deviceTypeList
* @return List<BluetoothPairingDeviceInfoDto> ペアリング情報リスト
*/
public List<BluetoothPairingDeviceInfoDto> getPairingBluetoothDeviceInfoList(List<Integer> deviceTypeList) {
List<BluetoothPairingDeviceInfoDto> bluetoothPairingDeviceInfoDtoList = new ArrayList<BluetoothPairingDeviceInfoDto>();
for (Integer deviceType : deviceTypeList) {
// 引数のデバイスタイプのリスト全部を1つずつデータ取得
BluetoothPairingDeviceInfoDto dto = getPairingBluetoothDeviceInfo(deviceType);
if (dto != null) {
// dtoがnullではない場合のみリストに追加
bluetoothPairingDeviceInfoDtoList.add(dto);
}
}
return bluetoothPairingDeviceInfoDtoList;
}
/**
* ペアリング情報をローカルに保存する
* deviceType毎に保存するキーが異なる
* @param pairingDeviceInfoDto
*/
public void setPairingBluetoothDeviceInfo(BluetoothPairingDeviceInfoDto pairingDeviceInfoDto) {
if (pairingDeviceInfoDto.deviceType.equals(Constant.DeviceType.centerThermomete)) {
// 中心温度計
PreferenceUtil.putUserPref(context, UserPrefKey.BLE_DEVICE_CENTER_TEMPERATURE_NAME, pairingDeviceInfoDto.deviceName);
PreferenceUtil.putUserPref(context, UserPrefKey.BLE_DEVICE_CENTER_TEMPERATURE_ADDRESS, pairingDeviceInfoDto.deviceAddress);
} else if (pairingDeviceInfoDto.deviceType.equals(Constant.DeviceType.radiationThermomete)) {
// 放射温度計
PreferenceUtil.putUserPref(context, UserPrefKey.BLE_DEVICE_RADIATION_TEMPERATURE_NAME, pairingDeviceInfoDto.deviceName);
PreferenceUtil.putUserPref(context, UserPrefKey.BLE_DEVICE_RADIATION_TEMPERATURE_ADDRESS, pairingDeviceInfoDto.deviceAddress);
}
}
/**
* 引数であるデバイスタイプの
* ペアリング情報を削除する
* @param deviceType
*/
public void removePairingBluetoothDeviceInfo(int deviceType) {
if (deviceType == Constant.DeviceType.centerThermomete) {
// 中心温度計
PreferenceUtil.removeUserPref(context, UserPrefKey.BLE_DEVICE_CENTER_TEMPERATURE_NAME);
PreferenceUtil.removeUserPref(context, UserPrefKey.BLE_DEVICE_CENTER_TEMPERATURE_ADDRESS);
} else if (deviceType == Constant.DeviceType.radiationThermomete) {
// 放射温度計
PreferenceUtil.removeUserPref(context, UserPrefKey.BLE_DEVICE_RADIATION_TEMPERATURE_NAME);
PreferenceUtil.removeUserPref(context, UserPrefKey.BLE_DEVICE_RADIATION_TEMPERATURE_ADDRESS);
}
}
} }
...@@ -65,6 +65,14 @@ public interface AppDefType { ...@@ -65,6 +65,14 @@ public interface AppDefType {
String RESOURCE_PATTERN_TYPE = "resourcePatternType"; // 文言リソースパターン String RESOURCE_PATTERN_TYPE = "resourcePatternType"; // 文言リソースパターン
// 中心温度計
String BLE_DEVICE_CENTER_TEMPERATURE_NAME = "bleDeviceCenterTemperatureName"; // 中心温度計機器の名
String BLE_DEVICE_CENTER_TEMPERATURE_ADDRESS = "bleDeviceCenterTemperatureAddress"; // 中心温度計機器のアドレス
// 放射温度計
String BLE_DEVICE_RADIATION_TEMPERATURE_NAME = "bleDeviceRadiationTemperatureName"; // 放射温度計機器の名
String BLE_DEVICE_RADIATION_TEMPERATURE_ADDRESS = "bleDeviceRadiationTemperatureAddress"; // 放射温度計機器のアドレス
String OPERATION_GROUP_MASERT_MODE = "operation_group_master"; // 通常・作業種別モード(画面) String OPERATION_GROUP_MASERT_MODE = "operation_group_master"; // 通常・作業種別モード(画面)
String OPERATION_GROUP_MASERT_ID = "operation_group_master_id"; // 作業種別のID String OPERATION_GROUP_MASERT_ID = "operation_group_master_id"; // 作業種別のID
......
...@@ -24,11 +24,16 @@ import java.util.Arrays; ...@@ -24,11 +24,16 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import jp.agentec.abook.abv.bl.common.Constant; import jp.agentec.abook.abv.bl.common.Constant;
import jp.agentec.abook.abv.bl.common.Constant.DeviceType;
import jp.agentec.abook.abv.bl.common.log.Logger; import jp.agentec.abook.abv.bl.common.log.Logger;
import jp.agentec.abook.abv.bl.dto.BluetoothPairingDeviceInfoDto;
import jp.agentec.abook.abv.cl.util.BleManagerUtil; import jp.agentec.abook.abv.cl.util.BleManagerUtil;
import jp.agentec.abook.abv.launcher.android.R; import jp.agentec.abook.abv.launcher.android.R;
import jp.agentec.abook.abv.ui.common.activity.ABVUIActivity; import jp.agentec.abook.abv.ui.common.activity.ABVUIActivity;
import jp.agentec.abook.abv.ui.common.util.ABVToastUtil; import jp.agentec.abook.abv.ui.common.util.ABVToastUtil;
import jp.agentec.abook.abv.ui.home.adapter.BleListAdapter;
import jp.agentec.abook.abv.ui.home.adapter.BleListRowData;
import jp.agentec.abook.abv.ui.home.adapter.common.SectionHeaderData;
import jp.agentec.abook.abv.ui.home.helper.ABookPermissionHelper; import jp.agentec.abook.abv.ui.home.helper.ABookPermissionHelper;
import jp.agentec.adf.util.CollectionUtil; import jp.agentec.adf.util.CollectionUtil;
...@@ -98,10 +103,10 @@ public class BlePairingSettingActivity extends ABVUIActivity { ...@@ -98,10 +103,10 @@ public class BlePairingSettingActivity extends ABVUIActivity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
Logger.i(TAG, "onCreate"); Logger.i(TAG, "onCreate");
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.pairing_setting); //setContentView(R.layout.pairing_setting);
TextView deviceTitle = (TextView) findViewById(R.id.device_toolbar_title); //TextView deviceTitle = (TextView) findViewById(R.id.device_toolbar_title);
deviceTitle.setText(getString(R.string.chino_machine)); //eviceTitle.setText(getString(R.string.chino_machine));
// 戻り値の初期化 // 戻り値の初期化
setResult( Activity.RESULT_CANCELED ); setResult( Activity.RESULT_CANCELED );
...@@ -140,25 +145,25 @@ public class BlePairingSettingActivity extends ABVUIActivity { ...@@ -140,25 +145,25 @@ public class BlePairingSettingActivity extends ABVUIActivity {
// bleManagerUtil.mBluetoothAdapter.startDiscovery(); // bleManagerUtil.mBluetoothAdapter.startDiscovery();
ListView listView = (ListView) findViewById(R.id.devicelist); // リストビューの取得 // ListView listView = (ListView) findViewById(R.id.devicelist); // リストビューの取得
listView.setAdapter(mBleListAdapter); // リストビューにビューアダプターをセット // listView.setAdapter(mBleListAdapter); // リストビューにビューアダプターをセット
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { // listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override // @Override
public void onItemClick(AdapterView<?> parent, View view, int position, // public void onItemClick(AdapterView<?> parent, View view, int position,
long id) { // long id) {
Logger.d(TAG, "position = " + position); // Logger.d(TAG, "position = " + position);
BleListRowData bleListRowData = (BleListRowData)parent.getItemAtPosition(position); // BleListRowData bleListRowData = (BleListRowData)parent.getItemAtPosition(position);
// 既に保存されてる場合は何もしない // // 既に保存されてる場合は何もしない
if (!bleListRowData.isSaved) { // if (!bleListRowData.isSaved) {
localSaveDeviceInfo(bleListRowData); // localSaveDeviceInfo(bleListRowData);
} // }
} // }
}); // });
// Reload Button // Reload Button
mButton_Scan = (Button)findViewById( R.id.btn_reload ); //mButton_Scan = (Button)findViewById( R.id.btn_reload );
mButton_Scan.setAllCaps(false); mButton_Scan.setAllCaps(false);
mButton_Scan.setText(getString(R.string.pairing_search_scan)); //mButton_Scan.setText(getString(R.string.pairing_search_scan));
mButton_Scan.setOnClickListener(new View.OnClickListener() { mButton_Scan.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
...@@ -198,7 +203,7 @@ public class BlePairingSettingActivity extends ABVUIActivity { ...@@ -198,7 +203,7 @@ public class BlePairingSettingActivity extends ABVUIActivity {
switch (requestCode) { switch (requestCode) {
case REQUEST_ENABLEBLUETOOTH: // Bluetooth有効化要求 case REQUEST_ENABLEBLUETOOTH: // Bluetooth有効化要求
if( Activity.RESULT_CANCELED == resultCode ) { // 有効にされなかった if( Activity.RESULT_CANCELED == resultCode ) { // 有効にされなかった
ABVToastUtil.showMakeText(getApplicationContext(), String.format(getString(R.string.msg_scan_bluetooth_no_allow), getString(R.string.chino_machine)), Toast.LENGTH_SHORT); //ABVToastUtil.showMakeText(getApplicationContext(), String.format(getString(R.string.msg_scan_bluetooth_no_allow), getString(R.string.chino_machine)), Toast.LENGTH_SHORT);
return; return;
} }
break; break;
...@@ -224,7 +229,7 @@ public class BlePairingSettingActivity extends ABVUIActivity { ...@@ -224,7 +229,7 @@ public class BlePairingSettingActivity extends ABVUIActivity {
//端末側の位置情報許可チェック //端末側の位置情報許可チェック
if (!(gpsEnabled || secureLocationGpsEnabled)) { if (!(gpsEnabled || secureLocationGpsEnabled)) {
showSimpleAlertDialog(R.string.chino_machine, R.string.msg_location_device_no_allow); //showSimpleAlertDialog(R.string.chino_machine, R.string.msg_location_device_no_allow);
return; return;
} }
...@@ -259,7 +264,7 @@ public class BlePairingSettingActivity extends ABVUIActivity { ...@@ -259,7 +264,7 @@ public class BlePairingSettingActivity extends ABVUIActivity {
mScanning = true; mScanning = true;
mButton_Scan.setText(getString(R.string.pairing_search_stop)); //Button_Scan.setText(getString(R.string.pairing_search_stop));
reloadListView(); reloadListView();
Logger.d(TAG, "start scan !!"); Logger.d(TAG, "start scan !!");
} }
...@@ -282,7 +287,7 @@ public class BlePairingSettingActivity extends ABVUIActivity { ...@@ -282,7 +287,7 @@ public class BlePairingSettingActivity extends ABVUIActivity {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
scanner.stopScan( mLeScanCallback ); scanner.stopScan( mLeScanCallback );
} }
mButton_Scan.setText(getString(R.string.pairing_search_scan)); //mButton_Scan.setText(getString(R.string.pairing_search_scan));
reloadListView(); reloadListView();
Logger.d(TAG, "stop scan !!"); Logger.d(TAG, "stop scan !!");
} }
...@@ -339,14 +344,14 @@ public class BlePairingSettingActivity extends ABVUIActivity { ...@@ -339,14 +344,14 @@ public class BlePairingSettingActivity extends ABVUIActivity {
for (BluetoothPairingDeviceInfoDto bluetoothPairingDeviceInfoDto : bluetoothPairingInfoDtoList) { for (BluetoothPairingDeviceInfoDto bluetoothPairingDeviceInfoDto : bluetoothPairingInfoDtoList) {
// ペアリング情報が既に保存されてる場合はヘッダー情報を各機器毎に追加する // ペアリング情報が既に保存されてる場合はヘッダー情報を各機器毎に追加する
if (bluetoothPairingDeviceInfoDto.deviceType.equals(DeviceType.centerThermomete)) { if (bluetoothPairingDeviceInfoDto.deviceType.equals(DeviceType.centerThermomete)) {
sectionList.add(new SectionHeaderData(String.format(getString(R.string.pairing_save_machine), getString(R.string.center_thermometer)))); //sectionList.add(new SectionHeaderData(String.format(getString(R.string.pairing_save_machine), getString(R.string.center_thermometer))));
} else if (bluetoothPairingDeviceInfoDto.deviceType.equals(DeviceType.radiationThermomete)) { } else if (bluetoothPairingDeviceInfoDto.deviceType.equals(DeviceType.radiationThermomete)) {
sectionList.add(new SectionHeaderData(String.format(getString(R.string.pairing_save_machine), getString(R.string.radiation_thermometer)))); //sectionList.add(new SectionHeaderData(String.format(getString(R.string.pairing_save_machine), getString(R.string.radiation_thermometer))));
} }
} }
} }
// その他のヘッダー情報追加 // その他のヘッダー情報追加
sectionList.add(new SectionHeaderData(String.format(getString(mScanning ? R.string.pairing_other_machine_searching : R.string.pairing_other_machine), getString(R.string.chino_machine)))); //sectionList.add(new SectionHeaderData(String.format(getString(mScanning ? R.string.pairing_other_machine_searching : R.string.pairing_other_machine), getString(R.string.chino_machine))));
return sectionList; return sectionList;
} }
...@@ -384,9 +389,9 @@ public class BlePairingSettingActivity extends ABVUIActivity { ...@@ -384,9 +389,9 @@ public class BlePairingSettingActivity extends ABVUIActivity {
for (BluetoothDevice bleDevice : mScanDeviceInfoList) { for (BluetoothDevice bleDevice : mScanDeviceInfoList) {
String labelDeviceName = ""; String labelDeviceName = "";
if (bleDevice.getName().startsWith(CENTER_THERMOMETE_DEVICE_NAME)) { if (bleDevice.getName().startsWith(CENTER_THERMOMETE_DEVICE_NAME)) {
labelDeviceName = getString(R.string.center_thermometer); //labelDeviceName = getString(R.string.center_thermometer);
} else if (bleDevice.getName().startsWith(RADIATION_THERMOMETE_DEVICE_NAME)) { } else if (bleDevice.getName().startsWith(RADIATION_THERMOMETE_DEVICE_NAME)) {
labelDeviceName = getString(R.string.radiation_thermometer); //labelDeviceName = getString(R.string.radiation_thermometer);
} }
BleListRowData scanRowData = new BleListRowData(bleDevice.getName(), labelDeviceName, bleDevice.getAddress(), false); BleListRowData scanRowData = new BleListRowData(bleDevice.getName(), labelDeviceName, bleDevice.getAddress(), false);
scanRowDataList.add(scanRowData); scanRowDataList.add(scanRowData);
......
...@@ -8,11 +8,13 @@ import android.widget.TextView; ...@@ -8,11 +8,13 @@ import android.widget.TextView;
import java.util.List; import java.util.List;
import jp.agentec.abook.abv.launcher.android.R; import jp.agentec.abook.abv.launcher.android.R;
import jp.agentec.abook.abv.ui.home.adapter.common.BaseSectionAdapter;
import jp.agentec.abook.abv.ui.home.adapter.common.IndexPath;
import jp.agentec.abook.abv.ui.home.adapter.common.SectionHeaderData;
public class BleListAdapter { public class BleListAdapter extends BaseSectionAdapter<SectionHeaderData, BleListRowData> {
public class BleListAdapter extends BaseSectionAdapter<SectionHeaderData, BleListRowData> {
private static final String TAG = "BleListAdapter"; private static final String TAG = "BleListAdapter";
protected jp.agentec.abook.abv.ui.home.adapter.BleListAdapter.BleListAdapterListener listener; protected BleListAdapter.BleListAdapterListener listener;
public interface BleListAdapterListener { public interface BleListAdapterListener {
// 登録されたデバイス情報削除(bluetooth情報を引数としてセット) // 登録されたデバイス情報削除(bluetooth情報を引数としてセット)
...@@ -30,10 +32,10 @@ public class BleListAdapter { ...@@ -30,10 +32,10 @@ public class BleListAdapter {
public View viewForHeaderInSection(View convertView, int section) { public View viewForHeaderInSection(View convertView, int section) {
ListHeaderViewHolder holder = null; ListHeaderViewHolder holder = null;
if (convertView == null) { if (convertView == null) {
convertView = inflater.inflate(R.layout.ble_section_list_header, null); //convertView = inflater.inflate(R.layout.ble_section_list_header, null);
holder = new ListHeaderViewHolder(); holder = new ListHeaderViewHolder();
holder.titleTxt = (TextView) convertView.findViewById(R.id.titleTxt); //holder.titleTxt = (TextView) convertView.findViewById(R.id.titleTxt);
holder.subtitleTxt = (TextView) convertView.findViewById(R.id.subTitleTxt); // holder.subtitleTxt = (TextView) convertView.findViewById(R.id.subTitleTxt);
convertView.setTag(holder); convertView.setTag(holder);
} else { } else {
holder = (ListHeaderViewHolder) convertView.getTag(); holder = (ListHeaderViewHolder) convertView.getTag();
...@@ -48,14 +50,14 @@ public class BleListAdapter { ...@@ -48,14 +50,14 @@ public class BleListAdapter {
public View cellForRowAtIndexPath(View convertView, IndexPath indexPath) { public View cellForRowAtIndexPath(View convertView, IndexPath indexPath) {
ListRowViewHolder holder = null; ListRowViewHolder holder = null;
if (convertView == null) { if (convertView == null) {
convertView = inflater.inflate(R.layout.ble_section_list_row, null); //convertView = inflater.inflate(R.layout.ble_section_list_row, null);
holder = new ListRowViewHolder(); holder = new ListRowViewHolder();
// bluetoothのデバイス名 // bluetoothのデバイス名
holder.bl_title = (TextView) convertView.findViewById(R.id.bl_title); //holder.bl_title = (TextView) convertView.findViewById(R.id.bl_title);
// 該当通信機器の名(中心温度計・放射温度計) // 該当通信機器の名(中心温度計・放射温度計)
holder.sub_title = (TextView) convertView.findViewById(R.id.sub_title); //holder.sub_title = (TextView) convertView.findViewById(R.id.sub_title);
// 削除ボタン // 削除ボタン
holder.bl_deleteBtn = (Button) convertView.findViewById(R.id.bl_deleteBtn); //holder.bl_deleteBtn = (Button) convertView.findViewById(R.id.bl_deleteBtn);
convertView.setTag(holder); convertView.setTag(holder);
} else { } else {
holder = (ListRowViewHolder) convertView.getTag(); holder = (ListRowViewHolder) convertView.getTag();
...@@ -97,6 +99,4 @@ public class BleListAdapter { ...@@ -97,6 +99,4 @@ public class BleListAdapter {
settingSectionRowData(sectionList, rowList); settingSectionRowData(sectionList, rowList);
notifyDataSetChanged(); notifyDataSetChanged();
} }
} }
package jp.agentec.abook.abv.ui.home.adapter;
import jp.agentec.abook.abv.ui.home.adapter.common.SectionRowData;
public class BleListRowData extends SectionRowData {
public boolean isSaved;
public String deviceAddress;
/**
* デフォルト
* @param title タイトル
* @param subTitle サブタイトル
*/
public BleListRowData(String title, String subTitle) {
super(title, subTitle);
}
/**
* bluetooth情報
* @param title bluetoothデバイス名
* @param deviceAddress bluetoothデバイスアドレス
* @param isSaved 登録状態
*/
public BleListRowData(String title, String deviceAddress, boolean isSaved) {
super(title, null);
this.deviceAddress = deviceAddress;
this.isSaved = isSaved;
}
/**
* bluetooth情報
* @param title bluetoothデバイス名
* @param subTitle 通信機器名(中心温度計・放射温度計)
* @param deviceAddress bluetoothデバイスアドレス
* @param isSaved 登録状態
*/
public BleListRowData(String title, String subTitle, String deviceAddress, boolean isSaved) {
super(title, subTitle);
this.deviceAddress = deviceAddress;
this.isSaved = isSaved;
}
}
package jp.agentec.abook.abv.ui.home.adapter.common;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
public class BaseSectionAdapter<T1, T2> extends BaseAdapter {
/** インデックス行:ヘッダー */
private static final int INDEX_PATH_ROW_HEADER = -1;
/** ビュータイプ:ヘッダー行 */
private static final int ITEM_VIEW_TYPE_HEADER = 0;
/** ビュータイプ:データ行 */
private static final int ITEM_VIEW_TYPE_ROW = 1;
protected Context context;
protected LayoutInflater inflater;
/** ヘッダー行で使用するデータリスト */
protected List<T1> sectionList;
/** データ行で使用するデータリスト */
protected List<List<T2>> rowList;
private List<IndexPath> indexPathList;
public BaseSectionAdapter(Context context, List<T1> sectionList, List<List<T2>> rowList) {
super();
this.context = context;
this.inflater = LayoutInflater.from(context);
this.sectionList = sectionList;
this.rowList = rowList;
this.indexPathList = getIndexPathList(sectionList, rowList);
}
@Override
public int getCount() {
int count = indexPathList.size();
return count;
}
@Override
public Object getItem(int position) {
IndexPath indexPath = indexPathList.get(position);
if (isHeader(indexPath)) {
return sectionList.get(indexPath.section);
} else {
return rowList.get(indexPath.section).get(indexPath.row);
}
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
IndexPath indexPath = indexPathList.get(position);
// ヘッダー行とデータ行とで分岐します。
if (isHeader(indexPath)) {
return viewForHeaderInSection(convertView, indexPath.section);
} else {
return cellForRowAtIndexPath(convertView, indexPath);
}
}
/**
* ヘッダー行のViewを返します。
*
* @param convertView
* @param section
* @return ヘッダー行のView
*/
public View viewForHeaderInSection(View convertView, int section) {
if (convertView == null) {
convertView = inflater.inflate(android.R.layout.simple_list_item_1, null);
TextView castedConvertView = (TextView) convertView;
castedConvertView.setBackgroundColor(Color.GRAY);
castedConvertView.setTextColor(Color.WHITE);
}
TextView textView = (TextView) convertView;
textView.setText(sectionList.get(section).toString());
return convertView;
}
/**
* データ行のViewを返します。
*
* @param convertView
* @param indexPath
* @return データ行のView
*/
public View cellForRowAtIndexPath(View convertView, IndexPath indexPath) {
if (convertView == null) {
convertView = inflater.inflate(android.R.layout.simple_list_item_1, null);
}
TextView textView = (TextView) convertView;
textView.setText(rowList.get(indexPath.section).get(indexPath.row).toString());
return convertView;
}
@Override
public int getViewTypeCount() {
// ヘッダー行とデータ行の2種類なので、2を返します。
return 2;
}
@Override
public int getItemViewType(int position) {
// ビュータイプを返します。
if (isHeader(position)) {
return ITEM_VIEW_TYPE_HEADER;
} else {
return ITEM_VIEW_TYPE_ROW;
}
}
@Override
public boolean isEnabled(int position) {
if (isHeader(position)) {
// ヘッダー行の場合は、タップできないようにします。
return false;
} else {
IndexPath indexPath = indexPathList.get(position);
SectionRowData rowData = (SectionRowData) rowList.get(indexPath.section).get(indexPath.row);
if (rowData.title.isEmpty()) { //タイトルが空白の場合はタップ不能に設定
return false;
}
return super.isEnabled(position);
}
}
/**
* インデックスパスリストを取得します。
*
* @param sectionList
* @param rowList
* @return インデックスパスリスト
*/
private List<IndexPath> getIndexPathList(List<T1> sectionList, List<List<T2>> rowList) {
List<IndexPath> indexPathList = new ArrayList<IndexPath>();
for (int i = 0; i < sectionList.size(); i++) {
IndexPath sectionIndexPath = new IndexPath();
sectionIndexPath.section = i;
sectionIndexPath.row = INDEX_PATH_ROW_HEADER;
indexPathList.add(sectionIndexPath);
List<T2> rowListBySection = rowList.get(i);
for (int j = 0; j < rowListBySection.size(); j++) {
IndexPath rowIndexPath = new IndexPath();
rowIndexPath.section = i;
rowIndexPath.row = j;
indexPathList.add(rowIndexPath);
}
}
return indexPathList;
}
private boolean isHeader(int position) {
IndexPath indexPath = indexPathList.get(position);
return isHeader(indexPath);
}
private boolean isHeader(IndexPath indexPath) {
if (INDEX_PATH_ROW_HEADER == indexPath.row) {
return true;
} else {
return false;
}
}
protected void settingSectionRowData(List<T1> sectionList, List<List<T2>> rowList) {
this.sectionList = sectionList;
this.rowList = rowList;
this.indexPathList = getIndexPathList(sectionList, rowList);
}
}
package jp.agentec.abook.abv.ui.home.adapter.common;
public class IndexPath {
public int section;
public int row;
}
package jp.agentec.abook.abv.ui.home.adapter.common;
/**
* ListViewのAdapterで利用するSectionの値設定クラス
*/
public class SectionHeaderData {
/**
* 中心温度計用
* @param title タイトル
*/
public SectionHeaderData(String title) {
this.title = title;
}
/**
* 共通用
* @param title タイトル
* @param subTitle サブタイトル
*/
public SectionHeaderData(String title, String subTitle) {
this.title = title;
this.subTitle = subTitle;
}
public String title;
public String subTitle;
}
\ No newline at end of file
package jp.agentec.abook.abv.ui.home.adapter.common;
/**
* ListViewのAdapterで利用するRowの値設定クラス
*/
public class SectionRowData {
/**
* 共通用
* @param title タイトル
* @param subTitle サブタイトル
*/
public SectionRowData(String title, String subTitle) {
this.title = title;
this.subTitle = subTitle;
}
public String title;
public String subTitle;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment