@Override public View getView() throws ElementFailureException { if (elementView != null) return elementView; LinearLayout v = (LinearLayout) LayoutInflater.from(Utils.mainActivity) .inflate(R.layout.template_livelabel, this.layout, false); assert v != null; elementView = v; /** Nesting another element's view in our own for title and description. */ LinearLayout descriptionFrame = (LinearLayout) v.findViewById(R.id.SLiveLabel_descriptionFrame); if (titleObj != null) { TextView titleView = (TextView) titleObj.getView(); titleView.setBackground(null); descriptionFrame.addView(titleView); } if (descriptionObj != null) descriptionFrame.addView(descriptionObj.getView()); liveLabel = (TextView) v.findViewById(R.id.SLiveLabel_textView); if (style != null) { if (style.contains("bold") && style.contains("italic")) { liveLabel.setTypeface(liveLabel.getTypeface(), Typeface.BOLD_ITALIC); return v; } if (style.contains("bold")) liveLabel.setTypeface(liveLabel.getTypeface(), Typeface.BOLD); if (style.contains("italic")) liveLabel.setTypeface(liveLabel.getTypeface(), Typeface.ITALIC); } try { liveLabel.setText(Utils.runCommand(command).replace("@n", "\n")); } catch (Exception e) { throw new ElementFailureException(this, e); } return v; }
@Override public View getView() throws ElementFailureException { if (elementView != null) return elementView; LinearLayout v = new LinearLayout(Utils.mainActivity); v.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); v.setOrientation(LinearLayout.VERTICAL); elementView = v; /** Nesting another element's view in our own for title and description. */ LinearLayout descriptionFrame = new LinearLayout(Utils.mainActivity); LayoutParams dfl = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); descriptionFrame.setOrientation(LinearLayout.VERTICAL); final int leftMargin = (int) (2 * Utils.density + 0.5f); dfl.setMargins(leftMargin, 0, 0, 0); descriptionFrame.setLayoutParams(dfl); elementView.addView(descriptionFrame); if (titleObj != null) { TextView titleView = (TextView) titleObj.getView(); titleView.setBackground(null); descriptionFrame.addView(titleView); } if (descriptionObj != null) descriptionFrame.addView(descriptionObj.getView()); textView = new TextView(Utils.mainActivity); textView.setLayoutParams( new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); textView.setTextColor(Color.parseColor("#AAAAAA")); textView.setId(tv_id); elementView.addView(textView); v.setOnLongClickListener(this); textView.setOnLongClickListener(this); elementFrame = new LinearLayout(Utils.mainActivity); elementFrame.setLayoutParams( new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); elementFrame.setOrientation(LinearLayout.VERTICAL); selectorFrame = new FrameLayout(Utils.mainActivity); LayoutParams sfl = new LayoutParams((int) (15 * Utils.density + 0.5f), LayoutParams.MATCH_PARENT); int margin = (int) (Utils.density + 0.5f); sfl.setMargins(0, margin, 0, margin); selectorFrame.setLayoutParams(sfl); selectorFrame.setBackgroundColor(Color.DKGRAY); selectorFrame.setVisibility(View.GONE); elementFrame.addView(selectorFrame); elementFrame.addView(v); elementView = elementFrame; String initialLive = getLiveValue(); if (getStoredValue() == null) { Utils.db.setValue(command, initialLive); stored = lastLive; } lastEdit = lastLive; if (original == null) original = lastLive; textView.setOnClickListener(this); textView.setText(lastLive.toString()); valueCheck(); return elementView; }