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. Problems with building android

Hello,
I am building androind for the first time and have some doubts. Some
of the header files are like<linux/usbdevice_fs.h> are read from /usr/
include/linux in my environment. Should they be instead picked up from
bionic/libc/kernel/common/linux ?
How many others would have this kind of issue if at all this is one? I
am using redhat linux with gcc 4.1.2

Thanks

--~--~---------~--~----~------------~-------~--~----~

2. I'm not able to receive more than two GPS position. The application hangs.

Hi all, my application read info from the GPS provider and shows it on
the screen.
The problem is that the locationListener is executed only twice for
some reason.
I tried to create another thread to print some other information at
the same time to verify that the application is still running, and it
was so. However, the listener that listens to the location change is
not invoked any more.

To generate the GPS info i'm using DDMS manually and a .GPX file.

Did any of you run into this issue? (I didn't find anything similar in
the discussion group)

thanks
Patricio

--------------------------------------

package com.apps.GpsApp;

import java.io.IOException;


import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.location.LocationProvider;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;

public class GpsApp extends Activity {

        private TextView textView;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Set the layout for this activity.  You can find it in res/
layout/location_view.xml
        setContentView(R.layout.location_view);

        // The text view for our text view, identified by its ID in
the XML file.
        textView = (TextView) findViewById(R.id.text);
        textView.setText("Ready to receive my location...");

        final LocationManager locationManager = (LocationManager)
getSystemService(Context.LOCATION_SERVICE);
        locationManager.requestLocationUpdates
(LocationManager.GPS_PROVIDER, 0, 0, new MyLocationListener
());
    }


        private class MyLocationListener implements LocationListener {

                public void onLocationChanged(Location location) {
                        String lat = String.valueOf(location.getLatitude());
                        String lon = String.valueOf(location.getLongitude());
                        Log.e("GPS", "location changed: lat="+lat+", lon="+lon);

                textView.append("\nLast location:" + lat + " " + lon);

                Toast.makeText(getBaseContext(), "Location changed : Lat: " +
lat + " Lng: " + lon, Toast.LENGTH_LONG).show();

                }

                public void onProviderDisabled(String provider) {
                }

                public void onProviderEnabled(String provider) {
                }

                public void onStatusChanged(String provider, int status, Bundle
extras) {
                }
    }
}


and the xml is:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.apps.GpsApp"
      android:versionCode="1"
      android:versionName="1.0">

    <uses-permission android:name="android.permission.ACCESS_LOCATION"/
    <uses-permission android:name="android.permission.ACCESS_GPS"/
    <uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission
android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>
    <uses-permission
android:name="android.permission.ACCESS_MOCK_LOCATION"/>
    <uses-permission
android:name="android.permission.CONTROL_LOCATION_UPDATES"/>
    <uses-permission android:name="android.permission.INTERNET"/>

    <application android:icon="@drawable/icon" android:label="@string/
app_name">
        <activity android:name=".GpsApp"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category
android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-sdk android:minSdkVersion="2" />
</manifest>


--~--~---------~--~----~------------~-------~--~----~

3. This post does not show up in discussion

4. The new Android 1.5 message problem

5. Message counting app

6. short message controlling

7. How to establish sqlite database in linux?