0

I have a problem while displaying a list on Sony SmartWatch 2.

I copied layouts from sample project (AdvancedControlSample) and I have the following class:

 public class OpenPositionsView extends ControlExtension implements BaseView {
    private static final String LOG_TAG = "TAGG";

    private Context context;
    private ControlViewGroup mLayout;

    public OpenPositionsView(Context context, String hostAppPackageName) {
        super(context, hostAppPackageName);
        this.context = context;
        mLayout = setup();
    }

    public ControlViewGroup setup() {
        Log.i(LOG_TAG, "setup");

        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(R.layout.watch_positions, null);
        ControlViewGroup mLayout = (ControlViewGroup) parseLayout(layout);

        return mLayout;
    }

    public void show(Controller parent) {

        int listCount = DataProvider.getInstance().getPositions().size();
        parent.sendListCountM(R.id.watch_positions_listview, listCount);
        parent.sendListPositionM(R.id.watch_positions_listview, 0);
        parent.refreshLayout(R.layout.watch_positions, null);


        Log.i(LOG_TAG, "show [listCount: " + listCount + "]");
    }

    @Override
    public void onRequestListItem(final int layoutReference, final int listItemPosition) {
        Log.d(LOG_TAG, "onRequestListItem [layoutReference: " + layoutReference + ", position: " + listItemPosition + "]");
        if (layoutReference != -1 && listItemPosition != -1 && layoutReference == R.id.watch_positions_listview) {
            ControlListItem item = createControlListItem(listItemPosition);
            if (item != null) {
                Log.d(LOG_TAG, "Sending list item");
                sendListItem(item);
            }
        }
    }

    @Override
    public void onListItemSelected(ControlListItem listItem) {
        super.onListItemSelected(listItem);
    }

    @Override
    public void onListItemClick(final ControlListItem listItem, final int clickType, final int itemLayoutReference) {
        Log.d(LOG_TAG, "onListItemClick [listItemPosition: " + listItem.listItemPosition + ", clickType: " + clickType + ", itemLayoutReference: "
                + itemLayoutReference + "]");
    }

    public void onClick(int id) {
        mLayout.onClick(id);
    }

    protected ControlListItem createControlListItem(int position) {
        Log.d(LOG_TAG, "createControlListItem [position: " + position + "]");

        ControlListItem item = new ControlListItem();
        item.layoutReference = R.id.watch_positions_listview;
        item.dataXmlLayout = R.layout.watch_positions_item;
        item.listItemPosition = position;

        // We use position as listItemId. Here we could use some other unique id
        // to reference the list data
        item.listItemId = position;

        Position target = DataProvider.getInstance().getPosition(position);

        if (target != null) {
            Bundle symbolBundle = new Bundle();
            symbolBundle.putInt(Control.Intents.EXTRA_LAYOUT_REFERENCE, R.id.watch_position_symbol);
            symbolBundle.putString(Control.Intents.EXTRA_TEXT, target.getSymbol());

            Bundle typeBundle = new Bundle();
            typeBundle.putInt(Control.Intents.EXTRA_LAYOUT_REFERENCE, R.id.watch_position_type);
            typeBundle.putString(Control.Intents.EXTRA_TEXT, target.getTypeAsString());

            item.layoutData = new Bundle[2];
            item.layoutData[0] = symbolBundle;
            item.layoutData[1] = typeBundle;
            Log.d(LOG_TAG, "Item list created: [symbolBundle: " + symbolBundle + ", typeBundle: " + typeBundle + "]");
        }

        return item;
    }

    protected Bundle[] createBundle(int position) {
        Bundle[] result = new Bundle[2];

        Position target = DataProvider.getInstance().getPosition(position);

        if (target != null) {
            Bundle symbolBundle = new Bundle();
            symbolBundle.putInt(Control.Intents.EXTRA_LAYOUT_REFERENCE, R.id.watch_position_symbol);
            symbolBundle.putString(Control.Intents.EXTRA_TEXT, target.getSymbol());

            Bundle typeBundle = new Bundle();
            typeBundle.putInt(Control.Intents.EXTRA_LAYOUT_REFERENCE, R.id.watch_position_type);
            typeBundle.putString(Control.Intents.EXTRA_TEXT, target.getTypeAsString());

            result[0] = symbolBundle;
            result[1] = typeBundle;
        }
        return result;
    }
}

However, onRequestListItem gets called and createControlListItem returns a correct item list. Touching the display gives me the following result:

onListItemClick [listItem: com.sonyericsson.extras.liveware.extension.util.control.ControlListItem@423b6960, clickType: 0, itemLayoutReference: -1]

The problem is, I do not see any of "added" list items :(

oskario
  • 251
  • 2
  • 6

3 Answers3

1

Make sure you also copied the List-related intents from the Manifest.xml:

<action android:name="com.sonyericsson.extras.aef.control.LIST_REFERESH_REQUEST" />
<action android:name="com.sonyericsson.extras.aef.control.LIST_REQUEST_ITEM" />
<action android:name="com.sonyericsson.extras.aef.control.LIST_ITEM_CLICK" />
<action android:name="com.sonyericsson.extras.aef.control.LIST_ITEM_SELECTED" />
Eir
  • 1,003
  • 9
  • 24
0

Couple questions for you:

  1. What is being shown on the screen? Is it just blank?
  2. Are you calling showLayout() and sendListCount()? I don't see them in the above code. In the sample code in onResume() you should see something like:

    showLayout(R.layout.layout_test_list, null); sendListCount(R.id.listView, mListContent.length);

    These need to be called.

  3. Did you make sure that sendListItem(item) is actually being called?

mldeveloper
  • 2,253
  • 1
  • 13
  • 14
  • Ad. 1. It is not blank, it displays the top bar like in the example, but no elements are visible on the list. Ad. 2 & 3. Yes, I do call them. I verified it in the debugger. I even noticed that I cannot change packet names from the samples. After changing com.sonymobile.smartconnect.extension.advancedcontrolsample to com.myapp the application compiles, but when I tap the icon on the watch, nothing happens. I also changed it in manifest, of course. – oskario Nov 21 '13 at 08:55
0

Aren't you adding black text items to layout with black background? :) Please check your layouts.

peter.bartos
  • 11,855
  • 3
  • 51
  • 62