Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Eclipse
.project
.classpath
.settings
.checkstyle

# IntelliJ IDEA
.idea
*.iml
*.ipr
*.iws
classes
gen-external-apklibs

# Gradle
.gradle
build

# Maven
target
release.properties
pom.xml.*

# Ant
bin
gen
build.xml
ant.properties
local.properties
proguard.cfg
proguard-project.txt

# Other
.DS_Store
tmp
6 changes: 0 additions & 6 deletions AndroidManifest.xml → Library/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,4 @@
android:minSdkVersion="11"
android:targetSdkVersion="17" />

<application
android:allowBackup="true"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
</application>

</manifest>
18 changes: 18 additions & 0 deletions Library/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apply plugin: 'android-library'

dependencies {
compile 'com.android.support:support-v4:18.0.0'
}

android {
compileSdkVersion 18
buildToolsVersion '18'

sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
2 changes: 1 addition & 1 deletion project.properties → Library/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

# Project target.
target=android-17
target=android-18
android.library=true
Binary file added Library/res/drawable-hdpi/overscroll_edge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Library/res/drawable-hdpi/overscroll_glow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Library/res/drawable-mdpi/overscroll_edge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Library/res/drawable-mdpi/overscroll_glow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Library/res/drawable-xhdpi/overscroll_edge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Library/res/drawable-xhdpi/overscroll_glow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions Library/res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="EdgeEffectView">
<attr name="edgeeffect_color" format="color"/>
</declare-styleable>
</resources>
4 changes: 4 additions & 0 deletions Library/res/values/defaults.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="default_edgeeffect_color">#FF33B5E5</color>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* Copyright (c) 2013 Android Alliance, LTD
*
* 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.
*/
package uk.co.androidalliance.edgeeffectoverride;

import android.content.Context;
import android.content.ContextWrapper;
import android.content.res.AssetManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.util.DisplayMetrics;
import android.util.Log;

public class ContextWrapperEdgeEffect extends ContextWrapper {

private ResourcesEdgeEffect mResourcesEdgeEffect;
private int mColor;
private Drawable mEdgeDrawable;
private Drawable mGlowDrawable;

public ContextWrapperEdgeEffect(Context context) {
this(context, 0);
}

public ContextWrapperEdgeEffect(Context context, int color) {
super(context);
mColor = color;
Resources resources = context.getResources();
mResourcesEdgeEffect = new ResourcesEdgeEffect(resources.getAssets(), resources.getDisplayMetrics(), resources.getConfiguration());
}

public void setEdgeEffectColor(int color) {
mColor = color;
if (mEdgeDrawable != null) mEdgeDrawable.setColorFilter(color, PorterDuff.Mode.MULTIPLY);
if (mGlowDrawable != null) mGlowDrawable.setColorFilter(color, PorterDuff.Mode.MULTIPLY);
}

@Override
public Resources getResources() {
return mResourcesEdgeEffect;
}

private class ResourcesEdgeEffect extends Resources {
private int overscroll_edge = getPlatformDrawableId("overscroll_edge");
private int overscroll_glow = getPlatformDrawableId("overscroll_glow");

public ResourcesEdgeEffect(AssetManager assets, DisplayMetrics metrics, Configuration config) {
//super(metrics, localConfiguration);
super(assets, metrics, config);
}

private int getPlatformDrawableId(String name) {
try {
int i = ((Integer) Class.forName("com.android.internal.R$drawable").getField(name).get(null)).intValue();
return i;
} catch (ClassNotFoundException e) {
Log.e("[ContextWrapperEdgeEffect].getPlatformDrawableId()", "Cannot find internal resource class");
return 0;
} catch (NoSuchFieldException e1) {
Log.e("[ContextWrapperEdgeEffect].getPlatformDrawableId()", "Internal resource id does not exist: " + name);
return 0;
} catch (IllegalArgumentException e2) {
Log.e("[ContextWrapperEdgeEffect].getPlatformDrawableId()", "Cannot access internal resource id: " + name);
return 0;
} catch (IllegalAccessException e3) {
Log.e("[ContextWrapperEdgeEffect].getPlatformDrawableId()", "Cannot access internal resource id: " + name);
}
return 0;
}

@Override
public Drawable getDrawable(int resId) throws Resources.NotFoundException {
Drawable ret = null;
if (resId == this.overscroll_edge) {
mEdgeDrawable = ContextWrapperEdgeEffect.this.getBaseContext().getResources().getDrawable(R.drawable.overscroll_edge);
ret = mEdgeDrawable;
} else if (resId == this.overscroll_glow) {
mGlowDrawable = ContextWrapperEdgeEffect.this.getBaseContext().getResources().getDrawable(R.drawable.overscroll_glow);
ret = mGlowDrawable;
} else return super.getDrawable(resId);

if (ret != null) {
ret.setColorFilter(mColor, PorterDuff.Mode.MULTIPLY);
}

return ret;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2013 Android Alliance, LTD
*
* 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.
*/
package uk.co.androidalliance.edgeeffectoverride;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;

public class EdgeEffectExpandableListView extends android.widget.ExpandableListView {

public EdgeEffectExpandableListView(Context context) {
this(context, null);
}

public EdgeEffectExpandableListView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}

public EdgeEffectExpandableListView(Context context, AttributeSet attrs, int defStyle) {
super(new ContextWrapperEdgeEffect(context), attrs, defStyle);
init(context, attrs, defStyle);
}

private void init(Context context, AttributeSet attrs, int defStyle){
int color = context.getResources().getColor(R.color.default_edgeeffect_color);

if (attrs != null) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.EdgeEffectView, defStyle, 0);
color = a.getColor(R.styleable.EdgeEffectView_edgeeffect_color, color);
a.recycle();
}
setEdgeEffectColor(color);
}

public void setEdgeEffectColor(int edgeEffectColor){
((ContextWrapperEdgeEffect) getContext()).setEdgeEffectColor(edgeEffectColor);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2013 Android Alliance, LTD
*
* 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.
*/
package uk.co.androidalliance.edgeeffectoverride;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;

public class EdgeEffectGridView extends android.widget.GridView {

public EdgeEffectGridView(Context context) {
this(context, null);
}

public EdgeEffectGridView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}

public EdgeEffectGridView(Context context, AttributeSet attrs, int defStyle) {
super(new ContextWrapperEdgeEffect(context), attrs, defStyle);
init(context, attrs, defStyle);
}

private void init(Context context, AttributeSet attrs, int defStyle){
int color = context.getResources().getColor(R.color.default_edgeeffect_color);

if (attrs != null) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.EdgeEffectView, defStyle, 0);
color = a.getColor(R.styleable.EdgeEffectView_edgeeffect_color, color);
a.recycle();
}
setEdgeEffectColor(color);
}

public void setEdgeEffectColor(int edgeEffectColor){
((ContextWrapperEdgeEffect) getContext()).setEdgeEffectColor(edgeEffectColor);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2013 Android Alliance, LTD
*
* 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.
*/
package uk.co.androidalliance.edgeeffectoverride;

import android.content.Context;
import android.content.res.TypedArray;
import android.test.IsolatedContext;
import android.util.AttributeSet;

public class EdgeEffectListView extends android.widget.ListView {

public EdgeEffectListView(Context context) {
this(context, null);
}

public EdgeEffectListView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}

public EdgeEffectListView(Context context, AttributeSet attrs, int defStyle) {
super(new ContextWrapperEdgeEffect(context), attrs, defStyle);
init(context, attrs, defStyle);
}

private void init(Context context, AttributeSet attrs, int defStyle) {
int color = context.getResources().getColor(R.color.default_edgeeffect_color);

if (attrs != null) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.EdgeEffectView, defStyle, 0);
color = a.getColor(R.styleable.EdgeEffectView_edgeeffect_color, color);
a.recycle();
}
setEdgeEffectColor(color);
}

public void setEdgeEffectColor(int edgeEffectColor) {
((ContextWrapperEdgeEffect) getContext()).setEdgeEffectColor(edgeEffectColor);
}
}
Loading