wired up all basic OD client functionality (except disconnect)
This commit is contained in:
parent
63b4a86999
commit
fd5b1826de
|
@ -3,6 +3,7 @@ package im.ricochet.androidod;
|
|||
import android.os.AsyncTask;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
@ -19,6 +20,8 @@ public class RemoteActivity extends AppCompatActivity {
|
|||
Button highButton;
|
||||
Button disconnectButton;
|
||||
|
||||
int vibeLevel = 0;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -34,13 +37,58 @@ public class RemoteActivity extends AppCompatActivity {
|
|||
highButton = (Button)findViewById(R.id.highButton);
|
||||
disconnectButton = (Button)findViewById(R.id.disconnetButton);
|
||||
|
||||
offButton.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
SetLevelTask setLevelTask = new SetLevelTask();
|
||||
setLevelTask.execute(0);
|
||||
}
|
||||
});
|
||||
lowButton.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
SetLevelTask setLevelTask = new SetLevelTask();
|
||||
setLevelTask.execute(2);
|
||||
}
|
||||
});
|
||||
medButton.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
SetLevelTask setLevelTask = new SetLevelTask();
|
||||
setLevelTask.execute(4);
|
||||
}
|
||||
});
|
||||
highButton.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
SetLevelTask setLevelTask = new SetLevelTask();
|
||||
setLevelTask.execute(6);
|
||||
}
|
||||
});
|
||||
|
||||
GetDeviceNameTask getDeviceNameTask = new GetDeviceNameTask();
|
||||
getDeviceNameTask.execute();
|
||||
|
||||
GetBatteryTask getBatteryTask = new GetBatteryTask();
|
||||
getBatteryTask.execute();
|
||||
|
||||
GetLevelTask getLevelTask = new GetLevelTask();
|
||||
getLevelTask.execute();
|
||||
}
|
||||
|
||||
// current impelementation of OD server can return 0 to 6 (potentially downsampled from 12?)
|
||||
// The go API respects that, further downsample to [off low med high] here
|
||||
// Assuming 1 means off and 2-6 are active states...
|
||||
private void setVibeLevel(int newVibeLevel) {
|
||||
vibeLevel = newVibeLevel;
|
||||
if (vibeLevel == 1) {
|
||||
statusText.setText("Off");
|
||||
} else if (vibeLevel == 2) {
|
||||
statusText.setText("Low");
|
||||
} else if (vibeLevel == 3 || vibeLevel == 4) {
|
||||
statusText.setText("Medium");
|
||||
} else if (vibeLevel == 5 || vibeLevel == 6) {
|
||||
statusText.setText("High");
|
||||
}
|
||||
}
|
||||
|
||||
private class GetDeviceNameTask extends AsyncTask<Void, Void, String> {
|
||||
|
||||
@Override
|
||||
protected String doInBackground(Void... params) {
|
||||
String name = GoRicochetMobile.getDeviceName();
|
||||
|
@ -52,4 +100,44 @@ public class RemoteActivity extends AppCompatActivity {
|
|||
deviceText.setText(deviceName);
|
||||
}
|
||||
}
|
||||
|
||||
private class GetBatteryTask extends AsyncTask<Void, Void, String> {
|
||||
@Override
|
||||
protected String doInBackground(Void... params) {
|
||||
String batteryLevel = GoRicochetMobile.getBatteryLevel();
|
||||
return batteryLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(String batteryLevel) {
|
||||
batteryText.setText(batteryLevel + "%");
|
||||
}
|
||||
}
|
||||
|
||||
private class GetLevelTask extends AsyncTask<Void, Void, Integer> {
|
||||
@Override
|
||||
protected Integer doInBackground(Void... params) {
|
||||
Integer vibeLevel = (int) GoRicochetMobile.getVibeLevel();
|
||||
return vibeLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Integer newVibeLevel) {
|
||||
setVibeLevel(newVibeLevel);
|
||||
}
|
||||
}
|
||||
|
||||
private class SetLevelTask extends AsyncTask<Integer, Void, Integer> {
|
||||
@Override
|
||||
protected Integer doInBackground(Integer... params) {
|
||||
Integer newVibeLevel = params[0];
|
||||
GoRicochetMobile.setVibeLevel(newVibeLevel);
|
||||
return newVibeLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Integer newVibeLevel) {
|
||||
setVibeLevel(newVibeLevel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintLeft_toRightOf="@+id/textView7"
|
||||
android:layout_marginLeft="0dp"
|
||||
android:layout_marginLeft="8dp"
|
||||
app:layout_constraintTop_toTopOf="@+id/textView7"
|
||||
android:layout_marginTop="0dp" />
|
||||
|
||||
|
|
Loading…
Reference in New Issue