[android-developers] Digest for android-developers@googlegroups.com - 8 Messages in 7 Topics

Comments: (0)

Group: http://groups.google.com/group/android-developers/topics

    Peter Webb <r.peter.webb@gmail.com> Oct 31 09:47PM -0700 ^
     
    Thankyou, thankyou, thankyou to both of you. Exactly what I needed.

     

    Bob Kerns <rwk@acm.org> Oct 31 08:20PM -0700 ^
     
    Well, I've never expected onTerminate to be useful, but subclassing
    Application is.
     
    The Application's onCreate() method (and any static and instance
    initializers) are called before ANY application component is created
    or loaded.
     
    There's no other way to make this guaranty that I am aware of. You can
    come close if you put a reference to a singleton in every single
    component, and remember to always do so. But that's not a good
    approach -- it violates once-and-only-once. And if you're using third-
    party code as part of your app, it may not be possible. Although,
    admittedly, such code reuse is rare and problematic on Android, so
    it's nearly always possible.
     
    But why campaign against Application? It's a perfectly fine singleton
    itself, it's just misunderstood. Fix the documentation. Deprecate
    onTerminate. Suggest to people that their modularity would benefit if
    they group related statics into their own singleton, and their memory
    use might even improve if they then reference this singleton only
    where it's needed.
     

     

    Dianne Hackborn <hackbod@android.com> Oct 31 08:47PM -0700 ^
     
    > party code as part of your app, it may not be possible. Although,
    > admittedly, such code reuse is rare and problematic on Android, so
    > it's nearly always possible.
     
    Hm, so when do you need to just have code start running in your process
    first thing? Generally it needs to run for something else -- and that
    something else needs to make a call somewhere to get what it wants. Having
    that call Singleton.getInstance(context) (at which point you can do init for
    the first call) isn't any harder that ((Singleton)context.getApplication()),
    and it has some significant benefits:
     
    - Does lazy initialization so that you don't end up doing more stuff than
    needed when launching the process (important for first launch speed, and if
    you do things like receive broadcasts in the background).
     
    - Avoids Application is basically a big global. This also is far better for
    third party code, since if that code wants to have some global state it
    would be a pain to require modifying Application or having the app call into
    the library to init it.
     
    I don't understand your comment about violating once-and-only-once -- the
    whole point of a singleton is that it is one instance that is initialized
    the first time it is needed. There isn't actually any extra code you need
    to write to have it initialized, because by definition there is something
    there your other code needs, so the initialization can happen as a
    side-effect of getting access to it.
     
     
    > they group related statics into their own singleton, and their memory
    > use might even improve if they then reference this singleton only
    > where it's needed.
     
    I will fix the documentation. But conceptually, it just doesn't match with
    how you should be thinking about designing your app.
     
    --
    Dianne Hackborn
    Android framework engineer
    hackbod@android.com
     
    Note: please don't send private questions to me, as I don't have time to
    provide private support, and so won't reply to such e-mails. All such
    questions should be posted on public forums, where I and others can see and
    answer them.

     

    Bob Kerns <rwk@acm.org> Oct 31 08:46PM -0700 ^
     
    I may know more about magnetic compasses than some of the engineers
    putting them in devices...but of course, I don't know what those
    engineers are doing. But let me try to address the question in general
    terms anyway.
     
    Consider that traditionally, huge iron ships could use magnetic
    compasses with fair accuracy. How did they do this? Well, you may have
    seen pictures of a ship's compass, with two big iron balls on either
    side of it? The purpose of those balls is to allow the local magnetic
    field to be "flattened", so the effect of all that iron, much of it
    magnetized by arc welding, would be balanced out and made more uniform
    in all directions. They are placed side-by-side, to compensate for the
    fore-and-aft alignment of the ship, and independently adjustable for
    compasses not on the ship's centerline.
     
    Then once the field was flattened, the compass would be calibrated by
    a specialist. As best I recall the procedure, the ship would be run
    back and forth in calm waters on each heading, and the discrepancies
    recorded, to be applied to headings and bearings taken using the
    compass.
     
    The ship's compass is filled with a fluid, with vanes attached below,
    to provide damping and to keep it level.
     
    All of this could better be done electronically, in software, working
    from the raw sensor data.
     
    But, of course nobody actually calibrates a phone this way. The
    manufacturer's could, but I seriously doubt they do. But I don't think
    there's any real reason for them to do so -- because how accurately
    can you judge the orientation of your phone relative to your heading?
    And without the little pin in the middle for you to sight against the
    distant object, how well can you peer over your phone and just the
    bearing of the distant object?
     
    I expect that details like this outweigh any sensor accuracy issues.
     
    As for batteries -- those should have no effect. They generally won't
    have ferrous metals. The currents involved are small -- and so long as
    they are relatively constant, on a reasonable timescale, at most
    they'd be something that could be taken care of in the calibration
    process, were there such a process.
     
    But I wouldn't be surprised to see something like a camera flash LED
    being lit, or the battery being charged, making a noticeable
    difference. That could also be addressed in software, but could also
    be addressed by carefully separating the sensor from the LED current.
     
    The bottom line is, that while I think phones could be quite accurate,
    I see no advantage in doing so, because if you need that kind of
    accuracy, you will be better served by a compass with a physical
    package designed for the purpose. These days, many of those are
    electronic using the same technologies as are found in the phone. You
    can get them built into binoculars, even.
     

     

 Topic: Linkify
    Priyank Maiya <priyankvmaiya@gmail.com> Oct 31 09:50PM -0500 ^
     
    Hi,
    Thanks for the reply.. I am trying to do what you said.
    I defined a string:
     
    <string name= "support_request">Support Request: <a href="
    support@unl.com?subject=Comments">support@unl.com</a></string>
     
    In my .java code, I created a textview and called the setMovementmethod like
    this:
     
    TextView emailLink;
    emailLink = (TextView) this.findViewById(R.id.support_request);
     
    emailLink.setMovementMethod(LinkMovementMethod.getInstance());
     
     
    I am getting the error below when I run the app and click on the email text:
    11-01 02:44:42.431: ERROR/AndroidRuntime(1870):
    android.content.ActivityNotFoundException: No Activity found to handle
    Intent { act=android.intent.action.VIEW
    dat=support@unl.com?subject=Comments(has extras) }
     
    I think I am missing something in the manifest file. I am not sure what I
    need to fill there. Whar do I enter in the data field in the intent filter?
     
    Here is my intent filter I have defined in the corresponding activity:
    <intent-filter>
    <action android:name="android.intent.action.VIEW"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.BROWSABLE"/>
     
    <data android:scheme="http" android:host=support@unl.com"/>
    </intent-filter>
     
    I think I am doing something wrong here.
    Please Help.
     
    Thanks,
    Priyank
     

     

    Bob Kerns <rwk@acm.org> Oct 31 07:36PM -0700 ^
     
    No, assuming he doesn't get an error even earlier, I'm sure he gets a
    ClassCastException on that line. That happens before it even checks
    for the method. NoSuchMethodException is somewhat more esoteric
     
    The advice he actually needs is beyond the scope of this group. But
    I'll sum it up:
     
    "Learn to use the debugger". Running it under the debugger, set up to
    stop on RuntimeException and Error, would leave it stopped at the
    problem line, with a ClassCastException on the stack, and thus neatly
    answer your question for you, in far less time than it took to ask
    this group. And that skill will pay off many times a day.
     

     

    acr <acriib@gmail.com> Oct 31 06:58PM -0700 ^
     
    Thanks for the reply Miguel, Im positive I went through all of the
    lines just to double check.
    its getting the incorrect coordinates from the initial values of x and
    y where graphic.getGridCoordinates().setGrid1Y(y) sets to.
    but when I print lines via logcat to show the current
    getGridCoordinates().setGrid1Y(y) they show correct coordinates when I
    add the graphic but only the second graphic draws to the correct
    coordinates. I feel like I tried everything and keep going in circles.
     
     
     
     

     

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Digest for android-developers@googlegroups.com - 25 Messages in 14 Topics

Comments: (0)

Group: http://groups.google.com/group/android-developers/topics

    davemac <davemac327@gmail.com> Oct 31 06:39PM -0700 ^
     
    I'm going to guess that asking for the SEARCH_SERVICE and casting it
    to a SensorManager is not going to go well for you. You're probably
    getting a NoSuchMethodException, yes?
     
    - dave
    www.androidbook.com
     

     

    Miguel Morales <therevoltingx@gmail.com> Oct 31 06:19PM -0700 ^
     
    Are you sure you are not modifying any of those values from another thread.
     
     
    On Oct 31, 2010 11:07 AM, "acr" <acriib@gmail.com> wrote:
     
    So, It has nothing to do with the loop if I add the images manually I
    get the very same result
    the first graphic is being drawn to x0 y0 in my code. what I have is
    a column of 7 graphics(_theGrid) and when I remove a graphic from it,
    a new graphic is created in _toAdd. What my code is doing taking what
    ever is in _toAdd array and adding it to _theGrid array.
     
    If I only add the first graphic, the graphic is drawn CORRECTLY to x63
    y63
     
    if I add both, the first is drawn INCORRECTLY to x0 y0, and the second
    graphic is drawn CORRECTLY to x63 y126
     
    if I add a third, the the first TWO are drawn INCORRECTLY and the last
    is drawn correctly.
     
    I have tried invalidate and postInvalidate with no success and have
    hit a wall.
     
    Can anyone here help me remedy this problem, I am totally stumped
    here :?
    I am obviously missing something Im just not sure what.
     
     
    //FIRST GRAPHIC TO ADD FROM
    THE _toAdd ARRAY
    x=63;
    y=63;
     
    graphic.getGridCoordinates().setGrid1X(x);
     
    graphic.getGridCoordinates().setGrid1Y(y);
     
    _toMove.add(_toAdd.get(0));
     
    _theGrid.add(0,_toAdd.get(0));
     
    _theGrid.get(0).setAMT(_theGrid.get(0).getAMT()+2);
    _theGrid.get(0).setMV(11);
     
    _toAdd.remove(_theGrid.get(0));
     
     
    //SECOND GRAPHIC TO
    ADD FROM THE _toAdd ARRAY
    x=63;
    y=126;
     
    graphic.getGridCoordinates().setGrid1X(x);
     
    graphic.getGridCoordinates().setGrid1Y(y);
     
    _toMove.add(_toAdd.get(0));
     
    _theGrid.add(0,_toAdd.get(0));
     
    _theGrid.get(0).setAMT(_theGrid.get(0).getAMT()+2);
    _theGrid.get(0).setMV(12);
     
    _toAdd.remove(_theGrid.get(0));
     
     
     
    I have the following running in OnDraw(Canvas canvas) non stop
     
     
    bitmap = _theGrid.get(0).getBitmap();
    gridcoords = _theGrid.get(0).getGridCoordinates();
    canvas.drawBitmap(bitmap, gridcoords.getGrid1X(),
    gridcoords.getGrid1Y(), null);
     
    On Oct 31, 8:16 am, acr <acr...@gmail.com> wrote: > Now I even tried to
    change my loop to go throu...

     

    dipu <contactdd@gmail.com> Oct 31 05:38PM -0700 ^
     
    Thank you very much for the tip. I have restrasted my phone and made
    sure that my app is not running.
    Now I see two processes causing the GC.
     
    system 1103 1013 221560 49288 ffffffff 00000000 S system_server
    app_38 1872 1013 146228 23724 ffffffff 00000000 R
    com.android.email
     
    D/dalvikvm( 1103): GC_EXPLICIT freed 3427 objects / 138696 bytes in
    103ms
    D/dalvikvm( 1872): GC_FOR_MALLOC freed 9738 objects / 521552 bytes in
    58ms
    D/dalvikvm( 1103): GC_EXPLICIT freed 3425 objects / 138488 bytes in
    106ms
    D/dalvikvm( 1872): GC_FOR_MALLOC freed 9762 objects / 522360 bytes in
    60ms
    D/dalvikvm( 1103): GC_EXPLICIT freed 3374 objects / 136712 bytes in
    100ms
    D/dalvikvm( 1103): GC_EXPLICIT freed 3412 objects / 138048 bytes in
    102ms
    D/dalvikvm( 1872): GC_FOR_MALLOC freed 9822 objects / 525296 bytes in
    60ms
    D/dalvikvm( 1103): GC_EXPLICIT freed 3393 objects / 137328 bytes in
    101ms
    D/dalvikvm( 1872): GC_FOR_MALLOC freed 9912 objects / 528128 bytes in
    60ms
    D/dalvikvm( 1103): GC_EXPLICIT freed 3399 objects / 137480 bytes in
    102ms
    D/dalvikvm( 1872): GC_FOR_MALLOC freed 9730 objects / 522016 bytes in
    60ms
    D/dalvikvm( 1103): GC_EXPLICIT freed 3483 objects / 141184 bytes in
    102ms
    D/dalvikvm( 1872): GC_FOR_MALLOC freed 9747 objects / 520984 bytes in
    59ms
     
     
    On Oct 28, 4:24 pm, William Ferguson <william.ferguson...@gmail.com>
    wrote:

     

    Miguel Morales <therevoltingx@gmail.com> Oct 31 06:11PM -0700 ^
     
    Try putting your phone in airplane mode and see what happens.
     
    On Oct 31, 2010 5:39 PM, "dipu" <contactdd@gmail.com> wrote:
     
    Thank you very much for the tip. I have restrasted my phone and made
    sure that my app is not running.
    Now I see two processes causing the GC.
     
    system 1103 1013 221560 49288 ffffffff 00000000 S system_server
    app_38 1872 1013 146228 23724 ffffffff 00000000 R
    com.android.email
     
    D/dalvikvm( 1103): GC_EXPLICIT freed 3427 objects / 138696 bytes in
    103ms
    D/dalvikvm( 1872): GC_FOR_MALLOC freed 9738 objects / 521552 bytes in
    58ms
    D/dalvikvm( 1103): GC_EXPLICIT freed 3425 objects / 138488 bytes in
    106ms
    D/dalvikvm( 1872): GC_FOR_MALLOC freed 9762 objects / 522360 bytes in
    60ms
    D/dalvikvm( 1103): GC_EXPLICIT freed 3374 objects / 136712 bytes in
    100ms
    D/dalvikvm( 1103): GC_EXPLICIT freed 3412 objects / 138048 bytes in
    102ms
    D/dalvikvm( 1872): GC_FOR_MALLOC freed 9822 objects / 525296 bytes in
    60ms
    D/dalvikvm( 1103): GC_EXPLICIT freed 3393 objects / 137328 bytes in
    101ms
    D/dalvikvm( 1872): GC_FOR_MALLOC freed 9912 objects / 528128 bytes in
    60ms
    D/dalvikvm( 1103): GC_EXPLICIT freed 3399 objects / 137480 bytes in
    102ms
    D/dalvikvm( 1872): GC_FOR_MALLOC freed 9730 objects / 522016 bytes in
    60ms
    D/dalvikvm( 1103): GC_EXPLICIT freed 3483 objects / 141184 bytes in
    102ms
    D/dalvikvm( 1872): GC_FOR_MALLOC freed 9747 objects / 520984 bytes in
    59ms
     
     
    On Oct 28, 4:24 pm, William Ferguson <william.ferguson...@gmail.com>
    wrote:
     

     

    Mario Zechner <badlogicgames@gmail.com> Oct 31 05:22PM -0700 ^
     
    Hi there,
     
    i was refactoring some of my code today and wanted to minimze buffer
    object binds. My use case is it to bind a vertex buffer/index buffer
    pair once and batch up rendering as much as possible. Each batch is
    uploaded to the currently bound vbo.
     
    This works as expected on all tested devices (Nexus One, Droid,
    Samsung Galaxy) but fails on the HTC Hero with stock Android 1.5. I
    haven't updated the Hero to test exactly that kind of problems.
     
    I have compiled a small in depth description with a reproduceable test
    example. Both can be found at:
     
    http://www.badlogicgames.com/wiki/index.php/Severe_Bug_Updating_Already_Bound_Buffer_Object#Sample_Code
     
    I consulted with a couple of people whom i consider OpenGL experts and
    they all agreed that the way i handle the vbo/ibo is indeed correct
    and standard compliant.
     
    It would help if some people with an update Hero could try it out and
    see whether the problem persists.
     
    Should i file a bug on the Android bug tracker?

     

    greg <sepesi@eduneer.com> Oct 31 02:08PM -0700 ^
     
    From Dianne,
    > Android works so ends up just causing problems.
     
    > As far as using Application to clean up statics -- this simply doesn't
    > really make sense, for the reasons above.
     
    I confess to using an Application subclass to clean up statics in my
    application and I would be glad to repent if I knew how. Dianne, is
    there a sample application in the SDK (or elsewhere) showing the best
    practice for collecting statics in a static singleton? The SDK
    documentation about singletons at http://developer.android.com/resources/faq/framework.html
    seems to suggest the use of an Application subclass: "There are
    advantages to using a static Singleton, such as you can refer to them
    without casting getApplication() to an application-specific class, or
    going to the trouble of hanging an interface on all your Application
    subclasses so that your various modules can refer to that interface
    instead. But, the life cycle of a static is not well under your
    control; so to abide by the life-cycle model, the application class
    should initiate and tear down these static objects in the onCreate()
    and onTerminate() methods of the Application Class."
     
     
     
    On Oct 31, 2:07 pm, Dianne Hackborn <hack...@android.com> wrote:

     

    Dianne Hackborn <hackbod@android.com> Oct 31 03:39PM -0700 ^
     
    > control; so to abide by the life-cycle model, the application class
    > should initiate and tear down these static objects in the onCreate()
    > and onTerminate() methods of the Application Class."
     
    Gah I'll get that removed from the documentation.
     
    It is just totally wrong to rely on onTerminate. There is just
    fundamentally no reason to worry about "cleaning up your statics" when the
    way your process goes away is by killing it. There isn't anything to clean
    up. And anyway, onTerminate never gets called.
     
    Implementing a singleton is not special on Android; you just do it the same
    way you would elsewhere. Have a static method that returns the singleton:
     
    class Singleton {
    static final Object sLock = new Object();
    static final Singleton sInstance;
     
    static getInstance() {
    synchronized (sLock) {
    if (sInstance == null) {
    sInstance = new Singleton();
    }
    return sInstance;
    }
    }
     
     
    --
    Dianne Hackborn
    Android framework engineer
    hackbod@android.com
     
    Note: please don't send private questions to me, as I don't have time to
    provide private support, and so won't reply to such e-mails. All such
    questions should be posted on public forums, where I and others can see and
    answer them.

     

    Tom Gibara <tomgibara@gmail.com> Oct 31 10:49PM ^
     
    Given this strong recommendation against subclassing Application, I'll look
    to avoid doing so in future projects, but when you say
     
    [subclassing Application] gives you *nothing* you can't do in other, better
    > ways.
     
     
    the main benefit that comes to my mind is that you can expose static
    accessors for singletons that need a basic context (nothing more than the
    application context provides), without being required to pass it in.
     
    This occurs frequently in my code - I often have a number of independent
    static classes that deal with things like image caching. These types of
    classes invariably need a context during initialization (eg. to open
    databases or files) even if they don't need them at any later time.
     
    Objects within the app that aren't tied to any particular component's
    lifecycle are often the very same objects that need to interact with caches
    - ensuring that every such object has access (possibly indirectly of course)
    to a suitable context with which to access the cache will be a lot of work.
     
    In this case, I'm pretty sure that subclassing the Application object is
    giving me something; it's reducing the amount state that my objects need to
    carry (state which is almost always redundant since only one call to the
    accessor will ever need to create the singleton; it also allows me to avoid
    a synchronized lazy instantiation that would otherwise be necessary for some
    singletons).
     
    I think what's essentially providing this benefit, isn't the subclass of
    Application per se, but the presence of an reliable event (the call to
    Application.onCreate in this case) that precedes the instantiation of all
    other components, and which signals that the availability of the Application
    context. Without this, everything else carries the burden of providing an
    initializing context.
     
    My understanding of application start-up very incomplete, perhaps it's the
    provision of such an event (in whatever form) that causes difficulties at a
    platform level, and/or maybe there's some better way that bypasses the
    Application class.
     
    Tom.

     

    Adrian Romanelli <adrian.romanelli@gmail.com> Oct 31 02:06PM -0700 ^
     
    Does an Android 'sensor' have a compass built in? I thought it was
    just a motion sensor, portrait/landscape, etc., and not a true
    compass?
     
    And as far as I know, the gps device is a coordinate/point location
    thing, not a compass thing.
     
    How would the phone/device actually know its facing North?
     
    Finally, I'm not sure if this would help you out, but take a look at
    this article (its in three parts, link is part one), that describes a
    scrollable surface view: http://www.droidnova.com/create-a-scrollable-map-with-cells-part-i,654.html
     
    Not sure if it can help you or not, but maybe a place to start?
     
     
     

     

    Adrian Romanelli <adrian.romanelli@gmail.com> Oct 31 03:35PM -0700 ^
     
    Just to answer my own question, Compass functionality is built into
    some (all?) devices. I noticed that the up-coming T-Mobile Comet has
    compass functionality.
     
     
    On Oct 31, 2:06 pm, Adrian Romanelli <adrian.romane...@gmail.com>
    wrote:

     

    DanH <danhicks@ieee.org> Oct 31 03:39PM -0700 ^
     
    I do wonder how accurate it could possibly be, however. Your standard
    compass can be led astray by a steel belt buckle, so it's hard to see
    how a compass inside a phone, with batteries, printed circuits,
    electrons whizzing around, etc, could be very accurate at all.
     
    On Oct 31, 5:35 pm, Adrian Romanelli <adrian.romane...@gmail.com>
    wrote:

     

    DanH <danhicks@ieee.org> Oct 31 03:46PM -0700 ^
     
    In answer to the original query, there are four conceptual ways I can
    think of to do the job:
    1) Paint the letters and hash marks under program control
    2) Have an image that goes, say W..N..E..S..W..N..E and slide it back
    and forth as needed
    3) Have images W, N, E, S, and several ".." images of different
    lengths, and "tile" together the desired image.
    4) Have about 32 complete separate images and select one
     
     

     

    "longingtoadopt.com" <anil.rita@gmail.com> Oct 31 03:01PM -0700 ^
     
    > given (treating it as a wildcard); if no data characteristics are
    > specified, however, then the filter will only match intents that
    > contain no data."
     
    Thanks for your reply...
    If you look at the code, I did specify the action in both the Intent
    and the Intent filter: ALERT_ME_ACTION
    Correct me if I am mistaken but it is intuitive to expect that if the
    Actions match then that should be the overriding consideration. It is
    analogous to a message or a method call.
    If the name of the method matches, then the case "no data" is also
    valid and handled by the same method.
     
     
    > I suspect that you are confusing <intent-filter> characteristics with
    > IntentFilter characteristics.
     
    I think one is just a convenient way of specifying in XML and the
    other is a way of specifying the same thing dynamically. This is also
    true of Views.
     
    > > mime type should I specify in the intent filter?
     
    > Data is not "an id that is simply a String". Data is a Uri. Please use
    > a string extra for an arbitrary string.
     
    Yes, the data is a Uri
    Here is the value I was using: "content://com.iovercomer/alerts/99"
     
    I meant that in the line
    Intent inte = registerReceiver(receiver, new
    IntentFilter(ALERT_ME_ACTION));
     
    If I am now instead trying to specify
     
    public IntentFilter (String action, String dataType)
    http://developer.android.com/reference/android/content/IntentFilter.html#IntentFilter%28java.lang.String,%20java.lang.String%29
     
    the MIME type is specified as a String. if it is to be lower case,
    what would I use to pass in?
     
    Diahn Hackborn mentioned that the data part is used to distinguish
    PendingIntents.
     
    Since I am using PendingIntent.FLAG_UPDATE_CURRENT, I want the
    PendingIntent associated with
    "content://com.iovercomer/alerts/99" to be different from the
    PendingIntent for
    "content://com.iovercomer/alerts/100"
    Hence I am not simply passing it in as an extra in the Bundle.
    thanks,

     

    Dianne Hackborn <hackbod@android.com> Oct 31 03:34PM -0700 ^
     
    > analogous to a message or a method call.
    > If the name of the method matches, then the case "no data" is also
    > valid and handled by the same method.
     
    Whether or not it is intuitive, this is the way it works. If you want an
    analogy to a method call, consider this to be overloading. A method call
    ACTION_SOMETHING with argument "content://foo" is a different method than
    ACTION_SOMETHING with no argument.
     
     
     
    > http://developer.android.com/reference/android/content/IntentFilter.html#IntentFilter%28java.lang.String,%20java.lang.String%29
     
    > the MIME type is specified as a String. if it is to be lower case,
    > what would I use to pass in?
     
    If you don't have a MIME type, don't use anything.
     
    Let's back up... *why* are you doing this? Unless you need intent
    resolution to interact with other applications, my first suggestion would be
    to simply not use it.
     
    I also see a red flag in that you are talking about what looks like alarms
    but using registerReceiver(). Generally you wouldn't use these two together
    -- the only reason to use an alarm is to allow your application to execute
    at the time even if it is not currently running. Using registerReceiver()
    means that your application needs to be actively running with the
    registration to receive the broadcast. Generally it just doesn't make sense
    to mix both of these. If you are doing an alarm, usually the PendingIntent
    you create is an explicit Intent set to the ComponentName of a receiver
    component declared in your manifest. For that case, you don't need an
    intent-filter at all, and in fact anything you specify for it will be
    ignored (since you have already specified the exact component you want to
    receive it).
     
     
    > PendingIntent for
    > "content://com.iovercomer/alerts/100"
    > Hence I am not simply passing it in as an extra in the Bundle.
     
    Explicitly specify the component to receive the intent. Or if you *really*
    need to have matching done to send to a registerReceiver(), register with an
    IntentFilter matching scheme "content" and authority "com.iovercomer". But
    I suspect that is not actually what you want.
     
    --
    Dianne Hackborn
    Android framework engineer
    hackbod@android.com
     
    Note: please don't send private questions to me, as I don't have time to
    provide private support, and so won't reply to such e-mails. All such
    questions should be posted on public forums, where I and others can see and
    answer them.

     

    Kumar Bibek <coomar.101@gmail.com> Oct 31 12:44PM -0700 ^
     
    You need to launch the default browser with your donation URL. After
    that, the browser app should take care of the further actions.
     
    To launch the Browser, you need to use a VIEW intent like this.
     
    http://developer.android.com/guide/appendix/g-app-intents.html
     
    Action - View
    Uri - Your donation URL
     

     

    "Jonas Petersson" <jonas.petersson@xms.se> Oct 31 09:45PM +0100 ^
     
    An alternative to this is to do my trick: Just create your own donation
    app and link to it on Market - no need for any permission, just:
     
    startActivity(new Intent(Intent.ACTION_VIEW,
    Uri.parse("market://details?id=se.petersson.freebeer")));
     
    Best / Jonas
     
    On 10/30/2010 05:27 PM, Mark Murphy wrote:

     

    Marcin Orlowski <webnet.android@gmail.com> Oct 31 11:09PM +0100 ^
     
    >> > On Sat, Oct 30, 2010 at 11:23 PM, Raziel23x <raziel...@gmail.com> wrote:
    >> > > I am having trouble creating a donate menu button but I am having
    >> > > trouble
     
     
    Try PayPal android library:
    https://www.x.com/community/ppx/xspaces/mobile/mobile_ec
    I've played with it a bit and it's far better than redirecting to
    website (as it uses native android
    UI)

     

 Topic: button click
    Filip Havlicek <havlicek.filip@gmail.com> Oct 31 10:37PM +0100 ^
     
    I'm going the crystal ball way here.
     
    You need to take the current content of text view (or save it somewhere) and
    when you press the button next time, take that content (or it's id or
    something like that, really depends on what you are trying to do and how)
    and then select next content based on current one. If you are trying to
    show, for example, tags from your xml, I would suggest parsing the whole
    file on first button press and save the tags along with their ids
    (reflecting their position in the file), then just selecting next id on next
    button presses.
     
    Best regards,
    Filip Havlicek
     
     
     
    2010/10/31 TreKing <trekingapp@gmail.com>
     

     

    jtoolsdev <brianjtools@gmail.com> Oct 31 12:59PM -0700 ^
     
    Isn't LVL locked to the user's Google email? I thought that was the
    idea though they you can use device IDs as an option. Linked to the
    account it allows the user to install the app again if they get a
    different device. The ID option would be for a single device policy
    though they could stand to flesh out the documentation on LVL a bit
    more.
     

     

    Alex <maroebuck@gmail.com> Oct 31 04:33AM -0700 ^
     
    I have finally got LVL working in my app, but now I am having second
    thoughts about including it.
     
    If you have published an app including LVL, what are your
    experiences? Has it caused bad feedback from your users?

     

    Pent <tasker@dinglisch.net> Oct 31 07:43AM -0700 ^
     
    > If you have published an app including LVL, what are your experiences?  
     
    99.9% no problem.
     
    > Has it caused bad feedback from your users?
     
    Once or twice, a long time ago.
     
    But my implementation is very forgiving. It doesn't care if the
    licence can't be verified for the first 7 days, and only needs one
    positive response (per install). It validates in the background so
    most people don't even notice it.
     
    I also have a backup licence-code system they can use if all else
    fails (I needed it for paypal sales).
     
    Pent

     

    jtoolsdev <brianjtools@gmail.com> Oct 31 12:54PM -0700 ^
     
    I have only had one customer complain of a problem since I upgraded to
    LVL. And who knows why that is happening as they could have changed
    emails since the original purchase under the old system or part of the
    problem which seems to be going on with the Market these days. Also
    it was my understanding that the default policy was to check the first
    few days so authorization could be canceled if a refund was done. But
    my app is still checking after several weeks. Like a lot of Android
    documentation there needs to be more information on using LVL.
     
    And I also have an alternate third party system from my web site and
    haven't had any problems with it other than the eseller failing to
    tell me that the second try on a charge went through.
     
    Brian
     

     

    Kumar Bibek <coomar.101@gmail.com> Oct 31 12:38PM -0700 ^
     
    You need a different layout for your dialog for the landscape mode.
     

     

    Mark Murphy <mmurphy@commonsware.com> Oct 31 12:00PM -0400 ^
     
    > Yes the receiver calls startActivity().
     
    Then don't do that, since the complete and entire purpose of that is
    to put the activity in the foreground, which you do not want.
     
    > I think sending broadcast
    > would not help me as the message already sent and received by the
    > receiver.
     
    Send a different broadcast, targeted to your activity. Or register the
    first BroadcastReceiver via registerReceiver() from the activity in
    the first place.
     
    --
    Mark Murphy (a Commons Guy)
    http://commonsware.com | http://github.com/commonsguy
    http://commonsware.com/blog | http://twitter.com/commonsguy
     
    Android 2.2 Programming Books: http://commonsware.com/books

     

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Digest for android-developers@googlegroups.com - 25 Messages in 12 Topics

Comments: (0)

Group: http://groups.google.com/group/android-developers/topics

    oriharel <ori.harel@gmail.com> Oct 31 07:58AM -0700 ^
     
    the triggering code is:
     
    getContentResolver().registerContentObserver(Uri.parse("refreshChange"),
    false, _refreshObserver);
     

     

    Dianne Hackborn <hackbod@android.com> Oct 31 11:21AM -0700 ^
     
    The system shouldn't crash, but your code is broken.
    Your Uri.parse("refreshChange") is creating a Uri that is not actually a
    content: URI. You need to provide a Uri that is a full content: URI (with
    authority) to the data you want to observe.
     
     
    --
    Dianne Hackborn
    Android framework engineer
    hackbod@android.com
     
    Note: please don't send private questions to me, as I don't have time to
    provide private support, and so won't reply to such e-mails. All such
    questions should be posted on public forums, where I and others can see and
    answer them.

     

    Dianne Hackborn <hackbod@android.com> Oct 31 11:19AM -0700 ^
     
    > the size of the screen, construct a Canvas using the constructor that
    > takes a Bitmap, then get the Window from the Activity, then get the
    > decor View from that, and pass the Canvas to its onDraw.
     
    Yes, that works fine.
     
    --
    Dianne Hackborn
    Android framework engineer
    hackbod@android.com
     
    Note: please don't send private questions to me, as I don't have time to
    provide private support, and so won't reply to such e-mails. All such
    questions should be posted on public forums, where I and others can see and
    answer them.

     

    "longingtoadopt.com" <anil.rita@gmail.com> Oct 31 07:25AM -0700 ^
     
    I thought that Action was preeminent during intent resolution and if
    the intent had the same action as the intent filter, it would be
    considered a match regardless of data, if the filter did not specify
    anything.
    So I was very surprised to find that supplying action+data where
    filter had only action, causes it to fail.
    In the code below, if you comment out line 47 so that data is *not*
    sent, only then it resolves correctly.
     
    alertIntent.setData(alert_i);
     
    To get it to work with the data (an id that is simply a String), what
    mime type should I specify in the intent filter?
    thanks...
    -----
    package com.iovercomer;
     
    import java.util.Calendar;
    import java.util.Date;
     
    import android.app.Activity;
    import android.app.AlarmManager;
    import android.app.PendingIntent;
    import android.content.BroadcastReceiver;
    import android.content.Context;
    import android.content.Intent;
    import android.content.IntentFilter;
    import android.content.IntentFilter.MalformedMimeTypeException;
    import android.net.Uri;
    import android.os.Bundle;
    import android.os.SystemClock;
    import android.util.Log;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.TextView;
    import android.widget.Toast;
     
    public class TestIntentResolution extends Activity {
    public static final String ALERT_ME_ACTION =
    "com.iovercomer.TestIntentResolution.alertMe";
    AlarmManager am;
    PendingIntent mAlarmSender;
    String uriBase = "content://com.iovercomer/alerts/";
    Intent alertIntent;
    int alarmNumber = 99;
    protected int requestCode = 23;
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Button startButton = (Button) findViewById(R.id.start_alarm);
    startButton.setOnClickListener(mStartAlarmListener);
    am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    alertIntent = new Intent(ALERT_ME_ACTION);
     
    }
    private OnClickListener mStartAlarmListener = new OnClickListener() {
    @Override
    public void onClick(View v) {
    Uri alert_i = Uri.parse(uriBase + alarmNumber);
    // comment out the following line to get the intent to resolve to
    the receiver
    alertIntent.setData(alert_i);
    int flags = PendingIntent.FLAG_UPDATE_CURRENT;
    mAlarmSender =
    PendingIntent.getBroadcast(TestIntentResolution.this,
    requestCode , alertIntent, flags);
    long firstTime = SystemClock.elapsedRealtime();
    am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime + 10 *
    1000, mAlarmSender);
    Toast.makeText(TestIntentResolution.this,
    "starting >>>" + "alarm " + alarmNumber,
    Toast.LENGTH_LONG).show();
     
    }
    };
    @Override
    public void onResume() {
    super.onResume();
    Intent inte = registerReceiver(receiver, new IntentFilter(
    ALERT_ME_ACTION));
    }
     
    @Override
    public void onPause() {
    super.onPause();
    unregisterReceiver(receiver);
    }
    void alertMe(String time, String data) {
    String t = "alert! at " + time + " " + data + "\n";
    Toast.makeText(getApplicationContext(), t,
    Toast.LENGTH_SHORT).show();
    TextView tv = (TextView) findViewById(R.id.myginew);
    tv.setText(t);
    }
     
    MyAlarmReceiver receiver = new MyAlarmReceiver();
     
    public class MyAlarmReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
    Date dt = Calendar.getInstance().getTime();
    intent.getAction();
    intent.getType();
    Uri d = intent.getData();
    String frag = (d == null ? "":d.getLastPathSegment());
    alertMe(dt.toString(), frag);
    }
    };
    }

     

    Mark Murphy <mmurphy@commonsware.com> Oct 31 10:44AM -0400 ^
     
    On Sun, Oct 31, 2010 at 10:25 AM, longingtoadopt.com
    > the intent had the same action as the intent filter, it would be
    > considered a match regardless of data, if the filter did not specify
    > anything.
     
    Quoting the IntentFilter object documentation:
     
    "For actions, the field will not be tested if no values have been
    given (treating it as a wildcard); if no data characteristics are
    specified, however, then the filter will only match intents that
    contain no data."
     
    I suspect that you are confusing <intent-filter> characteristics with
    IntentFilter characteristics.
     
    > To get it to work with the data (an id that is simply a String), what
    > mime type should I specify in the intent filter?
     
    Data is not "an id that is simply a String". Data is a Uri. Please use
    a string extra for an arbitrary string.
     
    --
    Mark Murphy (a Commons Guy)
    http://commonsware.com | http://github.com/commonsguy
    http://commonsware.com/blog | http://twitter.com/commonsguy
     
    Android 2.2 Programming Books: http://commonsware.com/books

     

    Dianne Hackborn <hackbod@android.com> Oct 31 11:18AM -0700 ^
     

    > I suspect that you are confusing <intent-filter> characteristics with
    > IntentFilter characteristics.
     
    <intent-filter> and IntentFilter have the same characteristics. In fact
    <intent-filter> is just the XML syntax for creating an IntentFiler object.
     
    --
    Dianne Hackborn
    Android framework engineer
    hackbod@android.com
     
    Note: please don't send private questions to me, as I don't have time to
    provide private support, and so won't reply to such e-mails. All such
    questions should be posted on public forums, where I and others can see and
    answer them.

     

    Dianne Hackborn <hackbod@android.com> Oct 31 11:07AM -0700 ^
     
    Only one Application per-.apk-per-process is created, ever. If you use
    android:process to have multiple .apks sharing the same process, each .apk
    will have its own Application instantiated in the process. If you use
    android:process to have an .apk run in multiple processes, each process will
    get its own Application instance.
     
    Application.onTerminate() is *never* called. This function is there for
    environments where processes are emulated, which is not any production
    device or the emulator. But it doesn't matter that it isn't called
    because... well, Application lives for the lifetime of the process, and the
    process goes away by the OOM killer killing it, which cleans up Application
    and everything else related to the process without any user space code for
    it running.
     
    Now it is conceivable that there is some case where if a process is left
    completely empty (with no app components) for a while, and GCs, the data
    about the loaded process may get GCed as well and have to be recreated. I
    don't see how this can happen off-hand (there are a number of ways
    non-weak-references are held between these things), but I can't say for
    certain there is no such bug here.
     
    That said, my recommendation to everyone is to just not subclass
    Application. This gives you *nothing* you can't do in other, better ways.
    In particular, a singleton directly represents what is really going on (it
    lives for the life of the process after the first need for it) and helps
    keep code more modular.
     
    I regret that the Application class was ever introduced; it was a compromise
    to make people more comfortable with there being some kind of traditional
    "main application" concept, but in fact it doesn't really fit in with how
    Android works so ends up just causing problems.
     
    As far as using Application to clean up statics -- this simply doesn't
    really make sense, for the reasons above. For a legacy application with
    statics that can't be re-used again in the same process, your only choice is
    probably to just self-kill your process when the user leave the game. That
    is, when the game activity is finished. If you can reset your statics after
    the game is over, then at least instead of killing it you can do that when
    the activity is finished. But this needs to be driven by Activity, not
    Application.
     
     
    --
    Dianne Hackborn
    Android framework engineer
    hackbod@android.com
     
    Note: please don't send private questions to me, as I don't have time to
    provide private support, and so won't reply to such e-mails. All such
    questions should be posted on public forums, where I and others can see and
    answer them.

     

    Dianne Hackborn <hackbod@android.com> Oct 31 11:17AM -0700 ^
     
    > > probably to just self-kill your process when the user leave the game.
    > Wait, what? I was under the distinct impression we should not be
    > killing processes this way.
     
    You should not be, but if you have a bunch of legacy code that can't cleanly
    work without doing so... well, sometimes you need to compromise. This does
    have other negative consequences, so nobody writing Android applications
    should do this.
     
    Games, though, games are sometimes so special.
     
    --
    Dianne Hackborn
    Android framework engineer
    hackbod@android.com
     
    Note: please don't send private questions to me, as I don't have time to
    provide private support, and so won't reply to such e-mails. All such
    questions should be posted on public forums, where I and others can see and
    answer them.

     

    tenacious <fbeachler@gmail.com> Oct 31 10:44AM -0700 ^
     
    I'm not sure what the motivation was to deprecate
    Display#getOrientation() in SDK 8 is, since I haven't had a chance to
    read the changeset description. The decision made the API a little
    less humanistic. I propose it be brought back in SDK 9 for these
    reasons:
    1) The community has two+ years of discovery and documentation around
    Display#getOrientation.
    2) There's no clear reason why applications which don't distinguish
    between a 90/270 degree rotation should have to implement extra work
    for forwards/backwards compatibility.
    3) The system already decides which side is "top" whether the rotation
    is 90 or 270 degrees.
    4) android.view.Surface has no setRotation(...) method, it uses
    setOrientation(...). Thus, if Display#getOrientation() was to be
    deprecated, the same should have happened to Surface#getOrientation
    for architectural symmetry.
    5) Using Display#getOrientation() will always be desired by some
    applications, whereas Display#getRotation() will always be desired by
    others.
     
    The frustrating factor here is that on top of the confusion caused by
    the SDK having different classes/methods to get runtime orientation
    versus configured orientation, this deprecation is poorly motivated.
     
    Yours Truly,
    Free

     

    Dianne Hackborn <hackbod@android.com> Oct 31 11:14AM -0700 ^
     
    getOrientation() has never returned orientation, it returns rotation. So it
    is being renamed to getRotation(). This is *much* less confusing. In fact
    you were confused -- you thought it returned orientation, when it does not.
     
    If you want the current orientation,
    Resources.getConfiguration().orientation has that.
     
    Surface.setOrientation() is actually not available to applications (it is an
    accident it is in the SDK, but apps don't have permission to use it, so
    there is nothing they can actually do with it), so not really relevant here.
    The solution for that one is probably just to remove it from the SDK since
    apps can't use it anyway.
     
    This was done to better clarify the differences between orientations and
    screen rotations, which a lot of people have been confused about, and has
    resulted in a lot of incorrect use of sensors and such.
     
    It's worth noting that both Display.getOrientation() and
    Surface.setOrientation() work with the constants Surface.ROTATION_0,
    Surface.ROTATION_90, Surface.ROTATION_180, etc. Those APIs intrinsically
    have a naming conflict.
     
     
    --
    Dianne Hackborn
    Android framework engineer
    hackbod@android.com
     
    Note: please don't send private questions to me, as I don't have time to
    provide private support, and so won't reply to such e-mails. All such
    questions should be posted on public forums, where I and others can see and
    answer them.

     

    Frank Weiss <feweiss@gmail.com> Oct 31 11:13AM -0700 ^
     
    Is the lower part of the gauge textual or a pretty image? What part are you
    having problems with?

     

    acr <acriib@gmail.com> Oct 31 05:16AM -0700 ^
     
    Now I even tried to change my loop to go through the array and get the
    same EXACT result.. I have to be missing something here.
    Has ANYone else experienced this type of problem? or can give me some
    guidance. Thanks a bunch.
     
     
     
     
    int temp1Y=0;
    for(Graphic g1 : _toAdd1){
    temp1Y+=1;
    x1=0;
    y1=temp1Y*-63;
    graphic.getGridCoordinates().setGrid1X(x1);
    graphic.getGridCoordinates().setGrid1Y(y1);
    _toMove.add(g1);
    _theGrid1.add(0,g1);
    _theGrid1.get(0).setAMT(_toAdd1.size());
    _theGrid1.get(0).setMV(temp1Y+10);
    x1=0;
    y1=temp1Y*-63;
    graphic.getGridCoordinates().setGrid1X(x1);
    graphic.getGridCoordinates().setGrid1Y(y1);
    }
    _toAdd1.removeAll(_toAdd1);
    temp1Y=0;
     

     

    acr <acriib@gmail.com> Oct 31 11:07AM -0700 ^
     
    So, It has nothing to do with the loop if I add the images manually I
    get the very same result
    the first graphic is being drawn to x0 y0 in my code. what I have is
    a column of 7 graphics(_theGrid) and when I remove a graphic from it,
    a new graphic is created in _toAdd. What my code is doing taking what
    ever is in _toAdd array and adding it to _theGrid array.
     
    If I only add the first graphic, the graphic is drawn CORRECTLY to x63
    y63
     
    if I add both, the first is drawn INCORRECTLY to x0 y0, and the second
    graphic is drawn CORRECTLY to x63 y126
     
    if I add a third, the the first TWO are drawn INCORRECTLY and the last
    is drawn correctly.
     
    I have tried invalidate and postInvalidate with no success and have
    hit a wall.
     
    Can anyone here help me remedy this problem, I am totally stumped
    here :?
    I am obviously missing something Im just not sure what.
     
     
    //FIRST GRAPHIC TO ADD FROM THE _toAdd ARRAY
    x=63;
    y=63;
    graphic.getGridCoordinates().setGrid1X(x);

    graphic.getGridCoordinates().setGrid1Y(y);
    _toMove.add(_toAdd.get(0));
    _theGrid.add(0,_toAdd.get(0));
    _theGrid.get(0).setAMT(_theGrid.get(0).getAMT()+2);
    _theGrid.get(0).setMV(11);
    _toAdd.remove(_theGrid.get(0));
     
     
    //SECOND GRAPHIC TO
    ADD FROM THE _toAdd ARRAY
    x=63;
    y=126;
    graphic.getGridCoordinates().setGrid1X(x);

    graphic.getGridCoordinates().setGrid1Y(y);
    _toMove.add(_toAdd.get(0));
    _theGrid.add(0,_toAdd.get(0));
    _theGrid.get(0).setAMT(_theGrid.get(0).getAMT()+2);
    _theGrid.get(0).setMV(12);
    _toAdd.remove(_theGrid.get(0));
     
     
     
    I have the following running in OnDraw(Canvas canvas) non stop
     
     
    bitmap = _theGrid.get(0).getBitmap();
    gridcoords = _theGrid.get(0).getGridCoordinates();
    canvas.drawBitmap(bitmap, gridcoords.getGrid1X(),
    gridcoords.getGrid1Y(), null);
     
     

     

    Brad Gies <rbgies@gmail.com> Oct 31 10:20AM -0700 ^
     
    David,
     
    I'm in the process of developing a website that collects market
    statistics and developer statistics, and one of the features I'm adding
    is a utility to collect my own market download numbers daily so I can
    put them into a spreadsheet and chart/graph them so I can easily spot
    trends.
     
    I thought about adding this for use by any developer, but the problem
    with it is that to automatically collect the actual download numbers, we
    would have to store your Google login information, and I don't think
    many developers would want to give that information... I could be wrong,
    but that's my opinion. Maybe I should ask... How many developers would
    be willing to have a website (a trustworthy website) store their login
    information to be able to automatically collect the download/installed
    numbers so they could collect them?
     
    Without the login information the only way to get the actual download
    and installed numbers would be for the developer to visit a page and
    manually start the download information, and I'm not sure many
    developers would do that consistently enough to get good information.
     
    Let me know if you are interested in having this... I can add it fairly
    easily... but I'd need to know exactly what would be acceptable to the
    developers.
     
     
     
    Sincerely,
     
    Brad Gies
    -----------------------------------------------------------------------
    Bistro Bot - Bistro Blurb
    http://bgies.com http://nocrappyapps.com
    http://bistroblurb.com http://forcethetruth.com
    http://ihottonight.com
    -----------------------------------------------------------------------
    Everything in moderation, including abstinence (paraphrased)
     
    Every person is born with a brain... Those who use it well are the successful happy ones - Brad Gies
     
    Adversity can make or break you... It's your choice... Choose wisely - Brad Gies
     
    Never doubt that a small group of thoughtful, committed people can
    change the world. Indeed. It is the only thing that ever has - Margaret Mead
     
     
    On 31/10/2010 3:16 AM, deg wrote:

     

    TreKing <trekingapp@gmail.com> Oct 31 11:59AM -0500 ^
     
    The mistake is you posted a bunch of code with no context and have not even
    explained what problem it is you're having.
     
    -------------------------------------------------------------------------------------------------
    TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago
    transit tracking app for Android-powered devices

     

 Topic: button click
    TreKing <trekingapp@gmail.com> Oct 31 11:57AM -0500 ^
     
    Your question is difficult to understand. You should try to clarify and
    rephrase so we can better understand the problem you're having.
     
    -------------------------------------------------------------------------------------------------
    TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago
    transit tracking app for Android-powered devices

     

    Donald <hasitharandika@gmail.com> Oct 31 06:11AM -0700 ^
     
    hi guys,
    i'm working with a google maps for a while now. i'm having multiple
    markers in the map once you select a perticular maker an Overaly will
    appear so once the Overlay is selected i want to get the index of the
    overlay. every time its 0.
     
    this is how i'm adding overlays
     
     
    GeoPoint point = new GeoPoint((int) (postal_lat * 1E6),
    (int) (postal_lng * 1E6));
    Drawable postal_icon =
    getResources().getDrawable(R.drawable.location);
    MyItemizedOverlay itemizedOverlay2 = new
    MyItemizedOverlay(postal_icon, mapview);
     
    OverlayItem overlayItem_postal = new OverlayItem(point,
    postal_msg, null);
    itemizedOverlay2.addOverlay(overlayItem_postal);
     
     
    MyItemizedOverlay implementation
     
     
    public class MyItemizedOverlay extends
    BalloonItemizedOverlay<OverlayItem> {
     
    private ArrayList<OverlayItem> m_overlays = new
    ArrayList<OverlayItem>();
    private Context c;
     
    public MyItemizedOverlay(Drawable defaultMarker, MapView mapView) {
    super(boundCenter(defaultMarker), mapView);
    c = mapView.getContext();
    }
     
    public void addOverlay(OverlayItem overlay, int id) {
    m_overlays.add(overlay);
    populate();
    }
     
    @Override
    protected OverlayItem createItem(int i) {
    return m_overlays.get(i);
    }
     
    @Override
    public int size() {
    return m_overlays.size();
    }
     
    @Override
    protected boolean onBalloonTap(int index) {
    NearestLocation near = MapInfo.nearestArray[index];
    Toast.makeText(c, "index " + near.getPartname() + index,
    Toast.LENGTH_LONG).show();
    return true;
    }
     
    }
    onBalloonTap always returns 0??
     
    regards,
    Mike

     

    TreKing <trekingapp@gmail.com> Oct 31 09:04AM -0500 ^
     

    > onBalloonTap always returns 0??
     
     
    Actually, it looks like it always returns true, according to your code.
     
    What is onBalloonTap and BalloonItemizedOverlay? I don't see either of those
    in the documentation.
     
    -------------------------------------------------------------------------------------------------
    TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago
    transit tracking app for Android-powered devices

     

    Donald <hasitharandika@gmail.com> Oct 31 07:35AM -0700 ^
     
    Hi Treking,
     
    thanks for your reply.BalloonItemizedOverlay is a class which extends
    BalloonItemizedOverlay.
     
    this is the BalloonItemizedOverlay implementation
     
     
    public abstract class BalloonItemizedOverlay<Item> extends
    ItemizedOverlay<OverlayItem> {
     
    private MapView mapView;
    private BalloonOverlayView balloonView;
    private View clickRegion;
    private int viewOffset;
    final MapController mc;
    private int id;
     
    /**
    * Create a new BalloonItemizedOverlay
    *
    * @param defaultMarker
    * - A bounded Drawable to be drawn on the map for each
    item in
    * the overlay.
    * @param mapView
    * - The view upon which the overlay items are to be
    drawn.
    */
    public BalloonItemizedOverlay(Drawable defaultMarker, MapView
    mapView) {
    super(defaultMarker);
    this.mapView = mapView;
    viewOffset = 0;
    mc = mapView.getController();
    }
     
    /**
    * Set the horizontal distance between the marker and the bottom of
    the
    * information balloon. The default is 0 which works well for center
    bounded
    * markers. If your marker is center-bottom bounded, call this before
    adding
    * overlay items to ensure the balloon hovers exactly above the
    marker.
    *
    * @param pixels
    * - The padding between the center point and the bottom
    of the
    * information balloon.
    */
    public void setBalloonBottomOffset(int pixels) {
    viewOffset = pixels;
    }
     
    /**
    * Override this method to handle a "tap" on a balloon. By default,
    does
    * nothing and returns false.
    *
    * @param index
    * - The index of the item whose balloon is tapped.
    * @return true if you handled the tap, otherwise false.
    */
    protected boolean onBalloonTap(int index) {
    id = index;
    Toast.makeText(mapView.getContext(), "IDDD " + index,
    Toast.LENGTH_LONG).show();
    return false;
    }
     
    /*
    * (non-Javadoc)
    *
    * @see com.google.android.maps.ItemizedOverlay#onTap(int)
    */
    @Override
    protected final boolean onTap(int index) {
     
    boolean isRecycled;
    final int thisIndex;
    GeoPoint point;
     
    thisIndex = index;
    point = createItem(index).getPoint();
     
    if (balloonView == null) {
    balloonView = new BalloonOverlayView(mapView.getContext(),
    viewOffset);
     
    clickRegion = (View) balloonView
    .findViewById(R.id.balloon_inner_layout);
    isRecycled = false;
    } else {
    isRecycled = true;
    }
     
    balloonView.setVisibility(View.GONE);
     
    List<Overlay> mapOverlays = mapView.getOverlays();
    if (mapOverlays.size() > 1) {
    hideOtherBalloons(mapOverlays);
    }
     
    balloonView.setData(createItem(index));
     
    MapView.LayoutParams params = new MapView.LayoutParams(
    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, point,
    MapView.LayoutParams.BOTTOM_CENTER);
    params.mode = MapView.LayoutParams.MODE_MAP;
     
    setBalloonTouchListener(thisIndex);
    balloonView.setVisibility(View.VISIBLE);
    if (isRecycled) {
    balloonView.setLayoutParams(params);
    } else {
    mapView.addView(balloonView, params);
    }
    mc.animateTo(point);
    /*Toast.makeText(mapView.getContext(), "indexdss " + index,
    Toast.LENGTH_LONG).show();*/
    return true;
    }
     
    /**
    * Sets the visibility of this overlay's balloon view to GONE.
    */
    private void hideBalloon() {
    if (balloonView != null) {
    balloonView.setVisibility(View.GONE);
    }
    }
     
    /**
    * Hides the balloon view for any other BalloonItemizedOverlay
    instances
    * that might be present on the MapView.
    *
    * @param overlays
    * - list of overlays (including this) on the MapView.
    */
    private void hideOtherBalloons(List<Overlay> overlays) {
     
    for (Overlay overlay : overlays) {
    if (overlay instanceof BalloonItemizedOverlay<?> && overlay !=
    this) {
    ((BalloonItemizedOverlay<?>) overlay).hideBalloon();
    }
    }
     
    }
     
    /**
    * Sets the onTouchListener for the balloon being displayed, calling
    the
    * overridden onBalloonTap if implemented.
    *
    * @param thisIndex
    * - The index of the item whose balloon is tapped.
    */
    private void setBalloonTouchListener(final int thisIndex) {
     
    try {
    @SuppressWarnings("unused")
    Method m = this.getClass().getDeclaredMethod("onBalloonTap",
    int.class);
     
    clickRegion.setOnTouchListener(new OnTouchListener() {
    public boolean onTouch(View v, MotionEvent event) {
     
    View l = ((View) v.getParent())
    .findViewById(R.id.balloon_main_layout);
    Drawable d = l.getBackground();
     
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
    int[] states = { android.R.attr.state_pressed };
    if (d.setState(states)) {
    d.invalidateSelf();
    }
    return true;
    } else if (event.getAction() == MotionEvent.ACTION_UP) {
    int newStates[] = {};
    if (d.setState(newStates)) {
    d.invalidateSelf();
    }
    // call overridden method
    onBalloonTap(thisIndex);
     
    NearestLocation near = MapInfo.nearestArray[thisIndex];
    /*Toast.makeText(mapView.getContext(), "index Touch :- " +
    near.getPartname() + thisIndex,
    Toast.LENGTH_LONG).show();*/
    return true;
    } else {
    return false;
    }
     
    }
    });
     
    } catch (SecurityException e) {
    Log.e("BalloonItemizedOverlay",
    "setBalloonTouchListener reflection SecurityException");
    return;
    } catch (NoSuchMethodException e) {
    // method not overridden - do nothing
    return;
    }
     
    }
     
    }
     
    but why it's always giving the index of 0?
     
    regards,
    Mike

     

    TreKing <trekingapp@gmail.com> Oct 31 11:16AM -0500 ^
     

    > but why it's always giving the index of 0?
     
     
    I don't know and I don't have time to review and make sense of you code, but
    printing log statements and stepping through the debugger should yield an
    answer pretty quickly.
     
    -------------------------------------------------------------------------------------------------
    TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago
    transit tracking app for Android-powered devices

     

    rrd <rrd@1108.cc> Oct 31 08:27AM -0700 ^
     
    Hari,
     
    My app's main activity listens to a broadcast message. When it
    receives the message it brings the activity to the front. I want to
    update the activity if it is in the front, so the user is playing with
    it, but otherwise I do not want to bring the activity to the front.
     
    How should I do it? Is there a flag for invoking the intent, or what?
     
    rrd

     

    rrd <rrd@1108.cc> Oct 31 08:51AM -0700 ^
     
    Yes the receiver calls startActivity(). I think sending broadcast
    would not help me as the message already sent and received by the
    receiver.

     

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en