Categories
discuss

Android Canvas.DrawBitmap without blurring/AntiAliasing?

I’m trying to make an android game using sprites, (or very pixelated characters, backgrounds etc.). I draw them on the canvas like so…

matrix.preScale(xrat,yrat);

canvas.drawBitmap(img, matrix, null);

Where img is the Bitmap and the xrat and yrat are the scales.

My problem is that when I test, the Bitmap is blurry or anti-aliased, is there a way to prevent this? The rigid-blocky art style of the game will be ruined if the blocks are blurry.

Any (ANY) help appreciated!

Answer

Create a new Paint to use when drawing the bitmaps with the settings:

Paint drawPaint = new Paint();
drawPaint.setAntiAlias(false);
drawPaint.setFilterBitmap(false);

Filtering I believe is on by default and will attempt to smooth out bitmaps when drawn scaled up.

Categories
discuss

NSLog equivalent for Android dev using Eclipse

I am wondering if there is a syntax to print out something in the eclipse console windows. This is just like NSLog in xcode. Thank you

Answer

Use the android.util.Log class http://developer.android.com/reference/android/util/Log.html.

For example:

import android.util.Log;

class Someclass {
    private static final String TAG = "Someclass";
    ...
    public boolean someMethod(int argument) {
        Log.i(TAG, "This is some information log");
        if (argument == 0) {
           Log.e(TAG, "Error argument is 0!!!");
           return false;
        }


        Log.w(TAG, "Warning returning default value");
        return true;
    }
};

The reason the TAG variable is assigned like that instead of something like: Somelcass.class.getSimpleName() is because the reflective method will cause the reflection metta data of the class to be loaded on initialisation, however, the ‘preferred’ method by android developers prevents that and hence saves CPU and initialisation time.

Categories
discuss

How to preload a webpage before showing it?

I have created a simple webpage with several images, but when a user visits it, the browser loads the images one at a time, instead of all at once.

I want instead to first show a “loading” gif in the center of the page and then, when all the images are downloaded, show the entire webpage to the user at once..

How can I do this?

Answer

You can show a loader image by putting it somewhere im <img> tag and use below js code to hide it later on when all images are shown:

window.onload = function(){
  var el = document.getElementById('elementID');
  el.style.display = 'none';
};

Where elementID is supposed to be the id of loader element/tag.


The load event fires when all images/frames/external resources are loaded, so by the time that event fires, all images are loaded and we therefore hide the loading message/image here.

Categories
discuss

Is there any Twitter API SDK for Android?

I tried https://github.com/sugree/twitter-android-sdk, but could not get it work….I am not even sure what CALLBACK_URI should I set to….I am working on a native android APP so very confused here.

I have used Facebook sdk and was able to update my status from my app successfully…now I try to do the same with twitter…why twitter does not even release an Android SDK ?

Answer

Far and away the best Twitter API for Android is Twitter4J.

Categories
discuss

Android Organise Layouts into Sub Folders

I have a fairly complex android app, the contents of the ‘layout’ folder is becoming increasingly large. I’ve tried to organise the individual layout xml files into sub folders e.g. layout/buttons/, layout/activity/, layout/views/ etc. This doesn’t seem to work, the content of the folders in not parsed into the R. class.

Is there a way to do this?

Thanks!

Answer

I don’t think you’re going to be able to do this. I believe that it only supports certain folder names like layout-large,
layout-mdpi, layout-hdpi, layout-fr, etc. You can use more than one of these modifies as well like layout-fr-hdpi-large.

This page shows all of the allowed modifiers

http://developer.android.com/guide/topics/resources/providing-resources.html

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..