Skip to content

Commit

Permalink
Update ExpandableLayout.java to allow implementing AnimationListener.
Browse files Browse the repository at this point in the history
  • Loading branch information
dinosoeren committed Apr 20, 2015
2 parents 6ea34f9 + 1ab0aec commit cc01bc6
Show file tree
Hide file tree
Showing 18 changed files with 96 additions and 106 deletions.
14 changes: 6 additions & 8 deletions .gitignore
Expand Up @@ -8,29 +8,27 @@ gen
.settings

#IntelliJ IDEA
build
.idea
*.iml
*.ipr
*.iws
out

#Gradle
.gradle
build

#Maven
target
release.properties
pom.xml.*
project.properties
gradle.properties

#Ant
build.xml
local.properties
gradle.properties
proguard.cfg

#OSX
.DS_Store

# Crashlytics
com_crashlytics_export_strings.xml
crashlytics-build.properties
crashlytics.properties
.DS_Store/
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.2'
classpath 'com.android.tools.build:gradle:1.0.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
#Wed Apr 10 15:27:10 PDT 2013
#Mon Jan 26 11:47:03 CET 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.12-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
14 changes: 6 additions & 8 deletions library/.gitignore
Expand Up @@ -8,29 +8,27 @@ gen
.settings

#IntelliJ IDEA
build
.idea
*.iml
*.ipr
*.iws
out

#Gradle
.gradle
build

#Maven
target
release.properties
pom.xml.*
project.properties
gradle.properties

#Ant
build.xml
local.properties
gradle.properties
proguard.cfg

#OSX
.DS_Store

# Crashlytics
com_crashlytics_export_strings.xml
crashlytics-build.properties
crashlytics.properties
.DS_Store/
13 changes: 6 additions & 7 deletions library/build.gradle
@@ -1,19 +1,18 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
compileSdkVersion 21
buildToolsVersion "21.1.2"

defaultConfig {
applicationId "com.andexert.expandablelayout.library"
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
targetSdkVersion 21
versionCode 7
versionName "1.3"
}
buildTypes {
release {
runProguard false
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
Expand Down
7 changes: 1 addition & 6 deletions library/src/main/AndroidManifest.xml
@@ -1,11 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.andexert.expandablelayout.library">

<application android:allowBackup="true"
android:label="@string/app_name"
android:icon="@drawable/ic_launcher"
>

</application>
<application />

</manifest>
Expand Up @@ -31,15 +31,16 @@
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.Transformation;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;

public class ExpandableLayout extends RelativeLayout
{
private Boolean isAnimationRunning = false;
private Boolean isOpened = false;
private Integer duration;
private RelativeLayout contentRelativeLayout;
private RelativeLayout headerRelativeLayout;
private FrameLayout contentLayout;
private FrameLayout headerLayout;
private Animation animation;

public ExpandableLayout(Context context)
Expand All @@ -62,34 +63,37 @@ public ExpandableLayout(Context context, AttributeSet attrs, int defStyle)
private void init(final Context context, AttributeSet attrs)
{
final View rootView = View.inflate(context, R.layout.view_expandable, this);
headerRelativeLayout = (RelativeLayout) rootView.findViewById(R.id.view_expandable_headerlayout);
headerLayout = (FrameLayout) rootView.findViewById(R.id.view_expandable_headerlayout);
final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ExpandableLayout);
final int headerID = typedArray.getResourceId(R.styleable.ExpandableLayout_headerLayout, -1);
final int contentID = typedArray.getResourceId(R.styleable.ExpandableLayout_contentLayout, -1);
contentRelativeLayout = (RelativeLayout) rootView.findViewById(R.id.view_expandable_contentLayout);
final int headerID = typedArray.getResourceId(R.styleable.ExpandableLayout_el_headerLayout, -1);
final int contentID = typedArray.getResourceId(R.styleable.ExpandableLayout_el_contentLayout, -1);
contentLayout = (FrameLayout) rootView.findViewById(R.id.view_expandable_contentLayout);

if (headerID == -1 || contentID == -1)
throw new IllegalArgumentException("HeaderLayout and ContentLayout cannot be null!");

duration = typedArray.getInt(R.styleable.ExpandableLayout_duration, getContext().getResources().getInteger(android.R.integer.config_shortAnimTime));
if (isInEditMode())
return;

duration = typedArray.getInt(R.styleable.ExpandableLayout_el_duration, getContext().getResources().getInteger(android.R.integer.config_shortAnimTime));
final View headerView = View.inflate(context, headerID, null);
headerView.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
headerRelativeLayout.addView(headerView);
headerLayout.addView(headerView);
final View contentView = View.inflate(context, contentID, null);
contentView.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
contentRelativeLayout.addView(contentView);
contentRelativeLayout.setVisibility(GONE);
headerRelativeLayout.setOnClickListener(new OnClickListener()
contentLayout.addView(contentView);
contentLayout.setVisibility(GONE);
headerLayout.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
if (!isAnimationRunning)
{
if (contentRelativeLayout.getVisibility() == VISIBLE)
collapse(contentRelativeLayout);
if (contentLayout.getVisibility() == VISIBLE)
collapse(contentLayout);
else
expand(contentRelativeLayout);
expand(contentLayout);

isAnimationRunning = true;
new Handler().postDelayed(new Runnable()
Expand All @@ -103,6 +107,8 @@ public void run()
}
}
});

typedArray.recycle();
}

private void expand(final View v)
Expand Down Expand Up @@ -170,7 +176,7 @@ public void show()
{
if (!isAnimationRunning)
{
expand(contentRelativeLayout);
expand(contentLayout);
isAnimationRunning = true;
new Handler().postDelayed(new Runnable()
{
Expand All @@ -183,21 +189,21 @@ public void run()
}
}

public RelativeLayout getHeaderRelativeLayout()
public FrameLayout getHeaderLayout()
{
return headerRelativeLayout;
return headerLayout;
}

public RelativeLayout getContentRelativeLayout()
public FrameLayout getContentLayout()
{
return contentRelativeLayout;
return contentLayout;
}

public void hide()
{
if (!isAnimationRunning)
{
collapse(contentRelativeLayout);
collapse(contentLayout);
isAnimationRunning = true;
new Handler().postDelayed(new Runnable()
{
Expand Down
Expand Up @@ -25,26 +25,23 @@

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.os.Handler;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.animation.Animation;
import android.view.animation.Transformation;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;

public class ExpandableLayoutItem extends RelativeLayout
{
private Boolean isAnimationRunning = false;
private Boolean isOpened = false;
private Integer duration;
private RelativeLayout contentRelativeLayout;
private RelativeLayout headerRelativeLayout;
private FrameLayout contentLayout;
private FrameLayout headerLayout;
private Boolean closeByUser = true;

public ExpandableLayoutItem(Context context)
Expand All @@ -67,26 +64,29 @@ public ExpandableLayoutItem(Context context, AttributeSet attrs, int defStyle)
private void init(final Context context, AttributeSet attrs)
{
final View rootView = View.inflate(context, R.layout.view_expandable, this);
headerRelativeLayout = (RelativeLayout) rootView.findViewById(R.id.view_expandable_headerlayout);
headerLayout = (FrameLayout) rootView.findViewById(R.id.view_expandable_headerlayout);
final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ExpandableLayout);
final int headerID = typedArray.getResourceId(R.styleable.ExpandableLayout_headerLayout, -1);
final int contentID = typedArray.getResourceId(R.styleable.ExpandableLayout_contentLayout, -1);
contentRelativeLayout = (RelativeLayout) rootView.findViewById(R.id.view_expandable_contentLayout);
final int headerID = typedArray.getResourceId(R.styleable.ExpandableLayout_el_headerLayout, -1);
final int contentID = typedArray.getResourceId(R.styleable.ExpandableLayout_el_contentLayout, -1);
contentLayout = (FrameLayout) rootView.findViewById(R.id.view_expandable_contentLayout);

if (headerID == -1 || contentID == -1)
throw new IllegalArgumentException("HeaderLayout and ContentLayout cannot be null!");

duration = typedArray.getInt(R.styleable.ExpandableLayout_duration, getContext().getResources().getInteger(android.R.integer.config_shortAnimTime));
if (isInEditMode())
return;

duration = typedArray.getInt(R.styleable.ExpandableLayout_el_duration, getContext().getResources().getInteger(android.R.integer.config_shortAnimTime));
final View headerView = View.inflate(context, headerID, null);
headerView.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
headerRelativeLayout.addView(headerView);
headerLayout.addView(headerView);
setTag(ExpandableLayoutItem.class.getName());
final View contentView = View.inflate(context, contentID, null);
contentView.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
contentRelativeLayout.addView(contentView);
contentRelativeLayout.setVisibility(GONE);
contentLayout.addView(contentView);
contentLayout.setVisibility(GONE);

headerRelativeLayout.setOnTouchListener(new OnTouchListener()
headerLayout.setOnTouchListener(new OnTouchListener()
{
@Override
public boolean onTouch(View v, MotionEvent event)
Expand Down Expand Up @@ -161,20 +161,20 @@ public boolean willChangeBounds() {

public void hideNow()
{
contentRelativeLayout.getLayoutParams().height = 0;
contentRelativeLayout.invalidate();
contentRelativeLayout.setVisibility(View.GONE);
contentLayout.getLayoutParams().height = 0;
contentLayout.invalidate();
contentLayout.setVisibility(View.GONE);
isOpened = false;
}

public void showNow()
{
if (!this.isOpened())
{
contentRelativeLayout.setVisibility(VISIBLE);
contentLayout.setVisibility(VISIBLE);
this.isOpened = true;
contentRelativeLayout.getLayoutParams().height = LayoutParams.WRAP_CONTENT;
contentRelativeLayout.invalidate();
contentLayout.getLayoutParams().height = LayoutParams.WRAP_CONTENT;
contentLayout.invalidate();
}
}

Expand All @@ -187,7 +187,7 @@ public void show()
{
if (!isAnimationRunning)
{
expand(contentRelativeLayout);
expand(contentLayout);
isAnimationRunning = true;
new Handler().postDelayed(new Runnable()
{
Expand All @@ -200,21 +200,21 @@ public void run()
}
}

public RelativeLayout getHeaderRelativeLayout()
public FrameLayout getHeaderLayout()
{
return headerRelativeLayout;
return headerLayout;
}

public RelativeLayout getContentRelativeLayout()
public FrameLayout getContentLayout()
{
return contentRelativeLayout;
return contentLayout;
}

public void hide()
{
if (!isAnimationRunning)
{
collapse(contentRelativeLayout);
collapse(contentLayout);
isAnimationRunning = true;
new Handler().postDelayed(new Runnable()
{
Expand Down
Binary file removed library/src/main/res/drawable-hdpi/ic_launcher.png
Binary file not shown.
Binary file removed library/src/main/res/drawable-mdpi/ic_launcher.png
Binary file not shown.
Binary file not shown.
Binary file removed library/src/main/res/drawable-xxhdpi/ic_launcher.png
Binary file not shown.

0 comments on commit cc01bc6

Please sign in to comment.