Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding DraggableHorizontalListView based on HListView #86

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
69 changes: 5 additions & 64 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,65 +1,13 @@
Horizontal Variable ListView
Draggable Horizontal ListView
==========================

Horizontal ListView for Android. Based on the official [ListView][3] google code.
The library includes also an ExpandableHListView, also based on the official [ExpandableListView][4]. <br />
See the demo project for sample implementations
This is forked from [sephiroth74/HorizontalVariableListView](https://github.com/sephiroth74/HorizontalVariableListView) and modified with [DynamicListView from DevBytes of Android Developer](https://www.youtube.com/watch?v=_BZIvjMgH-Q) to come up with a **Draggable** **Horizontal** ListView.

## Usage (gradle)
Add this line to your dependency group:


compile 'it.sephiroth.android.library.horizontallistview:hlistview:1.2.2'

## Features
It supports almost all the features of the ListView widget.
There are minor differences in the attributes supported like "hlv_dividerWidth" instead of the default "dividerHeight".

This is the styleable used for the HListView class:
<pre>
&lt;declare-styleable name="HListView">
&lt;attr name="android:entries" />
&lt;attr name="android:divider" />
&lt;attr name="hlv_dividerWidth" format="dimension" />
&lt;attr name="hlv_headerDividersEnabled" format="boolean" />
&lt;attr name="hlv_footerDividersEnabled" format="boolean" />
&lt;attr name="hlv_overScrollHeader" format="reference|color" />
&lt;attr name="hlv_overScrollFooter" format="reference|color" />

&lt;!--
When "wrap_content" is used as value of the layout_height property.
Pass the position, inside the adapter, of the view being used to measure the view
or '-1' to use the default behavior ( default is -1 )
-->
&lt;attr name="hlv_measureWithChild" format="integer" />
&lt;/declare-styleable>


&lt;declare-styleable name="AbsHListView">
&lt;attr name="android:listSelector" />
&lt;attr name="android:smoothScrollbar" />
&lt;attr name="android:drawSelectorOnTop" />
&lt;attr name="android:cacheColorHint" />
&lt;attr name="android:scrollingCache" />
&lt;attr name="android:choiceMode" />

&lt;attr name="hlv_stackFromRight" format="boolean" />
&lt;attr name="hlv_transcriptMode">
&lt;enum name="disabled" value="0"/>
&lt;enum name="normal" value="1" />
&lt;enum name="alwaysScroll" value="2" />
&lt;/attr>

&lt;/declare-styleable>

</pre>
Please also checkout live demo on [Youtube](http://youtu.be/mnaq-MA16Cs) to see if it meets your requirement.

## ChangeLog

* 1.2.0 Added the **ExpandableHListView**

## API Requirements
The minimum supported Android version is android 2.3 (API Level 9)
* 0.0.1 Add DraggableHorizontalListView & its demo Activity

## License
This software is distributed under Apache License 2.0:
Expand All @@ -68,12 +16,5 @@ http://www.apache.org/licenses/LICENSE-2.0
---

> Author
> [Alessandro Crugnola][2]



[2]: http://www.sephiroth.it

[3]: http://developer.android.com/reference/android/widget/ListView.html
> [Robert Wang](http://twitter.com/cyberrob)

[4]: http://developer.android.com/reference/android/widget/ExpandableListView.html
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:0.10.+'
classpath 'com.android.tools.build:gradle:0.12.2'
}
}

Expand Down
3 changes: 3 additions & 0 deletions demo/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
<activity
android:name=".ExpandableListActivity"
android:label="Expandable List" />

<activity android:name=".SimpleDraggableHListViewActivity"
android:label="Simple Draggable HListView" />
</application>

</manifest>
2 changes: 1 addition & 1 deletion demo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ dependencies {

android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
buildToolsVersion "19.1.0"

defaultConfig {
versionCode 1
Expand Down
23 changes: 23 additions & 0 deletions demo/res/layout/activity_draggable_hlistview.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:orientation="vertical" >

<it.sephiroth.android.library.widget.DraggableHorizontalListView
android:id="@+id/draggable_hListView"
android:layout_width="match_parent"
android:layout_height="300dip"
android:paddingTop="20dip"
android:paddingBottom="20dip"
android:background="#11000000" />
</LinearLayout>


</LinearLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,34 @@

public class MainActivity extends ListActivity {

@Override
protected void onCreate( final Bundle savedInstanceState ) {
super.onCreate( savedInstanceState );

List<String> activities = new ArrayList<String>();
activities.add( "Simple List" );
activities.add( "Expandable List" );


setListAdapter( new ArrayAdapter<String>( this, android.R.layout.simple_list_item_1, activities ) );
}

@Override
protected void onListItemClick( final ListView l, final View v, final int position, final long id ) {

switch( position ) {
case 0:
startActivity( new Intent( this, SimpleHListActivity.class ) );
break;
case 1:
startActivity( new Intent( this, ExpandableListActivity.class ) );
break;
}

super.onListItemClick( l, v, position, id );
}
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

List<String> activities = new ArrayList<String>();
activities.add("Simple List");
activities.add("Expandable List");
activities.add("Draggable HListView");


setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, activities));
}

@Override
protected void onListItemClick(final ListView l, final View v, final int position, final long id) {

switch (position) {
case 0:
startActivity(new Intent(this, SimpleHListActivity.class));
break;
case 1:
startActivity(new Intent(this, ExpandableListActivity.class));
break;
case 2:
startActivity(new Intent(this, SimpleDraggableHListViewActivity.class));
break;
}

super.onListItemClick(l, v, position, id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
package it.sephiroth.android.sample.horizontalvariablelistviewdemo;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import it.sephiroth.android.library.widget.AdapterView;
import it.sephiroth.android.library.widget.DraggableHorizontalListView;

/**
* Created by robertwang on 9/11/14.
*/
public class SimpleDraggableHListViewActivity extends Activity implements AdapterView.OnItemClickListener {

private static final String TAG = SimpleDraggableHListViewActivity.class.getSimpleName();
private TestAdapter mAdapter;
private DraggableHorizontalListView listView;
private ArrayList<String> items;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_draggable_hlistview);

items = new ArrayList<String>();
for (int i = 0; i < 50; i++) {
items.add(String.valueOf(i));
}

listView.setList(items);

mAdapter = new TestAdapter(this, R.layout.test_item_1, android.R.id.text1, items);
listView.setHeaderDividersEnabled(true);
listView.setFooterDividersEnabled(true);

listView.setChoiceMode(ListView.CHOICE_MODE_NONE);

//if( listView.getChoiceMode() == ListView.CHOICE_MODE_MULTIPLE ) {
listView.setOnItemClickListener(this);
//}

listView.setAdapter(mAdapter);
}

@Override
protected void onStop() {
super.onStop();
String finalContent = "";
for (String item : items) {
if (items.indexOf(item) == items.size() - 1) {
finalContent += item;
} else {
finalContent += item + ",";
}
}
Log.d(TAG, "Final content: " + finalContent);
}

@Override
public void onContentChanged() {
super.onContentChanged();
listView = (DraggableHorizontalListView) findViewById(R.id.draggable_hListView);
}

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

}

class TestAdapter extends ArrayAdapter<String> {

private static final long INVALID_ID = -1;
List<String> mItems;
LayoutInflater mInflater;
int mResource;
int mTextResId;

public TestAdapter(Context context, int resourceId, int textViewResourceId, List<String> objects) {
super(context, resourceId, textViewResourceId, objects);
mInflater = LayoutInflater.from(context);
mResource = resourceId;
mTextResId = textViewResourceId;
mItems = objects;
}

@Override
public boolean hasStableIds() {
return true;
}

@Override
public long getItemId(int position) {

if (position < 0 || position >= mItems.size()) {
return INVALID_ID;
}
return getItem(position).hashCode();
}

@Override
public int getViewTypeCount() {
return 3;
}

@Override
public int getItemViewType(int position) {
return position % 3;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

if (null == convertView) {
convertView = mInflater.inflate(mResource, parent, false);
}

TextView textView = (TextView) convertView.findViewById(mTextResId);
textView.setText(getItem(position));

int type = getItemViewType(position);

ViewGroup.LayoutParams params = convertView.getLayoutParams();
if (type == 0) {
params.width = getResources().getDimensionPixelSize(R.dimen.item_size_1);
} else if (type == 1) {
params.width = getResources().getDimensionPixelSize(R.dimen.item_size_2);
} else {
params.width = getResources().getDimensionPixelSize(R.dimen.item_size_3);
}

return convertView;
}
}
}
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Mar 04 09:42:43 EST 2014
#Fri Sep 12 10:32:57 CST 2014
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.10-all.zip
distributionUrl=http\://services.gradle.org/distributions/gradle-1.12-all.zip
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ version VERSION_NAME

android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
buildToolsVersion "19.1.0"

defaultConfig {
minSdkVersion 9
Expand Down
Loading