正在查看: xDrip+ v04633772025.07.16 应用的 ProfileEditor.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: xDrip+ v04633772025.07.16 应用的 ProfileEditor.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.eveningoutpost.dexdrip.profileeditor;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Point;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.TextView;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.eveningoutpost.dexdrip.BaseAppCompatActivity;
import com.eveningoutpost.dexdrip.Home;
import com.eveningoutpost.dexdrip.models.JoH;
import com.eveningoutpost.dexdrip.models.Profile;
import com.eveningoutpost.dexdrip.models.UserError;
import com.eveningoutpost.dexdrip.utilitymodels.JamorhamShowcaseDrawer;
import com.eveningoutpost.dexdrip.utilitymodels.Pref;
import com.eveningoutpost.dexdrip.utilitymodels.ShotStateStore;
import com.eveningoutpost.dexdrip.utils.Preferences;
import com.github.amlcurran.showcaseview.ShowcaseView;
import com.github.amlcurran.showcaseview.targets.Target;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
public class ProfileEditor extends BaseAppCompatActivity {
private static TextView adjustPercentage = null;
private static SeekBar adjustallSeekBar = null;
private static double adjustmentFactor = 1.0d;
private static boolean doMgdl;
private static double last_conversion;
private static ShowcaseView myShowcase;
private static Button saveBtn;
private static Button undoBtn;
private ProfileAdapter mAdapter;
private Context mContext;
private RecyclerView recyclerView;
private final List<ProfileItem> profileItemList = new ArrayList();
private boolean dataChanged = false;
@Override
protected void onCreate(Bundle bundle) {
this.mContext = this;
doMgdl = Pref.getString("units", "mgdl").equals("mgdl");
super.onCreate(bundle);
setContentView(2131492933);
undoBtn = (Button) findViewById(2131296856);
saveBtn = (Button) findViewById(2131296852);
adjustallSeekBar = (SeekBar) findViewById(2131296849);
adjustPercentage = (TextView) findViewById(2131296848);
this.profileItemList.clear();
this.profileItemList.addAll(loadData(true));
JoH.fixActionBar(this);
adjustallSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean z) {
double unused = ProfileEditor.adjustmentFactor = ((i - 25) * 0.02d) + 1.0d;
ProfileEditor.adjustPercentage.setText(JoH.qs(ProfileEditor.adjustmentFactor * 100.0d, 0) + "%");
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
ProfileEditor.this.profileItemList.clear();
ProfileEditor.this.profileItemList.addAll(ProfileEditor.loadData(false));
ProfileEditor.this.mAdapter.resetTopMax();
ProfileEditor.this.forceRefresh(true);
}
});
this.recyclerView = (RecyclerView) findViewById(2131296859);
this.mAdapter = new ProfileAdapter(this, this.profileItemList, doMgdl);
this.recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
this.recyclerView.setItemAnimator(new DefaultItemAnimator());
if (this.profileItemList.size() == 0) {
this.profileItemList.add(new ProfileItem(0, 1439, JoH.tolerantParseDouble(Pref.getString("profile_carb_ratio_default", "10"), 10.0d), JoH.tolerantParseDouble(Pref.getString("profile_insulin_sensitivity_default", "0.1"), 0.1d)));
}
updateAdjustmentFactor(1.0d);
shuffleFit();
this.mAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
@Override
public void onChanged() {
super.onChanged();
}
@Override
public void onItemRangeChanged(final int i, int i2, Object obj) {
super.onItemRangeChanged(i, i2, obj);
Log.d("jamorhamprofile", "onItemRangeChanged: pos:" + i + " cnt:" + i2 + " p: " + obj.toString());
if (obj.toString().equals("time start updated")) {
if (i > 0) {
int i3 = i - 1;
if (((ProfileItem) ProfileEditor.this.profileItemList.get(i3)).end_min != ((ProfileItem) ProfileEditor.this.profileItemList.get(i)).start_min - 1) {
((ProfileItem) ProfileEditor.this.profileItemList.get(i3)).end_min = ((ProfileItem) ProfileEditor.this.profileItemList.get(i)).start_min - 1;
}
} else {
((ProfileItem) ProfileEditor.this.profileItemList.get(ProfileEditor.this.profileItemList.size() - 1)).end_min = ((ProfileItem) ProfileEditor.this.profileItemList.get(i)).start_min - 1;
}
ProfileEditor.this.forceRefresh();
return;
}
if (obj.toString().equals("time end updated")) {
if (i < ProfileEditor.this.profileItemList.size() - 1) {
int i4 = i + 1;
if (((ProfileItem) ProfileEditor.this.profileItemList.get(i4)).start_min != ((ProfileItem) ProfileEditor.this.profileItemList.get(i)).end_min + 1) {
((ProfileItem) ProfileEditor.this.profileItemList.get(i4)).start_min = ((ProfileItem) ProfileEditor.this.profileItemList.get(i)).end_min + 1;
}
} else {
((ProfileItem) ProfileEditor.this.profileItemList.get(0)).start_min = ((ProfileItem) ProfileEditor.this.profileItemList.get(i)).end_min + 1;
}
ProfileEditor.this.forceRefresh();
return;
}
if (!obj.toString().equals("long-split")) {
ProfileEditor.this.forceRefresh();
return;
}
DisplayMetrics displayMetrics = new DisplayMetrics();
ProfileEditor.this.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
boolean z = displayMetrics.widthPixels < 720 || displayMetrics.heightPixels < 720;
AlertDialog.Builder builder = new AlertDialog.Builder(ProfileEditor.this.mContext);
builder.setMessage(2131756411);
builder.setPositiveButton(ProfileEditor.this.getString(z ? 2131756410 : 2131756412), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i5) {
ProfileItem profileItem;
ProfileItem profileItem2 = (ProfileItem) ProfileEditor.this.profileItemList.get(i);
if (profileItem2.start_min < profileItem2.end_min) {
int i6 = profileItem2.end_min;
profileItem = new ProfileItem(i6 - ((i6 - profileItem2.start_min) / 2), i6, profileItem2.carb_ratio, profileItem2.sensitivity);
} else {
int i7 = profileItem2.end_min;
profileItem = new ProfileItem(i7 - (((i7 - 1440) - profileItem2.start_min) / 2), i7, profileItem2.carb_ratio, profileItem2.sensitivity);
}
profileItem2.end_min = profileItem.start_min - 1;
ProfileEditor.this.profileItemList.add(i + 1, profileItem);
ProfileEditor.this.forceRefresh();
}
});
if (ProfileEditor.this.profileItemList.size() > 1) {
builder.setNeutralButton(ProfileEditor.this.getString(z ? 2131755418 : 2131755422), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i5) {
ProfileEditor.this.profileItemList.remove(i);
ProfileEditor.this.forceRefresh();
}
});
}
builder.setNegativeButton(ProfileEditor.this.getString(z ? 2131755280 : 2131755283), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i5) {
}
});
builder.create().show();
}
});
this.recyclerView.setItemAnimator(new DefaultItemAnimator() {
@Override
public boolean canReuseUpdatedViewHolder(RecyclerView.ViewHolder viewHolder) {
return true;
}
});
this.recyclerView.setAdapter(this.mAdapter);
this.mAdapter.notifyDataSetChanged();
showcasemenu(501);
}
@Override
public void onResume() {
super.onResume();
this.profileItemList.clear();
this.profileItemList.addAll(loadData(true));
this.mAdapter.notifyDataSetChanged();
}
@Override
public void onPause() {
super.onPause();
if (this.dataChanged) {
Profile.reloadPreferences();
Intent intent = new Intent(this, (Class<?>) Preferences.class);
intent.setFlags(536870912);
intent.putExtra("refresh", "");
startActivity(intent);
}
}
private static void updateAdjustmentFactor(double d) {
adjustmentFactor = d;
adjustPercentage.setText(JoH.qs(adjustmentFactor * 100.0d, 0) + "%");
int i = ((int) ((adjustmentFactor - 1.0d) / 0.02d)) + 25;
adjustallSeekBar.setProgress(i > 0 ? i : 0);
}
private void saveData(boolean z) {
Gson create = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().serializeSpecialFloatingPointValues().create();
ArrayList<ProfileItem> arrayList = new ArrayList();
if (!z) {
Log.d("jamorhamprofile", "Saving for real with adjustment factor: " + adjustmentFactor);
Iterator<ProfileItem> it = this.profileItemList.iterator();
while (it.hasNext()) {
arrayList.add(it.next().m140clone());
}
for (ProfileItem profileItem : arrayList) {
double d = profileItem.carb_ratio;
double d2 = adjustmentFactor;
profileItem.carb_ratio = d / d2;
profileItem.sensitivity *= d2;
}
} else {
arrayList.addAll(this.profileItemList);
for (ProfileItem profileItem2 : arrayList) {
profileItem2.carb_ratio = Math.round(profileItem2.carb_ratio * 10.0d) / 10.0d;
profileItem2.sensitivity = Math.round(profileItem2.sensitivity * 10.0d) / 10.0d;
}
}
String json = create.toJson(arrayList);
if (z) {
saveBtn.setVisibility(4);
saveProfileJson(json);
UserError.Log.uel("jamorhamprofile", "Saved Treatment Profile data, timeblocks:" + arrayList.size());
updateAdjustmentFactor(1.0d);
this.dataChanged = true;
Profile.invalidateProfile();
return;
}
Pref.setString("saved_profile_list_json_working", json);
saveBtn.setVisibility(0);
undoBtn.setVisibility(0);
Log.d("jamorhamprofile", "Saved working data");
}
public static void saveProfileJson(String str) {
Pref.setString("saved_profile_list_json", str);
Pref.setString("saved_profile_list_json_working", "");
Log.d("jamorhamprofile", "Saved final data");
}
private void clearWorkingData() {
Pref.setString("saved_profile_list_json_working", "");
}
public void profileCancelButton(View view) {
clearWorkingData();
finish();
}
public void profileSaveButton(View view) {
saveData(true);
finish();
}
public void profileUndoButton(View view) {
clearWorkingData();
adjustmentFactor = 1.0d;
adjustallSeekBar.setProgress(25);
this.profileItemList.clear();
this.profileItemList.addAll(loadData(true));
this.mAdapter.resetTopMax();
forceRefresh(false);
}
public static void convertData(double d) {
if (last_conversion == d) {
return;
}
last_conversion = d;
List<ProfileItem> loadData = loadData(false);
for (ProfileItem profileItem : loadData) {
profileItem.carb_ratio = Math.round(profileItem.carb_ratio * 10.0d) / 10.0d;
profileItem.sensitivity = Math.round((profileItem.sensitivity * 10.0d) * d) / 10.0d;
}
Pref.setString("saved_profile_list_json", new GsonBuilder().excludeFieldsWithoutExposeAnnotation().serializeSpecialFloatingPointValues().create().toJson(loadData));
Pref.setString("saved_profile_list_json_working", "");
StringBuilder sb = new StringBuilder();
sb.append("Converted Profile data with multiplier: ");
sb.append(d == 0.055560000240802765d ? " to mmol/l" : "to mg/dl");
UserError.Log.uel("jamorhamprofile", sb.toString());
}
public static List<ProfileItem> loadData(boolean z) {
ArrayList arrayList = new ArrayList();
String string = Pref.getString("saved_profile_list_json_working", "");
if (string.length() == 0) {
string = Pref.getString("saved_profile_list_json", "");
if (z) {
saveBtn.setVisibility(4);
undoBtn.setVisibility(4);
}
Log.d("jamorhamprofile", "Loaded real data");
} else {
Log.d("jamorhamprofile", "Loaded working data");
if (z) {
saveBtn.setVisibility(0);
undoBtn.setVisibility(0);
}
}
ProfileItem[] profileItemArr = (ProfileItem[]) new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create().fromJson(string, ProfileItem[].class);
if (profileItemArr != null) {
for (ProfileItem profileItem : profileItemArr) {
double d = profileItem.carb_ratio;
double d2 = adjustmentFactor;
profileItem.carb_ratio = d * d2;
profileItem.sensitivity /= d2;
}
Collections.addAll(arrayList, profileItemArr);
}
if (arrayList.size() == 0) {
try {
Log.d("jamorhamprofile", "Creating default profile entries: sens default: " + Pref.getString("profile_insulin_sensitivity_default", "0.1"));
arrayList.add(new ProfileItem(0, 1439, Double.parseDouble(Pref.getString("profile_carb_ratio_default", "10")), Double.parseDouble(Pref.getString("profile_insulin_sensitivity_default", "0.1"))));
} catch (Exception unused) {
Home.toaststatic("Problem with default insulin parameters");
}
}
return arrayList;
}
public static String minMaxCarbs(List<ProfileItem> list) {
Iterator<ProfileItem> it = list.iterator();
double d = 9999999.0d;
double d2 = -1.0d;
while (it.hasNext()) {
double d3 = it.next().carb_ratio;
if (d3 > d2) {
d2 = d3;
}
if (d3 < d) {
d = d3;
}
}
if (d == d2) {
return JoH.qs(d, -1);
}
return JoH.qs(d, -1) + " - " + JoH.qs(d2, -1);
}
public static String minMaxSens(List<ProfileItem> list) {
Iterator<ProfileItem> it = list.iterator();
double d = 9999999.0d;
double d2 = -1.0d;
while (it.hasNext()) {
double d3 = it.next().sensitivity;
if (d3 > d2) {
d2 = d3;
}
if (d3 < d) {
d = d3;
}
}
if (d == d2) {
return JoH.qs(d, -1);
}
return JoH.qs(d, -1) + " - " + JoH.qs(d2, -1);
}
public void forceRefresh() {
forceRefresh(true);
}
public void forceRefresh(boolean z) {
shuffleFit();
if (z) {
saveData(false);
}
this.mAdapter.calcTopScale();
this.mAdapter.first_run = this.profileItemList.size();
this.recyclerView.invalidate();
this.recyclerView.refreshDrawableState();
this.mAdapter.notifyDataSetChanged();
}
private void shuffleFit() {
if (this.profileItemList.size() > 1) {
ProfileItem profileItem = this.profileItemList.get(0);
List<ProfileItem> list = this.profileItemList;
profileItem.start_min = list.get(list.size() - 1).end_min + 1;
} else {
this.profileItemList.get(0).start_min = 0;
this.profileItemList.get(0).end_min = 1439;
}
for (ProfileItem profileItem2 : this.profileItemList) {
profileItem2.end_min %= 1440;
profileItem2.start_min %= 1440;
}
if (this.profileItemList.size() > 0) {
for (int i = 1; i < this.profileItemList.size(); i++) {
ProfileItem profileItem3 = this.profileItemList.get(i);
ProfileItem profileItem4 = this.profileItemList.get(i - 1);
int i2 = profileItem3.start_min;
int i3 = profileItem4.end_min;
if (i2 < i3) {
profileItem3.start_min = i3 + 1;
}
}
}
}
private synchronized void showcasemenu(int i) {
ProfileViewTarget profileViewTarget;
ShowcaseView showcaseView = myShowcase;
if (showcaseView == null || !showcaseView.isShowing()) {
if (ShotStateStore.hasShot(i)) {
return;
}
String str = "";
String str2 = "";
if (i != 501) {
profileViewTarget = null;
} else {
try {
profileViewTarget = new ProfileViewTarget(2131296859, this, 40, 40);
str = getString(2131755776);
str2 = getString(2131756145);
} catch (Exception e) {
Log.e("jamorhamprofile", "Exception in showcase: " + e.toString());
}
}
if (profileViewTarget != null) {
ShowcaseView build = new ShowcaseView.Builder(this).setTarget(profileViewTarget).setStyle(2131820768).setContentTitle(str).setContentText("\n" + str2).setShowcaseDrawer(new JamorhamShowcaseDrawer(getResources(), getTheme(), 90.0f, 14.0f)).singleShot(i).build();
myShowcase = build;
build.setBackgroundColor(0);
myShowcase.show();
}
}
}
public class ProfileViewTarget implements Target {
private final View mView;
private int offsetX;
private int offsetY;
public ProfileViewTarget(int i, Activity activity, int i2, int i3) {
this.offsetX = 0;
this.offsetY = 0;
this.mView = activity.findViewById(i);
this.offsetX = i2;
this.offsetY = i3;
}
@Override
public Point getPoint() {
int i;
int i2;
int[] iArr = new int[2];
this.mView.getLocationInWindow(iArr);
int i3 = this.offsetX;
if (i3 != 0 || this.offsetY != 0) {
i = i3 + iArr[0];
i2 = iArr[1] + this.offsetY;
} else {
i = iArr[0] + (this.mView.getWidth() / 2);
i2 = iArr[1] + (this.mView.getHeight() / 2);
}
return new Point(i, i2);
}
}
}