正在查看: xDrip+ v04633772025.07.16 应用的 NoteSearch.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: xDrip+ v04633772025.07.16 应用的 NoteSearch.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.eveningoutpost.dexdrip;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import com.activeandroid.Cache;
import com.activeandroid.util.SQLiteUtils;
import com.eveningoutpost.dexdrip.models.BgReading;
import com.eveningoutpost.dexdrip.models.JoH;
import com.eveningoutpost.dexdrip.utils.ListActivityWithMenu;
import java.text.DateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.Vector;
import lecho.lib.hellocharts.util.ChartUtils;
public class NoteSearch extends ListActivityWithMenu {
private GregorianCalendar date1;
private GregorianCalendar date2;
private Button dateButton1;
private Button dateButton2;
private Cursor dbCursor;
private SearchResultAdapter resultListAdapter;
private EditText searchTextField;
private DateFormat dateFormatter = DateFormat.getDateInstance(2, Locale.getDefault());
private long last_keypress_time = -1;
@Override
public String getMenuName() {
return getString(2131755929);
}
@Override
protected void onCreate(Bundle bundle) {
setTheme(2131820787);
super.onCreate(bundle);
setContentView(2131492931);
GregorianCalendar gregorianCalendar = new GregorianCalendar();
this.date1 = gregorianCalendar;
gregorianCalendar.set(11, 0);
this.date1.set(12, 0);
this.date1.set(13, 0);
this.date1.set(14, 0);
this.date1.add(5, -7);
GregorianCalendar gregorianCalendar2 = new GregorianCalendar();
this.date2 = gregorianCalendar2;
gregorianCalendar2.set(11, 0);
this.date2.set(12, 0);
this.date2.set(13, 0);
this.date2.set(14, 0);
SearchResultAdapter searchResultAdapter = new SearchResultAdapter();
this.resultListAdapter = searchResultAdapter;
setListAdapter(searchResultAdapter);
getListView().setLongClickable(true);
getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long j) {
final SearchResult searchResult = (SearchResult) NoteSearch.this.resultListAdapter.getItem(i);
if (searchResult == null) {
return true;
}
final EditText editText = new EditText(this);
if (searchResult.note == null) {
searchResult.note = "";
}
editText.setText(searchResult.note);
new AlertDialog.Builder(this).setTitle(2131755490).setMessage(2131755083).setView(editText).setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i2) {
searchResult.note = editText.getText().toString().trim();
NoteSearch.this.resultListAdapter.notifyDataSetChanged();
SearchResult searchResult2 = searchResult;
SQLiteUtils.execSql("update Treatments set notes = ? where uuid = ?", new String[]{searchResult2.note, searchResult2.uuid});
}
}).setNegativeButton(NoteSearch.this.getString(2131755280), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i2) {
}
}).show();
return true;
}
});
setupGui();
doAll(false);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(2131558410, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
int itemId = menuItem.getItemId();
if (itemId == 2131296737) {
doAll(true);
return true;
}
if (itemId == 2131296740) {
doSearch(true);
return true;
}
return super.onOptionsItemSelected(menuItem);
}
private void doAll(boolean z) {
if (JoH.ratelimit("NoteSearch-All", 2)) {
if (z) {
hideKeyboard();
}
this.resultListAdapter.clear();
if (z) {
JoH.static_toast_short(getString(2131755342));
}
SQLiteDatabase openDatabase = Cache.openDatabase();
Cursor cursor = this.dbCursor;
if (cursor != null && !cursor.isClosed()) {
this.dbCursor.close();
}
long timeInMillis = this.date1.getTimeInMillis();
GregorianCalendar gregorianCalendar = (GregorianCalendar) this.date2.clone();
gregorianCalendar.add(5, 1);
Cursor rawQuery = openDatabase.rawQuery("select timestamp, notes, carbs, insulin, uuid from Treatments where notes IS NOT NULL AND timestamp < " + gregorianCalendar.getTimeInMillis() + " AND timestamp >= " + timeInMillis + " ORDER BY timestamp DESC", null);
this.dbCursor = rawQuery;
rawQuery.moveToFirst();
int i = 0;
while (i < 8 && !this.dbCursor.isAfterLast()) {
this.resultListAdapter.addSingle(new SearchResult(this.dbCursor.getLong(0), this.dbCursor.getString(1), this.dbCursor.getDouble(2), this.dbCursor.getDouble(3), this.dbCursor.getString(4)));
this.dbCursor.moveToNext();
i++;
}
if (i == 0 && z) {
JoH.static_toast_short(getString(2131755932));
}
if (this.dbCursor.isAfterLast()) {
this.dbCursor.close();
return;
}
SearchResult searchResult = new SearchResult(0L, getString(2131755762), BgReading.BESTOFFSET, BgReading.BESTOFFSET, null);
searchResult.setLoadMoreActionFlag();
this.resultListAdapter.addSingle(searchResult);
}
}
public void doSearch(boolean z) {
if (z) {
hideKeyboard();
}
String trim = this.searchTextField.getText().toString().trim();
if ("".equals(trim)) {
if (z) {
JoH.static_toast_short(getString(2131755914));
return;
}
return;
}
int i = 2;
if (z || trim.length() >= 2) {
this.resultListAdapter.clear();
if (z) {
JoH.static_toast_short(getString(2131756242));
}
SQLiteDatabase openDatabase = Cache.openDatabase();
Cursor cursor = this.dbCursor;
if (cursor != null && !cursor.isClosed()) {
this.dbCursor.close();
}
DatabaseUtils.sqlEscapeString(trim);
long timeInMillis = this.date1.getTimeInMillis();
GregorianCalendar gregorianCalendar = (GregorianCalendar) this.date2.clone();
gregorianCalendar.add(5, 1);
Cursor rawQuery = openDatabase.rawQuery("select timestamp, notes, carbs, insulin, uuid from Treatments where notes IS NOT NULL AND timestamp < ? AND timestamp >= ? AND notes like ? ORDER BY timestamp DESC", new String[]{Long.toString(gregorianCalendar.getTimeInMillis()), Long.toString(timeInMillis), "%" + trim + "%"});
this.dbCursor = rawQuery;
rawQuery.moveToFirst();
int i2 = 0;
while (i2 < 8 && !this.dbCursor.isAfterLast()) {
this.resultListAdapter.addSingle(new SearchResult(this.dbCursor.getLong(0), this.dbCursor.getString(1), this.dbCursor.getDouble(i), this.dbCursor.getDouble(3), this.dbCursor.getString(4)));
this.dbCursor.moveToNext();
i2++;
i = 2;
}
if (i2 == 0 && z) {
JoH.static_toast_short(getString(2131755932));
}
if (this.dbCursor.isAfterLast()) {
this.dbCursor.close();
return;
}
SearchResult searchResult = new SearchResult(0L, getString(2131755762), BgReading.BESTOFFSET, BgReading.BESTOFFSET, null);
searchResult.setLoadMoreActionFlag();
this.resultListAdapter.addSingle(searchResult);
}
}
private void hideKeyboard() {
getApplicationContext();
((InputMethodManager) getSystemService("input_method")).hideSoftInputFromWindow(this.searchTextField.getWindowToken(), 0);
}
@Override
protected void onDestroy() {
Cursor cursor = this.dbCursor;
if (cursor != null && !cursor.isClosed()) {
this.dbCursor.close();
}
super.onDestroy();
}
private void setupGui() {
this.dateButton1 = (Button) findViewById(2131296461);
this.dateButton2 = (Button) findViewById(2131296462);
this.searchTextField = (EditText) findViewById(2131296947);
updateButtonText();
this.searchTextField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
if (i != 3) {
return false;
}
NoteSearch.this.doSearch(true);
return true;
}
});
this.searchTextField.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
@Override
public void afterTextChanged(Editable editable) {
NoteSearch.this.last_keypress_time = JoH.tsl();
JoH.runOnUiThreadDelayed(new Runnable() {
@Override
public void run() {
NoteSearch.this.searchOnKeyPress();
}
}, 500L);
}
});
this.dateButton1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new DatePickerDialog(NoteSearch.this, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker datePicker, int i, int i2, int i3) {
NoteSearch.this.date1.set(i, i2, i3);
NoteSearch.this.updateButtonText();
}
}, NoteSearch.this.date1.get(1), NoteSearch.this.date1.get(2), NoteSearch.this.date1.get(5)).show();
}
});
this.dateButton2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new DatePickerDialog(NoteSearch.this, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker datePicker, int i, int i2, int i3) {
NoteSearch.this.date2.set(i, i2, i3);
NoteSearch.this.updateButtonText();
}
}, NoteSearch.this.date2.get(1), NoteSearch.this.date2.get(2), NoteSearch.this.date2.get(5)).show();
}
});
}
public void updateButtonText() {
this.dateButton1.setText(this.dateFormatter.format(this.date1.getTime()));
this.dateButton2.setText(this.dateFormatter.format(this.date2.getTime()));
}
@Override
protected void onListItemClick(ListView listView, View view, int i, long j) {
SearchResult searchResult = (SearchResult) this.resultListAdapter.getItem(i);
if (!searchResult.isLoadMoreAction) {
Intent intent = new Intent(this, (Class<?>) BGHistory.class);
intent.putExtra("BGHistory.open_on_time", searchResult.timestamp);
startActivity(intent);
finish();
return;
}
loadMore();
}
public void searchOnKeyPress() {
if (this.last_keypress_time <= 0 || JoH.tsl() - this.last_keypress_time <= 499) {
return;
}
this.last_keypress_time = -1L;
doSearch(false);
}
private void loadMore() {
this.resultListAdapter.removeLoadMoreAction();
Cursor cursor = this.dbCursor;
if (cursor == null || cursor.isClosed()) {
return;
}
for (int i = 0; i < 8 && !this.dbCursor.isAfterLast(); i++) {
this.resultListAdapter.addSingle(new SearchResult(this.dbCursor.getLong(0), this.dbCursor.getString(1), this.dbCursor.getDouble(2), this.dbCursor.getDouble(3), this.dbCursor.getString(4)));
this.dbCursor.moveToNext();
}
if (this.dbCursor.isAfterLast()) {
this.dbCursor.close();
return;
}
SearchResult searchResult = new SearchResult(0L, getString(2131755762), BgReading.BESTOFFSET, BgReading.BESTOFFSET, null);
searchResult.setLoadMoreActionFlag();
this.resultListAdapter.addSingle(searchResult);
}
static class ViewHolder {
boolean modified;
TextView note;
TextView time;
TextView treatments;
ViewHolder() {
}
}
private class SearchResultAdapter extends BaseAdapter {
private Vector<SearchResult> noteList = new Vector<>(30);
@Override
public long getItemId(int i) {
return i;
}
public SearchResultAdapter() {
}
@Override
public int getCount() {
return this.noteList.size();
}
@Override
public Object getItem(int i) {
return this.noteList.get(i);
}
public void clear() {
this.noteList.clear();
notifyDataSetChanged();
}
public void addSingle(SearchResult searchResult) {
this.noteList.add(searchResult);
notifyDataSetChanged();
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
ViewHolder viewHolder;
if (view == null || ((ViewHolder) view.getTag()).modified) {
view = NoteSearch.this.getLayoutInflater().inflate(2131493029, (ViewGroup) null);
viewHolder = new ViewHolder();
viewHolder.note = (TextView) view.findViewById(2131296813);
viewHolder.time = (TextView) view.findViewById(2131296814);
viewHolder.treatments = (TextView) view.findViewById(2131296815);
view.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) view.getTag();
}
SearchResult searchResult = this.noteList.get(i);
if (searchResult.isLoadMoreAction) {
viewHolder.note.setTextColor(ChartUtils.COLOR_BLUE);
viewHolder.note.setTextSize(2, 26.0f);
viewHolder.treatments.setVisibility(8);
viewHolder.time.setVisibility(8);
viewHolder.modified = true;
}
viewHolder.note.setText(searchResult.note);
if (!"".equals(searchResult.otherTreatments)) {
viewHolder.treatments.setText(searchResult.otherTreatments);
} else {
viewHolder.treatments.setVisibility(8);
viewHolder.modified = true;
}
viewHolder.time.setText(new Date(searchResult.timestamp).toString());
return view;
}
public void removeLoadMoreAction() {
if (this.noteList.get(r0.size() - 1).isLoadMoreAction) {
this.noteList.remove(r0.size() - 1);
notifyDataSetChanged();
}
}
}
private class SearchResult {
boolean isLoadMoreAction;
String note;
String otherTreatments = "";
long timestamp;
String uuid;
public SearchResult(long j, String str, double d, double d2, String str2) {
this.timestamp = j;
this.note = str;
this.uuid = str2;
if (d != BgReading.BESTOFFSET) {
this.otherTreatments += NoteSearch.this.getString(2131755292) + ": " + d;
}
if (d2 != BgReading.BESTOFFSET) {
this.otherTreatments += " " + NoteSearch.this.getString(2131755700) + ": " + d2;
}
}
public void setLoadMoreActionFlag() {
this.isLoadMoreAction = true;
}
}
}