PhotosReceiver.java 1.51 KB
package com.polysoft.nafmii.broadcast;

import android.content.Context;
import android.content.Intent;

public class PhotosReceiver extends Receiver<String> {

    public static final String ACTION_CAMERA = "com.polysoft.nafmii.action_camera";
    public static final String ACTION_ALBUM = "com.polysoft.nafmii.action_album";

    protected PhotosReceiver(Context context) {
        super(context);
    }

    public static Receiver<String> getInstance(Context context) {
        Receiver<String> receiver = getReceiver(PhotosReceiver.class);
        return null != receiver ? receiver : new PhotosReceiver(context.getApplicationContext());
    }

    public static void sendBroadcastCamera(Context context, String filepath) {
        Intent intent = new Intent().setAction(ACTION_CAMERA);
        intent.putExtra("data", filepath);
        onSendBroadcast(context, intent);
    }

    public static void sendBroadcastAlbum(Context context, String filepath) {
        Intent intent = new Intent().setAction(ACTION_ALBUM);
        intent.putExtra("data", filepath);
        onSendBroadcast(context, intent);
    }

    @Override
    protected String[] getActions() {
        return new String[]{ACTION_CAMERA, ACTION_ALBUM};
    }

    @Override
    protected String onReceiverData(String action, Intent intent) {
        if (ACTION_CAMERA.equals(action)) {
            return intent.getStringExtra("data");
        } else if (ACTION_ALBUM.equals(action)) {
            return intent.getStringExtra("data");
        }
        return null;
    }

}