diff --git a/android/titanium/src/java/org/appcelerator/titanium/view/TiBorderWrapperView.java b/android/titanium/src/java/org/appcelerator/titanium/view/TiBorderWrapperView.java index 1b9c6a94dbe..202e313bab1 100644 --- a/android/titanium/src/java/org/appcelerator/titanium/view/TiBorderWrapperView.java +++ b/android/titanium/src/java/org/appcelerator/titanium/view/TiBorderWrapperView.java @@ -42,6 +42,7 @@ public class TiBorderWrapperView extends FrameLayout private Paint paint; private Rect bounds; private ViewOutlineProvider viewOutlineProvider; + private int viewMaxWidth = -1; public TiBorderWrapperView(Context context) { super(context); @@ -238,6 +239,20 @@ public void setRadius(Object obj) } } + /* + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) + { + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + int measuredWidth = widthMeasureSpec; + int measuredHeight = heightMeasureSpec; + if (viewMaxWidth != -1 && measuredWidth > viewMaxWidth) { + measuredWidth = viewMaxWidth; + } + setMeasuredDimension(measuredWidth, measuredHeight); + } + */ + public void setBorderWidth(float borderWidth) { this.borderWidth = borderWidth; @@ -248,4 +263,9 @@ public boolean onSetAlpha(int alpha) { return false; } + + public void setMaxWidth(int maxWidth) + { + viewMaxWidth = maxWidth; + } } diff --git a/android/titanium/src/java/org/appcelerator/titanium/view/TiCompositeLayout.java b/android/titanium/src/java/org/appcelerator/titanium/view/TiCompositeLayout.java index c8f15cc1815..2c22bd0970c 100644 --- a/android/titanium/src/java/org/appcelerator/titanium/view/TiCompositeLayout.java +++ b/android/titanium/src/java/org/appcelerator/titanium/view/TiCompositeLayout.java @@ -67,6 +67,10 @@ public enum LayoutArrangement { private boolean enableHorizontalWrap = true; private int horizontalLayoutLastIndexBeforeWrap = 0; private int horiztonalLayoutPreviousRight = 0; + private int viewMinWidth = -1; + private int viewMaxWidth = -1; + private int viewMaxHeight = -1; + private int viewMinHeight = -1; int[] horizontal = new int[2]; int[] vertical = new int[2]; /** @@ -641,6 +645,18 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) int measuredWidth = getMeasuredWidth(maxWidth, widthMeasureSpec); int measuredHeight = getMeasuredHeight(maxHeight, heightMeasureSpec); + if (viewMaxWidth != -1 && measuredWidth > viewMaxWidth) { + measuredWidth = viewMaxWidth; + } + if (viewMinWidth != -1 && measuredWidth < viewMinWidth) { + measuredWidth = viewMinWidth; + } + if (viewMaxHeight != -1 && measuredHeight > viewMaxHeight) { + measuredHeight = viewMaxHeight; + } + if (viewMinHeight != -1 && measuredHeight < viewMinHeight) { + measuredHeight = viewMinHeight; + } setMeasuredDimension(measuredWidth, measuredHeight); } @@ -1237,6 +1253,24 @@ public void setLayoutArrangement(String arrangementProperty) } } + public void setMaxWidth(Integer value) + { + viewMaxWidth = value; + } + + public void setMinWidth(Integer value) + { + viewMinWidth = value; + } + public void setMaxHeight(Integer value) + { + viewMaxHeight = value; + } + public void setMinHeight(Integer value) + { + viewMinHeight = value; + } + public void setEnableHorizontalWrap(boolean enable) { enableHorizontalWrap = enable; diff --git a/android/titanium/src/java/org/appcelerator/titanium/view/TiUIView.java b/android/titanium/src/java/org/appcelerator/titanium/view/TiUIView.java index 520b611193b..56cd0087073 100644 --- a/android/titanium/src/java/org/appcelerator/titanium/view/TiUIView.java +++ b/android/titanium/src/java/org/appcelerator/titanium/view/TiUIView.java @@ -111,6 +111,10 @@ public abstract class TiUIView implements KrollProxyListener, OnFocusChangeListe protected LayoutParams layoutParams; protected TiAnimationBuilder animBuilder; protected TiBackgroundDrawable background; + private int minWidth = -1; + private int maxWidth = -1; + private int minHeight = -1; + private int maxHeight = -1; public TiBackgroundDrawable getBackground() { @@ -784,6 +788,14 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP doSetClickable(TiConvert.toBoolean(newValue)); } else if (key.equals(TiC.PROPERTY_FILTER_TOUCHES_WHEN_OBSCURED)) { setFilterTouchesWhenObscured(TiConvert.toBoolean(newValue, false)); + } else if (key.equals("maxWidth")) { + setMaxWidth(newValue, hasBorder(proxy.getProperties())); + } else if (key.equals("minWidth")) { + setMinWidth(newValue, hasBorder(proxy.getProperties())); + } else if (key.equals("maxHeight")) { + setMaxHeight(newValue, hasBorder(proxy.getProperties())); + } else if (key.equals("minHeight")) { + setMinHeight(newValue, hasBorder(proxy.getProperties())); } else if (key.equals(TiC.PROPERTY_VISIBLE)) { newValue = (newValue == null) ? false : newValue; this.setVisibility(TiConvert.toBoolean(newValue) ? View.VISIBLE : View.INVISIBLE); @@ -1054,6 +1066,18 @@ public void processProperties(KrollDict d) nativeView.setEnabled(TiConvert.toBoolean(d, TiC.PROPERTY_ENABLED, true)); } + if (d.containsKey("maxWidth")) { + setMaxWidth(d.get("maxWidth"), hasBorder(d)); + } + if (d.containsKey("minWidth")) { + setMinWidth(d.get("minWidth"), hasBorder(d)); + } + if (d.containsKey("maxHeight")) { + setMaxHeight(d.get("maxHeight"), hasBorder(d)); + } + if (d.containsKey("minHeight")) { + setMinHeight(d.get("minHeight"), hasBorder(d)); + } initializeBorder(d, bgColor); if (d.containsKey(TiC.PROPERTY_OPACITY) && !nativeViewNull) { @@ -1143,6 +1167,65 @@ public void processProperties(KrollDict d) } } + private void setMaxWidth(Object value, Boolean hasBorder) + { + maxWidth = -1; + if (value != null) { + maxWidth = TiConvert.toTiDimension(TiConvert.toInt(value), + TiDimension.TYPE_WIDTH).getAsPixels(nativeView); + } + + if (!hasBorder) { + ((TiCompositeLayout) nativeView).setMaxWidth(maxWidth); + } else { + Log.w(TAG, "You can only use maxWidth for Views without borders"); + } + } + + private void setMinWidth(Object value, Boolean hasBorder) + { + minWidth = -1; + if (value != null) { + minWidth = TiConvert.toTiDimension(TiConvert.toInt(value), + TiDimension.TYPE_WIDTH).getAsPixels(nativeView); + } + + if (!hasBorder) { + ((TiCompositeLayout) nativeView).setMinWidth(minWidth); + } else { + Log.w(TAG, "You can only use minWidth for Views without borders"); + } + } + + private void setMaxHeight(Object value, Boolean hasBorder) + { + maxHeight = -1; + if (value != null) { + maxHeight = TiConvert.toTiDimension(TiConvert.toInt(value), + TiDimension.TYPE_HEIGHT).getAsPixels(nativeView); + } + + if (!hasBorder) { + ((TiCompositeLayout) nativeView).setMaxHeight(maxHeight); + } else { + Log.w(TAG, "You can only use maxHeight for Views without borders"); + } + } + private void setMinHeight(Object value, Boolean hasBorder) + { + minHeight = -1; + if (value != null) { + minHeight = TiConvert.toTiDimension(TiConvert.toInt(value), + TiDimension.TYPE_HEIGHT).getAsPixels(nativeView); + } + + if (!hasBorder) { + ((TiCompositeLayout) nativeView).setMinHeight(minHeight); + } else { + Log.w(TAG, "You can only use maxHeight for Views without borders"); + } + } + private void setAnchor(HashMap point) { View outerView = getOuterView(); @@ -1499,6 +1582,7 @@ private void initializeBorder(KrollDict d, Integer bgColor) currentActivity = TiApplication.getAppCurrentActivity(); } borderView = new TiBorderWrapperView(currentActivity); + //borderView.setMaxWidth(maxWidth); // TODO fix borderView maxWidth // Create new layout params for the child view since we just want the // wrapper to control the layout LayoutParams params = new LayoutParams(); diff --git a/apidoc/Titanium/UI/View.yml b/apidoc/Titanium/UI/View.yml index 522308f2c80..d2360fa0dd8 100644 --- a/apidoc/Titanium/UI/View.yml +++ b/apidoc/Titanium/UI/View.yml @@ -1951,6 +1951,42 @@ properties: type: [Number,String] constants: [Titanium.UI.FILL, Titanium.UI.SIZE] + - name: maxWidth + summary: Maximum width of the View, in platform-specific units. + description: | + You can use the setting in combination with `width: Ti.UI.FILL` to set a maximum width. + The view won't extend the `maxWidth` value. + type: Number + since: {android: "12.4.0"} + platforms: [android] + + - name: maxHeight + summary: Maximum height of the View, in platform-specific units. + description: | + You can use the setting in combination with `height: Ti.UI.FILL` to set a maximum height. + The view won't extend the `maxHeight` value. + type: Number + since: {android: "12.4.0"} + platforms: [android] + + - name: minWidth + summary: Minimum width of the View, in platform-specific units. + description: | + You can use the setting in combination with `width: Ti.UI.SIZE` to set a minimum width. + The view won't be smaller than the `minWidth` value. + type: Number + since: {android: "12.4.0"} + platforms: [android] + + - name: minHeight + summary: Minimum height of the View, in platform-specific units. + description: | + You can use the setting in combination with `height: Ti.UI.SIZE` to set a minimum height. + The view won't be smaller than the `minHeight` value. + type: Number + since: {android: "12.4.0"} + platforms: [android] + - name: horizontalWrap summary: Determines whether the layout has wrapping behavior. description: |