List of usage examples for android.widget Button Button
public Button(Context context)
From source file:org.zeroxlab.benchmark.Benchmark.java
private void initViews() { /*//from w ww .j av a2s . c o m mRun = (Button)findViewById(R.id.btn_run); mRun.setOnClickListener(this); mShow = (Button)findViewById(R.id.btn_show); mShow.setOnClickListener(this); mShow.setClickable(false); mLinearLayout = (LinearLayout)findViewById(R.id.list_container); mMainView = (LinearLayout)findViewById(R.id.main_view); mBannerInfo = (TextView)findViewById(R.id.banner_info); mBannerInfo.setText("Hello!\nSelect cases to Run.\nUploaded results:\nhttp://0xbenchmark.appspot.com"); */ mTabHost = getTabHost(); int length = mCases.size(); mCheckList = new CheckBox[length]; mDesc = new TextView[length]; for (int i = 0; i < length; i++) { mCheckList[i] = new CheckBox(this); mCheckList[i].setText(mCases.get(i).getTitle()); mDesc[i] = new TextView(this); mDesc[i].setText(mCases.get(i).getDescription()); mDesc[i].setTextSize(mDesc[i].getTextSize() - 2); mDesc[i].setPadding(42, 0, 10, 10); } TabContentFactory mTCF = new TabContentFactory() { public View createTabContent(String tag) { ViewGroup.LayoutParams fillParent = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT); ViewGroup.LayoutParams fillWrap = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams wrapContent = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); wrapContent.gravity = Gravity.CENTER; LinearLayout.LayoutParams weightedFillWrap = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); weightedFillWrap.weight = 1; if (tag.equals(MAIN)) { LinearLayout mMainView = new LinearLayout(Benchmark.this); mMainView.setOrientation(1); ScrollView mListScroll = new ScrollView(Benchmark.this); LinearLayout mMainViewContainer = new LinearLayout(Benchmark.this); mMainViewContainer.setOrientation(1); ImageView mIconView = new ImageView(Benchmark.this); mIconView.setImageResource(R.drawable.icon); TextView mBannerInfo = new TextView(Benchmark.this); mBannerInfo.setText("0xbench\nSelect benchmarks in the tabs,\nor batch select:"); d2CheckBox = new CheckBox(Benchmark.this); d2CheckBox.setText(D2); d2CheckBox.setOnClickListener(Benchmark.this); d2HWCheckBox = new CheckBox(Benchmark.this); d2HWCheckBox.setText(D2HW); d2HWCheckBox.setOnClickListener(Benchmark.this); d2SW1CheckBox = new CheckBox(Benchmark.this); d2SW1CheckBox.setText(D2SW1); d2SW1CheckBox.setOnClickListener(Benchmark.this); d2SW2CheckBox = new CheckBox(Benchmark.this); d2SW2CheckBox.setText(D2SW2); d2SW2CheckBox.setOnClickListener(Benchmark.this); d3CheckBox = new CheckBox(Benchmark.this); d3CheckBox.setText(D3); d3CheckBox.setOnClickListener(Benchmark.this); mathCheckBox = new CheckBox(Benchmark.this); mathCheckBox.setText(MATH); mathCheckBox.setOnClickListener(Benchmark.this); vmCheckBox = new CheckBox(Benchmark.this); vmCheckBox.setText(VM); vmCheckBox.setOnClickListener(Benchmark.this); nativeCheckBox = new CheckBox(Benchmark.this); nativeCheckBox.setText(NATIVE); nativeCheckBox.setOnClickListener(Benchmark.this); miscCheckBox = new CheckBox(Benchmark.this); miscCheckBox.setText(MISC); miscCheckBox.setOnClickListener(Benchmark.this); filterBitmapCheckBox = new CheckBox(Benchmark.this); filterBitmapCheckBox.setText("Filter Bitmap in Draw Image"); filterBitmapCheckBox.setOnClickListener(Benchmark.this); useGradientCheckBox = new CheckBox(Benchmark.this); useGradientCheckBox.setText("Use Gradient in Draw Canvas/Circle/Rect/Arc"); useGradientCheckBox.setOnClickListener(Benchmark.this); useTextureCheckBox = new CheckBox(Benchmark.this); useTextureCheckBox.setText("Use Texture in Draw Canvas/Circle/Rect/Arc"); useTextureCheckBox.setOnClickListener(Benchmark.this); TextView mWebInfo = new TextView(Benchmark.this); mWebInfo.setText("Uploaded results:\nhttp://0xbenchmark.appspot.com"); LinearLayout mButtonContainer = new LinearLayout(Benchmark.this); mRun = new Button(Benchmark.this); mShow = new Button(Benchmark.this); mRun.setText("Run"); mShow.setText("Show"); mRun.setOnClickListener(Benchmark.this); mShow.setOnClickListener(Benchmark.this); mButtonContainer.addView(mRun, weightedFillWrap); mButtonContainer.addView(mShow, weightedFillWrap); WebView mTracker = new WebView(Benchmark.this); mTracker.clearCache(true); mTracker.setWebViewClient(new WebViewClient() { public void onPageFinished(WebView view, String url) { Log.i(TAG, "Tracker: " + view.getTitle() + " -> " + url); } public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "Track err: " + description); } }); mTracker.loadUrl(trackerUrl); mMainViewContainer.addView(mIconView, wrapContent); mMainViewContainer.addView(mBannerInfo); mMainViewContainer.addView(mathCheckBox); mMainViewContainer.addView(d2CheckBox); mMainViewContainer.addView(d2HWCheckBox); mMainViewContainer.addView(d2SW1CheckBox); mMainViewContainer.addView(d2SW2CheckBox); mMainViewContainer.addView(d3CheckBox); mMainViewContainer.addView(vmCheckBox); mMainViewContainer.addView(nativeCheckBox); mMainViewContainer.addView(miscCheckBox); mMainViewContainer.addView(filterBitmapCheckBox); mMainViewContainer.addView(useGradientCheckBox); mMainViewContainer.addView(useTextureCheckBox); mMainViewContainer.addView(mWebInfo); mMainViewContainer.addView(mButtonContainer, fillWrap); mMainViewContainer.addView(mTracker, 0, 0); mListScroll.addView(mMainViewContainer, fillParent); mMainView.addView(mListScroll, fillWrap); return mMainView; } LinearLayout mMainView = new LinearLayout(Benchmark.this); mMainView.setOrientation(1); ScrollView mListScroll = new ScrollView(Benchmark.this); LinearLayout mListContainer = new LinearLayout(Benchmark.this); mListContainer.setOrientation(1); mListScroll.addView(mListContainer, fillParent); mMainView.addView(mListScroll, fillWrap); boolean gray = true; int length = mCases.size(); Log.i(TAG, "L: " + length); Log.i(TAG, "TCF: " + tag); for (int i = 0; i < length; i++) { if (!mCategory.get(tag).contains(mCases.get(i))) continue; Log.i(TAG, "Add: " + i); mListContainer.addView(mCheckList[i], fillWrap); mListContainer.addView(mDesc[i], fillWrap); if (gray) { int color = 0xFF333333; //ARGB mCheckList[i].setBackgroundColor(color); mDesc[i].setBackgroundColor(color); } gray = !gray; } return mMainView; } }; mTabHost.addTab(mTabHost.newTabSpec(MAIN).setIndicator(MAIN, getResources().getDrawable(R.drawable.ic_eye)) .setContent(mTCF)); mTabHost.addTab(mTabHost.newTabSpec(D2).setIndicator(D2, getResources().getDrawable(R.drawable.ic_2d)) .setContent(mTCF)); mTabHost.addTab(mTabHost.newTabSpec(D2HW).setIndicator(D2HW, getResources().getDrawable(R.drawable.ic_2d)) .setContent(mTCF)); mTabHost.addTab(mTabHost.newTabSpec(D2SW1).setIndicator(D2SW1, getResources().getDrawable(R.drawable.ic_2d)) .setContent(mTCF)); mTabHost.addTab(mTabHost.newTabSpec(D2SW2).setIndicator(D2SW2, getResources().getDrawable(R.drawable.ic_2d)) .setContent(mTCF)); mTabHost.addTab(mTabHost.newTabSpec(D3).setIndicator(D3, getResources().getDrawable(R.drawable.ic_3d)) .setContent(mTCF)); mTabHost.addTab(mTabHost.newTabSpec(MATH).setIndicator(MATH, getResources().getDrawable(R.drawable.ic_pi)) .setContent(mTCF)); mTabHost.addTab(mTabHost.newTabSpec(VM).setIndicator(VM, getResources().getDrawable(R.drawable.ic_vm)) .setContent(mTCF)); mTabHost.addTab(mTabHost.newTabSpec(NATIVE) .setIndicator(NATIVE, getResources().getDrawable(R.drawable.ic_c)).setContent(mTCF)); mTabHost.addTab(mTabHost.newTabSpec(MISC).setIndicator(MISC, getResources().getDrawable(R.drawable.ic_misc)) .setContent(mTCF)); }
From source file:com.dtworkshop.inappcrossbrowser.WebViewBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load. *//*from w w w. j a v a 2 s . c om*/ public String showWebPage(final String url, HashMap<String, Boolean> features) { // Determine if we should hide the location bar. showLocationBar = true; openWindowHidden = false; if (features != null) { Boolean show = features.get(LOCATION); if (show != null) { showLocationBar = show.booleanValue(); } Boolean hidden = features.get(HIDDEN); if (hidden != null) { openWindowHidden = hidden.booleanValue(); } Boolean cache = features.get(CLEAR_ALL_CACHE); if (cache != null) { clearAllCache = cache.booleanValue(); } else { cache = features.get(CLEAR_SESSION_CACHE); if (cache != null) { clearSessionCache = cache.booleanValue(); } } } final CordovaWebView thatWebView = this.webView; // Create dialog in new thread Runnable runnable = new Runnable() { /** * Convert our DIP units to Pixels * * @return int */ private int dpToPixels(int dipValue) { int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) dipValue, cordova.getActivity().getResources().getDisplayMetrics()); return value; } @SuppressLint("NewApi") public void run() { // Let's create the main dialog dialog = new InAppBrowserDialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar); dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog; dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCancelable(true); dialog.setInAppBroswer(getInAppBrowser()); // Main container layout LinearLayout main = new LinearLayout(cordova.getActivity()); main.setOrientation(LinearLayout.VERTICAL); // Toolbar layout RelativeLayout toolbar = new RelativeLayout(cordova.getActivity()); //Please, no more black! toolbar.setBackgroundColor(android.graphics.Color.LTGRAY); toolbar.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44))); toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2)); toolbar.setHorizontalGravity(Gravity.LEFT); toolbar.setVerticalGravity(Gravity.TOP); // Action Button Container layout RelativeLayout actionButtonContainer = new RelativeLayout(cordova.getActivity()); actionButtonContainer.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); actionButtonContainer.setHorizontalGravity(Gravity.LEFT); actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL); actionButtonContainer.setId(1); // Back button Button back = new Button(cordova.getActivity()); RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT); back.setLayoutParams(backLayoutParams); back.setContentDescription("Back Button"); back.setId(2); Resources activityRes = cordova.getActivity().getResources(); int backResId = activityRes.getIdentifier("ic_action_previous_item", "drawable", cordova.getActivity().getPackageName()); Drawable backIcon = activityRes.getDrawable(backResId); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { back.setBackgroundDrawable(backIcon); } else { back.setBackground(backIcon); } back.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goBack(); } }); // Forward button Button forward = new Button(cordova.getActivity()); RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2); forward.setLayoutParams(forwardLayoutParams); forward.setContentDescription("Forward Button"); forward.setId(3); int fwdResId = activityRes.getIdentifier("ic_action_next_item", "drawable", cordova.getActivity().getPackageName()); Drawable fwdIcon = activityRes.getDrawable(fwdResId); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { forward.setBackgroundDrawable(fwdIcon); } else { forward.setBackground(fwdIcon); } forward.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goForward(); } }); // Edit Text Box edittext = new EditText(cordova.getActivity()); RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1); textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5); edittext.setLayoutParams(textLayoutParams); edittext.setId(4); edittext.setSingleLine(true); edittext.setText(url); edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI); edittext.setImeOptions(EditorInfo.IME_ACTION_GO); edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE edittext.setOnKeyListener(new View.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { navigate(edittext.getText().toString()); return true; } return false; } }); // Close/Done button Button close = new Button(cordova.getActivity()); RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); close.setLayoutParams(closeLayoutParams); forward.setContentDescription("Close Button"); close.setId(5); int closeResId = activityRes.getIdentifier("ic_action_remove", "drawable", cordova.getActivity().getPackageName()); Drawable closeIcon = activityRes.getDrawable(closeResId); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { close.setBackgroundDrawable(closeIcon); } else { close.setBackground(closeIcon); } close.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { closeDialog(); } }); // WebView inAppWebView = new WebView(cordova.getActivity()); inAppWebView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView)); WebViewClient client = new InAppBrowserClient(thatWebView, edittext); inAppWebView.setWebViewClient(client); WebSettings settings = inAppWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setBuiltInZoomControls(true); settings.setPluginState(WebSettings.PluginState.ON); //Toggle whether this is enabled or not! Bundle appSettings = cordova.getActivity().getIntent().getExtras(); boolean enableDatabase = appSettings == null ? true : appSettings.getBoolean("InAppBrowserStorageEnabled", true); if (enableDatabase) { String databasePath = cordova.getActivity().getApplicationContext() .getDir("inAppBrowserDB", Context.MODE_PRIVATE).getPath(); settings.setDatabasePath(databasePath); settings.setDatabaseEnabled(true); } settings.setDomStorageEnabled(true); if (clearAllCache) { CookieManager.getInstance().removeAllCookie(); } else if (clearSessionCache) { CookieManager.getInstance().removeSessionCookie(); } inAppWebView.loadUrl(url); inAppWebView.setId(6); inAppWebView.getSettings().setLoadWithOverviewMode(true); inAppWebView.getSettings().setUseWideViewPort(true); inAppWebView.requestFocus(); inAppWebView.requestFocusFromTouch(); // Add the back and forward buttons to our action button container layout actionButtonContainer.addView(back); actionButtonContainer.addView(forward); // Add the views to our toolbar toolbar.addView(actionButtonContainer); toolbar.addView(edittext); toolbar.addView(close); // Don't add the toolbar if its been disabled if (getShowLocationBar()) { // Add our toolbar to our main view/layout main.addView(toolbar); } // Add our webview to our main view/layout main.addView(inAppWebView); LayoutParams lp = new LayoutParams(); lp.copyFrom(dialog.getWindow().getAttributes()); lp.width = LayoutParams.MATCH_PARENT; lp.height = LayoutParams.MATCH_PARENT; dialog.setContentView(main); dialog.show(); dialog.getWindow().setAttributes(lp); // the goal of openhidden is to load the url and not display it // Show() needs to be called to cause the URL to be loaded if (openWindowHidden) { dialog.hide(); } } }; this.cordova.getActivity().runOnUiThread(runnable); return ""; }
From source file:org.apache.cordova.inappbrowser.InAppBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load. * @param jsonObject//from w w w . j a v a2s. c o m */ public String showWebPage(final String url, HashMap<String, Boolean> features) { // Determine if we should hide the location bar. showLocationBar = true; openWindowHidden = false; if (features != null) { Boolean show = features.get(LOCATION); if (show != null) { showLocationBar = show.booleanValue(); } Boolean hidden = features.get(HIDDEN); if (hidden != null) { openWindowHidden = hidden.booleanValue(); } Boolean cache = features.get(CLEAR_ALL_CACHE); if (cache != null) { clearAllCache = cache.booleanValue(); } else { cache = features.get(CLEAR_SESSION_CACHE); if (cache != null) { clearSessionCache = cache.booleanValue(); } } } final CordovaWebView thatWebView = this.webView; // Create dialog in new thread Runnable runnable = new Runnable() { /** * Convert our DIP units to Pixels * * @return int */ private int dpToPixels(int dipValue) { int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) dipValue, cordova.getActivity().getResources().getDisplayMetrics()); return value; } @SuppressLint("NewApi") public void run() { // Let's create the main dialog dialog = new InAppBrowserDialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar); dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog; dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCancelable(true); dialog.setInAppBroswer(getInAppBrowser()); // Main container layout LinearLayout main = new LinearLayout(cordova.getActivity()); main.setOrientation(LinearLayout.VERTICAL); // Toolbar layout RelativeLayout toolbar = new RelativeLayout(cordova.getActivity()); //Please, no more black! toolbar.setBackgroundColor(android.graphics.Color.LTGRAY); toolbar.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44))); toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2)); toolbar.setHorizontalGravity(Gravity.LEFT); toolbar.setVerticalGravity(Gravity.TOP); // Action Button Container layout RelativeLayout actionButtonContainer = new RelativeLayout(cordova.getActivity()); actionButtonContainer.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); actionButtonContainer.setHorizontalGravity(Gravity.LEFT); actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL); actionButtonContainer.setId(1); // Back button Button back = new Button(cordova.getActivity()); RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT); back.setLayoutParams(backLayoutParams); back.setContentDescription("Back Button"); back.setId(2); Resources activityRes = cordova.getActivity().getResources(); int backResId = activityRes.getIdentifier("ic_action_previous_item", "drawable", cordova.getActivity().getPackageName()); Drawable backIcon = activityRes.getDrawable(backResId); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { back.setBackgroundDrawable(backIcon); } else { back.setBackground(backIcon); } back.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goBack(); } }); // Forward button Button forward = new Button(cordova.getActivity()); RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2); forward.setLayoutParams(forwardLayoutParams); forward.setContentDescription("Forward Button"); forward.setId(3); int fwdResId = activityRes.getIdentifier("ic_action_next_item", "drawable", cordova.getActivity().getPackageName()); Drawable fwdIcon = activityRes.getDrawable(fwdResId); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { forward.setBackgroundDrawable(fwdIcon); } else { forward.setBackground(fwdIcon); } forward.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goForward(); } }); // Edit Text Box edittext = new EditText(cordova.getActivity()); RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1); textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5); edittext.setLayoutParams(textLayoutParams); edittext.setId(4); edittext.setSingleLine(true); edittext.setText(url); edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI); edittext.setImeOptions(EditorInfo.IME_ACTION_GO); edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE edittext.setOnKeyListener(new View.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { navigate(edittext.getText().toString()); return true; } return false; } }); // Close/Done button Button close = new Button(cordova.getActivity()); RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); close.setLayoutParams(closeLayoutParams); forward.setContentDescription("Close Button"); close.setId(5); int closeResId = activityRes.getIdentifier("ic_action_remove", "drawable", cordova.getActivity().getPackageName()); Drawable closeIcon = activityRes.getDrawable(closeResId); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { close.setBackgroundDrawable(closeIcon); } else { close.setBackground(closeIcon); } close.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { closeDialog(); } }); // WebView inAppWebView = new WebView(cordova.getActivity()); inAppWebView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView)); WebViewClient client = new InAppBrowserClient(thatWebView, edittext); inAppWebView.setWebViewClient(client); WebSettings settings = inAppWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setBuiltInZoomControls(true); settings.setPluginState(android.webkit.WebSettings.PluginState.ON); //Toggle whether this is enabled or not! Bundle appSettings = cordova.getActivity().getIntent().getExtras(); boolean enableDatabase = appSettings == null ? true : appSettings.getBoolean("InAppBrowserStorageEnabled", true); if (enableDatabase) { String databasePath = cordova.getActivity().getApplicationContext() .getDir("inAppBrowserDB", Context.MODE_PRIVATE).getPath(); settings.setDatabasePath(databasePath); settings.setDatabaseEnabled(true); } settings.setDomStorageEnabled(true); if (clearAllCache) { CookieManager.getInstance().removeAllCookie(); } else if (clearSessionCache) { CookieManager.getInstance().removeSessionCookie(); } inAppWebView.loadUrl(url); inAppWebView.setId(6); inAppWebView.getSettings().setLoadWithOverviewMode(true); inAppWebView.getSettings().setUseWideViewPort(true); inAppWebView.requestFocus(); inAppWebView.requestFocusFromTouch(); // Add the back and forward buttons to our action button container layout actionButtonContainer.addView(back); actionButtonContainer.addView(forward); // Add the views to our toolbar toolbar.addView(actionButtonContainer); toolbar.addView(edittext); toolbar.addView(close); // Don't add the toolbar if its been disabled if (getShowLocationBar()) { // Add our toolbar to our main view/layout main.addView(toolbar); } // Add our webview to our main view/layout main.addView(inAppWebView); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(dialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.MATCH_PARENT; lp.height = WindowManager.LayoutParams.MATCH_PARENT; dialog.setContentView(main); dialog.show(); dialog.getWindow().setAttributes(lp); // the goal of openhidden is to load the url and not display it // Show() needs to be called to cause the URL to be loaded if (openWindowHidden) { dialog.hide(); } } }; this.cordova.getActivity().runOnUiThread(runnable); return ""; }
From source file:se.liu.tddd77.bilsensor.MainActivity.java
@SuppressLint("UseValueOf") public void addNewDynamicEventString(String name) { //TODO: Storlek p denna ruta mste hllas konstant. if (name == null || name.isEmpty()) { Toast.makeText(this, "Dynamic Events require a name.", Toast.LENGTH_SHORT).show(); return;//w w w .j a va 2 s . c om } //TODO: r this korrekt? LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.HORIZONTAL); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);//(LinearLayout.LayoutParams)layout.getLayoutParams(); layout.setLayoutParams(params); Button button = new Button(this); buttonList.add(button); LinearLayout.LayoutParams buttonparams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT, 1.0f); button.setLayoutParams(buttonparams); button.setText(name); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { try { Backend.getInstance().sendDynamicMessage((Long) (System.currentTimeMillis() / 1000L), ((Button) v).getText().toString()); } catch (BackendError e) { e.printStackTrace(); } } }); Button rmEventButton = new Button(this); LinearLayout.LayoutParams rmButtonparams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT, 0.0f); rmEventButton.setLayoutParams(rmButtonparams); rmEventButton.setText("-"); rmEventButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //TODO: For-loop through trying to find the one with matching name? buttonList.remove(((Button) ((LinearLayout) v.getParent()).getChildAt(0))); ((LinearLayout) v.getParent().getParent()).removeView((LinearLayout) v.getParent()); } }); layout.addView(button); layout.addView(rmEventButton); ((LinearLayout) findViewById(R.id.dynamic_events_buttons_container)).addView(layout); //((LinearLayout)((LinearLayout)(view.getParent().getParent())).getChildAt(1)).addView(layout); //((LinearLayout) ((LinearLayout)(view.getParent().getParent()))findViewById(R.id.dynamic_events_buttons_container)).addView(button); //textfield.setText(""); }
From source file:org.openremote.android.console.AppSettingsActivity.java
/** * It contains a list view to display custom servers, * "Add" button to add custom server, "Delete" button to delete custom server. * The custom servers would be saved in customServers.xml. If click a list item, it would be saved as current server. * //from w w w . j av a 2s. c om * @return the linear layout */ private LinearLayout constructCustomServersView() { LinearLayout custumeView = new LinearLayout(this); custumeView.setOrientation(LinearLayout.VERTICAL); custumeView.setPadding(20, 5, 5, 0); custumeView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); ArrayList<String> customServers = new ArrayList<String>(); initCustomServersFromFile(customServers); RelativeLayout buttonsView = new RelativeLayout(this); buttonsView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, 80)); Button addServer = new Button(this); addServer.setWidth(80); RelativeLayout.LayoutParams addServerLayout = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); addServerLayout.addRule(RelativeLayout.CENTER_HORIZONTAL); addServer.setLayoutParams(addServerLayout); addServer.setText("Add"); addServer.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent intent = new Intent(); intent.setClass(AppSettingsActivity.this, AddServerActivity.class); startActivityForResult(intent, Constants.REQUEST_CODE); } }); Button deleteServer = new Button(this); deleteServer.setWidth(80); RelativeLayout.LayoutParams deleteServerLayout = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); deleteServerLayout.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); deleteServer.setLayoutParams(deleteServerLayout); deleteServer.setText("Delete"); deleteServer.setOnClickListener(new OnClickListener() { @SuppressWarnings("unchecked") public void onClick(View v) { int checkedPosition = customListView.getCheckedItemPosition(); if (!(checkedPosition == ListView.INVALID_POSITION)) { customListView.setItemChecked(checkedPosition, false); ((ArrayAdapter<String>) customListView.getAdapter()) .remove(customListView.getItemAtPosition(checkedPosition).toString()); currentServer = ""; AppSettingsModel.setCurrentServer(AppSettingsActivity.this, currentServer); writeCustomServerToFile(); } } }); buttonsView.addView(addServer); buttonsView.addView(deleteServer); customListView = new ListView(this); customListView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, 200)); customListView.setCacheColorHint(0); final ArrayAdapter<String> serverListAdapter = new ArrayAdapter<String>(appSettingsView.getContext(), R.layout.server_list_item, customServers); customListView.setAdapter(serverListAdapter); customListView.setItemsCanFocus(true); customListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); if (currentCustomServerIndex != -1) { customListView.setItemChecked(currentCustomServerIndex, true); currentServer = (String) customListView.getItemAtPosition(currentCustomServerIndex); } customListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { currentServer = (String) parent.getItemAtPosition(position); AppSettingsModel.setCurrentServer(AppSettingsActivity.this, currentServer); writeCustomServerToFile(); requestPanelList(); checkAuthentication(); requestAccess(); } }); custumeView.addView(customListView); custumeView.addView(buttonsView); requestPanelList(); checkAuthentication(); requestAccess(); return custumeView; }
From source file:de.cachebox_test.splash.java
@SuppressWarnings("deprecation") @Override/*from w w w .j a v a 2 s. c om*/ protected void onStart() { super.onStart(); Log.debug(log, "onStart"); if (android.os.Build.VERSION.SDK_INT >= 23) { PermissionCheck.checkNeededPermissions(this); } // initial GDX Gdx.files = new AndroidFiles(this.getAssets(), this.getFilesDir().getAbsolutePath()); // first, try to find stored preferences of workPath androidSetting = this.getSharedPreferences(Global.PREFS_NAME, 0); workPath = androidSetting.getString("WorkPath", Environment.getDataDirectory() + "/cachebox"); boolean askAgain = androidSetting.getBoolean("AskAgain", true); showSandbox = androidSetting.getBoolean("showSandbox", false); Global.initTheme(this); Global.InitIcons(this); CB_Android_FileExplorer fileExplorer = new CB_Android_FileExplorer(this); PlatformConnector.setGetFileListener(fileExplorer); PlatformConnector.setGetFolderListener(fileExplorer); String LangPath = androidSetting.getString("Sel_LanguagePath", ""); if (LangPath.length() == 0) { // set default lang String locale = Locale.getDefault().getLanguage(); if (locale.contains("de")) { LangPath = "data/lang/de/strings.ini"; } else if (locale.contains("cs")) { LangPath = "data/lang/cs/strings.ini"; } else if (locale.contains("cs")) { LangPath = "data/lang/cs/strings.ini"; } else if (locale.contains("fr")) { LangPath = "data/lang/fr/strings.ini"; } else if (locale.contains("nl")) { LangPath = "data/lang/nl/strings.ini"; } else if (locale.contains("pl")) { LangPath = "data/lang/pl/strings.ini"; } else if (locale.contains("pt")) { LangPath = "data/lang/pt/strings.ini"; } else if (locale.contains("hu")) { LangPath = "data/lang/hu/strings.ini"; } else { LangPath = "data/lang/en-GB/strings.ini"; } } new Translation(workPath, FileType.Internal); try { Translation.LoadTranslation(LangPath); } catch (Exception e) { e.printStackTrace(); } // check Write permission if (!askAgain) { if (!FileIO.checkWritePermission(workPath)) { askAgain = true; if (!ToastEx) { ToastEx = true; String WriteProtectionMsg = Translation.Get("NoWriteAcces"); Toast.makeText(splash.this, WriteProtectionMsg, Toast.LENGTH_LONG).show(); } } } if ((askAgain)) { // no saved workPath found -> search sd-cards and if more than 1 is found give the user the possibility to select one String externalSd = getExternalSdPath("/CacheBox"); boolean hasExtSd; final String externalSd2 = externalSd; if (externalSd != null) { hasExtSd = (externalSd.length() > 0) && (!externalSd.equalsIgnoreCase(workPath)); } else { hasExtSd = false; } // externe SD wurde gefunden != internal // oder Tablet Layout mglich // -> Auswahldialog anzeigen try { final Dialog dialog = new Dialog(context) { @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { splash.this.finish(); } return super.onKeyDown(keyCode, event); } }; dialog.setContentView(R.layout.sdselectdialog); TextView title = (TextView) dialog.findViewById(R.id.select_sd_title); title.setText(Translation.Get("selectWorkSpace") + "\n\n"); /* * TextView tbLayout = (TextView) dialog.findViewById(R.id.select_sd_layout); tbLayout.setText("\nLayout"); final RadioGroup * rgLayout = (RadioGroup) dialog.findViewById(R.id.select_sd_radiogroup); final RadioButton rbHandyLayout = (RadioButton) * dialog.findViewById(R.id.select_sd_handylayout); final RadioButton rbTabletLayout = (RadioButton) * dialog.findViewById(R.id.select_sd_tabletlayout); rbHandyLayout.setText("Handy-Layout"); * rbTabletLayout.setText("Tablet-Layout"); if (!GlobalCore.posibleTabletLayout) { * rgLayout.setVisibility(RadioGroup.INVISIBLE); rbHandyLayout.setChecked(true); } else { if (GlobalCore.isTab) { * rbTabletLayout.setChecked(true); } else { rbHandyLayout.setChecked(true); } } */ final CheckBox cbAskAgain = (CheckBox) dialog.findViewById(R.id.select_sd_askagain); cbAskAgain.setText(Translation.Get("AskAgain")); cbAskAgain.setChecked(askAgain); Button buttonI = (Button) dialog.findViewById(R.id.button1); buttonI.setText("Internal SD\n\n" + workPath); buttonI.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // close select dialog dialog.dismiss(); // show please wait dialog showPleaseWaitDialog(); // use internal SD -> nothing to change Thread thread = new Thread() { @Override public void run() { boolean askAgain = cbAskAgain.isChecked(); // boolean useTabletLayout = rbTabletLayout.isChecked(); saveWorkPath(askAgain/* , useTabletLayout */); dialog.dismiss(); startInitial(); } }; thread.start(); } }); Button buttonE = (Button) dialog.findViewById(R.id.button2); final boolean isSandbox = externalSd == null ? false : externalSd.contains("Android/data/de.cachebox_test"); if (!hasExtSd) { buttonE.setVisibility(Button.INVISIBLE); } else { String extSdText = isSandbox ? "External SD SandBox\n\n" : "External SD\n\n"; buttonE.setText(extSdText + externalSd); } buttonE.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // show KitKat Massage? if (isSandbox && !showSandbox) { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context); // set title alertDialogBuilder.setTitle("KitKat Sandbox"); // set dialog message alertDialogBuilder.setMessage(Translation.Get("Desc_Sandbox")).setCancelable(false) .setPositiveButton(Translation.Get("yes"), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { // if this button is clicked, run Sandbox Path showSandbox = true; Config.AcceptChanges(); // close select dialog dialog.dismiss(); // show please wait dialog showPleaseWaitDialog(); // use external SD -> change workPath Thread thread = new Thread() { @Override public void run() { workPath = externalSd2; boolean askAgain = cbAskAgain.isChecked(); // boolean useTabletLayout = rbTabletLayout.isChecked(); saveWorkPath(askAgain/* , useTabletLayout */); startInitial(); } }; thread.start(); } }) .setNegativeButton(Translation.Get("no"), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { // if this button is clicked, just close // the dialog box and do nothing dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); } else { // close select dialog dialog.dismiss(); // show please wait dialog showPleaseWaitDialog(); // use external SD -> change workPath Thread thread = new Thread() { @Override public void run() { workPath = externalSd2; boolean askAgain = cbAskAgain.isChecked(); // boolean useTabletLayout = rbTabletLayout.isChecked(); saveWorkPath(askAgain/* , useTabletLayout */); startInitial(); } }; thread.start(); } } }); LinearLayout ll = (LinearLayout) dialog.findViewById(R.id.scrollViewLinearLayout); // add all Buttons for created Workspaces AdditionalWorkPathArray = getAdditionalWorkPathArray(); for (final String AddWorkPath : AdditionalWorkPathArray) { final String Name = FileIO.GetFileNameWithoutExtension(AddWorkPath); if (!FileIO.checkWritePermission(AddWorkPath)) { // delete this Work Path deleteWorkPath(AddWorkPath); continue; } Button buttonW = new Button(context); buttonW.setText(Name + "\n\n" + AddWorkPath); buttonW.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { // setting the MassageBox then the UI_sizes are not initial in this moment Resources res = splash.this.getResources(); float scale = res.getDisplayMetrics().density; float calcBase = 533.333f * scale; FrameLayout frame = (FrameLayout) findViewById(R.id.frameLayout1); int width = frame.getMeasuredWidth(); int height = frame.getMeasuredHeight(); MessageBox.Builder.WindowWidth = width; MessageBox.Builder.WindowHeight = height; MessageBox.Builder.textSize = (calcBase / res.getDimensionPixelSize(R.dimen.BtnTextSize)) * scale; MessageBox.Builder.ButtonHeight = (int) (50 * scale); // Ask before delete msg = (MessageBox) MessageBox.Show(Translation.Get("shuredeleteWorkspace", Name), Translation.Get("deleteWorkspace"), MessageBoxButtons.YesNo, MessageBoxIcon.Question, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (which == MessageBox.BUTTON_POSITIVE) { // Delete this Workpath only from Settings don't delete any File deleteWorkPath(AddWorkPath); } // Start again to exclude the old Folder msg.dismiss(); onStart(); } }); dialog.dismiss(); return true; } }); buttonW.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // close select dialog dialog.dismiss(); // show please wait dialog showPleaseWaitDialog(); // use external SD -> change workPath Thread thread = new Thread() { @Override public void run() { workPath = AddWorkPath; boolean askAgain = cbAskAgain.isChecked(); // boolean useTabletLayout = rbTabletLayout.isChecked(); saveWorkPath(askAgain/* , useTabletLayout */); startInitial(); } }; thread.start(); } }); ll.addView(buttonW); } Button buttonC = (Button) dialog.findViewById(R.id.buttonCreateWorkspace); buttonC.setText(Translation.Get("createWorkSpace")); buttonC.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // close select dialog dialog.dismiss(); getFolderReturnListener = new IgetFolderReturnListener() { @Override public void getFolderReturn(String Path) { if (FileIO.checkWritePermission(Path)) { AdditionalWorkPathArray.add(Path); writeAdditionalWorkPathArray(AdditionalWorkPathArray); // Start again to include the new Folder onStart(); } else { String WriteProtectionMsg = Translation.Get("NoWriteAcces"); Toast.makeText(splash.this, WriteProtectionMsg, Toast.LENGTH_LONG).show(); } } }; PlatformConnector.getFolder("", Translation.Get("select_folder"), Translation.Get("select"), getFolderReturnListener); } }); dialog.show(); } catch (Exception ex) { ex.printStackTrace(); } } else { if (GlobalCore.displayType == DisplayType.Large || GlobalCore.displayType == DisplayType.xLarge) GlobalCore.isTab = isLandscape; // restore the saved workPath // test whether workPath is available by checking the free size on the SD String workPathToTest = workPath.substring(0, workPath.lastIndexOf("/")); long bytesAvailable = 0; try { StatFs stat = new StatFs(workPathToTest); bytesAvailable = (long) stat.getBlockSize() * (long) stat.getBlockCount(); } catch (Exception ex) { bytesAvailable = 0; } if (bytesAvailable == 0) { // there is a workPath stored but this workPath is not available at the moment (maybe SD is removed) Toast.makeText(splashActivity, "WorkPath " + workPath + " is not available!\nMaybe SD-Card is removed?", Toast.LENGTH_LONG) .show(); finish(); return; } startInitial(); } }
From source file:com.google.sample.beaconservice.ManageBeaconFragment.java
private Button createAttachmentDeleteButton(final int viewId, final String attachmentName) { final Button button = new Button(getActivity()); button.setLayoutParams(BUTTON_COL_LAYOUT); button.setText("-"); button.setOnClickListener(new View.OnClickListener() { @Override// w w w . j a va2 s .com public void onClick(View v) { Utils.setEnabledViews(false, button); Callback deleteAttachmentCallback = new Callback() { @Override public void onFailure(Request request, IOException e) { logErrorAndToast("Failed request: " + request, e); } @Override public void onResponse(Response response) throws IOException { if (response.isSuccessful()) { attachmentsTable.removeView(attachmentsTable.findViewById(viewId)); } else { String body = response.body().string(); logErrorAndToast("Unsuccessful deleteAttachment request: " + body); } } }; client.deleteAttachment(deleteAttachmentCallback, attachmentName); } }); return button; }
From source file:com.webcomm.plugin.CustomInAppBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load. * @param jsonObject//w w w . jav a2s . co m */ public String showWebPage(final String url, HashMap<String, Boolean> features) { // Determine if we should hide the location bar. showLocationBar = true; openWindowHidden = false; if (features != null) { Boolean show = features.get(LOCATION); if (show != null) { showLocationBar = show.booleanValue(); } Boolean hidden = features.get(HIDDEN); if (hidden != null) { openWindowHidden = hidden.booleanValue(); } Boolean cache = features.get(CLEAR_ALL_CACHE); if (cache != null) { clearAllCache = cache.booleanValue(); } else { cache = features.get(CLEAR_SESSION_CACHE); if (cache != null) { clearSessionCache = cache.booleanValue(); } } } final CordovaWebView thatWebView = this.webView; // Create dialog in new thread Runnable runnable = new Runnable() { /** * Convert our DIP units to Pixels * * @return int */ private int dpToPixels(int dipValue) { int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) dipValue, cordova.getActivity().getResources().getDisplayMetrics()); return value; } @SuppressLint("NewApi") public void run() { // Let's create the main dialog dialog = new CustomInAppBrowserDialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar); dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog; dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCancelable(true); dialog.setInAppBroswer(getInAppBrowser()); // Main container layout LinearLayout main = new LinearLayout(cordova.getActivity()); main.setOrientation(LinearLayout.VERTICAL); // Toolbar layout RelativeLayout toolbar = new RelativeLayout(cordova.getActivity()); //Please, no more black! toolbar.setBackgroundColor(android.graphics.Color.LTGRAY); toolbar.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44))); toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2)); toolbar.setHorizontalGravity(Gravity.LEFT); toolbar.setVerticalGravity(Gravity.TOP); // Action Button Container layout RelativeLayout actionButtonContainer = new RelativeLayout(cordova.getActivity()); actionButtonContainer.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); actionButtonContainer.setHorizontalGravity(Gravity.LEFT); actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL); actionButtonContainer.setId(1); // Back button Button back = new Button(cordova.getActivity()); RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT); back.setLayoutParams(backLayoutParams); back.setContentDescription("Back Button"); back.setId(2); Resources activityRes = cordova.getActivity().getResources(); int backResId = activityRes.getIdentifier("ic_action_previous_item", "drawable", cordova.getActivity().getPackageName()); Drawable backIcon = activityRes.getDrawable(backResId); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { back.setBackgroundDrawable(backIcon); } else { back.setBackground(backIcon); } back.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goBack(); } }); // Forward button Button forward = new Button(cordova.getActivity()); RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2); forward.setLayoutParams(forwardLayoutParams); forward.setContentDescription("Forward Button"); forward.setId(3); int fwdResId = activityRes.getIdentifier("ic_action_next_item", "drawable", cordova.getActivity().getPackageName()); Drawable fwdIcon = activityRes.getDrawable(fwdResId); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { forward.setBackgroundDrawable(fwdIcon); } else { forward.setBackground(fwdIcon); } forward.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goForward(); } }); // Edit Text Box edittext = new EditText(cordova.getActivity()); RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1); textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5); edittext.setLayoutParams(textLayoutParams); edittext.setId(4); edittext.setSingleLine(true); edittext.setText(url); edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI); edittext.setImeOptions(EditorInfo.IME_ACTION_GO); edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE edittext.setOnKeyListener(new View.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { navigate(edittext.getText().toString()); return true; } return false; } }); // Close/Done button Button close = new Button(cordova.getActivity()); RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); close.setLayoutParams(closeLayoutParams); forward.setContentDescription("Close Button"); close.setId(5); int closeResId = activityRes.getIdentifier("ic_action_remove", "drawable", cordova.getActivity().getPackageName()); Drawable closeIcon = activityRes.getDrawable(closeResId); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { close.setBackgroundDrawable(closeIcon); } else { close.setBackground(closeIcon); } close.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { closeDialog(); } }); // WebView inAppWebView = new WebView(cordova.getActivity()); inAppWebView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); inAppWebView.setWebChromeClient(new CustomInAppChromeClient(thatWebView)); // [Modify] inAppWebView.addJavascriptInterface( new WebAppInterface(cordova.getActivity().getApplicationContext()), "CustomInAppBrowser"); WebViewClient client = new InAppBrowserClient(thatWebView, edittext); inAppWebView.setWebViewClient(client); WebSettings settings = inAppWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setBuiltInZoomControls(true); settings.setPluginState(android.webkit.WebSettings.PluginState.ON); //Toggle whether this is enabled or not! Bundle appSettings = cordova.getActivity().getIntent().getExtras(); boolean enableDatabase = appSettings == null ? true : appSettings.getBoolean("InAppBrowserStorageEnabled", true); if (enableDatabase) { String databasePath = cordova.getActivity().getApplicationContext() .getDir("inAppBrowserDB", Context.MODE_PRIVATE).getPath(); settings.setDatabasePath(databasePath); settings.setDatabaseEnabled(true); } settings.setDomStorageEnabled(true); if (clearAllCache) { CookieManager.getInstance().removeAllCookie(); } else if (clearSessionCache) { CookieManager.getInstance().removeSessionCookie(); } inAppWebView.loadUrl(url); inAppWebView.setId(6); inAppWebView.getSettings().setLoadWithOverviewMode(true); inAppWebView.getSettings().setUseWideViewPort(true); inAppWebView.requestFocus(); inAppWebView.requestFocusFromTouch(); // Add the back and forward buttons to our action button container layout actionButtonContainer.addView(back); actionButtonContainer.addView(forward); // Add the views to our toolbar toolbar.addView(actionButtonContainer); toolbar.addView(edittext); toolbar.addView(close); // Don't add the toolbar if its been disabled if (getShowLocationBar()) { // Add our toolbar to our main view/layout main.addView(toolbar); } // Add our webview to our main view/layout main.addView(inAppWebView); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(dialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.MATCH_PARENT; lp.height = WindowManager.LayoutParams.MATCH_PARENT; dialog.setContentView(main); dialog.show(); dialog.getWindow().setAttributes(lp); // the goal of openhidden is to load the url and not display it // Show() needs to be called to cause the URL to be loaded if (openWindowHidden) { dialog.hide(); } } }; this.cordova.getActivity().runOnUiThread(runnable); return ""; }
From source file:org.apache.cordova.inappbrowser.InAppBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load. * @param jsonObject//from w ww . j a v a 2 s .co m */ public String showWebPage(final String url, HashMap<String, Boolean> features) { // Determine if we should hide the location bar. showLocationBar = true; showZoomControls = true; openWindowHidden = false; if (features != null) { Boolean show = features.get(LOCATION); if (show != null) { showLocationBar = show.booleanValue(); } Boolean zoom = features.get(ZOOM); if (zoom != null) { showZoomControls = zoom.booleanValue(); } Boolean hidden = features.get(HIDDEN); if (hidden != null) { openWindowHidden = hidden.booleanValue(); } Boolean hardwareBack = features.get(HARDWARE_BACK_BUTTON); if (hardwareBack != null) { hadwareBackButton = hardwareBack.booleanValue(); } Boolean cache = features.get(CLEAR_ALL_CACHE); if (cache != null) { clearAllCache = cache.booleanValue(); } else { cache = features.get(CLEAR_SESSION_CACHE); if (cache != null) { clearSessionCache = cache.booleanValue(); } } } final CordovaWebView thatWebView = this.webView; // Create dialog in new thread Runnable runnable = new Runnable() { /** * Convert our DIP units to Pixels * * @return int */ private int dpToPixels(int dipValue) { int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) dipValue, cordova.getActivity().getResources().getDisplayMetrics()); return value; } @SuppressLint("NewApi") public void run() { // Let's create the main dialog dialog = new InAppBrowserDialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar); dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog; dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCancelable(true); dialog.setInAppBroswer(getInAppBrowser()); // Main container layout LinearLayout main = new LinearLayout(cordova.getActivity()); main.setOrientation(LinearLayout.VERTICAL); // Toolbar layout RelativeLayout toolbar = new RelativeLayout(cordova.getActivity()); //Please, no more black! toolbar.setBackgroundColor(android.graphics.Color.LTGRAY); toolbar.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44))); toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2)); toolbar.setHorizontalGravity(Gravity.LEFT); toolbar.setVerticalGravity(Gravity.TOP); // Action Button Container layout RelativeLayout actionButtonContainer = new RelativeLayout(cordova.getActivity()); actionButtonContainer.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); actionButtonContainer.setHorizontalGravity(Gravity.LEFT); actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL); actionButtonContainer.setId(1); // Back button Button back = new Button(cordova.getActivity()); RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT); back.setLayoutParams(backLayoutParams); back.setContentDescription("Back Button"); back.setId(2); Resources activityRes = cordova.getActivity().getResources(); int backResId = activityRes.getIdentifier("ic_action_previous_item", "drawable", cordova.getActivity().getPackageName()); Drawable backIcon = activityRes.getDrawable(backResId); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { back.setBackgroundDrawable(backIcon); } else { back.setBackground(backIcon); } back.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goBack(); } }); // Forward button Button forward = new Button(cordova.getActivity()); RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2); forward.setLayoutParams(forwardLayoutParams); forward.setContentDescription("Forward Button"); forward.setId(3); int fwdResId = activityRes.getIdentifier("ic_action_next_item", "drawable", cordova.getActivity().getPackageName()); Drawable fwdIcon = activityRes.getDrawable(fwdResId); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { forward.setBackgroundDrawable(fwdIcon); } else { forward.setBackground(fwdIcon); } forward.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goForward(); } }); // Edit Text Box edittext = new EditText(cordova.getActivity()); RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1); textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5); edittext.setLayoutParams(textLayoutParams); edittext.setId(4); edittext.setSingleLine(true); edittext.setText(url); edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI); edittext.setImeOptions(EditorInfo.IME_ACTION_GO); edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE edittext.setOnKeyListener(new View.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { navigate(edittext.getText().toString()); return true; } return false; } }); // Close/Done button Button close = new Button(cordova.getActivity()); RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); close.setLayoutParams(closeLayoutParams); forward.setContentDescription("Close Button"); close.setId(5); int closeResId = activityRes.getIdentifier("ic_action_remove", "drawable", cordova.getActivity().getPackageName()); Drawable closeIcon = activityRes.getDrawable(closeResId); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { close.setBackgroundDrawable(closeIcon); } else { close.setBackground(closeIcon); } close.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { closeDialog(); } }); // WebView inAppWebView = new WebView(cordova.getActivity()); inAppWebView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView)); WebViewClient client = new InAppBrowserClient(thatWebView, edittext); inAppWebView.setWebViewClient(client); WebSettings settings = inAppWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setBuiltInZoomControls(getShowZoomControls()); settings.setPluginState(android.webkit.WebSettings.PluginState.ON); //Toggle whether this is enabled or not! Bundle appSettings = cordova.getActivity().getIntent().getExtras(); boolean enableDatabase = appSettings == null ? true : appSettings.getBoolean("InAppBrowserStorageEnabled", true); if (enableDatabase) { String databasePath = cordova.getActivity().getApplicationContext() .getDir("inAppBrowserDB", Context.MODE_PRIVATE).getPath(); settings.setDatabasePath(databasePath); settings.setDatabaseEnabled(true); } settings.setDomStorageEnabled(true); if (clearAllCache) { CookieManager.getInstance().removeAllCookie(); } else if (clearSessionCache) { CookieManager.getInstance().removeSessionCookie(); } inAppWebView.loadUrl(url); inAppWebView.setId(6); inAppWebView.getSettings().setLoadWithOverviewMode(true); inAppWebView.getSettings().setUseWideViewPort(true); inAppWebView.requestFocus(); inAppWebView.requestFocusFromTouch(); // Add the back and forward buttons to our action button container layout actionButtonContainer.addView(back); actionButtonContainer.addView(forward); // Add the views to our toolbar toolbar.addView(actionButtonContainer); toolbar.addView(edittext); toolbar.addView(close); // Don't add the toolbar if its been disabled if (getShowLocationBar()) { // Add our toolbar to our main view/layout main.addView(toolbar); } // Add our webview to our main view/layout main.addView(inAppWebView); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(dialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.MATCH_PARENT; lp.height = WindowManager.LayoutParams.MATCH_PARENT; dialog.setContentView(main); dialog.show(); dialog.getWindow().setAttributes(lp); // the goal of openhidden is to load the url and not display it // Show() needs to be called to cause the URL to be loaded if (openWindowHidden) { dialog.hide(); } } }; this.cordova.getActivity().runOnUiThread(runnable); return ""; }
From source file:com.mobiroller.tools.inappbrowser.MobirollerInAppBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load. * @param jsonObject/*from w w w .j a v a 2 s . c o m*/ */ public String showWebPage(final String url, final HashMap<String, Boolean> features) { // Determine if we should hide the location bar. showLocationBar = true; showZoomControls = false; openWindowHidden = false; if (features != null) { Boolean show = features.get(LOCATION); if (show != null) { showLocationBar = show.booleanValue(); } Boolean zoom = features.get(ZOOM); if (zoom != null) { showZoomControls = zoom.booleanValue(); } Boolean hidden = features.get(HIDDEN); if (hidden != null) { openWindowHidden = hidden.booleanValue(); } Boolean hardwareBack = features.get(HARDWARE_BACK_BUTTON); if (hardwareBack != null) { hadwareBackButton = hardwareBack.booleanValue(); } Boolean cache = features.get(CLEAR_ALL_CACHE); if (cache != null) { clearAllCache = cache.booleanValue(); } else { cache = features.get(CLEAR_SESSION_CACHE); if (cache != null) { clearSessionCache = cache.booleanValue(); } } } final CordovaWebView thatWebView = this.webView; // Create dialog in new thread Runnable runnable = new Runnable() { /** * Convert our DIP units to Pixels * * @return int */ private int dpToPixels(int dipValue) { int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) dipValue, cordova.getActivity().getResources().getDisplayMetrics()); return value; } @SuppressLint("NewApi") public void run() { // Let's create the main dialog dialog = new MobirollerInAppBrowserDialog(cordova.getActivity(), android.R.style.Theme_Translucent_NoTitleBar); dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog; dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCancelable(true); dialog.setInAppBroswer(getInAppBrowser()); // Main container layout LinearLayout main = new LinearLayout(cordova.getActivity()); main.setBackgroundColor(Color.TRANSPARENT); main.setOrientation(LinearLayout.VERTICAL); // Toolbar layout RelativeLayout toolbar = new RelativeLayout(cordova.getActivity()); //Please, no more black! toolbar.setBackgroundColor(Color.TRANSPARENT); toolbar.setLayoutParams(new RelativeLayout.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, this.dpToPixels(44))); toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2)); toolbar.setHorizontalGravity(Gravity.LEFT); toolbar.setVerticalGravity(Gravity.TOP); // Action Button Container layout RelativeLayout actionButtonContainer = new RelativeLayout(cordova.getActivity()); actionButtonContainer.setLayoutParams(new RelativeLayout.LayoutParams( WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT)); actionButtonContainer.setHorizontalGravity(Gravity.LEFT); actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL); actionButtonContainer.setId(1); // Back button Button back = new Button(cordova.getActivity()); RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams( WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.MATCH_PARENT); backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT); back.setLayoutParams(backLayoutParams); back.setContentDescription("Back Button"); back.setId(2); Resources activityRes = cordova.getActivity().getResources(); int backResId = activityRes.getIdentifier("ic_action_previous_item", "drawable", cordova.getActivity().getPackageName()); Drawable backIcon = activityRes.getDrawable(backResId); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { back.setBackgroundDrawable(backIcon); } else { back.setBackground(backIcon); } back.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goBack(); } }); // Forward button Button forward = new Button(cordova.getActivity()); RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams( WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.MATCH_PARENT); forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2); forward.setLayoutParams(forwardLayoutParams); forward.setContentDescription("Forward Button"); forward.setId(3); int fwdResId = activityRes.getIdentifier("ic_action_next_item", "drawable", cordova.getActivity().getPackageName()); Drawable fwdIcon = activityRes.getDrawable(fwdResId); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { forward.setBackgroundDrawable(fwdIcon); } else { forward.setBackground(fwdIcon); } forward.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goForward(); } }); // Edit Text Box edittext = new EditText(cordova.getActivity()); RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams( WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT); textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1); textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5); edittext.setLayoutParams(textLayoutParams); edittext.setId(4); edittext.setSingleLine(true); edittext.setText(url); edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI); edittext.setImeOptions(EditorInfo.IME_ACTION_GO); edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE edittext.setOnKeyListener(new View.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { navigate(edittext.getText().toString()); return true; } return false; } }); // Close/Done button Button close = new Button(cordova.getActivity()); RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams( WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.MATCH_PARENT); closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); close.setLayoutParams(closeLayoutParams); forward.setContentDescription("Close Button"); close.setId(5); int closeResId = activityRes.getIdentifier("ic_action_remove", "drawable", cordova.getActivity().getPackageName()); Drawable closeIcon = activityRes.getDrawable(closeResId); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { close.setBackgroundDrawable(closeIcon); } else { close.setBackground(closeIcon); } close.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { closeDialog(); } }); // WebView inAppWebView = new WebView(cordova.getActivity()); inAppWebView.setLayoutParams(new LinearLayout.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT)); inAppWebView.setWebChromeClient(new MobirollerInAppChromeClient(thatWebView)); WebViewClient client = new InAppBrowserClient(thatWebView, edittext); inAppWebView.setWebViewClient(client); WebSettings settings = inAppWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setBuiltInZoomControls(showZoomControls); settings.setPluginState(android.webkit.WebSettings.PluginState.ON); //Toggle whether this is enabled or not! Bundle appSettings = cordova.getActivity().getIntent().getExtras(); boolean enableDatabase = appSettings == null ? true : appSettings.getBoolean("InAppBrowserStorageEnabled", true); if (enableDatabase) { String databasePath = cordova.getActivity().getApplicationContext() .getDir("inAppBrowserDB", Context.MODE_PRIVATE).getPath(); settings.setDatabasePath(databasePath); settings.setDatabaseEnabled(true); } settings.setDomStorageEnabled(true); if (clearAllCache) { CookieManager.getInstance().removeAllCookie(); } else if (clearSessionCache) { CookieManager.getInstance().removeSessionCookie(); } inAppWebView.loadUrl(url); inAppWebView.setId(6); inAppWebView.getSettings().setLoadWithOverviewMode(true); inAppWebView.getSettings().setUseWideViewPort(true); inAppWebView.requestFocus(); inAppWebView.requestFocusFromTouch(); // Add the back and forward buttons to our action button container layout actionButtonContainer.addView(back); actionButtonContainer.addView(forward); // Add the views to our toolbar // toolbar.addView(actionButtonContainer); // toolbar.addView(edittext); toolbar.addView(close); // Don't add the toolbar if its been disabled if (getShowLocationBar()) { // Add our toolbar to our main view/layout main.addView(toolbar); } // Add our webview to our main view/layout main.addView(inAppWebView); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(dialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.MATCH_PARENT; lp.height = WindowManager.LayoutParams.MATCH_PARENT; //Mobiroller Needs DisplayMetrics metrics = cordova.getActivity().getResources().getDisplayMetrics(); Rect windowRect = new Rect(); webView.getView().getWindowVisibleDisplayFrame(windowRect); int bottomGap = 0; if (features.containsKey("hasTabs")) { if (features.get("hasTabs")) { bottomGap += Math.ceil(44 * metrics.density); } } lp.height = (windowRect.bottom - windowRect.top) - (bottomGap); lp.gravity = Gravity.TOP; lp.format = PixelFormat.TRANSPARENT; close.setAlpha(0); //Mobiroller Needs dialog.setContentView(main); dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); dialog.show(); dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); dialog.getWindow().setAttributes(lp); // the goal of openhidden is to load the url and not display it // Show() needs to be called to cause the URL to be loaded if (openWindowHidden) { dialog.hide(); } } }; this.cordova.getActivity().runOnUiThread(runnable); return ""; }