Full Code of amarjain07/StickyScrollView for AI

master 763d5ae111b0 cached
43 files
51.1 KB
13.7k tokens
8 symbols
1 requests
Download .txt
Repository: amarjain07/StickyScrollView
Branch: master
Commit: 763d5ae111b0
Files: 43
Total size: 51.1 KB

Directory structure:
gitextract_ikmcfygz/

├── .gitignore
├── LICENSE
├── README.md
├── build.gradle
├── dependencies.gradle
├── gradle/
│   └── wrapper/
│       ├── gradle-wrapper.jar
│       └── gradle-wrapper.properties
├── gradle.properties
├── gradlew
├── gradlew.bat
├── jitpack.yml
├── library/
│   ├── build.gradle
│   ├── proguard-rules.pro
│   ├── publish.gradle
│   └── src/
│       ├── androidTest/
│       │   └── java/
│       │       └── com/
│       │           └── amar/
│       │               └── library/
│       │                   └── ExampleInstrumentedTest.java
│       ├── main/
│       │   ├── AndroidManifest.xml
│       │   ├── java/
│       │   │   └── com/
│       │   │       └── amar/
│       │   │           └── library/
│       │   │               ├── provider/
│       │   │               │   ├── ResourceProvider.kt
│       │   │               │   ├── ScreenInfoProvider.kt
│       │   │               │   └── interfaces/
│       │   │               │       ├── IResourceProvider.kt
│       │   │               │       └── IScreenInfoProvider.kt
│       │   │               └── ui/
│       │   │                   ├── PropertySetter.kt
│       │   │                   ├── StickyScrollView.kt
│       │   │                   ├── interfaces/
│       │   │                   │   └── IScrollViewListener.kt
│       │   │                   ├── presentation/
│       │   │                   │   └── IStickyScrollPresentation.kt
│       │   │                   └── presenter/
│       │   │                       └── StickyScrollPresenter.kt
│       │   └── res/
│       │       └── values/
│       │           ├── attrs.xml
│       │           └── strings.xml
│       └── test/
│           └── java/
│               └── com/
│                   └── amar/
│                       └── library/
│                           └── ExampleUnitTest.java
├── sample/
│   ├── build.gradle
│   ├── proguard-rules.pro
│   └── src/
│       ├── androidTest/
│       │   └── java/
│       │       └── com/
│       │           └── amar/
│       │               └── sample/
│       │                   └── ExampleInstrumentedTest.java
│       ├── main/
│       │   ├── AndroidManifest.xml
│       │   ├── java/
│       │   │   └── com/
│       │   │       └── amar/
│       │   │           └── sample/
│       │   │               ├── MainActivity.kt
│       │   │               ├── PageFragment.kt
│       │   │               └── ViewPagerActivity.kt
│       │   └── res/
│       │       ├── layout/
│       │       │   ├── activity_main.xml
│       │       │   ├── activity_view_pager.xml
│       │       │   └── view_page.xml
│       │       └── values/
│       │           ├── colors.xml
│       │           ├── strings.xml
│       │           └── styles.xml
│       └── test/
│           └── java/
│               └── com/
│                   └── amar/
│                       └── sample/
│                           └── ExampleUnitTest.java
└── settings.gradle

================================================
FILE CONTENTS
================================================

================================================
FILE: .gitignore
================================================
.idea/
# Built application files
*.apk
*.ap_

# Files for the ART/Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/
out/

# Gradle files
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log

# Android Studio Navigation editor temp files
.navigation/

# Android Studio captures folder
captures/

# Intellij
*.iml
.idea/workspace.xml

# Keystore files
*.jks


================================================
FILE: LICENSE
================================================
MIT License

Copyright (c) 2017 Amar Jain

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.


================================================
FILE: README.md
================================================
# StickyScrollView
Sticky header and footer for android ScrollView.

[![](https://jitpack.io/v/amarjain07/StickyScrollView.svg)](https://jitpack.io/#amarjain07/StickyScrollView)

### Install

Add jitpack to your root's `build.gradle`
```groovy
allprojects {
    repositories {
	    maven { url "https://jitpack.io" }
	}
}
```

Add the dependency
```groovy
dependencies {
    implementation 'com.github.amarjain07:StickyScrollView:<latest-version>'
}
```

### Usage
```xml
<?xml version="1.0" encoding="utf-8"?>
<com.amar.library.ui.StickyScrollView
    android:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:stickyHeader="@+id/title"
    app:stickyFooter="@+id/buttons">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <LinearLayout
            android:id="@+id/title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/white"
            android:orientation="vertical"
            android:padding="15dp">
            ...
        </LinearLayout>
        <LinearLayout
            android:id="@+id/buttons"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            ...
        </LinearLayout>
    </LinearLayout>
</com.amar.library.ui.StickyScrollView>
```

### Demo
![StickyScrollViewGif](demo/StickyScroll.gif)

License
-------

    MIT License

    Copyright (c) 2017 Amar Jain

    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.


================================================
FILE: build.gradle
================================================
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    apply from: 'dependencies.gradle'

    repositories {
        mavenCentral()
        google()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:$gradlePluginVersion"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
    }
}

allprojects {
    repositories {
        mavenCentral()
        google()
        maven { url 'https://jitpack.io' }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

================================================
FILE: dependencies.gradle
================================================
ext {
    gradlePluginVersion = '7.0.4'
    projectMinSdkVersion = 16
    compileVersionSdk = 30
    targetSdkVersion = compileVersionSdk
    projectVersionCode = 1
    projectVersionName = "0.0.1"

    kotlinVersion = '1.6.10'
    kotlinSdk = "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"

    androidXCoreVersion = '1.3.2'
    androidXVersion = '1.1.0'
    androidXCompatVersion = '1.2.0'
    androidXConstraintLayoutVersion = '2.0.4'
    androidXMultidexVersion = '2.0.0'
    androidSupportV4Version = "1.0.0"
    droid = [
            androidSupportV4        : "androidx.legacy:legacy-support-v4:$androidSupportV4Version",
            androidCardview         : "androidx.cardview:cardview:$androidSupportV4Version",
            fragment                : "androidx.fragment:fragment:$androidSupportV4Version",

            androidAppCompatV7      : "androidx.appcompat:appcompat:$androidXCompatVersion",
            coreX                   : "androidx.core:core-ktx:$androidXCoreVersion",

            androidDesign           : "com.google.android.material:material:$androidXVersion",
            androidRecyclerview     : "androidx.recyclerview:recyclerview:$androidXVersion",
            androidSupportAnnotation: "androidx.annotation:annotation:$androidXVersion",
            
            androidConstraint       : "androidx.constraintlayout:constraintlayout:$androidXConstraintLayoutVersion",
            androidMultidex         : "androidx.multidex:multidex:$androidXMultidexVersion",
            databinding             : "androidx.databinding:databinding-common:$gradlePluginVersion",
            databindingBase         : "androidx.databinding:databinding-runtime:$gradlePluginVersion"
    ]

    // Only include dependencies to be added to the library/AAR
    internalLibs = [
            androidAppCompatV7      : "androidx.appcompat:appcompat:$androidXCompatVersion",
            coreX                   : "androidx.core:core-ktx:$androidXCoreVersion"
    ]

    daggerVersion = '2.29.1'
    di = [
            dagger       : "com.google.dagger:dagger:$daggerVersion",
            daggerAndroid: "com.google.dagger:dagger-android-support:$daggerVersion"
    ]

    glideVersion = "4.12.0"
    externalLibs = [
            glide        : "com.github.bumptech.glide:glide:$glideVersion"
    ]

    kaptLibs = [
            daggerCompiler        : "com.google.dagger:dagger-compiler:$daggerVersion",
            daggerAndroidProcessor: "com.google.dagger:dagger-android-processor:$daggerVersion",
            glideProcessor        : "com.github.bumptech.glide:compiler:$glideVersion"
    ]

    junit5 = "5.6.2"
    mockitoVersion = "3.2.4"
    mockitoKotlinVersion = "1.6.0"
    archCoreTesting = "2.1.0"
    testLibs = [
            junitJupiterApi   : "org.junit.jupiter:junit-jupiter-api:$junit5",
            junitJupiterEngine: "org.junit.jupiter:junit-jupiter-engine:$junit5",
            junitJupiterParams: "org.junit.jupiter:junit-jupiter-params:$junit5",
            mockito           : "org.mockito:mockito-core:$mockitoVersion",
            mokitoKotlin      : "com.nhaarman:mockito-kotlin:$mockitoKotlinVersion",
            coreTesting       : "androidx.arch.core:core-testing:$archCoreTesting"
    ]
    mockitoAndroid = "org.mockito:mockito-android:" + mockitoVersion

    espressoVersion = "3.2.0"
    testVersion = "1.2.0"
    junitTestVersion = "1.1.1"
    mockWebServerVersion = "3.12.1"
    idlingResourceVersion = "1.0.0"
    uiTestLibs = [
            espressoCore   : "androidx.test.espresso:espresso-core:$espressoVersion",
            espressoContrib: "androidx.test.espresso:espresso-contrib:$espressoVersion",
            espressoIntents: "androidx.test.espresso:espresso-intents:$espressoVersion",
            testRunner     : "androidx.test:runner:$testVersion",
            testRules      : "androidx.test:rules:$testVersion",
            junitTest      : "androidx.test.ext:junit:$junitTestVersion",
            mockWebServer  : "com.squareup.okhttp3:mockwebserver:$mockWebServerVersion",
            idlingResource : "com.jakewharton.espresso:okhttp3-idling-resource:$idlingResourceVersion"
    ]
}

================================================
FILE: gradle/wrapper/gradle-wrapper.properties
================================================
#Thu Jul 09 18:59:02 IST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip


================================================
FILE: gradle.properties
================================================
android.enableJetifier=true
android.useAndroidX=true

================================================
FILE: gradlew
================================================
#!/usr/bin/env bash

##############################################################################
##
##  Gradle start up script for UN*X
##
##############################################################################

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""

APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

warn ( ) {
    echo "$*"
}

die ( ) {
    echo
    echo "$*"
    echo
    exit 1
}

# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
  CYGWIN* )
    cygwin=true
    ;;
  Darwin* )
    darwin=true
    ;;
  MINGW* )
    msys=true
    ;;
esac

# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
    ls=`ls -ld "$PRG"`
    link=`expr "$ls" : '.*-> \(.*\)$'`
    if expr "$link" : '/.*' > /dev/null; then
        PRG="$link"
    else
        PRG=`dirname "$PRG"`"/$link"
    fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar

# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
        # IBM's JDK on AIX uses strange locations for the executables
        JAVACMD="$JAVA_HOME/jre/sh/java"
    else
        JAVACMD="$JAVA_HOME/bin/java"
    fi
    if [ ! -x "$JAVACMD" ] ; then
        die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
    fi
else
    JAVACMD="java"
    which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi

# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
    MAX_FD_LIMIT=`ulimit -H -n`
    if [ $? -eq 0 ] ; then
        if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
            MAX_FD="$MAX_FD_LIMIT"
        fi
        ulimit -n $MAX_FD
        if [ $? -ne 0 ] ; then
            warn "Could not set maximum file descriptor limit: $MAX_FD"
        fi
    else
        warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
    fi
fi

# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
    GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi

# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
    APP_HOME=`cygpath --path --mixed "$APP_HOME"`
    CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
    JAVACMD=`cygpath --unix "$JAVACMD"`

    # We build the pattern for arguments to be converted via cygpath
    ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
    SEP=""
    for dir in $ROOTDIRSRAW ; do
        ROOTDIRS="$ROOTDIRS$SEP$dir"
        SEP="|"
    done
    OURCYGPATTERN="(^($ROOTDIRS))"
    # Add a user-defined pattern to the cygpath arguments
    if [ "$GRADLE_CYGPATTERN" != "" ] ; then
        OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
    fi
    # Now convert the arguments - kludge to limit ourselves to /bin/sh
    i=0
    for arg in "$@" ; do
        CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
        CHECK2=`echo "$arg"|egrep -c "^-"`                                 ### Determine if an option

        if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then                    ### Added a condition
            eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
        else
            eval `echo args$i`="\"$arg\""
        fi
        i=$((i+1))
    done
    case $i in
        (0) set -- ;;
        (1) set -- "$args0" ;;
        (2) set -- "$args0" "$args1" ;;
        (3) set -- "$args0" "$args1" "$args2" ;;
        (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
        (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
        (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
        (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
        (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
        (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
    esac
fi

# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
    JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"

exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"


================================================
FILE: gradlew.bat
================================================
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem  Gradle startup script for Windows
@rem
@rem ##########################################################################

@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto init

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:init
@rem Get command-line arguments, handling Windowz variants

if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args

:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2

:win9xME_args_slurp
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*
goto execute

:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if  not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1

:mainEnd
if "%OS%"=="Windows_NT" endlocal

:omega


================================================
FILE: jitpack.yml
================================================
jdk:
  - openjdk11

================================================
FILE: library/build.gradle
================================================
plugins {
    id 'com.android.library'
    id 'kotlin-android'
}
apply from: 'publish.gradle'

android {
    compileSdkVersion compileVersionSdk

    defaultConfig {
        minSdkVersion projectMinSdkVersion
        targetSdkVersion targetSdkVersion

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        consumerProguardFiles 'consumer-rules.pro'
        vectorDrawables.useSupportLibrary = true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation kotlinSdk
    internalLibs.values().forEach { implementation it }
    testLibs.values().forEach { testImplementation it }
    uiTestLibs.values().forEach { androidTestImplementation it }
}

================================================
FILE: library/proguard-rules.pro
================================================
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/m02256/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile


================================================
FILE: library/publish.gradle
================================================
apply plugin: 'maven-publish'

afterEvaluate {
    publishing {
        publications {
            release(MavenPublication) {
                from components.release
                groupId = 'weekend.coder'
                artifactId = 'sticky-scrollview'
                version = '1.0.4'
            }
        }
    }
}

================================================
FILE: library/src/androidTest/java/com/amar/library/ExampleInstrumentedTest.java
================================================
package com.amar.library;

import android.content.Context;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
 * Instrumentation test, which will execute on an Android device.
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
    @Test
    public void useAppContext() throws Exception {
        // Context of the app under test.
        Context appContext = InstrumentationRegistry.getTargetContext();

        assertEquals("com.amar.library.test", appContext.getPackageName());
    }
}


================================================
FILE: library/src/main/AndroidManifest.xml
================================================
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.amar.library" />


================================================
FILE: library/src/main/java/com/amar/library/provider/ResourceProvider.kt
================================================
package com.amar.library.provider

import android.content.Context
import android.util.AttributeSet
import androidx.annotation.StyleableRes
import androidx.core.content.res.use
import com.amar.library.provider.interfaces.IResourceProvider

internal class ResourceProvider(private val context: Context, private val attrs: AttributeSet?, @StyleableRes private val styleRes: IntArray) :
    IResourceProvider {
    override fun getResourcesByIds(@StyleableRes vararg styleResIds: Int): Array<Int> {
        context.obtainStyledAttributes(attrs, styleRes).use { typedArray ->
            return mutableListOf<Int>().apply {
                styleResIds.forEach { styleResId -> add(typedArray.getResourceId(styleResId, 0)) }
            }.toTypedArray()
        }
    }
}

================================================
FILE: library/src/main/java/com/amar/library/provider/ScreenInfoProvider.kt
================================================
package com.amar.library.provider

import android.content.Context
import android.graphics.Point
import com.amar.library.provider.interfaces.IScreenInfoProvider

internal class ScreenInfoProvider(private val mContext: Context) : IScreenInfoProvider {
    private val deviceDimension: Point
        get() {
            val lPoint = Point()
            val metrics = mContext.resources.displayMetrics
            lPoint.x = metrics.widthPixels
            lPoint.y = metrics.heightPixels
            return lPoint
        }
    override val screenHeight: Int
        get() = deviceDimension.y
    override val screenWidth: Int
        get() = deviceDimension.x

    override val navigationBarHeight: Int
        get() {
            val resourceId: Int =
                mContext.resources.getIdentifier("navigation_bar_height", "dimen", "android")
            return if (resourceId > 0) {
                mContext.resources.getDimensionPixelSize(resourceId)
            } else 0
        }
}

================================================
FILE: library/src/main/java/com/amar/library/provider/interfaces/IResourceProvider.kt
================================================
package com.amar.library.provider.interfaces

import androidx.annotation.StyleableRes

internal interface IResourceProvider {
    fun getResourcesByIds(@StyleableRes vararg styleResId: Int): Array<Int>
}

================================================
FILE: library/src/main/java/com/amar/library/provider/interfaces/IScreenInfoProvider.kt
================================================
package com.amar.library.provider.interfaces

internal interface IScreenInfoProvider {
    val screenHeight: Int
    val screenWidth: Int
    val navigationBarHeight: Int
}

================================================
FILE: library/src/main/java/com/amar/library/ui/PropertySetter.kt
================================================
package com.amar.library.ui

import android.os.Build
import android.view.View
import androidx.core.view.ViewCompat

internal object PropertySetter {
    fun setTranslationZ(view: View?, translationZ: Float) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            view?.let {
                ViewCompat.setTranslationZ(it, translationZ)
            }
        } else if (translationZ != 0f) {
            view?.bringToFront()
            if (view?.parent != null) {
                (view.parent as View).invalidate()
            }
        }
    }
}

================================================
FILE: library/src/main/java/com/amar/library/ui/StickyScrollView.kt
================================================
package com.amar.library.ui

import android.content.Context
import android.os.Build
import android.os.Bundle
import android.os.Parcelable
import android.util.AttributeSet
import android.view.View
import androidx.annotation.IdRes
import androidx.core.widget.NestedScrollView
import com.amar.library.R
import com.amar.library.provider.ResourceProvider
import com.amar.library.provider.ScreenInfoProvider
import com.amar.library.provider.interfaces.IResourceProvider
import com.amar.library.provider.interfaces.IScreenInfoProvider
import com.amar.library.ui.interfaces.IScrollViewListener
import com.amar.library.ui.presentation.IStickyScrollPresentation
import com.amar.library.ui.presenter.StickyScrollPresenter
import android.view.ViewTreeObserver.OnGlobalLayoutListener as OnGlobalLayoutListener1

class StickyScrollView @JvmOverloads constructor(
    context: Context,
    attributeSet: AttributeSet? = null,
    defStyleAttr: Int = 0
) : NestedScrollView(context, attributeSet, defStyleAttr) {
    private var scrollViewListener: IScrollViewListener? = null
    private var stickyFooterView: View? = null
    private var stickyHeaderView: View? = null
    private var mStickyScrollPresenter: StickyScrollPresenter

    init {
        val screenInfoProvider: IScreenInfoProvider = ScreenInfoProvider(context)
        val resourceProvider: IResourceProvider =
            ResourceProvider(context, attributeSet, R.styleable.StickyScrollView)
        mStickyScrollPresenter = StickyScrollPresenter(StickyScrollPresentation(), screenInfoProvider, resourceProvider)
        onLayoutUpdate {
            mStickyScrollPresenter.onGlobalLayoutChange(
                R.styleable.StickyScrollView_stickyHeader,
                R.styleable.StickyScrollView_stickyFooter
            )
        }
    }

    override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {
        super.onLayout(changed, l, t, r, b)
        if (!changed) {
            mStickyScrollPresenter.recomputeFooterLocation(getFooterTop())
        }
        stickyHeaderView?.let {
            mStickyScrollPresenter.recomputeHeaderLocation(it.top)
        }
    }

    override fun onScrollChanged(mScrollX: Int, mScrollY: Int, oldX: Int, oldY: Int) {
        super.onScrollChanged(mScrollX, mScrollY, oldX, oldY)
        mStickyScrollPresenter.onScroll(mScrollY)
        scrollViewListener?.onScrollChanged(mScrollX, mScrollY, oldX, oldY)
    }

    override fun onOverScrolled(scrollX: Int, scrollY: Int, clampedX: Boolean, clampedY: Boolean) {
        super.onOverScrolled(scrollX, scrollY, clampedX, clampedY)
        scrollViewListener?.onScrollStopped(clampedY)
    }

    override fun onSaveInstanceState(): Parcelable {
        val bundle = Bundle()
        bundle.putParcelable(STATE_SUPER, super.onSaveInstanceState())
        bundle.putBoolean(STATE_SCROLL, mStickyScrollPresenter.mScrolled)
        bundle.putInt(STATE_NAV_BAR_HEIGHT, mStickyScrollPresenter.mNavigationBarInitialHeight)
        return bundle
    }

    override fun onRestoreInstanceState(state: Parcelable) {
        if (state is Bundle) {
            mStickyScrollPresenter.mNavigationBarInitialHeight = state.getInt(STATE_NAV_BAR_HEIGHT)
            mStickyScrollPresenter.mScrolled = state.getBoolean(STATE_SCROLL)
            super.onRestoreInstanceState(state.getParcelable(STATE_SUPER))
            return
        }
        super.onRestoreInstanceState(state)
    }

    val isFooterSticky: Boolean
        get() = mStickyScrollPresenter.isFooterSticky
    val isHeaderSticky: Boolean
        get() = mStickyScrollPresenter.isHeaderSticky

    fun setHeaderView(@IdRes id: Int) {
        stickyHeaderView = findViewById(id)
        stickyHeaderView?.onLayoutUpdate { initialiseHeader() }
    }

    fun setFooterView(@IdRes id: Int) {
        stickyFooterView = findViewById(id)
        stickyFooterView?.onLayoutUpdate { initialiseFooter() }
    }

    fun setScrollViewListener(scrollViewListener: IScrollViewListener) {
        this.scrollViewListener = scrollViewListener
    }

    private fun initialiseHeader(){
        mStickyScrollPresenter.initStickyHeader(stickyHeaderView?.top)
    }

    private fun initialiseFooter(){
        mStickyScrollPresenter.initStickyFooter(
            stickyFooterView?.measuredHeight,
            getFooterTop()
        )
    }

    private fun getRelativeTop(myView: View): Int {
        return if (myView.parent === myView.rootView) {
            myView.top
        } else {
            myView.top + getRelativeTop(myView.parent as View)
        }
    }

    private fun getFooterTop(): Int {
        return stickyFooterView?.let {
            return getRelativeTop(it) - it.topCutOutHeight()
        } ?: 0
    }

    private inner class StickyScrollPresentation: IStickyScrollPresentation {
        override val currentScrollYPos: Int
            get() = scrollY

        override fun freeHeader() {
            stickyHeaderView?.let {
                it.translationY = 0f
                PropertySetter.setTranslationZ(it, 0f)
            }
        }

        override fun freeFooter() {
            stickyFooterView?.translationY = 0f
        }

        override fun stickHeader(translationY: Int) {
            stickyHeaderView?.let {
                it.translationY = translationY.toFloat()
                PropertySetter.setTranslationZ(it, 1f)
            }
        }

        override fun stickFooter(translationY: Int) {
            stickyFooterView?.translationY = translationY.toFloat()
        }

        override fun initHeaderView(@IdRes id: Int) {
            stickyHeaderView = findViewById(id)
            stickyHeaderView?.post { initialiseHeader() }
        }

        override fun initFooterView(@IdRes id: Int) {
            stickyFooterView = findViewById(id)
            stickyFooterView?.post { initialiseFooter() }
        }
    }

    private fun View.topCutOutHeight(): Int {
        return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            rootWindowInsets.displayCutout?.safeInsetTop ?: 0
        } else {
            0
        }
    }

    private fun View.onLayoutUpdate(action: () -> Unit) {
        viewTreeObserver.addOnGlobalLayoutListener(object : OnGlobalLayoutListener1 {
            override fun onGlobalLayout() {
                action.invoke()
                viewTreeObserver.removeOnGlobalLayoutListener(this)
            }
        })
    }

    companion object {
        private const val STATE_SCROLL = "scroll_state"
        private const val STATE_SUPER = "super_state"
        private const val STATE_NAV_BAR_HEIGHT = "nav_bar_height_state"
    }
}

================================================
FILE: library/src/main/java/com/amar/library/ui/interfaces/IScrollViewListener.kt
================================================
package com.amar.library.ui.interfaces

interface IScrollViewListener {
    fun onScrollChanged(l: Int, t: Int, oldl: Int, oldt: Int){}
    fun onScrollStopped(isStopped: Boolean){}
}

================================================
FILE: library/src/main/java/com/amar/library/ui/presentation/IStickyScrollPresentation.kt
================================================
package com.amar.library.ui.presentation

interface IStickyScrollPresentation {
    val currentScrollYPos: Int
    fun freeHeader()
    fun freeFooter()
    fun stickHeader(translationY: Int)
    fun stickFooter(translationY: Int)
    fun initHeaderView(id: Int)
    fun initFooterView(id: Int)
}

================================================
FILE: library/src/main/java/com/amar/library/ui/presenter/StickyScrollPresenter.kt
================================================
package com.amar.library.ui.presenter

import androidx.annotation.StyleableRes
import com.amar.library.provider.interfaces.IResourceProvider
import com.amar.library.provider.interfaces.IScreenInfoProvider
import com.amar.library.ui.presentation.IStickyScrollPresentation

internal class StickyScrollPresenter(
    stickyScrollPresentation: IStickyScrollPresentation,
    private val screenInfoProvider: IScreenInfoProvider,
    typedArrayResourceProvider: IResourceProvider
) {
    private val mTypedArrayResourceProvider: IResourceProvider = typedArrayResourceProvider
    private val mStickyScrollPresentation: IStickyScrollPresentation = stickyScrollPresentation
    private val mDeviceHeight: Int = screenInfoProvider.screenHeight
    private var mStickyFooterHeight = 0
    private var mStickyFooterInitialTranslation = 0
    private var mStickyFooterInitialLocation = 0
    private var mStickyHeaderInitialLocation = 0
    private var navBarHeightDiff = 0
    var mNavigationBarInitialHeight = screenInfoProvider.navigationBarHeight
    var isFooterSticky = false
        private set
    var isHeaderSticky = false
        private set
    var mScrolled = false
    fun onGlobalLayoutChange(@StyleableRes headerRes: Int, @StyleableRes footerRes: Int) {
        val currentNavBarHeight = screenInfoProvider.navigationBarHeight
        navBarHeightDiff = mNavigationBarInitialHeight - currentNavBarHeight
        mNavigationBarInitialHeight = currentNavBarHeight
        val resources = mTypedArrayResourceProvider.getResourcesByIds(headerRes, footerRes)
        val headerId = resources[0]
        if (headerId != 0) {
            mStickyScrollPresentation.initHeaderView(headerId)
        }
        val footerId = resources[1]
        if (footerId != 0) {
            mStickyScrollPresentation.initFooterView(footerId)
        }
    }

    fun initStickyFooter(measuredHeight: Int?, initialStickyFooterLocation: Int) {
        measuredHeight?.let {
            mStickyFooterHeight = it
        }
        mStickyFooterInitialLocation = initialStickyFooterLocation - navBarHeightDiff
        mStickyFooterInitialTranslation =
            mDeviceHeight - mStickyFooterInitialLocation - mStickyFooterHeight
        if (mStickyFooterInitialLocation > mDeviceHeight - mStickyFooterHeight) {
            mStickyScrollPresentation.stickFooter(mStickyFooterInitialTranslation)
            isFooterSticky = true
        }
    }

    fun initStickyHeader(headerTop: Int?) {
        if (headerTop == null) {
            mStickyHeaderInitialLocation = 0
            return
        }
        mStickyHeaderInitialLocation = headerTop
    }

    fun onScroll(scrollY: Int) {
        mScrolled = true
        handleFooterStickiness(scrollY)
        handleHeaderStickiness(scrollY)
    }

    private fun handleFooterStickiness(scrollY: Int) {
        isFooterSticky = if (scrollY > mStickyFooterInitialLocation - mDeviceHeight + mStickyFooterHeight) {
            mStickyScrollPresentation.freeFooter()
            false
        } else {
            mStickyScrollPresentation.stickFooter(mStickyFooterInitialTranslation + scrollY)
            true
        }
    }

    private fun handleHeaderStickiness(scrollY: Int) {
        isHeaderSticky = if (scrollY > mStickyHeaderInitialLocation) {
            mStickyScrollPresentation.stickHeader(scrollY - mStickyHeaderInitialLocation)
            true
        } else {
            mStickyScrollPresentation.freeHeader()
            false
        }
    }

    fun recomputeFooterLocation(footerTop: Int) {
        if (mScrolled) {
            mStickyFooterInitialLocation = footerTop - navBarHeightDiff
            mStickyFooterInitialTranslation = mDeviceHeight - mStickyFooterInitialLocation - mStickyFooterHeight
        } else {
            initStickyFooter(mStickyFooterHeight, footerTop)
        }
        handleFooterStickiness(mStickyScrollPresentation.currentScrollYPos)
    }

    fun recomputeHeaderLocation(headerTop: Int) {
        initStickyHeader(headerTop)
        handleHeaderStickiness(mStickyScrollPresentation.currentScrollYPos)
    }
}

================================================
FILE: library/src/main/res/values/attrs.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="StickyScrollView">
        <attr name="stickyFooter" format="reference" />
        <attr name="stickyHeader" format="reference" />
    </declare-styleable>
</resources>

================================================
FILE: library/src/main/res/values/strings.xml
================================================
<resources>
    <string name="app_name">library</string>
</resources>


================================================
FILE: library/src/test/java/com/amar/library/ExampleUnitTest.java
================================================
package com.amar.library;

import org.junit.Test;

import static org.junit.Assert.*;

/**
 * Example local unit test, which will execute on the development machine (host).
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
public class ExampleUnitTest {
    @Test
    public void addition_isCorrect() throws Exception {
        assertEquals(4, 2 + 2);
    }
}

================================================
FILE: sample/build.gradle
================================================
plugins {
    id 'com.android.application'
    id 'kotlin-android'
}

android {
    compileSdkVersion compileVersionSdk

    defaultConfig {
        applicationId "com.amar.hack"
        minSdkVersion projectMinSdkVersion
        targetSdkVersion targetSdkVersion
        versionCode projectVersionCode
        versionName projectVersionName

        multiDexEnabled true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_11
        targetCompatibility = JavaVersion.VERSION_11
    }
}

dependencies {
    implementation kotlinSdk
    implementation project(':library')
    droid.values().forEach { implementation it }
    externalLibs.values().forEach { implementation it }
    testLibs.values().forEach { testImplementation it }
    uiTestLibs.values().forEach { androidTestImplementation it }
}

================================================
FILE: sample/proguard-rules.pro
================================================
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/m02256/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile


================================================
FILE: sample/src/androidTest/java/com/amar/sample/ExampleInstrumentedTest.java
================================================
package com.amar.sample;

import android.content.Context;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
 * Instrumentation test, which will execute on an Android device.
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
    @Test
    public void useAppContext() throws Exception {
        // Context of the app under test.
        Context appContext = InstrumentationRegistry.getTargetContext();

        assertEquals("com.amar.hack", appContext.getPackageName());
    }
}


================================================
FILE: sample/src/main/AndroidManifest.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.amar.sample">

    <application
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".ViewPagerActivity"
            android:exported="false"
            android:label="ViewPager Screen" />
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:label="Home Screen">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

================================================
FILE: sample/src/main/java/com/amar/sample/MainActivity.kt
================================================
package com.amar.sample

import android.content.Intent
import android.os.Bundle
import android.util.TypedValue
import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.amar.library.ui.StickyScrollView
import com.amar.library.ui.interfaces.IScrollViewListener

class MainActivity : AppCompatActivity(), View.OnClickListener {
    private var scrollView: StickyScrollView? = null
    private var mainShoeView: ImageView? = null
    private var redShoeVisible = true
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        scrollView = findViewById<View>(R.id.scrollView) as StickyScrollView
        val titleHeader = findViewById<View>(R.id.title)
        scrollView?.setScrollViewListener(object: IScrollViewListener{
            override fun onScrollChanged(l: Int, t: Int, oldl: Int, oldt: Int) {
                if(scrollView?.isHeaderSticky == true) {
                    titleHeader.setBackgroundResource(android.R.color.white)
                } else {
                    titleHeader.setBackgroundResource(android.R.color.transparent)
                }
            }
        })
        findViewById<View>(R.id.buy).setOnClickListener(this)
        findViewById<View>(R.id.save).setOnClickListener(this)
        findViewById<View>(R.id.title).setOnClickListener(this)
        findViewById<View>(R.id.other_product).setOnClickListener(this)
        mainShoeView = findViewById(R.id.main_shoe_picture)
        scrollView?.setFooterView(R.id.buttons)
    }

    override fun onClick(v: View) {
        when (v.id) {
            R.id.buy -> {
                startActivity(Intent(this, ViewPagerActivity::class.java))
            }
            R.id.save -> Toast.makeText(
                this,
                if (scrollView!!.isFooterSticky) "Footer is Sticky" else "Footer is not sticky",
                Toast.LENGTH_SHORT
            ).show()
            R.id.title -> Toast.makeText(
                this,
                if (scrollView!!.isHeaderSticky) "Header is Sticky" else "Header is not sticky",
                Toast.LENGTH_SHORT
            ).show()
            R.id.other_product -> switchShoeViews()
        }
    }

    private fun switchShoeViews() {
        if (redShoeVisible) {
            redShoeVisible = false
            mainShoeView!!.setImageResource(R.drawable.similar_1)
            val params = mainShoeView!!.layoutParams as LinearLayout.LayoutParams
            params.height = dpToPixel(420).toInt()
            mainShoeView!!.layoutParams = params
        } else {
            redShoeVisible = true
            mainShoeView!!.setImageResource(R.drawable.nike)
            val params = mainShoeView!!.layoutParams as LinearLayout.LayoutParams
            params.height = dpToPixel(520).toInt()
            mainShoeView!!.layoutParams = params
        }
    }

    private fun dpToPixel(pixel: Int): Float {
        val r = resources
        return TypedValue.applyDimension(
            TypedValue.COMPLEX_UNIT_DIP,
            pixel.toFloat(),
            r.displayMetrics
        )
    }
}

================================================
FILE: sample/src/main/java/com/amar/sample/PageFragment.kt
================================================
package com.amar.sample

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.amar.library.ui.StickyScrollView

class PageFragment : Fragment() {
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        val view = inflater.inflate(R.layout.activity_main, container, false)
        view.findViewById<StickyScrollView>(R.id.scrollView).setFooterView(R.id.buttons)
        return view
    }
}

================================================
FILE: sample/src/main/java/com/amar/sample/ViewPagerActivity.kt
================================================
package com.amar.sample

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter
import androidx.viewpager2.widget.ViewPager2

class ViewPagerActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_view_pager)
        val viewPager: ViewPager2 = findViewById(R.id.pager)
        viewPager.adapter = CustomPagerAdapter(this)
    }

    private inner class CustomPagerAdapter(fa: FragmentActivity) : FragmentStateAdapter(fa) {
        override fun getItemCount(): Int = 2
        override fun createFragment(position: Int): Fragment = PageFragment()
    }
}

================================================
FILE: sample/src/main/res/layout/activity_main.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<com.amar.library.ui.StickyScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:stickyHeader="@+id/title"
    tools:context="com.amar.sample.MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/main_shoe_picture"
            android:layout_width="match_parent"
            android:layout_height="520dp"
            android:contentDescription="@string/app_name"
            android:src="@drawable/nike" />

        <View
            android:layout_width="match_parent"
            android:layout_height="0.1dp"
            android:background="@android:color/darker_gray" />

        <LinearLayout
            android:id="@+id/title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/white"
            android:orientation="vertical"
            android:padding="15dp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/product_title"
                android:textStyle="bold" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/product_description_goes_here"
                android:textStyle="italic" />
        </LinearLayout>

        <View
            android:layout_width="match_parent"
            android:layout_height="0.1dp"
            android:background="@android:color/darker_gray" />

        <LinearLayout
            android:id="@+id/other_product"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorAccent"
            android:orientation="vertical"
            android:padding="15dp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/check_other_product"
                android:textStyle="bold" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/other_product_info_goes_here"
                android:textStyle="italic" />
        </LinearLayout>

        <View
            android:layout_width="match_parent"
            android:layout_height="0.1dp"
            android:background="@android:color/darker_gray" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:padding="15dp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/product_similar"
                android:textStyle="bold" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/similar_items_go_here"
                android:textStyle="italic" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/buttons"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/save"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="#535766"
                android:gravity="center"
                android:padding="15dp"
                android:text="@string/save"
                android:textColor="@android:color/white"
                android:textSize="14sp"
                app:drawableLeftCompat="@mipmap/ic_wishlist" />

            <TextView
                android:id="@+id/buy"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="#0BC6A0"
                android:gravity="center"
                android:maxLines="1"
                android:text="@string/buy"
                android:textColor="@android:color/white"
                android:textSize="14sp"
                app:drawableLeftCompat="@mipmap/ic_bag" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/other_footer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:background="@android:color/white"
            android:padding="15dp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/other_product_related_info_goes_here"
                android:textStyle="bold" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/you_can_add_more_data_here"
                android:textStyle="italic" />
        </LinearLayout>

        <View
            android:layout_width="match_parent"
            android:layout_height="0.1dp"
            android:background="@android:color/darker_gray" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="15dp"
            android:text="@string/more_colors"
            android:textStyle="bold" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="0dp"
                android:layout_height="220dp"
                android:layout_weight="1"
                android:contentDescription="@string/app_name"
                android:src="@drawable/similar_1" />

            <ImageView
                android:layout_width="0dp"
                android:layout_height="620dp"
                android:layout_weight="1"
                android:contentDescription="@string/app_name"
                android:src="@drawable/similar_2" />
        </LinearLayout>
    </LinearLayout>
</com.amar.library.ui.StickyScrollView>

================================================
FILE: sample/src/main/res/layout/activity_view_pager.xml
================================================
<?xml version="1.0" encoding="utf-8"?>

<androidx.viewpager2.widget.ViewPager2 xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

================================================
FILE: sample/src/main/res/layout/view_page.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="16dp"
    android:background="@android:color/holo_green_light">

    <TextView
        android:id="@+id/page_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:text="Page Title" />

</androidx.constraintlayout.widget.ConstraintLayout>

================================================
FILE: sample/src/main/res/values/colors.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#009688</color>
    <color name="colorPrimaryDark">#00796B</color>
    <color name="colorAccent">#80CBC4</color>
</resources>


================================================
FILE: sample/src/main/res/values/strings.xml
================================================
<resources>
    <string name="app_name">StickyScrollView</string>
    <string name="product_title">Product Title</string>
    <string name="product_description_goes_here">Product Description goes here</string>
    <string name="check_other_product">Check other product</string>
    <string name="other_product_info_goes_here">Other product info goes here</string>
    <string name="product_similar">Product Similar</string>
    <string name="similar_items_go_here">Similar items go here</string>
    <string name="save">SAVE</string>
    <string name="buy">BUY</string>
    <string name="other_product_related_info_goes_here">Other product related info goes here!</string>
    <string name="you_can_add_more_data_here">You can add more data here</string>
    <string name="more_colors">More colors</string>
</resources>


================================================
FILE: sample/src/main/res/values/styles.xml
================================================
<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

</resources>


================================================
FILE: sample/src/test/java/com/amar/sample/ExampleUnitTest.java
================================================
package com.amar.sample;

import org.junit.Test;

import static org.junit.Assert.*;

/**
 * Example local unit test, which will execute on the development machine (host).
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
public class ExampleUnitTest {
    @Test
    public void addition_isCorrect() throws Exception {
        assertEquals(4, 2 + 2);
    }
}

================================================
FILE: settings.gradle
================================================
include ':sample', ':library'
Download .txt
gitextract_ikmcfygz/

├── .gitignore
├── LICENSE
├── README.md
├── build.gradle
├── dependencies.gradle
├── gradle/
│   └── wrapper/
│       ├── gradle-wrapper.jar
│       └── gradle-wrapper.properties
├── gradle.properties
├── gradlew
├── gradlew.bat
├── jitpack.yml
├── library/
│   ├── build.gradle
│   ├── proguard-rules.pro
│   ├── publish.gradle
│   └── src/
│       ├── androidTest/
│       │   └── java/
│       │       └── com/
│       │           └── amar/
│       │               └── library/
│       │                   └── ExampleInstrumentedTest.java
│       ├── main/
│       │   ├── AndroidManifest.xml
│       │   ├── java/
│       │   │   └── com/
│       │   │       └── amar/
│       │   │           └── library/
│       │   │               ├── provider/
│       │   │               │   ├── ResourceProvider.kt
│       │   │               │   ├── ScreenInfoProvider.kt
│       │   │               │   └── interfaces/
│       │   │               │       ├── IResourceProvider.kt
│       │   │               │       └── IScreenInfoProvider.kt
│       │   │               └── ui/
│       │   │                   ├── PropertySetter.kt
│       │   │                   ├── StickyScrollView.kt
│       │   │                   ├── interfaces/
│       │   │                   │   └── IScrollViewListener.kt
│       │   │                   ├── presentation/
│       │   │                   │   └── IStickyScrollPresentation.kt
│       │   │                   └── presenter/
│       │   │                       └── StickyScrollPresenter.kt
│       │   └── res/
│       │       └── values/
│       │           ├── attrs.xml
│       │           └── strings.xml
│       └── test/
│           └── java/
│               └── com/
│                   └── amar/
│                       └── library/
│                           └── ExampleUnitTest.java
├── sample/
│   ├── build.gradle
│   ├── proguard-rules.pro
│   └── src/
│       ├── androidTest/
│       │   └── java/
│       │       └── com/
│       │           └── amar/
│       │               └── sample/
│       │                   └── ExampleInstrumentedTest.java
│       ├── main/
│       │   ├── AndroidManifest.xml
│       │   ├── java/
│       │   │   └── com/
│       │   │       └── amar/
│       │   │           └── sample/
│       │   │               ├── MainActivity.kt
│       │   │               ├── PageFragment.kt
│       │   │               └── ViewPagerActivity.kt
│       │   └── res/
│       │       ├── layout/
│       │       │   ├── activity_main.xml
│       │       │   ├── activity_view_pager.xml
│       │       │   └── view_page.xml
│       │       └── values/
│       │           ├── colors.xml
│       │           ├── strings.xml
│       │           └── styles.xml
│       └── test/
│           └── java/
│               └── com/
│                   └── amar/
│                       └── sample/
│                           └── ExampleUnitTest.java
└── settings.gradle
Download .txt
SYMBOL INDEX (8 symbols across 4 files)

FILE: library/src/androidTest/java/com/amar/library/ExampleInstrumentedTest.java
  class ExampleInstrumentedTest (line 17) | @RunWith(AndroidJUnit4.class)
    method useAppContext (line 19) | @Test

FILE: library/src/test/java/com/amar/library/ExampleUnitTest.java
  class ExampleUnitTest (line 12) | public class ExampleUnitTest {
    method addition_isCorrect (line 13) | @Test

FILE: sample/src/androidTest/java/com/amar/sample/ExampleInstrumentedTest.java
  class ExampleInstrumentedTest (line 17) | @RunWith(AndroidJUnit4.class)
    method useAppContext (line 19) | @Test

FILE: sample/src/test/java/com/amar/sample/ExampleUnitTest.java
  class ExampleUnitTest (line 12) | public class ExampleUnitTest {
    method addition_isCorrect (line 13) | @Test
Condensed preview — 43 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (58K chars).
[
  {
    "path": ".gitignore",
    "chars": 472,
    "preview": ".idea/\n# Built application files\n*.apk\n*.ap_\n\n# Files for the ART/Dalvik VM\n*.dex\n\n# Java class files\n*.class\n\n# Generat"
  },
  {
    "path": "LICENSE",
    "chars": 1066,
    "preview": "MIT License\n\nCopyright (c) 2017 Amar Jain\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\n"
  },
  {
    "path": "README.md",
    "chars": 2679,
    "preview": "# StickyScrollView\nSticky header and footer for android ScrollView.\n\n[![](https://jitpack.io/v/amarjain07/StickyScrollVi"
  },
  {
    "path": "build.gradle",
    "chars": 580,
    "preview": "// Top-level build file where you can add configuration options common to all sub-projects/modules.\nbuildscript {\n    ap"
  },
  {
    "path": "dependencies.gradle",
    "chars": 4154,
    "preview": "ext {\n    gradlePluginVersion = '7.0.4'\n    projectMinSdkVersion = 16\n    compileVersionSdk = 30\n    targetSdkVersion = "
  },
  {
    "path": "gradle/wrapper/gradle-wrapper.properties",
    "chars": 232,
    "preview": "#Thu Jul 09 18:59:02 IST 2020\ndistributionBase=GRADLE_USER_HOME\ndistributionPath=wrapper/dists\nzipStoreBase=GRADLE_USER_"
  },
  {
    "path": "gradle.properties",
    "chars": 52,
    "preview": "android.enableJetifier=true\nandroid.useAndroidX=true"
  },
  {
    "path": "gradlew",
    "chars": 4971,
    "preview": "#!/usr/bin/env bash\n\n##############################################################################\n##\n##  Gradle start "
  },
  {
    "path": "gradlew.bat",
    "chars": 2404,
    "preview": "@if \"%DEBUG%\" == \"\" @echo off\r\n@rem ##########################################################################\r\n@rem\r\n@r"
  },
  {
    "path": "jitpack.yml",
    "chars": 18,
    "preview": "jdk:\n  - openjdk11"
  },
  {
    "path": "library/build.gradle",
    "chars": 854,
    "preview": "plugins {\n    id 'com.android.library'\n    id 'kotlin-android'\n}\napply from: 'publish.gradle'\n\nandroid {\n    compileSdkV"
  },
  {
    "path": "library/proguard-rules.pro",
    "chars": 935,
    "preview": "# Add project specific ProGuard rules here.\n# By default, the flags in this file are appended to flags specified\n# in /U"
  },
  {
    "path": "library/publish.gradle",
    "chars": 323,
    "preview": "apply plugin: 'maven-publish'\n\nafterEvaluate {\n    publishing {\n        publications {\n            release(MavenPublicat"
  },
  {
    "path": "library/src/androidTest/java/com/amar/library/ExampleInstrumentedTest.java",
    "chars": 751,
    "preview": "package com.amar.library;\n\nimport android.content.Context;\nimport androidx.test.platform.app.InstrumentationRegistry;\nim"
  },
  {
    "path": "library/src/main/AndroidManifest.xml",
    "chars": 103,
    "preview": "<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    package=\"com.amar.library\" />\n"
  },
  {
    "path": "library/src/main/java/com/amar/library/provider/ResourceProvider.kt",
    "chars": 764,
    "preview": "package com.amar.library.provider\n\nimport android.content.Context\nimport android.util.AttributeSet\nimport androidx.annot"
  },
  {
    "path": "library/src/main/java/com/amar/library/provider/ScreenInfoProvider.kt",
    "chars": 987,
    "preview": "package com.amar.library.provider\n\nimport android.content.Context\nimport android.graphics.Point\nimport com.amar.library."
  },
  {
    "path": "library/src/main/java/com/amar/library/provider/interfaces/IResourceProvider.kt",
    "chars": 203,
    "preview": "package com.amar.library.provider.interfaces\n\nimport androidx.annotation.StyleableRes\n\ninternal interface IResourceProvi"
  },
  {
    "path": "library/src/main/java/com/amar/library/provider/interfaces/IScreenInfoProvider.kt",
    "chars": 172,
    "preview": "package com.amar.library.provider.interfaces\n\ninternal interface IScreenInfoProvider {\n    val screenHeight: Int\n    val"
  },
  {
    "path": "library/src/main/java/com/amar/library/ui/PropertySetter.kt",
    "chars": 573,
    "preview": "package com.amar.library.ui\n\nimport android.os.Build\nimport android.view.View\nimport androidx.core.view.ViewCompat\n\ninte"
  },
  {
    "path": "library/src/main/java/com/amar/library/ui/StickyScrollView.kt",
    "chars": 6622,
    "preview": "package com.amar.library.ui\n\nimport android.content.Context\nimport android.os.Build\nimport android.os.Bundle\nimport andr"
  },
  {
    "path": "library/src/main/java/com/amar/library/ui/interfaces/IScrollViewListener.kt",
    "chars": 183,
    "preview": "package com.amar.library.ui.interfaces\n\ninterface IScrollViewListener {\n    fun onScrollChanged(l: Int, t: Int, oldl: In"
  },
  {
    "path": "library/src/main/java/com/amar/library/ui/presentation/IStickyScrollPresentation.kt",
    "chars": 296,
    "preview": "package com.amar.library.ui.presentation\n\ninterface IStickyScrollPresentation {\n    val currentScrollYPos: Int\n    fun f"
  },
  {
    "path": "library/src/main/java/com/amar/library/ui/presenter/StickyScrollPresenter.kt",
    "chars": 4089,
    "preview": "package com.amar.library.ui.presenter\n\nimport androidx.annotation.StyleableRes\nimport com.amar.library.provider.interfac"
  },
  {
    "path": "library/src/main/res/values/attrs.xml",
    "chars": 248,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n    <declare-styleable name=\"StickyScrollView\">\n        <attr name=\"s"
  },
  {
    "path": "library/src/main/res/values/strings.xml",
    "chars": 70,
    "preview": "<resources>\n    <string name=\"app_name\">library</string>\n</resources>\n"
  },
  {
    "path": "library/src/test/java/com/amar/library/ExampleUnitTest.java",
    "chars": 394,
    "preview": "package com.amar.library;\n\nimport org.junit.Test;\n\nimport static org.junit.Assert.*;\n\n/**\n * Example local unit test, wh"
  },
  {
    "path": "sample/build.gradle",
    "chars": 1013,
    "preview": "plugins {\n    id 'com.android.application'\n    id 'kotlin-android'\n}\n\nandroid {\n    compileSdkVersion compileVersionSdk\n"
  },
  {
    "path": "sample/proguard-rules.pro",
    "chars": 935,
    "preview": "# Add project specific ProGuard rules here.\n# By default, the flags in this file are appended to flags specified\n# in /U"
  },
  {
    "path": "sample/src/androidTest/java/com/amar/sample/ExampleInstrumentedTest.java",
    "chars": 742,
    "preview": "package com.amar.sample;\n\nimport android.content.Context;\nimport androidx.test.platform.app.InstrumentationRegistry;\nimp"
  },
  {
    "path": "sample/src/main/AndroidManifest.xml",
    "chars": 911,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    package="
  },
  {
    "path": "sample/src/main/java/com/amar/sample/MainActivity.kt",
    "chars": 3246,
    "preview": "package com.amar.sample\n\nimport android.content.Intent\nimport android.os.Bundle\nimport android.util.TypedValue\nimport an"
  },
  {
    "path": "sample/src/main/java/com/amar/sample/PageFragment.kt",
    "chars": 597,
    "preview": "package com.amar.sample\n\nimport android.os.Bundle\nimport android.view.LayoutInflater\nimport android.view.View\nimport and"
  },
  {
    "path": "sample/src/main/java/com/amar/sample/ViewPagerActivity.kt",
    "chars": 831,
    "preview": "package com.amar.sample\n\nimport androidx.appcompat.app.AppCompatActivity\nimport android.os.Bundle\nimport androidx.fragme"
  },
  {
    "path": "sample/src/main/res/layout/activity_main.xml",
    "chars": 6866,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<com.amar.library.ui.StickyScrollView xmlns:android=\"http://schemas.android.com/a"
  },
  {
    "path": "sample/src/main/res/layout/activity_view_pager.xml",
    "chars": 249,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n\n<androidx.viewpager2.widget.ViewPager2 xmlns:android=\"http://schemas.android.com"
  },
  {
    "path": "sample/src/main/res/layout/view_page.xml",
    "chars": 863,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<androidx.constraintlayout.widget.ConstraintLayout xmlns:android=\"http://schemas."
  },
  {
    "path": "sample/src/main/res/values/colors.xml",
    "chars": 208,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n    <color name=\"colorPrimary\">#009688</color>\n    <color name=\"color"
  },
  {
    "path": "sample/src/main/res/values/strings.xml",
    "chars": 820,
    "preview": "<resources>\n    <string name=\"app_name\">StickyScrollView</string>\n    <string name=\"product_title\">Product Title</string"
  },
  {
    "path": "sample/src/main/res/values/styles.xml",
    "chars": 383,
    "preview": "<resources>\n\n    <!-- Base application theme. -->\n    <style name=\"AppTheme\" parent=\"Theme.AppCompat.Light.DarkActionBar"
  },
  {
    "path": "sample/src/test/java/com/amar/sample/ExampleUnitTest.java",
    "chars": 393,
    "preview": "package com.amar.sample;\n\nimport org.junit.Test;\n\nimport static org.junit.Assert.*;\n\n/**\n * Example local unit test, whi"
  },
  {
    "path": "settings.gradle",
    "chars": 30,
    "preview": "include ':sample', ':library'\n"
  }
]

// ... and 1 more files (download for full content)

About this extraction

This page contains the full source code of the amarjain07/StickyScrollView GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 43 files (51.1 KB), approximately 13.7k tokens, and a symbol index with 8 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!