package net.ddns.mahaljsp.clockwidget;

import android.appwidget.AppWidgetManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.widget.RemoteViews;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by Thomas Wu(mahaljsp@gmail.com) on 2016/12/24.
 */

public class TimeTickReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        RemoteViews views=new RemoteViews(context.getPackageName(), R.layout.clock_app_widget);
        SimpleDateFormat sdf=new SimpleDateFormat("HH:mm");
        views.setTextViewText(R.id.now_text, sdf.format(new Date(System.currentTimeMillis())));
        ComponentName cn=new ComponentName(context, ClockAppWidget.class);
        AppWidgetManager manager=AppWidgetManager.getInstance(context);
        manager.updateAppWidget(cn, views);
    }
}
