List of usage examples for android.widget RelativeLayout setLayoutParams
public void setLayoutParams(ViewGroup.LayoutParams params)
From source file:mobisocial.musubi.ui.FeedIdentityGrid.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //TODO: this begs for being in util, huh. i wonder where else it is used. //check that we aren't going to send a message using the local authority //to our friends. This is similar to the initial hidden state of the //person picker on the feed list mDatabaseSource = App.getDatabaseSource(this); mIdentitiesManager = new IdentitiesManager(mDatabaseSource); mFeedManager = new FeedManager(mDatabaseSource); if (mIdentitiesManager.getOwnedIdentities().size() < 2) { Toast.makeText(this, "You must connect an account in Musubi to be able to share with your contacts", Toast.LENGTH_SHORT).show(); Intent intent = new Intent(this, FeedListActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent);// w ww. j a v a 2s . c o m return; } setTitle("Share"); RelativeLayout window = new RelativeLayout(this); LayoutParams fill = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); window.setLayoutParams(fill); // Identity multi-select mIdentitySelector = new MultiIdentitySelector(this); mIdentitySelector.setOnIdentitiesUpdatedListener(mIdentitiesUpdatedListener); mIdentitySelector.setOnRequestAddIdentityListener(mOnRequestAddIdentityListener); RelativeLayout.LayoutParams selectorParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); selectorParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); mIdentitySelector.setLayoutParams(selectorParams); mIdentitySelector.setId(R.id.people); // Feed list mFeedListView = new ListView(this); RelativeLayout.LayoutParams listParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); listParams.addRule(RelativeLayout.BELOW, R.id.people); listParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); mFeedListView.setLayoutParams(listParams); mFeedListView.setOnItemClickListener(mFeedClickListener); // Must be called before setAdapter(): //mFeedListView.addHeaderView(mHeaderView); // Bind to content view window.addView(mIdentitySelector); window.addView(mFeedListView); setContentView(window, fill); getSupportLoaderManager().initLoader(LOAD_FEEDS, null, this); }
From source file:com.breadwallet.tools.adapter.TransactionListAdapter.java
@Override public View getView(int position, View convertView, ViewGroup viewGroup) { View tmpLayout = inflater.inflate(R.layout.transaction_list_item, null); if (data.size() == 0 && position == 0) { RelativeLayout noTransactions = (RelativeLayout) inflater.inflate(R.layout.button_no_transactions, null);/*from ww w .ja va 2 s .c om*/ noTransactions.setLayoutParams(new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Utils.getPixelsFromDps(activity, 70))); return noTransactions; } else if (position == getCount() - (buyBitcoinEnabled ? 5 : 4)) { View separator = new View(activity); separator.setLayoutParams(new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Utils.getPixelsFromDps(activity, 30))); separator.setBackgroundResource(android.R.color.transparent); return separator; } else if (buyBitcoinEnabled && position == getCount() - 4) { RelativeLayout buyBitcoinLayout = (RelativeLayout) inflater.inflate(R.layout.button_buy_bitcoin, null); buyBitcoinLayout.setLayoutParams(new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Utils.getPixelsFromDps(activity, 50))); buyBitcoinLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (BRAnimator.checkTheMultipressingAvailability()) { FragmentWebView fragmentWebView = new FragmentWebView(); fragmentWebView.setMode(1); BRAnimator.animateSlideToLeft((MainActivity) activity, fragmentWebView, FragmentSettingsAll.instantiate(activity, FragmentSettingsAll.class.getName())); } } }); return buyBitcoinLayout; } else if (position == getCount() - 3) { RelativeLayout importPrivateKeys = (RelativeLayout) inflater.inflate(R.layout.button_import_privkey, null); importPrivateKeys.setLayoutParams(new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Utils.getPixelsFromDps(activity, 50))); importPrivateKeys.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (BRAnimator.checkTheMultipressingAvailability()) { BRAnimator.animateDecoderFragment(); } } }); return importPrivateKeys; } else if (position == getCount() - 2) { RelativeLayout settings = (RelativeLayout) inflater.inflate(R.layout.button_settings, null); settings.setLayoutParams(new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Utils.getPixelsFromDps(activity, 50))); settings.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (BRAnimator.checkTheMultipressingAvailability()) { MainActivity app = MainActivity.app; if (app == null) return; FragmentSettingsAll fragmentSettingsAll = (FragmentSettingsAll) activity .getFragmentManager().findFragmentByTag(FragmentSettingsAll.class.getName()); BRAnimator.animateSlideToLeft(app, new FragmentSettings(), fragmentSettingsAll); } } }); return settings; } else if (position == getCount() - 1) { View separator = new View(activity); separator.setLayoutParams(new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Utils.getPixelsFromDps(activity, 30))); separator.setBackgroundResource(android.R.color.transparent); separator.setClickable(false); return separator; } if (!BreadWalletApp.unlocked) { if (getUnconfirmedCount(data) == 0 && position == 0) { RelativeLayout txHistory = (RelativeLayout) inflater.inflate(R.layout.button_transaction_history, null); txHistory.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Utils.getPixelsFromDps(activity, 40))); txHistory.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (BRAnimator.checkTheMultipressingAvailability()) { ((BreadWalletApp) activity.getApplicationContext()).promptForAuthentication(activity, BRConstants.AUTH_FOR_GENERAL, null, null, null, null, false); } } }); return txHistory; } else { if (position == getUnconfirmedCount(data)) { RelativeLayout moreAuth = (RelativeLayout) inflater.inflate(R.layout.button_more, null); moreAuth.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Utils.getPixelsFromDps(activity, 40))); moreAuth.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (BRAnimator.checkTheMultipressingAvailability()) { ((BreadWalletApp) activity.getApplicationContext()).promptForAuthentication( activity, BRConstants.AUTH_FOR_GENERAL, null, null, null, null, false); } } }); return moreAuth; } else { return getTxView(tmpLayout, position); } } } else { if (showAllTx) return getTxView(tmpLayout, position); if (data.size() > 5) { if (position < 5) { return getTxView(tmpLayout, position); } else { RelativeLayout more = (RelativeLayout) inflater.inflate(R.layout.button_more, null); more.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Utils.getPixelsFromDps(activity, 40))); more.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showAllTx = true; notifyDataSetChanged(); } }); return more; } } else { return getTxView(tmpLayout, position); } } }
From source file:fr.cph.chicago.core.adapter.NearbyAdapter.java
private View handleBuses(final int position, @NonNull final ViewGroup parent) { final LayoutInflater vi = (LayoutInflater) parent.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); final View convertView = vi.inflate(R.layout.list_nearby, parent, false); // Bus//from w w w . j a v a 2s . co m final int index = position - stations.size(); final BusStop busStop = busStops.get(index); final ImageView imageView = (ImageView) convertView.findViewById(R.id.icon); imageView.setImageDrawable( ContextCompat.getDrawable(parent.getContext(), R.drawable.ic_directions_bus_white_24dp)); final TextView routeView = (TextView) convertView.findViewById(R.id.station_name); routeView.setText(busStop.getName()); final LinearLayout resultLayout = (LinearLayout) convertView.findViewById(R.id.nearby_results); final Map<String, List<BusArrival>> arrivalsForStop = busArrivals.get(busStop.getId(), new HashMap<>()); Stream.of(arrivalsForStop.entrySet()).forEach(entry -> { final LinearLayout.LayoutParams leftParam = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); final RelativeLayout insideLayout = new RelativeLayout(context); insideLayout.setLayoutParams(leftParam); insideLayout.setPadding(line1PaddingColor * 2, stopsPaddingTop, 0, 0); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { insideLayout.setBackground(ContextCompat.getDrawable(parent.getContext(), R.drawable.any_selector)); } final RelativeLayout lineIndication = LayoutUtil.createColoredRoundForFavorites(context, TrainLine.NA); int lineId = Util.generateViewId(); lineIndication.setId(lineId); final RelativeLayout.LayoutParams stopParam = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); stopParam.addRule(RelativeLayout.RIGHT_OF, lineId); stopParam.setMargins(Util.convertDpToPixel(context, 10), 0, 0, 0); final LinearLayout stopLayout = new LinearLayout(context); stopLayout.setOrientation(LinearLayout.VERTICAL); stopLayout.setLayoutParams(stopParam); int stopId = Util.generateViewId(); stopLayout.setId(stopId); final RelativeLayout.LayoutParams boundParam = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); boundParam.addRule(RelativeLayout.RIGHT_OF, stopId); final LinearLayout boundLayout = new LinearLayout(context); boundLayout.setOrientation(LinearLayout.HORIZONTAL); final String direction = entry.getKey(); final List<BusArrival> busArrivals = entry.getValue(); final String routeId = busArrivals.get(0).getRouteId(); final TextView bound = new TextView(context); final String routeIdText = routeId + " (" + direction + "): "; bound.setText(routeIdText); bound.setTextColor(ContextCompat.getColor(context, R.color.grey_5)); boundLayout.addView(bound); Stream.of(busArrivals).forEach(busArrival -> { final TextView timeView = new TextView(context); final String timeLeftDueDelay = busArrival.getTimeLeftDueDelay() + " "; timeView.setText(timeLeftDueDelay); timeView.setTextColor(ContextCompat.getColor(context, R.color.grey)); timeView.setLines(1); timeView.setEllipsize(TruncateAt.END); boundLayout.addView(timeView); }); stopLayout.addView(boundLayout); insideLayout.addView(lineIndication); insideLayout.addView(stopLayout); resultLayout.addView(insideLayout); }); convertView.setOnClickListener(new NearbyOnClickListener(googleMap, markers, busStop.getId(), busStop.getPosition().getLatitude(), busStop.getPosition().getLongitude())); return convertView; }
From source file:fr.cph.chicago.core.adapter.NearbyAdapter.java
private View handleBikes(final int position, @NonNull final ViewGroup parent) { final LayoutInflater vi = (LayoutInflater) parent.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); final View convertView = vi.inflate(R.layout.list_nearby, parent, false); final int index = position - (stations.size() + busStops.size()); final BikeStation bikeStation = bikeStations.get(index); final LinearLayout favoritesData = (LinearLayout) convertView.findViewById(R.id.nearby_results); final ImageView imageView = (ImageView) convertView.findViewById(R.id.icon); imageView.setImageDrawable(// w ww . ja v a 2 s . c o m ContextCompat.getDrawable(parent.getContext(), R.drawable.ic_directions_bike_white_24dp)); final TextView routeView = (TextView) convertView.findViewById(R.id.station_name); routeView.setText(bikeStation.getName()); final LinearLayout llh = new LinearLayout(context); llh.setOrientation(LinearLayout.HORIZONTAL); llh.setPadding(line1PaddingColor, stopsPaddingTop, 0, 0); final LinearLayout availableLayout = new LinearLayout(context); availableLayout.setOrientation(LinearLayout.VERTICAL); final LinearLayout.LayoutParams leftParam = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); final RelativeLayout availableBikes = new RelativeLayout(context); availableBikes.setLayoutParams(leftParam); availableBikes.setPadding(line1PaddingColor, 0, 0, 0); final RelativeLayout lineIndication = LayoutUtil.createColoredRoundForFavorites(context, TrainLine.NA); int lineId = Util.generateViewId(); lineIndication.setId(lineId); final RelativeLayout.LayoutParams availableParam = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); availableParam.addRule(RelativeLayout.RIGHT_OF, lineId); availableParam.setMargins(Util.convertDpToPixel(context, 10), 0, 0, 0); final TextView availableBike = new TextView(context); availableBike.setText(context.getString(R.string.bike_available_bikes)); availableBike.setTextColor(ContextCompat.getColor(context, R.color.grey_5)); availableBike.setLayoutParams(availableParam); int availableBikeId = Util.generateViewId(); availableBike.setId(availableBikeId); final RelativeLayout.LayoutParams amountParam = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); amountParam.addRule(RelativeLayout.RIGHT_OF, availableBikeId); final TextView amountBike = new TextView(context); final String amountBikeText = String.valueOf(bikeStation.getAvailableBikes()); amountBike.setText(amountBikeText); int color = bikeStation.getAvailableBikes() == 0 ? R.color.red : R.color.green; amountBike.setTextColor(ContextCompat.getColor(context, color)); amountBike.setLayoutParams(amountParam); availableBikes.addView(lineIndication); availableBikes.addView(availableBike); availableBikes.addView(amountBike); final LinearLayout.LayoutParams leftParam2 = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); final RelativeLayout availableDocks = new RelativeLayout(context); availableDocks.setLayoutParams(leftParam2); availableDocks.setPadding(line1PaddingColor, 0, 0, 0); final RelativeLayout lineIndication2 = LayoutUtil.createColoredRoundForFavorites(context, TrainLine.NA); int lineId2 = Util.generateViewId(); lineIndication2.setId(lineId2); final RelativeLayout.LayoutParams availableDockParam = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); availableDockParam.addRule(RelativeLayout.RIGHT_OF, lineId2); availableDockParam.setMargins(Util.convertDpToPixel(context, 10), 0, 0, 0); final TextView availableDock = new TextView(context); availableDock.setText(context.getString(R.string.bike_available_docks)); availableDock.setTextColor(ContextCompat.getColor(context, R.color.grey_5)); availableDock.setLayoutParams(availableDockParam); int availableDockBikeId = Util.generateViewId(); availableDock.setId(availableDockBikeId); final RelativeLayout.LayoutParams amountParam2 = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); amountParam2.addRule(RelativeLayout.RIGHT_OF, availableDockBikeId); final TextView amountDock = new TextView(context); final String amountDockText = String.valueOf(bikeStation.getAvailableDocks()); amountDock.setText(amountDockText); color = bikeStation.getAvailableDocks() == 0 ? R.color.red : R.color.green; amountDock.setTextColor(ContextCompat.getColor(context, color)); amountDock.setLayoutParams(amountParam2); availableDocks.addView(lineIndication2); availableDocks.addView(availableDock); availableDocks.addView(amountDock); availableLayout.addView(availableBikes); availableLayout.addView(availableDocks); llh.addView(availableLayout); favoritesData.addView(llh); convertView.setOnClickListener(new NearbyOnClickListener(googleMap, markers, bikeStation.getId(), bikeStation.getLatitude(), bikeStation.getLongitude())); return convertView; }
From source file:com.tweetlanes.android.core.view.BaseLaneFragment.java
void configureLaneWidth(View resultView) { RelativeLayout laneContent = (RelativeLayout) resultView.findViewById(R.id.lane_content); if (laneContent != null) { RelativeLayout tweetFeedLoaded = (RelativeLayout) resultView.findViewById(R.id.tweet_feed_loaded); if (tweetFeedLoaded != null) { if (!AppSettings.get().showTabletMargin()) { android.view.ViewGroup.LayoutParams parentParams = tweetFeedLoaded.getLayoutParams(); laneContent.setLayoutParams( new RelativeLayout.LayoutParams(parentParams.width, parentParams.height)); } else { /*/*from w w w .ja va2 s . c o m*/ * final Resources res = getResources(); float width = * res.getDimension(R.dimen.lane_content_width); * RelativeLayout.LayoutParams params = new * RelativeLayout.LayoutParams((int) width, * RelativeLayout.LayoutParams.FILL_PARENT); * params.addRule(RelativeLayout.CENTER_IN_PARENT, -1); * laneContent.setLayoutParams(params); */ } } } }
From source file:com.shafiq.mytwittle.view.BaseLaneFragment.java
public void configureLaneWidth(View resultView) { RelativeLayout laneContent = (RelativeLayout) resultView.findViewById(R.id.lane_content); if (laneContent != null) { RelativeLayout tweetFeedLoaded = (RelativeLayout) resultView.findViewById(R.id.tweet_feed_loaded); if (tweetFeedLoaded != null) { if (AppSettings.get().showTabletMargin() == false) { android.view.ViewGroup.LayoutParams parentParams = tweetFeedLoaded.getLayoutParams(); laneContent.setLayoutParams( new RelativeLayout.LayoutParams(parentParams.width, parentParams.height)); } else { /*/*from w ww .j ava 2 s. c om*/ * final Resources res = getResources(); float width = * res.getDimension(R.dimen.lane_content_width); * RelativeLayout.LayoutParams params = new * RelativeLayout.LayoutParams((int) width, * RelativeLayout.LayoutParams.FILL_PARENT); * params.addRule(RelativeLayout.CENTER_IN_PARENT, -1); * laneContent.setLayoutParams(params); */ } } } }
From source file:com.tweetlanes.android.view.BaseLaneFragment.java
public void configureLaneWidth(View resultView) { RelativeLayout laneContent = (RelativeLayout) resultView.findViewById(R.id.lane_content); if (laneContent != null) { RelativeLayout tweetFeedLoaded = (RelativeLayout) resultView.findViewById(R.id.tweet_feed_loaded); if (tweetFeedLoaded != null) { if (AppSettings.get().showTabletMargin() == false) { android.view.ViewGroup.LayoutParams parentParams = tweetFeedLoaded.getLayoutParams(); laneContent.setLayoutParams( new RelativeLayout.LayoutParams(parentParams.width, parentParams.height)); } else { /*//from w w w . java 2 s.c o m final Resources res = getResources(); float width = res.getDimension(R.dimen.lane_content_width); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams((int) width, RelativeLayout.LayoutParams.FILL_PARENT); params.addRule(RelativeLayout.CENTER_IN_PARENT, -1); laneContent.setLayoutParams(params); */ } } } }
From source file:mobi.monaca.framework.plugin.ChildBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load. * @param jsonObject/* ww w. j a va2s . 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() { /** * 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) { try { JSONObject obj = new JSONObject(); obj.put("type", CLOSE_EVENT); sendUpdate(obj, false); } catch (JSONException e) { Log.d(LOG_TAG, "Should never happen"); } } }); // Main container layout LinearLayout main = new LinearLayout(cordova.getActivity()); main.setOrientation(LinearLayout.VERTICAL); // Toolbar layout RelativeLayout toolbar = new RelativeLayout(cordova.getActivity()); toolbar.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.FILL_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 ImageButton back = new ImageButton(cordova.getActivity()); RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT); backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT); back.setLayoutParams(backLayoutParams); back.setContentDescription("Back Button"); back.setId(2); back.setImageResource(R.drawable.childbroswer_icon_arrow_left); back.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goBack(); } }); // Forward button ImageButton forward = new ImageButton(cordova.getActivity()); RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT); forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2); forward.setLayoutParams(forwardLayoutParams); forward.setContentDescription("Forward Button"); forward.setId(3); forward.setImageResource(R.drawable.childbroswer_icon_arrow_right); 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.FILL_PARENT, LayoutParams.FILL_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 ImageButton close = new ImageButton(cordova.getActivity()); RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT); closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); close.setLayoutParams(closeLayoutParams); forward.setContentDescription("Close Button"); close.setId(5); close.setImageResource(R.drawable.childbroswer_icon_close); close.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { closeDialog(); } }); // WebView webview = new WebView(cordova.getActivity()); webview.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); 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(6); webview.getSettings().setLoadWithOverviewMode(true); webview.getSettings().setUseWideViewPort(true); webview.requestFocus(); webview.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(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 { //TODO check LocalFileBootloader InputStream input = cordova.getActivity().getAssets().open(filename); return BitmapFactory.decodeStream(input); } }; this.cordova.getActivity().runOnUiThread(runnable); return ""; }
From source file:HeaderGridView.java
/** added by Ahmed Basyouni * this method take supported fragment and fragment activity to add that * fragment as a banner to listView it create a layout at runtime then when * view is added to list we replace it with fragment otherwise it will crash * since view is not on screen to be replaced * * @param fragment//from w w w . j a v a2 s .c om * @param activity */ public void addBannerFragment(final Fragment fragment, final FragmentActivity activity) { RelativeLayout layout = new RelativeLayout(activity); AbsListView.LayoutParams param = new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); layout.setLayoutParams(param); // please don't ever remove that view otherwise application will crash and I mean it :D View view = new View(activity); view.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, 300)); view.setVisibility(View.INVISIBLE); layout.addView(view); layout.setId(CONTAINER_ID); addHeaderView(layout); this.addOnLayoutChangeListener(new OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { HeaderGridView.this.removeOnLayoutChangeListener(this); FragmentManager manager = activity.getSupportFragmentManager(); FragmentTransaction transaction = manager.beginTransaction(); transaction.replace(CONTAINER_ID, fragment).commit(); } }); }
From source file:phonegap.plugins.childBrowser.ChildBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load. * @param jsonObject/*from ww w. j a v a2 s . com*/ */ 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() { /** * 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) { try { JSONObject obj = new JSONObject(); obj.put("type", CLOSE_EVENT); sendUpdate(obj, false); } catch (JSONException e) { Log.d(LOG_TAG, "Should never happen"); } } }); // Main container layout LinearLayout main = new LinearLayout(cordova.getActivity()); main.setOrientation(LinearLayout.VERTICAL); // Toolbar layout RelativeLayout toolbar = new RelativeLayout(cordova.getActivity()); toolbar.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.FILL_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 ImageButton back = new ImageButton(cordova.getActivity()); RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT); backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT); back.setLayoutParams(backLayoutParams); back.setContentDescription("Back Button"); back.setId(2); try { back.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_left.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } back.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goBack(); } }); // Forward button ImageButton forward = new ImageButton(cordova.getActivity()); RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT); forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2); forward.setLayoutParams(forwardLayoutParams); forward.setContentDescription("Forward Button"); forward.setId(3); try { forward.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_right.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } 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.FILL_PARENT, LayoutParams.FILL_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 ImageButton close = new ImageButton(cordova.getActivity()); RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT); closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); close.setLayoutParams(closeLayoutParams); forward.setContentDescription("Close Button"); close.setId(5); try { close.setImageBitmap(loadDrawable("www/childbrowser/icon_close.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } close.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { closeDialog(); } }); // WebView webview = new WebView(cordova.getActivity()); webview.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); 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(6); webview.getSettings().setLoadWithOverviewMode(true); webview.getSettings().setUseWideViewPort(true); webview.requestFocus(); webview.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(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 = cordova.getActivity().getAssets().open(filename); return BitmapFactory.decodeStream(input); } }; this.cordova.getActivity().runOnUiThread(runnable); return ""; }