mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-09 18:48:51 -06:00
Update widget previews
This commit is contained in:
@@ -33,6 +33,7 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RemoteViews;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.isoron.uhabits.R;
|
||||
import org.isoron.uhabits.helpers.UIHelper;
|
||||
@@ -123,23 +124,27 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider
|
||||
|
||||
protected abstract void refreshCustomViewData(View widgetView);
|
||||
|
||||
private void savePreview(Context context, int widgetId, Bitmap widgetCache)
|
||||
private void savePreview(Context context, int widgetId, Bitmap widgetCache, int width,
|
||||
int height, String label)
|
||||
{
|
||||
try
|
||||
{
|
||||
LayoutInflater inflater = LayoutInflater.from(context);
|
||||
View view = inflater.inflate(getLayoutId(), null);
|
||||
|
||||
ImageView iv = (ImageView) view.findViewById(R.id.imageView);
|
||||
iv.setImageBitmap(widgetCache);
|
||||
TextView tvLabel = (TextView) view.findViewById(R.id.label);
|
||||
if(tvLabel != null) tvLabel.setText(label);
|
||||
|
||||
view.measure(portraitWidth, portraitHeight);
|
||||
ImageView iv = (ImageView) view.findViewById(R.id.imageView);
|
||||
if(iv != null) iv.setImageBitmap(widgetCache);
|
||||
|
||||
view.measure(width, height);
|
||||
view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
|
||||
view.setDrawingCacheEnabled(true);
|
||||
view.buildDrawingCache();
|
||||
Bitmap previewCache = view.getDrawingCache();
|
||||
|
||||
String filename = String.format("%s/%d.png", context.getExternalCacheDir(), widgetId);
|
||||
String filename = String.format("%s/%d_%d.png", context.getExternalCacheDir(), widgetId, width);
|
||||
Log.d("BaseWidgetProvider", String.format("Writing %s", filename));
|
||||
FileOutputStream out = new FileOutputStream(filename);
|
||||
|
||||
@@ -285,7 +290,7 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider
|
||||
remoteViews.setViewPadding(R.id.buttonOverlay, p[0], p[1], p[2], p[3]);
|
||||
}
|
||||
|
||||
//savePreview(context, widgetId, drawingCache);
|
||||
//savePreview(context, widgetId, drawingCache, width, height, habit.name);
|
||||
|
||||
PendingIntent onClickIntent = getOnClickPendingIntent(context, habit);
|
||||
if (onClickIntent != null) remoteViews.setOnClickPendingIntent(R.id.button,
|
||||
|
||||
Reference in New Issue
Block a user