platform/android/Rhodes/src/com/rhomobile/rhodes/Rhodes.java in rhodes-2.0.0.beta1 vs platform/android/Rhodes/src/com/rhomobile/rhodes/Rhodes.java in rhodes-2.0.0.beta2
- old
+ new
@@ -27,22 +27,24 @@
import java.util.Vector;
import com.rhomobile.rhodes.Utils.AssetsSource;
import com.rhomobile.rhodes.Utils.FileSource;
import com.rhomobile.rhodes.mainview.MainView;
-import com.rhomobile.rhodes.mainview.SimpleMainView;
import com.rhomobile.rhodes.ui.AboutDialog;
import com.rhomobile.rhodes.ui.LogOptionsDialog;
import com.rhomobile.rhodes.ui.LogViewDialog;
import com.rhomobile.rhodes.uri.MailUriHandler;
+import com.rhomobile.rhodes.uri.SmsUriHandler;
import com.rhomobile.rhodes.uri.TelUriHandler;
import com.rhomobile.rhodes.uri.UriHandler;
import com.rhomobile.rhodes.uri.VideoUriHandler;
import android.app.Activity;
import android.content.Context;
import android.content.pm.ActivityInfo;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
@@ -80,12 +82,11 @@
public static int WINDOW_FLAGS = WindowManager.LayoutParams.FLAG_FULLSCREEN;
public static int WINDOW_MASK = WindowManager.LayoutParams.FLAG_FULLSCREEN;
private static int MAX_PROGRESS = 10000;
- private static final String INSTALLING_PAGE = "apps/app/installing.html";
- private static final String LOADING_PAGE = "apps/app/loading.html";
+ private static boolean ENABLE_LOADING_INDICATION = true;
private long uiThreadId;
public long getUiThreadId() {
return uiThreadId;
}
@@ -147,15 +148,25 @@
public String getRootPath() {
return rootPath;
}
private String phoneMemoryRootPath() {
- return "/data/data/" + getPackageName() + "/data/";
+ String pkgName = getPackageName();
+ try {
+ ApplicationInfo info = getPackageManager().getApplicationInfo(pkgName, 0);
+ String path = info.dataDir + "/rhodata/";
+ return path;
+ } catch (NameNotFoundException e) {
+ throw new RuntimeException("Internal error: package " + pkgName + " not found: " + e.getMessage());
+ }
}
private String sdcardRootPath() {
- return Environment.getExternalStorageDirectory() + "/rhomobile/" + getPackageName() + "/";
+ String sdPath = Environment.getExternalStorageDirectory().getAbsolutePath();
+ String pkgName = getPackageName();
+ String path = sdPath + "/rhomobile/" + pkgName + "/";
+ return path;
}
private RhoLogConf m_rhoLogConf = new RhoLogConf();
public RhoLogConf getLogConf() {
return m_rhoLogConf;
@@ -202,22 +213,22 @@
phPath.getParentFile().mkdirs();
makeLink(sdPath.getAbsolutePath(), phPath.getAbsolutePath());
*/
}
- private boolean isNameChanged() {
+ public boolean isNameChanged() {
try {
FileSource as = new AssetsSource(getResources().getAssets());
FileSource fs = new FileSource();
return !Utils.isContentsEquals(as, "name", fs, new File(getRootPath(), "name").getPath());
}
catch (IOException e) {
return true;
}
}
- private boolean isBundleChanged() {
+ public boolean isBundleChanged() {
if (contentChanged == null) {
try {
String rp = getRootPath();
FileSource as = new AssetsSource(getResources().getAssets());
@@ -304,53 +315,54 @@
w.setHorizontalScrollBarEnabled(true);
w.setVerticalScrollbarOverlay(true);
w.setHorizontalScrollbarOverlay(true);
w.setWebViewClient(new WebViewClient() {
-
- private boolean realPageLoaded = false;
+ private boolean splashHidden = false;
+
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return handleUrlLoading(url);
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
- getWindow().setFeatureInt(Window.FEATURE_PROGRESS, 0);
+ if (ENABLE_LOADING_INDICATION)
+ getWindow().setFeatureInt(Window.FEATURE_PROGRESS, 0);
super.onPageStarted(view, url, favicon);
}
@Override
public void onPageFinished(WebView view, String url) {
- // Clear page until we get real page loaded
- if (!(realPageLoaded || url.equals(LOADING_PAGE)))
- realPageLoaded = true;
- if (!realPageLoaded)
- view.clearHistory();
// Set title
Rhodes r = RhodesInstance.getInstance();
String title = view.getTitle();
r.setTitle(title);
// Hide splash screen
- if (url.startsWith("http://"))
+ if (!splashHidden && url.startsWith("http://")) {
hideSplashScreen();
- getWindow().setFeatureInt(Window.FEATURE_PROGRESS, MAX_PROGRESS);
+ splashHidden = true;
+ }
+ if (ENABLE_LOADING_INDICATION)
+ getWindow().setFeatureInt(Window.FEATURE_PROGRESS, MAX_PROGRESS);
super.onPageFinished(view, url);
}
});
w.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
- newProgress *= 100;
- if (newProgress < 0)
- newProgress = 0;
- if (newProgress > MAX_PROGRESS)
- newProgress = MAX_PROGRESS;
- getWindow().setFeatureInt(Window.FEATURE_PROGRESS, newProgress);
+ if (ENABLE_LOADING_INDICATION) {
+ newProgress *= 100;
+ if (newProgress < 0)
+ newProgress = 0;
+ if (newProgress > MAX_PROGRESS)
+ newProgress = MAX_PROGRESS;
+ getWindow().setFeatureInt(Window.FEATURE_PROGRESS, newProgress);
+ }
super.onProgressChanged(view, newProgress);
}
});
return w;
@@ -418,12 +430,12 @@
catch (Exception e) {
Logger.E("Rhodes", "performOnUiThread failed: " + e.getMessage());
}
}
- private void showSplashScreen(String file) throws IOException {
- splashScreen = new SplashScreen(this, file);
+ private void showSplashScreen() {
+ splashScreen = new SplashScreen(this);
splashScreen.start(outerFrame);
}
public void hideSplashScreen() {
if (splashScreen != null) {
@@ -433,52 +445,10 @@
View view = mainView.getView();
view.setVisibility(View.VISIBLE);
view.requestFocus();
}
- private void showLoadingPage() {
- try {
- boolean hasInstalling = false;
- try {
- getResources().getAssets().open("apps/app/installing.png").close();
- hasInstalling = true;
- }
- catch (IOException e) {}
- showSplashScreen("apps/app/" + (hasInstalling && isBundleChanged() ? "installing.png" : "loading.png"));
- }
- catch (Exception e) {
- MainView v = new SimpleMainView();
-
- boolean bc = isBundleChanged();
- String page = bc ? INSTALLING_PAGE : LOADING_PAGE;
-
- boolean hasNeededPage;
- try {
- getResources().getAssets().open(page).close();
- hasNeededPage = true;
- }
- catch (IOException e1) {
- hasNeededPage = false;
- }
-
- if (hasNeededPage) {
- v.navigate("file:///android_asset/" + page, 0);
- }
- else {
- StringBuffer p = new StringBuffer();
- p.append("<html><title>");
- p.append(bc ? "Installing" : "Loading");
- p.append("</title><body>");
- p.append(bc ? "Installing" : "Loading");
- p.append("...</body></html>");
- v.loadData(p.toString(), 0);
- }
-
- setMainView(v);
- }
- }
-
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -509,17 +479,19 @@
boolean disableScreenRotation = RhoConf.getBool("disable_screen_rotation");
this.setRequestedOrientation(disableScreenRotation ? ActivityInfo.SCREEN_ORIENTATION_PORTRAIT :
ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
- this.requestWindowFeature(Window.FEATURE_PROGRESS);
+ ENABLE_LOADING_INDICATION = !RhoConf.getBool("disable_loading_indication");
+ if (ENABLE_LOADING_INDICATION)
+ this.requestWindowFeature(Window.FEATURE_PROGRESS);
outerFrame = new FrameLayout(this);
this.setContentView(outerFrame, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
Logger.I("Rhodes", "Loading...");
- showLoadingPage();
+ showSplashScreen();
// Increase WebView rendering priority
WebView w = new WebView(this);
WebSettings webSettings = w.getSettings();
webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH);
@@ -539,9 +511,10 @@
isCameraAvailable = true;
// Register custom uri handlers here
uriHandlers.addElement(new MailUriHandler(this));
uriHandlers.addElement(new TelUriHandler(this));
+ uriHandlers.addElement(new SmsUriHandler(this));
uriHandlers.addElement(new VideoUriHandler(this));
Thread init = new Thread(new Runnable() {
public void run() {