/**
   * 从TypedArray里面抽取需要的resourceID
   *
   * @param typedArr
   */
  private void initLayer(TypedArray typedArr) {
    removeAllViews();
    for (int i = 0; i < typedArr.getIndexCount(); i++) {
      if (typedArr.getIndex(i) == R.styleable.VDVideoView_layerAttrs) {
        int resID = -1;
        // 1.layerAttrs中格式一般为@array/sv_videoview_layers之类的格式
        // 先读出其resourceID来,准备加载TypedArray
        resID = typedArr.getResourceId(R.styleable.VDVideoView_layerAttrs, -1);
        if (resID == -1) {
          if (typedArr != null) typedArr.recycle();
          throw new IllegalArgumentException("resID=-1");
        }

        readLayerAttrs(resID);
      } else if (typedArr.getIndex(i) == R.styleable.VDVideoView_canPopupWindow) {
        int popWindowType = typedArr.getInt(R.styleable.VDVideoView_canPopupWindow, -1);
        if (popWindowType != -1) {
          mIsCanPopupWindow = true;
          mPopupWindowType = popWindowType;
        }
      } else if (typedArr.getIndex(i) == R.styleable.VDVideoView_popWindowWidth) {
        float width = typedArr.getDimension(R.styleable.VDVideoView_popWindowWidth, -1);
        if (width != -1) {
          mPopupWindowWidth = (int) width;
        }
      } else if (typedArr.getIndex(i) == R.styleable.VDVideoView_popWindowHeight) {
        float height = typedArr.getDimension(R.styleable.VDVideoView_popWindowHeight, -1);
        if (height != -1) {
          mPopupWindowHeight = (int) height;
        }
      }
    }
  }
  public VDVideoSoundSeekButton(Context context, AttributeSet attrs) {
    super(context, attrs);
    // TODO Auto-generated constructor stub
    mContext = context;
    // 支持自定义背景
    TypedArray typedArr =
        context.obtainStyledAttributes(attrs, new int[] {android.R.attr.background});

    mResID = R.drawable.play_ctrl_volume;
    if (typedArr != null) {
      mResID = typedArr.getResourceId(0, -1);
      if (mResID == -1) {
        mResID = R.drawable.play_ctrl_volume;
      }
      typedArr.recycle();
    }
    setBackgroundResource(mResID);

    // 指定相应的音量控制容器类
    typedArr = context.obtainStyledAttributes(attrs, R.styleable.VDVideoSoundSeekButton);
    mSilentResID = R.drawable.ad_silent_selcetor;
    if (typedArr != null) {
      for (int i = 0; i < typedArr.getIndexCount(); i++) {
        if (typedArr.getIndex(i) == R.styleable.VDVideoSoundSeekButton_soundSeekContainer) {
          mContainerID = typedArr.getResourceId(i, -1);
        } else if (typedArr.getIndex(i) == R.styleable.VDVideoSoundSeekButton_soundSeekSilent) {
          // 自定义背景的时候,换静音按钮
          mSilentResID = typedArr.getResourceId(i, -1);
        }
      }
      typedArr.recycle();
    }

    registerListeners();
  }
    /**
     * Create a key with the given top-left coordinate and extract its attributes from the XML
     * parser.
     *
     * @param res resources associated with the caller's context
     * @param parent the row that this key belongs to. The row must already be attached to a {@link
     *     Keyboard}.
     * @param x the x coordinate of the top-left
     * @param y the y coordinate of the top-left
     * @param parser the XML parser containing the attributes for this key
     */
    public Key(
        Context askContext,
        Resources res,
        Row parent,
        KeyboardDimens keyboardDimens,
        int x,
        int y,
        XmlResourceParser parser) {
      this(parent, keyboardDimens);
      final Resources askResources = askContext.getResources();
      SparseIntArray attributeIdMap = parent.parent.attributeIdMap;
      this.x = x;
      this.y = y;

      // setting up some defaults
      width = Math.min(keyboardDimens.getKeyMaxWidth(), parent.defaultWidth);
      height =
          KeyboardSupport.getKeyHeightFromHeightCode(
              keyboardDimens,
              parent.defaultHeightCode,
              askResources.getConfiguration().orientation);
      gap = parent.defaultHorizontalGap;
      codes = null;
      iconPreview = null;
      popupCharacters = null;
      popupResId = 0;
      repeatable = false;
      showPreview = true;
      dynamicEmblem = KEY_EMBLEM_NONE;
      modifier = false;
      sticky = false;

      // loading data from XML
      int[] remoteKeyboardLayoutStyleable = parent.parent.remoteKeyboardLayoutStyleable;
      TypedArray a =
          res.obtainAttributes(Xml.asAttributeSet(parser), remoteKeyboardLayoutStyleable);
      int n = a.getIndexCount();
      for (int i = 0; i < n; i++) {
        final int remoteIndex = a.getIndex(i);
        final int localAttrId = attributeIdMap.get(remoteKeyboardLayoutStyleable[remoteIndex]);
        setDataFromTypedArray(parent, keyboardDimens, askResources, a, remoteIndex, localAttrId);
      }
      a.recycle();
      this.x += gap;

      int[] remoteKeyboardKeyLayoutStyleable = parent.parent.remoteKeyboardKeyLayoutStyleable;
      a = res.obtainAttributes(Xml.asAttributeSet(parser), remoteKeyboardKeyLayoutStyleable);
      n = a.getIndexCount();
      for (int i = 0; i < n; i++) {
        final int remoteIndex = a.getIndex(i);
        final int localAttrId = attributeIdMap.get(remoteKeyboardKeyLayoutStyleable[remoteIndex]);
        setDataFromTypedArray(parent, keyboardDimens, askResources, a, remoteIndex, localAttrId);
      }
      externalResourcePopupLayout = popupResId != 0;
      if (codes == null && !TextUtils.isEmpty(label)) {
        codes = new int[] {label.charAt(0)};
      }
      a.recycle();
    }
 public Row(Context askContext, Resources res, Keyboard parent, XmlResourceParser parser) {
   this.parent = parent;
   // some defaults
   defaultWidth = parent.mDefaultWidth;
   defaultHeightCode = parent.mDefaultHeightCode;
   defaultHorizontalGap = parent.mDefaultHorizontalGap;
   verticalGap = parent.getVerticalGap();
   // now reading from the XML
   SparseIntArray attributeIdMap = parent.attributeIdMap;
   int[] remoteKeyboardLayoutStyleable = parent.remoteKeyboardLayoutStyleable;
   TypedArray a =
       res.obtainAttributes(Xml.asAttributeSet(parser), remoteKeyboardLayoutStyleable);
   int n = a.getIndexCount();
   for (int i = 0; i < n; i++) {
     final int remoteIndex = a.getIndex(i);
     final int localAttrId = attributeIdMap.get(remoteKeyboardLayoutStyleable[remoteIndex]);
     try {
       switch (localAttrId) {
         case android.R.attr.keyWidth:
           defaultWidth =
               getDimensionOrFraction(
                   a, remoteIndex, parent.mDisplayWidth, parent.mDefaultWidth);
           break;
         case android.R.attr.keyHeight:
           defaultHeightCode = getKeyHeightCode(a, remoteIndex, parent.mDefaultHeightCode);
           break;
         case android.R.attr.horizontalGap:
           defaultHorizontalGap =
               getDimensionOrFraction(
                   a, remoteIndex, parent.mDisplayWidth, parent.mDefaultHorizontalGap);
           break;
       }
     } catch (Exception e) {
       Log.w(TAG, "Failed to set data from XML!", e);
     }
   }
   a.recycle();
   int[] remoteKeyboardRowLayoutStyleable = parent.remoteKeyboardRowLayoutStyleable;
   a = res.obtainAttributes(Xml.asAttributeSet(parser), remoteKeyboardRowLayoutStyleable);
   n = a.getIndexCount();
   for (int i = 0; i < n; i++) {
     final int remoteIndex = a.getIndex(i);
     final int localAttrId = attributeIdMap.get(remoteKeyboardRowLayoutStyleable[remoteIndex]);
     try {
       switch (localAttrId) {
         case android.R.attr.rowEdgeFlags:
           rowEdgeFlags = a.getInt(remoteIndex, 0);
           break;
         case android.R.attr.keyboardMode:
           mode = a.getResourceId(remoteIndex, 0);
           break;
       }
     } catch (Exception e) {
       Log.w(TAG, "Failed to set data from XML!", e);
     }
   }
   a.recycle();
 }
Example #5
0
  public SlidingMenu(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    mScreenWidth = ScreenUtils.getScreenWidth(context);
    speed = ScreenUtils.dip2px(context, SLIDING_SPEED);

    TypedArray a =
        context.getTheme().obtainStyledAttributes(attrs, R.styleable.SlidingMenu, defStyle, 0);
    int n = a.getIndexCount();
    for (int i = 0; i < n; i++) {
      int attr = a.getIndex(i);
      switch (attr) {
        case R.styleable.SlidingMenu_rightPadding:
          // 默认75
          mMenuRightPadding =
              a.getDimensionPixelSize(
                  attr,
                  (int)
                      TypedValue.applyDimension(
                          TypedValue.COMPLEX_UNIT_DIP,
                          75f,
                          getResources().getDisplayMetrics())); // 默认为10DP
          break;
      }
    }
    a.recycle();
  }
 public VDVideoResolutionListButton(Context context, AttributeSet attrs) {
   super(context, attrs);
   // 自定义背景
   TypedArray typedArr =
       context.obtainStyledAttributes(attrs, new int[] {android.R.attr.background});
   int background = R.drawable.quality_bg;
   if (typedArr != null) {
     int res = typedArr.getResourceId(0, -1);
     if (res != -1) {
       background = res;
     }
     typedArr.recycle();
   }
   setBackgroundResource(background);
   // 自定义属性部分
   typedArr = context.obtainStyledAttributes(attrs, R.styleable.VDVideoResolutionListButton);
   if (typedArr != null) {
     for (int i = 0; i < typedArr.getIndexCount(); i++) {
       if (typedArr.getIndex(i) == R.styleable.VDVideoResolutionListButton_resolutionTag) {
         mResolutionIndex = typedArr.getInt(i, -1);
       }
     }
     typedArr.recycle();
   }
   init(context);
 }
 private void initAttrs(Context context, AttributeSet attrs) {
   TypedArray typedArray = context.obtainStyledAttributes(attrs, getAttrs());
   final int N = typedArray.getIndexCount();
   for (int i = 0; i < N; i++) {
     initAttr(typedArray.getIndex(i), typedArray);
   }
   typedArray.recycle();
 }
Example #8
0
 private void initView(Context context, AttributeSet attrs) {
   // 设置为可点击的
   setClickable(true);
   if (attrs != null) {
     float scale = context.getResources().getDisplayMetrics().density;
     TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PengRadioButton);
     int count = a.getIndexCount();
     for (int i = 0; i < count; i++) {
       int attr = a.getIndex(i);
       switch (attr) {
         case R.styleable.PengRadioButton_peng_drawableBottom:
           drawableBottom = a.getDrawable(attr);
           break;
         case R.styleable.PengRadioButton_peng_drawableTop:
           drawableTop = a.getDrawable(attr);
           break;
         case R.styleable.PengRadioButton_peng_drawableLeft:
           drawableLeft = a.getDrawable(attr);
           break;
         case R.styleable.PengRadioButton_peng_drawableRight:
           drawableRight = a.getDrawable(attr);
           break;
         case R.styleable.PengRadioButton_peng_drawableTopWith:
           mTopWith = (int) (a.getDimension(attr, 20) * scale + 0.5f);
           break;
         case R.styleable.PengRadioButton_peng_drawableTopHeight:
           mTopHeight = (int) (a.getDimension(attr, 20) * scale + 0.5f);
           break;
         case R.styleable.PengRadioButton_peng_drawableBottomWith:
           mBottomWith = (int) (a.getDimension(attr, 20) * scale + 0.5f);
           break;
         case R.styleable.PengRadioButton_peng_drawableBottomHeight:
           mBottomHeight = (int) (a.getDimension(attr, 20) * scale + 0.5f);
           break;
         case R.styleable.PengRadioButton_peng_drawableRightWith:
           mRightWith = (int) (a.getDimension(attr, 20) * scale + 0.5f);
           break;
         case R.styleable.PengRadioButton_peng_drawableRightHeight:
           mRightHeight = (int) (a.getDimension(attr, 20) * scale + 0.5f);
           break;
         case R.styleable.PengRadioButton_peng_drawableLeftWith:
           mLeftWith = (int) (a.getDimension(attr, 20) * scale + 0.5f);
           break;
         case R.styleable.PengRadioButton_peng_drawableLeftHeight:
           mLeftHeight = (int) (a.getDimension(attr, 20) * scale + 0.5f);
           break;
         default:
           break;
       }
     }
     a.recycle();
     setCompoundDrawablesWithIntrinsicBounds(
         drawableLeft, drawableTop, drawableRight, drawableBottom);
   }
 }
 private boolean getLeftFromAttrs(Context context, AttributeSet attrs) {
   TypedArray typedArray =
       context.obtainStyledAttributes(attrs, R.styleable.lcim_chat_play_button);
   boolean left = true;
   for (int i = 0; i < typedArray.getIndexCount(); i++) {
     int attr = typedArray.getIndex(i);
     if (attr == R.styleable.lcim_chat_play_button_left) {
       left = typedArray.getBoolean(attr, true);
     }
   }
   return left;
 }
Example #10
0
 public LCalendarView(Context context, AttributeSet attrs, int defStyleAttr) {
   super(context, attrs, defStyleAttr);
   days = new int[42];
   year = 2015;
   month = 9;
   today = 0;
   textSize = 0;
   textY = 0;
   selectColor = Color.parseColor("#99c9f2");
   textColor = Color.BLACK;
   weekColor = Color.GRAY;
   backgroundColor = Color.parseColor("#50EEEEEE");
   todayColor = Color.parseColor("#50000000");
   /** 获得我们所定义的自定义样式属性 */
   TypedArray a =
       context.getTheme().obtainStyledAttributes(attrs, R.styleable.calendarview, defStyleAttr, 0);
   int n = a.getIndexCount();
   for (int i = 0; i < n; i++) {
     int attr = a.getIndex(i);
     switch (attr) {
       case R.styleable.calendarview_background_color:
         backgroundColor = a.getColor(attr, Color.parseColor("#ebebeb"));
         break;
       case R.styleable.calendarview_month:
         month = a.getInt(attr, 0);
         break;
       case R.styleable.calendarview_selected:
         selectedDay = a.getInt(attr, 0);
         break;
       case R.styleable.calendarview_selected_color:
         selectColor = a.getColor(attr, Color.parseColor("#99c9f2"));
         break;
       case R.styleable.calendarview_today:
         today = a.getInt(attr, 0);
         break;
       case R.styleable.calendarview_text_color:
         textColor = a.getColor(attr, Color.BLACK);
         break;
       case R.styleable.calendarview_today_color:
         todayColor = a.getColor(attr, Color.parseColor("#50000000"));
         break;
       case R.styleable.calendarview_weeks_color:
         weekColor = a.getColor(attr, Color.GRAY);
         break;
       case R.styleable.calendarview_year:
         year = a.getColor(attr, 0);
         break;
     }
   }
   a.recycle();
   init();
   initPaint();
 }
 public DraggableFlagView(Context context, AttributeSet attrs) {
   super(context, attrs);
   TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DraggableFlagView);
   int indexCount = a.getIndexCount();
   for (int i = 0; i < indexCount; i++) {
     int attrIndex = a.getIndex(i);
     if (attrIndex == R.styleable.DraggableFlagView_color) {
       patientColor = a.getColor(attrIndex, Color.RED);
     }
   }
   a.recycle();
   init(context);
 }
Example #12
0
  private void parseAttrs(Context context, AttributeSet attrs) {
    // Load from custom attributes
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.FButton);
    if (typedArray == null) return;
    for (int i = 0; i < typedArray.getIndexCount(); i++) {
      int attr = typedArray.getIndex(i);
      if (attr == R.styleable.FButton_shadowEnabled) {
        isShadowEnabled = typedArray.getBoolean(attr, true); // Default is true
      } else if (attr == R.styleable.FButton_buttonColor) {
        mButtonColor =
            typedArray.getColor(attr, getResources().getColor(R.color.fbutton_default_color));
      } else if (attr == R.styleable.FButton_shadowColor) {
        mShadowColor =
            typedArray.getColor(
                attr, getResources().getColor(R.color.fbutton_default_shadow_color));
        isShadowColorDefined = true;
      } else if (attr == R.styleable.FButton_shadowHeight) {
        mShadowHeight =
            typedArray.getDimensionPixelSize(attr, R.dimen.fbutton_default_shadow_height);
      } else if (attr == R.styleable.FButton_cornerRadius) {
        mCornerRadius =
            typedArray.getDimensionPixelSize(attr, R.dimen.fbutton_default_conner_radius);
      }
    }
    typedArray.recycle();

    // Get paddingLeft, paddingRight
    int[] attrsArray =
        new int[] {
          android.R.attr.paddingLeft, // 0
          android.R.attr.paddingRight, // 1
        };
    TypedArray ta = context.obtainStyledAttributes(attrs, attrsArray);
    if (ta == null) return;
    mPaddingLeft = ta.getDimensionPixelSize(0, 0);
    mPaddingRight = ta.getDimensionPixelSize(1, 0);
    ta.recycle();

    // Get paddingTop, paddingBottom
    int[] attrsArray2 =
        new int[] {
          android.R.attr.paddingTop, // 0
          android.R.attr.paddingBottom, // 1
        };
    TypedArray ta1 = context.obtainStyledAttributes(attrs, attrsArray2);
    if (ta1 == null) return;
    mPaddingTop = ta1.getDimensionPixelSize(0, 0);
    mPaddingBottom = ta1.getDimensionPixelSize(1, 0);
    ta1.recycle();
  }
  public ShadowView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    TypedArray a =
        context.getTheme().obtainStyledAttributes(attrs, R.styleable.ShadowView, defStyleAttr, 0);
    int n = a.getIndexCount();
    for (int i = 0; i < n; i++) {
      int attr = a.getIndex(i);
      switch (attr) {
        case R.styleable.ShadowView_sv_text:
          text = a.getString(attr);
          break;
        case R.styleable.ShadowView_sv_textColor:
          textColor = a.getColor(attr, Color.BLACK);
          break;
        case R.styleable.ShadowView_sv_textSize:
          textSize =
              a.getDimensionPixelSize(
                  attr,
                  (int)
                      TypedValue.applyDimension(
                          TypedValue.COMPLEX_UNIT_SP, 16, getResources().getDisplayMetrics()));
          break;
        case R.styleable.ShadowView_sv_shadowColor:
          shadowColor = a.getColor(attr, Color.BLACK);
          break;
        case R.styleable.ShadowView_sv_shadowSize:
          shadowSize =
              a.getDimensionPixelSize(
                  attr,
                  (int)
                      TypedValue.applyDimension(
                          TypedValue.COMPLEX_UNIT_DIP, 0, getResources().getDisplayMetrics()));
          break;
        case R.styleable.ShadowView_sv_direction:
          shadowDirection = a.getInt(attr, RIGHTBOTTOM);
          break;
      }
    }
    a.recycle();

    paint = new Paint();
    paint.setTextSize(textSize);
    paint.setFakeBoldText(true);
    paint.setColor(textColor);
    textBound = new Rect();
    paint.getTextBounds(text, 0, text.length(), textBound);
    calcShadow();
  }
Example #14
0
  public TypefaceHelper(Context context, AttributeSet attrs) {
    this.context = context;
    this.typefaceName = null;

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CustomTextView);
    for (int i = 0; i < a.getIndexCount(); i++) {
      int attr = a.getIndex(i);
      switch (attr) {
        case R.styleable.CustomTextView_typeface:
          this.typefaceName = a.getString(attr);
          break;
      }
    }
    a.recycle();
  }
Example #15
0
  /** Default constructor */
  public BlurLinearLayout(Context context, AttributeSet attrs) {
    super(context, attrs);

    mBlurRenderer = new BlurRenderer(this);

    // Read blur radius from the layout parameters
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.BlurView);
    for (int i = 0; i < a.getIndexCount(); ++i) {
      int attr = a.getIndex(i);
      if (attr == R.styleable.BlurView_radius) {
        int radius = a.getDimensionPixelSize(attr, 1);
        mBlurRenderer.setBlurRadius(radius);
      }
    }
    a.recycle();
  }
Example #16
0
  public ScaledLinearLayout(Context context, AttributeSet attrs) {
    super(context, attrs);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ScaledLinearLayout);
    final int N = a.getIndexCount();
    for (int i = 0; i < N; ++i) {
      int attr = a.getIndex(i);
      switch (attr) {
        case R.styleable.ScaledLinearLayout_linear_layout_ratio:
          float styleableRatio = a.getFloat(attr, widthRatio);
          widthRatio = styleableRatio;
          break;
      }
    }
    a.recycle();
  }
Example #17
0
  private void initHorizontalScrollView(AttributeSet attrs, int defStyleAttr) {
    final ViewConfiguration configuration = ViewConfiguration.get(getContext());
    mTouchSlop = configuration.getScaledTouchSlop();

    TypedArray a =
        getContext()
            .obtainStyledAttributes(attrs, R.styleable.HorizontalScrollView, defStyleAttr, 0);
    for (int i = 0; i < a.getIndexCount(); i++) {
      int attr = a.getIndex(i);
      if (attr == R.styleable.HorizontalScrollView_carbon_overScroll) {
        setOverScrollMode(a.getInt(attr, OVER_SCROLL_ALWAYS));
      }
    }
    a.recycle();

    Carbon.initTint(this, attrs, defStyleAttr);
  }
  public ListItemView(Context context, AttributeSet attrs) {
    super(context, attrs);
    sharedConstructor(context);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ListItemView);

    final int N = a.getIndexCount();
    for (int i = 0; i < N; ++i) {
      int attr = a.getIndex(i);
      switch (attr) {
        case R.styleable.ListItemView_text:
          String text = a.getString(attr);
          textView.setText(text);
          break;
      }
    }
    a.recycle();
  }
Example #19
0
 private void init(Context context, AttributeSet attrs, int defStyle) {
   TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.TabTextView, defStyle, 0);
   if (array != null) {
     int count = array.getIndexCount();
     int index = 0;
     for (int i = 0; i < count; i++) {
       index = array.getIndex(i);
       switch (index) {
         case R.styleable.TabTextView_bottom_height:
           bottomHeight = array.getDimensionPixelSize(index, -1);
           break;
         case R.styleable.TabTextView_bottom_width:
           bottomWidth = array.getDimensionPixelSize(index, -1);
           break;
         case R.styleable.TabTextView_left_height:
           leftHeight = array.getDimensionPixelSize(index, -1);
           break;
         case R.styleable.TabTextView_left_width:
           leftWidth = array.getDimensionPixelSize(index, -1);
           break;
         case R.styleable.TabTextView_right_height:
           rightHeight = array.getDimensionPixelSize(index, -1);
           break;
         case R.styleable.TabTextView_right_width2:
           rightWidth = array.getDimensionPixelSize(index, -1);
           break;
         case R.styleable.TabTextView_top_height:
           topHeight = array.getDimensionPixelSize(index, -1);
           break;
         case R.styleable.TabTextView_top_width:
           topWidth = array.getDimensionPixelSize(index, -1);
           break;
       }
     }
     Drawable[] drawables = getCompoundDrawables();
     int dir = 0;
     // 0-left; 1-top; 2-right; 3-bottom;
     for (Drawable drawable : drawables) {
       // 设定图片大小
       setImageSize(drawable, dir++);
     }
     setCompoundDrawables(drawables[0], drawables[1], drawables[2], drawables[3]);
   }
   array.recycle();
 }
Example #20
0
 /** 3个参数的构造函数 */
 @TargetApi(Build.VERSION_CODES.HONEYCOMB)
 public RevealLayout(Context context, AttributeSet attrs, int defStyleAttr) {
   super(context, attrs, defStyleAttr);
   TypedArray a =
       context.getTheme().obtainStyledAttributes(attrs, R.styleable.RevealLayout, defStyleAttr, 0);
   int n = a.getIndexCount();
   for (int i = 0; i < n; i++) {
     int attr = a.getIndex(i);
     switch (attr) {
       case R.styleable.RevealLayout_ReavelColor:
         mReavelColor = a.getColor(attr, getResources().getColor(R.color.reveal_color));
         break;
     }
   }
   a.recycle();
   /** 视图的初始化 */
   init();
 }
Example #21
0
  public ViewPager(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs);
    super.setOnPageChangeListener(internalOnPageChangeListener);

    final ViewConfiguration configuration = ViewConfiguration.get(getContext());
    mTouchSlop = configuration.getScaledTouchSlop();

    TypedArray a =
        getContext().obtainStyledAttributes(attrs, R.styleable.ViewPager, defStyleAttr, 0);
    for (int i = 0; i < a.getIndexCount(); i++) {
      int attr = a.getIndex(i);
      if (attr == R.styleable.ViewPager_carbon_overScroll) {
        setOverScrollMode(a.getInt(attr, OVER_SCROLL_ALWAYS));
      }
    }
    a.recycle();

    Carbon.initTint(this, attrs, defStyleAttr);
  }
Example #22
0
  /**
   * @param context
   * @param attrs
   * @param defStyleAttr 自定义VIEW
   */
  public RandomInt(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    TypedArray arr = context.obtainStyledAttributes(attrs, R.styleable.RandomInt, defStyleAttr, 0);
    int count = arr.getIndexCount();
    for (int i = 0; i < count; i++) {
      int index = arr.getIndex(i);
      switch (index) {
        case R.styleable.RandomInt_myInt:
          this.mInt = arr.getString(index);
          break;
        case R.styleable.RandomInt_myBgColor:
          this.mBgColor = arr.getColor(index, Color.RED);
          break;
        case R.styleable.RandomInt_myTextColor:
          this.mTextColor = arr.getColor(index, Color.GREEN);
          break;
        case R.styleable.RandomInt_myTextSize:
          this.mTextSize =
              arr.getDimensionPixelSize(
                  index,
                  (int)
                      TypedValue.applyDimension(
                          TypedValue.COMPLEX_UNIT_SP, 16, getResources().getDisplayMetrics()));
          break;

        default:
          break;
      }
    }
    arr.recycle();
    mPaint = new Paint();
    mPaint.setTextSize(mTextSize);
    mBound = new Rect();
    mPaint.getTextBounds(mInt, 0, mInt.length(), mBound);
    this.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            todo();
          }
        });
  }
Example #23
0
  public CustomView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    Log.v(TAG, "--bin--3--");
    TypedArray typeArr =
        context.getTheme().obtainStyledAttributes(attrs, R.styleable.customStyle, defStyleAttr, 0);
    int indexCount = typeArr.getIndexCount();
    for (int i = 0; i < indexCount; i++) {
      int arr = typeArr.getIndex(i);
      switch (arr) {
        case R.styleable.customStyle_titleColor:
          this.mTitleColor = typeArr.getColor(arr, Color.BLACK);
          break;
        case R.styleable.customStyle_titleSize:
          this.mTitleSize =
              typeArr.getDimensionPixelSize(
                  arr,
                  (int)
                      TypedValue.applyDimension(
                          TypedValue.COMPLEX_UNIT_SP, 16, getResources().getDisplayMetrics()));
          break;
        case R.styleable.customStyle_titleText:
          this.mTitleText = typeArr.getString(arr);
          break;
      }
    }

    typeArr.recycle();

    mPaint = new Paint();
    mPaint.setTextSize(mTitleSize);
    mBound = new Rect();
    mPaint.getTextBounds(mTitleText, 0, mTitleText.length(), mBound);

    setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View view) {
            mTitleText = randomText();
            mPaint.setColor(Color.YELLOW);
            postInvalidate();
          }
        });
  }
Example #24
0
  private void parseKeyboardAttributes(
      Context askContext, Resources res, XmlResourceParser parser) {
    TypedArray a = res.obtainAttributes(Xml.asAttributeSet(parser), remoteKeyboardLayoutStyleable);
    Resources askRes = askContext.getResources();
    // some defaults
    mDefaultWidth = mDisplayWidth / 10;
    mDefaultHeightCode = -1;
    mDefaultHorizontalGap = 0;
    mDefaultVerticalGap = askRes.getDimensionPixelOffset(R.dimen.default_key_vertical_gap);
    // now reading from XML
    int n = a.getIndexCount();
    for (int i = 0; i < n; i++) {
      final int remoteIndex = a.getIndex(i);
      final int localAttrId = attributeIdMap.get(remoteKeyboardLayoutStyleable[remoteIndex]);
      try {
        switch (localAttrId) {
          case android.R.attr.keyWidth:
            mDefaultWidth =
                getDimensionOrFraction(a, remoteIndex, mDisplayWidth, mDisplayWidth / 10);
            break;
          case android.R.attr.keyHeight:
            mDefaultHeightCode = getKeyHeightCode(a, remoteIndex, -1);
            break;
          case android.R.attr.horizontalGap:
            mDefaultHorizontalGap = getDimensionOrFraction(a, remoteIndex, mDisplayWidth, 0);
            break;
          case android.R.attr.verticalGap:
            mDefaultVerticalGap =
                getDimensionOrFraction(a, remoteIndex, mDisplayWidth, mDefaultVerticalGap);
            break;
        }
      } catch (Exception e) {
        Log.w(TAG, "Failed to set data from XML!", e);
      }
    }
    a.recycle();

    mProximityThreshold = (int) (mDefaultWidth * SEARCH_DISTANCE);
    // Square it for comparison
    mProximityThreshold = mProximityThreshold * mProximityThreshold;
  }
  public StickyGridHeadersGridView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    super.setOnScrollListener(this);
    setVerticalFadingEdgeEnabled(false);

    if (!mNumColumnsSet) {
      mNumColumns = AUTO_FIT;
    }

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.StickyGridHeadersGridView);
    for (int i = 0; i < a.getIndexCount(); i++) {
      final int attr = a.getIndex(i);
      if (attr == R.styleable.StickyGridHeadersGridView_areHeadersSticky) {
        mAreHeadersSticky = a.getBoolean(attr, true);
      }
    }
    a.recycle();

    ViewConfiguration vc = ViewConfiguration.get(context);
    mTouchSlop = vc.getScaledTouchSlop();
  }
  /**
   * @param context
   * @param attrs
   * @param defStyleAttr
   */
  private void init(Context context, AttributeSet attrs, int defStyleAttr) {
    mNestedScrollingParentHelper = new NestedScrollingParentHelper(this);

    mNestedScrollingChildHelper = new NestedScrollingChildHelper(this);
    setNestedScrollingEnabled(true);
    mScroller = new Scroller(context, new DecelerateInterpolator());
    TypedArray a =
        context.obtainStyledAttributes(attrs, R.styleable.AbsRefreshLayout, defStyleAttr, 0);
    final int N = a.getIndexCount();
    int resFooter = R.layout.layout_loadmore;
    for (int i = 0; i < N; i++) {
      int attr = a.getIndex(i);
      if (attr == R.styleable.AbsRefreshLayout_footerNestLayout) {
        resFooter = a.getInt(attr, resFooter);
        break;
      }
    }
    a.recycle();
    /** Convert values in dp to values in px; */
    setFooterView(inflate(context, resFooter, null));
  }
  /**
   * 初始化自定义属性值
   *
   * @param context
   * @param attrs
   */
  public ChangeColorIconWithTextView(Context context, AttributeSet attrs) {
    super(context, attrs);

    // 获取设置的图标
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ChangeColorIconViewWX);

    int n = a.getIndexCount();
    for (int i = 0; i < n; i++) {

      int attr = a.getIndex(i);
      switch (attr) {
        case R.styleable.ChangeColorIconViewWX_icon_wx:
          BitmapDrawable drawable = (BitmapDrawable) a.getDrawable(attr);
          mIconBitmap = drawable.getBitmap();
          break;
        case R.styleable.ChangeColorIconViewWX_color_wx:
          mColor = a.getColor(attr, 0x45C01A);
          break;
        case R.styleable.ChangeColorIconViewWX_text_wx:
          mText = a.getString(attr);
          break;
        case R.styleable.ChangeColorIconViewWX_text_size_wx:
          mTextSize =
              (int)
                  a.getDimension(
                      attr,
                      TypedValue.applyDimension(
                          TypedValue.COMPLEX_UNIT_SP, 10, getResources().getDisplayMetrics()));
          break;
      }
    }

    a.recycle();
    mTextPaint = new Paint();
    mTextPaint.setTextSize(mTextSize);
    mTextPaint.setTypeface(BaseApplication.xiyuanTypeface);
    mTextPaint.setColor(0xff555555);
    // 得到text绘制范围
    mTextPaint.getTextBounds(mText, 0, mText.length(), mTextBound);
  }
  public CustomVolumControlBar(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    TypedArray a =
        context
            .getTheme()
            .obtainStyledAttributes(attrs, R.styleable.CustomVolumControlBar, defStyleAttr, 0);
    int n = a.getIndexCount();

    for (int i = 0; i < n; i++) {
      int attr = a.getIndex(i);
      switch (attr) {
        case R.styleable.CustomVolumControlBar_firstColor:
          mFirstColor = a.getColor(attr, Color.GREEN);
          break;
        case R.styleable.CustomVolumControlBar_secondColor:
          mSecondColor = a.getColor(attr, Color.CYAN);
          break;
        case R.styleable.CustomVolumControlBar_bg:
          mImage = BitmapFactory.decodeResource(getResources(), a.getResourceId(attr, 0));
          break;
        case R.styleable.CustomVolumControlBar_circleWidth:
          mCircleWidth =
              a.getDimensionPixelSize(
                  attr,
                  (int)
                      TypedValue.applyDimension(
                          TypedValue.COMPLEX_UNIT_PX, 20, getResources().getDisplayMetrics()));
          break;
        case R.styleable.CustomVolumControlBar_dotCount:
          mCount = a.getInt(attr, 20); // 默认20
          break;
        case R.styleable.CustomVolumControlBar_splitSize:
          mSplitSize = a.getInt(attr, 20);
          break;
      }
    }
    a.recycle();
    mPaint = new Paint();
    mRect = new Rect();
  }
  private void init(Context context, AttributeSet attrs) {
    mContext = context;

    // default value
    mOverlayColor = DEFAULT_COLOR;
    mRevealSize = DEFAULT_REVEAL_SIZE;

    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.WScratchView, 0, 0);

    final int indexCount = ta.getIndexCount();
    for (int i = 0; i < indexCount; i++) {
      int attr = ta.getIndex(i);
      switch (attr) {
        case R.styleable.WScratchView_overlayColor:
          mOverlayColor = ta.getColor(attr, DEFAULT_COLOR);
          break;
        case R.styleable.WScratchView_revealSize:
          mRevealSize = ta.getDimensionPixelSize(attr, DEFAULT_REVEAL_SIZE);
          break;
        case R.styleable.WScratchView_antiAlias:
          mIsAntiAlias = ta.getBoolean(attr, false);
          break;
        case R.styleable.WScratchView_scratchable:
          mIsScratchable = ta.getBoolean(attr, true);
          break;
      }
    }

    setZOrderOnTop(true);
    SurfaceHolder holder = getHolder();
    holder.addCallback(this);
    holder.setFormat(PixelFormat.TRANSPARENT);

    mOverlayPaint = new Paint();
    mOverlayPaint.setXfermode(new PorterDuffXfermode(Mode.CLEAR));
    mOverlayPaint.setStyle(Paint.Style.STROKE);
    mOverlayPaint.setStrokeCap(Paint.Cap.ROUND);
    mOverlayPaint.setStrokeJoin(Paint.Join.ROUND);
  }
 public GestureLockViewGroup(Context context, AttributeSet attrs, int defStyleAttr) {
   super(context, attrs, defStyleAttr);
   // 获取自定义参数
   TypedArray typedArray =
       context
           .getTheme()
           .obtainStyledAttributes(attrs, R.styleable.GestureLockViewGroup, defStyleAttr, 0);
   int count = typedArray.getIndexCount();
   for (int i = 0; i < count; i++) {
     int index = typedArray.getIndex(i);
     switch (index) {
       case R.styleable.GestureLockViewGroup_color_no_finger_inner_circle: // 未被触摸状态内圓颜色
         mNoFingerInnerCircleColor = typedArray.getColor(index, mNoFingerInnerCircleColor);
         break;
       case R.styleable.GestureLockViewGroup_color_no_finger_outer_circle: // 未被触摸状态外圆颜色
         mNoFingerOuterCircleColor = typedArray.getColor(index, mNoFingerOuterCircleColor);
         break;
       case R.styleable.GestureLockViewGroup_color_finger_on: // 触摸状态下颜色
         mFingerOnColor = typedArray.getColor(index, mFingerOnColor);
         break;
       case R.styleable.GestureLockViewGroup_color_finger_up: // 呈现结果颜色
         mFingerUpColor = typedArray.getColor(index, mFingerUpColor);
         break;
       case R.styleable.GestureLockViewGroup_count: // 个数
         mCount = typedArray.getInt(index, 3);
         break;
       case R.styleable.GestureLockViewGroup_tryTimes: // 尝试次数
         mTryTimes = typedArray.getInt(index, 5);
         break;
     }
   }
   typedArray.recycle();
   // 初始化画笔
   mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
   mPaint.setStyle(Paint.Style.STROKE);
   mPaint.setStrokeCap(Paint.Cap.ROUND); // 起始点
   mPaint.setStrokeJoin(Paint.Join.ROUND); // 连接点
   mPath = new Path();
 }