Skip to content
This repository has been archived by the owner on Sep 27, 2020. It is now read-only.

Commit

Permalink
use executors for async function
Browse files Browse the repository at this point in the history
added wevibe cougar to bluetooth emulator
added devices tab
bumped client to schema version 1
added embedded client
switched ws client to java-websocket
initial interface and ws client integration with exampleclientgui
fixed edittext focus in nested scrollview
added open source notice to about tab
converted all Class references to simpleName
added android studio 3.1 files to .gitignore
bumped gradle version
bumped support lib version
  • Loading branch information
mftrips committed Apr 18, 2018
1 parent 9de8864 commit 2789cf8
Show file tree
Hide file tree
Showing 67 changed files with 1,544 additions and 681 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -2,6 +2,9 @@
.gradle
/local.properties
/.idea/workspace.xml
/.idea/caches
/.idea/codeStyles
/.idea/dictionaries
/.idea/libraries
.DS_Store
/build
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Expand Up @@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
classpath 'com.android.tools.build:gradle:3.1.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -27,7 +27,7 @@ ext {
targetSdkVersion = 27
versionCode = 1
versionName = "0.1"
supportLibVersion = "27.1.0"
supportLibVersion = "27.1.1"
}

task clean(type: Delete) {
Expand Down
Expand Up @@ -37,6 +37,7 @@
import org.metafetish.buttplug.server.bluetooth.devices.FleshlightLaunchBluetoothInfo;
import org.metafetish.buttplug.server.bluetooth.devices.KiirooBluetoothInfo;
import org.metafetish.buttplug.server.bluetooth.devices.VorzeA10CycloneInfo;
import org.metafetish.buttplug.server.bluetooth.devices.WeVibeBluetoothInfo;
import org.metafetish.buttplug.server.util.FleshlightHelper;

import java.util.ArrayList;
Expand All @@ -45,7 +46,7 @@

public class MainActivity extends AppCompatActivity {
private ButtplugLogManager bpLogManager = new ButtplugLogManager();
private IButtplugLog bpLogger = this.bpLogManager.getLogger(this.getClass());
private IButtplugLog bpLogger = this.bpLogManager.getLogger(this.getClass().getSimpleName());

private List<IBluetoothDeviceInfo> deviceInfos;

Expand All @@ -55,6 +56,7 @@ public class MainActivity extends AppCompatActivity {

private TextView status;
private ImageView icon;
private ImageView icon2;
private BluetoothGattServer bluetoothGattServer;
private BluetoothGattCharacteristic tx;
private BluetoothLeAdvertiser bluetoothLeAdvertiser;
Expand All @@ -77,11 +79,13 @@ protected void onCreate(Bundle savedInstanceState) {
this.deviceInfos = new ArrayList<>();
deviceInfos.add(new FleshlightLaunchBluetoothInfo());
deviceInfos.add(new KiirooBluetoothInfo());
deviceInfos.add(new WeVibeBluetoothInfo());
deviceInfos.add(new VorzeA10CycloneInfo());

List<String> deviceNames = new ArrayList<>();
deviceNames.add("Fleshlight Launch");
deviceNames.add("Kiiroo Pearl");
deviceNames.add("WeVibe Cougar");
deviceNames.add("Vorze A10 Cyclone");

this.sharedPreferences = this.getPreferences(Context.MODE_PRIVATE);
Expand Down Expand Up @@ -116,12 +120,22 @@ public void onNothingSelected(AdapterView<?> adapterView) {
private void prepareDevice() {
this.status = findViewById(R.id.status);
this.icon = findViewById(R.id.icon);
this.icon2 = findViewById(R.id.icon2);

if (this.objectAnimator != null) {
this.objectAnimator.cancel();
}
IBluetoothDeviceInfo deviceInfo = this.deviceInfos.get(
((Spinner) findViewById(R.id.device)).getSelectedItemPosition());

this.icon.setTranslationY(0);
this.icon.setRotation(0);
this.icon2.setRotation(0);
if (deviceInfo instanceof WeVibeBluetoothInfo) {
this.icon2.setVisibility(View.VISIBLE);
} else {
this.icon2.setVisibility(View.INVISIBLE);
}

BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context
.BLUETOOTH_SERVICE);
Expand Down Expand Up @@ -198,9 +212,6 @@ public void onCharacteristicWriteRequest(
this.bpLogger.trace(String.format("bluetoothGattServer services size: %s",
this.bluetoothGattServer.getServices().size()));

IBluetoothDeviceInfo deviceInfo = this.deviceInfos.get(
((Spinner) findViewById(R.id.device)).getSelectedItemPosition());

BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter();
this.bpLogger.trace(String.format("bluetoothAdapter name: %s", bluetoothAdapter.getName()));
int deviceIndex = 0;
Expand Down Expand Up @@ -353,22 +364,13 @@ public void run() {
objectAnimator.setInterpolator(new LinearInterpolator());
objectAnimator.start();
} else if (deviceInfo instanceof KiirooBluetoothInfo) {
MainActivity.this.icon.setTranslationY(0);
MainActivity.this.icon.setRotation(0);
float degrees = MainActivity.this.lastCommand[0] - 48;
if (degrees > 0) {
RotateAnimation rotateAnimation = new RotateAnimation(-degrees, degrees,
Animation.RELATIVE_TO_SELF,
0.5f,
Animation.RELATIVE_TO_SELF,
0.5f);
rotateAnimation.setDuration(10);
rotateAnimation.setRepeatCount(Animation.INFINITE);
rotateAnimation.setRepeatMode(Animation.REVERSE);
MainActivity.this.icon.startAnimation(rotateAnimation);
} else {
MainActivity.this.icon.clearAnimation();
}
MainActivity.this.vibrateImageView(MainActivity.this.icon, degrees);
} else if (deviceInfo instanceof WeVibeBluetoothInfo) {
float degreesExt = (float) (MainActivity.this.lastCommand[3] & 0x0f) / 4;
MainActivity.this.vibrateImageView(MainActivity.this.icon, degreesExt);
float degreesInt = (float) ((MainActivity.this.lastCommand[3] & 0xf0) >> 4) / 4;
MainActivity.this.vibrateImageView(MainActivity.this.icon2, degreesInt);
} else if (deviceInfo instanceof VorzeA10CycloneInfo) {
MainActivity.this.icon.setTranslationY(0);
float speed = MainActivity.this.lastCommand[2];
Expand All @@ -395,6 +397,24 @@ public void run() {
});
}

private void vibrateImageView(ImageView icon, float degrees) {
icon.setTranslationY(0);
icon.setRotation(0);
if (degrees > 0) {
RotateAnimation rotateAnimation = new RotateAnimation(-degrees, degrees,
Animation.RELATIVE_TO_SELF,
0.5f,
Animation.RELATIVE_TO_SELF,
0.5f);
rotateAnimation.setDuration(10);
rotateAnimation.setRepeatCount(Animation.INFINITE);
rotateAnimation.setRepeatMode(Animation.REVERSE);
icon.startAnimation(rotateAnimation);
} else {
icon.clearAnimation();
}
}

private float fromDp(double dp) {
return (float) (dp * this.getResources().getDisplayMetrics().density);
}
Expand Down
Expand Up @@ -63,4 +63,16 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/status_label" />

<ImageView
android:id="@+id/icon2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:contentDescription="@string/icon_desc"
android:visibility="invisible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/icon"
app:srcCompat="@mipmap/ic_launcher" />

</android.support.constraint.ConstraintLayout>
7 changes: 1 addition & 6 deletions buttplug.apps.ExampleClientGUI/build.gradle
Expand Up @@ -29,12 +29,7 @@ android {

applicationVariants.all { variant ->
variant.outputs.all { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
def buildType = variant.variantData.variantConfiguration.buildType.name
def fileName = "${project.name}-${variant.versionName}-${buildType}.apk"
outputFileName = fileName
}
outputFileName = "${project.name}-${variant.versionName}-${variant.name}.apk"
}
}

Expand Down
Expand Up @@ -6,6 +6,7 @@
<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".ExampleClientDeviceApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
Expand Down
@@ -0,0 +1,45 @@
package org.metafetish.buttplug.apps.exampleclientgui;

import android.app.Application;
import android.support.annotation.NonNull;

import org.metafetish.buttplug.components.controls.IButtplugDeviceApplication;
import org.metafetish.buttplug.core.ButtplugEventHandler;

public class ExampleClientDeviceApplication extends Application implements IButtplugDeviceApplication {
private ButtplugEventHandler startScanning = new ButtplugEventHandler();
private ButtplugEventHandler stopScanning = new ButtplugEventHandler();
private ButtplugEventHandler deviceAdded = new ButtplugEventHandler();
private ButtplugEventHandler deviceRemoved = new ButtplugEventHandler();
private ButtplugEventHandler devicesReset = new ButtplugEventHandler();

@NonNull
@Override
public ButtplugEventHandler getStartScanning() {
return this.startScanning;
}

@NonNull
@Override
public ButtplugEventHandler getStopScanning() {
return this.stopScanning;
}

@NonNull
@Override
public ButtplugEventHandler getDeviceAdded() {
return this.deviceAdded;
}

@NonNull
@Override
public ButtplugEventHandler getDeviceRemoved() {
return this.deviceRemoved;
}

@NonNull
@Override
public ButtplugEventHandler getDevicesReset() {
return this.devicesReset;
}
}

0 comments on commit 2789cf8

Please sign in to comment.