Fixed issue where stopping took to long
This commit is contained in:
parent
bb84e2188f
commit
1c35a97240
3 changed files with 19 additions and 14 deletions
|
|
@ -19,7 +19,7 @@ public abstract class UeBehaviour implements Serializable{
|
||||||
/**
|
/**
|
||||||
* Starts to run the behaviour, this method will block until the execution is done
|
* Starts to run the behaviour, this method will block until the execution is done
|
||||||
*/
|
*/
|
||||||
public synchronized void run(){
|
public void run(){
|
||||||
running = true;
|
running = true;
|
||||||
|
|
||||||
if(execListener != null) execListener.executionStarted();
|
if(execListener != null) execListener.executionStarted();
|
||||||
|
|
@ -36,7 +36,7 @@ public abstract class UeBehaviour implements Serializable{
|
||||||
/**
|
/**
|
||||||
* Will stop the currently running behaviour
|
* Will stop the currently running behaviour
|
||||||
*/
|
*/
|
||||||
public synchronized void terminate(){
|
public void terminate(){
|
||||||
running = false;
|
running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -97,11 +97,13 @@ public class UeControlExecutor implements Runnable, UeBehaviour.DataHandledListe
|
||||||
log.info("Running behaviour: " + currentlyActive.getName());
|
log.info("Running behaviour: " + currentlyActive.getName());
|
||||||
currentlyActive.run();
|
currentlyActive.run();
|
||||||
|
|
||||||
int index = behaviours.indexOf(currentlyActive) +1;
|
if(isRunning()) {
|
||||||
if(index < behaviours.size())
|
int index = behaviours.indexOf(currentlyActive) + 1;
|
||||||
currentlyActive = behaviours.get(index);
|
if (index < behaviours.size())
|
||||||
else
|
currentlyActive = behaviours.get(index);
|
||||||
currentlyActive = null;
|
else
|
||||||
|
currentlyActive = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
log.info("Execution completed");
|
log.info("Execution completed");
|
||||||
}
|
}
|
||||||
|
|
@ -127,8 +129,10 @@ public class UeControlExecutor implements Runnable, UeBehaviour.DataHandledListe
|
||||||
}
|
}
|
||||||
protected boolean setRealDataUsage(){
|
protected boolean setRealDataUsage(){
|
||||||
boolean ret = false;
|
boolean ret = false;
|
||||||
long currentRxBytes = TrafficStats.getUidRxBytes(MainActivity.getUID());
|
//long currentRxBytes = TrafficStats.getUidRxBytes(MainActivity.getUID());
|
||||||
long currentTxBytes = TrafficStats.getUidTxBytes(MainActivity.getUID());
|
//long currentTxBytes = TrafficStats.getUidTxBytes(MainActivity.getUID());
|
||||||
|
long currentRxBytes = TrafficStats.getTotalRxBytes();
|
||||||
|
long currentTxBytes = TrafficStats.getTotalTxBytes();
|
||||||
|
|
||||||
if (currentRxBytes != TrafficStats.UNSUPPORTED && currentTxBytes != TrafficStats.UNSUPPORTED
|
if (currentRxBytes != TrafficStats.UNSUPPORTED && currentTxBytes != TrafficStats.UNSUPPORTED
|
||||||
&& previousRxBytes != TrafficStats.UNSUPPORTED && previousTxBytes != TrafficStats.UNSUPPORTED){
|
&& previousRxBytes != TrafficStats.UNSUPPORTED && previousTxBytes != TrafficStats.UNSUPPORTED){
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,8 @@ import java.util.regex.Pattern;
|
||||||
*/
|
*/
|
||||||
public class UeBehaviourVideoStreaming extends UeBehaviour implements MediaPlayer.OnErrorListener{
|
public class UeBehaviourVideoStreaming extends UeBehaviour implements MediaPlayer.OnErrorListener{
|
||||||
private static final Logger log = Logger.getLogger(UeBehaviourVideoStreaming.class);
|
private static final Logger log = Logger.getLogger(UeBehaviourVideoStreaming.class);
|
||||||
|
private static final Pattern YOUTUBE_VIDEOURL_PATTERN = Pattern.compile(".*youtube.*[&\\?]v=([\\w-]*)[&#]?");
|
||||||
|
private static final Pattern YOUTUBE_VIDEOID_PATTERN = Pattern.compile("^[\\w-]*$");
|
||||||
protected static final String YOUTUBE_FEED_URL = "http://gdata.youtube.com/feeds/api/videos/";
|
protected static final String YOUTUBE_FEED_URL = "http://gdata.youtube.com/feeds/api/videos/";
|
||||||
|
|
||||||
@Configurable("Streaming URL")
|
@Configurable("Streaming URL")
|
||||||
|
|
@ -65,15 +67,14 @@ public class UeBehaviourVideoStreaming extends UeBehaviour implements MediaPlaye
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static boolean isYouTubeUrl(String url){
|
protected static boolean isYouTubeUrl(String url){
|
||||||
return Pattern.matches("youtube\\.com.*v=", url) ||
|
return YOUTUBE_VIDEOURL_PATTERN.matcher(url).matches() ||
|
||||||
Pattern.matches("^[\\w-]*$", url);
|
YOUTUBE_VIDEOID_PATTERN.matcher(url).matches();
|
||||||
}
|
}
|
||||||
protected static String getYoutubeVideoId(String url){
|
protected static String getYoutubeVideoId(String url){
|
||||||
if(Pattern.matches("^[\\w-]*$", url))
|
if(YOUTUBE_VIDEOID_PATTERN.matcher(url).matches())
|
||||||
return url;
|
return url;
|
||||||
|
|
||||||
Pattern pattern = Pattern.compile("v=([\\w-]*)[&#]?");
|
Matcher match = YOUTUBE_VIDEOURL_PATTERN.matcher(url);
|
||||||
Matcher match = pattern.matcher(url);
|
|
||||||
if(match.find())
|
if(match.find())
|
||||||
return match.group(1);
|
return match.group(1);
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue