dialog
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package ru.vtosters.lite.translators;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
|
||||
public class Translate{
|
||||
public static void dialog(String text) {
|
||||
new Handler(Looper.getMainLooper()).post(() -> {
|
||||
String translated;
|
||||
|
||||
Log.d("Translate", text + " will be translated");
|
||||
|
||||
try {
|
||||
translated = YandexTranslator.translate(text); // for future
|
||||
} catch (Exception e) {
|
||||
translated = "Error";
|
||||
Log.e("Translate", e.getMessage());
|
||||
}
|
||||
|
||||
Context ctx = getGlobalContext();
|
||||
AlertDialog.Builder alertDialog = new AlertDialog.Builder(ctx);
|
||||
alertDialog.setTitle("Переводчик");
|
||||
alertDialog.setMessage(translated);
|
||||
alertDialog.setPositiveButton("Закрыть", (dialog, which) -> {
|
||||
dialog.cancel();
|
||||
});
|
||||
var alert = alertDialog.create();
|
||||
alert.show();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
@@ -17,7 +16,7 @@ import okhttp3.RequestBody;
|
||||
|
||||
public class YandexTranslator {
|
||||
|
||||
private static OkHttpClient client = new OkHttpClient();
|
||||
private static final OkHttpClient client = new OkHttpClient();
|
||||
|
||||
static String uuid = UUID.randomUUID().toString().replace("-", "");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user