Skip to content

Instantly share code, notes, and snippets.

@b00sti
Created April 6, 2017 10:30
Show Gist options
  • Save b00sti/e78e7a06abc912554e77fa2df664e55f to your computer and use it in GitHub Desktop.
Save b00sti/e78e7a06abc912554e77fa2df664e55f to your computer and use it in GitHub Desktop.
@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