Пример #1
0
  public void setViewImage(ImageView v, String value) {

    try {
      v.setImageResource(Integer.parseInt(value));
    } catch (NumberFormatException nfe) {
      v.setImageURI(Uri.parse(value));
    }
  }
Пример #2
0
  @Override
  public void onBindViewHolder(RecycleViewHolder holder, int position) {

    if (mClientDataTable.isEmpty()) return;

    mClientDataTable.moveToPosition(position);

    if ((position >= getItemCount() - 1)) onLoadMore();

    int lListHolderSize = holder.mSparseArrayHolderViews.size();

    for (int i = 0; i < lListHolderSize; i++) {

      int lColumnIndex = holder.mSparseArrayHolderViews.keyAt(i);
      View lWidget = holder.mSparseArrayHolderViews.get(lColumnIndex);

      if (lWidget != null) {

        final TCell data = mClientDataTable.getCell(position, lColumnIndex);
        if (lWidget instanceof Checkable) {
          ((Checkable) lWidget).setChecked(data.asBoolean());
        } else if (lWidget instanceof TextView) {
          ((TextView) lWidget).setText(data.asString());
        } else if (lWidget instanceof UiPicassoImageView) {
          if (data.getValueType() == TCell.ValueType.BASE64) {
            try {
              throw new WrongTypeException(mContext, R.string.exception_canotUserBase64);
            } catch (WrongTypeException e) {
              e.printStackTrace();
            }
          } else {
            UiPicassoImageView picassoImageView = (UiPicassoImageView) lWidget;
            picassoImageView.setData(data.asString(), mIsNotUsePicassoCache);
          }
        } else if (lWidget instanceof ImageView) {
          ImageView im = (ImageView) lWidget;
          if (data.getValueType() == TCell.ValueType.INTEGER && !data.asString().isEmpty()) {
            im.setImageResource(data.asInteger());
          } else if (data.getValueType() == TCell.ValueType.BASE64) {
            byte[] decodedString = Base64.decode(data.asString(), Base64.NO_WRAP);
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inSampleSize = mBase64OptionSize;
            Bitmap decodedByte =
                BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length, options);
            im.setImageBitmap(decodedByte);
          } else {
            if (!data.asString().equals("")) setViewImage((ImageView) lWidget, data.asString());
            else im.setImageDrawable(null);
          }
        } else if (lWidget instanceof Spinner) {
          Spinner spinner = ((Spinner) lWidget);
          if (spinner.getAdapter() instanceof ArrayAdapter) {
            ArrayAdapter arrayAdapter = (ArrayAdapter) spinner.getAdapter();
            spinner.setSelection(arrayAdapter.getPosition(data.asString()));
          } else
            Log.e(
                this.getClass().getName(),
                "Cannot set Spinner default value, because Spinner Adapter is not ArrayAdapter Type, you need to customize it in onIterateWidget method");
        }

        onIteratedRow(holder.mRowView, lWidget, lWidget.getTag().toString());
      }
    }
    int lListHolderSizeNotInCDT = holder.mSparseArrayHolderViewsNotInCDT.size();

    for (int i = 0; i < lListHolderSizeNotInCDT; i++) {
      int lColumnIndex = holder.mSparseArrayHolderViewsNotInCDT.keyAt(i);
      View lWidget = holder.mSparseArrayHolderViewsNotInCDT.get(lColumnIndex);

      if (lWidget != null) {
        onIteratedRow(holder.mRowView, lWidget, lWidget.getTag().toString());
      }
    }

    // ClickListener
    holder.setClickListener(
        new OnRecycleClickListener() {
          @Override
          public void onClick(View v, int position) {
            onClickRow(v, position);
          }

          @Override
          public void onLongClick(View v, int position) {
            onLongClickRow(v, position);
          }
        });

    holder.setOnRecycleWidgetClickListener(
        new OnRecycleWidgetClickListener() {

          @Override
          public void onClick(View parentView, View clickedView, String tag, int position) {
            onClickWidget(parentView, clickedView, tag, position);
          }
        });

    holder.setOnRecycleCheckedRadioButtonGroupChangeListener(
        new OnRecycleCheckedRadioButtonGroupChangeListener() {
          @Override
          public void onCheckedChanged(
              View parentView,
              RadioGroup radioButtonGroup,
              String widgetTag,
              int radioButtonID,
              int position) {
            onCheckRadioButtonGroupWidget(
                parentView, radioButtonGroup, widgetTag, radioButtonID, position);
          }
        });

    holder.setOnRecycleCheckedChangeListener(
        new OnRecycleCheckedChangeListener() {
          @Override
          public void onCheckedChanged(
              boolean isWidgetInCDT, CompoundButton buttonView, boolean isChecked, int position) {

            if (!isWidgetInCDT || position >= mClientDataTable.getRowsCount()) return;

            String columnName = buttonView.getTag().toString();
            mClientDataTable.moveToPosition(position);
            mClientDataTable.cellByName(columnName).setValue(isChecked);
          }
        });

    holder.setOnRecycleTextWatcher(
        new OnRecycleTextWatcher() {
          @Override
          public void afterTextChanged(
              boolean isWidgetInCDT, EditText v, String newText, int position) {
            if (!isWidgetInCDT
                || position >= mClientDataTable.getRowsCount()
                || !(v.isFocusable() || v.isFocusableInTouchMode())) return;

            mClientDataTable.moveToPosition(position);
            String columnName = v.getTag().toString();
            mClientDataTable.cellByName(columnName).setValue(newText);
          }
        });
  }