Use str4d/android-floating-action-button

pull/281/head
Alex Baker 10 years ago
parent 858fd97798
commit 1c35c38319

@ -89,6 +89,8 @@ dependencies {
compile group: 'com.rubiconproject.oss', name: 'jchronic', version: '0.2.6', transitive: false
compile group: 'org.scala-saddle', name: 'google-rfc-2445', version: '20110304', transitive: false
compile group: 'net.i2p.android.ext', name: 'floatingactionbutton', version: '1.8.0'
compile(group: 'com.google.apis', name: 'google-api-services-tasks', version: 'v1-rev33-1.18.0-rc') {
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
}

@ -1,93 +0,0 @@
package com.faizmalkani.floatingactionbutton;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import org.tasks.R;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastHoneycomb;
public class FloatingActionButton extends View {
private final Paint mButtonPaint = new Paint(Paint.ANTI_ALIAS_FLAG) {{
setStyle(Style.FILL);
}};
private final Paint mButtonPaintStroke = new Paint(Paint.ANTI_ALIAS_FLAG) {{
setStyle(Style.STROKE);
}};
private final Paint mDrawablePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
private Bitmap mBitmap;
private int tint;
private int stroke;
public FloatingActionButton(Context context) {
this(context, null);
}
public FloatingActionButton(Context context, AttributeSet attributeSet) {
this(context, attributeSet, 0);
}
public FloatingActionButton(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.FloatingActionButton);
tint = a.getColor(R.styleable.FloatingActionButton_tint, Color.WHITE);
stroke = a.getColor(R.styleable.FloatingActionButton_stroke, Color.TRANSPARENT);
mButtonPaint.setColor(tint);
mButtonPaintStroke.setColor(stroke);
mButtonPaint.setShadowLayer(
a.getFloat(R.styleable.FloatingActionButton_shadowRadius, 10.0f),
a.getFloat(R.styleable.FloatingActionButton_shadowDx, 0.0f),
a.getFloat(R.styleable.FloatingActionButton_shadowDy, 3.5f),
a.getInteger(R.styleable.FloatingActionButton_shadowColor, Color.argb(100, 0, 0, 0)));
Drawable drawable = a.getDrawable(R.styleable.FloatingActionButton_drawable);
if (null != drawable) {
mBitmap = ((BitmapDrawable) drawable).getBitmap();
}
setWillNotDraw(false);
if (atLeastHoneycomb()) {
setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
}
private static int darkenColor(int color) {
float[] hsv = new float[3];
Color.colorToHSV(color, hsv);
hsv[2] *= 0.8f;
return Color.HSVToColor(hsv);
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawCircle(getWidth() / 2, getHeight() / 2, (float) (getWidth() / 2.6), mButtonPaint);
canvas.drawCircle(getWidth() / 2, getHeight() / 2, (float) (getWidth() / 2.6), mButtonPaintStroke);
if (null != mBitmap) {
canvas.drawBitmap(mBitmap, (getWidth() - mBitmap.getWidth()) / 2,
(getHeight() - mBitmap.getHeight()) / 2, mDrawablePaint);
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
int color;
if (event.getAction() == MotionEvent.ACTION_UP) {
color = tint;
} else {
color = darkenColor(tint);
}
mButtonPaint.setColor(color);
invalidate();
return super.onTouchEvent(event);
}
}

@ -34,7 +34,6 @@ import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import com.faizmalkani.floatingactionbutton.FloatingActionButton;
import com.todoroo.andlib.data.Property;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.sql.Criterion;
@ -274,8 +273,7 @@ public class TaskListFragment extends InjectingListFragment implements OnSortSel
Bundle savedInstanceState) {
ViewGroup parent = (ViewGroup) getActivity().getLayoutInflater().inflate(
R.layout.task_list_activity, container, false);
FloatingActionButton fab = (FloatingActionButton) parent.findViewById(R.id.fab);
fab.setOnClickListener(new OnClickListener() {
parent.findViewById(R.id.fab).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (ActivityPreferences.isTabletSized(context)) {

@ -3,9 +3,8 @@
**
** See the file "LICENSE" for the full license governing this code.
-->
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tasks="http://schemas.android.com/apk/res-auto"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:id="@+id/taskListParent"
android:background="?attr/asContentBackground"
android:layout_width="fill_parent"
@ -17,15 +16,19 @@
<!-- Body goes here -->
<com.faizmalkani.floatingactionbutton.FloatingActionButton
<net.i2p.android.ext.floatingactionbutton.AddFloatingActionButton
android:id="@+id/fab"
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_gravity="end|bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
fab:fab_colorNormal="?attr/fab_background"
fab:fab_colorPressed="?attr/fab_background_pressed"
fab:fab_plusIconColor="?attr/fab_plus"
fab:fab_stroke_visible="false"
android:layout_marginBottom="16dp"
android:layout_marginRight="16dp"
tasks:drawable="?attr/ic_action_add"
tasks:tint="?attr/asAbBackgroundColor"
tasks:stroke="?attr/floatingActionButtonStroke"/>
android:layout_marginEnd="16dp" />
</FrameLayout>
</RelativeLayout>

@ -52,18 +52,12 @@
<attr name="drawer_text" format="color"/>
<attr name="importance_background_selected" format="reference"/>
<attr name="asFilterRowSelected" format="reference"/>
<attr name="fab_background" format="color" />
<attr name="fab_background_pressed" format="color" />
<attr name="fab_plus" format="color" />
<declare-styleable name="DateAndTimePicker">
<attr name="shortcutLabels" format="reference"/>
</declare-styleable>
<declare-styleable name="FloatingActionButton">
<attr name="drawable" format="integer"/>
<attr name="tint" format="color"/>
<attr name="stroke" format="color" />
<attr name="shadowRadius" format="float"/>
<attr name="shadowDx" format="float"/>
<attr name="shadowDy" format="float"/>
<attr name="shadowColor" format="integer"/>
</declare-styleable>
</resources>

@ -67,6 +67,10 @@
<item name="ic_action_reload">@drawable/ic_action_reload</item>
<item name="ic_action_calendar_month">@drawable/ic_action_calendar_month</item>
<item name="ic_action_help">@drawable/ic_action_help</item>
<item name="fab_background">?attr/asAbBackgroundColor</item>
<item name="fab_background_pressed">#476472</item>
<item name="fab_plus">@android:color/white</item>
</style>
<style name="Tasks.Dark">
@ -100,6 +104,10 @@
<item name="ic_action_calendar_month">@drawable/ic_action_calendar_month_white</item>
<item name="ic_action_help">@drawable/ic_action_help_white</item>
<item name="asDueDateColor">#c3c3c3</item>
<item name="fab_background">@android:color/white</item>
<item name="fab_background_pressed">#e6e6e6</item>
<item name="fab_plus">@android:color/black</item>
</style>
<style name="TasksDialog" parent="@android:style/Theme.Dialog">

Loading…
Cancel
Save