|
|
@@ -3,18 +3,15 @@ package kr.co.zumo.app.lifeplus.view.screen.widget;
|
|
|
import android.app.PendingIntent;
|
|
|
import android.appwidget.AppWidgetManager;
|
|
|
import android.appwidget.AppWidgetProvider;
|
|
|
-import android.content.ComponentName;
|
|
|
import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
-import android.graphics.Bitmap;
|
|
|
import android.net.Uri;
|
|
|
import android.util.Log;
|
|
|
-import android.widget.ImageView;
|
|
|
import android.widget.RemoteViews;
|
|
|
|
|
|
-import com.makeramen.roundedimageview.RoundedTransformationBuilder;
|
|
|
-import com.squareup.picasso.Picasso;
|
|
|
-import com.squareup.picasso.Transformation;
|
|
|
+import com.bumptech.glide.load.resource.bitmap.CenterCrop;
|
|
|
+import com.bumptech.glide.request.RequestOptions;
|
|
|
+import com.bumptech.glide.request.target.AppWidgetTarget;
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
@@ -32,18 +29,14 @@ import kr.co.zumo.app.lifeplus.config.NetworkConfigProduct;
|
|
|
import kr.co.zumo.app.lifeplus.network.api.LifeplusAPIService;
|
|
|
import kr.co.zumo.app.lifeplus.tool.ShareKakaoTalk;
|
|
|
import kr.co.zumo.app.lifeplus.util.AppUtil;
|
|
|
+import kr.co.zumo.app.lifeplus.view.GlideApp;
|
|
|
|
|
|
/**
|
|
|
* Implementation of App Widget functionality.
|
|
|
*/
|
|
|
-public class LifeplusWidget extends AppWidgetProvider {
|
|
|
+public class LifeplusWidgetProvider extends AppWidgetProvider {
|
|
|
|
|
|
- private LifeplusContentsBean contentsBean;
|
|
|
- private static final String REFRESH_CLICK = "refresh_click";
|
|
|
-
|
|
|
- private static Disposable disposable;
|
|
|
-
|
|
|
- private static void render(Context context, AppWidgetManager appWidgetManager, int appWidgetId, LifeplusContentsBean contentsBean) {
|
|
|
+ private void render(Context context, AppWidgetManager appWidgetManager, int appWidgetId, LifeplusContentsBean contentsBean) {
|
|
|
// Construct the RemoteViews object
|
|
|
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.lifeplus_widget);
|
|
|
|
|
|
@@ -55,8 +48,9 @@ public class LifeplusWidget extends AppWidgetProvider {
|
|
|
views.setOnClickPendingIntent(R.id.image_view_bi, PendingIntent.getActivity(context, 0, mainIntent, 0));
|
|
|
|
|
|
// refresh
|
|
|
- Intent refreshIntent = new Intent(context, LifeplusWidget.class);
|
|
|
- refreshIntent.setAction(REFRESH_CLICK);
|
|
|
+ Intent refreshIntent = new Intent(context, LifeplusWidgetProvider.class);
|
|
|
+ refreshIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[]{appWidgetId});
|
|
|
+ refreshIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
|
|
|
views.setOnClickPendingIntent(R.id.image_view_refresh, PendingIntent.getBroadcast(context, appWidgetId, refreshIntent, PendingIntent.FLAG_UPDATE_CURRENT));
|
|
|
|
|
|
// contents link
|
|
|
@@ -67,28 +61,41 @@ public class LifeplusWidget extends AppWidgetProvider {
|
|
|
.build());
|
|
|
views.setOnClickPendingIntent(R.id.image_view_background, PendingIntent.getActivity(context, 0, linkIntent, 0));
|
|
|
|
|
|
- //appWidgetManager.getAppWidgetIds(new ComponentName(context, LifeplusWidget.class));
|
|
|
- Log.e("APP# LifeplusWidget | render", "|" + appWidgetId);
|
|
|
+ // picasso
|
|
|
+// Transformation transformation = new RoundedTransformationBuilder().scaleType(ImageView.ScaleType.FIT_XY).cornerRadiusDp(8).build();
|
|
|
+// Picasso.get().load(contentsBean.getImageUrl()).resize(100, 100).transform(transformation).into(views, R.id.image_view_background, new int[]{appWidgetId});
|
|
|
+
|
|
|
+ // glide
|
|
|
+ AppWidgetTarget backgroundImage = new AppWidgetTarget(context, R.id.image_view_background, views, appWidgetId);
|
|
|
+ String url = contentsBean.getImageUrl();
|
|
|
+ try {
|
|
|
+ GlideApp.with(context.getApplicationContext()).clear(backgroundImage);
|
|
|
+ GlideApp.with(context.getApplicationContext())
|
|
|
+ .asBitmap()
|
|
|
+ .skipMemoryCache(true)
|
|
|
+ .load(url)
|
|
|
+ .override(400, 400)
|
|
|
+ .apply(new RequestOptions().transforms(new CenterCrop()))
|
|
|
+ .into(backgroundImage);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ //appWidgetManager.getAppWidgetIds(new ComponentName(context, LifeplusWidgetProvider.class));
|
|
|
+ Log.w("APP# LifeplusWidgetProvider | render", "|" + "----------------------------------- id: " + appWidgetId);
|
|
|
+ Log.w("APP# LifeplusWidgetProvider | render", "|" + "contentsBean: " + contentsBean.toJson());
|
|
|
appWidgetManager.updateAppWidget(appWidgetId, views);
|
|
|
- //appWidgetManager.updateAppWidget(new ComponentName(context, LifeplusWidget.class), views);
|
|
|
- Log.w("APP# LifeplusWidget | render", "|" + "----------------------------------- id: " + appWidgetId);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
|
|
- super.onUpdate(context, appWidgetManager, appWidgetIds);
|
|
|
- Log.e("APP# LifeplusWidget | onUpdate", "|" + Arrays.toString(appWidgetIds));
|
|
|
+ Log.e("APP# LifeplusWidgetProvider | onUpdate", "| " + Arrays.toString(appWidgetIds));
|
|
|
for (int appWidgetId : appWidgetIds) {
|
|
|
updateAppWidget(context, appWidgetManager, appWidgetId);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
|
|
|
- RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.lifeplus_widget);
|
|
|
- if (null != disposable) {
|
|
|
- disposable.dispose();
|
|
|
- }
|
|
|
-
|
|
|
+ private void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
|
|
|
INetworkConfig networkConfig;
|
|
|
if (AppUtil.isDebug()) {
|
|
|
networkConfig = new NetworkConfigDevelop();
|
|
|
@@ -98,60 +105,24 @@ public class LifeplusWidget extends AppWidgetProvider {
|
|
|
}
|
|
|
|
|
|
String API_URL = networkConfig.getHostUrl() + ":" + networkConfig.getHostPort() + "/";
|
|
|
- disposable = new LifeplusAPIService(API_URL).getWidgetData(new RequestBean())
|
|
|
+ Disposable disposable = new LifeplusAPIService(API_URL).getWidgetData(new RequestBean())
|
|
|
.subscribeOn(Schedulers.io())
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
.subscribe(resultBean -> {
|
|
|
- disposable = null;
|
|
|
render(context, appWidgetManager, appWidgetId, resultBean.getData());
|
|
|
- updateImage(context, appWidgetManager, views, R.id.image_view_background, resultBean.getData().getImageUrl());
|
|
|
+// updateImage(context, appWidgetManager, views, R.id.image_view_background, resultBean.getData().getImageUrl());
|
|
|
}, e -> {
|
|
|
- disposable = null;
|
|
|
- Log.e("APP# LifeplusWidget | updateAppWidget", "| " + " error -> " + e.getLocalizedMessage());
|
|
|
+ Log.e("APP# LifeplusWidgetProvider | updateAppWidget", "| " + " error -> " + e.getLocalizedMessage());
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- public static void updateImage(Context context, AppWidgetManager appWidgetManager, RemoteViews remoteViews, int resourceId, String imageUrl) {
|
|
|
- Bitmap imageBitmap = null;
|
|
|
- int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, LifeplusWidget.class));
|
|
|
- //Picasso.with(context).load(url).into(remoteViews, resourceId, appWidgetIds);
|
|
|
- //Picasso.get().load(url).into(remoteViews, resourceId, appWidgetIds);
|
|
|
-// try {
|
|
|
-// URL url = new URL(imageUrl);
|
|
|
-// imageBitmap = BitmapFactory.decodeStream(url.openConnection().getInputStream());
|
|
|
-// } catch (IOException e) {
|
|
|
-// System.out.println(e);
|
|
|
-// }
|
|
|
-// Log.e("APP# LifeplusWidget | updateImage", "|" + imageBitmap.getHeight() + ", " + imageBitmap.getWidth());
|
|
|
-//
|
|
|
-// Matrix matrix = new Matrix();
|
|
|
-// matrix.postScale(0.5F, 0.5F);
|
|
|
-// Bitmap croppedBitmap = Bitmap.createBitmap(imageBitmap, 100, 100, 100, 100, matrix, true);
|
|
|
-
|
|
|
- Transformation transformation = new RoundedTransformationBuilder().scaleType(ImageView.ScaleType.FIT_XY).cornerRadiusDp(8).build();
|
|
|
- Picasso.get().load(imageUrl).transform(transformation).into(remoteViews, resourceId, appWidgetIds);
|
|
|
- // remoteViews.setImageViewBitmap(R.id.image_view_background, croppedBitmap);
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
-
|
|
|
- AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
|
|
|
-
|
|
|
+ /*
|
|
|
+ super 에서 처리된다.
|
|
|
+ */
|
|
|
super.onReceive(context, intent);
|
|
|
- super.onReceive(context, intent);
|
|
|
-
|
|
|
- int appWidgetId = intent.getFlags();
|
|
|
- switch (intent.getAction()) {
|
|
|
- case REFRESH_CLICK:
|
|
|
- int[] appWidgetIds = new int[]{appWidgetId};
|
|
|
- onUpdate(context, appWidgetManager, appWidgetIds);
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -164,7 +135,6 @@ public class LifeplusWidget extends AppWidgetProvider {
|
|
|
// Enter relevant functionality for when the last widget is disabled
|
|
|
}
|
|
|
|
|
|
-
|
|
|
}
|
|
|
|
|
|
|