Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

4.02 start code for lesson 4 #311

Open
wants to merge 34 commits into
base: 1.01_hello_world
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
e9f367e
1.02 Add list item forecast layout
Dec 16, 2014
fab554b
1.03 Update fragment layout
Dec 16, 2014
de032c1
1.04 Add dummy data
Dec 16, 2014
0281f77
1.05 Create ArrayAdapter to eventually use to populate the ListView
Dec 16, 2014
1d42493
1.06 Hook the adapter up to the ListView
Dec 17, 2014
ea6e195
2.01 Add the network call code
Dec 17, 2014
370d9bf
2.02 rename Placeholder -> Forecast
Dec 17, 2014
27e83bd
2.02 refactor ForecastFragment into to separate file
Dec 17, 2014
1e4314f
2.02 Refactor logging string into constant
sdspikes Jun 2, 2014
fa5e923
2.03 Add xml for refresh menu item
sdspikes May 28, 2014
f7f49a8
2.04 Inflate menu
sdspikes May 30, 2014
f18784f
2.05 Execute FetchWeatherTask
sdspikes May 28, 2014
d1579a4
2.06 Add Internet permission
sdspikes May 30, 2014
30afc9f
2.07 Build URL with params
sdspikes May 29, 2014
c281fef
2.08 Add in JSON parsing code
sdspikes May 29, 2014
c8542c3
2.09 Update the adapter so that the data is displayed
sdspikes May 29, 2014
2141b9c
3.00 remove verbose logging statements
sdspikes Jun 5, 2014
bd57648
3.01 Add toast on item click
sdspikes May 30, 2014
e8e638d
3.02 Create new DetailActivity
Dec 17, 2014
4a61c5a
3.03 Launch DetailActivity by initiating an explicit intent
Dec 18, 2014
0d060ff
3.04 Get the forecast from the intent and use it to populate the deta…
Dec 18, 2014
296319f
3.05 Add SettingsActivity and associated entry in the manifest
sdspikes May 31, 2014
fd12441
3.06 Launch the settings activity when the settings menu item is sele…
sdspikes May 31, 2014
d5eebe9
3.07 Add location setting xml
sdspikes May 31, 2014
5204747
3.08 Inflate view in SettingsActivity
sdspikes May 31, 2014
a01a072
3.09 Get location from shared prefs
sdspikes May 31, 2014
29db009
3.10 Refactor fetching weather data so we don't have to stare at the …
Dec 16, 2014
cdd3f2c
3.11 Add fully functional units setting
sdspikes Jun 5, 2014
745a01e
3.12 Add map intent from new menu item
Dec 17, 2014
f63ba9f
3.13 Add ShareActionProvider to detail fragment menu
Dec 18, 2014
35bbc96
4.01 Lifecycle Events quiz adding log statements
Dec 18, 2014
413fbdf
Revert "4.1 Lifecycle Events quiz -- add log statements to MainActivi…
Feb 10, 2015
eacae0c
4.02 Complete starting code for Lesson 4. Includes lots of important …
DAGalpin Jan 10, 2015
9baae67
Add API Key Parameter to OpenWeatherMap API Call
cdlei Oct 13, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildTypes.each {
it.buildConfigField 'String', 'OPEN_WEATHER_MAP_API_KEY', MyOpenWeatherMapApiKey
}
}

dependencies {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.android.sunshine.app;

import android.test.suitebuilder.TestSuiteBuilder;

import junit.framework.Test;
import junit.framework.TestSuite;

public class FullTestSuite extends TestSuite {
public static Test suite() {
return new TestSuiteBuilder(FullTestSuite.class)
.includeAllPackagesUnderHere().build();
}

public FullTestSuite() {
super();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.android.sunshine.app.data;

import android.test.AndroidTestCase;

public class TestDb extends AndroidTestCase {

public static final String LOG_TAG = TestDb.class.getSimpleName();

// Since we want each test to start with a clean slate
void deleteTheDatabase() {
mContext.deleteDatabase(WeatherDbHelper.DATABASE_NAME);
}

/*
This function gets called before each test is executed to delete the database. This makes
sure that we always have a clean test.
*/
public void setUp() {
deleteTheDatabase();
}

/*
Students: Uncomment this test once you've written the code to create the Location
table. Note that you will have to have chosen the same column names that I did in
my solution for this test to compile, so if you haven't yet done that, this is
a good time to change your column names to match mine.

Note that this only tests that the Location table has the correct columns, since we
give you the code for the weather table. This test does not look at the
*/
// public void testCreateDb() throws Throwable {
// // build a HashSet of all of the table names we wish to look for
// // Note that there will be another table in the DB that stores the
// // Android metadata (db version information)
// final HashSet<String> tableNameHashSet = new HashSet<String>();
// tableNameHashSet.add(WeatherContract.LocationEntry.TABLE_NAME);
// tableNameHashSet.add(WeatherContract.WeatherEntry.TABLE_NAME);
//
// mContext.deleteDatabase(WeatherDbHelper.DATABASE_NAME);
// SQLiteDatabase db = new WeatherDbHelper(
// this.mContext).getWritableDatabase();
// assertEquals(true, db.isOpen());
//
// // have we created the tables we want?
// Cursor c = db.rawQuery("SELECT name FROM sqlite_master WHERE type='table'", null);
//
// assertTrue("Error: This means that the database has not been created correctly",
// c.moveToFirst());
//
// // verify that the tables have been created
// do {
// tableNameHashSet.remove(c.getString(0));
// } while( c.moveToNext() );
//
// // if this fails, it means that your database doesn't contain both the location entry
// // and weather entry tables
// assertTrue("Error: Your database was created without both the location entry and weather entry tables",
// tableNameHashSet.isEmpty());
//
// // now, do our tables contain the correct columns?
// c = db.rawQuery("PRAGMA table_info(" + WeatherContract.LocationEntry.TABLE_NAME + ")",
// null);
//
// assertTrue("Error: This means that we were unable to query the database for table information.",
// c.moveToFirst());
//
// // Build a HashSet of all of the column names we want to look for
// final HashSet<String> locationColumnHashSet = new HashSet<String>();
// locationColumnHashSet.add(WeatherContract.LocationEntry._ID);
// locationColumnHashSet.add(WeatherContract.LocationEntry.COLUMN_CITY_NAME);
// locationColumnHashSet.add(WeatherContract.LocationEntry.COLUMN_COORD_LAT);
// locationColumnHashSet.add(WeatherContract.LocationEntry.COLUMN_COORD_LONG);
// locationColumnHashSet.add(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING);
//
// int columnNameIndex = c.getColumnIndex("name");
// do {
// String columnName = c.getString(columnNameIndex);
// locationColumnHashSet.remove(columnName);
// } while(c.moveToNext());
//
// // if this fails, it means that your database doesn't contain all of the required location
// // entry columns
// assertTrue("Error: The database doesn't contain all of the required location entry columns",
// locationColumnHashSet.isEmpty());
// db.close();
// }

/*
Students: Here is where you will build code to test that we can insert and query the
location database. We've done a lot of work for you. You'll want to look in TestUtilities
where you can uncomment out the "createNorthPoleLocationValues" function. You can
also make use of the ValidateCurrentRecord function from within TestUtilities.
*/
public void testLocationTable() {
// First step: Get reference to writable database

// Create ContentValues of what you want to insert
// (you can use the createNorthPoleLocationValues if you wish)

// Insert ContentValues into database and get a row ID back

// Query the database and receive a Cursor back

// Move the cursor to a valid database row

// Validate data in resulting Cursor with the original ContentValues
// (you can use the validateCurrentRecord function in TestUtilities to validate the
// query if you like)

// Finally, close the cursor and database

}

/*
Students: Here is where you will build code to test that we can insert and query the
database. We've done a lot of work for you. You'll want to look in TestUtilities
where you can use the "createWeatherValues" function. You can
also make use of the validateCurrentRecord function from within TestUtilities.
*/
public void testWeatherTable() {
// First insert the location, and then use the locationRowId to insert
// the weather. Make sure to cover as many failure cases as you can.

// Instead of rewriting all of the code we've already written in testLocationTable
// we can move this code to insertLocation and then call insertLocation from both
// tests. Why move it? We need the code to return the ID of the inserted location
// and our testLocationTable can only return void because it's a test.

// First step: Get reference to writable database

// Create ContentValues of what you want to insert
// (you can use the createWeatherValues TestUtilities function if you wish)

// Insert ContentValues into database and get a row ID back

// Query the database and receive a Cursor back

// Move the cursor to a valid database row

// Validate data in resulting Cursor with the original ContentValues
// (you can use the validateCurrentRecord function in TestUtilities to validate the
// query if you like)

// Finally, close the cursor and database
}


/*
Students: This is a helper method for the testWeatherTable quiz. You can move your
code from testLocationTable to here so that you can call this code from both
testWeatherTable and testLocationTable.
*/
public long insertLocation() {
return -1L;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.example.android.sunshine.app.data;

import android.test.AndroidTestCase;

public class TestPractice extends AndroidTestCase {
/*
This gets run before every test.
*/
@Override
protected void setUp() throws Exception {
super.setUp();
}

public void testThatDemonstratesAssertions() throws Throwable {
int a = 5;
int b = 3;
int c = 5;
int d = 10;

assertEquals("X should be equal", a, c);
assertTrue("Y should be true", d > a);
assertFalse("Z should be false", a == b);

if (b > d) {
fail("XX should never happen");
}
}

@Override
protected void tearDown() throws Exception {
super.tearDown();
}
}
Loading