list_item.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_width="match_parent"
	android:layout_height="wrap_content"
	android:gravity="center_vertical"
	android:orientation="horizontal"
	android:minHeight="?android:attr/listPreferredItemHeight"
	android:padding="16dp">

	<ImageView
		android:id="@+id/list_item_icon"
		android:layout_width="50dp"
		android:layout_height="50dp" />

	<LinearLayout
		android:layout_width="0dp"
		android:layout_height="wrap_content"
		andorid:layout_weight="1"
		android:orientation="vertical"
		android:padding="16dp">

		<TextView
			android:id="@+id/version_name"
			android:layout_width="wrap_content"
			android:layout_height="wrap_content" />

		<TextView
			android:id="@+id/version_name"
			android:layout_width="wrap_content"
			android:layout_height="wrap_content" />

	</LinearLayout>

</LinearLayout>

USGS earthquake API parameters

USGS earthquake API parameters

parameter name: description
mag: short for “magnitude”
place: where the earthquake occurred
time: when the earthquake occurred
felt: how strong this quake was felt
tsunami: was there a tsunami alert issued?
title: the title of the quake (mag + place)
coordinates: where the earthquake occured (long, lat, depth)

package com.example.android.quakereport;

import android.os.Bundle;
import android.support.v7.app.AppCompactActivity;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.util.ArrayList;

public class EarthquakeActivity extends AppCompactActivity {

	public static final String LOG_TAG = EarthquakeActivity.class.getName();

	@Override
	protected void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.earthquake_activity);

		ArrayList<String> earthquakes = new ArrayList<>();
		earthquakes.add("San Fransisco");
		earthquakes.add("London");
		earthquakes.add("Tokyo");
		earthquakes.add("Mexico City");
		earthquakes.add("Moscow");
		earthquakes.add("Rio de Janeiro");
		earthquakes.add("Paris");

		ListView earthquakeListView = (ListView) findViewById(R.id.list);

		ArrayAdapter<String> adapter = new ArrayAdapter<String>(
			this, android.R.layout.simple_list_item_1, earthquakes);

		earthquakeListView.setAdapter(adapter);

		
	}
}

USGS spreadsheet format

https://earthquake.usgs.gov/earthquakes/feed/v1.0/csv.php

real-time data provided by USGS in spreadsheet format, most useful data in app.
date, latitude, longitude, depth, magnitude, place, type

For Developers API documentation
https://earthquake.usgs.gov/fdsnws/event/1/

Get geojson data from query and parameter
https://earthquake.usgs.gov/fdsnws/event/1/query?starttime=2017-04-29&endtime=2017-04-30&format=geojson

json pretty print
http://jsonprettyprint.com/

-time is unix timestamp

more than 4.5 magnitude
https://earthquake.usgs.gov/fdsnws/event/1/query?starttime=2017-04-29&endtime=2017-04-30&format=geojson&minmagnitude=4.5

Earthquake data api

Where are some possible places to find earthquake data?
-USGA is geological survey
https://earthquake.usgs.gov/fdsnws/event/1/
http://www.seismi.org/api/
https://earthquake.usgs.gov/
https://www.programmableweb.com/category/earthquakes/api
http://www.j-shis.bosai.go.jp/api-list

MediaPlayer resources

/**
 * Clean up the media player by releasing its resources.
 */

private void releaseMediaPlayer(){
	if (mMediaPlayer != null){
		mMediaPlayer.release();

		mMediaPlayer = null;
	}  
}

Activity Lifecycle
-create, started, resumed, (User is interacting with app) paused, stopped, destroyed

http://androidniceties.tumblr.com/

States of Media Player

Idle -> Prepared -> Started -> Pause -> Stopped

object data type, variable name = object data type. factory method name(input arguments);

static method
MediaPlayer.create(context, R.raw.song);

Non-static (regular) Method
myMediaPlayer.start();

listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position, long id){
		mMediaPlayer = MediaPlayer.create(NumbersActivity.this, R.raw.number_one);
		mMediaPlayer.start();
	}
});
@Override
	public String toString(){
		return "Word{" +
		"mDefaultTranslation='" + mDefaultTranslation + '\'' +
		", mMiwokTranslation='" + mMiwokTranslation + '\'' +
		", mAudioResourceId=" + mAudioResourceId +
		", mImageResourceId=" + mImageResourceId +
		'}'; 
	}

Word word = words.get(position);
Log.v("NumbersActivity", "Current word: " + word);
mMediaPlayer = MediaPlayer.create(PhrasesActivity.this, word.getAudioResourceId());
mMediaPlayer.start();
	}
});

Music Player App

activity_main.xml

<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout
	xmlns:android="http://schemas.android.com/apk/res/android"
	xmlns:tools="http://chemas.android.com/tools"
	android:layout_width="match_parent"
	android:layout_height="match_parent"
	android:background="@color/tan_background"
	android:orientation="vertical"
	tools:context="com.example.android.miwok.MainActivity">

	<Button
		android:id="@+id/play_button"
		android:text="Play"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content" />

	<Button
		android:id="@+id/pause_button"
		android:text="Pause"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content" />

</LinearLayout>

MainActivity.java

package com.example.android.musicplayer;

import

public class MainActivity extends AppCompactActivity {

	private MediaPlayer mediaPlayer;


	@Override
	protected void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		mediaPlayer = MediaPlayer.create(this, R.raw.android_trailer);

		Button playButton = (Button)findViewById(R.id.play_button);

		playButton.setOnClickListener(new View.OnClickListener(){
			@Override
			public void onClick(View v){
				mediaPlayer.start();
			}
		});

		Button pauseButton = (Button)findViewById(R.id.play_button);

		playButton.setOnClickListener(new View.OnClickListener(){
			@Override
			public void onClick(View v){
				mediaPlayer.pause();
			}
		});
	}
}

Plan to build the audio feature

android media player
https://developer.android.com/guide/topics/media/mediaplayer.html

Which step to accomplish
– modify list item layout to include a play button
– handle clicking on a list item to play an audio file
– add in all audio files
– modify word class to store audio resource ID
– play correct audio file per word
– visual plish

use media player api in sample app

Providing Constructors

public Bicycle(int startGadence, int startSpeed, int startGear){
	gear = startGear;
	cadence = startCadence;
	speed = startSpeed;
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	xmlns:tools="http://schemas.android.com/tools"
	android:layout_width="match_parent"
	android:layout_height="wrap_content"
	android:orientation="horizontal"
	android:padding="16dp">

	<ImageView
		android:id="@+id/image"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:src="@mipmap/ic_launcher" />

	<LinearLayout
		android:id="@+id/text_container"
		android:layout_width="match_parent"
		android:layout_height="match_parent"
		android:orientation="vertical"
		android:paddingLeft="16dp">

		<TextView
			android:id="@+id/miwok_text_view"
			android:layout_width="match_parent"
			android:layout_height="wrap_content"
			tools:text="lutti" />

		<TextView
			android:id="@+id/default_text_view"
			android:layout_width="match_parent"
			android:layout_height="wrap_content"
			tools:text="one" />
	</LinearLayout>
</LinearLayout>

Change view visibility
textView.setVisibility(View.VISIBLE);
textView.setVisibility(View.INVISIBLE);
textView.setVisibility(View.GONE);

Modify Word Class

package com.example.android.miwok;

public class Word {
	private String mDefaultTranslation;
	private String mMiworkTranslation;
	private int mImageResourceId;

	public String getDefaultTranslation(){
		return mDefaultTranslation;
	}

	public String getMiwokTranslation() { return mMiwokTranslation; }

	public int getImageResourceId(){
		return mImageResourceId;
	}
}