@@ -94,6 +94,7 @@ public class TranslationFragment extends Fragment {
9494 private FloatingActionButton ttsOutputButton ;
9595 private ConstraintLayout outputContainer ;
9696 private TextView resultTypeText ;
97+ private TextView synonymsText ;
9798 private CustomAnimator animator = new CustomAnimator ();
9899 private Animator colorAnimator = null ;
99100 private int activatedColor = R .color .primary ;
@@ -103,8 +104,10 @@ public class TranslationFragment extends Fragment {
103104 private boolean isInputEmpty = true ;
104105 private boolean isOutputEmpty = true ;
105106 private boolean isOutputTypeVisible = false ;
107+ private boolean isSynonymsTextVisible = false ;
106108 ViewTreeObserver .OnGlobalLayoutListener layoutListener ;
107109 private static final int REDUCED_GUI_THRESHOLD_DP = 550 ;
110+ private static final int synonymsTopMargin = 16 ;
108111
109112 //languageListDialog
110113 private LanguageListAdapter listView ;
@@ -130,6 +133,8 @@ public class TranslationFragment extends Fragment {
130133 private Animator animationOutput ;
131134 @ Nullable
132135 private Animator animationResultType ;
136+ @ Nullable
137+ private Animator animationSynonyms ;
133138
134139
135140 @ Override
@@ -171,6 +176,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
171176 ttsOutputButton = view .findViewById (R .id .ttsButtonOutput );
172177 outputContainer = view .findViewById (R .id .outputContainer );
173178 resultTypeText = view .findViewById (R .id .resultTypeText );
179+ synonymsText = view .findViewById (R .id .synonymsText );
174180 //we set the initial tag for the tts buttons
175181 ttsInputButton .setTag (R .drawable .sound_icon );
176182 ttsOutputButton .setTag (R .drawable .sound_icon );
@@ -215,9 +221,10 @@ public void onClick(View view) {
215221 conversationButtonSmall .setOnClickListener (conversationButtonListener );
216222 translateListener = new Translator .TranslateListener () {
217223 @ Override
218- public void onTranslatedText (String textToTranslate , String text , long resultID , boolean isFinal , ResultType resultType , CustomLocale languageOfText ) {
224+ public void onTranslatedText (String textToTranslate , String text , String [] synonyms , long resultID , boolean isFinal , ResultType resultType , CustomLocale languageOfText ) {
219225 outputText .setText (text );
220226 if (isFinal ){
227+ //eventually we show result type text
221228 if (resultType != ResultType .NORMAL ){
222229 isOutputTypeVisible = true ;
223230 if (animationResultType != null ) {
@@ -237,6 +244,25 @@ public void onAnimationEnd() {
237244 }
238245 });
239246 }
247+ //eventually we show the synonyms of the translated word
248+ if (synonyms != null && synonyms .length > 0 ){
249+ isSynonymsTextVisible = true ;
250+ if (animationSynonyms != null ) {
251+ animationSynonyms .cancel ();
252+ }
253+ String t = synonyms [0 ];
254+ for (int i =1 ; i <synonyms .length ; i ++){
255+ t = ", " +synonyms [i ];
256+ }
257+ synonymsText .setText (t );
258+ animationSynonyms = animator .animateSynonymsTextEnlargement (activity , synonymsText , synonymsTopMargin , new CustomAnimator .Listener () {
259+ @ Override
260+ public void onAnimationEnd () {
261+ super .onAnimationEnd ();
262+ animationSynonyms = null ;
263+ }
264+ });
265+ }
240266 activateTranslationButton ();
241267 }
242268 }
@@ -355,7 +381,7 @@ public void afterTextChanged(Editable s) {
355381 }
356382 if (isInputEmpty != s .toString ().isEmpty ()){ //the input editText transitioned from empty to not empty or vice versa
357383 isInputEmpty = s .toString ().isEmpty ();
358- if (animationInput != null ){
384+ if (animationInput != null ) {
359385 animationInput .cancel ();
360386 }
361387 if (!s .toString ().isEmpty ()) {
@@ -403,6 +429,7 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
403429
404430 @ Override
405431 public void afterTextChanged (Editable s ) {
432+ //we eventually make the result type disappear
406433 if (isOutputTypeVisible ) {
407434 isOutputTypeVisible = false ;
408435 if (animationResultType != null ) {
@@ -416,6 +443,21 @@ public void onAnimationEnd() {
416443 }
417444 });
418445 }
446+ //we eventually make the synonyms of the result disappear
447+ if (isSynonymsTextVisible ) {
448+ isSynonymsTextVisible = false ;
449+ if (animationSynonyms != null ) {
450+ animationSynonyms .cancel ();
451+ }
452+ animationSynonyms = animator .animateSynonymsTextReduction (activity , synonymsText , synonymsTopMargin , new CustomAnimator .Listener () {
453+ @ Override
454+ public void onAnimationEnd () {
455+ super .onAnimationEnd ();
456+ animationSynonyms = null ;
457+ }
458+ });
459+ }
460+ //if the output text is empty we make it disappear
419461 if (isOutputEmpty != s .toString ().isEmpty ()){ //the output editText transitioned from empty to not empty or vice versa
420462 isOutputEmpty = s .toString ().isEmpty ();
421463 if (animationOutput != null ) {
0 commit comments