public ListPreference(Context context, AttributeSet attrs) {
    super(context, attrs);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ListPreference, 0, 0);

    mKey = Util.checkNotNull(a.getString(R.styleable.ListPreference_key));

    // We allow the defaultValue attribute to be a string or an array of
    // strings. The reason we need multiple default values is that some
    // of them may be unsupported on a specific platform (for example,
    // continuous auto-focus). In that case the first supported value
    // in the array will be used.
    int attrDefaultValue = R.styleable.ListPreference_defaultValue;
    TypedValue tv = a.peekValue(attrDefaultValue);
    if (tv != null && tv.type == TypedValue.TYPE_REFERENCE) {
      mDefaultValues = a.getTextArray(attrDefaultValue);
    } else {
      mDefaultValues = new CharSequence[1];
      mDefaultValues[0] = a.getString(attrDefaultValue);
    }

    setEntries(a.getTextArray(R.styleable.ListPreference_entries));
    setEntryValues(a.getTextArray(R.styleable.ListPreference_entryValues));
    a.recycle();
  }
  /**
   * * Creates a new grid layout animation controller from external resources.
   *
   * @param context the Context the view group is running in, through which it can access the
   *     resources
   * @param attrs the attributes of the XML tag that is inflating the layout animation controller
   */
  public GridLayoutAnimationController(Context context, AttributeSet attrs) {
    super(context, attrs);

    TypedArray a =
        context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.GridLayoutAnimation);

    Animation.Description d =
        Animation.Description.parseValue(
            a.peekValue(com.android.internal.R.styleable.GridLayoutAnimation_columnDelay));
    mColumnDelay = d.value;
    d =
        Animation.Description.parseValue(
            a.peekValue(com.android.internal.R.styleable.GridLayoutAnimation_rowDelay));
    mRowDelay = d.value;
    //noinspection PointlessBitwiseExpression
    mDirection =
        a.getInt(
            com.android.internal.R.styleable.GridLayoutAnimation_direction,
            DIRECTION_LEFT_TO_RIGHT | DIRECTION_TOP_TO_BOTTOM);
    mDirectionPriority =
        a.getInt(
            com.android.internal.R.styleable.GridLayoutAnimation_directionPriority, PRIORITY_NONE);

    a.recycle();
  }
 public static int getType(TypedArray array, int index) {
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) return array.getType(index);
   else {
     TypedValue value = array.peekValue(index);
     return value == null ? TypedValue.TYPE_NULL : value.type;
   }
 }
  /** Provide the default value to the system */
  @Override
  protected Object onGetDefaultValue(TypedArray a, int index) {
    TypedValue value = a.peekValue(index);

    if (value.type == TypedValue.TYPE_STRING && value.string.charAt(0) == '#')
      return Color.parseColor(value.string.toString());

    return a.getColor(index, mDefaultValue);
  }
示例#5
0
  public Rotate3dAnimation(Context context, AttributeSet attrs) {
    super(context, attrs);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Rotate3dAnimation);

    mFromDegrees = a.getFloat(R.styleable.Rotate3dAnimation_fromDeg, 0.0f);
    mToDegrees = a.getFloat(R.styleable.Rotate3dAnimation_toDeg, 0.0f);
    mRollType = a.getInt(R.styleable.Rotate3dAnimation_rollType, ROLL_BY_X);
    Description d = parseValue(a.peekValue(R.styleable.Rotate3dAnimation_pivotX));
    mPivotXType = d.type;
    mPivotXValue = d.value;

    d = parseValue(a.peekValue(R.styleable.Rotate3dAnimation_pivotY));
    mPivotYType = d.type;
    mPivotYValue = d.value;

    a.recycle();

    initializePivotPoint();
  }
示例#6
0
 static int getDimensionOrFraction(TypedArray a, int index, int base, int defValue) {
   TypedValue value = a.peekValue(index);
   if (value == null) return defValue;
   if (value.type == TypedValue.TYPE_DIMENSION) {
     return a.getDimensionPixelOffset(index, defValue);
   } else if (value.type == TypedValue.TYPE_FRACTION) {
     // Round it to avoid values like 47.9999 from getting truncated
     return Math.round(a.getFraction(index, base, base, defValue));
   }
   return defValue;
 }
示例#7
0
 private ArrayList<TargetDrawable> loadDrawableArray(int resourceId) {
   Resources res = getContext().getResources();
   TypedArray array = res.obtainTypedArray(resourceId);
   final int count = array.length();
   ArrayList<TargetDrawable> drawables = new ArrayList<TargetDrawable>(count);
   for (int i = 0; i < count; i++) {
     TypedValue value = array.peekValue(i);
     TargetDrawable target = new TargetDrawable(res, value != null ? value.resourceId : 0, 3);
     drawables.add(target);
   }
   array.recycle();
   return drawables;
 }
  @SuppressWarnings("unchecked")
  private T extractNumericValueFromAttributes(TypedArray a, int attribute, int defaultValue) {
    TypedValue tv = a.peekValue(attribute);
    if (tv == null) {
      return (T) Integer.valueOf(defaultValue);
    }

    int type = tv.type;
    if (type == TypedValue.TYPE_FLOAT) {
      return (T) Float.valueOf(a.getFloat(attribute, defaultValue));
    } else {
      return (T) Integer.valueOf(a.getInteger(attribute, defaultValue));
    }
  }
示例#9
0
 protected static int getKeyHeightCode(TypedArray a, int remoteIndex, int defaultHeightCode) {
   TypedValue value = a.peekValue(remoteIndex);
   if (value == null) {
     // means that it was not provided. So I take my parent's
     return defaultHeightCode;
   } else if (value.type >= TypedValue.TYPE_FIRST_INT
       && value.type <= TypedValue.TYPE_LAST_INT
       && value.data <= 0
       && value.data >= -3) {
     return value.data;
   } else {
     Log.w(TAG, "Key height attribute is incorrectly set! Defaulting to regular height.");
     return -1;
   }
 }
示例#10
0
 private static boolean matchTypedValue(
     final TypedArray a, final int index, final int intValue, final String strValue) {
   // If <case> does not have "index" attribute, that means this <case> is wild-card for
   // the attribute.
   final TypedValue v = a.peekValue(index);
   if (v == null) {
     return true;
   }
   if (ResourceUtils.isIntegerValue(v)) {
     return intValue == a.getInt(index, 0);
   }
   if (ResourceUtils.isStringValue(v)) {
     return StringUtils.containsInArray(strValue, a.getString(index).split("\\|"));
   }
   return false;
 }
示例#11
0
 private int getResourceId(TypedArray a, int id) {
   TypedValue tv = a.peekValue(id);
   return tv == null ? 0 : tv.resourceId;
 }
示例#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
  @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
  private void applyStyle(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    TypedArray a =
        context.obtainStyledAttributes(attrs, R.styleable.SnackBar, defStyleAttr, defStyleRes);

    int backgroundColor = a.getColor(R.styleable.SnackBar_sb_backgroundColor, 0xFF323232);
    int backgroundRadius =
        a.getDimensionPixelSize(R.styleable.SnackBar_sb_backgroundCornerRadius, 0);
    int horizontalPadding =
        a.getDimensionPixelSize(
            R.styleable.SnackBar_sb_horizontalPadding, ThemeUtil.dpToPx(context, 24));
    int verticalPadding = a.getDimensionPixelSize(R.styleable.SnackBar_sb_verticalPadding, 0);
    TypedValue value = a.peekValue(R.styleable.SnackBar_sb_width);
    if (value != null && value.type == TypedValue.TYPE_INT_DEC)
      mWidth = a.getInteger(R.styleable.SnackBar_sb_width, MATCH_PARENT);
    else mWidth = a.getDimensionPixelSize(R.styleable.SnackBar_sb_width, MATCH_PARENT);
    int minWidth = a.getDimensionPixelSize(R.styleable.SnackBar_sb_minWidth, 0);
    int maxWidth = a.getDimensionPixelSize(R.styleable.SnackBar_sb_maxWidth, 0);
    value = a.peekValue(R.styleable.SnackBar_sb_height);
    if (value != null && value.type == TypedValue.TYPE_INT_DEC)
      mHeight = a.getInteger(R.styleable.SnackBar_sb_height, WRAP_CONTENT);
    else mHeight = a.getDimensionPixelSize(R.styleable.SnackBar_sb_height, WRAP_CONTENT);
    int minHeight = a.getDimensionPixelSize(R.styleable.SnackBar_sb_minHeight, 0);
    int maxHeight = a.getDimensionPixelSize(R.styleable.SnackBar_sb_maxHeight, 0);
    mMarginStart = a.getDimensionPixelSize(R.styleable.SnackBar_sb_marginStart, 0);
    mMarginBottom = a.getDimensionPixelSize(R.styleable.SnackBar_sb_marginBottom, 0);
    int textSize = a.getDimensionPixelSize(R.styleable.SnackBar_sb_textSize, 0);
    boolean hasTextColor = a.hasValue(R.styleable.SnackBar_sb_textColor);
    int textColor = hasTextColor ? a.getColor(R.styleable.SnackBar_sb_textColor, 0xFFFFFFFF) : 0;
    int textAppearance = a.getResourceId(R.styleable.SnackBar_sb_textAppearance, 0);
    String text = a.getString(R.styleable.SnackBar_sb_text);
    boolean singleLine = a.getBoolean(R.styleable.SnackBar_sb_singleLine, true);
    int maxLines = a.getInteger(R.styleable.SnackBar_sb_maxLines, 0);
    int lines = a.getInteger(R.styleable.SnackBar_sb_lines, 0);
    int ellipsize = a.getInteger(R.styleable.SnackBar_sb_ellipsize, 0);
    int actionTextSize = a.getDimensionPixelSize(R.styleable.SnackBar_sb_actionTextSize, 0);
    ColorStateList actionTextColor;
    value = a.peekValue(R.styleable.SnackBar_sb_actionTextColor);
    if (value != null
        && value.type >= TypedValue.TYPE_FIRST_COLOR_INT
        && value.type <= TypedValue.TYPE_LAST_COLOR_INT)
      actionTextColor =
          ColorStateList.valueOf(a.getColor(R.styleable.SnackBar_sb_actionTextColor, 0xFF000000));
    else actionTextColor = a.getColorStateList(R.styleable.SnackBar_sb_actionTextColor);
    int actionTextAppearance = a.getResourceId(R.styleable.SnackBar_sb_actionTextAppearance, 0);
    String actionText = a.getString(R.styleable.SnackBar_sb_actionText);
    int actionRipple = a.getResourceId(R.styleable.SnackBar_sb_actionRipple, 0);
    int duration = a.getInteger(R.styleable.SnackBar_sb_duration, -1);
    mInAnimationId = a.getResourceId(R.styleable.SnackBar_sb_inAnimation, 0);
    mOutAnimationId = a.getResourceId(R.styleable.SnackBar_sb_outAnimation, 0);
    mRemoveOnDismiss = a.getBoolean(R.styleable.SnackBar_sb_removeOnDismiss, true);

    a.recycle();

    backgroundColor(backgroundColor).backgroundRadius(backgroundRadius);

    padding(horizontalPadding, verticalPadding);

    textAppearance(textAppearance);
    if (textSize > 0) textSize(textSize);
    if (hasTextColor) textColor(textColor);
    if (text != null) text(text);
    singleLine(singleLine);
    if (maxLines > 0) maxLines(maxLines);
    if (lines > 0) lines(lines);
    if (minWidth > 0) minWidth(minWidth);
    if (maxWidth > 0) maxWidth(maxWidth);
    if (minHeight > 0) minHeight(minHeight);
    if (maxHeight > 0) maxHeight(maxHeight);
    switch (ellipsize) {
      case 1:
        ellipsize(TruncateAt.START);
        break;
      case 2:
        ellipsize(TruncateAt.MIDDLE);
        break;
      case 3:
        ellipsize(TruncateAt.END);
        break;
      case 4:
        ellipsize(TruncateAt.MARQUEE);
        break;
      default:
        ellipsize(TruncateAt.END);
        break;
    }

    if (textAppearance != 0) actionTextAppearance(actionTextAppearance);
    if (actionTextSize > 0) actionTextSize(actionTextSize);
    if (actionTextColor != null) actionTextColor(actionTextColor);
    if (actionText != null) actionText(actionText);
    if (actionRipple != 0) actionRipple(actionRipple);
    if (duration >= 0) duration(duration);
  }
  /**
   * Parse the given XML file as a header description, adding each parsed Header into the target
   * list.
   *
   * @param resid The XML resource to load and parse.
   * @param target The list in which the parsed headers should be placed.
   */
  public void loadHeadersFromResource(int resid, List<Header> target) {
    XmlResourceParser parser = null;
    try {
      parser = getResources().getXml(resid);
      AttributeSet attrs = Xml.asAttributeSet(parser);

      int type;
      while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
          && type != XmlPullParser.START_TAG) {
        // Parse next until start tag is found
      }

      String nodeName = parser.getName();
      if (!"preference-headers".equals(nodeName)) {
        throw new RuntimeException(
            "XML document must start with <preference-headers> tag; found"
                + nodeName
                + " at "
                + parser.getPositionDescription());
      }

      Bundle curBundle = null;

      final int outerDepth = parser.getDepth();
      while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
          && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
        if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
          continue;
        }

        nodeName = parser.getName();
        if ("header".equals(nodeName)) {
          Header header = new Header();

          TypedArray sa = getResources().obtainAttributes(attrs, R.styleable.PreferenceHeader);
          header.id = sa.getResourceId(R.styleable.PreferenceHeader_id, (int) HEADER_ID_UNDEFINED);
          TypedValue tv = sa.peekValue(R.styleable.PreferenceHeader_title);
          if (tv != null && tv.type == TypedValue.TYPE_STRING) {
            if (tv.resourceId != 0) {
              header.titleRes = tv.resourceId;
            } else {
              header.title = tv.string;
            }
          }
          tv = sa.peekValue(R.styleable.PreferenceHeader_summary);
          if (tv != null && tv.type == TypedValue.TYPE_STRING) {
            if (tv.resourceId != 0) {
              header.summaryRes = tv.resourceId;
            } else {
              header.summary = tv.string;
            }
          }
          tv = sa.peekValue(R.styleable.PreferenceHeader_breadCrumbTitle);
          if (tv != null && tv.type == TypedValue.TYPE_STRING) {
            if (tv.resourceId != 0) {
              header.breadCrumbTitleRes = tv.resourceId;
            } else {
              header.breadCrumbTitle = tv.string;
            }
          }
          tv = sa.peekValue(R.styleable.PreferenceHeader_breadCrumbShortTitle);
          if (tv != null && tv.type == TypedValue.TYPE_STRING) {
            if (tv.resourceId != 0) {
              header.breadCrumbShortTitleRes = tv.resourceId;
            } else {
              header.breadCrumbShortTitle = tv.string;
            }
          }
          header.iconRes = sa.getResourceId(R.styleable.PreferenceHeader_icon, 0);
          header.fragment = sa.getString(R.styleable.PreferenceHeader_fragment);
          sa.recycle();

          if (curBundle == null) {
            curBundle = new Bundle();
          }

          final int innerDepth = parser.getDepth();
          while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
              && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
            if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
              continue;
            }

            String innerNodeName = parser.getName();
            if (innerNodeName.equals("extra")) {
              getResources().parseBundleExtra("extra", attrs, curBundle);
              XmlUtils.skipCurrentTag(parser);

            } else if (innerNodeName.equals("intent")) {
              header.intent = Intent.parseIntent(getResources(), parser, attrs);

            } else {
              XmlUtils.skipCurrentTag(parser);
            }
          }

          if (curBundle.size() > 0) {
            header.fragmentArguments = curBundle;
            curBundle = null;
          }

          target.add(header);
        } else {
          XmlUtils.skipCurrentTag(parser);
        }
      }

    } catch (XmlPullParserException e) {
      throw new RuntimeException("Error parsing headers", e);
    } catch (IOException e) {
      throw new RuntimeException("Error parsing headers", e);
    } finally {
      if (parser != null) parser.close();
    }
  }
    public Builder(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
      TypedArray a =
          context.obtainStyledAttributes(
              attrs, R.styleable.LinearProgressDrawable, defStyleAttr, defStyleRes);
      int resId;

      progressPercent(a.getFloat(R.styleable.LinearProgressDrawable_pv_progress, 0));
      secondaryProgressPercent(
          a.getFloat(R.styleable.LinearProgressDrawable_pv_secondaryProgress, 0));

      TypedValue value = a.peekValue(R.styleable.LinearProgressDrawable_lpd_maxLineWidth);
      if (value == null) maxLineWidth(0.75f);
      else if (value.type == TypedValue.TYPE_FRACTION)
        maxLineWidth(
            a.getFraction(R.styleable.LinearProgressDrawable_lpd_maxLineWidth, 1, 1, 0.75f));
      else
        maxLineWidth(
            a.getDimensionPixelSize(R.styleable.LinearProgressDrawable_lpd_maxLineWidth, 0));

      value = a.peekValue(R.styleable.LinearProgressDrawable_lpd_minLineWidth);
      if (value == null) minLineWidth(0.25f);
      else if (value.type == TypedValue.TYPE_FRACTION)
        minLineWidth(
            a.getFraction(R.styleable.LinearProgressDrawable_lpd_minLineWidth, 1, 1, 0.25f));
      else
        minLineWidth(
            a.getDimensionPixelSize(R.styleable.LinearProgressDrawable_lpd_minLineWidth, 0));

      strokeSize(
          a.getDimensionPixelSize(
              R.styleable.LinearProgressDrawable_lpd_strokeSize, ThemeUtil.dpToPx(context, 4)));
      verticalAlign(
          a.getInteger(
              R.styleable.LinearProgressDrawable_lpd_verticalAlign,
              LinearProgressDrawable.ALIGN_BOTTOM));
      strokeColors(
          a.getColor(
              R.styleable.LinearProgressDrawable_lpd_strokeColor,
              ThemeUtil.colorPrimary(context, 0xFF000000)));
      if ((resId = a.getResourceId(R.styleable.LinearProgressDrawable_lpd_strokeColors, 0)) != 0) {
        TypedArray ta = context.getResources().obtainTypedArray(resId);
        int[] colors = new int[ta.length()];
        for (int j = 0; j < ta.length(); j++) colors[j] = ta.getColor(j, 0);
        ta.recycle();
        strokeColors(colors);
      }
      strokeSecondaryColor(
          a.getColor(R.styleable.LinearProgressDrawable_lpd_strokeSecondaryColor, 0));
      reverse(a.getBoolean(R.styleable.LinearProgressDrawable_lpd_reverse, false));
      travelDuration(
          a.getInteger(
              R.styleable.LinearProgressDrawable_lpd_travelDuration,
              context.getResources().getInteger(android.R.integer.config_longAnimTime)));
      transformDuration(
          a.getInteger(
              R.styleable.LinearProgressDrawable_lpd_transformDuration,
              context.getResources().getInteger(android.R.integer.config_mediumAnimTime)));
      keepDuration(
          a.getInteger(
              R.styleable.LinearProgressDrawable_lpd_keepDuration,
              context.getResources().getInteger(android.R.integer.config_shortAnimTime)));
      if ((resId = a.getResourceId(R.styleable.LinearProgressDrawable_lpd_transformInterpolator, 0))
          != 0) transformInterpolator(AnimationUtils.loadInterpolator(context, resId));
      progressMode(
          a.getInteger(
              R.styleable.LinearProgressDrawable_pv_progressMode, ProgressView.MODE_INDETERMINATE));
      inAnimDuration(
          a.getInteger(
              R.styleable.LinearProgressDrawable_lpd_inAnimDuration,
              context.getResources().getInteger(android.R.integer.config_mediumAnimTime)));
      outAnimDuration(
          a.getInteger(
              R.styleable.LinearProgressDrawable_lpd_outAnimDuration,
              context.getResources().getInteger(android.R.integer.config_mediumAnimTime)));

      a.recycle();
    }