package com.longtu.sample;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;

import com.acegameproject.burstshooter.R;
import com.bh.sdk.Interface.LTBaseSDK;
import com.longtu.sdk.utils.Log.Logs;

import java.util.HashMap;

/**
 * 统计相关功能和接口使用
 */
public class LTBase_Demo_Analyticslayout extends LinearLayout implements OnClickListener {

    private Context mContext;
    private Button mRegistration, mLogin, mdeeplink, mPurchase, mcreaterole, mDiy1;

    public LTBase_Demo_Analyticslayout(Context context) {
        // TODO Auto-generated constructor stub
        super(context);
        mContext = context;
        init();
    }

    public LTBase_Demo_Analyticslayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
        init();
    }

    private void init() {
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View v = inflater.inflate(R.layout.longtu_demo_anlyticsdialog, this);

        mRegistration = (Button) v.findViewById(R.id.registration);
        mRegistration.setOnClickListener(this);
        mLogin = (Button) v.findViewById(R.id.login);
        mLogin.setOnClickListener(this);
        mdeeplink = (Button) v.findViewById(R.id.tutorial_deeplink);
        mdeeplink.setOnClickListener(this);
        mPurchase = (Button) v.findViewById(R.id.purchase);
        mPurchase.setOnClickListener(this);
        mcreaterole = (Button) v.findViewById(R.id.createrole);
        mcreaterole.setOnClickListener(this);
        mDiy1 = (Button) v.findViewById(R.id.diy1);
        mDiy1.setOnClickListener(this);

    }

    @SuppressLint("UseValueOf")
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        if (v == mRegistration) {
            HashMap<String, Object> logValue = new HashMap<String, Object>();
            logValue.put("userId", LTBase_Demo_MainActivity.LONGTU_UserId);
            LTBaseSDK.getInstance(LTBase_Demo_MainActivity.mMainActivity)
                    .LTBaseSDKSendAnalyticsInfoLog("registration", logValue);
        } else if (v == mLogin) {
            HashMap<String, Object> logValue = new HashMap<String, Object>();
            logValue.put("userId", LTBase_Demo_MainActivity.LONGTU_UserId);
            LTBaseSDK.getInstance(LTBase_Demo_MainActivity.mMainActivity)
                    .LTBaseSDKSendAnalyticsInfoLog("login",
                            logValue);

        } else if (v == mdeeplink) {
            HashMap<String, Object> logValue = new HashMap<String, Object>();
            logValue.put("link", "linklinklinklink");
            LTBaseSDK.getInstance(LTBase_Demo_MainActivity.mMainActivity)
                    .LTBaseSDKSendAnalyticsInfoLog("ReceiveDeepLink", logValue);

        } else if (v == mPurchase) {
            HashMap<String, Object> logValue = new HashMap<String, Object>();
            // Double price = new Double("108.01");
            logValue.put("price", "100");
            logValue.put("userId", LTBase_Demo_MainActivity.LONGTU_UserId);
            logValue.put("currency", "JPY");
            LTBaseSDK.getInstance(LTBase_Demo_MainActivity.mMainActivity)
                    .LTBaseSDKSendAnalyticsInfoLog("purchase",
                            logValue);

        } else if (v == mcreaterole) {
            HashMap<String, Object> logValue = new HashMap<String, Object>();
            logValue.put("roleId", LTBase_Demo_MainActivity.LONGTU_UserId);
            LTBaseSDK.getInstance(LTBase_Demo_MainActivity.mMainActivity)
                    .LTBaseSDKSendAnalyticsInfoLog("CreateRole", logValue);

        } else if (v == mDiy1) {
            HashMap<String, Object> logValue = new HashMap<String, Object>();
            LTBaseSDK.getInstance(LTBase_Demo_MainActivity.mMainActivity)
                    .LTBaseSDKSendAnalyticsInfoLog("CustEvent1", logValue);
        }

    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        // TODO Auto-generated method stub
        Logs.i("ltbasedemo", "onKeyDown  keyCode = " + keyCode + " event getRepeatCount = " + event.getRepeatCount());
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            // (SDK接口)
            LTBase_Demo_MainActivity.mMainActivity.setContentView(LTBase_Demo_MainActivity.mMainActivity.mPayView);
            LTBase_Demo_MainActivity.mMainActivity.mPayView.mAnalyticslayout = null;
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

}
