<commit_before>/*
 * Copyright (C) 2011 <NAME> (http://www.cyrilmottier.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package greendroid.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;

import com.cyrilmottier.android.greendroid.R;

/**
 * Visual indicator of a paged content. The {@link PageIndicator} usually
 * displays a line of dots. Each dot represents a page. {@link PageIndicator}
 * supports two types of dots. In {@link DotType#SINGLE} mode, all dots are
 * drawn but only one is is the selected state and represents the selected page,
 * In {@link DotType#MULTIPLE} the selected page is actually represented by the
 * amount of dots currently drawn. other dots are drawn.
 * 
 * @author <NAME>
 */
public class PageIndicator extends View {

    /**
     * Constant that may be used to select none of the dots in the
     * {@link PageIndicator}
     */
    public static final int NO_ACTIVE_DOT = -1;

    /**
     * Interface containing of dot types supported by the {@link PageIndicator}
     * class.
     * 
     * @author <NAME>
     */
    public interface DotType {
        /**
         * Represents the single dot type. Only one selected dot may be drawn.
         */
        int SINGLE = 0;
        /**
         * Represents the multiple dot type. Several selected dot may be drawn.
         */
        int MULTIPLE = 1;
    }

    private static final int MIN_DOT_COUNT = 1;

    private static Rect sInRect = new Rect();
    private static Rect sOutRect = new Rect();

    private int mGravity;
    private int mDotSpacing;
    private Drawable mDotDrawable;
    private int mDotCount;
    private int mDotType;

    private int mActiveDot;

    private int[] mExtraState;

    private boolean mInitializing;

    public PageIndicator(Context context) {
        this(context, null);
    }

    public PageIndicator(Context context, AttributeSet attrs) {
        this(context, attrs, R.attr.gdPageIndicatorStyle);
    }

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

        mInitializing = true;

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

        setDotCount(a.getInt(R.styleable.PageIndicator_dotCount, mDotCount));
        setActiveDot(a.getInt(R.styleable.PageIndicator_activeDot, mActiveDot));
        setDotDrawable(a.getDrawable(R.styleable.PageIndicator_dotDrawable));
        setDotSpacing(a.getDimensionPixelSize(R.styleable.PageIndicator_dotSpacing, mDotSpacing));
        setGravity(a.getInt(R.styleable.PageIndicator_gravity, mGravity));
        setDotType(a.getInt(R.styleable.PageIndicator_dotType, mDotType));

        a.recycle();

        mInitializing = false;
    }

    private void initPageIndicator() {
        mDotCount = MIN_DOT_COUNT;
        mGravity = Gravity.CENTER;
        mActiveDot = 0;
        mDotSpacing = 0;
        mDotType = DotType.SINGLE;
    }

    /**
     * How many dots are drawn by this {@link PageIndicator}
     * 
     * @return The maximum number of dots.
     */
    public int getDotCount() {
        return mDotCount;
    }

    /**
     * Sets the number of dots.
     * 
     * @param dotCount The number oF dots
     * @see #getDotCount()
     */
    public void setDotCount(int dotCount) {<commit_msg>Make sure the mExtraState array is not null<commit_after>/*
 * Copyright (C) 2011 <NAME> (http://www.cyrilmottier.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package greendroid.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;

import com.cyrilmottier.android.greendroid.R;

/**
 * Visual indicator of a paged content. The {@link PageIndicator} usually
 * displays a line of dots. Each dot represents a page. {@link PageIndicator}
 * supports two types of dots. In {@link DotType#SINGLE} mode, all dots are
 * drawn but only one is is the selected state and represents the selected page,
 * In {@link DotType#MULTIPLE} the selected page is actually represented by the
 * amount of dots currently drawn. other dots are drawn.
 * 
 * @author <NAME>
 */
public class PageIndicator extends View {

    /**
     * Constant that may be used to select none of the dots in the
     * {@link PageIndicator}
     */
    public static final int NO_ACTIVE_DOT = -1;

    /**
     * Interface containing of dot types supported by the {@link PageIndicator}
     * class.
     * 
     * @author <NAME>
     */
    public interface DotType {
        /**
         * Represents the single dot type. Only one selected dot may be drawn.
         */
        int SINGLE = 0;
        /**
         * Represents the multiple dot type. Several selected dot may be drawn.
         */
        int MULTIPLE = 1;
    }

    private static final int MIN_DOT_COUNT = 1;

    private static Rect sInRect = new Rect();
    private static Rect sOutRect = new Rect();

    private int mGravity;
    private int mDotSpacing;
    private Drawable mDotDrawable;
    private int mDotCount;
    private int mDotType;

    private int mActiveDot;

    private int[] mExtraState;

    private boolean mInitializing;

    public PageIndicator(Context context) {
        this(context, null);
    }

    public PageIndicator(Context context, AttributeSet attrs) {
        this(context, attrs, R.attr.gdPageIndicatorStyle);
    }

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

        mInitializing = true;

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

        setDotCount(a.getInt(R.styleable.PageIndicator_dotCount, mDotCount));
        setActiveDot(a.getInt(R.styleable.PageIndicator_activeDot, mActiveDot));
        setDotDrawable(a.getDrawable(R.styleable.PageIndicator_dotDrawable));
        setDotSpacing(a.getDimensionPixelSize(R.styleable.PageIndicator_dotSpacing, mDotSpacing));
        setGravity(a.getInt(R.styleable.PageIndicator_gravity, mGravity));
        setDotType(a.getInt(R.styleable.PageIndicator_dotType, mDotType));

        a.recycle();

        mInitializing = false;
    }

    private void initPageIndicator() {
        mDotCount = MIN_DOT_COUNT;
        mGravity = Gravity.CENTER;
        mActiveDot = 0;
        mDotSpacing = 0;
        mDotType = DotType.SINGLE;
        
        mExtraState = onCreateDrawableState(1);
        mergeDrawableStates(mExtraState, SELECTED_STATE_SET);
    }

    /**
     * How many dots are drawn by this {@link PageIndicator}
     * 
     * @return The maximum number of dots.
     */
    public int getDotCount() {
        return mDotCount;
    }

    /**
     * Sets the number of dots.
     * 
     * @param dotCount The number oF dots
     * @see #getDotCount()
     */
    public void setDotCount(int dotCount) {
{'fraction_non_alphanumeric': 0.08632588606854603, 'fraction_numerical': 0.0036261551058603347, 'mean_word_length': 2.991596638655462, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '409740', 'n_tokens_mistral': 2465, 'n_tokens_neox': 2438, 'n_words': 789}