This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.android.sunshine.app.data; | |
//imports... | |
/** Manages a local database for weather data. */ | |
public class WeatherDbHelper extends SQLiteOpenHelper { | |
// If you change the database schema, you must increment the database version. | |
private static final int DATABASE_VERSION = 2; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.android.sunshine.app.data; | |
import android.content.ContentValues; | |
import android.database.Cursor; | |
import android.database.sqlite.SQLiteDatabase; | |
import android.test.AndroidTestCase; | |
import java.util.HashSet; | |
public class TestDb extends AndroidTestCase { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class WeatherProvider extends ContentProvider { | |
... | |
static final int WEATHER = 100; | |
static final int WEATHER_WITH_LOCATION = 101; | |
static final int WEATHER_WITH_LOCATION_AND_DATE = 102; | |
static final int LOCATION = 300; | |
... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class WeatherProvider extends ContentProvider { | |
// The URI Matcher used by this content provider. | |
private static final UriMatcher sUriMatcher = buildUriMatcher(); | |
static UriMatcher buildUriMatcher() { | |
final UriMatcher uriMatcher = new UriMatcher(UriMatcher.NO_MATCH); | |
final String authority = WeatherContract.CONTENT_AUTHORITY; | |
uriMatcher.addURI(authority, WeatherContract.PATH_WEATHER, WEATHER); | |
uriMatcher.addURI(authority, WeatherContract.PATH_WEATHER + "/*", WEATHER_WITH_LOCATION); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class WeatherProvider extends ContentProvider { | |
@Override | |
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { | |
// Here's the switch statement that, given a URI, will determine what kind of request it is, and query the database accordingly. | |
Cursor retCursor; | |
switch (sUriMatcher.match(uri)) { | |
// "weather/*/*" | |
case WEATHER_WITH_LOCATION_AND_DATE: { | |
retCursor = getWeatherByLocationSettingAndDate(uri, projection, sortOrder); | |
break; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.android.sunshine.app; | |
import android.support.v4.app.Fragment; | |
import android.support.v4.app.LoaderManager; | |
import android.support.v4.content.CursorLoader; | |
import android.support.v4.content.Loader; | |
public class ForecastFragment extends Fragment implements LoaderManager.LoaderCallbacks<Cursor> { | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ForecastCursorAdapter extends CursorAdapter { | |
public ForecastCursorAdapter(Context context, Cursor cursor, int flags) { | |
super(context, cursor, flags); | |
} | |
/** Remember that these views are reused as needed. */ | |
@Override | |
public View newView(Context context, Cursor cursor, ViewGroup parent) { | |
return LayoutInflater.from(context).inflate(R.layout.list_item_forecast, parent, false); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android.sunshine.app"> | |
<application> | |
<activity>...</activity> | |
<provider | |
android:name=".data.WeatherProvider" | |
android:authorities="com.example.android.sunshine.app" | |
android:enabled="true" | |
android:exported="true" | |
android:permission="com.myapp.OhhhhDiosito"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright (C) 2016 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Now that we can declare tasks, it's time to think about the relationships | |
between tasks. For example, in a Java build, we can't JAR up our library | |
before compiling our sources. We model these relationships by task | |
dependencies and ordering. | |
We'll discuss three ways to configure the relationships between tasks: | |
`dependsOn`, `finalizedBy`, and `mustRunAfter`. |