Example usage for android.content.res TypedArray getString

List of usage examples for android.content.res TypedArray getString

Introduction

In this page you can find the example usage for android.content.res TypedArray getString.

Prototype

@Nullable
public String getString(@StyleableRes int index) 

Source Link

Document

Retrieves the string value for the attribute at index.

Usage

From source file:devlight.io.library.ArcProgressStackView.java

public ArcProgressStackView(final Context context, final AttributeSet attrs, final int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    // Init CPSV//from w  ww.  ja  v  a2  s.  co  m

    // Always draw
    setWillNotDraw(false);
    setLayerType(LAYER_TYPE_SOFTWARE, null);
    ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, null);

    // Detect if features available
    mIsFeaturesAvailable = Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB;

    // Retrieve attributes from xml
    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ArcProgressStackView);
    try {
        setIsAnimated(typedArray.getBoolean(R.styleable.ArcProgressStackView_apsv_animated, true));
        setIsShadowed(typedArray.getBoolean(R.styleable.ArcProgressStackView_apsv_shadowed, true));
        setIsRounded(typedArray.getBoolean(R.styleable.ArcProgressStackView_apsv_rounded, false));
        setIsDragged(typedArray.getBoolean(R.styleable.ArcProgressStackView_apsv_dragged, false));
        setIsLeveled(typedArray.getBoolean(R.styleable.ArcProgressStackView_apsv_leveled, false));
        setTypeface(typedArray.getString(R.styleable.ArcProgressStackView_apsv_typeface));
        setTextColor(typedArray.getColor(R.styleable.ArcProgressStackView_apsv_text_color, Color.WHITE));
        setShadowRadius(typedArray.getDimension(R.styleable.ArcProgressStackView_apsv_shadow_radius,
                DEFAULT_SHADOW_RADIUS));
        setShadowDistance(typedArray.getDimension(R.styleable.ArcProgressStackView_apsv_shadow_distance,
                DEFAULT_SHADOW_DISTANCE));
        setShadowAngle(typedArray.getInteger(R.styleable.ArcProgressStackView_apsv_shadow_angle,
                (int) DEFAULT_SHADOW_ANGLE));
        setShadowColor(
                typedArray.getColor(R.styleable.ArcProgressStackView_apsv_shadow_color, DEFAULT_SHADOW_COLOR));
        setAnimationDuration(typedArray.getInteger(R.styleable.ArcProgressStackView_apsv_animation_duration,
                DEFAULT_ANIMATION_DURATION));
        setStartAngle(typedArray.getInteger(R.styleable.ArcProgressStackView_apsv_start_angle,
                (int) DEFAULT_START_ANGLE));
        setSweepAngle(typedArray.getInteger(R.styleable.ArcProgressStackView_apsv_sweep_angle,
                (int) DEFAULT_SWEEP_ANGLE));
        setProgressModelOffset(typedArray.getDimension(R.styleable.ArcProgressStackView_apsv_model_offset,
                DEFAULT_MODEL_OFFSET));
        setModelBgEnabled(typedArray.getBoolean(R.styleable.ArcProgressStackView_apsv_model_bg_enabled, false));

        // Set orientation
        final int orientationOrdinal = typedArray
                .getInt(R.styleable.ArcProgressStackView_apsv_indicator_orientation, 0);
        setIndicatorOrientation(
                orientationOrdinal == 0 ? IndicatorOrientation.VERTICAL : IndicatorOrientation.HORIZONTAL);

        // Retrieve interpolator
        Interpolator interpolator = null;
        try {
            final int interpolatorId = typedArray
                    .getResourceId(R.styleable.ArcProgressStackView_apsv_interpolator, 0);
            interpolator = interpolatorId == 0 ? null
                    : AnimationUtils.loadInterpolator(context, interpolatorId);
        } catch (Resources.NotFoundException exception) {
            interpolator = null;
            exception.printStackTrace();
        } finally {
            setInterpolator(interpolator);
        }

        // Set animation info if is available
        if (mIsFeaturesAvailable) {
            mProgressAnimator.setFloatValues(MIN_FRACTION, MAX_FRACTION);
            mProgressAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(final ValueAnimator animation) {
                    mAnimatedFraction = (float) animation.getAnimatedValue();
                    if (mAnimatorUpdateListener != null)
                        mAnimatorUpdateListener.onAnimationUpdate(animation);

                    postInvalidate();
                }
            });
        }

        // Check whether draw width dimension or fraction
        if (typedArray.hasValue(R.styleable.ArcProgressStackView_apsv_draw_width)) {
            final TypedValue drawWidth = new TypedValue();
            typedArray.getValue(R.styleable.ArcProgressStackView_apsv_draw_width, drawWidth);
            if (drawWidth.type == TypedValue.TYPE_DIMENSION)
                setDrawWidthDimension(drawWidth.getDimension(context.getResources().getDisplayMetrics()));
            else
                setDrawWidthFraction(drawWidth.getFraction(MAX_FRACTION, MAX_FRACTION));
        } else
            setDrawWidthFraction(DEFAULT_DRAW_WIDTH_FRACTION);

        // Set preview models
        if (isInEditMode()) {
            String[] preview = null;
            try {
                final int previewId = typedArray
                        .getResourceId(R.styleable.ArcProgressStackView_apsv_preview_colors, 0);
                preview = previewId == 0 ? null : typedArray.getResources().getStringArray(previewId);
            } catch (Exception exception) {
                preview = null;
                exception.printStackTrace();
            } finally {
                if (preview == null)
                    preview = typedArray.getResources().getStringArray(R.array.default_preview);

                final Random random = new Random();
                for (String previewColor : preview)
                    mModels.add(
                            new Model("", random.nextInt((int) MAX_PROGRESS), Color.parseColor(previewColor)));
                measure(mSize, mSize);
            }

            // Set preview model bg color
            mPreviewModelBgColor = typedArray.getColor(R.styleable.ArcProgressStackView_apsv_preview_bg,
                    Color.LTGRAY);
        }
    } finally {
        typedArray.recycle();
    }
}

From source file:com.actionbarsherlock.internal.widget.IcsSpinner.java

/**
 * Construct a new spinner with the given context's theme, the supplied attribute set,
 * and default style./*w  w w  .  ja v a  2  s .c  o m*/
 *
 * @param context The Context the view is running in, through which it can
 *        access the current theme, resources, etc.
 * @param attrs The attributes of the XML tag that is inflating the view.
 * @param defStyle The default style to apply to this view. If 0, no style
 *        will be applied (beyond what is included in the theme). This may
 *        either be an attribute resource, whose value will be retrieved
 *        from the current theme, or an explicit style resource.
 */
public IcsSpinner(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

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

    DropdownPopup popup = new DropdownPopup(context, attrs, defStyle);

    mDropDownWidth = a.getLayoutDimension(R.styleable.SherlockSpinner_android_dropDownWidth,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    popup.setBackgroundDrawable(a.getDrawable(R.styleable.SherlockSpinner_android_popupBackground));
    final int verticalOffset = a
            .getDimensionPixelOffset(R.styleable.SherlockSpinner_android_dropDownVerticalOffset, 0);
    if (verticalOffset != 0) {
        popup.setVerticalOffset(verticalOffset);
    }

    final int horizontalOffset = a
            .getDimensionPixelOffset(R.styleable.SherlockSpinner_android_dropDownHorizontalOffset, 0);
    if (horizontalOffset != 0) {
        popup.setHorizontalOffset(horizontalOffset);
    }

    mPopup = popup;

    mGravity = a.getInt(R.styleable.SherlockSpinner_android_gravity, Gravity.CENTER);

    mPopup.setPromptText(a.getString(R.styleable.SherlockSpinner_android_prompt));

    mDisableChildrenWhenDisabled = true;

    a.recycle();

    // Base constructor can call setAdapter before we initialize mPopup.
    // Finish setting things up if this happened.
    if (mTempAdapter != null) {
        mPopup.setAdapter(mTempAdapter);
        mTempAdapter = null;
    }
}

From source file:com.hippo.vector.AnimatedVectorDrawable.java

public void inflate(Context context, XmlPullParser parser, AttributeSet attrs)
        throws XmlPullParserException, IOException {
    final AnimatedVectorDrawableState state = mAnimatedVectorState;

    int eventType = parser.getEventType();
    float pathErrorScale = 1;
    while (eventType != XmlPullParser.END_DOCUMENT) {
        if (eventType == XmlPullParser.START_TAG) {
            final String tagName = parser.getName();
            if (ANIMATED_VECTOR.equals(tagName)) {
                final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AnimatedVectorDrawable);
                int drawableRes = a.getResourceId(R.styleable.AnimatedVectorDrawable_drawable, 0);
                if (drawableRes != 0) {
                    VectorDrawable vectorDrawable = VectorDrawable.create(context, drawableRes);
                    if (vectorDrawable != null) {
                        vectorDrawable.setAllowCaching(false);
                        vectorDrawable.setCallback(mCallback);
                        pathErrorScale = vectorDrawable.getPixelSize();
                        if (state.mVectorDrawable != null) {
                            state.mVectorDrawable.setCallback(null);
                        }/* w  w  w. j  a va2  s .co  m*/
                        state.mVectorDrawable = vectorDrawable;
                    }
                }
                a.recycle();
            } else if (TARGET.equals(tagName)) {
                final TypedArray a = context.obtainStyledAttributes(attrs,
                        R.styleable.AnimatedVectorDrawableTarget);
                final String target = a.getString(R.styleable.AnimatedVectorDrawableTarget_name);
                final int animResId = a.getResourceId(R.styleable.AnimatedVectorDrawableTarget_animation, 0);
                if (animResId != 0) {
                    state.addTargetAnimator(target,
                            AnimatorInflater.loadAnimator(context, animResId, pathErrorScale));
                }
                a.recycle();
            }
        }

        eventType = parser.next();
    }
}

From source file:com.scoreflex.ScoreflexView.java

/**
 * The constructor of the view./*from   w ww. j  a v  a2s .c o  m*/
 * @param activity The activity holding the view.
 * @param attrs
 * @param defStyle
 */
@SuppressWarnings("deprecation")
public ScoreflexView(Activity activity, AttributeSet attrs, int defStyle) {
    super(activity, attrs, defStyle);

    // Keep a reference on the activity
    mParentActivity = activity;

    // Default layout params
    if (null == getLayoutParams()) {
        setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                Scoreflex.getDensityIndependantPixel(R.dimen.scoreflex_panel_height)));
    }

    // Set our background color
    setBackgroundColor(getContext().getResources().getColor(R.color.scoreflex_background_color));

    // Create the top bar
    View topBar = new View(getContext());
    topBar.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            getResources().getDimensionPixelSize(R.dimen.scoreflex_topbar_height), Gravity.TOP));
    topBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.scoreflex_gradient_background));
    addView(topBar);

    // Create the retry button
    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    mErrorLayout = (ViewGroup) inflater.inflate(R.layout.scoreflex_error_layout, null);
    if (mErrorLayout != null) {

        // Configure refresh button
        Button refreshButton = (Button) mErrorLayout.findViewById(R.id.scoreflex_retry_button);
        if (null != refreshButton) {
            refreshButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    if (null == Scoreflex.getPlayerId()) {
                        setUserInterfaceState(new LoadingState());
                        loadUrlAfterLoggedIn(mInitialResource, mInitialRequestParams);
                    } else if (null == mWebView.getUrl()) {
                        setResource(mInitialResource);
                    } else {
                        mWebView.reload();
                    }
                }
            });
        }

        // Configure cancel button
        Button cancelButton = (Button) mErrorLayout.findViewById(R.id.scoreflex_cancel_button);
        if (null != cancelButton) {
            cancelButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    close();
                }
            });
        }

        // Get hold of the message view
        mMessageView = (TextView) mErrorLayout.findViewById(R.id.scoreflex_error_message_view);
        addView(mErrorLayout);

    }

    // Create the close button
    mCloseButton = new ImageButton(getContext());
    Drawable closeButtonDrawable = getResources().getDrawable(R.drawable.scoreflex_close_button);
    int closeButtonMargin = (int) ((getResources().getDimensionPixelSize(R.dimen.scoreflex_topbar_height)
            - closeButtonDrawable.getIntrinsicHeight()) / 2.0f);
    FrameLayout.LayoutParams closeButtonLayoutParams = new FrameLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT,
            Gravity.TOP | Gravity.RIGHT);
    closeButtonLayoutParams.setMargins(0, closeButtonMargin, closeButtonMargin, 0);
    mCloseButton.setLayoutParams(closeButtonLayoutParams);
    mCloseButton.setImageDrawable(closeButtonDrawable);
    mCloseButton.setBackgroundDrawable(null);
    mCloseButton.setPadding(0, 0, 0, 0);
    mCloseButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            close();
        }
    });
    addView(mCloseButton);

    // Create the web view
    mWebView = new WebView(mParentActivity);
    mWebView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    // mWebView.setBackgroundColor(Color.RED);
    mWebView.setWebViewClient(new ScoreflexWebViewClient());
    mWebView.setWebChromeClient(new WebChromeClient() {

        @Override
        public boolean onConsoleMessage(ConsoleMessage cm) {
            Log.d("Scoreflex", "javascript Error: "
                    + String.format("%s @ %d: %s", cm.message(), cm.lineNumber(), cm.sourceId()));
            return true;
        }

        public void openFileChooser(ValueCallback<Uri> uploadMsg) {
            // mtbActivity.mUploadMessage = uploadMsg;
            mUploadMessage = uploadMsg;

            String fileName = "picture.jpg";
            ContentValues values = new ContentValues();
            values.put(MediaStore.Images.Media.TITLE, fileName);
            // mOutputFileUri = mParentActivity.getContentResolver().insert(
            // MediaStore.Images.Media.DATA, values);
            final List<Intent> cameraIntents = new ArrayList<Intent>();
            final Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            final PackageManager packageManager = mParentActivity.getPackageManager();
            final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0);
            for (ResolveInfo res : listCam) {
                final String packageName = res.activityInfo.packageName;
                final Intent intent = new Intent(captureIntent);
                intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
                intent.setPackage(packageName);
                cameraIntents.add(intent);
            }

            // Filesystem.
            final Intent galleryIntent = new Intent();
            galleryIntent.setType("image/*");
            galleryIntent.setAction(Intent.ACTION_GET_CONTENT);

            // Chooser of filesystem options.
            final Intent chooserIntent = Intent.createChooser(galleryIntent, "Select Source please");

            // Add the camera options.
            chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[] {}));

            mParentActivity.startActivityForResult(chooserIntent, Scoreflex.FILECHOOSER_RESULTCODE);
        }

        public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
            openFileChooser(uploadMsg);
        }

        public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
            openFileChooser(uploadMsg);
        }
    });
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setDomStorageEnabled(true);
    mWebView.getSettings().setDatabasePath(
            getContext().getFilesDir().getPath() + "/data/" + getContext().getPackageName() + "/databases/");
    addView(mWebView);

    TypedArray a = mParentActivity.obtainStyledAttributes(attrs, R.styleable.ScoreflexView, defStyle, 0);
    String resource = a.getString(R.styleable.ScoreflexView_resource);
    if (null != resource)
        setResource(resource);

    a.recycle();

    // Create the animated spinner

    mProgressBar = (ProgressBar) ((LayoutInflater) getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.scoreflex_progress_bar, null);
    mProgressBar.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER));
    addView(mProgressBar);
    LocalBroadcastManager.getInstance(activity).registerReceiver(mLoginReceiver,
            new IntentFilter(Scoreflex.INTENT_USER_LOGED_IN));
    setUserInterfaceState(new InitialState());
}

From source file:com.android.nobug.view.pattern.PatternView.java

public PatternView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

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

    mRowCount = a.getInteger(R.styleable.PatternView_rowCount, PATTERN_SIZE_DEFAULT);
    mColumnCount = a.getInteger(R.styleable.PatternView_columnCount, PATTERN_SIZE_DEFAULT);

    final String aspect = a.getString(R.styleable.PatternView_aspect);

    if ("square".equals(aspect)) {
        mAspect = ASPECT_SQUARE;//w ww .j a  va  2  s  .c o m
    } else if ("lock_width".equals(aspect)) {
        mAspect = ASPECT_LOCK_WIDTH;
    } else if ("lock_height".equals(aspect)) {
        mAspect = ASPECT_LOCK_HEIGHT;
    } else {
        mAspect = ASPECT_SQUARE;
    }

    setClickable(true);

    mPathPaint.setAntiAlias(true);
    mPathPaint.setDither(true);

    mRegularColor = a.getColor(R.styleable.PatternView_regularColor, mRegularColor);
    mErrorColor = a.getColor(R.styleable.PatternView_errorColor, mErrorColor);
    mSuccessColor = a.getColor(R.styleable.PatternView_successColor, mSuccessColor);

    a.recycle();

    mPathPaint.setStyle(Paint.Style.STROKE);
    mPathPaint.setStrokeJoin(Paint.Join.ROUND);
    mPathPaint.setStrokeCap(Paint.Cap.ROUND);

    mPathWidth = getResources().getDimensionPixelSize(R.dimen.pl_pattern_dot_line_width);
    mPathPaint.setStrokeWidth(mPathWidth);

    mDotSize = getResources().getDimensionPixelSize(R.dimen.pl_pattern_dot_size);
    mDotSizeActivated = getResources().getDimensionPixelSize(R.dimen.pl_pattern_dot_size_activated);

    mPaint.setAntiAlias(true);
    mPaint.setDither(true);

    updatePatternSize();

    mFastOutSlowInInterpolator = new FastOutSlowInInterpolator();
    mLinearOutSlowInInterpolator = new LinearOutSlowInInterpolator();
    mExploreByTouchHelper = new PatternExploreByTouchHelper(this);
    ViewCompat.setAccessibilityDelegate(this, mExploreByTouchHelper);
    mAccessibilityManager = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
    mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
}

From source file:me.zhanghai.android.patternlock.PatternView.java

public PatternView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

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

    mRowCount = a.getInteger(R.styleable.PatternView_pl_rowCount, PATTERN_SIZE_DEFAULT);
    mColumnCount = a.getInteger(R.styleable.PatternView_pl_columnCount, PATTERN_SIZE_DEFAULT);

    final String aspect = a.getString(R.styleable.PatternView_pl_aspect);

    if ("square".equals(aspect)) {
        mAspect = ASPECT_SQUARE;//from   w ww  .j av  a  2  s .  co m
    } else if ("lock_width".equals(aspect)) {
        mAspect = ASPECT_LOCK_WIDTH;
    } else if ("lock_height".equals(aspect)) {
        mAspect = ASPECT_LOCK_HEIGHT;
    } else {
        mAspect = ASPECT_SQUARE;
    }

    setClickable(true);

    mPathPaint.setAntiAlias(true);
    mPathPaint.setDither(true);

    // Removed since every developer should set their own patternViewStyle.
    //mRegularColor = context.getColor(R.color.lock_pattern_view_regular_color);
    //mErrorColor = context.getColor(R.color.lock_pattern_view_error_color);
    //mSuccessColor = context.getColor(R.color.lock_pattern_view_success_color);
    mRegularColor = a.getColor(R.styleable.PatternView_pl_regularColor, mRegularColor);
    mErrorColor = a.getColor(R.styleable.PatternView_pl_errorColor, mErrorColor);
    mSuccessColor = a.getColor(R.styleable.PatternView_pl_successColor, mSuccessColor);

    a.recycle();

    mPathPaint.setStyle(Paint.Style.STROKE);
    mPathPaint.setStrokeJoin(Paint.Join.ROUND);
    mPathPaint.setStrokeCap(Paint.Cap.ROUND);

    mPathWidth = getResources().getDimensionPixelSize(R.dimen.pl_pattern_dot_line_width);
    mPathPaint.setStrokeWidth(mPathWidth);

    mDotSize = getResources().getDimensionPixelSize(R.dimen.pl_pattern_dot_size);
    mDotSizeActivated = getResources().getDimensionPixelSize(R.dimen.pl_pattern_dot_size_activated);

    mPaint.setAntiAlias(true);
    mPaint.setDither(true);

    updatePatternSize();

    mFastOutSlowInInterpolator = new FastOutSlowInInterpolator();
    mLinearOutSlowInInterpolator = new LinearOutSlowInInterpolator();
    mExploreByTouchHelper = new PatternExploreByTouchHelper(this);
    ViewCompat.setAccessibilityDelegate(this, mExploreByTouchHelper);
    mAccessibilityManager = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
    mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
}

From source file:com.github.antoniodisanto92.swipeselector.SwipeSelector.java

private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    TypedArray ta = context.getTheme().obtainStyledAttributes(attrs, R.styleable.SwipeSelector, defStyleAttr,
            defStyleRes);/*from w  w w  . j a  va  2  s.  co  m*/

    int indicatorSize;
    int indicatorMargin;
    int indicatorInActiveColor;
    int indicatorActiveColor;
    int leftButtonResource;
    int rightButtonResource;

    String customFontPath;
    int titleTextAppearance;
    int descriptionTextAppearance;
    int descriptionGravity;

    try {
        indicatorSize = (int) ta.getDimension(R.styleable.SwipeSelector_swipe_indicatorSize,
                PixelUtils.dpToPixel(context, DEFAULT_INDICATOR_SIZE));
        indicatorMargin = (int) ta.getDimension(R.styleable.SwipeSelector_swipe_indicatorMargin,
                PixelUtils.dpToPixel(context, DEFAULT_INDICATOR_MARGIN));
        indicatorInActiveColor = ta.getColor(R.styleable.SwipeSelector_swipe_indicatorInActiveColor,
                ContextCompat.getColor(context, R.color.swipeselector_color_indicator_inactive));
        indicatorActiveColor = ta.getColor(R.styleable.SwipeSelector_swipe_indicatorActiveColor,
                ContextCompat.getColor(context, R.color.swipeselector_color_indicator_active));

        leftButtonResource = ta.getResourceId(R.styleable.SwipeSelector_swipe_leftButtonResource,
                R.drawable.ic_action_navigation_chevron_left);
        rightButtonResource = ta.getResourceId(R.styleable.SwipeSelector_swipe_rightButtonResource,
                R.drawable.ic_action_navigation_chevron_right);

        customFontPath = ta.getString(R.styleable.SwipeSelector_swipe_customFontPath);
        titleTextAppearance = ta.getResourceId(R.styleable.SwipeSelector_swipe_titleTextAppearance, -1);
        descriptionTextAppearance = ta.getResourceId(R.styleable.SwipeSelector_swipe_descriptionTextAppearance,
                -1);
        descriptionGravity = ta.getInteger(R.styleable.SwipeSelector_swipe_descriptionGravity, -1);
    } finally {
        ta.recycle();
    }

    LayoutInflater inflater = LayoutInflater.from(context);
    inflater.inflate(R.layout.swipeselector_layout, this);

    ViewPager pager = (ViewPager) findViewById(R.id.swipeselector_layout_swipePager);
    ViewGroup indicatorContainer = (ViewGroup) findViewById(R.id.swipeselector_layout_circleContainer);
    ImageView leftButton = (ImageView) findViewById(R.id.swipeselector_layout_leftButton);
    ImageView rightButton = (ImageView) findViewById(R.id.swipeselector_layout_rightButton);

    mAdapter = new SwipeAdapter.Builder().viewPager(pager).indicatorContainer(indicatorContainer)
            .indicatorSize(indicatorSize).indicatorMargin(indicatorMargin)
            .inActiveIndicatorColor(indicatorInActiveColor).activeIndicatorColor(indicatorActiveColor)
            .leftButtonResource(leftButtonResource).rightButtonResource(rightButtonResource)
            .leftButton(leftButton).rightButton(rightButton).customFontPath(customFontPath)
            .titleTextAppearance(titleTextAppearance).descriptionTextAppearance(descriptionTextAppearance)
            .descriptionGravity(descriptionGravity).build();
    pager.setAdapter(mAdapter);
}

From source file:com.zzti.fyg.widgets.SwipeRefreshLayout.java

/**
 * Constructor that is called when inflating SwipeRefreshLayout from XML.
 * /*from  ww  w  .j  a v a  2s  .  com*/
 * @param context
 * @param attrs
 */
public SwipeRefreshLayout(Context context, AttributeSet attrs) {
    super(context, attrs);

    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

    mMediumAnimationDuration = getResources().getInteger(android.R.integer.config_longAnimTime);

    setWillNotDraw(false);

    final DisplayMetrics metrics = getResources().getDisplayMetrics();
    mDecelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR);
    //screenWidth = metrics.widthPixels;

    trigger_angle = Math.atan((double) metrics.widthPixels / metrics.heightPixels);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.swiperefresh);
    //      setEnabled(a.getBoolean(0, true));
    setEnabled(true);

    ptr_drawable = a.getResourceId(R.styleable.swiperefresh_roateImage, R.drawable.default_ptr_rotate);
    ptr_flip_drawable = a.getResourceId(R.styleable.swiperefresh_flipImage, R.drawable.default_ptr_flip);
    finished_drawable = a.getResourceId(R.styleable.swiperefresh_finishedImage,
            R.drawable.ic_done_grey600_18dp);
    pull2refresh = a.getBoolean(R.styleable.swiperefresh_ptr, true);
    pull2load = a.getBoolean(R.styleable.swiperefresh_ptl, true);
    textSize = a.getDimension(R.styleable.swiperefresh_srlTextSize, DEFAULT_TIPS_TEXTSIZE * metrics.density);
    textColor = a.getColor(R.styleable.swiperefresh_srlTextColor, DEFAULT_TEXT_COLOR);
    type = a.getInt(R.styleable.swiperefresh_srlAnimationStyle, DEFAULT_TYPE);

    pullDownLabel = a.getString(R.styleable.swiperefresh_pullDownLabel);
    refreshingLabel = a.getString(R.styleable.swiperefresh_refreshingLabel);
    releaseDownLabel = a.getString(R.styleable.swiperefresh_releaseDownLabel);

    pullUpLabel = a.getString(R.styleable.swiperefresh_pullUpLabel);
    loadingLabel = a.getString(R.styleable.swiperefresh_loadingLabel);
    releaseUpLabel = a.getString(R.styleable.swiperefresh_releaseUpLabel);

    if (null == pullDownLabel || pullDownLabel.equals("")) {
        pullDownLabel = DEFAULT_PULL_DOWN_LABEL;
    }
    if (null == refreshingLabel || refreshingLabel.equals("")) {
        refreshingLabel = DEFAULT_REFRESHING_LABEL;
    }
    if (null == releaseDownLabel || releaseDownLabel.equals("")) {
        releaseDownLabel = DEFAULT_RELEASE_DOWN_LABEL;
    }

    if (null == pullUpLabel || pullUpLabel.equals("")) {
        pullUpLabel = DEFAULT_PULL_UP_LABEL;
    }
    if (null == loadingLabel || loadingLabel.equals("")) {
        loadingLabel = DEFAULT_LOADING_LABEL;
    }
    if (null == releaseUpLabel || releaseUpLabel.equals("")) {
        releaseUpLabel = DEFAULT_RELEASE_UP_LABEL;
    }

    mProgressBar = new SwipeProgressBar(this, textSize, textColor, ptr_drawable, ptr_flip_drawable,
            finished_drawable, type);
    a.recycle();
}

From source file:com.limxing.library.PullToRefresh.SwipeRefreshLayout.java

/**
 * Constructor that is called when inflating SwipeRefreshLayout from XML.
 * //from   w  w  w  .j a va  2s . co  m
 * @param context
 * @param attrs
 */
public SwipeRefreshLayout(Context context, AttributeSet attrs) {
    super(context, attrs);

    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

    mMediumAnimationDuration = getResources().getInteger(android.R.integer.config_longAnimTime);

    setWillNotDraw(false);

    final DisplayMetrics metrics = getResources().getDisplayMetrics();
    mDecelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR);
    // screenWidth = metrics.widthPixels;

    trigger_angle = Math.atan((double) metrics.widthPixels / metrics.heightPixels);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.swiperefresh);
    // setEnabled(a.getBoolean(0, true));
    setEnabled(true);

    ptr_drawable = a.getResourceId(R.styleable.swiperefresh_roateImage, R.drawable.default_ptr_rotate);
    ptr_flip_drawable = a.getResourceId(R.styleable.swiperefresh_flipImage, R.drawable.default_ptr_flip);
    finished_drawable = a.getResourceId(R.styleable.swiperefresh_finishedImage, R.drawable.xlistview_success);
    pull2refresh = a.getBoolean(R.styleable.swiperefresh_ptr, true);
    pull2load = a.getBoolean(R.styleable.swiperefresh_ptl, true);
    textSize = a.getDimension(R.styleable.swiperefresh_srlTextSize, DEFAULT_TIPS_TEXTSIZE * metrics.density);
    textColor = a.getColor(R.styleable.swiperefresh_srlTextColor, DEFAULT_TEXT_COLOR);
    type = a.getInt(R.styleable.swiperefresh_srlAnimationStyle, DEFAULT_TYPE);

    pullDownLabel = a.getString(R.styleable.swiperefresh_pullDownLabel);
    refreshingLabel = a.getString(R.styleable.swiperefresh_refreshingLabel);
    releaseDownLabel = a.getString(R.styleable.swiperefresh_releaseDownLabel);

    pullUpLabel = a.getString(R.styleable.swiperefresh_pullUpLabel);
    loadingLabel = a.getString(R.styleable.swiperefresh_loadingLabel);
    releaseUpLabel = a.getString(R.styleable.swiperefresh_releaseUpLabel);

    if (null == pullDownLabel || pullDownLabel.equals("")) {
        pullDownLabel = DEFAULT_PULL_DOWN_LABEL;
    }
    if (null == refreshingLabel || refreshingLabel.equals("")) {
        refreshingLabel = DEFAULT_REFRESHING_LABEL;
    }
    if (null == releaseDownLabel || releaseDownLabel.equals("")) {
        releaseDownLabel = DEFAULT_RELEASE_DOWN_LABEL;
    }

    if (null == pullUpLabel || pullUpLabel.equals("")) {
        pullUpLabel = DEFAULT_PULL_UP_LABEL;
    }
    if (null == loadingLabel || loadingLabel.equals("")) {
        loadingLabel = DEFAULT_LOADING_LABEL;
    }
    if (null == releaseUpLabel || releaseUpLabel.equals("")) {
        releaseUpLabel = DEFAULT_RELEASE_UP_LABEL;
    }

    mProgressBar = new SwipeProgressBar(this, textSize, textColor, ptr_drawable, ptr_flip_drawable,
            finished_drawable, type);
    a.recycle();
}

From source file:com.zwj.customview.gesturelock.PatternView.java

public PatternView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

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

    mRowCount = a.getInteger(R.styleable.PatternView_pl_rowCount, PATTERN_SIZE_DEFAULT);
    mColumnCount = a.getInteger(R.styleable.PatternView_pl_columnCount, PATTERN_SIZE_DEFAULT);

    final String aspect = a.getString(R.styleable.PatternView_pl_aspect);

    if ("square".equals(aspect)) {
        mAspect = ASPECT_SQUARE;/*from  ww w .  java 2  s .  co m*/
    } else if ("lock_width".equals(aspect)) {
        mAspect = ASPECT_LOCK_WIDTH;
    } else if ("lock_height".equals(aspect)) {
        mAspect = ASPECT_LOCK_HEIGHT;
    } else {
        mAspect = ASPECT_SQUARE;
    }

    setClickable(true);

    mPathPaint.setAntiAlias(true);
    mPathPaint.setDither(true);

    // Removed since every developer should set their own patternViewStyle.
    //mRegularColor = context.getColor(R.color.lock_pattern_view_regular_color);
    //mErrorColor = context.getColor(R.color.lock_pattern_view_error_color);
    //mSuccessColor = context.getColor(R.color.lock_pattern_view_success_color);
    mRegularColor = a.getColor(R.styleable.PatternView_pl_regularColor, mRegularColor);
    mErrorColor = a.getColor(R.styleable.PatternView_pl_errorColor, mErrorColor);
    mSuccessColor = a.getColor(R.styleable.PatternView_pl_successColor, mSuccessColor);

    // 
    int excircleColor = a.getColor(R.styleable.PatternView_excircle_color, Color.WHITE);

    // ?
    mExcircleRadius = a.getDimensionPixelSize(R.styleable.PatternView_excircle_radius,
            getResources().getDimensionPixelSize(R.dimen.pl_pattern_excircle_radius));

    // TODO ?????View????
    mDotRadius = a.getDimensionPixelSize(R.styleable.PatternView_dot_radius,
            getResources().getDimensionPixelSize(R.dimen.pl_pattern_dot_size));

    mDotRadiusActivated = a.getDimensionPixelSize(R.styleable.PatternView_dot_activated_radius,
            getResources().getDimensionPixelSize(R.dimen.pl_pattern_dot_size_activated));

    a.recycle();

    mPathPaint.setStyle(Paint.Style.STROKE);
    mPathPaint.setStrokeJoin(Paint.Join.ROUND);
    mPathPaint.setStrokeCap(Paint.Cap.ROUND);

    mPathWidth = getResources().getDimensionPixelSize(R.dimen.pl_pattern_dot_line_width);
    mPathPaint.setStrokeWidth(mPathWidth);

    mPaint.setAntiAlias(true);
    mPaint.setDither(true);

    mPaintExcircle.setAntiAlias(true);
    mPaintExcircle.setDither(true);
    mPaintExcircle.setColor(excircleColor);

    updatePatternSize();

    mFastOutSlowInInterpolator = new FastOutSlowInInterpolator();
    mLinearOutSlowInInterpolator = new LinearOutSlowInInterpolator();
    mExploreByTouchHelper = new PatternExploreByTouchHelper(this);
    ViewCompat.setAccessibilityDelegate(this, mExploreByTouchHelper);
    mAccessibilityManager = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
    mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
}