正在查看: xDrip+ v04633772025.07.16 应用的 BTGlucoseMeterActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: xDrip+ v04633772025.07.16 应用的 BTGlucoseMeterActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.eveningoutpost.dexdrip.glucosemeter;
import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import com.eveningoutpost.dexdrip.models.JoH;
import com.eveningoutpost.dexdrip.models.UserError;
import com.eveningoutpost.dexdrip.services.BluetoothGlucoseMeter;
import com.eveningoutpost.dexdrip.utilitymodels.Pref;
import com.eveningoutpost.dexdrip.utils.ListActivityWithMenu;
import com.eveningoutpost.dexdrip.utils.LocationHelper;
import java.util.ArrayList;
import java.util.Iterator;
@TargetApi(18)
public class BTGlucoseMeterActivity extends ListActivityWithMenu {
private static final String TAG = "BTGlucoseMeterActivity";
private BluetoothAdapter bluetooth_adapter;
private BluetoothManager bluetooth_manager;
private LeDeviceListAdapter mLeDeviceListAdapter;
private BroadcastReceiver serviceDataReceiver;
private TextView statusText;
private boolean is_scanning = false;
private boolean first_run = true;
@Override
public String getMenuName() {
return "Meter Scan";
}
@Override
protected void onCreate(Bundle bundle) {
setTheme(2131820787);
super.onCreate(bundle);
setContentView(2131492900);
TextView textView = (TextView) findViewById(2131296410);
this.statusText = textView;
textView.setText("Starting up");
BluetoothManager bluetoothManager = (BluetoothManager) getSystemService("bluetooth");
this.bluetooth_manager = bluetoothManager;
BluetoothAdapter adapter = bluetoothManager.getAdapter();
this.bluetooth_adapter = adapter;
if (adapter == null) {
Toast.makeText(this, 2131755535, 1).show();
finish();
return;
}
check_and_enable_bluetooth();
LocationHelper.requestLocationForBluetooth(this);
this.serviceDataReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
UserError.Log.d(BTGlucoseMeterActivity.TAG, "Got receive:" + action + " :: " + intent.getStringExtra("data"));
action.hashCode();
if (action.equals("com.eveningoutpost.dexdrip.BLUETOOTH_GLUCOSE_METER_SERVICE_UPDATE")) {
BTGlucoseMeterActivity.this.statusText.setText(intent.getStringExtra("data"));
} else if (action.equals("com.eveningoutpost.dexdrip.BLUETOOTH_GLUCOSE_METER_NEW_SCAN_DEVICE")) {
BTGlucoseMeterActivity.this.mLeDeviceListAdapter.addDevice(intent.getStringExtra("data"));
}
}
};
LeDeviceListAdapter leDeviceListAdapter = new LeDeviceListAdapter();
this.mLeDeviceListAdapter = leDeviceListAdapter;
setListAdapter(leDeviceListAdapter);
getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long j) {
final MyBluetoothDevice device = BTGlucoseMeterActivity.this.mLeDeviceListAdapter.getDevice(i);
if (device == null) {
UserError.Log.wtf(BTGlucoseMeterActivity.TAG, "Null pointer on list item long click");
return true;
}
AlertDialog.Builder builder = new AlertDialog.Builder(adapterView.getContext());
builder.setTitle("Choose Action");
builder.setMessage("You can disconnect from this device or forget its pairing here");
builder.setNeutralButton("Do Nothing", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i2) {
dialogInterface.dismiss();
}
});
builder.setPositiveButton("Disconnect", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i2) {
dialogInterface.dismiss();
if (Pref.getStringDefaultBlank("selected_bluetooth_meter_address").equals(device.address)) {
Pref.setString("selected_bluetooth_meter_address", "");
BTGlucoseMeterActivity.this.mLeDeviceListAdapter.changed();
JoH.static_toast_long("Disconnected!");
BluetoothGlucoseMeter.start_service(null);
return;
}
JoH.static_toast_short("Not connected to this device!");
}
});
builder.setNegativeButton("Forget Pair", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i2) {
BluetoothGlucoseMeter.start_forget(device.address);
dialogInterface.dismiss();
}
});
builder.create().show();
return true;
}
});
getListView().setLongClickable(true);
}
@Override
protected void onResume() {
super.onResume();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("com.eveningoutpost.dexdrip.BLUETOOTH_GLUCOSE_METER_NEW_SCAN_DEVICE");
intentFilter.addAction("com.eveningoutpost.dexdrip.BLUETOOTH_GLUCOSE_METER_SERVICE_UPDATE");
LocalBroadcastManager.getInstance(this).registerReceiver(this.serviceDataReceiver, intentFilter);
if (this.first_run) {
BluetoothGlucoseMeter.start_service(null);
this.first_run = false;
}
}
@Override
protected void onPause() {
super.onPause();
if (this.serviceDataReceiver != null) {
try {
LocalBroadcastManager.getInstance(this).unregisterReceiver(this.serviceDataReceiver);
} catch (IllegalArgumentException e) {
UserError.Log.e(TAG, "broadcast receiver not registered", e);
}
}
}
private void check_and_enable_bluetooth() {
if (this.bluetooth_manager.getAdapter().isEnabled()) {
return;
}
if (Pref.getBoolean("automatically_turn_bluetooth_on", true)) {
JoH.setBluetoothEnabled(getApplicationContext(), true);
Toast.makeText(this, "Trying to turn Bluetooth on", 1).show();
} else {
Toast.makeText(this, "Please turn Bluetooth on!", 1).show();
}
}
@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
if (menuItem.getItemId() == 2131296739) {
check_and_enable_bluetooth();
if (JoH.ratelimit("bluetooth-scan-button", 4)) {
UserError.Log.d(TAG, "Starting Bluetooth Glucose Meter Service");
this.mLeDeviceListAdapter.clear();
BluetoothGlucoseMeter.start_service(null);
return true;
}
UserError.Log.d(TAG, "Rate limited scan button");
return true;
}
return super.onOptionsItemSelected(menuItem);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(2131558403, menu);
menu.findItem(2131296738).setVisible(false);
if (!this.is_scanning) {
menu.findItem(2131296741).setVisible(false);
menu.findItem(2131296739).setVisible(true);
} else {
menu.findItem(2131296741).setVisible(true);
menu.findItem(2131296739).setVisible(false);
}
return true;
}
@Override
protected void onListItemClick(ListView listView, View view, int i, long j) {
MyBluetoothDevice device = this.mLeDeviceListAdapter.getDevice(i);
if (device != null) {
if (JoH.ratelimit("bt-meter-item-clicked", 7)) {
UserError.Log.d(TAG, "Item Clicked: " + device.address);
BluetoothGlucoseMeter.start_service(device.address);
return;
}
return;
}
UserError.Log.wtf(TAG, "Null pointer on list item click");
}
static class ViewHolder {
TextView deviceAddress;
TextView deviceName;
ViewHolder() {
}
}
static class MyBluetoothDevice {
String address;
String name;
int pairstate;
MyBluetoothDevice(String str) {
String[] split = str.split("\\^");
this.address = split[0];
this.pairstate = Integer.parseInt(split[1]);
if (split.length > 2) {
this.name = split[2];
} else {
this.name = "";
}
}
}
private class LeDeviceListAdapter extends BaseAdapter {
private LayoutInflater mInflator;
private ArrayList<MyBluetoothDevice> mLeDevices = new ArrayList<>();
@Override
public long getItemId(int i) {
return i;
}
LeDeviceListAdapter() {
this.mInflator = BTGlucoseMeterActivity.this.getLayoutInflater();
}
synchronized boolean isDupeDevice(MyBluetoothDevice myBluetoothDevice) {
if (myBluetoothDevice == null) {
return false;
}
Iterator<MyBluetoothDevice> it = this.mLeDevices.iterator();
while (it.hasNext()) {
MyBluetoothDevice next = it.next();
if (next.address.equals(myBluetoothDevice.address)) {
int i = next.pairstate;
int i2 = myBluetoothDevice.pairstate;
if (i != i2) {
next.pairstate = i2;
notifyDataSetChanged();
} else if (!next.name.equals(myBluetoothDevice.name)) {
notifyDataSetChanged();
}
return true;
}
}
return false;
}
synchronized void addDevice(String str) {
if (str == null) {
return;
}
MyBluetoothDevice myBluetoothDevice = new MyBluetoothDevice(str);
if (!isDupeDevice(myBluetoothDevice)) {
this.mLeDevices.add(myBluetoothDevice);
notifyDataSetChanged();
UserError.Log.d(BTGlucoseMeterActivity.TAG, "New list device added - data set changed");
}
}
public MyBluetoothDevice getDevice(int i) {
return this.mLeDevices.get(i);
}
public void changed() {
notifyDataSetChanged();
}
public void clear() {
this.mLeDevices.clear();
notifyDataSetChanged();
}
@Override
public int getCount() {
return this.mLeDevices.size();
}
@Override
public Object getItem(int i) {
return this.mLeDevices.get(i);
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
ViewHolder viewHolder;
if (view == null) {
view = this.mInflator.inflate(2131492997, (ViewGroup) null);
viewHolder = new ViewHolder();
viewHolder.deviceAddress = (TextView) view.findViewById(2131296547);
viewHolder.deviceName = (TextView) view.findViewById(2131296549);
view.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) view.getTag();
}
MyBluetoothDevice myBluetoothDevice = this.mLeDevices.get(i);
String str = myBluetoothDevice.name;
if (Pref.getString("selected_bluetooth_meter_address", "").equals(myBluetoothDevice.address)) {
viewHolder.deviceName.setTextColor(Color.parseColor("#ff99dd00"));
} else {
viewHolder.deviceName.setTextColor(-1);
}
boolean z = myBluetoothDevice.pairstate == 12;
if (z) {
viewHolder.deviceAddress.setTextColor(-256);
} else {
viewHolder.deviceAddress.setTextColor(-1);
}
viewHolder.deviceName.setText(str);
TextView textView = viewHolder.deviceAddress;
StringBuilder sb = new StringBuilder();
sb.append(myBluetoothDevice.address);
sb.append(z ? " Paired" : "");
textView.setText(sb.toString());
return view;
}
}
}