Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TIMOB-7739 add label for prompt and implement background properties #4409

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,29 @@

import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.util.TiFileHelper;
import org.appcelerator.titanium.util.TiUIHelper;

import ti.modules.titanium.ui.widget.TiUIText;
import android.text.InputType;
import android.graphics.drawable.Drawable;
import android.text.TextUtils.TruncateAt;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.inputmethod.EditorInfo;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class TiUISearchBar extends TiUIText
{
protected ImageButton cancelBtn;

private TextView promptText;

public interface OnSearchChangeListener {
public void filterBy(String text);
}
Expand All @@ -37,6 +42,9 @@ public TiUISearchBar(final TiViewProxy proxy)
super(proxy, true);

TiEditText tv = (TiEditText) getNativeView();
promptText = new TextView(proxy.getActivity());
promptText.setEllipsize(TruncateAt.END);
promptText.setSingleLine(true);
tv.setImeOptions(EditorInfo.IME_ACTION_DONE);

// TODO Add Filter support
Expand Down Expand Up @@ -75,9 +83,14 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
};

layout.setGravity(Gravity.NO_GRAVITY);
layout.setPadding(0,0,0,0);
layout.setPadding(0, 0, 0, 0);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.CENTER_IN_PARENT);
params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
promptText.setGravity(Gravity.CENTER_HORIZONTAL);
layout.addView(promptText, params);

RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
params.addRule(RelativeLayout.CENTER_VERTICAL);
params.addRule(RelativeLayout.LEFT_OF, 101);
Expand Down Expand Up @@ -106,22 +119,43 @@ public void processProperties(KrollDict d)
{
super.processProperties(d);

if (d.containsKey("showCancel")) {
boolean showCancel = TiConvert.toBoolean(d, "showCancel", false);
if (d.containsKey(TiC.PROPERTY_SHOW_CANCEL)) {
boolean showCancel = TiConvert.toBoolean(d, TiC.PROPERTY_SHOW_CANCEL, false);
cancelBtn.setVisibility(showCancel ? View.VISIBLE : View.GONE);
} else if (d.containsKey("barColor")) {
nativeView.setBackgroundColor(TiConvert.toColor(d, "barColor"));
}
if (d.containsKey(TiC.PROPERTY_BAR_COLOR)) {
nativeView.setBackgroundColor(TiConvert.toColor(d, TiC.PROPERTY_BAR_COLOR));
}
if (d.containsKey(TiC.PROPERTY_PROMPT)) {
String strPrompt = TiConvert.toString(d, TiC.PROPERTY_PROMPT);
promptText.setText(strPrompt);
}
if (d.containsKey(TiC.PROPERTY_BACKGROUND_IMAGE)) {
String bkgdImage = TiConvert.toString(proxy.getProperty(TiC.PROPERTY_BACKGROUND_IMAGE));
TiFileHelper tfh = new TiFileHelper(tv.getContext());
String url = proxy.resolveUrl(null, bkgdImage.toString());
Drawable background = tfh.loadDrawable(url, false);
nativeView.setBackgroundDrawable(background);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These properties need to be handled inside onPropertyChanged as well.

}

@Override
public void propertyChanged(String key, Object oldValue, Object newValue, KrollProxy proxy)
{
if (key.equals("showCancel")) {
if (key.equals(TiC.PROPERTY_SHOW_CANCEL)) {
boolean showCancel = TiConvert.toBoolean(newValue);
cancelBtn.setVisibility(showCancel ? View.VISIBLE : View.GONE);
} else if (key.equals("barColor")) {
} else if (key.equals(TiC.PROPERTY_BAR_COLOR)) {
nativeView.setBackgroundColor(TiConvert.toColor(TiConvert.toString(newValue)));
} else if (key.equals(TiC.PROPERTY_PROMPT)) {
String strPrompt = TiConvert.toString(newValue);
promptText.setText(strPrompt);
} else if (key.equals(TiC.PROPERTY_BACKGROUND_IMAGE)) {
String bkgdImage = TiConvert.toString(newValue);
TiFileHelper tfh = new TiFileHelper(tv.getContext());
String url = proxy.resolveUrl(null, bkgdImage);
Drawable background = tfh.loadDrawable(url, false);
nativeView.setBackgroundDrawable(background);
} else {
super.propertyChanged(key, oldValue, newValue, proxy);
}
Expand Down
17 changes: 16 additions & 1 deletion android/titanium/src/java/org/appcelerator/titanium/TiC.java
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,11 @@ public class TiC
* @module.api
*/
public static final String PROPERTY_BACKGROUND_SELECTED_IMAGE = "backgroundSelectedImage";

/**
* @module.api
*/
public static final String PROPERTY_BAR_COLOR = "barColor";

/**
* @module.api
Expand Down Expand Up @@ -1680,6 +1685,11 @@ public class TiC
* @module.api
*/
public static final String PROPERTY_PREFERRED_PROVIDER = "preferredProvider";

/**
* @module.api
*/
public static final String PROPERTY_PROMPT = "prompt";

/**
* @module.api
Expand Down Expand Up @@ -1857,7 +1867,12 @@ public class TiC
* @module.api
*/
public static final String PROPERTY_SHOW_AS_ACTION = "showAsAction";


/**
* @module.api
*/
public static final String PROPERTY_SHOW_CANCEL = "showCancel";

/**
* @module.api
*/
Expand Down
6 changes: 3 additions & 3 deletions apidoc/Titanium/UI/SearchBar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ properties:
description: |
For information about color values, see the "Colors" section of <Titanium.UI>.

On iOS, `barColor` specifies the color of the "frame" around the search text field.
On iOS and Android, `barColor` specifies the color of the "frame" around the search text field.
type: String
platforms: [iphone, ipad]
platforms: [android, iphone, ipad]
default: System default bar color.

- name: hintText
Expand All @@ -149,7 +149,7 @@ properties:
- name: prompt
summary: Single line of text displayed at the top of the search bar.
type: String
platforms: [iphone, ipad]
platforms: [android, iphone, ipad]
default: No prompt.

- name: promptid
Expand Down