package me.yoqi.deleteallcontacts;

import java.util.ArrayList;
import java.util.HashMap;

import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import me.yoqi.deleteallcontacts.utils.ContactManager;

public class MainActivity extends AppCompatActivity {
	Button btnDelUser;
	TextView tvContact;
	Context mContext;
	static String TAG = "me.yoqi.deleteallcontacts.MainActivity";
	ContactManager contactManager;

	private static class MyHandler extends Handler {

		public MyHandler(Context mContext) {

		}

		@Override
		public void handleMessage(Message msg) {
			super.handleMessage(msg);
			switch (msg.what) {
			case 0:
				// 更新UI
				break;
			}
			super.handleMessage(msg);
		}
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		mContext = this;
		contactManager = new ContactManager(mContext);
		initView();
		initData();
	}

	void initView() {
		btnDelUser = (Button) findViewById(R.id.btn_del_contact);
		tvContact = (TextView) findViewById(R.id.tv_contact);
		btnDelUser.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				HashMap<String, Object> contactNum = contactManager.delAllContacts();
				Toast.makeText(mContext, "已经删除  " + contactNum.size() + "    个联系人", Toast.LENGTH_SHORT).show();
				initData();
			}
		});
	}

	void initData() {
		MyHandler mHandler = new MyHandler(this);

		ArrayList<String> allContact = contactManager.getAllContact();
		tvContact.setText(allContact.toString());
	}
}
