From 79e14a6ae1c9a3fc7a5f8a4f06ba2feb2fad9d47 Mon Sep 17 00:00:00 2001 From: Alexander Vlasov Date: Tue, 17 May 2016 02:13:24 +0300 Subject: [PATCH] Initial commit --- README.md | 93 +++++++++++++++++++ .../ua/vlasov/likes_layout/MainActivity.java | 55 +++++++++-- app/src/main/res/layout/activity_main.xml | 11 ++- app/src/main/res/values/styles.xml | 4 - library/build.gradle | 1 + .../vlasov/likeslayout/LikesAttributes.java | 20 ++++ .../ua/vlasov/likeslayout/LikesDrawer.java | 13 +-- .../vlasov/likeslayout/LikesFrameLayout.java | 12 ++- .../vlasov/likeslayout/LikesLinearLayout.java | 12 ++- .../likeslayout/LikesRelativeLayout.java | 12 ++- library/src/main/res/values/likes_attrs.xml | 10 +- library/src/main/res/values/public.xml | 4 + library/src/main/res/values/strings.xml | 2 +- 13 files changed, 207 insertions(+), 42 deletions(-) create mode 100644 README.md create mode 100644 library/src/main/res/values/public.xml diff --git a/README.md b/README.md new file mode 100644 index 0000000..3d02432 --- /dev/null +++ b/README.md @@ -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 + + + + + +``` + +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. + +
+## Changelog + +| Version | Changes | +| --- | --- | +| v.1.0.0 | First public release | + +
+## 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. + +
+## 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. \ No newline at end of file diff --git a/app/src/main/java/ua/vlasov/likes_layout/MainActivity.java b/app/src/main/java/ua/vlasov/likes_layout/MainActivity.java index c51c5d0..a7cf47b 100644 --- a/app/src/main/java/ua/vlasov/likes_layout/MainActivity.java +++ b/app/src/main/java/ua/vlasov/likes_layout/MainActivity.java @@ -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)); } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 81b6381..a3c6e98 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -6,6 +6,13 @@ android:layout_height="match_parent" tools:context="ua.vlasov.likes_layout.MainActivity"> + + @@ -31,6 +39,7 @@ android:id="@+id/btn_grade" style="@style/LikeButton.Grade" app:likes_produceInterval="200" + app:likes_tintMode="on_random" /> diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 4f7e924..a550c9e 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -21,16 +21,12 @@ @drawable/ic_favorite @color/colorAccent @drawable/ic_favorite_normal - on_sequence - @array/drawable_colors