Skip to content

Instantly share code, notes, and snippets.

udacityandroid

Block or report user

Report or block udacityandroid

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Sample code for querying the pet shelter database
/** For this example, assume that
* public static final int GENDER_MALE = 1;
* public static final int GENDER_FEMALE = 2;
**/
String[] projection = { PetEntry.COLUMN_PET_BREED,
PetEntry.COLUMN_PET_WEIGHT };
String selection = PetEntry.COLUMN_PET_GENDER + “=?”;
String[] selectionArgs = new String[] { String.valueOf(PetEntry.GENDERFEMALE) };
@udacityandroid
udacityandroid / Excerpt from PetProvider.java
Last active Nov 13, 2019
Pets app - Replace delete() method in PetProvider
View Excerpt from PetProvider.java
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
// Get writeable database
SQLiteDatabase database = mDbHelper.getWritableDatabase();
final int match = sUriMatcher.match(uri);
switch (match) {
case PETS:
// Delete all rows that match the selection and selection args
return database.delete(PetEntry.TABLE_NAME, selection, selectionArgs);
@udacityandroid
udacityandroid / StoreContract.java
Created Jul 26, 2016
Example contract class for a table which contains data about the store's headphones stock
View StoreContract.java
public final class StoreContract {
public static abstract class HeadphoneEntry implements BaseColumns {
public static final String TABLE_NAME = "headphones";
public static final String COLUMN_NAME = "name";
public static final String COLUMN_PRICE = "price";
public static final String COLUMN_STYLE = "style";
public static final String COLUMN_IN_STOCK = "in_stock";
public static final String COLUMN_DESCRIPTION = "description";
@udacityandroid
udacityandroid / WeatherContract.java
Created Jul 26, 2016
Contract class for a weather application called Sunshine
View WeatherContract.java
/*
* 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
@udacityandroid
udacityandroid / onCreateView() method in NumbersFragment.java
Created May 14, 2016
After fixing 4 errors in NumbersFragment.java
View onCreateView() method in NumbersFragment.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.word_list);
// Create and setup the {@link AudioManager} to request audio focus
mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
// Create a list of words
final ArrayList<Word> words = new ArrayList<Word>();
@udacityandroid
udacityandroid / Code for releaseMediaPlayer from NumbersActivity.java
Created May 14, 2016
Copy over the releaseMediaPlayer() helper method from the NumbersActivity into the NumbersFragment.
View Code for releaseMediaPlayer from NumbersActivity.java
/**
* Clean up the media player by releasing its resources.
*/
private void releaseMediaPlayer() {
// If the media player is not null, then it may be currently playing a sound.
if (mMediaPlayer != null) {
// Regardless of the current state of the media player, release its resources
// because we no longer need it.
mMediaPlayer.release();
@udacityandroid
udacityandroid / Code to go into NumberFragment.java
Created May 14, 2016
Copy code from the NumbersActivity and paste it into the NumbersFragment
View Code to go into NumberFragment.java
/** Handles playback of all the sound files */
private MediaPlayer mMediaPlayer;
/** Handles audio focus when playing a sound file */
private AudioManager mAudioManager;
/**
* This listener gets triggered whenever the audio focus changes
* (i.e., we gain or lose audio focus because of another app or device).
*/
@udacityandroid
udacityandroid / list_item.xml
Created May 13, 2016
Miwok App: Miwok app: List Item Views with pressed states
View list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- Layout for a single list item -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="@dimen/list_item_height"
android:background="@color/tan_background"
android:orientation="horizontal">
@udacityandroid
udacityandroid / activity_main.xml
Created May 13, 2016
Miwok app: Category screen with pressed states
View activity_main.xml
<?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="match_parent"
android:background="@color/tan_background"
android:orientation="vertical"
tools:context="com.example.android.miwok.MainActivity">
<!-- Numbers category -->
@udacityandroid
udacityandroid / Helper Method - releaseMediaPlayer()
Last active Oct 27, 2019
Miwok app: Cleaning up MediaPlayer resources
View Helper Method - releaseMediaPlayer()
/**
* Clean up the media player by releasing its resources.
*/
private void releaseMediaPlayer() {
// If the media player is not null, then it may be currently playing a sound.
if (mMediaPlayer != null) {
// Regardless of the current state of the media player, release its resources
// because we no longer need it.
mMediaPlayer.release();
You can’t perform that action at this time.