/*
============================================================================
Author : Dmitry Moskalchuk
Version : 1.5
Copyright : Copyright (C) 2008 Rhomobile. All rights reserved.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
============================================================================
*/
package com.rhomobile.rhodes.mainview;
import java.util.Map;
import java.util.Vector;
import com.rhomobile.rhodes.AndroidR;
import com.rhomobile.rhodes.RhodesActivity;
import com.rhomobile.rhodes.RhodesAppOptions;
import com.rhomobile.rhodes.RhodesService;
import com.rhomobile.rhodes.Utils;
import com.rhomobile.rhodes.file.RhoFileApi;
import com.rhomobile.rhodes.nativeview.RhoNativeViewManager;
import com.rhomobile.rhodes.util.PerformOnUiThread;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
public class SimpleMainView implements MainView {
private final static String TAG = "SimpleMainView";
private static final int WRAP_CONTENT = ViewGroup.LayoutParams.WRAP_CONTENT;
private static final int FILL_PARENT = ViewGroup.LayoutParams.FILL_PARENT;
private class ActionBack implements View.OnClickListener {
public void onClick(View v) {
goBack();//back(0);
}
};
public class MyView extends LinearLayout {
public MyView(Context ctx) {
super(ctx);
}
protected void onSizeChanged (int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
StringBuilder msg = new StringBuilder();
msg.append(" Main Window :: onSizeChanged() old [ ");
msg.append(w);
msg.append(" x ");
msg.append(h);
msg.append(" ] new [ ");
msg.append(oldw);
msg.append(" x ");
msg.append(oldh);
msg.append(" ]");
Utils.platformLog("SimpleMainView.View", msg.toString());
}
}
private class ActionForward implements View.OnClickListener {
public void onClick(View v) {
forward(0);
}
};
private class ActionHome implements View.OnClickListener {
public void onClick(View v) {
navigate(RhodesAppOptions.getStartUrl(), 0);
}
};
private class ActionOptions implements View.OnClickListener {
public void onClick(View v) {
navigate(RhodesAppOptions.getOptionsUrl(), 0);
}
};
private class ActionRefresh implements View.OnClickListener {
public void onClick(View v) {
reload(0);
}
};
private class ActionExit implements View.OnClickListener {
public void onClick(View v) {
restoreWebView();
RhodesService.exit();
}
};
private class ActionCustom implements View.OnClickListener {
private String url;
public ActionCustom(String u) {
url = u;
}
public void onClick(View v) {
PerformOnUiThread.exec(new Runnable() {
public void run() {
RhodesService.loadUrl(ActionCustom.this.url);
}
}, false);
}
};
private LinearLayout view;
private WebView webView;
private RhoNativeViewManager.RhoNativeView mNativeView = null;
private View mNativeViewView = null;
private LinearLayout navBar = null;
private LinearLayout toolBar = null;
private int mCustomBackgroundColor = 0;
private boolean mCustomBackgroundColorEnable = false;
public View getView() {
return view;
}
public WebView getWebView(int tab_index) {
return webView;
}
public void setNativeView(RhoNativeViewManager.RhoNativeView nview) {
restoreWebView();
mNativeView = nview;
mNativeViewView = mNativeView.getView();
if (mNativeViewView != null) {
view.removeView(webView);
//int view_index = 0;
//if (navBar != null) {
//view_index = 1;
//}
if (navBar != null) {
view.removeView(navBar);
}
if (toolBar != null) {
view.removeView(toolBar);
}
int index = 0;
if (navBar != null) {
view.addView(navBar, index);
index++;
}
view.addView( mNativeViewView, index, new LinearLayout.LayoutParams(FILL_PARENT, 0, 1));
index++;
if (toolBar != null) {
view.addView(toolBar, index);
}
//view.bringChildToFront(mNativeViewView);
//view.requestLayout();
}
else {
mNativeView = null;
mNativeViewView = null;
}
}
public void restoreWebView() {
if (mNativeView != null) {
view.removeView(mNativeViewView);
mNativeViewView = null;
//int view_index = 0;
//if (navBar != null) {
//view_index = 1;
//}
if (navBar != null) {
view.removeView(navBar);
}
if (toolBar != null) {
view.removeView(toolBar);
}
int index = 0;
if (navBar != null) {
view.addView(navBar, index);
index++;
}
view.addView( webView, index, new LinearLayout.LayoutParams(FILL_PARENT, 0, 1));
index++;
if (toolBar != null) {
view.addView(toolBar, index);
}
//view.bringChildToFront(webView);
mNativeView.destroyView();
mNativeView = null;
//view.requestLayout();
}
}
private String processForNativeView(String _url) {
StringBuilder s = new StringBuilder("processForNativeView : [");
s.append(_url);
s.append("]");
Utils.platformLog(TAG, s.toString());
String url = _url;
String callback_prefix = "call_stay_native";
// find protocol:navto pairs
int last = -1;
int cur = url.indexOf(":", last+1);
while (cur > 0) {
String protocol = url.substring(last+1, cur);
String navto = url.substring(cur+1, url.length());
if (callback_prefix.equals(protocol)) {
// navigate but still in native view
String cleared_url = url.substring(callback_prefix.length()+1, url.length());
return cleared_url;
}
// check protocol for nativeView
RhoNativeViewManager.RhoNativeView nvf = RhoNativeViewManager.getNativeViewByteType(protocol);
if (nvf != null) {
// we should switch to NativeView
//restoreWebView();
if (mNativeView != null) {
if ( !protocol.equals(mNativeView.getViewType()) ) {
setNativeView(nvf);
}
}
else {
setNativeView(nvf);
}
if (mNativeView != null) {
mNativeView.navigate(navto);
return "";
}
}
last = cur;
int c1 = url.indexOf(":", last+1);
int c2 = url.indexOf("/", last+1);
if ((c1 < c2)) {
if (c1 <= 0) {
cur = c2;
}
else {
cur = c1;
}
}
else {
if (c2 <= 0) {
cur = c1;
}
else {
cur = c2;
}
}
}
restoreWebView();
return url;
}
public WebView detachWebView() {
restoreWebView();
WebView v = null;
if (webView != null) {
view.removeView(webView);
v = webView;
webView = null;
}
return v;
}
private View createButton(Map