I was making an Android app (min SDK : 8, target SDK : 19)
now I want to set a loading icon to appear at the start until the application checks internet cennectivity
until now I have no problem
I had this method do it for me :
void setLoader(boolean T, String msg){
View LAY = findViewById(R.id.loaderLayout);
TextView MTV = (TextView) findViewById(R.id.loader_msg);
if(T && !loaderStarted){
loader.start();
LAY.setVisibility(View.VISIBLE);
MTV.setText(msg);
loaderStarted = true;
}
else if (!T && loaderStarted) {
loader.interrupt();
LAY.setVisibility(View.GONE);
loaderStarted = false;
}
}
Then I needed to get user&pass then lock the UI with that thread again to check user&pass The problem is : I have problem pausing a thread :| my primary programming language isn't java
so please help me with this I have the Thread like this :
//first make loading icon visible then call :
final private Thread loader = new Thread(new Runnable(){
@Override
public void run() {
int i = 0;
while (true){
if(loader.isInterrupted()){
return;
}
try {Thread.sleep(25);} catch (InterruptedException e) {}
final int j = i;
runOnUiThread(new Runnable(){
public void run() {
ImageView imageView = (ImageView) findViewById(R.id.loaderImage);
Matrix matrix = new Matrix();
imageView.setScaleType(ScaleType.MATRIX);
int newWIDTH = imageView.getWidth();
int newHIEGHT = imageView.getHeight();
matrix.postScale(((float)(newWIDTH))/imageView.getDrawable().getBounds().width(), ((float)(newHIEGHT))/imageView.getDrawable().getBounds().height());
matrix.postRotate((float) j, newWIDTH/2, newHIEGHT/2);
imageView.setImageMatrix(matrix);
}
});
i = (i + 15) % 360;
}
}
});
then I need a method like this :
void setLoader(boolean T, String msg){
View LAY = findViewById(R.id.loaderLayout);
TextView MTV = (TextView) findViewById(R.id.loader_msg);
if(T && !loaderStarted){
loader.start();
LAY.setVisibility(View.VISIBLE);
MTV.setText(msg);
loaderStarted = true;
}
else if(T && loaderSuspended && loaderStarted){
loader.resume();
LAY.setVisibility(View.VISIBLE);
MTV.setText(msg);
loaderSuspended = false;
}
else if (loaderStarted && !loaderSuspended) {
loader.suspend();
LAY.setVisibility(View.GONE);
loaderStarted = false;
loaderSuspended = true;
}
}
to suspend the thread then resume it (.suspend() and .resume() are deprecated)
Thanks in advance :) And sorry for the awful English ( :D )