diff --git a/android/modules/ui/res/layout/titanium_ui_date_picker_calendar.xml b/android/modules/ui/res/layout/titanium_ui_date_picker_calendar.xml
new file mode 100644
index 00000000000..2a538bee087
--- /dev/null
+++ b/android/modules/ui/res/layout/titanium_ui_date_picker_calendar.xml
@@ -0,0 +1,7 @@
+
+
diff --git a/android/modules/ui/res/layout/titanium_ui_date_picker_spinner.xml b/android/modules/ui/res/layout/titanium_ui_date_picker_spinner.xml
index b96dd5f32a9..b7b098eb158 100644
--- a/android/modules/ui/res/layout/titanium_ui_date_picker_spinner.xml
+++ b/android/modules/ui/res/layout/titanium_ui_date_picker_spinner.xml
@@ -1,5 +1,7 @@
-
+ android:datePickerMode ="spinner"
+ android:calendarViewShown="false"
+ android:spinnersShown="true"/>
diff --git a/android/modules/ui/res/layout/titanium_ui_spinner.xml b/android/modules/ui/res/layout/titanium_ui_spinner.xml
deleted file mode 100644
index 38681f86b94..00000000000
--- a/android/modules/ui/res/layout/titanium_ui_spinner.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
\ No newline at end of file
diff --git a/android/modules/ui/src/java/kankan/wheel/widget/NumericWheelAdapter.java b/android/modules/ui/src/java/kankan/wheel/widget/NumericWheelAdapter.java
deleted file mode 100644
index 634ec005687..00000000000
--- a/android/modules/ui/src/java/kankan/wheel/widget/NumericWheelAdapter.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * Copyright 2010 Yuri Kanivets
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/**
- * MODIFICATIONS:
- * Appcelerator Titanium Mobile
- * Copyright (c) 2009-2011 by Appcelerator, Inc. All Rights Reserved.
- * Licensed under the terms of the Apache Public License
- * Please see the LICENSE included with this distribution for details.
- */
-package kankan.wheel.widget;
-
-/**
- * Numeric Wheel adapter.
- */
-public class NumericWheelAdapter implements WheelAdapter
-{
-
- /** The default min value */
- public static final int DEFAULT_MAX_VALUE = 9;
-
- /** The default max value */
- private static final int DEFAULT_MIN_VALUE = 0;
-
- /** The default max value */
- private static final int DEFAULT_STEP_VALUE = 1;
-
- // Values
- private int minValue;
- private int maxValue;
- private int stepValue;
-
- /**
- * Default constructor
- */
- public NumericWheelAdapter()
- {
- this(DEFAULT_MIN_VALUE, DEFAULT_MAX_VALUE, DEFAULT_STEP_VALUE);
- }
-
- /**
- * Constructor
- * @param minValue the wheel min value
- * @param maxValue the wheel maz value
- */
- public NumericWheelAdapter(int minValue, int maxValue)
- {
- this(minValue, maxValue, DEFAULT_STEP_VALUE);
- }
-
- /**
- * Constructor
- * @param minValue the wheel min value
- * @param maxValue the wheel maz value
- * @param stepValue the numeric step value
- */
- public NumericWheelAdapter(int minValue, int maxValue, int stepValue)
- {
- this.minValue = minValue;
- this.maxValue = maxValue;
- this.stepValue = stepValue;
- }
-
- @Override
- public String getItem(int index)
- {
- if (index >= 0 && index < getItemsCount()) {
- int actualValue = minValue + index * stepValue;
- return Integer.toString(actualValue);
- }
- return null;
- }
-
- @Override
- public int getItemsCount()
- {
- int itemCount = ((maxValue - minValue) / stepValue) + 1;
- return itemCount;
- }
-
- @Override
- public int getMaximumLength()
- {
- int max = Math.max(Math.abs(maxValue), Math.abs(minValue));
- int maxLen = Integer.toString(max).length();
- if (minValue < 0) {
- maxLen++;
- }
- return maxLen;
- }
-
- public int getMinValue()
- {
- return minValue;
- }
-
- public int getMaxValue()
- {
- return maxValue;
- }
-
- public int getValue(int index)
- {
- int tmpValue = (minValue + index * stepValue);
- if (tmpValue > maxValue)
- return maxValue;
- else
- return tmpValue;
- }
-
- public int getIndex(int value)
- {
- return (value - minValue) / stepValue;
- }
- public void setStepValue(int value)
- {
- this.stepValue = value;
- }
-}
diff --git a/android/modules/ui/src/java/kankan/wheel/widget/WheelAdapter.java b/android/modules/ui/src/java/kankan/wheel/widget/WheelAdapter.java
deleted file mode 100644
index 3d386a5067e..00000000000
--- a/android/modules/ui/src/java/kankan/wheel/widget/WheelAdapter.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright 2010 Yuri Kanivets
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package kankan.wheel.widget;
-
-public interface WheelAdapter {
- /**
- * Gets items count
- * @return the count of wheel items
- */
- int getItemsCount();
-
- /**
- * Gets a wheel item by index.
- *
- * @param index the item index
- * @return the wheel item text or null
- */
- String getItem(int index);
-
- /**
- * Gets maximum item length. It is used to determine the wheel width.
- * If -1 is returned there will be used the default wheel width.
- *
- * @return the maximum item length or -1
- */
- int getMaximumLength();
-}
diff --git a/android/modules/ui/src/java/kankan/wheel/widget/WheelView.java b/android/modules/ui/src/java/kankan/wheel/widget/WheelView.java
deleted file mode 100644
index d6a26a51614..00000000000
--- a/android/modules/ui/src/java/kankan/wheel/widget/WheelView.java
+++ /dev/null
@@ -1,809 +0,0 @@
-/*
- * Android Wheel Control.
- * http://android-devblog.blogspot.com/2010/05/wheel-ui-contol.html
- *
- * Copyright 2010 Yuri Kanivets
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/**
- * MODIFICATIONS:
- * Appcelerator Titanium Mobile
- * Copyright (c) 2009-2013 by Appcelerator, Inc. All Rights Reserved.
- * Licensed under the terms of the Apache Public License
- * Please see the LICENSE included with this distribution for details.
- */
-
-package kankan.wheel.widget;
-
-import android.content.Context;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.graphics.Rect;
-import android.graphics.Typeface;
-import android.graphics.drawable.Drawable;
-import android.graphics.drawable.GradientDrawable;
-import android.graphics.drawable.GradientDrawable.Orientation;
-import android.graphics.drawable.LayerDrawable;
-import android.text.Layout;
-import android.text.StaticLayout;
-import android.text.TextPaint;
-import android.text.TextUtils;
-import android.util.AttributeSet;
-import android.util.TypedValue;
-import android.view.MotionEvent;
-import android.view.View;
-
-/**
- * Numeric wheel view.
- *
- * @author Yuri Kanivets
- */
-@SuppressWarnings("deprecation")
-public class WheelView extends View
-{
- private static final int NOVAL = -1;
-
- /** Current value & label text color */
- private static final int VALUE_TEXT_COLOR = 0xE0000000;
-
- /** Items text color */
- private static final int ITEMS_TEXT_COLOR = 0xFF000000;
-
- /** Top and bottom shadows colors */
- private static final int[] SHADOWS_COLORS = new int[] { 0xFF111111, 0x00AAAAAA, 0x00AAAAAA };
-
- /** Additional items height (is added to standard text item height) */
- //private static final int ADDITIONAL_ITEM_HEIGHT = 15;
-
- /** Text size */
- //private static final int TEXT_SIZE = 24;
- private int textSize = 24; // default
-
- /** Top and bottom items offset (to hide that) */
- //private static final int ITEM_OFFSET = TEXT_SIZE / 5;
-
- /** Additional width for items layout */
- private static final int ADDITIONAL_ITEMS_SPACE = 5;
-
- /** Label offset */
- private static final int LABEL_OFFSET = 8;
-
- /** Left and right padding value */
- private static final int PADDING = 10;
-
- /** Default count of visible items */
- private static final int DEF_VISIBLE_ITEMS = 5;
-
- // Wheel Values
- private WheelAdapter adapter = null;
- private int currentItem = 0;
-
- // Widths
- private int itemsWidth = 0;
- private int labelWidth = 0;
-
- // Count of visible items
- private int visibleItems = DEF_VISIBLE_ITEMS;
-
- // Text paints
- private TextPaint itemsPaint;
- private TextPaint valuePaint;
-
- // Layouts
- private StaticLayout itemsLayout;
- private StaticLayout labelLayout;
- private StaticLayout valueLayout;
-
- // Label & background
- private String label;
- private Drawable centerDrawable;
-
- // Shadows drawables
- private GradientDrawable topShadow;
- private GradientDrawable bottomShadow;
-
- // Last touch Y position
- private float lastYTouch;
-
- private WheelView.OnItemSelectedListener itemSelectedListener;
-
- private int textColor = NOVAL;
- private Typeface typeface = Typeface.DEFAULT;
- private int typefaceWeight = Typeface.NORMAL;
- private boolean showSelectionIndicator = true;
-
- /**
- * Constructor
- */
- public WheelView(Context context, AttributeSet attrs, int defStyle)
- {
- super(context, attrs, defStyle);
- }
-
- /**
- * Constructor
- */
- public WheelView(Context context, AttributeSet attrs)
- {
- super(context, attrs);
- }
-
- /**
- * Constructor
- */
- public WheelView(Context context)
- {
- super(context);
- }
-
- /**
- * Gets wheel adapter
- * @return the adapter
- */
- public WheelAdapter getAdapter()
- {
- return adapter;
- }
-
- /**
- * Sets wheel adapter
- * @param adapter the new wheel adapter
- */
- public void setAdapter(WheelAdapter adapter)
- {
- this.adapter = adapter;
- itemsLayout = null;
- valueLayout = null;
- invalidate();
- }
-
- /**
- * Gets count of visible items
- *
- * @return the count of visible items
- */
- public int getVisibleItems()
- {
- return visibleItems;
- }
-
- /**
- * Sets count of visible items
- *
- * @param count
- * the new count
- */
- public void setVisibleItems(int count)
- {
- visibleItems = count;
- }
-
- /**
- * Gets label
- *
- * @return the label
- */
- public String getLabel()
- {
- return label;
- }
-
- /**
- * Sets label
- *
- * @param newLabel
- * the label to set
- */
- public void setLabel(String newLabel)
- {
- label = newLabel;
- labelLayout = null;
- invalidate();
- }
-
- /**
- * Gets current value
- *
- * @return the current value
- */
- public int getCurrentItem()
- {
- return currentItem;
- }
-
- /**
- * Sets the current item
- *
- * @param index the item index
- */
- public void setCurrentItem(int index)
- {
- if (index != currentItem) {
- itemsLayout = null;
- valueLayout = null;
- currentItem = index;
- invalidate();
- if (this.itemSelectedListener != null) {
- itemSelectedListener.onItemSelected(this, index);
- }
- }
- }
-
- private void resetTextPainters()
- {
- TextPaint[] painters = new TextPaint[] { itemsPaint, valuePaint };
- for (int i = 0; i < painters.length; i++) {
- TextPaint painter = painters[i];
- if (painter != null) {
- int flags = Paint.ANTI_ALIAS_FLAG;
- if (typefaceWeight == Typeface.BOLD) {
- flags = flags | Paint.FAKE_BOLD_TEXT_FLAG;
- }
- if (i == 1) {
- flags = flags | Paint.DITHER_FLAG;
- }
- painter.setFlags(flags);
- painter.setColor((textColor == NOVAL) ? ITEMS_TEXT_COLOR : textColor);
- painter.setTypeface(typeface);
- painter.setTextSize(textSize);
- }
- }
- }
-
- /**
- * Initializes resources
- */
- private void initResourcesIfNecessary()
- {
- if (itemsPaint == null) {
- if (typefaceWeight == Typeface.BOLD) {
- itemsPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.FAKE_BOLD_TEXT_FLAG);
- } else {
- itemsPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
- }
- //itemsPaint.density = getResources().getDisplayMetrics().density;
- itemsPaint.setTextSize(textSize);
- itemsPaint.setTypeface(typeface);
- itemsPaint.setColor((textColor == NOVAL) ? ITEMS_TEXT_COLOR : textColor);
- }
-
- if (valuePaint == null) {
- if (typefaceWeight == Typeface.BOLD) {
- valuePaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.FAKE_BOLD_TEXT_FLAG | Paint.DITHER_FLAG);
- } else {
- valuePaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
- }
- //valuePaint.density = getResources().getDisplayMetrics().density;
- valuePaint.setTextSize(textSize);
- valuePaint.setShadowLayer(0.5f, 0, 0.5f, 0xFFFFFFFF);
- valuePaint.setTypeface(typeface);
- valuePaint.setColor((textColor == NOVAL) ? ITEMS_TEXT_COLOR : textColor);
- }
-
- if (centerDrawable == null) {
- centerDrawable = getWheelValDrawable(); //getContext().getResources().getDrawable(R.drawable.wheel_val);
- }
-
- if (topShadow == null) {
- topShadow = new GradientDrawable(Orientation.TOP_BOTTOM, SHADOWS_COLORS);
- }
-
- if (bottomShadow == null) {
- bottomShadow = new GradientDrawable(Orientation.BOTTOM_TOP, SHADOWS_COLORS);
- }
-
- //setBackgroundResource(R.drawable.wheel_bg);
- setBackgroundDrawable(getWheelBackground());
- }
-
- /**
- * Direct programmatic creation of drawables (instead of R & res files)
- */
- private int dipToInt(float dips)
- {
- return Math.round(
- TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dips, getResources().getDisplayMetrics()));
- }
- private GradientDrawable makeGradientDrawable(Orientation orientation, int startColor, int centerColor,
- int endColor, float strokeDips, int strokeColor)
- {
- GradientDrawable gd = makeGradientDrawable(orientation, startColor, centerColor, endColor);
- gd.setStroke(dipToInt(strokeDips), strokeColor);
- return gd;
- }
-
- private GradientDrawable makeGradientDrawable(Orientation orientation, int startColor, int centerColor,
- int endColor)
- {
- int[] colors = new int[] { startColor, centerColor, endColor };
- GradientDrawable gd = new GradientDrawable(orientation, colors);
- return gd;
- }
-
- private Drawable getWheelValDrawable()
- {
- return makeGradientDrawable(Orientation.BOTTOM_TOP, Color.parseColor("#70222222"),
- Color.parseColor("#70222222"), Color.parseColor("#70EEEEEE"), 1f,
- Color.parseColor("#70333333"));
- }
-
- private Drawable getWheelBackground()
- {
- Drawable item0 =
- makeGradientDrawable(Orientation.BOTTOM_TOP, Color.parseColor("#333333"), Color.parseColor("#DDDDDD"),
- Color.parseColor("#333333"), 1f, Color.parseColor("#FF333333"));
- Drawable item1 = makeGradientDrawable(Orientation.BOTTOM_TOP, Color.parseColor("#AAAAAA"),
- Color.parseColor("#FFFFFF"), Color.parseColor("#AAAAAA"));
- LayerDrawable ld = new LayerDrawable(new Drawable[] { item0, item1 });
- ld.setLayerInset(1, dipToInt(4f), dipToInt(1f), dipToInt(4f), dipToInt(1f));
- return ld;
- }
-
- /**
- * Calculates desired height for layout
- *
- * @param layout
- * the source layout
- * @return the desired layout height
- */
- // APPCELERATOR TITANIUM CUSTOMIZATION:
- private int getDesiredHeight(Layout layout)
- {
- // Validate argument.
- if (layout == null) {
- return 0;
- }
-
- // Calculate height of spinner based on lines rendered in given layout.
- // Note: Subtracting offset from height clips the top-most and bottom-most lines in spinner
- // on purpose so that end-user knows that there are more items to scroll to.
- int desired = layout.getHeight();
- desired -= getItemOffset() * 2;
-
- // Do not allow desired height to be larger than assigned minimum.
- desired = Math.max(desired, getSuggestedMinimumHeight());
- return desired;
- }
-
- /**
- * Builds text depending on current value
- *
- * @return the text
- */
- // APPCELERATOR TITANIUM CUSTOMIZATION:
- // Must build ellipsized string here because the layout in this class only support one-line items. (TIMOB-14654)
- private String buildText(int widthItems)
- {
- // Empty lines on Android 5.0 and higher have a different line/spacing height compared to non-empty lines.
- // Work-Around: Add a zero-width space char to end of every line to ensure they all have same line height.
- final String ZERO_WIDTH_SPACE = "\u200B";
- final String LINE_ENDING = ZERO_WIDTH_SPACE + "\n";
-
- // Create the text lines above the selection.
- WheelAdapter adapter = getAdapter();
- StringBuilder itemsText = new StringBuilder();
- int addItems = visibleItems / 2;
- for (int i = currentItem - addItems; i < currentItem; i++) {
- if (i >= 0 && adapter != null) {
- String text = adapter.getItem(i);
- if (text != null) {
- // TITANIUM
- text = (String) TextUtils.ellipsize(text, itemsPaint, widthItems, TextUtils.TruncateAt.END);
- itemsText.append(text);
- }
- }
- itemsText.append(LINE_ENDING);
- }
-
- // Create an empty line where the selected item will be.
- itemsText.append(LINE_ENDING);
-
- // Create the text lines below the selection.
- for (int i = currentItem + 1; i <= currentItem + addItems; i++) {
- if (adapter != null && i < adapter.getItemsCount()) {
- String text = adapter.getItem(i);
- if (text != null) {
- // TITANIUM
- text = (String) TextUtils.ellipsize(text, itemsPaint, widthItems, TextUtils.TruncateAt.END);
- itemsText.append(text);
- }
- }
- if (i < currentItem + addItems) {
- itemsText.append(LINE_ENDING);
- }
- }
- itemsText.append(ZERO_WIDTH_SPACE);
-
- // Return the multiline text to be displayed by the spinner.
- return itemsText.toString();
- }
-
- /**
- * Returns the max item length that can be present
- * @return the max length
- */
- private int getMaxTextLength()
- {
- WheelAdapter adapter = getAdapter();
- if (adapter == null) {
- return 0;
- }
-
- int adapterLength = adapter.getMaximumLength();
- if (adapterLength > 0) {
- return adapterLength;
- }
-
- String maxText = null;
- int addItems = visibleItems / 2;
- for (int i = Math.max(currentItem - addItems, 0);
- i < Math.min(currentItem + visibleItems, adapter.getItemsCount()); i++) {
- String text = adapter.getItem(i);
- if (text != null && (maxText == null || maxText.length() < text.length())) {
- maxText = text;
- }
- }
-
- return maxText != null ? maxText.length() : 0;
- }
-
- /**
- * Calculates control width and creates text layouts
- * @param widthSize the input layout width
- * @param mode the layout mode
- * @return the calculated control width
- */
- private int calculateLayoutWidth(int widthSize, int mode)
- {
- initResourcesIfNecessary();
-
- int width = widthSize;
-
- int maxLength = getMaxTextLength();
- if (maxLength > 0) {
- float textWidth = (float) Math.ceil(Layout.getDesiredWidth("0", itemsPaint));
- itemsWidth = (int) (maxLength * textWidth);
- } else {
- itemsWidth = 0;
- }
- itemsWidth += ADDITIONAL_ITEMS_SPACE; // make it some more
-
- labelWidth = 0;
- if (label != null && label.length() > 0) {
- labelWidth = (int) Math.ceil(Layout.getDesiredWidth(label, valuePaint));
- }
-
- boolean recalculate = false;
- if (mode == MeasureSpec.EXACTLY) {
- width = widthSize;
- recalculate = true;
- } else {
- width = itemsWidth + labelWidth + 2 * PADDING;
- if (labelWidth > 0) {
- width += LABEL_OFFSET;
- }
-
- // Check against our minimum width
- width = Math.max(width, getSuggestedMinimumWidth());
-
- if (mode == MeasureSpec.AT_MOST && widthSize < width) {
- width = widthSize;
- recalculate = true;
- }
- }
-
- if (recalculate) {
- // recalculate width
- int pureWidth = width - LABEL_OFFSET - 2 * PADDING;
- if (pureWidth <= 0) {
- itemsWidth = labelWidth = 0;
- }
- if (labelWidth > 0) {
- double newWidthItems = (double) itemsWidth * pureWidth / (itemsWidth + labelWidth);
- itemsWidth = (int) newWidthItems;
- labelWidth = pureWidth - itemsWidth;
- } else {
- itemsWidth = pureWidth + LABEL_OFFSET; // no label
- }
- }
-
- if (itemsWidth > 0) {
- createLayouts(itemsWidth, labelWidth);
- }
-
- return width;
- }
-
- /**
- * Creates layouts
- * @param widthItems width of items layout
- * @param widthLabel width of label layout
- */
- private void createLayouts(int widthItems, int widthLabel)
- {
- if (itemsLayout == null || itemsLayout.getWidth() > widthItems) {
- // APPCELERATOR TITANIUM CUSTOMIZATION:
- // Must build ellipsized string here because the layout in this class only support one-line items. (TIMOB-14654)
- String text = buildText(widthItems);
- if (text == null) {
- text = "";
- }
- itemsLayout =
- new StaticLayout(text, 0, text.length(), itemsPaint, widthItems,
- widthLabel > 0 ? Layout.Alignment.ALIGN_OPPOSITE : Layout.Alignment.ALIGN_CENTER, 1,
- getAdditionalItemHeight(), false, TextUtils.TruncateAt.END, widthItems);
- } else {
- itemsLayout.increaseWidthTo(widthItems);
- }
-
- if (valueLayout == null || valueLayout.getWidth() > widthItems) {
- String text = getAdapter() != null ? getAdapter().getItem(currentItem) : null;
- // APPCELERATOR TITANIUM CUSTOMIZATION:
- // Must build ellipsized string here because the layout in this class only support one-line items. (TIMOB-14654)
- text = text != null ? (String) TextUtils.ellipsize(text, valuePaint, widthItems, TextUtils.TruncateAt.END)
- : null;
- valueLayout =
- new StaticLayout(text != null ? text : "", 0, text != null ? text.length() : 0, valuePaint, widthItems,
- widthLabel > 0 ? Layout.Alignment.ALIGN_OPPOSITE : Layout.Alignment.ALIGN_CENTER, 1,
- getAdditionalItemHeight(), false, TextUtils.TruncateAt.END, widthItems);
- } else {
- valueLayout.increaseWidthTo(widthItems);
- }
-
- if (widthLabel > 0) {
- if (labelLayout == null || labelLayout.getWidth() > widthLabel) {
- labelLayout = new StaticLayout(label, valuePaint, widthLabel, Layout.Alignment.ALIGN_NORMAL, 1,
- getAdditionalItemHeight(), false);
- } else {
- labelLayout.increaseWidthTo(widthLabel);
- }
- }
- }
-
- @Override
- protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
- {
- int widthMode = MeasureSpec.getMode(widthMeasureSpec);
- int heightMode = MeasureSpec.getMode(heightMeasureSpec);
- int widthSize = MeasureSpec.getSize(widthMeasureSpec);
- int heightSize = MeasureSpec.getSize(heightMeasureSpec);
-
- int width = calculateLayoutWidth(widthSize, widthMode);
-
- int height;
- if (heightMode == MeasureSpec.EXACTLY) {
- height = heightSize;
- } else {
- height = getDesiredHeight(itemsLayout);
-
- if (heightMode == MeasureSpec.AT_MOST) {
- height = Math.min(height, heightSize);
- }
- }
-
- setMeasuredDimension(width, height);
- }
-
- @Override
- protected void onDraw(Canvas canvas)
- {
- super.onDraw(canvas);
-
- if (itemsLayout == null) {
- if (itemsWidth == 0) {
- calculateLayoutWidth(getWidth(), MeasureSpec.EXACTLY);
- } else {
- createLayouts(itemsWidth, labelWidth);
- }
- }
-
- drawCenterRect(canvas);
-
- if (itemsWidth > 0) {
- canvas.save();
- canvas.translate(PADDING, -getItemOffset());
- drawItems(canvas);
- drawValue(canvas);
- canvas.restore();
- }
-
- drawShadows(canvas);
- }
-
- /**
- * Draws shadows on top and bottom of control
- * @param canvas the canvas for drawing
- */
- private void drawShadows(Canvas canvas)
- {
- topShadow.setBounds(0, 0, getWidth(), getHeight() / visibleItems);
- topShadow.draw(canvas);
-
- bottomShadow.setBounds(0, getHeight() - getHeight() / visibleItems, getWidth(), getHeight());
- bottomShadow.draw(canvas);
- }
-
- /**
- * Draws value and label layout
- * @param canvas the canvas for drawing
- */
- private void drawValue(Canvas canvas)
- {
- valuePaint.setColor((textColor == NOVAL) ? VALUE_TEXT_COLOR : textColor);
- valuePaint.drawableState = getDrawableState();
-
- Rect bounds = new Rect();
- itemsLayout.getLineBounds(visibleItems / 2, bounds);
-
- // draw label
- if (labelLayout != null) {
- canvas.save();
- canvas.translate(itemsLayout.getWidth() + LABEL_OFFSET, bounds.top);
- labelLayout.draw(canvas);
- canvas.restore();
- }
-
- // draw current value
- canvas.save();
- canvas.translate(0, bounds.top);
- valueLayout.draw(canvas);
- canvas.restore();
- }
-
- /**
- * Draws items
- * @param canvas the canvas for drawing
- */
- private void drawItems(Canvas canvas)
- {
- itemsPaint.drawableState = getDrawableState();
- itemsLayout.draw(canvas);
- }
-
- /**
- * Draws rect for current value
- * @param canvas the canvas for drawing
- */
- private void drawCenterRect(Canvas canvas)
- {
- if (!showSelectionIndicator) {
- return;
- }
- int center = getHeight() / 2;
- int offset = getHeight() / visibleItems / 2;
- centerDrawable.setBounds(0, center - offset, getWidth(), center + offset);
- centerDrawable.draw(canvas);
- }
-
- @Override
- public boolean onTouchEvent(MotionEvent event)
- {
- WheelAdapter adapter = getAdapter();
- if (adapter == null) {
- return true;
- }
-
- switch (event.getAction()) {
- case MotionEvent.ACTION_DOWN:
- lastYTouch = event.getY();
- break;
-
- case MotionEvent.ACTION_MOVE:
- float delta = event.getY() - lastYTouch;
- //A nasty hack for timob-8470 b/c touch events seem to not register in area above the first row when put in a scrollview.
- int count = (int) (visibleItems * delta * 3 / getHeight());
- int pos = currentItem - count;
- pos = Math.max(pos, 0);
- pos = Math.min(pos, adapter.getItemsCount() - 1);
- if (pos != currentItem) {
- lastYTouch = event.getY();
- setCurrentItem(pos);
- }
- break;
- case MotionEvent.ACTION_UP:
- break;
- }
- return true;
- }
-
- public interface OnItemSelectedListener {
- void onItemSelected(WheelView view, int index);
- }
-
- public void setItemSelectedListener(OnItemSelectedListener listener)
- {
- this.itemSelectedListener = listener;
- }
-
- private int getAdditionalItemHeight()
- {
- return (int) (textSize * 0.625);
- }
-
- private int getItemOffset()
- {
- return (int) (textSize / 5);
- }
-
- public void fullLayoutReset()
- {
- itemsLayout = null;
- valueLayout = null;
- requestLayout();
- }
-
- public void setTextSize(int size)
- {
- int orig = textSize;
- textSize = size;
- if (orig != textSize) {
- resetTextPainters();
- }
- }
-
- public int getTextSize()
- {
- return textSize;
- }
-
- public void setTextColor(int color)
- {
- this.textColor = color;
- resetTextPainters();
- invalidate();
- }
-
- public void setTypeface(Typeface tf)
- {
- Typeface old = this.typeface;
- this.typeface = tf;
- if (!old.equals(tf)) {
- resetTextPainters();
- }
- }
-
- public Typeface getTypeface()
- {
- return this.typeface;
- }
-
- public void setTypefaceWeight(int weight)
- {
- int old = this.typefaceWeight;
- this.typefaceWeight = weight;
- if (old != weight) {
- resetTextPainters();
- }
- }
-
- public int getTypefaceWeight()
- {
- return this.typefaceWeight;
- }
-
- public void setShowSelectionIndicator(boolean show)
- {
- boolean oldval = showSelectionIndicator;
- showSelectionIndicator = show;
- if (oldval != show) {
- invalidate();
- }
- }
-
- public boolean getShowSelectionIndicator()
- {
- return showSelectionIndicator;
- }
-}
diff --git a/android/modules/ui/src/java/ti/modules/titanium/ui/DatePickerProxy.java b/android/modules/ui/src/java/ti/modules/titanium/ui/DatePickerProxy.java
deleted file mode 100644
index ffa987734d0..00000000000
--- a/android/modules/ui/src/java/ti/modules/titanium/ui/DatePickerProxy.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * Appcelerator Titanium Mobile
- * Copyright (c) 2009-2016 by Appcelerator, Inc. All Rights Reserved.
- * Licensed under the terms of the Apache Public License
- * Please see the LICENSE included with this distribution for details.
- */
-package ti.modules.titanium.ui;
-
-import org.appcelerator.kroll.annotations.Kroll;
-import org.appcelerator.titanium.proxy.TiViewProxy;
-import org.appcelerator.titanium.view.TiUIView;
-
-import ti.modules.titanium.ui.widget.picker.TiUIDatePicker;
-import android.app.Activity;
-
-@Kroll.proxy(creatableInModule = UIModule.class)
-public class DatePickerProxy extends TiViewProxy
-{
- public DatePickerProxy()
- {
- super();
- }
-
- @Override
- public TiUIView createView(Activity activity)
- {
- return new TiUIDatePicker(this);
- }
-}
diff --git a/android/modules/ui/src/java/ti/modules/titanium/ui/PickerColumnProxy.java b/android/modules/ui/src/java/ti/modules/titanium/ui/PickerColumnProxy.java
index 78bf7d3537a..08c76ba866f 100644
--- a/android/modules/ui/src/java/ti/modules/titanium/ui/PickerColumnProxy.java
+++ b/android/modules/ui/src/java/ti/modules/titanium/ui/PickerColumnProxy.java
@@ -1,229 +1,220 @@
/**
* Appcelerator Titanium Mobile
- * Copyright (c) 2009-2016 by Appcelerator, Inc. All Rights Reserved.
+ * Copyright (c) 2009-2021 by Axway, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
package ti.modules.titanium.ui;
+import android.util.Log;
+import java.util.ArrayList;
import org.appcelerator.kroll.KrollDict;
+import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.kroll.annotations.Kroll;
-import org.appcelerator.titanium.proxy.TiViewProxy;
-import org.appcelerator.titanium.view.TiUIView;
-
-import ti.modules.titanium.ui.PickerRowProxy.PickerRowListener;
-import ti.modules.titanium.ui.widget.picker.TiUIPickerColumn;
-import ti.modules.titanium.ui.widget.picker.TiUISpinnerColumn;
-import android.app.Activity;
-import android.util.Log;
+import org.appcelerator.titanium.TiC;
-@Kroll.proxy(creatableInModule = UIModule.class)
-public class PickerColumnProxy extends TiViewProxy implements PickerRowListener
+@Kroll.proxy(creatableInModule = UIModule.class,
+ propertyAccessors = {
+ TiC.PROPERTY_WIDTH,
+})
+public class PickerColumnProxy extends KrollProxy implements PickerRowProxy.OnChangedListener
{
- private static final String TAG = "PickerColumnProxy";
-
- private PickerColumnListener columnListener = null;
- private boolean useSpinner = false;
- private boolean suppressListenerEvents = false;
+ public interface OnChangedListener {
+ void onChanged(PickerColumnProxy proxy);
+ }
- // Indicate whether this picker column is not created by users.
- // Users can directly add picker rows to the picker. In this case, we create a picker column for them and this is
- // the only column in the picker.
- private boolean createIfMissing = false;
+ private static final String TAG = "PickerColumnProxy";
+ private final ArrayList rowList = new ArrayList<>();
+ private final ArrayList listeners = new ArrayList<>();
+ private boolean canInvokeListeners = true;
- public PickerColumnProxy()
+ @Override
+ public void release()
{
- super();
+ super.release();
+
+ for (PickerRowProxy rowProxy : this.rowList) {
+ rowProxy.removeListener(this);
+ }
+ this.rowList.clear();
}
- public void setColumnListener(PickerColumnListener listener)
+ public void addListener(PickerColumnProxy.OnChangedListener listener)
{
- columnListener = listener;
+ if ((listener != null) && !this.listeners.contains(listener)) {
+ this.listeners.add(listener);
+ }
}
- public void setUseSpinner(boolean value)
+ public void removeListener(PickerColumnProxy.OnChangedListener listener)
{
- useSpinner = value;
+ this.listeners.remove(listener);
}
@Override
- public void handleCreationDict(KrollDict dict)
- {
- super.handleCreationDict(dict);
- if (dict.containsKey("rows")) {
- Object rowsAtCreation = dict.get("rows");
- if (rowsAtCreation.getClass().isArray()) {
- Object[] rowsArray = (Object[]) rowsAtCreation;
- addRows(rowsArray);
+ public void handleCreationDict(KrollDict options)
+ {
+ super.handleCreationDict(options);
+
+ if (options.containsKey("rows")) {
+ Object value = options.get("rows");
+ if ((value != null) && value.getClass().isArray()) {
+ setRows((Object[]) value);
+ } else {
+ setRows(null);
}
}
}
- @Override
- public void add(Object args)
+ @Kroll.setProperty
+ public void setFont(KrollDict value)
{
- handleAddRow((TiViewProxy) args);
+ setPropertyAndFire(TiC.PROPERTY_FONT, value);
+ onColumnChanged();
}
- private void handleAddRow(TiViewProxy o)
- {
- if (o == null)
- return;
- if (o instanceof PickerRowProxy) {
- ((PickerRowProxy) o).setRowListener(this);
- super.add((PickerRowProxy) o);
- if (columnListener != null && !suppressListenerEvents) {
- int index = children.indexOf(o);
- columnListener.rowAdded(this, index);
+ @Kroll.method
+ public void add(Object value)
+ {
+ if (value instanceof PickerRowProxy) {
+ // Add single row.
+ addRow((PickerRowProxy) value);
+ } else if ((value != null) && value.getClass().isArray()) {
+ // Add array of rows.
+ int rowCount = this.rowList.size();
+ boolean wasEnabled = this.canInvokeListeners;
+ this.canInvokeListeners = true;
+ for (Object nextObject : (Object[]) value) {
+ add(nextObject);
}
- } else {
- Log.w(TAG, "add() unsupported argument type: " + o.getClass().getSimpleName());
- }
- }
-
- @Override
- public void remove(TiViewProxy o)
- {
- if (o instanceof PickerRowProxy) {
- int index = children.indexOf(o);
- super.remove((PickerRowProxy) o);
- if (columnListener != null && !suppressListenerEvents) {
- columnListener.rowRemoved(this, index);
+ this.canInvokeListeners = wasEnabled;
+ if (rowCount != this.rowList.size()) {
+ onColumnChanged();
}
- } else if (o != null) {
- Log.w(TAG, "remove() unsupported argment type: " + o.getClass().getSimpleName());
+ } else {
+ Log.w(TAG, "Unable to add row to PickerColumn. Must be of type: Ti.UI.PickerRow");
}
}
@Kroll.method
- public void addRow(Object row)
+ public void addRow(PickerRowProxy rowProxy)
{
- if (row instanceof PickerRowProxy) {
- this.add((PickerRowProxy) row);
- } else {
- Log.w(TAG, "Unable to add the row. Invalid type for row.");
+ // Validate.
+ if (rowProxy == null) {
+ return;
}
- }
- protected void addRows(Object[] rows)
- {
- for (Object row : rows) {
- addRow(row);
+ // Do not continue if already added.
+ if (this.rowList.contains(rowProxy)) {
+ return;
}
+
+ // Add row to collection.
+ this.rowList.add(rowProxy);
+ rowProxy.addListener(this);
+
+ // Notify listeners that row has been added.
+ onColumnChanged();
}
@Kroll.method
- public void removeRow(Object row)
+ public void remove(Object row)
{
- if (row instanceof PickerRowProxy) {
- this.remove((PickerRowProxy) row);
- } else {
- Log.w(TAG, "Unable to remove the row. Invalid type for row.");
- }
+ removeRow(row);
}
- @Kroll.getProperty
- public PickerRowProxy[] getRows()
+ @Kroll.method
+ public void removeAllChildren()
{
- if (children == null || children.size() == 0) {
- return null;
- }
- return children.toArray(new PickerRowProxy[0]);
+ setRows(null);
}
- @Kroll.setProperty
- public void setRows(Object[] rows)
+ @Kroll.method
+ public void removeRow(Object value)
{
- try {
- suppressListenerEvents = true;
- if (children != null && children.size() > 0) {
- int count = children.size();
- for (int i = (count - 1); i >= 0; i--) {
- remove(children.get(i));
- }
- }
- addRows(rows);
- } finally {
- suppressListenerEvents = false;
+ // Validate argument.
+ if (!(value instanceof PickerRowProxy)) {
+ Log.w(TAG, "Unable to remove given row. Must be of type: Ti.UI.PickerRow");
+ return;
}
- if (columnListener != null) {
- columnListener.rowsReplaced(this);
+ PickerRowProxy rowProxy = (PickerRowProxy) value;
+
+ // Fetch index of given row by reference.
+ int index = this.rowList.indexOf(rowProxy);
+ if (index < 0) {
+ return;
}
+
+ // Remove given row.
+ this.rowList.remove(index);
+ rowProxy.removeListener(this);
+
+ // Notify listeners that row was removed.
+ onColumnChanged();
}
@Kroll.getProperty
- public int getRowCount()
+ public PickerRowProxy[] getRows()
{
- return children.size();
+ return this.rowList.toArray(new PickerRowProxy[0]);
}
- @Override
- public TiUIView createView(Activity activity)
+ @Kroll.setProperty(retain = false)
+ public void setRows(Object[] rows)
{
- if (useSpinner) {
- return new TiUISpinnerColumn(this);
- } else {
- return new TiUIPickerColumn(this);
- }
- }
-
- public interface PickerColumnListener {
- void rowAdded(PickerColumnProxy column, int rowIndex);
- void rowRemoved(PickerColumnProxy column, int oldRowIndex);
- void rowChanged(PickerColumnProxy column, int rowIndex);
- void rowSelected(PickerColumnProxy column, int rowIndex);
- void rowsReplaced(PickerColumnProxy column); // wholesale replace of rows
- }
+ // Temporarily disable listeners.
+ boolean wasEnabled = this.canInvokeListeners;
+ this.canInvokeListeners = false;
- @Override
- public void rowChanged(PickerRowProxy row)
- {
- if (columnListener != null && !suppressListenerEvents) {
- int index = children.indexOf(row);
- columnListener.rowChanged(this, index);
+ // Remove all rows.
+ while (!this.rowList.isEmpty()) {
+ removeRow(this.rowList.get(this.rowList.size() - 1));
}
- }
- public void onItemSelected(int rowIndex)
- {
- if (columnListener != null && !suppressListenerEvents) {
- columnListener.rowSelected(this, rowIndex);
+ // Add given rows.
+ if (rows != null) {
+ for (Object nextRow : rows) {
+ add(nextRow);
+ }
}
+
+ // Notify listeners that column has changed.
+ this.canInvokeListeners = wasEnabled;
+ onColumnChanged();
}
- public PickerRowProxy getSelectedRow()
+ public PickerRowProxy getRowByIndex(int index)
{
- if (!(peekView() instanceof TiUISpinnerColumn)) {
- return null;
- }
- int rowIndex = ((TiUISpinnerColumn) peekView()).getSelectedRowIndex();
- if (rowIndex < 0) {
- return null;
- } else {
- return (PickerRowProxy) children.get(rowIndex);
+ if ((index >= 0) && (index < this.rowList.size())) {
+ return this.rowList.get(index);
}
+ return null;
}
- public int getThisColumnIndex()
+ @Kroll.getProperty
+ public int getRowCount()
{
- return ((PickerProxy) getParent()).getColumnIndex(this);
+ return this.rowList.size();
}
- public void parentShouldRequestLayout()
+ @Override
+ public void onChanged(PickerRowProxy row)
{
- if (getParent() instanceof PickerProxy) {
- ((PickerProxy) getParent()).forceRequestLayout();
- }
+ onColumnChanged();
}
- public void setCreateIfMissing(boolean flag)
+ private void onColumnChanged()
{
- createIfMissing = flag;
- }
+ if (!canInvokeListeners) {
+ return;
+ }
- public boolean getCreateIfMissing()
- {
- return createIfMissing;
+ ArrayList clonedListeners = new ArrayList<>(this.listeners);
+ for (OnChangedListener listener : clonedListeners) {
+ if (this.listeners.contains(listener)) {
+ listener.onChanged(this);
+ }
+ }
}
@Override
diff --git a/android/modules/ui/src/java/ti/modules/titanium/ui/PickerProxy.java b/android/modules/ui/src/java/ti/modules/titanium/ui/PickerProxy.java
index cd9daad499b..e1590841504 100644
--- a/android/modules/ui/src/java/ti/modules/titanium/ui/PickerProxy.java
+++ b/android/modules/ui/src/java/ti/modules/titanium/ui/PickerProxy.java
@@ -1,6 +1,6 @@
/**
* Appcelerator Titanium Mobile
- * Copyright (c) 2009-2016 by Appcelerator, Inc. All Rights Reserved.
+ * Copyright (c) 2009-2021 by Axway, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
@@ -16,70 +16,66 @@
import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollFunction;
import org.appcelerator.kroll.annotations.Kroll;
+import org.appcelerator.titanium.R;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.TiC;
+import org.appcelerator.titanium.TiDimension;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.util.TiConvert;
+import org.appcelerator.titanium.util.TiUIHelper;
import org.appcelerator.titanium.view.TiUIView;
-import ti.modules.titanium.ui.PickerColumnProxy.PickerColumnListener;
import ti.modules.titanium.ui.widget.picker.TiUIDatePicker;
-import ti.modules.titanium.ui.widget.picker.TiUIDateSpinner;
-import ti.modules.titanium.ui.widget.picker.TiUINativePicker;
-import ti.modules.titanium.ui.widget.picker.TiUIPicker;
-import ti.modules.titanium.ui.widget.picker.TiUISpinner;
+import ti.modules.titanium.ui.widget.picker.TiUIPlainDropDownPicker;
+import ti.modules.titanium.ui.widget.picker.TiUIPlainPicker;
+import ti.modules.titanium.ui.widget.picker.TiUIPlainSpinnerPicker;
import ti.modules.titanium.ui.widget.picker.TiUITimePicker;
-import ti.modules.titanium.ui.widget.picker.TiUITimeSpinner;
-import ti.modules.titanium.ui.widget.picker.TiUITimeSpinnerNumberPicker;
import android.annotation.SuppressLint;
import android.app.Activity;
+import android.graphics.Color;
import android.util.Log;
+import android.view.Gravity;
+
+import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
+import androidx.appcompat.view.ContextThemeWrapper;
import com.google.android.material.datepicker.CalendarConstraints;
import com.google.android.material.datepicker.CompositeDateValidator;
import com.google.android.material.datepicker.DateValidatorPointBackward;
import com.google.android.material.datepicker.DateValidatorPointForward;
import com.google.android.material.datepicker.MaterialDatePicker;
+import com.google.android.material.textfield.MaterialAutoCompleteTextView;
+import com.google.android.material.textfield.TextInputLayout;
import com.google.android.material.timepicker.MaterialTimePicker;
import com.google.android.material.timepicker.TimeFormat;
@Kroll.proxy(creatableInModule = UIModule.class,
propertyAccessors = {
- TiC.PROPERTY_LOCALE,
- TiC.PROPERTY_SELECTION_OPENS,
- TiC.PROPERTY_VISIBLE_ITEMS,
- TiC.PROPERTY_VALUE,
TiC.PROPERTY_CALENDAR_VIEW_SHOWN,
+ TiC.PROPERTY_DATE_PICKER_STYLE,
TiC.PROPERTY_FONT,
+ TiC.PROPERTY_LOCALE,
TiC.PROPERTY_MIN_DATE,
- TiC.PROPERTY_MAX_DATE
+ TiC.PROPERTY_MAX_DATE,
+ TiC.PROPERTY_SELECTION_OPENS,
+ TiC.PROPERTY_VALUE
})
-public class PickerProxy extends TiViewProxy implements PickerColumnListener
+public class PickerProxy extends TiViewProxy implements PickerColumnProxy.OnChangedListener
{
- private int type = UIModule.PICKER_TYPE_PLAIN;
- private ArrayList preselectedRows = new ArrayList<>();
private static final String TAG = "PickerProxy";
- public static final int DEFAULT_VISIBLE_ITEMS_COUNT = 5;
+ private int type = UIModule.PICKER_TYPE_PLAIN;
+ private final ArrayList columnList = new ArrayList<>();
+ private final ArrayList selectedRows = new ArrayList<>();
private boolean useSpinner = false;
- private boolean nativeSpinner = false;
- private int lastSelectedIndex = -1;
+ private boolean canFireColumnEvents = true;
public PickerProxy()
{
super();
defaultValues.put(TiC.PROPERTY_CALENDAR_VIEW_SHOWN, false);
- }
-
- public void setLastSelectedIndex(int index)
- {
- this.lastSelectedIndex = index;
- }
-
- public int getLastSelectedIndex()
- {
- return lastSelectedIndex;
+ defaultValues.put(TiC.PROPERTY_DATE_PICKER_STYLE, UIModule.DATE_PICKER_STYLE_AUTOMATIC);
}
@Override
@@ -87,11 +83,10 @@ public void handleCreationDict(KrollDict dict)
{
super.handleCreationDict(dict);
if (dict.containsKey(TiC.PROPERTY_USE_SPINNER)) {
- useSpinner = TiConvert.toBoolean(dict, TiC.PROPERTY_USE_SPINNER);
- Log.w(TAG, "The useSpinner property is deprecated. Please refer to the documentation for more information");
+ this.useSpinner = TiConvert.toBoolean(dict, TiC.PROPERTY_USE_SPINNER, this.useSpinner);
}
if (dict.containsKey(TiC.PROPERTY_NATIVE_SPINNER)) {
- nativeSpinner = TiConvert.toBoolean(dict, TiC.PROPERTY_NATIVE_SPINNER);
+ this.useSpinner = TiConvert.toBoolean(dict, TiC.PROPERTY_NATIVE_SPINNER, this.useSpinner);
}
if (hasProperty("type")) {
type = TiConvert.toInt(getProperty("type"));
@@ -111,88 +106,110 @@ public TiUIView createView(Activity activity)
Log.w(TAG, "Date+Time timer not supported in Titanium for Android");
return null;
} else if (type == UIModule.PICKER_TYPE_PLAIN) {
- return createPlainPicker(activity, useSpinner);
- } else if (type == UIModule.PICKER_TYPE_DATE) {
- if (useSpinner) {
- return createDateSpinner(activity);
+ if (this.useSpinner) {
+ return new TiUIPlainSpinnerPicker(this);
} else {
- return createDatePicker(activity);
+ return new TiUIPlainDropDownPicker(this);
}
+ } else if (type == UIModule.PICKER_TYPE_DATE) {
+ return new TiUIDatePicker(this);
} else if (type == UIModule.PICKER_TYPE_TIME) {
- if (nativeSpinner) {
- return createTimeSpinnerNumberPicker(activity);
- }
- if (useSpinner) {
- return createTimeSpinner(activity);
- } else {
- return createTimePicker(activity);
- }
+ return new TiUITimePicker(this);
} else {
Log.w(TAG, "Unknown picker type");
return null;
}
}
- private TiUIView createPlainPicker(Activity activity, boolean useSpinner)
- {
- TiUIPicker picker = useSpinner ? new TiUISpinner(this, activity) : new TiUINativePicker(this, activity);
- return picker;
- }
-
- private TiUIView createDatePicker(Activity activity)
- {
- return new TiUIDatePicker(this, activity);
- }
-
- private TiUIView createTimePicker(Activity activity)
- {
- return new TiUITimePicker(this, activity);
- }
-
- private TiUIView createTimeSpinnerNumberPicker(Activity activity)
- {
- return new TiUITimeSpinnerNumberPicker(this, activity);
- }
-
- private TiUIView createTimeSpinner(Activity activity)
+ public TextInputLayout createTextInputLayout()
{
- return new TiUITimeSpinner(this, activity);
- }
-
- private TiUIView createDateSpinner(Activity activity)
- {
- return new TiUIDateSpinner(this, activity);
- }
-
- @Kroll.getProperty
- public boolean getUseSpinner()
- {
- Log.w(TAG, "The useSpinner property is deprecated. Please refer to the documentation for more information");
- return useSpinner;
- }
+ // Fetch proxy's activity.
+ Activity activity = getActivity();
+ if (activity == null) {
+ activity = TiApplication.getAppRootOrCurrentActivity();
+ if (activity == null) {
+ return null;
+ }
+ }
- @Kroll.setProperty
- public void setUseSpinner(boolean value)
- {
- Log.w(TAG, "The useSpinner property is deprecated. Please refer to the documentation for more information");
- if (peekView() != null) {
- Log.w(TAG, "Attempt to change useSpinner property after view has already been created. Ignoring.");
- } else {
- useSpinner = value;
- if (children != null && children.size() > 0) {
- for (TiViewProxy child : children) {
- if (child instanceof PickerColumnProxy) {
- ((PickerColumnProxy) child).setUseSpinner(value);
- }
+ // Create the TextInputLayout with drop-down arrow and configured border.
+ TextInputLayout textInputLayout = null;
+ int borderStyle = UIModule.INPUT_BORDERSTYLE_FILLED;
+ borderStyle = TiConvert.toInt(getProperty(TiC.PROPERTY_BORDER_STYLE), borderStyle);
+ switch (borderStyle) {
+ case UIModule.INPUT_BORDERSTYLE_BEZEL:
+ case UIModule.INPUT_BORDERSTYLE_LINE:
+ case UIModule.INPUT_BORDERSTYLE_ROUNDED:
+ textInputLayout = new TextInputLayout(new ContextThemeWrapper(
+ activity, R.style.Widget_MaterialComponents_TextInputLayout_OutlinedBox_ExposedDropdownMenu));
+ textInputLayout.setBoxBackgroundMode(TextInputLayout.BOX_BACKGROUND_OUTLINE);
+ textInputLayout.setBoxBackgroundColor(Color.TRANSPARENT);
+ if (borderStyle == UIModule.INPUT_BORDERSTYLE_ROUNDED) {
+ float radius = (new TiDimension("5dp", TiDimension.TYPE_LEFT)).getAsPixels(textInputLayout);
+ textInputLayout.setBoxCornerRadii(radius, radius, radius, radius);
+ } else {
+ textInputLayout.setBoxCornerRadii(0, 0, 0, 0);
}
+ break;
+ case UIModule.INPUT_BORDERSTYLE_NONE:
+ case UIModule.INPUT_BORDERSTYLE_UNDERLINED:
+ textInputLayout = new TextInputLayout(new ContextThemeWrapper(
+ activity, R.style.Widget_MaterialComponents_TextInputLayout_OutlinedBox_ExposedDropdownMenu));
+ textInputLayout.setBoxBackgroundMode(TextInputLayout.BOX_BACKGROUND_NONE);
+ break;
+ case UIModule.INPUT_BORDERSTYLE_FILLED:
+ default:
+ textInputLayout = new TextInputLayout(new ContextThemeWrapper(
+ activity, R.style.Widget_MaterialComponents_TextInputLayout_FilledBox_ExposedDropdownMenu));
+ textInputLayout.setBoxBackgroundMode(TextInputLayout.BOX_BACKGROUND_FILLED);
+ break;
+ }
+ textInputLayout.setHintEnabled(hasProperty(TiC.PROPERTY_HINT_TEXT));
+ if (textInputLayout.isHintEnabled()) {
+ textInputLayout.setHint(TiConvert.toString(getProperty(TiC.PROPERTY_HINT_TEXT), ""));
+ }
+
+ // Add a read-only EditText to the layout.
+ MaterialAutoCompleteTextView editText = null;
+ if (textInputLayout.getBoxBackgroundMode() != TextInputLayout.BOX_BACKGROUND_NONE) {
+ editText = new MaterialAutoCompleteTextView(textInputLayout.getContext());
+ } else {
+ editText = new MaterialAutoCompleteTextView(activity);
+ if (borderStyle == UIModule.INPUT_BORDERSTYLE_NONE) {
+ editText.setBackground(null);
}
}
+ editText.setSingleLine();
+ editText.setMaxLines(1);
+ editText.setGravity(Gravity.CENTER_VERTICAL | Gravity.START);
+ editText.setInputType(0);
+ if (textInputLayout.isHintEnabled() == false) {
+ // Remove extra padding from top since hint text is disabled.
+ editText.setPadding(
+ editText.getPaddingLeft(),
+ editText.getPaddingBottom(),
+ editText.getPaddingRight(),
+ editText.getPaddingBottom());
+ }
+ String[] fontProperties = TiUIHelper.getFontProperties(getProperties());
+ if ((fontProperties != null) && (fontProperties.length > 0)) {
+ TiUIHelper.styleText(
+ editText,
+ fontProperties[TiUIHelper.FONT_FAMILY_POSITION],
+ fontProperties[TiUIHelper.FONT_SIZE_POSITION],
+ fontProperties[TiUIHelper.FONT_WEIGHT_POSITION],
+ fontProperties[TiUIHelper.FONT_STYLE_POSITION]);
+ }
+ textInputLayout.addView(editText, new TextInputLayout.LayoutParams(
+ TextInputLayout.LayoutParams.MATCH_PARENT, TextInputLayout.LayoutParams.MATCH_PARENT));
+
+ return textInputLayout;
}
@Kroll.getProperty
public int getType()
{
- return type;
+ return this.type;
}
@Kroll.setProperty
@@ -211,94 +228,140 @@ private boolean isPlainPicker()
}
@Override
- public void remove(TiViewProxy child)
+ public void add(Object child)
{
- int index = -1;
- if (children.contains(child)) {
- index = children.indexOf(child);
- }
- super.remove(child);
- if (peekView() instanceof TiUIPicker) {
- ((TiUIPicker) peekView()).onColumnRemoved(index);
+ // If given a view proxy, then let base class remove.
+ if (child instanceof TiViewProxy) {
+ remove((TiViewProxy) child);
+ return;
}
- }
- @Override
- public void add(Object child)
- {
+ // Do not continue if not a plain picker.
if (!isPlainPicker()) {
Log.w(TAG, "Attempt to add to date/time or countdown picker ignored.");
return;
}
if (child instanceof PickerColumnProxy) {
- PickerColumnProxy column = (PickerColumnProxy) child;
- addColumn(column);
+ addColumn((PickerColumnProxy) child);
} else if (child instanceof PickerRowProxy) {
- getFirstColumn(true).add((PickerRowProxy) child);
- } else if (child.getClass().isArray()) {
- Object[] obj = (Object[]) child;
- Object firstObj = obj[0];
- if (firstObj instanceof PickerRowProxy) {
- getFirstColumn(true).addRows(obj);
- } else if (firstObj instanceof PickerColumnProxy) {
- addColumns(obj);
+ getOrCreateFirstColumn().add(child);
+ } else if ((child != null) && child.getClass().isArray()) {
+ Object[] childArray = (Object[]) child;
+ Object firstObject = childArray[0];
+ if (firstObject instanceof PickerRowProxy) {
+ getOrCreateFirstColumn().add(child);
+ } else if (firstObject instanceof PickerColumnProxy) {
+ int columnCount = this.columnList.size();
+ boolean wasEnabled = this.canFireColumnEvents;
+ this.canFireColumnEvents = false;
+ for (Object nextObject : childArray) {
+ if (nextObject instanceof PickerColumnProxy) {
+ addColumn((PickerColumnProxy) nextObject);
+ } else {
+ Log.w(TAG, "add() was given an invalid object. Must be of type: ");
+ }
+ }
+ this.canFireColumnEvents = wasEnabled;
+ if (columnCount != this.columnList.size()) {
+ onColumnListChanged();
+ }
}
} else {
- Log.w(TAG, "Unexpected type not added to picker: " + child.getClass().getName());
+ String errorMessage
+ = "add() method was given an invalid object."
+ + " Must be given an array of type 'Ti.UI.PickerColumn' or 'Ti.UI.PickerRow";
+ Log.w(TAG, errorMessage);
}
}
- private void addColumns(Object[] columns)
+ private void addColumn(@NonNull PickerColumnProxy column)
{
- for (Object obj : columns) {
- if (obj instanceof PickerColumnProxy) {
- addColumn((PickerColumnProxy) obj);
- } else {
- Log.w(TAG, "Unexpected type not added to picker: " + obj.getClass().getName());
- }
+ if (this.columnList.contains(column)) {
+ return;
}
+
+ this.columnList.add(column);
+ this.selectedRows.add(0);
+ column.addListener(this);
+ onColumnListChanged();
}
- private void addColumn(PickerColumnProxy column)
+ @Kroll.method
+ public void remove(Object child)
{
- prepareColumn(column);
- super.add(column);
- if (peekView() instanceof TiUIPicker) {
- ((TiUIPicker) peekView()).onColumnAdded(children.indexOf(column));
+ // If given a view proxy, then let base class remove.
+ if (child instanceof TiViewProxy) {
+ remove((TiViewProxy) child);
+ return;
+ }
+
+ // Do not continue if not a column.
+ if (!(child instanceof PickerColumnProxy)) {
+ Log.w(TAG, "Unable to remove given column. Must be of type: Ti.UI.PickerColumn");
+ return;
+ }
+
+ // Check exists in picker's collection.
+ int index = this.columnList.indexOf(child);
+ if (index < 0) {
+ return;
+ }
+
+ // Remove column from collection and UI.
+ this.columnList.remove(index);
+ if (index < this.selectedRows.size()) {
+ this.selectedRows.remove(index);
}
+ ((PickerColumnProxy) child).removeListener(this);
+ onColumnListChanged();
}
- private void prepareColumn(PickerColumnProxy column)
- {
- column.setUseSpinner(useSpinner);
- column.setColumnListener(this);
+ @Override
+ public void removeAllChildren()
+ {
+ // Remove all columns from picker.
+ this.selectedRows.clear();
+ if (!this.columnList.isEmpty()) {
+ boolean wasEnabled = this.canFireColumnEvents;
+ this.canFireColumnEvents = false;
+ while (!this.columnList.isEmpty()) {
+ remove(this.columnList.get(this.columnList.size() - 1));
+ }
+ this.canFireColumnEvents = wasEnabled;
+ onColumnListChanged();
+ }
+
+ // Remove all view proxies.
+ super.removeAllChildren();
}
@Kroll.method
- public void setSelectedRow(int column, int row, @Kroll.argument(optional = true) boolean animated)
+ public void setSelectedRow(int columnIndex, int rowIndex, @Kroll.argument(optional = true) boolean animated)
{
+ // Do not continue if not a plain picker.
if (!isPlainPicker()) {
Log.w(TAG, "Selecting row in date/time or countdown picker is not supported.");
return;
}
- TiUIView view = peekView();
- if (view == null) {
- // assign it to be selected after view creation
- if (preselectedRows == null) {
- preselectedRows = new ArrayList<>();
- }
- while (preselectedRows.size() < (column + 1)) {
- preselectedRows.add(null);
- }
- if (preselectedRows.size() >= (column + 1)) {
- preselectedRows.remove(column);
- }
- preselectedRows.add(column, row);
+
+ // Add given selection to collection.
+ // Needs to be stored in case view doesn't exist yet or it is recreated after a dark/light theme change.
+ if ((columnIndex >= 0) && (columnIndex < this.selectedRows.size())) {
+ this.selectedRows.set(columnIndex, rowIndex);
} else {
- ((TiUIPicker) view).selectRow(column, row, animated);
+ Log.w(TAG, "setSelectedRow() column index is out of range. Given: " + columnIndex);
+ return;
+ }
+
+ // Set selection in view if available.
+ TiUIView view = peekView();
+ if (view instanceof TiUIPlainPicker) {
+ ((TiUIPlainPicker) view).selectRow(columnIndex, rowIndex, animated);
if (TiConvert.toBoolean(getProperty(TiC.PROPERTY_SELECTION_OPENS), false)) {
- ((TiUIPicker) view).openPicker();
+ if (view instanceof TiUIPlainDropDownPicker) {
+ ((TiUIPlainDropDownPicker) view).openPicker();
+ }
}
}
}
@@ -306,134 +369,89 @@ public void setSelectedRow(int column, int row, @Kroll.argument(optional = true)
@Kroll.method
public PickerRowProxy getSelectedRow(int columnIndex)
{
+ int rowIndex = getSelectedRowIndex(columnIndex);
+ return (rowIndex >= 0) ? getRow(columnIndex, rowIndex) : null;
+ }
+
+ public int getSelectedRowIndex(int columnIndex)
+ {
+ // Do not continue if not a plain picker.
if (!isPlainPicker()) {
Log.w(TAG, "Cannot get selected row in date/time or countdown picker.");
- return null;
- }
- if (!(peekView() instanceof TiUIPicker)) {
- return null;
+ return -1;
}
- PickerRowProxy row = null;
- if (peekView() instanceof TiUIPicker) {
- int rowIndex = ((TiUIPicker) peekView()).getSelectedRowIndex(columnIndex);
- if (rowIndex >= 0) {
- row = getRow(columnIndex, rowIndex);
- }
+
+ // Validate column index.
+ if ((columnIndex < 0) || (columnIndex >= this.selectedRows.size())) {
+ return -1;
}
- return row;
+
+ // Fetch currently selected row index for given column.
+ return this.selectedRows.get(columnIndex);
}
+ @NonNull
@Kroll.getProperty
public PickerColumnProxy[] getColumns()
{
if (!isPlainPicker()) {
Log.w(TAG, "Cannot get columns from date/time or countdown picker.");
- return null;
- }
- if (children == null) {
- return new PickerColumnProxy[] {};
- } else {
- return children.toArray(new PickerColumnProxy[0]);
+ return new PickerColumnProxy[0];
}
+
+ return this.columnList.toArray(new PickerColumnProxy[0]);
}
@Kroll.setProperty
- public void setColumns(Object passedColumns)
+ public void setColumns(Object value)
{
+ // Do not continue if not a plain picker.
if (!isPlainPicker()) {
Log.w(TAG, "Cannot set columns in date/time or countdown picker.");
return;
}
- boolean dirty = false;
- try {
- if (peekView() instanceof TiUIPicker) {
- ((TiUIPicker) peekView()).batchModelChange = true;
- }
- if (children != null && children.size() > 0) {
- int count = children.size();
- for (int i = (count - 1); i >= 0; i--) {
- remove(children.get(i));
- dirty = true;
- }
- }
- Object[] columns = null;
- if (passedColumns.getClass().isArray()) {
- columns = (Object[]) passedColumns;
- } else {
- columns = new Object[] { passedColumns };
- }
- if (!(columns[0] instanceof PickerColumnProxy)) {
- Log.w(TAG, "Unexpected object type ignored for setColumns");
- } else {
- for (Object o : columns) {
- if (o instanceof PickerColumnProxy) {
- add((PickerColumnProxy) o);
- dirty = true;
- }
- }
- }
- } finally {
- if (peekView() instanceof TiUIPicker) {
- ((TiUIPicker) peekView()).batchModelChange = false;
- }
- }
- if (dirty) {
- TiUIPicker pickerView = (TiUIPicker) peekView();
- if (pickerView != null) {
- pickerView.onModelReplaced();
- }
- }
- }
-
- public int getColumnCount()
- {
- TiViewProxy[] columns = getColumns();
- if (columns == null) {
- return 0;
- } else {
- return columns.length;
- }
+ // Remove all previous columns and add given columns.
+ boolean wasEnabled = this.canFireColumnEvents;
+ this.canFireColumnEvents = false;
+ removeAllChildren();
+ add(value);
+ this.canFireColumnEvents = wasEnabled;
+ onColumnListChanged();
}
public PickerColumnProxy getColumn(int index)
{
- if (children == null || index >= children.size() || (!(children.get(index) instanceof PickerColumnProxy))) {
- return null;
- } else {
- return (PickerColumnProxy) children.get(index);
+ if ((index >= 0) && (index < this.columnList.size())) {
+ return this.columnList.get(index);
}
+ return null;
}
- public int getColumnIndex(PickerColumnProxy column)
+ public int getColumnIndexOf(PickerColumnProxy columnProxy)
{
- if (children != null && children.size() > 0) {
- return children.indexOf(column);
- } else {
- return -1;
- }
+ return this.columnList.indexOf(columnProxy);
}
public PickerRowProxy getRow(int columnIndex, int rowIndex)
{
PickerColumnProxy column = getColumn(columnIndex);
- if (column == null) {
- return null;
- }
- TiViewProxy[] rowArray = column.getChildren();
- if (rowArray == null || rowIndex >= rowArray.length || (!(rowArray[rowIndex] instanceof PickerRowProxy))) {
- return null;
- } else {
- return (PickerRowProxy) rowArray[rowIndex];
+ if (column != null) {
+ return column.getRowByIndex(rowIndex);
}
+ return null;
+ }
+
+ public PickerColumnProxy getFirstColumn()
+ {
+ return getColumn(0);
}
- public PickerColumnProxy getFirstColumn(boolean createIfMissing)
+ public PickerColumnProxy getOrCreateFirstColumn()
{
PickerColumnProxy column = getColumn(0);
- if (column == null && createIfMissing) {
+ if (column == null) {
column = new PickerColumnProxy();
- column.setCreateIfMissing(true);
add(column);
}
return column;
@@ -720,30 +738,20 @@ public void showTimePickerDialog(Object[] args)
picker.show(appCompatActivity.getSupportFragmentManager(), picker.toString());
}
- private void fireColumnModelChange(int columnIndex)
- {
- if (peekView() instanceof TiUIPicker) {
- ((TiUIPicker) peekView()).onColumnModelChanged(columnIndex);
- }
- }
-
- private void fireRowChange(int columnIndex, int rowIndex)
+ public void fireSelectionChange(int columnIndex, int rowIndex)
{
- if (peekView() instanceof TiUIPicker) {
- ((TiUIPicker) peekView()).onRowChanged(columnIndex, rowIndex);
+ // Update selection collection.
+ if ((columnIndex >= 0) && (columnIndex < this.selectedRows.size())) {
+ this.selectedRows.set(columnIndex, rowIndex);
}
- }
- public void fireSelectionChange(int columnIndex, int rowIndex)
- {
+ // Fire a "change" event with given selection.
KrollDict d = new KrollDict();
d.put("columnIndex", columnIndex);
d.put("rowIndex", rowIndex);
- PickerColumnProxy column = getColumn(columnIndex);
- PickerRowProxy row = getRow(columnIndex, rowIndex);
- d.put("column", column);
- d.put("row", row);
- int columnCount = getColumnCount();
+ d.put("column", getColumn(columnIndex));
+ d.put("row", getRow(columnIndex, rowIndex));
+ int columnCount = this.columnList.size();
ArrayList selectedValues = new ArrayList<>(columnCount);
for (int i = 0; i < columnCount; i++) {
PickerRowProxy rowInColumn = getSelectedRow(i);
@@ -754,49 +762,30 @@ public void fireSelectionChange(int columnIndex, int rowIndex)
}
}
d.put("selectedValue", selectedValues.toArray());
- fireEvent("change", d);
- }
-
- @Override
- public void rowAdded(PickerColumnProxy column, int rowIndex)
- {
- fireColumnModelChange(children.indexOf(column));
+ fireEvent(TiC.EVENT_CHANGE, d);
}
- @Override
- public void rowRemoved(PickerColumnProxy column, int oldRowIndex)
- {
- fireColumnModelChange(children.indexOf(column));
- }
-
- @Override
- public void rowsReplaced(PickerColumnProxy column)
+ public ArrayList getSelectedRows()
{
- fireColumnModelChange(children.indexOf(column));
+ return new ArrayList<>(this.selectedRows);
}
@Override
- public void rowChanged(PickerColumnProxy column, int rowIndex)
+ public void onChanged(PickerColumnProxy proxy)
{
- fireRowChange(children.indexOf(column), rowIndex);
- }
-
- @Override
- public void rowSelected(PickerColumnProxy column, int rowIndex)
- {
- int columnIndex = children.indexOf(column);
- fireSelectionChange(columnIndex, rowIndex);
- }
-
- public ArrayList getPreselectedRows()
- {
- return preselectedRows;
+ TiUIView uiView = peekView();
+ if (uiView instanceof TiUIPlainPicker) {
+ ((TiUIPlainPicker) uiView).onColumnChanged(proxy);
+ }
}
- public void forceRequestLayout()
+ private void onColumnListChanged()
{
- if (peekView() instanceof TiUISpinner) {
- ((TiUISpinner) view).forceRequestLayout();
+ if (this.canFireColumnEvents) {
+ TiUIView uiView = peekView();
+ if (uiView instanceof TiUIPlainPicker) {
+ ((TiUIPlainPicker) uiView).onColumnListChanged();
+ }
}
}
diff --git a/android/modules/ui/src/java/ti/modules/titanium/ui/PickerRowProxy.java b/android/modules/ui/src/java/ti/modules/titanium/ui/PickerRowProxy.java
index 6886d9cf0a9..e49aeb75d7d 100644
--- a/android/modules/ui/src/java/ti/modules/titanium/ui/PickerRowProxy.java
+++ b/android/modules/ui/src/java/ti/modules/titanium/ui/PickerRowProxy.java
@@ -1,32 +1,49 @@
/**
* Appcelerator Titanium Mobile
- * Copyright (c) 2009-2016 by Appcelerator, Inc. All Rights Reserved.
+ * Copyright (c) 2009-2021 by Axway, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
package ti.modules.titanium.ui;
+import java.util.ArrayList;
import org.appcelerator.kroll.KrollDict;
+import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.kroll.annotations.Kroll;
-import org.appcelerator.kroll.common.Log;
import org.appcelerator.titanium.TiC;
-import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.util.TiConvert;
-import org.appcelerator.titanium.view.TiUIView;
-
-import ti.modules.titanium.ui.widget.picker.TiUISpinnerRow;
-import android.app.Activity;
@Kroll.proxy(creatableInModule = UIModule.class)
-public class PickerRowProxy extends TiViewProxy
+public class PickerRowProxy extends KrollProxy
{
+ public interface OnChangedListener {
+ void onChanged(PickerRowProxy proxy);
+ }
+
private static final String TAG = "PickerRowProxy";
+ private final ArrayList listeners = new ArrayList<>();
private String title = "[PickerRow]";
- private PickerRowListener rowListener = null;
- public PickerRowProxy()
+ public void addListener(PickerRowProxy.OnChangedListener listener)
+ {
+ if ((listener != null) && !this.listeners.contains(listener)) {
+ this.listeners.add(listener);
+ }
+ }
+
+ public void removeListener(PickerRowProxy.OnChangedListener listener)
+ {
+ this.listeners.remove(listener);
+ }
+
+ @Override
+ public void handleCreationDict(KrollDict options)
{
- super();
+ super.handleCreationDict(options);
+
+ if (options.containsKey("title")) {
+ this.title = TiConvert.toString(options, "title");
+ }
}
@Kroll.getProperty
@@ -39,9 +56,7 @@ public String getColor()
public void setColor(String color)
{
setPropertyAndFire(TiC.PROPERTY_COLOR, color);
- if (rowListener != null) {
- rowListener.rowChanged(this);
- }
+ onRowChanged();
}
@Kroll.getProperty
@@ -53,54 +68,27 @@ public String getTitle()
@Kroll.setProperty
public void setTitle(String value)
{
- title = value;
- if (rowListener != null) {
- rowListener.rowChanged(this);
- }
+ this.title = value;
+ setPropertyAndFire(TiC.PROPERTY_TITLE, this.title);
+ onRowChanged();
}
@Override
public String toString()
{
- return title;
+ return this.title;
}
- public void setRowListener(PickerRowListener listener)
+ private void onRowChanged()
{
- rowListener = listener;
- }
-
- @Override
- public void add(Object args)
- {
- Log.w(TAG, "PickerRow does not support child controls");
- }
-
- @Override
- public void remove(TiViewProxy child)
- {
- Log.w(TAG, "PickerRow does not support child controls");
- }
-
- @Override
- public TiUIView createView(Activity activity)
- {
- return new TiUISpinnerRow(this);
- }
-
- @Override
- public void handleCreationDict(KrollDict options)
- {
- super.handleCreationDict(options);
- if (options.containsKey("title")) {
- title = TiConvert.toString(options, "title");
+ ArrayList clonedListeners = new ArrayList<>(this.listeners);
+ for (PickerRowProxy.OnChangedListener listener : clonedListeners) {
+ if (this.listeners.contains(listener)) {
+ listener.onChanged(this);
+ }
}
}
- public interface PickerRowListener {
- void rowChanged(PickerRowProxy row);
- }
-
@Override
public String getApiName()
{
diff --git a/android/modules/ui/src/java/ti/modules/titanium/ui/UIModule.java b/android/modules/ui/src/java/ti/modules/titanium/ui/UIModule.java
index bfc8da941a9..2d95e50f41c 100644
--- a/android/modules/ui/src/java/ti/modules/titanium/ui/UIModule.java
+++ b/android/modules/ui/src/java/ti/modules/titanium/ui/UIModule.java
@@ -208,6 +208,15 @@ public class UIModule extends KrollModule
@Kroll.constant
public static final int BUTTON_STYLE_OPTION_NEUTRAL = 6;
+ @Kroll.constant
+ public static final int DATE_PICKER_STYLE_AUTOMATIC = 1;
+ @Kroll.constant
+ public static final int DATE_PICKER_STYLE_COMPACT = 2;
+ @Kroll.constant
+ public static final int DATE_PICKER_STYLE_INLINE = 3;
+ @Kroll.constant
+ public static final int DATE_PICKER_STYLE_WHEELS = 4;
+
@Kroll.constant
public static final int INPUT_BORDERSTYLE_NONE = 0;
@Kroll.constant
diff --git a/android/modules/ui/src/java/ti/modules/titanium/ui/widget/picker/CustomDatePicker.java b/android/modules/ui/src/java/ti/modules/titanium/ui/widget/picker/CustomDatePicker.java
deleted file mode 100644
index 83ee98520af..00000000000
--- a/android/modules/ui/src/java/ti/modules/titanium/ui/widget/picker/CustomDatePicker.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/**
- * Appcelerator Titanium Mobile
- * Copyright (c) 2009-2021 by Axway, Inc. All Rights Reserved.
- * Licensed under the terms of the Apache Public License
- * Please see the LICENSE included with this distribution for details.
- */
-package ti.modules.titanium.ui.widget.picker;
-
-import android.content.Context;
-import android.util.AttributeSet;
-import android.widget.DatePicker;
-
-import org.appcelerator.kroll.common.Log;
-import org.appcelerator.titanium.proxy.TiViewProxy;
-import org.appcelerator.titanium.util.TiUIHelper;
-
-public class CustomDatePicker extends DatePicker
-{
-
- private TiViewProxy proxy = null;
-
- public void setProxy(TiViewProxy value)
- {
- this.proxy = value;
- }
-
- public CustomDatePicker(Context context)
- {
- super(context);
- }
-
- public CustomDatePicker(Context context, AttributeSet attrs)
- {
- super(context, attrs);
- }
-
- public CustomDatePicker(Context context, AttributeSet attrs, int defStyleAttr)
- {
- super(context, attrs, defStyleAttr);
- }
-
- @Override
- protected void onLayout(boolean changed, int left, int top, int right, int bottom)
- {
- super.onLayout(changed, left, top, right, bottom);
- if (this.proxy != null && changed) {
- TiUIHelper.firePostLayoutEvent(this.proxy);
- } else {
- Log.w("Picker", "Proxy not assigned to a native view!");
- }
- }
-}
diff --git a/android/modules/ui/src/java/ti/modules/titanium/ui/widget/picker/FormatNumericWheelAdapter.java b/android/modules/ui/src/java/ti/modules/titanium/ui/widget/picker/FormatNumericWheelAdapter.java
deleted file mode 100644
index ba626614d0e..00000000000
--- a/android/modules/ui/src/java/ti/modules/titanium/ui/widget/picker/FormatNumericWheelAdapter.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- * Appcelerator Titanium Mobile
- * Copyright (c) 2009-2011 by Appcelerator, Inc. All Rights Reserved.
- * Licensed under the terms of the Apache Public License
- * Please see the LICENSE included with this distribution for details.
- */
-
-package ti.modules.titanium.ui.widget.picker;
-
-import java.text.NumberFormat;
-
-import kankan.wheel.widget.NumericWheelAdapter;
-
-public class FormatNumericWheelAdapter extends NumericWheelAdapter
-{
- private NumberFormat formatter;
- private int maxCharacterLength = 2;
-
- public FormatNumericWheelAdapter(int minValue, int maxValue, NumberFormat formatter, int maxCharLength)
- {
- this(minValue, maxValue, formatter, maxCharLength, 1);
- }
-
- public FormatNumericWheelAdapter(int minValue, int maxValue, NumberFormat formatter, int maxCharLength,
- int stepValue)
- {
- super(minValue, maxValue, stepValue);
- this.formatter = formatter;
- this.maxCharacterLength = maxCharLength;
- }
-
- public void setFormatter(NumberFormat formatter)
- {
- this.formatter = formatter;
- }
- @Override
- public String getItem(int index)
- {
- int actualValue = getValue(index);
- if (formatter == null) {
- return Integer.toString(actualValue);
- } else {
- return formatter.format(actualValue);
- }
- }
- @Override
- public int getMaximumLength()
- {
- return maxCharacterLength;
- }
-
- public void setMaximumLength(int value)
- {
- maxCharacterLength = value;
- }
-}
diff --git a/android/modules/ui/src/java/ti/modules/titanium/ui/widget/picker/TextWheelAdapter.java b/android/modules/ui/src/java/ti/modules/titanium/ui/widget/picker/TextWheelAdapter.java
deleted file mode 100644
index 41e70254b73..00000000000
--- a/android/modules/ui/src/java/ti/modules/titanium/ui/widget/picker/TextWheelAdapter.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/**
- * Appcelerator Titanium Mobile
- * Copyright (c) 2009-2011 by Appcelerator, Inc. All Rights Reserved.
- * Licensed under the terms of the Apache Public License
- * Please see the LICENSE included with this distribution for details.
- */
-
-package ti.modules.titanium.ui.widget.picker;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-
-import kankan.wheel.widget.WheelAdapter;
-
-public class TextWheelAdapter implements WheelAdapter
-{
- private ArrayList