Code Monkey home page Code Monkey logo

progressbuttonview's Introduction

ProgressButtonView

Build Status GitHub license

Simple CustomView that shows a Button with a ProgressBar

Installation

Add this line in your app/build.gradle

compile 'es.voghdev.progressbuttonview:ProgressButtonView:1.0.0'

Screenshot

Usage

You can add ProgressButtonView to your XML layouts

<es.voghdev.progressbuttonview.ProgressButtonView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        app:hideButtonWhileLoading="true"
        app:text="@string/hello" />

You can also create it programatically

ProgressButtonView progressButtonView = new ProgressButtonView(context);

Then turn the widget into loading mode, or switch it back to a normal button with:

progressButtonView.showLoading();
progressButtonView.hideLoading();

There are many attributes that you can set to customize its behaviour

app:text="@string/hello"
app:textSize="20sp"
app:textColor="#ff0000"
app:hideButtonWhileLoading="true"
app:backgroundColorResource="@color/my_favorite_background_color"

The full list can be found in the attrs.xml styleable

Screenshot

Experimental

You can find isolation UI Tests for ProgressButtonView in this experimental branch. It uses novoda's espresso-support library. More info can be found in this blogpost

Apps using this lib

Many production apps are actually using this widget. Feel free to add yours by submitting a PR

If you have used this library in your production App, text me and let me know

Developed By

Follow me on Twitter Find me on Linkedin

License

Copyright 2016 Olmo Gallegos Hernández

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Contributing

For noobs (like me some months ago)

fork the project into your GitHub account
now clone your GitHub repo for this project
implement your changes
commit your changes, push them into your repo
review your code and send me a pull request if you consider it

For not-so-noobs

Please make sure that your changes pass both checkstyle and UI tests before submitting them

./gradlew checkstyle

./gradlew test

And with your Android device connected

./gradlew connectedCheck

progressbuttonview's People

Contributors

voghdev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

progressbuttonview's Issues

Rename strings and attrs

Rename R.string.send from strings.xml, and attrs like FullScreen, Element, FullW, to avoid possible clashes with another libraries in android projects.

Assign better-scoped names like ProgressButtonView_send or PBV_send

Expose setBackgroundTintList, setBackgroundTintMode

We need to do:

progressButtonView.setBackgroundTintMode(SRC_IN);
progressButtonView.setBackgroundTintList(colorStateList);

Expose these two methods, or create a public method called tintBackground that calls these two with a resolved color and/or a colorResId (tintBackgroundWithColorResId). Example calls:

progressButtonView.tintBackground(ContextCompat.getColor(ctx, R.color.red));
progressButtonView.tintBackgroundWithColorResId(R.color.red);

Improve nested framelayout using merge tag

ProgressButtonView inherits from FrameLayout, and inside its creation method, it inflates another FrameLayout.
The result is

<FrameLayout>
    <FrameLayout>

use the <merge> tag to improve performance using only one FrameLayout

Remove @string/send from Strings

As long as this is a library, it should not define very common strings like @string/send.

Maybe a customized name like progressButtonView_send or even hardcode the Send message

Alternative ProgressButtonView without merge tag

Maybe there should be a ProgressButtonView subclass that overrides getLayoutId() with a new layout containing its own RelativeLayout root. That should fit some cases like FrameLayouts or ConstraintLayouts

one of our apps demand this feature

Text capitalization

Text appears with AllCaps mode always on.

Please expose some methods to disable text capitalizations, and display lowercase text

setText programatically not taking effect

setBackgroundColor works fine but setText doesn't
Sample code

public void showOrderCompleted(Order order) {
    int color = ContextCompat.getColor(this, R.color.red);
    btnComplete.setBackgroundColor(color);
    btnComplete.setText(R.string.delivered);
}

BackgroundColorResource not working

When there is a backgroundDrawable defined, it overwrites background color resource.
A good solution could be to remove the default background resource.
Or to make the parameter optional in the style method

Instrumentation tests fail because of timing issues

For example, in ViewWithBackgroundColorTest, 1) succeeds but since it takes a while when 2) is executed, the view still has the progressButtonView_tint_mode text.

1) onView(withText(R.string.progressButtonView_tint_mode)).perform(click());
2) onView(withText(R.string.progressButtonView_visibility_response)).check(matches(isDisplayed()));

Simply waiting is enough to make the tests pass.

tintColor without tintMode

users may forget to add the progressBarTintMode attribute when they try to tint the ProgressBar. Maybe a default value like "SRC_ATOP" would make lib usage more intuitive

setTypeface method

Add two setTypeface methods to ProgressButtonView:

public void setTypeface(Typeface tf) {
    button.setTypeface(tf);
}

public void setTypeface(Typeface tf, int style) {
    button.setTypeface(tf, int style);
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.