<commit_before>/***
	Copyright (c) 2008-2009 CommonsWare, LLC
	
	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.commonsware.cwac.endless.demo;

import android.app.ListActivity;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.ArrayAdapter;
import com.commonsware.cwac.endless.EndlessAdapter;
import java.util.ArrayList;
import java.util.Arrays;

public class EndlessAdapterDemo extends ListActivity {
	private static String[] items={"lorem", "ipsum", "dolor",
																	"sit", "amet", "consectetuer",
																	"adipiscing", "elit", "morbi",
																	"vel", "ligula", "vitae",
																	"arcu", "aliquet", "mollis",
																	"etiam", "vel", "erat",
																	"placerat", "ante",
																	"porttitor", "sodales",
																	"pellentesque", "augue",
																	"purus"};
	
	@Override
	public void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		setContentView(R.layout.main);
		
		setListAdapter(new DemoAdapter(new ArrayList<String>(Arrays.asList(items))));
	}
	
	class DemoAdapter extends EndlessAdapter {
		private RotateAnimation rotate=null;
		
		DemoAdapter(ArrayList<String> list) {
			super(new ArrayAdapter<String>(EndlessAdapterDemo.this,
																			R.layout.row,
																			android.R.id.text1,
																			list));
			
			rotate=new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF,
																	0.5f, Animation.RELATIVE_TO_SELF,
																	0.5f);
			rotate.setDuration(600);
			rotate.setRepeatMode(Animation.RESTART);
			rotate.setRepeatCount(Animation.INFINITE);
		}
		
		protected View getPendingView(ViewGroup parent) {
			View row=getLayoutInflater().inflate(R.layout.row, null);
			
			View child=row.findViewById(android.R.id.text1);
			
			child.setVisibility(View.GONE);
			
			child=row.findViewById(R.id.throbber);
			child.setVisibility(View.VISIBLE);
			child.startAnimation(rotate);
			
			return(row);
		}
		
		protected boolean cacheInBackground() {
			SystemClock.sleep(10000);				// pretend to do work
			
			return(getWrappedAdapter().getCount()<60);
		}
		
		protected void appendCachedData() {
			@SuppressWarnings("unchecked")
			ArrayAdapter<String> a=(ArrayAdapter<String>)getWrappedAdapter();
			
			for (String item : items) {
				a.add(item);
			}
		}
	}
}<commit_msg>Revised demo to show handling failure to get data in cacheInBackground()<commit_after>/***
	Copyright (c) 2008-2009 CommonsWare, LLC
	
	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.commonsware.cwac.endless.demo;

import android.app.ListActivity;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.ArrayAdapter;
import com.commonsware.cwac.endless.EndlessAdapter;
import java.util.ArrayList;

public class EndlessAdapterDemo extends ListActivity {
	@Override
	public void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		setContentView(R.layout.main);
		
		ArrayList<Integer> items=new ArrayList<Integer>();
		
		for (int i=0;i<25;i++) { items.add(i); }
		
		setListAdapter(new DemoAdapter(items));
	}
	
	class DemoAdapter extends EndlessAdapter {
		private RotateAnimation rotate=null;
		
		DemoAdapter(ArrayList<Integer> list) {
			super(new ArrayAdapter<Integer>(EndlessAdapterDemo.this,
																			R.layout.row,
																			android.R.id.text1,
																			list));
			
			rotate=new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF,
																	0.5f, Animation.RELATIVE_TO_SELF,
																	0.5f);
			rotate.setDuration(600);
			rotate.setRepeatMode(Animation.RESTART);
			rotate.setRepeatCount(Animation.INFINITE);
		}
		
		protected View getPendingView(ViewGroup parent) {
			View row=getLayoutInflater().inflate(R.layout.row, null);
			
			View child=row.findViewById(android.R.id.text1);
			
			child.setVisibility(View.GONE);
			
			child=row.findViewById(R.id.throbber);
			child.setVisibility(View.VISIBLE);
			child.startAnimation(rotate);
			
			return(row);
		}
		
		protected boolean cacheInBackground() {
			SystemClock.sleep(10000);				// pretend to do work
			
			return(getWrappedAdapter().getCount()<75);
		}
		
		protected void appendCachedData() {
			if (getWrappedAdapter().getCount()<75) {
				@SuppressWarnings("unchecked")
				ArrayAdapter<Integer> a=(ArrayAdapter<Integer>)getWrappedAdapter();
				
				for (int i=0;i<25;i++) { a.add(a.getCount()); }
			}
		}
	}
}
{'fraction_non_alphanumeric': 0.10874538096076017, 'fraction_numerical': 0.012669364772127397, 'mean_word_length': 3.4897314375987363, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6816297', 'n_tokens_mistral': 2273, 'n_tokens_neox': 1712, 'n_words': 405}