diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 79203bf14..f1c20a8d3 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -62,6 +62,16 @@ + + + + + + + + diff --git a/app/src/main/ic_small_widget_preview-web.png b/app/src/main/ic_small_widget_preview-web.png new file mode 100644 index 000000000..5d6fa2451 Binary files /dev/null and b/app/src/main/ic_small_widget_preview-web.png differ diff --git a/app/src/main/java/org/isoron/uhabits/SmallWidgetProvider.java b/app/src/main/java/org/isoron/uhabits/SmallWidgetProvider.java new file mode 100644 index 000000000..0ba2d196a --- /dev/null +++ b/app/src/main/java/org/isoron/uhabits/SmallWidgetProvider.java @@ -0,0 +1,66 @@ +/* Copyright (C) 2016 Alinson Santos Xavier + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.isoron.uhabits; + +import android.appwidget.AppWidgetManager; +import android.appwidget.AppWidgetProvider; +import android.content.Context; +import android.graphics.Bitmap; +import android.util.Log; +import android.widget.RemoteViews; + +import org.isoron.uhabits.views.SmallWidgetView; + +import java.io.FileNotFoundException; +import java.io.FileOutputStream; + +public class SmallWidgetProvider extends AppWidgetProvider +{ + @Override + public void onUpdate(Context context, AppWidgetManager manager, int[] appWidgetIds) + { + for(int id : appWidgetIds) + updateWidget(context, manager, id); + } + + private void updateWidget(Context context, AppWidgetManager manager, int widgetId) + { + RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.small_widget); + + SmallWidgetView widgetView = new SmallWidgetView(context); + widgetView.setDrawingCacheEnabled(true); + widgetView.measure(200, 200); + widgetView.layout(0, 0, 200, 200); + widgetView.buildDrawingCache(true); + + Bitmap drawingCache = widgetView.getDrawingCache(); + + try + { + drawingCache.compress(Bitmap.CompressFormat.PNG, 100, + new FileOutputStream(context.getFilesDir() + "/widget.png")); + } + catch (FileNotFoundException e) + { + e.printStackTrace(); + } + + Log.d("SmallWidgetProvider", drawingCache.toString()); + remoteViews.setImageViewBitmap(R.id.imageView, drawingCache); + manager.updateAppWidget(widgetId, remoteViews); + } +} diff --git a/app/src/main/java/org/isoron/uhabits/views/SmallWidgetView.java b/app/src/main/java/org/isoron/uhabits/views/SmallWidgetView.java new file mode 100644 index 000000000..33c0105d4 --- /dev/null +++ b/app/src/main/java/org/isoron/uhabits/views/SmallWidgetView.java @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2016 Alinson Santos Xavier + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * + */ + +package org.isoron.uhabits.views; + +import android.content.Context; +import android.graphics.Canvas; +import android.graphics.Paint; +import android.util.AttributeSet; +import android.view.View; + +import org.isoron.helpers.ColorHelper; + +public class SmallWidgetView extends View +{ + private Paint pCircle; + + public SmallWidgetView(Context context) + { + super(context); + init(context); + } + + public SmallWidgetView(Context context, AttributeSet attrs) + { + super(context, attrs); + init(context); + } + + private void init(Context context) + { + pCircle = new Paint(); + pCircle.setColor(ColorHelper.palette[7]); + } + + @Override + protected void onDraw(Canvas canvas) + { + super.onDraw(canvas); + canvas.drawOval(0, 0, getMeasuredWidth(), getMeasuredHeight(), pCircle); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) + { + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + setMeasuredDimension(widthMeasureSpec, heightMeasureSpec); + } + + @Override + protected void onSizeChanged(int w, int h, int oldw, int oldh) + { + super.onSizeChanged(w, h, oldw, oldh); + } +} diff --git a/app/src/main/res/layout/small_widget.xml b/app/src/main/res/layout/small_widget.xml new file mode 100644 index 000000000..626b909f1 --- /dev/null +++ b/app/src/main/res/layout/small_widget.xml @@ -0,0 +1,25 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/small_widget_preview.xml b/app/src/main/res/layout/small_widget_preview.xml new file mode 100644 index 000000000..505bc619b --- /dev/null +++ b/app/src/main/res/layout/small_widget_preview.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-hdpi/ic_small_widget_preview.png b/app/src/main/res/mipmap-hdpi/ic_small_widget_preview.png new file mode 100644 index 000000000..7ee617aa6 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_small_widget_preview.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_small_widget_preview.png b/app/src/main/res/mipmap-mdpi/ic_small_widget_preview.png new file mode 100644 index 000000000..ff862e252 Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_small_widget_preview.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_small_widget_preview.png b/app/src/main/res/mipmap-xhdpi/ic_small_widget_preview.png new file mode 100644 index 000000000..8d90b8901 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_small_widget_preview.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_small_widget_preview.png b/app/src/main/res/mipmap-xxhdpi/ic_small_widget_preview.png new file mode 100644 index 000000000..734f9630f Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_small_widget_preview.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_small_widget_preview.png b/app/src/main/res/mipmap-xxxhdpi/ic_small_widget_preview.png new file mode 100644 index 000000000..f049e8332 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_small_widget_preview.png differ diff --git a/app/src/main/res/xml/small_widget_info.xml b/app/src/main/res/xml/small_widget_info.xml new file mode 100644 index 000000000..188d5e5c5 --- /dev/null +++ b/app/src/main/res/xml/small_widget_info.xml @@ -0,0 +1,12 @@ + + + + + \ No newline at end of file