List of usage examples for android.widget LinearLayout HORIZONTAL
int HORIZONTAL
To view the source code for android.widget LinearLayout HORIZONTAL.
Click Source Link
From source file:com.research.widget.PagerSlidingTabStrip.java
private void addTextTab(final int position, String title) { LinearLayout item = new LinearLayout(getContext()); item.setOrientation(LinearLayout.HORIZONTAL); item.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); TextView tab = new TextView(getContext()); tab.setText(title);/*from ww w .j av a2s . c om*/ tab.setGravity(Gravity.CENTER); tab.setSingleLine(); TextView msgTipText = new TextView(getContext()); msgTipText.setGravity(Gravity.CENTER); msgTipText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10); msgTipText.setSingleLine(); msgTipText.setTextColor(Color.parseColor("#ffffff")); if (position != 0) { msgTipText.setBackgroundDrawable(getContext().getResources().getDrawable(R.drawable.main_find_icon)); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( FeatureFunction.dip2px(BMapApiApp.getInstance(), 10), FeatureFunction.dip2px(BMapApiApp.getInstance(), 10)); msgTipText.setLayoutParams(params); } else { msgTipText.setBackgroundDrawable(getContext().getResources().getDrawable(R.drawable.message_count_bg)); } msgTipText.setVisibility(View.GONE); item.addView(tab); item.addView(msgTipText); addTab(position, item); }
From source file:com.phonegap.childBrowser.ChildBrowser.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 om*/ */ public String showWebPage(final String url, JSONObject options) { // Determine if we should hide the location bar. if (options != null) { showLocationBar = options.optBoolean("showLocationBar", true); } // Create dialog in new thread Runnable runnable = new Runnable() { public void run() { dialog = new Dialog(ctx); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCancelable(true); dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { public void onDismiss(DialogInterface dialog) { try { JSONObject obj = new JSONObject(); obj.put("type", CLOSE_EVENT); sendUpdate(obj, false); } catch (JSONException e) { Log.d(LOG_TAG, "Should never happen"); } } }); LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams forwardParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams editParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1.0f); LinearLayout.LayoutParams closeParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams wvParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); LinearLayout main = new LinearLayout(ctx); main.setOrientation(LinearLayout.VERTICAL); LinearLayout toolbar = new LinearLayout(ctx); toolbar.setOrientation(LinearLayout.HORIZONTAL); ImageButton back = new ImageButton(ctx); back.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goBack(); } }); back.setId(1); try { back.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_left.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } back.setLayoutParams(backParams); ImageButton forward = new ImageButton(ctx); forward.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goForward(); } }); forward.setId(2); try { forward.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_right.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } forward.setLayoutParams(forwardParams); edittext = new EditText(ctx); 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; } }); edittext.setId(3); edittext.setSingleLine(true); edittext.setText(url); edittext.setLayoutParams(editParams); ImageButton close = new ImageButton(ctx); close.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { closeDialog(); } }); close.setId(4); try { close.setImageBitmap(loadDrawable("www/childbrowser/icon_close.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } close.setLayoutParams(closeParams); webview = new WebView(ctx); webview.getSettings().setJavaScriptEnabled(true); webview.getSettings().setBuiltInZoomControls(true); WebViewClient client = new ChildBrowserClient(ctx, edittext); webview.setWebViewClient(client); webview.loadUrl(url); webview.setId(5); webview.setInitialScale(0); webview.setLayoutParams(wvParams); webview.requestFocus(); webview.requestFocusFromTouch(); toolbar.addView(back); toolbar.addView(forward); toolbar.addView(edittext); toolbar.addView(close); if (getShowLocationBar()) { main.addView(toolbar); } main.addView(webview); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(dialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.FILL_PARENT; lp.height = WindowManager.LayoutParams.FILL_PARENT; dialog.setContentView(main); dialog.show(); dialog.getWindow().setAttributes(lp); } private Bitmap loadDrawable(String filename) throws java.io.IOException { InputStream input = ctx.getAssets().open(filename); return BitmapFactory.decodeStream(input); } }; this.ctx.runOnUiThread(runnable); return ""; }
From source file:com.phonegap.plugins.childBrowser.ChildBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load./*from ww w . j ava 2s. c om*/ * @param jsonObject */ public String showWebPage(final String url, JSONObject options) { // Determine if we should hide the location bar. if (options != null) { showLocationBar = options.optBoolean("showLocationBar", true); } // Create dialog in new thread Runnable runnable = new Runnable() { public void run() { dialog = new Dialog(ctx.getContext()); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCancelable(true); dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { public void onDismiss(DialogInterface dialog) { try { JSONObject obj = new JSONObject(); obj.put("type", CLOSE_EVENT); sendUpdate(obj, false); } catch (JSONException e) { Log.d(LOG_TAG, "Should never happen"); } } }); LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams forwardParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams editParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1.0f); LinearLayout.LayoutParams closeParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams wvParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); LinearLayout main = new LinearLayout(ctx.getContext()); main.setOrientation(LinearLayout.VERTICAL); LinearLayout toolbar = new LinearLayout(ctx.getContext()); toolbar.setOrientation(LinearLayout.HORIZONTAL); ImageButton back = new ImageButton(ctx.getContext()); back.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goBack(); } }); back.setId(1); try { back.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_left.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } back.setLayoutParams(backParams); ImageButton forward = new ImageButton(ctx.getContext()); forward.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goForward(); } }); forward.setId(2); try { forward.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_right.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } forward.setLayoutParams(forwardParams); edittext = new EditText(ctx.getContext()); 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; } }); edittext.setId(3); edittext.setSingleLine(true); edittext.setText(url); edittext.setLayoutParams(editParams); ImageButton close = new ImageButton((Context) ctx); close.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { closeDialog(); } }); close.setId(4); try { close.setImageBitmap(loadDrawable("www/childbrowser/icon_close.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } close.setLayoutParams(closeParams); webview = new WebView(ctx.getContext()); webview.getSettings().setJavaScriptEnabled(true); webview.getSettings().setBuiltInZoomControls(true); // dda: intercept calls to console.log webview.setWebChromeClient(new WebChromeClient() { public boolean onConsoleMessage(ConsoleMessage cmsg) { // check secret prefix if (cmsg.message().startsWith("MAGIC")) { String msg = cmsg.message().substring(5); // strip off prefix /* process HTML */ try { JSONObject obj = new JSONObject(); obj.put("type", PAGE_LOADED); obj.put("html", msg); sendUpdate(obj, true); } catch (JSONException e) { Log.d("ChildBrowser", "This should never happen"); } return true; } return false; } }); // dda: inject the JavaScript on page load webview.setWebViewClient(new ChildBrowserClient(edittext) { public void onPageFinished(WebView view, String address) { // have the page spill its guts, with a secret prefix Log.d("ChildBrowser", "\n\nInjecting javascript\n\n"); view.loadUrl( "javascript:console.log('MAGIC'+document.getElementsByTagName('html')[0].innerHTML);"); } }); // webview.setWebViewClient(client); webview.loadUrl(url); webview.setId(5); webview.setInitialScale(0); webview.setLayoutParams(wvParams); webview.requestFocus(); webview.requestFocusFromTouch(); toolbar.addView(back); toolbar.addView(forward); toolbar.addView(edittext); toolbar.addView(close); if (getShowLocationBar()) { main.addView(toolbar); } main.addView(webview); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(dialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.FILL_PARENT; lp.height = WindowManager.LayoutParams.FILL_PARENT; dialog.setContentView(main); dialog.show(); dialog.getWindow().setAttributes(lp); } private Bitmap loadDrawable(String filename) throws java.io.IOException { InputStream input = ctx.getAssets().open(filename); return BitmapFactory.decodeStream(input); } }; this.ctx.runOnUiThread(runnable); return ""; }
From source file:com.mishiranu.dashchan.ui.navigator.DrawerForm.java
public DrawerForm(Context context, Context unstyledContext, Callback callback, WatcherService.Client watcherServiceClient) { this.context = context; this.unstyledContext = unstyledContext; this.callback = callback; this.watcherServiceClient = watcherServiceClient; float density = ResourceUtils.obtainDensity(context); LinearLayout linearLayout = new LinearLayout(context); linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.setLayoutParams(new SortableListView.LayoutParams(SortableListView.LayoutParams.MATCH_PARENT, SortableListView.LayoutParams.WRAP_CONTENT)); LinearLayout editTextContainer = new LinearLayout(context); editTextContainer.setGravity(Gravity.CENTER_VERTICAL); linearLayout.addView(editTextContainer); searchEdit = new SafePasteEditText(context); searchEdit.setOnKeyListener((v, keyCode, event) -> { if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) { v.clearFocus();//from ww w .java 2 s . c om } return false; }); searchEdit.setHint(context.getString(R.string.text_code_number_address)); searchEdit.setOnEditorActionListener(this); searchEdit.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI); searchEdit.setImeOptions(EditorInfo.IME_ACTION_GO | EditorInfo.IME_FLAG_NO_EXTRACT_UI); ImageView searchIcon = new ImageView(context, null, android.R.attr.buttonBarButtonStyle); searchIcon.setImageResource(ResourceUtils.getResourceId(context, R.attr.buttonForward, 0)); searchIcon.setScaleType(ImageView.ScaleType.CENTER); searchIcon.setOnClickListener(this); editTextContainer.addView(searchEdit, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1)); editTextContainer.addView(searchIcon, (int) (40f * density), (int) (40f * density)); if (C.API_LOLLIPOP) { editTextContainer.setPadding((int) (12f * density), (int) (8f * density), (int) (8f * density), 0); } else { editTextContainer.setPadding(0, (int) (2f * density), (int) (4f * density), (int) (2f * density)); } LinearLayout selectorContainer = new LinearLayout(context); selectorContainer.setBackgroundResource( ResourceUtils.getResourceId(context, android.R.attr.selectableItemBackground, 0)); selectorContainer.setOrientation(LinearLayout.HORIZONTAL); selectorContainer.setGravity(Gravity.CENTER_VERTICAL); selectorContainer.setOnClickListener(v -> { hideKeyboard(); setChanSelectMode(!chanSelectMode); }); linearLayout.addView(selectorContainer); selectorContainer.setMinimumHeight((int) (40f * density)); if (C.API_LOLLIPOP) { selectorContainer.setPadding((int) (16f * density), 0, (int) (16f * density), 0); ((LinearLayout.LayoutParams) selectorContainer.getLayoutParams()).topMargin = (int) (4f * density); } else { selectorContainer.setPadding((int) (8f * density), 0, (int) (12f * density), 0); } chanNameView = new TextView(context, null, android.R.attr.textAppearanceListItem); chanNameView.setTextSize(TypedValue.COMPLEX_UNIT_SP, C.API_LOLLIPOP ? 14f : 16f); if (C.API_LOLLIPOP) { chanNameView.setTypeface(GraphicsUtils.TYPEFACE_MEDIUM); } else { chanNameView.setFilters(new InputFilter[] { new InputFilter.AllCaps() }); } selectorContainer.addView(chanNameView, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1)); chanSelectorIcon = new ImageView(context); chanSelectorIcon.setImageResource(ResourceUtils.getResourceId(context, R.attr.buttonDropDownDrawer, 0)); selectorContainer.addView(chanSelectorIcon, (int) (24f * density), (int) (24f * density)); ((LinearLayout.LayoutParams) chanSelectorIcon.getLayoutParams()).gravity = Gravity.CENTER_VERTICAL | Gravity.END; headerView = linearLayout; inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); chans.add(new ListItem(ListItem.ITEM_DIVIDER, 0, 0, null)); int color = ResourceUtils.getColor(context, R.attr.drawerIconColor); ChanManager manager = ChanManager.getInstance(); Collection<String> availableChans = manager.getAvailableChanNames(); for (String chanName : availableChans) { ChanConfiguration configuration = ChanConfiguration.get(chanName); if (configuration.getOption(ChanConfiguration.OPTION_READ_POSTS_COUNT)) { watcherSupportSet.add(chanName); } Drawable drawable = manager.getIcon(chanName, color); chanIcons.put(chanName, drawable); chans.add( new ListItem(ListItem.ITEM_CHAN, chanName, null, null, configuration.getTitle(), 0, drawable)); } if (availableChans.size() == 1) { selectorContainer.setVisibility(View.GONE); } }
From source file:com.phonegap.plugin.ChildBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load. * @param jsonObject // w ww .j av a2 s . co m */ public String showWebPage(final String url, JSONObject options) { // Determine if we should hide the location bar. if (options != null) { showLocationBar = options.optBoolean("showLocationBar", true); } // Create dialog in new thread Runnable runnable = new Runnable() { public void run() { dialog = new Dialog(ctx.getContext(), android.R.style.Theme_Translucent_NoTitleBar); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCancelable(true); dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { public void onDismiss(DialogInterface dialog) { try { JSONObject obj = new JSONObject(); obj.put("type", CLOSE_EVENT); sendUpdate(obj, false); } catch (JSONException e) { Log.d(LOG_TAG, "Should never happen"); } } }); LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams forwardParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams editParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1.0f); LinearLayout.LayoutParams closeParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams wvParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); LinearLayout main = new LinearLayout(ctx.getContext()); main.setOrientation(LinearLayout.VERTICAL); LinearLayout toolbar = new LinearLayout(ctx.getContext()); toolbar.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); toolbar.setOrientation(LinearLayout.HORIZONTAL); ImageButton back = new ImageButton(ctx.getContext()); back.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goBack(); } }); back.setId(1); try { back.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_left.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } back.setLayoutParams(backParams); ImageButton forward = new ImageButton(ctx.getContext()); forward.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goForward(); } }); forward.setId(2); try { forward.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_right.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } forward.setLayoutParams(forwardParams); edittext = new EditText(ctx.getContext()); 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; } }); edittext.setId(3); edittext.setSingleLine(true); edittext.setText(url); edittext.setLayoutParams(editParams); ImageButton close = new ImageButton(ctx.getContext()); close.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { closeDialog(); } }); close.setId(4); try { close.setImageBitmap(loadDrawable("www/childbrowser/icon_close.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } close.setLayoutParams(closeParams); webview = new WebView(ctx.getContext()); webview.setWebChromeClient(new WebChromeClient()); WebViewClient client = new ChildBrowserClient(edittext); webview.setWebViewClient(client); WebSettings settings = webview.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setBuiltInZoomControls(true); settings.setPluginsEnabled(true); settings.setDomStorageEnabled(true); webview.loadUrl(url); webview.setId(5); webview.setInitialScale(0); webview.setLayoutParams(wvParams); webview.requestFocus(); webview.requestFocusFromTouch(); toolbar.addView(back); toolbar.addView(forward); toolbar.addView(edittext); toolbar.addView(close); if (getShowLocationBar()) { main.addView(toolbar); } main.addView(webview); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(dialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.FILL_PARENT; lp.height = WindowManager.LayoutParams.FILL_PARENT; dialog.setContentView(main); dialog.show(); dialog.getWindow().setAttributes(lp); } private Bitmap loadDrawable(String filename) throws java.io.IOException { InputStream input = ctx.getAssets().open(filename); return BitmapFactory.decodeStream(input); } }; this.ctx.runOnUiThread(runnable); return ""; }
From source file:com.taobao.wuzhong.plugins.ChildBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load. * @param jsonObject// ww w .j a v a 2s. co m */ public String showWebPage(final String url, JSONObject options) { // Determine if we should hide the location bar. if (options != null) { showLocationBar = options.optBoolean("showLocationBar", true); } // Create dialog in new thread Runnable runnable = new Runnable() { public void run() { dialog = new Dialog(ctx.getContext(), android.R.style.Theme_Translucent_NoTitleBar); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCancelable(true); dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { public void onDismiss(DialogInterface dialog) { try { JSONObject obj = new JSONObject(); obj.put("type", CLOSE_EVENT); sendUpdate(obj, false); } catch (JSONException e) { Log.d(LOG_TAG, "Should never happen"); } } }); LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams forwardParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams editParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1.0f); LinearLayout.LayoutParams closeParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams wvParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); LinearLayout main = new LinearLayout(ctx.getContext()); main.setOrientation(LinearLayout.VERTICAL); LinearLayout toolbar = new LinearLayout(ctx.getContext()); toolbar.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); toolbar.setOrientation(LinearLayout.HORIZONTAL); ImageButton back = new ImageButton(ctx.getContext()); back.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goBack(); } }); back.setId(1); try { back.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_left.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } back.setLayoutParams(backParams); ImageButton forward = new ImageButton(ctx.getContext()); forward.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goForward(); } }); forward.setId(2); try { forward.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_right.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } forward.setLayoutParams(forwardParams); edittext = new EditText(ctx.getContext()); 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; } }); edittext.setId(3); edittext.setSingleLine(true); edittext.setText(url); edittext.setLayoutParams(editParams); ImageButton close = new ImageButton(ctx.getContext()); close.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { closeDialog(); } }); close.setId(4); try { close.setImageBitmap(loadDrawable("www/childbrowser/icon_close.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } close.setLayoutParams(closeParams); webview = new WebView(ctx.getContext()); webview.setWebChromeClient(new WebChromeClient()); WebViewClient client = new ChildBrowserClient(edittext); webview.setWebViewClient(client); WebSettings settings = webview.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setBuiltInZoomControls(true); settings.setPluginsEnabled(true); settings.setDomStorageEnabled(true); webview.loadUrl(url); webview.setId(5); webview.setInitialScale(0); webview.setLayoutParams(wvParams); webview.requestFocus(); webview.requestFocusFromTouch(); toolbar.addView(back); toolbar.addView(forward); toolbar.addView(edittext); toolbar.addView(close); if (getShowLocationBar()) { main.addView(toolbar); } main.addView(webview); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(dialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.FILL_PARENT; lp.height = WindowManager.LayoutParams.FILL_PARENT; dialog.setContentView(main); dialog.show(); dialog.getWindow().setAttributes(lp); } private Bitmap loadDrawable(String filename) throws java.io.IOException { InputStream input = ctx.getAssets().open(filename); return BitmapFactory.decodeStream(input); } }; this.ctx.runOnUiThread(runnable); return ""; }
From source file:com.phonegap.plugins.slaveBrowser.SlaveBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load./*from w w w . ja v a 2 s .co m*/ * @param jsonObject */ public String showWebPage(final String url, JSONObject options, String myNewTitle) { // Determine if we should hide the location bar. if (options != null) { showLocationBar = options.optBoolean("showLocationBar", true); } zeTitle = myNewTitle; // Create dialog in new thread Runnable runnable = new Runnable() { public void run() { dialog = new Dialog(ctx.getContext()); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCancelable(true); dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { public void onDismiss(DialogInterface dialog) { try { JSONObject obj = new JSONObject(); obj.put("type", CLOSE_EVENT); sendUpdate(obj, false); } catch (JSONException e) { Log.d(LOG_TAG, "Should never happen"); } } }); LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams forwardParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams editParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1.0f); LinearLayout.LayoutParams closeParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams wvParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); LinearLayout main = new LinearLayout(ctx.getContext()); main.setOrientation(LinearLayout.VERTICAL); LinearLayout toolbar = new LinearLayout(ctx.getContext()); toolbar.setOrientation(LinearLayout.HORIZONTAL); edittext = new TextView(ctx.getContext()); edittext.setId(3); edittext.setSingleLine(true); edittext.setText(zeTitle); edittext.setTextSize(TypedValue.COMPLEX_UNIT_PX, 24); edittext.setGravity(Gravity.CENTER); edittext.setTextColor(Color.DKGRAY); edittext.setTypeface(Typeface.DEFAULT_BOLD); edittext.setLayoutParams(editParams); webview = new WebView(ctx.getContext()); webview.getSettings().setJavaScriptEnabled(true); webview.getSettings().setBuiltInZoomControls(true); // dda: intercept calls to console.log webview.setWebChromeClient(new WebChromeClient() { public boolean onConsoleMessage(ConsoleMessage cmsg) { // check secret prefix if (cmsg.message().startsWith("MAGICHTML")) { String msg = cmsg.message().substring(9); // strip off prefix /* process HTML */ try { JSONObject obj = new JSONObject(); obj.put("type", PAGE_LOADED); obj.put("html", msg); sendUpdate(obj, true); } catch (JSONException e) { Log.d(LOG_TAG, "This should never happen"); } return true; } return false; } }); // dda: inject the JavaScript on page load webview.setWebViewClient(new SlaveBrowserClient(edittext) { public void onPageFinished(WebView view, String address) { // have the page spill its guts, with a secret prefix view.loadUrl( "javascript:console.log('MAGICHTML'+document.getElementsByTagName('html')[0].innerHTML);"); } }); webview.loadUrl(url); webview.setId(5); webview.setInitialScale(0); webview.setLayoutParams(wvParams); webview.requestFocus(); webview.requestFocusFromTouch(); toolbar.addView(edittext); if (getShowLocationBar()) { main.addView(toolbar); } main.addView(webview); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(dialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.FILL_PARENT; lp.height = WindowManager.LayoutParams.FILL_PARENT; dialog.setContentView(main); dialog.show(); dialog.getWindow().setAttributes(lp); } private Bitmap loadDrawable(String filename) throws java.io.IOException { InputStream input = ctx.getAssets().open(filename); return BitmapFactory.decodeStream(input); } }; this.ctx.runOnUiThread(runnable); return ""; }
From source file:com.app.plugins.childBrowser.ChildBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load. * @param jsonObject /*ww w.j a v a 2 s . c o m*/ */ public String showWebPage(final String url, JSONObject options) { // Determine if we should hide the location bar. if (options != null) { showLocationBar = options.optBoolean("showLocationBar", false); } final WebView parent = this.webView; // Create dialog in new thread Runnable runnable = new Runnable() { public void run() { dialog = new Dialog(cordova.getActivity(), android.R.style.Theme_Black_NoTitleBar_Fullscreen); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCancelable(true); dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { public void onDismiss(DialogInterface dialog) { try { JSONObject obj = new JSONObject(); obj.put("type", CLOSE_EVENT); sendUpdate(obj, false); } catch (JSONException e) { Log.d(LOG_TAG, "Should never happen"); } } }); //LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); //LinearLayout.LayoutParams forwardParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); //LinearLayout.LayoutParams editParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT, 1.0f); LinearLayout.LayoutParams closeParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams wvParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); LinearLayout main = new LinearLayout(cordova.getActivity()); main.setOrientation(LinearLayout.VERTICAL); LinearLayout toolbar = new LinearLayout(cordova.getActivity()); toolbar.setOrientation(LinearLayout.HORIZONTAL); /* ImageButton back = new ImageButton((Context) ctx); back.getBackground().setAlpha(0); back.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goBack(); } }); back.setId(1); try { back.setImageBitmap(loadDrawable("plugins/childbrowser/icon_arrow_left.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } back.setLayoutParams(backParams); ImageButton forward = new ImageButton((Context) ctx); forward.getBackground().setAlpha(0); forward.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goForward(); } }); forward.setId(2); try { forward.setImageBitmap(loadDrawable("plugins/childbrowser/icon_arrow_right.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } forward.setLayoutParams(forwardParams); */ /* edittext = new EditText((Context) ctx); 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; } }); edittext.setId(3); edittext.setSingleLine(true); edittext.setText(url); edittext.setLayoutParams(editParams); */ //edittext = new EditText((Context) ctx); //edittext.setVisibility(View.GONE); LinearLayout.LayoutParams titleParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT, 1.0f); TextView title = new TextView(cordova.getActivity()); title.setId(1); title.setLayoutParams(titleParams); title.setGravity(Gravity.CENTER_VERTICAL); title.setTypeface(null, Typeface.BOLD); ImageButton close = new ImageButton(cordova.getActivity()); close.getBackground().setAlpha(0); close.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { closeDialog(); } }); close.setId(4); try { close.setImageBitmap(loadDrawable("plugins/childbrowser/icon_close.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } close.setLayoutParams(closeParams); childWebView = new WebView(cordova.getActivity()); childWebView.getSettings().setJavaScriptEnabled(true); childWebView.getSettings().setBuiltInZoomControls(true); WebViewClient client = new ChildBrowserClient(parent, ctx, title/*, edittext*/); childWebView.setWebViewClient(client); childWebView.loadUrl(url); childWebView.setId(5); childWebView.setInitialScale(0); childWebView.setLayoutParams(wvParams); childWebView.requestFocus(); childWebView.requestFocusFromTouch(); //toolbar.addView(back); //toolbar.addView(forward); //toolbar.addView(edittext); toolbar.addView(close); toolbar.addView(title); if (getShowLocationBar()) { main.addView(toolbar); } main.addView(childWebView); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(dialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.FILL_PARENT; lp.height = WindowManager.LayoutParams.FILL_PARENT; lp.verticalMargin = 0f; lp.horizontalMargin = 0f; dialog.setContentView(main); dialog.show(); dialog.getWindow().setAttributes(lp); } private Bitmap loadDrawable(String filename) throws java.io.IOException { InputStream input = cordova.getActivity().getAssets().open(filename); return BitmapFactory.decodeStream(input); } }; this.cordova.getActivity().runOnUiThread(runnable); return ""; }
From source file:brostore.maquillage.custom.PagerSlidingTabStrip.java
private void addCustomTextTab(final int position, String title) { LinearLayout conteneur = new LinearLayout(getContext()); LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); conteneur.setOrientation(LinearLayout.HORIZONTAL); conteneur.setGravity(Gravity.CENTER); TextView tab = new TextView(getContext()); TextView tabCust = new TextView(getContext()); //tabCust.setBackgroundResource(R.drawable.live_nombre); tabCust.setGravity(Gravity.CENTER);/*w ww . j a va2s .c o m*/ tabCust.setTextColor(Color.WHITE); tabCust.setTypeface(tabTypeface); tabCust.setTextSize(11); tabCust.setVisibility(View.GONE); int fiveDip = Utils.convertDpToPixel(5, getResources()); tabCust.setPadding(fiveDip, 0, fiveDip, 0); tabCust.setText("0"); tab.setText(title); tab.setGravity(Gravity.CENTER); tab.setSingleLine(); conteneur.addView(tab, param); param.leftMargin = Utils.convertDpToPixel(10, getResources()); conteneur.addView(tabCust, param); addTab(position, conteneur); }
From source file:com.astuetz.PagerSlidingTitleIconTabStrip.java
private void addTextIconTab(final int position, String title, int resId) { if (resId == TitleIconTabProvider.NONE_ICON) { addTextTab(position, title);//from www.ja v a2 s. co m return; } TextView tab = new TextView(getContext()); tab.setText(title); tab.setGravity(Gravity.CENTER); tab.setSingleLine(); ImageView icon = new ImageView(getContext()); icon.setImageResource(resId); LinearLayout linearLayout = new LinearLayout(getContext()); linearLayout.setOrientation(LinearLayout.HORIZONTAL); linearLayout.addView(icon, defaultTabLayoutParams); linearLayout.addView(tab, defaultTabLayoutParams); addTab(position, linearLayout); }