package com.view;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.util.AttributeSet;
import android.widget.RelativeLayout;


/**
 * author: jack
 * date: 2018/8/30 18:12
 * desc:Launcher界面基类
 */
public abstract class BaseLauncherView extends RelativeLayout {
    private static final String TAG = "BaseLauncherView";
    //UI state
    public static final int STATE_NO_CONNECT = 0;
    public static final int STATE_CONNECT = 1;
    public static final int STATE_CALL = 2;

    protected final Context mContext;
    protected Context mReadResContext;

    //view
    protected RelativeLayout mRlRoot;

    public BaseLauncherView(Context context) {
        this(context, null);
    }

    public BaseLauncherView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public BaseLauncherView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.mContext = context;
        try {
            mReadResContext = mContext.createPackageContext(Constants.PACKAGE_NAME, Context.CONTEXT_IGNORE_SECURITY | Context.CONTEXT_INCLUDE_CODE);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        onInit(context, attrs, defStyleAttr);
    }

    public abstract void onInit(Context context, AttributeSet attrs, int defStyleAttr);


    /**
     * 启动App
     */
    protected void startupApp() {
        Intent targetIntent = getContext().getPackageManager().getLaunchIntentForPackage(Constants.PACKAGE_NAME);
        mContext.startActivity(targetIntent);
    }

    protected void toHome() {
        Intent home = new Intent(Intent.ACTION_MAIN);
        home.addCategory(Intent.CATEGORY_HOME);
        getContext().startActivity(home);
    }

}
