This commit is contained in:
Igor I
2025-08-25 09:04:23 +05:00
parent 9d750fc6a3
commit 930ae8eafb
5 changed files with 74 additions and 3 deletions

View File

@ -1,5 +1,6 @@
package kz.istt.locust; package kz.istt.locust;
import androidx.core.app.ActivityCompat;
import androidx.core.content.res.ResourcesCompat; import androidx.core.content.res.ResourcesCompat;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
@ -8,6 +9,7 @@ import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap; import android.graphics.Bitmap;
@ -103,8 +105,28 @@ public class MapsActivity extends FragmentActivity implements OnMapReadyCallback
if(g_uid==null) g_uid=""; if(g_uid==null) g_uid="";
// Чтоб слушать GPS // Чтоб слушать GPS
lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 500, 1, this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && checkSelfPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{
android.Manifest.permission.ACCESS_FINE_LOCATION,
android.Manifest.permission.ACCESS_COARSE_LOCATION
}, 1001);
}else{
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 500, 1, this);
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (requestCode == 1) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 500, 1, this);
} else {
Toast.makeText(this, getResources().getString(R.string.Please_activate_GPS), Toast.LENGTH_LONG).show();
}
}
} }
/** /**

View File

@ -51,7 +51,7 @@ public class Tools
public static String readInputStream(InputStream is) { public static String readInputStream(InputStream is) {
try { try {
byte[] buffer = new byte[1024]; byte[] buffer = new byte[1024];
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder(1024);
int length; int length;
while ((length = is.read(buffer)) != -1) { while ((length = is.read(buffer)) != -1) {
result.append(new String(buffer, 0, length, "UTF-8")); // StandardCharsets.UTF_8.name() > JDK 7 result.append(new String(buffer, 0, length, "UTF-8")); // StandardCharsets.UTF_8.name() > JDK 7
@ -208,7 +208,7 @@ public class Tools
public static String convertStreamToString(InputStream is, int size) throws Exception { public static String convertStreamToString(InputStream is, int size) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(is)); BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder(1024);
String line = null; String line = null;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
sb.append(line).append("\n"); sb.append(line).append("\n");

View File

@ -0,0 +1,16 @@
package logging;
import android.util.Log;
public class AndroidLogger implements Logger {
private final String tag;
public AndroidLogger(Class<?> clazz) {
this.tag = clazz.getSimpleName();
}
public void debug(String msg) { Log.d(tag, msg); }
public void info(String msg) { Log.i(tag, msg); }
public void warn(String msg) { Log.w(tag, msg); }
public void error(String msg) { Log.e(tag, msg); }
}

View File

@ -0,0 +1,12 @@
package logging;
public interface Logger {
void debug(String msg);
void info(String msg);
void warn(String msg);
void error(String msg);
static Logger getLogger(Class<?> clazz) {
return LoggerFactory.createLogger(clazz); // Подменяется реализацией
}
}

View File

@ -0,0 +1,21 @@
package logging;
public class LoggerFactory {
public static Logger createLogger(Class<?> clazz) {
// Тут выбираешь реализацию по флагу/условию
//if (isAndroid()) {
return new AndroidLogger(clazz);
//} else {
// return new SLF4JLogger(clazz);
//}
}
private static boolean isAndroid() {
try {
Class.forName("android.os.Build");
return true;
} catch (ClassNotFoundException e) {
return false;
}
}
}