Skip to content

Commit

Permalink
Move to v0.5.2 && Update documents
Browse files Browse the repository at this point in the history
  • Loading branch information
renyuneyun committed Jan 12, 2018
2 parents c7fe3c8 + af7df5b commit 5098801
Show file tree
Hide file tree
Showing 31 changed files with 340 additions and 122 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ captures/
out
gen

release/

*.bak
*~
*.swp
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
CHANGELOG
======

* v0.5.2: Add "cool down" (seconds) && Allow to match BSSID for WiFi Event && Check permissions before enabling plugins && fixes & improvements
* Add "cool down" time (in seconds) for the re-activation of the same event
* `WifiEventPlugin` can now handle BSSIDs
* If you need to match BSSID and ESSID, you will need two chained events
* Check (and require) permissions before enabling plugins in Settings
* Fix `NfcEventPlugin` (which wasn't really working previously)
* Code improvements
* See 00fa3a6

* v0.5.1: Change a bit of plugins' definition (mainly generify and remove unneeded methods) && Add `HeadsetEventPlugin` && Code clean up
* Add `DataFactory` (and subclasses) to be used as a wrapper of `StorageData` (and subclasses)
* Generify `PluginDef`, `PluginViewFragment`, `DataFactory` (and subclasses) to use their related `StorageData` as the type parameter (so that there is no need to do lots of manual type casting and checking)
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId 'ryey.easer'
minSdkVersion 15
targetSdkVersion 23
versionCode 50
versionName "0.5.1"
versionCode 51
versionName "0.5.2"

vectorDrawables.useSupportLibrary = true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class EventTest {
@BeforeClass
public static void setUpAll() throws ParseException {
t_xml_root = "<?xml version='1.0' encoding='utf-8' standalone='no' ?><event><name>myparent</name><profile>profile1</profile><trigger><after>NO DATA</after><situation spec=\"time\"><at>13:23</at></situation><logic>after</logic></trigger></event>";
t_xml_child = "<?xml version='1.0' encoding='utf-8' standalone='no' ?><event version=\"2\"><active>true</active><name>123</name><profile>profile1</profile><trigger><after>myparent</after><situation spec=\"time\"><at>13:23</at></situation><logic>after</logic></trigger></event>";
t_xml_child = "<?xml version='1.0' encoding='utf-8' standalone='no' ?><event version=\"1\"><active>true</active><name>123</name><profile>profile1</profile><trigger><after>myparent</after><situation spec=\"time\"><at>13:23</at></situation><logic>after</logic></trigger></event>";

t_event_child = new EventStructure();
t_event_child.setName("123");
Expand Down
18 changes: 12 additions & 6 deletions app/src/main/java/ryey/easer/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -66,15 +67,20 @@ public static <T> List<String> set2strlist(Set<T> set) {
return list;
}

public static String StringListToString(List<String> category) {
public static String StringCollectionToString(@NonNull Collection<String> collection, boolean trailing) {
StringBuilder text = new StringBuilder();
if (category != null) {
for (String line : category) {
String trimmed = line.trim();
if (!trimmed.isEmpty())
text.append(trimmed).append('\n');
boolean is_first = true;
for (String line : collection) {
String trimmed = line.trim();
if (!trimmed.isEmpty()) {
if (!is_first)
text.append("\n");
text.append(trimmed);
is_first = false;
}
}
if (!is_first && trailing)
text.append("\n");
return text.toString();
}

Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/ryey/easer/commons/C.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ public class C {
public static final String STATE = "state";

public static final String VERSION = "version";
public static final int VERSION_WIFI_ADD_BSSID = 3;
public static final int VERSION_ADD_JSON = 2;
public static final int VERSION_FULL_MULTI = 1;
public static final int VERSION_DEFAULT = 0;
public static final int VERSION_CURRENT = VERSION_ADD_JSON;
public static final int VERSION_CURRENT = VERSION_WIFI_ADD_BSSID;

public enum Format {
XML,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import android.content.Context;
import android.support.annotation.NonNull;

import com.orhanobut.logger.Logger;

import ryey.easer.commons.plugindef.ValidData;

/**
Expand Down
27 changes: 19 additions & 8 deletions app/src/main/java/ryey/easer/core/Lotus.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.orhanobut.logger.Logger;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Locale;

Expand Down Expand Up @@ -62,7 +63,8 @@ final class Lotus {
private AbstractSlot mSlot;
private List<Lotus> subs = new ArrayList<>();

private boolean analyzing = false;
private final long cooldownInMillisecond;
private Calendar lastSatisfied;

private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
Expand Down Expand Up @@ -99,6 +101,8 @@ public void onReceive(Context context, Intent intent) {

mSlot = dataToSlot(eventTree.getEvent());
mSlot.register(notifyLotusIntent, notifyLotusUnsatisfiedIntent);

cooldownInMillisecond = SettingsHelper.coolDownInterval(context);
}

private <T extends EventData> AbstractSlot<T> dataToSlot(T data) {
Expand Down Expand Up @@ -130,14 +134,21 @@ void cancel() {

private synchronized void onSlotSatisfied() {
Logger.i("event <%s> satisfied", eventTree.getName());
if (!analyzing) {
analyzing = true;
if (mSlot.canPromoteSub()) {
triggerAndPromote();
} else {
traverseAndTrigger(eventTree, false);
if (cooldownInMillisecond > 0) {
Calendar now = Calendar.getInstance();
if (lastSatisfied != null) {
if (now.getTimeInMillis() - lastSatisfied.getTimeInMillis() < cooldownInMillisecond) {
Logger.d("event <%s> is within cooldown time");
return;
}
}
analyzing = false;
Logger.d("event <%s> is not within cooldown time");
lastSatisfied = now;
}
if (mSlot.canPromoteSub()) {
triggerAndPromote();
} else {
traverseAndTrigger(eventTree, false);
}
}

Expand Down
16 changes: 16 additions & 0 deletions app/src/main/java/ryey/easer/core/SettingsHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ryey.easer.core;

import android.content.Context;
import android.preference.PreferenceManager;

import ryey.easer.R;

public class SettingsHelper {

public static int coolDownInterval(Context context) {
String interval_pref = PreferenceManager.getDefaultSharedPreferences(context)
.getString(context.getString(R.string.key_pref_cooldown), "3");
return Integer.parseInt(interval_pref);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public String serialize(EventStructure eventStructure) throws UnableToSerializeE

private void writeEvent(EventStructure eventStructure) throws IOException {
serializer.startTag(ns, C.EVENT);
serializer.attribute(ns, ryey.easer.commons.C.VERSION, String.valueOf(ryey.easer.commons.C.VERSION_CURRENT));
serializer.attribute(ns, ryey.easer.commons.C.VERSION, String.valueOf(ryey.easer.commons.C.VERSION_FULL_MULTI));
writeActiveState(eventStructure.isActive());
writeName(eventStructure.getName());
writeProfile(eventStructure.getProfileName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import android.widget.CompoundButton;
import android.widget.TextView;

import com.orhanobut.logger.Logger;

import ryey.easer.R;
import ryey.easer.commons.plugindef.InvalidDataInputException;
import ryey.easer.commons.plugindef.PluginViewFragment;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
package ryey.easer.core.ui.setting;

import android.app.Activity;
import android.content.Context;
import android.preference.CheckBoxPreference;
import android.preference.Preference;

import ryey.easer.BuildConfig;
import ryey.easer.R;
import ryey.easer.commons.CommonHelper;
import ryey.easer.commons.plugindef.PluginDef;

class PluginEnabledPreference extends CheckBoxPreference {
class PluginEnabledPreference extends CheckBoxPreference implements Preference.OnPreferenceChangeListener {

private static final int REQCODE = 2333;

private final PluginDef plugin;

PluginEnabledPreference(Context context, PluginDef plugin) {
super(context);
this.plugin = plugin;
setOnPreferenceChangeListener(this);
setKey(CommonHelper.pluginEnabledKey(plugin));
setTitle(plugin.name());
boolean isCompatible = plugin.isCompatible(context);
Expand All @@ -22,4 +31,14 @@ class PluginEnabledPreference extends CheckBoxPreference {
setSummary(R.string.message_plugin_not_compatible);
}
}

@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (BuildConfig.DEBUG && !(newValue instanceof Boolean)) throw new AssertionError();
if ((Boolean) newValue && !plugin.checkPermissions(getContext())) {
plugin.requestPermissions((Activity) getContext(), REQCODE);
return false;
}
return true;
}
}
22 changes: 22 additions & 0 deletions app/src/main/java/ryey/easer/core/ui/setting/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Calendar;
import java.util.Locale;

import ryey.easer.BuildConfig;
import ryey.easer.R;
import ryey.easer.core.BootupReceiver;
import ryey.easer.core.EHService;
Expand Down Expand Up @@ -160,6 +161,27 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
}
});

findPreference(getString(R.string.key_pref_cooldown))
.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (BuildConfig.DEBUG && !(newValue instanceof String))
throw new AssertionError();
String interval_str = (String) newValue;
try {
int interval = Integer.parseInt(interval_str);
if (interval < 0)
throw new NumberFormatException();
return true;
} catch (NumberFormatException e) {
Toast.makeText(getActivity(),
R.string.cooldown_time_illformed, Toast.LENGTH_SHORT)
.show();
return false;
}
}
});

findPreference(getString(R.string.key_pref_plugins))
.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import android.content.IntentFilter;
import android.support.annotation.NonNull;

import ryey.easer.commons.IllegalArgumentTypeException;
import ryey.easer.commons.plugindef.ValidData;
import ryey.easer.commons.plugindef.eventplugin.AbstractSlot;
import ryey.easer.commons.plugindef.eventplugin.EventType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
@Override
protected void _fill(@ValidData @NonNull BroadcastEventData data) {
ReceiverSideIntentData intentData = data.intentData;
editText_action.setText(Utils.StringListToString(intentData.action));
editText_category.setText(Utils.StringListToString(intentData.category));
editText_action.setText(Utils.StringCollectionToString(intentData.action, false));
editText_category.setText(Utils.StringCollectionToString(intentData.category, false));
}

@ValidData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import android.content.Context;
import android.support.annotation.NonNull;

import ryey.easer.commons.IllegalArgumentTypeException;
import ryey.easer.commons.plugindef.ValidData;
import ryey.easer.commons.plugindef.eventplugin.EventType;
import ryey.easer.plugins.event.SelfNotifiableSlot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.DatePicker;

Expand All @@ -37,7 +38,7 @@ public class DatePluginViewFragment extends PluginViewFragment<DateEventData> {

@NonNull
@Override
public ViewGroup onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
datePicker = new DatePicker(getContext());
return datePicker;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import com.orhanobut.logger.Logger;

import ryey.easer.Utils;
import ryey.easer.commons.IllegalArgumentTypeException;
import ryey.easer.commons.plugindef.ValidData;
import ryey.easer.commons.plugindef.eventplugin.AbstractSlot;
import ryey.easer.commons.plugindef.eventplugin.EventType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TimePicker;

Expand All @@ -38,7 +39,7 @@ public class TimePluginViewFragment extends PluginViewFragment<TimeEventData> {

@NonNull
@Override
public ViewGroup onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
timePicker = new TimePicker(getContext());

return timePicker;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

import com.orhanobut.logger.Logger;

import ryey.easer.commons.IllegalArgumentTypeException;
import ryey.easer.commons.plugindef.ValidData;
import ryey.easer.commons.plugindef.eventplugin.AbstractSlot;
import ryey.easer.commons.plugindef.eventplugin.EventType;
Expand Down Expand Up @@ -102,9 +101,14 @@ public void check() {
}

private boolean compare(WifiInfo wifiInfo) {
String ssid = wifiInfo.getSSID();
if (ssid.startsWith("\"")) {
ssid = ssid.substring(1, ssid.length() - 1);
String ssid;
if (data.mode_essid) {
ssid = wifiInfo.getSSID();
if (ssid.startsWith("\"")) {
ssid = ssid.substring(1, ssid.length() - 1);
}
} else {
ssid = wifiInfo.getBSSID();
}
return data.match(ssid);
}
Expand Down
Loading

0 comments on commit 5098801

Please sign in to comment.