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 12176: Implementation of ListView #3935

Merged
merged 38 commits into from
Mar 14, 2013
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
f03926e
timob-12176: listview work so far #1
hieupham007 Feb 8, 2013
0939dfc
Merge branch 'master' of git://github.com/appcelerator/titanium_mobil…
hieupham007 Feb 12, 2013
631eb29
timob-12176: push #2
hieupham007 Feb 14, 2013
fadb1fe
Merge branch 'master' of git://github.com/appcelerator/titanium_mobil…
hieupham007 Feb 15, 2013
ad38236
timob-12176: add listCell + implement recycle views
hieupham007 Feb 17, 2013
1cc98d6
Merge branch 'master' of git://github.com/appcelerator/titanium_mobil…
hieupham007 Feb 17, 2013
c600dee
timob-12176: implement listCell + properties parsing
hieupham007 Feb 18, 2013
9891f0b
timob-12176: create proxies in js
hieupham007 Feb 20, 2013
a804e6e
timob-12716: update listview
hieupham007 Feb 22, 2013
08bb922
Merge branch 'master' of git://github.com/appcelerator/titanium_mobil…
hieupham007 Feb 23, 2013
a45e863
Merge branch 'master' of git://github.com/appcelerator/titanium_mobil…
hieupham007 Feb 25, 2013
6bf0077
timob-112176: resolve conflict
hieupham007 Feb 25, 2013
2e9eec5
Merge branch 'master' of git://github.com/appcelerator/titanium_mobil…
hieupham007 Feb 25, 2013
1e68f9e
timob-12176: update method names
hieupham007 Feb 26, 2013
f691eff
timob-12176: implement tree binding.
hieupham007 Feb 27, 2013
d5ff50f
timob-12176: added supported for header + footerTitle for sections an…
hieupham007 Feb 28, 2013
073fb22
timob-12176: add default itemList xml
hieupham007 Feb 28, 2013
a93b3e0
timob-12176: prototype eventing + create xml for base views
hieupham007 Mar 1, 2013
ded8c0e
timob-12176: fix bugs + implement section methods
hieupham007 Mar 2, 2013
02cbc1d
timob-12176: more eventing + section methods + fix layout issue
hieupham007 Mar 4, 2013
9e1b358
timob-12176: fix item type count
hieupham007 Mar 4, 2013
cbaecc3
timob-12176: implement the rest of required APIs
hieupham007 Mar 5, 2013
5276d4d
Merge branch 'master' of git://github.com/appcelerator/titanium_mobil…
hieupham007 Mar 5, 2013
450daab
timob-12176: fix eventing issues
hieupham007 Mar 6, 2013
b58a856
timob-12176: memory leak fix
hieupham007 Mar 7, 2013
59059c3
timob-12176: optimization
hieupham007 Mar 7, 2013
3f970d4
Merge branch 'master' of git://github.com/appcelerator/titanium_mobil…
hieupham007 Mar 7, 2013
29e9a88
timob-12176: fix bugs + add some invalid input handling
hieupham007 Mar 8, 2013
18a25ab
timob-12716: fix typo
hieupham007 Mar 9, 2013
df01733
timob-12176: fix various bugs.
hieupham007 Mar 9, 2013
6551f78
Merge branch 'master' of git://github.com/appcelerator/titanium_mobil…
hieupham007 Mar 12, 2013
9805f08
timob-12176: address comments
hieupham007 Mar 12, 2013
ac51568
timob-12176: fix crashing issues
hieupham007 Mar 12, 2013
6a099fe
timob-12176: fix 4.0+ crash
hieupham007 Mar 13, 2013
7e30f25
timob-12176: fix 'change' event in switch + typo
hieupham007 Mar 13, 2013
92174c0
timob-12176: address minor comments
hieupham007 Mar 13, 2013
9836e27
Merge branch 'master' of git://github.com/appcelerator/titanium_mobil…
hieupham007 Mar 14, 2013
c1e7588
timob-12176: change default dimensions for image
hieupham007 Mar 14, 2013
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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added android/modules/ui/res/drawable/btn_more_64.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions android/modules/ui/res/layout/list_header_or_footer.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="5sp"
android:background="#A9A9A9"
android:clickable="false" >

<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:typeface="sans"
android:textSize="14sp"/>

</LinearLayout>
32 changes: 32 additions & 0 deletions android/modules/ui/res/layout/list_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width= "fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >

<ti.modules.titanium.ui.widget.listview.ListItemLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">

<ti.modules.titanium.ui.widget.listview.TiBaseListViewItem
android:id="@+id/listItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</ti.modules.titanium.ui.widget.listview.ListItemLayout>

<ImageView
android:id="@+id/accessoryType"
android:contentDescription="@string/accessoryType"
android:layout_width="wrap_content"
android:layout_height= "fill_parent"
android:adjustViewBounds="true"
android:scaleType="centerInside"
android:maxWidth="35dp"
android:focusable="false"
android:focusableInTouchMode="false" />

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason why we are inflating from xml? I'm just asking for consistency sake since we don't really do that anywhere else in titanium. We just instantiate it programmatically.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's cleaner and faster. Definitely a lot cleaner though...

Copy link
Contributor

Choose a reason for hiding this comment

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

I doubt it's faster, it still has to instantiate it the same way. If anything it would be slightly slower since it has to parse the xml (probably negligible though). Personally I'd rather keep it consistent so we don't have these xml files floating around (my personal preference).



</LinearLayout>
1 change: 1 addition & 0 deletions android/modules/ui/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Titanium UI Module</string>
<string name="accessoryType">One of the following images: isCheck, hasChild, or custom image.</string>
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't use camel case here because some OS are case insensitive and some are case sensitive and this may introduce name conflict. BTW, in order to avoid the name conflict, it is better to add the package name to the string name, eg. titanium_ui_widget_listview_accessory_type.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, for all the resources used by titanium, like layout and drawable, we should add the package name to the res name/id to avoid name conflict.

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ public class UIModule extends KrollModule implements Handler.Callback
@Kroll.constant public static final int INPUT_BUTTONMODE_ONFOCUS = 0;
@Kroll.constant public static final int INPUT_BUTTONMODE_ALWAYS = 1;
@Kroll.constant public static final int INPUT_BUTTONMODE_NEVER = 2;

@Kroll.constant public static final String LIST_ITEM_TEMPLATE_DEFAULT = "listDefaultTemplate";
@Kroll.constant public static final int LIST_ACCESSORY_TYPE_NONE = 0;
@Kroll.constant public static final int LIST_ACCESSORY_TYPE_CHECKMARK = 1;
@Kroll.constant public static final int LIST_ACCESSORY_TYPE_DETAIL = 2;


@Kroll.constant public static final int MAP_VIEW_STANDARD = 1;
@Kroll.constant public static final int MAP_VIEW_SATELLITE = 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,6 @@ public void handleEvent(int id)
}
data.put(TiC.EVENT_PROPERTY_INDEX, id);
data.put(TiC.PROPERTY_CANCEL, id == cancelIndex);
proxy.fireEvent(TiC.EVENT_CLICK, data);
fireEvent(TiC.EVENT_CLICK, data);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -519,36 +519,37 @@ private void fireLoad(String state)
{
KrollDict data = new KrollDict();
data.put(TiC.EVENT_PROPERTY_STATE, state);
proxy.fireEvent(TiC.EVENT_LOAD, data);
fireEvent(TiC.EVENT_LOAD, data);
}

private void fireStart()
{
KrollDict data = new KrollDict();
proxy.fireEvent(TiC.EVENT_START, data);
fireEvent(TiC.EVENT_START, data);
}

private void fireChange(int index)
{
KrollDict data = new KrollDict();
data.put(TiC.EVENT_PROPERTY_INDEX, index);
proxy.fireEvent(TiC.EVENT_CHANGE, data);
fireEvent(TiC.EVENT_CHANGE, data);
}

private void fireStop()
{
KrollDict data = new KrollDict();
proxy.fireEvent(TiC.EVENT_STOP, data);
fireEvent(TiC.EVENT_STOP, data);
}

private void fireError(String message, String imageUrl)
{
KrollDict data = new KrollDict();

data.putCodeAndMessage(TiC.ERROR_CODE_UNKNOWN, message);
if (imageUrl != null) {
data.put(TiC.PROPERTY_IMAGE, imageUrl);
}
proxy.fireEvent(TiC.EVENT_ERROR, data);
fireEvent(TiC.EVENT_ERROR, data);
}

private class Animator extends TimerTask
Expand All @@ -567,7 +568,7 @@ public void run()
if (paused) {
synchronized (this) {
KrollDict data = new KrollDict();
proxy.fireEvent(TiC.EVENT_PAUSE, data);
fireEvent(TiC.EVENT_PAUSE, data);
waitOnResume = true;
wait();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,6 @@ protected void handleHide() {
@Override
public void onCancel(DialogInterface dialog) {
visible = false;
proxy.fireEvent(TiC.EVENT_CANCEL, null);
fireEvent(TiC.EVENT_CANCEL, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
data.put(TiC.EVENT_PROPERTY_THUMB_SIZE, size);
proxy.setProperty(TiC.PROPERTY_VALUE, scaledValue, false);

proxy.fireEvent(TiC.EVENT_CHANGE, data);
fireEvent(TiC.EVENT_CHANGE, data);
}

public void onStartTrackingTouch(SeekBar seekBar) {
Expand All @@ -302,7 +302,7 @@ public void onStartTrackingTouch(SeekBar seekBar) {
public void onStopTrackingTouch(SeekBar seekBar) {
KrollDict data = new KrollDict();
data.put(TiC.PROPERTY_VALUE, scaledValue());
proxy.fireEvent(TiC.EVENT_STOP, data);
fireEvent(TiC.EVENT_STOP, data);
}

private float scaledValue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void onCheckedChanged(CompoundButton btn, boolean value) {
data.put(TiC.PROPERTY_VALUE, value);

proxy.setProperty(TiC.PROPERTY_VALUE, value);
proxy.fireEvent(TiC.EVENT_CHANGE, data);
fireEvent(TiC.EVENT_CHANGE, data);
}

protected void setStyle(int style)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public void onTextChanged(CharSequence s, int start, int before, int count)
data.put("value", newValue);

proxy.setProperty(TiC.PROPERTY_VALUE, newValue);
proxy.fireEvent(TiC.EVENT_CHANGE, data);
fireEvent(TiC.EVENT_CHANGE, data);
}
}

Expand Down Expand Up @@ -348,7 +348,7 @@ public boolean onEditorAction(TextView v, int actionId, KeyEvent keyEvent)
if ((actionId == EditorInfo.IME_NULL && keyEvent != null) ||
actionId == EditorInfo.IME_ACTION_NEXT ||
actionId == EditorInfo.IME_ACTION_DONE ) {
proxy.fireEvent("return", data);
fireEvent("return", data);
}

Boolean enableReturnKey = (Boolean) proxy.getProperty(TiC.PROPERTY_ENABLE_RETURN_KEY);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package ti.modules.titanium.ui.widget.listview;

import java.util.HashMap;

import org.appcelerator.kroll.KrollDict;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.util.TiConvert;

import ti.modules.titanium.ui.ImageViewProxy;
import ti.modules.titanium.ui.LabelProxy;
import ti.modules.titanium.ui.widget.listview.TiTemplate.DataItem;
import android.app.Activity;

public class DefaultTemplate extends TiTemplate {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think TiTemplate should be named TiListViewTemplate and DefaultTemplate should be TiDefaultListViewTemplate. Just having template as the name is too generic and it's not clear that it's associated with listview.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


public static final String DEFAULT_LABEL_BINDING = "title";
public static final String DEFAULT_IMAGE_BINDING = "image";
Copy link
Contributor

Choose a reason for hiding this comment

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

These two constants have been in TiC. Don't need to define here again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


public DefaultTemplate(String id, KrollDict properties, Activity activity) {
super(id, properties);
generateDefaultProps(activity);
}

public void generateDefaultProps(Activity activity) {

//Generate root item data proxy
ListItemProxy proxy = new ListItemProxy();
proxy.setActivity(activity);
rootItem = new DataItem(proxy, TiC.PROPERTY_PROPERTIES, null);
dataItems.put(itemID, rootItem);

//Init default properties for our proxies
KrollDict defaultLabelProperties = new KrollDict();
KrollDict defaultImageProperties = new KrollDict();

//Generate label proxy
LabelProxy labelProxy = new LabelProxy();
labelProxy.setActivity(activity);
//Generate properties
defaultLabelProperties.put("left", "10%");
defaultLabelProperties.put("text", "label");
Copy link
Contributor

Choose a reason for hiding this comment

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

Use TiC.PROPERTY_LEFT and TiC.PROPERTY_TEXT instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

//bind the proxy and default properties
DataItem labelItem = new DataItem(labelProxy, DEFAULT_LABEL_BINDING, rootItem);
dataItems.put(DEFAULT_LABEL_BINDING, labelItem);
//set default properties
labelItem.setDefaultProperties(defaultLabelProperties);
//add child
rootItem.addChild(labelItem);

//Generate image proxy
ImageViewProxy imageProxy = new ImageViewProxy();
imageProxy.setActivity(activity);
//Generate properties
defaultImageProperties.put("right", "0");
defaultImageProperties.put("height", "100");
defaultImageProperties.put("width", "100");
Copy link
Contributor

Choose a reason for hiding this comment

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

Use TiC constants instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

//bind the proxy and default properties
DataItem imageItem = new DataItem (imageProxy, DEFAULT_IMAGE_BINDING, rootItem);
dataItems.put(DEFAULT_IMAGE_BINDING, imageItem);
//set default properties
imageItem.setDefaultProperties(defaultImageProperties);
//add child
rootItem.addChild(imageItem);


}
private void parseDefaultData(KrollDict data) {
if (!data.containsKey(TiC.PROPERTY_PROPERTIES)) {
return;
}

KrollDict properties = data.getKrollDict(TiC.PROPERTY_PROPERTIES);
KrollDict clone_properties = new KrollDict((HashMap)properties.clone());
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment about cloning the hashmap. Why do we clone this if we're just going to create a new krolldict with it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

if (clone_properties.containsKey(TiC.PROPERTY_TITLE)) {
KrollDict text = new KrollDict();
text.put(TiC.PROPERTY_TEXT, TiConvert.toString(clone_properties, TiC.PROPERTY_TITLE));
data.put(TiC.PROPERTY_TITLE, text);
if (clone_properties.containsKey(TiC.PROPERTY_FONT)) {
text.put(TiC.PROPERTY_FONT, clone_properties.getKrollDict(TiC.PROPERTY_FONT).clone());
clone_properties.remove(TiC.PROPERTY_FONT);
}
if (clone_properties.containsKey(TiC.PROPERTY_COLOR)) {
text.put(TiC.PROPERTY_COLOR, clone_properties.get(TiC.PROPERTY_COLOR));
clone_properties.remove(TiC.PROPERTY_COLOR);
}
clone_properties.remove(TiC.PROPERTY_TITLE);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we only support the "text", "font" and "color" properties for the default template? Because we support more properties in our Ti.UI.Label.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes if they're using built-in template, only "text", "color" and "font" are supported for the label, and only "image" is supported for image.

}

if (clone_properties.containsKey(TiC.PROPERTY_IMAGE)) {
KrollDict image = new KrollDict();
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm probably missing something. Why are we storing the image as a kroll dict instead of a string into 'data'?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is because I'm converting something like var item = {properties: {image: "img.png", backgroundColor: "blue"} } into var item = {properties: {backgroundColor: "blue"} , image: {image: "img.png"} }. Basically Im converting the special case into the regular expected case of "binding": "properties". Easier to process data if all data are in the same format.

image.put(TiC.PROPERTY_IMAGE, TiConvert.toString(clone_properties, TiC.PROPERTY_IMAGE));
data.put(TiC.PROPERTY_IMAGE, image);
clone_properties.remove(TiC.PROPERTY_IMAGE);
}

data.put(TiC.PROPERTY_PROPERTIES, clone_properties);
}

public void updateDefaultProperties(KrollDict data) {

parseDefaultData(data);
super.updateDefaultProperties(data);
}

public void mergeWithDefaultProperties(KrollDict data) {
parseDefaultData(data);
super.mergeWithDefaultProperties(data);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package ti.modules.titanium.ui.widget.listview;

import org.appcelerator.titanium.view.TiCompositeLayout;

import android.content.Context;
import android.util.AttributeSet;
import android.view.ViewGroup;

public class ListItemLayout extends TiCompositeLayout{

public ListItemLayout(Context context, AttributeSet set) {
super(context, set);
}

@Override
public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) {
LayoutParams params = generateDefaultLayoutParams();
params.autoFillsWidth = true;
return params;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this class is needed. It's just a TiCompositeLayout with width to be fill by default. You can probably just apply it to the layout params of your view during creation. Similar to how we do it in ViewProxy.

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ti.modules.titanium.ui.widget.listview;

import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.view.TiUIView;

import ti.modules.titanium.ui.UIModule;
import android.app.Activity;

@Kroll.proxy(creatableInModule = UIModule.class)
public class ListItemProxy extends TiViewProxy {


public TiUIView createView(Activity activity) {
return new TiListItem(this);
}

}