Giter Site home page Giter Site logo

werockstar / android-cookbook-examples Goto Github PK

View Code? Open in Web Editor NEW

This project forked from iandarwin/android-cookbook-examples

0.0 2.0 0.0 34.19 MB

Collected code examples from the O'Reilly Android Cookbook. See README below!

Home Page: http://androidcookbook.com/

License: Other

Java 67.78% HTML 21.89% JavaScript 8.20% CSS 1.50% Makefile 0.05% C 0.05% PHP 0.41% Shell 0.12%

android-cookbook-examples's Introduction

Android Cookbook Examples

This repo contains over a hundred source code examples from the recipes published in the O’Reilly Android Cookbook, a great source of tutorial material for the Android Developer. Not all recipes in the book or online have code accompanying them; this repo features code that was either linked by the contributor, or in several cases, re-constructed as a New Project by the editor for your convenience.

Further note that not all programs used in the book/online appear here; some of the examples in the book/online are only program fragments taken from other programs that can’t be included. And of course some code is drawn from existing projects that are hosted elsewhere.

Each Directory comprises its own project, and has a name that is cited at the end of the corresponding Recipe, under the "Source Code Download" section.

NOTE As of today, there are two styles of projects:

  1. Eclipse projects with the newer Eclipse Andmore;

  2. Android Studio projects (most complete with their extraneous "app" subdirectory).

If you have used the old Google ADT, you will need to update your Eclipse config by removing ADT, then replace it with AndMore from the Eclipse Marketplace Client.

Most of the Eclipse projects have been Mavenized; a few have not.

Most of the Gradle projects will also build with Android Studio; a few will not.

The table List of Projects shows which projects are set up for which build tools.

TL;DR: Build Most Projects with Apache Maven

Prerequisites: Java 7 SDK and Android SDK including "Google Maven Repository" for compat stuff, git, Maven

  1. git clone https://github.com/mosabua/maven-android-sdk-deployer

  2. cd maven-android-sdk-deployer

  3. mvn install -P 6.0 # at least

  4. mvn install -P 7.0 # after it’s released!

  5. cd ..

  6. git clone https://github.com/IanDarwin/Android-Cookbook-Examples

  7. cd Android-Cookbook-Examples

  8. mvn -fae package android:install android:run Include android:install and android:run only if you actually want to run them all, and have a device or emulator with some good free space; else just do 'package')

  9. Fix up any that didn’t work, and send pull requests!

Maven Build: More Details

Most of these projects were initially developed using Eclipse ADT, and migrated to Maven for automatic building. Obviously the Googlezilla has spoken and we will eventually have to migrate kicking and screaming to Android Studio and Gradle; pull requests for this would also be welcomed, as long as they don’t break support for Eclipse and Maven.

If you open the entire repo in Eclipse with eGit, be sure to check the Import all projects checkbox. If you want to keep these mini-projects separate from your "regular" work, you may want to use the Git repo as an Eclipse workspace (use File→Switch Workspace→Other→Browse). This directory is already set up to be an Eclipse workspace if you want it to (the .metadata directory exists and is already in .gitignore).

Note: As part of the move to Gradle, Google stopped pushing Android releases to Maven Central; their last version was 4.1.1.4, thus Lollipop, Marshmallow, and "N" have been left high-and-dry. And worse, their SDK license prohibits re-distribution of binaries, so nobody else can step in and upload these files to Maven Central. But of course there is a solution. To compile these projects with Maven you will need to download the amazing maven-android-sdk-deployer, which repackages files from the SDK - after you download it using the Android tools, thus nobody is redistributing it - into your local .m2/repository so that Maven can find it. This is the function of the first few steps in the numbered list above.

Note that projects using official releases use e.g. com.google.android:android:4.1.1.4 whereas projects deployed using the sdk-deployer use e.g android:android:6.0_r3.

You can download AndroidCookbookExamples as a Zip file from GitHub, but then you won’t get updates, and it will be hard to collaborate with the other contributors. If you’re not familiar with Git and Github, see the getting started page on GitHub and read up on how to collaborate. You can either send diff/patch files or send a pull request. Remember that GitHub is a free service for public projects!

Many of the projects may (depending on your version of Eclipse) give you some noise when you first open them due to bin and/or gen being missing. The Eclipse plug-in will usually create them but not notify that it’s done so, meaning you just have to do Refresh (F5), failing that, close and re-open the project. Does not happen with current Eclipse, last I tried.

There is neither a Wiki or a Tracker for this project, since bugs and suggestions about the code should be made on the Android Cookbook web site (http://androidcookbook.com/). Bugs or suggesions on the published edition of the book should go to http://shop.oreilly.com/product/0636920038092.do; you can also purchase the book there (which helps fund my continued work on this code base).

You can’t build the whole mess with Gradle

You can’t have this pretty thing. Because Gradle. Because Android Studio. Because fail.

Patches welcome if they don’t break any existing builds (Maven, Eclipse) AND if you can still open each individual project without Studio going ape-** and opening every other existing project as a "module" of the one you’re trying to build. Watch for my forthcoming paper "Gradle and Android Studio Considered Harmful."

Notes for the First Edition of the book

The current version of this repo has been reorganized in preparation for the second edition of the book. There have been quite a few projects added since the first published edition of the book, and a few renamed, so if you have the printed edition from 2012 you should rummage around here before re-typing anything that looks like a full example.

If you want this repo to correspond to the last minor revision of the first edition, use git to checkout the tag Book-1.0.

DELETED PROJECTS

JpsTrack and the ToDo applications have graduated to their own github projects, up one level from here on Github.

Wishlist

There are some things I’d love it if people would contribute:

  • Gradle files for each project that doesn’t already have one (they almost all have Maven files now.

  • Readme file for each project, to include a link back to the recipe in the online version of the book.

List of Projects

The following list is generated (periodically) from the project folders. In the Builds With column, E for Eclipse, M for Maven, S for Android Studio, G for Gradle.

Table 1. List of projects with description and build tools
Project Builds With Function Notes

AboutBoxDemo

GS

A re-usable About dialog.

-

AboutInfo

EM

Info about device and screen

-

ActionBarCompat

GS

Simple ActionBar demo(s)

-

AdMobDemo

GS

Using AdMob with interstitial (inter-Activity) ads.

-

AndroidPlot

EM

Graphing

-

AndroidRss

EM

RSS Reader

-

AppDownloader

MGS

Installs another app

Downloading, package management

AutocompleteTextViewContacts

EM

Contact picker with autocomplete

-

AutoUpdater

EM

App can update itself

see AppDownloader

BackupManager

EM

Backups

-

BluetoothDemo

EM

Bluetooth Connection

-

CalAdder

EM

Add appointment to Calendar

Calendar via Content Provider

CallFaker

EM

Pretend a call happened, for testing

-

CardDemo

GS

Demonstation of Card widget.

-

CheckBoxRadioButton

EM

GUI demo

name says it

ContentProviderBookmarks

EM

List of bookmarks from Bookmarks Content Provider

Browser ContentProvider

ContentProviderList

EM

List of ContentProviders

-

ContentProviderSample

EM

Implement a ContentProvider

-

ContentProviderTest

EM

Test it

-

CountDownTimerExample

EM

Time-based activity

-

CurrentMoodWidget

M

Application Widget

-

CursorLoaderDemo

EM

How to load data properly using CursorLoader

-

CustomMenu

EM

Menu

-

CustomSubMenu

GS

Submenu, created programmatically

-

CustomToast

EM

Toast

-

DatabaseFromFile

EM

Create a database from an SQLite .db file in 'assets'.

-

DataToCursor

EM

Fake up a Cursor from a list of files

-

DialogDemos

EM

Dialogs

-

DragDropDemo

E

A simple Drag-and-drop example.

-

DreamsDemo

EM

Demo of "Dreams" (4.x screensaver)

-

EmailTextView

EM

Send contents of EditText via email

-

EmailWithAttachments

EM

Attach file to email

-

EpochJSCalendar

EM

Java + JavaScript

-

EventListenersDemo

M

5 Ways to Wire an Event Listener.

-

FacebookSdk

EM

Access FB API

-

FaceFinder

EM

Face locator API in photos

-

FileProviderDemo

GS

Demo of FileProvider.

-

FilesystemDemos

MGS

Internal and external files.

-

FloatingActionButtonSnackbarDemo

GS

Demo of 'fab' Floating Abstract Button

-

FontDemo

EM

Using a custom font

-

FragmentsDemos

GS

Simple Fragment and List-Detail Fragments in one project

-

Gallery

EM

Simple photo gallery

Deprecated

GcmClient

EM

Google Cloud Messaging - receiver

-

GcmMockServer

EM

Google Cloud Messaging - sender

-

HelloCommandLine

EM

HelloWorld

SDK

HelloEclipse

EM

HelloWorld

Eclipse ADT

HelloEspressoTesting

GS

HelloWorld of EspressoTesting

-

HelloGradle

GS

Hello World with Gradle but NOT Studio.

-

HelloMaven

EM

HelloWorld

Maven, JayWay Plug-in

HelloStudioTesting

GS

HelloWorld of StudioTesting

-

HelloTestingTarget

EM

ADT Testing - subject

-

HelloTestingTestProject

EM

ADT Testing - Tests

-

HomeAppListView

EM

A Home Application

Shows running a program

HotContacts

EM

Add a contact

Shows ContactsContract, content provider

IconizedListView

EM

List View with Icon

-

IntentsDemo

EM

Intents

-

IpcServiceDemo

GS

IPC - Inter-Process Communication, simplified demo.

-

JavascriptDataDemo

EM

JavaScript from Java

-

JavaTimeDemo

MGS

Demos of java.time date/time API

Actually JSR-310 API; almost same but different package

LayoutBorder

G

Layout Border Demo Project Source for Android

-

ListViewAdvanced

EM

ListView

-

ListViewDemos

EM

ListView

-

ListViewEmpty

EM

ListView with empty list: don’t show blank screen!

-

ListViewSectionHeader

EM

ListView with section headers

-

LocalBroadcastDemo

EM

Local Broadcast Receiver

-

MapDemosV2

EM

Google Maps V2 API

-

MarketSearch

EM

Search the Play Store

-

MaterialDemos

EM

MaterialDesign demos

-

MediaPlayerDemo

EM

Play media

-

MediaPlayerInteractive

E

Media Player demo from Marco Dinacci, thanks.

-

MediaRecorderDemo

EM

Simple sound recorder

-

NdkDemo

EM

Native Development Kit

C Code

NotificationDemo

EM

Notifications

-

NumberPickers

EM

UI for picking numbers

-

OAuth2Demo

GS

Demo of OAuth2 to Google Tasks.

-

OpenGlDemo

EM

OpenGL graphics

-

OrientationChanges

EM

Rotation

-

OSMIntro

EM

OpenStreetMap API

(free alternative to Google Maps)

PdfShare

EM

Create and share a PDF

-

PermissionRequest

G

Shows asking for permissions at runtime, i.e,. "the new way"

-

PhoneGapDemo

EM

HTML5 app using phonegap/cordova

-

PinchAndZoom

GS

Pinch-and-zoom graphics demo

-

PreferencesDemo

EM

Preferences

-

RangeGraphDemo

EM

Using a graphing library

-

Rebooter

EM

How to reboot, and why you can’t

-

RecyclerViewDemo

GS

Demo of RecyclerView, the faster ListView.

-

RGraphDemo

EM

Using a graphing library

-

RuntimeLog

EM

A simpe runtime log facility

-

ScanBarcode

GS

Scan barcode using ZXing app via Intent

-

SecondScreen

M

Trivial example of one Activity (screen) starting another.

-

SendSMS

EM

Sends an SMS

-

ShareActionProviderDemo

EM

ICS "Share" action

-

SimpleAccountAndSyncDemo

EM

User account on device

-

SimpleCalendar

EM

Calendar

-

SimpleJumper

M

Flixel-based gaming demo

This example still needs to be re-created.

SimplePool

EM

Graphics

-

SimpleTorchLight

EM

Flashlight/torch from camera flash

-

SlidingDrawer-Topdown

EM

The "Sliding Drawer" view

-

SnackBarDemo

EM

Snackbar (bottom message text) demo

-

SoapDemo

EM

XML SOAP Web Service

-

SoundRec

EM

Sound Recorder

-

Speaker

EM

Text To Speech (TTS)

-

SpinnerDemo

EM

Drop-down Spinner Demos

-

SpinningCubeDemo

E

OpenGL Spinning Cube, from Marco Dinacci

-

SplashDialog

EM

Splash screen

-

SQLiteDemos

EM

SQLite demos

-

StandardDrawables

EM

Use Existing Drawables

-

StaticFileRead

EM

StaticFileRead - read a file from the application

-

StringsXML

G

Demos for "Nuances of Strings.xml" recipe.

-

TabSwipeDemo

EM

Tabbable and swipeable layout

-

TeleCorder

EM

Telephone call recorder (in progress!)

-

TelephonyManager

EM

Displays phone info

-

Tipster

EM

Full app: compute and show restaurant bill with tip

-

UniqueId

EM

Find device’s unique ID

-

Vibrate

EM

Make the device vibrate

-

ViewPagerDemo

EM

Swipe among views

-

VolleyDemo

EM

Demo of Volley networking library

-

WheelPickerDemo

GS

Apple-style Wheel Picker Demo

-

WindowBackgroundDemo

EM

Graphical window background

-

android-cookbook-examples's People

Contributors

amarekano avatar iandarwin avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.