Thursday, April 30, 2015

Dynamic Admob layout in android to display an ad

I am making a free app that has an ad in it, and I want the ad to be some kind of dynamic, like if there are no ads serve, the layout that wrap the ad will not be visible. It's just like this.


  1. Guidelines of implementing the ad
  2. Make sure that the layout of the ad is set to View.GONE. We will show it only if there is an ad serve.
  3. Add the AdListener
mAdView = (AdView) findViewById(R.id.adView);
mAdView.setAdListener(new AdListener() {
    @Override
    public void onAdClosed() {
        super.onAdClosed();
    }

    @Override
    public void onAdLoaded() {
        super.onAdLoaded();
        mAdView.setVisibility(View.VISIBLE);
    }

    @Override
    public void onAdOpened() {
        super.onAdOpened();
    }

    @Override
    public void onAdFailedToLoad(int errorCode) {
        super.onAdFailedToLoad(errorCode);
        mAdView.setVisibility(View.GONE);
    }
});
As you see, we only set the method onAdLoaded() to be visible and onAdFailedToLoad to be gone. Because, 
onAdOpened() - This will only happen if the ad will overlay the app after the user taps the ad. onAdClosed() - This will trigger if the overlay of the ad will be closed by the user.

That's it. Thanks.

Friday, March 14, 2014

Restore iPhone without updating

I have an iPhone 4 iOS 6 and I want just to restore to its original state without updating to iOS 7. It's really not a good idea in itunes that it will restore your phone plus you will really have to update to the latest iOS version. Really? And I don't like it that way.

Fortunately, there's an alternative on how to do a restore without updating the iOS version. Just navigate to

Settings > General > Reset > Erase All Content & Settings

And YES! it'll begin restoring your phone.

After restart, just fill out the fields and you're done.

Wednesday, March 12, 2014

Exit Functionality in Android

Usually we want our app to perform an exit function, so I wrote a simple tutorial about it.



Monday, February 24, 2014

Layouting UIScrollView via autolayout in xcode interface builder (iOS)

I am tired of writing code just to get the UIScrollView work. Well lucky for me I got a work around in xcode's interface builder using autolayout. Here's how.




Sunday, August 11, 2013

generic .htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Friday, July 5, 2013

URI is not hierarchical - Java

There are some problems when running the build jar of your project compare to running it in an IDE, when resources such as images is called within the build jar, usually we just use getClass#getResource("path/of/the/image.jpg") in the IDE, and when you build the project and execute the jar the "URI is not hierarchical" is thrown. One way to fix this is retrieve it as a resource-stream like.

InputStream dx = this.getClass().getResourceAsStream("/com/sample/images/default_image.png");
Image sm = ImageIO.read(dx).getScaledInstance(width, height, Image.SCALE_SMOOTH);

You can then us the Image in any component.