@Override
  public View getView(final int position, View convertView, ViewGroup parent) {
    Holder holder = null;
    if (convertView == null) {
      holder = new Holder();
      convertView = inflater.inflate(R.layout.good_report_item, null);
      holder.handImg = (ImageView) convertView.findViewById(R.id.iv_goodbg_hand);

      holder.title = (TextView) convertView.findViewById(R.id.tv_goodbg_title);
      holder.aName = (TextView) convertView.findViewById(R.id.tv_goodbg__aname);
      holder.price = (TextView) convertView.findViewById(R.id.tv_goodbg_price);
      holder.body = (TextView) convertView.findViewById(R.id.tv_goodbg_text);
      holder.download = (ImageButton) convertView.findViewById(R.id.ib_bg_download);
      convertView.setTag(holder);
    } else {
      holder = (Holder) convertView.getTag();
    }
    final Report report = data.get(position);
    holder.handImg.setTag(report.getPpath());
    // holder.handImg.setImageResource(Integer.parseInt(data.get(position).get("hand").toString()));
    holder.title.setText(report.getName());
    holder.aName.setText(report.getAuthor());
    holder.price.setText(report.getPrice());
    holder.body.setText(report.getIntro());
    ImageResourse imageResource = new ImageResourse();
    imageResource.setIconUrl(data.get(position).getPpath() + "/big.png");
    imageResource.setIconId(report.getId());
    imageResource.setIconTime(report.getProtime());
    asyncImageLoader.loadDrawable(
        imageResource,
        new ImageCallback() {

          @Override
          public void imageLoaded(Drawable imageDrawable, String imageUrl) {
            ImageView img = (ImageView) goodList.findViewWithTag(report.getPpath());
            if (img != null && imageDrawable != null) {
              // img.setLayoutParams(new Gallery.LayoutParams(360, 160));
              img.setScaleType(ImageView.ScaleType.FIT_CENTER);
              img.setImageDrawable(imageDrawable);
            }
          }
        });
    holder.download.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {}
        });
    return convertView;
  }
Exemplo n.º 2
0
  /** 初始化主业务的gridview控件 */
  private void installMainGridView() {
    asyncImageLoader = ((CeiApplication) (this.getApplication())).asyncImageLoader;
    // 获取一级业务的数据
    columnEntry = ((CeiApplication) getApplication()).columnEntry;
    columnEntries = new ArrayList<ColumnEntry>();
    List<ColumnEntry> firstColumnEntries = columnEntry.getEntryChildsForParent(null);
    this.columnEntry.getWitSeaColumns().clear();
    for (int i = 0; i < firstColumnEntries.size(); i++) {
      boolean isModels = false;
      ColumnEntry columnEntry = firstColumnEntries.get(i);
      for (int j = 0; j < MODELS.length; j++) {
        if ((MODELS[j]).equals(columnEntry.getName())) {
          isModels = true;
          columnEntries.add(columnEntry);
        }
      }
      if (!isModels && !columnEntry.getName().equals("关于我们")) {
        System.out.println(columnEntry.getName() + " : " + columnEntry.getOperationImage());
        this.columnEntry.getWitSeaColumns().add(columnEntry);
      }
    }
    columnEntries.addAll(columnEntry.getSelectColumnEntryChilds());
    GridView gridView = (GridView) findViewById(R.id.main_service_gridview);
    GridViewAdapter gaAdapter =
        new GridViewAdapter(this, R.layout.main_griview_item, columnEntries, gridView);
    gridView.setAdapter(gaAdapter);
    gridView.setOnItemClickListener(this);
    home_page_re = (RelativeLayout) findViewById(R.id.welcome);
    home_page_re.setBackgroundResource(R.drawable.welcome_background);
    ImageResourse imageResource = new ImageResourse();
    imageResource.setIconUrl(columnEntry.getBackground());
    imageResource.setIconId(columnEntry.getBackground());
    asyncImageLoader.loadDrawable(
        imageResource,
        new AsyncImageLoader.ImageCallback() {

          @Override
          public void imageLoaded(Drawable drawable, String path) {
            home_page_re.setBackgroundDrawable(drawable);
          }
        });
  }
  public View getView(final int position, View convertView, ViewGroup parent) {
    ViewHolder holder = null;
    holder = new ViewHolder();
    convertView = inflater.inflate(itemLayout, null);
    holder.courseIcon = (ImageView) convertView.findViewById(R.id.phone_study_listviewitem_icon);
    holder.coursePlayBtn =
        (ImageView) convertView.findViewById(R.id.phone_study_listviewitem_playbtn);
    holder.downloadBtn =
        (ImageView) convertView.findViewById(R.id.phone_study_listviewitem_downbtn);
    holder.controCourse = (ImageView) convertView.findViewById(R.id.phone_study_controllcourse);
    holder.sayBtn = (ImageView) convertView.findViewById(R.id.phone_study_listviewitem_say);
    holder.uploadStudyBtn =
        (ImageView) convertView.findViewById(R.id.phone_study_listviewitem_upload);
    holder.tv1 = (TextView) convertView.findViewById(R.id.phone_study_listviewitem_title);
    holder.tv2 = (TextView) convertView.findViewById(R.id.phone_study_listviewitem_teachername);
    holder.tv3 = (TextView) convertView.findViewById(R.id.phone_study_listviewitem_protime);
    holder.studystatus = (TextView) convertView.findViewById(R.id.phone_study_listviewitem_status);
    convertView.setTag(holder);
    if (holder.uploadStudyBtn != null) {
      if (coursewares.get(position).getUploadTime() != 0
          && !"1".equals(coursewares.get(position).getIscompleted()))
        holder.uploadStudyBtn.setImageResource(R.drawable.phone_study_uploadcourse_btn);
      else holder.uploadStudyBtn.setImageResource(R.drawable.phone_study_uploadcourse_btn_hover);
    }
    holder.tv1.setText(coursewares.get(position).getName());
    if (coursewares.get(position).getClassLevel() != null)
      holder.tv2.setText("讲师姓名 : " + coursewares.get(position).getTeacherName());
    else holder.tv2.setText("讲师姓名 : " + coursewares.get(position).getTeacherName());
    holder.tv3.setText("发布时间 : " + coursewares.get(position).getProTime());
    holder.courseIcon.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            Intent intent = new Intent(activity, CourseDetailActivity.class);
            intent.putExtra("coursewareInfo", coursewares.get(position));
            intent.putExtra("isRecord", isRecord);
            activity.startActivity(intent);
          }
        });
    if (holder.sayBtn != null) {
      holder.sayBtn.setOnClickListener(
          new OnClickListener() {

            @Override
            public void onClick(View v) {
              Intent intent = new Intent(activity, SayGroupActivity.class);
              intent.putExtra("coursewareinfo", coursewares.get(position));
              activity.startActivity(intent);
            }
          });
    }
    if (holder.uploadStudyBtn != null) {
      try {
        if ("1".equals(coursewares.get(position).getIscompleted()))
          holder.studystatus.setText("状态:已学完");
      } catch (Exception e) {
        e.printStackTrace();
      }
      coursewares.get(position).setFree(true);
      holder.uploadStudyBtn.setOnClickListener(
          new OnClickListener() {

            @Override
            public void onClick(View v) {
              // 上传学习记录,并同步数据库的信息,更新列表
              final Handler handler = new Handler();
              if (coursewares.get(position).getUploadTime() != 0
                  && !"1".equals(coursewares.get(position).getIscompleted())) {
                new Thread(
                        new Runnable() {
                          @Override
                          public void run() {
                            if (!XmlUtil.parseReturnCode(
                                    Service.saveUserClassTime(
                                        ((CeiApplication) (activity.getApplication()))
                                            .columnEntry.getUserId(),
                                        coursewares.get(position).getClassId(),
                                        coursewares.get(position).getUploadTime() + ""))
                                .equals("-1")) {
                              handler.post(
                                  new Runnable() {

                                    @Override
                                    public void run() {
                                      coursewares.get(position).setUploadTime(0);
                                      ((CeiApplication) (activity.getApplication()))
                                          .dataHelper.updatePlayRecord(coursewares.get(position));
                                      coursewares.add(0, coursewares.remove(position));
                                      ((FoundationActivity) activity)
                                          .courses.add(
                                              0,
                                              ((FoundationActivity) activity)
                                                  .courses.remove(position));
                                      ((FoundationActivity) activity)
                                          .allCoursewares.add(
                                              0,
                                              ((FoundationActivity) activity)
                                                  .allCoursewares.remove(position));
                                      PhoneStudyAdapter.this.notifyDataSetChanged();
                                      AlertDialog.Builder builder = new Builder(activity);
                                      builder.setMessage("上传学习记录成功 !");
                                      builder.setPositiveButton(
                                          "确认",
                                          new DialogInterface.OnClickListener() {

                                            @Override
                                            public void onClick(DialogInterface dialog, int which) {
                                              dialog.dismiss();
                                            }
                                          });

                                      builder.create().show();
                                    }
                                  });
                            }
                          }
                        })
                    .start();
              }
            }
          });
    }

    if (holder.coursePlayBtn != null) {
      holder.coursePlayBtn.setOnClickListener(
          new OnClickListener() {

            // 没有购买的
            private static final int NO_BUY = 0;
            // 已经购买的
            private static final int AL_BUY = 1;

            /** 检查是否有买了这个课件 */
            private void checkBuy() {
              if (coursewares.get(position).isFree()) {
                Message message = handler.obtainMessage();
                message.arg1 = AL_BUY;
                handler.sendMessage(message);
              } else {
                new Thread(
                        new Runnable() {

                          @Override
                          public void run() {
                            String result =
                                Service.queryBuyClass(
                                    columnEntry.getUserId(),
                                    coursewares.get(position).getClassId());
                            List<Courseware> coursewares = new ArrayList<Courseware>();
                            XmlUtil.parseCoursewares(result, coursewares);
                            Message message = handler.obtainMessage();
                            if (coursewares.size() > 0) {
                              message.arg1 = AL_BUY;
                            } else {
                              message.arg1 = NO_BUY;
                            }
                            handler.sendMessage(message);
                          }
                        })
                    .start();
              }
            }

            // 提示是否有权限
            private Handler handler =
                new Handler() {
                  @Override
                  public void dispatchMessage(Message msg) {
                    switch (msg.arg1) {
                      case NO_BUY:
                        if (((CeiApplication) activity.getApplication()).isNet())
                          MyTools.exitShow(
                              activity, activity.getWindow().getDecorView(), "未购买该课件!");
                        else
                          MyTools.exitShow(activity, activity.getWindow().getDecorView(), "请联网查看!");
                        break;
                      case AL_BUY:
                        Intent intent = new Intent(activity, WebViewUtil.class);
                        intent.putExtra("isRecord", isRecord);
                        intent.putExtra(
                            "path",
                            coursewares
                                .get(position)
                                .getLookPath()
                                .replace("/i2/", "/an2/")
                                .replace("an1", "an2"));
                        intent.putExtra("class", coursewares.get(position));
                        activity.startActivity(intent);
                        break;
                    }
                  }
                };

            @Override
            public void onClick(View v) {
              checkBuy();
            }
          });
    }
    if (holder.downloadBtn != null) {
      holder.downloadBtn.setOnClickListener(
          new OnClickListener() {

            // 没有购买的
            private static final int NO_BUY = 0;
            // 已经购买的
            private static final int AL_BUY = 1;

            /** 检查是否有买了这个课件 */
            private void checkBuy() {
              if (coursewares.get(position).isFree()) {
                Message message = handler.obtainMessage();
                message.arg1 = AL_BUY;
                handler.sendMessage(message);
              } else {
                new Thread(
                        new Runnable() {

                          @Override
                          public void run() {
                            String result =
                                Service.queryBuyClass(
                                    columnEntry.getUserId(),
                                    coursewares.get(position).getClassId());
                            List<Courseware> coursewares = new ArrayList<Courseware>();
                            XmlUtil.parseCoursewares(result, coursewares);
                            Message message = handler.obtainMessage();
                            if (coursewares.size() > 0) {
                              message.arg1 = AL_BUY;
                            } else {
                              message.arg1 = NO_BUY;
                            }
                            handler.sendMessage(message);
                          }
                        })
                    .start();
              }
            }

            // 提示是否有权限
            private Handler handler =
                new Handler() {
                  @Override
                  public void dispatchMessage(Message msg) {
                    switch (msg.arg1) {
                      case NO_BUY:
                        if (((CeiApplication) activity.getApplication()).isNet())
                          MyTools.exitShow(
                              activity, activity.getWindow().getDecorView(), "未购买该课件!");
                        else
                          MyTools.exitShow(activity, activity.getWindow().getDecorView(), "请联网查看!");
                        break;
                      case AL_BUY:
                        downloadThisCourse(coursewares.get(position));
                        break;
                    }
                  }
                };

            @Override
            public void onClick(View arg0) {
              checkBuy();
            }
          });
    }
    if (holder.controCourse != null) {
      if (!coursewares.get(position).isSelfCourse()) {
        holder.controCourse.setImageResource(R.drawable.phone_study_addcourse_btn);
        holder.controCourse.setOnClickListener(
            new OnClickListener() {

              @Override
              public void onClick(View v) {
                alertIsSurePop(
                    new OnClickListener() {

                      @Override
                      public void onClick(View v) {
                        new Thread(
                                new Runnable() {

                                  @Override
                                  public void run() {
                                    String rs =
                                        Service.saveCourse(
                                            coursewares.get(position).getClassId(),
                                            columnEntry.getUserId());
                                    if (XmlUtil.parseReturnCode(rs).length() > 5) {
                                      Message message = handler.obtainMessage();
                                      message.arg1 = ADD_SUCCESS;
                                      message.arg2 = position;
                                      handler.sendMessage(message);
                                    } else {
                                      Message message = handler.obtainMessage();
                                      message.arg1 = NO_NET;
                                      handler.sendMessage(message);
                                    }
                                  }
                                })
                            .start();
                      }
                    },
                    true);
              }
            });
      } else {
        holder.controCourse.setImageResource(R.drawable.phone_study_canclecourse_btn);
        holder.controCourse.setOnClickListener(
            new OnClickListener() {

              @Override
              public void onClick(View v) {
                alertIsSurePop(
                    new OnClickListener() {

                      @Override
                      public void onClick(View v) {
                        new Thread(
                                new Runnable() {

                                  @Override
                                  public void run() {
                                    String rs =
                                        Service.cancelCourse(
                                            coursewares.get(position).getClassId(),
                                            columnEntry.getUserId());
                                    if (XmlUtil.parseReturnCode(rs).equals("1")) {
                                      Message message = handler.obtainMessage();
                                      message.arg1 = CANCEL_SUCCESS;
                                      message.arg2 = position;
                                      handler.sendMessage(message);
                                    } else {
                                      Message message = handler.obtainMessage();
                                      message.arg1 = NO_NET;
                                      handler.sendMessage(message);
                                    }
                                  }
                                })
                            .start();
                      }
                    },
                    true);
              }
            });
      }
    }
    if (coursewares.size() != 0) {
      String imageUrl = coursewares.get(position).getSmallPath();
      holder.courseIcon.setTag(imageUrl);
      if (drawables.containsKey(coursewares.get(position).getClassId())
          && drawables.get(coursewares.get(position).getClassId()) != null) {
        holder.courseIcon.setImageDrawable(drawables.get(coursewares.get(position).getClassId()));
      } else {
        ImageResourse imageResource = new ImageResourse();
        imageResource.setIconUrl(imageUrl);
        imageResource.setIconId(coursewares.get(position).getClassId());
        asyncImageLoader.loadDrawable(
            imageResource,
            new AsyncImageLoader.ImageCallback() {

              @Override
              public void imageLoaded(Drawable drawable, String path) {
                ImageView imageView = (ImageView) lv.findViewWithTag(path);
                if (drawable != null && imageView != null) {
                  imageView.setImageDrawable(drawable);
                  try {
                    drawables.put(coursewares.get(position).getClassId(), drawable);
                  } catch (Exception e) {
                    e.printStackTrace();
                  }
                }
              }
            });
      }
    }

    return convertView;
  }
  public View getView(final int position, View convertView, ViewGroup parent) {
    final ProgressBar bar;
    final TextView tv;
    Holder holder = null;
    if (convertView == null) {
      holder = new Holder();
      convertView = inflater.inflate(R.layout.yjbg_book_shelf_item, null);
      holder.handImg = (ImageView) convertView.findViewById(R.id.yjbg_book_shelf_hand_img);

      holder.title = (TextView) convertView.findViewById(R.id.yjbg_book_shelf_title);
      holder.aName = (TextView) convertView.findViewById(R.id.yjbg_book_shelf_aname);
      holder.price = (TextView) convertView.findViewById(R.id.yjbg_book_shelf_price);
      holder.body = (TextView) convertView.findViewById(R.id.yjbg_book_shelf_text);
      convertView.setTag(holder);
    } else {
      holder = (Holder) convertView.getTag();
    }
    final Report report = data.get(position);
    holder.handImg.setTag(report.getPpath());
    holder.handImg.setImageResource(R.drawable.report1);
    holder.title.setText(report.getName());
    holder.aName.setText(report.getAuthor());
    holder.price.setText(report.getPrice());
    if (report.getIntro().length() > 100) {
      holder.body.setText(report.getIntro().replace("\n", "").subSequence(0, 100) + "...");
    } else {
      holder.body.setText(report.getIntro().replace("\n", ""));
    }

    ImageResourse imageResource = new ImageResourse();
    imageResource.setIconUrl(data.get(position).getSmallPpath().replace("/big.png", ""));
    imageResource.setIconId(data.get(position).getId());
    imageResource.setIconTime(data.get(position).getProtime());
    if (drawables.containsKey(report.getSmallPpath().replace("/big.png", ""))
        && drawables.get(report.getSmallPpath().replace("/big.png", "")) != null) {
      holder.handImg.setImageDrawable(
          drawables.get(report.getSmallPpath().replace("/big.png", "")));
      Log.i("view", position + "起作用了");
    } else {
      asyncImageLoader.loadDrawable(
          imageResource,
          new ImageCallback() {

            @Override
            public void imageLoaded(Drawable imageDrawable, String imageUrl) {
              ImageView img = (ImageView) listView.findViewWithTag(report.getPpath());
              if (img != null && imageDrawable != null) {
                // img.setLayoutParams(new Gallery.LayoutParams(360, 160));
                drawables.put(report.getSmallPpath().replace("/big.png", ""), imageDrawable);
                img.setScaleType(ImageView.ScaleType.FIT_CENTER);
                img.setImageDrawable(imageDrawable);
              }
            }
          });
    }
    tv = (TextView) convertView.findViewById(R.id.yjbg_book_list_item_tv);
    bar = (ProgressBar) convertView.findViewById(R.id.yjbg_book_list_item_pro);
    /*if (!report.getIsLoad().equals("yes")) {
    	tv.setVisibility(View.VISIBLE);
    	bar.setVisibility(View.VISIBLE);
    	Handler handler = new Handler() {

    		@Override
    		public void handleMessage(Message msg) {
    			bar.setProgress(msg.arg1);
    			tv.setText(msg.arg1 + "%");
    			if (msg.arg1 == 100) {
    				tv.setText("100%");
    				report.setIsLoad("yes");
    				dataHelper.UpdateReportZT(report);
    			}
    		}

    	};

    	String path = report.getDownpath().toString();
    	File savedir = new File(Report.SD_PATH+ report.getName());
    	// Environment.getExternalStorageDirectory().getAbsolutePath() + "/cei/bg/"
    	if (!savedir.exists()) {
    		savedir.mkdirs();
    	}

    	try {
    		NewFileDownload.download(path, savedir, handler);
    	} catch (Exception e) {
    		e.printStackTrace();
    	}
    }*/
    if (report.getIsLoad().equals("yes")) {
      tv.setText("100%");
    }
    return convertView;
  }