Example usage for android.content.res TypedArray getColor

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

Introduction

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

Prototype

@ColorInt
public int getColor(@StyleableRes int index, @ColorInt int defValue) 

Source Link

Document

Retrieve the color value for the attribute at index.

Usage

From source file:com.borjabravo.readmoretextview.ReadMoreTextView.java

public ReadMoreTextView(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ReadMoreTextView);
    this.trimLength = typedArray.getInt(R.styleable.ReadMoreTextView_trimLength, DEFAULT_TRIM_LENGTH);
    int resourceIdTrimCollapsedText = typedArray.getResourceId(R.styleable.ReadMoreTextView_trimCollapsedText,
            R.string.read_more);/*from  w w  w. ja  va 2s .co  m*/
    int resourceIdTrimExpandedText = typedArray.getResourceId(R.styleable.ReadMoreTextView_trimExpandedText,
            R.string.read_less);
    this.trimCollapsedText = getResources().getString(resourceIdTrimCollapsedText);
    this.trimExpandedText = getResources().getString(resourceIdTrimExpandedText);
    this.trimLines = typedArray.getInt(R.styleable.ReadMoreTextView_trimLines, DEFAULT_TRIM_LINES);
    this.colorClickableText = typedArray.getColor(R.styleable.ReadMoreTextView_colorClickableText,
            ContextCompat.getColor(context, R.color.accent));
    this.showTrimExpandedText = typedArray.getBoolean(R.styleable.ReadMoreTextView_showTrimExpandedText,
            DEFAULT_SHOW_TRIM_EXPANDED_TEXT);
    this.trimMode = typedArray.getInt(R.styleable.ReadMoreTextView_trimMode, TRIM_MODE_LINES);
    typedArray.recycle();
    viewMoreSpan = new ReadMoreClickableSpan();
    onGlobalLayoutLineEndIndex();
    setText();
}

From source file:com.crqi.shein_plants.suspenddemo.view.CirclePageIndicator.java

public CirclePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;//from w  w  w. j  a v  a2 s  .  c  o m

    //Load defaults from resources
    final Resources res = getResources();
    final int defaultPageColor = res.getColor(R.color.default_circle_indicator_page_color);
    final int defaultFillColor = res.getColor(R.color.default_circle_indicator_fill_color);
    final int defaultOrientation = res.getInteger(R.integer.default_circle_indicator_orientation);
    final int defaultStrokeColor = res.getColor(R.color.default_circle_indicator_stroke_color);
    final float defaultStrokeWidth = res.getDimension(R.dimen.default_circle_indicator_stroke_width);
    final float defaultRadius = res.getDimension(R.dimen.default_circle_indicator_radius);
    final boolean defaultCentered = res.getBoolean(R.bool.default_circle_indicator_centered);
    final boolean defaultSnap = res.getBoolean(R.bool.default_circle_indicator_snap);

    //Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CirclePageIndicator, defStyle, 0);

    mCentered = a.getBoolean(R.styleable.CirclePageIndicator_centered, defaultCentered);
    mFillStroke = a.getBoolean(R.styleable.CirclePageIndicator_fillStroke, false);
    mOrientation = a.getInt(R.styleable.CirclePageIndicator_android_orientation, defaultOrientation);
    mPaintPageFill.setStyle(Style.FILL);
    mPaintPageFill.setColor(a.getColor(R.styleable.CirclePageIndicator_pageColor, defaultPageColor));

    mPaintStroke.setStyle(mFillStroke ? Style.FILL : Style.STROKE);
    mPaintStroke.setColor(a.getColor(R.styleable.CirclePageIndicator_strokeColor, defaultStrokeColor));
    mPaintStroke
            .setStrokeWidth(a.getDimension(R.styleable.CirclePageIndicator_strokeWidth, defaultStrokeWidth));
    mPaintFill.setStyle(Style.FILL);
    mPaintFill.setColor(a.getColor(R.styleable.CirclePageIndicator_fillColor, defaultFillColor));
    mRadius = a.getDimension(R.styleable.CirclePageIndicator_radius, defaultRadius);
    mSnap = a.getBoolean(R.styleable.CirclePageIndicator_snap, defaultSnap);

    Drawable background = a.getDrawable(R.styleable.CirclePageIndicator_android_background);
    if (background != null) {
        setBackgroundDrawable(background);
    }

    a.recycle();

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}

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/*from w w w  .  ja va  2 s.com*/

    // 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.floyd.diamond.ui.pageindicator.CirclePageIndicator.java

public CirclePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;//  w ww.ja  v a2  s.  c o m

    //Load defaults from resources
    final Resources res = getResources();
    final int defaultPageColor = res.getColor(R.color.default_circle_indicator_page_color);
    final int defaultFillColor = res.getColor(R.color.default_circle_indicator_fill_color);
    final int defaultOrientation = res.getInteger(R.integer.default_circle_indicator_orientation);
    final int defaultStrokeColor = res.getColor(R.color.default_circle_indicator_stroke_color);
    final float defaultStrokeWidth = res.getDimension(R.dimen.default_circle_indicator_stroke_width);
    final float defaultRadius = res.getDimension(R.dimen.default_circle_indicator_radius);
    final boolean defaultCentered = res.getBoolean(R.bool.default_circle_indicator_centered);
    final boolean defaultRight = res.getBoolean(R.bool.default_circle_indicator_right);
    final boolean defaultSnap = res.getBoolean(R.bool.default_circle_indicator_snap);

    //Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CirclePageIndicator, defStyle, 0);

    mCentered = a.getBoolean(R.styleable.CirclePageIndicator_centered, defaultCentered);
    mRight = a.getBoolean(R.styleable.CirclePageIndicator_right, defaultRight);
    mOrientation = a.getInt(R.styleable.CirclePageIndicator_android_orientation, defaultOrientation);
    mPaintPageFill.setStyle(Style.FILL);
    mPaintPageFill.setColor(a.getColor(R.styleable.CirclePageIndicator_pageColor, defaultPageColor));
    mPaintStroke.setStyle(Style.STROKE);
    mPaintStroke.setColor(a.getColor(R.styleable.CirclePageIndicator_strokeColor, defaultStrokeColor));
    mPaintStroke
            .setStrokeWidth(a.getDimension(R.styleable.CirclePageIndicator_strokeWidth, defaultStrokeWidth));
    mPaintFill.setStyle(Style.FILL);
    mPaintFill.setColor(a.getColor(R.styleable.CirclePageIndicator_fillColor, defaultFillColor));
    mRadius = a.getDimension(R.styleable.CirclePageIndicator_radius, defaultRadius);
    mSnap = a.getBoolean(R.styleable.CirclePageIndicator_snap, defaultSnap);

    Drawable background = a.getDrawable(R.styleable.CirclePageIndicator_android_background);
    if (background != null) {
        setBackgroundDrawable(background);
    }

    a.recycle();

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}

From source file:com.todddavies.components.progressbar.ProgressWheel.java

/**
 * Parse the attributes passed to the view from the XML
 *
 * @param a the attributes to parse/*from w  w  w  .j  a v a  2s .  c o m*/
 */
private void parseAttributes(TypedArray a) {
    barWidth = (int) a.getDimension(R.styleable.ProgressWheel_barWidth, barWidth);

    rimWidth = (int) a.getDimension(R.styleable.ProgressWheel_rimWidth, rimWidth);

    spinSpeed = (int) a.getDimension(R.styleable.ProgressWheel_spinSpeed, spinSpeed);

    delayMillis = a.getInteger(R.styleable.ProgressWheel_delayMillis, delayMillis);
    if (delayMillis < 0) {
        delayMillis = 0;
    }

    barColor = a.getColor(R.styleable.ProgressWheel_barColor, barColor);

    barLength = (int) a.getDimension(R.styleable.ProgressWheel_barLength, barLength);

    textSize = (int) a.getDimension(R.styleable.ProgressWheel_textSize, textSize);

    textColor = (int) a.getColor(R.styleable.ProgressWheel_textColor, textColor);

    //if the text is empty , so ignore it
    if (a.hasValue(R.styleable.ProgressWheel_text)) {
        setText(a.getString(R.styleable.ProgressWheel_text));
    }

    rimColor = (int) a.getColor(R.styleable.ProgressWheel_rimColor, rimColor);

    circleColor = (int) a.getColor(R.styleable.ProgressWheel_circleColor, circleColor);

    contourColor = a.getColor(R.styleable.ProgressWheel_contourColor, contourColor);
    contourSize = a.getDimension(R.styleable.ProgressWheel_contourSize, contourSize);

    // Recycle
    a.recycle();
}

From source file:com.alibaba.akita.widget.CirclePageIndicator.java

public CirclePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    //Load defaults from resources
    final Resources res = getResources();
    final int defaultPageColor = res.getColor(R.color.default_circle_indicator_page_color);
    final int defaultFillColor = res.getColor(R.color.default_circle_indicator_fill_color);
    final int defaultOrientation = res.getInteger(R.integer.default_circle_indicator_orientation);
    final int defaultStrokeColor = res.getColor(R.color.default_circle_indicator_stroke_color);
    final float defaultStrokeWidth = res.getDimension(R.dimen.default_circle_indicator_stroke_width);
    final float defaultRadius = res.getDimension(R.dimen.default_circle_indicator_radius);
    final boolean defaultCentered = res.getBoolean(R.bool.default_circle_indicator_centered);
    final boolean defaultSnap = res.getBoolean(R.bool.default_circle_indicator_snap);

    //Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CirclePageIndicator, defStyle,
            R.style.Widget_CirclePageIndicator);

    mCentered = a.getBoolean(R.styleable.CirclePageIndicator_centered, defaultCentered);
    mOrientation = a.getInt(R.styleable.CirclePageIndicator_orientation, defaultOrientation);
    mPaintPageFill = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaintPageFill.setStyle(Style.FILL);
    mPaintPageFill.setColor(a.getColor(R.styleable.CirclePageIndicator_pageColor, defaultPageColor));
    mPaintStroke = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaintStroke.setStyle(Style.STROKE);
    mPaintStroke.setColor(a.getColor(R.styleable.CirclePageIndicator_strokeColor, defaultStrokeColor));
    mPaintStroke/*  w ww.  j a  v a 2  s  . c  o  m*/
            .setStrokeWidth(a.getDimension(R.styleable.CirclePageIndicator_strokeWidth, defaultStrokeWidth));
    mPaintFill = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaintFill.setStyle(Style.FILL);
    mPaintFill.setColor(a.getColor(R.styleable.CirclePageIndicator_fillColor, defaultFillColor));
    mRadius = a.getDimension(R.styleable.CirclePageIndicator_radius, defaultRadius);
    mSnap = a.getBoolean(R.styleable.CirclePageIndicator_snap, defaultSnap);

    a.recycle();

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}

From source file:com.example1.ui.CirclePageIndicator.java

public CirclePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;// w  w  w  .j av a2 s .c  om

    //Load defaults from resources
    final Resources res = getResources();
    final int defaultPageColor = res.getColor(R.color.default_circle_indicator_page_color);
    final int defaultFillColor = res.getColor(R.color.default_circle_indicator_fill_color);
    final int defaultOrientation = res.getInteger(R.integer.default_circle_indicator_orientation);
    final int defaultStrokeColor = res.getColor(R.color.default_circle_indicator_stroke_color);
    final float defaultStrokeWidth = res.getDimension(R.dimen.default_circle_indicator_stroke_width);
    final float defaultRadius = res.getDimension(R.dimen.default_circle_indicator_radius);
    final boolean defaultCentered = res.getBoolean(R.bool.default_circle_indicator_centered);
    final boolean defaultSnap = res.getBoolean(R.bool.default_circle_indicator_snap);
    final float defaultExtraSpace = res.getDimension(R.dimen.default_circle_indicator_extraspace_width);

    //Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CirclePageIndicator, defStyle, 0);
    mExtraSpace = a.getDimension(R.styleable.CirclePageIndicator_extraSpace, defaultExtraSpace);
    mCentered = a.getBoolean(R.styleable.CirclePageIndicator_centered1, defaultCentered);
    mOrientation = a.getInt(R.styleable.CirclePageIndicator_android_orientation, defaultOrientation);
    mPaintPageFill.setStyle(Style.FILL);
    mPaintPageFill.setColor(a.getColor(R.styleable.CirclePageIndicator_pageColor, defaultPageColor));
    mPaintStroke.setStyle(Style.STROKE);
    mPaintStroke.setColor(a.getColor(R.styleable.CirclePageIndicator_strokeColor, defaultStrokeColor));
    mPaintStroke
            .setStrokeWidth(a.getDimension(R.styleable.CirclePageIndicator_strokeWidth, defaultStrokeWidth));
    mPaintFill.setStyle(Style.FILL);
    mPaintFill.setColor(a.getColor(R.styleable.CirclePageIndicator_fillColor, defaultFillColor));
    mRadius = a.getDimension(R.styleable.CirclePageIndicator_radius1, defaultRadius);
    mSnap = a.getBoolean(R.styleable.CirclePageIndicator_snap, defaultSnap);

    Drawable background = a.getDrawable(R.styleable.CirclePageIndicator_android_background);
    if (background != null) {
        setBackgroundDrawable(background);
    }

    a.recycle();

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}

From source file:base.PagerSlidingTabStrip.java

public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setFillViewport(true);/*from ww w.j  av  a2s. c o m*/
    setWillNotDraw(false);
    tabsContainer = new LinearLayout(context);
    tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    addView(tabsContainer);

    DisplayMetrics dm = getResources().getDisplayMetrics();
    scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm);
    indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm);
    underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm);
    dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm);
    tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
    dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);

    // get system attrs (android:textSize and android:textColor)
    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);
    tabTextSize = a.getDimensionPixelSize(TEXT_SIZE_INDEX, tabTextSize);
    ColorStateList colorStateList = a.getColorStateList(TEXT_COLOR_INDEX);
    int textPrimaryColor = a.getColor(TEXT_COLOR_PRIMARY, android.R.color.white);
    if (colorStateList != null) {
        tabTextColor = colorStateList;
    } else {
        tabTextColor = getColorStateList(textPrimaryColor);
    }

    underlineColor = textPrimaryColor;
    dividerColor = textPrimaryColor;
    indicatorColor = textPrimaryColor;
    paddingLeft = a.getDimensionPixelSize(PADDING_LEFT_INDEX, paddingLeft);
    paddingRight = a.getDimensionPixelSize(PADDING_RIGHT_INDEX, paddingRight);
    a.recycle();

    //In case we have the padding they must be equal so we take the biggest
    if (paddingRight < paddingLeft) {
        paddingRight = paddingLeft;
    }

    if (paddingLeft < paddingRight) {
        paddingLeft = paddingRight;
    }
    // get custom attrs
    a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);
    indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor);
    dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor);
    dividerWidth = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerWidth, dividerWidth);
    indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight,
            indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight,
            underlineHeight);
    dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding,
            dividerPadding);
    tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding);

    //tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground, tabBackgroundResId);

    shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand);
    scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset);
    textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps);
    isPaddingMiddle = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsPaddingMiddle, isPaddingMiddle);
    tabTypefaceStyle = a.getInt(R.styleable.PagerSlidingTabStrip_pstsTextStyle, Typeface.BOLD);
    tabTypefaceSelectedStyle = a.getInt(R.styleable.PagerSlidingTabStrip_pstsTextSelectedStyle, Typeface.BOLD);
    tabTextAlpha = a.getFloat(R.styleable.PagerSlidingTabStrip_pstsTextAlpha, HALF_TRANSP);
    tabTextSelectedAlpha = a.getFloat(R.styleable.PagerSlidingTabStrip_pstsTextSelectedAlpha, OPAQUE);
    a.recycle();

    rectPaint = new Paint();
    rectPaint.setAntiAlias(true);
    rectPaint.setStyle(Style.FILL);

    dividerPaint = new Paint();
    dividerPaint.setAntiAlias(true);
    dividerPaint.setStrokeWidth(dividerWidth);

    defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.MATCH_PARENT);
    expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);

    if (locale == null) {
        locale = getResources().getConfiguration().locale;
    }
}

From source file:com.desno365.mods.Activities.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    Log.i(TAG, "APP LAUNCHED!");
    super.onCreate(savedInstanceState);

    activity = this;

    newsString = getResources().getString(R.string.loading);

    modsContainer = new ModsContainer(this);

    // set content of the activity
    setContentView(R.layout.activity_main);

    // Are statistics (crashlytics and analytics) enabled?
    DesnoUtils.updateStatisticsEnabledBool(this);

    // Load crashlytics
    if (SharedVariables.areStatisticsEnabled)
        Fabric.with(this, new Crashlytics());

    // Start Google Analytics
    AnalyticsApplication application = (AnalyticsApplication) getApplication();
    mTracker = application.getDefaultTracker();

    // Send screen change
    DesnoUtils.sendScreenChange(mTracker, "MainActivity");

    // Set up the ToolBar.
    toolbar = (Toolbar) findViewById(R.id.tool_bar); // Attaching the layout to the toolbar object
    setSupportActionBar(toolbar); // Setting toolbar as the ActionBar with setSupportActionBar() call

    // Set up the SwipeRefreshLayout
    swipeLayout = (MainSwipeRefreshLayout) findViewById(R.id.swipe_container);
    swipeLayout.setOnRefreshListener(new MainSwipeRefreshLayout.OnRefreshListener() {
        @Override/*from   w ww  . ja va2  s  . co  m*/
        public void onRefresh() {
            startRefreshingAndChecking();
        }
    });
    TypedArray a = getTheme().obtainStyledAttributes(new int[] { R.attr.color_primary, R.attr.color_accent });
    int color1 = a.getColor(0, 0);
    int color2 = a.getColor(1, 0);
    a.recycle();
    swipeLayout.setColorSchemeColors(color1, color2);

    // Create the adapter that will return a fragment for each section of the app.
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager and attaching the adapter
    mViewPager = (ViewPager) findViewById(R.id.fragment_container);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            swipeLayout.setEnabled(false);
            switch (event.getAction()) {
            case MotionEvent.ACTION_UP:
                swipeLayout.setEnabled(true);
                break;
            }
            return false;
        }
    });

    // Bind the tabs to the ViewPager
    PagerSlidingTabStrip tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);
    tabs.setViewPager(mViewPager);
    tabs.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            // When swiping between different app sections

            // change toolbar title
            if (position == 0)
                toolbar.setTitle(getResources().getString(R.string.app_name));
            else
                toolbar.setTitle(mAppSectionsPagerAdapter.getPageTitle(position));

            // close drawer
            if (mNavigationDrawerFragment.isDrawerOpen())
                MainNavigationDrawerFragment.mDrawerLayout.closeDrawer(findViewById(R.id.navigation_drawer));

            // analytics
            DesnoUtils.sendScreenChange(mTracker, mAppSectionsPagerAdapter.getPageTitle(position).toString());
        }
    });

    // Set up the drawer.
    mNavigationDrawerFragment = (MainNavigationDrawerFragment) getFragmentManager()
            .findFragmentById(R.id.navigation_drawer);
    mNavigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout));

    // actions to do at the first launch of the app or after the app gets an update
    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    SharedPreferences.Editor editor = sharedPrefs.edit();

    final int knownVersion = sharedPrefs.getInt("known_version_code", 0);
    int currentVersion;
    try {
        currentVersion = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(TAG,
                "This should never happen, if this really happened one of the following has most likely happened: 1) There is a significant bug in this code. 2) There is a significant bug in Android. 3) The universe has ceased to exist.");
        currentVersion = 0;
    }

    if (sharedPrefs.getBoolean("is_first_launch", true)) {
        // first launch, the app has never been launched before
        editor.putBoolean("is_first_launch", false);
        editor.putInt("known_version_code", currentVersion);

        editor.putBoolean("refresh_on_start", DefaultSettingsValues.REFRESH_ON_START);
        editor.putBoolean("notification_bool_mods", DefaultSettingsValues.NOTIFICATIONS_MODS);
        editor.putBoolean("notification_bool_news", DefaultSettingsValues.NOTIFICATIONS_NEWS);
        editor.putString("sync_frequency", DefaultSettingsValues.SYNC_FREQUENCY_STRING);
        editor.putString("selected_language", "not_changed");
        editor.putString("selected_theme", "0");
        editor.putString("selected_animations", "0");
        editor.putBoolean("anonymous_statistics", DefaultSettingsValues.ANONYMOUS_STATISTICS);
        editor.putBoolean("user_understood_full_resolution_help", false);
        Log.i(TAG, "First launch");
    } else {
        Log.i(TAG, "APP LAUNCHED, with versionCode " + currentVersion);
        editor.putInt("known_version_code", currentVersion);

        if (knownVersion < currentVersion) {
            Log.i(TAG, "New version of the app: current versionCode " + currentVersion + ", old versionCode: "
                    + knownVersion);

            if (knownVersion < 15) {
                editor.putBoolean("anonymous_statistics", DefaultSettingsValues.ANONYMOUS_STATISTICS);
            }
        }
    }
    editor.apply();

    // Load alarmManager for notifications
    AlarmReceiver aR = new AlarmReceiver();
    aR.cancelAlarm(getApplicationContext());
    aR.setAlarm(getApplicationContext());

    // Load the IntersitialAd, then we just need to call DesnoUtils.showAd() to show the loaded Interstitial
    // Now we don't need to load the ad again, here or in other activities
    DesnoUtils.loadInterstitialAd(this);
}

From source file:com.anysoftkeyboard.keyboards.views.CandidateView.java

/**
 * Construct a CandidateView for showing suggested words for completion.
 *//*from  www.j a  v a 2s.  c  o  m*/
public CandidateView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    mSelectionHighlight = ContextCompat.getDrawable(context, R.drawable.list_selector_background_pressed);

    mAddToDictionaryHint = context.getString(R.string.hint_add_to_dictionary);
    // themed
    final KeyboardTheme theme = KeyboardThemeFactory.getCurrentKeyboardTheme(context.getApplicationContext());
    TypedArray a = theme.getPackageContext().obtainStyledAttributes(attrs, R.styleable.AnyKeyboardViewTheme, 0,
            theme.getThemeResId());
    int colorNormal = ContextCompat.getColor(context, R.color.candidate_normal);
    int colorRecommended = ContextCompat.getColor(context, R.color.candidate_recommended);
    int colorOther = ContextCompat.getColor(context, R.color.candidate_other);
    float fontSizePixel = context.getResources().getDimensionPixelSize(R.dimen.candidate_font_height);
    try {
        colorNormal = a.getColor(R.styleable.AnyKeyboardViewTheme_suggestionNormalTextColor, colorNormal);
        colorRecommended = a.getColor(R.styleable.AnyKeyboardViewTheme_suggestionRecommendedTextColor,
                colorRecommended);
        colorOther = a.getColor(R.styleable.AnyKeyboardViewTheme_suggestionOthersTextColor, colorOther);
        mDivider = a.getDrawable(R.styleable.AnyKeyboardViewTheme_suggestionDividerImage);
        final Drawable stripImage = a.getDrawable(R.styleable.AnyKeyboardViewTheme_suggestionBackgroundImage);
        if (stripImage == null)
            setBackgroundColor(Color.BLACK);
        else
            setBackgroundDrawable(stripImage);
        fontSizePixel = a.getDimension(R.styleable.AnyKeyboardViewTheme_suggestionTextSize, fontSizePixel);
    } catch (Exception e) {
        Logger.w(TAG, "Got an exception while reading theme data", e);
    }
    mHorizontalGap = a.getDimension(R.styleable.AnyKeyboardViewTheme_suggestionWordXGap, 20);
    a.recycle();
    mColorNormal = colorNormal;
    mColorRecommended = colorRecommended;
    mColorOther = colorOther;
    if (mDivider == null)
        mDivider = ContextCompat.getDrawable(context, R.drawable.dark_suggestions_divider);
    // end of themed

    mPaint = new Paint();
    mPaint.setColor(mColorNormal);
    mPaint.setAntiAlias(true);
    mPaint.setTextSize(fontSizePixel);
    mPaint.setStrokeWidth(0);
    mPaint.setTextAlign(Align.CENTER);
    mTextPaint = new TextPaint(mPaint);
    final int minTouchableWidth = context.getResources()
            .getDimensionPixelOffset(R.dimen.candidate_min_touchable_width);
    mGestureDetector = new GestureDetector(context, new CandidateStripGestureListener(minTouchableWidth));
    setWillNotDraw(false);
    setHorizontalScrollBarEnabled(false);
    setVerticalScrollBarEnabled(false);
    scrollTo(0, getScrollY());
}