Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- Обновление SectionListAdapter

- Выполнение задачи: #1 Оптимизация для StickySectionListAdapter
  • Loading branch information...
commit b0efa95ecbc27946cfa5817911364b32b8234677 1 parent 105ec83
@nfirex authored
View
BIN  libs/SectionListAdapter(CaminoParts).jar
Binary file not shown
View
36 src/com/wagado/stickysection/StickySectionActivity.java
@@ -3,14 +3,17 @@
import java.util.ArrayList;
import java.util.List;
-import com.wagado.widget.StickySectionListAdapter;
import com.wagado.widget.StickySectionListView;
+import ru.camino.parts.adapter.SectionListAdapter;
import ru.camino.parts.adapter.SectionListAdapter.SectionDetector;
import android.app.Activity;
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 {
@@ -23,7 +26,7 @@ public void onCreate(Bundle savedInstanceState) {
mListView = (StickySectionListView) findViewById(R.id.sticky_section_list);
- StickySectionListAdapter adapter = (StickySectionListAdapter) getLastNonConfigurationInstance();
+ SectionListAdapter adapter = (SectionListAdapter) getLastNonConfigurationInstance();
if (getLastNonConfigurationInstance() == null) {
final int count = 10000;
final List<String> list = new ArrayList<String>();
@@ -42,7 +45,7 @@ public Object onRetainNonConfigurationInstance() {
return mListView.getAdapter();
}
- private StickySectionListAdapter createAdapter(BaseAdapter adapter) {
+ private SectionListAdapter createAdapter(BaseAdapter adapter) {
final SectionDetector sectionDetector = new SectionDetector() {
final private int portion = 19;
@@ -62,6 +65,31 @@ public Object detectSection(Object arg0, Object arg1) {
}
};
- return new StickySectionListAdapter(getBaseContext(), adapter, sectionDetector, android.R.layout.preference_category, android.R.id.title);
+ return new SectionListAdapter(adapter, sectionDetector) {
+ protected final int mHeaderLayoutId = android.R.layout.preference_category;
+ protected final int mTitleTextViewId = android.R.id.title;
+
+ @Override
+ protected View getSectionView(Object header, View convertView, ViewGroup parent) {
+ View v;
+ if (convertView != null) {
+ v = convertView;
+ } else {
+ v = View.inflate(getBaseContext(), mHeaderLayoutId, null);
+ }
+ ((TextView) v.findViewById(mTitleTextViewId)).setText(header.toString());
+
+ return v;
+ }
+
+ @Override
+ protected Object getSectionHeader(Object firstItem, Object secondItem) {
+ if (getSectionDetector() != null) {
+ return getSectionDetector().detectSection(firstItem, secondItem);
+ } else {
+ return null;
+ }
+ }
+ };
}
}
View
108 src/com/wagado/widget/StickySectionListAdapter.java
@@ -1,108 +0,0 @@
-/**
- * Copyright 2012 by Kleshchin Nikita (nfirex)
- *
- * 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.wagado.widget;
-
-import java.util.Iterator;
-
-import android.content.Context;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.BaseAdapter;
-import android.widget.SectionIndexer;
-import android.widget.TextView;
-import ru.camino.parts.adapter.SectionListAdapter;
-
-public class StickySectionListAdapter extends SectionListAdapter implements SectionIndexer {
- protected static final String TAG = "StickySectionListAdapter";
-
- protected final Context mContext;
- protected final int mHeaderLayoutId;
- protected final int mTitleTextViewId;
-
- public StickySectionListAdapter(Context context, BaseAdapter adapter, SectionListAdapter.SectionDetector detector) {
- this(context, adapter, detector, android.R.layout.preference_category, android.R.id.title);
- }
-
- public StickySectionListAdapter(Context context, BaseAdapter adapter, SectionListAdapter.SectionDetector detector, int headerLayoutId, int titleTextViewId) {
- super(adapter, detector);
- mContext = context;
- mHeaderLayoutId = headerLayoutId;
- mTitleTextViewId = titleTextViewId;
- }
-
- @Override
- protected View getSectionView(Object header, View convertView, ViewGroup parent) {
- View v;
- if (convertView != null) {
- v = convertView;
- } else {
- v = View.inflate(mContext, mHeaderLayoutId, null);
- }
- ((TextView) v.findViewById(mTitleTextViewId)).setText(header.toString());
-
- return v;
- }
-
- @Override
- protected Object getSectionHeader(Object firstItem, Object secondItem) {
- if (getSectionDetector() != null) {
- return getSectionDetector().detectSection(firstItem, secondItem);
- } else {
- return null;
- }
- }
-
- @Override
- public int getPositionForSection(int section) {
- final Iterator<Integer> iterator = getHeaders().keySet().iterator();
-
- int count = 0;
- int value = iterator.next();
- while (iterator.hasNext()) {
- if (section == count) {
- break;
- }
-
- count ++;
- value = iterator.next();
- }
-
- return value;
- }
-
- @Override
- public int getSectionForPosition(int position) {
- final Iterator<Integer> iterator = getHeaders().keySet().iterator();
-
- int count = 0;
- while (iterator.hasNext()) {
- int value = iterator.next();
- if (value == position) {
- break;
- }
-
- count ++;
- }
-
- return count;
- }
-
- @Override
- public Object[] getSections() {
- return getHeaders().values().toArray();
- }
-}
View
8 src/com/wagado/widget/StickySectionListView.java
@@ -18,6 +18,8 @@
import java.util.Iterator;
+import ru.camino.parts.adapter.SectionListAdapter;
+
import android.content.Context;
import android.graphics.Canvas;
import android.os.Parcel;
@@ -61,7 +63,7 @@ public StickySectionListView(Context context, AttributeSet attrs, int defStyle)
public void setAdapter(ListAdapter adapter) {
super.setAdapter(adapter);
- if (adapter instanceof StickySectionListAdapter) {
+ if (adapter instanceof SectionListAdapter) {
mParent = (FrameLayout) getParent();
mLayoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
mCurrentSection = 0;
@@ -122,7 +124,7 @@ public Parcelable onSaveInstanceState() {
* @param position - ïîçèöèÿ ýëåìåíòà, äëÿ êîòîðîãî èùåòñÿ ïîçèöèÿ ñåêöèè
*/
protected int getSectionByPosition(int position) {
- final Iterator<Integer> iterator = ((StickySectionListAdapter) getAdapter()).getHeaders().keySet().iterator();
+ final Iterator<Integer> iterator = ((SectionListAdapter) getAdapter()).getHeaders().keySet().iterator();
int value = iterator.next();
@@ -174,7 +176,7 @@ protected void createSticker (int position) {
*/
protected void catchNextSection (int position) {
final int delta = 1;
- final boolean isNextSection = ((StickySectionListAdapter) getAdapter()).isHeader(position + delta);
+ final boolean isNextSection = ((SectionListAdapter) getAdapter()).isHeader(position + delta);
if (isNextSection) {
mNextSectionChild = delta;
} else {
Please sign in to comment.
Something went wrong with that request. Please try again.