Skip to content

Commit 9a9ade7

Browse files
committed
Android Swipe Layout born
0 parents  commit 9a9ade7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2817
-0
lines changed

.gitignore

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
.gradle
2+
/local.properties
3+
/.idea/workspace.xml
4+
.DS_Store
5+
/build
6+
# built application files
7+
*.apk
8+
*.ap_
9+
10+
# files for the dex VM
11+
*.dex
12+
13+
# Java class files
14+
*.class
15+
.DS_Store
16+
17+
# generated files
18+
bin/
19+
gen/
20+
Wiki/
21+
22+
# Local configuration file (sdk path, etc)
23+
local.properties
24+
25+
# Eclipse project files
26+
.classpath
27+
.project
28+
.settings/
29+
30+
# Proguard folder generated by Eclipse
31+
proguard/
32+
33+
#Android Studio
34+
build/
35+
36+
# Intellij project files
37+
*.iml
38+
*.ipr
39+
*.iws
40+
.idea/
41+
42+
#gradle
43+
.gradle/

README.md

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Android Swipe Layout
2+
3+
This is the brother of [AndroidViewHover](https://github.com/daimajia/AndroidViewHover).
4+
5+
One year ago, I started to make an app named [EverMemo](https://play.google.com/store/apps/details?id=com.zhan_dui.evermemo) with my good friends. The designer gave me a design picture, the design like this:
6+
7+
![](http://ww1.sinaimg.cn/mw690/610dc034jw1ejoquidvvsg208i0630u4.gif)
8+
9+
I found it's pretty hard to archive this effect, cause you have to be very familiar with the Android Touch System. It was beyond my ability that moment, and I also noticed that there was no such a concept library...
10+
11+
So... as you see right now.
12+
13+
## Demo
14+
15+
![](http://ww2.sinaimg.cn/mw690/610dc034jw1ejoplapwtqg208n0e74dx.gif)
16+
17+
Before I made this, I actually found some libraries (eg.[SwipeListView](https://github.com/47deg/android-swipelistview)) that helps developers to integrate swiping with your UI component. But they have too much limitation, only in ListView, or some other limitations.
18+
19+
When I start to make this library, I set some goals:
20+
21+
- Can be easily integrated in anywhere, ListView, GridView, ViewGroup etc.
22+
- Can receive `onOpen`,`onClose`,`onUpdate` callbacks.
23+
- Can notifiy the hidden children how much they have shown.
24+
- Can be nested each other.
25+
26+
## Usage
27+
28+
### Step 1
29+
#### Gradle
30+
31+
```groovy
32+
dependencies {
33+
compile "com.daimajia.swipelayout:library:1.0.0@aar"
34+
}
35+
```
36+
37+
#### Maven
38+
39+
```xml
40+
<dependency>
41+
<groupId>com.daimajia.swipelayout</groupId>
42+
<artifactId>library</artifactId>
43+
<version>1.0.0</version>
44+
<type>apklib</type>
45+
</dependency>
46+
```
47+
48+
#### Eclipse
49+
50+
51+
### Step 2
52+
53+
Create a `SwipeLayout`:
54+
55+
- `SwipeLayout` must have 2 children (all should be an instance of `ViewGroup`).
56+
57+
```xml
58+
<com.daimajia.swipe.SwipeLayout xmlns:android="http://schemas.android.com/apk/res/android"
59+
android:layout_width="match_parent" android:layout_height="80dp">
60+
<!-- Bottom View Start-->
61+
<LinearLayout
62+
android:background="#66ddff00"
63+
android:id="@+id/bottom_wrapper"
64+
android:layout_width="160dp"
65+
android:weightSum="1"
66+
android:layout_height="match_parent">
67+
<!--What you want to show-->
68+
</LinearLayout>
69+
<!-- Bottom View End-->
70+
71+
<!-- Surface View Start -->
72+
<LinearLayout
73+
android:padding="10dp"
74+
android:background="#ffffff"
75+
android:layout_width="match_parent"
76+
android:layout_height="match_parent">
77+
<!--What you want to show in SurfaceView-->
78+
</LinearLayout>
79+
<!-- Surface View End -->
80+
</com.daimajia.swipe.SwipeLayout>
81+
```
82+
83+
There are some preset examples: [example1](./demo/src/main/res/layout/sample1.xml), [example2](./demo/src/main/res/layout/sample2.xml), [example3](./demo/src/main/res/layout/sample3.xml).
84+
85+
### Step3
86+
87+
[Source code](./demo/src/main/java/com/daimajia/swipedemo/MyActivity.java).
88+
89+
## Wiki
90+
91+
Wiki is under construction.
92+
93+
## About me
94+
95+
A student in mainland China.
96+
97+
Welcome to [offer me an internship](mailto:[email protected]). If you have any new idea about this project, feel free to [contact me](mailto:[email protected]). :smiley:
98+

build.gradle

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2+
3+
buildscript {
4+
repositories {
5+
jcenter()
6+
}
7+
dependencies {
8+
classpath 'com.android.tools.build:gradle:0.12.+'
9+
10+
// NOTE: Do not place your application dependencies here; they belong
11+
// in the individual module build.gradle files
12+
}
13+
}
14+
15+
allprojects {
16+
repositories {
17+
jcenter()
18+
}
19+
}

demo/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

demo/build.gradle

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 18
5+
buildToolsVersion "20.0.0"
6+
7+
defaultConfig {
8+
applicationId "com.daimajia.swipedemo"
9+
minSdkVersion 18
10+
targetSdkVersion 18
11+
versionCode 1
12+
versionName "1.0"
13+
}
14+
buildTypes {
15+
release {
16+
runProguard false
17+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18+
}
19+
}
20+
}
21+
22+
dependencies {
23+
compile fileTree(dir: 'libs', include: ['*.jar'])
24+
compile project(":library")
25+
compile 'com.nineoldandroids:library:2.4.0'
26+
compile 'com.daimajia.easing:library:1.0.0@aar'
27+
compile 'com.daimajia.androidanimations:library:1.1.2@aar'
28+
}

demo/proguard-rules.pro

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /Applications/Android Studio.app/sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.daimajia.swipe;
2+
3+
import android.app.Application;
4+
import android.test.ApplicationTestCase;
5+
6+
/**
7+
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
8+
*/
9+
public class ApplicationTest extends ApplicationTestCase<Application> {
10+
public ApplicationTest() {
11+
super(Application.class);
12+
}
13+
}

demo/src/main/AndroidManifest.xml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.daimajia.swipedemo" >
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@drawable/ic_launcher"
8+
android:label="@string/app_name"
9+
android:theme="@style/AppTheme" >
10+
<activity
11+
android:name="com.daimajia.swipedemo.MyActivity"
12+
android:label="@string/app_name" >
13+
<intent-filter>
14+
<action android:name="android.intent.action.MAIN" />
15+
16+
<category android:name="android.intent.category.LAUNCHER" />
17+
</intent-filter>
18+
</activity>
19+
<activity android:name="com.daimajia.swipedemo.ListViewExample"/>
20+
<activity android:name="com.daimajia.swipedemo.GridViewExample"/>
21+
</application>
22+
23+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.daimajia.swipedemo;
2+
3+
import android.app.Activity;
4+
import android.os.Bundle;
5+
import android.util.Log;
6+
import android.view.View;
7+
import android.widget.AdapterView;
8+
import android.widget.GridView;
9+
10+
import com.daimajia.swipedemo.adapter.GridViewAdapter;
11+
12+
public class GridViewExample extends Activity{
13+
14+
@Override
15+
protected void onCreate(Bundle savedInstanceState) {
16+
super.onCreate(savedInstanceState);
17+
setContentView(R.layout.gridview);
18+
final GridView gridView = (GridView)findViewById(R.id.gridview);
19+
gridView.setAdapter(new GridViewAdapter(this));
20+
gridView.setSelected(false);
21+
gridView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
22+
@Override
23+
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
24+
Log.e("onItemLongClick","onItemLongClick:" + position);
25+
return false;
26+
}
27+
});
28+
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
29+
@Override
30+
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
31+
Log.e("onItemClick","onItemClick:" + position);
32+
}
33+
});
34+
35+
36+
gridView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
37+
@Override
38+
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
39+
Log.e("onItemSelected","onItemSelected:" + position);
40+
}
41+
42+
@Override
43+
public void onNothingSelected(AdapterView<?> parent) {
44+
45+
}
46+
});
47+
}
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package com.daimajia.swipedemo;
2+
3+
import android.app.Activity;
4+
import android.content.Intent;
5+
import android.os.Bundle;
6+
import android.util.Log;
7+
import android.view.Menu;
8+
import android.view.MenuItem;
9+
import android.view.MotionEvent;
10+
import android.view.View;
11+
import android.widget.AbsListView;
12+
import android.widget.AdapterView;
13+
import android.widget.ListView;
14+
15+
import com.daimajia.swipedemo.adapter.ListViewAdapter;
16+
17+
public class ListViewExample extends Activity {
18+
19+
private ListView mListView;
20+
private ListViewAdapter mAdapter;
21+
22+
@Override
23+
protected void onCreate(Bundle savedInstanceState) {
24+
super.onCreate(savedInstanceState);
25+
setContentView(R.layout.listview);
26+
mListView = (ListView)findViewById(R.id.listview);
27+
mAdapter = new ListViewAdapter(this);
28+
mListView.setAdapter(mAdapter);
29+
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
30+
@Override
31+
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
32+
Log.e("ListView", "onItemClick:" + position);
33+
}
34+
});
35+
mListView.setOnTouchListener(new View.OnTouchListener() {
36+
@Override
37+
public boolean onTouch(View v, MotionEvent event) {
38+
Log.e("ListView","OnTouch");
39+
return false;
40+
}
41+
});
42+
mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
43+
@Override
44+
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
45+
Log.e("ListView","onItemLongClick:" + position);
46+
return false;
47+
}
48+
});
49+
mListView.setOnScrollListener(new AbsListView.OnScrollListener() {
50+
@Override
51+
public void onScrollStateChanged(AbsListView view, int scrollState) {
52+
Log.e("ListView","onScrollStateChanged");
53+
}
54+
55+
@Override
56+
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
57+
58+
}
59+
});
60+
61+
mListView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
62+
@Override
63+
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
64+
Log.e("ListView", "onItemSelected:" + position);
65+
}
66+
67+
@Override
68+
public void onNothingSelected(AdapterView<?> parent) {
69+
Log.e("ListView", "onNothingSelected:");
70+
}
71+
});
72+
}
73+
74+
75+
@Override
76+
public boolean onCreateOptionsMenu(Menu menu) {
77+
// Inflate the menu; this adds items to the action bar if it is present.
78+
getMenuInflater().inflate(R.menu.my, menu);
79+
return true;
80+
}
81+
82+
@Override
83+
public boolean onOptionsItemSelected(MenuItem item) {
84+
// Handle action bar item clicks here. The action bar will
85+
// automatically handle clicks on the Home/Up button, so long
86+
// as you specify a parent activity in AndroidManifest.xml.
87+
int id = item.getItemId();
88+
if (id == R.id.action_listview) {
89+
startActivity(new Intent(this, ListViewExample.class));
90+
return true;
91+
}else if(id == R.id.action_gridview){
92+
startActivity(new Intent(this, GridViewExample.class));
93+
return true;
94+
}
95+
return super.onOptionsItemSelected(item);
96+
}
97+
}

0 commit comments

Comments
 (0)