Делаю освобождение ресурсов базы
This commit is contained in:
4
.idea/deploymentTargetSelector.xml
generated
4
.idea/deploymentTargetSelector.xml
generated
@ -4,10 +4,10 @@
|
||||
<selectionStates>
|
||||
<SelectionState runConfigName="app">
|
||||
<option name="selectionMode" value="DROPDOWN" />
|
||||
<DropdownSelection timestamp="2024-08-04T06:58:46.122913300Z">
|
||||
<DropdownSelection timestamp="2024-08-08T11:32:33.898603700Z">
|
||||
<Target type="DEFAULT_BOOT">
|
||||
<handle>
|
||||
<DeviceId pluginId="LocalEmulator" identifier="path=C:\Users\igor\.android\avd\Pixel_Tablet_API_34.avd" />
|
||||
<DeviceId pluginId="LocalEmulator" identifier="path=C:\Users\ivanov.i\.android\avd\Pixel_3a_API_34_extension_level_7_x86_64.avd" />
|
||||
</handle>
|
||||
</Target>
|
||||
</DropdownSelection>
|
||||
|
||||
@ -11,11 +11,15 @@ import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import kz.istt.locust.Tools;
|
||||
|
||||
public class DateTimeTM extends com.google.android.material.textfield.TextInputEditText implements fieldDB
|
||||
{
|
||||
private String m_Value = null;
|
||||
private String m_Value = null; //Строка с датой в формате: "YYYY-mm-dd hh:mm:ss" без часового пояса так как храню время в гринвиче на сервере
|
||||
|
||||
public DateTimeTM(Context context)
|
||||
{
|
||||
@ -30,27 +34,28 @@ public class DateTimeTM extends com.google.android.material.textfield.TextInputE
|
||||
return m_Value;
|
||||
}
|
||||
|
||||
//Передаётся в секундах с 1970 года по гринвичу но отображается в локальном времени 1579154400 отображается 16.01.2020 12:00 (в Алмате)
|
||||
public void setValue(String val)
|
||||
{
|
||||
m_Value = val;
|
||||
m_Value = null; //Присваиваю ниже так как нужно только проверянное значение даты
|
||||
if(val!=null && !val.equals(""))
|
||||
{
|
||||
Date date=null;
|
||||
try {
|
||||
date = new Date(Long.parseLong(m_Value)*1000);
|
||||
date = new Date(Long.parseLong(val)*1000);
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //Теперь для простого преобразования в тип даты PostgreSQL дату храню в виде текста в формате "yyyy-MM-dd HH:mm:ss"
|
||||
m_Value=format.format(date);
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
if(date==null){
|
||||
try {
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
date = format.parse(m_Value);
|
||||
date = format.parse(val);
|
||||
m_Value = val;
|
||||
} catch (ParseException e) {
|
||||
}
|
||||
}
|
||||
if(date!=null) {
|
||||
SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm");
|
||||
//format.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm"); //Убрал секунды так всё равно то что отображается не соответствует тому что храниться
|
||||
String str = format.format(date);
|
||||
setText(str);
|
||||
}else{
|
||||
|
||||
@ -26,7 +26,6 @@ public class DateTimeText extends EditText implements fieldDB
|
||||
return m_Value;
|
||||
}
|
||||
|
||||
//Передаётся в секундах с 1970 года по гринвичу но отображается в локальном времени 1579154400 отображается 16.01.2020 12:00 (в Алмате)
|
||||
public void setValue(String val)
|
||||
{
|
||||
m_Value = val;
|
||||
@ -34,8 +33,7 @@ public class DateTimeText extends EditText implements fieldDB
|
||||
{
|
||||
Date date = new Date(Long.parseLong(m_Value)*1000);
|
||||
|
||||
SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm");
|
||||
//format.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
|
||||
|
||||
String str = format.format(date);
|
||||
setText(str);
|
||||
@ -45,7 +43,6 @@ public class DateTimeText extends EditText implements fieldDB
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Класс для сохранения изменений сделаных пользователем при повороте экрана
|
||||
public static class SavedStateDTT extends BaseSavedState
|
||||
{
|
||||
|
||||
@ -10,7 +10,7 @@ import android.util.Log;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Spinner;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import com.google.android.material.textfield.TextInputEditText;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -21,8 +21,8 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import dbfields.DateInput;
|
||||
import dbfields.DateTimeText;
|
||||
import dbfields.DateTimeTM;
|
||||
import dbfields.DateTimeText;
|
||||
import dbfields.SpinnerDB;
|
||||
import dbfields.AutoCompleteTextViewDB;
|
||||
import dbfields.StringDB;
|
||||
@ -62,19 +62,24 @@ public class DBGUITable
|
||||
String type=null;
|
||||
//Считываем поля и их типы из таблицы
|
||||
DbOpenHelper dboh = new DbOpenHelper(m_context);
|
||||
Cursor cursor = dboh.getReadableDatabase().rawQuery("PRAGMA table_info('"+m_table+"');",null);
|
||||
if(cursor.moveToFirst())
|
||||
{
|
||||
do{
|
||||
if(Tools.getStringFromCursor(cursor,"name").equals(name.toLowerCase()))
|
||||
{
|
||||
type = Tools.getStringFromCursor(cursor,"type");
|
||||
break;
|
||||
}
|
||||
}while (cursor.moveToNext());
|
||||
SQLiteDatabase rdb = null;
|
||||
try {
|
||||
rdb = dboh.getReadableDatabase();
|
||||
Cursor cursor = rdb.rawQuery("PRAGMA table_info('" + m_table + "');", null);
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
if (Tools.getStringFromCursor(cursor, "name").equals(name.toLowerCase())) {
|
||||
type = Tools.getStringFromCursor(cursor, "type");
|
||||
break;
|
||||
}
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
cursor.close();
|
||||
}finally{
|
||||
if(rdb != null) { rdb.close(); }
|
||||
}
|
||||
cursor.close();
|
||||
dboh.close();
|
||||
|
||||
if(type!=null){
|
||||
return type.toLowerCase().trim();
|
||||
}else{
|
||||
@ -87,32 +92,38 @@ public class DBGUITable
|
||||
{
|
||||
boolean result = true;
|
||||
DbOpenHelper dboh = new DbOpenHelper(m_context);
|
||||
Cursor cursor = dboh.getReadableDatabase().rawQuery("PRAGMA table_info('"+m_table+"');",null);
|
||||
if(cursor.moveToFirst())
|
||||
{
|
||||
do{
|
||||
String name=Tools.getStringFromCursor(cursor,"name");
|
||||
boolean find=false;
|
||||
String value="";
|
||||
Set<Map.Entry<String, Object>> valueSet = cv.valueSet();
|
||||
for (Map.Entry<String, Object> entry : valueSet) {
|
||||
if(entry.getKey().equals(name)) {
|
||||
find = true;
|
||||
Object obj = entry.getValue();
|
||||
if(obj!=null)
|
||||
value = obj.toString()+" "+obj.getClass().toString()+" = "+Tools.getStringFromCursor(cursor,"type");
|
||||
else
|
||||
value="null";
|
||||
break;
|
||||
SQLiteDatabase rdb = null;
|
||||
try {
|
||||
rdb = dboh.getReadableDatabase();
|
||||
Cursor cursor = rdb.rawQuery("PRAGMA table_info('"+m_table+"');",null);
|
||||
if(cursor.moveToFirst())
|
||||
{
|
||||
do{
|
||||
String name=Tools.getStringFromCursor(cursor,"name");
|
||||
boolean find=false;
|
||||
String value="";
|
||||
Set<Map.Entry<String, Object>> valueSet = cv.valueSet();
|
||||
for (Map.Entry<String, Object> entry : valueSet) {
|
||||
if(entry.getKey().equals(name)) {
|
||||
find = true;
|
||||
Object obj = entry.getValue();
|
||||
if(obj!=null)
|
||||
value = obj.toString()+" "+obj.getClass().toString()+" = "+Tools.getStringFromCursor(cursor,"type");
|
||||
else
|
||||
value="null";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!find)
|
||||
Log.e("CCALM", "Validate field = " + name + " not find in CV");
|
||||
else
|
||||
Log.e("CCALM", "Validate field = " + name + " find in CV value = "+value);
|
||||
}while (cursor.moveToNext());
|
||||
if(!find)
|
||||
Log.e("CCALM", "Validate field = " + name + " not find in CV");
|
||||
else
|
||||
Log.e("CCALM", "Validate field = " + name + " find in CV value = "+value);
|
||||
}while (cursor.moveToNext());
|
||||
}
|
||||
cursor.close();
|
||||
} finally {
|
||||
if (rdb != null) { rdb.close(); }
|
||||
}
|
||||
cursor.close();
|
||||
dboh.close();
|
||||
|
||||
return result;
|
||||
@ -194,11 +205,19 @@ public class DBGUITable
|
||||
{
|
||||
uid=cv.getAsString("uid");
|
||||
String sql="select 1 from "+m_table+" where uid = '" + uid +"'";
|
||||
cursor = dboh.getReadableDatabase().rawQuery(sql,null);
|
||||
b=cursor.moveToFirst();
|
||||
cursor.close();
|
||||
SQLiteDatabase rdb=null;
|
||||
try {
|
||||
rdb = dboh.getReadableDatabase();
|
||||
cursor = rdb.rawQuery(sql,null);
|
||||
b=cursor.moveToFirst();
|
||||
cursor.close();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
} finally {
|
||||
if(rdb!=null) rdb.close();
|
||||
}
|
||||
}
|
||||
dboh.close();
|
||||
|
||||
|
||||
if(!b) //Вставляем новую запись
|
||||
{
|
||||
@ -207,31 +226,40 @@ public class DBGUITable
|
||||
|
||||
validateField(cv);
|
||||
|
||||
SQLiteDatabase db = dboh.getWritableDatabase();
|
||||
db.beginTransaction(); //Вроде как защита от многопоточности (для сервиса)
|
||||
SQLiteDatabase db=null;
|
||||
try {
|
||||
db = dboh.getWritableDatabase();
|
||||
db.beginTransaction(); //Вроде как защита от многопоточности (для сервиса)
|
||||
db.insert(m_table, null, cv);
|
||||
db.setTransactionSuccessful();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
if(db!=null) db.endTransaction();
|
||||
if(db!=null) db.close();
|
||||
}
|
||||
db.close();
|
||||
|
||||
}else //Обновить запись
|
||||
{
|
||||
validateField(cv);
|
||||
|
||||
SQLiteDatabase db = dboh.getWritableDatabase();
|
||||
db.beginTransaction(); //Вроде как защита от многопоточности (для сервиса)
|
||||
uid=cv.getAsString("uid");
|
||||
SQLiteDatabase db=null;
|
||||
try {
|
||||
db = dboh.getWritableDatabase();
|
||||
db.beginTransaction(); //Вроде как защита от многопоточности (для сервиса)
|
||||
uid=cv.getAsString("uid");
|
||||
db.update(m_table, cv, "uid = ?", new String[] {uid});
|
||||
db.setTransactionSuccessful();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
if(db!=null) db.endTransaction();
|
||||
if(db!=null) db.close();
|
||||
}
|
||||
db.close();
|
||||
|
||||
}
|
||||
|
||||
dboh.close(); //Можно и не закрывать, главное закрыть getWritableDatabase() и getReadableDatabase()
|
||||
return uid;
|
||||
}
|
||||
|
||||
@ -247,32 +275,37 @@ public class DBGUITable
|
||||
Cursor cursor = null;
|
||||
sql = "select * from "+m_table+" where uid='" + uid + "'";
|
||||
|
||||
cursor = dboh.getReadableDatabase().rawQuery(sql, null);
|
||||
|
||||
if (cursor.moveToFirst())
|
||||
{
|
||||
//перебираем столбцы и вставляем значения в поля
|
||||
for(int i=0;i<cursor.getColumnCount();i++)
|
||||
SQLiteDatabase rdb=null;
|
||||
try {
|
||||
rdb = dboh.getReadableDatabase();
|
||||
cursor = rdb.rawQuery(sql, null);
|
||||
if (cursor.moveToFirst())
|
||||
{
|
||||
Object obj=findComponent(cursor.getColumnName(i));
|
||||
if(obj!=null)
|
||||
//перебираем столбцы и вставляем значения в поля
|
||||
for(int i=0;i<cursor.getColumnCount();i++)
|
||||
{
|
||||
if(cursor.getColumnName(i).equals("date")) {
|
||||
Log.e("CCALM", "1 field " + cursor.getColumnName(i) + " = " + cursor.getString(i) + " type= " + cursor.getType(i));
|
||||
}
|
||||
Object obj=findComponent(cursor.getColumnName(i));
|
||||
if(obj!=null)
|
||||
{
|
||||
if(cursor.getColumnName(i).equals("date")) {
|
||||
Log.e("CCALM", "1 field " + cursor.getColumnName(i) + " = " + cursor.getString(i) + " type= " + cursor.getType(i));
|
||||
}
|
||||
|
||||
if(cursor.getType(i)==2){ //Because cutting double
|
||||
setValue(obj, ""+cursor.getDouble(i));
|
||||
}else {
|
||||
setValue(obj, cursor.getString(i));
|
||||
}
|
||||
if(cursor.getType(i)==2){ //Because cutting double
|
||||
setValue(obj, ""+cursor.getDouble(i));
|
||||
}else {
|
||||
setValue(obj, cursor.getString(i));
|
||||
}
|
||||
|
||||
//для проверки обратное действие
|
||||
Log.e("CCALM", "read field = " + cursor.getColumnName(i) + " val1 = " + cursor.getString(i) + " val2 = " + getValue(findComponent(cursor.getColumnName(i))));
|
||||
//для проверки обратное действие
|
||||
Log.e("CCALM", "read field = " + cursor.getColumnName(i) + " val1 = " + cursor.getString(i) + " val2 = " + getValue(findComponent(cursor.getColumnName(i))));
|
||||
}
|
||||
}
|
||||
}
|
||||
cursor.close();
|
||||
}finally{
|
||||
if(rdb != null) { rdb.close(); }
|
||||
}
|
||||
cursor.close();
|
||||
dboh.close();
|
||||
}
|
||||
|
||||
|
||||
@ -4,9 +4,12 @@ import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.database.Cursor;
|
||||
import android.database.SQLException;
|
||||
import android.database.sqlite.SQLiteConstraintException;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@ -1573,22 +1576,26 @@ public class DbOpenHelper extends SQLiteOpenHelper
|
||||
/** Получить список столбцов*/
|
||||
public List<String> GetColumns(String tableName)
|
||||
{
|
||||
SQLiteDatabase db = getReadableDatabase();
|
||||
|
||||
List<String> ar = null;
|
||||
Cursor c = null;
|
||||
SQLiteDatabase rdb=null;
|
||||
try {
|
||||
c = db.rawQuery("select * from " + tableName + " limit 1", null);
|
||||
if (c != null) {
|
||||
ar = new ArrayList<String>(Arrays.asList(c.getColumnNames()));
|
||||
rdb = getReadableDatabase();
|
||||
try {
|
||||
c = rdb.rawQuery("select * from " + tableName + " limit 1", null);
|
||||
if (c != null) {
|
||||
ar = new ArrayList<String>(Arrays.asList(c.getColumnNames()));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.v(tableName, e.toString(), e);
|
||||
e.printStackTrace();
|
||||
} finally
|
||||
{
|
||||
if (c != null)
|
||||
c.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.v(tableName, e.toString(), e);
|
||||
e.printStackTrace();
|
||||
} finally
|
||||
{
|
||||
if (c != null)
|
||||
c.close();
|
||||
}finally{
|
||||
if(rdb != null) { rdb.close(); }
|
||||
}
|
||||
return ar;
|
||||
}
|
||||
@ -1596,6 +1603,9 @@ public class DbOpenHelper extends SQLiteOpenHelper
|
||||
/**Функция для обновления или вставки табличных данных*/
|
||||
public Boolean updateTable(TCTable tbl)
|
||||
{
|
||||
SQLiteDatabase db;
|
||||
Cursor cursor;
|
||||
|
||||
//Проверка на существование полей
|
||||
Boolean[] fb=new Boolean[tbl.fields.size()]; //Для проверки существования полей в локальной таблице
|
||||
for(int i=0;i<fb.length;i++) fb[i]=false; //Помечаем что ниодного поля не существует
|
||||
@ -1611,7 +1621,7 @@ public class DbOpenHelper extends SQLiteOpenHelper
|
||||
}
|
||||
}
|
||||
|
||||
SQLiteDatabase db = this.getWritableDatabase();
|
||||
db = this.getWritableDatabase();
|
||||
//Переписываем значения существующих полей и выполняем запросы
|
||||
while(tbl.ReadNextRecord())
|
||||
{
|
||||
@ -1621,9 +1631,16 @@ public class DbOpenHelper extends SQLiteOpenHelper
|
||||
String sql="select 1 from "+tbl.name+" where id = ?";
|
||||
String[] par = new String[] { tbl.getRowByName("id").getStrVal() };
|
||||
|
||||
Cursor cursor = getReadableDatabase().rawQuery(sql, par);
|
||||
boolean exists=cursor.moveToFirst();
|
||||
cursor.close();
|
||||
boolean exists=false;
|
||||
SQLiteDatabase rdb=null;
|
||||
try {
|
||||
rdb = getReadableDatabase();
|
||||
cursor = rdb.rawQuery(sql, par);
|
||||
exists=cursor.moveToFirst();
|
||||
cursor.close();
|
||||
}finally{
|
||||
if(rdb != null) { rdb.close(); }
|
||||
}
|
||||
|
||||
ContentValues cv = new ContentValues();
|
||||
for(int i=0;i<tbl.fields.size();i++)
|
||||
@ -1646,7 +1663,9 @@ public class DbOpenHelper extends SQLiteOpenHelper
|
||||
try {
|
||||
db.insert(tbl.name, null, cv);
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
}catch(SQLException ex){
|
||||
ex.printStackTrace();
|
||||
}finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
}else
|
||||
@ -1655,6 +1674,8 @@ public class DbOpenHelper extends SQLiteOpenHelper
|
||||
try {
|
||||
db.update(tbl.name, cv, "id = ?", new String[] { tbl.getRowByName("id").getStrVal() });
|
||||
db.setTransactionSuccessful();
|
||||
}catch(SQLException ex){
|
||||
ex.printStackTrace();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
@ -1663,14 +1684,19 @@ public class DbOpenHelper extends SQLiteOpenHelper
|
||||
db.close();
|
||||
|
||||
//Для дебага
|
||||
Cursor cursor = getReadableDatabase().rawQuery("select sum(1) s from "+tbl.name,null);
|
||||
if(cursor.moveToFirst())
|
||||
{
|
||||
do{
|
||||
Log.i("igor","tbl="+tbl.name+" cnt="+cursor.getString(cursor.getColumnIndex("s")));
|
||||
}while (cursor.moveToNext());
|
||||
SQLiteDatabase rdb=null;
|
||||
try {
|
||||
rdb=getReadableDatabase();
|
||||
cursor = rdb.rawQuery("select sum(1) s from " + tbl.name, null);
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
Log.i("igor", "tbl1=" + tbl.name + " cnt=" + cursor.getString(cursor.getColumnIndex("s")));
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
cursor.close();
|
||||
}finally{
|
||||
if(rdb!=null) rdb.close();
|
||||
}
|
||||
cursor.close();
|
||||
/**/
|
||||
|
||||
return true;
|
||||
@ -1728,11 +1754,17 @@ public class DbOpenHelper extends SQLiteOpenHelper
|
||||
public void setUser(int id, int del, int seq, String name, String surname, String patronymic, String login, String password)
|
||||
{
|
||||
//так как пользователь может быть только 1 то удаляем всех остальных
|
||||
getReadableDatabase().execSQL("update _user set del=1;");
|
||||
|
||||
Cursor cursor = getReadableDatabase().rawQuery("select 1 from _user where id = ?", new String[] { String.valueOf(id) });
|
||||
boolean b=cursor.moveToFirst();
|
||||
cursor.close();
|
||||
boolean b=false;
|
||||
SQLiteDatabase rdb=null;
|
||||
try {
|
||||
rdb=getReadableDatabase();
|
||||
rdb.execSQL("update _user set del=1;");
|
||||
Cursor cursor = rdb.rawQuery("select 1 from _user where id = ?", new String[]{String.valueOf(id)});
|
||||
b = cursor.moveToFirst();
|
||||
cursor.close();
|
||||
}finally{
|
||||
if(rdb!=null) rdb.close();
|
||||
}
|
||||
|
||||
if(!b) //Новый
|
||||
{
|
||||
@ -2144,74 +2176,73 @@ public class DbOpenHelper extends SQLiteOpenHelper
|
||||
public int[] inPerimeter(float lon,float lat)
|
||||
{
|
||||
int result[]={0,0};
|
||||
Cursor cursor = this
|
||||
.getReadableDatabase()
|
||||
.rawQuery(
|
||||
"select id,country_id,lon_max,name from CountriesRegions where del=0 and "+lon+">lon_min and "+lon+"<lon_max and "+lat+">lat_min and "+lat+"<lat_max order by area", null);
|
||||
if (cursor.moveToFirst())
|
||||
{
|
||||
do
|
||||
{
|
||||
result[0]=cursor.getInt(cursor.getColumnIndex("country_id"));
|
||||
Log.i("igor", "Region name = "+cursor.getString(cursor.getColumnIndex("name"))+" id = " + cursor.getString(cursor.getColumnIndex("id")));
|
||||
SQLiteDatabase rdb = null;
|
||||
try {
|
||||
rdb = this.getReadableDatabase();
|
||||
|
||||
Cursor cursor = rdb.rawQuery("select id,country_id,lon_max,name from CountriesRegions where del=0 and " + lon + ">lon_min and " + lon + "<lon_max and " + lat + ">lat_min and " + lat + "<lat_max order by area", null);
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
result[0] = cursor.getInt(cursor.getColumnIndex("country_id"));
|
||||
Log.i("igor", "Region name = " + cursor.getString(cursor.getColumnIndex("name")) + " id = " + cursor.getString(cursor.getColumnIndex("id")));
|
||||
//String points="{ \"type\": \"Polygon\", \"coordinates\": [[";
|
||||
Point PHead0 = new Point();
|
||||
PHead0.x=lon;
|
||||
PHead0.y=lat;
|
||||
Point PTail0 = new Point();
|
||||
PTail0.x=cursor.getFloat(cursor.getColumnIndex("lon_max"))+1;
|
||||
PTail0.y=lat;
|
||||
Point PHead0 = new Point();
|
||||
PHead0.x = lon;
|
||||
PHead0.y = lat;
|
||||
Point PTail0 = new Point();
|
||||
PTail0.x = cursor.getFloat(cursor.getColumnIndex("lon_max")) + 1;
|
||||
PTail0.y = lat;
|
||||
|
||||
int resId = _context.getResources().getIdentifier("raw/region_"+cursor.getString(cursor.getColumnIndex("id")), null, _context.getPackageName());
|
||||
try {
|
||||
InputStream isRaw = null;
|
||||
isRaw = _context.getResources().openRawResource(resId);
|
||||
if (isRaw != null) {
|
||||
TCTable tbl = new TCTable("", 0);
|
||||
if (tbl.OpenTableH(isRaw)) {
|
||||
int resId = _context.getResources().getIdentifier("raw/region_" + cursor.getString(cursor.getColumnIndex("id")), null, _context.getPackageName());
|
||||
try {
|
||||
InputStream isRaw = null;
|
||||
isRaw = _context.getResources().openRawResource(resId);
|
||||
if (isRaw != null) {
|
||||
TCTable tbl = new TCTable("", 0);
|
||||
if (tbl.OpenTableH(isRaw)) {
|
||||
|
||||
//Первая и конечная точка совпадают
|
||||
int cnt=0; //Подсчитываю пересичения в право, если они не чётны то внутри иначе с наружи
|
||||
boolean first=true;
|
||||
Point PHead1 = new Point();
|
||||
Point PTail1 = new Point();
|
||||
//Первая и конечная точка совпадают
|
||||
int cnt = 0; //Подсчитываю пересичения в право, если они не чётны то внутри иначе с наружи
|
||||
boolean first = true;
|
||||
Point PHead1 = new Point();
|
||||
Point PTail1 = new Point();
|
||||
|
||||
while(tbl.ReadNextRecord())
|
||||
{
|
||||
//points+="["+tbl.fields.get(0).getFloatVal()+", "+tbl.fields.get(1).getFloatVal()+"],";
|
||||
while (tbl.ReadNextRecord()) {
|
||||
//points+="["+tbl.fields.get(0).getFloatVal()+", "+tbl.fields.get(1).getFloatVal()+"],";
|
||||
|
||||
if(first)
|
||||
{
|
||||
PHead1.x = tbl.fields.get(0).getFloatVal();
|
||||
PHead1.y = tbl.fields.get(1).getFloatVal();
|
||||
first=false;
|
||||
}else{
|
||||
PTail1.x = tbl.fields.get(0).getFloatVal();
|
||||
PTail1.y = tbl.fields.get(1).getFloatVal();
|
||||
Point pnt = Tools.getCrossingLine2(PHead0,PTail0,PHead1,PTail1);
|
||||
if(pnt.x!=0 && pnt.y!=0) {
|
||||
cnt++;
|
||||
if (first) {
|
||||
PHead1.x = tbl.fields.get(0).getFloatVal();
|
||||
PHead1.y = tbl.fields.get(1).getFloatVal();
|
||||
first = false;
|
||||
} else {
|
||||
PTail1.x = tbl.fields.get(0).getFloatVal();
|
||||
PTail1.y = tbl.fields.get(1).getFloatVal();
|
||||
Point pnt = Tools.getCrossingLine2(PHead0, PTail0, PHead1, PTail1);
|
||||
if (pnt.x != 0 && pnt.y != 0) {
|
||||
cnt++;
|
||||
}
|
||||
PHead1.x = PTail1.x;
|
||||
PHead1.y = PTail1.y;
|
||||
}
|
||||
PHead1.x = PTail1.x;
|
||||
PHead1.y = PTail1.y;
|
||||
}
|
||||
//points+="]]}";
|
||||
//Log.i("igor", points);
|
||||
if (cnt % 2 != 0) {
|
||||
result[1] = cursor.getInt(cursor.getColumnIndex("id"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
//points+="]]}";
|
||||
//Log.i("igor", points);
|
||||
if(cnt%2!=0){
|
||||
result[1]=cursor.getInt(cursor.getColumnIndex("id"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
} while (cursor.moveToNext());
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
cursor.close();
|
||||
}finally{
|
||||
if(rdb != null) { rdb.close(); }
|
||||
}
|
||||
cursor.close();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,6 +37,7 @@ public class LatLon implements android.os.Parcelable{
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeString(uid);
|
||||
dest.writeDouble(lat);
|
||||
dest.writeDouble(lon);
|
||||
}
|
||||
|
||||
@ -253,13 +253,19 @@ public class LocustActivity extends FragmentActivity implements LocationListener
|
||||
((selectDB)spiCountry).addField("", "");
|
||||
// Выбираем страны и заполняем поля
|
||||
dboh = new DbOpenHelper(this);
|
||||
cursor = dboh.getReadableDatabase().rawQuery("select c.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = c.name AND l.short_name='" + Tools.getLang() + "' LIMIT 1),c.name) name from countries c where c.del=0 order by c.name", null);
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
((selectDB)spiCountry).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
|
||||
} while (cursor.moveToNext());
|
||||
SQLiteDatabase rdb = null;
|
||||
try {
|
||||
rdb = dboh.getReadableDatabase();
|
||||
cursor = rdb.rawQuery("select c.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = c.name AND l.short_name='" + Tools.getLang() + "' LIMIT 1),c.name) name from countries c where c.del=0 order by c.name", null);
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
((selectDB) spiCountry).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
cursor.close();
|
||||
}finally{
|
||||
if(rdb != null) { rdb.close(); }
|
||||
}
|
||||
cursor.close();
|
||||
dboh.close();
|
||||
|
||||
//----------------------------------------------------------------------------------------------
|
||||
@ -287,13 +293,19 @@ public class LocustActivity extends FragmentActivity implements LocationListener
|
||||
if (((selectDB)spiCountry).getValue() != null && !((selectDB)spiCountry).getValue().equals("")) {
|
||||
DbOpenHelper dboh = new DbOpenHelper(LocustActivity.this);
|
||||
String sql = "select id, name, lon_min from countriesregions where del=0 and country_id=" + ((selectDB)spiCountry).getValue() + " order by name";
|
||||
Cursor cursor = dboh.getReadableDatabase().rawQuery(sql, null);
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
((selectDB)spiRegion).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
|
||||
} while (cursor.moveToNext());
|
||||
SQLiteDatabase rdb=null;
|
||||
try {
|
||||
rdb = dboh.getReadableDatabase();
|
||||
Cursor cursor = rdb.rawQuery(sql, null);
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
((selectDB) spiRegion).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
cursor.close();
|
||||
}finally{
|
||||
if(rdb!=null) { rdb.close();}
|
||||
}
|
||||
cursor.close();
|
||||
dboh.close();
|
||||
}
|
||||
}
|
||||
@ -328,8 +340,7 @@ public class LocustActivity extends FragmentActivity implements LocationListener
|
||||
// @Override
|
||||
// public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
|
||||
//
|
||||
// //SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm");
|
||||
// //format.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
// //SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
|
||||
// //LocustActivity.this.edtDate.setText(format.format(curDateTime));
|
||||
//
|
||||
// //Теперь выбираем время
|
||||
@ -365,8 +376,7 @@ public class LocustActivity extends FragmentActivity implements LocationListener
|
||||
//
|
||||
// if (!LocustActivity.this.edtDate.getText().toString().equals("")) {
|
||||
// Date date = null;
|
||||
// SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm");
|
||||
// //format.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
// SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
|
||||
// try {
|
||||
// date = format.parse(LocustActivity.this.edtDate.getText().toString());
|
||||
// } catch (ParseException e) {
|
||||
|
||||
@ -356,88 +356,6 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
|
||||
|
||||
View btnGetDate = (View) findViewById(R.id.btnGetDate);
|
||||
btnGetDate.setOnClickListener(new OnClickListenerDateTime((fieldDB)edtDate,this));
|
||||
//Закоментил так как создал отдельный класс: OnClickListenerDateTime2
|
||||
// View.OnClickListener clk0 = new View.OnClickListener() {
|
||||
// public void onClick(View v)
|
||||
// {
|
||||
// DatePickerDialog.OnDateSetListener myDateListener = new DatePickerDialog.OnDateSetListener() {
|
||||
// @Override
|
||||
// public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth)
|
||||
// {
|
||||
//
|
||||
// //SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm");
|
||||
// //format.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
// //LocustDelActivity.this.edtDate.setText(format.format(curDateTime));
|
||||
//
|
||||
// //Теперь выбираем время
|
||||
// OnTimeSetListener myDateListener = new OnTimeSetListener() {
|
||||
// @Override
|
||||
// public void onTimeSet(TimePicker view, int hourOfDay, int minute)
|
||||
// {
|
||||
// long val = Long.parseLong(((fieldDB)LocustDelActivity.this.edtDate).getValue());
|
||||
// val += (hourOfDay*60+minute)*60;
|
||||
// ((fieldDB)LocustDelActivity.this.edtDate).setValue(String.valueOf(val));
|
||||
// }
|
||||
// };
|
||||
//
|
||||
// if(((fieldDB)LocustDelActivity.this.edtDate).getValue()!=null && !((fieldDB)LocustDelActivity.this.edtDate).getValue().equals(""))
|
||||
// {
|
||||
// Date time = new Date(Long.parseLong(((fieldDB)LocustDelActivity.this.edtDate).getValue())*1000);
|
||||
// Calendar myCal = new GregorianCalendar();
|
||||
// myCal.setTime(time);
|
||||
// int hour = myCal.get(Calendar.HOUR_OF_DAY);
|
||||
// int minute = myCal.get(Calendar.MINUTE);
|
||||
// TimePickerDialog tpd = new TimePickerDialog(LocustDelActivity.this, R.style.AlertDialogTheme, myDateListener, hour, minute, true);
|
||||
// tpd.show();
|
||||
// }else
|
||||
// {
|
||||
// final Calendar myCal = Calendar.getInstance();
|
||||
// int hour = myCal.get(Calendar.HOUR_OF_DAY);
|
||||
// int minute = myCal.get(Calendar.MINUTE);
|
||||
// TimePickerDialog tpd = new TimePickerDialog(LocustDelActivity.this, R.style.AlertDialogTheme, myDateListener, hour, minute, true);
|
||||
// tpd.show();
|
||||
// }
|
||||
//
|
||||
// Date date = new Date(year-1900, monthOfYear, dayOfMonth);
|
||||
// ((fieldDB)LocustDelActivity.this.edtDate).setValue(String.valueOf(date.getTime()/1000));
|
||||
//
|
||||
//
|
||||
// }
|
||||
// };
|
||||
//
|
||||
// if(!LocustDelActivity.this.edtDate.getText().toString().equals(""))
|
||||
// {
|
||||
// Date date=null;
|
||||
// SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm");
|
||||
// //format.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
// try {
|
||||
// date = format.parse(LocustDelActivity.this.edtDate.getText().toString());
|
||||
// } catch (ParseException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// if(date!=null)
|
||||
// {
|
||||
// Calendar myCal = new GregorianCalendar();
|
||||
// myCal.setTime(date);
|
||||
// int day = myCal.get(Calendar.DAY_OF_MONTH);
|
||||
// int month = myCal.get(Calendar.MONTH);
|
||||
// int year = myCal.get(Calendar.YEAR);
|
||||
// DatePickerDialog dpd = new DatePickerDialog(LocustDelActivity.this, R.style.AlertDialogTheme, myDateListener, year, month, day);
|
||||
// dpd.show();
|
||||
// }
|
||||
// }else
|
||||
// {
|
||||
// final Calendar c = Calendar.getInstance();
|
||||
// int year = c.get(Calendar.YEAR);
|
||||
// int month = c.get(Calendar.MONTH);
|
||||
// int day = c.get(Calendar.DAY_OF_MONTH);
|
||||
//
|
||||
// DatePickerDialog dpd = new DatePickerDialog(LocustDelActivity.this, R.style.AlertDialogTheme, myDateListener, year, month, day);
|
||||
// dpd.show();
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
// btnGetDate.setOnClickListener(clk0);
|
||||
|
||||
edtTimeZone = (EditText) findViewById(R.id.edtTimeZone);
|
||||
guiTable.add(edtTimeZone,"timezone");
|
||||
|
||||
@ -1358,9 +1358,9 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
|
||||
guiTableHealth.add(edtImage2, "image_name2");
|
||||
edtImage3 = (EditText) findViewById(R.id.edtImage3); // Фото
|
||||
guiTableHealth.add(edtImage3, "image_name3");
|
||||
edtImage4 = (EditText) findViewById(R.id.edtImage3); // Фото
|
||||
edtImage4 = (EditText) findViewById(R.id.edtImage4); // Фото
|
||||
guiTableHealth.add(edtImage4, "image_name4");
|
||||
edtImage5 = (EditText) findViewById(R.id.edtImage3); // Фото
|
||||
edtImage5 = (EditText) findViewById(R.id.edtImage5); // Фото
|
||||
guiTableHealth.add(edtImage5, "image_name5");
|
||||
|
||||
//********** Оценки риска **********
|
||||
@ -1896,88 +1896,7 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
|
||||
// guiTable.add(edtDate, "date");
|
||||
|
||||
// View btnGetDate = (View) findViewById(R.id.btnGetDate);
|
||||
// OnClickListener clk0 = new OnClickListener() {
|
||||
// public void onClick(View v)
|
||||
// {
|
||||
// DatePickerDialog.OnDateSetListener myDateListener = new DatePickerDialog.OnDateSetListener() {
|
||||
// @Override
|
||||
// public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth)
|
||||
// {
|
||||
//
|
||||
// //SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm");
|
||||
// //format.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
// //LocustDelActivity.this.edtDate.setText(format.format(curDateTime));
|
||||
//
|
||||
// //Теперь выбираем время
|
||||
// OnTimeSetListener myDateListener = new OnTimeSetListener() {
|
||||
// @Override
|
||||
// public void onTimeSet(TimePicker view, int hourOfDay, int minute)
|
||||
// {
|
||||
// long val = Long.parseLong(((fieldDB) LocustHealthActivity.this.edtDate).getValue());
|
||||
// val += (hourOfDay*60+minute)*60;
|
||||
// ((fieldDB) LocustHealthActivity.this.edtDate).setValue(String.valueOf(val));
|
||||
// }
|
||||
// };
|
||||
//
|
||||
// if(((fieldDB) LocustHealthActivity.this.edtDate).getValue()!=null && !((fieldDB) LocustHealthActivity.this.edtDate).getValue().equals(""))
|
||||
// {
|
||||
// Date time = new Date(Long.parseLong(((fieldDB) LocustHealthActivity.this.edtDate).getValue())*1000);
|
||||
// Calendar myCal = new GregorianCalendar();
|
||||
// myCal.setTime(time);
|
||||
// int hour = myCal.get(Calendar.HOUR_OF_DAY);
|
||||
// int minute = myCal.get(Calendar.MINUTE);
|
||||
// TimePickerDialog tpd = new TimePickerDialog(LocustHealthActivity.this, R.style.AlertDialogTheme, myDateListener, hour, minute, true);
|
||||
// tpd.show();
|
||||
// }else
|
||||
// {
|
||||
// final Calendar myCal = Calendar.getInstance();
|
||||
// int hour = myCal.get(Calendar.HOUR_OF_DAY);
|
||||
// int minute = myCal.get(Calendar.MINUTE);
|
||||
// TimePickerDialog tpd = new TimePickerDialog(LocustHealthActivity.this, R.style.AlertDialogTheme, myDateListener, hour, minute, true);
|
||||
// tpd.show();
|
||||
// }
|
||||
//
|
||||
// Date date = new Date(year-1900, monthOfYear, dayOfMonth);
|
||||
// ((fieldDB) LocustHealthActivity.this.edtDate).setValue(String.valueOf(date.getTime()/1000));
|
||||
//
|
||||
//
|
||||
// }
|
||||
// };
|
||||
//
|
||||
// if(!LocustHealthActivity.this.edtDate.getText().toString().equals(""))
|
||||
// {
|
||||
// Date date=null;
|
||||
// SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm");
|
||||
// //format.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
// try {
|
||||
// date = format.parse(LocustHealthActivity.this.edtDate.getText().toString());
|
||||
// } catch (ParseException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// if(date!=null)
|
||||
// {
|
||||
// Calendar myCal = new GregorianCalendar();
|
||||
// myCal.setTime(date);
|
||||
// int day = myCal.get(Calendar.DAY_OF_MONTH);
|
||||
// int month = myCal.get(Calendar.MONTH);
|
||||
// int year = myCal.get(Calendar.YEAR);
|
||||
// DatePickerDialog dpd = new DatePickerDialog(LocustHealthActivity.this, R.style.AlertDialogTheme, myDateListener, year, month, day);
|
||||
// dpd.show();
|
||||
// }
|
||||
// }else
|
||||
// {
|
||||
// final Calendar c = Calendar.getInstance();
|
||||
// int year = c.get(Calendar.YEAR);
|
||||
// int month = c.get(Calendar.MONTH);
|
||||
// int day = c.get(Calendar.DAY_OF_MONTH);
|
||||
//
|
||||
// DatePickerDialog dpd = new DatePickerDialog(LocustHealthActivity.this, R.style.AlertDialogTheme, myDateListener, year, month, day);
|
||||
// dpd.show();
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
// btnGetDate.setOnClickListener(clk0);
|
||||
//
|
||||
|
||||
// edtTimeZone = (EditText) findViewById(R.id.edtTimeZone);
|
||||
// guiTable.add(edtTimeZone,"timezone");
|
||||
//
|
||||
|
||||
@ -622,7 +622,7 @@ public class LocustListActivity extends AppCompatActivity
|
||||
|
||||
long dv = cursor.getLong(cursor.getColumnIndex("date")) * (long) 1000; // its need to be in milisecond
|
||||
Date df = new java.util.Date(dv);
|
||||
String vv = new SimpleDateFormat("dd.MM.yyyy HH:mm").format(df);
|
||||
String vv = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(df);
|
||||
|
||||
btn.setText(cursor.getString(cursor.getColumnIndex("terrain")) + " (" + vv + ")");
|
||||
|
||||
|
||||
@ -96,8 +96,9 @@ public class MySynchronizationOld
|
||||
private int rid_sendFrmLocustDel = -1; //Для отправки данных
|
||||
private int rid_sendFrmLocustHealth = -1; //Для отправки данных
|
||||
|
||||
private int rid_frmlocust = -1; //Для запроса данных
|
||||
private int rid_frmlocust = -1; //Для запроса данных (не используется так как нет синхронизации)
|
||||
private int rid_frmlocustdel = -1; //Для запроса данных
|
||||
private int rid_frmlocustdel_locations = -1; //Для подгрузки координат формы
|
||||
|
||||
private int rid_Borns = -1;
|
||||
private int rid_countries=-1; //Для идентификации прихода данных списка стран
|
||||
@ -509,10 +510,11 @@ public class MySynchronizationOld
|
||||
{
|
||||
String country_id = cursor.getString(0);
|
||||
rid_frmlocustdel = makeRequest("frmlocustdel",String.valueOf(MySynchronizationOld.SyncDays),country_id);
|
||||
//Загружаю координаты для формы frmlocustdel
|
||||
rid_frmlocustdel_locations = makeRequest("frmlocustdel_locations",String.valueOf(MySynchronizationOld.SyncDays),country_id);
|
||||
}
|
||||
cursor.close();
|
||||
dboh.close();
|
||||
|
||||
}
|
||||
|
||||
//Пришел ответ от HTTP сервера
|
||||
@ -546,7 +548,7 @@ public class MySynchronizationOld
|
||||
(rid == rid_Borns && rid_Borns!=-1) || (rid == rid_LocustsTypes && rid_LocustsTypes!=-1) ||
|
||||
(rid == rid_countries && rid_countries!=-1) || (rid==rid_CountriesRegions && rid_CountriesRegions!=-1) ||
|
||||
(rid == rid__languages && rid__languages != -1) || (rid == rid__translations && rid__translations != -1) ||
|
||||
(rid == rid_frmlocust && rid_frmlocust!=-1) || (rid == rid_frmlocustdel && rid_frmlocustdel!=-1) ||
|
||||
(rid == rid_frmlocust && rid_frmlocust!=-1) || (rid == rid_frmlocustdel && rid_frmlocustdel!=-1) || (rid == rid_frmlocustdel_locations && rid_frmlocustdel_locations!=-1) ||
|
||||
(rid == rid_list_greenery && rid_list_greenery!=-1) || (rid == rid_list_biotope && rid_list_biotope!=-1) ||
|
||||
(rid == rid_list_cover && rid_list_cover!=-1) || (rid == rid_list_age && rid_list_age!=-1) ||
|
||||
(rid == rid_list_actions && rid_list_actions!=-1) || (rid == rid_list_paintings && rid_list_paintings!=-1) ||
|
||||
|
||||
@ -21,6 +21,7 @@ import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
@ -44,6 +45,66 @@ import android.widget.AdapterView.OnItemSelectedListener;
|
||||
*/
|
||||
public class Tools
|
||||
{
|
||||
public static Date getDateFromStr(String str) {
|
||||
if(str==null)
|
||||
return null;
|
||||
Date date=null;
|
||||
try {
|
||||
date = new Date(Long.parseLong(str)*1000);
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
if(date==null){
|
||||
try {
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
date = format.parse(str);
|
||||
} catch (ParseException e) {
|
||||
}
|
||||
}
|
||||
return date;
|
||||
}
|
||||
//Преобразую в подходящий формат для PostgreSQL
|
||||
public static String dateToStr(Date date){
|
||||
if(date==null)
|
||||
return null;
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
return format.format(date);
|
||||
}
|
||||
|
||||
public static Date setYMD(Date date, int year, int monthOfYear, int dayOfMonth){
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
calendar.set(Calendar.YEAR, year);
|
||||
calendar.set(Calendar.MONTH, monthOfYear - 1); // Месяцы в Calendar начинаются с 0 (январь)
|
||||
calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
public static Date setHMS(Date date, int hourOfDay, int minute,int second){
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
|
||||
calendar.set(Calendar.MINUTE, minute);
|
||||
calendar.set(Calendar.SECOND, second);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
// Преобразование из локального времени пользователя во время по Гринвичу (UTC)
|
||||
/*public static Date toUTCDate(Date localDate) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(localDate);
|
||||
calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
// Преобразование из времени по Гринвичу (UTC) в локальное время пользователя
|
||||
public static Date toLocalDate(Date utcDate) {
|
||||
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
||||
calendar.setTime(utcDate);
|
||||
calendar.setTimeZone(TimeZone.getDefault());
|
||||
return calendar.getTime();
|
||||
}*/
|
||||
|
||||
public static boolean setListViewHeightBasedOnItems(ListView listView) {
|
||||
|
||||
ListAdapter listAdapter = listView.getAdapter();
|
||||
|
||||
@ -7,12 +7,16 @@ import android.view.View;
|
||||
import android.widget.DatePicker;
|
||||
import android.widget.TimePicker;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import dbfields.fieldDB;
|
||||
import kz.istt.locust.R;
|
||||
import kz.istt.locust.Tools;
|
||||
|
||||
|
||||
public class OnClickListenerDateTime implements View.OnClickListener {
|
||||
@ -30,62 +34,53 @@ public class OnClickListenerDateTime implements View.OnClickListener {
|
||||
DatePickerDialog.OnDateSetListener myDateListener = new DatePickerDialog.OnDateSetListener() {
|
||||
@Override
|
||||
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
|
||||
|
||||
//SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm");
|
||||
//format.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
//LocustActivity.this.edtDate.setText(format.format(curDateTime));
|
||||
int month = monthOfYear + 1;
|
||||
|
||||
//Теперь выбираем время
|
||||
TimePickerDialog.OnTimeSetListener myDateListener = new TimePickerDialog.OnTimeSetListener() {
|
||||
TimePickerDialog.OnTimeSetListener myTimeListener = new TimePickerDialog.OnTimeSetListener() {
|
||||
@Override
|
||||
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
|
||||
long val = Long.parseLong(edtDate.getValue());
|
||||
val += (hourOfDay * 60 + minute) * 60;
|
||||
edtDate.setValue(String.valueOf(val));
|
||||
Date date = Tools.getDateFromStr(edtDate.getValue());
|
||||
if(date != null) {
|
||||
date = Tools.setHMS(date,hourOfDay,minute,0);
|
||||
edtDate.setValue(Tools.dateToStr(date));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (edtDate.getValue() != null && !edtDate.getValue().equals("")) {
|
||||
Date time = new Date(Long.parseLong(edtDate.getValue()) * 1000);
|
||||
Date time = Tools.getDateFromStr(edtDate.getValue());
|
||||
if(time != null){
|
||||
|
||||
Calendar myCal = new GregorianCalendar();
|
||||
myCal.setTime(time);
|
||||
int hour = myCal.get(Calendar.HOUR_OF_DAY);
|
||||
int minute = myCal.get(Calendar.MINUTE);
|
||||
TimePickerDialog tpd = new TimePickerDialog(context, R.style.AlertDialogTheme, myDateListener, hour, minute, true);
|
||||
TimePickerDialog tpd = new TimePickerDialog(context, R.style.AlertDialogTheme, myTimeListener, hour, minute, true);
|
||||
tpd.show();
|
||||
} else {
|
||||
final Calendar myCal = Calendar.getInstance();
|
||||
int hour = myCal.get(Calendar.HOUR_OF_DAY);
|
||||
int minute = myCal.get(Calendar.MINUTE);
|
||||
TimePickerDialog tpd = new TimePickerDialog(context, R.style.AlertDialogTheme, myDateListener, hour, minute, true);
|
||||
TimePickerDialog tpd = new TimePickerDialog(context, R.style.AlertDialogTheme, myTimeListener, hour, minute, true);
|
||||
tpd.show();
|
||||
}
|
||||
|
||||
Date date = new Date(year - 1900, monthOfYear, dayOfMonth);
|
||||
edtDate.setValue(String.valueOf(date.getTime() / 1000));
|
||||
time = Tools.setYMD(time,year,month,dayOfMonth);
|
||||
edtDate.setValue(Tools.dateToStr(time));
|
||||
}
|
||||
};
|
||||
|
||||
//if (!edtDate.getText().toString().equals("")) {
|
||||
if(edtDate.getValue() != null && !edtDate.getValue().equals("")){
|
||||
Date date = null;
|
||||
date = new Date(Long.parseLong(edtDate.getValue())*1000);
|
||||
//SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm");
|
||||
//format.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
//try {
|
||||
// date = format.parse(edtDate.getText().toString());
|
||||
//} catch (ParseException e) {
|
||||
// e.printStackTrace();
|
||||
//}
|
||||
if (date != null) {
|
||||
Calendar myCal = new GregorianCalendar();
|
||||
myCal.setTime(date);
|
||||
int day = myCal.get(Calendar.DAY_OF_MONTH);
|
||||
int month = myCal.get(Calendar.MONTH);
|
||||
int year = myCal.get(Calendar.YEAR);
|
||||
DatePickerDialog dpd = new DatePickerDialog(context, R.style.AlertDialogTheme, myDateListener, year, month, day);
|
||||
dpd.show();
|
||||
}
|
||||
Date date = Tools.getDateFromStr(edtDate.getValue());
|
||||
if(date != null){
|
||||
|
||||
Calendar myCal = new GregorianCalendar();
|
||||
myCal.setTime(date);
|
||||
int day = myCal.get(Calendar.DAY_OF_MONTH);
|
||||
int month = myCal.get(Calendar.MONTH);
|
||||
int year = myCal.get(Calendar.YEAR);
|
||||
DatePickerDialog dpd = new DatePickerDialog(context, R.style.AlertDialogTheme, myDateListener, year, month, day);
|
||||
dpd.show();
|
||||
|
||||
} else {
|
||||
final Calendar c = Calendar.getInstance();
|
||||
int year = c.get(Calendar.YEAR);
|
||||
|
||||
Reference in New Issue
Block a user