Tables iPhone; HTML 5 Networking; Android TableLayout and ListView




CS175

Chris Pollett

Oct 29, 2014

Outline

Tables

Introduction

Table Interface Builder

ViewController.h

#import < UIKit/UIKit.h> 
#include < sys/types.h> 
#include < sys/socket.h> 
#include < netinet/in.h> 
#include < netdb.h> 

@interface ViewController : UIViewController 
	< UITableViewDelegate, UITableViewDataSource> 
@property (nonatomic, copy) NSArray *listData;

@end

Table Code

HTML 5 Networking

XMLHttpRequest

Step-by-Step Continued II

Step-by-Step Continued III

Step-by-Step Continued IV

Simplifying Life with jQuery

HTML 5 WebSockets

HTML 5 WebSockets -- HTTP

HTML 5 WebSockets -- Javascript

Below are the basic WebSocket Javascript functions (websocket URI's are prefixed with ws: or wss: (secure)):

var webSocket = new
WebSocket("ws://some.websocketplace.org");
// Associate listeners
webSocket.onopen = function(evt) {
alert("The connection was opened");
};
webSocket.onmessage = function(evt) {
alert("Received message: " + evt.data);
};
webSocket.onclose = function(evt) {
alert("The connection was closed");
};
webSocket.onerror = function(evt) {
alert("Ouch an error!");
};

webSocket.send("This is some WebSocket data!");
// Close WebSocket
webSocket.close();

UI for Android

ListActivity

What ListViewTest Looks Like

Android Screenshot of a ListView

ListActivity with a custom layout (First the Layout)

ListActivity with a custom layout (code)

package org.pollett;

import android.app.*;
import android.content.DialogInterface;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;
import android.os.Bundle;

public class ListViewTest extends ListActivity implements OnClickListener {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	View button;
    	
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        setListAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, FOOD));
        getListView().setTextFilterEnabled(true);

        button = this.findViewById(R.id.mybutton);
        button.setOnClickListener(this );
    }

    protected void  onListItemClick(ListView l, View v, int position, long id)
    {
        AlertDialog alertDialog = new AlertDialog.Builder(this).create();
        alertDialog.setTitle("List Item Clicked");
        alertDialog.setMessage("You clicked list item " + position);
        alertDialog.setButton("Okay", new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int which) {
            return;
          } });
        alertDialog.show();
    }
 
    public void onClick(View v)
    {
    	AlertDialog alertDialog = new AlertDialog.Builder(this).create();
    	alertDialog.setTitle("Button Clicked");
    	alertDialog.setMessage("You clicked the button");
    	alertDialog.setButton("Okay", new DialogInterface.OnClickListener() {
 	          public void onClick(DialogInterface dialog, int which) {
 	            return;
 	          } });
 	    alertDialog.show();
    }    
    
    static final String[] FOOD= new String[] {
        "Pizza", "Apple", "Calzone", "Ma Po Do Fu",
        "Pho Bo", "Curry", "Coffee", "Catfish"
        
      };
    
}

TableLayout

TableLayout Example (based on Android Developer Example)

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="1">

    <TableRow>
        <TextView
            android:layout_column="1"
            android:text="Open..."
            android:padding="3dip" />
        <TextView
            android:text="Ctrl-O"
            android:gravity="right"
            android:padding="3dip" />
    </TableRow>

    <TableRow>
        <TextView
            android:layout_column="1"
            android:text="Save..."
            android:padding="3dip" />
        <TextView
            android:text="Ctrl-S"
            android:gravity="right"
            android:padding="3dip" />
    </TableRow>

    <View
        android:layout_height="2dip"
        android:background="#FF909090" />

    <TableRow>
        <TextView
            android:text="X"
            android:padding="3dip" />
        <TextView
            android:text="Import..."
            android:padding="3dip" />
    </TableRow>

</TableLayout>

What TableLayoutTest Looks Like

Android Screenshot of a TableLayout