Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn screen on Plugin #7031

Merged
merged 35 commits into from
Jul 6, 2019
Merged

Turn screen on Plugin #7031

merged 35 commits into from
Jul 6, 2019

Conversation

nazar-kutz
Copy link
Contributor

No description provided.

@vshcherb
Copy link
Member

Please rename OsmAnd-Plugin-TurnScreenOn

@nazar-kutz nazar-kutz marked this pull request as ready for review June 19, 2019 17:43
private RadioGroupWrapper osmandVersionRadioGroup;
private FrameLayout btnOpenOsmand;

private LayoutInflater inflater;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use local variable


if (!settings.isProgramOpenedEarlier()) {
settings.setOpened();
isReturnedFromAnotherActivity = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this var needed? Is it possible to move code from onResume to onCreate?

settings.setOpened();
isReturnedFromAnotherActivity = true;
startPluginDescriptionActivity(PluginDescriptionActivity.MODE_FIRST_OPEN);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting

if (settings.hasAvailableOsmandVersions()) {
try {
if (!isReturnedFromAnotherActivity) {
Log.d("ttpl2", "no returned");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove such logs from PR.

setContentView(R.layout.activity_main);

app = (TurnScreenApp) getApplicationContext();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra space


public void registerForVoiceRouterMessages() {
try {
Log.d("ttpl", "try add a listener");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drop dev logs

isRegistered = false;
}
} catch (RemoteException e) {
e.printStackTrace();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not use e.printStackTrace() (even if you copy-pasted it)

refreshUI();
}
} catch (Exception e) {
Log.d("ttpl2", "take an exception");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what exception?

@@ -0,0 +1,8 @@
package net.osmand.turnScreenOn.listener;

public interface MessageSender {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like abstract, but used for single purpose. Needs to be renamed?

import android.util.SparseArray;
import android.widget.RadioButton;

public class RadioGroupWrapper {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Purpose is unclear.

voiceMessageListeners.remove(voiceMessageListener);
}

public void notifyOnVoiceMessage() {
Log.d("ttpl", "notify listeners: ");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log.d should be deleted - only for dev and we use commons logging for prod

@@ -1897,6 +1899,33 @@ public void unregisterFromUpdates(long id) {
navUpdateCallbacks.remove(id);
}

private Map<Long, VoiceRouter.VoiceMessageListener> voiceRouterMessageCallbacks= new ConcurrentHashMap<>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fields in top of the class

int i = 0;
for (VoiceMessageListener lnt : voiceMessageListeners.keySet()) {
Log.d("ttpl", "listner " + ++i);
lnt.onVoiceMessage();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Paramater which voice message should be present

@@ -8,6 +8,7 @@
import java.util.concurrent.ConcurrentHashMap;

import net.osmand.Location;
import net.osmand.aidl.OsmandAidlService;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this class shouldn't be present here

@@ -27,6 +28,7 @@
import alice.tuprolog.Term;
import android.media.AudioManager;
import android.media.SoundPool;
import android.util.Log;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class should be deleted

@@ -27,6 +28,7 @@
import alice.tuprolog.Term;
import android.media.AudioManager;
import android.media.SoundPool;
import android.util.Log;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use weakreference for listeners

public final CommonPreference<Integer> WAKE_ON_VOICE_TIME_INT = new IntPreference("wake_on_voice_time_int", 0).makeProfile();

{
// 0 means never
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// 0 means never?


{
// 0 means never
WAKE_ON_VOICE_SENSOR.setModeDefaultValue(ApplicationMode.CAR, false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete theses blocks

LOG.debug("switch on sensor");
mSensorManager.registerListener(this, mProximity, SensorManager.SENSOR_DELAY_NORMAL);
} else {
LOG.debug("switch off sensor");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

debug?

}
play(null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double play?

}

public void switchOnSensor() {
LOG.debug("switch on sensor");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete debug

voiceMessageListener = new VoiceRouter.VoiceMessageListener() {
@Override
public void onVoiceMessage() {
LOG.debug("onVoiceMessage");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

debug?

@@ -705,4 +706,7 @@ interface IOsmAndAidlInterface {
boolean areOsmandSettingsCustomized(in OsmandSettingsInfoParams params);

boolean setCustomization(in CustomizationInfoParams params);
long registerForVoiceRouterMessages(in ANavigationVoiceRouterMessageParams params, IOsmAndAidlCallback callback);

boolean changeMapActivityKeyguardFlags(in boolean enable);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add comments

};

setVoiceRouterListener(true);
setSensor(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Start sensor only if turned on in settings

public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_PROXIMITY) {
if (event.values[0] >= -SENSOR_SENSITIVITY && event.values[0] <= SENSOR_SENSITIVITY) {
if (isSensorEnabled()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such check must be at top of the method

}
};

setVoiceRouterListener(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nazar-kutz and others added 9 commits July 4, 2019 11:30
move sensor state verification
Now it activates only if enable in the settings and the screen is off while navigation.

Remove router checkbox from preferences
Now it activates only if enable in the settings and the screen is off while navigation.

Remove router checkbox from preferences
fix changeKeyguardFlags (MapActivity) multithreading problem
@crimean crimean merged commit e9ae109 into master Jul 6, 2019
@vshcherb vshcherb deleted the turn_screen_on_plugin branch July 7, 2019 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants