Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 当最大值接近100000000时,我无法搜索最小值或最大值_Java_Android - Fatal编程技术网

Java 当最大值接近100000000时,我无法搜索最小值或最大值

Java 当最大值接近100000000时,我无法搜索最小值或最大值,java,android,Java,Android,我正在使用库,如果我将最大值设置在1000附近,它工作正常,但当我将最大值设置为100000000时,我无法在最小值或最大值处搜索 这是我的密码 <com.hdfcclife.activities.SeekArc android:id="@+id/seekArc" android:layout_width="match_parent" android:layout_height="wrap_content" android:l

我正在使用库,如果我将最大值设置在1000附近,它工作正常,但当我将最大值设置为100000000时,我无法在最小值或最大值处搜索

这是我的密码

<com.hdfcclife.activities.SeekArc
        android:id="@+id/seekArc"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
         seekarc:arcWidth="@dimen/seekwidth"
        seekarc:progressWidth="@dimen/seekprowidth"
        seekarc:arcColor="@android:color/white"
        seekarc:clockwise="true"
        android:layout_marginTop="@dimen/seektop"
        seekarc:max="100000000"
        seekarc:progressColor="@color/red"
        seekarc:rotation="250"
        seekarc:startAngle="62"
        seekarc:sweepAngle="95"
        seekarc:thumb="@drawable/custom_seek_arc_control_selector"
        seekarc:touchInside="false"
         />

这是代码

public class SeekArc extends View {

private static final String TAG = SeekArc.class.getSimpleName();
private static int INVALID_PROGRESS_VALUE = -1;
// The initial rotational offset -90 means we start at 12 o'clock
private final int mAngleOffset = -90;

/**
 * The Drawable for the seek arc thumbnail
 */
private Drawable mThumb;

/**
 * The Maximum value that this SeekArc can be set to
 */
private long mMax = 100;
private int mMaxV = 100;

/**
 * The Current value that the SeekArc is set to
 */
private long mProgress = 0;
private int mProg = 0;

/**
 * The width of the progress line for this SeekArc
 */
private int mProgressWidth = 12;

/**
 * The Width of the background arc for the SeekArc 
 */
private int mArcWidth = 18;

/**
 * The Angle to start drawing this Arc from
 */
private int mStartAngle = 0;

/**
 * The Angle through which to draw the arc (Max is 360)
 */
private int mSweepAngle = 360;

/**
 * The rotation of the SeekArc- 0 is twelve o'clock
 */
private int mRotation = 0;

/**
 * Give the SeekArc rounded edges
 */
private boolean mRoundedEdges = false;

/**
 * Enable touch inside the SeekArc
 */
private boolean mTouchInside = true;

/**
 * Will the progress increase clockwise or anti-clockwise
 */
private boolean mClockwise = true;

// Internal variables
private int mArcRadius = 0;
private float mProgressSweep = 0;
private RectF mArcRect = new RectF();
private Paint mArcPaint;
private Paint mProgressPaint;
private int mTranslateX;
private int mTranslateY;
private int mThumbXPos;
private int mThumbYPos;
private double mTouchAngle;
private float mTouchIgnoreRadius;
private OnSeekArcChangeListener mOnSeekArcChangeListener;

public interface OnSeekArcChangeListener {

    /**
     * Notification that the progress level has changed. Clients can use the
     * fromUser parameter to distinguish user-initiated changes from those
     * that occurred programmatically.
     * 
     * @param seekArc
     *            The SeekArc whose progress has changed
     * @param progress
     *            The current progress level. This will be in the range
     *            0..max where max was set by
     *            {@link ProgressArc#setMax(int)}. (The default value for
     *            max is 100.)
     * @param fromUser
     *            True if the progress change was initiated by the user.
     */
    void onProgressChanged(SeekArc seekArc, long progress, boolean fromUser);

    /**
     * Notification that the user has started a touch gesture. Clients may
     * want to use this to disable advancing the seekbar.
     * 
     * @param seekArc
     *            The SeekArc in which the touch gesture began
     */
    void onStartTrackingTouch(SeekArc seekArc);

    /**
     * Notification that the user has finished a touch gesture. Clients may
     * want to use this to re-enable advancing the seekarc.
     * 
     * @param seekArc
     *            The SeekArc in which the touch gesture began
     */
    void onStopTrackingTouch(SeekArc seekArc);
}

public SeekArc(Context context) {
    super(context);
    init(context, null, 0);
}

public SeekArc(Context context, AttributeSet attrs) {
    super(context, attrs);
    init(context, attrs, R.attr.seekArcStyle);
}

public SeekArc(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    init(context, attrs, defStyle);
}

private void init(Context context, AttributeSet attrs, int defStyle) {

    Log.d(TAG, "Initialising SeekArc");
    final Resources res = getResources();
    float density = context.getResources().getDisplayMetrics().density;

    // Defaults, may need to link this into theme settings
    int arcColor = res.getColor(R.color.progress_gray);
    int progressColor = res.getColor(android.R.color.holo_blue_light);
    int thumbHalfheight = 0;
    int thumbHalfWidth = 0;
    mThumb = res.getDrawable(R.drawable.seek_arc_control_selector);
    // Convert progress width to pixels for current density
    mProgressWidth = (int) (mProgressWidth * density);


    if (attrs != null) {
        // Attribute initialization
        final TypedArray a = context.obtainStyledAttributes(attrs,
                R.styleable.SeekArc, defStyle, 0);

        Drawable thumb = a.getDrawable(R.styleable.SeekArc_thumb);
        if (thumb != null) {
            mThumb = thumb;
        }



        thumbHalfheight = (int) mThumb.getIntrinsicHeight() / 2;
        thumbHalfWidth = (int) mThumb.getIntrinsicWidth() / 2;
        mThumb.setBounds(-thumbHalfWidth, -thumbHalfheight, thumbHalfWidth,
                thumbHalfheight);

        mMax = a.getInteger(R.styleable.SeekArc_max, mMaxV);
        Integer mPro = a.getInteger(R.styleable.SeekArc_progress, mProg);
        mProgress=new Long(mPro);
        mProgressWidth = (int) a.getDimension(
                R.styleable.SeekArc_progressWidth, mProgressWidth);
        mArcWidth = (int) a.getDimension(R.styleable.SeekArc_arcWidth,
                mArcWidth);
        mStartAngle = a.getInt(R.styleable.SeekArc_startAngle, mStartAngle);
        mSweepAngle = a.getInt(R.styleable.SeekArc_sweepAngle, mSweepAngle);
        mRotation = a.getInt(R.styleable.SeekArc_rotation, mRotation);
        mRoundedEdges = a.getBoolean(R.styleable.SeekArc_roundEdges,
                mRoundedEdges);
        mTouchInside = a.getBoolean(R.styleable.SeekArc_touchInside,
                mTouchInside);
        mClockwise = a.getBoolean(R.styleable.SeekArc_clockwise,
                mClockwise);

        arcColor = a.getColor(R.styleable.SeekArc_arcColor, arcColor);
        progressColor = a.getColor(R.styleable.SeekArc_progressColor,
                progressColor);

        a.recycle();
    }

    mProgress = (mProgress > mMax) ? mMax : mProgress;
    mProgress = (mProgress < 0) ? 0 : mProgress;

    mSweepAngle = (mSweepAngle > 360) ? 360 : mSweepAngle;
    mSweepAngle = (mSweepAngle < 0) ? 0 : mSweepAngle;

    mStartAngle = (mStartAngle > 360) ? 0 : mStartAngle;
    mStartAngle = (mStartAngle < 0) ? 0 : mStartAngle;

    mArcPaint = new Paint();
    mArcPaint.setColor(arcColor);
    mArcPaint.setAntiAlias(true);
    mArcPaint.setStyle(Paint.Style.STROKE);
    mArcPaint.setStrokeWidth(mArcWidth);
    mArcPaint.setStrokeMiter(5.5f);
    //mArcPaint.setAlpha(45);

    mProgressPaint = new Paint();
    mProgressPaint.setColor(progressColor);
    mProgressPaint.setAntiAlias(true);
    mProgressPaint.setStyle(Paint.Style.STROKE);
    mProgressPaint.setStrokeWidth(mProgressWidth);

    if (mRoundedEdges) {
        mArcPaint.setStrokeCap(Paint.Cap.ROUND);
        mProgressPaint.setStrokeCap(Paint.Cap.ROUND);
    }
}

@Override
protected void onDraw(Canvas canvas) {      
    if(!mClockwise) {
        canvas.scale(-1, 1, mArcRect.centerX(), mArcRect.centerY() );
    }

    // Draw the arcs
    final int arcStart = mStartAngle + mAngleOffset + mRotation;
    final int arcSweep = mSweepAngle;
    canvas.drawArc(mArcRect, arcStart, arcSweep, false, mArcPaint);
    canvas.drawArc(mArcRect, arcStart, mProgressSweep, false,
            mProgressPaint);

    // Draw the thumb nail
    canvas.translate(mTranslateX -mThumbXPos, mTranslateY -mThumbYPos);
    mThumb.draw(canvas);        
}


@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

    final int height = getDefaultSize(getSuggestedMinimumHeight(),
            heightMeasureSpec);
    final int width = getDefaultSize(getSuggestedMinimumWidth(),
            widthMeasureSpec);
    final int min = Math.min(width, height);
    float top = 0;
    float left = 0;
    int arcDiameter = 0;

    mTranslateX = (int) (width * 0.5f);
    mTranslateY = (int) (height * 0.5f);

    arcDiameter = min - getPaddingLeft();
    mArcRadius = arcDiameter / 2;
    top = (height / 2 - (arcDiameter / 2));
    left = width / 2 - (arcDiameter / 2);
    mArcRect.set(left, top, left + arcDiameter, top + arcDiameter);

    int arcStart = (int)mProgressSweep + mStartAngle  + mRotation + 90;
    mThumbXPos = (int) (mArcRadius * Math.cos(Math.toRadians(arcStart)));
    mThumbYPos = (int) (mArcRadius * Math.sin(Math.toRadians(arcStart)));

    setTouchInSide(mTouchInside);
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

@Override
public boolean onTouchEvent(MotionEvent event) {
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        onStartTrackingTouch();
        updateOnTouch(event);
        break;
    case MotionEvent.ACTION_MOVE:
        updateOnTouch(event);
        break;
    case MotionEvent.ACTION_UP:
        onStopTrackingTouch();
        setPressed(false);
        break;
    case MotionEvent.ACTION_CANCEL:
        onStopTrackingTouch();
        setPressed(false);

        break;
    }

    return true;
}

@Override
protected void drawableStateChanged() {
    super.drawableStateChanged();
    if (mThumb != null && mThumb.isStateful()) {
        int[] state = getDrawableState();
        mThumb.setState(state);
    }
    invalidate();
}

private void onStartTrackingTouch() {
    if (mOnSeekArcChangeListener != null) {
        mOnSeekArcChangeListener.onStartTrackingTouch(this);
    }
}

private void onStopTrackingTouch() {
    if (mOnSeekArcChangeListener != null) {
        mOnSeekArcChangeListener.onStopTrackingTouch(this);
    }
}

private void updateOnTouch(MotionEvent event) {
    boolean ignoreTouch = ignoreTouch(event.getX(), event.getY());
    if (ignoreTouch) {
        return;
    }
    setPressed(true);
    mTouchAngle = getTouchDegrees(event.getX(), event.getY());
    int progress = getProgressForAngle(mTouchAngle);
    onProgressRefresh(progress, true);
}

private boolean ignoreTouch(float xPos, float yPos) {
    boolean ignore = false;
    float x = xPos - mTranslateX;
    float y = yPos - mTranslateY;

    float touchRadius = (float) Math.sqrt(((x * x) + (y * y)));
    if (touchRadius < mTouchIgnoreRadius) {
        ignore = true;
    }else if(touchRadius>mArcRadius+40)
    {
        ignore = true;
    }
    return ignore;
}

private double getTouchDegrees(float xPos, float yPos) {
    float x = xPos - mTranslateX;
    float y = yPos - mTranslateY;
    //invert the x-coord if we are rotating anti-clockwise
    x= (mClockwise) ? x:-x;
    // convert to arc Angle
    double angle = Math.toDegrees(Math.atan2(y, x) + (Math.PI / 2)
            - Math.toRadians(mRotation));
    if (angle < 0) {
        angle = 360 + angle;
    }
    angle -= mStartAngle;
    return angle;
}

private int getProgressForAngle(double angle) {
    int touchProgress = (int) Math.round(valuePerDegree() * angle);

    touchProgress = (touchProgress < 0) ? INVALID_PROGRESS_VALUE
            : touchProgress;
    touchProgress = (touchProgress > mMax) ? INVALID_PROGRESS_VALUE
            : touchProgress;
    return touchProgress;
}

private float valuePerDegree() {
    return (float) mMax / mSweepAngle;
}

private void onProgressRefresh(int progress, boolean fromUser) {
    updateProgress(progress, fromUser);
}

private void updateThumbPosition() {
    int thumbAngle = (int) (mStartAngle + mProgressSweep + mRotation + 90);
    mThumbXPos = (int) (mArcRadius * Math.cos(Math.toRadians(thumbAngle)));
    mThumbYPos = (int) (mArcRadius * Math.sin(Math.toRadians(thumbAngle)));
}

private void updateProgress(long progress, boolean fromUser) {

    if (progress == INVALID_PROGRESS_VALUE) {
        return;
    }

    if (mOnSeekArcChangeListener != null) {
        mOnSeekArcChangeListener
                .onProgressChanged(this, progress, fromUser);
    }

    progress = (progress > mMax) ? mMax : progress;
    progress = (mProgress < 0) ? 0 : progress;

    mProgress = (int) progress;
    mProgressSweep = (float) progress / mMax * mSweepAngle;

    updateThumbPosition();

    invalidate();
}

/**
 * Sets a listener to receive notifications of changes to the SeekArc's
 * progress level. Also provides notifications of when the user starts and
 * stops a touch gesture within the SeekArc.
 * 
 * @param l
 *            The seek bar notification listener
 * 
 * @see SeekArc.OnSeekBarChangeListener
 */
public void setOnSeekArcChangeListener(OnSeekArcChangeListener l) {
    mOnSeekArcChangeListener = l;
}

public void setProgress(long progress) {
    updateProgress(progress, false);
}
public void setMax(long progress) {
    mMax=progress;
    invalidate();
}

public int getProgressWidth() {
    return mProgressWidth;
}

public void setProgressWidth(int mProgressWidth) {
    this.mProgressWidth = mProgressWidth;
    mProgressPaint.setStrokeWidth(mProgressWidth);
}

public int getArcWidth() {
    return mArcWidth;
}

public void setArcWidth(int mArcWidth) {
    this.mArcWidth = mArcWidth;
    mArcPaint.setStrokeWidth(mArcWidth);
}
public int getArcRotation() {
    return mRotation;
}

public void setArcRotation(int mRotation) {
    this.mRotation = mRotation;
    updateThumbPosition();
}

public int getStartAngle() {
    return mStartAngle;
}

public void setStartAngle(int mStartAngle) {
    this.mStartAngle = mStartAngle;
    updateThumbPosition();
}

public int getSweepAngle() {
    return mSweepAngle;
}

public void setSweepAngle(int mSweepAngle) {
    this.mSweepAngle = mSweepAngle;
    updateThumbPosition();
}

public void setRoundedEdges(boolean isEnabled) {
    mRoundedEdges = isEnabled;
    if (mRoundedEdges) {
        mArcPaint.setStrokeCap(Paint.Cap.ROUND);
        mProgressPaint.setStrokeCap(Paint.Cap.ROUND);
    } else {
        mArcPaint.setStrokeCap(Paint.Cap.SQUARE);
        mProgressPaint.setStrokeCap(Paint.Cap.SQUARE);
    }
}

public void setTouchInSide(boolean isEnabled) {
    int thumbHalfheight = (int) mThumb.getIntrinsicHeight() / 2;
    int thumbHalfWidth = (int) mThumb.getIntrinsicWidth() / 2;
    mTouchInside = isEnabled;
    if (mTouchInside) {
        mTouchIgnoreRadius = (float) mArcRadius / 4;
    } else {
        // Don't use the exact radius makes interaction too tricky
        mTouchIgnoreRadius = mArcRadius
                - Math.min(thumbHalfWidth, thumbHalfheight);
    }
}

public void setClockwise(boolean isClockwise) {
    mClockwise = isClockwise;
}
}
public类SeekArc扩展视图{
私有静态最终字符串标记=SeekArc.class.getSimpleName();
私有静态int无效_进程_值=-1;
//初始旋转偏移量-90意味着我们从12点开始
私有最终整数mAngleOffset=-90;
/**
*可绘制的搜索弧缩略图
*/
私人可提取mThumb;
/**
*此SeekArc可以设置为的最大值
*/
私人长mMax=100;
私有int mMaxV=100;
/**
*SeekArc设置为的当前值
*/
私有长进程=0;
私有整数mProg=0;
/**
*此SeekArc的进度线宽度
*/
私有int mProgressWidth=12;
/**
*SeekArc的背景弧的宽度
*/
私有宽度=18;
/**
*开始绘制此圆弧的角度
*/
私有int mStartAngle=0;
/**
*绘制圆弧的角度(最大值为360)
*/
私人角度=360;
/**
*SeekArc-0的旋转是12点钟
*/
私有整数旋转=0;
/**
*给SeekArc圆边
*/
私有布尔值mRoundedEdges=false;
/**
*在SeekArc内启用触摸
*/
私有布尔值mTouchInside=true;
/**
*进度是顺时针还是逆时针增加
*/
私有布尔值mClockwise=true;
//内部变量
私有int mArcRadius=0;
专用浮点mProgressSweep=0;
private RectF mArcRect=新的RectF();
私人涂料;
私人涂料;
私人国际运输公司;
私人内部交易;
私营部门;
私营企业;
私家双首长乐;
私人浮子mTouchIgnoreRadius;
私有OnSeekArcChangeListener mOnSeekArcChangeListener;
SeekarcChangeListener上的公共接口{
/**
*通知进度级别已更改。客户端可以使用
*fromUser参数以区分用户发起的更改和
*这是通过编程实现的。
* 
*@param seekArc
*进展已经改变的赛卡人
*@param进度
*当前进度级别。这将在范围内
*0..max,其中max由
*{@link ProgressArc#setMax(int)}。(的默认值
*最大值为100。)
*@param fromUser
*如果进度更改是由用户发起的,则为True。
*/
void onProgressChanged(SeekArc SeekArc,long progress,boolean fromUser);
/**
*通知用户已开始触摸手势。客户端可能会
*要使用此选项禁用seekbar前进。
* 
*@param seekArc
*触摸手势开始的SeekArc
*/
开始跟踪触摸时无效(参见KARC SeekArc);
/**
*用户已完成触摸手势的通知。客户端可能会
*希望使用此选项重新启用seekarc。
* 
*@param seekArc
*触摸手势开始的SeekArc
*/
TopTrackingTouch无效(参见KARC SeekArc);
}
公共SeekArc(上下文){
超级(上下文);
init(上下文,null,0);
}
公共SeekArc(上下文、属性集属性){
超级(上下文,attrs);
init(context,attrs,R.attr.seekArcStyle);
}
公共SeekArc(上下文、属性集属性、int-defStyle){
超级(上下文、属性、定义样式);
init(上下文、属性、定义样式);
}
私有void init(上下文上下文、属性集attrs、int-defStyle){
日志d(标签“初始化SeekArc”);
最终资源res=getResources();
float density=context.getResources().getDisplayMetrics().density;
//默认设置,可能需要将其链接到主题设置中
int arcColor=res.getColor(R.color.progress\u gray);
int progressColor=res.getColor(android.R.color.holo_蓝光);
int-thumbHalfheight=0;
int thumbHalfWidth=0;
mThumb=res.getDrawable(R.drawable.seek\u arc\u control\u选择器);
//将进度宽度转换为当前密度的像素
mProgressWidth=(int)(mProgressWidth*密度);
如果(属性!=null){
//属性初始化
最终类型Darray a=上下文。获取样式属性(属性,
R.styleable.SeekArc,defStyle,0);
Drawable thumb=a.getDrawable(R.styleable.SeekArc_thumb);
if(thumb!=null){
mThumb=拇指;
}
thumbHalfheight=(int)mThumb.getIntrinsicHeight()/2;
thumbHalfWidth=(int)mThumb.getIntrinsicWidth()/2;
mThumb.立根(-thumbHalfWidth,-thumbHalfheight,thumbHalfWidth,
拇指半高);
mMax=a.getInteger(R.styleable.SeekArc_max,mMaxV);
整数mPro=a.getInteger(R.styleable.SeekArc_progress,mProg);
mProgress=新长(mPro);
mProgressWidth=(int)a.getDimension(
R.styleable.SeekArc_progressWidth,mProgressWidth);
mArcWidth=(int)a.getDimension(R.styleable.SeekArc_arcWidth,
宽度);
mStartAngle=a.getInt(R.styleable.SeekArc_startAngle,mStartAngle);
msweapangle=a.getInt(R.styleable.SeekArc_扫描角度,msweapangle);
mRotation=a.getInt(R.styleable.SeekArc_旋转,mRotation);
mRoundedEdges=a.getBoolean(R.styleable.SeekArc_roundEdges,
mRoundedEdges);
mTouchInside=a.getBoolean(R.styleable.SeekArc_touchind,
mTouchInside);
mClockwise=a.getBoolean(R.styleable.SeekArc_顺时针,
mClockwise);
arcColor=a.getColor(R.styleable.SeekArc_arcColor,arcColor);
progressColor=a.getColor(R.styleable.SeekArc\u progressColor,
颜色);
a、 回收();
}
mProgress=(mProgress>mMax)?mMax:mProgress;
private long mMax = 100;
private int mMaxV = 100;
private long mMax = 100000000;
private int mMaxV = 100000000;