Posts

Showing posts from April, 2013

How to draw an overlay on a SurfaceView used by Camera on Android?

Solution 1: I have a simple program that draws the preview of the Camera into a SurfaceView . What I'm trying to do is using the onPreviewFrame method, which is invoked each time a new frame is drawn into the SurfaceView , in order to execute the invalidate method which is supposed to invoke the onDraw method. In fact, the onDraw method is being invoked, but nothing there is being printed (I guess the camera preview is overwriting the text I'm trying to draw). This is a simplify version of the SurfaceView subclass I have: public class Superficie extends SurfaceView implements SurfaceHolder . Callback { SurfaceHolder mHolder ; public Camera camera ; Superficie ( Context context ) { super ( context ); mHolder = getHolder (); mHolder . addCallback ( this ); mHolder . setType ( SurfaceHolder . SURFACE_TYPE_PUSH_BUFFERS ); } public void surfaceCreated ( final SurfaceHolder holder ) { camera = Camera . open (); try {

Create a spinning cube with OpenGL ES and Android

Image
Android supports 3D graphics via the OpenGL ES API, a flavor of OpenGL specifically designed for embedded devices. This article is not an OpenGL tutorial, it assumes the reader has already basic OpenGL knowledge. The final result will look like this: First we write a new Activity and in the onCreate method we create the two fundamental objects we need to use the OpenGL API: a GLSurfaceView and a Renderer . public class OpenGLDemoActivity extends Activity { @Override public void onCreate ( Bundle savedInstanceState ) { super . onCreate ( savedInstanceState ); // Go fullscreen requestWindowFeature ( Window . FEATURE_NO_TITLE ); getWindow (). setFlags ( WindowManager . LayoutParams . FLAG_FULLSCREEN , WindowManager . LayoutParams . FLAG_FULLSCREEN ); GLSurfaceView view = new GLSurfaceView ( this ); view . setRenderer ( new OpenGLRenderer ());

how to make surfaceview transparent

Try this: SurfaceView sfvTrack = ( SurfaceView ) findViewById ( R . id . sfvTrack ); sfvTrack . setZOrderOnTop ( true ); // necessary sfhTrack = sfvTrack . getHolder (); sfhTrack . setFormat ( PixelFormat . TRANSPARENT );

Video Live Streaming in Android

Hello Frirends, Today i am going to post for Live Video streaming from server.     import android.app.Activity; import android.app.ProgressDialog; import android.graphics.PixelFormat; import android.media.MediaPlayer; import android.media.MediaPlayer.OnPreparedListener; import android.net.Uri; import android.os.Bundle; import android.widget.MediaController; import android.widget.VideoView; public class MainActivity extends Activity {        private static ProgressDialog progressDialog ;        String videourl = "" ;        VideoView videoView ;        @Override        protected void onCreate(Bundle savedInstanceState)        {               super .onCreate(savedInstanceState);               setContentView(R.layout. activity_main );               videoView = (VideoView) findViewById(R.id. video_View );               progressDialog = ProgressDialog. show (MainActivity. this , "" , "Buffe

cannot pass objects of non-trivially-copyable type through '...'

Question: I have a string I am trying to print. when I used cout, it outputs perfectly but using printf leaves it mangled. Here is the code: int main ( int argc , char * argv [] ) { // Check to make sure there is a single argument if ( argc != 2 ) { cout << "usage: " << argv [ 0 ] << " <filename>\n" ; return 1 ; } // Grab the filename and remove the extension std :: string filename ( argv [ 1 ]); int lastindex = filename . find_last_of ( "." ); std :: string rawname = filename . substr ( 0 , lastindex ); cout << "rawname:" << rawname << endl ; printf ( "rawname: %s" , rawname ); } The cout gives me "rawname: file" The printf gives me "rawname: " and then a bunch of squiggly characters Sorry if this is a dumb question. I am doing my best to learn. Thank you

how to fix error: unknown type name ‘namespace’

Question: #ifndef UNO_ACTION_ #define UNO_ACTION_ namespace Uno { namespace Game { class Game ; } } // namespace namespace Uno { namespace Action { using :: Uno :: Game :: Game ; class Action { public : virtual bool isDisposeable () = 0 ; virtual void takeAction ( Game * game ) = 0 ; virtual ~ Action () {} }; } } #endif I compile these code on ubutun 12.04 and it return to set of error: action . h : 4 : 1 : error : unknown type name ‘ namespace ’ action . h : 4 : 15 : error : expected ‘=’, ‘,’, ‘;’, ‘ asm ’ or ‘ __attribute__ ’ before ‘{’ token action . h : 8 : 1 : error : unknown type name ‘ namespace ’ action . h : 8 : 15 : error : expected ‘=’, ‘,’, ‘;’, ‘ asm ’ or ‘ __attribute__ ’ before ‘{’ token I don't know how to solve these errors. Solution:  It sounds like you're trying to compile your C++ code with a C compiler. Trying using g++ instead of gcc and giving

java.lang.UnsatisfiedLinkError: Native method not found

Question: I'm trying to make a NDK application, but i get this error java.lang.UnsatisfiedLinkError: Native method not found: com.example.hellondk.jni.HelloNDK.hello:()I I don't understand because the name of the C++ funtion is the same as the java packagename and class HelloNDK.cpp #include <jni.h> JNIEXPORT jint JNICALL Java_com_example_hellondk_jni_HelloNDK_hello ( JNIEnv * env , jobject o ){ return ( jint ) 2 ; } HelloNDK.java package com . example . hellondk . jni ; public class HelloNDK { public native int hello (); static { System . loadLibrary ( "HelloNDK" ); } } Android.mk LOCAL_PATH := $ ( call my - dir ) include $ ( CLEAR_VARS ) LOCAL_MODULE := HelloNDK LOCAL_SRC_FILES := HelloNDK . cpp include $ ( BUILD_SHARED_LIBRARY )     Solution 1:   You're exporting it as a C++ function, but the JNI linker doesn't understand C++ name mangling, so it won't be able to find

PhoneGap: Getting Data from a Server

Well your application would be pretty useless if you couldn't get data from a remote server now wouldn't it? Luckily since your PhoneGap application is running off of the file:// protocol it isn't limited by the same origin policy . This means we can request data using XmlHttpRequest from any domain. I'm going to give you an example of searching for all tweets that mention PhoneGap that demonstrates this ability without the use of any extra JavaScript library like jQuery or Dojo. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32

LOCAL_SHARED_LIBRARIES and LOCAL_LDLIBS

Question: hello i would like to ask the differences between LOCAL_SHARED_LIBRARIES and LOCAL_LDLIBS for example , i try to link skia in mydroid  i need to use LOCAL_SHARED_LIBRARIES = libskia but in NDK i need to use LOCAL_LDLIBS = -lskia so i am wondering what's the differences and why do i need to two different ways for my Android.mk thanks  Solution: Libraries that are linked via LOCAL_LDLIBS will not have any dependencies generated for them. So, typically, LOCAL_LDLIBS should be used when you don't want to or don't have the resources to build the specific library. So, if you are using a library provided by the NDK, you *technically* don't need to rebuild the provided libraries. So, in your case, in your "mydrdoid", if you use: LOCAL_LDLIBS := -lskia" ...then, libskia.so *need not* be rebuilt. whereas, if you use: LOCAL_SHARED_LIBRARIES := libskia ... then libskia.so *will* be rebuilt if there are any changes in it's dependencies. 

Android ndk-build iostream: No such file or directory

I think "APP_STL:=stlport_static" must be in Application.mk file. Create a "Application.mk" file and write "APP_STL:=stlport_static" in it.

Abstract Factory Design Pattern

Factory of factories. To keep things simple you can understand it like, you have a set of ‘related’ factory method design pattern . Then you will put all those set of simple factories inside a factory pattern. So in turn you need not be aware of the final concrete class that will be instantiated. You can program for the interface using the top factory. There is also a view that abstract factory is ‘also’ implemented using prototype instead of factory methords pattern. Beginners for now please don’t yourself with that. Just go with factory methods pattern. As there is a word ‘abstract’ in the pattern name don’t mistake and confuse it with java ‘abstract’ keyword. It is not related to that. This abstract is from object oriented programming paradim. Sample abstract factory design pattern implementation in Java API XML API implements abstract factory. There is a class name SchemaFactory . This acts as a factory and supports implemenation of multiple schemas using abstract