ImageView imageview = (ImageView) findViewById(R.id.imageView);
// imageview click callback
imageview.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
TextView textview = (TextView) findViewById(R.id.textView);
textview.setText("Image is clicked");
}
});
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.floatingActionButton);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
rotate();
}
});
// my function for image rotation
// use a fixed value (45 degrees) here for later expansion
private void rotate() {
... //// As assignment
}
public class MainActivity extends AppCompatActivity implements SensorEventListener {
SensorManager sensorManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
...
sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
...
}
@Override
protected void onResume() {
super.onResume();
//// for the system's orientation sensor registered listeners
}
@Override
protected void onPause() {
super.onPause();
//// to stop the listener and save battery
}
@Override
public void onSensorChanged(SensorEvent event) {
//// get the angle around the z-axis rotated and update textview
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
//// not in use, NO CODE HERE
}
public class MainActivity extends AppCompatActivity implements SensorEventListener, TextToSpeech.OnInitListener {
TextToSpeech tts;
@Override
protected void onCreate(Bundle savedInstanceState) {
...
tts = new TextToSpeech(this, this);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.floatingActionButton);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
speakOut();
}
});
@Override
public void onDestroy() {
//// Don't forget to shutdown tts!
super.onDestroy();
}
@Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
int result = tts.setLanguage(Locale.US);
if (result == TextToSpeech.LANG_MISSING_DATA
|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
} else {
}
} else {
}
}
private void speakOut() {
String text = "You are facing ";
... //// As assignment
}
private String direction;
private String dir[] = {"North","Northeast","East","Southeast","South","Southwest","West","Northwest","North"};
//// speaks the direction using degrees
String text = editText.getText().toString(); tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION),
SensorManager.SENSOR_DELAY_GAME);