allow lock screen in nsclient mode
This commit is contained in:
parent
e0e0a75519
commit
5a27f9afa1
|
@ -23,6 +23,7 @@ import android.view.MenuInflater;
|
|||
import android.view.MenuItem;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageButton;
|
||||
|
@ -40,6 +41,7 @@ import info.nightscout.androidaps.events.EventPreferenceChange;
|
|||
import info.nightscout.androidaps.events.EventRefreshGui;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.Overview.events.EventSetWakeLock;
|
||||
import info.nightscout.androidaps.tabs.SlidingTabLayout;
|
||||
import info.nightscout.androidaps.tabs.TabPageAdapter;
|
||||
import info.nightscout.utils.ImportExportPrefs;
|
||||
|
@ -60,6 +62,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
|||
|
||||
ImageButton menuButton;
|
||||
|
||||
protected PowerManager.WakeLock mWakeLock;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -79,10 +82,24 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
|||
if (Config.logFunctionCalls)
|
||||
log.debug("onCreate");
|
||||
|
||||
onStatusEvent(new EventSetWakeLock(SP.getBoolean("lockscreen", false)));
|
||||
|
||||
registerBus();
|
||||
setUpTabs(false);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventSetWakeLock ev) {
|
||||
final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
||||
if (ev.lock) {
|
||||
mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "AAPS");
|
||||
mWakeLock.acquire();
|
||||
} else {
|
||||
if (mWakeLock != null)
|
||||
mWakeLock.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventRefreshGui ev) {
|
||||
String lang = SP.getString("language", "en");
|
||||
|
@ -96,6 +113,11 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
|||
} catch (IllegalStateException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
boolean lockScreen = BuildConfig.NSCLIENTOLNY && SP.getBoolean("lockscreen", false);
|
||||
if (lockScreen)
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
else
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -156,6 +178,13 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
|||
askForSMSPermissions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
if (mWakeLock != null)
|
||||
mWakeLock.release();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
private void askForBatteryOptimizationPermission() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
final String packageName = getPackageName();
|
||||
|
|
|
@ -31,6 +31,7 @@ import android.widget.CheckBox;
|
|||
import android.widget.CompoundButton;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.ToggleButton;
|
||||
|
||||
import com.crashlytics.android.answers.Answers;
|
||||
import com.crashlytics.android.answers.CustomEvent;
|
||||
|
@ -63,6 +64,7 @@ import java.util.concurrent.TimeUnit;
|
|||
import info.nightscout.androidaps.BuildConfig;
|
||||
import info.nightscout.androidaps.Config;
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainActivity;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.broadcasts.NSClearAlarmBroadcast;
|
||||
|
@ -85,6 +87,7 @@ import info.nightscout.androidaps.events.EventExtendedBolusChange;
|
|||
import info.nightscout.androidaps.events.EventInitializationChanged;
|
||||
import info.nightscout.androidaps.events.EventPreferenceChange;
|
||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||
import info.nightscout.androidaps.events.EventRefreshGui;
|
||||
import info.nightscout.androidaps.events.EventRefreshOverview;
|
||||
import info.nightscout.androidaps.events.EventTempBasalChange;
|
||||
import info.nightscout.androidaps.events.EventTempTargetChange;
|
||||
|
@ -108,6 +111,7 @@ import info.nightscout.androidaps.plugins.Overview.Dialogs.CalibrationDialog;
|
|||
import info.nightscout.androidaps.plugins.Overview.Dialogs.NewTreatmentDialog;
|
||||
import info.nightscout.androidaps.plugins.Overview.Dialogs.WizardDialog;
|
||||
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
||||
import info.nightscout.androidaps.plugins.Overview.events.EventSetWakeLock;
|
||||
import info.nightscout.androidaps.plugins.Overview.graphExtensions.AreaGraphSeries;
|
||||
import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface;
|
||||
import info.nightscout.androidaps.plugins.Overview.graphExtensions.DoubleDataPoint;
|
||||
|
@ -181,6 +185,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
Button acceptTempButton;
|
||||
Button quickWizardButton;
|
||||
|
||||
CheckBox lockScreen;
|
||||
|
||||
boolean smallWidth;
|
||||
boolean smallHeight;
|
||||
|
||||
|
@ -330,6 +336,18 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
}
|
||||
});
|
||||
|
||||
lockScreen = (CheckBox) view.findViewById(R.id.overview_lockscreen);
|
||||
if (lockScreen != null) {
|
||||
lockScreen.setChecked(SP.getBoolean("lockscreen", false));
|
||||
lockScreen.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
SP.putBoolean("lockscreen", isChecked);
|
||||
MainApp.bus().post(new EventSetWakeLock(isChecked));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package info.nightscout.androidaps.plugins.Overview.events;
|
||||
|
||||
/**
|
||||
* Created by mike on 02.07.2017.
|
||||
*/
|
||||
|
||||
public class EventSetWakeLock {
|
||||
public boolean lock = false;
|
||||
|
||||
public EventSetWakeLock(boolean val) {
|
||||
lock = val;
|
||||
}
|
||||
}
|
|
@ -138,6 +138,11 @@
|
|||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/overview_time"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -150,6 +155,14 @@
|
|||
android:textSize="30sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/overview_lockscreen"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/lock_screen_short"
|
||||
android:textAlignment="center" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
|
|
|
@ -152,6 +152,14 @@
|
|||
android:layout_marginLeft="10dp"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/overview_lockscreen"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0.5"
|
||||
android:text="@string/lock_screen"
|
||||
android:textAlignment="center" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
|
@ -718,6 +726,21 @@
|
|||
android:textSize="10sp"
|
||||
android:visibility="gone" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/overview_calibrationbutton"
|
||||
style="?android:attr/buttonStyle"
|
||||
android:layout_width="0px"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_marginRight="-4dp"
|
||||
android:layout_weight="0.5"
|
||||
android:drawableTop="@drawable/icon_calibration"
|
||||
android:paddingLeft="0dp"
|
||||
android:paddingRight="0dp"
|
||||
android:text="@string/overview_calibration"
|
||||
android:textColor="@color/colorCalibrationButton"
|
||||
android:textSize="10sp"
|
||||
android:visibility="gone" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/overview_quickwizardbutton"
|
||||
style="?android:attr/buttonStyle"
|
||||
|
@ -733,6 +756,20 @@
|
|||
android:textSize="10sp"
|
||||
android:visibility="gone" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/overview_canceltempbutton"
|
||||
style="?android:attr/buttonStyle"
|
||||
android:layout_width="0px"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_weight="0.5"
|
||||
android:drawableTop="@drawable/icon_cancelbasal"
|
||||
android:paddingLeft="0dp"
|
||||
android:paddingRight="0dp"
|
||||
android:text="Cancel temp basal"
|
||||
android:textColor="@color/colorCancelTempButton"
|
||||
android:textSize="10sp"
|
||||
android:visibility="gone" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -674,4 +674,6 @@
|
|||
<string name="uploader_short">UPLD</string>
|
||||
<string name="basal_short">BAS</string>
|
||||
<string name="virtualpump_extendedbolus_label_short">EXT</string>
|
||||
<string name="lock_screen">Lock screen</string>
|
||||
<string name="lock_screen_short">Lock</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue