List of usage examples for java.lang Float toString
public static String toString(float f)
From source file:io.coala.config.AbstractPropertyGetter.java
/** * @param defaultValue// w w w . j av a 2s .co m * @return */ public Float getFloat(final Float defaultValue) { final String value = get(defaultValue == null ? null : Float.toString(defaultValue)); return value == null ? null : Float.valueOf(value); }
From source file:com.netsteadfast.greenstep.bsc.util.TimeSeriesAnalysisUtils.java
public static Map<String, Object> getResultWithVision(String tsaOid, String visionOid, String startDate, String endDate, String startYearDate, String endYearDate, String frequency, String dataFor, String measureDataOrganizationOid, String measureDataEmployeeOid) throws ServiceException, Exception { List<TimeSeriesAnalysisResult> results = new ArrayList<TimeSeriesAnalysisResult>(); ChainResultObj chainResult = PerformanceScoreChainUtils.getResult(visionOid, startDate, endDate, startYearDate, endYearDate, frequency, dataFor, measureDataOrganizationOid, measureDataEmployeeOid); if (chainResult.getValue() == null || ((BscStructTreeObj) chainResult.getValue()).getVisions() == null || ((BscStructTreeObj) chainResult.getValue()).getVisions().size() == 0) { throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.SEARCH_NO_DATA)); }/*ww w . j ava 2 s . com*/ TsaVO tsa = getParam(tsaOid); BscStructTreeObj resultObj = (BscStructTreeObj) chainResult.getValue(); VisionVO visionObj = resultObj.getVisions().get(0); for (PerspectiveVO perspective : visionObj.getPerspectives()) { for (ObjectiveVO objective : perspective.getObjectives()) { for (KpiVO kpi : objective.getKpis()) { double[] observations = new double[kpi.getDateRangeScores().size()]; for (int i = 0; i < observations.length; i++) { observations[i] = Double .parseDouble(Float.toString(kpi.getDateRangeScores().get(i).getScore())); } double[] forecastNext = getForecastNext(tsa, observations); TimeSeriesAnalysisResult tsaModel = new TimeSeriesAnalysisResult(kpi, forecastNext); results.add(tsaModel); } } } Map<String, Object> dataMap = new HashMap<String, Object>(); dataMap.put("vision", visionObj); dataMap.put("result", results); return dataMap; }
From source file:it.tidalwave.northernwind.frontend.ui.component.sitemap.DefaultSitemapViewController.java
/******************************************************************************************************************* * * ******************************************************************************************************************/ private void appendUrl(final @Nonnull StringBuilder builder, final @Nonnull SiteNode siteNode, final @Nullable SiteNode childSiteNode) throws IOException { final SiteNode n = (childSiteNode != null) ? childSiteNode : siteNode; final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); final ResourceProperties properties = n.getProperties(); ////from w w w .j av a 2s . co m // FIXME: if you put the sitemap property straightly into the child site node, you can simplify a lot, // just using a single property and only peeking into a single node final Key<String> priorityKey = (childSiteNode == null) ? PROPERTY_SITEMAP_PRIORITY : PROPERTY_SITEMAP_CHILDREN_PRIORITY; final float sitemapPriority = Float.parseFloat(siteNode.getProperties().getProperty(priorityKey, "0.5")); if (sitemapPriority > 0) { builder.append(" <url>\n"); builder.append(String.format(" <loc>%s</loc>%n", site.createLink(n.getRelativeUri()))); builder.append(String.format(" <lastmod>%s</lastmod>%n", getSiteNodeDateTime(properties).format(dateTimeFormatter))); builder.append(String.format(" <changefreq>%s</changefreq>%n", properties.getProperty(PROPERTY_SITEMAP_CHANGE_FREQUENCY, "daily"))); builder.append(String.format(" <priority>%s</priority>%n", Float.toString(sitemapPriority))); builder.append(" </url>\n"); } }
From source file:blue.automation.Parameter.java
public Element saveAsXML() { Element retVal = new Element("parameter"); retVal.setAttribute("uniqueId", uniqueId); retVal.setAttribute("name", name); retVal.setAttribute("label", label); retVal.setAttribute("min", Float.toString(min)); retVal.setAttribute("max", Float.toString(max)); retVal.setAttribute("resolution", Float.toString(resolution)); retVal.setAttribute("automationEnabled", Boolean.toString(automationEnabled)); retVal.setAttribute("value", Float.toString(value)); retVal.addElement(line.saveAsXML()); return retVal; }
From source file:com.cloudera.oryx.rdf.common.pmml.DecisionForestPMML.java
private static Segment buildTreeModel(DecisionForest forest, Map<Integer, BiMap<String, Integer>> columnToCategoryNameToIDMapping, MiningFunctionType miningFunctionType, MiningSchema miningSchema, int treeID, DecisionTree tree, InboundSettings settings) {/* w ww. j a v a 2s . c o m*/ List<String> columnNames = settings.getColumnNames(); int targetColumn = settings.getTargetColumn(); Node root = new Node(); root.setId("r"); // Queue<Node> modelNodes = Queues.newArrayDeque(); Queue<Node> modelNodes = new ArrayDeque<Node>(); modelNodes.add(root); Queue<Pair<TreeNode, Decision>> treeNodes = new ArrayDeque<Pair<TreeNode, Decision>>(); treeNodes.add(new Pair<TreeNode, Decision>(tree.getRoot(), null)); while (!treeNodes.isEmpty()) { Pair<TreeNode, Decision> treeNodePredicate = treeNodes.remove(); Node modelNode = modelNodes.remove(); // This is the decision that got us here from the parent, if any; not the predicate at this node Predicate predicate = buildPredicate(treeNodePredicate.getSecond(), columnNames, columnToCategoryNameToIDMapping); modelNode.setPredicate(predicate); TreeNode treeNode = treeNodePredicate.getFirst(); if (treeNode.isTerminal()) { TerminalNode terminalNode = (TerminalNode) treeNode; modelNode.setRecordCount((double) terminalNode.getCount()); Prediction prediction = terminalNode.getPrediction(); if (prediction.getFeatureType() == FeatureType.CATEGORICAL) { Map<Integer, String> categoryIDToName = columnToCategoryNameToIDMapping.get(targetColumn) .inverse(); CategoricalPrediction categoricalPrediction = (CategoricalPrediction) prediction; int[] categoryCounts = categoricalPrediction.getCategoryCounts(); float[] categoryProbabilities = categoricalPrediction.getCategoryProbabilities(); for (int categoryID = 0; categoryID < categoryProbabilities.length; categoryID++) { int categoryCount = categoryCounts[categoryID]; float probability = categoryProbabilities[categoryID]; if (categoryCount > 0 && probability > 0.0f) { String categoryName = categoryIDToName.get(categoryID); ScoreDistribution distribution = new ScoreDistribution(categoryName, categoryCount); distribution.setProbability((double) probability); modelNode.getScoreDistributions().add(distribution); } } } else { NumericPrediction numericPrediction = (NumericPrediction) prediction; modelNode.setScore(Float.toString(numericPrediction.getPrediction())); } } else { DecisionNode decisionNode = (DecisionNode) treeNode; Decision decision = decisionNode.getDecision(); Node positiveModelNode = new Node(); positiveModelNode.setId(modelNode.getId() + '+'); modelNode.getNodes().add(positiveModelNode); Node negativeModelNode = new Node(); negativeModelNode.setId(modelNode.getId() + '-'); modelNode.getNodes().add(negativeModelNode); modelNode.setDefaultChild( decision.getDefaultDecision() ? positiveModelNode.getId() : negativeModelNode.getId()); modelNodes.add(positiveModelNode); modelNodes.add(negativeModelNode); treeNodes.add(new Pair<TreeNode, Decision>(decisionNode.getRight(), decision)); treeNodes.add(new Pair<TreeNode, Decision>(decisionNode.getLeft(), null)); } } TreeModel treeModel = new TreeModel(miningSchema, root, miningFunctionType); treeModel.setSplitCharacteristic(TreeModel.SplitCharacteristic.BINARY_SPLIT); treeModel.setMissingValueStrategy(MissingValueStrategyType.DEFAULT_CHILD); Segment segment = new Segment(); segment.setId(Integer.toString(treeID)); segment.setPredicate(new True()); segment.setModel(treeModel); segment.setWeight(forest.getWeights()[treeID]); return segment; }
From source file:co.foldingmap.mapImportExport.SvgExporter.java
private void exportMapLabel(BufferedWriter outputStream, MapLabel label) { Color outlineColor, fillColor; float x, y;/* ww w .j av a 2 s. c o m*/ Font labelFont; String style, fontStyle; try { labelFont = label.getFont(); //construct style if (label.getFillColor() != null) { fillColor = label.getFillColor(); } else { fillColor = Color.BLACK; } if (label.getOutlineColor() != null) { outlineColor = label.getOutlineColor(); } else { outlineColor = Color.WHITE; } if (labelFont.getStyle() == Font.BOLD) { fontStyle = "font-weight=\"bold\""; } else if (labelFont.getStyle() == Font.PLAIN) { fontStyle = "font-style=\"normal\""; } else if (labelFont.getStyle() == Font.ITALIC) { fontStyle = "font-style=\"italic\""; } else { fontStyle = ""; } style = "font-family=\"" + labelFont.getFamily() + "\" font-size=\"" + labelFont.getSize() + "\" " + fontStyle + " "; outputStream.write(getIndent()); outputStream.write("<g " + style + ">\n"); addIndent(); style = "fill:#" + getHexColor(fillColor) + ";stroke:#" + getHexColor(outlineColor); if (label instanceof PointLabel) { PointLabel pointLabel = (PointLabel) label; x = pointLabel.getLine1StartPoint().x; y = pointLabel.getLine1StartPoint().y; outputStream.write(getIndent()); outputStream.write("<text x=\""); outputStream.write(Float.toString(x)); outputStream.write("\" y=\""); outputStream.write(Float.toString(y)); outputStream.write("\" style=\""); outputStream.write(style); outputStream.write("\">\n"); addIndent(); outputStream.write(getIndent()); outputStream.write("<tspan x=\""); outputStream.write(Float.toString(x)); outputStream.write("\" y=\""); outputStream.write(Float.toString(y)); outputStream.write("\">"); outputStream.write(pointLabel.getLine1Text()); outputStream.write("</tspan>\n"); if (pointLabel.getLine2Text() != null && pointLabel.getLine2Text().length() > 0) { x = pointLabel.getLine2StartPoint().x; y = pointLabel.getLine2StartPoint().y; if (x != 0 && y != 0) { outputStream.write(getIndent()); outputStream.write("<tspan x=\""); outputStream.write(Float.toString(x)); outputStream.write("\" y=\""); outputStream.write(Float.toString(y)); outputStream.write("\">"); outputStream.write(pointLabel.getLine2Text()); outputStream.write("</tspan>\n"); } } removeIndent(); outputStream.write(getIndent()); outputStream.write("</text>\n"); removeIndent(); outputStream.write(getIndent()); outputStream.write("</g>\n"); } else if (label instanceof LineStringLabel) { LineStringLabel lineLabel = (LineStringLabel) label; } else if (label instanceof PolygonLabel) { PolygonLabel polyLabel = (PolygonLabel) label; } } catch (Exception e) { Logger.log(Logger.ERR, "Error in SvgExporter.exportMapLabel(BufferedWriter, MapLabel) - " + e); } }
From source file:com.example.sam.savemeapp.StatisticsFragment.java
/** * Sets up the initial legend with the contained categories shown * in the pie chart and bullet points with the corresponding colors. *//*from w ww .j a v a 2 s . c om*/ public void setUpPiechart() { pieChart.getDescription().setEnabled(false); Legend pieL = pieChart.getLegend(); Log.d("stats", Float.toString(pieL.getEntries().length)); startLegend = pieL; LegendEntry[] legends = pieL.getEntries(); pieL.setEnabled(false); mLegend.removeAllViews(); //The default legend consist of TextViews and ImageViews which contains a bullet point. //The legends are contained inside of a horizontal LinearLayout which is contained in a vertical LinearLayout. for (int t = 0; t < legends.length - 1; t++) { LegendEntry x = legends[t]; LinearLayout hLayout = new LinearLayout(getContext()); hLayout.setLayoutParams(params); TextView tv = new TextView(getContext()); tv.setText(x.label); tv.setTextColor(x.formColor); tv.setTypeface(fontLight); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_main_text_size)); tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); LinearLayoutCompat.LayoutParams textViewParams = new LinearLayoutCompat.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); textViewParams.setMarginStart((int) getResources().getDimension(R.dimen.statistics_text_margin)); tv.setLayoutParams(textViewParams); ImageView iv = new ImageView(getContext()); Drawable dot = ContextCompat.getDrawable(getContext(), R.drawable.circle_legend); dot.setColorFilter(x.formColor, PorterDuff.Mode.SRC); iv.setImageDrawable(dot); iv.setLayoutParams(new LinearLayoutCompat.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)); hLayout.addView(iv); hLayout.addView(tv); mLegend.addView(hLayout); } designPiechart(); pieChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() { private int color; @Override public void onValueSelected(Entry e, Highlight h) { //it creates new legends with the information of the subcategories when a // category in the pi chart is clicked ArrayList<LegendEntry> list = new ArrayList<>(); mLegend.removeAllViews(); if (e.getData().equals(Color.parseColor("#00a0ae"))) { for (LegendEntry x : startLegend.getEntries()) { if (x.label.equals("Food & Beverage")) { color = x.formColor; } } list.add(new LegendEntry("Food & Beverage: " + u.categories.get("Food & Beverage").get("Food & Beverage") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Restaurant & Caf: " + u.categories.get("Food & Beverage").get("Restaurant & Caf") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Supermarket: " + u.categories.get("Food & Beverage").get("Supermarket") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); mLegend.removeAllViews(); //This category legends consist of the main category in this case "Food & Beverage" in the top of the legend //and the sub categories bellow. The name is also shown together with the amount spend in that category. for (LegendEntry x : list) { TextView tv = new TextView(getContext()); if (x.equals(list.get(0))) { tv.setTypeface(fontBlack); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_main_text_size)); } else { tv.setTypeface(fontLight); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_text_size)); } tv.setText(x.label); tv.setTextColor(color); tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); mLegend.addView(tv); } } else if (e.getData().equals(Color.parseColor("#be3127"))) { for (LegendEntry x : startLegend.getEntries()) { if (x.label.equals("Transportation")) { color = x.formColor; } } list.add(new LegendEntry("Transportation: " + u.categories.get("Transportation").get("Transportation") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Public transport: " + u.categories.get("Transportation").get("Public transport") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Taxi & Uber: " + u.categories.get("Transportation").get("Taxi & Uber") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Petrol: " + u.categories.get("Transportation").get("Petrol") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Maintenance: " + u.categories.get("Transportation").get("Maintenance") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); mLegend.removeAllViews(); for (LegendEntry x : list) { TextView tv = new TextView(getContext()); if (x.equals(list.get(0))) { tv.setTypeface(fontBlack); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_main_text_size)); } else { tv.setTypeface(fontLight); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_text_size)); } tv.setText(x.label); tv.setTextColor(color); tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); mLegend.addView(tv); } } else if (e.getData().equals(Color.parseColor("#7dc725"))) { for (LegendEntry x : startLegend.getEntries()) { if (x.label.equals("Shopping")) { color = x.formColor; } } list.add(new LegendEntry( "Shopping: " + u.categories.get("Shopping").get("Shopping") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Clothing: " + u.categories.get("Shopping").get("Clothing") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Electronics: " + u.categories.get("Shopping").get("Electronics") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Books: " + u.categories.get("Shopping").get("Books") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Gifts: " + u.categories.get("Shopping").get("Gifts") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Other: " + u.categories.get("Shopping").get("Other") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); mLegend.removeAllViews(); for (LegendEntry x : list) { TextView tv = new TextView(getContext()); if (x.equals(list.get(0))) { tv.setTypeface(fontBlack); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_main_text_size)); } else { tv.setTypeface(fontLight); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_text_size)); } tv.setText(x.label); tv.setTextColor(color); tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); mLegend.addView(tv); } } else if (e.getData().equals(Color.parseColor("#e88300"))) { for (LegendEntry x : startLegend.getEntries()) { if (x.label.equals("Entertainment")) { color = x.formColor; } } list.add(new LegendEntry( "Entertainment: " + u.categories.get("Entertainment").get("Entertainment") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Going out: " + u.categories.get("Entertainment").get("Going out") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Sports: " + u.categories.get("Entertainment").get("Sports") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); mLegend.removeAllViews(); for (LegendEntry x : list) { TextView tv = new TextView(getContext()); if (x.equals(list.get(0))) { tv.setTypeface(fontBlack); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_main_text_size)); } else { tv.setTypeface(fontLight); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_text_size)); } tv.setText(x.label); tv.setTextColor(color); tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); mLegend.addView(tv); } } else if (e.getData().equals(Color.parseColor("#dc006d"))) { for (LegendEntry x : startLegend.getEntries()) { if (x.label.equals("Health")) { color = x.formColor; } } list.add(new LegendEntry("Health: " + u.categories.get("Health").get("Health") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Doctor: " + u.categories.get("Health").get("Doctor") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Pharmacy: " + u.categories.get("Health").get("Pharmacy") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); mLegend.removeAllViews(); for (LegendEntry x : list) { TextView tv = new TextView(getContext()); if (x.equals(list.get(0))) { tv.setTypeface(fontBlack); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_main_text_size)); } else { tv.setTypeface(fontLight); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_text_size)); } tv.setText(x.label); tv.setTextColor(color); tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); mLegend.addView(tv); } } else if (e.getData().equals(Color.parseColor("#1562a4"))) { for (LegendEntry x : startLegend.getEntries()) { if (x.label.equals("Bills")) { color = x.formColor; } } list.add(new LegendEntry("Bills: " + u.categories.get("Bills").get("Bills") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Water: " + u.categories.get("Bills").get("Water") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Electricity: " + u.categories.get("Bills").get("Electricity") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Gas: " + u.categories.get("Bills").get("Gas") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Rent: " + u.categories.get("Bills").get("Rent") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Phone: " + u.categories.get("Bills").get("Phone") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add( new LegendEntry("Insurance: " + u.categories.get("Bills").get("Insurance") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("TV: " + u.categories.get("Bills").get("TV") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Internet: " + u.categories.get("Bills").get("Internet") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); mLegend.removeAllViews(); for (LegendEntry x : list) { TextView tv = new TextView(getContext()); if (x.equals(list.get(0))) { tv.setTypeface(fontBlack); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_main_text_size)); } else { tv.setTypeface(fontLight); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_text_size)); } tv.setText(x.label); tv.setTextColor(color); tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); mLegend.addView(tv); } } } @Override public void onNothingSelected() { //Sets up the default legend when nothing is selected pieChart = (PieChart) v.findViewById(R.id.piechart); pieChart.setUsePercentValues(true); LegendEntry[] legends = startLegend.getEntries(); startLegend.setEnabled(false); mLegend.removeAllViews(); for (LegendEntry x : legends) { LinearLayout hLayout = new LinearLayout(getContext()); hLayout.setLayoutParams(params); TextView tv = new TextView(getContext()); tv.setText(x.label); tv.setTextColor(x.formColor); tv.setTypeface(fontLight); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_main_text_size)); tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); LinearLayoutCompat.LayoutParams textViewParams = new LinearLayoutCompat.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); textViewParams .setMarginStart((int) getResources().getDimension(R.dimen.statistics_text_margin)); tv.setLayoutParams(textViewParams); ImageView iv = new ImageView(getContext()); Drawable dot = ContextCompat.getDrawable(getContext(), R.drawable.circle_legend); dot.setColorFilter(x.formColor, PorterDuff.Mode.SRC); iv.setImageDrawable(dot); iv.setLayoutParams(new LinearLayoutCompat.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)); hLayout.addView(iv); hLayout.addView(tv); mLegend.addView(hLayout); } } }); }
From source file:org.hyperic.hq.ui.taglib.ConstantsTag.java
public int doEndTag() throws JspException { try {/*from w w w .j a v a 2s . co m*/ JspWriter out = pageContext.getOut(); if (className == null) { className = pageContext.getServletContext().getInitParameter(constantsClassNameParam); } if (validate(out)) { // we're misconfigured. getting this far // is a matter of what our failure mode is // if we haven't thrown an Error, carry on log.debug("constants tag misconfigured"); return EVAL_PAGE; } HashMap fieldMap; if (constants.containsKey(className)) { // we cache the result of the constants class // reflection field walk as a map fieldMap = (HashMap) constants.get(className); } else { fieldMap = new HashMap(); Class typeClass = Class.forName(className); //Object con = typeClass.newInstance(); Field[] fields = typeClass.getFields(); for (int i = 0; i < fields.length; i++) { // string comparisons of class names should be cheaper // than reflective Class comparisons, the asumption here // is that most constants are Strings, ints and booleans // but a minimal effort is made to accomadate all types // and represent them as String's for our tag's output //BIG NEW ASSUMPTION: Constants are statics and do not require instantiation of the class if (Modifier.isStatic(fields[i].getModifiers())) { String fieldType = fields[i].getType().getName(); String strVal; if (fieldType.equals("java.lang.String")) { strVal = (String) fields[i].get(null); } else if (fieldType.equals("int")) { strVal = Integer.toString(fields[i].getInt(null)); } else if (fieldType.equals("boolean")) { strVal = Boolean.toString(fields[i].getBoolean(null)); } else if (fieldType.equals("char")) { strVal = Character.toString(fields[i].getChar(null)); } else if (fieldType.equals("double")) { strVal = Double.toString(fields[i].getDouble(null)); } else if (fieldType.equals("float")) { strVal = Float.toString(fields[i].getFloat(null)); } else if (fieldType.equals("long")) { strVal = Long.toString(fields[i].getLong(null)); } else if (fieldType.equals("short")) { strVal = Short.toString(fields[i].getShort(null)); } else if (fieldType.equals("byte")) { strVal = Byte.toString(fields[i].getByte(null)); } else { Object val = (Object) fields[i].get(null); strVal = val.toString(); } fieldMap.put(fields[i].getName(), strVal); } } // cache the result constants.put(className, fieldMap); } if (symbol != null && !fieldMap.containsKey(symbol)) { // tell the developer that he's being a dummy and what // might be done to remedy the situation // TODO: what happens if the constants change? // do we need to throw a JspException, here? String err1 = symbol + " was not found in " + className + "\n"; String err2 = err1 + "use <constants:diag classname=\"" + className + "\"/>\n" + "to figure out what you're looking for"; log.error(err2); die(out, err1); } if (varSpecified) { doSet(fieldMap); } else { doOutput(fieldMap, out); } } catch (JspException e) { throw e; } catch (Exception e) { log.debug("doEndTag() failed: ", e); throw new JspException("Could not access constants tag", e); } return EVAL_PAGE; }
From source file:ly.count.android.sdk.CrashDetails.java
/** * Returns the current device battery level. *//* w w w .ja va 2 s .co m*/ static String getBatteryLevel(Context context) { try { Intent batteryIntent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); if (batteryIntent != null) { int level = batteryIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); int scale = batteryIntent.getIntExtra(BatteryManager.EXTRA_SCALE, -1); // Error checking that probably isn't needed but I added just in case. if (level > -1 && scale > 0) { return Float.toString(((float) level / (float) scale) * 100.0f); } } } catch (Exception e) { if (Countly.sharedInstance().isLoggingEnabled()) { Log.i(Countly.TAG, "Can't get batter level"); } } return null; }
From source file:jp.terasoluna.fw.util.ConvertUtil.java
/** * <code>value</code>??????? * ?<code>String</code>????<code>List</code>?? * ?// w ww .j a va2s .co m * * @param value ?? * @return ??????????<code>List</code> * ??????<code>value</code>???? */ public static Object convertPrimitiveArrayToList(Object value) { if (value == null) { return value; } Class<?> type = value.getClass().getComponentType(); // value??????? if (type == null) { return value; } // ????????? if (!type.isPrimitive()) { return value; } List<Object> list = new ArrayList<Object>(); if (value instanceof boolean[]) { for (boolean data : (boolean[]) value) { // String??????? list.add(data); } } else if (value instanceof byte[]) { for (byte data : (byte[]) value) { list.add(Byte.toString(data)); } } else if (value instanceof char[]) { for (char data : (char[]) value) { list.add(Character.toString(data)); } } else if (value instanceof double[]) { for (double data : (double[]) value) { list.add(Double.toString(data)); } } else if (value instanceof float[]) { for (float data : (float[]) value) { list.add(Float.toString(data)); } } else if (value instanceof int[]) { for (int data : (int[]) value) { list.add(Integer.toString(data)); } } else if (value instanceof long[]) { for (long data : (long[]) value) { list.add(Long.toString(data)); } } else if (value instanceof short[]) { for (short data : (short[]) value) { list.add(Short.toString(data)); } } return list; }