Created
April 6, 2017 10:30
-
-
Save b00sti/e78e7a06abc912554e77fa2df664e55f to your computer and use it in GitHub Desktop.
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
@EActivity(R.layout.translate) // Sets content view to R.layout.translate | |
public class TranslateActivity extends Activity { | |
@ViewById // Injects R.id.textInput | |
EditText textInput; | |
@ViewById(R.id.myTextView) // Injects R.id.myTextView | |
TextView result; | |
@AnimationRes // Injects android.R.anim.fade_in | |
Animation fadeIn; | |
@Click // When R.id.doTranslate button is clicked | |
void doTranslate() { | |
translateInBackground(textInput.getText().toString()); | |
} | |
@Background // Executed in a background thread | |
void translateInBackground(String textToTranslate) { | |
String translatedText = callGoogleTranslate(textToTranslate); | |
showResult(translatedText); | |
} | |
@UiThread // Executed in the ui thread | |
void showResult(String translatedText) { | |
result.setText(translatedText); | |
result.startAnimation(fadeIn); | |
} | |
// [...] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment