Skip to content
This repository has been archived by the owner on Oct 20, 2022. It is now read-only.

Commit

Permalink
Created Project.
Browse files Browse the repository at this point in the history
  • Loading branch information
ragunathjawahar committed Jun 9, 2012
0 parents commit ba46751
Show file tree
Hide file tree
Showing 16 changed files with 455 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .classpath
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
bin
gen

33 changes: 33 additions & 0 deletions .project
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>simple-section-adapter</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
23 changes: 23 additions & 0 deletions AndroidManifest.xml
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mobsandgeeks.adapters"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="7" />

<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".demo.SSADemoActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
62 changes: 62 additions & 0 deletions README.md
@@ -0,0 +1,62 @@
About
=====

This is the **SIMPLEST** [Section Adapter][google-search] available for Android. Works with any custom adapter that you already have. No project specific dependencies. Just include the [jar][jar-download] or the sources[github-project] to your Android project.

Pros
----

- The simplest implementation requires just *6 lines* of code.
- Zero project specific dependencies.

Versions
-------

- Android 1.6 and up

Implementation
--------------

// 1. Create a Sectionizer
class BookSectionizer implements Sectionizer<Book> {

@Override
public String getSectionTitleForItem(Book book) {
return book.getGenre();
}
}

// 2. Wrap your existing adapter with the SimpleSectionAdapter
....
sectionAdapter = new SimpleSectionAdapter<Book>(this,
yourBookAdapter, R.layout.section_header, R.id.title,
new BookSectionizer());
...

OnItemClickListener
-------------------
While using an [OnItemClickListener][item-click-listener] instead of using the list item's position directly, use is as shown below.

@Override
public void onItemClick(AdapterView<?> parentView, View view, int position, long id) {
int actualPosition = sectionAdapter.getUndecoratedItemPosition(position);

// More code...
}


FAQs
----
- **Can I use SimpleSectionAdapter with ArrayAdapter or CursorAdapter?**
<br />Yes, you can use [SimpleSectionAdapter][simple-section-adpater] with any adapter that extends [BaseAdapter][base-adapter].

- **Are there any resource files that has to be included with my project?**
<br />No, you don't have to include anything beyond the SimpleSectionAdapter and the Sectionizer.

[google-search]: https://www.google.co.in/search?ie=UTF-8&q=android+section+adapter
[github-project]: https://github.com/ragunathjawahar/simple-section-adapter
[jar-download]: http://jarlink
[item-click-listener]: http://developer.android.com/reference/android/widget/AdapterView.OnItemClickListener.html
[simple-section-adpater]: http://linktosimplesectionadapter
[base-adapter]: http://developer.android.com/reference/android/widget/BaseAdapter.html

20 changes: 20 additions & 0 deletions proguard-project.txt
@@ -0,0 +1,20 @@
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
14 changes: 14 additions & 0 deletions project.properties
@@ -0,0 +1,14 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

# Project target.
target=android-7
Binary file added res/drawable-hdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-ldpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-mdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-xhdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions res/layout/main.xml
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />

</LinearLayout>
7 changes: 7 additions & 0 deletions res/values/strings.xml
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="hello">Hello World, SSADemoActivity!</string>
<string name="app_name">Simple-section-adapter</string>

</resources>
36 changes: 36 additions & 0 deletions src/com/mobsandgeeks/adapters/Sectionizer.java
@@ -0,0 +1,36 @@
/*
* Copyright (C) 2012 Mobs and Geeks
*
* 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 com.mobsandgeeks.adapters;

/**
* Interface provides mechanism for supplying titles for instances based on the property they are
* compared against. The parameterized type of the <b>Sectionizer</b> should be same as that of the
* {@link SimpleSectionAdapter}.
*
* @author Ragunath Jawahar R (rj@mobsandgeeks.com)
* @version 1.0
*/
public interface Sectionizer<T> {

/**
* Returns the title for the given instance from the data source.
*
* @param instance The instance obtained from the data source of the decorated list adapter.
* @return section title for the given instance.
*/
public String getSectionTitleForItem(T instance);
}

0 comments on commit ba46751

Please sign in to comment.