allow lock screen in nsclient mode

This commit is contained in:
Milos Kozak 2017-07-03 00:02:54 +02:00
parent e0e0a75519
commit 5a27f9afa1
6 changed files with 121 additions and 9 deletions

View file

@ -23,6 +23,7 @@ import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageButton; import android.widget.ImageButton;
@ -40,6 +41,7 @@ import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.events.EventRefreshGui; import info.nightscout.androidaps.events.EventRefreshGui;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; 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.SlidingTabLayout;
import info.nightscout.androidaps.tabs.TabPageAdapter; import info.nightscout.androidaps.tabs.TabPageAdapter;
import info.nightscout.utils.ImportExportPrefs; import info.nightscout.utils.ImportExportPrefs;
@ -60,6 +62,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
ImageButton menuButton; ImageButton menuButton;
protected PowerManager.WakeLock mWakeLock;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -79,10 +82,24 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
if (Config.logFunctionCalls) if (Config.logFunctionCalls)
log.debug("onCreate"); log.debug("onCreate");
onStatusEvent(new EventSetWakeLock(SP.getBoolean("lockscreen", false)));
registerBus(); registerBus();
setUpTabs(false); 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 @Subscribe
public void onStatusEvent(final EventRefreshGui ev) { public void onStatusEvent(final EventRefreshGui ev) {
String lang = SP.getString("language", "en"); String lang = SP.getString("language", "en");
@ -96,6 +113,11 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
e.printStackTrace(); 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(); askForSMSPermissions();
} }
@Override
public void onDestroy() {
if (mWakeLock != null)
mWakeLock.release();
super.onDestroy();
}
private void askForBatteryOptimizationPermission() { private void askForBatteryOptimizationPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
final String packageName = getPackageName(); final String packageName = getPackageName();

View file

@ -31,6 +31,7 @@ import android.widget.CheckBox;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.ToggleButton;
import com.crashlytics.android.answers.Answers; import com.crashlytics.android.answers.Answers;
import com.crashlytics.android.answers.CustomEvent; import com.crashlytics.android.answers.CustomEvent;
@ -63,6 +64,7 @@ import java.util.concurrent.TimeUnit;
import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.BuildConfig;
import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainActivity;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.broadcasts.NSClearAlarmBroadcast; 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.EventInitializationChanged;
import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.events.EventPumpStatusChanged; import info.nightscout.androidaps.events.EventPumpStatusChanged;
import info.nightscout.androidaps.events.EventRefreshGui;
import info.nightscout.androidaps.events.EventRefreshOverview; import info.nightscout.androidaps.events.EventRefreshOverview;
import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.events.EventTempTargetChange; 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.NewTreatmentDialog;
import info.nightscout.androidaps.plugins.Overview.Dialogs.WizardDialog; import info.nightscout.androidaps.plugins.Overview.Dialogs.WizardDialog;
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; 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.AreaGraphSeries;
import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface; import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface;
import info.nightscout.androidaps.plugins.Overview.graphExtensions.DoubleDataPoint; import info.nightscout.androidaps.plugins.Overview.graphExtensions.DoubleDataPoint;
@ -181,6 +185,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
Button acceptTempButton; Button acceptTempButton;
Button quickWizardButton; Button quickWizardButton;
CheckBox lockScreen;
boolean smallWidth; boolean smallWidth;
boolean smallHeight; 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; return view;
} }

View file

@ -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;
}
}

View file

@ -138,17 +138,30 @@
</LinearLayout> </LinearLayout>
<TextView <LinearLayout
android:id="@+id/overview_time"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="fill_vertical" android:orientation="vertical">
android:layout_marginTop="10dp"
android:maxWidth="150dp" <TextView
android:paddingLeft="10dp" android:id="@+id/overview_time"
android:text="8:00 PM" android:layout_width="wrap_content"
android:textSize="30sp" android:layout_height="wrap_content"
android:textStyle="bold" /> android:layout_gravity="fill_vertical"
android:layout_marginTop="10dp"
android:maxWidth="150dp"
android:paddingLeft="10dp"
android:text="8:00 PM"
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>

View file

@ -152,6 +152,14 @@
android:layout_marginLeft="10dp" android:layout_marginLeft="10dp"
android:textAppearance="?android:attr/textAppearanceSmall" /> 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> </LinearLayout>
<TextView <TextView
@ -718,6 +726,21 @@
android:textSize="10sp" android:textSize="10sp"
android:visibility="gone" /> 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 <Button
android:id="@+id/overview_quickwizardbutton" android:id="@+id/overview_quickwizardbutton"
style="?android:attr/buttonStyle" style="?android:attr/buttonStyle"
@ -733,6 +756,20 @@
android:textSize="10sp" android:textSize="10sp"
android:visibility="gone" /> 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>
</LinearLayout> </LinearLayout>

View file

@ -674,4 +674,6 @@
<string name="uploader_short">UPLD</string> <string name="uploader_short">UPLD</string>
<string name="basal_short">BAS</string> <string name="basal_short">BAS</string>
<string name="virtualpump_extendedbolus_label_short">EXT</string> <string name="virtualpump_extendedbolus_label_short">EXT</string>
<string name="lock_screen">Lock screen</string>
<string name="lock_screen_short">Lock</string>
</resources> </resources>