-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jbarr21
committed
Feb 14, 2015
1 parent
37b2558
commit 8d7eff4
Showing
8 changed files
with
230 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?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="@dimen/footer_height" | ||
android:gravity="center_vertical" | ||
android:paddingLeft="8dp" | ||
android:minHeight="@dimen/footer_height" | ||
android:textColor="@android:color/black" | ||
android:background="@android:color/holo_red_light"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
sample/src/com/twotoasters/jazzylistview/sample/PagerListAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
package com.twotoasters.jazzylistview.sample; | ||
|
||
import android.content.Context; | ||
import android.content.res.Resources; | ||
import android.os.Handler; | ||
import android.os.Looper; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.AbsListView; | ||
import android.widget.BaseAdapter; | ||
import android.widget.ListView; | ||
import android.widget.TextView; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class PagerListAdapter extends BaseAdapter implements AbsListView.OnScrollListener { | ||
|
||
public static final int COUNT_OF_PER_PAGE = 15; | ||
private final LayoutInflater inflater; | ||
private final Resources res; | ||
private final int itemLayout; | ||
private final List<String> pagerResults = new ArrayList<String>(); | ||
private LoadingState state = LoadingState.PENDING; | ||
private final ListView listView; | ||
|
||
private int currentPage = 1; | ||
private final int totalPages; | ||
|
||
private final Handler handler = new Handler(Looper.getMainLooper()); | ||
|
||
public PagerListAdapter(Context context, int itemLayout, ListView listView) { | ||
inflater = LayoutInflater.from(context); | ||
res = context.getResources(); | ||
this.itemLayout = itemLayout; | ||
final int length = ListModel.getModel().length; | ||
totalPages = length % COUNT_OF_PER_PAGE == 0 ? length / COUNT_OF_PER_PAGE : (length / COUNT_OF_PER_PAGE) + 1; | ||
this.listView = listView; | ||
this.listView.setOnScrollListener(this); | ||
} | ||
|
||
@Override | ||
public int getCount() { | ||
return pagerResults.size(); | ||
} | ||
|
||
@Override | ||
public String getItem(int position) { | ||
return pagerResults.get(position); | ||
} | ||
|
||
@Override | ||
public long getItemId(int position) { | ||
return position; | ||
} | ||
|
||
@Override | ||
public View getView(int position, View convertView, ViewGroup parent) { | ||
ViewHolder holder; | ||
|
||
if (convertView == null) { | ||
convertView = inflater.inflate(itemLayout, null); | ||
holder = new ViewHolder(convertView); | ||
convertView.setTag(holder); | ||
} else { | ||
holder = (ViewHolder) convertView.getTag(); | ||
} | ||
|
||
int colorResId = position % 2 == 0 ? R.color.even : R.color.odd; | ||
holder.text.setBackgroundColor(res.getColor(colorResId)); | ||
holder.text.setText(ListModel.getModelItem(position)); | ||
|
||
return convertView; | ||
} | ||
|
||
@Override | ||
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { | ||
if (state != LoadingState.PENDING) { | ||
return; | ||
} | ||
|
||
if (firstVisibleItem + visibleItemCount >= totalItemCount && currentPage < totalPages) { | ||
loadPage(currentPage++); | ||
} | ||
} | ||
|
||
private void loadPage(final int page) { | ||
state = LoadingState.LOADING; | ||
handler.postDelayed(new Runnable() { | ||
@Override | ||
public void run() { | ||
final int length = ListModel.getModel().length; | ||
for (int i = 0; i < COUNT_OF_PER_PAGE; i++) { | ||
int index = page * COUNT_OF_PER_PAGE + i; | ||
if (index >= length) { | ||
break; | ||
} | ||
pagerResults.add(ListModel.getModelItem(index)); | ||
} | ||
notifyDataSetChanged(); | ||
state = page == totalPages ? LoadingState.END : LoadingState.PENDING; | ||
} | ||
}, 2000); | ||
} | ||
|
||
@Override | ||
public void onScrollStateChanged(AbsListView view, int scrollState) {} | ||
|
||
static class ViewHolder { | ||
final TextView text; | ||
|
||
ViewHolder(View view) { | ||
text = (TextView) view.findViewById(R.id.text); | ||
} | ||
} | ||
|
||
static enum LoadingState { | ||
PENDING, LOADING, FAILURE, END | ||
} | ||
|
||
} |
88 changes: 88 additions & 0 deletions
88
sample/src/com/twotoasters/jazzylistview/sample/SimpleListWithHeadersAndFootersActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package com.twotoasters.jazzylistview.sample; | ||
|
||
import android.app.Activity; | ||
import android.os.Bundle; | ||
import android.view.Menu; | ||
import android.view.MenuItem; | ||
import android.widget.TextView; | ||
import android.widget.Toast; | ||
import com.twotoasters.jazzylistview.JazzyHelper; | ||
import com.twotoasters.jazzylistview.JazzyListView; | ||
|
||
import java.util.*; | ||
|
||
public class SimpleListWithHeadersAndFootersActivity extends Activity { | ||
|
||
private static final String KEY_TRANSITION_EFFECT = "transition_effect"; | ||
|
||
private JazzyListView mList; | ||
private HashMap<String, Integer> mEffectMap; | ||
private int mCurrentTransitionEffect = JazzyHelper.HELIX; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_list); | ||
|
||
// add header to listview | ||
mList = (JazzyListView) findViewById(android.R.id.list); | ||
TextView headerView = (TextView) getLayoutInflater().inflate(R.layout.item, null); | ||
headerView.setBackgroundColor(0xFFEA4C89); | ||
headerView.setText("ListView Header"); | ||
mList.addHeaderView(headerView); | ||
|
||
// add footer to listview | ||
mList = (JazzyListView) findViewById(android.R.id.list); | ||
TextView footerView = (TextView) getLayoutInflater().inflate(R.layout.item, null); | ||
footerView.setBackgroundColor(0xFFEA4C89); | ||
footerView.setText("ListView Footer"); | ||
mList.addFooterView(footerView); | ||
|
||
mList.setAdapter(new PagerListAdapter(this, R.layout.item, mList)); | ||
// mList.setShouldOnlyAnimateNewItems(true); | ||
|
||
if (savedInstanceState != null) { | ||
mCurrentTransitionEffect = savedInstanceState.getInt(KEY_TRANSITION_EFFECT, JazzyHelper.HELIX); | ||
setupJazziness(mCurrentTransitionEffect); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean onCreateOptionsMenu(Menu menu) { | ||
mEffectMap = new HashMap<String, Integer>(); | ||
int i = 0; | ||
String[] effects = this.getResources().getStringArray(R.array.jazzy_effects); | ||
for (String effect : effects) { | ||
mEffectMap.put(effect, i++); | ||
} | ||
|
||
List<String> effectList = new ArrayList<String>(Arrays.asList(effects)); | ||
Collections.sort(effectList); | ||
effectList.remove(getString(R.string.standard)); | ||
effectList.add(0, getString(R.string.standard)); | ||
for (String effect : effectList) { | ||
menu.add(effect); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public boolean onOptionsItemSelected(MenuItem item) { | ||
String strEffect = item.getTitle().toString(); | ||
Toast.makeText(this, strEffect, Toast.LENGTH_SHORT).show(); | ||
setupJazziness(mEffectMap.get(strEffect)); | ||
return true; | ||
} | ||
|
||
@Override | ||
public void onSaveInstanceState(Bundle outState) { | ||
super.onSaveInstanceState(outState); | ||
outState.putInt(KEY_TRANSITION_EFFECT, mCurrentTransitionEffect); | ||
} | ||
|
||
private void setupJazziness(int effect) { | ||
mCurrentTransitionEffect = effect; | ||
mList.setTransitionEffect(mCurrentTransitionEffect); | ||
} | ||
} |