Gallery3d 学习笔记

来源:互联网 发布:淘宝不允许好评返现 编辑:程序博客网 时间:2024/05/21 21:50

上次我们说到ActionBar的适配器


[java] view plain copy
  1. mActionBar.setListNavigationCallbacks(mAdapter, this);  

使用上述代码关联,而mAdapter的适配器是单独的一个私有类的实例


 private ClusterAdapter mAdapter = new ClusterAdapter();


[java] view plain copy
  1. private class ClusterAdapter extends BaseAdapter {  
  2.   
  3.     @Override  
  4.     public int getCount() {  
  5.         return sClusterItems.length;  
  6.     }  
  7.   
  8.     @Override  
  9.     public Object getItem(int position) {  
  10.         return sClusterItems[position];  
  11.     }  
  12.   
  13.     @Override  
  14.     public long getItemId(int position) {  
  15.         return sClusterItems[position].action;  
  16.     }  
  17.   
  18.     @Override  
  19.     public View getView(int position, View convertView, ViewGroup parent) {  
  20.         if (convertView == null) {  
  21.             convertView = mInflater.inflate(R.layout.action_bar_text,  
  22.                     parent, false);  
  23.         }  
  24.         TextView view = (TextView) convertView;  
  25.         view.setText(sClusterItems[position].spinnerTitle);  
  26.         return convertView;  
  27.     }  
  28. }  



类中主要使用5个菜单项目来组织。


而只有getView的时候,使用的是action_bar_text的layout.

那么这个GalleryActionBar,并没有直接继承,而是将ActionBar做一个成员变量放入类中,自己仅仅实现一个接口 OnNavigationListerer


[java] view plain copy
  1. public class GalleryActionBar implements OnNavigationListener {  
  2.     @SuppressWarnings("unused")  
  3.     private static final String TAG = "GalleryActionBar";  
  4.   
  5.     private ClusterRunner mClusterRunner;        --用来回调接口doCluster的成员变量  
  6.     private CharSequence[] mTitles;  
  7.     private ArrayList<Integer> mActions;  
  8.     private Context mContext;  
  9.     private LayoutInflater mInflater;  
  10.     private AbstractGalleryActivity mActivity;  
  11.     private ActionBar mActionBar;  ---实际的上层基础实现  
  12.     private int mCurrentIndex;  
  13.     private ClusterAdapter mAdapter = new ClusterAdapter(); --相册集使用的适配器(时间 地点 人物 标签)  
  14.   
  15.     private AlbumModeAdapter mAlbumModeAdapter;  -- 相册使用的适配器(幻灯片视图 网格视图)  
  16.     private OnAlbumModeSelectedListener mAlbumModeListener;  
  17.     private int mLastAlbumModeSelected;  
  18.     private CharSequence [] mAlbumModes;  
  19.     public static final int ALBUM_FILMSTRIP_MODE_SELECTED = 0;  
  20.     public static final int ALBUM_GRID_MODE_SELECTED = 1;  
  21.     public interface ClusterRunner {            --后面Page要实现的接口  
  22.         public void doCluster(int id);  
  23.     }  
  24.     public interface OnAlbumModeSelectedListener {   --后面Page要实现的接口  
  25.         public void onAlbumModeSelected(int mode);  
  26.     }  


相册集页面的调用

[java] view plain copy
  1. @Override  
  2. public void doCluster(int clusterType) {  
  3.     String basePath = mMediaSet.getPath().toString();  
  4.     String newPath = FilterUtils.switchClusterPath(basePath, clusterType);  
  5.     Bundle data = new Bundle(getData());  
  6.     data.putString(AlbumSetPage.KEY_MEDIA_PATH, newPath);  
  7.     data.putInt(KEY_SELECTED_CLUSTER_TYPE, clusterType);  
  8.     mActivity.getStateManager().switchState(this, AlbumSetPage.class, data);  
  9. }  

相册页面的调用

[java] view plain copy
  1. @Override  
  2. public void doCluster(int clusterType) {  
  3.     String basePath = mMediaSet.getPath().toString();  
  4.     String newPath = FilterUtils.newClusterPath(basePath, clusterType);  
  5.     Bundle data = new Bundle(getData());  
  6.     data.putString(AlbumSetPage.KEY_MEDIA_PATH, newPath);  
  7.     if (mShowClusterMenu) {  
  8.         Context context = mActivity.getAndroidContext();  
  9.         data.putString(AlbumSetPage.KEY_SET_TITLE, mMediaSet.getName());  
  10.         data.putString(AlbumSetPage.KEY_SET_SUBTITLE,  
  11.                 GalleryActionBar.getClusterByTypeString(context, clusterType));  
  12.     }  
  13.   
  14.     // mAlbumView.savePositions(PositionRepository.getInstance(mActivity));  
  15.     mActivity.getStateManager().startStateForResult(  
  16.             AlbumSetPage.class, REQUEST_DO_ANIMATION, data);  
  17. }  

而客户点击的是ActionBar的菜单,必须要实现菜单点击的事件,经常使用ActionBar的同志们应该都是熟悉的onNavigationItemSelected,

[java] view plain copy
  1. @Override  
  2. public boolean onNavigationItemSelected(int itemPosition, long itemId) {  
  3.     if (itemPosition != mCurrentIndex && mClusterRunner != null  
  4.             || mAlbumModeListener != null) {  
  5.         // Need to lock rendering when operations invoked by system UI (main thread) are  
  6.         // modifying slot data used in GL thread for rendering.  
  7.         mActivity.getGLRoot().lockRenderThread();  
  8.         try {  
  9.             if (mAlbumModeListener != null) {  
  10.                 mAlbumModeListener.onAlbumModeSelected(itemPosition);       --相册的时候不同菜单的实现  
  11.             } else {  
  12.                 mClusterRunner.doCluster(sClusterItems[itemPosition].action);  ---相册集的时候不同菜单的实现  
  13.             }  
  14.         } finally {  
  15.             mActivity.getGLRoot().unlockRenderThread();  
  16.         }  
  17.     }  
  18.     return false;  
  19. }  

为什么是这个呢,因为我们实现了这个系统接口,而系统在实现ActionBar的时候会回调回来

GalleryActionBar implements OnNavigationListener


那么ActionBar左边的东西在两种状态下的实现我们都清楚了,下次讲讲右边的内容如何实现的。

原创粉丝点击