// --------------------------------------------------------------------- @Override byte[] get(String p, String v) { TextView w = (TextView) widget; ByteArrayOutputStream r = new ByteArrayOutputStream(); try { if (p.equals("property")) { r.write(Util.s2ba("alignment" + "\012" + "caption" + "\012" + "text" + "\012")); r.write(super.get(p, v)); } else if (p.equals("caption") || p.equals("text")) r.write(Util.s2ba(w.getText().toString())); else if (p.equals("alignment")) { if ((w.getGravity()) == Gravity.RIGHT) r.write(Util.s2ba("right")); else if ((w.getGravity()) == Gravity.CENTER) r.write(Util.s2ba("center")); else r.write(Util.s2ba("left")); } else r.write(super.get(p, v)); } catch (IOException exc) { Log.d(JConsoleApp.LogTag, Log.getStackTraceString(exc)); } catch (Exception exc) { Log.d(JConsoleApp.LogTag, Log.getStackTraceString(exc)); } return r.toByteArray(); }
public static boolean setProperty(TextView instance, String propertyName, Object propertyValue) { // First look at TextView-specific properties // The .endsWith checks are important for supporting standard properties on custom // TextViews. What would have been Control.FontSize would appear as XXXTextView.FontSize. if (propertyName.endsWith(".Content") || propertyName.endsWith(".Text") || propertyName.endsWith(".Header")) { if (propertyValue instanceof String || propertyValue == null) { instance.setText((String) propertyValue); } else { instance.setText(propertyValue.toString()); } return true; } else if (propertyName.endsWith(".Inlines")) { InlineCollection inlines = (InlineCollection) propertyValue; // TODO: Handling of multiple Runs and with separate formatting instance.setText(inlines.get(0).toString()); return true; } else if (propertyName.endsWith(".FontSize")) { if (propertyValue instanceof Double) instance.setTextSize((float) (double) (Double) propertyValue); else if (propertyValue instanceof Integer) instance.setTextSize((float) (int) (Integer) propertyValue); else instance.setTextSize((float) Integer.parseInt(propertyValue.toString())); return true; } else if (propertyName.endsWith(".FontWeight")) { double weight; if (propertyValue instanceof Double) weight = (Double) propertyValue; else if (propertyValue instanceof String) weight = FontWeightConverter.parse((String) propertyValue); else weight = (double) (int) (Integer) propertyValue; // TODO: Preserve italicness if (weight >= 600 /* SemiBold or greater */) instance.setTypeface(null, Typeface.BOLD); else instance.setTypeface(null, Typeface.NORMAL); return true; } else if (propertyName.endsWith(".FontStyle")) { String s = ((String) propertyValue).toLowerCase(); if (s.equals("italic") || s.equals("oblique")) { // TODO: Preserve boldness instance.setTypeface(null, Typeface.ITALIC); } else if (s.equals("normal")) { // TODO: Preserve boldness instance.setTypeface(null, Typeface.NORMAL); } else { throw new RuntimeException("Unknown " + propertyName + ": " + propertyValue); } return true; } else if (propertyName.endsWith(".Foreground")) { int color = Color.fromObject(propertyValue); instance.setTextColor(color); return true; } else if (propertyName.endsWith(".HorizontalContentAlignment")) { String alignment = ((String) propertyValue).toLowerCase(); if (alignment.equals("center") || alignment.equals("stretch")) { int gravity = instance.getGravity(); instance.setGravity((gravity & Gravity.VERTICAL_GRAVITY_MASK) | Gravity.CENTER_HORIZONTAL); } else if (alignment.equals("left")) { int gravity = instance.getGravity(); instance.setGravity((gravity & Gravity.VERTICAL_GRAVITY_MASK) | Gravity.LEFT); } else if (alignment.equals("right")) { int gravity = instance.getGravity(); instance.setGravity((gravity & Gravity.VERTICAL_GRAVITY_MASK) | Gravity.RIGHT); } else { throw new RuntimeException("Unknown " + propertyName + ": " + propertyValue); } return true; } else if (propertyName.endsWith(".VerticalContentAlignment")) { String alignment = ((String) propertyValue).toLowerCase(); if (alignment.equals("center") || alignment.equals("stretch")) { int gravity = instance.getGravity(); instance.setGravity((gravity & Gravity.HORIZONTAL_GRAVITY_MASK) | Gravity.CENTER_VERTICAL); } else if (alignment.equals("top")) { int gravity = instance.getGravity(); instance.setGravity((gravity & Gravity.HORIZONTAL_GRAVITY_MASK) | Gravity.TOP); } else if (alignment.equals("bottom")) { int gravity = instance.getGravity(); instance.setGravity((gravity & Gravity.HORIZONTAL_GRAVITY_MASK) | Gravity.BOTTOM); } else { throw new RuntimeException("Unknown " + propertyName + ": " + propertyValue); } return true; } // Now look at properties applicable to all Views return ViewHelper.setProperty(instance, propertyName, propertyValue, true); }
@Override public void setCallState( int state, Call.DisconnectCause cause, boolean bluetoothOn, String gatewayLabel, String gatewayNumber) { String callStateLabel = null; // States other than disconnected not yet supported callStateLabel = getCallStateLabelFromState(state, cause); Log.v(this, "setCallState " + callStateLabel); Log.v(this, "DisconnectCause " + cause); Log.v(this, "bluetooth on " + bluetoothOn); Log.v(this, "gateway " + gatewayLabel + gatewayNumber); // There are cases where we totally skip the animation, in which case remove the transition // animation here and restore it afterwards. final boolean skipAnimation = (Call.State.isDialing(state) || state == Call.State.DISCONNECTED || state == Call.State.DISCONNECTING); LayoutTransition transition = null; if (skipAnimation) { transition = mSupplementaryInfoContainer.getLayoutTransition(); mSupplementaryInfoContainer.setLayoutTransition(null); } // Update the call state label. if (!TextUtils.isEmpty(callStateLabel)) { mCallStateLabel.setVisibility(View.VISIBLE); mCallStateLabel.setText(callStateLabel); if (Call.State.INCOMING == state) { setBluetoothOn(bluetoothOn); } } else { mCallStateLabel.setVisibility(View.GONE); // Gravity is aligned left when receiving an incoming call in landscape. // In that rare case, the gravity needs to be reset to the right. // Also, setText("") is used since there is a delay in making the view GONE, // so the user will otherwise see the text jump to the right side before disappearing. if (mCallStateLabel.getGravity() != Gravity.END) { mCallStateLabel.setText(""); mCallStateLabel.setGravity(Gravity.END); } } // Provider info: (e.g. "Calling via <gatewayLabel>") if (!TextUtils.isEmpty(gatewayLabel) && !TextUtils.isEmpty(gatewayNumber)) { mProviderLabel.setText(gatewayLabel); mProviderNumber.setText(gatewayNumber); mProviderInfo.setVisibility(View.VISIBLE); } else { mProviderInfo.setVisibility(View.GONE); } // Restore the animation. if (skipAnimation) { mSupplementaryInfoContainer.setLayoutTransition(transition); } }