@Override
  protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    this.width = w;
    this.height = h;
    itemWidth = Math.min(itemWidth, width);
    int number = height / itemHeight;
    if ((number & 1) == 1) {
      this.numberPerPage = number;
    } else {
      this.numberPerPage = number - 1;
    }
    this.topBottomPadding = (height - numberPerPage * itemHeight) / 2;
    this.leftRightPadding = (width - itemWidth) / 2;
    this.originalSelectedIndex = 0;
    this.selectedIndex = 0;

    itemList = new ArrayList<ItemView>();
    for (int i = -numberPerPage / 2; i < stringList.size() + numberPerPage / 2; i++) {
      ItemView itemView = new ItemView(getContext());
      itemView.setIndex(i);
      itemView.setyOffset((i + numberPerPage / 2) * itemHeight);
      LogUtil.i("chenxu", "onSizeChanged:i:" + i + " yoffset:" + itemView.getyOffset());
      if (i >= 0 && i < stringList.size()) {
        itemView.setText(stringList.get(i));
      } else {
        itemView.setText("");
      }
      itemList.add(itemView);
    }
  }
 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
   ItemView view;
   if (convertView == null) {
     view = new ItemView(mContext);
   } else {
     view = (ItemView) convertView;
   }
   view.setData(items.get(position));
   return view;
 }
 @Override
 protected void onDraw(Canvas canvas) {
   super.onDraw(canvas);
   LogUtil.i("chenxu", "---------------------------------");
   for (int i = 0; i < itemList.size(); i++) {
     ItemView itemView = itemList.get(i);
     LogUtil.i("chenxu", "onDraw:i:" + i + " yoffset:" + itemView.getyOffset());
     // if (isInView(itemView.getIndex())) {
     itemView.drawSelf(canvas);
     // }
   }
   LogUtil.i("chenxu", "---------------------------------");
 }
 public void moveByOffset(float offset, float accumulatedOffset) {
   for (int i = 0; i < itemList.size(); i++) {
     ItemView itemView = itemList.get(i);
     itemView.setyOffset((int) (itemView.getyOffset() + offset));
     ;
   }
   selectedIndex =
       (int)
           Math.min(
               stringList.size(),
               Math.max(
                   0,
                   (originalSelectedIndex - (accumulatedOffset + itemHeight / 2) / itemHeight)));
   LogUtil.i("chenxu", "moveByOffset-selectedIndex:" + selectedIndex);
   invalidate();
 }
示例#5
0
  /*
   *@param  pCriteria            List of SearchCriteria objects
   *@return  a set of ItemView objects
   *@exception  RemoteException
   */
  public ItemViewVector searchStoreItems(List pCriteria, boolean pDistInfoFl)
      throws RemoteException {
    Connection con = null;
    try {
      con = getReportConnection();

      Integer storeIdI = new Integer(0);
      String categCond = "";
      String shortDescCond = "";
      String manufCond = "";
      String manufSkuCond = "";
      String distSkuCond = "";

      String storeFilter = "";
      /////////////////////
      // Create a set of filters
      for (Iterator iter = pCriteria.iterator(); iter.hasNext(); ) {
        SearchCriteria sc = (SearchCriteria) iter.next();
        String name = sc.getName();
        Object objValue = sc.getObjectValue();
        String strValue = (objValue instanceof String) ? ((String) objValue).trim() : "";
        if (SearchCriteria.STORE_ID.equals(name)) {
          storeIdI = (Integer) objValue;
          storeFilter =
              "select STORE_DIM_ID from DW_STORE_DIM \n"
                  + "  where STORE_ID = "
                  + storeIdI
                  + "  \n";

        } else if (SearchCriteria.CATALOG_CATEGORY.equals(name)) {
          String subStr = " like '%" + strValue.toUpperCase().replaceAll("'", "''") + "%' \n";
          categCond =
              "    and (UPPER(JD_CATEGORY1) "
                  + subStr
                  + " or  \n"
                  + "         UPPER(JD_CATEGORY2) "
                  + subStr
                  + " or  \n"
                  + "         UPPER(JD_CATEGORY3) "
                  + subStr
                  + ") \n";
        } else if (SearchCriteria.PRODUCT_SHORT_DESC.equals(name)) {
          shortDescCond =
              " and UPPER(JD_ITEM_DESC) like '%"
                  + strValue.toUpperCase().replaceAll("'", "''")
                  + "%' \n";
        } else if (SearchCriteria.MANUFACTURER_SHORT_DESC.equals(name)) {
          manufCond =
              " and UPPER(JD_MANUF_NAME) like '%"
                  + strValue.toUpperCase().replaceAll("'", "''")
                  + "%' \n";
        } else if (SearchCriteria.MANUFACTURER_SKU_NUMBER.equals(name)) {
          manufSkuCond =
              " and UPPER(JD_MANUF_SKU) like '%"
                  + strValue.toUpperCase().replaceAll("'", "''")
                  + "%' \n";
        } else if (SearchCriteria.DISTRIBUTOR_SKU_NUMBER.equals(name)) {
          distSkuCond =
              " and UPPER(JD_DIST_SKU) like '%"
                  + strValue.toUpperCase().replaceAll("'", "''")
                  + "%' \n";
        }
      }

      // Get catalog id --------------------------------------------------------//
      /*       int catalogId = 0;
             String sql = "select distinct STORE_CATALOG_ID from DW_CATEGORY_DIM \n" +
                          " where STORE_DIM_ID IN (" + storeFilter  + ")";
             log(
             "DWOperationBean ---------------------------> sql1: " + sql);

             Statement stmt = con.createStatement();
             ResultSet rs = stmt.executeQuery(sql);
             int count = 0;
             while (rs.next()) {
               count++;
               catalogId = rs.getInt(1);
             }
             rs.close();
             stmt.close();
             if (count == 0) {
               String errorMess = "No catalog for store. Store id: " + storeIdI;
               throw new Exception(errorMess);
             }
             if (count > 1) {
               String errorMess = "Multiple active catalogs for store. Store id: " +
                                  storeIdI;
               throw new Exception(errorMess);
             }
      */
      // ---------------------------------------------------------------------//
      String sql =
          "select                \n"
              + " id.ITEM_DIM_ID,      \n"
              + " JD_ITEM_DESC  ,      \n"
              + " JD_ITEM_PACK ,       \n"
              + " JD_ITEM_UOM ,        \n"
              + " JD_MANUF_SKU,        \n"
              + " JD_MANUF_NAME,        \n"
              + " JD_CATEGORY1         \n";

      String fromSql =
          " from DW_ITEM_DIM id,                               \n "
              + "      DW_CATEGORY_DIM cd,                           \n"
              + "      DW_MANUFACTURER_DIM md                        \n";
      String whereSql =
          " where id.CATEGORY_DIM_ID = cd.CATEGORY_DIM_ID     \n"
              +
              //          "    and cd.STORE_CATALOG_ID = " + catalogId + "    \n" +
              "    and cd.STORE_DIM_ID IN ("
              + storeFilter
              + ")  \n"
              + "    and md.MANUFACTURER_DIM_ID  = id.MANUFACTURER_DIM_ID   \n";

      // ---------------------------------------------------------------------//

      if (pDistInfoFl) {
        sql +=
            " , JD_DIST_SKU,                                       \n"
                + " (select JD_DIST_NAME from DW_DISTRIBUTOR_DIM dd      \n"
                + "   where DISTRIBUTOR_DIM_ID  = did.DISTRIBUTOR_DIM_ID \n"
                + " ) JD_DIST_NAME                                       \n";

        fromSql += "    ,DW_ITEM_DISTRIBUTOR did  \n";
        whereSql += "    and id.ITEM_DIM_ID   = did.ITEM_DIM_ID (+)         \n" + distSkuCond;
      }
      sql += fromSql + whereSql;
      sql += categCond + shortDescCond + manufCond + manufSkuCond;
      sql += " order by JD_MANUF_SKU ";

      Statement stmt = con.createStatement();
      ResultSet rs = stmt.executeQuery(sql);
      ItemViewVector itemVwV = new ItemViewVector();
      while (rs.next()) {
        ItemView itemVw = ItemView.createValue();
        itemVwV.add(itemVw);
        itemVw.setStoreId(storeIdI.intValue());
        //         itemVw.setCatalogId(catalogId);

        itemVw.setItemId(rs.getInt("ITEM_DIM_ID"));
        itemVw.setName(Utility.strNN(rs.getString("JD_ITEM_DESC")));
        itemVw.setSku(Utility.strNN(rs.getString("JD_MANUF_SKU")));
        itemVw.setUom(Utility.strNN(rs.getString("JD_ITEM_UOM")));
        itemVw.setPack(Utility.strNN(rs.getString("JD_ITEM_PACK")));
        itemVw.setCategory(Utility.strNN(rs.getString("JD_CATEGORY1")));
        itemVw.setManufName(Utility.strNN(rs.getString("JD_MANUF_NAME")));
        itemVw.setManufSku(Utility.strNN(rs.getString("JD_MANUF_SKU")));
        if (pDistInfoFl) {
          itemVw.setDistId(0);
          itemVw.setDistName(Utility.strNN(rs.getString("JD_DIST_NAME")));
          itemVw.setDistSku(Utility.strNN(rs.getString("JD_DIST_SKU")));
        } else {
          itemVw.setDistId(0);
          itemVw.setDistName("");
          itemVw.setDistSku("");
        }
        itemVw.setSelected(false);
      }
      rs.close();
      stmt.close();
      return itemVwV;
    } catch (Exception e) {
      e.printStackTrace();
      throw new RemoteException(e.getMessage());
    } finally {
      closeConnection(con);
    }
  }