List of usage examples for android.widget LinearLayout measure
public final void measure(int widthMeasureSpec, int heightMeasureSpec)
This is called to find out how big a view should be.
From source file:com.thingsee.tracker.MainActivity.java
@SuppressLint("InflateParams") private Marker makeMarkerToMap(LatLng latLng, boolean visible, boolean alarmActive, String name, double timeStamp, double accuracy) { String snippet;//from w w w. j av a 2s .c om LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); LinearLayout tv = (LinearLayout) inflater.inflate(R.layout.tracker_map_marker, null, false); TextView trackerName = (TextView) tv.findViewById(R.id.tracker_name); trackerName.setText(name); ImageView image2 = (ImageView) tv.findViewById(R.id.tracker_marker_icon); if (alarmActive) { image2.setColorFilter(mResources.getColor(R.color.red)); trackerName.setTextColor(mResources.getColor(R.color.white_effect)); } else { image2.setColorFilter(mResources.getColor(R.color.dark_blue)); trackerName.setTextColor(mResources.getColor(R.color.white_effect)); } tv.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); tv.layout(0, 0, tv.getMeasuredWidth(), tv.getMeasuredHeight()); tv.setDrawingCacheEnabled(true); tv.buildDrawingCache(); Bitmap bm = tv.getDrawingCache(); tv = null; if (accuracy != -1) { snippet = String.format(mResources.getString(R.string.tracker_accuracy), accuracy); } else { snippet = String.format(mResources.getString(R.string.tracker_accuracy), 0.0f); } if (timeStamp != 0) { String timeStampText = Utilities.getSmartTimeStampString(mContext, mResources, timeStamp); snippet = snippet + "\n" + mResources.getString(R.string.tracker_timestamp) + " " + timeStampText; } else { snippet = snippet + "\n" + mResources.getString(R.string.tracker_timestamp) + " - "; } return mMap.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromBitmap(bm)) .visible(visible).title(name).snippet(snippet)); }
From source file:com.forrestguice.suntimeswidget.SuntimesActivity.java
/** * Stretch the horizontal rule to match the actual table width.. this is a hack to work around * unwanted stretching of the GridLayout columns when setting the hr to match_parent or fill_parent. *///ww w. ja v a 2s . c om private void stretchTableRule() { LinearLayout[] cards = new LinearLayout[2]; cards[0] = (LinearLayout) findViewById(R.id.info_time_all_today); cards[1] = (LinearLayout) findViewById(R.id.info_time_all_tomorrow); for (LinearLayout card : cards) // for each card { View tableRule = card.findViewById(R.id.table_rule); if (tableRule != null) { LinearLayout[] cols = new LinearLayout[3]; cols[0] = (LinearLayout) card.findViewById(R.id.table_head_date); cols[1] = (LinearLayout) card.findViewById(R.id.table_head_rise); cols[2] = (LinearLayout) card.findViewById(R.id.table_head_set); int tableWidth = 0; for (LinearLayout col : cols) // add up the measured column widths { if (col != null) { col.measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); tableWidth += col.getMeasuredWidth(); } } ViewGroup.LayoutParams tableRuleParams = tableRule.getLayoutParams(); tableRuleParams.width = tableWidth; tableRule.setLayoutParams(tableRuleParams); // and adjust the horizontal rule width } } }
From source file:com.samknows.measurement.activity.SamKnowsAggregateStatViewerActivity.java
@Override public void onClick(View v) { // Toast.makeText(this,"clicked ..."+v.getId(),3000).show(); ImageView button = null;//from w ww .ja va 2 s.co m LinearLayout l = null; int grid = 0; int testid = 0; boolean buttonfound = false; int id = v.getId(); if (id == R.id.download_header || id == R.id.btn_download_toggle) { if (total_download_archive_records > 0) { buttonfound = true; } grid = R.id.agggregate_test1_grid; testid = TestResult.DOWNLOAD_TEST_ID; l = (LinearLayout) findViewById(R.id.download_content); button = (ImageView) findViewById(R.id.btn_download_toggle); } if (id == R.id.upload_header || id == R.id.btn_upload_toggle) { if (total_upload_archive_records > 0) { buttonfound = true; } grid = R.id.agggregate_test2_grid; testid = TestResult.UPLOAD_TEST_ID; l = (LinearLayout) findViewById(R.id.upload_content); button = (ImageView) findViewById(R.id.btn_upload_toggle); } if (id == R.id.latency_header || id == R.id.btn_latency_toggle) { if (total_latency_archive_records > 0) { buttonfound = true; } grid = R.id.agggregate_test3_grid; testid = TestResult.LATENCY_TEST_ID; l = (LinearLayout) findViewById(R.id.latency_content); button = (ImageView) findViewById(R.id.btn_latency_toggle); } if (id == R.id.packetloss_header || id == R.id.btn_packetloss_toggle) { if (total_packetloss_archive_records > 0) { buttonfound = true; } grid = R.id.agggregate_test4_grid; testid = TestResult.PACKETLOSS_TEST_ID; l = (LinearLayout) findViewById(R.id.packetloss_content); button = (ImageView) findViewById(R.id.btn_packetloss_toggle); } if (id == R.id.jitter_header || id == R.id.btn_jitter_toggle) { if (total_jitter_archive_records > 0) { buttonfound = true; } grid = R.id.agggregate_test5_grid; testid = TestResult.JITTER_TEST_ID; l = (LinearLayout) findViewById(R.id.jitter_content); button = (ImageView) findViewById(R.id.btn_jitter_toggle); } // actions if (buttonfound) { if (l.getVisibility() == View.INVISIBLE) { button.setBackgroundResource(R.drawable.btn_up); button.setContentDescription(getString(R.string.close_panel)); // graphHandler1.update(); l.measure(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); target_height = l.getMeasuredHeight(); clearGrid(grid); loadDownloadGrid(testid, grid, 0, 5); l.getLayoutParams().height = 0; l.setVisibility(View.VISIBLE); ResizeAnimation animation = null; animation = new ResizeAnimation(l, target_height, 0, false); animation.setDuration(500); animation.setFillEnabled(true); animation.setFillAfter(true); animation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { } }); l.startAnimation(animation); } else { ResizeAnimation animation = null; int required_height = l.getMeasuredHeight(); animation = new ResizeAnimation(l, 0, target_height, false); animation.setDuration(500); animation.setFillEnabled(true); animation.setFillAfter(true); MyAnimationListener animationListener = new MyAnimationListener(); animationListener.setView(l); animation.setAnimationListener(animationListener); l.startAnimation(animation); button.setBackgroundResource(R.drawable.btn_down); button.setContentDescription(getString(R.string.open_panel)); } } }
From source file:cm.aptoide.pt.MainActivity.java
private void loadUItopapps() { ((ToggleButton) featuredView.findViewById(R.id.toggleButton1)).setOnCheckedChangeListener(null); Cursor c = db.getFeaturedTopApps(); values = new ArrayList<HashMap<String, String>>(); for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) { HashMap<String, String> item = new HashMap<String, String>(); item.put("name", c.getString(1)); item.put("icon", db.getIconsPath(0, Category.TOPFEATURED) + c.getString(4)); item.put("rating", c.getString(5)); item.put("id", c.getString(0)); item.put("apkid", c.getString(7)); item.put("vercode", c.getString(8)); item.put("vername", c.getString(2)); item.put("downloads", c.getString(6)); if (values.size() == 26) { break; }//from w ww. j a v a2 s. c o m values.add(item); } c.close(); runOnUiThread(new Runnable() { public void run() { LinearLayout ll = (LinearLayout) featuredView.findViewById(R.id.container); ll.removeAllViews(); LinearLayout llAlso = new LinearLayout(MainActivity.this); llAlso.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); llAlso.setOrientation(LinearLayout.HORIZONTAL); for (int i = 0; i != values.size(); i++) { LinearLayout txtSamItem = (LinearLayout) getLayoutInflater().inflate(R.layout.row_grid_item, null); ((TextView) txtSamItem.findViewById(R.id.name)).setText(values.get(i).get("name")); // ((TextView) txtSamItem.findViewById(R.id.version)) // .setText(getString(R.string.version) +" "+ // values.get(i).get("vername")); ((TextView) txtSamItem.findViewById(R.id.downloads)).setText( "(" + values.get(i).get("downloads") + " " + getString(R.string.downloads) + ")"); String hashCode = (values.get(i).get("apkid") + "|" + values.get(i).get("vercode")) + ""; cm.aptoide.com.nostra13.universalimageloader.core.ImageLoader.getInstance().displayImage( values.get(i).get("icon"), (ImageView) txtSamItem.findViewById(R.id.icon), hashCode); // imageLoader.DisplayImage(-1, values.get(i).get("icon"), // (ImageView) txtSamItem.findViewById(R.id.icon), // mContext); float stars = 0f; try { stars = Float.parseFloat(values.get(i).get("rating")); } catch (Exception e) { stars = 0f; } ((RatingBar) txtSamItem.findViewById(R.id.rating)).setRating(stars); ((RatingBar) txtSamItem.findViewById(R.id.rating)).setIsIndicator(true); txtSamItem.setPadding(10, 0, 0, 0); txtSamItem.setTag(values.get(i).get("id")); txtSamItem.setLayoutParams( new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 100, 1)); // txtSamItem.setOnClickListener(featuredListener); txtSamItem.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent i = new Intent(MainActivity.this, ApkInfo.class); long id = Long.parseLong((String) arg0.getTag()); i.putExtra("_id", id); i.putExtra("top", true); i.putExtra("category", Category.TOPFEATURED.ordinal()); startActivity(i); } }); txtSamItem.measure(0, 0); if (i % 2 == 0) { ll.addView(llAlso); llAlso = new LinearLayout(MainActivity.this); llAlso.setLayoutParams( new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 100)); llAlso.setOrientation(LinearLayout.HORIZONTAL); llAlso.addView(txtSamItem); } else { llAlso.addView(txtSamItem); } } ll.addView(llAlso); SharedPreferences sPref = PreferenceManager.getDefaultSharedPreferences(mContext); // System.out.println(sPref.getString("app_rating", // "All").equals( // "Mature")); ((ToggleButton) featuredView.findViewById(R.id.toggleButton1)) .setChecked(!sPref.getBoolean("matureChkBox", false)); ((ToggleButton) featuredView.findViewById(R.id.toggleButton1)) .setOnCheckedChangeListener(adultCheckedListener); } }); }
From source file:cm.aptoide.pt.MainActivity.java
private void loadRecommended() { if (Login.isLoggedIn(mContext)) { ((TextView) featuredView.findViewById(R.id.recommended_text)).setVisibility(View.GONE); } else {/*w ww .jav a 2s .c om*/ ((TextView) featuredView.findViewById(R.id.recommended_text)).setVisibility(View.VISIBLE); } new Thread(new Runnable() { private ArrayList<HashMap<String, String>> valuesRecommended; public void run() { loadUIRecommendedApps(); File f = null; try { SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); NetworkUtils utils = new NetworkUtils(); BufferedInputStream bis = new BufferedInputStream( utils.getInputStream("http://webservices.aptoide.com/webservices/listUserBasedApks/" + Login.getToken(mContext) + "/10/xml", null, null, mContext), 8 * 1024); f = File.createTempFile("abc", "abc"); OutputStream out = new FileOutputStream(f); byte buf[] = new byte[1024]; int len; while ((len = bis.read(buf)) > 0) out.write(buf, 0, len); out.close(); bis.close(); String hash = Md5Handler.md5Calc(f); ViewApk parent_apk = new ViewApk(); parent_apk.setApkid("recommended"); if (!hash.equals(db.getItemBasedApksHash(parent_apk.getApkid()))) { // Database.database.beginTransaction(); db.deleteItemBasedApks(parent_apk); sp.parse(f, new HandlerItemBased(parent_apk)); db.insertItemBasedApkHash(hash, parent_apk.getApkid()); // Database.database.setTransactionSuccessful(); // Database.database.endTransaction(); loadUIRecommendedApps(); } } catch (Exception e) { e.printStackTrace(); } if (f != null) f.delete(); } private void loadUIRecommendedApps() { valuesRecommended = db.getItemBasedApksRecommended("recommended"); runOnUiThread(new Runnable() { public void run() { LinearLayout ll = (LinearLayout) featuredView.findViewById(R.id.recommended_container); ll.removeAllViews(); LinearLayout llAlso = new LinearLayout(MainActivity.this); llAlso.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); llAlso.setOrientation(LinearLayout.HORIZONTAL); if (valuesRecommended.isEmpty()) { if (Login.isLoggedIn(mContext)) { TextView tv = new TextView(mContext); tv.setText(R.string.no_recommended_apps); tv.setTextAppearance(mContext, android.R.attr.textAppearanceMedium); tv.setPadding(10, 10, 10, 10); ll.addView(tv); } } else { for (int i = 0; i != valuesRecommended.size(); i++) { LinearLayout txtSamItem = (LinearLayout) getLayoutInflater() .inflate(R.layout.row_grid_item, null); ((TextView) txtSamItem.findViewById(R.id.name)) .setText(valuesRecommended.get(i).get("name")); ImageLoader.getInstance().displayImage(valuesRecommended.get(i).get("icon"), (ImageView) txtSamItem.findViewById(R.id.icon)); float stars = 0f; try { stars = Float.parseFloat(valuesRecommended.get(i).get("rating")); } catch (Exception e) { stars = 0f; } ((RatingBar) txtSamItem.findViewById(R.id.rating)).setIsIndicator(true); ((RatingBar) txtSamItem.findViewById(R.id.rating)).setRating(stars); txtSamItem.setPadding(10, 0, 0, 0); // ((TextView) // txtSamItem.findViewById(R.id.version)) // .setText(getString(R.string.version) +" "+ // valuesRecommended.get(i).get("vername")); ((TextView) txtSamItem.findViewById(R.id.downloads)) .setText("(" + valuesRecommended.get(i).get("downloads") + " " + getString(R.string.downloads) + ")"); txtSamItem.setTag(valuesRecommended.get(i).get("_id")); txtSamItem.setLayoutParams(new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, 100, 1)); // txtSamItem.setOnClickListener(featuredListener); txtSamItem.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent i = new Intent(MainActivity.this, ApkInfo.class); long id = Long.parseLong((String) arg0.getTag()); i.putExtra("_id", id); i.putExtra("top", true); i.putExtra("category", Category.ITEMBASED.ordinal()); startActivity(i); } }); txtSamItem.measure(0, 0); if (i % 2 == 0) { ll.addView(llAlso); llAlso = new LinearLayout(MainActivity.this); llAlso.setLayoutParams(new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, 100)); llAlso.setOrientation(LinearLayout.HORIZONTAL); llAlso.addView(txtSamItem); } else { llAlso.addView(txtSamItem); } } ll.addView(llAlso); } } }); } }).start(); }