Thursday, August 27, 2009

Zooming the ImageView

For Zooming the ImageView Here is the snippet :

public class Zoom extends View {
private Drawable image;
private int zoomControler=200;
public Zoom(Context context)
{
super(context);
image=context.getResources().getDrawable(R.drawable.gallery_photo_1);
setFocusable(true);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
//here u can control the width and height of the images........ this line is very important
image.setBounds((getWidth()/2)-zoomControler, (getHeight()/2)-zoomControler, (getWidth()/2)+zoomControler, (getHeight()/2)+zoomControler);
image.draw(canvas);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode==KeyEvent.KEYCODE_DPAD_UP)// zoom in
zoomControler+=10;
if(keyCode==KeyEvent.KEYCODE_DPAD_DOWN) // zoom out
zoomControler-=10;
if(zoomControler<10)
zoomControler=10;
invalidate();
return true;
}
}


If any body knows the other way they can post here it should be helpful for others to develop.....

WebView in Android :

Web View In Android :

WebViewclassOverview click here to see the webview class details .

Here i am pasting the small example over webview implementation


package com.vinnysoft.webkit;

import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.FrameLayout;

public class WebSample extends Activity {
/** Called when the activity is first created. */
private static final FrameLayout.LayoutParams ZOOM_PARAMS =
new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
Gravity.BOTTOM);
private WebView wv;

@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
this.setContentView(R.layout.main);
this.wv = (WebView) this.findViewById(R.id.webview);

FrameLayout mContentView = (FrameLayout) getWindow().
getDecorView().findViewById(android.R.id.content);
final View zoom = this.wv.getZoomControls();
mContentView.addView(zoom, ZOOM_PARAMS);
zoom.setVisibility(View.GONE);

this.wv.loadUrl("http://imageurl.com/1.jpg");

// for example this.wv.loadUrl("http://news.softpedia.com/newsImage/RIM-Announces-BlackBerry-JDE-Plug-in-for-Eclipse-3.JPG");

like this example ....



}
}

In the res folder make the layout like this create a webview widget over there


android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
/>


Wednesday, August 26, 2009

XML Layout in Java

Write Layouts in Java :

This is the file which help how to write eidgets in java file and instaniate there it self....

package com.vinnysoft.hello;

import com.vinnysoft.hello.R;

import android.app.Activity;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.TextView;

public class HelloWorld extends Activity {

// TextView that will be assigned to the
// TextView resource when it's inflated or
// created in code.
TextView myTextView;

// Variable used to determine if the layout
// should be inflated from XML or constructed
// in code.
private static boolean inflate = true;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);

if (inflate)
inflateXMLLayout();
else
constructLayout();
}

// Use the 'main.xml' layout resource to create
// the UI for this Activity.
private void inflateXMLLayout() {
setContentView(R.layout.main);
myTextView = (TextView)findViewById(R.id.myTextView);
}

// Create the Activity's UI layout by creating
// and populating the layout in code.
private void constructLayout() {
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
LinearLayout.LayoutParams textViewLP = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);

LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
myTextView = new TextView(this);
myTextView.setText("Hello World, HelloWorld");
ll.addView(myTextView, textViewLP);
addContentView(ll, lp);
}
}


Androidmanifest file for the Programs ...


// application package
package="com.vinnysoft.hello">
// application icon path

//application activity permission with lable name

// intent filter what we need to launch






Proxy setting

To get the internet in emulator type the follow commands on sdk tools path .

// Proxy Settings

Open

Cd :\sdk\tools

adb shell



ls -l /data/data/com.android.providers.settings/databases/settings.db

sqlite3 /data/data/com.android.providers.settings/databases/settings.db

Open the databases

.databases

Show the tables


.tables

setting the proxy permission

insert into system values(99,'http_proxy','Server Address :Port Number');

insert into system values(99,'http_proxy','192.1.1.1:22');

or
insert into system values(101,'http_proxy','192.1.1.1:22');

Enjoy the Internet in Emulator

ADB Commands:

What is ADB?

Android Debugger Bridge....

Commands where i collected and used i am posting here for helpful to others...

// installing apk in system

adb install filename.apk

adb kill-server
adb start-server

adb devices // to get what are the devices running or attached

to uninstall the apk...

adb uninstall packagename.apk

To access the data bases and seeing the data in the content providers:

here one small example to open the content providers contacts

adb shell

# cd /data/data

# cd com.google.android.providers.contacts/databases

# ls

contacts.db

# sqlite3 contacts.db # it's picky you must include suffix
SQLite version 3.5.0

Enter ".help" for instructions

sqlite> .tables
_deleted_people android_metadata people
_sync_state calls peopleLookup
_sync_state_metadata contact_methods phones

sqlite> select * from people;


android:authorities="aexp.syncexample.SimpleString"
android:syncable="true"/>


for modification or inserting

sqlite>.dump

Friday, August 14, 2009

Sound Pool Manager Class

Here I am posting the Sound Pool Manager Class for playing the Sounds and Music from the resources.....

SoundPoolManager Class

package com.vinnysoft.music;
import android.media.SoundPool;
import android.media.JetPlayer;
class SoundPoolEvent
{
public SoundPoolEvent(int eventType,int eventSound)
{
this.eventType = eventType;
this.eventSound = eventSound;
}
public int eventType;
public int eventSound;

public static final int SOUND_PLAY=0;
public static final int SOUND_STOP=1;
public static final int SOUND_MUSIC_PLAY=2;
public static final int SOUND_MUSIC_PAUSE=3;
public static final int SOUND_MUSIC_STOP=4;
public static final int SOUND_MUSIC_RESUME=5;
}
class SoundStatus
{
public SoundStatus()
{

}
public static final int STATUS_LOOPING_NOT_STARTED=0;
public static final int STATUS_LOOPING_PAUSED=1;
public static final int STATUS_LOOPING_PLAYING=2;


}
public class SoundPoolManager implements Sound
{
SoundPoolManager(android.content.Context context)
{
this.context = context;
soundEvents = new java.util.LinkedList();
sounds = new java.util.HashMap();
handles = new java.util.HashMap();
streamIds = new java.util.HashMap();
isRunning = false;
finished = false;
this.musicPlayer =JetPlayer.getJetPlayer();
this.musicPlayer.loadJetFile(context.getResources().openRawResourceFd(R.raw.notify));
byte segmentId = 0;

this.musicPlayer.queueJetSegment(0, -1, -1, 0, 0, segmentId++);
}
public void addSound(int resid, boolean isLooping)
{

sounds.put(resid, new Boolean(isLooping));

}

public void startSound()
{
this.soundPool = new android.media.SoundPool(this.sounds.size(),android.media.AudioManager.STREAM_MUSIC,100);
java.util.Iterator iterator = sounds.keySet().iterator();

while(iterator.hasNext())
{
int soundid = iterator.next().intValue();
int soundhandle = this.soundPool.load(this.context, soundid, 1);
handles.put(new Integer(soundid), new Integer(soundhandle));
}


}
public void stopSound()
{
try
{
java.util.Iterator iterator = sounds.keySet().iterator();

while(iterator.hasNext())
{

int soundid = iterator.next().intValue();

this.soundPool.pause( this.handles.get(soundid).intValue());
this.soundPool.stop(this.handles.get(soundid).intValue());



}
}
catch(Exception e)
{

}
finally
{
try
{
this.musicPlayer.pause();
}
catch(Exception e1)
{

}
try
{
this.musicPlayer.release();
}
catch(Exception e2)
{

}
try
{
this.soundPool.release();
}
catch(Exception e3)
{

}

}


}

public int currentPlayer;
private boolean isRunning;
private java.util.HashMap sounds;
private java.util.HashMap handles;
private java.util.HashMap streamIds;
private android.content.Context context;
private java.util.LinkedList soundEvents;
private java.util.HashMap mediaPlayers;
public void stopSound(int resid)
{

}
public void playSound(int resid)
{
if(soundEvents!=null)
{
try
{
android.media.AudioManager mgr = (android.media.AudioManager) context.getSystemService(android.content.Context.AUDIO_SERVICE);
int streamVolume = mgr.getStreamVolume(android.media.AudioManager.STREAM_MUSIC);
int streamID = soundPool.play(handles.get( resid).intValue(), streamVolume, streamVolume, 1, 0, 1.0f);
int maxvolume = mgr.getStreamMaxVolume(android.media.AudioManager.STREAM_MUSIC);
mgr.setStreamVolume(android.media.AudioManager.STREAM_MUSIC, maxvolume, 0);
this.streamIds.put(resid, streamID);

}
catch(Exception e)
{

}
}
}
public void startMusic(int resid)
{

this.musicPlayer.play();

}
public void stopMusic(int resid)
{
this.musicPlayer.pause();
}
public void pauseMusic(int resid)
{
this.musicPlayer.pause();
}
public void resumeMusic(int resid)
{
this.musicPlayer.play();
}
SoundPool soundPool;
JetPlayer musicPlayer;

boolean finished = false;

}


And add the interface of Sound..... to the above package


package com.vinnysoft.music;

public interface Sound {

public void addSound(int resid, boolean isLooping);
public void startSound();
public void stopSound();
public void stopSound(int resid);
public void playSound(int resid);
public void startMusic(int resid);
public void stopMusic(int resid);
public void pauseMusic(int resid);
public void resumeMusic(int resid);

}

And u can use in difffernt ways ....

1. creating the soundpoolmanager instance class ......
2. by using Sound interface instance,....

SoundPoolManager m = new SoundPoolManager(context);
m.addSound(R.raw.vinny, false);
m.addSound(R.raw.soft,true);
m.startSound();
m.playSound(R.raw.vinny);
m.playMusic(R.raw.soft);



or

private Sound soundManager;

soundManager.playSound(R.raw.vinny);

Log.i("**********","kshasjklgfjkas");

public synchronized void stopMusic()
{
soundManager.stopSound();

//message.sendToTarget();
this.soundManager.stopSound();
}


By the above class you can play the music and sounds calling the above snippet....

for more details go through this example:

http://code.google.com/p/monolithandroid