List of usage examples for android.widget Button Button
public Button(Context context)
From source file:com.gammalabs.wifianalyzer.wifi.graph.channel.ChannelGraphNavigation.java
private NavigationItem makeNavigationItem(Pair<WiFiChannel, WiFiChannel> pair) { Button button = new Button(context); String text = pair.first.getChannel() + " - " + pair.second.getChannel(); button.setLayoutParams(getLayoutParams()); button.setVisibility(View.GONE); button.setText(text);//from w ww . ja v a 2 s . co m button.setOnClickListener(new ButtonOnClickListener(pair)); return new NavigationItem(button, pair); }
From source file:com.aqnote.app.wifianalyzer.wifi.graph.channel.ChannelGraphNavigation.java
private NavigationItem makeNavigationItem(@NonNull Context context, Pair<WiFiChannel, WiFiChannel> pair) { Button button = new Button(context); String text = pair.first.getChannel() + " - " + pair.second.getChannel(); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, TEXT_SIZE_ADJUSTMENT); if (configuration.isLargeScreenLayout()) { params.setMargins(10, -10, 10, -10); } else {// w w w . j a v a 2s . co m params.setMargins(5, -30, 5, -30); } button.setLayoutParams(params); button.setVisibility(View.GONE); button.setText(text); button.setOnClickListener(new ButtonOnClickListener(pair)); return new NavigationItem(button, pair); }
From source file:dev.drsoran.moloko.fragments.TagCloudFragment.java
private void showTagCloudEntries(final List<TagCloudEntry> cloudEntries) { final Activity activity = getSherlockActivity(); // Sort all cloud entries by their name Collections.sort(cloudEntries); final int size = cloudEntries.size(); final List<Button> buttons = new ArrayList<Button>(size); for (int i = 0; i < size; ++i) { final TagCloudEntry cloudEntry = cloudEntries.get(i); final Button cloudEntryButton = new Button(activity); cloudEntryButton.setId(i);/*from ww w. j a v a 2 s. co m*/ cloudEntryButton.setText(cloudEntry.name); cloudEntryButton.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18 * getMagnifyFactor(cloudEntry.count)); cloudEntry.present(cloudEntryButton); cloudEntry.setTagCloudFragmentListener(listener); if (cloudEntry.count > 1) { cloudEntryButton.setTypeface(Typeface.DEFAULT_BOLD); } buttons.add(cloudEntryButton); } final ViewGroup tagContainer = (ViewGroup) activity.findViewById(R.id.tagcloud_container); addButtons(buttons, tagContainer); }
From source file:io.openkit.leaderboards.OKScoresFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { int viewID = getResources().getIdentifier("io_openkit_fragment_okscores", "layout", getActivity().getPackageName()); View view = inflater.inflate(viewID, container, false); //View view = inflater.inflate(R.layout.io_openkit_fragment_okscores, container, false); listView = (ListView) view.findViewById(android.R.id.list); int spinnerBarId, todayScoresButtonId, weekScoresButtonId, allTimeScoresButtonId; spinnerBarId = getResources().getIdentifier("progressSpinner", "id", getActivity().getPackageName()); todayScoresButtonId = getResources().getIdentifier("io_openkit_leaderboards_todayButton", "id", getActivity().getPackageName()); weekScoresButtonId = getResources().getIdentifier("io_openkit_leaderboards_thisWeekButton", "id", getActivity().getPackageName()); allTimeScoresButtonId = getResources().getIdentifier("io_openkit_leaderboards_allTimeButton", "id", getActivity().getPackageName()); spinnerBar = (ProgressBar) view.findViewById(spinnerBarId); todayScoresButton = (Button) view.findViewById(todayScoresButtonId); weekScoresButton = (Button) view.findViewById(weekScoresButtonId); allTimeScoresButton = (Button) view.findViewById(allTimeScoresButtonId); todayScoresButton.setOnClickListener(todayScoresPressed); weekScoresButton.setOnClickListener(thisWeekScoresPressed); allTimeScoresButton.setOnClickListener(allTimeScoresPressed); if (currentLeaderboard == null) { currentLeaderboard = getLeaderboard(); }/*from www . j a v a 2 s . co m*/ moreScoresButton = new Button(this.getActivity()); moreScoresButton.setText("Show more scores"); moreScoresButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { v.setEnabled(false); getMoreScores(currentLeaderboard.getDisplayedTimeRange(), v); } }); selectCurrentTab(); return view; }
From source file:jp.ne.sakura.kkkon.java.net.inetaddress.testapp.android.NetworkConnectionCheckerTestApp.java
/** Called when the activity is first created. */ @Override//from w w w. java2 s . c o m public void onCreate(Bundle savedInstanceState) { final Context context = this.getApplicationContext(); { NetworkConnectionChecker.initialize(); } 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("reachable="); layout.addView(tv); this.textView = 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("disp isReachable"); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { final boolean isReachable = NetworkConnectionChecker.isReachable(); Toast toast = Toast.makeText(context, "IsReachable=" + isReachable, Toast.LENGTH_LONG); toast.show(); } }); layout.addView(btn); } { 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() { Log.d(TAG, "start"); try { InetAddress dest = InetAddress.getByName("www.google.com"); if (null == dest) { dest = destHost; } if (null != dest) { final String[] uris = new String[] { "http://www.google.com/", "https://www.google.com/" }; for (final String destURI : uris) { URI uri = null; try { uri = new URI(destURI); } catch (URISyntaxException e) { //Log.d( TAG, e.toString() ); } if (null != uri) { URL url = null; try { url = uri.toURL(); } catch (MalformedURLException ex) { Log.d(TAG, "got exception:" + ex.toString(), ex); } URLConnection conn = null; if (null != url) { Log.d(TAG, "openConnection before"); try { conn = url.openConnection(); if (null != conn) { conn.setConnectTimeout(3 * 1000); conn.setReadTimeout(3 * 1000); } } catch (IOException e) { //Log.d( TAG, "got Exception" + e.toString(), e ); } Log.d(TAG, "openConnection after"); if (conn instanceof HttpURLConnection) { HttpURLConnection httpConn = (HttpURLConnection) conn; int responceCode = -1; try { Log.d(TAG, "getResponceCode before"); responceCode = httpConn.getResponseCode(); Log.d(TAG, "getResponceCode after"); } catch (IOException ex) { Log.d(TAG, "got exception:" + ex.toString(), ex); } Log.d(TAG, "responceCode=" + responceCode); if (0 < responceCode) { isReachable = true; destHost = dest; } Log.d(TAG, " HTTP ContentLength=" + httpConn.getContentLength()); httpConn.disconnect(); Log.d(TAG, " HTTP ContentLength=" + httpConn.getContentLength()); } } } // if uri if (isReachable) { //break; } } // for uris } else { } } catch (UnknownHostException e) { Log.d(TAG, "dns error" + e.toString()); destHost = null; } { if (null != destHost) { Log.d(TAG, "destHost=" + destHost); } } Log.d(TAG, "end"); } }); 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() { Log.d(TAG, "start"); 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); } } Log.d(TAG, "end"); } }); 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) support proxy"); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { isReachable = false; Thread thread = new Thread(new Runnable() { public void run() { try { String target = null; { 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); if (null != proxy) { if (Proxy.Type.HTTP == proxy.type()) { final SocketAddress sa = proxy.address(); if (sa instanceof InetSocketAddress) { final InetSocketAddress isa = (InetSocketAddress) sa; target = isa.getHostName(); break; } } } } } } } if (null == target) { target = "kkkon.sakura.ne.jp"; } InetAddress dest = InetAddress.getByName(target); 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"); { 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() ); } if (null != uri) { List<Proxy> proxies = proxySelector.select(uri); if (null != proxies) { for (final Proxy proxy : proxies) { //Log.d( TAG, " proxy=" + proxy ); if (null != proxy) { if (Proxy.Type.HTTP == proxy.type()) { URL url = uri.toURL(); URLConnection conn = null; if (null != url) { try { conn = url.openConnection(proxy); if (null != conn) { conn.setConnectTimeout( 3 * 1000); conn.setReadTimeout(3 * 1000); } } catch (IOException e) { Log.d(TAG, "got Exception" + e.toString(), e); } if (conn instanceof HttpURLConnection) { HttpURLConnection httpConn = (HttpURLConnection) conn; if (0 < httpConn .getResponseCode()) { isReachable = true; } Log.d(TAG, " HTTP ContentLength=" + httpConn .getContentLength()); Log.d(TAG, " HTTP res=" + httpConn .getResponseCode()); //httpConn.setInstanceFollowRedirects( false ); //httpConn.setRequestMethod( "HEAD" ); //conn.connect(); httpConn.disconnect(); Log.d(TAG, " HTTP ContentLength=" + httpConn .getContentLength()); Log.d(TAG, " HTTP res=" + httpConn .getResponseCode()); } } } } } } } } } } destHost = dest; } catch (IOException e) { Log.d(TAG, "got Excpetion " + e.toString()); } } 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.esri.android.ecologicalmarineunitexplorer.watercolumn.WaterColumnFragment.java
/** * Dynamically add a button for each EMU represented * in the water column./*from w w w.j a va2 s .c om*/ * @param waterColumn */ public void buildWaterColumn(WaterColumn waterColumn) { int count = mRoot.getChildCount(); for (int z = 0; z < count; z++) { View v = mRoot.getChildAt(z); if (v instanceof Button) { mRoot.removeViewAt(z); } } // Each button will be added to layout with a layout_weight // relative to the ratio of the EUMObservation to // the depth of the water column Set<EMUObservation> emuObservationSet = waterColumn.getEmuSet(); float depth = (float) waterColumn.getDepth(); TextView tv = (TextView) mRoot.findViewById(R.id.txtBottom); tv.setText(waterColumn.getDepth() + " m"); int buttonId = 0; for (EMUObservation observation : emuObservationSet) { float relativeSize = (observation.getThickness() / depth) * 100; final Button button = new Button(getContext()); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, 0, relativeSize); button.setLayoutParams(layoutParams); button.setBackground(buildStateList(observation.getEmu().getName())); button.setId(buttonId); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mSelectedButton != null) { mSelectedButton.setSelected(false); } button.setSelected(true); mSelectedButton = button; mCallback.onSegmentClicked(v.getId()); } }); mButtonContainer.addView(button); buttonId = buttonId + 1; } }
From source file:br.org.funcate.dynamicforms.views.GSketchView.java
/** * @param noteId the id of the note this image belows to. * @param fragmentDetail the fragment detail to use. * @param attrs attributes. * @param requestCode the code for starting the activity with result. * @param parentView parent/*w w w.j av a 2 s.c o m*/ * @param label label * @param value value * @param constraintDescription constraints */ public GSketchView(final long noteId, final FragmentDetail fragmentDetail, AttributeSet attrs, final int requestCode, LinearLayout parentView, String label, String value, String constraintDescription) { super(fragmentDetail.getActivity(), attrs); this.noteId = noteId; _value = value; final FragmentActivity activity = fragmentDetail.getActivity(); LinearLayout textLayout = new LinearLayout(activity); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); layoutParams.setMargins(10, 10, 10, 10); textLayout.setLayoutParams(layoutParams); textLayout.setOrientation(LinearLayout.VERTICAL); parentView.addView(textLayout); TextView textView = new TextView(activity); textView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); textView.setPadding(2, 2, 2, 2); textView.setText(label.replace(UNDERSCORE, " ").replace(COLON, " ") + " " + constraintDescription); textView.setTextColor(activity.getResources().getColor(R.color.formcolor)); textLayout.addView(textView); final Button button = new Button(activity); button.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); button.setPadding(15, 5, 15, 5); button.setText(R.string.draw_sketch); textLayout.addView(button); button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { try { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity); double[] gpsLocation = PositionUtilities.getGpsLocationFromPreferences(preferences); Date currentDate = new Date(); String sketchImageName = ImageUtilities.getSketchImageName(currentDate); File tempDir = ResourcesManager.getInstance(getContext()).getTempDir(); File sketchFile = new File(tempDir, sketchImageName); /* * open markers for new sketch */ MarkersUtilities.launch(fragmentDetail, sketchFile, gpsLocation, requestCode); } catch (Exception e) { //GPLog.error(this, null, e); Toast.makeText(getContext(), e.getMessage(), Toast.LENGTH_LONG).show(); } } }); ScrollView scrollView = new ScrollView(activity); ScrollView.LayoutParams scrollLayoutParams = new ScrollView.LayoutParams(LayoutParams.MATCH_PARENT, 150); scrollView.setLayoutParams(scrollLayoutParams); parentView.addView(scrollView); imageLayout = new LinearLayout(activity); LinearLayout.LayoutParams imageLayoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); imageLayout.setLayoutParams(imageLayoutParams); // imageLayout.setMinimumHeight(200); imageLayout.setOrientation(LinearLayout.HORIZONTAL); scrollView.addView(imageLayout); // scrollView.setFillViewport(true); try { refresh(activity); } catch (Exception e) { //GPLog.error(this, null, e); Toast.makeText(this.getContext(), e.getMessage(), Toast.LENGTH_LONG).show(); } }
From source file:eu.geopaparazzi.library.forms.views.GPictureView.java
/** * @param noteId the id of the note this image belows to. * @param fragmentDetail the fragment detail to use. * @param attrs attributes. * @param requestCode the code for starting the activity with result. * @param parentView parent// www. j av a 2 s . c om * @param key key * @param value in case of pictures, the value are the ids of the image, semicolonseparated. * @param constraintDescription constraints */ public GPictureView(final long noteId, final FragmentDetail fragmentDetail, AttributeSet attrs, final int requestCode, LinearLayout parentView, String key, String value, String constraintDescription) { super(fragmentDetail.getActivity(), attrs); _value = value; final FragmentActivity activity = fragmentDetail.getActivity(); LinearLayout textLayout = new LinearLayout(activity); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); layoutParams.setMargins(10, 10, 10, 10); textLayout.setLayoutParams(layoutParams); textLayout.setOrientation(LinearLayout.VERTICAL); parentView.addView(textLayout); TextView textView = new TextView(activity); textView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); textView.setPadding(2, 2, 2, 2); textView.setText(key.replace(UNDERSCORE, " ").replace(COLON, " ") + " " + constraintDescription); textView.setTextColor(activity.getResources().getColor(R.color.formcolor)); textLayout.addView(textView); final Button button = new Button(activity); button.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); button.setPadding(15, 5, 15, 5); button.setText(R.string.take_picture); textLayout.addView(button); button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity); double[] gpsLocation = PositionUtilities.getGpsLocationFromPreferences(preferences); String imageName = ImageUtilities.getCameraImageName(null); Intent cameraIntent = new Intent(activity, CameraActivity.class); cameraIntent.putExtra(LibraryConstants.PREFS_KEY_CAMERA_IMAGENAME, imageName); cameraIntent.putExtra(LibraryConstants.DATABASE_ID, noteId); if (gpsLocation != null) { cameraIntent.putExtra(LibraryConstants.LATITUDE, gpsLocation[1]); cameraIntent.putExtra(LibraryConstants.LONGITUDE, gpsLocation[0]); cameraIntent.putExtra(LibraryConstants.ELEVATION, gpsLocation[2]); } fragmentDetail.startActivityForResult(cameraIntent, requestCode); } }); ScrollView scrollView = new ScrollView(activity); ScrollView.LayoutParams scrollLayoutParams = new ScrollView.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); scrollView.setLayoutParams(scrollLayoutParams); parentView.addView(scrollView); imageLayout = new LinearLayout(activity); LinearLayout.LayoutParams imageLayoutParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); imageLayout.setLayoutParams(imageLayoutParams); imageLayout.setOrientation(LinearLayout.HORIZONTAL); scrollView.addView(imageLayout); try { refresh(activity); } catch (Exception e) { GPLog.error(this, null, e); } }
From source file:com.matthewtamlin.sliding_intro_screen_manual_testing.TestPageLock.java
/** * @return creates a Button which navigates to the previous page *//* w w w .ja v a 2 s .co m*/ private Button createGoToPreviousPageButton() { final Button button = new Button(this); button.setText("Go to previous page"); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final int startIndex = getIndexOfCurrentPage(); goToPreviousPage(); validateCommandPageChange(startIndex, (startIndex == 0) ? 0 : startIndex - 1); } }); return button; }
From source file:eu.geopaparazzi.library.forms.views.GSketchView.java
/** * @param noteId the id of the note this image belows to. * @param fragmentDetail the fragment detail to use. * @param attrs attributes. * @param requestCode the code for starting the activity with result. * @param parentView parent// w ww .j ava 2 s . c o m * @param key key * @param value value * @param constraintDescription constraints */ public GSketchView(final long noteId, final FragmentDetail fragmentDetail, AttributeSet attrs, final int requestCode, LinearLayout parentView, String key, String value, String constraintDescription) { super(fragmentDetail.getActivity(), attrs); this.noteId = noteId; _value = value; final FragmentActivity activity = fragmentDetail.getActivity(); LinearLayout textLayout = new LinearLayout(activity); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); layoutParams.setMargins(10, 10, 10, 10); textLayout.setLayoutParams(layoutParams); textLayout.setOrientation(LinearLayout.VERTICAL); parentView.addView(textLayout); TextView textView = new TextView(activity); textView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); textView.setPadding(2, 2, 2, 2); textView.setText(key.replace(UNDERSCORE, " ").replace(COLON, " ") + " " + constraintDescription); textView.setTextColor(activity.getResources().getColor(R.color.formcolor)); textLayout.addView(textView); final Button button = new Button(activity); button.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); button.setPadding(15, 5, 15, 5); button.setText(R.string.draw_sketch); textLayout.addView(button); button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { try { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity); double[] gpsLocation = PositionUtilities.getGpsLocationFromPreferences(preferences); Date currentDate = new Date(); String sketchImageName = ImageUtilities.getSketchImageName(currentDate); File tempDir = ResourcesManager.getInstance(getContext()).getTempDir(); File sketchFile = new File(tempDir, sketchImageName); /* * open markers for new sketch */ MarkersUtilities.launch(fragmentDetail, sketchFile, gpsLocation, requestCode); } catch (Exception e) { e.printStackTrace(); } } }); ScrollView scrollView = new ScrollView(activity); ScrollView.LayoutParams scrollLayoutParams = new ScrollView.LayoutParams(LayoutParams.FILL_PARENT, 150); scrollView.setLayoutParams(scrollLayoutParams); parentView.addView(scrollView); imageLayout = new LinearLayout(activity); LinearLayout.LayoutParams imageLayoutParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); imageLayout.setLayoutParams(imageLayoutParams); // imageLayout.setMinimumHeight(200); imageLayout.setOrientation(LinearLayout.HORIZONTAL); scrollView.addView(imageLayout); // scrollView.setFillViewport(true); try { refresh(activity); } catch (Exception e) { GPLog.error(this, null, e); } }