Commit c3283389 authored by Henry Heino's avatar Henry Heino
Browse files

Extract string resources

parent c5036b54
......@@ -21,20 +21,27 @@ public class MainActivity extends AppCompatActivity {
eventDisplay.setText(R.string.click_event);
});
mainLayout.setOnTouchListener((target, evt) -> {
displayMotionEvent("TouchEvent", evt);
displayMotionEvent(R.string.touch_event, evt);
return false;
});
mainLayout.setOnGenericMotionListener((target, evt) -> {
displayMotionEvent("Generic MotionEvent", evt);
displayMotionEvent(R.string.motion_event, evt);
return false;
});
}
private void displayMotionEvent(String eventType, MotionEvent evt) {
/**
* Display data about a motion event.
*
* @param eventType Resource ID of the string to display as the type
* of the event
* @param evt Event record associated with the event
*/
private void displayMotionEvent(int eventType, MotionEvent evt) {
TextView eventDisplay = findViewById(R.id.event_display);
eventDisplay.setText(
getResources().getString(R.string.event_rec_display,
eventType,
getResources().getString(eventType),
MotionEvent.actionToString(evt.getAction()),
evt.getX(),
evt.getY(),
......
......@@ -9,7 +9,7 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:text="@string/waiting_for_event"
android:id="@+id/event_display"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
......
......@@ -13,4 +13,7 @@
pointerCount: %d
</string>
<string name="click_event">Click event!</string>
<string name="waiting_for_event">Waiting for event…</string>
<string name="touch_event">Touch Event</string>
<string name="motion_event">Motion Event</string>
</resources>
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment