Ejemplo n.º 1
0
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

      ViewHolder holder = null;
      if (convertView == null) {
        convertView = _inflater.inflate(R.layout.layout_search_app_item, null);

        holder = new ViewHolder();
        holder.imageView = (ImageView) convertView.findViewById(R.id.imageViewIcon);
        holder.textViewTitle = (TextView) convertView.findViewById(R.id.textViewTitle);
        holder.textViewInfo = (TextView) convertView.findViewById(R.id.textViewInfo);
        convertView.setTag(holder);

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

      AppInfo appInfo = _appList.get(position);

      holder.keyId = appInfo.id;

      holder.textViewTitle.setText(appInfo.name);
      String s =
          String.format("版本:%s  大小:%s", appInfo.version, MyUtils.GetSizeString(appInfo.size));
      holder.textViewInfo.setText(s);

      holder.imageView.setImageResource(R.drawable.app_loading);

      Map<String, Object> params = new HashMap<String, Object>();
      params.put("appinfo", appInfo);
      params.put("view", convertView);
      params.put("roundcorner", 15);

      _imgDownloader.downloadImage(
          _context,
          appInfo.icon,
          new OnDownloadTaskListener() {

            @Override
            public void onDownloadSuccessfully(DownloadTask downloadTask) {
              // TODO Auto-generated method stub
              AppInfo appInfo = (AppInfo) downloadTask.params.get("appinfo");
              View view = (View) downloadTask.params.get("view");
              ViewHolder holder = (ViewHolder) view.getTag();
              if (appInfo.id == holder.keyId) {
                holder.imageView.setImageBitmap(downloadTask.getBitmap());
              }
            }

            @Override
            public void onDownloadFailed(int errCode, DownloadTask downloadTask) {
              // TODO Auto-generated method stub

            }
          },
          params);

      //			Bitmap bmp = ImageUtils.loadBitmapFromResource(_context, R.drawable.ad1);
      //			if( bmp != null )
      //			{
      //				bmp = ImageUtils.getRoundedCornerBitmap(bmp, 30);
      //				holder.imageView.setImageBitmap(bmp);
      //			}

      return convertView;
    }
Ejemplo n.º 2
0
  private void buildKeyboard() {
    RelativeLayout keyboard = (RelativeLayout) this.findViewById(R.id.keyboard);

    int baseId = CHAR_ID_BASE;

    int idx = 0;
    int line = 0;
    int lineStartIndex = 0;
    int total = _charString.length();
    for (int i = 0; i < total; i++) {
      int id = baseId + i;

      TextView tv = new TextView(this);
      tv.setGravity(Gravity.CENTER);
      tv.setId(id);
      tv.setText(_charString.substring(i, i + 1));
      tv.setTextSize(
          TypedValue.COMPLEX_UNIT_SP,
          this.getResources().getDimension(R.dimen.search_char_text_size));
      tv.setTextColor(Color.WHITE);
      tv.setHighlightColor(Color.BLACK);
      tv.setBackgroundResource(R.drawable.btn_search_char_selector);
      tv.setFocusable(true);

      tv.setOnClickListener(_charOnClickListener);

      int w =
          MyUtils.dip2px(this, this.getResources().getDimension(R.dimen.search_char_view_width));
      int h =
          MyUtils.dip2px(this, this.getResources().getDimension(R.dimen.search_char_view_height));

      RelativeLayout.LayoutParams rllp = new RelativeLayout.LayoutParams(w, h);

      if (idx > 0) {
        rllp.addRule(RelativeLayout.RIGHT_OF, id - 1);
        rllp.leftMargin =
            MyUtils.dip2px(this, this.getResources().getDimension(R.dimen.search_char_view_space));
        rllp.addRule(RelativeLayout.ALIGN_TOP, id - 1);
      } else if (line > 0) {
        rllp.addRule(RelativeLayout.BELOW, id - 6);
        rllp.addRule(RelativeLayout.ALIGN_LEFT, id - 6);
        rllp.topMargin =
            MyUtils.dip2px(this, this.getResources().getDimension(R.dimen.search_char_view_space));
      }

      keyboard.addView(tv, rllp);

      idx++;

      if (idx >= 6) {
        idx = 0;
        line++;
        if (i < total - 1) lineStartIndex = id + 1;
      }
    }

    TextView tv = new TextView(this);
    tv.setGravity(Gravity.CENTER);
    tv.setId(CHAR_ID_SPACE);
    tv.setText("空格");
    tv.setTextSize(
        TypedValue.COMPLEX_UNIT_SP,
        this.getResources().getDimension(R.dimen.search_char_text_size));
    tv.setTextColor(Color.WHITE);
    tv.setHighlightColor(Color.BLACK);
    tv.setBackgroundResource(R.drawable.btn_search_char_selector);
    tv.setFocusable(true);
    tv.setOnClickListener(_charOnClickListener);

    int w = MyUtils.dip2px(this, this.getResources().getDimension(R.dimen.search_char_view_width));
    int h = MyUtils.dip2px(this, this.getResources().getDimension(R.dimen.search_char_view_height));

    RelativeLayout.LayoutParams rllp = new RelativeLayout.LayoutParams(w * 2, h);
    rllp.addRule(RelativeLayout.BELOW, lineStartIndex);
    rllp.addRule(RelativeLayout.ALIGN_LEFT, lineStartIndex);
    rllp.addRule(RelativeLayout.ALIGN_RIGHT, lineStartIndex + 1);
    rllp.topMargin =
        MyUtils.dip2px(this, this.getResources().getDimension(R.dimen.search_char_view_space));
    keyboard.addView(tv, rllp);

    tv = new TextView(this);
    tv.setGravity(Gravity.CENTER);
    tv.setId(CHAR_ID_CLEAR);
    tv.setText("清空");
    tv.setTextSize(
        TypedValue.COMPLEX_UNIT_SP,
        this.getResources().getDimension(R.dimen.search_char_text_size));
    tv.setTextColor(Color.WHITE);
    tv.setHighlightColor(Color.BLACK);
    tv.setBackgroundResource(R.drawable.btn_search_char_selector);
    tv.setFocusable(true);
    tv.setOnClickListener(_charOnClickListener);

    w = MyUtils.dip2px(this, this.getResources().getDimension(R.dimen.search_char_view_width));
    h = MyUtils.dip2px(this, this.getResources().getDimension(R.dimen.search_char_view_height));

    rllp = new RelativeLayout.LayoutParams(w * 2, h);
    rllp.addRule(RelativeLayout.BELOW, lineStartIndex);
    rllp.addRule(RelativeLayout.ALIGN_LEFT, lineStartIndex + 2);
    rllp.addRule(RelativeLayout.ALIGN_RIGHT, lineStartIndex + 3);
    rllp.addRule(RelativeLayout.ALIGN_TOP, CHAR_ID_SPACE);
    keyboard.addView(tv, rllp);

    tv = new TextView(this);
    tv.setGravity(Gravity.CENTER);
    tv.setId(CHAR_ID_BACKSPACE);
    tv.setText("退格");
    tv.setTextSize(
        TypedValue.COMPLEX_UNIT_SP,
        this.getResources().getDimension(R.dimen.search_char_text_size));
    tv.setTextColor(Color.WHITE);
    tv.setHighlightColor(Color.BLACK);
    tv.setBackgroundResource(R.drawable.btn_search_char_selector);
    tv.setFocusable(true);
    tv.setOnClickListener(_charOnClickListener);

    w = MyUtils.dip2px(this, this.getResources().getDimension(R.dimen.search_char_view_width));
    h = MyUtils.dip2px(this, this.getResources().getDimension(R.dimen.search_char_view_height));

    rllp = new RelativeLayout.LayoutParams(w * 2, h);
    rllp.addRule(RelativeLayout.BELOW, lineStartIndex);
    rllp.addRule(RelativeLayout.ALIGN_LEFT, lineStartIndex + 4);
    rllp.addRule(RelativeLayout.ALIGN_RIGHT, lineStartIndex + 5);
    rllp.addRule(RelativeLayout.ALIGN_TOP, CHAR_ID_SPACE);
    keyboard.addView(tv, rllp);
  }