Exemplo n.º 1
0
 /*
  * @see android.widget.Checkable#toggle()
  */
 public void toggle() {
   this.isChecked = !this.isChecked;
   for (Checkable c : checkableViews) {
     c.toggle();
   }
   refreshDrawableState();
 }
  @Test
  public void testHandlingWithConvention() {
    assertThat(activity.conventionButtonEventHandled).isFalse();

    Checkable button = (Checkable) activity.findViewById(R.id.conventionButton);
    button.setChecked(true);

    assertThat(activity.conventionButtonEventHandled).isTrue();
  }
  @Test
  public void testCheckedStatePassedToAnnotatedMethod() {
    assertThat(activity.checked).isFalse();

    Checkable button = (Checkable) activity.findViewById(R.id.conventionButton);
    button.setChecked(true);

    assertThat(activity.checked).isTrue();
  }
Exemplo n.º 4
0
  /*
   * @see android.widget.Checkable#setChecked(boolean)
   */
  public void setChecked(boolean isChecked) {
    //		Log.i(TAG,"setChecked: "+isChecked);

    for (Checkable c : checkableViews) {
      c.setChecked(isChecked);
      //			Log.d(TAG,"view at position "+ checkableViews.indexOf(c) + " is checked?" + isChecked);
    }
    //		Log.e(TAG, "set checked, we have " + checkableViews.size() + " checkable children");
    this.isChecked = isChecked;
    refreshDrawableState();
  }
  @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
  @Override
  protected void onBindView(View view) {
    super.onBindView(view);

    View checkableView = view.findViewById(R.id.switchWidget);
    if (checkableView != null && checkableView instanceof Checkable) {
      ((Checkable) checkableView).setChecked(mChecked);
      if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        if (checkableView instanceof Switch) {
          final Switch switchView = (Switch) checkableView;
          switchView.setTextOn(mSwitchOn);
          switchView.setTextOff(mSwitchOff);
          switchView.setOnCheckedChangeListener(mListener);
        }
      } else {
        if (checkableView instanceof android.widget.Switch) {
          final android.widget.Switch switchView = (android.widget.Switch) checkableView;
          switchView.setTextOn(mSwitchOn);
          switchView.setTextOff(mSwitchOff);
          switchView.setOnCheckedChangeListener(mListener);
        }
      }
    }

    syncSummaryView(view);
  }
Exemplo n.º 6
0
  /** 更新当前CheckedView池 */
  protected void updateCurrentCheckedViews(View view, boolean isChecked) {

    // 非选中状态 若checkedView池含有 就移除该View
    if (!isChecked) {
      if (mCheckedViews.contains(view)) {
        mCheckedViews.remove(view);
      }
      return;
    }

    // 选中状态 根据ChoiceMode 作出相应的处理
    switch (mChoiceMode) {
      case SingleChoice:
        if (mCheckedViews.size() > 0 && !mCheckedViews.contains(view)) {
          View lastCheckedView = mCheckedViews.get(0);
          if (lastCheckedView instanceof Checkable) {
            ((Checkable) lastCheckedView).setChecked(false);
          }
        }

        mCheckedViews.clear();
        mCheckedViews.add(view);

        break;
      case MultieChoice:
        mCheckedViews.add(view);

        break;
      default:
        break;
    }
  }
    private void bindView(int position, View view) {
      final Map<String, ?> dataSet = map.get(position);
      if (dataSet == null) {
        return;
      }

      final ViewBinder binder = super.getViewBinder();
      final int count = to.length;

      for (int i = 0; i < count; i++) {
        final View v = view.findViewById(to[i]);
        if (v != null) {
          final Object data = dataSet.get(from[i]);
          String text = data == null ? "" : data.toString();
          if (text == null) {
            text = "";
          }

          boolean bound = false;
          if (binder != null) {
            bound = binder.setViewValue(v, data, text);
          }

          if (!bound) {
            if (v instanceof Checkable) {
              if (data instanceof Boolean) {
                ((Checkable) v).setChecked((Boolean) data);
              } else if (v instanceof TextView) {
                //  Note: keep the instanceof TextView check at the bottom of these
                //  ifs since a lot of views are TextViews (e.g. CheckBoxes).
                setViewText((TextView) v, text);
              } else {
                throw new IllegalStateException(
                    v.getClass().getName()
                        + " should be bound to a Boolean, not a "
                        + (data == null ? "<unknown type>" : data.getClass()));
              }
            } else if (v instanceof TextView) {
              // Note: keep the instanceof TextView check at the bottom of these
              // ifs since a lot of views are TextViews (e.g. CheckBoxes).
              setViewText((TextView) v, text);
            } else if (v instanceof ImageView) {
              if (data instanceof Integer) {
                setViewImage((ImageView) v, (Integer) data);
              } else if (data instanceof Bitmap) {
                setViewImage((ImageView) v, (Bitmap) data);
              } else {
                setViewImage((ImageView) v, text);
              }
            } else {
              throw new IllegalStateException(
                  v.getClass().getName()
                      + " is not a "
                      + " view that can be bounds by this SimpleAdapter");
            }
          }
        }
      }
    }
 @TargetApi(HONEYCOMB)
 public void setViewChecked(View view, boolean checked) {
   if (view instanceof Checkable) {
     ((Checkable) view).setChecked(checked);
   } else if (Build.VERSION.SDK_INT >= HONEYCOMB) {
     view.setActivated(checked);
   }
 }
 @Override
 protected void onBindView(View view) {
   super.onBindView(view);
   View checkboxView = view.findViewById(android.R.id.checkbox);
   if (checkboxView != null && checkboxView instanceof Checkable)
     ((Checkable) checkboxView).setChecked(mChecked);
   syncSummaryView(view);
 }
Exemplo n.º 10
0
 @SuppressLint("NewApi")
 protected final void setStateOnView(View child, boolean value) {
   if (child instanceof Checkable) {
     ((Checkable) child).setChecked(value);
   } else if (USE_ACTIVATED) {
     child.setActivated(value);
   }
 }
Exemplo n.º 11
0
  /** 设置当前View 选中状态 */
  protected final void setItemChecked(View view, boolean isChecked) {
    if (mChoiceMode == FlowChoiceMode.None) return;

    if (view instanceof Checkable) {
      ((Checkable) view).setChecked(isChecked);
    }

    updateCurrentCheckedViews(view, isChecked);
  }
 private void clearItemState() {
   int child_size = itemBar.getChildCount();
   for (int i = 0; i < child_size; i++) {
     View childView = itemBar.getChildAt(i);
     if (childView instanceof Checkable) {
       ((Checkable) childView).setChecked(false);
     }
   }
 }
 protected void a(View paramView)
 {
   super.a(paramView);
   View localView = paramView.findViewById(fkr.g);
   if ((localView instanceof Checkable))
   {
     ((Checkable)localView).setChecked(a);
     b(localView);
   }
   c(paramView);
 }
Exemplo n.º 14
0
  private void onDeleteClicked() {
    String reason = customReasonText.getText().toString();
    boolean notifyUser = this.notifyUser.isChecked();
    boolean ban = blockUser.isChecked();

    Observable<Void> response = deleteItem(reason, notifyUser, ban);
    response
        .compose(bindToLifecycle())
        .lift(BusyDialogFragment.busyDialog(this))
        .subscribe(event -> dismiss(), defaultOnError());
  }
Exemplo n.º 15
0
  /**
   * Bind the given {@link Checkable} in a {@link ListView} item to the given position.
   *
   * @param checkable checkable representing an item
   * @param position position of item
   */
  public void bind(Checkable checkable, int position) {
    if (checkable == null) {
      throw new IllegalArgumentException();
    }

    View view = (View) checkable;

    view.setOnClickListener(null);

    checkable.setChecked(isChosen(listView, position));

    view.setOnClickListener(this);
  }
  @Override
  public void setChecked(boolean checked) {
    this.checked = checked;

    refreshDrawableState();

    // Propagate to childs
    final int count = getChildCount();
    for (int i = 0; i < count; i++) {
      final View child = getChildAt(i);
      if (child instanceof Checkable) {
        ((Checkable) child).setChecked(checked);
      }
    }
  }
 @Override
 public void onClick(View v) {
   for (Pair<View, View> pair : tabs) {
     if (pair.first == v) {
       int pageIndex = adapter.getIndexOfItem(pair.second);
       if (pageIndex == pager.getCurrentItem()) {
         if (v instanceof Checkable) {
           ((Checkable) v).setChecked(true);
         }
       } else {
         pager.setCurrentItem(pageIndex, isPageSmoothScroll);
       }
       break;
     }
   }
 }
Exemplo n.º 18
0
 @Override
 protected void onBindView(View view) {
   super.onBindView(view);
   View checkableView = view.findViewById(R.id.switchWidget);
   if (checkableView != null && checkableView instanceof Checkable) {
     ((Checkable) checkableView).setChecked(mChecked);
     sendAccessibilityEvent(checkableView);
     if (checkableView instanceof Switch) {
       final Switch switchView = (Switch) checkableView;
       switchView.setTextOn(mSwitchOn);
       switchView.setTextOff(mSwitchOff);
       switchView.setOnCheckedChangeListener(mListener);
     }
   }
   syncSummaryView(view);
 }
 @Override
 public void toggle() {
   View child = getChildAt(0);
   if (child instanceof Checkable) ((Checkable) child).toggle();
 }
 @Override
 public void toggle() {
   child.toggle();
 }
 @Override
 public void setChecked(final boolean checked) {
   ((Checkable) mItem).setChecked(checked);
 }
 @Override
 public void setChecked(boolean checked) {
   View child = getChildAt(0);
   if (child instanceof Checkable) ((Checkable) child).setChecked(checked);
 }
Exemplo n.º 23
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);
          }
        });
  }
 public RecyclerViewHolder setChecked(int viewId, boolean checked) {
   Checkable view = (Checkable) findViewById(viewId);
   view.setChecked(checked);
   return this;
 }
 @Override
 public boolean isChecked() {
   return child.isChecked();
 }
Exemplo n.º 26
0
 public ViewHolder setChecked(int viewId, boolean checked) {
   Checkable view = (Checkable) getView(viewId);
   view.setChecked(checked);
   return this;
 }
 @Override
 public void setChecked(boolean checked) {
   child.setChecked(checked);
 }
 private void updateChild(boolean checked) {
   if (mCheckableChild != null) {
     mCheckableChild.setChecked(checked);
   }
 }
 /**
  * Sets the checked status of a checkable.
  *
  * @param viewId The view id.
  * @param checked The checked status;
  * @return The BaseAdapterHelper for chaining.
  */
 public BaseRcvAdapterHelper setChecked(int viewId, boolean checked) {
   Checkable view = (Checkable) retrieveView(viewId);
   view.setChecked(checked);
   return this;
 }