Categories
discuss

Does Android support scaling Video?

Using a VideoView is it possible to set a scale factor for Android? By Default the video view resizes itself to fit the encoded resolution of the Video. Can I force Android to render a video into a smaller or larger rect?

Answer

By Default the video view resizes
itself to fit the encoded resolution
of the Video.

VideoView (or the SurfaceView for use with MediaPlayer) will be the size you tell it to be in your layout. Within that space, the video will play back as large as possible while maintaining the aspect ratio.

Can I force Android to render a video
into a smaller or larger rect?

Yes: make your VideoView be the size you want, and Android will scale to fit the size of the VideoView.

Categories
discuss

Android – How do I get raw touch screen information?

I’m working on a painting application for Android and I’d like to use raw data from the device’s touch screen to adjust the user’s paint brush as they draw. I’ve seen other apps for Android (iSteam, for example) where the size of the brush is based on the size of your fingerprint on the screen. As far as painting apps go, that would be a huge feature.

Is there a way to get this data? I’ve googled for quite a while, but I haven’t found any source demonstrating it. I know it’s possible, because Dolphin Browser adds multi-touch support to the Hero without any changes beneath the application level. You must be able to get a 2D matrix of raw data or something…

I’d really appreciate any help I can get!

Answer

There are some properties in the Motion Event class. You can use the getSize() method to find the size of the object. The Motion Event class also gives access to pressure, coordinates etc…

Categories
discuss

Fast Bitmap Blur For Android SDK

Currently in an Android application that I’m developing I’m looping through the pixels of an image to blur it. This takes about 30 seconds on a 640×480 image.

While browsing apps in the Android Market I came across one that includes a blur feature and their blur is very fast (like 5 seconds) so they must be using a different method of blurring.

Anyone know a faster way other than looping through the pixels?

Answer

This is a shot in the dark, but you might try shrinking the image and then enlarging it again. This can be done with Bitmap.createScaledBitmap(Bitmap src, int dstWidth, int dstHeight, boolean filter). Make sure and set the filter parameter to true. It’ll run in native code so it might be faster.

Categories
discuss

Android ListView programmatic selection/highlight

I have a simple listview and listadapter setup as follows:

listAdapter = new ArrayAdapter<MyDomainObject>(this, android.R.layout.simple_list_item_1, listOfDomainObjects);
listView.setAdapter(listAdapter);

The user makes a selection on the list which takes them to another activity. From the new activity they can click their selection which returns them to the activity with the above list. I want to highlight the previous selection made. I currently find the matching list entry and call:

listView.setSelection(matchIndex);

This brings their previous selection to the top of the list. Is it possible to highlight (in that default orange) the previous selection. I have tried several approaches with no luck.

Answer

What you have is fine. However, the determination of whether the selection is “highlighted” is determined on whether the user was using the touchscreen. If they have used the touchscreen more recently than the trackball/D-pad/whatever, the device is in “touch mode” and selection highlights are not shown.

Categories
discuss

What is the proper style for listing imports in Java?

Is it better to list each individual piece of a package you’re going to need (see #1) or is it better to just import everything from a package (see #2)?

1

import java.awt.image.ColorModel;
import java.awt.image.ComponentColorModel;
import java.awt.image.ColorConvertOp;

2

import java.awt.*;

Answer

It’s NOT simply a matter of style; import-on-demand can result in code that ceases to compile as new classes are added to existing packages.

Basic idea (See http://javadude.com/articles/importondemandisevil.html for details.):

import java.awt.*;
import java.util.*;
...
List list;

worked in Java 1.1; as of Java 1.2, the above code will no longer compile.

Import on demand is EVIL because your program can stop compiling when new classes are added to existing packages!

ALWAYS use explicit imports. It’s not a matter of style; it’s a matter of safety.

This is especially bad if you check in perfectly-compiling code and a year later someone checks it out and tries to compile it with new class libraries.

(Import-on-demand is an example of a really bad programming language feature – no feature should break code when new types are added to a system!)

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