package com.gs.apidemo;

import android.content.Intent;
import android.util.Log;

import com.gs.phone.service.BasePhoneService;

/*
 */
public class MyPhoneService extends BasePhoneService {
    private static final String TAG = MyPhoneService.class.getSimpleName();


    @Override
    public void onHookEvent(boolean isOffHook) {
        super.onHookEvent(isOffHook);
        Log.i(TAG, "isOffHook:"+isOffHook);
        if (isOffHook) {
            Log.i(TAG, "open my phone!");
            Intent intent = new Intent(this, DialerActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        } else {
            Log.i(TAG, "try to finish dialer or end call!");
        }
    }

    @Override
    public void onEHSHookEvent(boolean offHook) {
        super.onEHSHookEvent(offHook);
        Log.i(TAG, "isEhsOffHook:"+offHook);
    }

    @Override
    public void onLineStateChanged(int lineId, int status) {
        super.onLineStateChanged(lineId, status);
        Log.i(TAG, "onLineStateChanged:"+lineId + ", new status:" + status);
        if (status != 0) {
            Intent intent = new Intent(this, TalkingActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
            startActivity(intent);
        }
    }

    @Override
    public boolean onEmergencyCallButtonClicked() {
        Log.i(TAG, "onEmergencyCallButtonClicked");
        return false;
    }

    @Override
    public void onShowCallingView() {
        super.onShowCallingView();
        Log.i(TAG, "onShowCallingView");
        Intent intent = new Intent(this, TalkingActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        startActivity(intent);
    }

    @Override
    public void onShowDefinedView() {
        super.onShowDefinedView();
        Log.i(TAG, "onShowDefinedView");
        Intent intent = new Intent(this, DialerActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }
}
