Forum » Programiranje » Programiranje problem android
Programiranje problem android
g333kk ::
Delam program z veselja imam pa vprašnje, oz mi zadeva ne dela dobro.
Da vas seznanim z problemom:
-move
-zoom
Če mi kdo hoče pomagati mu pošljem kodo, limat jo ne mislim ker je predolga.
Lepo Vas Prosim, za pomoč.
lp
Matej
Da vas seznanim z problemom:
-move
-zoom
Če mi kdo hoče pomagati mu pošljem kodo, limat jo ne mislim ker je predolga.
Lepo Vas Prosim, za pomoč.
lp
Matej
- odbrisal: Gandalfar ()
g333kk ::
Muiči me bom zastavil izrez kode:
DrawHandler.java
Panel.java
Kompajlar javi tole:
10-07 20:52:49.882: W/dalvikvm(955): threadid=1: thread exiting with uncaught exception (group=0x40015560)
10-07 20:52:49.976: E/AndroidRuntime(955): FATAL EXCEPTION: main
10-07 20:52:49.976: E/AndroidRuntime(955): java.lang.NullPointerException
10-07 20:52:49.976: E/AndroidRuntime(955): at aa.bb.cc.DrawHandler.handleMoveTool(DrawHandler.java:477)
10-07 20:52:49.976: E/AndroidRuntime(955): at aa.bb.cc.DrawHandler.handleTouchEvent(DrawHandler.java:452)
10-07 20:52:49.976: E/AndroidRuntime(955): at aa.bb.cc.Panel.onTouchEvent(Panel.java:328)
10-07 20:52:49.976: E/AndroidRuntime(955): at android.view.View.dispatchTouchEvent(View.java:3885)
10-07 20:52:49.976: E/AndroidRuntime(955): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
10-07 20:52:49.976: E/AndroidRuntime(955): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
10-07 20:52:49.976: E/AndroidRuntime(955): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
10-07 20:52:49.976: E/AndroidRuntime(955): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
10-07 20:52:49.976: E/AndroidRuntime(955): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1691)
10-07 20:52:49.976: E/AndroidRuntime(955): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1125)
10-07 20:52:49.976: E/AndroidRuntime(955): at android.app.Activity.dispatchTouchEvent(Activity.java:2096)
10-07 20:52:49.976: E/AndroidRuntime(955): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1675)
10-07 20:52:49.976: E/AndroidRuntime(955): at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2194)
10-07 20:52:49.976: E/AndroidRuntime(955): at android.view.ViewRoot.handleMessage(ViewRoot.java:1878)
10-07 20:52:49.976: E/AndroidRuntime(955): at android.os.Handler.dispatchMessage(Handler.java:99)
10-07 20:52:49.976: E/AndroidRuntime(955): at android.os.Looper.loop(Looper.java:123)
10-07 20:52:49.976: E/AndroidRuntime(955): at android.app.ActivityThread.main(ActivityThread.java:3683)
10-07 20:52:49.976: E/AndroidRuntime(955): at java.lang.reflect.Method.invokeNative(Native Method)
10-07 20:52:49.976: E/AndroidRuntime(955): at java.lang.reflect.Method.invoke(Method.java:507)
10-07 20:52:49.976: E/AndroidRuntime(955): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-07 20:52:49.976: E/AndroidRuntime(955): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-07 20:52:49.976: E/AndroidRuntime(955): at dalvik.system.NativeStart.main(Native Method)
10-07 20:52:55.642: I/Process(955): Sending signal. PID: 955 SIG: 9
DrawHandler.java
private float xTouchCoordinate; private float yTouchCoordinate; private float previousX; private float previousY; private float oldDist; private boolean hasMoved; private boolean pinchToZoom; Point point; public void handleTouchEvent(MotionEvent event) { Point point1 = new Point(event.getX(), event.getY()); point=point1; xTouchCoordinate = event.getX(); yTouchCoordinate = event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: previousX = xTouchCoordinate; previousY = yTouchCoordinate; hasMoved = false; break; case MotionEvent.ACTION_MOVE: float dx = Math.abs(xTouchCoordinate - previousX); float dy = Math.abs(yTouchCoordinate - previousY); if (dx > moveThreshold || dy > moveThreshold) { hasMoved = true; } break; } // always allow pinch to zoom handlePinchToZoom(event); // if zooming, don't handle tools if (!pinchToZoom) { switch (SELECTED_SHAPE) { case LINE: case FREEHAND: case RECTANGLE: case CIRCLE: case OVAL: case ERASE: case FILL: case SPRAY: handleBrushTool(event); break; case MOVE: handleMoveTool(event); break; } } previousX = xTouchCoordinate; previousY = yTouchCoordinate; } private float spacing(MotionEvent event) { float x = event.getX(0) - event.getX(1); float y = event.getY(0) - event.getY(1); return FloatMath.sqrt(x * x + y * y); } /** * Scroll the picture. */ private void handleMoveTool(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_MOVE: int dx = Math.round(xTouchCoordinate - previousX); int dy = Math.round(yTouchCoordinate - previousY); mPanel.scroll(dx, dy); break; } } /** * Zoom into the picture or out of it. */ void handlePinchToZoom(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_POINTER_2_DOWN: oldDist = spacing(event) / mPanel.getZoom(); pinchToZoom = true; break; case MotionEvent.ACTION_MOVE: if (pinchToZoom) { float newDist = spacing(event); if (newDist > 10) { float scale = newDist / oldDist; mPanel.zoom(scale); } } break; default: pinchToZoom = false; } } void handleBrushTool(MotionEvent event) { if (SELECTED_SHAPE == SHAPES.ERASE) { mCurrentPaint = mErasePaint; } else mCurrentPaint = mPaint; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mDownPoint = point; break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_MOVE: setCurrentShape(SELECTED_SHAPE, point); if (mOnDrawListener != null) { if (event.getAction() == MotionEvent.ACTION_MOVE) { mOnDrawListener.onDrawShapeTemp(mCurrentShape, mCurrentPaint); } else { mOnDrawListener.onDrawShape(mCurrentShape, mCurrentPaint); } } break; } if (event.getAction() == MotionEvent.ACTION_UP) { GRAPHICOBJECTS.add(new AuditContainer(mCurrentShape.getPath(), mCurrentPaint)); // undopaint.length; mCurrentShape = null; } }
Panel.java
float getZoom() { return zoom; } void scroll(int dx, int dy) { float surfaceZoomedWidth = rectSurface.right / zoom; float surfaceZoomedHeight = rectSurface.bottom / zoom; // Don't scroll if the (zoomed) bitmap is smaller than the surface. if ((surfaceZoomedWidth - rectBitmap.right) > 0 && (surfaceZoomedHeight - rectBitmap.bottom) > 0) { scroll.set(0, 0); } else { scroll.offset(Math.round(dx / zoom), Math.round(dy / zoom)); float pivotX = surfaceCenter.x - (surfaceCenter.x / zoom); float pivotY = surfaceCenter.y - (surfaceCenter.y / zoom); float xMax = (surfaceZoomedWidth - rectBitmap.right) + pivotX; float yMax = (surfaceZoomedHeight - rectBitmap.bottom) + pivotY; if (scroll.x < xMax) { scroll.x = Math.round(xMax); } if (scroll.y < yMax) { scroll.y = Math.round(yMax); } // Make checks for upper left corner after checks for // lower right corner to prevent jumping. if (scroll.x - pivotX > 0) { scroll.x = Math.round(pivotX); } if (scroll.y - pivotY > 0) { scroll.y = Math.round(pivotY); } } } /** * Set the zoom factor for the Canvas. * * @param scale [1.0..*] Factor to zoom. */ void zoom(float scale) { if (zoom >= 1) { zoom = scale; } if (zoom < 1) { zoom = 1; } } public boolean onTouchEvent(MotionEvent event) { // Če je ACTION_MOVE pa da se številka poveča iz 1 na 2 prekineš tmpDrawing pa skaliraš sliko. // Če je pa kuj 2, pa direkt začeneš skalirat. // event.getPointerCount() mDrawHandler.handleTouchEvent(event); // mDrawHandler.handleBrushTool(event); return true; } public void drawBitmap(Bitmap btp) { displayCanvas = getHolder().lockCanvas(); displayCanvas.scale(zoom, zoom, surfaceCenter.x, surfaceCenter.y); displayCanvas.translate(scroll.x, scroll.y); // displayCanvas.drawPaint(checkeredPattern); displayCanvas.drawColor(mBackgroundColor); displayCanvas.drawBitmap(btp, 0, 0, null); getHolder().unlockCanvasAndPost(displayCanvas); }
Kompajlar javi tole:
10-07 20:52:49.882: W/dalvikvm(955): threadid=1: thread exiting with uncaught exception (group=0x40015560)
10-07 20:52:49.976: E/AndroidRuntime(955): FATAL EXCEPTION: main
10-07 20:52:49.976: E/AndroidRuntime(955): java.lang.NullPointerException
10-07 20:52:49.976: E/AndroidRuntime(955): at aa.bb.cc.DrawHandler.handleMoveTool(DrawHandler.java:477)
10-07 20:52:49.976: E/AndroidRuntime(955): at aa.bb.cc.DrawHandler.handleTouchEvent(DrawHandler.java:452)
10-07 20:52:49.976: E/AndroidRuntime(955): at aa.bb.cc.Panel.onTouchEvent(Panel.java:328)
10-07 20:52:49.976: E/AndroidRuntime(955): at android.view.View.dispatchTouchEvent(View.java:3885)
10-07 20:52:49.976: E/AndroidRuntime(955): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
10-07 20:52:49.976: E/AndroidRuntime(955): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
10-07 20:52:49.976: E/AndroidRuntime(955): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
10-07 20:52:49.976: E/AndroidRuntime(955): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
10-07 20:52:49.976: E/AndroidRuntime(955): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1691)
10-07 20:52:49.976: E/AndroidRuntime(955): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1125)
10-07 20:52:49.976: E/AndroidRuntime(955): at android.app.Activity.dispatchTouchEvent(Activity.java:2096)
10-07 20:52:49.976: E/AndroidRuntime(955): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1675)
10-07 20:52:49.976: E/AndroidRuntime(955): at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2194)
10-07 20:52:49.976: E/AndroidRuntime(955): at android.view.ViewRoot.handleMessage(ViewRoot.java:1878)
10-07 20:52:49.976: E/AndroidRuntime(955): at android.os.Handler.dispatchMessage(Handler.java:99)
10-07 20:52:49.976: E/AndroidRuntime(955): at android.os.Looper.loop(Looper.java:123)
10-07 20:52:49.976: E/AndroidRuntime(955): at android.app.ActivityThread.main(ActivityThread.java:3683)
10-07 20:52:49.976: E/AndroidRuntime(955): at java.lang.reflect.Method.invokeNative(Native Method)
10-07 20:52:49.976: E/AndroidRuntime(955): at java.lang.reflect.Method.invoke(Method.java:507)
10-07 20:52:49.976: E/AndroidRuntime(955): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-07 20:52:49.976: E/AndroidRuntime(955): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-07 20:52:49.976: E/AndroidRuntime(955): at dalvik.system.NativeStart.main(Native Method)
10-07 20:52:55.642: I/Process(955): Sending signal. PID: 955 SIG: 9
g333kk ::
in še AndroidPaint.java:
Tukaj je glavni del kode kar se kliče, ko pa hočem da button ena začne funkcionirat move pa je vse narobe ostalo dela ..groza..
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mPanel = (Panel) findViewById(R.id.yourID); // View view = new SandboxView(this, mPanel.getBitmap()); /* * * Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.advert); View view = new SandboxView(this, bitmap); setContentView(view); */ Button Button1 = (Button) findViewById(R.id.button1); Button1.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { mPanel.getPainterHandler().setShape(SHAPES.MOVE); // mPanel.getPainterHandler().back(); } }); ImageButton imageButton1 = (ImageButton) findViewById(R.id.imageButton2); imageButton1.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { mPanel.getPainterHandler().back(); } }); ImageButton imageButton2 = (ImageButton) findViewById(R.id.imageButton1); imageButton2.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { mPanel.getPainterHandler().next(); } });}
Tukaj je glavni del kode kar se kliče, ko pa hočem da button ena začne funkcionirat move pa je vse narobe ostalo dela ..groza..
Vredno ogleda ...
Tema | Ogledi | Zadnje sporočilo | |
---|---|---|---|
Tema | Ogledi | Zadnje sporočilo | |
» | Android zamenjava pogledovOddelek: Programiranje | 1067 (888) | c00L3r |
» | [Android] Aplikacija se zrušiOddelek: Programiranje | 807 (644) | g333kk |
» | android črtaOddelek: Programiranje | 2389 (1660) | g333kk |
» | [android] vstavljanje slikeOddelek: Programiranje | 1232 (1129) | messi |
» | [android] crashOddelek: Programiranje | 1329 (1138) | messi |