How can i make a text in android-studio to be animated? - java

For example if i display in a TextView the text "Uploading" now i want it to display the text as "Uploading..." and the 3 points to be delete and show again like it's processing doing something and not just static text.
I have this in the MainActivity onTouch event:
#Override
public boolean onTouchEvent(MotionEvent event)
{
float eventX = event.getX();
float eventY = event.getY();
float lastdownx = 0;
float lastdowny = 0;
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
lastdownx = eventX;
lastdowny = eventY;
Thread t = new Thread(new Runnable()
{
#Override
public void run()
{
byte[] response = null;
if (connectedtoipsuccess == true)
{
if (is_start == true)
{
uploadTimerBool = true;
timers.StartTimer(timerValueRecord, "Recording Time: ");
response = Get(iptouse + "start");
is_start = false;
} else
{
timers.StopTimer(timerValueRecord);
textforthespeacch = "Recording stopped and preparing the file to be shared on youtube";
MainActivity.this.runOnUiThread(new Runnable()
{
#Override
public void run()
{
status1.setText("Preparing the file");
}
});
MainActivity.this.initTTS();
response = Get(iptouse + "stop");
is_start = true;
startuploadstatusthread = true;
servercheckCounter = 0;
}
if (response != null)
{
try
{
a = new String(response, "UTF-8");
MainActivity.this.runOnUiThread(new Runnable()
{
#Override
public void run()
{
if (a.equals("Recording started"))
{
status1.setText("Recording");
}
if (a.equals("Recording stopped and preparing the file to be shared on youtube"))
{
status1.setText("Recording Stopped");
}
}
});
textforthespeacch = a;
MainActivity.this.initTTS();
} catch (UnsupportedEncodingException e)
{
e.printStackTrace();
}
Logger.getLogger("MainActivity(inside thread)").info(a);
}
}
}
});
t.start();
return true;
case MotionEvent.ACTION_MOVE:
break;
case MotionEvent.ACTION_UP:
break;
default:
return false;
}
return true;
}
This line:
status1.setText("Preparing the file");
Instead displaying only static text "Preparing the file" i was wondering how to make that it will display something like moving points like "Preparing the file..." then "Preparing the file.." and "Preparing the file." and again "Preparing the file..." then "Preparing the file.." and so on.

Use this awesome library, exactly what you are looking for:
https://github.com/tajchert/WaitingDots
Add this to dependencies
compile 'pl.tajchert:waitingdots:0.2.0'
and you can use the methos. The description is in the link

Handler handler = new Handler();
for (int i = 100; i <= 3500; i=i+100) {
handler.postDelayed(new Runnable() {
#Override
public void run() {
if(i%300 == 0){
textView.setText("Uploading.");
}else if(i%200 == 0){
textView.setText("Uploading..");
}else if(i%100 == 0){
textView.setText("Uploading...");
}
}
}, i);
}

Related

Clicking a button 3 times in a row to trigger a toast?

I was just wondering how to create a toast (or trigger something else to happen) when clicking on button 3 times in a row?
For example: I've created a coin flip so far and I want a toast to appear if the user manages to get 3 heads/tails in a row.
This is my current code:
if (randomNumber == 1) {
Log.i("Result", "Heads");
greycoin.animate().alpha(0).setDuration(1000).rotationYBy(1800);
redcoin.animate().alpha(1).setDuration(1000).rotationYBy(1800);
view.animate()
.withEndAction(new Runnable() {
#Override
public void run() {
Toast.makeText(MainActivity.this, "Heads", Toast.LENGTH_SHORT).show();
}
})
.start();
} else {
Log.i("Result", "Tails");
greycoin.animate().alpha(1).setDuration(1000).rotationYBy(1800);
redcoin.animate().alpha(0).setDuration(1000).rotationYBy(1800);
view.animate()
.withEndAction(new Runnable() {
#Override
public void run() {
Toast.makeText(MainActivity.this, "Tails", Toast.LENGTH_SHORT).show();
}
})
.start();
}
}
I'm still incredibly new to Java and programming, so please pardon my poor programming vocabulary.
Thank you very much in advance!
you should use the gesture instead:
view.setOnTouchListener(new View.OnTouchListener() {
Handler handler = new Handler();
int numberOfTaps = 0;
long lastTapTimeMs = 0;
long touchDownMs = 0;
#Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
touchDownMs = System.currentTimeMillis();
break;
case MotionEvent.ACTION_UP:
handler.removeCallbacksAndMessages(null);
if ((System.currentTimeMillis() - touchDownMs) > ViewConfiguration.getTapTimeout()) {
//it was not a tap
numberOfTaps = 0;
lastTapTimeMs = 0;
break;
}
if (numberOfTaps > 0
&& (System.currentTimeMillis() - lastTapTimeMs) < ViewConfiguration.getDoubleTapTimeout()) {
numberOfTaps += 1;
} else {
numberOfTaps = 1;
}
lastTapTimeMs = System.currentTimeMillis();
if (numberOfTaps == 3) {
Toast.makeText(getApplicationContext(), "triple click", Toast.LENGTH_SHORT).show();
//handle triple tap
}
return true;
}
});

delay inside for loop, make toast every 2 seconds

So hi everyone, this is my first post in stackoverflow,
and i get stucked in 1 problem,
the problem is:
how can I add a delay inside for loop
I did lots of research and none of it works
So I decided to ask myself.
Here is my code
Handler handler1 = new Handler();
for (langId = 1; langId <= 3; langId++) {
handler1.postDelayed(new Runnable() {
#Override
public void run() {
if (langId == 1) {
Toast.makeText(KCRdestActivity.this, "1", Toast.LENGTH_LONG).show();
delayTime += 2000;
}
if (langId == 2) {
Toast.makeText(KCRdestActivity.this, "2", Toast.LENGTH_LONG).show();
delayTime += 2000;
}
if (langId == 3) {
Toast.makeText(KCRdestActivity.this, "3", Toast.LENGTH_LONG).show();
delayTime += 2000;
}
}
}, delayTime);
}
So the result I want is:
"1" -> 2000ms -> "2" -> 2000ms -> "3"
Any ideas?
I tried Thread.sleep(2000), it works, but it freeze the app, I need to do extra things during the process.
Edit
Problem solved, this is the working code, also my final goal
playBtn2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final Handler handler1 = new Handler();
langId = 1;
max = 1;
delayTime = 0;
selectedMP = 1;
if (((RadioButton) findViewById(R.id.noneDepart)).isChecked()) max = 3;
else max = 6;
handler1.post(new Runnable() {
#Override
public void run() {
if (((RadioButton) findViewById(R.id.noneDepart)).isChecked()) {
String destdir = "KCR/Depart/" + Utils.getDestID(selectedDest) + "_";
if (viaRAC.isChecked()) destdir = destdir + "via_rac_";
destdir = destdir + langId + ".mp3";
if (selectedMP == 1) {
try {
afd = getAssets().openFd(destdir);
mp1.reset();
mp1.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
mp1.prepare();
mp1.start();
//Utils.RunOnUiThread(KCRdestActivity.this, mp1, sb1);
((Button) findViewById(R.id.Play1)).setText("❙❙");
selectedMP = 2;
delayTime = mp1.getDuration() - 130;
Toast.makeText(KCRdestActivity.this, delayTime + "##" + destdir, Toast.LENGTH_LONG).show();
} catch (Exception e) {
e.printStackTrace();
}
} else {
try {
afd = getAssets().openFd(destdir);
mp2.reset();
mp2.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
mp2.prepare();
mp2.start();
//Utils.RunOnUiThread(KCRdestActivity.this, mp1, sb1);
((Button) findViewById(R.id.Play1)).setText("❙❙");
selectedMP = 1;
delayTime = mp2.getDuration() - 130;
Toast.makeText(KCRdestActivity.this, delayTime + "##" + destdir, Toast.LENGTH_LONG).show();
} catch (Exception e) {
e.printStackTrace();
}
}
}
if (langId > 3) {
return;
}
langId++;
handler1.postDelayed(this, delayTime);
}
});
}
});
Handler handler1 = new Handler();
int langId = 1;
handler1.postDelayed(new Runnable() {
#Override
public void run() {
if (langId > 3) {
return;
}
if (langId == 1) {
Toast.makeText(KCRdestActivity.this, "1", Toast.LENGTH_LONG).show();
delayTime = 2000;
}
if (langId == 2) {
Toast.makeText(KCRdestActivity.this, "2", Toast.LENGTH_LONG).show();
delayTime = 2000;
}
if (langId == 3) {
Toast.makeText(KCRdestActivity.this, "3", Toast.LENGTH_LONG).show();
delayTime = 2000;
}
langId++;
handler1.postDelayed(this, delayTyme);
}
}
There's no need to write that much lines of code, try this:
Handler handler1 = new Handler();
int langId = 1;
handler1.post(new Runnable() {
#Override
public void run() {
if (langId > 3) {
return;
}
Toast.makeText(KCRdestActivity.this, String.valueOf(langId++), Toast.LENGTH_LONG).show();
handler1.postDelayed(this, 2000); // If delay time is constant!
}
});
you can use asyntask along with Thread.sleep(2000) in the doInBackground method
try this..
MainActivity.....
long Delay = 2000;
oncreate().........
Timer Run = new Timer();
TimerTask Show = new TimerTask() {
#Override
public void run() {
do something.........
}
};
Run.schedule(Show, Delay);
}
You need to move your code out of run method and put into for loop directly. Put only toast inside run method.
1. Implement a timer task and schedule it after every 2seconds
int value = 1;
Timer timer = new Timer();
TimerTask task = new TimerTask() {
#Override
public void run() {
Toast.makeText(KCRdestActivity.this, value, Toast.LENGTH_LONG).show();
value++;
}
};
timer.schedule(task, 2000);
OR
2. Change your code to
Try
for (langId = 1; langId <= 3; langId++) {
delayTime += 2000;
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
Toast.makeText(KCRdestActivity.this, String.valueOf(langId), Toast.LENGTH_LONG).show();
}
}, delayTime);
}
You can use an AsyncTask for this.
public class MyAsyncTask extends AsyncTask<Void, Integer, Void> {
#Override
protected Void doInBackground(Void... params) {
for (int langId = 1; langId <= 3; langId++) {
publishProgress(langId);
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
return null;
}
#Override
protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
Toast.makeText(KCRdestActivity.this, String.valueOf(values[0]), Toast.LENGTH_LONG).show();
}
}
use this method
declare global these classes
private int TIME_STAMP_INTERVAL = 2000;
private Runnable runnable = null;
private int count=0;
final Handler handler = new Handler();
then add this in method which u call
runnable = new Runnable() {
#Override
public void run() {
Toast.makeText(context, ""count++, Toast.LENGTH_SHORT).show();
handler.postDelayed(runnable, TIME_STAMP_INTERVAL);
}
};
handler.post(runnable);
A quick and dirty way to achieve this using Thread.sleep(2000):
public static void main(String[] args) {
Runnable forLoop = () -> {
for (int i = 1; i <= 3; i++) {
System.out.print(i); // Do your stuff
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
new Thread(forLoop).start();
}
Output:
1 -> 2000ms -> 2 -> 2000ms -> 3

Issues using android studio to get time of travel between two points

For the last week, I have been using Android Studio to write code that achieves the following goals:
Wait for the user to be within a certain distance of the start waypoint
Once at start waypoint, begin a timer that logs gps data and current time
Stops timer when the end waypoint is crossed
At the moment, I have the start and end waypoints hard coded but I seem to run into an error that I have been trying to trace with the step through function on my IDE but can't seem to find it. Below is the code I have been using:
void StartTimer (View view){
//Location l = null;
boolean hasLoc = false; //are we at the start?
float speed = 0;
float topSpeed = 0;
while(hasLoc == false && cancel == false){
float d = l.distanceTo(t);
if(d < 2.0)
hasLoc = true;
//if(!l.equals(lm.getLastKnownLocation("")))
String msg = "Latitude: " + l.getLatitude() + "\nLongitude: "+ l.getLongitude();
Toast.makeText(getBaseContext(), msg, Toast.LENGTH_LONG).show();
}
hasLoc = false;
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
// Actions to do after 10 seconds
buzzer();
}
}, 10000);
while(l.distanceTo(tf) > 2.0 && cancel == false){
float cSpeed = l.getSpeed();
if(cSpeed>topSpeed)
topSpeed = cSpeed;
String msg = "Current Speed: "+cSpeed+"Top Speed: "+topSpeed;
Toast.makeText(getBaseContext(), msg, Toast.LENGTH_LONG).show();
}
cancel = false;
}
When I run the code, the phone I test it one will run it but it won't respond, which leads me to believe there is an unsatisfied loop that I have not considered.
Any suggestions would be helpful, thank you in advance for advice!
Your while loops are clogging up the CPU's execution which is what is causing it to not respond. Instead you should place your code inside a thread and call Thread.sleep(1000); inside the thread, this way the the while loop is paused for 1 second after every execution of the code inside it.
Something like this:
new Thread(new Runnable() {
#Override
public void run() {
while (hasLoc == false && cancel == false) {
float d = l.distanceTo(t);
if (d < 2.0)
hasLoc = true;
String msg = "Latitude: " + l.getLatitude() + "\nLongitude: " + l.getLongitude();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
runOnUiThread(new Runnable() {
#Override
public void run() {
Toast.makeText(getBaseContext(), msg, Toast.LENGTH_LONG).show();
}
});
}
hasLoc = false;
new Handler().postDelayed(new Runnable() {
public void run() {
// Actions to do after 10 seconds
buzzer();
}
}, 10000);
while (l.distanceTo(tf) > 2.0 && cancel == false) {
float cSpeed = l.getSpeed();
if (cSpeed > topSpeed)
topSpeed = cSpeed;
String msg = "Current Speed: " + cSpeed + "Top Speed: " + topSpeed;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
runOnUiThread(new Runnable() {
#Override
public void run() {
Toast.makeText(getBaseContext(), msg, Toast.LENGTH_LONG).show();
}
});
}
cancel = false;
}
}).start();

How can i resolve the exception Only the original thread that created a view hierarchy can touch its views?

I'm not sure why it happen and how to solve it.
I have this method:
#Override
public boolean onTouchEvent(MotionEvent event)
{
float eventX = event.getX();
float eventY = event.getY();
float lastdownx = 0;
float lastdowny = 0;
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
lastdownx = eventX;
lastdowny = eventY;
Thread t = new Thread(new Runnable()
{
#Override
public void run()
{
byte[] response = null;
if (connectedtoipsuccess == true)
{
if (is_start == true)
{
response = Get(iptouse + "start");
is_start = false;
} else
{
response = Get(iptouse + "stop");
is_start = true;
servercheckCounter = 0;
}
if (response != null)
{
String a = null;
try
{
a = new String(response, "UTF-8");
if (a.equals("Recording started"))
{
status1.setText("Recording");
}
if (a.equals("Recording stopped and preparing the file to be shared on youtube"))
{
status1.setText("Recording Stopped");
}
textforthespeacch = a;
MainActivity.this.initTTS();
} catch (UnsupportedEncodingException e)
{
e.printStackTrace();
}
Logger.getLogger("MainActivity(inside thread)").info(a);
}
}
}
});
t.start();
return true;
case MotionEvent.ACTION_MOVE:
break;
case MotionEvent.ACTION_UP:
break;
default:
return false;
}
return true;
}
The exception haapen after this line:
a = new String(response, "UTF-8");
Or this line:
status1.setText("Recording");
status1 is a TextView and in the onCreate i did:
status1 = (TextView) findViewById(R.id.textView3);
Make the program crash.
The eexception message from the logcat:
09-19 10:22:18.458 19836-20124/com.test.webservertest E/AndroidRuntime﹕ FATAL EXCEPTION: Thread-78258
Process: com.test.webservertest, PID: 19836
android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:6334)
at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:890)
at android.view.View.requestLayout(View.java:17407)
at android.view.View.requestLayout(View.java:17407)
at android.view.View.requestLayout(View.java:17407)
at android.view.View.requestLayout(View.java:17407)
at android.view.View.requestLayout(View.java:17407)
at android.view.View.requestLayout(View.java:17407)
at android.widget.RelativeLayout.requestLayout(RelativeLayout.java:360)
at android.view.View.requestLayout(View.java:17407)
at android.widget.TextView.checkForRelayout(TextView.java:7054)
at android.widget.TextView.setText(TextView.java:4186)
at android.widget.TextView.setText(TextView.java:4044)
at android.widget.TextView.setText(TextView.java:3999)
at com.test.webservertest.MainActivity$6.run(MainActivity.java:633)
at java.lang.Thread.run(Thread.java:818)
The error message states: "Only the original thread that created a view hierarchy can touch its views." Looking at your program, you actually try to set a text on some view in a thread that is not the main thread.
In situations like this you can use the runOnUiThread() method.
For example:
runOnUiThread(new Runnable() {
status1.setText("Recording");
});

Using a BoxSelect class inside a runnable method in a thread (java)

This is how I am trying to execute my code.
private final class BoxSelect implements View.OnTouchListener
{
public boolean onTouch(View view, MotionEvent motionEvent)
{
setView(view);
setMotionEvent(motionEvent);
if (t1.getState() == Thread.State.NEW)
{
t1.start();
if (getHit() == false) {
t2.start();
}
}
return false;
}
}
I have two thread created called t1 and t2 which take the two runnable methods r1 and r1 as parameters:
Thread t1 = new Thread(r1);
Thread t2 = new Thread(r2);
R1 is defined as:
Runnable r1 = new Runnable() {
public void run() {
System.out.println("ENTERING RUN t1");
class BoxSelect implements View.OnTouchListener {
Drawable hitTarget = getResources().getDrawable(R.drawable.hit);
Drawable missTarget = getResources().getDrawable(R.drawable.miss);
View view1 = getView();
MotionEvent motionEvent1 = getMotionEvent();
public void whenCreate()
{
System.out.println("HERE t1");
hit = false;
boolean goToElse = true;
boolean hit2 = false;
boolean goToElse2 = true;
if (motionEvent1.getAction() == MotionEvent.ACTION_DOWN) {
for (int i = 0; i < ids.length; i++) {
for (int j = 0; j < ids.length; j++) {
String coord = b.getBoard()[i][j];
if (view == ids[i][j]) {
System.out.println("ATTACKING " + b.getCompTempBoard()[i][j]);
player.basicAttack(b.getBoard(), coord, ai);
}
if (view == ids[i][j] && b.getCompTempBoard()[i][j].equalsIgnoreCase("HIT")) {
System.out.println("Hit GUI");
if (ids[i][j].getBackground().equals(hitTarget)) {
hit = true;
goToElse = false;
} else {
ids[i][j].setBackgroundDrawable(hitTarget);
System.out.println("ert 1 " + b.getCompTempBoard()[i][j]);
playerCount++;
if (playerCount == 10) {
player.endGame();
b.incrementPlayerCount();
AlertDialog.Builder builder1 = new AlertDialog.Builder(context);
builder1.setMessage("YOU WIN :)\nScore is:\nPlayer: " + b.getPlayerWinCount() + "\nComputer: " + b.getCompWinCount());
builder1.setCancelable(true);
builder1.setNegativeButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
Intent intent = new Intent(AttackShips6.this, MainMenu.class);
startActivity(intent);
}
});
AlertDialog alert11 = builder1.create();
alert11.show();
for (int k = 0; k < ids2.length; k++) {
for (int r = 0; r < ids2.length; r++) {
if (b.getCompTempBoard()[k][r].equalsIgnoreCase("HIT") || b.getCompTempBoard()[k][r].equalsIgnoreCase("NULL NOT HIT")) {
ids[k][r].setBackgroundDrawable(hitTarget);
}
if (b.getCompTempBoard()[k][r].equalsIgnoreCase("MISS") || b.getCompTempBoard()[k][r].equalsIgnoreCase(b.getBoard()[k][r])) {
ids[k][r].setBackgroundDrawable(missTarget);
}
if (b.getTempBoard()[k][r].equalsIgnoreCase("HIT") || b.getTempBoard()[k][r].equalsIgnoreCase("NULL NOT HIT")) {
ids2[k][r].setBackgroundDrawable(hitTarget);
}
if (b.getTempBoard()[k][r].equalsIgnoreCase("MISS") || b.getTempBoard()[k][r].equalsIgnoreCase(b.getBoard()[k][r])) {
ids2[k][r].setBackgroundDrawable(missTarget);
}
}
}
}
hit = true;
goToElse = false;
}
} else if (view == ids[i][j] && b.getCompTempBoard()[i][j].equalsIgnoreCase("MISS")) {
System.out.println("MISS GUI 1");
if (ids[i][j].getBackground().equals(missTarget)) {
hit = true;
goToElse = false;
} else {
System.out.println("MISS GUI");
ids[i][j].setBackgroundDrawable(missTarget);
System.out.println("ert 2 " + b.getCompTempBoard()[i][j]);
hit = true;
goToElse = true;
}
}
if (goToElse == true) {
hit = false;
System.out.println("MISS PLAYER GUI");
view.setBackgroundDrawable(missTarget);
}
}
}
}
}
public boolean onTouch(View view, MotionEvent motionEvent) {
return false;
}
}
}
};
and R2 is:
Runnable r2 = new Runnable() {
public void run() {
System.out.println("ENTERING RUN t2");
try {
TimeUnit.NANOSECONDS.sleep(1);
System.out.println("HERE 2");
class BoxSelect implements View.OnTouchListener {
Drawable hitTarget = getResources().getDrawable(R.drawable.hit);
Drawable missTarget = getResources().getDrawable(R.drawable.miss);
public boolean onTouch(View view, MotionEvent motionEvent) {
System.out.println("HERE t2");
if (hit == false) {
System.out.println("SLEEPING 2");
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("COMPUTERS TURN");
ai.advancedAttack(b.getBoard(), ai.getRandomCoordinate_For_Attacking_6x6(), player);
System.out.println("First attack: " + ai.getFirstCoord());
boolean goAgain = true;
while (goAgain == true) {
for (int w = 0; w < ids2.length; w++) {
for (int y = 0; y < ids2.length; y++) {
if (b.getBoard()[w][y].equalsIgnoreCase(ai.getFirstCoord()) && b.getTempBoard()[w][y].equalsIgnoreCase("HIT")) {
System.out.println("DR 1");
ids2[w][y].setBackgroundDrawable(hitTarget);
ai.setFirstCoord(ai.getNextCoordToAttack());
System.out.println("Next: " + ai.getFirstCoord());
ai.advancedAttack(b.getBoard(), ai.getFirstCoord(), player);
System.out.println("After attack in loop");
goAgain = true;
CompCount++;
if (CompCount == 10) {
b.incrementCompCount();
AlertDialog.Builder builder1 = new AlertDialog.Builder(context);
builder1.setMessage("YOU LOSE :(\n" + "Score is:\n" + "Player: \n" + b.getPlayerWinCount() + "\nComputer: " + b.getCompWinCount());
builder1.setCancelable(true);
builder1.setNegativeButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
Intent intent = new Intent(AttackShips6.this, MainMenu.class);
startActivity(intent);
}
});
AlertDialog alert11 = builder1.create();
alert11.show();
for (int k = 0; k < ids2.length; k++) {
for (int r = 0; r < ids2.length; r++) {
if (b.getCompTempBoard()[k][r].equalsIgnoreCase("HIT") || b.getCompTempBoard()[k][r].equalsIgnoreCase("NULL NOT HIT")) {
ids[k][r].setBackgroundDrawable(hitTarget);
}
if (b.getCompTempBoard()[k][r].equalsIgnoreCase("MISS") || b.getCompTempBoard()[k][r].equalsIgnoreCase(b.getBoard()[k][r])) {
ids[k][r].setBackgroundDrawable(missTarget);
}
if (b.getTempBoard()[k][r].equalsIgnoreCase("HIT") || b.getTempBoard()[k][r].equalsIgnoreCase("NULL NOT HIT")) {
ids2[k][r].setBackgroundDrawable(hitTarget);
}
if (b.getTempBoard()[k][r].equalsIgnoreCase("MISS") || b.getTempBoard()[k][r].equalsIgnoreCase(b.getBoard()[k][r])) {
ids2[k][r].setBackgroundDrawable(missTarget);
}
}
}
}
} else if (b.getBoard()[w][y].equalsIgnoreCase(ai.getFirstCoord()) && b.getTempBoard()[w][y].equalsIgnoreCase("MISS")) {
System.out.println("DR 2");
ids2[w][y].setBackgroundDrawable(missTarget);
ai.setFirstCoord(ai.getNextCoordToAttack());
goAgain = false;
}
}
}
}
}
return hit;
}
}
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
System.out.println("IN CATCH");
}
System.out.println("END");
}
};`
I originally had these two together as one block, but separated it as I wish to pause thread 2 from occurring for one second after thread 2.
The problem I am having is that the BoxSelect class is not getting executed inside the R1 and R2 and so none of the code is executing. Any help on this matter would be appreciated!

Categories

Resources