This commit is contained in:
Nazar 2019-06-11 20:00:42 +03:00
parent 18ae10380f
commit 1655c6a7c9
53 changed files with 810 additions and 269 deletions

View file

@ -38,6 +38,7 @@ dependencies {
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:cardview-v7:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

View file

@ -13,9 +13,12 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".AdminDevicePermissionSetUpActivity"
android:theme="@style/AppTheme.NoActionBar"></activity>
<activity android:name=".MainActivity"
<activity android:name=".PluginDescriptionActivity"></activity>
<activity
android:name=".PermissionsSetUpActivity"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".MainActivity"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

View file

@ -1,86 +1,150 @@
package net.osmand.turn_screen_on;
import android.content.Intent;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.SwitchCompat;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.ScrollView;
import android.widget.Spinner;
import android.widget.TextView;
import net.osmand.turn_screen_on.helpers.LockHelper;
import net.osmand.turn_screen_on.helpers.AndroidUtils;
import net.osmand.turn_screen_on.helpers.OsmAndAidlHelper;
import java.util.ArrayList;
import java.util.List;
import static android.view.View.LAYER_TYPE_HARDWARE;
public class MainActivity extends AppCompatActivity {
private FrameLayout flRootLayout;
private LinearLayout llMainScreen;
private Toolbar tbPluginToolbar;
private FrameLayout btnOpenOsmand;
private SwitchCompat swFunctionSwitcher;
private SwitchCompat swPluginEnableSwitcher;
private SwitchCompat swSensorEnableSwitcher;
private TextView tvPluginStateDescription;
private Spinner spTime;
private LinearLayout llPluginPreferencesLayout;
private LinearLayout llOsmandVersions;
//todo delete
private Button btnRegister;
private List<PluginSettings.OsmandVersion> availableOsmandVersions;
private static int[] timeBySeconds = {5, 10, 15};
private Paint pGreyScale;
private OsmAndAidlHelper osmAndAidlHelper;
private PluginSettings settings;
private PluginState pluginState;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
private LayoutInflater inflater;
osmAndAidlHelper = OsmAndAidlHelper.getInstance();
settings = PluginSettings.getInstance();
interface PluginState {
void createUI();
tbPluginToolbar = findViewById(R.id.tbPluginToolbar);
btnOpenOsmand = findViewById(R.id.btnOpenOsmand);
swFunctionSwitcher = findViewById(R.id.swFunctionSwitcher);
void refreshUI();
}
private PluginState NO_INSTALLED_OSMAND_STATE = new PluginState() {
@Override
public void createUI() {
llMainScreen.addView(inflater.inflate(R.layout.main_el_plugin_switcher, null, false));
llMainScreen.addView(inflater.inflate(R.layout.main_install_desc, null, false));
flRootLayout.addView(llMainScreen);
llPluginPreferencesLayout = findViewById(R.id.llPluginPreferencesLayout);
swPluginEnableSwitcher = findViewById(R.id.swPluginEnableSwitcher);
tvPluginStateDescription = findViewById(R.id.tvPluginStateDescription);
}
@Override
public void refreshUI() {
swPluginEnableSwitcher.setChecked(false);
tvPluginStateDescription.setText(R.string.disabled);
swPluginEnableSwitcher.setEnabled(false);
}
};
private PluginState PLUGIN_PREFERENCE_STATE = new PluginState() {
@Override
public void createUI() {
//add interface elements
llMainScreen.addView(inflater.inflate(R.layout.main_el_plugin_switcher, null, false));
llMainScreen.addView(inflater.inflate(R.layout.main_el_time_set_up, null, false));
llMainScreen.addView(inflater.inflate(R.layout.main_el_sensor, null, false));
View btnOpenOsmandLayout = inflater.inflate(R.layout.main_el_btn_open_osmand, null, false);
flRootLayout.addView(btnOpenOsmandLayout);
llMainScreen.setPadding(0, 0, 0, AndroidUtils.dpToPx(getApplicationContext(), 82));
ScrollView sv = new ScrollView(MainActivity.this);
sv.addView(llMainScreen);
//getting control elements
flRootLayout.addView(sv);
llPluginPreferencesLayout = findViewById(R.id.llPluginPreferencesLayout);
swPluginEnableSwitcher = findViewById(R.id.swPluginEnableSwitcher);
tvPluginStateDescription = findViewById(R.id.tvPluginStateDescription);
btnOpenOsmand = findViewById(R.id.btnOpenOsmand);
spTime = findViewById(R.id.spTime);
swSensorEnableSwitcher = findViewById(R.id.swSensorEnableSwitcher);
if (availableOsmandVersions.size() > 1) {
llMainScreen.addView(inflater.inflate(R.layout.main_el_osmand_versions, null, false));
llOsmandVersions = findViewById(R.id.llOsmandVersions);
createVersionUI();
}
btnOpenOsmand.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
osmAndAidlHelper.show();
Intent launchIntent = getPackageManager().getLaunchIntentForPackage(settings.getOsmandVersion().getPath());
if (launchIntent != null) {
startActivity(launchIntent);
}
}
});
swFunctionSwitcher.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
swPluginEnableSwitcher.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
Intent intent = new Intent(MainActivity.this, AdminDevicePermissionSetUpActivity.class);
if (!settings.isPermissionAvailable()) {
Intent intent = new Intent(MainActivity.this, PermissionsSetUpActivity.class);
startActivity(intent);
} else {
settings.enablePlugin();
}
} else {
settings.disablePlugin();
}
refreshView();
refreshUI();
}
});
List<String> spinnerArray = new ArrayList<>();
for (int t : timeBySeconds) {
spinnerArray.add(new StringBuilder().append(t).append(" ")
.append(getString(R.string.secondsShort)).toString());
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
MainActivity.this,
android.R.layout.simple_spinner_item,
spinnerArray
settings.getUnlockTimeDescriptionList()
);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
@ -89,10 +153,7 @@ public class MainActivity extends AppCompatActivity {
spTime.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent,
View itemSelected, int selectedItemPosition, long selectedId) {
int time = timeBySeconds[selectedItemPosition];
settings.setTimeLikeSeconds(time);
settings.setTimePosition(selectedItemPosition);
settings.setTimeModePosition(selectedItemPosition);
}
public void onNothingSelected(AdapterView<?> parent) {
@ -100,60 +161,171 @@ public class MainActivity extends AppCompatActivity {
}
});
//todo delete
btnRegister = findViewById(R.id.btnRegister);
/*btnRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (settings.isPluginEnabled()) {
Handler handler = new Handler();
final LockHelper lockHelper = new LockHelper(MainActivity.this);
lockHelper.lock();
handler.postDelayed(new Runnable() {
@Override
public void run() {
lockHelper.timedUnlock(5000);
btnOpenOsmandLayout.bringToFront();
}
}, 5000);
}
}
});*/
btnRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
public void refreshUI() {
boolean isPluginEnabled = settings.isPluginEnabled();
if (isPluginEnabled) {
setStatusBarColor(R.color.orange);
osmAndAidlHelper.register();
tvPluginStateDescription.setText(getString(R.string.enabled));
tvPluginStateDescription.setTextColor(getResources().getColor(R.color.black));
tbPluginToolbar.setBackgroundColor(getResources().getColor(R.color.orange));
llPluginPreferencesLayout.setLayerType(LAYER_TYPE_HARDWARE, null);
setEnableForElements(true);
} else {
setStatusBarColor(R.color.darkGrey);
// osmAndAidlHelper.unregister();
tvPluginStateDescription.setText(getString(R.string.disabled));
tvPluginStateDescription.setTextColor(getResources().getColor(R.color.darkGrey));
tbPluginToolbar.setBackgroundColor(getResources().getColor(R.color.darkGrey));
llPluginPreferencesLayout.setLayerType(LAYER_TYPE_HARDWARE, pGreyScale);
setEnableForElements(false);
}
swPluginEnableSwitcher.setChecked(isPluginEnabled);
int timePosition = settings.getTimeModePosition();
spTime.setSelection(timePosition);
PluginSettings.OsmandVersion version = settings.getOsmandVersion();
int checkedId = version.getId();
RadioButton checkedVersion = findViewById(checkedId);
if (checkedVersion != null) {
checkedVersion.setChecked(true);
}
}
public void createVersionUI() {
for (PluginSettings.OsmandVersion version : availableOsmandVersions) {
ViewGroup container = (ViewGroup) inflater
.inflate(R.layout.osmand_version_item, null, false);
container.setMinimumHeight(52);
ImageView ivVersionImg = container.findViewById(R.id.ivVersionImg);
ivVersionImg.setImageResource(version.getImgResId());
TextView tvVersionName = container.findViewById(R.id.tvVersionName);
tvVersionName.setText(getString(version.getNameId()));
RadioButton rbVersionCheckButton = container.findViewById(R.id.rbVersion);
rbVersionCheckButton.setId(version.getId());
rbVersionCheckButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int id = v.getId();
settings.setOsmandVersion(id);
for (PluginSettings.OsmandVersion version : availableOsmandVersions) {
if (id != version.getId()) {
RadioButton rbCurrent = findViewById(version.getId());
rbCurrent.setChecked(false);
}
}
}
});
llOsmandVersions.addView(container);
}
}
private void setEnableForElements(boolean enable) {
swSensorEnableSwitcher.setEnabled(enable);
for (PluginSettings.OsmandVersion version : availableOsmandVersions) {
RadioButton rb = findViewById(version.getId());
if (rb!=null) {
rb.setEnabled(enable);
}
}
spTime.setEnabled(enable);
btnOpenOsmand.setEnabled(enable);
//todo delete
osmAndAidlHelper.connect(settings.getOsmandVersion().getPath());
}
};
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
osmAndAidlHelper = OsmAndAidlHelper.getInstance();
settings = PluginSettings.getInstance();
inflater = getLayoutInflater();
availableOsmandVersions = PluginSettings.OsmandVersion.getOnlyInstalledVersions();
if (availableOsmandVersions == null || availableOsmandVersions.size() == 0) {
pluginState = NO_INSTALLED_OSMAND_STATE;
} else {
pluginState = PLUGIN_PREFERENCE_STATE;
}
createUI();
}
public void createUI() {
//grey filter preparation
ColorMatrix cm = new ColorMatrix();
cm.setSaturation(0);
pGreyScale = new Paint();
pGreyScale.setColorFilter(new ColorMatrixColorFilter(cm));
flRootLayout = findViewById(R.id.flRootLayout);
llMainScreen = new LinearLayout(this);
llMainScreen.setOrientation(LinearLayout.VERTICAL);
llMainScreen.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup
.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
tbPluginToolbar = findViewById(R.id.tbPluginToolbar);
setSupportActionBar(tbPluginToolbar);
pluginState.createUI();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_help) {
Intent intent = new Intent(MainActivity.this, PluginDescriptionActivity.class);
startActivity(intent);
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
protected void onResume() {
super.onResume();
refreshView();
refreshUI();
}
public void refreshView() {
//set up status bar color
public void refreshUI() {
pluginState.refreshUI();
}
private void setStatusBarColor(int colorResId) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (settings.isPluginEnabled()) {
getWindow().setStatusBarColor(ContextCompat.getColor(this, R.color.orange));
} else {
getWindow().setStatusBarColor(ContextCompat.getColor(this, R.color.darkGrey));
getWindow().setStatusBarColor(ContextCompat.getColor(this, colorResId));
}
}
boolean isPluginEnabled = settings.isPluginEnabled();
if (isPluginEnabled) {
tvPluginStateDescription.setText(getString(R.string.enabled));
tbPluginToolbar.setBackgroundColor(getResources().getColor(R.color.orange));
} else {
tvPluginStateDescription.setText(getString(R.string.disabled));
tbPluginToolbar.setBackgroundColor(getResources().getColor(R.color.darkGrey));
}
swFunctionSwitcher.setChecked(isPluginEnabled);
int timePosition = settings.getTimePosition();
spTime.setSelection(timePosition);
}
}

View file

@ -3,15 +3,16 @@ package net.osmand.turn_screen_on;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Intent;
import android.preference.Preference;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;
import net.osmand.turn_screen_on.receiver.DeviceAdminRecv;
public class AdminDevicePermissionSetUpActivity extends AppCompatActivity
implements Preference.OnPreferenceChangeListener, Preference.OnPreferenceClickListener {
public class PermissionsSetUpActivity extends AppCompatActivity {
private FrameLayout btnContinue;
private ComponentName mDeviceAdmin;
private PluginSettings settings;
private static final int DEVICE_ADMIN_REQUEST = 5;
@ -23,17 +24,16 @@ public class AdminDevicePermissionSetUpActivity extends AppCompatActivity
settings = PluginSettings.getInstance();
DevicePolicyManager mDevicePolicyManager = (DevicePolicyManager) getSystemService(DEVICE_POLICY_SERVICE);
mDeviceAdmin = new ComponentName(getApplicationContext(),
DeviceAdminRecv.class);
mDeviceAdmin = new ComponentName(getApplicationContext(), DeviceAdminRecv.class);
if (mDevicePolicyManager.isAdminActive(mDeviceAdmin)) {
settings.enablePlugin();
} else {
btnContinue = findViewById(R.id.btnContinue);
btnContinue.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
requestLockScreenAdmin();
onBackPressed();
}
super.onBackPressed();
});
}
@Override
@ -65,28 +65,4 @@ public class AdminDevicePermissionSetUpActivity extends AppCompatActivity
""));
startActivityForResult(intent, DEVICE_ADMIN_REQUEST);
}
//TODO CHANGE_PREFERENCE
//TODO WAKE_ON_VOICE
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
String id = preference.getKey();
// if (id.equals(settings.WAKE_ON_VOICE_INT.getId())) {
// Integer value;
// try {
// value = Integer.parseInt(newValue.toString());
// } catch (NumberFormatException e) {
// value = 0;
// }
// if (value > 0) {
// requestLockScreenAdmin();
// }
// }
return true;
}
@Override
public boolean onPreferenceClick(Preference preference) {
return false;
}
}

View file

@ -0,0 +1,25 @@
package net.osmand.turn_screen_on;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;
public class PluginDescriptionActivity extends AppCompatActivity {
private FrameLayout btnContinue;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_plugin_description);
btnContinue = findViewById(R.id.btnContinue);
btnContinue.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onBackPressed();
}
});
}
}

View file

@ -1,22 +1,100 @@
package net.osmand.turn_screen_on;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.preference.PreferenceManager;
import net.osmand.turn_screen_on.app.TurnScreenOnApplication;
import net.osmand.turn_screen_on.helpers.OsmAndAidlHelper;
import net.osmand.turn_screen_on.receiver.DeviceAdminRecv;
import java.util.ArrayList;
import java.util.List;
public class PluginSettings {
private SharedPreferences preferences;
private static final String APP_PREFERENCE = "TurnScreenOnPreferences";
private static final String PREFERENCE_ENABLE = "enable";
private static final String PREFERENCE_TIME = "timeSeconds";
private static final String PREFERENCE_TIME_INDEX = "timeId";
private static final String PREFERENCE_OSMAND_VERSION = "OsmandVersionInt";
private final static Context context = TurnScreenOnApplication.getAppContext();
public enum OsmandVersion {
OSMAND_PLUS(132356, R.string.OsmandPlus, R.drawable.ic_action_osmand_plus, "net.osmand.plus"),
OSMAND(132357, R.string.Osmand, R.drawable.ic_action_osmand, "net.osmand");
int id;
int nameId;
int imgId;
String path;
OsmandVersion(int id, int nameId, int imgId, String path) {
this.id = id;
this.nameId = nameId;
this.imgId = imgId;
this.path = path;
}
public int getId() {
return id;
}
public int getNameId() {
return nameId;
}
public int getImgResId() {
return imgId;
}
public String getPath() {
return path;
}
public static OsmandVersion getVersionById(int id) {
for (OsmandVersion v : OsmandVersion.values()) {
if (v.getId() == id) {
return v;
}
}
return OSMAND;
}
public static boolean isVersionInstalled(OsmandVersion version) {
String path = version.getPath();
PackageManager pm = context.getPackageManager();
try {
pm.getPackageInfo(path, PackageManager.GET_ACTIVITIES);
return true;
} catch (PackageManager.NameNotFoundException e) {
}
return false;
}
public static ArrayList<OsmandVersion> getOnlyInstalledVersions() {
OsmandVersion[] versions = values();
ArrayList<OsmandVersion> installedVersions = new ArrayList<>();
for (OsmandVersion version : versions) {
if (isVersionInstalled(version)) {
installedVersions.add(version);
}
}
return installedVersions;
}
}
private static int[] unlockTime = {5, 10, 15, 20, 30, 45, 60};
//todo change singleton type
private static PluginSettings INSTANCE = new PluginSettings();
private PluginSettings() {
preferences = PreferenceManager.getDefaultSharedPreferences(TurnScreenOnApplication.getAppContext());
preferences = PreferenceManager.getDefaultSharedPreferences(context);
OsmAndAidlHelper helper = OsmAndAidlHelper.getInstance();
}
public static PluginSettings getInstance() {
@ -32,35 +110,44 @@ public class PluginSettings {
}
public boolean isPluginEnabled() {
if (preferences.contains(PREFERENCE_ENABLE)) {
return preferences.getBoolean(PREFERENCE_ENABLE, false);
}
return false;
public boolean isPermissionAvailable() {
ComponentName mDeviceAdmin = new ComponentName(context, DeviceAdminRecv.class);
DevicePolicyManager mDevicePolicyManager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
return mDevicePolicyManager.isAdminActive(mDeviceAdmin);
}
public int getTimeLikeSeconds() {
if (preferences.contains(PREFERENCE_TIME)) {
return preferences.getInt(PREFERENCE_TIME, 0);
int position = getTimeModePosition();
if (position < unlockTime.length) {
return unlockTime[position];
}
return 0;
}
public void setTimeLikeSeconds(int seconds) {
SharedPreferences.Editor editor = preferences.edit();
editor.putInt(PREFERENCE_TIME, seconds);
editor.apply();
}
public int getTimePosition() {
if (preferences.contains(PREFERENCE_TIME_INDEX)) {
public int getTimeModePosition() {
return preferences.getInt(PREFERENCE_TIME_INDEX, 0);
}
return 0;
public void setTimeModePosition(int seconds) {
setInteger(PREFERENCE_TIME_INDEX, seconds);
}
public void setTimePosition(int seconds) {
public void setOsmandVersion(int versionId) {
setInteger(PREFERENCE_OSMAND_VERSION, versionId);
}
public OsmandVersion getOsmandVersion() {
int versionId = preferences.getInt(PREFERENCE_OSMAND_VERSION, OsmandVersion.OSMAND_PLUS.id);
return OsmandVersion.getVersionById(versionId);
}
private void setInteger(String tag, int val) {
SharedPreferences.Editor editor = preferences.edit();
editor.putInt(PREFERENCE_TIME_INDEX, seconds);
editor.putInt(tag, val);
editor.apply();
}
@ -69,4 +156,19 @@ public class PluginSettings {
editor.putBoolean(tag, val);
editor.apply();
}
private void setString(String tag, String val) {
SharedPreferences.Editor editor = preferences.edit();
editor.putString(tag, val);
editor.apply();
}
public List<String> getUnlockTimeDescriptionList() {
List<String> result = new ArrayList<>();
for (int t : unlockTime) {
result.add(new StringBuilder().append(t).append(" ")
.append(context.getString(R.string.secondsShort)).toString());
}
return result;
}
}

View file

@ -0,0 +1,18 @@
package net.osmand.turn_screen_on.helpers;
import android.content.Context;
import android.content.res.Resources;
import android.util.TypedValue;
import static android.util.TypedValue.COMPLEX_UNIT_DIP;
public class AndroidUtils {
public static int dpToPx(Context ctx, float dp) {
Resources r = ctx.getResources();
return (int) TypedValue.applyDimension(
COMPLEX_UNIT_DIP,
dp,
r.getDisplayMetrics()
);
}
}

View file

@ -22,17 +22,15 @@ import net.osmand.turn_screen_on.app.TurnScreenOnApplication;
import java.util.List;
public class OsmAndAidlHelper {
public final static String OSMAND_FREE_PACKAGE_NAME = "net.osmand";
public final static String OSMAND_PLUS_PACKAGE_NAME = "net.osmand.plus";
public final static String OSMAND_NIGHTLY_PACKAGE_NAME = "net.osmand.dev";
//todo change singleton type
private final static OsmAndAidlHelper INSTANCE = new OsmAndAidlHelper();
private final static String AIDL_SERVICE_PATH = "net.osmand.aidl.OsmandAidlService";
private LockHelper lockHelper;
private PluginSettings settings;
private IOsmAndAidlInterface mIOsmAndAidlInterface;
private IOsmAndAidlCallback mIOsmAndAidlCallbackInterface = new IOsmAndAidlCallback.Stub() {
@Override
@ -68,7 +66,9 @@ public class OsmAndAidlHelper {
@Override
public void onVoiceRouterNotify() throws RemoteException {
Log.d("ttpl", "take message from vr");
lockHelper.timedUnlock(PluginSettings.getInstance().getTimeLikeSeconds()*1000L);
if (settings.isPluginEnabled()) {
lockHelper.timedUnlock(PluginSettings.getInstance().getTimeLikeSeconds() * 1000L);
}
}
};
@ -99,7 +99,9 @@ public class OsmAndAidlHelper {
};
private OsmAndAidlHelper() {
bindService(OSMAND_PLUS_PACKAGE_NAME, TurnScreenOnApplication.getAppContext());
//todo change
settings = PluginSettings.getInstance();
lockHelper = new LockHelper(TurnScreenOnApplication.getAppContext());
}
public static OsmAndAidlHelper getInstance(){
@ -143,10 +145,15 @@ public class OsmAndAidlHelper {
}
private boolean bindService(String appToConnectPackage, Context context) {
Intent intent = new Intent("net.osmand.aidl.OsmandAidlService");
Intent intent = new Intent(AIDL_SERVICE_PATH);
intent.setPackage(appToConnectPackage);
context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
lockHelper = new LockHelper(TurnScreenOnApplication.getAppContext());
return false;
return true;
}
public boolean connect(String appToConnectPackage){
bindService(appToConnectPackage, TurnScreenOnApplication.getAppContext());
Log.d("ttpl", "connecting...");
return true;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 574 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 485 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 554 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 560 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 380 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 356 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 346 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 402 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 685 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 657 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 602 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 716 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 923 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 824 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View file

@ -1,9 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".AdminDevicePermissionSetUpActivity">
tools:context=".PermissionsSetUpActivity">
</android.support.constraint.ConstraintLayout>
<FrameLayout
android:id="@+id/btnContinue"
android:layout_width="200dp"
android:layout_height="50dp"
android:layout_gravity="center_horizontal|bottom"
android:layout_marginBottom="58dp"
android:background="@color/lighterViolet">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/continueDesc"
android:textColor="@color/white"/>
</FrameLayout>
</FrameLayout>

View file

@ -2,6 +2,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/llPluginPreferencesLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/activityBackground"
@ -18,101 +19,7 @@
app:titleTextColor="@color/white" />
<FrameLayout
android:id="@+id/flRootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="52dp"
android:background="@color/white">
<TextView
android:id="@+id/tvPluginStateDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/disabled"
android:layout_gravity="center_vertical|start"
android:layout_marginLeft="12dp"
android:textColor="#727272"
android:textSize="24sp" />
<android.support.v7.widget.SwitchCompat
android:id="@+id/swFunctionSwitcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|end"
android:theme="@style/SwitchStyle"
android:layout_marginRight="12dp"/>
</FrameLayout>
<View
android:layout_height="20dp"
android:layout_width="match_parent"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tvPluginTimeWorkDescription"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/timeWorkingDescription"/>
<Spinner
android:id="@+id/spTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</FrameLayout>
<Button
android:id="@+id/btnRegister"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="register"/>
</LinearLayout>
<FrameLayout
android:id="@+id/btnOpenOsmand"
android:layout_width="200dp"
android:layout_height="74dp"
android:layout_gravity="center_horizontal|bottom"
android:layout_marginBottom="32dp"
android:background="@drawable/blue_button">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|start"
android:layout_marginLeft="16dp"
android:text="+"
android:textColor="@color/white"
android:textSize="48sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|end"
android:layout_marginRight="24dp"
android:text="@string/openOsmand"
android:textColor="@color/white"
android:textSize="18sp" />
</FrameLayout>
</FrameLayout>
android:layout_height="match_parent" />
</LinearLayout>

View file

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".PluginDescriptionActivity">
<FrameLayout
android:id="@+id/btnContinue"
android:layout_width="200dp"
android:layout_height="50dp"
android:layout_gravity="center_horizontal|bottom"
android:layout_marginBottom="58dp"
android:background="@color/violet">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/continueDesc"
android:textColor="@color/white"/>
</FrameLayout>
</FrameLayout>

View file

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<FrameLayout
android:id="@+id/btnOpenOsmand"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
android:layout_marginBottom="16dp"
android:background="@drawable/blue_button">
<LinearLayout
android:layout_width="160dp"
android:layout_height="50dp">
<ImageView
android:id="@+id/ivOsmandVersionOnButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|start"
android:paddingLeft="14dp"
android:src="@drawable/ic_action_osmand_logo" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="18dp"
android:layout_weight="1"
android:gravity="center_vertical|end"
android:text="@string/openOsmand"
android:textColor="@color/white"
android:textSize="14sp" />
</LinearLayout>
</FrameLayout>
</FrameLayout>

View file

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/flRootLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:paddingRight="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="46dp"
android:text="@string/OsmandVersion"
android:gravity="center_vertical"
style="@style/turnScreenOnHeaderTextStyle"/>
<LinearLayout
android:id="@+id/llOsmandVersions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</LinearLayout>
</FrameLayout>
</android.support.v7.widget.CardView>

View file

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="52dp"
android:background="@color/white"
android:paddingLeft="16dp"
android:paddingRight="16dp">
<TextView
android:id="@+id/tvPluginStateDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|start"
android:text="@string/disabled"
android:textColor="#727272"
android:textSize="16sp" />
<android.support.v7.widget.SwitchCompat
android:id="@+id/swPluginEnableSwitcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|end"
android:theme="@style/SwitchStyle" />
</FrameLayout>
</android.support.v7.widget.CardView>

View file

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="52dp"
android:background="@color/white">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_action_sensor_interaction"
android:tint="@color/darkGrey"
android:layout_gravity="center_vertical"/>
<TextView
style="@style/turnScreenOnHeaderTextStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/sensorHeader"
android:layout_gravity="center_vertical"/>
<android.support.v7.widget.SwitchCompat
android:id="@+id/swSensorEnableSwitcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|end"
android:theme="@style/SwitchStyle" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/turnScreenOnDescriptionTextStyle"
android:text="@string/sensorDescription"/>
</LinearLayout>
</android.support.v7.widget.CardView>

View file

@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:paddingLeft="16dp"
android:paddingRight="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="52dp"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_action_time_span"
android:tint="@color/darkGrey"
android:layout_gravity="center_vertical"/>
<TextView
android:id="@+id/tvPluginTimeWorkDescription"
style="@style/turnScreenOnHeaderTextStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/timeWorkingHeader"
android:layout_gravity="center_vertical"/>
<Spinner
android:id="@+id/spTime"
android:background="@color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/turnScreenOnDescriptionTextStyle"
android:text="@string/timeWorkingDescription"/>
</LinearLayout>
</FrameLayout>
</android.support.v7.widget.CardView>

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/install_instruction" />
</LinearLayout>

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>

View file

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/ivVersionImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/ic_action_osmand"/>
<TextView
android:id="@+id/tvVersionName"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="52dp"
android:gravity="center_vertical"
xmlns:tools="http://schemas.android.com/tools"
style="@style/turnScreenOnHeaderTextStyle"
tools:text="OsmAnd"/>
<RadioButton
android:id="@+id/rbVersion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
style="@style/RadioButtonStyle"/>
</LinearLayout>

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_help"
android:orderInCategory="200"
android:icon="@drawable/ic_action_help"
app:showAsAction="ifRoom"
android:title="@string/help" />
</menu>

View file

@ -9,4 +9,7 @@
<color name="darkGrey">#727272</color>
<color name="activityBackground">#F0F0F0</color>
<color name="orange">#FF8800</color>
<color name="violet">#4F29C1</color>
<color name="lighterViolet">#6617D3</color>
<color name="black">#000000</color>
</resources>

View file

@ -4,6 +4,15 @@
<string name="openOsmand">Open OsmAnd</string>
<string name="disabled">Disabled</string>
<string name="enabled">Enabled</string>
<string name="timeWorkingDescription">Время включения экрана</string>
<string name="timeWorkingHeader">Время включения экрана</string>
<string name="secondsShort">sec</string>
<string name="OsmandVersion">OsmAnd Version</string>
<string name="OsmandPlus">OsmAnd Plus</string>
<string name="Osmand">OsmAnd</string>
<string name="continueDesc">continue</string>
<string name="sensorHeader">Использовать датчик приближения</string>
<string name="help">Help</string>
<string name="install_instruction">You need to install OsmAnd to use this plugin.</string>
<string name="timeWorkingDescription">Set the time for which the screen will turn on, to display the map and navigation instructions.</string>
<string name="sensorDescription">Проведите рукой над верхней частью экрана, чтобы включить экран во время навигации.</string>
</resources>

View file

@ -11,6 +11,7 @@
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="colorControlActivated">@color/blue</item>
</style>
<style name="SwitchStyle" parent="Theme.AppCompat.Light">
@ -18,4 +19,21 @@
<item name="android:colorForeground">@color/darkGrey</item>
</style>
<style name="RadioButtonStyle" parent="Theme.AppCompat.Light">
<!--<item name="colorControlNormal">@color/darkGrey</item>-->
<item name="colorControlActivated">@color/blue</item>
</style>
<style name="turnScreenOnHeaderTextStyle">
<item name="android:textSize">16sp</item>
<item name="android:textColor">@color/black</item>
<item name="android:paddingLeft">10dp</item>
</style>
<style name="turnScreenOnDescriptionTextStyle">
<item name="android:textSize">16sp</item>
<item name="android:textColor">@color/darkGrey</item>
<item name="android:layout_marginTop">8dp</item>
<item name="android:layout_marginBottom">8dp</item>
</style>
</resources>