server ready for testing - but untested
This commit is contained in:
@@ -3,11 +3,13 @@ package com.mhalka.qurantranslationdisplay;
|
|||||||
import java.net.DatagramPacket;
|
import java.net.DatagramPacket;
|
||||||
import java.net.DatagramSocket;
|
import java.net.DatagramSocket;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
public class RemoteControlServer{
|
public class RemoteControlServer {
|
||||||
|
|
||||||
public static final String SERVERIP = "0.0.0.0";
|
public static final String SERVERIP = "0.0.0.0";
|
||||||
public static final int SERVERPORT = 4444;
|
public static final int SERVERPORT = 4444;
|
||||||
@@ -32,13 +34,11 @@ public class RemoteControlServer{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void recieve(String command) {
|
public void recieve(String command) {
|
||||||
// dummy implementation to be sure there is something to call
|
// dummy interface
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
DatagramSocket socket = null;
|
DatagramSocket socket = null;
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
package com.mhalka.qurantranslationdisplay;
|
package com.mhalka.qurantranslationdisplay;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import com.mhalka.qurantranslationdisplay.RemoteControlServer.OnCommandRecieved;
|
import com.mhalka.qurantranslationdisplay.RemoteControlServer.OnCommandRecieved;
|
||||||
import com.mhalka.qurantranslationdisplay.VerticalMarqueeTextView.ScrollingStoppedListener;
|
import com.mhalka.qurantranslationdisplay.VerticalMarqueeTextView.ScrollingStoppedListener;
|
||||||
|
|
||||||
@@ -7,9 +11,12 @@ import android.app.Activity;
|
|||||||
import android.content.res.AssetManager;
|
import android.content.res.AssetManager;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
import android.text.method.ScrollingMovementMethod;
|
import android.text.method.ScrollingMovementMethod;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.util.TypedValue;
|
||||||
|
import android.view.View;
|
||||||
import android.view.animation.Animation;
|
import android.view.animation.Animation;
|
||||||
import android.view.animation.LinearInterpolator;
|
import android.view.animation.LinearInterpolator;
|
||||||
import android.view.animation.TranslateAnimation;
|
import android.view.animation.TranslateAnimation;
|
||||||
@@ -26,12 +33,15 @@ import android.widget.TextView;
|
|||||||
public class ShowAyah extends Activity {
|
public class ShowAyah extends Activity {
|
||||||
|
|
||||||
private static int NUMBER_OF_MILISECONDS_TO_READ_ONE_LINE = 2500;
|
private static int NUMBER_OF_MILISECONDS_TO_READ_ONE_LINE = 2500;
|
||||||
|
private static int NUMBER_OF_MINUTES_BEFORE_RESTARTING_SLIDESHOW = 5;
|
||||||
private VerticalMarqueeTextView ayah;
|
private VerticalMarqueeTextView ayah;
|
||||||
private TextView chapterName;
|
private TextView chapterName;
|
||||||
int currentChapter=1;
|
int currentChapter=1;
|
||||||
int currentVerse=1;
|
int currentVerse=1;
|
||||||
private RemoteControlServer rcs;
|
private RemoteControlServer rcs;
|
||||||
private ServerTask server;
|
private ServerTask server;
|
||||||
|
private Handler pauseHandler = new Handler();
|
||||||
|
private long timeAyahChanged = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -155,9 +165,55 @@ public class ShowAyah extends Activity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void recieve(String command) {
|
public void recieve(String command) {
|
||||||
// TODO parse the command and do it !
|
String pattern = "([SF])(\\d+)(A?)(\\d*)";
|
||||||
|
|
||||||
|
// Create a Pattern object
|
||||||
|
Pattern r = Pattern.compile(pattern);
|
||||||
|
|
||||||
|
// Now create matcher object.
|
||||||
|
Matcher m = r.matcher(command);
|
||||||
|
if (m.find()) {
|
||||||
|
String commandName = m.group(0);
|
||||||
|
String firstParameter = m.group(1);
|
||||||
|
if(commandName.equals("S")) {
|
||||||
|
String secondParameter = m.group(3);
|
||||||
|
int surah = Integer.parseInt(firstParameter);
|
||||||
|
int ayah = Integer.parseInt(secondParameter);
|
||||||
|
handleAyahChange(surah, ayah);
|
||||||
|
}
|
||||||
|
else if(commandName.equals("F")) {
|
||||||
|
int size = Integer.parseInt(firstParameter);
|
||||||
|
ayah.setTextSize(TypedValue.COMPLEX_UNIT_SP, (float)size);
|
||||||
|
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
System.out.println("NO MATCH");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void handleAyahChange(int surahNumber, int ayahNumber) {
|
||||||
|
showAyah(surahNumber, ayahNumber);
|
||||||
|
timeAyahChanged = (new Date()).getTime();
|
||||||
|
ayah.pauseMarquee();
|
||||||
|
pauseHandler.postDelayed(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
long timeNow = (new Date()).getTime();
|
||||||
|
long difference = timeNow - timeAyahChanged;
|
||||||
|
|
||||||
|
boolean imamFinishedSwitchingAyahs = difference >= NUMBER_OF_MINUTES_BEFORE_RESTARTING_SLIDESHOW * 60 * 1000;
|
||||||
|
if(imamFinishedSwitchingAyahs) {
|
||||||
|
ayah.resumeMarquee();
|
||||||
|
}
|
||||||
|
// else next posted runnable will try handle the continuation
|
||||||
|
|
||||||
|
}
|
||||||
|
// 100 miliseconds after period should expire try to unpause the slideshow
|
||||||
|
}, (NUMBER_OF_MINUTES_BEFORE_RESTARTING_SLIDESHOW * 60 * 1000) + 100);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
server.execute("");
|
server.execute("");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user