List of usage examples for android.content Context BLUETOOTH_SERVICE
String BLUETOOTH_SERVICE
To view the source code for android.content Context BLUETOOTH_SERVICE.
Click Source Link
From source file:com.example.android.bluetoothlegatt.BluetoothLeService.java
/** * Initializes a reference to the local Bluetooth adapter. * * @return Return true if the initialization is successful. *///www .java 2s . c o m public boolean initialize() { // For API level 18 and above, get a reference to BluetoothAdapter through // BluetoothManager. if (mBluetoothManager == null) { mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); if (mBluetoothManager == null) { Log.e(TAG, "Unable to initialize BluetoothManager."); return false; } } mBluetoothAdapter = mBluetoothManager.getAdapter(); if (mBluetoothAdapter == null) { Log.e(TAG, "Unable to obtain a BluetoothAdapter."); return false; } return true; }
From source file:de.dmarcini.bt.homelight.HomeLightMainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (BuildConfig.DEBUG) { Log.v(TAG, "erzeuge Application..."); }//from w w w . j ava 2 s . c om setContentView(R.layout.activity_home_light_main); if (BuildConfig.DEBUG) { Log.e(TAG, "D E B U G Version"); } //############################################################################################## // // Ist Bluethooth LE (4.0) untersttzt? // if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { Toast.makeText(this, R.string.main_ble_not_supported, Toast.LENGTH_SHORT).show(); finish(); } // // initialisiere den Adapter // final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); btConfig.setBluetoothAdapter(bluetoothManager.getAdapter()); // // Ist ein BT Adapter vorhanden? // if (btConfig.getBluethoothAdapter() == null) { Toast.makeText(this, R.string.main_ble_not_supported, Toast.LENGTH_SHORT).show(); finish(); return; } // // Systemeinstellungen einlesen // HomeLightSysConfig.readSysPrefs(getResources(), PreferenceManager.getDefaultSharedPreferences(this)); // // Kommando-Queue Tread aktivieren // cmdTread = new CmdQueueThread(recCmdQueue, CReciver); Thread tr = new Thread(cmdTread, "cmd_queue_thread"); tr.start(); // // Vorerst nur der Platzhalter fr ein Spielerchen spter // FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fabOnOff); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { view.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); setModulOnOff(); //Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG).setAction("Action", null).show(); } }); if (BuildConfig.DEBUG) { Log.v(TAG, "erzeuge Application...OK"); } }
From source file:de.frank_durr.ble_v_monitor.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); restoreDataModel(savedInstanceState); if (bluetoothAdapter == null) { BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); bluetoothAdapter = bluetoothManager.getAdapter(); }// w w w.j a v a 2 s.co m if (savedInstanceState != null && savedInstanceState.containsKey(BUNDLE_KEY_BLUETOOTH_DEVICE)) { bluetoothDevice = savedInstanceState.getParcelable(BUNDLE_KEY_BLUETOOTH_DEVICE); } PreferenceManager.setDefaultValues(this, R.xml.preferences, false); gattHandler = new GattCallbackHandler(); taskTimoutHandler = new Handler(); updateTriggerHandler = new ModelUpdateTriggerHandler(); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); String appName = getString(R.string.app_name); toolbar.setTitle(appName); setSupportActionBar(toolbar); FragmentManager fm = getSupportFragmentManager(); ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager); FPAdapter fpAdapter = new FPAdapter(fm); viewPager.setAdapter(fpAdapter); // Get references to already existing tags if (savedInstanceState != null) { if (savedInstanceState.containsKey(BUNDLE_KEY_CURRENT_VOLTAGE_FRAGMENT)) { String tag = savedInstanceState.getString(BUNDLE_KEY_CURRENT_VOLTAGE_FRAGMENT); fragmentCurrentVoltage = (CurrentVoltageFragment) fm.findFragmentByTag(tag); } if (savedInstanceState.containsKey(BUNDLE_KEY_MINUTELY_HISTORY_FRAGMENT)) { String tag = savedInstanceState.getString(BUNDLE_KEY_MINUTELY_HISTORY_FRAGMENT); fragmentMinutelyHistory = (HistoryFragment) fm.findFragmentByTag(tag); } if (savedInstanceState.containsKey(BUNDLE_KEY_HOURLY_HISTORY_FRAGMENT)) { String tag = savedInstanceState.getString(BUNDLE_KEY_HOURLY_HISTORY_FRAGMENT); fragmentHourlyHistory = (HistoryFragment) fm.findFragmentByTag(tag); } if (savedInstanceState.containsKey(BUNDLE_KEY_DAILY_HISTORY_FRAGMENT)) { String tag = savedInstanceState.getString(BUNDLE_KEY_DAILY_HISTORY_FRAGMENT); fragmentDailyHistory = (HistoryFragment) fm.findFragmentByTag(tag); } } TabLayout tabLayout = (TabLayout) findViewById(R.id.tablayout); tabLayout.setupWithViewPager(viewPager); }
From source file:com.landenlabs.all_devtool.NetFragment.java
public void updateList() { // Time today = new Time(Time.getCurrentTimezone()); // today.setToNow(); // today.format(" %H:%M:%S") Date dt = new Date(); m_titleTime.setText(m_timeFormat.format(dt)); boolean expandAll = m_list.isEmpty(); m_list.clear();//from w w w . j a v a 2 s. c o m // Swap colors int color = m_rowColor1; m_rowColor1 = m_rowColor2; m_rowColor2 = color; ActivityManager actMgr = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE); try { String androidIDStr = Settings.Secure.getString(getContext().getContentResolver(), Settings.Secure.ANDROID_ID); addBuild("Android ID", androidIDStr); try { AdvertisingIdClient.Info adInfo = AdvertisingIdClient.getAdvertisingIdInfo(getContext()); final String adIdStr = adInfo.getId(); final boolean isLAT = adInfo.isLimitAdTrackingEnabled(); addBuild("Ad ID", adIdStr); } catch (IOException e) { // Unrecoverable error connecting to Google Play services (e.g., // the old version of the service doesn't support getting AdvertisingId). } catch (GooglePlayServicesNotAvailableException e) { // Google Play services is not available entirely. } /* try { InstanceID instanceID = InstanceID.getInstance(getContext()); if (instanceID != null) { // Requires a Google Developer project ID. String authorizedEntity = "<need to make this on google developer site>"; instanceID.getToken(authorizedEntity, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null); addBuild("Instance ID", instanceID.getId()); } } catch (Exception ex) { } */ ConfigurationInfo info = actMgr.getDeviceConfigurationInfo(); addBuild("OpenGL", info.getGlEsVersion()); } catch (Exception ex) { m_log.e(ex.getMessage()); } // --------------- Connection Services ------------- try { ConnectivityManager connMgr = (ConnectivityManager) getActivity() .getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo netInfo = connMgr.getActiveNetworkInfo(); if (netInfo != null) { Map<String, String> netListStr = new LinkedHashMap<String, String>(); putIf(netListStr, "Available", "Yes", netInfo.isAvailable()); putIf(netListStr, "Connected", "Yes", netInfo.isConnected()); putIf(netListStr, "Connecting", "Yes", !netInfo.isConnected() && netInfo.isConnectedOrConnecting()); putIf(netListStr, "Roaming", "Yes", netInfo.isRoaming()); putIf(netListStr, "Extra", netInfo.getExtraInfo(), !TextUtils.isEmpty(netInfo.getExtraInfo())); putIf(netListStr, "WhyFailed", netInfo.getReason(), !TextUtils.isEmpty(netInfo.getReason())); if (Build.VERSION.SDK_INT >= 16) { putIf(netListStr, "Metered", "Avoid heavy use", connMgr.isActiveNetworkMetered()); } netListStr.put("NetworkType", netInfo.getTypeName()); if (connMgr.getAllNetworkInfo().length > 1) { netListStr.put("Available Networks:", " "); for (NetworkInfo netI : connMgr.getAllNetworkInfo()) { if (netI.isAvailable()) { netListStr.put(" " + netI.getTypeName(), netI.isAvailable() ? "Yes" : "No"); } } } if (netInfo.isConnected()) { try { for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en .hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr .hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); if (!inetAddress.isLoopbackAddress()) { if (inetAddress.getHostAddress() != null) { String ipType = (inetAddress instanceof Inet4Address) ? "IPv4" : "IPv6"; netListStr.put(intf.getName() + " " + ipType, inetAddress.getHostAddress()); } // if (!TextUtils.isEmpty(inetAddress.getHostName())) // listStr.put( "HostName", inetAddress.getHostName()); } } } } catch (Exception ex) { m_log.e("Network %s", ex.getMessage()); } } addBuild("Network...", netListStr); } } catch (Exception ex) { m_log.e("Network %s", ex.getMessage()); } // --------------- Telephony Services ------------- TelephonyManager telephonyManager = (TelephonyManager) getActivity() .getSystemService(Context.TELEPHONY_SERVICE); if (telephonyManager != null) { Map<String, String> cellListStr = new LinkedHashMap<String, String>(); try { cellListStr.put("Version", telephonyManager.getDeviceSoftwareVersion()); cellListStr.put("Number", telephonyManager.getLine1Number()); cellListStr.put("Service", telephonyManager.getNetworkOperatorName()); cellListStr.put("Roaming", telephonyManager.isNetworkRoaming() ? "Yes" : "No"); cellListStr.put("Type", getNetworkTypeName(telephonyManager.getNetworkType())); if (Build.VERSION.SDK_INT >= 17) { if (telephonyManager.getAllCellInfo() != null) { for (CellInfo cellInfo : telephonyManager.getAllCellInfo()) { String cellName = cellInfo.getClass().getSimpleName(); int level = 0; if (cellInfo instanceof CellInfoCdma) { level = ((CellInfoCdma) cellInfo).getCellSignalStrength().getLevel(); } else if (cellInfo instanceof CellInfoGsm) { level = ((CellInfoGsm) cellInfo).getCellSignalStrength().getLevel(); } else if (cellInfo instanceof CellInfoLte) { level = ((CellInfoLte) cellInfo).getCellSignalStrength().getLevel(); } else if (cellInfo instanceof CellInfoWcdma) { if (Build.VERSION.SDK_INT >= 18) { level = ((CellInfoWcdma) cellInfo).getCellSignalStrength().getLevel(); } } cellListStr.put(cellName, "Level% " + String.valueOf(100 * level / 4)); } } } for (NeighboringCellInfo cellInfo : telephonyManager.getNeighboringCellInfo()) { int level = cellInfo.getRssi(); cellListStr.put("Cell level%", String.valueOf(100 * level / 31)); } } catch (Exception ex) { m_log.e("Cell %s", ex.getMessage()); } if (!cellListStr.isEmpty()) { addBuild("Cell...", cellListStr); } } // --------------- Bluetooth Services (API18) ------------- if (Build.VERSION.SDK_INT >= 18) { try { BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (bluetoothAdapter != null) { Map<String, String> btListStr = new LinkedHashMap<String, String>(); btListStr.put("Enabled", bluetoothAdapter.isEnabled() ? "yes" : "no"); btListStr.put("Name", bluetoothAdapter.getName()); btListStr.put("ScanMode", String.valueOf(bluetoothAdapter.getScanMode())); btListStr.put("State", String.valueOf(bluetoothAdapter.getState())); Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices(); // If there are paired devices if (pairedDevices.size() > 0) { // Loop through paired devices for (BluetoothDevice device : pairedDevices) { // Add the name and address to an array adapter to show in a ListView btListStr.put("Paired:" + device.getName(), device.getAddress()); } } BluetoothManager btMgr = (BluetoothManager) getActivity() .getSystemService(Context.BLUETOOTH_SERVICE); if (btMgr != null) { // btMgr.getAdapter(). } addBuild("Bluetooth", btListStr); } } catch (Exception ex) { } } // --------------- Wifi Services ------------- final WifiManager wifiMgr = (WifiManager) getContext().getApplicationContext() .getSystemService(Context.WIFI_SERVICE); if (wifiMgr != null && wifiMgr.isWifiEnabled() && wifiMgr.getDhcpInfo() != null) { if (mSystemBroadcastReceiver == null) { mSystemBroadcastReceiver = new SystemBroadcastReceiver(wifiMgr); getActivity().registerReceiver(mSystemBroadcastReceiver, INTENT_FILTER_SCAN_AVAILABLE); } if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) { if (wifiMgr.getScanResults() == null || wifiMgr.getScanResults().size() != mLastScanSize) { mLastScanSize = wifiMgr.getScanResults().size(); wifiMgr.startScan(); } } Map<String, String> wifiListStr = new LinkedHashMap<String, String>(); try { DhcpInfo dhcpInfo = wifiMgr.getDhcpInfo(); wifiListStr.put("DNS1", Formatter.formatIpAddress(dhcpInfo.dns1)); wifiListStr.put("DNS2", Formatter.formatIpAddress(dhcpInfo.dns2)); wifiListStr.put("Default Gateway", Formatter.formatIpAddress(dhcpInfo.gateway)); wifiListStr.put("IP Address", Formatter.formatIpAddress(dhcpInfo.ipAddress)); wifiListStr.put("Subnet Mask", Formatter.formatIpAddress(dhcpInfo.netmask)); wifiListStr.put("Server IP", Formatter.formatIpAddress(dhcpInfo.serverAddress)); wifiListStr.put("Lease Time(sec)", String.valueOf(dhcpInfo.leaseDuration)); WifiInfo wifiInfo = wifiMgr.getConnectionInfo(); if (wifiInfo != null) { wifiListStr.put("LinkSpeed Mbps", String.valueOf(wifiInfo.getLinkSpeed())); int numberOfLevels = 10; int level = WifiManager.calculateSignalLevel(wifiInfo.getRssi(), numberOfLevels + 1); wifiListStr.put("Signal%", String.valueOf(100 * level / numberOfLevels)); if (Build.VERSION.SDK_INT >= 23) { wifiListStr.put("MAC", getMacAddr()); } else { wifiListStr.put("MAC", wifiInfo.getMacAddress()); } } } catch (Exception ex) { m_log.e("Wifi %s", ex.getMessage()); } if (!wifiListStr.isEmpty()) { addBuild("WiFi...", wifiListStr); } try { if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) { List<ScanResult> listWifi = wifiMgr.getScanResults(); if (listWifi != null && !listWifi.isEmpty()) { int idx = 0; for (ScanResult scanResult : listWifi) { Map<String, String> wifiScanListStr = new LinkedHashMap<String, String>(); wifiScanListStr.put("SSID", scanResult.SSID); if (Build.VERSION.SDK_INT >= 23) { wifiScanListStr.put(" Name", scanResult.operatorFriendlyName.toString()); wifiScanListStr.put(" Venue", scanResult.venueName.toString()); } // wifiScanListStr.put(" BSSID ",scanResult.BSSID); wifiScanListStr.put(" Capabilities", scanResult.capabilities); // wifiScanListStr.put(" Center Freq", String.valueOf(scanResult.centerFreq0)); // wifiScanListStr.put(" Freq width", String.valueOf(scanResult.channelWidth)); wifiScanListStr.put(" Level, Freq", String.format("%d, %d", scanResult.level, scanResult.frequency)); if (Build.VERSION.SDK_INT >= 17) { Date wifiTime = new Date(scanResult.timestamp); wifiScanListStr.put(" Time", wifiTime.toLocaleString()); } addBuild(String.format("WiFiScan #%d", ++idx), wifiScanListStr); } } } } catch (Exception ex) { m_log.e("WifiList %s", ex.getMessage()); } try { List<WifiConfiguration> listWifiCfg = wifiMgr.getConfiguredNetworks(); for (WifiConfiguration wifiCfg : listWifiCfg) { Map<String, String> wifiCfgListStr = new LinkedHashMap<String, String>(); if (Build.VERSION.SDK_INT >= 23) { wifiCfgListStr.put("Name", wifiCfg.providerFriendlyName); } wifiCfgListStr.put("SSID", wifiCfg.SSID); String netStatus = ""; switch (wifiCfg.status) { case WifiConfiguration.Status.CURRENT: netStatus = "Connected"; break; case WifiConfiguration.Status.DISABLED: netStatus = "Disabled"; break; case WifiConfiguration.Status.ENABLED: netStatus = "Enabled"; break; } wifiCfgListStr.put(" Status", netStatus); wifiCfgListStr.put(" Priority", String.valueOf(wifiCfg.priority)); if (null != wifiCfg.wepKeys) { // wifiCfgListStr.put(" wepKeys", TextUtils.join(",", wifiCfg.wepKeys)); } String protocols = ""; if (wifiCfg.allowedProtocols.get(WifiConfiguration.Protocol.RSN)) protocols = "RSN "; if (wifiCfg.allowedProtocols.get(WifiConfiguration.Protocol.WPA)) protocols = protocols + "WPA "; wifiCfgListStr.put(" Protocols", protocols); String keyProt = ""; if (wifiCfg.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.NONE)) keyProt = "none"; if (wifiCfg.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.WPA_EAP)) keyProt = "WPA+EAP "; if (wifiCfg.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.WPA_PSK)) keyProt = "WPA+PSK "; wifiCfgListStr.put(" Keys", keyProt); if (wifiCfg.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.NONE)) { // Remove network connections with no Password. // wifiMgr.removeNetwork(wifiCfg.networkId); } addBuild("WiFiCfg #" + wifiCfg.networkId, wifiCfgListStr); } } catch (Exception ex) { m_log.e("Wifi Cfg List %s", ex.getMessage()); } } if (expandAll) { // updateList(); int count = m_list.size(); for (int position = 0; position < count; position++) m_listView.expandGroup(position); } m_adapter.notifyDataSetChanged(); }
From source file:com.elitise.appv2.Peripheral.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent I = getIntent();/*from w ww.j av a 2s . com*/ name = I.getStringExtra("mBname"); batteryIdx = I.getIntExtra("idx", -1); if (!sNExist()) { String mSN = I.getStringExtra("mSN"); saveSN(mSN); } isTablet = isTabletDevice(); // FirebaseStorage storage = FirebaseStorage.getInstance(); // StorageReference storageRef = storage.getReference(); // FirebaseOptions opts = FirebaseApp.getInstance().getOptions(); // Log.e(TAG, "Bucket = " + opts.getStorageBucket()+"\n URL"+opts.getApplicationId()); //mDetetor = new GestureDetectorCompat(this, new MyGestureListener()); setContentView(R.layout.activity_peripherals); TextView demoText = (TextView) findViewById(R.id.demoText); if (mUser.getBatteriesList().get(batteryIdx).isDemo) { demoText.setVisibility(View.VISIBLE); demoText.bringToFront(); } else { demoText.setVisibility(View.INVISIBLE); } getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); mBluetoothDevices = new HashSet<>(); mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); mBluetoothAdapter = mBluetoothManager.getAdapter(); sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); statusBar = (TextView) findViewById(R.id.statusBar); // boolean enableDiag = sharedPrefs.getBoolean(getString(R.string.pref_mode_key), false); // // if (!enableDiag) // mCurrentServiceFragment = new BatteryServiceFragment(); // else // mCurrentServiceFragment = new BatteryServiceDiagFragment(); if (savedInstanceState != null) { phoneFragment = (PhoneLayoutFragement) getSupportFragmentManager().findFragmentByTag("PHONE"); normalFragment = (BatteryServiceFragment) getSupportFragmentManager().findFragmentByTag("NORMAL"); diagFragment = (BatteryServiceDiagFragment) getSupportFragmentManager().findFragmentByTag("DIAG"); if (isTablet) { mCurrentServiceFragment = normalFragment; } else { mCurrentServiceFragment = phoneFragment; } } else { diagFragment = new BatteryServiceDiagFragment(); normalFragment = new BatteryServiceFragment(); phoneFragment = new PhoneLayoutFragement(); //mCurrentServiceFragment = normalFragment; Bundle bd = new Bundle(); bd.putString("mBname", name); bd.putInt("bIndex", batteryIdx); diagFragment.setArguments(bd); normalFragment.setArguments(bd); phoneFragment.setArguments(bd); if (isTablet) { mCurrentServiceFragment = normalFragment; getSupportFragmentManager().beginTransaction() .add(R.id.normal_fragment_container, normalFragment, "NORMAL") .add(R.id.diag_fragment_container, diagFragment, "DIAG").hide(diagFragment) .show(normalFragment).commit(); } else { mCurrentServiceFragment = phoneFragment; getSupportFragmentManager().beginTransaction() .add(R.id.phone_fragment_container, phoneFragment, "PHONE") .add(R.id.normal_fragment_container, normalFragment, "NORMAL") .add(R.id.diag_fragment_container, diagFragment, "DIAG").hide(diagFragment) .hide(normalFragment).show(phoneFragment).commit(); } mCurrentServiceFragment.setArguments(bd); } if (!mUser.getBatteriesList().get(batteryIdx).isBonded) { mBluetoothGattService = mCurrentServiceFragment.getBluetoothGattService(); } else { mBluetoothGattService = mCurrentServiceFragment.getBluetoothGattServiceCustom(); } mAdvSettings = new AdvertiseSettings.Builder().setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED) .setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_HIGH).setConnectable(true).setTimeout(0) .build(); mAdvData = new AdvertiseData.Builder().setIncludeDeviceName(false).setIncludeTxPowerLevel(false) .addServiceUuid( mCurrentServiceFragment.getServiceUUID(mUser.getBatteriesList().get(batteryIdx).isBonded)) .build(); mScanResponse = new AdvertiseData.Builder().setIncludeDeviceName(true).setIncludeTxPowerLevel(true).build(); // Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar2); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(false); getSupportActionBar().setDisplayShowTitleEnabled(false); logoView = (Logo_pathsView) findViewById(R.id.logoBar); Context context = getApplicationContext(); // or activity.getApplicationContext() PackageManager packageManager = context.getPackageManager(); String packageName = context.getPackageName(); String myVersionName = "1.0.0"; // initialize String try { myVersionName = packageManager.getPackageInfo(packageName, 0).versionName; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } logoView.setVersion(myVersionName); if (!mBluetoothAdapter.isMultipleAdvertisementSupported()) { new MaterialDialog.Builder(this).title("BLE ERROR") .content("Sorry, this device not support BLE peripheral mode").positiveText("CONFIRM") .onPositive(new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { finish(); } }); } }
From source file:io.puzzlebox.bloom.ui.MakerFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View v = inflater.inflate(R.layout.fragment_maker, container, false); // requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); // setContentView(R.layout.main); // getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title); progressBarRange = (ProgressBar) v.findViewById(R.id.progressBarRange); //// ShapeDrawable progressBarRangeDrawable = new ShapeDrawable(new RoundRectShape(roundedCorners, null,null)); // ShapeDrawable progressBarRangeDrawable = new ShapeDrawable(); //// String progressBarRangeColor = "#FF00FF"; // String progressBarRangeColor = "#990099"; // progressBarRangeDrawable.getPaint().setColor(Color.parseColor(progressBarRangeColor)); // ClipDrawable progressRange = new ClipDrawable(progressBarRangeDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL); // progressBarRange.setProgressDrawable(progressRange); // progressBarRange.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.progress_horizontal)); // progressBarRange.setMax(128 + 127); progressBarRange.setMax(bloomRangeMax); // imageViewStatus = (ImageView) v.findViewById(R.id.imageViewStatus); servoSeekBar = (SeekBar) v.findViewById(R.id.ServoSeekBar); servoSeekBar.setEnabled(false);/*w ww .j a va 2s. co m*/ // servoSeekBar.setMax(180); servoSeekBar.setMax(100); servoSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { byte[] buf = new byte[] { (byte) 0x03, (byte) 0x00, (byte) 0x00 }; buf[1] = (byte) servoSeekBar.getProgress(); BloomSingleton.getInstance().characteristicTx.setValue(buf); BloomSingleton.getInstance().mBluetoothLeService .writeCharacteristic(BloomSingleton.getInstance().characteristicTx); } }); // rssiValue = (TextView) v.findViewById(R.id.rssiValue); connectBloom = (Button) v.findViewById(R.id.connectBloom); connectBloom.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { if (!BloomSingleton.getInstance().scanFlag) { scanLeDevice(); Timer mTimer = new Timer(); mTimer.schedule(new TimerTask() { @Override public void run() { if ((BloomSingleton.getInstance().mDevice != null) && (BloomSingleton.getInstance().mDevice.getAddress() != null) && (BloomSingleton.getInstance().mBluetoothLeService != null)) { BloomSingleton .getInstance().mDeviceAddress = BloomSingleton.getInstance().mDevice .getAddress(); if (BloomSingleton.getInstance().mDeviceAddress != null) BloomSingleton.getInstance().mBluetoothLeService .connect(BloomSingleton.getInstance().mDeviceAddress); else { Toast toast = Toast.makeText(getActivity(), "Error connecting to Puzzlebox Bloom", Toast.LENGTH_SHORT); toast.setGravity(0, 0, Gravity.CENTER | Gravity.BOTTOM); toast.show(); } BloomSingleton.getInstance().scanFlag = true; } else { getActivity().runOnUiThread(new Runnable() { public void run() { Toast toast = Toast.makeText(getActivity(), "Error connecting to Puzzlebox Bloom", Toast.LENGTH_SHORT); toast.setGravity(0, 0, Gravity.CENTER | Gravity.BOTTOM); toast.show(); } }); } } }, BloomSingleton.getInstance().SCAN_PERIOD); } } catch (Exception e) { Log.e(TAG, "Exception connecting to Bloom: " + e); Toast toast = Toast.makeText(getActivity(), "Exception connecting to Puzzlebox Bloom", Toast.LENGTH_SHORT); toast.setGravity(0, 0, Gravity.CENTER | Gravity.BOTTOM); toast.show(); } System.out.println(BloomSingleton.getInstance().connState); // Log.e(TAG, connState); // if (connState == false) { if (!BloomSingleton.getInstance().connState && BloomSingleton.getInstance().mDeviceAddress != null) { BloomSingleton.getInstance().mBluetoothLeService .connect(BloomSingleton.getInstance().mDeviceAddress); } else { if (BloomSingleton.getInstance().mBluetoothLeService != null) { setBloomRGBOff(); BloomSingleton.getInstance().mBluetoothLeService.disconnect(); BloomSingleton.getInstance().mBluetoothLeService.close(); setButtonDisable(); } } } }); redSeekBar = (SeekBar) v.findViewById(R.id.seekBarRed); redSeekBar.setEnabled(false); redSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { bloomColorRed = redSeekBar.getProgress(); byte[] buf = new byte[] { (byte) 0x0A, (byte) 0x00, (byte) bloomColorRed }; BloomSingleton.getInstance().characteristicTx.setValue(buf); BloomSingleton.getInstance().mBluetoothLeService .writeCharacteristic(BloomSingleton.getInstance().characteristicTx); } }); greenSeekBar = (SeekBar) v.findViewById(R.id.seekBarGreen); greenSeekBar.setEnabled(false); greenSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { bloomColorGreen = greenSeekBar.getProgress(); byte[] buf = new byte[] { (byte) 0x0A, (byte) 0x01, (byte) bloomColorGreen }; BloomSingleton.getInstance().characteristicTx.setValue(buf); BloomSingleton.getInstance().mBluetoothLeService .writeCharacteristic(BloomSingleton.getInstance().characteristicTx); } }); blueSeekBar = (SeekBar) v.findViewById(R.id.seekBarBlue); blueSeekBar.setEnabled(false); blueSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { bloomColorBlue = blueSeekBar.getProgress(); byte[] buf = new byte[] { (byte) 0x0A, (byte) 0x02, (byte) bloomColorBlue }; BloomSingleton.getInstance().characteristicTx.setValue(buf); BloomSingleton.getInstance().mBluetoothLeService .writeCharacteristic(BloomSingleton.getInstance().characteristicTx); } }); buttonOpen = (Button) v.findViewById(R.id.buttonOpen); buttonOpen.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { byte[] buf = new byte[] { (byte) 0x01, (byte) 0x00, (byte) 0x00 }; BloomSingleton.getInstance().characteristicTx.setValue(buf); BloomSingleton.getInstance().mBluetoothLeService .writeCharacteristic(BloomSingleton.getInstance().characteristicTx); } }); buttonClose = (Button) v.findViewById(R.id.buttonClose); buttonClose.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { byte[] buf = new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00 }; BloomSingleton.getInstance().characteristicTx.setValue(buf); BloomSingleton.getInstance().mBluetoothLeService .writeCharacteristic(BloomSingleton.getInstance().characteristicTx); } }); buttonCycleServo = (Button) v.findViewById(R.id.buttonDemoServo); buttonCycleServo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { byte[] buf = new byte[] { (byte) 0x03, (byte) 0x00, (byte) 0x00 }; // Cycle // byte[] buf = new byte[] { (byte) 0x04, (byte) 0x00, (byte) 0x00 }; // CycleSlow BloomSingleton.getInstance().characteristicTx.setValue(buf); BloomSingleton.getInstance().mBluetoothLeService .writeCharacteristic(BloomSingleton.getInstance().characteristicTx); } }); buttonCycleRGB = (Button) v.findViewById(R.id.buttonDemoRGB); buttonCycleRGB.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { byte[] buf = new byte[] { (byte) 0x06, (byte) 0x00, (byte) 0x00 }; BloomSingleton.getInstance().characteristicTx.setValue(buf); BloomSingleton.getInstance().mBluetoothLeService .writeCharacteristic(BloomSingleton.getInstance().characteristicTx); updateBloomRGB(); } }); buttonDemo = (Button) v.findViewById(R.id.buttonDemo); buttonDemo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { byte[] buf = new byte[] { (byte) 0x05, (byte) 0x00, (byte) 0x00 }; BloomSingleton.getInstance().characteristicTx.setValue(buf); BloomSingleton.getInstance().mBluetoothLeService .writeCharacteristic(BloomSingleton.getInstance().characteristicTx); } }); // buttonDemo = (Button) v.findViewById(R.id.buttonDemo); // buttonDemo.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // byte[] buf; //// if (! BloomSingleton.getInstance().demoActive) { // BloomSingleton.getInstance().demoActive = true; // // // bloomOpen() //// buf = new byte[]{(byte) 0x01, (byte) 0x00, (byte) 0x00}; //// BloomSingleton.getInstance().characteristicTx.setValue(buf); //// BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx); // // // loopRGB() // buf = new byte[]{(byte) 0x06, (byte) 0x00, (byte) 0x00}; // BloomSingleton.getInstance().characteristicTx.setValue(buf); // BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx); // // // Set Red to 0 // buf = new byte[]{(byte) 0x0A, (byte) 0x00, (byte) 0x00}; // R = 0 // BloomSingleton.getInstance().characteristicTx.setValue(buf); // BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx); // // // bloomClose() //// buf = new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00}; //// BloomSingleton.getInstance().characteristicTx.setValue(buf); //// BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx); // // //// } else { //// BloomSingleton.getInstance().demoActive = false; ////// buf = new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00}; ////// BloomSingleton.getInstance().characteristicTx.setValue(buf); ////// BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx); //// buf = new byte[]{(byte) 0x0A, (byte) 0x00, (byte) 0x00}; // R = 0 //// BloomSingleton.getInstance().characteristicTx.setValue(buf); //// BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx); ////// buf = new byte[]{(byte) 0x0A, (byte) 0x01, (byte) 0x00}; // G = 0 ////// BloomSingleton.getInstance().characteristicTx.setValue(buf); ////// BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx); ////// buf = new byte[]{(byte) 0x0A, (byte) 0x02, (byte) 0x00}; // B = 0 ////// BloomSingleton.getInstance().characteristicTx.setValue(buf); ////// BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx); //// } // } // }); if (!getActivity().getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { Toast.makeText(getActivity(), "Bluetooth LE not supported", Toast.LENGTH_SHORT).show(); getActivity().finish(); } final BluetoothManager mBluetoothManager = (BluetoothManager) getActivity() .getSystemService(Context.BLUETOOTH_SERVICE); BloomSingleton.getInstance().mBluetoothAdapter = mBluetoothManager.getAdapter(); if (BloomSingleton.getInstance().mBluetoothAdapter == null) { Toast.makeText(getActivity(), "Bluetooth LE not supported", Toast.LENGTH_SHORT).show(); getActivity().finish(); return v; } Intent gattServiceIntent = new Intent(getActivity(), RBLService.class); // bindService(gattServiceIntent, mServiceConnection, BIND_AUTO_CREATE); getActivity().bindService(gattServiceIntent, mServiceConnection, getActivity().BIND_AUTO_CREATE); /** * Update settings according to default UI */ updateScreenLayout(); // updatePowerThresholds(); // updatePower(); if (BloomSingleton.getInstance().connState) { setButtonEnable(); updateBloomRGB(); } return v; }
From source file:io.puzzlebox.bloom.ui.BloomFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View v = inflater.inflate(R.layout.fragment_bloom, container, false); // requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); // setContentView(R.layout.main); // getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title); progressBarAttention = (ProgressBar) v.findViewById(R.id.progressBarAttention); final float[] roundedCorners = new float[] { 5, 5, 5, 5, 5, 5, 5, 5 }; ShapeDrawable progressBarAttentionDrawable = new ShapeDrawable( new RoundRectShape(roundedCorners, null, null)); String progressBarAttentionColor = "#FF0000"; progressBarAttentionDrawable.getPaint().setColor(Color.parseColor(progressBarAttentionColor)); ClipDrawable progressAttention = new ClipDrawable(progressBarAttentionDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL);//from w w w . j ava 2 s . c o m progressBarAttention.setProgressDrawable(progressAttention); progressBarAttention .setBackgroundDrawable(getResources().getDrawable(android.R.drawable.progress_horizontal)); progressBarMeditation = (ProgressBar) v.findViewById(R.id.progressBarMeditation); ShapeDrawable progressBarMeditationDrawable = new ShapeDrawable( new RoundRectShape(roundedCorners, null, null)); String progressBarMeditationColor = "#0000FF"; progressBarMeditationDrawable.getPaint().setColor(Color.parseColor(progressBarMeditationColor)); ClipDrawable progressMeditation = new ClipDrawable(progressBarMeditationDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL); progressBarMeditation.setProgressDrawable(progressMeditation); progressBarMeditation .setBackgroundDrawable(getResources().getDrawable(android.R.drawable.progress_horizontal)); progressBarSignal = (ProgressBar) v.findViewById(R.id.progressBarSignal); ShapeDrawable progressBarSignalDrawable = new ShapeDrawable(new RoundRectShape(roundedCorners, null, null)); String progressBarSignalColor = "#00FF00"; progressBarSignalDrawable.getPaint().setColor(Color.parseColor(progressBarSignalColor)); ClipDrawable progressSignal = new ClipDrawable(progressBarSignalDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL); progressBarSignal.setProgressDrawable(progressSignal); progressBarSignal.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.progress_horizontal)); // progressBarSignal.setProgress(tgSignal); progressBarPower = (ProgressBar) v.findViewById(R.id.progressBarPower); ShapeDrawable progressBarPowerDrawable = new ShapeDrawable(new RoundRectShape(roundedCorners, null, null)); String progressBarPowerColor = "#FFFF00"; progressBarPowerDrawable.getPaint().setColor(Color.parseColor(progressBarPowerColor)); ClipDrawable progressPower = new ClipDrawable(progressBarPowerDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL); progressBarPower.setProgressDrawable(progressPower); progressBarPower.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.progress_horizontal)); // progressBarRange = (ProgressBar) v.findViewById(R.id.progressBarRange); //// ShapeDrawable progressBarRangeDrawable = new ShapeDrawable(new RoundRectShape(roundedCorners, null,null)); // ShapeDrawable progressBarRangeDrawable = new ShapeDrawable(); //// String progressBarRangeColor = "#FF00FF"; // String progressBarRangeColor = "#990099"; // progressBarRangeDrawable.getPaint().setColor(Color.parseColor(progressBarRangeColor)); // ClipDrawable progressRange = new ClipDrawable(progressBarRangeDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL); // progressBarRange.setProgressDrawable(progressRange); // progressBarRange.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.progress_horizontal)); // //// progressBarRange.setMax(128 + 127); // progressBarRange.setMax(bloomRangeMax); // progressBarBloom = (ProgressBar) v.findViewById(R.id.progressBarBloom); // ShapeDrawable progressBarBloomDrawable = new ShapeDrawable(new RoundRectShape(roundedCorners, null,null)); // String progressBarBloomColor = "#7F0000"; // progressBarBloomDrawable.getPaint().setColor(Color.parseColor(progressBarBloomColor)); // ClipDrawable progressBloom = new ClipDrawable(progressBarBloomDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL); // progressBarBloom.setProgressDrawable(progressBloom); // progressBarBloom.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.progress_horizontal)); seekBarAttention = (SeekBar) v.findViewById(R.id.seekBarAttention); seekBarAttention.setOnSeekBarChangeListener(this); seekBarMeditation = (SeekBar) v.findViewById(R.id.seekBarMeditation); seekBarMeditation.setOnSeekBarChangeListener(this); // imageViewStatus = (ImageView) v.findViewById(R.id.imageViewStatus); servoSeekBar = (SeekBar) v.findViewById(R.id.ServoSeekBar); servoSeekBar.setEnabled(false); // servoSeekBar.setMax(180); servoSeekBar.setMax(100); servoSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { byte[] buf = new byte[] { (byte) 0x03, (byte) 0x00, (byte) 0x00 }; buf[1] = (byte) servoSeekBar.getProgress(); BloomSingleton.getInstance().characteristicTx.setValue(buf); BloomSingleton.getInstance().mBluetoothLeService .writeCharacteristic(BloomSingleton.getInstance().characteristicTx); } }); // rssiValue = (TextView) v.findViewById(R.id.rssiValue); connectBloom = (Button) v.findViewById(R.id.connectBloom); connectBloom.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { if (!BloomSingleton.getInstance().scanFlag) { scanLeDevice(); Timer mTimer = new Timer(); mTimer.schedule(new TimerTask() { @Override public void run() { if ((BloomSingleton.getInstance().mDevice != null) && (BloomSingleton.getInstance().mDevice.getAddress() != null) && (BloomSingleton.getInstance().mBluetoothLeService != null)) { BloomSingleton .getInstance().mDeviceAddress = BloomSingleton.getInstance().mDevice .getAddress(); if (BloomSingleton.getInstance().mDeviceAddress != null) BloomSingleton.getInstance().mBluetoothLeService .connect(BloomSingleton.getInstance().mDeviceAddress); else { Toast toast = Toast.makeText(getActivity(), "Error connecting to Puzzlebox Bloom", Toast.LENGTH_SHORT); toast.setGravity(0, 0, Gravity.CENTER | Gravity.BOTTOM); toast.show(); } BloomSingleton.getInstance().scanFlag = true; } else { getActivity().runOnUiThread(new Runnable() { public void run() { Toast toast = Toast.makeText(getActivity(), "Error connecting to Puzzlebox Bloom", Toast.LENGTH_SHORT); toast.setGravity(0, 0, Gravity.CENTER | Gravity.BOTTOM); toast.show(); } }); } } }, BloomSingleton.getInstance().SCAN_PERIOD); } } catch (Exception e) { Log.e(TAG, "Exception connecting to Bloom: " + e); Toast toast = Toast.makeText(getActivity(), "Exception connecting to Puzzlebox Bloom", Toast.LENGTH_SHORT); toast.setGravity(0, 0, Gravity.CENTER | Gravity.BOTTOM); toast.show(); } System.out.println(BloomSingleton.getInstance().connState); // Log.e(TAG, connState); // if (connState == false) { if (!BloomSingleton.getInstance().connState && BloomSingleton.getInstance().mDeviceAddress != null) { BloomSingleton.getInstance().mBluetoothLeService .connect(BloomSingleton.getInstance().mDeviceAddress); } else { if (BloomSingleton.getInstance().mBluetoothLeService != null) { setBloomRGBOff(); BloomSingleton.getInstance().mBluetoothLeService.disconnect(); BloomSingleton.getInstance().mBluetoothLeService.close(); setButtonDisable(); } } } }); // Button buttonOpen = (Button) v.findViewById(R.id.buttonOpen); // buttonOpen.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // byte[] buf = new byte[] { (byte) 0x01, (byte) 0x00, (byte) 0x00 }; // BloomSingleton.getInstance().characteristicTx.setValue(buf); // BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx); // } // }); // buttonOpen.setVisibility(View.GONE); // // Button buttonClose = (Button) v.findViewById(R.id.buttonClose); // buttonClose.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // byte[] buf = new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00 }; // BloomSingleton.getInstance().characteristicTx.setValue(buf); // BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx); // } // }); // buttonClose.setVisibility(View.GONE); // buttonDemo = (Button) v.findViewById(R.id.buttonDemo); // buttonDemo.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // byte[] buf; //// if (! BloomSingleton.getInstance().demoActive) { // BloomSingleton.getInstance().demoActive = true; // // // bloomOpen() //// buf = new byte[]{(byte) 0x01, (byte) 0x00, (byte) 0x00}; //// BloomSingleton.getInstance().characteristicTx.setValue(buf); //// BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx); // // // loopRGB() // buf = new byte[]{(byte) 0x06, (byte) 0x00, (byte) 0x00}; // BloomSingleton.getInstance().characteristicTx.setValue(buf); // BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx); // // // Set Red to 0 // buf = new byte[]{(byte) 0x0A, (byte) 0x00, (byte) 0x00}; // R = 0 // BloomSingleton.getInstance().characteristicTx.setValue(buf); // BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx); // // // bloomClose() //// buf = new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00}; //// BloomSingleton.getInstance().characteristicTx.setValue(buf); //// BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx); // // //// } else { //// BloomSingleton.getInstance().demoActive = false; ////// buf = new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00}; ////// BloomSingleton.getInstance().characteristicTx.setValue(buf); ////// BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx); //// buf = new byte[]{(byte) 0x0A, (byte) 0x00, (byte) 0x00}; // R = 0 //// BloomSingleton.getInstance().characteristicTx.setValue(buf); //// BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx); ////// buf = new byte[]{(byte) 0x0A, (byte) 0x01, (byte) 0x00}; // G = 0 ////// BloomSingleton.getInstance().characteristicTx.setValue(buf); ////// BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx); ////// buf = new byte[]{(byte) 0x0A, (byte) 0x02, (byte) 0x00}; // B = 0 ////// BloomSingleton.getInstance().characteristicTx.setValue(buf); ////// BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx); //// } // } // }); if (!getActivity().getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { Toast.makeText(getActivity(), "Bluetooth LE not supported", Toast.LENGTH_SHORT).show(); getActivity().finish(); } final BluetoothManager mBluetoothManager = (BluetoothManager) getActivity() .getSystemService(Context.BLUETOOTH_SERVICE); BloomSingleton.getInstance().mBluetoothAdapter = mBluetoothManager.getAdapter(); if (BloomSingleton.getInstance().mBluetoothAdapter == null) { Toast.makeText(getActivity(), "Bluetooth LE not supported", Toast.LENGTH_SHORT).show(); getActivity().finish(); return v; } Intent gattServiceIntent = new Intent(getActivity(), RBLService.class); // bindService(gattServiceIntent, mServiceConnection, BIND_AUTO_CREATE); getActivity().bindService(gattServiceIntent, mServiceConnection, getActivity().BIND_AUTO_CREATE); /** * Update settings according to default UI */ updateScreenLayout(); // updatePowerThresholds(); // updatePower(); if (BloomSingleton.getInstance().connState) setButtonEnable(); return v; }
From source file:com.coinblesk.client.utils.UIUtils.java
private static boolean isBluetoothEnabled(Context context) { BluetoothManager bm = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE); BluetoothAdapter mBluetoothAdapter = bm.getAdapter(); return mBluetoothAdapter != null && mBluetoothAdapter.isEnabled(); }
From source file:com.coinblesk.client.utils.UIUtils.java
private static boolean hasBluetoothLEAdvertiser(Context context) { BluetoothManager bm = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE); BluetoothAdapter mBluetoothAdapter = bm.getAdapter(); return mBluetoothAdapter != null && mBluetoothAdapter.isMultipleAdvertisementSupported(); }
From source file:com.coinblesk.client.utils.UIUtils.java
private static void disableBluetooth(Activity activity) { BluetoothManager bm = (BluetoothManager) activity.getSystemService(Context.BLUETOOTH_SERVICE); BluetoothAdapter mBluetoothAdapter = bm.getAdapter(); if (mBluetoothAdapter != null && mBluetoothAdapter.isEnabled()) { mBluetoothAdapter.disable();//from w w w . jav a 2 s.co m Intent exchangeRateChanged = new Intent(Constants.EXCHANGE_RATE_CHANGED_ACTION); LocalBroadcastManager.getInstance(activity).sendBroadcast(exchangeRateChanged); } }