diff options
Diffstat (limited to 'libraries/StickyListHeaders/sample')
24 files changed, 891 insertions, 0 deletions
diff --git a/libraries/StickyListHeaders/sample/AndroidManifest.xml b/libraries/StickyListHeaders/sample/AndroidManifest.xml new file mode 100644 index 000000000..4bf61a441 --- /dev/null +++ b/libraries/StickyListHeaders/sample/AndroidManifest.xml @@ -0,0 +1,27 @@ +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="se.emilsjolander.stickylistheaders" + android:versionCode="2" + android:versionName="2.0"> + + <uses-sdk + android:minSdkVersion="7" + android:targetSdkVersion="18" /> + + <application + android:allowBackup="true" + android:icon="@drawable/ic_launcher" + android:label="@string/app_name" + android:theme="@style/Theme.AppCompat.Light.DarkActionBar" + android:supportsRtl="true"> + <activity + android:name=".TestActivity" + 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>
\ No newline at end of file diff --git a/libraries/StickyListHeaders/sample/build.gradle b/libraries/StickyListHeaders/sample/build.gradle new file mode 100644 index 000000000..b620008e3 --- /dev/null +++ b/libraries/StickyListHeaders/sample/build.gradle @@ -0,0 +1,23 @@ +apply plugin: 'android' + +repositories { + mavenCentral() +} +dependencies { + compile project(':library') + compile 'com.android.support:appcompat-v7:19.0.+' + compile 'com.android.support:support-v4:19.0.0' +} + +android { + compileSdkVersion 19 + buildToolsVersion '19.0.0' + + sourceSets { + main { + manifest.srcFile 'AndroidManifest.xml' + java.srcDirs = ['src'] + res.srcDirs = ['res'] + } + } +} diff --git a/libraries/StickyListHeaders/sample/libs/android-support-v4.jar b/libraries/StickyListHeaders/sample/libs/android-support-v4.jar Binary files differnew file mode 100644 index 000000000..cf12d2839 --- /dev/null +++ b/libraries/StickyListHeaders/sample/libs/android-support-v4.jar diff --git a/libraries/StickyListHeaders/sample/project.properties b/libraries/StickyListHeaders/sample/project.properties new file mode 100644 index 000000000..a6cf15dae --- /dev/null +++ b/libraries/StickyListHeaders/sample/project.properties @@ -0,0 +1,15 @@ +# 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-19 +android.library.reference.1=../library diff --git a/libraries/StickyListHeaders/sample/res/drawable-hdpi/ic_drawer.png b/libraries/StickyListHeaders/sample/res/drawable-hdpi/ic_drawer.png Binary files differnew file mode 100644 index 000000000..6614ea4f4 --- /dev/null +++ b/libraries/StickyListHeaders/sample/res/drawable-hdpi/ic_drawer.png diff --git a/libraries/StickyListHeaders/sample/res/drawable-hdpi/ic_launcher.png b/libraries/StickyListHeaders/sample/res/drawable-hdpi/ic_launcher.png Binary files differnew file mode 100644 index 000000000..96a442e5b --- /dev/null +++ b/libraries/StickyListHeaders/sample/res/drawable-hdpi/ic_launcher.png diff --git a/libraries/StickyListHeaders/sample/res/drawable-ldpi/ic_launcher.png b/libraries/StickyListHeaders/sample/res/drawable-ldpi/ic_launcher.png Binary files differnew file mode 100644 index 000000000..99238729d --- /dev/null +++ b/libraries/StickyListHeaders/sample/res/drawable-ldpi/ic_launcher.png diff --git a/libraries/StickyListHeaders/sample/res/drawable-mdpi/ic_drawer.png b/libraries/StickyListHeaders/sample/res/drawable-mdpi/ic_drawer.png Binary files differnew file mode 100644 index 000000000..b05c026c1 --- /dev/null +++ b/libraries/StickyListHeaders/sample/res/drawable-mdpi/ic_drawer.png diff --git a/libraries/StickyListHeaders/sample/res/drawable-mdpi/ic_launcher.png b/libraries/StickyListHeaders/sample/res/drawable-mdpi/ic_launcher.png Binary files differnew file mode 100644 index 000000000..359047dfa --- /dev/null +++ b/libraries/StickyListHeaders/sample/res/drawable-mdpi/ic_launcher.png diff --git a/libraries/StickyListHeaders/sample/res/drawable-xhdpi/ic_drawer.png b/libraries/StickyListHeaders/sample/res/drawable-xhdpi/ic_drawer.png Binary files differnew file mode 100644 index 000000000..bcf49dd73 --- /dev/null +++ b/libraries/StickyListHeaders/sample/res/drawable-xhdpi/ic_drawer.png diff --git a/libraries/StickyListHeaders/sample/res/drawable-xhdpi/ic_launcher.png b/libraries/StickyListHeaders/sample/res/drawable-xhdpi/ic_launcher.png Binary files differnew file mode 100644 index 000000000..71c6d760f --- /dev/null +++ b/libraries/StickyListHeaders/sample/res/drawable-xhdpi/ic_launcher.png diff --git a/libraries/StickyListHeaders/sample/res/drawable/header_selector.xml b/libraries/StickyListHeaders/sample/res/drawable/header_selector.xml new file mode 100644 index 000000000..5dfb8265c --- /dev/null +++ b/libraries/StickyListHeaders/sample/res/drawable/header_selector.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="utf-8"?> +<selector xmlns:android="http://schemas.android.com/apk/res/android" > + + <item android:state_pressed="true" android:drawable="@color/header_pressed" /> + <item android:drawable="@color/header_normal" /> + +</selector>
\ No newline at end of file diff --git a/libraries/StickyListHeaders/sample/res/layout/header.xml b/libraries/StickyListHeaders/sample/res/layout/header.xml new file mode 100644 index 000000000..177e40c4e --- /dev/null +++ b/libraries/StickyListHeaders/sample/res/layout/header.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="utf-8"?> +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:background="@drawable/header_selector" > + + <se.emilsjolander.stickylistheaders.views.UnderlineTextView + android:id="@+id/text1" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_gravity="start|left" + android:padding="5dp" + android:textColor="@android:color/white" + android:textSize="17sp" + android:textStyle="bold" /> + +</RelativeLayout>
\ No newline at end of file diff --git a/libraries/StickyListHeaders/sample/res/layout/list_footer.xml b/libraries/StickyListHeaders/sample/res/layout/list_footer.xml new file mode 100644 index 000000000..4fa22c1f3 --- /dev/null +++ b/libraries/StickyListHeaders/sample/res/layout/list_footer.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="utf-8"?> +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" > + + <TextView android:text="@string/app_name" + android:layout_width="match_parent" + android:layout_height="700dip" + android:gravity="center" + android:layout_gravity="center"/> + + +</FrameLayout>
\ No newline at end of file diff --git a/libraries/StickyListHeaders/sample/res/layout/list_header.xml b/libraries/StickyListHeaders/sample/res/layout/list_header.xml new file mode 100644 index 000000000..97d46c69b --- /dev/null +++ b/libraries/StickyListHeaders/sample/res/layout/list_header.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="utf-8"?> +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" > + + <TextView android:text="@string/app_name" + android:layout_width="match_parent" + android:layout_height="400dip" + android:gravity="center" + android:layout_gravity="center"/> + + +</FrameLayout>
\ No newline at end of file diff --git a/libraries/StickyListHeaders/sample/res/layout/main.xml b/libraries/StickyListHeaders/sample/res/layout/main.xml new file mode 100644 index 000000000..2d22c3266 --- /dev/null +++ b/libraries/StickyListHeaders/sample/res/layout/main.xml @@ -0,0 +1,114 @@ +<android.support.v4.widget.DrawerLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/drawer_layout" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <FrameLayout + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical"> + + <se.emilsjolander.stickylistheaders.StickyListHeadersListView + android:id="@+id/list" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:clipToPadding="false" + android:drawSelectorOnTop="true" + android:padding="16dp" + android:scrollbarStyle="outsideOverlay" + android:fastScrollEnabled="true"/> + + <TextView + android:id="@+id/empty" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:gravity="center" + android:text="@string/empty" + android:textSize="30sp" + android:visibility="gone"/> + + </FrameLayout> + + <ScrollView + android:id="@+id/left_drawer" + android:layout_width="240dp" + android:layout_height="match_parent" + android:layout_gravity="start" + android:padding="5dp" + android:scrollbars="none" + android:clickable="true" + android:background="@android:color/white"> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical"> + + <se.emilsjolander.stickylistheaders.views.UnderlineTextView + style="@style/MenuSectionHeader" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_gravity="start|left" + android:text="@string/actions" + android:textStyle="bold"/> + + <Button + android:layout_width="match_parent" + android:layout_height="48dp" + android:gravity="left|center_vertical" + android:text="@string/restore_list" + android:id="@+id/restore_button"/> + + <Button + android:layout_width="match_parent" + android:layout_height="48dp" + android:gravity="left|center_vertical" + android:text="@string/update_list" + android:id="@+id/update_button"/> + + <Button + android:layout_width="match_parent" + android:layout_height="48dp" + android:gravity="left|center_vertical" + android:id="@+id/clear_button" + android:text="@string/clear_list"/> + + <se.emilsjolander.stickylistheaders.views.UnderlineTextView + style="@style/MenuSectionHeader" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_gravity="start|left" + android:text="@string/options" + android:textStyle="bold"/> + + <CheckBox + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/sticky_header" + android:id="@+id/sticky_checkBox" + android:checked="true"/> + + <CheckBox + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/fade_header" + android:id="@+id/fade_checkBox" + android:checked="true"/> + + <CheckBox + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/draw_behind_header" + android:id="@+id/draw_behind_checkBox" + android:checked="true"/> + + <CheckBox + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/fast_scroll" + android:id="@+id/fast_scroll_checkBox" + android:checked="true"/> + </LinearLayout> + </ScrollView> +</android.support.v4.widget.DrawerLayout>
\ No newline at end of file diff --git a/libraries/StickyListHeaders/sample/res/layout/test_list_item_layout.xml b/libraries/StickyListHeaders/sample/res/layout/test_list_item_layout.xml new file mode 100644 index 000000000..0f8efc32e --- /dev/null +++ b/libraries/StickyListHeaders/sample/res/layout/test_list_item_layout.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="utf-8"?> +<TextView xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/text" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_gravity="center_vertical" + android:paddingBottom="20dp" + android:paddingTop="20dp" /> diff --git a/libraries/StickyListHeaders/sample/res/values/arrays.xml b/libraries/StickyListHeaders/sample/res/values/arrays.xml new file mode 100755 index 000000000..5cd71de49 --- /dev/null +++ b/libraries/StickyListHeaders/sample/res/values/arrays.xml @@ -0,0 +1,230 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + + <string-array name="countries"> + + <item>Afghanistan</item> + <item>Albania</item> + <item>Algeria</item> + <item>Andorra</item> + <item>Angola</item> + <item>Antigua & Barbuda</item> + <item>Argentina</item> + <item>Armenia</item> + <item>Australia</item> + <item>Austria</item> + <item>Azerbaijan</item> + + <item>Bahamas</item> + <item>Bahrain</item> + <item>Bangladesh</item> + <item>Barbados</item> + <item>Belarus</item> + <item>Belgium</item> + <item>Belize</item> + <item>Benin</item> + <item>Bhutan</item> + <item>Bolivia</item> + <item>Bosnia and Herzegovina</item> + <item>Botswana</item> + <item>Brazil</item> + <item>Brunei</item> + <item>Bulgaria</item> + <item>Burkina Faso</item> + <item>Burma</item> + <item>Burundi</item> + + <item>Cambodia</item> + <item>Cameroon</item> + <item>Canada</item> + <item>Cape Verde</item> + <item>Central African Republic</item> + <item>Chad</item> + <item>Chile</item> + <item>China</item> + <item>Colombia</item> + <item>Comoros</item> + <item>Congo, Democratic Republic of the</item> + <item>Congo, Republic of the</item> + <item>Costa Rica</item> + <item>Cote d\'voire</item> + <item>Croatia</item> + <item>Cuba</item> + <item>Cyprus</item> + <item>Czech Republic</item> + + <item>Denmark</item> + <item>Djibouti</item> + <item>Dominica</item> + <item>Dominican Republic</item> + + <item>Ecuador</item> + <item>Egypt</item> + <item>El Salvador</item> + <item>Equatorial Guinea</item> + <item>Eritrea</item> + <item>Estonia</item> + <item>Ethiopia</item> + + <item>Fiji</item> + <item>Finland</item> + <item>France</item> + + <item>Gabon</item> + <item>Gambia, The</item> + <item>Georgia</item> + <item>Ghana</item> + <item>Greece</item> + <item>Grenada</item> + <item>Guatemala</item> + <item>Guinea</item> + <item>Guinea-Bissau</item> + <item>Guyana</item> + + <item>Haiti</item> + <item>Holy See</item> + <item>Honduras</item> + <item>Hong Kong</item> + <item>Hungary</item> + + <item>Iceland</item> + <item>India</item> + <item>Indonesia</item> + <item>Iran</item> + <item>Iraq</item> + <item>Ireland</item> + <item>Israel</item> + <item>Italy</item> + + <item>Jamaica</item> + <item>Japan</item> + <item>Jordan</item> + + <item>Kazakhstan</item> + <item>Kenya</item> + <item>Kiribati</item> + <item>Korea, North</item> + <item>Korea, South</item> + <item>Kosovo</item> + <item>Kuwait</item> + <item>Kyrgyzstan</item> + + <item>Laos</item> + <item>Latvia</item> + <item>Lebanon</item> + <item>Lesotho</item> + <item>Liberia</item> + <item>Libya</item> + <item>Liechtenstein</item> + <item>Lithuania</item> + <item>Luxembourg</item> + + <item>Macau</item> + <item>Macedonia</item> + <item>Madagascar</item> + <item>Malawi</item> + <item>Malaysia</item> + <item>Maldives</item> + <item>Mali</item> + <item>Malta</item> + <item>Marshall Islands</item> + <item>Mauritania</item> + <item>Mauritius</item> + <item>Mexico</item> + <item>Micronesia</item> + <item>Moldova</item> + <item>Monaco</item> + <item>Mongolia</item> + <item>Montenegro</item> + <item>Morocco</item> + <item>Mozambique</item> + + <item>Namibia</item> + <item>Nauru</item> + <item>Nepal</item> + <item>Netherlands</item> + <item>Netherlands Antilles</item> + <item>New Zealand</item> + <item>Nicaragua</item> + <item>Niger</item> + <item>Nigeria</item> + <item>North Korea</item> + <item>Norway</item> + + <item>Oman</item> + + <item>Pakistan</item> + <item>Palau</item> + <item>Palestinian Territories</item> + <item>Panama</item> + <item>Papua New Guinea</item> + <item>Paraguay</item> + <item>Peru</item> + <item>Philippines</item> + <item>Poland</item> + <item>Portugal</item> + + <item>Qatar</item> + + <item>Romania</item> + <item>Russia</item> + <item>Rwanda</item> + + <item>Saint Kitts and Nevis</item> + <item>Saint Lucia</item> + <item>Saint Vincent and the Grenadines</item> + <item>Samoa</item> + <item>San Marino</item> + <item>Sao Tome and Principe</item> + <item>Saudi Arabia</item> + <item>Senegal</item> + <item>Serbia</item> + <item>Seychelles</item> + <item>Sierra Leone</item> + <item>Singapore</item> + <item>Slovakia</item> + <item>Slovenia</item> + <item>Solomon Islands</item> + <item>Somalia</item> + <item>South Africa</item> + <item>South Korea</item> + <item>South Sudan</item> + <item>Spain</item> + <item>Sri Lanka</item> + <item>Sudan</item> + <item>Suriname</item> + <item>Swaziland</item> + <item>Sweden</item> + <item>Switzerland</item> + <item>Syria</item> + + <item>Taiwan</item> + <item>Tajikistan</item> + <item>Tanzania</item> + <item>Thailand </item> + <item>Timor-Leste</item> + <item>Togo</item> + <item>Tonga</item> + <item>Trinidad and Tobago</item> + <item>Tunisia</item> + <item>Turkey</item> + <item>Turkmenistan</item> + <item>Tuvalu</item> + + <item>Uganda</item> + <item>Ukraine</item> + <item>United Arab Emirates</item> + <item>United Kingdom</item> + <item>Uruguay</item> + <item>Uzbekistan</item> + + <item>Vanuatu</item> + <item>Venezuela</item> + <item>Vietnam</item> + + <item>Yemen</item> + + <item>Zambia</item> + <item>Zimbabwe</item> + </string-array> +</resources> diff --git a/libraries/StickyListHeaders/sample/res/values/colors.xml b/libraries/StickyListHeaders/sample/res/values/colors.xml new file mode 100644 index 000000000..601687e2e --- /dev/null +++ b/libraries/StickyListHeaders/sample/res/values/colors.xml @@ -0,0 +1,7 @@ +<resources> + + <color name="header_normal">#ffe74c3c</color> + <color name="header_pressed">#ffc0392b</color> + <color name="menu_section_header">#FFDDDDDD</color> + +</resources>
\ No newline at end of file diff --git a/libraries/StickyListHeaders/sample/res/values/strings.xml b/libraries/StickyListHeaders/sample/res/values/strings.xml new file mode 100644 index 000000000..6beadbe75 --- /dev/null +++ b/libraries/StickyListHeaders/sample/res/values/strings.xml @@ -0,0 +1,20 @@ +<resources> + + <string name="app_name">StickyListHeaders Sample</string> + <string name="restore">Restore</string> + <string name="update">Update</string> + <string name="clear">Clear</string> + <string name="empty">Empty Adapter</string> + <string name="drawer_open">Drawer Open</string> + <string name="drawer_close">Drawer Close</string> + <string name="options">OPTIONS</string> + <string name="actions">ACTIONS</string> + <string name="restore_list">Restore list</string> + <string name="update_list">Update list</string> + <string name="clear_list">Clear list</string> + <string name="sticky_header">Sticky header</string> + <string name="fade_header">Fade header</string> + <string name="draw_behind_header">Draw behind header</string> + <string name="fast_scroll">Fast scroll</string> + +</resources>
\ No newline at end of file diff --git a/libraries/StickyListHeaders/sample/res/values/style.xml b/libraries/StickyListHeaders/sample/res/values/style.xml new file mode 100644 index 000000000..b34634b58 --- /dev/null +++ b/libraries/StickyListHeaders/sample/res/values/style.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <style name="MenuSectionHeader"> + <item name="android:padding">5dp</item> + <item name="android:textStyle">bold</item> + <item name="android:textColor">@color/menu_section_header</item> + <item name="android:textSize">14sp</item> + </style> +</resources>
\ No newline at end of file diff --git a/libraries/StickyListHeaders/sample/src/se/emilsjolander/stickylistheaders/TestActivity.java b/libraries/StickyListHeaders/sample/src/se/emilsjolander/stickylistheaders/TestActivity.java new file mode 100644 index 000000000..dc795ff4e --- /dev/null +++ b/libraries/StickyListHeaders/sample/src/se/emilsjolander/stickylistheaders/TestActivity.java @@ -0,0 +1,169 @@ +package se.emilsjolander.stickylistheaders; + +import android.annotation.TargetApi; +import android.content.res.Configuration; +import android.os.Build; +import android.os.Bundle; +import android.support.v4.app.ActionBarDrawerToggle; +import android.support.v4.widget.DrawerLayout; +import android.support.v7.app.ActionBarActivity; +import android.view.MenuItem; +import android.view.View; +import android.widget.*; + +/** + * @author Emil Sjölander + */ +public class TestActivity extends ActionBarActivity implements + AdapterView.OnItemClickListener, StickyListHeadersListView.OnHeaderClickListener, + StickyListHeadersListView.OnStickyHeaderOffsetChangedListener { + + private TestBaseAdapter mAdapter; + private DrawerLayout mDrawerLayout; + private ActionBarDrawerToggle mDrawerToggle; + private boolean fadeHeader = true; + + private StickyListHeadersListView stickyList; + + private Button restoreButton; + private Button updateButton; + private Button clearButton; + + private CheckBox stickyCheckBox; + private CheckBox fadeCheckBox; + private CheckBox drawBehindCheckBox; + private CheckBox fastScrollCheckBox; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.main); + + mAdapter = new TestBaseAdapter(this); + + stickyList = (StickyListHeadersListView) findViewById(R.id.list); + stickyList.setOnItemClickListener(this); + stickyList.setOnHeaderClickListener(this); + stickyList.setOnStickyHeaderOffsetChangedListener(this); +// mStickyList.addHeaderView(inflater.inflate(R.layout.list_header, null)); +// mStickyList.addFooterView(inflater.inflate(R.layout.list_footer, null)); + stickyList.setEmptyView(findViewById(R.id.empty)); + stickyList.setDrawingListUnderStickyHeader(true); + stickyList.setAreHeadersSticky(true); + stickyList.setAdapter(mAdapter); + + mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); + mDrawerToggle = new ActionBarDrawerToggle( + this, /* host Activity */ + mDrawerLayout, /* DrawerLayout object */ + R.drawable.ic_drawer, /* nav drawer icon to replace 'Up' caret */ + R.string.drawer_open, /* "open drawer" description */ + R.string.drawer_close /* "close drawer" description */ + ); + + // Set the drawer toggle as the DrawerListener + mDrawerLayout.setDrawerListener(mDrawerToggle); + + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setHomeButtonEnabled(true); + + restoreButton = (Button) findViewById(R.id.restore_button); + restoreButton.setOnClickListener(buttonListener); + updateButton = (Button) findViewById(R.id.update_button); + updateButton.setOnClickListener(buttonListener); + clearButton = (Button) findViewById(R.id.clear_button); + clearButton.setOnClickListener(buttonListener); + + stickyCheckBox = (CheckBox) findViewById(R.id.sticky_checkBox); + stickyCheckBox.setOnCheckedChangeListener(checkBoxListener); + fadeCheckBox = (CheckBox) findViewById(R.id.fade_checkBox); + fadeCheckBox.setOnCheckedChangeListener(checkBoxListener); + drawBehindCheckBox = (CheckBox) findViewById(R.id.draw_behind_checkBox); + drawBehindCheckBox.setOnCheckedChangeListener(checkBoxListener); + fastScrollCheckBox = (CheckBox) findViewById(R.id.fast_scroll_checkBox); + fastScrollCheckBox.setOnCheckedChangeListener(checkBoxListener); + } + + @Override + protected void onPostCreate(Bundle savedInstanceState) { + super.onPostCreate(savedInstanceState); + // Sync the toggle state after onRestoreInstanceState has occurred. + mDrawerToggle.syncState(); + } + + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + mDrawerToggle.onConfigurationChanged(newConfig); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (mDrawerToggle.onOptionsItemSelected(item)) { + return true; + } + + return super.onOptionsItemSelected(item); + } + + CompoundButton.OnCheckedChangeListener checkBoxListener = new CompoundButton.OnCheckedChangeListener() { + + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + switch (buttonView.getId()) { + case R.id.sticky_checkBox: + stickyList.setAreHeadersSticky(isChecked); + break; + case R.id.fade_checkBox: + fadeHeader = isChecked; + break; + case R.id.draw_behind_checkBox: + stickyList.setDrawingListUnderStickyHeader(isChecked); + break; + case R.id.fast_scroll_checkBox: + stickyList.setFastScrollEnabled(isChecked); + stickyList.setFastScrollAlwaysVisible(isChecked); + break; + } + } + }; + + View.OnClickListener buttonListener = new View.OnClickListener() { + @Override + public void onClick(View view) { + switch (view.getId()) { + case R.id.restore_button: + mAdapter.restore(); + break; + case R.id.update_button: + mAdapter.notifyDataSetChanged(); + break; + case R.id.clear_button: + mAdapter.clear(); + break; + } + } + }; + + @Override + public void onItemClick(AdapterView<?> parent, View view, int position, + long id) { + Toast.makeText(this, "Item " + position + " clicked!", + Toast.LENGTH_SHORT).show(); + } + + @Override + public void onHeaderClick(StickyListHeadersListView l, View header, + int itemPosition, long headerId, boolean currentlySticky) { + Toast.makeText(this, "Header " + headerId + " currentlySticky ? " + currentlySticky, + Toast.LENGTH_SHORT).show(); + } + + @Override + @TargetApi(Build.VERSION_CODES.HONEYCOMB) + public void onStickyHeaderOffsetChanged(StickyListHeadersListView l, View header, int offset) { + if (fadeHeader && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + header.setAlpha(1 - (offset / (float) header.getMeasuredHeight())); + } + } +}
\ No newline at end of file diff --git a/libraries/StickyListHeaders/sample/src/se/emilsjolander/stickylistheaders/TestBaseAdapter.java b/libraries/StickyListHeaders/sample/src/se/emilsjolander/stickylistheaders/TestBaseAdapter.java new file mode 100644 index 000000000..777b7bd57 --- /dev/null +++ b/libraries/StickyListHeaders/sample/src/se/emilsjolander/stickylistheaders/TestBaseAdapter.java @@ -0,0 +1,169 @@ +package se.emilsjolander.stickylistheaders; + +import java.util.ArrayList; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.SectionIndexer; +import android.widget.TextView; + +/** + * @author Emil Sjölander + */ +public class TestBaseAdapter extends BaseAdapter implements + StickyListHeadersAdapter, SectionIndexer { + + private final Context mContext; + private String[] mCountries; + private int[] mSectionIndices; + private Character[] mSectionLetters; + private LayoutInflater mInflater; + + public TestBaseAdapter(Context context) { + mContext = context; + mInflater = LayoutInflater.from(context); + mCountries = context.getResources().getStringArray(R.array.countries); + mSectionIndices = getSectionIndices(); + mSectionLetters = getSectionLetters(); + } + + private int[] getSectionIndices() { + ArrayList<Integer> sectionIndices = new ArrayList<Integer>(); + char lastFirstChar = mCountries[0].charAt(0); + sectionIndices.add(0); + for (int i = 1; i < mCountries.length; i++) { + if (mCountries[i].charAt(0) != lastFirstChar) { + lastFirstChar = mCountries[i].charAt(0); + sectionIndices.add(i); + } + } + int[] sections = new int[sectionIndices.size()]; + for (int i = 0; i < sectionIndices.size(); i++) { + sections[i] = sectionIndices.get(i); + } + return sections; + } + + private Character[] getSectionLetters() { + Character[] letters = new Character[mSectionIndices.length]; + for (int i = 0; i < mSectionIndices.length; i++) { + letters[i] = mCountries[mSectionIndices[i]].charAt(0); + } + return letters; + } + + @Override + public int getCount() { + return mCountries.length; + } + + @Override + public Object getItem(int position) { + return mCountries[position]; + } + + @Override + public long getItemId(int position) { + return position; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + ViewHolder holder; + + if (convertView == null) { + holder = new ViewHolder(); + convertView = mInflater.inflate(R.layout.test_list_item_layout, parent, false); + holder.text = (TextView) convertView.findViewById(R.id.text); + convertView.setTag(holder); + } else { + holder = (ViewHolder) convertView.getTag(); + } + + holder.text.setText(mCountries[position]); + + return convertView; + } + + @Override + public View getHeaderView(int position, View convertView, ViewGroup parent) { + HeaderViewHolder holder; + + if (convertView == null) { + holder = new HeaderViewHolder(); + convertView = mInflater.inflate(R.layout.header, parent, false); + holder.text = (TextView) convertView.findViewById(R.id.text1); + convertView.setTag(holder); + } else { + holder = (HeaderViewHolder) convertView.getTag(); + } + + // set header text as first char in name + CharSequence headerChar = mCountries[position].subSequence(0, 1); + holder.text.setText(headerChar); + + return convertView; + } + + /** + * Remember that these have to be static, postion=1 should always return + * the same Id that is. + */ + @Override + public long getHeaderId(int position) { + // return the first character of the country as ID because this is what + // headers are based upon + return mCountries[position].subSequence(0, 1).charAt(0); + } + + @Override + public int getPositionForSection(int section) { + if (section >= mSectionIndices.length) { + section = mSectionIndices.length - 1; + } else if (section < 0) { + section = 0; + } + return mSectionIndices[section]; + } + + @Override + public int getSectionForPosition(int position) { + for (int i = 0; i < mSectionIndices.length; i++) { + if (position < mSectionIndices[i]) { + return i - 1; + } + } + return mSectionIndices.length - 1; + } + + @Override + public Object[] getSections() { + return mSectionLetters; + } + + public void clear() { + mCountries = new String[0]; + mSectionIndices = new int[0]; + mSectionLetters = new Character[0]; + notifyDataSetChanged(); + } + + public void restore() { + mCountries = mContext.getResources().getStringArray(R.array.countries); + mSectionIndices = getSectionIndices(); + mSectionLetters = getSectionLetters(); + notifyDataSetChanged(); + } + + class HeaderViewHolder { + TextView text; + } + + class ViewHolder { + TextView text; + } + +} diff --git a/libraries/StickyListHeaders/sample/src/se/emilsjolander/stickylistheaders/views/UnderlineTextView.java b/libraries/StickyListHeaders/sample/src/se/emilsjolander/stickylistheaders/views/UnderlineTextView.java new file mode 100644 index 000000000..c202c00b8 --- /dev/null +++ b/libraries/StickyListHeaders/sample/src/se/emilsjolander/stickylistheaders/views/UnderlineTextView.java @@ -0,0 +1,50 @@ +package se.emilsjolander.stickylistheaders.views; + +import android.content.Context; +import android.content.res.Resources; +import android.graphics.Canvas; +import android.graphics.Paint; +import android.util.AttributeSet; +import android.util.TypedValue; +import android.widget.TextView; + +/** + * @author Eric Frohnhoefer + */ +public class UnderlineTextView extends TextView { + private final Paint mPaint = new Paint(); + private int mUnderlineHeight = 0; + + public UnderlineTextView(Context context) { + this(context, null); + } + + public UnderlineTextView(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public UnderlineTextView(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + + init(context, attrs); + } + + private void init(Context context, AttributeSet attrs) { + Resources r = getResources(); + mUnderlineHeight = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, r.getDisplayMetrics()); + } + + @Override + public void setPadding(int left, int top, int right, int bottom) { + super.setPadding(left, top, right, bottom + mUnderlineHeight); + } + + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + + // Draw the underline the same color as the text + mPaint.setColor(getTextColors().getDefaultColor()); + canvas.drawRect(0, getHeight() - mUnderlineHeight, getWidth(), getHeight(), mPaint); + } +} |