超级课程表课表的界面的实现

http://blog.csdn.net/mhxy199288/article/details/30255761


由于毕业设计有一个功能模块是课程表,就想模仿一下超级课程表的界面,可是开始做的时候却没有一点头绪,百度google均无果,在CSDN和知乎上提问了也没人回答(估计是太简单了 大神不愿回答尴尬),总之自己鼓捣了几天还是弄出来了,虽然实现的方法很挫。。。因为有好几个人都发私信问我怎么实现的,现在毕设做完了,所以我干脆就写到博客上吧,先上几张效果图:


当时看到超级课程表的界面时,第一个想法就是使用ListView来实现,好不容易把格子画出来了,课程信息不知道怎么放上去····,主要难点有:

1、第一排的8个格子是固定的,下面的课表信息部分是可以滑动的,单用ListView无法实现,即下图。


 2、课程信息怎么附着在格子上,并且可以随着课表一起滚动。


放弃了ListView实现的想法,就只有另寻它路了,在CSDN上有一位朋友的回答给了我灵感,即每一个格子都用一个TextView实现。然后课程信息可以使用相对布局,根据课程的时间(节数和天数)算出他的偏移位置,比如星期二的第三、四节课就可以和周二下面的第一个格子保持左对齐和上对齐,并且向下偏移2个格子的距离。这个N个格子和课程信息都放到一个RelativeLayout中,然后再在外面嵌套一个ScrollViewLayout,就可以滚动了,总的布局还是RelayoutLayout,不多说了,直接上代码!

[html]  view plain  copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     android:background="@drawable/c_bg" >  
  6.       
  7.             <!-- 最左边空白的格子 -->    
  8.            <TextView android:id="@+id/test_empty"  
  9.                 android:layout_width="wrap_content"  
  10.                 android:layout_height="wrap_content"  
  11.                 style="@style/courseTableText"  
  12.                 android:text="@string/empty"  
  13.                 android:background="@drawable/course_text_view_bg"  
  14.                 />  
  15.       
  16.              <!-- 星期一的格子 -->    
  17.             <TextView android:id="@+id/test_monday_course"  
  18.                 android:layout_width="wrap_content"  
  19.                 android:layout_height="wrap_content"  
  20.                 android:text="@string/mon"  
  21.                 style="@style/courseTableText"  
  22.                 android:layout_toRightOf="@id/test_empty"  
  23.                 android:background="@drawable/course_text_view_bg"  
  24.                 />  
  25.       
  26.             
  27.             <!-- 星期二的格子 -->  
  28.             <TextView android:id="@+id/test_tuesday_course"  
  29.                 android:layout_width="wrap_content"  
  30.                 android:layout_height="wrap_content"  
  31.                 android:text="@string/tue"  
  32.                 style="@style/courseTableText"  
  33.                 android:layout_toRightOf="@id/test_monday_course"  
  34.                 android:background="@drawable/course_text_view_bg"  
  35.                 />  
  36.   
  37.              <!-- 星期三的格子 -->  
  38.             <TextView android:id="@+id/test_wednesday_course"  
  39.                 android:layout_width="wrap_content"  
  40.                 android:layout_height="wrap_content"  
  41.                 android:text="@string/wen"  
  42.                 style="@style/courseTableText"  
  43.                 android:layout_toRightOf="@id/test_tuesday_course"  
  44.                 android:background="@drawable/course_text_view_bg"  
  45.                 />  
  46.   
  47.             <!-- 星期四的格子 -->  
  48.             <TextView android:id="@+id/test_thursday_course"  
  49.                 android:layout_width="wrap_content"  
  50.                 android:layout_height="wrap_content"  
  51.                 android:text="@string/thu"  
  52.                 style="@style/courseTableText"  
  53.                  android:layout_toRightOf="@id/test_wednesday_course"  
  54.                  android:background="@drawable/course_text_view_bg"  
  55.                 />  
  56.             <!-- 星期五的格子 -->  
  57.             <TextView android:id="@+id/test_friday_course"  
  58.                 android:layout_width="wrap_content"  
  59.                 android:layout_height="wrap_content"  
  60.                 android:text="@string/fri"  
  61.                 style="@style/courseTableText"  
  62.                 android:layout_toRightOf="@id/test_thursday_course"  
  63.                 android:background="@drawable/course_text_view_bg"  
  64.                 />  
  65.   
  66.             <!-- 星期六的格子 -->  
  67.             <TextView android:id="@+id/test_saturday_course"  
  68.                 android:layout_width="wrap_content"  
  69.                 android:layout_height="wrap_content"  
  70.                 android:text="@string/sta"  
  71.                 style="@style/courseTableText"  
  72.                  android:layout_toRightOf="@id/test_friday_course"  
  73.                  android:background="@drawable/course_text_view_bg"  
  74.                 />  
  75.               
  76.             <!-- 星期天的格子 -->  
  77.             <TextView android:id="@+id/test_sunday_course"  
  78.                 android:layout_width="wrap_content"  
  79.                 android:layout_height="wrap_content"  
  80.                 style="@style/courseTableText"  
  81.                 android:text="@string/sun"  
  82.                 android:layout_toRightOf="@id/test_saturday_course"  
  83.                 android:background="@drawable/course_table_last_colum"  
  84.                 />  
  85.   
  86.              <!-- 课程表body部分 -->  
  87.             <ScrollView  
  88.                 android:id="@+id/scroll_body"  
  89.                 android:layout_width="fill_parent"  
  90.                 android:layout_height="wrap_content"  
  91.                 android:layout_below="@id/test_empty"   
  92.                 android:scrollbars="none"  
  93.                 >  
  94.                 <!-- 课程信息 -->  
  95.                 <RelativeLayout   
  96.                      android:layout_width="fill_parent"  
  97.                      android:layout_height="wrap_content"  
  98.                      android:id="@+id/test_course_rl"  
  99.                      >  
  100.                 </RelativeLayout>  
  101.   
  102.             </ScrollView>  
  103. </RelativeLayout>  


 

当然这样做的坏处有:

1、有多少个格子就要生成多少个TextView,实在是有点浪费资源。

2、用TextView表示一个格子,即有边框的TextView,整个课表是由N个TextView组成的,所以就没办法使用一张图当背景了。

当然现在我也想到了改进的方法,其实给课程信息做参照算出偏移位置的只需要一个格子就可以了,所以可以用一个透明的TextView放在星期一的第一个格子的位置作为参照,格子使用view画线实现,就可以使用背景了,也不用生成多个TextView了···这是我的想法,我还没用代码实现,有兴趣的朋友可以自己去试试。

超级课程表还有一个要点就是它的课程展示3D视图,不过那个可以用Android自带的gallery实现,网上有现成的代码,拿过来改改就可以了,下面上主要代码

1、CourseTableActivity

[java]  view plain  copy
  1. package nd.leiyi.crims.activity;  
  2.   
  3. import java.lang.ref.WeakReference;  
  4. import java.util.ArrayList;  
  5. import java.util.Collections;  
  6. import java.util.Comparator;  
  7. import java.util.HashMap;  
  8. import java.util.Iterator;  
  9. import java.util.List;  
  10. import java.util.Map;  
  11.   
  12. import nd.leiyi.crims.R;  
  13. import nd.leiyi.crims.adapter.CourseInfoAdapter;  
  14. import nd.leiyi.crims.appException.AppException;  
  15. import nd.leiyi.crims.constant.UserInfo;  
  16. import nd.leiyi.crims.db.CourseInfoDBManager;  
  17. import nd.leiyi.crims.gallery3D.CourseInfoGallery;  
  18. import nd.leiyi.crims.http.CourseInfoFetcher;  
  19. import nd.leiyi.crims.model.CourseInfo;  
  20. import nd.leiyi.crims.util.CourseSettingUtil;  
  21. import android.app.Activity;  
  22. import android.app.AlertDialog;  
  23. import android.app.Dialog;  
  24. import android.app.ProgressDialog;  
  25. import android.content.Context;  
  26. import android.content.Intent;  
  27. import android.content.SharedPreferences;  
  28. import android.content.SharedPreferences.Editor;  
  29. import android.graphics.Color;  
  30. import android.graphics.drawable.BitmapDrawable;  
  31. import android.graphics.drawable.Drawable;  
  32. import android.os.Bundle;  
  33. import android.os.Handler;  
  34. import android.os.Message;  
  35. import android.util.DisplayMetrics;  
  36. import android.util.Log;  
  37. import android.view.Gravity;  
  38. import android.view.LayoutInflater;  
  39. import android.view.View;  
  40. import android.view.View.OnClickListener;  
  41. import android.view.ViewGroup.LayoutParams;  
  42. import android.view.Window;  
  43. import android.view.WindowManager;  
  44. import android.widget.AdapterView;  
  45. import android.widget.AdapterView.OnItemClickListener;  
  46. import android.widget.ListView;  
  47. import android.widget.PopupWindow;  
  48. import android.widget.PopupWindow.OnDismissListener;  
  49. import android.widget.Button;  
  50. import android.widget.RelativeLayout;  
  51. import android.widget.SimpleAdapter;  
  52. import android.widget.TextView;  
  53. import android.widget.Toast;  
  54.   
  55. public class CourseTableActivity extends Activity {  
  56.   
  57.     /** 标题栏文字 */  
  58.     protected TextView textTitle;  
  59.     /** 第一个无内容的格子 */  
  60.     protected TextView empty;  
  61.     /** 星期一的格子 */  
  62.     protected TextView monColum;  
  63.     /** 星期二的格子 */  
  64.     protected TextView tueColum;  
  65.     /** 星期三的格子 */  
  66.     protected TextView wedColum;  
  67.     /** 星期四的格子 */  
  68.     protected TextView thrusColum;  
  69.     /** 星期五的格子 */  
  70.     protected TextView friColum;  
  71.     /** 星期六的格子 */  
  72.     protected TextView satColum;  
  73.     /** 星期日的格子 */  
  74.     protected TextView sunColum;  
  75.     /** 课程表body部分布局 */  
  76.     protected RelativeLayout course_table_layout;  
  77.     /** 选择周数弹出窗口 */  
  78.     protected PopupWindow weekListWindow;  
  79.     /** 显示周数的listview*/  
  80.     protected ListView weekListView;  
  81.     /** 选择周数弹出窗口的layout */  
  82.     protected View popupWindowLayout;  
  83.     /** 课程信息 **/  
  84.     protected Map<String, List<CourseInfo>> courseInfoMap;  
  85.     /** 保存显示课程信息的TextView **/  
  86.     protected List<TextView> courseTextViewList = new ArrayList<TextView>();  
  87.     /** 保存每个textview对应的课程信息 map,key为哪一天(如星期一则key为1) **/  
  88.     protected Map<Integer, List<CourseInfo>> textviewCourseInfoMap = new HashMap<Integer, List<CourseInfo>>();  
  89.     /** 课程格子平均宽度 **/  
  90.     protected int aveWidth;  
  91.     /** 屏幕宽度 **/  
  92.     protected int screenWidth;  
  93.     /** 格子高度 **/  
  94.     protected int gridHeight = 80;  
  95.     /** 最大课程节数 **/  
  96.     protected int maxCourseNum;   
  97.       
  98.     protected Button goBackButton;  
  99.       
  100.     protected ProgressDialog pDialog;  
  101.       
  102.     protected Handler mhandler = new Handler();  
  103.     @Override  
  104.     protected void onCreate(Bundle savedInstanceState) {  
  105.           
  106.         super.onCreate(savedInstanceState);  
  107.         //设置自定义标题栏布局  
  108.         requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);  
  109.         setContentView(R.layout.course_table_layout);  
  110.         getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.title);  
  111.         //设置标题栏周数  
  112.         textTitle = (TextView) this.findViewById(R.id.textTile);  
  113.         textTitle.setTextSize(20);  
  114.         textTitle.setPadding(152152);  
  115.         //右边白色倒三角  
  116.         Drawable down = this.getResources().getDrawable(R.drawable.title_down);  
  117.         down.setBounds(00, down.getMinimumWidth(), down.getMinimumHeight());  
  118.         textTitle.setCompoundDrawables(nullnull, down, null);  
  119.         textTitle.setCompoundDrawablePadding(2);  
  120.         //获得列头的控件  
  121.         empty = (TextView) this.findViewById(R.id.test_empty);  
  122.         monColum = (TextView) this.findViewById(R.id.test_monday_course);  
  123.         tueColum = (TextView) this.findViewById(R.id.test_tuesday_course);  
  124.         wedColum = (TextView) this.findViewById(R.id.test_wednesday_course);  
  125.         thrusColum = (TextView) this.findViewById(R.id.test_thursday_course);  
  126.         friColum = (TextView) this.findViewById(R.id.test_friday_course);  
  127.         satColum  = (TextView) this.findViewById(R.id.test_saturday_course);  
  128.         sunColum = (TextView) this.findViewById(R.id.test_sunday_course);  
  129.         //返回按钮  
  130.         goBackButton = (Button) this.findViewById(R.id.button_go_back);  
  131.         goBackButton.setOnClickListener(new OnClickListener() {  
  132.             @Override  
  133.             public void onClick(View arg0) {  
  134.                 //改变返回按钮的背景,体现出被“按下出”的感觉  
  135.                 goBackButton.setBackgroundDrawable(CourseTableActivity.this  
  136.                         .getResources().getDrawable(R.drawable.arrow_left_down));  
  137.                 // 恢复背景  
  138.                 mhandler.postDelayed(new Runnable() {  
  139.                     @Override  
  140.                     public void run() {  
  141.                         goBackButton.setBackgroundDrawable(CourseTableActivity.this  
  142.                                 .getResources().getDrawable(R.drawable.arrow_left));  
  143.                     }  
  144.                 }, 200);  
  145.                 mhandler.postDelayed(new Runnable() {  
  146.                     @Override  
  147.                     public void run() {  
  148.                         finish();  
  149.                     }  
  150.                 }, 400);  
  151.                   
  152.             }  
  153.         });  
  154.         // 列表布局文件  
  155.         course_table_layout = (RelativeLayout) this.findViewById(R.id.test_course_rl);  
  156.         DisplayMetrics dm = new DisplayMetrics();    
  157.         getWindowManager().getDefaultDisplay().getMetrics(dm);  
  158.         //屏幕宽度  
  159.         int width = dm.widthPixels;  
  160.           
  161.         //平均宽度  
  162.         int aveWidth = width / 8;  
  163.         //给列头设置宽度  
  164.         empty.setWidth(aveWidth * 3/4);  
  165.         monColum.setWidth(aveWidth * 33/32 + 1);  
  166.         tueColum.setWidth(aveWidth * 33/32 + 1);  
  167.         wedColum.setWidth(aveWidth * 33/32 + 1);  
  168.         thrusColum.setWidth(aveWidth * 33/32 + 1);  
  169.         friColum.setWidth(aveWidth * 33/32 + 1);  
  170.         satColum.setWidth(aveWidth * 33/32 + 1);  
  171.         sunColum.setWidth(aveWidth * 33/32 + 1);  
  172.         this.screenWidth = width;  
  173.         this.aveWidth = aveWidth;  
  174.         //初始化body部分  
  175.         init();  
  176.     }  
  177.     /** 
  178.      * 初始化课程表body部分 
  179.      * @param aveWidth 
  180.      */  
  181.      protected void init(){  
  182.            
  183.           
  184.         //获取课表配置信息  
  185.         final SharedPreferences courseSettings = getSharedPreferences("course_setting", Activity.MODE_PRIVATE);  
  186.         //检测是否设置过学期  
  187.         if(courseSettings.getString("currentTerm_" + UserInfo.currentUser.getStuNum(), null) == null)  
  188.         {  
  189.             Toast.makeText(CourseTableActivity.this"您尚未设置当前学期!快去设置吧!", Toast.LENGTH_SHORT).show();  
  190.             return;  
  191.         }  
  192.         //计算出当前的周数  
  193.         final String currentWeekStr = CourseSettingUtil.figureCurrentWeek(courseSettings);  
  194.         if(currentWeekStr.equals(""))  
  195.         {  
  196.             textTitle.setText("全部");  
  197.         }  
  198.         else  
  199.         {  
  200.             textTitle.setText("第" + currentWeekStr + "周");  
  201.       
  202.         }  
  203.         //设置点击事件  
  204.         textTitle.setOnClickListener(new OnClickListener() {  
  205.             @Override  
  206.             public void onClick(View arg0) {  
  207.                   
  208.                 //改变背景(体现出被"按下去"的感觉  
  209.                 textTitle.setBackgroundDrawable(  
  210.                         CourseTableActivity.this.getResources().getDrawable(R.drawable.title_text_bg));  
  211.                 //显示弹出窗口  
  212.                 showWeekListWindow(textTitle);  
  213.             }  
  214.         });  
  215.         //获取最大课程节数  
  216.         String maxCourseNumStr = courseSettings.getString("maxCourseNum_" + UserInfo.currentUser.getStuNum(), "");  
  217.         if(maxCourseNumStr.equals(""))  
  218.         {  
  219.             courseSettings.edit().putString("maxCourseNum_" + UserInfo.currentUser.getStuNum(), "12");  
  220.             maxCourseNum = 12;  
  221.         }  
  222.         else  
  223.         {  
  224.             maxCourseNum = Integer.parseInt(maxCourseNumStr);  
  225.         }  
  226.         DisplayMetrics dm = new DisplayMetrics();    
  227.         getWindowManager().getDefaultDisplay().getMetrics(dm);  
  228.         //屏幕高度   
  229.         int height = dm.heightPixels;  
  230.         gridHeight = height / maxCourseNum;  
  231.         //设置课表界面  
  232.         //动态生成12 * maxCourseNum个textview  
  233.         for(int i = 1; i <= maxCourseNum; i ++){  
  234.               
  235.             for(int j = 1; j <= 8; j ++){  
  236.                   
  237.                 TextView tx = new TextView(CourseTableActivity.this);  
  238.                 tx.setId((i - 1) * 8  + j);  
  239.                 //除了最后一列,都使用course_text_view_bg背景(最后一列没有右边框)  
  240.                 if(j < 8)  
  241.                     tx.setBackgroundDrawable(CourseTableActivity.this.  
  242.                             getResources().getDrawable(R.drawable.course_text_view_bg));  
  243.                 else  
  244.                     tx.setBackgroundDrawable(CourseTableActivity.this.  
  245.                         getResources().getDrawable(R.drawable.course_table_last_colum));  
  246.                 //相对布局参数  
  247.                 RelativeLayout.LayoutParams rp = new RelativeLayout.LayoutParams(  
  248.                         aveWidth * 33 / 32 + 1,  
  249.                         gridHeight);  
  250.                 //文字对齐方式  
  251.                 tx.setGravity(Gravity.CENTER);  
  252.                 //字体样式  
  253.                 tx.setTextAppearance(this, R.style.courseTableText);  
  254.                 //如果是第一列,需要设置课的序号(1 到 12)  
  255.                 if(j == 1)  
  256.                 {  
  257.                     tx.setText(String.valueOf(i));  
  258.                     rp.width = aveWidth * 3/4;    
  259.                     //设置他们的相对位置  
  260.                     if(i == 1)  
  261.                         rp.addRule(RelativeLayout.BELOW, empty.getId());  
  262.                     else  
  263.                         rp.addRule(RelativeLayout.BELOW, (i - 1) * 8);  
  264.                 }  
  265.                 else  
  266.                 {  
  267.                     rp.addRule(RelativeLayout.RIGHT_OF, (i - 1) * 8  + j - 1);  
  268.                     rp.addRule(RelativeLayout.ALIGN_TOP, (i - 1) * 8  + j - 1);  
  269.                     tx.setText("");  
  270.                 }  
  271.                       
  272.                 tx.setLayoutParams(rp);  
  273.                 course_table_layout.addView(tx);  
  274.             }  
  275.         }  
  276.           
  277.           
  278.           
  279.         pDialog = new ProgressDialog(this);  
  280.         pDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);  
  281.         pDialog.setMessage("正在加载信息。。。。");  
  282.         pDialog.setIndeterminate(true);  
  283.         pDialog.setCanceledOnTouchOutside(false);  
  284.         pDialog.setCancelable(false);  
  285.         pDialog.show();  
  286.           
  287.           
  288.         //获取当前学期  
  289.         final String currentTerm = courseSettings.getString("currentTerm_" + UserInfo.currentUser.getStuNum(), null);  
  290.         //查看这个学期的课程信息是否已经抓取过  
  291.         final boolean hasSetting = courseSettings.getBoolean("Is_" + currentTerm + "_saved_" + UserInfo.currentUser.getStuNum(), false);  
  292.         /** 
  293.          这里写你自己的获取课程信息的方法 
  294.         */  
  295.         new Thread() {  
  296.             @Override  
  297.             public void run() {  
  298.                   
  299.                 CourseInfoDBManager dbManager = new CourseInfoDBManager(CourseTableActivity.this);  
  300.                 //打开数据库  
  301.                 dbManager.open();  
  302.                   
  303.                 try {  
  304.                     //入果还没抓取过该学期的课程信息,先抓取  
  305.                     if(!hasSetting)  
  306.                     {  
  307.                         //抓取这个学期的课表信息  
  308.                         List<CourseInfo> list = CourseInfoFetcher.fetchCourseInfo("", currentTerm, UserInfo.currentUser.getStuNum());  
  309.                         //插入课程信息  
  310.                         for(CourseInfo courseInfo : list)  
  311.                         {  
  312.                             dbManager.insertCourse(courseInfo, currentTerm);  
  313.                         }  
  314.                         //设置该学期的课程已经抓取过的标志  
  315.                         Editor editor = courseSettings.edit();  
  316.                         editor.putBoolean("Is_" + currentTerm + "_saved_" + UserInfo.currentUser.getStuNum(), true);  
  317.                         editor.commit();  
  318.                           
  319.                     }  
  320.                       
  321.                     //从数据库中读取课程信息,存放在courseInfoMap中,key为星期几,value是这一天的课程信息  
  322.                     courseInfoMap  = dbManager.query(currentTerm);  
  323.                     // 发送更新界面信息  
  324.                     Message msg = new Message();  
  325.                     if(courseInfoMap.isEmpty())  
  326.                     {  
  327.                         msg.what = -2;  
  328.                         courseInfoInitMessageHandler.sendMessage(msg);  
  329.                         return;  
  330.                     }  
  331.                     int currentWeek = -1;  
  332.                     if(!currentWeekStr.equals(""))  
  333.                     {  
  334.                         currentWeek = Integer.parseInt(currentWeekStr);  
  335.                     }  
  336.                     dbManager.close();  
  337.                     InitMessageObj msgObj = new InitMessageObj(aveWidth, currentWeek, screenWidth, maxCourseNum);  
  338.                     msg.obj = msgObj;  
  339.                     courseInfoInitMessageHandler.sendMessage(msg);  
  340.                       
  341.                 } catch (AppException e) {  
  342.                     Message msg = new Message();  
  343.                     msg.what = -1;  
  344.                     courseInfoInitMessageHandler.sendMessage(msg);  
  345.                     Log.e("courseInfo_fetch_exception", e.toString());  
  346.                       
  347.                 } finally {  
  348.                       
  349.                     dbManager.close();  
  350.                 }  
  351.             }  
  352.         }.start();  
  353.           
  354.     }    
  355.        
  356.     CourseInfoInitMessageHandler courseInfoInitMessageHandler = new CourseInfoInitMessageHandler(this);  
  357.       
  358.     static class InitMessageObj{  
  359.           
  360.         int aveWidth;  
  361.         int currentWeek;  
  362.         int screenWidth;  
  363.         int maxCourseNum;  
  364.         public InitMessageObj(int aveWidth, int currentWeek, int screenWidth, int maxCourseNum) {  
  365.             super();  
  366.             this.aveWidth = aveWidth;  
  367.             this.currentWeek = currentWeek;  
  368.             this.screenWidth = screenWidth;  
  369.             this.maxCourseNum = maxCourseNum;  
  370.         }  
  371.           
  372.     }  
  373.     //初始化课程表的messageHandler  
  374.     static class CourseInfoInitMessageHandler extends Handler{  
  375.           
  376.         WeakReference<CourseTableActivity> mActivity;  
  377.           
  378.         public CourseInfoInitMessageHandler(CourseTableActivity activity){  
  379.               
  380.             mActivity = new WeakReference<CourseTableActivity>(activity);  
  381.         }  
  382.   
  383.         @Override  
  384.         public void handleMessage(Message msg) {  
  385.               
  386.             mActivity.get().pDialog.dismiss();  
  387.             //网络错误  
  388.             if(msg.what == -1)  
  389.             {  
  390.                 Toast.makeText(mActivity.get(), "获取课程信息失败!请检查您的网络或者稍后再试", Toast.LENGTH_SHORT).show();  
  391.                 return;  
  392.             }  
  393.             //没有课程信息  
  394.             if(msg.what == -2)  
  395.             {  
  396.                 Toast.makeText(mActivity.get(), "教务管理系统中无该学期的课程信息···", Toast.LENGTH_SHORT).show();  
  397.                 return;  
  398.             }  
  399.             //五种颜色的背景  
  400.             int[] background = {R.drawable.course_info_blue, R.drawable.course_info_green,   
  401.                                 R.drawable.course_info_red, R.drawable.course_info_red,  
  402.                                 R.drawable.course_info_yellow};  
  403.             //获取课程信息的map  
  404.             Map<String, List<CourseInfo>> courseInfoMap = mActivity.get().courseInfoMap;  
  405.             //一些传过来的参数  
  406.             final InitMessageObj msgObj = (InitMessageObj) msg.obj;  
  407.             //当前周数  
  408.             int currentWeek = msgObj.currentWeek;  
  409.             //最大课程节数  
  410.             int maxCourseNum = msgObj.maxCourseNum;  
  411.             for(Map.Entry<String, List<CourseInfo>> entry: courseInfoMap.entrySet())  
  412.             {  
  413.                   
  414.                 //查找出最顶层的课程信息(顶层课程信息即显示在最上层的课程,最顶层的课程信息满足两个条件 1、当前周数在该课程的周数范围内 2、该课程的节数跨度最大  
  415.                 CourseInfo upperCourse = null;  
  416.                 //list里保存的是一周内某 一天的课程  
  417.                 final List<CourseInfo> list = new ArrayList<CourseInfo>(entry.getValue());  
  418.                 //  
  419.                 //按开始的时间(哪一节)进行排序  
  420.                 Collections.sort(list, new Comparator<CourseInfo>(){  
  421.                     @Override  
  422.                     public int compare(CourseInfo arg0, CourseInfo arg1) {  
  423.                           
  424.                         if(arg0.getBeginIndex() < arg1.getBeginIndex())  
  425.                             return -1;  
  426.                         else  
  427.                             return 1;  
  428.                     }  
  429.                       
  430.                 });  
  431.                 int lastListSize;  
  432.                 do {  
  433.                       
  434.                     lastListSize = list.size();  
  435.                     Iterator<CourseInfo> iter = list.iterator();  
  436.                     //先查找出第一个在周数范围内的课  
  437.                     while(iter.hasNext())  
  438.                     {  
  439.                         CourseInfo c = iter.next();//  
  440.                         if(((c.getBeginWeek() <= currentWeek && c.getEndWeek() >= currentWeek) || currentWeek == -1) && c.getEndIndex() <= maxCourseNum)  
  441.                         {  
  442.                             //判断是单周还是双周的课  
  443.                             if(c.getCourseType() == CourseInfo.ALL ||  
  444.                               (c.getCourseType() == CourseInfo.EVEN && currentWeek % 2 == 0) ||  
  445.                               (c.getCourseType() == CourseInfo.ODD && currentWeek % 2 != 0) )  
  446.                             {  
  447.                                 //从list中移除该项,并设置这节课为顶层课  
  448.                                 iter.remove();  
  449.                                 upperCourse = c;  
  450.                                 break;  
  451.                             }  
  452.                         }  
  453.                     }  
  454.                     if(upperCourse != null)  
  455.                     {  
  456.                         List<CourseInfo> courseInfoList = new ArrayList<CourseInfo>();  
  457.                         courseInfoList.add(upperCourse);  
  458.                         int index = 0;  
  459.                         iter = list.iterator();  
  460.                         //查找这一天有哪些课与刚刚查找出来的顶层课相交  
  461.                         while(iter.hasNext())  
  462.                         {  
  463.                             CourseInfo c = iter.next();  
  464.                             //先判断该课程与upperCourse是否相交,如果相交加入courseInfoList中  
  465.                             if((c.getBeginIndex() <= upperCourse.getBeginIndex()  
  466.                                 &&upperCourse.getBeginIndex() < c.getEndIndex())  
  467.                                 ||(upperCourse.getBeginIndex() <= c.getBeginIndex()  
  468.                                 && c.getBeginIndex() < upperCourse.getEndIndex()))  
  469.                             {  
  470.                                 courseInfoList.add(c);  
  471.                                 iter.remove();  
  472.                                 //在判断哪个跨度大,跨度大的为顶层课程信息  
  473.                                 if((c.getEndIndex() - c.getEndIndex()) > (upperCourse.getEndIndex() - upperCourse.getBeginIndex())  
  474.                                     && ((c.getBeginWeek() <= currentWeek && c.getEndWeek() >= currentWeek) || currentWeek == -1))  
  475.                                 {  
  476.                                     upperCourse = c;  
  477.                                     index ++;  
  478.                                 }  
  479.                                   
  480.                             }  
  481.                               
  482.                         }  
  483.                         //记录顶层课程在courseInfoList中的索引位置  
  484.                         final int upperCourseIndex = index;  
  485.                         // 动态生成课程信息TextView  
  486.                         TextView courseInfo = new TextView(mActivity.get());  
  487.                         courseInfo.setId(1000 + upperCourse.getDay() * 100 + upperCourse.getBeginIndex() * 10 + upperCourse.getId());  
  488.                         int id = courseInfo.getId();  
  489.                         mActivity.get().textviewCourseInfoMap.put(id, courseInfoList);  
  490.                         courseInfo.setText(upperCourse.getCourseName() + "\n@" + upperCourse.getClassRoom());  
  491.                         //该textview的高度根据其节数的跨度来设置  
  492.                         RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(  
  493.                                 msgObj.aveWidth * 31 / 32,  
  494.                                 (mActivity.get().gridHeight - 5) * 2 + (upperCourse.getEndIndex() - upperCourse.getBeginIndex() - 1) * mActivity.get().gridHeight);  
  495.                         //textview的位置由课程开始节数和上课的时间(day of week)确定  
  496.                         rlp.topMargin = 5 + (upperCourse.getBeginIndex() - 1) * mActivity.get().gridHeight;  
  497.                         rlp.leftMargin = 1;  
  498.                         // 前面生成格子时的ID就是根据Day来设置的  
  499.                         rlp.addRule(RelativeLayout.RIGHT_OF, upperCourse.getDay());  
  500.                         //字体居中中  
  501.                         courseInfo.setGravity(Gravity.CENTER);  
  502.                         //选择一个颜色背景  
  503.                         int colorIndex = ((upperCourse.getBeginIndex() - 1) * 8 + upperCourse.getDay()) % (background.length - 1);  
  504.                         courseInfo.setBackgroundResource(background[colorIndex]);  
  505.                         courseInfo.setTextSize(12);  
  506.                         courseInfo.setLayoutParams(rlp);  
  507.                         courseInfo.setTextColor(Color.WHITE);  
  508.                         //设置不透明度  
  509.                         courseInfo.getBackground().setAlpha(222);  
  510.                         // 设置监听事件  
  511.                         courseInfo.setOnClickListener(new OnClickListener() {  
  512.                             @Override  
  513.                             public void onClick(View arg0) {  
  514.                                 Log.i("text_view", String.valueOf(arg0.getId()));  
  515.                                 Map<Integer, List<CourseInfo>> map = mActivity.get().textviewCourseInfoMap;  
  516.                                 final List<CourseInfo> tempList = map.get(arg0.getId());  
  517.                                 if(tempList.size() > 1)  
  518.                                 {  
  519.                                     //如果有多个课程,则设置点击弹出gallery 3d 对话框  
  520.                                     LayoutInflater layoutInflater = (LayoutInflater) mActivity.get().getSystemService(Context.LAYOUT_INFLATER_SERVICE);  
  521.                                     View galleryView = layoutInflater.inflate(R.layout.course_info_gallery_layout, null);  
  522.                                     final Dialog coursePopupDialog = new AlertDialog.Builder(mActivity.get()).create();  
  523.                                     coursePopupDialog.setCanceledOnTouchOutside(true);  
  524.                                     coursePopupDialog.setCancelable(true);  
  525.                                     coursePopupDialog.show();  
  526.                                     WindowManager.LayoutParams params = coursePopupDialog.getWindow().getAttributes();  
  527.                                     params.width = LayoutParams.FILL_PARENT;  
  528.                                     coursePopupDialog.getWindow().setAttributes(params);  
  529.                                     CourseInfoAdapter adapter = new CourseInfoAdapter(mActivity.get(), tempList, msgObj.screenWidth, msgObj.currentWeek);  
  530.                                     CourseInfoGallery gallery = (CourseInfoGallery) galleryView.findViewById(R.id.course_info_gallery);  
  531.                                     gallery.setSpacing(10);  
  532.                                     gallery.setAdapter(adapter);  
  533.                                     gallery.setSelection(upperCourseIndex);  
  534.                                     gallery.setOnItemClickListener(new OnItemClickListener() {  
  535.                                         @Override  
  536.                                         public void onItemClick(  
  537.                                                 AdapterView<?> arg0, View arg1,  
  538.                                                 int arg2, long arg3) {  
  539.                                                 CourseInfo courseInfo = tempList.get(arg2);  
  540.                                                 Intent intent = new Intent();  
  541.                                                 Bundle mBundle = new Bundle();  
  542.                                                 mBundle.putSerializable("courseInfo", courseInfo);  
  543.                                                 intent.putExtras(mBundle);  
  544.                                                 intent.setClass(mActivity.get(), DetailCourseInfoActivity.class);  
  545.                                                 mActivity.get().startActivity(intent);  
  546.                                                 coursePopupDialog.dismiss();  
  547.                                         }  
  548.                                     });  
  549.                                     coursePopupDialog.setContentView(galleryView);  
  550.                                 }  
  551.                                 else  
  552.                                 {  
  553.                                     Intent intent = new Intent();  
  554.                                     Bundle mBundle = new Bundle();  
  555.                                     mBundle.putSerializable("courseInfo", tempList.get(0));  
  556.                                     intent.putExtras(mBundle);  
  557.                                     intent.setClass(mActivity.get(), DetailCourseInfoActivity.class);  
  558.                                     mActivity.get().startActivity(intent);  
  559.                                 }  
  560.                             }  
  561.                               
  562.                         });  
  563.                         mActivity.get().course_table_layout.addView(courseInfo);  
  564.                         mActivity.get().courseTextViewList.add(courseInfo);  
  565.                         upperCourse = null;  
  566.                     }  
  567.                 } while(list.size() < lastListSize && list.size() != 0);  
  568.             }  
  569.             super.handleMessage(msg);  
  570.         }  
  571.           
  572.     }  
  573.     /** 
  574.      * 显示周数下拉列表悬浮窗 
  575.      * @param parent 
  576.      */  
  577.     private void showWeekListWindow(View parent){  
  578.           
  579.         if(weekListWindow == null)  
  580.         {  
  581.             LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);  
  582.             //获取layout  
  583.             popupWindowLayout = layoutInflater.inflate(R.layout.week_list_layout, null);  
  584.             weekListView = (ListView) popupWindowLayout.findViewById(R.id.week_list_view_body);  
  585.             //禁用滚动条(貌似没用··)  
  586.             weekListView.setVerticalScrollBarEnabled(false);  
  587.             List<Map<String, Object>> weekList = new ArrayList<Map<String, Object>>();  
  588.             //默认25周  
  589.             for(int i = 1; i <= 25; i ++)  
  590.             {  
  591.                 Map<String, Object> rowData = new HashMap<String, Object>();  
  592.                 rowData.put("week_index""第" + i + "周");  
  593.                 weekList.add(rowData);  
  594.             }  
  595.               
  596.             //设置listview的adpter  
  597.             SimpleAdapter listAdapter = new SimpleAdapter(this,   
  598.                     weekList, R.layout.week_list_item_layout,   
  599.                     new String[]{"week_index"},   
  600.                     new int[]{R.id.week_list_item});  
  601.             weekListView.setAdapter(listAdapter);  
  602.             weekListView.setOnItemClickListener(new OnItemClickListener() {  
  603.                 @Override  
  604.                 public void onItemClick(AdapterView<?> adpater, View arg1,  
  605.                         int arg2, long arg3) {  
  606.                     int index = 0;  
  607.                     String indexStr = textTitle.getText().toString();  
  608.                     indexStr = indexStr.replaceAll("第""").replaceAll("周""");  
  609.                     if(!indexStr.equals("全部"))  
  610.                         index = Integer.parseInt(indexStr);  
  611.                     textTitle.setText("第" + (arg2 + 1) + "周");  
  612.                     weekListWindow.dismiss();  
  613.                     if((arg2 + 1) != index)  
  614.                     {  
  615.                         Log.i("courseTableActivity""清空当前课程信息");  
  616.                         for(TextView tx : courseTextViewList)  
  617.                         {  
  618.                             course_table_layout.removeView(tx);  
  619.                         }  
  620.                         courseTextViewList.clear();  
  621.                         //重新设置课程信息  
  622.                         Message msg = new Message();  
  623.                         InitMessageObj msgObj = new InitMessageObj(aveWidth, arg2 + 1, screenWidth, maxCourseNum);  
  624.                         msg.obj = msgObj;  
  625.                         courseInfoInitMessageHandler.sendMessage(msg);  
  626.                     }  
  627.                 }  
  628.             });  
  629.             int width = textTitle.getWidth();  
  630.             //实例化一个popupwindow  
  631.             weekListWindow = new PopupWindow(popupWindowLayout, width + 100, width + 120);  
  632.   
  633.         }  
  634.           
  635.         weekListWindow.setFocusable(true);  
  636.         //设置点击外部可消失  
  637.         weekListWindow.setOutsideTouchable(true);  
  638.         weekListWindow.setBackgroundDrawable(new BitmapDrawable());  
  639.         //消失的时候恢复按钮的背景(消除"按下去"的样式)  
  640.         weekListWindow.setOnDismissListener(new OnDismissListener() {  
  641.             @Override  
  642.             public void onDismiss() {  
  643.                 textTitle.setBackgroundDrawable(null);  
  644.             }  
  645.         });  
  646.         weekListWindow.showAsDropDown(parent, -500);  
  647.     }  
  648.   
  649. }  

2、CourseInfo

[java]  view plain  copy
  1. package nd.leiyi.crims.model;  
  2.   
  3. import java.io.Serializable;  
  4.   
  5.   
  6. public class CourseInfo implements Serializable{  
  7.   
  8.     /** 
  9.      *  
  10.      */  
  11.     private static final long serialVersionUID = 2074656067805712769L;  
  12.     /** id */  
  13.     private int id;  
  14.     /** 课程名称  */  
  15.     private String courseName;  
  16.     /** 上课教室 */  
  17.     private String classRoom;  
  18.     /** 老师  */  
  19.     private String teacher;  
  20.     /** 上课时间(哪一天)(周一--周日) */  
  21.     private int day;  
  22.     /** 上课时间(哪一节)开始(1--12) */  
  23.     private int beginIndex;  
  24.     /** 上课时间(哪一节)节数(1--12) */  
  25.     private int endIndex;  
  26.     /** 上课时间(哪一周) 开始 */  
  27.     private int beginWeek;  
  28.     /** 上课时间(哪一周) 结束 */  
  29.     private int endWeek;  
  30.     /** 课程类型(单周还是双周) **/  
  31.     private int courseType;  
  32.       
  33.     public static final int ALL = 1;  
  34.     public static final int ODD = 2;  
  35.     public static final int EVEN = 3;  
  36.       
  37.     public String getCourseName() {  
  38.         return courseName;  
  39.     }  
  40.     public void setCourseName(String courseName) {  
  41.         this.courseName = courseName;  
  42.     }  
  43.     public String getClassRoom() {  
  44.         return classRoom;  
  45.     }  
  46.     public void setClassRoom(String classRoom) {  
  47.         this.classRoom = classRoom;  
  48.     }  
  49.     public String getTeacher() {  
  50.         return teacher;  
  51.     }  
  52.     public void setTeacher(String teacher) {  
  53.         this.teacher = teacher;  
  54.     }  
  55.     public int getDay() {  
  56.         return day;  
  57.     }  
  58.     public void setDay(int day) {  
  59.         this.day = day;  
  60.     }  
  61.     public int getBeginIndex() {  
  62.         return beginIndex;  
  63.     }  
  64.     public void setBeginIndex(int beginIndex) {  
  65.         this.beginIndex = beginIndex;  
  66.     }  
  67.     public int getEndIndex() {  
  68.         return endIndex;  
  69.     }  
  70.     public void setEndIndex(int endIndex) {  
  71.         this.endIndex = endIndex;  
  72.     }  
  73.     public int getBeginWeek() {  
  74.         return beginWeek;  
  75.     }  
  76.     public void setBeginWeek(int beginWeek) {  
  77.         this.beginWeek = beginWeek;  
  78.     }  
  79.     public int getEndWeek() {  
  80.         return endWeek;  
  81.     }  
  82.     public void setEndWeek(int endWeek) {  
  83.         this.endWeek = endWeek;  
  84.     }  
  85.     public int getId() {  
  86.         return id;  
  87.     }  
  88.     public void setId(int id) {  
  89.         this.id = id;  
  90.     }  
  91.     public int getCourseType() {  
  92.         return courseType;  
  93.     }  
  94.     public void setCourseType(int courseType) {  
  95.         this.courseType = courseType;  
  96.     }  
  97.       
  98.       
  99. }  

3、CourseInfoGallery

[java]  view plain  copy
  1. package nd.leiyi.crims.gallery3D;  
  2.   
  3. import android.content.Context;  
  4. import android.graphics.Camera;  
  5. import android.graphics.Matrix;  
  6. import android.util.AttributeSet;  
  7. import android.view.MotionEvent;  
  8. import android.view.View;  
  9. import android.view.animation.Transformation;  
  10. import android.widget.Gallery;  
  11.   
  12. public class CourseInfoGallery extends Gallery {  
  13.   
  14.      private Camera mCamera = new Camera();  
  15.         private int mMaxRotationAngle = 60;  
  16.         private int mMaxZoom = -60;  
  17.         private int mCoveflowCenter;  
  18.   
  19.         public CourseInfoGallery(Context context) {  
  20.                 super(context);  
  21.                 this.setStaticTransformationsEnabled(true);  
  22.         }  
  23.   
  24.         public CourseInfoGallery(Context context, AttributeSet attrs) {  
  25.                 super(context, attrs);  
  26.                 this.setStaticTransformationsEnabled(true);  
  27.         }  
  28.   
  29.         public CourseInfoGallery(Context context, AttributeSet attrs, int defStyle) {  
  30.                 super(context, attrs, defStyle);  
  31.                 this.setStaticTransformationsEnabled(true);  
  32.         }  
  33.   
  34.         public int getMaxRotationAngle() {  
  35.                 return mMaxRotationAngle;  
  36.         }  
  37.   
  38.         public void setMaxRotationAngle(int maxRotationAngle) {  
  39.                 mMaxRotationAngle = maxRotationAngle;  
  40.         }  
  41.   
  42.         public int getMaxZoom() {  
  43.                 return mMaxZoom;  
  44.         }  
  45.   
  46.         public void setMaxZoom(int maxZoom) {  
  47.                 mMaxZoom = maxZoom;  
  48.         }  
  49.   
  50.         private int getCenterOfCoverflow() {  
  51.                 return (getWidth() - getPaddingLeft() - getPaddingRight()) / 2  
  52.                                 + getPaddingLeft();  
  53.         }  
  54.   
  55.         private static int getCenterOfView(View view) {  
  56.                 return view.getLeft() + view.getWidth() / 2;  
  57.         }  
  58.   
  59.         protected boolean getChildStaticTransformation(View child, Transformation t) {  
  60.   
  61.                 final int childCenter = getCenterOfView(child);  
  62.                 final int childWidth = child.getWidth();  
  63.                 int rotationAngle = 0;  
  64.   
  65.                 t.clear();  
  66.                 t.setTransformationType(Transformation.TYPE_MATRIX);  
  67.   
  68.                 if (childCenter == mCoveflowCenter) {  
  69.                         transformImageBitmap(child, t, 0);  
  70.                 } else {  
  71.                         rotationAngle = (int) (((float) (mCoveflowCenter - childCenter) / childWidth) * mMaxRotationAngle);  
  72.                         if (Math.abs(rotationAngle) > mMaxRotationAngle) {  
  73.                                 rotationAngle = (rotationAngle < 0) ? -mMaxRotationAngle  
  74.                                                 : mMaxRotationAngle;  
  75.                         }  
  76.                         transformImageBitmap(child, t, rotationAngle);  
  77.                 }  
  78.   
  79.                 return true;  
  80.         }  
  81.   
  82.         protected void onSizeChanged(int w, int h, int oldw, int oldh) {  
  83.                 mCoveflowCenter = getCenterOfCoverflow();  
  84.                 super.onSizeChanged(w, h, oldw, oldh);  
  85.         }  
  86.   
  87.         private void transformImageBitmap(View child, Transformation t,  
  88.                         int rotationAngle) {  
  89.                 mCamera.save();  
  90.                 final Matrix imageMatrix = t.getMatrix();  
  91.                 final int imageHeight = child.getLayoutParams().height;  
  92.                 final int imageWidth = child.getLayoutParams().width;  
  93.                 final int rotation = Math.abs(rotationAngle);  
  94.   
  95.                 mCamera.translate(0.0f, 0.0f, 100.0f);  
  96.   
  97.                 // As the angle of the view gets less, zoom in  
  98.                 if (rotation < mMaxRotationAngle) {  
  99.                         float zoomAmount = (float) (mMaxZoom + (rotation * 1.5));  
  100.                         mCamera.translate(0.0f, 0.0f, zoomAmount);  
  101.                 }  
  102.   
  103.                 mCamera.rotateY(rotationAngle);  
  104.                 mCamera.getMatrix(imageMatrix);  
  105.                 imageMatrix.preTranslate(-(imageWidth / 2), -(imageHeight / 2));  
  106.                 imageMatrix.postTranslate((imageWidth / 2), (imageHeight / 2));  
  107.                 mCamera.restore();  
  108.         }  
  109.   
  110.         @Override  
  111.         public boolean onInterceptTouchEvent(MotionEvent ev) {  
  112.               
  113.             if (ev.getAction() == MotionEvent.ACTION_MOVE) {  
  114.                 return true;  
  115.             } else {  
  116.                 return false;  
  117.             }  
  118.         }  
  119.           
  120.           
  121.           
  122. }  

4、CourseInfoAdapter

[java]  view plain  copy
  1. package nd.leiyi.crims.adapter;  
  2.   
  3. import java.util.List;  
  4.   
  5. import nd.leiyi.crims.R;  
  6. import nd.leiyi.crims.gallery3D.CourseInfoGallery;  
  7. import nd.leiyi.crims.model.CourseInfo;  
  8. import android.content.Context;  
  9. import android.graphics.Color;  
  10. import android.view.Gravity;  
  11. import android.view.View;  
  12. import android.view.ViewGroup;  
  13. import android.widget.BaseAdapter;  
  14. import android.widget.TextView;  
  15.   
  16. public class CourseInfoAdapter extends BaseAdapter {  
  17.   
  18.     private Context context;  
  19.     private TextView[] courseTextViewList;  
  20.     private int screenWidth;  
  21.     private int currentWeek;  
  22.     public CourseInfoAdapter(Context context, List<CourseInfo> courseList, int width, int currentWeek) {  
  23.         super();  
  24.         this.screenWidth = width;  
  25.         this.context = context;  
  26.         this.currentWeek = currentWeek;  
  27.         createGalleryWithCourseList(courseList);  
  28.     }  
  29.   
  30.     private void createGalleryWithCourseList(List<CourseInfo> courseList){  
  31.         //五种颜色的背景  
  32.         int[] background = {R.drawable.course_info_blue, R.drawable.course_info_green,   
  33.                             R.drawable.course_info_red, R.drawable.course_info_red,  
  34.                             R.drawable.course_info_yellow};  
  35.         this.courseTextViewList = new TextView[courseList.size()];  
  36.         for(int i = 0; i < courseList.size(); i ++)  
  37.         {  
  38.             final CourseInfo course = courseList.get(i);  
  39.             TextView textView = new TextView(context);  
  40.             textView.setText(course.getCourseName() + "@" + course.getClassRoom());  
  41.             textView.setLayoutParams(new CourseInfoGallery.LayoutParams((screenWidth / 6) *3, (screenWidth / 6) *3));  
  42.             textView.setTextColor(Color.WHITE);  
  43.             textView.setGravity(Gravity.CENTER_VERTICAL);  
  44.             textView.setPadding(10000);  
  45.             if(course.getBeginWeek() <= currentWeek && course.getEndWeek() >= currentWeek &&  
  46.               (course.getCourseType() == CourseInfo.ALL ||  
  47.               (course.getCourseType() == CourseInfo.EVEN && currentWeek % 2 == 0) ||  
  48.               (course.getCourseType() == CourseInfo.ODD && currentWeek % 2 != 0)))  
  49.             {  
  50.                 //选择一个颜色背景  
  51.                 int colorIndex = ((course.getBeginIndex() - 1) * 8 + course.getDay()) % (background.length - 1);  
  52.                 textView.setBackgroundResource(background[colorIndex]);  
  53.             }  
  54.             else  
  55.             {  
  56.                 textView.setBackgroundResource(R.drawable.course_info_light_grey);  
  57.             }  
  58.             textView.getBackground().setAlpha(222);  
  59. //          textView.setOnClickListener(new OnClickListener() {  
  60. //              @Override  
  61. //              public void onClick(View arg0) {  
  62. //                  // TODO Auto-generated method stub  
  63. //                  Intent intent = new Intent();  
  64. //                  Bundle mBundle = new Bundle();  
  65. //                  mBundle.putSerializable("courseInfo", course);  
  66. //                  intent.putExtras(mBundle);  
  67. //                  intent.setClass(context, DetailCourseInfoActivity.class);  
  68. //                  context.startActivity(intent);  
  69. //              }  
  70. //          });  
  71.             this.courseTextViewList[i] = textView;  
  72.         }  
  73.     }  
  74.     @Override  
  75.     public int getCount() {  
  76.           
  77.         return courseTextViewList.length;  
  78.     }  
  79.   
  80.     @Override  
  81.     public Object getItem(int index) {  
  82.           
  83.         return courseTextViewList[index];  
  84.     }  
  85.   
  86.     @Override  
  87.     public long getItemId(int arg0) {  
  88.           
  89.         return arg0;  
  90.     }  
  91.   
  92.     @Override  
  93.     public View getView(int position, View convertView, ViewGroup parent) {  
  94.   
  95.         return courseTextViewList[position];  
  96.     }  
  97.   
  98.     public float getScale(boolean focused, int offset) {  
  99.         return Math.max(01.0f / (float) Math.pow(2, Math.abs(offset)));  
  100.     }  
  101.   
  102.   
  103.       
  104. }  
5、gallery-3d布局

[html]  view plain  copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     android:orientation="vertical" >  
  6.       
  7.     <nd.leiyi.crims.gallery3D.CourseInfoGallery   
  8.         android:id="@+id/course_info_gallery"  
  9.         android:layout_width="fill_parent"  
  10.         android:layout_height="wrap_content"  
  11.         android:layout_centerInParent="true"  
  12.         />  
  13.   
  14. </LinearLayout>  

6、gallery-3d-item

[html]  view plain  copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     android:orientation="vertical" >  
  6.       
  7.     <TextView   
  8.         android:id="@+id/course_info_gallery_item"  
  9.         android:layout_width="wrap_content"  
  10.         android:layout_height="wrap_content"  
  11.         android:textColor="#ffffff"  
  12.         android:gravity="center_vertical"/>  
  13.   
  14. </LinearLayout>  

7、course_text_view_bg (课程格子背景)

[html]  view plain  copy
  1. <?xml version="1.0" encoding="UTF-8"?>    
  2. <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >    
  3.   <item>    
  4.         <shape>    
  5.             <solid android:color="#FFFFFF" />    
  6.             <stroke    
  7.                 android:width="1dp"    
  8.                 android:color="#a8abad" />    
  9.         </shape>    
  10.     </item>   
  11.      <item    
  12.         android:right="1dp"    
  13.         android:bottom="1dp">    
  14.         <shape>    
  15.             <solid android:color="#FFFFFF" />    
  16.             <stroke    
  17.                 android:width="1dp"    
  18.                 android:color="#ffffff" />    
  19.         </shape>    
  20.     </item>   
  21. </layer-list>  

8、course_table_last_colum(最后一列的背景,无边框)

[html]  view plain  copy
  1. <?xml version="1.0" encoding="UTF-8"?>    
  2. <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >    
  3.   <item>    
  4.         <shape>    
  5.             <solid android:color="#FFFFFF" />    
  6.             <stroke    
  7.                 android:width="1dp"    
  8.                 android:color="#a8abad" />    
  9.         </shape>    
  10.     </item>   
  11.      <item    
  12.         android:bottom="1dp">    
  13.         <shape>    
  14.             <solid android:color="#FFFFFF" />    
  15.             <stroke    
  16.                 android:width="1dp"    
  17.                 android:color="#ffffff" />    
  18.         </shape>    
  19.     </item>   
  20. </layer-list>  


还有一些布局文件就不贴了。代码太多了··,有兴趣的同学可以在github里下载我的工程···工程比较大,而且后台服务端程序我已经从云服务器上撤销了,所以跑不起来,我也不愿改代码了··

gitbub上的代码已删除

demo版:超级课程表demo


  • 3
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值