/** @see TextView#setCompoundDrawablesWithIntrinsicBounds(int, int, int, int) */
  private void checkCompoundDrawable(Context context, AttributeSet attrs, View view) {
    if (view instanceof TextView) {
      TextView textView = (TextView) view;
      final int drawablePadding = textView.getCompoundDrawablePadding();

      final TypedValue value = new TypedValue();
      TypedArray array =
          context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.TextView, 0, 0);
      array.getValue(com.android.internal.R.styleable.TextView_drawableLeft, value);
      final int drawableLeftResId = value.resourceId;
      array.getValue(com.android.internal.R.styleable.TextView_drawableTop, value);
      final int drawableTopResId = value.resourceId;
      array.getValue(com.android.internal.R.styleable.TextView_drawableRight, value);
      final int drawableRightResId = value.resourceId;
      array.getValue(com.android.internal.R.styleable.TextView_drawableBottom, value);
      final int drawableBottomResId = value.resourceId;
      array.recycle();

      EnvRes drawableLeftRes = new EnvRes(drawableLeftResId);
      EnvRes drawableTopRes = new EnvRes(drawableTopResId);
      EnvRes drawableRightRes = new EnvRes(drawableRightResId);
      EnvRes drawableBottomRes = new EnvRes(drawableBottomResId);
      if (drawableLeftRes.isValid()
          || drawableTopRes.isValid()
          || drawableRightRes.isValid()
          || drawableBottomRes.isValid()) {
        textView.setCompoundDrawablesWithIntrinsicBounds(
            drawableLeftRes.getResid(),
            drawableTopRes.getResid(),
            drawableRightRes.getResid(),
            drawableBottomRes.getResid());
        textView.setCompoundDrawablePadding(drawablePadding);
      }
    }
  }
示例#2
0
    /** Called when the parser is pointing to an item tag. */
    public void readItem(AttributeSet attrs) {
      TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.SherlockMenuItem);

      // Inherit attributes from the group as default value
      itemId = a.getResourceId(R.styleable.SherlockMenuItem_android_id, defaultItemId);
      final int category =
          a.getInt(R.styleable.SherlockMenuItem_android_menuCategory, groupCategory);
      final int order = a.getInt(R.styleable.SherlockMenuItem_android_orderInCategory, groupOrder);
      itemCategoryOrder = (category & Menu.CATEGORY_MASK) | (order & Menu.USER_MASK);
      itemTitle = a.getText(R.styleable.SherlockMenuItem_android_title);
      itemTitleCondensed = a.getText(R.styleable.SherlockMenuItem_android_titleCondensed);
      itemIconResId = a.getResourceId(R.styleable.SherlockMenuItem_android_icon, 0);
      itemAlphabeticShortcut =
          getShortcut(a.getString(R.styleable.SherlockMenuItem_android_alphabeticShortcut));
      itemNumericShortcut =
          getShortcut(a.getString(R.styleable.SherlockMenuItem_android_numericShortcut));
      if (a.hasValue(R.styleable.SherlockMenuItem_android_checkable)) {
        // Item has attribute checkable, use it
        itemCheckable = a.getBoolean(R.styleable.SherlockMenuItem_android_checkable, false) ? 1 : 0;
      } else {
        // Item does not have attribute, use the group's (group can have one more state
        // for checkable that represents the exclusive checkable)
        itemCheckable = groupCheckable;
      }

      itemChecked = a.getBoolean(R.styleable.SherlockMenuItem_android_checked, defaultItemChecked);
      itemVisible = a.getBoolean(R.styleable.SherlockMenuItem_android_visible, groupVisible);
      itemEnabled = a.getBoolean(R.styleable.SherlockMenuItem_android_enabled, groupEnabled);

      TypedValue value = new TypedValue();
      a.getValue(R.styleable.SherlockMenuItem_android_showAsAction, value);
      itemShowAsAction = value.type == TypedValue.TYPE_INT_HEX ? value.data : -1;

      itemListenerMethodName = a.getString(R.styleable.SherlockMenuItem_android_onClick);
      itemActionViewLayout = a.getResourceId(R.styleable.SherlockMenuItem_android_actionLayout, 0);
      itemActionViewClassName = a.getString(R.styleable.SherlockMenuItem_android_actionViewClass);
      itemActionProviderClassName =
          a.getString(R.styleable.SherlockMenuItem_android_actionProviderClass);

      final boolean hasActionProvider = itemActionProviderClassName != null;
      if (hasActionProvider && itemActionViewLayout == 0 && itemActionViewClassName == null) {
        itemActionProvider =
            newInstance(
                itemActionProviderClassName,
                ACTION_PROVIDER_CONSTRUCTOR_SIGNATURE,
                mActionProviderConstructorArguments);
      } else {
        if (hasActionProvider) {
          Log.w(
              LOG_TAG,
              "Ignoring attribute 'actionProviderClass'." + " Action view already specified.");
        }
        itemActionProvider = null;
      }

      a.recycle();

      itemAdded = false;
    }
  public FakeDialogPhoneWindow(Context context, AttributeSet attrs) {
    super(context, attrs);

    TypedArray a = context.obtainStyledAttributes(attrs, CT_Traffic_R.styleable.SherlockTheme());

    a.getValue(CT_Traffic_R.styleable.SherlockTheme_windowMinWidthMajor(), mMinWidthMajor);
    a.getValue(CT_Traffic_R.styleable.SherlockTheme_windowMinWidthMinor(), mMinWidthMinor);

    a.recycle();
  }
 /** @see View#setBackgroundResource(int) */
 private void checkBackground(Context context, AttributeSet attrs, View view) {
   final TypedValue value = new TypedValue();
   TypedArray array =
       context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.View, 0, 0);
   array.getValue(com.android.internal.R.styleable.View_background, value);
   EnvRes backgroundRes = new EnvRes(value.resourceId);
   if (backgroundRes.isValid()) {
     view.setBackgroundResource(backgroundRes.getResid());
   }
   array.recycle();
 }
 public int[] getIntArray(Resources resources, int resId) {
   TypedArray array = resources.obtainTypedArray(resId);
   int[] rc = new int[array.length()];
   TypedValue value = new TypedValue();
   for (int i = 0; i < array.length(); i++) {
     array.getValue(i, value);
     rc[i] = value.resourceId;
   }
   array.recycle();
   return rc;
 }
 private void checkAbsSeekBar(Context context, AttributeSet attrs, View view) {
   if (view instanceof AbsSeekBar) {
     AbsSeekBar seekBar = (AbsSeekBar) view;
     final TypedValue value = new TypedValue();
     TypedArray array =
         context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.SeekBar, 0, 0);
     array.getValue(com.android.internal.R.styleable.SeekBar_thumb, value);
     EnvRes thumbRes = new EnvRes(value.resourceId);
     if (thumbRes.isValid()) {
       seekBar.setThumb(context.getResources().getDrawable(thumbRes.getResid()));
     }
     array.recycle();
   }
 }
 private void checkAbsListView(Context context, AttributeSet attrs, View view) {
   if (view instanceof AbsListView) {
     AbsListView listView = (AbsListView) view;
     final TypedValue value = new TypedValue();
     TypedArray array =
         context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.AbsListView, 0, 0);
     array.getValue(com.android.internal.R.styleable.AbsListView_listSelector, value);
     EnvRes listSelectorRes = new EnvRes(value.resourceId);
     if (listSelectorRes.isValid()) {
       listView.setSelector(context.getResources().getDrawable(listSelectorRes.getResid()));
     }
     array.recycle();
   }
 }
 /** @see ImageView#setImageResource(int) */
 private void checkImageView(Context context, AttributeSet attrs, View view) {
   if (view instanceof ImageView) {
     ImageView imageView = (ImageView) view;
     final TypedValue value = new TypedValue();
     TypedArray array =
         context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.ImageView, 0, 0);
     array.getValue(com.android.internal.R.styleable.ImageView_src, value);
     EnvRes srcRes = new EnvRes(value.resourceId);
     if (srcRes.isValid()) {
       imageView.setImageResource(srcRes.getResid());
     }
     array.recycle();
   }
 }
  @NonNull
  public static int[] getKeyCodesFromTypedArray(TypedArray typedArray, int index) {
    TypedValue codesValue = new TypedValue();
    typedArray.getValue(index, codesValue);

    if (codesValue.type == TypedValue.TYPE_INT_DEC || codesValue.type == TypedValue.TYPE_INT_HEX) {
      return new int[] {codesValue.data};
    } else if (codesValue.type == TypedValue.TYPE_STRING) {
      return parseCSV(codesValue.string.toString());
    } else {
      Log.w(TAG, "Unknown codes values!");
      return new int[0];
    }
  }
 /** @see CompoundButton#setButtonDrawable(int) */
 private void checkCompoundButton(Context context, AttributeSet attrs, View view) {
   if (view instanceof CompoundButton) {
     CompoundButton button = (CompoundButton) view;
     final TypedValue value = new TypedValue();
     TypedArray array =
         context.obtainStyledAttributes(
             attrs, com.android.internal.R.styleable.CompoundButton, 0, 0);
     array.getValue(com.android.internal.R.styleable.CompoundButton_button, value);
     EnvRes buttonRes = new EnvRes(value.resourceId);
     if (buttonRes.isValid()) {
       button.setButtonDrawable(buttonRes.getResid());
     }
     array.recycle();
   }
 }
示例#11
0
  public LoadingLayout(
      Context context, final Mode mode, final Orientation scrollDirection, TypedArray attrs) {
    super(context);
    mMode = mode;
    mScrollDirection = scrollDirection;

    switch (scrollDirection) {
      case HORIZONTAL:
        LayoutInflater.from(context).inflate(R.layout.pull_to_refresh_header_horizontal, this);
        break;
      case VERTICAL:
      default:
        LayoutInflater.from(context).inflate(R.layout.pull_to_refresh_header_vertical, this);
        break;
    }

    mInnerLayout = (FrameLayout) findViewById(R.id.fl_inner);
    mHeaderText = (TextView) mInnerLayout.findViewById(R.id.pull_to_refresh_text);
    mHeaderProgress = (ProgressBar) mInnerLayout.findViewById(R.id.pull_to_refresh_progress);
    mSubHeaderText = (TextView) mInnerLayout.findViewById(R.id.pull_to_refresh_sub_text);
    mHeaderImage = (ImageView) mInnerLayout.findViewById(R.id.pull_to_refresh_image);

    FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mInnerLayout.getLayoutParams();

    switch (mode) {
      case PULL_FROM_END:
        lp.gravity = scrollDirection == Orientation.VERTICAL ? Gravity.TOP : Gravity.LEFT;

        // Load in labels
        mPullLabel = context.getString(R.string.pull_to_refresh_from_bottom_pull_label);
        mRefreshingLabel = context.getString(R.string.pull_to_refresh_from_bottom_refreshing_label);
        mReleaseLabel = context.getString(R.string.pull_to_refresh_from_bottom_release_label);
        break;

      case PULL_FROM_START:
      default:
        lp.gravity = scrollDirection == Orientation.VERTICAL ? Gravity.BOTTOM : Gravity.RIGHT;

        // Load in labels
        mPullLabel = context.getString(R.string.pull_to_refresh_pull_label);
        mRefreshingLabel = context.getString(R.string.pull_to_refresh_refreshing_label);
        mReleaseLabel = context.getString(R.string.pull_to_refresh_release_label);
        break;
    }

    if (attrs.hasValue(R.styleable.PullToRefresh_ptrHeaderBackground)) {
      Drawable background = attrs.getDrawable(R.styleable.PullToRefresh_ptrHeaderBackground);
      if (null != background) {
        ViewCompat.setBackground(this, background);
      }
    }

    if (attrs.hasValue(R.styleable.PullToRefresh_ptrHeaderTextAppearance)) {
      TypedValue styleID = new TypedValue();
      attrs.getValue(R.styleable.PullToRefresh_ptrHeaderTextAppearance, styleID);
      setTextAppearance(styleID.data);
    }
    if (attrs.hasValue(R.styleable.PullToRefresh_ptrSubHeaderTextAppearance)) {
      TypedValue styleID = new TypedValue();
      attrs.getValue(R.styleable.PullToRefresh_ptrSubHeaderTextAppearance, styleID);
      setSubTextAppearance(styleID.data);
    }

    // Text Color attrs need to be set after TextAppearance attrs
    if (attrs.hasValue(R.styleable.PullToRefresh_ptrHeaderTextColor)) {
      ColorStateList colors = attrs.getColorStateList(R.styleable.PullToRefresh_ptrHeaderTextColor);
      if (null != colors) {
        setTextColor(colors);
      }
    }
    if (attrs.hasValue(R.styleable.PullToRefresh_ptrHeaderSubTextColor)) {
      ColorStateList colors =
          attrs.getColorStateList(R.styleable.PullToRefresh_ptrHeaderSubTextColor);
      if (null != colors) {
        setSubTextColor(colors);
      }
    }

    // Try and get defined drawable from Attrs
    Drawable imageDrawable = null;
    if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawable)) {
      imageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawable);
    }

    // Check Specific Drawable from Attrs, these overrite the generic
    // drawable attr above
    switch (mode) {
      case PULL_FROM_START:
      default:
        if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawableStart)) {
          imageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawableStart);
        } else if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawableTop)) {
          Utils.warnDeprecation("ptrDrawableTop", "ptrDrawableStart");
          imageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawableTop);
        }
        break;

      case PULL_FROM_END:
        if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawableEnd)) {
          imageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawableEnd);
        } else if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawableBottom)) {
          Utils.warnDeprecation("ptrDrawableBottom", "ptrDrawableEnd");
          imageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawableBottom);
        }
        break;
    }

    // If we don't have a user defined drawable, load the default
    if (null == imageDrawable) {
      imageDrawable = context.getResources().getDrawable(getDefaultDrawableResId());
    }

    // Set Drawable, and save width/height
    setLoadingDrawable(imageDrawable);

    reset();
  }
示例#12
0
  public GlowPadView(Context context, AttributeSet attrs) {
    super(context, attrs);
    Resources res = context.getResources();

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GlowPadView);
    mInnerRadius = a.getDimension(R.styleable.GlowPadView_innerRadius, mInnerRadius);
    mOuterRadius = a.getDimension(R.styleable.GlowPadView_outerRadius, mOuterRadius);
    mSnapMargin = a.getDimension(R.styleable.GlowPadView_snapMargin, mSnapMargin);
    mVibrationDuration = a.getInt(R.styleable.GlowPadView_vibrationDuration, mVibrationDuration);
    mFeedbackCount = a.getInt(R.styleable.GlowPadView_feedbackCount, mFeedbackCount);
    mAllowScaling = a.getBoolean(R.styleable.GlowPadView_allowScaling, false);
    TypedValue handle = a.peekValue(R.styleable.GlowPadView_handleDrawable);
    mHandleDrawable = new TargetDrawable(res, handle != null ? handle.resourceId : 0, 2);
    mHandleDrawable.setState(TargetDrawable.STATE_INACTIVE);
    mOuterRing =
        new TargetDrawable(res, getResourceId(a, R.styleable.GlowPadView_outerRingDrawable), 1);

    mAlwaysTrackFinger = a.getBoolean(R.styleable.GlowPadView_alwaysTrackFinger, false);

    int pointId = getResourceId(a, R.styleable.GlowPadView_pointDrawable);
    Drawable pointDrawable = pointId != 0 ? res.getDrawable(pointId) : null;
    mGlowRadius = a.getDimension(R.styleable.GlowPadView_glowRadius, 0.0f);

    TypedValue outValue = new TypedValue();

    // Read array of target drawables
    if (a.getValue(R.styleable.GlowPadView_targetDrawables, outValue)) {
      internalSetTargetResources(outValue.resourceId);
    }
    if (mTargetDrawables == null || mTargetDrawables.size() == 0) {
      throw new IllegalStateException("Must specify at least one target drawable");
    }

    // Read array of target descriptions
    if (a.getValue(R.styleable.GlowPadView_targetDescriptions, outValue)) {
      final int resourceId = outValue.resourceId;
      if (resourceId == 0) {
        throw new IllegalStateException("Must specify target descriptions");
      }
      setTargetDescriptionsResourceId(resourceId);
    }

    // Read array of direction descriptions
    if (a.getValue(R.styleable.GlowPadView_directionDescriptions, outValue)) {
      final int resourceId = outValue.resourceId;
      if (resourceId == 0) {
        throw new IllegalStateException("Must specify direction descriptions");
      }
      setDirectionDescriptionsResourceId(resourceId);
    }

    a.recycle();

    // Use gravity attribute from LinearLayout
    // a = context.obtainStyledAttributes(attrs, R.styleable.LinearLayout);
    mGravity = a.getInt(R.styleable.GlowPadView_android_gravity, Gravity.TOP);
    a.recycle();

    setVibrateEnabled(mVibrationDuration > 0);

    assignDefaultsIfNeeded();

    mPointCloud = new PointCloud(pointDrawable);
    mPointCloud.makePointCloud(mInnerRadius, mOuterRadius);
    mPointCloud.glowManager.setRadius(mGlowRadius);
  }
示例#13
0
  public LcSearchView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {

    super(context, attrs, defStyleAttr);
    LayoutInflater inflater =
        (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.lc_search_view, this, true);
    mSearchTrack = findViewById(R.id.lc_search_plate);
    mTitleIcon = (ImageView) findViewById(R.id.lc_search_icon);
    mEditorTextView = (SearchAutoComplete) findViewById(R.id.lc_search_src_text);
    mClearBtn = (ImageView) findViewById(R.id.lc_search_clear_btn);
    mCancelTextView = (TextView) findViewById(R.id.lc_search_text_cancel);

    mTitleIcon.setOnClickListener(mOnClickListener);
    mClearBtn.setOnClickListener(mOnClickListener);
    mCancelTextView.setOnClickListener(mOnClickListener);
    mEditorTextView.setOnClickListener(mOnClickListener);
    mEditorTextView.setOnEditorActionListener(mOnEditorActionListener);
    mEditorTextView.setOnItemClickListener(mOnItemClickListener);
    mEditorTextView.addTextChangedListener(mTextWatcher);
    mEditorTextView.setSearchView(this);
    mEditorTextView.ensureImeVisible(true);
    // Inform any listener of focus changes
    mEditorTextView.setOnFocusChangeListener(
        new OnFocusChangeListener() {
          public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) {
              mTitleIcon.setAlpha(unfocusAlpha);
              mEditorTextView.setAlpha(unfocusAlpha);
            } else {
              mTitleIcon.setAlpha(1.0f);
              mEditorTextView.setAlpha(1.0f);
            }

            if (mOnTextFocusChangeListener != null) {
              mOnTextFocusChangeListener.onFocusChange(LcSearchView.this, hasFocus);
            }
          }
        });

    mDropDownAnchor = findViewById(mEditorTextView.getDropDownAnchor());
    if (mDropDownAnchor != null) {
      mDropDownAnchor.addOnLayoutChangeListener(
          new OnLayoutChangeListener() {
            @Override
            public void onLayoutChange(
                View v,
                int left,
                int top,
                int right,
                int bottom,
                int oldLeft,
                int oldTop,
                int oldRight,
                int oldBottom) {
              adjustDropDownSizeAndPosition();
            }
          });
    }

    int maxWidth = -1;
    CharSequence cancelText = null;
    CharSequence queryHintText = null;
    int clearBtnResId = R.drawable.lc_icon_search_view_clear_light;
    int titleIconId = R.drawable.lc_icon_search_view_search_light;
    int searchBgId = R.drawable.lc_selector_search_view_frame_light;
    int imeOptions = -1;
    int inputType = -1;
    boolean focusable = true;

    final Resources res = getResources();

    TypedValue out = new TypedValue();
    res.getValue(R.dimen.lc_search_view_default_text_alpha, out, true);
    unfocusAlpha = out.getFloat();

    int queryTextSize = res.getDimensionPixelSize(R.dimen.lc_default_search_query_text_size);
    ColorStateList queryTextColor =
        res.getColorStateList(R.color.lc_search_view_query_text_color_light);
    ColorStateList queryHintTextColor =
        res.getColorStateList(R.color.lc_search_view_query_hint_text_color_light);
    int cancelTextSize = res.getDimensionPixelSize(R.dimen.lc_default_search_query_text_size);
    ColorStateList cancelTextColor = null;

    int mTrackMarginLeft = res.getDimensionPixelSize(R.dimen.lc_search_track_margin_left);
    mTrackMarginRight = res.getDimensionPixelSize(R.dimen.lc_search_track_margin_right);
    int mTrackMarginTop = res.getDimensionPixelSize(R.dimen.lc_search_track_margin_top);
    int mTrackMarginBottom = res.getDimensionPixelSize(R.dimen.lc_search_track_margin_bottom);
    int mTrackPaddingLeft = res.getDimensionPixelSize(R.dimen.lc_search_track_padding_left);
    int mTrackPaddingRight = res.getDimensionPixelSize(R.dimen.lc_search_track_padding_right);

    mMatchColor = res.getColor(R.color.lc_search_view_drop_down_match_text_color_light);
    mCursorResId = R.drawable.lc_shape_search_view_cursor_light;
    mDropDownBg = res.getDrawable(R.drawable.lc_search_drop_down_bg);
    mDropDownBlurRadius = 10;
    mPopupItemLayoutResId = R.layout.lc_search_dropdown_item_icons_2line_light;
    mAlwaysShowCancel = true;
    Drawable popupDivider = res.getDrawable(R.drawable.lc_search_drop_down_divider);

    TypedArray a =
        context.obtainStyledAttributes(attrs, R.styleable.LcSearchView, defStyleAttr, defStyleRes);

    a.getValue(R.styleable.LcSearchView_lcSearchUnfocusAlpha, out);
    unfocusAlpha = out.getFloat();

    queryTextSize =
        a.getDimensionPixelSize(R.styleable.LcSearchView_lcQueryTextSize, queryTextSize);
    cancelTextSize =
        a.getDimensionPixelSize(R.styleable.LcSearchView_lcCancelTextSize, cancelTextSize);
    if (a.hasValue(R.styleable.LcSearchView_lcQueryTextColor)) {
      queryTextColor = a.getColorStateList(R.styleable.LcSearchView_lcQueryTextColor);
    }

    if (a.hasValue(R.styleable.LcSearchView_lcQueryHintColor)) {
      queryHintTextColor = a.getColorStateList(R.styleable.LcSearchView_lcQueryHintColor);
    }
    if (a.hasValue(R.styleable.LcSearchView_lcCancelTextColor)) {
      cancelTextColor = a.getColorStateList(R.styleable.LcSearchView_lcCancelTextColor);
    } else {
      cancelTextColor = queryTextColor;
    }

    mTrackMarginBottom =
        a.getDimensionPixelSize(R.styleable.LcSearchView_lcInputMarginBottom, mTrackMarginBottom);
    mTrackMarginLeft =
        a.getDimensionPixelSize(R.styleable.LcSearchView_lcInputMarginLeft, mTrackMarginLeft);
    mTrackMarginRight =
        a.getDimensionPixelSize(R.styleable.LcSearchView_lcInputMarginRight, mTrackMarginRight);
    mTrackMarginTop =
        a.getDimensionPixelSize(R.styleable.LcSearchView_lcInputMarginTop, mTrackMarginTop);

    maxWidth = a.getDimensionPixelSize(R.styleable.LcSearchView_android_maxWidth, maxWidth);
    queryHintText = a.getText(R.styleable.LcSearchView_lcQueryHint);
    clearBtnResId = a.getResourceId(R.styleable.LcSearchView_lcClearIcon, clearBtnResId);
    titleIconId = a.getResourceId(R.styleable.LcSearchView_lcSearchIcon, titleIconId);
    searchBgId = a.getResourceId(R.styleable.LcSearchView_lcBackground, searchBgId);
    imeOptions = a.getInt(R.styleable.LcSearchView_android_imeOptions, imeOptions);
    inputType = a.getInt(R.styleable.LcSearchView_android_inputType, inputType);
    focusable = a.getBoolean(R.styleable.LcSearchView_android_focusable, focusable);

    mMatchColor = a.getColor(R.styleable.LcSearchView_lcMatchColor, mMatchColor);
    mCursorResId =
        a.getResourceId(R.styleable.LcSearchView_android_textCursorDrawable, mCursorResId);

    if (a.hasValue(R.styleable.LcSearchView_lcCancelText)) {
      cancelText = a.getString(R.styleable.LcSearchView_lcCancelText);
    }

    if (a.hasValue(R.styleable.LcSearchView_lcPopupBackground)) {
      mDropDownBg = a.getDrawable(R.styleable.LcSearchView_lcPopupBackground);
    }

    if (a.hasValue(R.styleable.LcSearchView_lcPopupListDivider)) {
      popupDivider = a.getDrawable(R.styleable.LcSearchView_lcPopupListDivider);
    }
    mDropDownBlurRadius =
        a.getDimensionPixelSize(R.styleable.LcSearchView_lcPopupBlurRadius, mDropDownBlurRadius);
    mPopupItemLayoutResId =
        a.getResourceId(R.styleable.LcSearchView_lcPopupItemLayout, mPopupItemLayoutResId);

    final int completeThreshold = a.getInt(R.styleable.LcSearchView_android_completionThreshold, 2);

    mAlwaysShowCancel =
        a.getBoolean(R.styleable.LcSearchView_lcAlwaysShowCancel, mAlwaysShowCancel);
    a.recycle();

    mEditorTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, queryTextSize);
    mEditorTextView.setTextColor(queryTextColor);
    mEditorTextView.setHintTextColor(queryHintTextColor);
    HIDDEN_METHOD.setCursorDrawableRes(mEditorTextView, mCursorResId);
    mEditorTextView.setPopupBackground(mDropDownBg);
    mEditorTextView.setPopupListDivider(popupDivider);
    mEditorTextView.setPopupBlurRadius(mDropDownBlurRadius);
    mEditorTextView.setThreshold(completeThreshold);

    if (mEditorTextView.hasFocus()) {
      mTitleIcon.setAlpha(1.0f);
      mEditorTextView.setAlpha(1.0f);
    } else {
      mTitleIcon.setAlpha(unfocusAlpha);
      mEditorTextView.setAlpha(unfocusAlpha);
    }

    mCancelTextView.setTextColor(cancelTextColor);
    mCancelTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, cancelTextSize);
    if (mAlwaysShowCancel) {
      mCancelTextView.setVisibility(View.VISIBLE);
    }
    mClearBtn.setImageResource(clearBtnResId);
    mTitleIcon.setImageResource(titleIconId);

    mSearchTrack.setBackgroundResource(searchBgId);
    LinearLayout.LayoutParams plateParams =
        (LinearLayout.LayoutParams) mSearchTrack.getLayoutParams();
    plateParams.topMargin = mTrackMarginTop;
    plateParams.bottomMargin = mTrackMarginBottom;
    plateParams.leftMargin = mTrackMarginLeft;
    plateParams.rightMargin = mAlwaysShowCancel ? 0 : mTrackMarginRight;

    LinearLayout.LayoutParams params = (LayoutParams) mTitleIcon.getLayoutParams();
    params.leftMargin = mTrackPaddingLeft;
    params = (LayoutParams) mClearBtn.getLayoutParams();
    params.rightMargin = mTrackPaddingRight;

    mCancelTextView.setPadding(mTrackMarginRight, 0, mTrackMarginRight, 0);

    if (maxWidth != -1) {
      setMaxWidth(maxWidth);
    }

    if (!TextUtils.isEmpty(queryHintText)) {
      setQueryHint(queryHintText);
    }

    if (imeOptions != -1) {
      setImeOptions(imeOptions);
    }
    if (inputType != -1) {
      setInputType(inputType);
    }

    if (cancelText != null) {
      mCancelTextView.setText(cancelText);
    }

    setFocusable(focusable);

    updateQueryHint();
  }
示例#14
0
  private boolean parsePackage(Resources res, XmlResourceParser parser) {
    AttributeSet attrs = parser;
    mPackageInfo = new PackageInfo();

    try {
      int type;
      while ((type = parser.next()) != XmlResourceParser.START_TAG
          && type != XmlResourceParser.END_DOCUMENT) ;

      // <manifest ...
      mPackageInfo.packageName = parser.getAttributeValue(null, "package").intern();

      // After gradle-small 0.9.0, we roll out
      // `The Small exclusive flags`
      //  F    F    F    F    F    F    F    F
      // 1111 1111 1111 1111 1111 1111 1111 1111
      // ^^^^ ^^^^ ^^^^ ^^^^ ^^^^
      //       ABI Flags (20)
      //                          ^
      //                 nonResources Flag (1)
      //                           ^^^ ^^^^ ^^^^
      //                     platformBuildVersionCode (11) => MAX=0x7FF=4095
      int flags = parser.getAttributeIntValue(null, "platformBuildVersionCode", 0);
      int abiFlags = (flags & 0xFFFFF000) >> 12;
      mNonResources = (flags & 0x800) != 0;

      TypedArray sa = res.obtainAttributes(attrs, R.styleable.AndroidManifest);
      mPackageInfo.versionCode = sa.getInteger(R.styleable.AndroidManifest_versionCode, 0);
      String versionName = sa.getString(R.styleable.AndroidManifest_versionName);
      if (versionName != null) {
        mPackageInfo.versionName = versionName.intern();
      }

      // <application ...
      while ((type = parser.next()) != XmlResourceParser.END_DOCUMENT) {
        if (type == XmlResourceParser.TEXT) {
          continue;
        }

        String tagName = parser.getName();
        if (tagName.equals("application")) {
          ApplicationInfo app = new ApplicationInfo(Small.getContext().getApplicationInfo());

          sa = res.obtainAttributes(attrs, R.styleable.AndroidManifestApplication);

          String name = sa.getString(R.styleable.AndroidManifestApplication_name);
          if (name != null) {
            app.className = name.intern();
          } else {
            app.className = null;
          }

          // Get the label value which used as ABI flags.
          // This is depreciated, we read it from the `platformBuildVersionCode` instead.
          // TODO: Remove this if the gradle-small 0.9.0 or above being widely used.
          if (abiFlags == 0) {
            TypedValue label = new TypedValue();
            if (sa.getValue(R.styleable.AndroidManifestApplication_label, label)) {
              if (label.type == TypedValue.TYPE_STRING) {
                abiFlags = Integer.parseInt(label.string.toString());
              } else {
                abiFlags = label.data;
              }
            }
          }

          app.theme = sa.getResourceId(R.styleable.AndroidManifestApplication_theme, 0);
          mPackageInfo.applicationInfo = app;
          break;
        }
      }

      if (abiFlags != 0) {
        String abi = JNIUtils.getExtractABI(abiFlags, Bundle.is64bit());
        if (abi != null) {
          mLibDir = "lib/" + abi + "/";
        }
      }

      sa.recycle();
      return true;
    } catch (XmlPullParserException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
    return false;
  }
 private void checkScrollBar(Context context, AttributeSet attrs, View view) {
   try {
     Field mScrollCacheField = View.class.getDeclaredField("mScrollCache");
     if (mScrollCacheField != null) {
       mScrollCacheField.setAccessible(true);
       Object mScrollCache = mScrollCacheField.get(view);
       if (mScrollCache != null) {
         Field scrollBarField = mScrollCache.getClass().getDeclaredField("scrollBar");
         if (scrollBarField != null) {
           Object scrollBar = scrollBarField.get(mScrollCache);
           if (scrollBar != null) {
             final TypedValue value = new TypedValue();
             TypedArray array =
                 context.obtainStyledAttributes(
                     attrs, com.android.internal.R.styleable.View, 0, 0);
             array.getValue(com.android.internal.R.styleable.View_scrollbarTrackHorizontal, value);
             EnvRes scrollbarTrackHorizontalRes = new EnvRes(value.resourceId);
             if (scrollbarTrackHorizontalRes.isValid()) {
               Method setHorizontalTrackDrawableMethod =
                   scrollBar
                       .getClass()
                       .getDeclaredMethod("setHorizontalTrackDrawable", Drawable.class);
               if (setHorizontalTrackDrawableMethod != null) {
                 setHorizontalTrackDrawableMethod.setAccessible(true);
                 setHorizontalTrackDrawableMethod.invoke(
                     scrollBar,
                     context.getResources().getDrawable(scrollbarTrackHorizontalRes.getResid()));
               }
             }
             array.getValue(com.android.internal.R.styleable.View_scrollbarThumbHorizontal, value);
             EnvRes scrollbarThumbHorizontalRes = new EnvRes(value.resourceId);
             if (scrollbarThumbHorizontalRes.isValid()) {
               Method setHorizontalThumbDrawableMethod =
                   scrollBar
                       .getClass()
                       .getDeclaredMethod("setHorizontalThumbDrawable", Drawable.class);
               if (setHorizontalThumbDrawableMethod != null) {
                 setHorizontalThumbDrawableMethod.setAccessible(true);
                 setHorizontalThumbDrawableMethod.invoke(
                     scrollBar,
                     context.getResources().getDrawable(scrollbarThumbHorizontalRes.getResid()));
               }
             }
             array.getValue(com.android.internal.R.styleable.View_scrollbarTrackVertical, value);
             EnvRes scrollbarTrackVerticalRes = new EnvRes(value.resourceId);
             if (scrollbarTrackVerticalRes.isValid()) {
               Method setVerticalTrackDrawableMethod =
                   scrollBar
                       .getClass()
                       .getDeclaredMethod("setVerticalTrackDrawable", Drawable.class);
               if (setVerticalTrackDrawableMethod != null) {
                 setVerticalTrackDrawableMethod.setAccessible(true);
                 setVerticalTrackDrawableMethod.invoke(
                     scrollBar,
                     context.getResources().getDrawable(scrollbarTrackVerticalRes.getResid()));
               }
             }
             array.getValue(com.android.internal.R.styleable.View_scrollbarThumbVertical, value);
             EnvRes scrollbarThumbVerticalRes = new EnvRes(value.resourceId);
             if (scrollbarThumbVerticalRes.isValid()) {
               Method setVerticalThumbDrawableMethod =
                   scrollBar
                       .getClass()
                       .getDeclaredMethod("setVerticalThumbDrawable", Drawable.class);
               if (setVerticalThumbDrawableMethod != null) {
                 setVerticalThumbDrawableMethod.setAccessible(true);
                 setVerticalThumbDrawableMethod.invoke(
                     scrollBar,
                     context.getResources().getDrawable(scrollbarThumbVerticalRes.getResid()));
               }
             }
             array.recycle();
           }
         }
       }
     }
   } catch (NoSuchFieldException e) {
     e.printStackTrace();
   } catch (IllegalAccessException e) {
     e.printStackTrace();
   } catch (IllegalArgumentException e) {
     e.printStackTrace();
   } catch (NoSuchMethodException e) {
     e.printStackTrace();
   } catch (InvocationTargetException e) {
     e.printStackTrace();
   } catch (NotFoundException e) {
     e.printStackTrace();
   }
 }
  public DiscreteSeekBar(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    setFocusable(true);
    setWillNotDraw(false);

    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    float density = context.getResources().getDisplayMetrics().density;
    mTrackHeight = (int) (1 * density);
    mScrubberHeight = (int) (4 * density);
    int thumbSize = (int) (density * ThumbDrawable.DEFAULT_SIZE_DP);

    // Extra pixels for a touch area of 48dp
    int touchBounds = (int) (density * 32);
    mAddedTouchBounds = (touchBounds - thumbSize) / 2;

    TypedArray a =
        context.obtainStyledAttributes(
            attrs, R.styleable.DiscreteSeekBar, defStyleAttr, R.style.Widget_DiscreteSeekBar);

    int max = 100;
    int min = 0;
    int value = 0;
    mMirrorForRtl = a.getBoolean(R.styleable.DiscreteSeekBar_dsb_mirrorForRtl, mMirrorForRtl);
    mAllowTrackClick =
        a.getBoolean(R.styleable.DiscreteSeekBar_dsb_allowTrackClickToDrag, mAllowTrackClick);
    mIndicatorPopupEnabled =
        a.getBoolean(R.styleable.DiscreteSeekBar_dsb_indicatorPopupEnabled, mIndicatorPopupEnabled);
    int indexMax = R.styleable.DiscreteSeekBar_dsb_max;
    int indexMin = R.styleable.DiscreteSeekBar_dsb_min;
    int indexValue = R.styleable.DiscreteSeekBar_dsb_value;
    final TypedValue out = new TypedValue();
    // Not sure why, but we wanted to be able to use dimensions here...
    if (a.getValue(indexMax, out)) {
      if (out.type == TypedValue.TYPE_DIMENSION) {
        max = a.getDimensionPixelSize(indexMax, max);
      } else {
        max = a.getInteger(indexMax, max);
      }
    }
    if (a.getValue(indexMin, out)) {
      if (out.type == TypedValue.TYPE_DIMENSION) {
        min = a.getDimensionPixelSize(indexMin, min);
      } else {
        min = a.getInteger(indexMin, min);
      }
    }
    if (a.getValue(indexValue, out)) {
      if (out.type == TypedValue.TYPE_DIMENSION) {
        value = a.getDimensionPixelSize(indexValue, value);
      } else {
        value = a.getInteger(indexValue, value);
      }
    }

    mMin = min;
    mMax = Math.max(min + 1, max);
    mValue = Math.max(min, Math.min(max, value));
    updateKeyboardRange();

    mIndicatorFormatter = a.getString(R.styleable.DiscreteSeekBar_dsb_indicatorFormatter);

    ColorStateList trackColor = a.getColorStateList(R.styleable.DiscreteSeekBar_dsb_trackColor);
    ColorStateList progressColor =
        a.getColorStateList(R.styleable.DiscreteSeekBar_dsb_progressColor);
    ColorStateList rippleColor = a.getColorStateList(R.styleable.DiscreteSeekBar_dsb_rippleColor);
    boolean editMode = isInEditMode();
    if (editMode || rippleColor == null) {
      rippleColor = new ColorStateList(new int[][] {new int[] {}}, new int[] {Color.DKGRAY});
    }
    if (editMode || trackColor == null) {
      trackColor = new ColorStateList(new int[][] {new int[] {}}, new int[] {Color.GRAY});
    }
    if (editMode || progressColor == null) {
      progressColor =
          new ColorStateList(new int[][] {new int[] {}}, new int[] {DEFAULT_THUMB_COLOR});
    }
    mRipple = SeekBarCompat.getRipple(rippleColor);
    if (isLollipopOrGreater) {
      SeekBarCompat.setBackground(this, mRipple);
    } else {
      mRipple.setCallback(this);
    }

    TrackRectDrawable shapeDrawable = new TrackRectDrawable(trackColor);
    mTrack = shapeDrawable;
    mTrack.setCallback(this);

    shapeDrawable = new TrackRectDrawable(progressColor);
    mScrubber = shapeDrawable;
    mScrubber.setCallback(this);

    mThumb = new ThumbDrawable(progressColor, thumbSize);
    mThumb.setCallback(this);
    mThumb.setBounds(0, 0, mThumb.getIntrinsicWidth(), mThumb.getIntrinsicHeight());

    if (!editMode) {
      mIndicator = new PopupIndicator(context, attrs, defStyleAttr, convertValueToMessage(mMax));
      mIndicator.setListener(mFloaterListener);
    }
    a.recycle();

    setNumericTransformer(new DefaultNumericTransformer());
  }