entry = handlers.next();
39 | EventHandler eventHandler = entry.getValue();
40 | if (eventHandler != null)
41 | eventHandler.handleEvent(eventType, obj);
42 | }
43 | }
44 |
45 | public void registerEventHandler(int key, EventHandler eventHandler) {
46 | synchronized (this) {
47 | eventHandlers.put(key, eventHandler);
48 | }
49 | }
50 |
51 | }
--------------------------------------------------------------------------------
/CodeBox/src/com/jcodecraeer/jcode/HttpUtil.java:
--------------------------------------------------------------------------------
1 | package com.jcodecraeer.jcode;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.File;
5 | import java.io.FileInputStream;
6 | import java.io.FileNotFoundException;
7 | import java.io.FileOutputStream;
8 | import java.io.IOException;
9 | import java.io.InputStreamReader;
10 | import java.io.ObjectInputStream;
11 | import java.io.ObjectOutputStream;
12 | import java.io.Serializable;
13 | import java.io.UnsupportedEncodingException;
14 | import java.util.Map;
15 |
16 | import org.apache.commons.httpclient.Cookie;
17 | import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
18 | import org.apache.commons.httpclient.Header;
19 | import org.apache.commons.httpclient.HttpClient;
20 | import org.apache.commons.httpclient.HttpException;
21 | import org.apache.commons.httpclient.HttpStatus;
22 | import org.apache.commons.httpclient.methods.GetMethod;
23 | import org.apache.commons.httpclient.methods.PostMethod;
24 | import org.apache.commons.httpclient.methods.multipart.FilePart;
25 | import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
26 | import org.apache.commons.httpclient.methods.multipart.Part;
27 | import org.apache.commons.httpclient.methods.multipart.StringPart;
28 | import org.apache.commons.httpclient.params.HttpMethodParams;
29 |
30 | import android.content.Context;
31 | import android.net.ConnectivityManager;
32 | import android.net.NetworkInfo;
33 | import android.telephony.TelephonyManager;
34 | import android.text.TextUtils;
35 | import android.util.Log;
36 |
37 |
38 | public class HttpUtil {
39 | private static final String TAG = "HttpUtil";
40 | public static final String UTF_8 = "UTF-8";
41 | public static final String GBK = "GBK";
42 | public static final String DESC = "descend";
43 | public static final String ASC = "ascend";
44 |
45 | private final static int TIMEOUT_CONNECTION = 20000;
46 | private final static int TIMEOUT_SOCKET = 20000;
47 | private final static int RETRY_TIME = 3;
48 |
49 | private static String appCookie;
50 | private static String appUserAgent;
51 |
52 | /** 没有网络 */
53 | public static final int NETWORKTYPE_INVALID = 0;
54 | /** wap网络 */
55 | public static final int NETWORKTYPE_WAP = 1;
56 | /** 2G网络 */
57 | public static final int NETWORKTYPE_2G = 2;
58 | /** 3G和3G以上网络,或统称为快速网络 */
59 | public static final int NETWORKTYPE_3G = 3;
60 | /** wifi网络 */
61 | public static final int NETWORKTYPE_WIFI = 4;
62 |
63 | private static final int CACHE_TIME = 2 * 60000;
64 |
65 | public static boolean isNetworkConnected() {
66 | ConnectivityManager cm = (ConnectivityManager) AppContext.getInstance().getSystemService(Context.CONNECTIVITY_SERVICE);
67 | NetworkInfo ni = cm.getActiveNetworkInfo();
68 | return ni != null && ni.isConnected();
69 | }
70 |
71 | /**
72 | * 获取网络状态,wifi,wap,2g,3g.
73 | *
74 | * @param context 上下文
75 | * @return int 网络状态 {@link #NETWORKTYPE_2G},{@link #NETWORKTYPE_3G}, *{@link #NETWORKTYPE_INVALID},{@link #NETWORKTYPE_WAP}* {@link #NETWORKTYPE_WIFI}
76 | */
77 |
78 | public static int getNetWorkType(Context context) {
79 |
80 | ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
81 | NetworkInfo networkInfo = manager.getActiveNetworkInfo();
82 | int netWorkType = NETWORKTYPE_INVALID;
83 | if (networkInfo != null && networkInfo.isConnected()) {
84 | String type = networkInfo.getTypeName();
85 |
86 | if (type.equalsIgnoreCase("WIFI")) {
87 | netWorkType = NETWORKTYPE_WIFI;
88 | Log.i("NETWORKTYPE_WIFI","NETWORKTYPE_WIFI");
89 | } else if (type.equalsIgnoreCase("MOBILE")) {
90 | String proxyHost = android.net.Proxy.getDefaultHost();
91 |
92 | netWorkType = TextUtils.isEmpty(proxyHost)
93 | ? (isFastMobileNetwork(context) ? NETWORKTYPE_3G : NETWORKTYPE_2G)
94 | : NETWORKTYPE_WAP;
95 | }
96 | } else {
97 | netWorkType = NETWORKTYPE_INVALID;
98 | }
99 |
100 | return netWorkType;
101 | }
102 |
103 | private static boolean isFastMobileNetwork(Context context) {
104 | TelephonyManager telephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
105 | switch (telephonyManager.getNetworkType()) {
106 | case TelephonyManager.NETWORK_TYPE_1xRTT:
107 | return false; // ~ 50-100 kbps
108 | case TelephonyManager.NETWORK_TYPE_CDMA:
109 | return false; // ~ 14-64 kbps
110 | case TelephonyManager.NETWORK_TYPE_EDGE:
111 | return false; // ~ 50-100 kbps
112 | case TelephonyManager.NETWORK_TYPE_EVDO_0:
113 | return true; // ~ 400-1000 kbps
114 | case TelephonyManager.NETWORK_TYPE_EVDO_A:
115 | return true; // ~ 600-1400 kbps
116 | case TelephonyManager.NETWORK_TYPE_GPRS:
117 | return false; // ~ 100 kbps
118 | case TelephonyManager.NETWORK_TYPE_HSDPA:
119 | return true; // ~ 2-14 Mbps
120 | case TelephonyManager.NETWORK_TYPE_HSPA:
121 | return true; // ~ 700-1700 kbps
122 | case TelephonyManager.NETWORK_TYPE_HSUPA:
123 | return true; // ~ 1-23 Mbps
124 | case TelephonyManager.NETWORK_TYPE_UMTS:
125 | return true; // ~ 400-7000 kbps
126 | case TelephonyManager.NETWORK_TYPE_EHRPD:
127 | return true; // ~ 1-2 Mbps
128 | case TelephonyManager.NETWORK_TYPE_EVDO_B:
129 | return true; // ~ 5 Mbps
130 | case TelephonyManager.NETWORK_TYPE_HSPAP:
131 | return true; // ~ 10-20 Mbps
132 | case TelephonyManager.NETWORK_TYPE_IDEN:
133 | return false; // ~25 kbps
134 | case TelephonyManager.NETWORK_TYPE_LTE:
135 | return true; // ~ 10+ Mbps
136 | case TelephonyManager.NETWORK_TYPE_UNKNOWN:
137 | return false;
138 | default:
139 | return false;
140 | }
141 | }
142 |
143 | public static void cleanCookie() {
144 | appCookie = "";
145 | }
146 | private static String getCookie(AppContext appContext) {
147 | if(appCookie == null || appCookie == "") {
148 | appCookie = appContext.getPropertyString("cookie");
149 | }
150 | return appCookie;
151 | }
152 |
153 | private static String getUserAgent(AppContext appContext) {
154 | if(appUserAgent == null || appUserAgent == "") {
155 | StringBuilder ua = new StringBuilder("www.jcodecraeer.com");
156 | ua.append('/'+appContext.getPackageInfo().versionName+'_'+appContext.getPackageInfo().versionCode);//App版本
157 | ua.append("/Android");//手机系统平台
158 | ua.append("/"+android.os.Build.VERSION.RELEASE);//手机系统版本
159 | ua.append("/"+android.os.Build.MODEL); //手机型号
160 | appUserAgent = ua.toString();
161 | }
162 | return appUserAgent;
163 | }
164 |
165 | private static HttpClient getHttpClient() {
166 | HttpClient httpClient = new HttpClient();
167 | // 设置 HttpClient 接收 Cookie,用与浏览器一样的策略
168 | //httpClient.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
169 | // 设置 默认的超时重试处理策略
170 | httpClient.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler());
171 | // 设置 连接超时时间
172 | httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(TIMEOUT_CONNECTION);
173 | // 设置 读数据超时时间
174 | httpClient.getHttpConnectionManager().getParams().setSoTimeout(TIMEOUT_SOCKET);
175 | // 设置 字符集
176 | httpClient.getParams().setContentCharset(UTF_8);
177 | return httpClient;
178 | }
179 |
180 | private static GetMethod getHttpGet(String url,String cookie, String userAgent) {
181 | GetMethod httpGet = new GetMethod(url);
182 | // 设置 请求超时时间
183 | httpGet.getParams().setSoTimeout(TIMEOUT_SOCKET);
184 | httpGet.setRequestHeader("Host", "www.jcodecraeer.com");
185 | httpGet.setRequestHeader("Connection","Keep-Alive");
186 | httpGet.setRequestHeader("Cookie", cookie);
187 | httpGet.setRequestHeader("User-Agent", userAgent);
188 | return httpGet;
189 | }
190 |
191 | private static PostMethod getHttpPost(String url,String cookie, String userAgent) {
192 | PostMethod httpPost = new PostMethod(url);
193 | // 设置 请求超时时间
194 | httpPost.getParams().setSoTimeout(TIMEOUT_SOCKET);
195 | httpPost.setRequestHeader("Host", "www.jcodecraeer.com");
196 | httpPost.setRequestHeader("Connection","Keep-Alive");
197 | httpPost.setRequestHeader("Cookie", cookie);
198 | httpPost.setRequestHeader("User-Agent", userAgent);
199 |
200 | return httpPost;
201 | }
202 |
203 | public static String _MakeURL(String p_url, Map params) {
204 | StringBuilder url = new StringBuilder(p_url);
205 | if(url.indexOf("?")<0)
206 | url.append('?');
207 |
208 | for(String name : params.keySet()){
209 | url.append('&');
210 | url.append(name);
211 | url.append('=');
212 | url.append(String.valueOf(params.get(name)));
213 | //不做URLEncoder处理
214 | //url.append(URLEncoder.encode(String.valueOf(params.get(name)), UTF_8));
215 | }
216 |
217 | return url.toString().replace("?&", "?");
218 | }
219 |
220 | /**
221 | * get请求URL
222 | * @param url
223 | * @throws AppException
224 | */
225 | public static String http_get(AppContext appContext,String url) throws AppException {
226 | String cookie = getCookie(appContext);
227 | String userAgent = getUserAgent(appContext);
228 | HttpClient httpClient = null;
229 | GetMethod httpGet = null;
230 | String responseBody = "";
231 | int time = 0;
232 | do{
233 | try
234 | {
235 | httpClient = getHttpClient();
236 | httpGet = getHttpGet(url,cookie,userAgent);
237 | int statusCode = httpClient.executeMethod(httpGet);
238 | Log.i("http","url="+url);
239 | Header[] headers = httpGet.getRequestHeaders();
240 | for(int i=0 ;i params, Map files) throws AppException {
305 | //System.out.println("post_url==> "+url);
306 | HttpClient httpClient = null;
307 | PostMethod httpPost = null;
308 | String cookie = getCookie(appContext);
309 | String userAgent = getUserAgent(appContext);
310 | //post表单参数处理
311 | int length = (params == null ? 0 : params.size()) + (files == null ? 0 : files.size());
312 | Part[] parts = new Part[length];
313 | int i = 0;
314 | if(params != null)
315 | for(String name : params.keySet()){
316 | parts[i++] = new StringPart(name, String.valueOf(params.get(name)), UTF_8);
317 | //System.out.println("post_key==> "+name+" value==>"+String.valueOf(params.get(name)));
318 | }
319 | if(files != null)
320 | for(String file : files.keySet()){
321 | try {
322 | parts[i++] = new FilePart(file, files.get(file));
323 | } catch (FileNotFoundException e) {
324 | e.printStackTrace();
325 | }
326 | //System.out.println("post_key_file==> "+file);
327 | }
328 |
329 | String responseBody = "";
330 | int time = 0;
331 | do{
332 | try {
333 | httpClient = getHttpClient();
334 | httpPost = getHttpPost(url,cookie,userAgent);
335 | httpPost.setRequestEntity(new MultipartRequestEntity(parts,httpPost.getParams()));
336 | int statusCode = httpClient.executeMethod(httpPost);
337 |
338 | if(statusCode != HttpStatus.SC_OK)
339 | {
340 | throw AppException.http(statusCode);
341 | }
342 | else if(statusCode == HttpStatus.SC_OK){
343 | Cookie[] cookies = httpClient.getState().getCookies();
344 | String tmpcookies = "";
345 | for (Cookie ck : cookies) {
346 | tmpcookies += ck.toString()+";";
347 | }
348 |
349 | //保存cookie
350 | if(appContext != null && tmpcookies != ""){
351 | appContext.setPropertyString("cookie", tmpcookies);
352 | appCookie = tmpcookies;
353 | }
354 | }
355 |
356 | BufferedReader reader = new BufferedReader(new InputStreamReader(httpPost.getResponseBodyAsStream()));
357 | StringBuffer stringBuffer = new StringBuffer();
358 | String str = "";
359 | while((str = reader.readLine())!=null){
360 | stringBuffer.append(str);
361 | }
362 | responseBody = stringBuffer.toString();
363 | //System.out.println("XMLDATA=====>"+responseBody);
364 | break;
365 | } catch (HttpException e) {
366 | time++;
367 | if(time < RETRY_TIME) {
368 | try {
369 | Thread.sleep(1000);
370 | } catch (InterruptedException e1) {}
371 | continue;
372 | }
373 | // 发生致命的异常,可能是协议不对或者返回的内容有问题
374 | e.printStackTrace();
375 | throw AppException.http(e);
376 | } catch (IOException e) {
377 | time++;
378 | if(time < RETRY_TIME) {
379 | try {
380 | Thread.sleep(1000);
381 | } catch (InterruptedException e1) {}
382 | continue;
383 | }
384 | // 发生网络异常
385 | e.printStackTrace();
386 | throw AppException.http(e);
387 | } finally {
388 | // 释放连接
389 | httpPost.releaseConnection();
390 | httpClient = null;
391 | }
392 | }while(time < RETRY_TIME);
393 | return responseBody;
394 | }
395 |
396 | /**
397 | * 判断缓存是否失效
398 | *
399 | * @param cachefile
400 | * @return
401 | */
402 | public static boolean isCacheDataFailure(String cachefile) {
403 | boolean failure = false;
404 | File data = AppContext.getInstance().getFileStreamPath(cachefile);
405 | if (data.exists()
406 | && (System.currentTimeMillis() - data.lastModified()) > CACHE_TIME)
407 | failure = true;
408 | else if (!data.exists())
409 | failure = true;
410 | return failure;
411 | }
412 |
413 | /**
414 | * 保存对象
415 | *
416 | * @param ser
417 | * @param file
418 | * @throws IOException
419 | */
420 | public static boolean saveObject(Serializable ser, String file) {
421 | FileOutputStream fos = null;
422 | ObjectOutputStream oos = null;
423 | try {
424 | fos = AppContext.getInstance().openFileOutput(file, AppContext.getInstance().MODE_PRIVATE);
425 | oos = new ObjectOutputStream(fos);
426 | oos.writeObject(ser);
427 | oos.flush();
428 | return true;
429 | } catch (Exception e) {
430 | e.printStackTrace();
431 | return false;
432 | } finally {
433 | try {
434 | oos.close();
435 | } catch (Exception e) {
436 | }
437 | try {
438 | fos.close();
439 | } catch (Exception e) {
440 | }
441 | }
442 | }
443 |
444 | /**
445 | * 读取对象
446 | *
447 | * @param file
448 | * @return
449 | * @throws IOException
450 | */
451 | public static Serializable readObject(String file) {
452 | FileInputStream fis = null;
453 | ObjectInputStream ois = null;
454 | try {
455 | fis = AppContext.getInstance().openFileInput(file);
456 | ois = new ObjectInputStream(fis);
457 | return (Serializable) ois.readObject();
458 | } catch (FileNotFoundException e) {
459 | } catch (Exception e) {
460 | e.printStackTrace();
461 | } finally {
462 | try {
463 | ois.close();
464 | } catch (Exception e) {
465 | }
466 | try {
467 | fis.close();
468 | } catch (Exception e) {
469 | }
470 | }
471 | return null;
472 | }
473 | }
474 |
--------------------------------------------------------------------------------
/CodeBox/src/com/jcodecraeer/jcode/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.jcodecraeer.jcode;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import com.jcodecraeer.jcode.fragment.CodeListFragment;
7 | import com.jcodecraeer.jcode.fragment.NavigationDrawerFragment;
8 | import com.jcodecraeer.jcode.update.UpdateChecker;
9 |
10 | import be.webelite.ion.Icon;
11 |
12 | import android.annotation.SuppressLint;
13 | import android.app.ActionBar;
14 | import android.app.Activity;
15 | import android.app.FragmentManager;
16 | import android.content.ContentResolver;
17 | import android.content.ContentValues;
18 | import android.content.Context;
19 | import android.content.Intent;
20 | import android.content.SharedPreferences;
21 | import android.content.res.Configuration;
22 | import android.content.res.TypedArray;
23 | import android.database.Cursor;
24 | import android.graphics.Bitmap;
25 | import android.graphics.Color;
26 | import android.graphics.Matrix;
27 | import android.graphics.Rect;
28 | import android.graphics.drawable.ColorDrawable;
29 | import android.graphics.drawable.Drawable;
30 | import android.net.Uri;
31 | import android.os.Build;
32 | import android.os.Bundle;
33 | import android.os.Handler;
34 | import android.provider.MediaStore;
35 | import android.provider.MediaStore.Images;
36 | import android.provider.MediaStore.Images.ImageColumns;
37 | import android.support.v4.app.ActionBarDrawerToggle;
38 | import android.support.v4.app.Fragment;
39 | import android.support.v4.app.FragmentActivity;
40 | import android.support.v4.widget.DrawerLayout;
41 | import android.text.format.Time;
42 | import android.util.DisplayMetrics;
43 | import android.util.Log;
44 | import android.view.LayoutInflater;
45 | import android.view.Menu;
46 | import android.view.MenuItem;
47 | import android.view.View;
48 | import android.view.Window;
49 | import android.view.WindowManager;
50 | import android.view.ViewGroup.LayoutParams;
51 | import android.widget.AbsListView;
52 | import android.widget.Toast;
53 |
54 | public class MainActivity extends Activity implements NavigationDrawerFragment.NavigationDrawerCallbacks{
55 | private CodeListFragment mCodeLIstFragment;
56 | private NavigationDrawerFragment mNavigationDrawerFragment;
57 | public EventBus mEventBus;
58 | private DrawerLayout mDrawerLayout;
59 | @SuppressLint("NewApi")
60 | @Override
61 | protected void onCreate(Bundle savedInstanceState) {
62 | super.onCreate(savedInstanceState);
63 | mEventBus = EventBus.getInstance();
64 | setContentView(R.layout.activity_main);
65 | getActionBar().setDisplayHomeAsUpEnabled(true);
66 | mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
67 | mNavigationDrawerFragment = (NavigationDrawerFragment) getFragmentManager()
68 | .findFragmentById(R.id.navigation_drawer);
69 | mNavigationDrawerFragment.setUp(R.id.navigation_drawer,
70 | mDrawerLayout);
71 | mEventBus.registerEventHandler(0, mNavigationDrawerFragment);
72 | UpdateChecker updateChecker = new UpdateChecker(this);
73 | updateChecker.setCheckUrl("http://jcodecraeer.com/update.php");
74 | updateChecker.checkForUpdates();
75 | mCodeLIstFragment = CodeListFragment.newInstance(Integer.MIN_VALUE);
76 | mEventBus.registerEventHandler(1, mCodeLIstFragment);
77 | getFragmentManager().beginTransaction().replace(R.id.container,mCodeLIstFragment).commit();
78 | }
79 |
80 | @SuppressLint("NewApi")
81 | @Override
82 | public void onNavigationDrawerItemSelected(int position) {
83 | final FragmentManager fragmentManager = getFragmentManager();
84 | final Handler handler = new Handler();
85 | switch(position) {
86 | case 0:
87 | if(mCodeLIstFragment == null) {
88 |
89 | }
90 | handler.postDelayed(new Runnable() {
91 | @Override
92 | public void run() {
93 |
94 | }
95 | }, 500);
96 | break;
97 | }
98 | }
99 |
100 | @Override
101 | public boolean onOptionsItemSelected(MenuItem item) {
102 | switch(item.getItemId()){
103 | case android.R.id.home:
104 | mEventBus.sendEvent(EventBus.EventType.TOGGLE, null);
105 | break;
106 | case R.id.about:
107 | Intent intent = new Intent(MainActivity.this, AboutActivity.class);
108 | startActivity(intent);
109 | break;
110 | }
111 | return super.onOptionsItemSelected(item);
112 | }
113 |
114 | @Override
115 | public boolean onCreateOptionsMenu(Menu menu) {
116 | if (!mNavigationDrawerFragment.isDrawerOpen()) {
117 | // Only show items in the action bar relevant to this screen
118 | // if the drawer is not showing. Otherwise, let the drawer
119 | // decide what to show in the action bar.
120 | getMenuInflater().inflate(R.menu.main, menu);
121 | //restoreActionBar();
122 | return true;
123 | }
124 | return super.onCreateOptionsMenu(menu);
125 | }
126 |
127 | }
128 |
--------------------------------------------------------------------------------
/CodeBox/src/com/jcodecraeer/jcode/MultiItemRowListAdapter.java:
--------------------------------------------------------------------------------
1 | package com.jcodecraeer.jcode;
2 |
3 | import java.lang.ref.WeakReference;
4 | import java.util.ArrayList;
5 | import java.util.List;
6 |
7 | import android.content.Context;
8 | import android.database.DataSetObserver;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.view.ViewGroup.LayoutParams;
12 | import android.widget.AbsListView;
13 | import android.widget.LinearLayout;
14 | import android.widget.ListAdapter;
15 | import android.widget.WrapperListAdapter;
16 |
17 | public class MultiItemRowListAdapter implements WrapperListAdapter {
18 | private final ListAdapter mAdapter;
19 | private final int mItemsPerRow;
20 | private final int mCellSpacing;
21 | private final WeakReference mContextReference;
22 | private final LinearLayout.LayoutParams mItemLayoutParams;
23 | private final AbsListView.LayoutParams mRowLayoutParams;
24 |
25 | public MultiItemRowListAdapter(Context context, ListAdapter adapter, int itemsPerRow, int cellSpacing) {
26 | if (itemsPerRow <= 0) {
27 | throw new IllegalArgumentException("Number of items per row must be positive");
28 | }
29 | mContextReference = new WeakReference(context);
30 | mAdapter = adapter;
31 | mItemsPerRow = itemsPerRow;
32 | mCellSpacing = cellSpacing;
33 |
34 | mItemLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT);
35 | mItemLayoutParams.setMargins(cellSpacing, cellSpacing, 0, 0);
36 | mItemLayoutParams.weight = 1;
37 | mRowLayoutParams = new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
38 | }
39 |
40 | @Override
41 | public boolean isEmpty() {
42 | return (mAdapter == null || mAdapter.isEmpty());
43 | }
44 |
45 | public int getItemsPerRow() {
46 | return mItemsPerRow;
47 | }
48 |
49 | @Override
50 | public int getCount() {
51 | if (mAdapter != null) {
52 | return (int)Math.ceil(1.0f * mAdapter.getCount() / mItemsPerRow);
53 | }
54 | return 0;
55 | }
56 |
57 | @Override
58 | public boolean areAllItemsEnabled() {
59 | if (mAdapter != null) {
60 | return mAdapter.areAllItemsEnabled();
61 | } else {
62 | return true;
63 | }
64 | }
65 |
66 | @Override
67 | public boolean isEnabled(int position) {
68 | if (mAdapter != null) {
69 | // the cell is enabled if at least one item is enabled
70 | boolean enabled = false;
71 | for (int i = 0; i < mItemsPerRow; ++i) {
72 | int p = position * mItemsPerRow + i;
73 | if (p < mAdapter.getCount()) {
74 | enabled |= mAdapter.isEnabled(p);
75 | }
76 | }
77 | return enabled;
78 | }
79 | return true;
80 | }
81 |
82 | @Override
83 | public Object getItem(int position) {
84 | if (mAdapter != null) {
85 | List