diff options
author | Chris "Koying" Browet <cbro@semperpax.com> | 2012-11-26 14:53:45 +0100 |
---|---|---|
committer | Chris "Koying" Browet <cbro@semperpax.com> | 2012-11-29 13:07:57 +0100 |
commit | 6338c9fe829e8914f03cde3e6e9e11cdca5d4e07 (patch) | |
tree | becc5a2fbefa211853822b3726e371d017c2b358 /tools/android/packaging | |
parent | 28047c7e8ced9a280ff50ae0311e012bc01314e3 (diff) |
[droid] Do not show any ui if pre-checks are OK
Diffstat (limited to 'tools/android/packaging')
-rw-r--r-- | tools/android/packaging/xbmc/res/layout/activity_splash.xml | 3 | ||||
-rw-r--r-- | tools/android/packaging/xbmc/src/org/xbmc/xbmc/Splash.java | 223 |
2 files changed, 123 insertions, 103 deletions
diff --git a/tools/android/packaging/xbmc/res/layout/activity_splash.xml b/tools/android/packaging/xbmc/res/layout/activity_splash.xml index 4bf79f09ce..fd1b1af0c0 100644 --- a/tools/android/packaging/xbmc/res/layout/activity_splash.xml +++ b/tools/android/packaging/xbmc/res/layout/activity_splash.xml @@ -29,7 +29,8 @@ android:layout_centerHorizontal="true" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" - android:layout_marginTop="-35dp" /> + android:layout_marginTop="-35dp" + android:visibility="invisible" /> <TextView android:id="@+id/textView1" diff --git a/tools/android/packaging/xbmc/src/org/xbmc/xbmc/Splash.java b/tools/android/packaging/xbmc/src/org/xbmc/xbmc/Splash.java index df832d82e7..0cf0db7978 100644 --- a/tools/android/packaging/xbmc/src/org/xbmc/xbmc/Splash.java +++ b/tools/android/packaging/xbmc/src/org/xbmc/xbmc/Splash.java @@ -15,7 +15,6 @@ import java.util.zip.ZipFile; import android.os.AsyncTask; import android.os.Bundle; -import android.preference.PreferenceManager; import android.app.Activity; import android.app.ActivityManager; import android.app.ActivityManager.RunningTaskInfo; @@ -23,7 +22,6 @@ import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; -import android.content.SharedPreferences; import android.util.Log; import android.text.Html; import android.text.method.LinkMovementMethod; @@ -34,7 +32,7 @@ import android.widget.TextView; public class Splash extends Activity { public enum State { - Uninitialized, Checking, Caching, StartingXBMC + Uninitialized, InError, Checking, Caching, StartingXBMC } private static final String TAG = "Splash"; @@ -47,6 +45,11 @@ public class Splash extends Activity { private State mState = State.Uninitialized; public AlertDialog myAlertDialog; + private String sPackagePath; + private String sApkDir; + private File fPackagePath; + private File fApkDir; + public void showErrorDialog(Context context, String title, String message) { if (myAlertDialog != null && myAlertDialog.isShowing()) return; @@ -67,7 +70,9 @@ public class Splash extends Activity { myAlertDialog.show(); // Make links actually clickable - ((TextView)myAlertDialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance()); } + ((TextView) myAlertDialog.findViewById(android.R.id.message)) + .setMovementMethod(LinkMovementMethod.getInstance()); + } // Do the Work class Work extends AsyncTask<Void, Integer, Integer> { @@ -81,108 +86,85 @@ public class Splash extends Activity { @Override protected Integer doInBackground(Void... param) { - mState = State.Checking; - publishProgress(0); + fApkDir.mkdirs(); + + // Log.d(TAG, "apk: " + sPackagePath); + // Log.d(TAG, "output: " + sApkDir); + + ZipFile zip; + byte[] buf = new byte[4096]; + int n; + try { + zip = new ZipFile(sPackagePath); + Enumeration<? extends ZipEntry> entries = zip.entries(); + mProgress.setProgress(0); + mProgress.setMax(zip.size()); + + mState = State.Caching; + publishProgress(mProgressStatus); + while (entries.hasMoreElements()) { + // Update the progress bar + publishProgress(++mProgressStatus); + + ZipEntry e = (ZipEntry) entries.nextElement(); + + if (!e.getName().startsWith("assets/")) + continue; + if (e.getName().startsWith("assets/python2.6")) + continue; + + String sFullPath = sApkDir + "/" + e.getName(); + File fFullPath = new File(sFullPath); + if (e.isDirectory()) { + // Log.d(TAG, "creating dir: " + sFullPath); + fFullPath.mkdirs(); + continue; + } - boolean ret = ParseCpuFeature(); - if (!ret) { - mErrorMsg = "Error! Cannot parse CPU features."; - return -1; - } + // Log.d(TAG, + // "time: " + e.getTime() + ";" + // + fFullPath.lastModified()); + + // If file exists and has same time, skip + if (e.getTime() == fFullPath.lastModified()) + continue; + + // Log.d(TAG, "writing: " + sFullPath); + fFullPath.getParentFile().mkdirs(); + + try { + InputStream in = zip.getInputStream(e); + BufferedOutputStream out = new BufferedOutputStream( + new FileOutputStream(sFullPath)); + while ((n = in.read(buf, 0, 4096)) > -1) + out.write(buf, 0, n); + + in.close(); + out.close(); + + // save the zip time. this way we know for certain + // if we + // need to refresh. + fFullPath.setLastModified(e.getTime()); + } catch (IOException e1) { + e1.printStackTrace(); + } + } - ret = CheckCpuFeature("neon"); - if (!ret) { - mErrorMsg = "This XBMC package is not compatible with your device.\nPlease check the <a href=\"http://wiki.xbmc.org/index.php?title=XBMC_for_Android_specific_FAQ\">XBMC Android wiki</a> for more information."; - return -1; - } + zip.close(); - String sPackagePath = mSplash.getPackageResourcePath(); - File fPackagePath = new File(sPackagePath); - File fCacheDir = mSplash.getCacheDir(); - String sApkDir = fCacheDir.getAbsolutePath() + "/apk"; - File fApkDir = new File(sApkDir); - - if (!fApkDir.exists() || fApkDir.lastModified() < fPackagePath.lastModified()) { - fApkDir.mkdirs(); - - // Log.d(TAG, "apk: " + sPackagePath); - // Log.d(TAG, "output: " + sApkDir); - - ZipFile zip; - byte[] buf = new byte[4096]; - int n; - try { - zip = new ZipFile(sPackagePath); - Enumeration<? extends ZipEntry> entries = zip.entries(); - mProgress.setProgress(0); - mProgress.setMax(zip.size()); - - mState = State.Caching; - publishProgress(mProgressStatus); - while (entries.hasMoreElements()) { - // Update the progress bar - publishProgress(++mProgressStatus); - - ZipEntry e = (ZipEntry) entries.nextElement(); - - if (!e.getName().startsWith("assets/")) - continue; - if (e.getName().startsWith("assets/python2.6")) - continue; - - String sFullPath = sApkDir + "/" + e.getName(); - File fFullPath = new File(sFullPath); - if (e.isDirectory()) { - // Log.d(TAG, "creating dir: " + sFullPath); - fFullPath.mkdirs(); - continue; - } - - // Log.d(TAG, - // "time: " + e.getTime() + ";" - // + fFullPath.lastModified()); - - // If file exists and has same time, skip - if (e.getTime() == fFullPath.lastModified()) - continue; - - // Log.d(TAG, "writing: " + sFullPath); - fFullPath.getParentFile().mkdirs(); - - try { - InputStream in = zip.getInputStream(e); - BufferedOutputStream out = new BufferedOutputStream( - new FileOutputStream(sFullPath)); - while ((n = in.read(buf, 0, 4096)) > -1) - out.write(buf, 0, n); - - in.close(); - out.close(); - - // save the zip time. this way we know for certain - // if we - // need to refresh. - fFullPath.setLastModified(e.getTime()); - } catch (IOException e1) { - e1.printStackTrace(); - } - } + fApkDir.setLastModified(fPackagePath.lastModified()); - zip.close(); - - fApkDir.setLastModified(fPackagePath.lastModified()); - - } catch (FileNotFoundException e1) { - e1.printStackTrace(); - mErrorMsg = "Cannot find package."; - return -1; - } catch (IOException e) { - e.printStackTrace(); - mErrorMsg = "Cannot read package."; - return -1; - } + } catch (FileNotFoundException e1) { + e1.printStackTrace(); + mErrorMsg = "Cannot find package."; + return -1; + } catch (IOException e) { + e.printStackTrace(); + mErrorMsg = "Cannot read package."; + return -1; } - + mState = State.StartingXBMC; publishProgress(0); @@ -242,7 +224,8 @@ public class Splash extends Activity { } private boolean CheckCpuFeature(String feat) { - final Pattern FeaturePattern = Pattern.compile(":.*?\\s" + feat + "(?:\\s|$)"); + final Pattern FeaturePattern = Pattern.compile(":.*?\\s" + feat + + "(?:\\s|$)"); Matcher m = FeaturePattern.matcher(mCpuinfo); return m.find(); } @@ -272,10 +255,46 @@ public class Splash extends Activity { return; } + mState = State.Checking; + + boolean ret = ParseCpuFeature(); + if (!ret) { + mErrorMsg = "Error! Cannot parse CPU features."; + mState = State.InError; + } else { + ret = CheckCpuFeature("neon"); + if (!ret) { + mErrorMsg = "This XBMC package is not compatible with your device.\nPlease check the <a href=\"http://wiki.xbmc.org/index.php?title=XBMC_for_Android_specific_FAQ\">XBMC Android wiki</a> for more information."; + mState = State.InError; + } + } + if (mState != State.InError) { + sPackagePath = getPackageResourcePath(); + fPackagePath = new File(sPackagePath); + File fCacheDir = getCacheDir(); + sApkDir = fCacheDir.getAbsolutePath() + "/apk"; + fApkDir = new File(sApkDir); + + if (fApkDir.exists() + && fApkDir.lastModified() >= fPackagePath.lastModified()) { + mState = State.StartingXBMC; + } + } + + if (mState == State.StartingXBMC) { + startXBMC(); + return; + } + setContentView(R.layout.activity_splash); mProgress = (ProgressBar) findViewById(R.id.progressBar1); mTextView = (TextView) findViewById(R.id.textView1); + + if (mState == State.InError) { + showErrorDialog(this, "Error", mErrorMsg); + return; + } new Work(this).execute(); } |