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:com.bliex.android.lockpatternlib.PatternView.java

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

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

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

    if ("square".equals(aspect)) {
        mAspect = ASPECT_SQUARE;/* w w  w . j  a v  a 2 s.  c  om*/
    } 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);

    mCellStates = new CellState[3][3];
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            mCellStates[i][j] = new CellState();
            mCellStates[i][j].radius = mDotSize / 2;
            mCellStates[i][j].row = i;
            mCellStates[i][j].col = j;
        }
    }

    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.layer.atlas.AtlasMessagesList.java

public void parseStyle(Context context, AttributeSet attrs, int defStyle) {
    TypedArray ta = context.getTheme().obtainStyledAttributes(attrs, R.styleable.AtlasMessageList,
            R.attr.AtlasMessageList, defStyle);
    this.myTextColor = ta.getColor(R.styleable.AtlasMessageList_myTextColor,
            context.getResources().getColor(R.color.atlas_text_black));
    this.myTextStyle = ta.getInt(R.styleable.AtlasMessageList_myTextStyle, Typeface.NORMAL);
    String myTextTypefaceName = ta.getString(R.styleable.AtlasMessageList_myTextTypeface);
    this.myTextTypeface = myTextTypefaceName != null ? Typeface.create(myTextTypefaceName, myTextStyle) : null;
    //this.myTextSize = ta.getDimension(R.styleable.AtlasMessageList_myTextSize, context.getResources().getDimension(R.dimen.atlas_text_size_general));

    this.otherTextColor = ta.getColor(R.styleable.AtlasMessageList_theirTextColor,
            context.getResources().getColor(R.color.atlas_text_black));
    this.otherTextStyle = ta.getInt(R.styleable.AtlasMessageList_theirTextStyle, Typeface.NORMAL);
    String otherTextTypefaceName = ta.getString(R.styleable.AtlasMessageList_theirTextTypeface);
    this.otherTextTypeface = otherTextTypefaceName != null
            ? Typeface.create(otherTextTypefaceName, otherTextStyle)
            : null;/*from  ww w.  j  a  va2 s.  co m*/
    //this.otherTextSize = ta.getDimension(R.styleable.AtlasMessageList_theirTextSize, context.getResources().getDimension(R.dimen.atlas_text_size_general));

    this.myBubbleColor = ta.getColor(R.styleable.AtlasMessageList_myBubbleColor,
            context.getResources().getColor(R.color.atlas_bubble_blue));
    this.otherBubbleColor = ta.getColor(R.styleable.AtlasMessageList_theirBubbleColor,
            context.getResources().getColor(R.color.atlas_background_gray));

    this.dateTextColor = ta.getColor(R.styleable.AtlasMessageList_dateTextColor,
            context.getResources().getColor(R.color.atlas_text_gray));
    this.avatarTextColor = ta.getColor(R.styleable.AtlasMessageList_avatarTextColor,
            context.getResources().getColor(R.color.atlas_text_black));
    this.avatarBackgroundColor = ta.getColor(R.styleable.AtlasMessageList_avatarBackgroundColor,
            context.getResources().getColor(R.color.atlas_background_gray));
    ta.recycle();
}

From source file:com.example.alvarpao.popularmovies.MovieGridFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.main_fragment, menu);

    // Get the array of values for the sort options since the onItemSelected method only
    // returns the string representation of the item, not the value associated
    Resources resources = getResources();
    final TypedArray sortArrayValues = resources.obtainTypedArray(R.array.sort_options_values);

    MenuItem sortMenuItem = menu.findItem(R.id.sort_spinner);
    mSortSpinner = (Spinner) MenuItemCompat.getActionView(sortMenuItem);
    mSortSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override//from w  ww .ja  va2 s .  c o m
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

            if (Utility.getPreferredSortOptionPosition(getActivity()) != position) {
                // Update the shared preferences with the new sort option election
                SharedPreferences sharedPreferences = PreferenceManager
                        .getDefaultSharedPreferences(getActivity());
                SharedPreferences.Editor editor = sharedPreferences.edit();
                //Save the sort_by value to query the movie database
                editor.putString(getString(R.string.sort_preference_key), sortArrayValues.getString(position));
                // Save the current position of the selected sort option
                editor.putInt(getString(R.string.sort_position_preference_key), position);
                editor.commit();

                // Update movie grid to reflect new sort option selected by user
                resetMovieGrid();
                getMovies(PAGE_1);
            }

            else {
                // If the sort option didn't change, the event most likely was triggered by
                // either a rotation or the activity being created. In case of the rotation
                // the state has already been restored in the onCreate() method, after onCreate()
                // the onCreateOptionsMenu() is called. If the activity has been created, the
                // favorite movies need to be fetched
                if (Utility.getPreferredSortOption(getActivity())
                        .equals(getString(R.string.sort_favorites_value))) {
                    if (!mMovies.isEmpty() && ((MainActivity) getActivity()).inTwoPaneLayout())
                        updateDetailsFragment();
                    else if (mMovies.isEmpty())
                        getMovies(Integer.valueOf(mPageToFetch).toString());
                }

                else {
                    // For the other sort options since pagination is involved the default
                    // movie to display in the details fragment when the user hasn't selected
                    // any movie is either the first one in the returned list when it is
                    // first loaded or the first visible movie before rotation. The first one
                    // when is first loaded is instantiated in the onScroll method
                    if (((MainActivity) getActivity()).inTwoPaneLayout()) {
                        if ((mSelectedMovie != -1) && (mMovieAdapter.getCount() != 0)) {
                            Movie selectedMovie = mMovieAdapter.getItem(mSelectedMovie);
                            ((Callback) getActivity()).onItemSelected(selectedMovie);
                        }
                    }
                    // Determine if another page needs to be retrieved by making an API call
                    getMovies(Integer.valueOf(mPageToFetch).toString());
                }

                // Restoring the scroll position
                mMoviesGridView.smoothScrollToPosition(mCurrentScrollPosition);
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            //Do nothing
        }
    });

    // This statement is needed to restore the state of the sort selection in case a screen
    // rotation has occurred. The spinner is restored to the position it was retrieved
    // from the SharedPreferences;
    mSortSpinner.setSelection(Utility.getPreferredSortOptionPosition(getActivity()));
}

From source file:io.authme.sdk.widget.LockPatternView.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public LockPatternView(Context context, AttributeSet attrs) {
    super(context, attrs);
    senSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
    senAccelerometer = senSensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY);
    if (senAccelerometer == null) {
        senAccelerometer = senSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    }//from ww w  .ja  v  a  2  s.  c om

    senSensorManager.registerListener(this, senAccelerometer, SensorManager.SENSOR_DELAY_GAME);

    sensGyro = senSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);

    if (sensGyro != null) {
        senSensorManager.registerListener(this, sensGyro, SensorManager.SENSOR_DELAY_GAME);
    }

    senMagnetometer = senSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);

    if (senMagnetometer != null) {
        senSensorManager.registerListener(this, senMagnetometer, SensorManager.SENSOR_DELAY_GAME);
    }

    accelList = new ArrayList<>();
    magnetics = new ArrayList<>();
    gyrolist = new ArrayList<>();
    rawXYList = new ArrayList<>();
    velocityList = new ArrayList<>();
    orientationArrayList = new ArrayList<>();
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Alp_42447968_LockPatternView);

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

    if ("square".equals(aspect)) {
        mAspect = ASPECT_SQUARE;
    } 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 = getResources().getColor(
            ResourceUtils.resolveAttribute(getContext(), R.attr.alp_42447968_color_lock_pattern_view_regular));
    mErrorColor = getResources().getColor(
            ResourceUtils.resolveAttribute(getContext(), R.attr.alp_42447968_color_lock_pattern_view_error));
    mSuccessColor = getResources().getColor(
            ResourceUtils.resolveAttribute(getContext(), R.attr.alp_42447968_color_lock_pattern_view_success));

    mRegularColor = a.getColor(R.styleable.Alp_42447968_LockPatternView_alp_42447968_regularColor,
            mRegularColor);
    mErrorColor = a.getColor(R.styleable.Alp_42447968_LockPatternView_alp_42447968_errorColor, mErrorColor);
    mSuccessColor = a.getColor(R.styleable.Alp_42447968_LockPatternView_alp_42447968_successColor,
            mSuccessColor);

    int pathColor = a.getColor(R.styleable.Alp_42447968_LockPatternView_alp_42447968_pathColor, mRegularColor);
    mPathPaint.setColor(pathColor);

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

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

    mDotSize = getResources().getDimensionPixelSize(R.dimen.alp_42447968_lock_pattern_dot_size);
    mDotSizeActivated = getResources()
            .getDimensionPixelSize(R.dimen.alp_42447968_lock_pattern_dot_size_activated);

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

    mCellStates = new CellState[MATRIX_WIDTH][MATRIX_WIDTH];
    for (int i = 0; i < MATRIX_WIDTH; i++) {
        for (int j = 0; j < MATRIX_WIDTH; j++) {
            mCellStates[i][j] = new CellState();
            mCellStates[i][j].size = mDotSize;
        }
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !isInEditMode()) {
        mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
                android.R.interpolator.fast_out_slow_in);
        mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
                android.R.interpolator.linear_out_slow_in);
    } // if
}

From source file:com.rexmtorres.android.patternlock.PatternLockView.java

@SuppressWarnings("deprecation")
public PatternLockView(Context context, AttributeSet attrs) {
    super(context, attrs);

    mContext = getContext();/* w w  w .  j a v a 2 s. c o  m*/

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PatternLockView,
            R.attr.patternLockViewStyle, 0);
    final String aspect = a.getString(R.styleable.PatternLockView_aspect);
    if ("square".equals(aspect)) {
        mAspect = ASPECT_SQUARE;
    } 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);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        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);
    } else {
        Resources resources = context.getResources();

        mRegularColor = resources.getColor(R.color.lock_pattern_view_regular_color);
        mErrorColor = resources.getColor(R.color.lock_pattern_view_error_color);
        mSuccessColor = resources.getColor(R.color.lock_pattern_view_success_color);
    }

    mRegularColor = a.getColor(R.styleable.PatternLockView_regularColor, mRegularColor);
    mErrorColor = a.getColor(R.styleable.PatternLockView_errorColor, mErrorColor);
    mSuccessColor = a.getColor(R.styleable.PatternLockView_successColor, mSuccessColor);

    int pathColor = a.getColor(R.styleable.PatternLockView_pathColor, mRegularColor);

    // [START rexmtorres 20160401] If set, replaces the pattern dots with the specified bitmap.
    Drawable oDotDrawable = a.getDrawable(R.styleable.PatternLockView_dotBitmap);

    if (oDotDrawable != null) {
        if (oDotDrawable instanceof BitmapDrawable) {
            m_oDotBitmap = ((BitmapDrawable) oDotDrawable).getBitmap();
            m_oBigDotBitmap = Bitmap.createScaledBitmap(m_oDotBitmap, (int) (m_oDotBitmap.getWidth() * 1.25),
                    (int) (m_oDotBitmap.getHeight() * 1.25), false);
        }
    }
    // [END rexmtorres 20160401]

    a.recycle();

    mPathPaint.setColor(pathColor);
    mPathPaint.setStyle(Paint.Style.STROKE);
    mPathPaint.setStrokeJoin(Paint.Join.ROUND);
    mPathPaint.setStrokeCap(Paint.Cap.ROUND);
    mPathWidth = getResources().getDimensionPixelSize(R.dimen.lock_pattern_dot_line_width);
    mPathPaint.setStrokeWidth(mPathWidth);
    mDotSize = getResources().getDimensionPixelSize(R.dimen.lock_pattern_dot_size);
    mDotSizeActivated = getResources().getDimensionPixelSize(R.dimen.lock_pattern_dot_size_activated);
    mPaint.setAntiAlias(true);
    mPaint.setDither(true);
    mCellStates = new CellState[3][3];
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            mCellStates[i][j] = new CellState();
            mCellStates[i][j].radius = mDotSize / 2;
            mCellStates[i][j].row = i;
            mCellStates[i][j].col = j;
            mCellStates[i][j].bitmapDot = m_oDotBitmap;
        }
    }

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

From source file:com.android.incallui.widget.multiwaveview.GlowPadView.java

private ArrayList<String> loadDescriptions(int resourceId) {
    TypedArray array = getContext().getResources().obtainTypedArray(resourceId);
    final int count = array.length();
    ArrayList<String> targetContentDescriptions = new ArrayList<String>(count);
    for (int i = 0; i < count; i++) {
        String contentDescription = array.getString(i);
        targetContentDescriptions.add(contentDescription);
    }/*from  w ww  .  j a  va 2  s.  c o m*/
    array.recycle();
    return targetContentDescriptions;
}

From source file:com.wl.tabguidance.utils.TabLayoutTitleStrip.java

public TabLayoutTitleStrip(final Context context, final AttributeSet attrs, final int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    //Init NTS/*from  ww  w . j av a2s  .  c o  m*/

    // Always draw
    setWillNotDraw(false);
    // Speed and fix for pre 17 API
    ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, null);
    setLayerType(LAYER_TYPE_SOFTWARE, null);

    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.TabTitleStrip);
    try {
        setStripColor(typedArray.getColor(R.styleable.TabTitleStrip_nts_color, DEFAULT_STRIP_COLOR));
        setTitleSize(typedArray.getDimension(R.styleable.TabTitleStrip_nts_size, DEFAULT_TITLE_SIZE));
        setStripWeight(typedArray.getDimension(R.styleable.TabTitleStrip_nts_weight, DEFAULT_STRIP_WEIGHT));
        setStripFactor(typedArray.getFloat(R.styleable.TabTitleStrip_nts_factor, DEFAULT_STRIP_FACTOR));
        setStripType(typedArray.getInt(R.styleable.TabTitleStrip_nts_type, StripType.LINE_INDEX));
        setStripGravity(typedArray.getInt(R.styleable.TabTitleStrip_nts_gravity, StripGravity.BOTTOM_INDEX));

        setTypeface(typedArray.getString(R.styleable.TabTitleStrip_nts_typeface));
        setInactiveColor(
                typedArray.getColor(R.styleable.TabTitleStrip_nts_inactive_color, DEFAULT_INACTIVE_COLOR));
        setActiveColor(typedArray.getColor(R.styleable.TabTitleStrip_nts_active_color, DEFAULT_ACTIVE_COLOR));
        setAnimationDuration(typedArray.getInteger(R.styleable.TabTitleStrip_nts_animation_duration,
                DEFAULT_ANIMATION_DURATION));
        setCornersRadius(
                typedArray.getDimension(R.styleable.TabTitleStrip_nts_corners_radius, DEFAULT_CORNER_RADIUS));

        // Get titles
        String[] titles = null;
        try {
            final int titlesResId = typedArray.getResourceId(R.styleable.TabTitleStrip_nts_titles, 0);
            titles = titlesResId == 0 ? null : typedArray.getResources().getStringArray(titlesResId);
        } catch (Exception exception) {
            titles = null;
            exception.printStackTrace();
        } finally {
            if (titles == null) {
                if (isInEditMode()) {
                    titles = new String[new Random().nextInt(5) + 1];
                    Arrays.fill(titles, PREVIEW_TITLE);
                } else
                    titles = new String[0];
            }

            setTitles(titles);
        }

        // Init animator
        mAnimator.setFloatValues(MIN_FRACTION, MAX_FRACTION);
        mAnimator.setInterpolator(new LinearInterpolator());
        mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(final ValueAnimator animation) {
                updateIndicatorPosition((Float) animation.getAnimatedValue());
            }
        });
    } finally {
        typedArray.recycle();
    }
}

From source file:com.roughike.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);//  w w  w. j av a2  s . co m

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

    String customFontPath;
    int titleTextAppearance;
    int descriptionTextAppearance;

    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);
    } 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).customTypeFace(customFontPath)
            .titleTextAppearance(titleTextAppearance).descriptionTextAppearance(descriptionTextAppearance)
            .build();
    pager.setAdapter(mAdapter);
}

From source file:com.appsummary.luoxf.myappsummary.navigationtabstrip.NavigationTabStrip.java

public NavigationTabStrip(final Context context, final AttributeSet attrs, final int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    //Init NTS//ww w  .jav  a2 s .c  o  m

    // Always draw
    setWillNotDraw(false);
    // More speed!
    setLayerType(LAYER_TYPE_HARDWARE, null);

    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NavigationTabStrip);
    try {
        setStripColor(typedArray.getColor(R.styleable.NavigationTabStrip_nts_color, DEFAULT_STRIP_COLOR));
        setTitleSize(typedArray.getDimension(R.styleable.NavigationTabStrip_nts_size, DEFAULT_TITLE_SIZE));
        setStripWeight(
                typedArray.getDimension(R.styleable.NavigationTabStrip_nts_weight, DEFAULT_STRIP_WEIGHT));
        setStripFactor(typedArray.getFloat(R.styleable.NavigationTabStrip_nts_factor, DEFAULT_STRIP_FACTOR));
        setStripType(typedArray.getInt(R.styleable.NavigationTabStrip_nts_type, StripType.LINE_INDEX));
        setStripGravity(
                typedArray.getInt(R.styleable.NavigationTabStrip_nts_gravity, StripGravity.BOTTOM_INDEX));

        setTypeface(typedArray.getString(R.styleable.NavigationTabStrip_nts_typeface));
        setInactiveColor(
                typedArray.getColor(R.styleable.NavigationTabStrip_nts_inactive_color, DEFAULT_INACTIVE_COLOR));
        setActiveColor(
                typedArray.getColor(R.styleable.NavigationTabStrip_nts_active_color, DEFAULT_ACTIVE_COLOR));
        setAnimationDuration(typedArray.getInteger(R.styleable.NavigationTabStrip_nts_animation_duration,
                DEFAULT_ANIMATION_DURATION));
        setCornersRadius(typedArray.getDimension(R.styleable.NavigationTabStrip_nts_corners_radius,
                DEFAULT_CORNER_RADIUS));

        // Get titles
        String[] titles = null;
        try {
            final int titlesResId = typedArray.getResourceId(R.styleable.NavigationTabStrip_nts_titles, 0);
            titles = titlesResId == 0 ? null : typedArray.getResources().getStringArray(titlesResId);
        } catch (Exception exception) {
            titles = null;
            exception.printStackTrace();
        } finally {
            if (titles == null) {
                if (isInEditMode()) {
                    titles = new String[new Random().nextInt(5) + 1];
                    Arrays.fill(titles, PREVIEW_TITLE);
                } else
                    titles = new String[0];
            }

            setTitles(titles);
        }

        // Init animator
        mAnimator.setFloatValues(MIN_FRACTION, MAX_FRACTION);
        mAnimator.setInterpolator(new LinearInterpolator());
        mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(final ValueAnimator animation) {
                updateIndicatorPosition((Float) animation.getAnimatedValue());
            }
        });
    } finally {
        typedArray.recycle();
    }
}

From source file:com.gigamole.navigationtabstrip.NavigationTabStrip.java

public NavigationTabStrip(final Context context, final AttributeSet attrs, final int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    //Init NTS//  w  w  w.j  ava  2s.c  o m

    // Always draw
    setWillNotDraw(false);
    // Speed and fix for pre 17 API
    ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, null);
    setLayerType(LAYER_TYPE_SOFTWARE, null);

    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NavigationTabStrip);
    try {
        setStripColor(typedArray.getColor(R.styleable.NavigationTabStrip_nts_color, DEFAULT_STRIP_COLOR));
        setTitleSize(typedArray.getDimension(R.styleable.NavigationTabStrip_nts_size, DEFAULT_TITLE_SIZE));
        setStripWeight(
                typedArray.getDimension(R.styleable.NavigationTabStrip_nts_weight, DEFAULT_STRIP_WEIGHT));
        setStripFactor(typedArray.getFloat(R.styleable.NavigationTabStrip_nts_factor, DEFAULT_STRIP_FACTOR));
        setStripType(typedArray.getInt(R.styleable.NavigationTabStrip_nts_type, StripType.LINE_INDEX));
        setStripGravity(
                typedArray.getInt(R.styleable.NavigationTabStrip_nts_gravity, StripGravity.BOTTOM_INDEX));

        setTypeface(typedArray.getString(R.styleable.NavigationTabStrip_nts_typeface));
        setInactiveColor(
                typedArray.getColor(R.styleable.NavigationTabStrip_nts_inactive_color, DEFAULT_INACTIVE_COLOR));
        setActiveColor(
                typedArray.getColor(R.styleable.NavigationTabStrip_nts_active_color, DEFAULT_ACTIVE_COLOR));
        setAnimationDuration(typedArray.getInteger(R.styleable.NavigationTabStrip_nts_animation_duration,
                DEFAULT_ANIMATION_DURATION));
        setCornersRadius(typedArray.getDimension(R.styleable.NavigationTabStrip_nts_corners_radius,
                DEFAULT_CORNER_RADIUS));

        // Get titles
        String[] titles = null;
        try {
            final int titlesResId = typedArray.getResourceId(R.styleable.NavigationTabStrip_nts_titles, 0);
            titles = titlesResId == 0 ? null : typedArray.getResources().getStringArray(titlesResId);
        } catch (Exception exception) {
            titles = null;
            exception.printStackTrace();
        } finally {
            if (titles == null) {
                if (isInEditMode()) {
                    titles = new String[new Random().nextInt(5) + 1];
                    Arrays.fill(titles, PREVIEW_TITLE);
                } else
                    titles = new String[0];
            }

            setTitles(titles);
        }

        // Init animator
        mAnimator.setFloatValues(MIN_FRACTION, MAX_FRACTION);
        mAnimator.setInterpolator(new LinearInterpolator());
        mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(final ValueAnimator animation) {
                updateIndicatorPosition((Float) animation.getAnimatedValue());
            }
        });
    } finally {
        typedArray.recycle();
    }
}