Jason 5 years ago
parent
commit
d5d797eb22

+ 82 - 0
AnimationImageView帧动画结束.java

@@ -0,0 +1,82 @@
+package com.example.animationtest.ui;
+
+import android.content.Context;
+import android.graphics.drawable.AnimationDrawable;
+import android.os.Handler;
+import android.util.AttributeSet;
+import android.widget.ImageView;
+
+/**
+ * 自定义ImageView
+ * @author 1234
+ * 可以播放动态图片
+ */
+public class AnimationImageView extends ImageView {
+
+	public AnimationImageView(Context context, AttributeSet attrs, int defStyle) {
+		super(context, attrs, defStyle);
+	}
+
+	public AnimationImageView(Context context, AttributeSet attrs) {
+		super(context, attrs);
+	}
+
+	public AnimationImageView(Context context) {
+		super(context);
+	}
+	
+	public interface OnFrameAnimationListener{
+		/**
+		 * 动画开始播放后调用
+		 */
+		void onStart();
+		/**
+		 * 动画结束播放后调用
+		 */
+		void onEnd();
+	}
+
+	/**
+	 * 不带动画监听的播放
+	 * @param resId
+	 */
+	public void loadAnimation(int resId){
+		setImageResource(resId);
+		AnimationDrawable anim = (AnimationDrawable)getDrawable();
+		anim.start();
+	}
+	
+	/**
+	 * 带动画监听的播放
+	 * @param resId
+	 * @param listener
+	 */
+	public void loadAnimation(int resId, final OnFrameAnimationListener listener) {
+		setImageResource(resId);
+		AnimationDrawable anim = (AnimationDrawable)getDrawable();
+		anim.start();
+		if(listener != null){
+			// 调用回调函数onStart
+			listener.onStart();
+		}
+		
+		// 计算动态图片所花费的事件
+		int durationTime = 0;
+        for (int i = 0; i < anim.getNumberOfFrames(); i++) {
+            durationTime += anim.getDuration(i);
+        }
+        
+        // 动画结束后
+        Handler handler = new Handler();
+        handler.postDelayed(new Runnable() {
+			
+			@Override
+			public void run() {
+				if(listener != null){
+					// 调用回调函数onEnd
+					listener.onEnd();
+				}
+			}
+		}, durationTime);
+	}
+}

+ 63 - 0
GifView.java

@@ -0,0 +1,63 @@
+package com.easymorse.dialog;
+
+
+
+import android.app.Activity;
+import android.app.Dialog;
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Movie;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+
+public class MainActivity extends Activity {
+	
+	private Movie mMovie;
+	private long mMovieStart;
+
+	/** Called when the activity is first created. */
+	@Override
+	public void onCreate(Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
+		// setContentView(R.layout.main);
+		setContentView(new CustomGifView(this));
+		// Dialog customDialog = new Dialog(this);
+		// customDialog.setTitle("test");
+		// customDialog.setContentView(new CustomGifView(this));
+		// customDialog.show();
+
+	}
+
+	class CustomGifView extends View {
+
+		public CustomGifView(Context context) {
+			super(context);
+			mMovie = Movie.decodeStream(getResources().openRawResource(
+					R.drawable.animation));
+
+		}
+		
+		public void onDraw(Canvas canvas) {
+
+			long now = android.os.SystemClock.uptimeMillis();
+			
+			if (mMovieStart == 0) { // first time
+				mMovieStart = now;
+			}
+			if (mMovie != null) {
+				
+				int dur = mMovie.duration();
+				if (dur == 0) {
+					dur = 1000;
+				}
+				int relTime = (int) ((now - mMovieStart) % dur);				
+				mMovie.setTime(relTime);
+				mMovie.draw(canvas, 0, 0);
+				invalidate();
+			}
+		}
+
+	}
+
+}

+ 9 - 0
MyNFCDemon/.classpath

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+	<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
+	<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="src" path="gen"/>
+	<classpathentry kind="output" path="bin/classes"/>
+</classpath>

+ 33 - 0
MyNFCDemon/.project

@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>MyNFCDemon</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>com.android.ide.eclipse.adt.ApkBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

+ 52 - 0
MyNFCDemon/AndroidManifest.xml

@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.example.mynfcdemon"
+    android:versionCode="1"
+    android:versionName="1.0" >
+
+    <uses-sdk
+        android:minSdkVersion="14"
+        android:targetSdkVersion="18" />
+    
+    <uses-permission android:name="android.permission.NFC" />
+    
+    <uses-feature android:name="android.hardware.nfc" android:required="true" />
+
+    <application
+        android:allowBackup="true"
+        android:icon="@drawable/ic_launcher"
+        android:label="@string/app_name"
+        android:theme="@style/AppTheme" >
+        <activity
+            android:name="com.example.mynfcdemon.MainActivity"
+            android:label="@string/app_name" >
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+            
+        </activity>
+        
+        
+        <activity android:name="com.example.mynfcdemon.TagView"
+            android:theme="@android:style/Theme.NoTitleBar">
+             <intent-filter>
+                <action android:name="android.nfc.action.TAG_DISCOVERED"/>
+                <category android:name="android.intent.category.DEFAULT"/>
+            </intent-filter>
+            <intent-filter>
+                 <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
+            </intent-filter> 
+             <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>
+<!-- 
+ -->

BIN
MyNFCDemon/ic_launcher-web.png


BIN
MyNFCDemon/libs/android-support-v4.jar


+ 20 - 0
MyNFCDemon/proguard-project.txt

@@ -0,0 +1,20 @@
+# To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+#   http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+#   public *;
+#}

+ 14 - 0
MyNFCDemon/project.properties

@@ -0,0 +1,14 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system edit
+# "ant.properties", and override values to adapt the script to your
+# project structure.
+#
+# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
+#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
+
+# Project target.
+target=android-19

BIN
MyNFCDemon/res/drawable-hdpi/ic_launcher.png


BIN
MyNFCDemon/res/drawable-mdpi/ic_launcher.png


BIN
MyNFCDemon/res/drawable-xhdpi/ic_launcher.png


BIN
MyNFCDemon/res/drawable-xxhdpi/ic_launcher.png


+ 32 - 0
MyNFCDemon/res/layout/activity_main.xml

@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical" >
+
+
+    <LinearLayout
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent"
+        android:layout_weight="1"
+        android:orientation="vertical"
+        android:gravity="center" >
+        
+        
+         <LinearLayout
+	        android:layout_width="fill_parent"
+	        android:layout_height="fill_parent"
+	        android:layout_weight="1"
+	        android:orientation="vertical"
+	        android:gravity="center" >
+
+	            <TextView
+	                android:layout_width="match_parent"
+	                android:layout_height="wrap_content"
+	                android:text="请将标签放入识别区域!"
+	                android:textSize="18dp" />
+	
+            </LinearLayout>
+    </LinearLayout>
+
+</LinearLayout>

+ 38 - 0
MyNFCDemon/res/layout/tag_vierwr.xml

@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical" >
+        <LinearLayout
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent"
+        android:layout_weight="1"
+        android:background="@color/white"
+        android:orientation="vertical"
+        android:gravity="center" >
+         <LinearLayout
+	        android:layout_width="fill_parent"
+	        android:layout_height="fill_parent"
+	        android:layout_weight="1"
+	        android:orientation="vertical"
+	        android:gravity="center" >
+	            <TextView
+	            android:id="@+id/tagidtext"
+	            android:layout_width="match_parent"
+	            android:layout_height="wrap_content"
+	            android:textColor="@color/black"
+	            android:gravity="left"
+	            android:text="" />
+	            <TextView
+	            android:id="@+id/tagdatatext"
+	            android:layout_width="match_parent"
+	            android:layout_height="wrap_content"
+	            android:textColor="@color/black"
+	            android:gravity="left"
+	            android:text="" />
+	        	
+            </LinearLayout>
+    </LinearLayout>
+    
+
+</LinearLayout>

+ 9 - 0
MyNFCDemon/res/menu/main.xml

@@ -0,0 +1,9 @@
+<menu xmlns:android="http://schemas.android.com/apk/res/android" >
+
+    <item
+        android:id="@+id/action_settings"
+        android:orderInCategory="100"
+        android:showAsAction="never"
+        android:title="@string/action_settings"/>
+
+</menu>

+ 8 - 0
MyNFCDemon/res/values-sw600dp/dimens.xml

@@ -0,0 +1,8 @@
+<resources>
+
+    <!--
+         Customize dimensions originally defined in res/values/dimens.xml (such as
+         screen margins) for sw600dp devices (e.g. 7" tablets) here.
+    -->
+
+</resources>

+ 9 - 0
MyNFCDemon/res/values-sw720dp-land/dimens.xml

@@ -0,0 +1,9 @@
+<resources>
+
+    <!--
+         Customize dimensions originally defined in res/values/dimens.xml (such as
+         screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here.
+    -->
+    <dimen name="activity_horizontal_margin">128dp</dimen>
+
+</resources>

+ 11 - 0
MyNFCDemon/res/values-v11/styles.xml

@@ -0,0 +1,11 @@
+<resources>
+
+    <!--
+        Base application theme for API 11+. This theme completely replaces
+        AppBaseTheme from res/values/styles.xml on API 11+ devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Holo.Light">
+        <!-- API 11 theme customizations can go here. -->
+    </style>
+
+</resources>

+ 12 - 0
MyNFCDemon/res/values-v14/styles.xml

@@ -0,0 +1,12 @@
+<resources>
+
+    <!--
+        Base application theme for API 14+. This theme completely replaces
+        AppBaseTheme from BOTH res/values/styles.xml and
+        res/values-v11/styles.xml on API 14+ devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
+        <!-- API 14 theme customizations can go here. -->
+    </style>
+
+</resources>

+ 14 - 0
MyNFCDemon/res/values/color.xml

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <color name="black">#000000</color>
+    <color name="white">#ffffff</color>
+    <color name="red">#ff0000</color>
+    <color name="green">#00ff00</color>
+    <color name="blue">#0000ff</color>
+    
+    <color name="home_page_color_bg">#ebd175</color>
+    <color name="title_bg_color">#75b1d0</color>
+    
+    <color name="text_color">#f5730b</color>
+    <color name="unhome_color_bg">#f8efe7</color>
+</resources>

+ 7 - 0
MyNFCDemon/res/values/dimens.xml

@@ -0,0 +1,7 @@
+<resources>
+
+    <!-- Default screen margins, per the Android Design guidelines. -->
+    <dimen name="activity_horizontal_margin">16dp</dimen>
+    <dimen name="activity_vertical_margin">16dp</dimen>
+
+</resources>

+ 20 - 0
MyNFCDemon/res/values/strings.xml

@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+    <string name="app_name">MyNFCDemon</string>
+    <string name="action_settings">Settings</string>
+    <string name="hello_world">Hello world!</string>
+    
+         <!-- HhpRfidTestActivity -->
+     <string name="rfid_test">RFID</string>
+     <string name="rfid_search">搜索rfid标签</string>
+     <string name="rfid_find">查找</string>
+     <string name="rfid_wdata">RFID写入数据:</string>
+     <string name="rfid_rdata">RFID读出数据:</string>
+     <string name="rfid_write">写入</string>
+     <string name="rfid_read">读取</string>
+     <string name="rfid_findnull">未找到rfid卡</string>
+     <string name="rfid_readerror">读取失败</string>
+     <string name="rfid_writeerror">写入失败</string>
+
+</resources>

+ 20 - 0
MyNFCDemon/res/values/styles.xml

@@ -0,0 +1,20 @@
+<resources>
+
+    <!--
+        Base application theme, dependent on API level. This theme is replaced
+        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Light">
+        <!--
+            Theme customizations available in newer API levels can go in
+            res/values-vXX/styles.xml, while customizations related to
+            backward-compatibility can go here.
+        -->
+    </style>
+
+    <!-- Application theme. -->
+    <style name="AppTheme" parent="AppBaseTheme">
+        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
+    </style>
+
+</resources>

+ 9 - 0
MyNFCDemon/res/xml/nfc_tech_filter.xml

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+    <tech-list>
+        <tech>android.nfc.tech.NfcV</tech>
+        <tech>android.nfc.tech.NdefFormatable</tech>
+        <tech>android.nfc.tech.Ndef</tech>
+    </tech-list>
+    
+</resources>

+ 22 - 0
MyNFCDemon/src/com/example/mynfcdemon/MainActivity.java

@@ -0,0 +1,22 @@
+package com.example.mynfcdemon;
+
+import android.app.Activity;
+import android.nfc.NfcAdapter;
+import android.os.Bundle;
+
+public class MainActivity extends Activity {
+
+	
+	//private NfcAdapter nfcAdapter;
+	@Override
+	protected void onCreate(Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
+		setContentView(R.layout.activity_main);
+		
+		//nfcAdapter = NfcAdapter.getDefaultAdapter(this); 
+		//运行APK  把标签靠近识别区即可。
+	}
+
+	
+
+}

+ 194 - 0
MyNFCDemon/src/com/example/mynfcdemon/NfcVUtil.java

@@ -0,0 +1,194 @@
+package com.example.mynfcdemon;
+
+import java.io.IOException;
+
+import android.nfc.tech.NfcV;
+
+public class NfcVUtil {
+private NfcV mNfcV;
+//UID数组行式
+private byte[] ID;
+private String UID;
+private String DSFID;
+private String AFI;
+//block的个数
+private int blockNumber;
+//一个block长度
+private int oneBlockSize;
+//信息
+private byte[] infoRmation;
+
+
+/*@function		:初始化
+@param 			 :mNfcV NfcV对象
+@return 		:返回内容byte[]
+@author:		:Demon [email protected]
+*/
+ 
+public NfcVUtil(NfcV mNfcV) throws IOException{
+	this.mNfcV = mNfcV;
+	ID = this.mNfcV.getTag().getId();
+	byte[] uid = new byte[ID.length];
+	int j = 0;
+	for(int i = ID.length - 1; i>=0; i-- ){
+		uid[j] = ID[i];
+		j++;
+	}
+	this.UID = printHexString(uid);
+	
+	getInfoRmation();
+	
+	System.out.println("UID:" + getUID()
+			+"AFI:" + getAFI()
+			+"DSFID:" + getDSFID()
+			+"BlockNumber:" + getBlockNumber()
+			+"BlockSize:" + getOneBlockSize());
+}
+
+public String getUID() {
+	return UID;
+}
+
+/*@function		:取得标签信息
+@return 		:返回内容byte[]
+@author:		:Demon [email protected]
+*/
+private byte[] getInfoRmation() throws IOException{
+	byte[] cmd = new byte[10];
+	cmd[0] = (byte) 0x22;  //flag
+	cmd[1] = (byte) 0x2B;  //command
+	System.arraycopy(ID, 0, cmd, 2, ID.length); // UID
+	infoRmation = mNfcV.transceive(cmd);
+	blockNumber = infoRmation[12];
+	oneBlockSize = infoRmation[13];
+	AFI = printHexString(new byte[]{infoRmation[11]});
+	DSFID = printHexString(new byte[]{infoRmation[10]});
+	return infoRmation;
+}
+
+
+public String getDSFID() {
+	return DSFID;
+}
+
+
+public String getAFI() {
+	return AFI;
+}
+public int getBlockNumber(){
+	return blockNumber + 1;
+}
+
+
+public int getOneBlockSize() {
+	return oneBlockSize + 1;
+}
+
+/*@function		:读取一个位置在position的block
+@param 		:position 要读取的block位置
+@return 		:返回内容字符串
+@author:		:Demon [email protected]
+*/
+public String readOneBlock(int position) throws IOException{
+	byte cmd[] = new byte[11];
+	cmd[0] = (byte) 0x22;
+	cmd[1] = (byte) 0x20;
+	System.arraycopy(ID, 0, cmd, 2, ID.length);  //UID
+	cmd[10] = (byte) position;
+	byte res[] = mNfcV.transceive(cmd);
+	
+	for(int i=0; i < res.length; i++){
+		
+		System.out.println("/" + res[i]);
+	}
+	String r = new String(res);
+	System.out.println("/" + r);
+	
+	if(res[0] == 0x00){
+		byte block[] = new byte[res.length - 1];
+		System.arraycopy(res, 1, block, 0, res.length - 1);
+		
+		//return printHexString(block);
+		
+		String blockstr = new String(block);
+		return blockstr;
+	}
+	return null;
+}
+
+/*@function		:读取从begin开始end个block
+  @instructions	:begin + count 不能超过blockNumber
+  @param 		:begin 	block开始位置
+  @param 		:count 	读取block数量
+  @return 		:返回内容字符串
+  @author:		:Demon [email protected]
+ */
+public String readBlocks(int begin, int count) throws IOException{
+	if((begin + count)>blockNumber){
+		count = blockNumber - begin;
+	}
+	StringBuffer data = new StringBuffer();
+	
+	for(int i = begin; i<=count + begin; i++){
+		data.append(readOneBlock(i));
+	}
+	return data.toString(); 
+
+}
+
+
+
+/*  将byte[]转换成16进制字符串
+  @param data 要转换成字符串的字节数组
+  @return 16进制字符串
+ */
+private String printHexString(byte[] data) {  
+	StringBuffer s = new StringBuffer();;
+	for (int i = 0; i < data.length; i++) { 
+	    String hex = Integer.toHexString(data[i] & 0xFF);
+	    
+	    if (hex.length() == 1) { 
+	    	hex = '0' + hex; 
+	    } 
+	    s.append(hex);
+	} 
+	return s.toString();
+}
+
+
+
+
+
+
+
+/*  将数据写入到block,
+  @param position 要写内容的block位置
+  @param data 要写的内容,必须长度为blockOneSize
+  @return false为写入失败,true为写入成功
+  @throws IOException */
+public boolean writeBlock(int position, byte[] data) throws IOException{
+	byte cmd[] = new byte[15];
+	cmd[0] = (byte) 0x22;
+	cmd[1] = (byte) 0x21;
+	System.arraycopy(ID, 0, cmd, 2, ID.length);//  UID
+	//block
+	cmd[10] = (byte) position;
+	//value
+	System.arraycopy(data, 0, cmd, 11, data.length);
+	byte[]rsp = mNfcV.transceive(cmd);
+	if(rsp[0] == 0x00){
+		return true;
+	}
+		
+	return false;
+}
+
+public boolean writeStrToTag(String str){
+	
+	
+	return false;
+	
+}
+
+
+}

+ 204 - 0
MyNFCDemon/src/com/example/mynfcdemon/TagView.java

@@ -0,0 +1,204 @@
+package com.example.mynfcdemon;
+
+import java.io.IOException;
+
+import android.app.Activity;
+import android.app.PendingIntent;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.IntentFilter.MalformedMimeTypeException;
+import android.nfc.NdefMessage;
+import android.nfc.NdefRecord;
+import android.nfc.NfcAdapter;
+import android.nfc.Tag;
+import android.nfc.tech.NfcV;
+import android.os.Bundle;
+import android.os.Parcelable;
+import android.widget.TextView;
+
+public class TagView extends Activity{
+	
+	// NFC parts
+	private static NfcAdapter mAdapter;
+	private static PendingIntent mPendingIntent;
+	private static IntentFilter[] mFilters;
+	private static String[][] mTechLists;
+	
+	private TextView texttagid;
+	private TextView texttagdata;
+
+		@Override
+		protected void onCreate(Bundle savedInstanceState) {
+			// TODO Auto-generated method stub
+			super.onCreate(savedInstanceState);
+			setContentView(R.layout.tag_vierwr);
+			texttagdata = (TextView) findViewById(R.id.tagdatatext);
+			texttagid = (TextView) findViewById(R.id.tagidtext);
+			
+			mAdapter = NfcAdapter.getDefaultAdapter(this);
+			// Create a generic PendingIntent that will be deliver to this activity.
+			// The NFC stack
+			// will fill in the intent with the details of the discovered tag before
+			// delivering to
+			// this activity.
+			mPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this,
+					getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
+			// Setup an intent filter for all MIME based dispatches
+			IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);
+
+			try {
+				ndef.addDataType("*/*");
+			} catch (MalformedMimeTypeException e) {
+				throw new RuntimeException("fail", e);
+			}
+			mFilters = new IntentFilter[] { ndef, };
+
+			// Setup a tech list for all NfcV tags
+			mTechLists = new String[][] { new String[] { NfcV.class.getName() } };
+
+			try {
+				rfid_scanresult(getIntent());
+			} catch (IOException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+		}
+		
+
+		void rfid_scanresult(Intent intent) throws IOException{
+			
+			String action = intent.getAction();
+			if(NfcAdapter.ACTION_NDEF_DISCOVERED == action
+				|| NfcAdapter.ACTION_TECH_DISCOVERED == action
+				|| NfcAdapter.ACTION_TAG_DISCOVERED == action){
+			//if(NfcAdapter.ACTION_TECH_DISCOVERED == action){
+				//byte[] tagid = intent.getByteArrayExtra(NfcAdapter.EXTRA_ID);
+				
+				Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
+				byte[] tagid = tag.getId();
+				//String strid = new String(tagid);
+				//System.out.println("TAGID:"+strid);
+				//System.out.println("TAGID:"+bytesToHexString(tagid));
+				//texttagid.setText("TagID=" + bytesToHexString(tagid));
+				
+				Tag tagFromIntent = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
+				NfcV nfcv = NfcV.get(tagFromIntent);
+				nfcv.connect();
+				NfcVUtil mNfcVutil = new NfcVUtil(nfcv);
+
+				texttagid.setText("UID:" + mNfcVutil.getUID()+'\n'
+						+"AFI:" + mNfcVutil.getAFI()+'\n'
+						+"DSFID:" + mNfcVutil.getDSFID()+'\n'
+						+"BlockNumber:" + mNfcVutil.getBlockNumber()+'\n'
+						+"BlockSize:" + mNfcVutil.getOneBlockSize());
+				//NfcVClassCard mifareClassCard=null;
+				texttagdata.setText("block0:"+mNfcVutil.readOneBlock(0)
+						+"block1:"+mNfcVutil.readOneBlock(1)+'\n'
+						+"block2:"+mNfcVutil.readOneBlock(2)
+						+"block3:"+mNfcVutil.readOneBlock(3)+'\n'
+						+"block4:"+mNfcVutil.readOneBlock(4)
+						+"block5:"+mNfcVutil.readOneBlock(5)+'\n'
+						+"block6:"+mNfcVutil.readOneBlock(6)
+						+"block7:"+mNfcVutil.readOneBlock(7)+'\n'
+						+"block8:"+mNfcVutil.readOneBlock(8)
+						+"block9:"+mNfcVutil.readOneBlock(9)+'\n'
+						+"block10:"+mNfcVutil.readOneBlock(10)
+						+"block11:"+mNfcVutil.readOneBlock(11)+'\n'
+						+"block12:"+mNfcVutil.readOneBlock(12)
+						+"block13:"+mNfcVutil.readOneBlock(13)+'\n'
+						+"block14:"+mNfcVutil.readOneBlock(14)
+						+"block15:"+mNfcVutil.readOneBlock(15)+'\n'
+						+"block16:"+mNfcVutil.readOneBlock(16)
+						+"block17:"+mNfcVutil.readOneBlock(17)+'\n'
+						+"block18:"+mNfcVutil.readOneBlock(18)
+						+"block19:"+mNfcVutil.readOneBlock(19)+'\n'
+						+"block20:"+mNfcVutil.readOneBlock(20)
+						+"block21:"+mNfcVutil.readOneBlock(21)+'\n'
+						+"block22:"+mNfcVutil.readOneBlock(22)
+						+"block23:"+mNfcVutil.readOneBlock(23)+'\n'
+						+"block24:"+mNfcVutil.readOneBlock(24)
+						+"block25:"+mNfcVutil.readOneBlock(25)+'\n'
+						+"block26:"+mNfcVutil.readOneBlock(26)
+						+"block27:"+mNfcVutil.readOneBlock(27)+'\n'
+						+"Read:"+ mNfcVutil.readBlocks(0, 28)
+						);
+				/*String str;
+				str = getNdefMessages(intent).toString();
+				
+				System.out.println("Ndef::"+str);*/
+				String s = "kaic";
+				mNfcVutil.writeBlock(0, s.getBytes());
+			
+			}
+		
+			
+		}
+		
+		NdefMessage[] getNdefMessages(Intent intent) {
+		    // Parse the intent
+		    NdefMessage[] msgs = null;
+		    String action = intent.getAction();
+		    if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(action)) {
+		        Parcelable[] rawMsgs =intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
+		        if (rawMsgs != null) {
+		            msgs = new NdefMessage[rawMsgs.length];
+		            for (int i = 0; i < rawMsgs.length; i++) {
+		                msgs[i] = (NdefMessage) rawMsgs[i];
+		            }
+		        }
+		        else {
+		        // Unknown tag type
+		            byte[] empty = new byte[] {};
+		            NdefRecord record = new NdefRecord(NdefRecord.TNF_UNKNOWN, empty, empty,empty);
+		            NdefMessage msg = new NdefMessage(new NdefRecord[] {record});
+		            msgs = new NdefMessage[] {msg};
+		        }
+		    }        
+		    else {
+		       // Log.e(TAG, "Unknown intent " + intent);
+		        finish();
+		    }
+		    return msgs;
+		}
+		
+		void write_NdefFormatableTag(){
+			/*NdefFormatable tag = NdefFormatable.get(t);
+			Locale locale = Locale.US;
+			final byte[] langBytes = locale.getLanguage().getBytes(Charsets.US_ASCII);
+			String text = "Tag, you're it!";
+			final byte[] textBytes = text.getBytes(Charsets.UTF_8);
+			final int utfBit = 0;
+			final char status = (char) (utfBit + langBytes.length);
+			final byte[] data = Bytes.concat(new byte[] {(byte) status}, langBytes, textBytes);
+			NdefRecord record = NdefRecord(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_TEXT, newbyte[0], data);
+			try {
+			    NdefRecord[] records = {text};
+			    NdefMessage message = new NdefMessage(records);
+			    tag.connect();
+			    tag.format(message);
+			}
+			catch (Exception e){
+			    //do error handling
+			}*/
+
+		}
+
+		
+		
+		public static String bytesToHexString(byte[] src){       
+			            StringBuilder stringBuilder = new StringBuilder();       
+			            if (src == null || src.length <= 0) {       
+			                return null;       
+			            }       
+			            for (int i = 0; i < src.length; i++) {       
+			                int v = src[i] & 0xFF;       
+			                String hv = Integer.toHexString(v);       
+			                if (hv.length() < 2) {       
+			                    stringBuilder.append(0);       
+			                }       
+			                stringBuilder.append(hv);       
+			            }       
+			            return stringBuilder.toString();       
+			        }
+
+}

+ 61 - 0
监听Home键点击.java

@@ -0,0 +1,61 @@
+package com.example.homedemo;
+
+import android.app.Service;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.SharedPreferences.Editor;
+import android.os.IBinder;
+import android.widget.Toast;
+
+public class HomeService extends Service{
+	private HomeReceiver homeReceiver;
+	private Intent newActivity;
+
+	@Override
+	public IBinder onBind(Intent intent) {
+		// TODO Auto-generated method stub
+		return null;
+	}
+	@Override
+	public void onCreate() {
+		super.onCreate();
+		homeReceiver = new HomeReceiver();
+		IntentFilter homeFilter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
+		registerReceiver(homeReceiver, homeFilter);
+	}
+	
+	/**
+	 * ²¶»ñhome¼ü
+	 * @author Administrator
+	 *
+	 */
+	public class HomeReceiver extends BroadcastReceiver{
+		final String SYSTEM_DIALOG_REASON_KEY = "reason";
+		final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
+
+		@Override
+		public void onReceive(Context context, Intent intent) {
+			String action = intent.getAction();
+			if (action.equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) {
+				String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY);
+				if (reason != null && reason.equals(SYSTEM_DIALOG_REASON_HOME_KEY)) {
+					Toast.makeText(getApplicationContext(), "²¶»ñµ½Home¼ü", 0).show();
+					return;
+				}
+			}
+		}
+
+	}
+	
+	
+	@Override
+	public void onDestroy() {
+		unregisterReceiver(homeReceiver);
+		homeReceiver = null;
+		super.onDestroy();
+	}
+	
+
+}

+ 31 - 0
算法/快速排序例子.txt

@@ -0,0 +1,31 @@
+public static void main(String[] args) {
+	int len = 8000000;
+	int[] a = new int[len];
+	for (int i = 0; i < a.length; i++) {
+		int t = (int) (Math.random() * 10000);
+		a[i] = t;
+	}
+}
+
+public static void sort(int left, int right, int[] arr) {
+	int l = left;
+	int r = right;
+	int pivot = arr[(left + right) / 2];
+	int temp = 0;
+	while (l < r) {
+		while (arr[l] < pivot) l++;
+		while (arr[r] > pivot) r--;
+		if (l >= r) bread;
+		temp = arr[l];
+		arr[l] = arr[r];
+		arr[r] = temp;
+		if (arr[l] == pivot) --r;
+		if (arr[r] == pivot) ++l;
+	}
+	if (l == r) {
+		l++;
+		r--;
+	}
+	if (left < r) sort(left, r, arr);
+	if (right > l) sort(l, right, arr);
+}