mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Add ripple effect to check mark widget
This commit is contained in:
@@ -254,8 +254,8 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
buildRemoteViews(portraitWidgetView, portraitRemoteViews);
|
buildRemoteViews(portraitWidgetView, portraitRemoteViews, portraitWidth, portraitHeight);
|
||||||
buildRemoteViews(landscapeWidgetView, landscapeRemoteViews);
|
buildRemoteViews(landscapeWidgetView, landscapeRemoteViews, landscapeWidth, landscapeHeight);
|
||||||
updateAppWidget();
|
updateAppWidget();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@@ -267,7 +267,7 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider
|
|||||||
super.onPostExecute(aVoid);
|
super.onPostExecute(aVoid);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buildRemoteViews(View widgetView, RemoteViews remoteViews)
|
private void buildRemoteViews(View widgetView, RemoteViews remoteViews, int width, int height)
|
||||||
{
|
{
|
||||||
widgetView.invalidate();
|
widgetView.invalidate();
|
||||||
widgetView.setDrawingCacheEnabled(true);
|
widgetView.setDrawingCacheEnabled(true);
|
||||||
@@ -276,11 +276,29 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider
|
|||||||
remoteViews.setTextViewText(R.id.label, habit.name);
|
remoteViews.setTextViewText(R.id.label, habit.name);
|
||||||
remoteViews.setImageViewBitmap(R.id.imageView, drawingCache);
|
remoteViews.setImageViewBitmap(R.id.imageView, drawingCache);
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
|
||||||
|
{
|
||||||
|
int imageWidth = widgetView.getMeasuredWidth();
|
||||||
|
int imageHeight = widgetView.getMeasuredHeight();
|
||||||
|
int p[] = getPadding(width, height, imageWidth, imageHeight);
|
||||||
|
|
||||||
|
remoteViews.setViewPadding(R.id.buttonOverlay, p[0], p[1], p[2], p[3]);
|
||||||
|
}
|
||||||
|
|
||||||
//savePreview(context, widgetId, drawingCache);
|
//savePreview(context, widgetId, drawingCache);
|
||||||
|
|
||||||
PendingIntent onClickIntent = getOnClickPendingIntent(context, habit);
|
PendingIntent onClickIntent = getOnClickPendingIntent(context, habit);
|
||||||
if (onClickIntent != null) remoteViews.setOnClickPendingIntent(R.id.imageView,
|
if (onClickIntent != null) remoteViews.setOnClickPendingIntent(R.id.button,
|
||||||
onClickIntent);
|
onClickIntent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int[] getPadding(int entireWidth, int entireHeight, int imageWidth,
|
||||||
|
int imageHeight)
|
||||||
|
{
|
||||||
|
int w = (int) (((float) entireWidth - imageWidth) / 2);
|
||||||
|
int h = (int) (((float) entireHeight - imageHeight) / 2);
|
||||||
|
|
||||||
|
return new int[]{ w, h, w, h };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
39
app/src/main/res/drawable-v21/widget_button_background.xml
Normal file
39
app/src/main/res/drawable-v21/widget_button_background.xml
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<!--
|
||||||
|
~ Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
~
|
||||||
|
~ This file is part of Loop Habit Tracker.
|
||||||
|
~
|
||||||
|
~ Loop Habit Tracker 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.
|
||||||
|
~
|
||||||
|
~ Loop Habit Tracker 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/>.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item
|
||||||
|
android:top="1dp"
|
||||||
|
android:left="1dp"
|
||||||
|
android:bottom="3dp"
|
||||||
|
android:right="3dp">
|
||||||
|
<ripple
|
||||||
|
android:color="#60ffffff">
|
||||||
|
|
||||||
|
<item android:id="@android:id/mask">
|
||||||
|
<shape android:shape="rectangle">
|
||||||
|
<corners android:radius="5dp"/>
|
||||||
|
<solid android:color="?android:colorPrimary"/>
|
||||||
|
</shape>
|
||||||
|
<color android:color="@color/white"/>
|
||||||
|
</item>
|
||||||
|
</ripple>
|
||||||
|
</item>
|
||||||
|
|
||||||
|
</layer-list>
|
||||||
34
app/src/main/res/drawable/widget_button_background.xml
Normal file
34
app/src/main/res/drawable/widget_button_background.xml
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<!--
|
||||||
|
~ Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
~
|
||||||
|
~ This file is part of Loop Habit Tracker.
|
||||||
|
~
|
||||||
|
~ Loop Habit Tracker 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.
|
||||||
|
~
|
||||||
|
~ Loop Habit Tracker 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/>.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item android:state_enabled="true" android:state_pressed="true">
|
||||||
|
<layer-list>
|
||||||
|
<item android:bottom="3dp"
|
||||||
|
android:left="1dp"
|
||||||
|
android:right="3dp"
|
||||||
|
android:top="1dp">
|
||||||
|
<shape android:shape="rectangle">
|
||||||
|
<corners android:radius="5dp"/>
|
||||||
|
<solid android:color="#30ffffff"/>
|
||||||
|
</shape>
|
||||||
|
</item>
|
||||||
|
</layer-list>
|
||||||
|
</item>
|
||||||
|
</selector>
|
||||||
@@ -18,12 +18,11 @@
|
|||||||
~ with this program. If not, see <http://www.gnu.org/licenses/>.
|
~ with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<LinearLayout
|
<RelativeLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:orientation="vertical"
|
|
||||||
android:padding="0dp">
|
android:padding="0dp">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
@@ -33,4 +32,18 @@
|
|||||||
android:adjustViewBounds="true"
|
android:adjustViewBounds="true"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
</LinearLayout>
|
<FrameLayout
|
||||||
|
android:id="@+id/buttonOverlay"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/button"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="@drawable/widget_button_background"
|
||||||
|
/>
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
@@ -58,6 +58,7 @@
|
|||||||
android:maxLines="2"
|
android:maxLines="2"
|
||||||
android:layout_marginTop="4dp"
|
android:layout_marginTop="4dp"
|
||||||
android:layout_marginBottom="4dp"
|
android:layout_marginBottom="4dp"
|
||||||
android:fontFamily="sans-serif-condensed"/>
|
android:fontFamily="sans-serif-condensed"
|
||||||
|
android:breakStrategy="balanced" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
Reference in New Issue
Block a user