Skip to content
This repository has been archived by the owner on Oct 5, 2019. It is now read-only.

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
google-automerger committed Sep 2, 2014
0 parents commit d045090
Show file tree
Hide file tree
Showing 43 changed files with 2,399 additions and 0 deletions.
35 changes: 35 additions & 0 deletions CONTRIB.md
@@ -0,0 +1,35 @@
# How to become a contributor and submit your own code

## Contributor License Agreements

We'd love to accept your sample apps and patches! Before we can take them, we
have to jump a couple of legal hurdles.

Please fill out either the individual or corporate Contributor License Agreement (CLA).

* If you are an individual writing original source code and you're sure you
own the intellectual property, then you'll need to sign an [individual CLA]
(https://developers.google.com/open-source/cla/individual).
* If you work for a company that wants to allow you to contribute your work,
then you'll need to sign a [corporate CLA]
(https://developers.google.com/open-source/cla/corporate).

Follow either of the two links above to access the appropriate CLA and
instructions for how to sign and return it. Once we receive it, we'll be able to
accept your pull requests.

## Contributing A Patch

1. Submit an issue describing your proposed change to the repo in question.
1. The repo owner will respond to your issue promptly.
1. If your proposed change is accepted, and you haven't already done so, sign a
Contributor License Agreement (see details above).
1. Fork the desired repo, develop and test your code changes.
1. Ensure that your code adheres to the existing style in the sample to which
you are contributing. Refer to the
[Android Code Style Guide]
(https://source.android.com/source/code-style.html) for the
recommended coding standards for this organization.
1. Ensure that your code has an appropriate set of unit tests which all pass.
1. Submit a pull request.

61 changes: 61 additions & 0 deletions CardReaderSample/build.gradle
@@ -0,0 +1,61 @@
buildscript {
repositories {
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
}
}

apply plugin: 'android'


dependencies {

// Add the support lib that is appropriate for SDK 19
compile "com.android.support:support-v13:20.+"


}

// The sample build uses multiple directories to
// keep boilerplate and common code separate from
// the main sample code.
List<String> dirs = [
'main', // main sample code; look here for the interesting stuff.
'common', // components that are reused by multiple samples
'template'] // boilerplate code that is generated by the sample template process

android {
compileSdkVersion 19

buildToolsVersion "20"

sourceSets {
main {
dirs.each { dir ->
java.srcDirs "src/${dir}/java"
res.srcDirs "src/${dir}/res"
}
}
androidTest.setRoot('tests')
androidTest.java.srcDirs = ['tests/src']

}
}















53 changes: 53 additions & 0 deletions CardReaderSample/src/main/AndroidManifest.xml
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2013 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
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.cardreader"
android:versionCode="1"
android:versionName="1.0">

<!-- NFC Reader Mode was added in API 19. -->
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.NFC" />
<uses-feature android:name="android.hardware.nfc" android:required="true" />

<application android:allowBackup="true"
android:label="@string/app_name"
android:icon="@drawable/ic_launcher"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity"
android:label="@string/app_name"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<!-- NFC-related intent filter. Allows application to handle messages from any
NFC-A devices discovered. Other Android devices are required to support NFC-A.
See: res/xml/nfc_tech_filter.xml -->
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED" />
</intent-filter>
<meta-data
android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="@xml/nfc_tech_filter" />
</activity>
</application>


</manifest>
@@ -0,0 +1,109 @@
/*
* Copyright (C) 2013 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
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.android.cardreader;

import android.app.Activity;
import android.nfc.NfcAdapter;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.android.common.logger.Log;

/**
* Generic UI for sample discovery.
*/
public class CardReaderFragment extends Fragment implements LoyaltyCardReader.AccountCallback {

public static final String TAG = "CardReaderFragment";
// Recommend NfcAdapter flags for reading from other Android devices. Indicates that this
// activity is interested in NFC-A devices (including other Android devices), and that the
// system should not check for the presence of NDEF-formatted data (e.g. Android Beam).
public static int READER_FLAGS =
NfcAdapter.FLAG_READER_NFC_A | NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK;
public LoyaltyCardReader mLoyaltyCardReader;
private TextView mAccountField;

/** Called when sample is created. Displays generic UI with welcome text. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.main_fragment, container, false);
if (v != null) {
mAccountField = (TextView) v.findViewById(R.id.card_account_field);
mAccountField.setText("Waiting...");

mLoyaltyCardReader = new LoyaltyCardReader(this);

// Disable Android Beam and register our card reader callback
enableReaderMode();
}

return v;
}

@Override
public void onPause() {
super.onPause();
disableReaderMode();
}

@Override
public void onResume() {
super.onResume();
enableReaderMode();
}

private void enableReaderMode() {
Log.i(TAG, "Enabling reader mode");
Activity activity = getActivity();
NfcAdapter nfc = NfcAdapter.getDefaultAdapter(activity);
if (nfc != null) {
nfc.enableReaderMode(activity, mLoyaltyCardReader, READER_FLAGS, null);
}
}

private void disableReaderMode() {
Log.i(TAG, "Disabling reader mode");
Activity activity = getActivity();
NfcAdapter nfc = NfcAdapter.getDefaultAdapter(activity);
if (nfc != null) {
nfc.disableReaderMode(activity);
}
}

@Override
public void onAccountReceived(final String account) {
// This callback is run on a background thread, but updates to UI elements must be performed
// on the UI thread.
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
mAccountField.setText(account);
}
});
}
}

0 comments on commit d045090

Please sign in to comment.