Categories
discuss

Android Preventing Double Click On A Button

What is the best way to prevent double clicks on a button in Android?

Answer

Disable the button with setEnabled(false) until it is safe for the user to click it again.

Categories
discuss

Compress images on client side before uploading [closed]

Does anyone know of any free script that compresses JPG, GIF and PNG files as much as possible?

Answer

You might be able to resize the image with canvas and export it using dataURI. Not sure about compression, though.

Take a look at this: Resizing an image in an HTML5 canvas

Categories
discuss

Closure Compiler – can a++ >= 3 become ++a > 3?

I admit that I asked a question about why Closure Compiler does not shorten certain code which looks shortenable at first sight a few days ago already, but that reason is not applicable in this case and I’m not really sure why it isn’t shortened here.

What code I have is:

var a = 0;
function b() {
    return a++ >= 3;
}

Now there is pre-incrementing and post-incrementing. The difference is the return value – a++ returns a and then increments it, ++a first increments a and then returns it.

What this comes down to is that my code could be shortened to (ignoring whitespace removal):

var a = 0;
function b() {
    return ++a > 3;
}

However, Closure Compiler does not seem to alter (or recognise) this.

My question therefore is: what side effects could ++a > have when used instead of a++ >=?

Answer

There is a particular edge-case for this construct (but not for 3).

It occurs because JavaScript stores numbers as IEEE-754 float-point 64-bit doubles and “only” has a guaranteed “exact” integer-representation up to 2^53 (although implementations may have lee-way to have a higher range, I do not know).

This is on Firefox 4:

a = 2e53
a++ >= 2e53 // true

a = 2e53
++a > 2e53 // false

Real question is what realized gain would such a very particular transformation have? :-0

Happy coding.

Categories
discuss

Recommended practice environment for OpenGL ES 2.0?

I decided to learn some OpenGL ES 2.0 and I am trying to pick a practice platform for it. What comes to possible target platform, it could be Android, iPhone or WebGL. But I don’t want to spend too much time and effort to get the environment setup properly.

Would you recommend WebGL for a fast start to OpenGL ES 2.0 learning or something else?

Edit: I am using Mac and I am not really interested in ES 1.x at the moment.

Answer

If you register as a developer at the iOS Developer Center (free), you can download Xcode and the iOS SDK (again, for free when you get Xcode 3), which includes a simulator capable of OpenGL ES 2.0. This of course assumes you have a Mac to run that all on.

Once you have the SDK, you can simply start up Xcode and create a new application based on the OpenGL ES Application template. This application will be a fully functional OpenGL ES 1.1 and 2.0 iOS application that you can build and run in the simulator. You can ignore all of the iOS-specific setup code and focus on the -drawFrame method in the xxxViewController.m class, which is where the OpenGL ES 2.0 drawing code lies.

This can be a pretty quick environment to set up for playing with OpenGL ES 2.0 shaders. I’ve also tried out the PowerVR SDK package that trenki suggests, and it is a little more involved to get something set up with that. If you’re on Windows, it will be a lot more viable of a solution than the Mac-based iOS SDK I describe here.

One other shader development tool that can come in handy for prototyping on the Mac is Quartz Composer. It comes along with Xcode, and provides a visual prototyping environment for all sorts of effects, including OpenGL shaders. I demonstrate an example of doing this kind of prototyping in an article I wrote here. Desktop GLSL and the implementation in OpenGL ES differs slightly, but much is the same between the two.

While targeted at iOS, I taught a class on OpenGL ES 2.0 recently as part of a course that can be downloaded from iTunes U for free. It might helpful in getting up to speed on shaders.

Categories
discuss

Android’s in-app billing and bindService

I am trying to implement in-app billing in my application based on Sample Application. But bindService always returns false.

Here is what I have. AndroidManifest.xml:

<service android:name="tv.app.billing.BillingService" />

Preferences.java (need to start purchase from Preferences screen):

protected void onCreate(Bundle savedInstanceState) {
    mBillingService = new BillingService();
    mBillingService.setContext(this); // tried to use getApplicationContext also

BillingService.java: public class BillingService extends Service implements ServiceConnection {

/**
 * Binds to the MarketBillingService and returns true if the bind
 * succeeded.
 * @return true if the bind succeeded; false otherwise
 */
private boolean bindToMarketBillingService() {
    try {
        if (Debug.DEBUG) {
            Log.i(TAG, "binding to Market billing service");
        }
        boolean bindResult = bindService(
                new Intent(Consts.MARKET_BILLING_SERVICE_ACTION),
                this,  // ServiceConnection.
                Context.BIND_AUTO_CREATE);

        if (bindResult) {
            return true;
        } else {
            Log.e(TAG, "Could not bind to service.");
        }
    } catch (SecurityException e) {
        Log.e(TAG, "Security exception: " + e);
    }
    return false;
}

And in LogCat I see:

WARN/ActivityManager(48): Unable to start service Intent { act=com.android.vending.billing.MarketBillingService.BIND }: not found

What do I need to correct here?

Answer

Ok, it can not be tested on the emulator (since it doesn’t have Android Market?). Testing In-app Billing section of official site says

You cannot use the Android emulator to test in-app billing

Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..