ScreenOnOffBroadCast.java 2.18 KB
package com.lotus.town.broadcast;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

import com.controller.NotifyType;
import com.lotus.town.ali.MonitorService;
import com.lotus.town.config.SupportAction;
import com.lotus.town.locker.LockerActivity;
import com.lotus.town.notify.NotifyManager;
import com.sdk.Debug;
import com.sdk.EventBus;
import com.sdk.SharedPref;


public class ScreenOnOffBroadCast extends BroadcastReceiver{

    private final String TAG = "secln.ScreenOnOffBroadCast";
    @Override
    public void onReceive(final Context context, Intent intent) {
        if(intent.getAction().equals("android.intent.action.SCREEN_OFF")|| intent.getAction().equals(SupportAction.SCREEN_OFF_MY)){
            SharedPref.getOrSetEvFlag(context,false,false);
            NotifyManager.NotifyChange(context, NotifyType.SCREEN_OFF_NOTIRY);
        } else if(intent.getAction().equals("android.intent.action.SCREEN_ON")){
            MonitorService.invoke(context);
            NotifyManager.NotifyChange(context,NotifyType.SCREEN_ON_NOTIRY);
            EventBus.getInstance().notify(EventBus.SCREEN_ON);
        } else if(intent.getAction().equals("android.intent.action.USER_PRESENT")){
            SharedPref.increateUnlockScreen(context);
            NotifyManager.NotifyChange(context,NotifyType.UNLOCK_NOTIRY);
        } else if(intent.getAction().equals("android.intent.action.TIME_TICK")){

            MonitorService.invoke(context);
        } else if(intent.getAction().equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)){
            if(Debug.DEBUG_MODE){
                Toast.makeText(context,"ACTION_CLOSE_SYSTEM_DIALOGS",Toast.LENGTH_SHORT).show();
            }

            String reason = intent.getStringExtra( "reason" );
            if(reason != null) {
                if (reason.equals("homekey")) {
                    LockerActivity.startActivitySelf(context);
                    // 按Home按键
                    MonitorService.invokeMp3(context, false);
                } else if (reason.equals("recentapps")) {
                    MonitorService.invokeMp3(context, true);
                }
            }
        }
    }
}