List of usage examples for android.widget LinearLayout LinearLayout
public LinearLayout(Context context)
From source file:com.moonpi.tapunlock.MainActivity.java
@Override protected Dialog onCreateDialog(int id) { // Scan NFC Tag dialog, inflate image LayoutInflater factory = LayoutInflater.from(MainActivity.this); final View view = factory.inflate(R.layout.scan_tag_image, null); // Ask for tagTitle (tagName) in dialog final EditText tagTitle = new EditText(this); tagTitle.setHint(getResources().getString(R.string.set_tag_name_dialog_hint)); tagTitle.setSingleLine(true);/*from w w w.ja v a 2 s . co m*/ tagTitle.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES); // Set tagTitle maxLength int maxLength = 50; InputFilter[] array = new InputFilter[1]; array[0] = new InputFilter.LengthFilter(maxLength); tagTitle.setFilters(array); final LinearLayout l = new LinearLayout(this); l.setOrientation(LinearLayout.VERTICAL); l.addView(tagTitle); // Dialog that shows scan tag image if (id == DIALOG_READ) { return new AlertDialog.Builder(this).setTitle(R.string.scan_tag_dialog_title).setView(view) .setCancelable(false) .setNeutralButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialogCancelled = true; killForegroundDispatch(); dialog.cancel(); } }).create(); } // Dialog that asks for tagName and stores it after 'Ok' pressed else if (id == DIALOG_SET_TAGNAME) { tagTitle.requestFocus(); return new AlertDialog.Builder(this).setTitle(R.string.set_tag_name_dialog_title).setView(l) .setCancelable(false) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { JSONObject newTag = new JSONObject(); try { newTag.put("tagName", tagTitle.getText()); newTag.put("tagID", tagID); } catch (JSONException e) { e.printStackTrace(); } tags.put(newTag); writeToJSON(); adapter.notifyDataSetChanged(); updateListViewHeight(listView); if (tags.length() == 0) noTags.setVisibility(View.VISIBLE); else noTags.setVisibility(View.INVISIBLE); Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_tag_added, Toast.LENGTH_SHORT); toast.show(); imm.hideSoftInputFromWindow(tagTitle.getWindowToken(), 0); tagID = ""; tagTitle.setText(""); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { tagID = ""; tagTitle.setText(""); imm.hideSoftInputFromWindow(tagTitle.getWindowToken(), 0); dialog.cancel(); } }).create(); } return null; }
From source file:android.support.v7.internal.view.menu.MenuItemImpl.java
@Override public SupportMenuItem setActionView(int resId) { final Context context = mMenu.getContext(); final LayoutInflater inflater = LayoutInflater.from(context); setActionView(inflater.inflate(resId, new LinearLayout(context), false)); return this; }
From source file:com.grarak.kerneladiutor.fragments.other.SettingsFragment.java
private void deletePasswordDialog(final String password) { if (password.isEmpty()) { Utils.toast(getString(R.string.set_password_first), getActivity()); return;/*from ww w.j av a 2 s . c o m*/ } mDeletePassword = password; LinearLayout linearLayout = new LinearLayout(getActivity()); linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.setGravity(Gravity.CENTER); int padding = Math.round(getResources().getDimension(R.dimen.dialog_padding)); linearLayout.setPadding(padding, padding, padding, padding); final AppCompatEditText mPassword = new AppCompatEditText(getActivity()); mPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); mPassword.setHint(getString(R.string.password)); linearLayout.addView(mPassword); new Dialog(getActivity()).setView(linearLayout) .setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { if (!mPassword.getText().toString().equals(Utils.decodeString(password))) { Utils.toast(getString(R.string.password_wrong), getActivity()); return; } Prefs.saveString("password", "", getActivity()); if (mFingerprint != null) { mFingerprint.setEnabled(false); } } }).setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialogInterface) { mDeletePassword = null; } }).show(); }
From source file:com.oonhee.oojs.inappbrowser.InAppBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load. * @param jsonObject//w ww .j a va 2 s. com */ 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; } public void run() { // Let's create the main dialog dialog = new Dialog(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.setOnDismissListener(new DialogInterface.OnDismissListener() { public void onDismiss(DialogInterface dialog) { closeDialog(); } }); // 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); back.setText("<"); 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); forward.setText(">"); 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 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); close.setText(buttonLabel); close.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { closeDialog(); } }); // WebView inAppWebView = new AmazonWebView(cordova.getActivity()); CordovaActivity app = (CordovaActivity) cordova.getActivity(); cordova.getFactory().initializeWebView(inAppWebView, 0x00FF00, false, null); inAppWebView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView)); AmazonWebViewClient client = new InAppBrowserClient(thatWebView, edittext); inAppWebView.setWebViewClient(client); AmazonWebSettings settings = inAppWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setBuiltInZoomControls(true); settings.setPluginState(com.amazon.android.webkit.AmazonWebSettings.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) { AmazonCookieManager.getInstance().removeAllCookie(); } else if (clearSessionCache) { AmazonCookieManager.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.cssweb.android.base.QuoteGridActivity.java
protected void refreshIndexUI(List<CssStock> list, String[] cols) throws JSONException { LinearLayout localLinearLayout1 = (LinearLayout) this.findViewById(R.id.zr_htable_lock); LinearLayout localLinearLayout2 = (LinearLayout) this.findViewById(R.id.zr_htable_linearlayout); this.mLinerLock = localLinearLayout1; this.mLinerHScroll = localLinearLayout2; this.mLinerLock.removeAllViews(); this.mLinerHScroll.removeAllViews(); if (nameOrcode) AddViewItem(cols[0], Utils.getTextColor(mContext, 0), mLinerLock, -1, 0, 0, true); else// w w w . ja v a 2 s . com AddViewItem(cols[1], Utils.getTextColor(mContext, 0), mLinerLock, -1, 0, 0, true); LinearLayout l1 = new LinearLayout(this); for (int i = 2; i < cols.length; i++) { if (i == cols.length - 1) AddViewItem(cols[i], Utils.getTextColor(mContext, 0), l1, -i, 100, 0, true); else AddViewItem(cols[i], Utils.getTextColor(mContext, 0), l1, -i, i - 1, 0, true); } mLinerHScroll.addView(l1); int mDigit = 1; double d0 = 0; for (int i = 1; i <= list.size(); i++) { CssStock cs = list.get(i - 1); d0 = cs.getZrsp(); //?? mDigit = Utils.getNumFormat(cs.getMarket(), cs.getStkcode()); //mLinerLock.setTag(i); if (nameOrcode) AddViewItem(Utils.clearSpace(cs.getStkname()), Utils.getTextColor(mContext, 1), mLinerLock, i, 0, i, true); else AddViewItem(cs.getStkcode(), Utils.getTextColor(mContext, 1), mLinerLock, i, 0, i, true); l1 = new LinearLayout(this); l1.setTag(i); if (cs.getStkcode() == null || cs.getStkcode().equals("") || cs.getStkname() == null || cs.getStkname().equals("")) { AddViewItem("", Utils.getTextColor(mContext, 0), l1, i, 1, i, true); AddViewItem("", Utils.getTextColor(mContext, 0), l1, i, 2, i, true); AddViewItem("", Utils.getTextColor(mContext, 0), l1, i, 3, i, true); AddViewItem("", Utils.getTextColor(mContext, 0), l1, i, 4, i, true); AddViewItem("", Utils.getTextColor(mContext, 0), l1, i, 5, i, true); AddViewItem("", Utils.getTextColor(mContext, 0), l1, i, 6, i, true); AddViewItem("", Utils.getTextColor(mContext, 0), l1, i, 7, i, true); AddViewItem("", Utils.getTextColor(mContext, 0), l1, i, 8, i, true); AddViewItem("", Utils.getTextColor(mContext, 0), l1, i, 9, i, true); AddViewItem("", Utils.getTextColor(mContext, 0), l1, i, 10, i, true); AddViewItem("", Utils.getTextColor(mContext, 0), l1, i, 11, i, true); AddViewItem("", Utils.getTextColor(mContext, 0), l1, i, 11, i, true); AddViewItem("", Utils.getTextColor(mContext, 0), l1, i, 11, i, true); AddViewItem("", Utils.getTextColor(mContext, 0), l1, i, 11, i, true); AddViewItem("", Utils.getTextColor(mContext, 0), l1, i, 11, i, true); AddViewItem("", Utils.getTextColor(mContext, 0), l1, i, 11, i, true); AddViewItem("", Utils.getTextColor(mContext, 0), l1, i, 11, i, true); AddViewItem("", Utils.getTextColor(mContext, 0), l1, i, 100, i, true); } else { // String str1; // if(cs.getZf()==0) // str1 = Utils.dataFormation(cs.getZf()*100, 1) + "%"; // else // str1 = Utils.dataFormation(cs.getZf()*100, 1) + "%"; AddViewItem(Utils.dataFormation(cs.getZjcj(), mDigit), Utils.getTextColor(mContext, cs.getZjcj(), d0), l1, i, 1, i, true); AddViewItem(Utils.dataFormation(cs.getZf() * 100, 1), Utils.getTextColor(mContext, cs.getZf()), l1, i, 2, i, true); AddViewItem(Utils.getAmountFormat(cs.getZje(), false, 1), Utils.getTextColor(mContext, 2), l1, i, 3, i, true); AddViewItem(Utils.dataFormation(cs.getZd(), mDigit), Utils.getTextColor(mContext, cs.getZd()), l1, i, 4, i, true); AddViewItem(Utils.getAmountFormat(cs.getZl(), false, 1), Utils.getTextColor(mContext, 1), l1, i, 5, i, true); AddViewItem(Utils.getAmountFormat(cs.getXs(), false, 1), Utils.getTextColor(mContext, 1), l1, i, 6, i, true); AddViewItem(Utils.dataFormation(cs.getJrkp(), mDigit), Utils.getTextColor(mContext, cs.getJrkp(), d0), l1, i, 7, i, true); AddViewItem(Utils.dataFormation(cs.getZrsp(), mDigit), Utils.getTextColor(mContext, 0), l1, i, 8, i, true); AddViewItem(Utils.dataFormation(cs.getZgcj(), mDigit), Utils.getTextColor(mContext, cs.getZgcj(), d0), l1, i, 9, i, true); AddViewItem(Utils.dataFormation(cs.getZdcj(), mDigit), Utils.getTextColor(mContext, cs.getZdcj(), d0), l1, i, 10, i, true); AddViewItem(Utils.dataFormation(cs.getAmp() * 100, 1), Utils.getTextColor(mContext, 5), l1, i, 11, i, true); //AddViewItem(Utils.dataFormation(cs.getLb(), 1), Utils.getTextColor(mContext, 1), l1, i, 100, i, true); AddViewItem(Utils.dataFormation(cs.getLb(), 1), Utils.getTextColor(mContext, 1), l1, i, 12, i, true); AddViewItem(cs.getJtsy(), Utils.getTextColor(mContext, 0), l1, i, 13, i, true); AddViewItem(cs.getPjgb(), Utils.getTextColor(mContext, 0), l1, i, 14, i, true); AddViewItem(cs.getZsz(), Utils.getTextColor(mContext, 0), l1, i, 15, i, true); AddViewItem(cs.getZb(), Utils.getTextColor(mContext, 0), l1, i, 16, i, true); AddViewItem(cs.getYbjj(), Utils.getTextColor(mContext, 0), l1, i, 17, i, true); AddViewItem(cs.getYbsl(), Utils.getTextColor(mContext, 0), l1, i, 100, i, true); } mLinerHScroll.addView(l1); } }
From source file:com.chatwing.whitelabel.managers.ChatboxModeManager.java
@Override public boolean onCreateOptionsMenu(Menu menu) { AppCompatActivity activity = mActivityDelegate.getActivity(); final DrawerLayout drawerLayout = mActivityDelegate.getDrawerLayout(); activity.getMenuInflater().inflate(R.menu.chatbox_menu, menu); MenuItem onlineUsersItem = menu.findItem(R.id.online_users); mediaAddItem = menu.findItem(R.id.audio_add); /**/* w ww. j a va 2s. co m*/ * Create badge view for online user item */ ImageButton iconView = new ImageButton(activity, null, R.style.Widget_AppCompat_ActionButton); iconView.setImageDrawable(onlineUsersItem.getIcon()); iconView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (drawerLayout.isDrawerOpen(DRAWER_GRAVITY_ONLINE_USER)) { drawerLayout.closeDrawer(DRAWER_GRAVITY_ONLINE_USER); } else { drawerLayout.openDrawer(DRAWER_GRAVITY_ONLINE_USER); } } }); // The badge view requires target view (iconView in this case) // to have a ViewGroup parent LinearLayout container = new LinearLayout(activity); container.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); container.addView(iconView); Resources res = activity.getResources(); mOnlineUsersBadgeView = new BadgeView(activity, iconView); mOnlineUsersBadgeView.setBadgePosition(BadgeView.POSITION_TOP_RIGHT); mOnlineUsersBadgeView.setTextSize(TypedValue.COMPLEX_UNIT_SP, res.getDimension(R.dimen.badge_view_text_size)); mOnlineUsersBadgeView.setBadgeMargin(res.getDimensionPixelSize(R.dimen.default_margin)); onlineUsersItem.setActionView(container); mOnlineUsersBadgeView .setBadgeBackgroundColor(mActivityDelegate.getActivity().getResources().getColor(R.color.accent)); return true; }
From source file:jp.watnow.plugins.dialog.Notification.java
/** * /* ww w. jav a 2 s. co m*/ * @param message * @param title * @param buttonLabels * @param defaultTexts * @param callbackContext */ public synchronized void login(final String title, final String message, final JSONArray buttonLabels, final JSONArray defaultTexts, final CallbackContext callbackContext) { final CordovaInterface cordova = this.cordova; Runnable runnable = new Runnable() { public void run() { LinearLayout layout = new LinearLayout(cordova.getActivity()); layout.setOrientation(LinearLayout.VERTICAL); layout.setPadding(10, 0, 10, 0); final EditText usernameInput = new EditText(cordova.getActivity()); usernameInput.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL); final EditText passwordInput = new EditText(cordova.getActivity()); passwordInput.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); try { usernameInput.setHint("ID"); usernameInput.setText(defaultTexts.getString(0)); passwordInput.setHint("PASSWORD"); passwordInput.setText(defaultTexts.getString(1)); } catch (JSONException e1) { } layout.addView(usernameInput, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); layout.addView(passwordInput, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); AlertDialog.Builder dlg = createDialog(cordova); // new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); dlg.setMessage(message); dlg.setTitle(title); dlg.setCancelable(false); dlg.setView(layout); final JSONObject result = new JSONObject(); try { dlg.setNegativeButton(buttonLabels.getString(0), new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); try { result.put("buttonIndex", 1); result.put("input1", usernameInput.getText()); result.put("input2", passwordInput.getText()); } catch (JSONException e) { e.printStackTrace(); } callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); } }); } catch (JSONException e) { } try { dlg.setPositiveButton(buttonLabels.getString(1), new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); try { result.put("buttonIndex", 3); } catch (JSONException e) { e.printStackTrace(); } callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); } }); } catch (JSONException e) { } dlg.setOnCancelListener(new AlertDialog.OnCancelListener() { public void onCancel(DialogInterface dialog) { dialog.dismiss(); try { result.put("buttonIndex", 0); } catch (JSONException e) { e.printStackTrace(); } callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); } }); changeTextDirection(dlg); }; }; this.cordova.getActivity().runOnUiThread(runnable); }
From source file:com.google.samples.apps.iosched.ui.widget.CollectionView.java
private View makeNewItemRow(RowComputeResult rowInfo) { LinearLayout ll = new LinearLayout(getContext()); LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); ll.setOrientation(LinearLayout.HORIZONTAL); ll.setLayoutParams(params);// w w w. ja va 2s.c om int nbColumns = rowInfo.group.mDisplayCols; if (hasCustomGroupView()) { nbColumns = 1; } for (int i = 0; i < nbColumns; i++) { View view = getItemView(rowInfo, i, null, ll); setupLayoutParams(view); ll.addView(view); } return ll; }
From source file:com.neka.cordova.inappbrowser.InAppBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load. * @param jsonObject/* w ww. j av a 2s . 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; } 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); /* back.setText("<"); */ 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); //forward.setText(">"); 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 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); //close.setText(buttonLabel); 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:com.bhb27.isu.Props.java
private void EditProps(String[] props) { LinearLayout linearLayout = new LinearLayout(getActivity()); linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.setGravity(Gravity.CENTER); linearLayout.setPadding(30, 20, 30, 20); TextView descriptionText = new TextView(getActivity()); descriptionText.setText(getString(R.string.props_any_edit_dialog_summary)); linearLayout.addView(descriptionText); ScrollView scrollView = new ScrollView(getActivity()); scrollView.setPadding(0, 0, 0, 10);/*from www.j a v a2 s. c o m*/ linearLayout.addView(scrollView); LinearLayout editLayout = new LinearLayout(getActivity()); editLayout.setOrientation(LinearLayout.VERTICAL); scrollView.addView(editLayout); final AppCompatEditText[] EditProps = new AppCompatEditText[props.length]; final AppCompatCheckBox[] ForceBP = new AppCompatCheckBox[props.length]; final TextView[] descriptionAboveText = new TextView[props.length]; final TextView[] descriptionBelowText = new TextView[props.length]; for (int i = 0; i < props.length; i++) { descriptionAboveText[i] = new TextView(getActivity()); descriptionAboveText[i].setText(String.format(getString(R.string.empty), props[i])); editLayout.addView(descriptionAboveText[i]); EditProps[i] = new AppCompatEditText(getActivity()); EditProps[i].setText(Tools.getprop(props[i])); editLayout.addView(EditProps[i]); descriptionBelowText[i] = new TextView(getActivity()); descriptionBelowText[i].setText(getString(R.string.props_any_edit_dialog_already_bp)); ForceBP[i] = new AppCompatCheckBox(getActivity()); ForceBP[i].setText(getString(R.string.props_any_edit_dialog_force_bp)); if (Tools.PropIsinbp(props[i], getActivity())) editLayout.addView(descriptionBelowText[i]); else editLayout.addView(ForceBP[i]); } new AlertDialog.Builder(getActivity(), R.style.AlertDialogStyle) .setTitle(getString(R.string.props_any_edit_dialog_title)).setView(linearLayout) .setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { return; } }).setPositiveButton(getString(R.string.apply), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int id) { String finalmenssage = "\n", edited; for (int i = 0; i < props.length; i++) { edited = EditProps[i].getText().toString(); if (edited.isEmpty()) { finalmenssage = finalmenssage + String.format(getString(R.string.edited_text_ro), props[i]); } else if (edited.equals(Tools.getprop(props[i]))) finalmenssage = finalmenssage + String.format(getString(R.string.edited_text_equals), props[i]); else { if (((AppCompatCheckBox) ForceBP[i]).isChecked()) Tools.resetprop(executableFilePath, props[i], edited, getActivity(), true); else Tools.resetprop(executableFilePath, props[i], edited, getActivity(), false); finalmenssage = finalmenssage + String.format(getString(R.string.edited_text_ok), props[i]); save_prop(props[i], edited); } finalmenssage = finalmenssage + "\n"; } finaldialogro(finalmenssage); return; } }).show(); }