-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
207 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
## Setup and usage | ||
|
||
To include this library to your project add dependency in **build.gradle** file: | ||
|
||
```groovy | ||
dependencies { | ||
compile '$coming_soon$' | ||
} | ||
``` | ||
|
||
There are three implementations of LikesLayout: **LikesFrameLayout**, **LikesLinearLayout**, **LikesRelativeLayout**. | ||
|
||
```XML | ||
<ua.vlasov.likeslayout.LikesLinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="250dp" | ||
app:likes_drawable="drawable resource id" | ||
app:likes_drawableWidth="custom drawable width" | ||
app:likes_drawableHeight="custom drawable height" | ||
app:likes_produceInterval="produce interval in milliseconds" | ||
app:likes_animationDuration="animationduration in milliseconds" | ||
app:likes_tintMode="off|on_successively|on_random" | ||
app:likes_tintColors="array resource id" | ||
> | ||
|
||
<ImageButton | ||
... | ||
app:likes_drawable="drawable resource id" | ||
app:likes_drawableWidth="custom drawable width" | ||
app:likes_drawableHeight="custom drawable height" | ||
app:likes_mode="enabled|disabled" | ||
app:likes_produceInterval="produce interval in milliseconds" | ||
app:likes_animationDuration="animationduration in milliseconds" | ||
app:likes_tintMode="off|on_successively|on_random" | ||
app:likes_tintColors="array resource id" | ||
/> | ||
|
||
</ua.vlasov.likeslayout.LikesLinearLayout> | ||
``` | ||
|
||
There are the list of available attributes: | ||
|
||
| Attribute name | Applicable to LikesLayout? | Can be overridden by child? | Description | Default value | | ||
|--|--|--|--|--| | ||
| likes_animationDuration | yes | yes | Animation duration in milliseconds. | 1200 | | ||
| likes_drawable | yes | yes | Drawable that will be drawn when user presses view. | n/a | | ||
| likes_drawableWidth | yes | yes | Custom drawable width. | 0 | | ||
| likes_drawableHeight | yes | yes | Custom drawable height. | 0 | | ||
| likes_mode | no | yes | Switch that allows to enable/disable drawing likes on touching child view. If `likes_drawable` is null, `likes_mode` will be considered as `disabled`. | disabled | | ||
| likes_produceInterval | yes | yes | Rate at which new likes drawables are produced in milliseconds. | 300 | | ||
| likes_tintMode | yes | yes | Switch that allows to enable/disable tinting drawables. | not_set | | ||
| likes_tintColors | yes | yes | Array of colors used for tinting drawables. If array is empty, `likes_tintMode` will be considered as `off`.| n/a | | ||
|
||
###### Restrictions: | ||
* If you will not set `likes_mode` or set it to `disabled`, this view will not draw any likes on touch event. | ||
* All attributes applicable to LikesLayout will be used as default values for child with `likes_mode` set to `enabled`. | ||
* Custom drawable width and height will set exact size ignoring aspect ratio. | ||
* Likes floating from bottom to top. | ||
|
||
<br /> | ||
## Changelog | ||
|
||
| Version | Changes | | ||
| --- | --- | | ||
| v.1.0.0 | First public release | | ||
|
||
<br /> | ||
## Support | ||
|
||
You can support this library by creating a pull request with bug fixes and/or new features on `develop` branch. Any pull requests on `master` branch will be removed. | ||
|
||
<br /> | ||
## License | ||
* * * | ||
The MIT License (MIT) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
55 changes: 45 additions & 10 deletions
55
app/src/main/java/ua/vlasov/likes_layout/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,79 @@ | ||
package ua.vlasov.likes_layout; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.view.Gravity; | ||
import android.view.View; | ||
import android.widget.Toast; | ||
import android.widget.TextView; | ||
|
||
import java.util.Locale; | ||
|
||
import ua.vlasov.likeslayout.LikesLinearLayout; | ||
import ua.vlasov.likeslayout.OnChildTouchListener; | ||
|
||
public class MainActivity extends AppCompatActivity implements OnChildTouchListener { | ||
|
||
private Toast mToast; | ||
private TextView mStatus; | ||
private int mFavoriteCounter; | ||
private int mGradeCounter; | ||
private int mStarsCounter; | ||
|
||
@SuppressLint("ShowToast") | ||
@SuppressWarnings("ConstantConditions") | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
mToast = Toast.makeText(this, "", Toast.LENGTH_SHORT); | ||
mToast.setGravity(Gravity.TOP, 0, (int) (getResources().getDisplayMetrics().density * 56)); | ||
mStatus = (TextView) findViewById(R.id.status); | ||
final LikesLinearLayout likesLayout = ((LikesLinearLayout) findViewById(R.id.likes_layout)); | ||
likesLayout.setOnChildTouchListener(this); | ||
updateStatus(); | ||
} | ||
|
||
@Override | ||
public void onChildTouched(View child) { | ||
mToast.setText(String.format("touched: %s", getResources().getResourceEntryName(child.getId()))); | ||
mToast.show(); | ||
switch (child.getId()) { | ||
case R.id.btn_favorite: { | ||
mFavoriteCounter = 0; | ||
break; | ||
} | ||
case R.id.btn_grade: { | ||
mGradeCounter = 0; | ||
break; | ||
} | ||
case R.id.btn_stars: { | ||
mStarsCounter = 0; | ||
break; | ||
} | ||
} | ||
updateStatus(); | ||
} | ||
|
||
@Override | ||
public void onLikeProduced(View child) { | ||
// do something here | ||
switch (child.getId()) { | ||
case R.id.btn_favorite: { | ||
mFavoriteCounter++; | ||
break; | ||
} | ||
case R.id.btn_grade: { | ||
mGradeCounter++; | ||
break; | ||
} | ||
case R.id.btn_stars: { | ||
mStarsCounter++; | ||
break; | ||
} | ||
} | ||
updateStatus(); | ||
} | ||
|
||
@Override | ||
public void onChildReleased(View child, boolean isCanceled) { | ||
mToast.cancel(); | ||
updateStatus(); | ||
} | ||
|
||
private void updateStatus() { | ||
mStatus.setText(String.format(Locale.US, "Counter. favorites: %1$d, grades: %2$d, stars: %3$d", | ||
mFavoriteCounter, mGradeCounter, mStarsCounter)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.