package com.example.ueventtest;

import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.widget.TextView;
import android.os.Handler;
import android.os.UEventObserver;
import android.os.Message;
import java.util.Timer;
import java.util.TimerTask;

public class MainActivity extends Activity {
	private TextView tv;
	private TextView tv2;
    private String ueventTest = "DEVPATH=/kset_p";
    private String ueventTest2 = "/devices/virtual/android_usb/android0";
    private String test;
    private String test2;
	private Handler myHandler;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		tv = (TextView)findViewById(R.id.test);
		tv2 = (TextView)findViewById(R.id.test2);

		mUEventObserver.startObserving(ueventTest);
		mUEventObserver.startObserving(ueventTest2);
		mUEventObserver.startObserving("DEVPATH=/devices/virtual/switch/h2w");

		tv.setText("sdcjbdjvkc");
		myHandler = new Handler(){
			public void handleMessage(Message msg) {
				tv.setText(test);
				tv2.setText(test2);
			}
		};
	}
	private final UEventObserver mUEventObserver = new UEventObserver() {
		@Override
			public void onUEvent(UEventObserver.UEvent event){
				Log.e("Seven", "yulinghan UEVENT: "+event.toString());
				test = "ACTION:" + event.get("ACTION");
				test2 = "SUBSYSTEM:" + event.get("SUBSYSTEM");
				myHandler.sendEmptyMessage(0x01);
			}
	};
}
