Skip to content

Instantly share code, notes, and snippets.

View AntonioDiaz's full-sized avatar
🤓

Antonio Diaz Arroyo AntonioDiaz

🤓
View GitHub Profile
@AntonioDiaz
AntonioDiaz / WeatherDbHelper.java
Last active December 28, 2016 19:05
Manages a local database for weather data.
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;
@AntonioDiaz
AntonioDiaz / TestDb.java
Last active December 29, 2016 09:58
Testing db in android app.
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 {
@AntonioDiaz
AntonioDiaz / Uris.java
Last active December 29, 2016 11:33
Uris types
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;
...
}
@AntonioDiaz
AntonioDiaz / UriMatcher.java
Created December 29, 2016 11:36
UriMatcher
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);
@AntonioDiaz
AntonioDiaz / ContentProvider.java
Last active December 29, 2016 11:47
query ContentProvider Override.
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;
@AntonioDiaz
AntonioDiaz / CursorLoader.java
Last active December 19, 2020 19:31
CursorLoader example in a Fragment
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> {
@AntonioDiaz
AntonioDiaz / ForecastCursorAdapter.java
Last active January 4, 2017 07:10
CursorAdapter implementation example.
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);
@AntonioDiaz
AntonioDiaz / AndroidManifest_PROVIDER.xml
Last active January 5, 2017 07:36
Declare Content Provider and allow access from another app.
<?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">
@AntonioDiaz
AntonioDiaz / MainActivity.java
Last active December 30, 2021 10:46
AsyncTaskLoader Example
/*
* 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
@AntonioDiaz
AntonioDiaz / build.gradle
Created March 14, 2017 07:22
Grade task dependences
/*
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`.