@Override protected void onDraw(Canvas canvas) { float wf = getWidth(); float hf = getHeight(); final float cx = wf/2; final float cy = hf/2; wf -= getPaddingLeft() + getPaddingRight(); hf -= getPaddingTop() + getPaddingBottom(); float rad = (wf < hf) ? wf/2 : hf/2; canvas.drawCircle(cx, cy, rad, mPaint); if (mLegend != null && mLegend.length() > 0) { canvas.drawText(mLegend, 0, mLegend.length(), cx, cy + mLegendPaint.getFontSpacing()/2, mLegendPaint); } // if we're in the middle of a drag, light up as a potential target if (mDragInProgress && mAcceptsDrag) { for (int i = NUM_GLOW_STEPS; i > 0; i--) { int color = (mHovering) ? WHITE_STEP : GREEN_STEP; color = i*(color | ALPHA_STEP); mGlow.setColor(color); canvas.drawCircle(cx, cy, rad, mGlow); rad -= 0.5f; canvas.drawCircle(cx, cy, rad, mGlow); rad -= 0.5f; } } }
@Override protected void onMeasure(int widthSpec, int heightSpec) { int totalDiameter = 2*mRadius + getPaddingLeft() + getPaddingRight(); setMeasuredDimension(totalDiameter, totalDiameter); }
public DraggableDot(Context context, AttributeSet attrs) { super(context, attrs); setFocusable(true); setClickable(true); + "' anr=" + mAnrType); setOnLongClickListener(new View.OnLongClickListener() { public boolean onLongClick(View v) { ClipData data = ClipData.newPlainText("dot", "Dot : " + v.toString());
invalidate(); Log.i(TAG, "Drag ended."); if (mAcceptsDrag) { invalidate(); Log.i(TAG, "Got a drop! dot=" + this + " event=" + event); if (mAnrType == ANR_DROP) { sleepSixSeconds(); processDrop(event); result = true; } break; Log.i(TAG, "Entered dot @ " + this); mHovering = true; invalidate(); } break; Log.i(TAG, "Exited dot @ " + this); mHovering = false; invalidate(); } break;
private void processDrop(DragEvent event) { final ClipData data = event.getClipData(); final int N = data.getItemCount(); for (int i = 0; i < N; i++) { ClipData.Item item = data.getItemAt(i); Log.i(TAG, "Dropped item " + i + " : " + item); if (mReportView != null) { String text = item.coerceToText(getContext()).toString(); if (event.getLocalState() == (Object) this) { text += " : Dropped on self!"; } mReportView.setText(text); } } } }
@Override protected void onMeasure(int widthSpec, int heightSpec) { int totalDiameter = 2*mRadius + getPaddingLeft() + getPaddingRight(); setMeasuredDimension(totalDiameter, totalDiameter); }
public DraggableDot(Context context, AttributeSet attrs) { super(context, attrs); setFocusable(true); setClickable(true); + "' anr=" + mAnrType); setOnLongClickListener(new View.OnLongClickListener() { public boolean onLongClick(View v) { ClipData data = ClipData.newPlainText("dot", "Dot : " + v.toString());
invalidate(); Log.i(TAG, "Drag ended."); if (mAcceptsDrag) { invalidate(); Log.i(TAG, "Got a drop! dot=" + this + " event=" + event); if (mAnrType == ANR_DROP) { sleepSixSeconds(); processDrop(event); result = true; } break; Log.i(TAG, "Entered dot @ " + this); mHovering = true; invalidate(); } break; Log.i(TAG, "Exited dot @ " + this); mHovering = false; invalidate(); } break;
private void processDrop(DragEvent event) { final ClipData data = event.getClipData(); final int N = data.getItemCount(); for (int i = 0; i < N; i++) { ClipData.Item item = data.getItemAt(i); Log.i(TAG, "Dropped item " + i + " : " + item); if (mReportView != null) { String text = item.coerceToText(getContext()).toString(); if (event.getLocalState() == (Object) this) { text += " : Dropped on self!"; } mReportView.setText(text); } } } }
@Override protected void onDraw(Canvas canvas) { float wf = getWidth(); float hf = getHeight(); final float cx = wf/2; final float cy = hf/2; wf -= getPaddingLeft() + getPaddingRight(); hf -= getPaddingTop() + getPaddingBottom(); float rad = (wf < hf) ? wf/2 : hf/2; canvas.drawCircle(cx, cy, rad, mPaint); if (mLegend != null && mLegend.length() > 0) { canvas.drawText(mLegend, 0, mLegend.length(), cx, cy + mLegendPaint.getFontSpacing()/2, mLegendPaint); } // if we're in the middle of a drag, light up as a potential target if (mDragInProgress && mAcceptsDrag) { for (int i = NUM_GLOW_STEPS; i > 0; i--) { int color = (mHovering) ? WHITE_STEP : GREEN_STEP; color = i*(color | ALPHA_STEP); mGlow.setColor(color); canvas.drawCircle(cx, cy, rad, mGlow); rad -= 0.5f; canvas.drawCircle(cx, cy, rad, mGlow); rad -= 0.5f; } } }