contact-form

Check input type with mozilla.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input

<form class="date-and-time-picker">
	<label for="date">
		<span>what day do you want to leave?</span>
		<input id="date" type="date">
	</label>
	<label for="time">
		<span>What time do you want to leave?</span>
		<input id="time" type="date-time">
	</label>
</form>

data list

<input list="nano">
<datalist id="nano">
	<option value="Android"></option>
	<option value="Data Analyst"></option>
	<option value="Front End"></option>
	<option value="Full Stack"></option>
	<option value="Intro to Programming"></option>
	<option value="iOS"></option>
	<option value="Tech Entrepreneur"></option>
</datalist>

Another datalist

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Quiz - Datalists</title>
</head>
<body>
    <p>What kind of event are you hosting?</p>
    <input list="event">
    <datalist id="event">
        <option>Party</option>
        <option>Meeting</option>
        <option>Conference Talk</option>
        <option>Sports Game</option>
    </datalist>
</body>
</html>
<form>
	<label for="use-billing">
		<span>Same as billing address</span>
	</label>
	<input type="checkbox" id="use-billing">

	<br>

	<label for="tel-number">
		<span>Telephone Number</span>
		<input type="tel" id="tel-number">
	</label>
</form>

Camera and Audio Input

<input type="file" accept="image/*;capture=camera">
<input type="file" accept="image/*;capture=camcorder">
<input type="file" accept="image/*;capture=microphone">

problems with file input capture
-only works on mobile
-file open button is unstylable
-different app can break the flow

navigator.getUserMedia(constraints, successCallback, errorCallback);

function openCameraPane(callback, fullscreen) {
	if (fullscreen)
		document.body.webkitRequestFullscreen();
	_myVideoCallback = callback;
	var constraints = {video: true};
    
	navigator.getUserMedia(constraints,successCallback,errorCallback);
}
function successCallback(stream) {
	var video = createVideoUserInterface();
	video.src = window.URL.createObjectURL(stream);
    
}
function snapshot(ev) {
	var video = document.querySelector('.camera-video');
	var canvas = document.querySelector('.camera-picture');
	var ctx = canvas.getContext('2d');

  ctx.drawImage(video, 0, 0);
}
MediaStreamTrack.getSources(gotSources);
<element>.requestFullscreen();

html5 geolocation API
maps, augmented reality, geocaching, nearby features

navigator.geolocation.getCurrentPosition(
	function(position){
		do_something(
			position.coords.latitude,
			position.coords.longitude )
	});

Vibration API
navigator.vibrate(1000)

viewport and media query

<meta name="viewport" content="width=device-width">

start this tag.

<meta name="viewport" content="width=device-width,initial-scale=1">

1vmin = 1vm or 1vh, whichever is smallest
1vmax = 1vm or 1vh, whichever is largest

available media query expressions
width, height, device-width, device-height, orientation, aspect-ratio,
device-aspect-ratio, grid, color, color-index, monochrome, resolution, scan

.menu-items-grid {
    display: flex;
    flex-wrap: wrap;
    flex-direction: row;
    justify-content: space-around;
    padding: 0 1%
}

@media (orientation:portrait){
  .menu-items-grid {
    flex-direction: column;
  }
}

window.devicePixelRatio

@media (min-pixel-ratio:2){
  .pretteybackground {
    background: url('images/hires_bkg.png');
  }
}

cellular radio lifecycle
Idle -> active -> short sleep -> long sleep

-lifecycle of an HTTP request
DNS lookup -> socket connect -> HTTP request -> Data download

avoid redirect
minimize or eliminate render-blocking resources (stylesheets, fonts, unknown-size, image)

animation framework
settimeout, setInterval -> requestAnimationFrame

touch UI
hover does not rely on
use large hit target
do not disable mouse support

touch events
->touchstart, touchmove, touchend, touch cancel

Input
html5 has tel input type.

<input type="tel">
<label>
  <input type="checkbox">
  "Do you love lemurs?"
</label>

interface

public interface Drawable
{
	void draw();
}

public class House implements Drawable
{
	public void draw(){...}
}
for (Drawable d : elements) { d.draw();}
public interface Moveable
{
	void move(int seconds);
}

public class Car implements Drawable, Moveable

setter and getter

publi class Person
{
	private String name;

	public String getName(){ return name; }
	public void setName(String newName)
	{
		if(newName.length() > 0) { name = newName; }
	}
}

getter はprivate instance field を getできるようにするもの。
setter はpublic (String/double/picture..) getHogeの値をセットするものです。

    public void setDriverName(String newName)
    {
      driverName = newName;
    }

    public String getDriverName()
    {
      return driverName;
    }

static method:staticメソッドはインスタンスではなく「クラスに属するメソッド」のため、インスタンスを作らずに直接呼び出すことができる。

    public Person(String name)
    {
        this.name = name;
        friends = new ArrayList<Person>();
        lastAssignedId++;
        id = lastAssignedId;
    }
public boolean tryToAdd(Person p)
{
    if(passengers.size() + 2 < numberOfSeats && p.getDestination() <= destination);
    {
        passengers.add(p);
        return true;
    }
    else
    {
        return false;
    }
}
public void drive()
{
    location++;
    while (i < passengers.size())
    {
      Person p = passengers.get(i);
      if (p.getDestination() == location)
      {
        passengers.remove(i);
      }
      else
      {
        i++;
      }
    }
}
public void loadPassengers()
{
    for (Person p : people)
    {
      boolean added = false;
      for (int i = 0; !added && i < cars.size(); i++)
      {
        added = cars.get(i).tryToAdd(p);
      }
    }
}
public void driveCars()
{
  while (cars.size() > 0)
  {
    for (int i = 0; i < cars.size(); i++)
    {
      Car c = cars.get(i);
      c.drive();
      if (c.hasArrived())
      {
        cars.remove(i);
      }
      else
      {
        i++;
      }
    }
  }
}

Java class

class look for nouns in the process
methods: verbs
each method is the responsibility of a single class

  private int numberOfPassengers;

    public void addPassenger(int n)
    {
        if (numberOfPassengers + 1 < numberOfSeats)
        {
          numberOfPassengers++;
        }
    }
    public int getPassengerCount()
    {
        return numberOfPassengers;
    }
import java.util.ArrayList;

public class Car
{
    private int numberOfSeats;
    private ArrayList passengers;
    private int numberOfPassengers;


    public Car(int numberOfSeats)
    {
        this.numberOfSeats = numberOfSeats;
        passengers = new ArrayList();
    }

   /**
    *  Adds a passenger to this car, provided that there is space.
    *  @param name the name of the passenger
    */
    public void addPassenger(String name)
    {
        if(getPassengerCount() + 1 < numberOfSeats)
        {
          passengers.add(name);
        }
        
    }

    public int getPassengerCount()
    {
        return passengers.size();
    }

    public String getPassengerList()
    {
        return passengers.toString();
    }
    
}

average pic color

public class Blocks
{
    public static void main(String[] args)
    {
        Picture pic = new Picture("eiffel-tower.jpg");
        int[][] pixels = pic.getGrayLevels();

        
        for (int i = 0; i < pixels.length; i = i + 2)
        {
            for (int j = 0; j < pixels[0].length; j = j + 2)
            {
                int avg = (pixels[i][j] + pixels[i][j+1]
                    + pixels[i+1][j] + pixels[i+1][j+1]) / 4;
                pixels[i][j] = avg;
                pixels[i][j+1] = avg;
                pixels[i+1][j] = avg;
                pixels[i+1][j+1] = avg;                
            }
        }

        pic.draw();
        Picture pic2 = new Picture(pixels);
        pic2.translate(pic.getWidth() + 10, 0);
        pic2.draw();
    }
}

double[] total = new double[numStudents];
for(int i = 0; i < numStudents; i++) { total[i] = totalForStudent(i); } return total; [/java]

swap halves

import java.util.Arrays;

public class SwapHalves
{
    public static void main(String[] args)
    {
        int[] elements = { 1, 4, 9, 7, 3, 2, 5, 11, 0, 9 };

        int j = elements.length / 2;
        for(int i = 0;  i < (elements.length / 2); i++)
        {
            int saved = elements[i];
            elements[i] = elements[j];
            elements[j] = saved;
            j++;
        }
        System.out.println(Arrays.toString(elements));
    }
}

two dimension array

double reg1 = prices[0][1];
for (int i = 0; i < prices.length; i++)
{
	for (j = 0; j < prices[0].length; j++)
	{
		System.out.printf("%10.3f", prices[i][j]);
	}
	System.out.println();
}