package com.xplora.xpsettings.Observer;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.util.Log;

public class RingtoneBroadcastReceiver extends BroadcastReceiver {
    private OnRingtoneBroadcastListener mListener;

    public RingtoneBroadcastReceiver(Context context) {
        // 更新时间的广播
        IntentFilter filter = new IntentFilter();
        filter.addAction("ACTION_NEW_RINGTONES");
        context.registerReceiver(this, filter);
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (action == null || action.isEmpty())
            return;
        if (action.equals("ACTION_NEW_RINGTONES")) {
            if (mListener != null) {
                int status = intent.getIntExtra("ringtone_status", 0);
                int progress = intent.getIntExtra("ringtone_progress", 0);
                int reason = intent.getIntExtra("ringtone_reason", 0);
                mListener.onReceiveRingtoneBroadcast(status, progress, reason);
            }
        }
    }

    public void setBroadcastListener(OnRingtoneBroadcastListener listener) {
        this.mListener = listener;
    }

    public interface OnRingtoneBroadcastListener {
        void onReceiveRingtoneBroadcast(int status, int progress, int reason);
    }
}
