Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.harrysoft.androidbluetoothserial.demoapp;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.BatteryManager;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
Expand All @@ -22,9 +27,21 @@ public class CommunicateActivity extends AppCompatActivity {
private EditText messageBox;
private Button sendButton, connectButton;
private JoystickView joystick;
private TextView battery;

private CommunicateViewModel viewModel;

//Get Battery state
private BroadcastReceiver nBatInfoReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {

int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL,0);
battery.setText(String.valueOf(level)+"%");

}
};

@Override
protected void onCreate(Bundle savedInstanceState) {
// Setup our activity
Expand All @@ -35,6 +52,9 @@ protected void onCreate(Bundle savedInstanceState) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}

battery = (TextView) this.findViewById(R.id.communicate_messages);
this.registerReceiver(this.nBatInfoReceiver,new IntentFilter(Intent.ACTION_BATTERY_CHANGED));

// Setup our ViewModel
viewModel = ViewModelProviders.of(this).get(CommunicateViewModel.class);

Expand Down