SingleClickButton

This commit is contained in:
Milos Kozak 2017-12-22 19:50:16 +01:00
parent 25667bc79e
commit 600e2ade1c
17 changed files with 155 additions and 76 deletions

View file

@ -8,7 +8,6 @@ import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import com.crashlytics.android.Crashlytics;
import com.crashlytics.android.answers.Answers;
@ -33,6 +32,7 @@ import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialo
import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.utils.SingleClickButton;
/**
* A simple {@link Fragment} subclass.
@ -45,13 +45,13 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL
return actionsPlugin;
}
Button profileSwitch;
Button tempTarget;
Button extendedBolus;
Button extendedBolusCancel;
Button tempBasal;
Button tempBasalCancel;
Button fill;
SingleClickButton profileSwitch;
SingleClickButton tempTarget;
SingleClickButton extendedBolus;
SingleClickButton extendedBolusCancel;
SingleClickButton tempBasal;
SingleClickButton tempBasalCancel;
SingleClickButton fill;
public ActionsFragment() {
super();
@ -64,13 +64,13 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL
try {
View view = inflater.inflate(R.layout.actions_fragment, container, false);
profileSwitch = (Button) view.findViewById(R.id.actions_profileswitch);
tempTarget = (Button) view.findViewById(R.id.actions_temptarget);
extendedBolus = (Button) view.findViewById(R.id.actions_extendedbolus);
extendedBolusCancel = (Button) view.findViewById(R.id.actions_extendedbolus_cancel);
tempBasal = (Button) view.findViewById(R.id.actions_settempbasal);
tempBasalCancel = (Button) view.findViewById(R.id.actions_canceltempbasal);
fill = (Button) view.findViewById(R.id.actions_fill);
profileSwitch = (SingleClickButton) view.findViewById(R.id.actions_profileswitch);
tempTarget = (SingleClickButton) view.findViewById(R.id.actions_temptarget);
extendedBolus = (SingleClickButton) view.findViewById(R.id.actions_extendedbolus);
extendedBolusCancel = (SingleClickButton) view.findViewById(R.id.actions_extendedbolus_cancel);
tempBasal = (SingleClickButton) view.findViewById(R.id.actions_settempbasal);
tempBasalCancel = (SingleClickButton) view.findViewById(R.id.actions_canceltempbasal);
fill = (SingleClickButton) view.findViewById(R.id.actions_fill);
profileSwitch.setOnClickListener(this);
tempTarget.setOnClickListener(this);

View file

@ -100,6 +100,8 @@ public class FillDialog extends DialogFragment implements OnClickListener {
if (button1.getVisibility() == View.GONE && button2.getVisibility() == View.GONE && button3.getVisibility() == View.GONE) {
divider.setVisibility(View.GONE);
}
setCancelable(false);
return view;
}

View file

@ -54,14 +54,9 @@ public class NewExtendedBolusDialog extends DialogFragment implements View.OnCli
view.findViewById(R.id.ok).setOnClickListener(this);
view.findViewById(R.id.cancel).setOnClickListener(this);
return view;
}
@Override
public void onResume() {
super.onResume();
if (getDialog() != null)
getDialog().getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
setCancelable(false);
return view;
}
@Override

View file

@ -102,6 +102,8 @@ public class NewTempBasalDialog extends DialogFragment implements View.OnClickLi
view.findViewById(R.id.ok).setOnClickListener(this);
view.findViewById(R.id.cancel).setOnClickListener(this);
basalTypeRadioGroup.setOnCheckedChangeListener(this);
setCancelable(false);
return view;
}

View file

@ -360,6 +360,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_reuse_layout), options.profile && ps != null && ps.isCPP);
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_temptarget_layout), options.tempTarget);
setCancelable(false);
return view;
}

View file

@ -76,6 +76,7 @@ public class CalibrationDialog extends DialogFragment implements View.OnClickLis
unitsView = (TextView) view.findViewById(R.id.overview_calibration_units);
unitsView.setText(units);
setCancelable(false);
return view;
}

View file

@ -102,6 +102,7 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene
editCarbs.setParams(0d, 0d, (double) maxCarbs, 1d, new DecimalFormat("0"), false, textWatcher);
editInsulin.setParams(0d, 0d, maxInsulin, ConfigBuilderPlugin.getActivePump().getPumpDescription().bolusStep, new DecimalFormat("0.00"), false, textWatcher);
setCancelable(false);
return view;
}

View file

@ -251,6 +251,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
editCarbTime.setParams(0d, -60d, 60d, 5d, new DecimalFormat("0"), false);
initDialog();
setCancelable(false);
return view;
}

View file

@ -52,7 +52,6 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import info.nightscout.androidaps.BuildConfig;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
@ -113,6 +112,7 @@ import info.nightscout.utils.NSUpload;
import info.nightscout.utils.OKDialog;
import info.nightscout.utils.Profiler;
import info.nightscout.utils.SP;
import info.nightscout.utils.SingleClickButton;
import info.nightscout.utils.ToastUtils;
public class OverviewFragment extends Fragment implements View.OnClickListener, CompoundButton.OnCheckedChangeListener {
@ -156,11 +156,11 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
LinearLayoutManager llm;
LinearLayout acceptTempLayout;
Button treatmentButton;
Button wizardButton;
Button calibrationButton;
Button acceptTempButton;
Button quickWizardButton;
SingleClickButton treatmentButton;
SingleClickButton wizardButton;
SingleClickButton calibrationButton;
SingleClickButton acceptTempButton;
SingleClickButton quickWizardButton;
CheckBox lockScreen;
@ -244,16 +244,16 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
bgGraph = (GraphView) view.findViewById(R.id.overview_bggraph);
iobGraph = (GraphView) view.findViewById(R.id.overview_iobgraph);
treatmentButton = (Button) view.findViewById(R.id.overview_treatmentbutton);
treatmentButton = (SingleClickButton) view.findViewById(R.id.overview_treatmentbutton);
treatmentButton.setOnClickListener(this);
wizardButton = (Button) view.findViewById(R.id.overview_wizardbutton);
wizardButton = (SingleClickButton) view.findViewById(R.id.overview_wizardbutton);
wizardButton.setOnClickListener(this);
acceptTempButton = (Button) view.findViewById(R.id.overview_accepttempbutton);
acceptTempButton = (SingleClickButton) view.findViewById(R.id.overview_accepttempbutton);
if (acceptTempButton != null)
acceptTempButton.setOnClickListener(this);
quickWizardButton = (Button) view.findViewById(R.id.overview_quickwizardbutton);
quickWizardButton = (SingleClickButton) view.findViewById(R.id.overview_quickwizardbutton);
quickWizardButton.setOnClickListener(this);
calibrationButton = (Button) view.findViewById(R.id.overview_calibrationbutton);
calibrationButton = (SingleClickButton) view.findViewById(R.id.overview_calibrationbutton);
if (calibrationButton != null)
calibrationButton.setOnClickListener(this);
@ -320,6 +320,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
return view;
} catch (Exception e) {
Crashlytics.logException(e);
log.debug("Runtime Exception", e);
}
return null;

View file

@ -0,0 +1,67 @@
package info.nightscout.utils;
import android.app.Activity;
import android.content.Context;
import android.os.SystemClock;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Created by mike on 22.12.2017.
*/
public class SingleClickButton extends android.support.v7.widget.AppCompatButton implements View.OnClickListener {
private static Logger log = LoggerFactory.getLogger(SingleClickButton.class);
Context context;
OnClickListener listener = null;
public SingleClickButton(Context context) {
super(context);
this.context = context;
super.setOnClickListener(this);
}
public SingleClickButton(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
super.setOnClickListener(this);
}
public SingleClickButton(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
this.context = context;
super.setOnClickListener(this);
}
@Override
public void setOnClickListener(@Nullable OnClickListener l) {
listener = l;
}
@Override
public void onClick(final View v) {
setEnabled(false);
new Thread(new Runnable() {
@Override
public void run() {
SystemClock.sleep(3000);
Activity activity = (Activity) context;
if (activity != null)
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
setEnabled(true);
log.debug("Button enabled");
}
});
}
}).start();
if (listener != null)
listener.onClick(v);
}
}

View file

@ -13,7 +13,7 @@
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/actions_profileswitch"
style="?android:attr/buttonStyle"
android:layout_width="fill_parent"
@ -26,7 +26,7 @@
android:drawableTop="@drawable/icon_actions_profileswitch"
android:text="@string/careportal_profileswitch" />
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/actions_temptarget"
style="?android:attr/buttonStyle"
android:layout_width="fill_parent"
@ -39,7 +39,7 @@
android:drawableTop="@drawable/icon_actions_temptarget"
android:text="@string/careportal_temporarytarget" />
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/actions_settempbasal"
style="?android:attr/buttonStyle"
android:layout_width="fill_parent"
@ -52,7 +52,7 @@
android:drawableTop="@drawable/icon_actions_starttempbasal"
android:text="@string/overview_tempbasal_button" />
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/actions_canceltempbasal"
style="?android:attr/buttonStyle"
android:layout_width="fill_parent"
@ -65,7 +65,7 @@
android:drawableTop="@drawable/icon_cancelbasal"
android:text="Cancel temp basal" />
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/actions_extendedbolus"
style="?android:attr/buttonStyle"
android:layout_width="fill_parent"
@ -78,7 +78,7 @@
android:drawableTop="@drawable/icon_actions_startextbolus"
android:text="@string/overview_extendedbolus_button" />
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/actions_extendedbolus_cancel"
style="?android:attr/buttonStyle"
android:layout_width="fill_parent"
@ -91,7 +91,7 @@
android:drawableTop="@drawable/icon_actions_cancelextbolus"
android:text="@string/overview_extendedbolus_cancel_button" />
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/actions_fill"
style="?android:attr/buttonStyle"
android:layout_width="fill_parent"

View file

@ -51,7 +51,7 @@
android:padding="10dip"
app:columnCount="3">
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/careportal_bgcheck"
style="@style/ButtonSmallFontStyle"
android:layout_width="0px"
@ -66,7 +66,7 @@
app:layout_gravity="fill"
app:layout_row="0" />
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/careportal_exercise"
style="@style/ButtonSmallFontStyle"
android:layout_width="0dp"
@ -80,7 +80,7 @@
app:layout_gravity="fill"
app:layout_row="0" />
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/careportal_temporarytarget"
style="@style/ButtonSmallFontStyle"
android:layout_width="0dp"
@ -111,7 +111,7 @@
android:padding="10dip"
app:columnCount="3">
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/careportal_snackbolus"
style="@style/ButtonSmallFontStyle"
android:layout_width="0dp"
@ -125,7 +125,7 @@
app:layout_gravity="fill"
app:layout_row="1" />
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/careportal_mealbolus"
style="@style/ButtonSmallFontStyle"
android:layout_width="0dp"
@ -139,7 +139,7 @@
app:layout_gravity="fill"
app:layout_row="1" />
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/careportal_correctionbolus"
style="@style/ButtonSmallFontStyle"
android:layout_width="0dp"
@ -153,7 +153,7 @@
app:layout_gravity="fill"
app:layout_row="1" />
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/careportal_carbscorrection"
style="@style/ButtonSmallFontStyle"
android:layout_width="0dp"
@ -167,7 +167,7 @@
app:layout_gravity="fill"
app:layout_row="2" />
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/careportal_combobolus"
style="@style/ButtonSmallFontStyle"
android:layout_width="0dp"
@ -181,7 +181,7 @@
app:layout_gravity="fill"
app:layout_row="2" />
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/careportal_tempbasalstart"
style="@style/ButtonSmallFontStyle"
android:layout_width="0dp"
@ -195,7 +195,7 @@
app:layout_gravity="fill"
app:layout_row="2" />
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/careportal_tempbasalend"
style="@style/ButtonSmallFontStyle"
android:layout_width="0dp"
@ -225,7 +225,7 @@
android:padding="10dip"
app:columnCount="3">
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/careportal_cgmsensorstart"
style="@style/ButtonSmallFontStyle"
android:layout_width="0dp"
@ -240,7 +240,7 @@
app:layout_row="1" />
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/careportal_cgmsensorinsert"
style="@style/ButtonSmallFontStyle"
android:layout_width="0dp"
@ -255,7 +255,7 @@
app:layout_row="1" />
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/careportal_openapsoffline"
style="@style/ButtonSmallFontStyle"
android:layout_width="0dp"
@ -270,7 +270,7 @@
app:layout_row="1" />
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/careportal_announcement"
style="@style/ButtonSmallFontStyle"
android:layout_width="0dp"
@ -284,7 +284,7 @@
app:layout_gravity="fill"
app:layout_row="4" />
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/careportal_question"
style="@style/ButtonSmallFontStyle"
android:layout_width="0dp"
@ -298,7 +298,7 @@
app:layout_gravity="fill"
app:layout_row="4" />
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/careportal_note"
style="@style/ButtonSmallFontStyle"
android:layout_width="0dp"
@ -328,7 +328,7 @@
android:padding="10dip"
app:columnCount="3">
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/careportal_pumpsitechange"
style="@style/ButtonSmallFontStyle"
android:layout_width="0dp"
@ -342,7 +342,7 @@
app:layout_gravity="fill"
app:layout_row="0" />
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/careportal_insulincartridgechange"
style="@style/ButtonSmallFontStyle"
android:layout_width="0dp"
@ -356,7 +356,7 @@
app:layout_gravity="fill"
app:layout_row="0" />
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/careportal_profileswitch"
style="@style/ButtonSmallFontStyle"
android:layout_width="0dp"
@ -371,7 +371,7 @@
app:layout_row="0" />
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/careportal_pumpbatterychange"
style="@style/ButtonSmallFontStyle"
android:layout_width="0dp"

View file

@ -381,7 +381,7 @@
android:orientation="horizontal"
android:visibility="gone">
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/overview_accepttempbutton"
style="?android:attr/buttonStyle"
android:layout_width="match_parent"
@ -398,7 +398,7 @@
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/overview_treatmentbutton"
style="?android:attr/buttonStyle"
android:layout_width="0px"
@ -413,7 +413,7 @@
android:textSize="10sp"
android:visibility="gone" />
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/overview_wizardbutton"
style="?android:attr/buttonStyle"
android:layout_width="0px"
@ -428,7 +428,7 @@
android:textSize="10sp"
android:visibility="gone" />
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/overview_calibrationbutton"
style="?android:attr/buttonStyle"
android:layout_width="0px"
@ -443,7 +443,7 @@
android:textSize="10sp"
android:visibility="gone" />
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/overview_quickwizardbutton"
style="?android:attr/buttonStyle"
android:layout_width="0px"

View file

@ -593,7 +593,7 @@
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/overview_treatmentbutton"
style="?android:attr/buttonStyle"
android:layout_width="0px"
@ -607,7 +607,7 @@
android:textColor="@color/colorTreatmentButton"
android:textSize="10sp" />
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/overview_wizardbutton"
style="?android:attr/buttonStyle"
android:layout_width="0px"
@ -622,7 +622,7 @@
android:textSize="10sp"
android:visibility="gone" />
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/overview_quickwizardbutton"
style="?android:attr/buttonStyle"
android:layout_width="0px"

View file

@ -691,7 +691,7 @@
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/overview_treatmentbutton"
style="?android:attr/buttonStyle"
android:layout_width="0px"
@ -705,7 +705,7 @@
android:textColor="@color/colorTreatmentButton"
android:textSize="10sp" />
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/overview_wizardbutton"
style="?android:attr/buttonStyle"
android:layout_width="0px"
@ -720,7 +720,7 @@
android:textSize="10sp"
android:visibility="gone" />
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/overview_calibrationbutton"
style="?android:attr/buttonStyle"
android:layout_width="0px"
@ -735,7 +735,7 @@
android:textSize="10sp"
android:visibility="gone" />
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/overview_quickwizardbutton"
style="?android:attr/buttonStyle"
android:layout_width="0px"

View file

@ -377,7 +377,7 @@
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/overview_treatmentbutton"
style="?android:attr/buttonStyle"
android:layout_width="0px"
@ -391,7 +391,7 @@
android:textColor="@color/colorTreatmentButton"
android:textSize="10sp" />
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/overview_wizardbutton"
style="?android:attr/buttonStyle"
android:layout_width="0px"
@ -406,7 +406,7 @@
android:textSize="10sp"
android:visibility="gone" />
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/overview_calibrationbutton"
style="?android:attr/buttonStyle"
android:layout_width="0px"
@ -421,7 +421,7 @@
android:textSize="10sp"
android:visibility="gone" />
<Button
<info.nightscout.utils.SingleClickButton
android:id="@+id/overview_quickwizardbutton"
style="?android:attr/buttonStyle"
android:layout_width="0px"

View file

@ -8,6 +8,14 @@
android:orientation="vertical"
android:padding="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingBottom="10dp"
android:text="@string/virtualpump_extendedbolus_label"
android:textAppearance="?android:attr/textAppearanceLarge" />
<LinearLayout
android:id="@+id/careportal_newnstreatment_insulin_layout"
android:layout_width="match_parent"