Add styleable ability

Fix mismatch of application package between gradle and manifest.
Remove unused resources.
Update demo with new ability.
This commit is contained in:
StephaneBg 2014-08-27 12:52:46 +02:00
parent 3ac67e06c7
commit f1a4188d89
11 changed files with 35 additions and 24 deletions

View File

@ -21,8 +21,8 @@ public class MyActivity extends Activity {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SwipeLayout swipeLayout = (SwipeLayout)findViewById(R.id.godfather);
swipeLayout.setDragEdge(SwipeLayout.DragEdge.Bottom);
// SwipeLayout swipeLayout = (SwipeLayout)findViewById(R.id.godfather);
// swipeLayout.setDragEdge(SwipeLayout.DragEdge.Bottom); // Set in XML
//sample1

View File

@ -1,8 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<com.daimajia.swipe.SwipeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<com.daimajia.swipe.SwipeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/godfather"
android:layout_width="match_parent" android:layout_height="match_parent">
android:layout_width="match_parent" android:layout_height="match_parent"
app:drag_edge="bottom">
<LinearLayout
android:gravity="center"
android:layout_width="match_parent"

View File

@ -5,7 +5,7 @@ android {
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.daimajia.swipelayout"
applicationId "com.daimajia.swipe"
minSdkVersion 8
targetSdkVersion 20
versionCode 1
@ -20,7 +20,6 @@ android {
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:20.+'
compile 'com.android.support:support-v4:20.+'
}
apply from: './gradle-mvn-push.gradle'

View File

@ -1,11 +1 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.daimajia.swipe">
<application android:allowBackup="true"
android:label="@string/app_name"
android:icon="@drawable/ic_launcher"
>
</application>
</manifest>
<manifest package="com.daimajia.swipe"/>

View File

@ -1,6 +1,7 @@
package com.daimajia.swipe;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.support.v4.view.ViewCompat;
import android.support.v4.widget.ViewDragHelper;
@ -23,8 +24,8 @@ public class SwipeLayout extends FrameLayout {
private ViewDragHelper mDragHelper;
private int mDragDistance = 0;
private DragEdge mDragEdge = DragEdge.Right;
private ShowMode mShowMode = ShowMode.PullOut;
private DragEdge mDragEdge;
private ShowMode mShowMode;
private List<SwipeListener> mSwipeListeners = new ArrayList<SwipeListener>();
private Map<View, ArrayList<OnRevealListener>> mRevealListeners = new HashMap<View, ArrayList<OnRevealListener>>();
@ -53,6 +54,12 @@ public class SwipeLayout extends FrameLayout {
public SwipeLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mDragHelper = ViewDragHelper.create(this, mDragHelperCallback);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SwipeLayout);
int ordinal = a.getInt(R.styleable.SwipeLayout_drag_edge, DragEdge.Right.ordinal());
mDragEdge = DragEdge.values()[ordinal];
ordinal = a.getInt(R.styleable.SwipeLayout_show_mode, ShowMode.PullOut.ordinal());
mShowMode = ShowMode.values()[ordinal];
}
@ -590,7 +597,7 @@ public class SwipeLayout extends FrameLayout {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if(mDragEdge == DragEdge.Left || mDragEdge == DragEdge.Right)
mDragDistance = getBottomView().getMeasuredWidth();
else

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="SwipeLayout">
<attr name="drag_edge" format="enum">
<enum name="left" value="0"/>
<enum name="right" value="1"/>
<enum name="top" value="2"/>
<enum name="bottom" value="3"/>
</attr>
<attr name="show_mode" format="enum">
<enum name="lay_down" value="0"/>
<enum name="pull_out" value="1"/>
</attr>
</declare-styleable>
</resources>

View File

@ -1,3 +0,0 @@
<resources>
<string name="app_name">library</string>
</resources>