// Path: app/src/main/java/top/soyask/calendarii/ui/widget/transparent/MonthWidget.java
// public class MonthWidget extends AppWidgetProvider {
// 
//     private static final String TAG = "MonthWidget";
// 
//     public static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
//                                        int appWidgetId) {
//         Setting.loadSetting(context);
//         Calendar calendar = Calendar.getInstance(Locale.CHINA);
//         RemoteViews views = setupRemoteViews(context, calendar);
//         appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, R.id.gv_month);
//         appWidgetManager.updateAppWidget(appWidgetId, views);
//     }
// 
//     @NonNull
//     private static RemoteViews setupRemoteViews(Context context, Calendar calendar) {
//         // 应该更改theme来达到目的，然而Android似乎并没有为View提供setTheme这样的功能 w(ﾟДﾟ)w
//         int layout = Setting.TransparentWidget.trans_widget_theme_color == 0 ? R.layout.month_widget : R.layout.month_widget_light;
//         RemoteViews views = new RemoteViews(context.getPackageName(), layout);
//         LunarDay lunarDay = LunarUtils.getLunar(calendar);
// 
//         Intent intent = new Intent(context, MonthService.class);
// 
//         int month = calendar.get(Calendar.MONTH) + 1;
//         PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), 0);
// 
//         views.setOnClickPendingIntent(R.id.iv_launch, pendingIntent);
//         int themeColor = Setting.TransparentWidget.trans_widget_theme_color;
//         views.setInt(R.id.widget, "setBackgroundColor", Color.argb(Setting.TransparentWidget.trans_widget_alpha, themeColor, themeColor, themeColor));
// 
//         views.setRemoteAdapter(R.id.gv_month, intent);
//         views.setTextViewText(R.id.tv_lunar, lunarDay.getLunarDate());
//         views.setTextViewTextSize(R.id.tv_lunar, TypedValue.COMPLEX_UNIT_SP, Setting.TransparentWidget.trans_widget_lunar_month_text_size);
//         views.setTextViewTextSize(R.id.tv_year, TypedValue.COMPLEX_UNIT_SP, Setting.TransparentWidget.trans_widget_year_text_size);
//         views.setTextViewTextSize(R.id.tv_date, TypedValue.COMPLEX_UNIT_SP, Setting.TransparentWidget.trans_widget_month_text_size);
//         views.setTextViewText(R.id.tv_year, String.valueOf(calendar.get(Calendar.YEAR)));
//         views.setTextViewText(R.id.tv_date, String.format(Locale.CHINA, "%02d月", month));
//         return views;
//     }
// 
//     @Override
//     public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
//         for (int appWidgetId : appWidgetIds) {
//             updateAppWidget(context, appWidgetManager, appWidgetId);
//         }
//     }
// 
//     @Override
//     public void onDeleted(Context context, int[] appWidgetIds) {
//         super.onDeleted(context, appWidgetIds);
//     }
// 
//     @Override
//     public void onEnabled(Context context) {
// 
//     }
// 
//     @Override
//     public void onDisabled(Context context) {
//     }
// 
// }
// 
// Path: app/src/main/java/top/soyask/calendarii/ui/widget/white/WhiteWidget.java
// public class WhiteWidget extends AppWidgetProvider {
// 
//     public static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
//                                        int appWidgetId) {
//         RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.white_widget);
//         Intent intent = new Intent(context, WhiteWidgetService.class);
//         Setting.loadSetting(context);
//         Calendar calendar = Calendar.getInstance(Locale.CHINA);
//         views.setTextViewText(R.id.tv_year, String.valueOf(calendar.get(Calendar.YEAR)));
//         views.setTextViewText(R.id.tv_month, String.valueOf(calendar.get(Calendar.MONTH) + 1) + "月");
//         views.setRemoteAdapter(R.id.gv_month, intent);
//         if (Setting.white_widget_pic != null) {
//             Bitmap bitmap = BitmapFactory.decodeFile(Setting.white_widget_pic);
//             views.setBitmap(R.id.iv, "setImageBitmap", bitmap);
//         } else {
//             Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.mipmap.miku);
//             views.setBitmap(R.id.iv, "setImageBitmap", bitmap);
//         }
//         PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), 0);
//         views.setOnClickPendingIntent(R.id.iv, pendingIntent);
//         appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, R.id.gv_month);
//         appWidgetManager.updateAppWidget(appWidgetId, views);
//     }
// 
//     @Override
//     public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
//         for (int appWidgetId : appWidgetIds) {
//             updateAppWidget(context, appWidgetManager, appWidgetId);
//         }
//     }
// 
//     @Override
//     public void onEnabled(Context context) {
//     }
// 
//     @Override
//     public void onDisabled(Context context) {
//         // Enter relevant functionality for when the last widget is disabled
//     }
// }


import android.support.annotation.Nullable;
import android.appwidget.AppWidgetManager;
import android.content.ComponentName;
import android.content.Context;
import top.soyask.calendarii.ui.widget.transparent.MonthWidget;
import top.soyask.calendarii.ui.widget.white.WhiteWidget;
package top.soyask.calendarii.ui.widget;



/**
 * Created by mxf on 2017/11/19.
 */

public class WidgetManager {
    public static void updateAllWidget(Context context) {
        AppWidgetManager appWidgetManager =
                (AppWidgetManager) context.getSystemService(Context.APPWIDGET_SERVICE);
        updateMonthWidget(context, appWidgetManager);
        updateWhiteWidget(context, appWidgetManager);
    }

    public static void updateWhiteWidget(Context context,@Nullable AppWidgetManager appWidgetManager) {
        if(appWidgetManager != null){
// Path: app/src/main/java/top/soyask/calendarii/ui/widget/transparent/MonthWidget.java
// public class MonthWidget extends AppWidgetProvider {
// 
//     private static final String TAG = "MonthWidget";
// 
//     public static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
//                                        int appWidgetId) {
//         Setting.loadSetting(context);
//         Calendar calendar = Calendar.getInstance(Locale.CHINA);
//         RemoteViews views = setupRemoteViews(context, calendar);
//         appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, R.id.gv_month);
//         appWidgetManager.updateAppWidget(appWidgetId, views);
//     }
// 
//     @NonNull
//     private static RemoteViews setupRemoteViews(Context context, Calendar calendar) {
//         // 应该更改theme来达到目的，然而Android似乎并没有为View提供setTheme这样的功能 w(ﾟДﾟ)w
//         int layout = Setting.TransparentWidget.trans_widget_theme_color == 0 ? R.layout.month_widget : R.layout.month_widget_light;
//         RemoteViews views = new RemoteViews(context.getPackageName(), layout);
//         LunarDay lunarDay = LunarUtils.getLunar(calendar);
// 
//         Intent intent = new Intent(context, MonthService.class);
// 
//         int month = calendar.get(Calendar.MONTH) + 1;
//         PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), 0);
// 
//         views.setOnClickPendingIntent(R.id.iv_launch, pendingIntent);
//         int themeColor = Setting.TransparentWidget.trans_widget_theme_color;
//         views.setInt(R.id.widget, "setBackgroundColor", Color.argb(Setting.TransparentWidget.trans_widget_alpha, themeColor, themeColor, themeColor));
// 
//         views.setRemoteAdapter(R.id.gv_month, intent);
//         views.setTextViewText(R.id.tv_lunar, lunarDay.getLunarDate());
//         views.setTextViewTextSize(R.id.tv_lunar, TypedValue.COMPLEX_UNIT_SP, Setting.TransparentWidget.trans_widget_lunar_month_text_size);
//         views.setTextViewTextSize(R.id.tv_year, TypedValue.COMPLEX_UNIT_SP, Setting.TransparentWidget.trans_widget_year_text_size);
//         views.setTextViewTextSize(R.id.tv_date, TypedValue.COMPLEX_UNIT_SP, Setting.TransparentWidget.trans_widget_month_text_size);
//         views.setTextViewText(R.id.tv_year, String.valueOf(calendar.get(Calendar.YEAR)));
//         views.setTextViewText(R.id.tv_date, String.format(Locale.CHINA, "%02d月", month));
//         return views;
//     }
// 
//     @Override
//     public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
//         for (int appWidgetId : appWidgetIds) {
//             updateAppWidget(context, appWidgetManager, appWidgetId);
//         }
//     }
// 
//     @Override
//     public void onDeleted(Context context, int[] appWidgetIds) {
//         super.onDeleted(context, appWidgetIds);
//     }
// 
//     @Override
//     public void onEnabled(Context context) {
// 
//     }
// 
//     @Override
//     public void onDisabled(Context context) {
//     }
// 
// }
// 
// Path: app/src/main/java/top/soyask/calendarii/ui/widget/white/WhiteWidget.java
// public class WhiteWidget extends AppWidgetProvider {
// 
//     public static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
//                                        int appWidgetId) {
//         RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.white_widget);
//         Intent intent = new Intent(context, WhiteWidgetService.class);
//         Setting.loadSetting(context);
//         Calendar calendar = Calendar.getInstance(Locale.CHINA);
//         views.setTextViewText(R.id.tv_year, String.valueOf(calendar.get(Calendar.YEAR)));
//         views.setTextViewText(R.id.tv_month, String.valueOf(calendar.get(Calendar.MONTH) + 1) + "月");
//         views.setRemoteAdapter(R.id.gv_month, intent);
//         if (Setting.white_widget_pic != null) {
//             Bitmap bitmap = BitmapFactory.decodeFile(Setting.white_widget_pic);
//             views.setBitmap(R.id.iv, "setImageBitmap", bitmap);
//         } else {
//             Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.mipmap.miku);
//             views.setBitmap(R.id.iv, "setImageBitmap", bitmap);
//         }
//         PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), 0);
//         views.setOnClickPendingIntent(R.id.iv, pendingIntent);
//         appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, R.id.gv_month);
//         appWidgetManager.updateAppWidget(appWidgetId, views);
//     }
// 
//     @Override
//     public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
//         for (int appWidgetId : appWidgetIds) {
//             updateAppWidget(context, appWidgetManager, appWidgetId);
//         }
//     }
// 
//     @Override
//     public void onEnabled(Context context) {
//     }
// 
//     @Override
//     public void onDisabled(Context context) {
//         // Enter relevant functionality for when the last widget is disabled
//     }
// }


// Path: app/src/main/java/top/soyask/calendarii/ui/widget/WidgetManager.java
import android.support.annotation.Nullable;
import android.appwidget.AppWidgetManager;
import android.content.ComponentName;
import android.content.Context;
import top.soyask.calendarii.ui.widget.transparent.MonthWidget;
import top.soyask.calendarii.ui.widget.white.WhiteWidget;

package top.soyask.calendarii.ui.widget;



/**
 * Created by mxf on 2017/11/19.
 */

public class WidgetManager {
    public static void updateAllWidget(Context context) {
        AppWidgetManager appWidgetManager =
                (AppWidgetManager) context.getSystemService(Context.APPWIDGET_SERVICE);
        updateMonthWidget(context, appWidgetManager);
        updateWhiteWidget(context, appWidgetManager);
    }

    public static void updateWhiteWidget(Context context,@Nullable AppWidgetManager appWidgetManager) {
        if(appWidgetManager != null){
            int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, WhiteWidget.class));