Is ProgressBar correctly handling padding-values?

by Cyril M » Thu, 05 Mar 2009 01:04:43 GMT


Sponsored Links
 ere is a skeleton of the class I'm currently working on.
Unfortunatly, i'm stuck on two problems and it's driving me mad !

The first problem is about the onKeyDown(KeyEvent) : I don't
understand why this method isn't called while I pressed a key on the
emulator.
The second problem deals with padding. Indeed, I'm always creating
widget using fake paddings in order to be sure my widget correctly
handle those values. Unfortunatly, I tried to extend a ProgressBar and
I had some problems because my ProgressBar is clipped.

My code is :

package com.niji.android.myhouse;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.widget.ProgressBar;

public class ProgressWheel extends ProgressBar {

private static final String TAG_LOG = "ProgressWheel";
private static final Paint mPaint = new Paint();

private float oldX;

public ProgressWheel(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}

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

mPaint.setStrokeWidth(1.0f);
mPaint.setColor(Color.MAGENTA);
mPaint.setStyle(Paint.Style.STROKE);

setPadding(5, 15, 40, 10)

}

@Override
protected synchronized void onDraw(Canvas canvas) {
/*
* I'm not sure the onDraw(Canvas) method from ProgressBar is
correctly
* implemented. Indeed. With padding values, The progressBar
may be
"clipped"
*/
super.onDraw(canvas);
canvas.drawRect(0, 0, getWidth()-1, getHeight()-1, mPaint);
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
/*
* I don't understand why this method is not called
*/
int progress = getProgress();
Log.d(TAG_LOG, "onKeyDown");
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_LEFT:
Log.d(TAG_LOG, "KEYCODE_DPAD_LEFT");
if (progress <= 0) break;
setProgress(progress - 1);
return true;

case KeyEvent.KEYCODE_DPAD_RIGHT:
Log.d(TAG_LOG, "KEYCODE_DPAD_RIGHT");
if (progress >= getMax()) break;
setProgress(progress + 1);
return true;
}

return super.onKeyDown(keyCode, event);
}

@Override
public boolean onTouchEvent(MotionEvent event) {
Log.d(TAG_LOG, "onTouchEvent");
int progress = getProgress();

switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
oldX = event.getX();
break;
case MotionEvent.ACTION_MOVE:
if (event.getX() > oldX) {
setProgress(progress + 1);
}
else setProgress(progress -



Is ProgressBar correctly handling padding-values?

by Sundog » Thu, 05 Mar 2009 01:52:47 GMT


 > Sorry for being terse, sent from my phone :)

Yeah, isn't that keyboard a drag?  ;)
--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Is ProgressBar correctly handling padding-values?

by Cyril Mottier » Thu, 05 Mar 2009 17:01:11 GMT


  prefer you being terse and giving understandable answers than no one
answering me :p. Thanks ;)

On 4 mar, 18:09, Romain Guy <romain...@google.com> wrote:
--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. jena framework

saya masih newbie di android, cuma mau tanya apakah Jena fremawork
(untuk semantik) bisa diterapkan pada Android? kalo bisa, tolong kasih
petunjuk atau link tutorialnya. terima kasih sebelumnya :)

-- 
===============
"

2. GPU Tercepat Jatuh Pada Samsung 鈥檚 Hummingbird

nokia n900 bisa nyundul ditengah 2 .... droid x malah nggak masuk ya .. ?

yg kesian ipad .. malah paling bontot... tuh masak kalah n900 yg cuma 600
mhz ya ? amazing juga tuh portable computer ..

2010/12/21 Said Muhamad Husni <saidmhu...@gmail.com>






-- 
-----------
Best regards,
Rafael Estevez - rafael(at)digi2go.net - 0811 98 4353 / 021 988 00 324
www.digi2go.net - Unique Gadgets, Gifts and Souvenirs

-- 
===============
"

3. [Oot] Paging android-er jogja

4. WTT: 1 Unit Galaxy Tab *mint cond dengan 12 Tiket VIP Timur Final FFA...

5. [isat-android] Happy birthday jakontil

6. Database storage filling and securing

7. Oot: android dibahas di e-life style metro