This file contains 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
/** 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) }; |
This file contains 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
@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); |
This file contains 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 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"; |
This file contains 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) 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 |
This file contains 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
@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>(); |
This file contains 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
/** | |
* 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(); |
This file contains 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
/** 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). | |
*/ |
This file contains 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"?> | |
<!-- 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"> |
This file contains 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"?> | |
<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 --> |
This file contains 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
/** | |
* 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(); |
NewerOlder