-
-
Save Mindstormer619/c3125914a49703e5c1bc9e5bd59899a0 to your computer and use it in GitHub Desktop.
Retromania app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~~~ | |
dependencies { | |
compile fileTree(dir: 'libs', include: ['*.jar']) | |
testCompile 'junit:junit:4.12' | |
compile 'com.android.support:appcompat-v7:23.4.0' | |
compile 'com.squareup.okhttp3:okhttp:3.4.1' | |
compile 'com.squareup.okhttp3:okhttp-ws:3.4.1' | |
compile ('io.socket:socket.io-client:0.7.0') { | |
// excluding org.json which is provided by Android | |
exclude group: 'org.json', module: 'json' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends AppCompatActivity implements SensorEventListener { | |
Socket socket; | |
SensorManager sensorManager; | |
Sensor accelerometer; | |
TextView textView; | |
String ip_addr; | |
String y_value; | |
boolean isRunning=true; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
textView = (TextView) findViewById(R.id.textView); | |
sensorManager= (SensorManager) getSystemService(Context.SENSOR_SERVICE); | |
accelerometer=sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); | |
ip_addr="192.168.43.155"; | |
try { | |
socket= IO.socket("http://"+ip_addr+":7171"); | |
} catch (URISyntaxException e) { | |
e.printStackTrace(); | |
} | |
socket.connect(); | |
} | |
@Override | |
public void onSensorChanged(SensorEvent event) { | |
float ax,ay,az; | |
ax=event.values[0]; //x value | |
ay=event.values[1]; //y value | |
az=event.values[2]; //z value | |
y_value=String.valueOf(ay); | |
textView.setText(String.valueOf(ay)); | |
socket.emit("app-message",ay); | |
} | |
@Override | |
public void onAccuracyChanged(Sensor sensor, int accuracy) { | |
} | |
protected void onResume() { | |
super.onResume(); | |
sensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_NORMAL); | |
isRunning=true; | |
} | |
protected void onPause() { | |
super.onPause(); | |
sensorManager.unregisterListener(this); | |
isRunning=false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment