private void changeSelectedType(View selectedView) {
    for (int i = 0; i < mContainerType.getChildCount(); i++) {
      View child = mContainerType.getChildAt(i);
      if (child != selectedView) {
        child.setBackgroundResource(R.drawable.back);
      } else {
        child.setBackgroundResource(R.drawable.back2);
      }
    }

    mCurrentSelectedType = (String) selectedView.getTag();
    final String allString = mActivity.getString(R.string.discipline_all);

    mDisplayElements.clear();
    if (mCurrentSelectedType.equals(allString)) {
      mDisplayElements.addAll(mDateElements);
    } else {
      for (Element dateElement : mDateElements) {
        Element meritElement = XmlUtil.selectElement(dateElement, "Merit");
        Element demeritElement = XmlUtil.selectElement(dateElement, "Demerit");

        int value = 0;
        if (mCurrentSelectedType.equals(MERIT_A) && meritElement != null) {
          value = StringUtil.convertToInt(meritElement.getAttribute("A"));
        } else if (mCurrentSelectedType.equals(MERIT_B) && meritElement != null) {
          value = StringUtil.convertToInt(meritElement.getAttribute("B"));
        } else if (mCurrentSelectedType.equals(MERIT_C) && meritElement != null) {
          value = StringUtil.convertToInt(meritElement.getAttribute("C"));
        } else if (mCurrentSelectedType.equals(DEMERIT_A) && demeritElement != null) {
          value = StringUtil.convertToInt(demeritElement.getAttribute("A"));
        } else if (mCurrentSelectedType.equals(DEMERIT_B) && demeritElement != null) {
          value = StringUtil.convertToInt(demeritElement.getAttribute("B"));
        } else if (mCurrentSelectedType.equals(DEMERIT_C) && demeritElement != null) {
          value = StringUtil.convertToInt(demeritElement.getAttribute("C"));
        }

        if (value != 0) {
          mDisplayElements.add(dateElement);
        }
      }
    }

    mAdapter.notifyDataSetChanged();
  }
Ejemplo n.º 2
0
  private void parseResult(DSResponse resp) {
    List<StudentInfo> reqs = new ArrayList<StudentInfo>();

    if (resp != null) {
      Element elmRoot = resp.getBody();
      // Log.d("DEBUG", XmlHelper.convertToString(elmRoot));

      List<Element> elms = XmlUtil.selectElements(elmRoot, "Student");
      for (Element elm : elms) {
        reqs.add(new StudentInfo(elm));
      }
    }

    if (mListener != null) mListener.onSuccess(reqs);
  }
Ejemplo n.º 3
0
  public static DSUserInfo load(Element source) {
    DSUserInfo user = new DSUserInfo();
    user.applicationName = source.getAttribute("Application");
    user.contractName = source.getAttribute("Contract");
    user.serverName = source.getAttribute("Server");
    user.userName = source.getAttribute("UserName");
    user.timeout = Converter.toInteger(source.getAttribute("Timeout"), -1);
    user.extendable = Converter.toBoolean(source.getAttribute("Extendable"), true);

    Date d = Converter.toDate(source.getAttribute("Expired"));
    user.expired.setTime(d);

    for (Element r : XmlUtil.selectElements(source, "Role")) {
      user.roles.add(r.getAttribute("Name"));
    }

    for (Element p : XmlUtil.selectElements(source, "Property")) {
      String pname = p.getAttribute("Name");
      String pvalue = p.getTextContent();
      user.properties.setProperty(pname, pvalue);
    }

    return user;
  }
  // 解析XML資料
  private void bindStudentList(Element content) {

    mListStudent.clear();
    map.clear();
    int studSize = 0;
    for (Element item : XmlUtil.selectElements(content)) {
      studSize += 1;
      InfoObject into = new InfoObject();
      into.ClassName = XmlUtil.getElementText(item, "ClassName");

      if (!map.contains(into.ClassName)) {
        into.IsExtends = false;
        mListStudent.add(into);
        map.add(into.ClassName);
      }

      StudentObject stud = new StudentObject();
      stud.IsExtends = true;
      stud.ClassName = XmlUtil.getElementText(item, "ClassName");
      stud.StudentNumber = XmlUtil.getElementText(item, "StudentNumber");
      stud.StudentName = XmlUtil.getElementText(item, "StudentName");
      stud.Gender = XmlUtil.getElementText(item, "Gender");
      stud.StudentId = XmlUtil.getElementText(item, "RefStudentId");
      mListStudent.add(stud);
    }

    Collections.sort(
        mListStudent,
        new Comparator<InfoObject>() {
          @Override
          public int compare(InfoObject lhs, InfoObject rhs) {
            return lhs.ClassName.compareTo(rhs.ClassName);
          }
        });

    TextView txtStudentCount = (TextView) getActivity().findViewById(R.id.course_countStudent);
    txtStudentCount.setText("學生人數:" + studSize);
    startDisplay();
  }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      ViewHolder holder;
      if (convertView == null) {
        holder = new ViewHolder();
        convertView = _inflater.inflate(R.layout.item_discipline, null);
        holder.txtDate = (TextView) convertView.findViewById(R.id.txtDate);
        holder.txtDetail = (TextView) convertView.findViewById(R.id.txtDetail);
        holder.txtCountA = (TextView) convertView.findViewById(R.id.txtCountA);
        holder.txtCountB = (TextView) convertView.findViewById(R.id.txtCountB);
        holder.txtCountC = (TextView) convertView.findViewById(R.id.txtCountC);
        holder.txtNameA = (TextView) convertView.findViewById(R.id.txtNameA);
        holder.txtNameB = (TextView) convertView.findViewById(R.id.txtNameB);
        holder.txtNameC = (TextView) convertView.findViewById(R.id.txtNameC);
        holder.layoutClearInfo = (LinearLayout) convertView.findViewById(R.id.layoutClearInfo);
        holder.txtClearDate = (TextView) convertView.findViewById(R.id.txtClearDate);
        holder.txtClearReason = (TextView) convertView.findViewById(R.id.txtClearReason);

        convertView.setTag(holder);
      } else {
        holder = (ViewHolder) convertView.getTag();
      }

      Element dayElement = mDisplayElements.get(position);
      holder.txtDate.setText(dayElement.getAttribute("OccurDate"));
      holder.txtDetail.setText(XmlUtil.getElementText(dayElement, "Reason"));

      int flag = StringUtil.convertToInt(dayElement.getAttribute("MeritFlag"));

      Element meritElement;
      if (flag == 1) {
        meritElement = XmlUtil.selectElement(dayElement, "Merit");
        holder.txtNameA.setText(MERIT_A);
        holder.txtNameB.setText(MERIT_B);
        holder.txtNameC.setText(MERIT_C);
        holder.txtCountA.setBackgroundResource(R.drawable.merit_a);
        holder.txtCountB.setBackgroundResource(R.drawable.merit_b);
        holder.txtCountC.setBackgroundResource(R.drawable.merit_c);
      } else {
        meritElement = XmlUtil.selectElement(dayElement, "Demerit");
        holder.txtNameA.setText(DEMERIT_A);
        holder.txtNameB.setText(DEMERIT_B);
        holder.txtNameC.setText(DEMERIT_C);
        holder.txtCountA.setBackgroundResource(R.drawable.demerit_a);
        holder.txtCountB.setBackgroundResource(R.drawable.demerit_b);
        holder.txtCountC.setBackgroundResource(R.drawable.demerit_c);

        String cleared = meritElement.getAttribute("Cleared");
        String clearReason = meritElement.getAttribute("ClearReason");
        String clearDate = meritElement.getAttribute("ClearDate");

        if (!StringUtil.isNullOrWhitespace(cleared)) {
          holder.layoutClearInfo.setVisibility(View.VISIBLE);

          holder.txtClearDate.setText(clearDate);
          holder.txtClearReason.setText("銷過原因 : " + clearReason);
        }
      }

      holder.txtCountA.setText(meritElement.getAttribute("A"));
      holder.txtCountB.setText(meritElement.getAttribute("B"));
      holder.txtCountC.setText(meritElement.getAttribute("C"));
      return convertView;
    }
  private void bindAbsense() {
    // mContainerType.removeAllViews();
    // if (mAllAbsenceElements == null || mAllAbsenceElements.size() == 0)
    // return;

    HashMap<String, Integer> absMap = new HashMap<String, Integer>();

    // absMap.put(MERIT_ALL, 0);
    absMap.put(MERIT_A, 0);
    absMap.put(MERIT_B, 0);
    absMap.put(MERIT_C, 0);
    absMap.put(DEMERIT_A, 0);
    absMap.put(DEMERIT_B, 0);
    absMap.put(DEMERIT_C, 0);

    for (Element e : mDisplayElements) {

      String flag = e.getAttribute("MeritFlag");

      // flag = 1 = 獎勵
      if (flag.equals("1")) {
        Element meritElement = XmlUtil.selectElement(e, "Merit");
        int a = StringUtil.convertToInt(meritElement.getAttribute("A"));
        if (a != 0) {
          int value = absMap.get(MERIT_A);
          absMap.put(MERIT_A, value + a);
        }

        a = StringUtil.convertToInt(meritElement.getAttribute("B"));
        if (a != 0) {
          int value = absMap.get(MERIT_B);
          absMap.put(MERIT_B, value + a);
        }

        a = StringUtil.convertToInt(meritElement.getAttribute("C"));
        if (a != 0) {
          int value = absMap.get(MERIT_C);
          absMap.put(MERIT_C, value + a);
        }
      } else { // flag = 0 = 懲
        Element meritElement = XmlUtil.selectElement(e, "Demerit");
        int a = StringUtil.convertToInt(meritElement.getAttribute("A"));
        if (a != 0) {
          int value = absMap.get(DEMERIT_A);
          absMap.put(DEMERIT_A, value + a);
        }

        a = StringUtil.convertToInt(meritElement.getAttribute("B"));
        if (a != 0) {
          int value = absMap.get(DEMERIT_B);
          absMap.put(DEMERIT_B, value + a);
        }

        a = StringUtil.convertToInt(meritElement.getAttribute("C"));
        if (a != 0) {
          int value = absMap.get(DEMERIT_C);
          absMap.put(DEMERIT_C, value + a);
        }
      }
    }

    int total = 0;
    for (String key : absMap.keySet()) {
      total += absMap.get(key);
    }

    mTxtCountAll.setText(String.valueOf(total));
    mContainerAll.setTag(MERIT_ALL);
    mContainerAll.setOnClickListener(mTypeClickListener);

    mTxtCountMeritA.setText(String.valueOf(absMap.get(MERIT_A)));
    mContainerMeritA.setTag(MERIT_A);
    mContainerMeritA.setOnClickListener(mTypeClickListener);

    mTxtCountMeritB.setText(String.valueOf(absMap.get(MERIT_B)));
    mContainerMeritB.setTag(MERIT_B);
    mContainerMeritB.setOnClickListener(mTypeClickListener);

    mTxtCountMeritC.setText(String.valueOf(absMap.get(MERIT_C)));
    mContainerMeritC.setTag(MERIT_C);
    mContainerMeritC.setOnClickListener(mTypeClickListener);

    mTxtCountDemeritA.setText(String.valueOf(absMap.get(DEMERIT_A)));
    mContainerDemeritA.setTag(DEMERIT_A);
    mContainerDemeritA.setOnClickListener(mTypeClickListener);

    mTxtCountDemeritB.setText(String.valueOf(absMap.get(DEMERIT_B)));
    mContainerDemeritB.setTag(DEMERIT_B);
    mContainerDemeritB.setOnClickListener(mTypeClickListener);

    mTxtCountDemeritC.setText(String.valueOf(absMap.get(DEMERIT_C)));
    mContainerDemeritC.setTag(DEMERIT_C);
    mContainerDemeritC.setOnClickListener(mTypeClickListener);

    changeSelectedType(mContainerAll);
    // int dp5 = mActivityHelper.getScreen().toPixelInt(5);
    //
    // LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
    // LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    //
    // List<String> keys = new ArrayList<String>(absMap.keySet());
    // Collections.sort(keys, new Comparator<String>() {
    //
    // @Override
    // public int compare(String lhs, String rhs) {
    // if (lhs.equals(MERIT_ALL))
    // return -1;
    // if (rhs.equals(MERIT_ALL))
    // return 1;
    // return lhs.compareTo(rhs);
    // }
    // });
    //
    // for (String type : keys) {
    // TextView textView = new TextView(mActivity);
    // textView.setGravity(Gravity.CENTER);
    // textView.setMinimumWidth(mActivityHelper.getScreen()
    // .toPixelInt(100));
    // textView.setBackgroundResource(R.drawable.back);
    // textView.setPadding(dp5 * 2, dp5, dp5 * 2, dp5);
    //
    // int count = absMap.get(type);
    // String display = "%s ( %d )";
    // display = String.format(display, type, count);
    // textView.setText(display);
    // textView.setTag(type);
    //
    // textView.setOnClickListener(new OnClickListener() {
    //
    // @Override
    // public void onClick(View v) {
    // changeSelectedType(v);
    // }
    // });
    //
    // mContainerType.addView(textView, params);
    //
    // if (type.equals(MERIT_ALL)) {
    // changeSelectedType(textView);
    // }
    // }
  }