ScaleTouchListener

Additional

Language
Java
Version
1.0.0 (Jul 21, 2018)
Created
Jul 17, 2018
Updated
Oct 28, 2018
Owner
Mahmoud Jafarinejad (mjn1369)
Contributor
Mahmoud Jafarinejad (mjn1369)
1
Activity
Badge
Generate
Download
Source code
APK file

Blurb

ScaleTouchListener

ScaleTouchListener

ScaleTouchListener is an Android library that makes your view to scale down (and also fade down) on touch press and scales it back up on touch being released. It also includes a click listener in case the touch releases inside the view (without leaving it).

Download

Gradle:

Add the following to your project level build.gradle:

allprojects {
   repositories {
      maven { url "https://jitpack.io" }
   }
}

Add this to your app build.gradle:

dependencies {
   compile 'com.github.mjn1369:ScaleTouchListener:1.0.0'
}

Usage

Default Settings

fabHeart.setOnTouchListener(new ScaleTouchListener() {
            @Override
            public void onClick(View v) {
                //OnClickListener
                Toast.makeText(mContext,"Heart",Toast.LENGTH_SHORT).show();
            }
        });

Custom Settings

//create custom config object
ScaleTouchListener.Config config = new ScaleTouchListener.Config(
                        300,    // Duration
                        0.75f,  // ScaleDown
                        0.75f); // Alpha
                        
fabHeart.setOnTouchListener(new ScaleTouchListener(config) {     // <--- pass config object
            @Override
            public void onClick(View v) {
                //OnClickListener
                Toast.makeText(MainActivity.this, "Heart", Toast.LENGTH_SHORT).show();
            }
        });

Config Attributes

Attribute Description Default
Duration (int) The whole shebang's duration 100 (milliseconds)
ScaleDown (float) ScaleDown value between 0.0f and 1.0f 0.9f
Alpha (float) Alpha degree value 0.0f and 1.0f 0.4f

cheers 🍻

License

Copyright 2018 mjn1369

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.