assets/src/org/ruboto/SplashActivity.java in ruboto-0.14.0 vs assets/src/org/ruboto/SplashActivity.java in ruboto-0.15.0
- old
+ new
@@ -29,29 +29,29 @@
private long enqueue;
java.io.File localFile;
private static final int INSTALL_REQUEST_CODE = 4242;
public void onCreate(Bundle bundle) {
- Log.d("SplashActivity onCreate:");
+ Log.d("SplashActivity onCreate:");
localFile = new java.io.File(getFilesDir(), RUBOTO_APK);
- try {
- splash = Class.forName(getPackageName() + ".R$layout").getField("splash").getInt(null);
- } catch (Exception e) {
- splash = -1;
- }
+ try {
+ splash = Class.forName(getPackageName() + ".R$layout").getField("splash").getInt(null);
+ } catch (Exception e) {
+ splash = -1;
+ }
if (!JRubyAdapter.isInitialized()) {
- initJRuby(true);
- }
- super.onCreate(bundle);
+ initJRuby(true);
+ }
+ super.onCreate(bundle);
}
public void onResume() {
Log.d("onResume: ");
if (!JRubyAdapter.isInitialized() && receiver == null) {
- registerPackageInstallReceiver();
+ registerPackageInstallReceiver();
}
- super.onResume();
+ super.onResume();
}
public void onPause() {
Log.d("onPause: ");
if (receiver != null) {
@@ -71,49 +71,47 @@
}
private void initJRuby(final boolean firstTime) {
showProgress();
new Thread(new Runnable() {
- public void run() {
- final boolean jrubyOk = JRubyAdapter.setUpJRuby(SplashActivity.this);
- if (jrubyOk) {
- Log.d("onResume: JRuby OK");
- startUserActivity();
- hideProgress();
- finish();
- } else {
- registerPackageInstallReceiver();
- runOnUiThread(new Runnable() {
- public void run() {
- if (localFile.exists()) {
- installDownload();
- } else {
- if (firstTime) {
- Log.d("onResume: Checking JRuby - IN UI thread");
- try {
- setContentView(Class.forName(getPackageName() + ".R$layout").getField("get_ruboto_core").getInt(null));
- if (hasInternetPermission()) {
- getRubotoCore(null);
- return;
- }
- } catch (Exception e) {
- }
- } else {
- Toast.makeText(SplashActivity.this,"Failed to initialize Ruboto Core.",Toast.LENGTH_LONG).show();
- try {
- TextView textView = (TextView) findViewById(Class.forName(getPackageName() + ".R$id").getField("text").getInt(null));
- textView.setText("Woops! Ruboto Core was installed, but it failed to initialize properly! I am not sure how to proceed from here. If you can, please file an error report at http://ruboto.org/");
- } catch (Exception e) {
- }
- }
- }
- hideProgress();
- }
- });
- }
- }
- }).start();
+ public void run() {
+ final boolean jrubyOk = JRubyAdapter.setUpJRuby(SplashActivity.this);
+ if (jrubyOk) {
+ Log.d("onResume: JRuby OK");
+ startUserActivity();
+ } else {
+ registerPackageInstallReceiver();
+ runOnUiThread(new Runnable() {
+ public void run() {
+ if (localFile.exists()) {
+ installDownload();
+ } else {
+ if (firstTime) {
+ Log.d("onResume: Checking JRuby - IN UI thread");
+ try {
+ setContentView(Class.forName(getPackageName() + ".R$layout").getField("get_ruboto_core").getInt(null));
+ if (hasInternetPermission()) {
+ getRubotoCore(null);
+ return;
+ }
+ } catch (Exception e) {
+ }
+ } else {
+ Toast.makeText(SplashActivity.this,"Failed to initialize Ruboto Core.",Toast.LENGTH_LONG).show();
+ try {
+ TextView textView = (TextView) findViewById(Class.forName(getPackageName() + ".R$id").getField("text").getInt(null));
+ textView.setText("Woops! Ruboto Core was installed, but it failed to initialize properly! I am not sure how to proceed from here. If you can, please file an error report at http://ruboto.org/");
+ } catch (Exception e) {
+ }
+ }
+ }
+ hideProgress();
+ }
+ });
+ }
+ }
+ }).start();
}
private static final String RUBOTO_APK = "RubotoCore-release.apk";
private static final String RUBOTO_URL = "http://ruboto.org/downloads/" + RUBOTO_APK;
@@ -126,22 +124,22 @@
Request request = new Request(Uri.parse(RUBOTO_URL));
enqueue = dm.enqueue(request);
hideProgress();
showDownloadProgress("Downloading RubotoCore...");
new Thread(new Runnable() {
- public void run() {
- while (loadingDialog != null && enqueue > 0) {
- // FIXME(uwe): Also set total bytes and bytes downloaded.
- loadingDialog.setProgress(getProgressPercentage());
- try {
- Thread.sleep(1000);
- } catch (InterruptedException ie) {
- Log.e("Interupted!");
- }
- }
- }
- }).start();
+ public void run() {
+ while (loadingDialog != null && enqueue > 0) {
+ // FIXME(uwe): Also set total bytes and bytes downloaded.
+ loadingDialog.setProgress(getProgressPercentage());
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException ie) {
+ Log.e("Interupted!");
+ }
+ }
+ }
+ }).start();
}
return;
}
} catch (Exception e) {
Log.e("Exception in direct RubotoCore download: " + e);
@@ -163,15 +161,15 @@
} else {
Log.i("Showing progress");
loadingDialog = ProgressDialog.show(this, null, "Starting...", true, true);
loadingDialog.setCanceledOnTouchOutside(false);
loadingDialog.setOnCancelListener(new OnCancelListener() {
- public void onCancel(DialogInterface dialog) {
- dialogCancelled = true;
- finish();
- }
- });
+ public void onCancel(DialogInterface dialog) {
+ dialogCancelled = true;
+ finish();
+ }
+ });
}
}
}
private void showDownloadProgress(String message) {
@@ -189,15 +187,15 @@
loadingDialog.setMax(100);
loadingDialog.setProgressStyle(android.app.ProgressDialog.STYLE_HORIZONTAL);
loadingDialog.setCancelable(true);
loadingDialog.setCanceledOnTouchOutside(false);
loadingDialog.setOnCancelListener(new OnCancelListener() {
- public void onCancel(DialogInterface dialog) {
- dialogCancelled = true;
- finish();
- }
- });
+ public void onCancel(DialogInterface dialog) {
+ dialogCancelled = true;
+ finish();
+ }
+ });
loadingDialog.show();
}
} else {
loadingDialog.setMessage(message);
}
@@ -211,52 +209,52 @@
}
}
private void registerPackageInstallReceiver() {
receiver = new BroadcastReceiver(){
- public void onReceive(Context context, Intent intent) {
- Log.d("Received intent: " + intent + " (" + intent.getExtras() + ")");
- if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(intent.getAction())) {
- long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0);
- if (downloadId == enqueue) {
- if (localFile.exists()) {
- return;
- }
- Query query = new Query();
- query.setFilterById(enqueue);
- DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
- Cursor c = dm.query(query);
- if (c.moveToFirst()) {
- hideProgress();
- int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));
- if (DownloadManager.STATUS_SUCCESSFUL == status) {
- storeDownload(dm, downloadId);
- installDownload();
- } else {
- int reason = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_REASON));
- Toast.makeText(context,"Download failed (" + status + "): " + reason, Toast.LENGTH_LONG).show();
- }
- } else {
- Toast.makeText(context,"Download diappeared!", Toast.LENGTH_LONG).show();
- }
- c.close();
- }
- } else if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())) {
- if (intent.getData().toString().equals("package:org.ruboto.core")) {
- Toast.makeText(context,"Ruboto Core is now installed.",Toast.LENGTH_LONG).show();
- deleteFile(RUBOTO_APK);
- if (receiver != null) {
- unregisterReceiver(receiver);
- receiver = null;
- }
- initJRuby(false);
- } else {
- Toast.makeText(context,"Installed: " + intent.getData().toString(),Toast.LENGTH_LONG).show();
- }
- }
- }
- };
+ public void onReceive(Context context, Intent intent) {
+ Log.d("Received intent: " + intent + " (" + intent.getExtras() + ")");
+ if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(intent.getAction())) {
+ long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0);
+ if (downloadId == enqueue) {
+ if (localFile.exists()) {
+ return;
+ }
+ Query query = new Query();
+ query.setFilterById(enqueue);
+ DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
+ Cursor c = dm.query(query);
+ if (c.moveToFirst()) {
+ hideProgress();
+ int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));
+ if (DownloadManager.STATUS_SUCCESSFUL == status) {
+ storeDownload(dm, downloadId);
+ installDownload();
+ } else {
+ int reason = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_REASON));
+ Toast.makeText(context,"Download failed (" + status + "): " + reason, Toast.LENGTH_LONG).show();
+ }
+ } else {
+ Toast.makeText(context,"Download diappeared!", Toast.LENGTH_LONG).show();
+ }
+ c.close();
+ }
+ } else if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())) {
+ if (intent.getData().toString().equals("package:org.ruboto.core")) {
+ Toast.makeText(context,"Ruboto Core is now installed.",Toast.LENGTH_LONG).show();
+ deleteFile(RUBOTO_APK);
+ if (receiver != null) {
+ unregisterReceiver(receiver);
+ receiver = null;
+ }
+ initJRuby(false);
+ } else {
+ Toast.makeText(context,"Installed: " + intent.getData().toString(),Toast.LENGTH_LONG).show();
+ }
+ }
+ }
+ };
IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
filter.addDataScheme("package");
registerReceiver(receiver, filter);
IntentFilter download_filter = new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE);
registerReceiver(receiver, download_filter);
@@ -357,11 +355,11 @@
// when we stop supporting Android api level < 17
String[] selectionArgs = {Settings.Secure.INSTALL_NON_MARKET_APPS, String.valueOf(1)};
// EMXIF
Cursor query = getContentResolver().query(settingsUri, projection,
- selection, selectionArgs, null);
+ selection, selectionArgs, null);
return query.getCount() == 1;
}
// Get the downloaded percent
private int getProgressPercentage() {
@@ -374,21 +372,21 @@
downloadedBytesSoFar = (int) c.getLong(soFarIndex);
int totalSizeIndex = c.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES);
totalBytes = (int) c.getLong(totalSizeIndex);
}
System.out.println("PERCEN ------" + downloadedBytesSoFar
- + " ------ " + totalBytes + "****" + percentage);
+ + " ------ " + totalBytes + "****" + percentage);
percentage = (downloadedBytesSoFar * 100 / totalBytes);
System.out.println("percentage % " + percentage);
} catch (Exception e) {
e.printStackTrace();
}
return percentage;
}
private void startUserActivity() {
- if (getIntent().hasExtra(Intent.EXTRA_INTENT)) {
- startActivity((Intent)getIntent().getParcelableExtra(Intent.EXTRA_INTENT));
- }
+ if (getIntent().hasExtra(Intent.EXTRA_INTENT)) {
+ startActivity((Intent)getIntent().getParcelableExtra(Intent.EXTRA_INTENT));
+ }
}
}