Permalink
Browse files

Changed main layout to imitate real conditions.

Moved mParent in StickySelectionListView from FrameLayout to ViewGroup. 
And other small changes.
  • Loading branch information...
vasyx
vasyx committed Apr 2, 2012
1 parent b0efa95 commit 90655cfdb94700ca4e1904c41df5a4252c828bdf
View
@@ -1,11 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
-<merge xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent" >
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent" >
- <com.wagado.widget.StickySectionListView
- android:id="@+id/sticky_section_list"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent" />
+ <!--
+ Layout changed to RelativeLayout
+ TextView and ImageView added
+ We need to imitate real layout
+ -->
-</merge>
+ <TextView
+ android:id="@+id/randomText"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/random_text" />
+
+ <ImageView
+ android:id="@+id/randomImage"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentRight="true"
+ android:layout_below="@id/randomText"
+ android:contentDescription="@string/here_be_dragons"
+ android:src="@drawable/ic_launcher" />
+
+ <com.wagado.widget.StickySectionListView
+ android:id="@android:id/list"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:layout_below="@id/randomImage" />
+
+</RelativeLayout>
View
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
- <string name="app_name">StickySection</string>
+ <string name="app_name">StickySection</string>
+ <string name="random_text">Some random text here</string>
+ <string name="here_be_dragons">Here be Dragons</string>
</resources>
@@ -7,15 +7,15 @@
import ru.camino.parts.adapter.SectionListAdapter;
import ru.camino.parts.adapter.SectionListAdapter.SectionDetector;
-import android.app.Activity;
+import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.TextView;
-public class StickySectionActivity extends Activity {
+public class StickySectionActivity extends ListActivity {
private StickySectionListView mListView;
@@ -24,14 +24,14 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
- mListView = (StickySectionListView) findViewById(R.id.sticky_section_list);
+ mListView = (StickySectionListView) getListView();
SectionListAdapter adapter = (SectionListAdapter) getLastNonConfigurationInstance();
if (getLastNonConfigurationInstance() == null) {
final int count = 10000;
final List<String> list = new ArrayList<String>();
for (int i = 1; i <= count; i ++) {
- list.add("element ¹ " + Integer.toString(i));
+ list.add("element " + Integer.toString(i));
}
adapter = createAdapter(new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_list_item_1, android.R.id.text1, list));
}
@@ -16,8 +16,6 @@
package com.wagado.widget;
-import java.util.Iterator;
-
import ru.camino.parts.adapter.SectionListAdapter;
import android.content.Context;
@@ -26,8 +24,8 @@
import android.os.Parcelable;
import android.util.AttributeSet;
import android.view.View;
+import android.view.ViewGroup;
import android.widget.AbsListView;
-import android.widget.FrameLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
@@ -38,8 +36,8 @@
private View mStickerSection;
- private FrameLayout mParent;
- private FrameLayout.LayoutParams mLayoutParams;
+ private ViewGroup mParent;
+ private ViewGroup.LayoutParams mLayoutParams;
private boolean isStickyScroll;
@@ -64,8 +62,8 @@ public void setAdapter(ListAdapter adapter) {
super.setAdapter(adapter);
if (adapter instanceof SectionListAdapter) {
- mParent = (FrameLayout) getParent();
- mLayoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
+ mParent = (ViewGroup) getParent();
+ mLayoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
mCurrentSection = 0;
createSticker(mCurrentSection);
@@ -120,33 +118,23 @@ public Parcelable onSaveInstanceState() {
/**
- * Ïîëó÷èòü ïîçèöèþ ñåêöèè, êîòîðîé ïðèíàäëåæèò ýëåìåíò
- * @param position - ïîçèöèÿ ýëåìåíòà, äëÿ êîòîðîãî èùåòñÿ ïîçèöèÿ ñåêöèè
+ * �������� ������� ������, ������� ����������� �������
+ * @param position - ������� ��������, ��� �������� ������ ������� ������
*/
protected int getSectionByPosition(int position) {
- final Iterator<Integer> iterator = ((SectionListAdapter) getAdapter()).getHeaders().keySet().iterator();
-
- int value = iterator.next();
-
- if (position < value) {
- return NOT_VALUE;
- }
-
- while (iterator.hasNext()) {
- final int value2 = iterator.next();
- if (position < value2) {
- break;
- }
+ int result = NOT_VALUE;
- value = value2;
+ for (int i: ((SectionListAdapter) getAdapter()).getHeaders().keySet()) {
+ if (position < i) break;
+ else result = i;
}
- return value;
+ return result;
}
/**
- * Èíèöèàëèçàöèÿ "Ñòèêåðà" ïî ïåðåäàííîé ïîçèöèè.
- * @param position - ïîçèöèÿ ñåêöèè â ñïèñêå
+ * ������������� "�������" �� ���������� �������.
+ * @param position - ������� ������ � ������
*/
protected void createSticker (int position) {
final int section = getSectionByPosition(position);
@@ -171,8 +159,8 @@ protected void createSticker (int position) {
}
/**
- * Èíèöèàëèçàöèÿ ñåêöèè, êîòîðàÿ áóäåò ñìåùàòü "Ñòèêåð" ïî ïåðåäàííîé ïîçèöèè.
- * @param position - ïîçèöèÿ ñåêöèè â ñïèñêå
+ * ������������� ������, ������� ����� ������� "������" �� ���������� �������.
+ * @param position - ������� ������ � ������
*/
protected void catchNextSection (int position) {
final int delta = 1;
@@ -185,7 +173,7 @@ protected void catchNextSection (int position) {
}
/**
- * Ðàñ÷åò îòñóïà "Ñòèêåðà" îò âåðõíåé ãðàíèöû StickySectionListView
+ * ������ ������ "�������" �� ������� ������� StickySectionListView
*/
protected void calculateStickerMargin () {
if (mNextSectionChild != NOT_VALUE) {
@@ -203,8 +191,8 @@ protected void calculateStickerMargin () {
}
/**
- * Ðèñîâàíèå "ñòèêåðà" íà ïåðåäàííîì Canvas. Ðèñîâàíèå èäåò ïîñëå äåòåé, ïåðåä ýôôåêòàìè è Scrollbar.
- * @param canvas - Canvas íà êîòîðîì ðèñóþòñÿ âñå ýëåìåíòû ListView
+ * ��������� "�������" �� ���������� Canvas. ��������� ���� ����� �����, ����� ��������� � Scrollbar.
+ * @param canvas - Canvas �� ������� �������� ��� �������� ListView
*/
protected void drawSticker(Canvas canvas) {
canvas.translate(0, mStickerMargin);
@@ -216,8 +204,8 @@ protected void drawSticker(Canvas canvas) {
/**
- * OnScrollListener äëÿ îòñëåæèâàíèÿ ñìåíû ýëåìåíòîâ ñïèñêà.
- * Îïðåäåëÿåò êàêèå ýëåìåíòû ó÷àâñòâóþò â îòîáðàæåíèè è ðàñïîëîæåíèÿ "Ñòèêåðà".
+ * OnScrollListener ��� ������������ ����� ��������� ������.
+ * ���������� ����� �������� ���������� � ����������� � ������������ "�������".
*/
private class StickyScrollListener implements OnScrollListener {
@Override
@@ -233,8 +221,8 @@ public void onScrollStateChanged(AbsListView view, int scrollState) {
};
/**
- * Êëàññ äëÿ ñîõðàíåíèÿ ñîñòîÿíèÿ StickySectionListView, ÷òîáû ïîñëå ïåðåçàãðóçêè àêòèâèòè (íàïðèìåð, ïîñëå ïîâîðîòà),
- * íå ïîòåðÿòü "Ñòèêåð".
+ * ����� ��� ���������� ��������� StickySectionListView, ����� ����� ������������ �������� (��������, ����� ��������),
+ * �� �������� "������".
*/
private class SavedState extends BaseSavedState {
int currentStickerSection;

0 comments on commit 90655cf

Please sign in to comment.