mirror of https://github.com/iSoron/uhabits.git
parent
88455acc76
commit
c1dae021bf
After Width: | Height: | Size: 35 KiB |
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView"
|
||||
android:layout_width="55dp"
|
||||
android:layout_height="55dp"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:shadowColor="#000000"
|
||||
android:shadowDx="1"
|
||||
android:shadowDy="1"
|
||||
android:shadowRadius="3"
|
||||
android:padding="6dp"
|
||||
android:text="Widget"/>
|
||||
|
||||
</LinearLayout>
|
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<org.isoron.uhabits.views.SmallWidgetView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="120dp"
|
||||
android:layout_height="120dp">
|
||||
|
||||
</org.isoron.uhabits.views.SmallWidgetView>
|
After Width: | Height: | Size: 2.7 KiB |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 3.7 KiB |
After Width: | Height: | Size: 6.0 KiB |
After Width: | Height: | Size: 8.5 KiB |
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:minHeight="40dp"
|
||||
android:minWidth="40dp"
|
||||
android:initialLayout="@layout/small_widget"
|
||||
android:previewImage="@mipmap/ic_small_widget_preview"
|
||||
android:resizeMode="none"
|
||||
android:updatePeriodMillis="3600000"
|
||||
android:widgetCategory="home_screen">
|
||||
|
||||
|
||||
</appwidget-provider>
|
Loading…
Reference in new issue