List of usage examples for android.widget LinearLayout addView
public void addView(View child)
Adds a child view.
From source file:com.cmput301w15t15.travelclaimsapp.activitys.EditClaimActivity.java
/** * Create a alert dialog for entering Destination values * /*from w ww.j ava 2 s . c o m*/ */ private void showDestinationAlert(final String dlocation, final String dreason) { final EditText enterLocation = new EditText(this); final EditText enterReason = new EditText(this); if (!dlocation.equals("")) { enterLocation.setText(dlocation); } if (!dreason.equals("")) { enterReason.setText(dreason); } enterLocation.setHint("Enter location"); enterReason.setHint("Enter reason"); LinearLayout linearLayout = new LinearLayout(this); linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.addView(enterLocation); linearLayout.addView(enterReason); AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setView(linearLayout); alert.setPositiveButton("Add", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Destination dest = new Destination(enterLocation.getText().toString(), enterReason.getText().toString()); ClaimListController.addDestination(dest, theClaim); //open Map activity and make user pick a geolocation Intent intent = GeoLocationController.pickLocationIntent(EditClaimActivity.this); startActivityForResult(intent, GET_GEOLOCATION_CODE); destAdaptor.notifyDataSetChanged(); } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); alert.show(); }
From source file:com.appfirst.activities.details.AFServerDetail.java
/** * Draw a ScrollView to display the CPU value for each core. * /* www .ja v a 2s. c o m*/ * @return a ScrollView containing a list of BarView. */ private View createCPUListDialog() { ScrollView container = createOuterContainer(); LinearLayout innerContainer = createInnerContainer(); List<BasicNameValuePair> items = data.getCpu_cores(); for (int i = 0; i < items.size(); i++) { BasicNameValuePair item = items.get(i); Double value = Double.parseDouble(item.getValue()); LinearLayout row = createTableRow(LinearLayout.HORIZONTAL); AFBarView barView = createBarView(value); row.addView(barView); innerContainer.addView(row); } container.addView(innerContainer); innerContainer.invalidate(); container.invalidate(); return container; }
From source file:com.fbbackup.MyFriendFragmentActivity.java
public void setView() { rl_prb_download = (RelativeLayout) findViewById(R.id.rl_prb_download); rl_controls = (RelativeLayout) findViewById(R.id.rl_controls); btn_tag_me = (ImageButton) findViewById(R.id.btn_tag_me); btn_photo = (ImageButton) findViewById(R.id.btn_photo); pb_download = (ProgressBar) findViewById(R.id.pb_download); btn_cancel_download = (ImageButton) findViewById(R.id.btn_cancel_download); btn_logout = (Button) findViewById(R.id.btn_logout); LinearLayout layout = (LinearLayout) findViewById(R.id.rl_ad); btn_photo.setBackgroundResource(R.drawable.album); // b[J adView layout.addView(adView); ///*www . jav a2 s .c o m*/ // // xDAHsi@_J adView.loadAd(new AdRequest()); }
From source file:com.appfirst.activities.details.AFServerDetail.java
/** * Draw a ScrollView to display the Disk usage for each disk. * //from www. j av a 2s .c o m * @return a ScrollView containing a list of AFBarView and AFPieView. */ private View createDiskListDialog() { // use the scroll view to scale ScrollView container = createOuterContainer(); LinearLayout innerContainer = createInnerContainer(); List<BasicNameValuePair> items = data.getDisk_percent_part(); for (int i = 0; i < items.size(); i++) { BasicNameValuePair item = items.get(i); Double value = Double.parseDouble(item.getValue()); String name = item.getName(); LinearLayout row = createTableRow(LinearLayout.HORIZONTAL); AFPieView pieView = createPieView(value); row.addView(pieView); TextView text = new TextView(this); text.setPadding(10, 0, 0, 0); text.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); text.setText(String.format("%s - %.1f %s used", name, value, "%")); row.addView(text); innerContainer.addView(row); } container.addView(innerContainer); innerContainer.invalidate(); container.invalidate(); return container; }
From source file:com.farmerbb.taskbar.service.DashboardService.java
private void addWidget(int appWidgetId, int cellId, boolean shouldSave) { AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); final DashboardCell cellLayout = cells.get(cellId); final AppWidgetHostView hostView = mAppWidgetHost.createView(DashboardService.this, appWidgetId, appWidgetInfo);//from ww w . ja v a 2 s . c o m hostView.setAppWidget(appWidgetId, appWidgetInfo); Bundle bundle = new Bundle(); bundle.putInt("cellId", cellId); hostView.setTag(bundle); cellLayout.findViewById(R.id.empty).setVisibility(View.GONE); cellLayout.findViewById(R.id.placeholder).setVisibility(View.GONE); cellLayout.setOnLongClickListener(olcl); cellLayout.setOnGenericMotionListener(ogml); cellLayout.setOnInterceptedLongPressListener(listener); LinearLayout linearLayout = (LinearLayout) cellLayout.findViewById(R.id.dashboard); linearLayout.addView(hostView); Bundle bundle2 = (Bundle) cellLayout.getTag(); bundle2.putInt("appWidgetId", appWidgetId); cellLayout.setTag(bundle2); widgets.put(cellId, hostView); if (shouldSave) { SharedPreferences pref = U.getSharedPreferences(this); SharedPreferences.Editor editor = pref.edit(); editor.putInt("dashboard_widget_" + Integer.toString(cellId), appWidgetId); editor.putString("dashboard_widget_" + Integer.toString(cellId) + "_provider", appWidgetInfo.provider.flattenToString()); editor.remove("dashboard_widget_" + Integer.toString(cellId) + "_placeholder"); editor.apply(); } new Handler().post(() -> { ViewGroup.LayoutParams params = hostView.getLayoutParams(); params.width = cellLayout.getWidth(); params.height = cellLayout.getHeight(); hostView.setLayoutParams(params); hostView.updateAppWidgetSize(null, cellLayout.getWidth(), cellLayout.getHeight(), cellLayout.getWidth(), cellLayout.getHeight()); }); }
From source file:com.facebook.android.FbDialog.java
private void setUpWebView(int margin) { LinearLayout webViewContainer = new LinearLayout(getContext()); mWebView = new WebView(getContext()); mWebView.setVerticalScrollBarEnabled(false); mWebView.setHorizontalScrollBarEnabled(false); mWebView.setWebViewClient(new FbDialog.FbWebViewClient()); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.loadUrl(mUrl);//from w w w . j a v a 2s . c o m mWebView.setLayoutParams(FILL); mWebView.setVisibility(View.INVISIBLE); webViewContainer.setPadding(margin, margin, margin, margin); webViewContainer.addView(mWebView); mContent.addView(webViewContainer); }
From source file:com.garage.payless.fragment.FragmentList.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View rootView = inflater.inflate(R.layout.list_fragment, container, false); DelayAutoCompleteTextView bookTitle = (DelayAutoCompleteTextView) rootView.findViewById(R.id.book_title); bookTitle.setThreshold(4);//ww w .ja va 2s .c o m bookTitle.setAdapter(new GoodAutoCompleteAdapter(getActivity().getApplicationContext())); bookTitle.setLoadingIndicator((ProgressBar) rootView.findViewById(R.id.progress_bar)); bookTitle.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) { LinearLayout basketList = (LinearLayout) rootView.findViewById(R.id.basket); LinearLayout row = new LinearLayout(getActivity().getApplicationContext()); row.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); row.setOrientation(LinearLayout.HORIZONTAL); TextView valueTV = new TextView(getActivity().getApplicationContext()); valueTV.setText((String) adapterView.getItemAtPosition(position)); valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); row.addView(valueTV); ImageButton cancel = new ImageButton(getActivity().getApplicationContext()); cancel.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); cancel.setImageDrawable(Drawable.createFromPath("@android:drawable/ic_menu_close_clear_cancel")); row.addView(cancel); basketList.addView(row); } }); rootView.findViewById(R.id.create_btn).setOnClickListener(this); return rootView; }
From source file:jp.ne.sakura.kkkon.java.net.socketimpl.testapp.android.SocketImplHookTestApp.java
/** Called when the activity is first created. */ @Override//ww w . ja v a 2 s . c o m public void onCreate(Bundle savedInstanceState) { final Context context = this.getApplicationContext(); { SocketImplHookFactory.initialize(); } { ProxySelector proxySelector = ProxySelector.getDefault(); Log.d(TAG, "proxySelector=" + proxySelector); if (null != proxySelector) { URI uri = null; try { uri = new URI("http://www.google.com/"); } catch (URISyntaxException e) { Log.d(TAG, e.toString()); } List<Proxy> proxies = proxySelector.select(uri); if (null != proxies) { for (final Proxy proxy : proxies) { Log.d(TAG, " proxy=" + proxy); } } } } super.onCreate(savedInstanceState); /* Create a TextView and set its content. * the text is retrieved by calling a native * function. */ LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setText("ExceptionHandler"); layout.addView(tv); Button btn1 = new Button(this); btn1.setText("invoke Exception"); btn1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { final int count = 2; int[] array = new int[count]; int value = array[count]; // invoke IndexOutOfBOundsException } }); layout.addView(btn1); { Button btn = new Button(this); btn.setText("upload http AsyncTask"); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { AsyncTask<String, Void, Boolean> asyncTask = new AsyncTask<String, Void, Boolean>() { @Override protected Boolean doInBackground(String... paramss) { Boolean result = true; Log.d(TAG, "upload AsyncTask tid=" + android.os.Process.myTid()); try { //$(BRAND)/$(PRODUCT)/$(DEVICE)/$(BOARD):$(VERSION.RELEASE)/$(ID)/$(VERSION.INCREMENTAL):$(TYPE)/$(TAGS) Log.d(TAG, "fng=" + Build.FINGERPRINT); final List<NameValuePair> list = new ArrayList<NameValuePair>(16); list.add(new BasicNameValuePair("fng", Build.FINGERPRINT)); HttpPost httpPost = new HttpPost(paramss[0]); //httpPost.getParams().setParameter( CoreConnectionPNames.SO_TIMEOUT, new Integer(5*1000) ); httpPost.setEntity(new UrlEncodedFormEntity(list, HTTP.UTF_8)); DefaultHttpClient httpClient = new DefaultHttpClient(); Log.d(TAG, "socket.timeout=" + httpClient.getParams() .getIntParameter(CoreConnectionPNames.SO_TIMEOUT, -1)); Log.d(TAG, "connection.timeout=" + httpClient.getParams() .getIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, -1)); httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, new Integer(5 * 1000)); httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, new Integer(5 * 1000)); Log.d(TAG, "socket.timeout=" + httpClient.getParams() .getIntParameter(CoreConnectionPNames.SO_TIMEOUT, -1)); Log.d(TAG, "connection.timeout=" + httpClient.getParams() .getIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, -1)); // <uses-permission android:name="android.permission.INTERNET"/> // got android.os.NetworkOnMainThreadException, run at UI Main Thread HttpResponse response = httpClient.execute(httpPost); Log.d(TAG, "response=" + response.getStatusLine().getStatusCode()); } catch (Exception e) { Log.d(TAG, "got Exception. msg=" + e.getMessage(), e); result = false; } Log.d(TAG, "upload finish"); return result; } }; asyncTask.execute("http://kkkon.sakura.ne.jp/android/bug"); asyncTask.isCancelled(); } }); layout.addView(btn); } { Button btn = new Button(this); btn.setText("pre DNS query(0.0.0.0)"); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { isReachable = false; Thread thread = new Thread(new Runnable() { public void run() { try { destHost = InetAddress.getByName("0.0.0.0"); if (null != destHost) { try { if (destHost.isReachable(5 * 1000)) { Log.d(TAG, "destHost=" + destHost.toString() + " reachable"); } else { Log.d(TAG, "destHost=" + destHost.toString() + " not reachable"); } } catch (IOException e) { } } } catch (UnknownHostException e) { } Log.d(TAG, "destHost=" + destHost); } }); thread.start(); try { thread.join(1000); } catch (InterruptedException e) { } } }); layout.addView(btn); } { Button btn = new Button(this); btn.setText("pre DNS query(www.google.com)"); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { isReachable = false; Thread thread = new Thread(new Runnable() { public void run() { try { InetAddress dest = InetAddress.getByName("www.google.com"); if (null == dest) { dest = destHost; } if (null != dest) { try { if (dest.isReachable(5 * 1000)) { Log.d(TAG, "destHost=" + dest.toString() + " reachable"); isReachable = true; } else { Log.d(TAG, "destHost=" + dest.toString() + " not reachable"); } destHost = dest; } catch (IOException e) { } } else { } } catch (UnknownHostException e) { Log.d(TAG, "dns error" + e.toString()); destHost = null; } { if (null != destHost) { Log.d(TAG, "destHost=" + destHost); } } } }); thread.start(); try { thread.join(); { final String addr = (null == destHost) ? ("") : (destHost.toString()); final String reachable = (isReachable) ? ("reachable") : ("not reachable"); Toast toast = Toast.makeText(context, "DNS result=\n" + addr + "\n " + reachable, Toast.LENGTH_LONG); toast.show(); } } catch (InterruptedException e) { } } }); layout.addView(btn); } { Button btn = new Button(this); btn.setText("pre DNS query(kkkon.sakura.ne.jp)"); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { isReachable = false; Thread thread = new Thread(new Runnable() { public void run() { try { InetAddress dest = InetAddress.getByName("kkkon.sakura.ne.jp"); if (null == dest) { dest = destHost; } if (null != dest) { try { if (dest.isReachable(5 * 1000)) { Log.d(TAG, "destHost=" + dest.toString() + " reachable"); isReachable = true; } else { Log.d(TAG, "destHost=" + dest.toString() + " not reachable"); } destHost = dest; } catch (IOException e) { } } else { } } catch (UnknownHostException e) { Log.d(TAG, "dns error" + e.toString()); destHost = null; } { if (null != destHost) { Log.d(TAG, "destHost=" + destHost); } } } }); thread.start(); try { thread.join(); { final String addr = (null == destHost) ? ("") : (destHost.toString()); final String reachable = (isReachable) ? ("reachable") : ("not reachable"); Toast toast = Toast.makeText(context, "DNS result=\n" + addr + "\n " + reachable, Toast.LENGTH_LONG); toast.show(); } } catch (InterruptedException e) { } } }); layout.addView(btn); } setContentView(layout); }
From source file:com.adguard.android.contentblocker.MainActivity.java
@SuppressWarnings("ConstantConditions") private void refreshMainInfo() { boolean available = false; boolean reorder = false; final boolean samsungBrowserAvailable = BrowserUtils.isSamsungBrowserAvailable(this); final boolean yandexBrowserAvailable = BrowserUtils.isYandexBrowserAvailable(this); if (samsungBrowserAvailable) { available = true;/* w w w .j a v a2 s . c o m*/ if (!yandexBrowserAvailable) { reorder = true; } findViewById(R.id.start_samsung_browser).setVisibility(View.VISIBLE); findViewById(R.id.start_samsung_settings).setVisibility(View.VISIBLE); findViewById(R.id.install_samsung_browser).setVisibility(View.GONE); findViewById(R.id.start_samsung_browser).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { BrowserUtils.startSamsungBrowser(MainActivity.this); } }); findViewById(R.id.start_samsung_settings).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { BrowserUtils.openSamsungBlockingOptions(MainActivity.this); } }); } else { findViewById(R.id.start_samsung_browser).setVisibility(View.GONE); findViewById(R.id.start_samsung_settings).setVisibility(View.GONE); findViewById(R.id.install_samsung_browser).setVisibility(View.VISIBLE); findViewById(R.id.install_samsung_browser).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ActivityUtils.startMarket(MainActivity.this, "com.sec.android.app.sbrowser", null); } }); } if (yandexBrowserAvailable) { available = true; findViewById(R.id.start_yandex_browser).setVisibility(View.VISIBLE); findViewById(R.id.start_yandex_settings).setVisibility(View.VISIBLE); findViewById(R.id.install_yandex_browser).setVisibility(View.GONE); findViewById(R.id.start_yandex_browser).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { BrowserUtils.startYandexBrowser(MainActivity.this); } }); findViewById(R.id.start_yandex_settings).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { BrowserUtils.openYandexBlockingOptions(MainActivity.this); } }); } else { findViewById(R.id.start_yandex_browser).setVisibility(View.GONE); findViewById(R.id.start_yandex_settings).setVisibility(View.GONE); findViewById(R.id.install_yandex_browser).setVisibility(View.VISIBLE); findViewById(R.id.install_yandex_browser).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ActivityUtils.startMarket(MainActivity.this, "com.yandex.browser", "adguard1"); } }); } if (available) { findViewById(R.id.choose_browser_button).setVisibility(View.GONE); findViewById(R.id.enable_adguard_button).setVisibility(View.VISIBLE); findViewById(R.id.enable_adguard_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (yandexBrowserAvailable) { BrowserUtils.openYandexBlockingOptions(MainActivity.this); } else { BrowserUtils.openSamsungBlockingOptions(MainActivity.this); } } }); if (reorder) { View yandex = findViewById(R.id.yandex_card); LinearLayout layout = (LinearLayout) findViewById(R.id.cards_layout); layout.removeView(yandex); layout.addView(yandex); } PreferencesService preferencesService = ServiceLocator.getInstance(getApplicationContext()) .getPreferencesService(); if (preferencesService.getBrowserConnectedCount() > 0) { View noBrowsersCard = findViewById(R.id.no_browsers_card); LinearLayout layout = (LinearLayout) findViewById(R.id.cards_layout); layout.removeView(noBrowsersCard); layout.addView(noBrowsersCard); } } else { findViewById(R.id.choose_browser_button).setVisibility(View.VISIBLE); findViewById(R.id.enable_adguard_button).setVisibility(View.GONE); findViewById(R.id.choose_browser_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { BrowserUtils.showBrowserInstallDialog(MainActivity.this); } }); } refreshStatistics(); FilterServiceImpl.enableContentBlocker(this); }
From source file:com.google.sample.beaconservice.ManageBeaconFragment.java
private LinearLayout makeAttachmentTableHeader() { LinearLayout headerRow = new LinearLayout(getActivity()); headerRow.addView(makeTextView("Namespace")); headerRow.addView(makeTextView("Type")); headerRow.addView(makeTextView("Data")); // Attachment rows will have four elements, so insert a fake one here with the same // layout weight as the delete button. TextView dummyView = new TextView(getActivity()); dummyView.setLayoutParams(BUTTON_COL_LAYOUT); headerRow.addView(dummyView);/*from w ww . j a v a2 s . co m*/ return headerRow; }