package com.talk.demo.account;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.talk.demo.MainActivity;
import com.talk.demo.R;
import com.talk.demo.setting.LuckDayActivity;
import com.talk.demo.util.AccountUtils;

public class AppMainActivity extends Activity {
	
	private Button login_btn, signup_btn;
	// whether need to call Login Activity
	private boolean accountExist = false;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_app_main);
		login_btn = (Button)findViewById(R.id.login_btn);
		signup_btn = (Button)findViewById(R.id.signup_btn);
        Account existing = AccountUtils.getPasswordAccessibleAccount(this);
        if (existing != null && !TextUtils.isEmpty(existing.name)) {
            accountExist = true;
        }
		login_btn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
	            if (accountExist) {
			        Intent mIntent = new Intent();
			        mIntent.setClass(v.getContext(), LuckDayActivity.class);
			        startActivity(mIntent);
			    } else {
    		        Intent intent = new Intent();
    		        intent.setClass(v.getContext(), LoginActivity.class);
    		        startActivity(intent);
			    }
		        finish();
			}
		});
		
		signup_btn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO 
				// 4 test: jump to mainActivity
		        Intent intent = new Intent();
		        intent.setClass(v.getContext(), LuckDayActivity.class);
		        startActivity(intent);
		        finish();
			}
		});
	}
}

@@ -1070,151 +1070,8 @@
     
-%7D%0A%09%09login_btn.setOnClickListener(new OnClickListener() %7B%0A%09%09%09@Override%0A%09%09%09public void onClick(View v) %7B%0A%09            if (accountExist) %7B%0A%09%09%09    
     
@@ -1101,19 +1101,20 @@
 tent();%0A
-%09%09%09
+    
         
@@ -1126,38 +1126,28 @@
 nt.setClass(
-v.getContext()
+this
 , LuckDayAct
@@ -1160,19 +1160,20 @@
 class);%0A
-%09%09%09
+    
         
@@ -1200,28 +1200,163 @@
 t);%0A
-%09%09%09    %7D else %7B%0A    
+            %0A            finish();%0A        %7D%0A        %0A%09%09login_btn.setOnClickListener(new OnClickListener() %7B%0A%09%09%09@Override%0A%09%09%09public void onClick(View v) %7B%0A
 %09%09  
@@ -1391,20 +1391,16 @@
 tent();%0A
-    
 %09%09      
@@ -1455,20 +1455,16 @@
 class);%0A
-    
 %09%09      
@@ -1492,17 +1492,8 @@
 t);%0A
-%09%09%09    %7D%0A
 %09%09  

update ...