Заставка клиента ProfiWM

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package ru.abler98.profiwm;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
public class SplashScreen extends Activity {
String url = "http://test.ru/api/profiwm/index.php";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_screen);
new GetTopicTask().execute(url);
}
private class GetTopicTask extends AsyncTask<String, Integer, String> {
@Override
protected String doInBackground(String... params) {
String result = JSONParser.getJsonFromUrl(params[0]);
return result;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
if (result == null) {
AlertDialog.Builder builder = new AlertDialog.Builder(SplashScreen.this);
builder.setTitle(R.string.error);
builder.setMessage(R.string.error_download_data);
builder.setCancelable(false);
builder.setNegativeButton(R.string.repeat, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
new GetTopicTask().execute(url);
}
});
AlertDialog dialog = builder.create();
dialog.show();
} else {
Intent intent = new Intent(SplashScreen.this, MainActivity.class);
intent.putExtra("result", result);
startActivity(intent);
finish();
}
}
}
}