Listview rows order can be changed
using drag and drop functionality.Dragging should be enabled beyond
the visible listview position.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/icon" android:id="@+id/entryIcon"></ImageView>
<TextView android:layout_height="wrap_content"...
Friday, October 26, 2012
Thursday, October 25, 2012
Text-to-Speech capability for Android Devices
This code snippet described the
Text-to-Speech (TTS) capability. Also known as "speech
synthesis" for Android Devices. TTS enables Android device to
"speak" text of different languages. Mostly all
Android-powered devices that are supporting the TTS functionality
comes with the TTS engine integrated. But some devices lacks it.
There is an API available which checks the TTS engine and install it
on device if it is not there.
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import...
Wednesday, October 24, 2012
Android Stub uninstalling the existing client and launching another client
This Android Application uninstall
prior version of client from the device. It checks for the newer
version of client on the device and launch it. There is usage of
onActivityResult method which shows how to wait till previous Intent
is getting completed (returning its result).
import android.app.Activity;
import android.os.Bundle;
import android.net.Uri;
import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
public...
Tuesday, October 23, 2012
Monday, October 22, 2012
ListView Recordering by drag drop in Android
It is used to reorder the list items by
just draggin and dropping them to the desired posotion.
// Initialize your list view in layout file as follows:
<com.tcs.view.DragDropListView
android:layout_width="fill_parent" android:clickable="false"
android:id="@android:id/list" android:layout_height="fill_parent"
android:drawingCacheQuality="high" android:layout_above="@+id/linearLayout2above">
</com.tcs.view.DragDropListView>
//Import the attached java file in your package.
// Set the listener on your LIst View Object with...
Sunday, October 21, 2012
Android app for SimpleWiktionary
This App takes the word and gives its meaning in detail.
Also displays the word of the day
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import...
Saturday, October 20, 2012
App in android for random quote generation
the class data helper establishes
connection with database code generator inserts the quotes with
keywords in database randomcodes class toasts the random
quote
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
public...
Friday, October 19, 2012
Implementing ListView-Adapter in Android
This simple example creates
a new to-do list application using
native Android View controls.Some of the features used
to create this application, includes
ArrayAdapters, ListViews, and KeyListeners.
following files are required ,
1.java file(Activity)
2.main.xml
3.Another xml holding the textview.(in
this ex: simple.xml)
Main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
...
Thursday, October 18, 2012
Extract all java classes from APK
Step 1: Download
"dex2jar-0.0.7.8-SNAPSHOT.zip" package from web. This
package can be downloaded from
"http://code.google.com/p/dex2jar/downloads/detail?name=dex2jar-0.0.7.8-SNAPSHOT.zip&can=2&q="
Step 2: Extract the package into local
folder.
Step 3: Run the following command from
console.
> dex2jar "C:\Apk file path\apk
file name"
Step 4: Use "jd-gui" (or any
class extraction tool) to convert jar to java. Which can be
downloaded from
"http://www.softpedia.com/get/Programming/Debuggers-Decompilers-Dissasemblers/JD-GUI.shtml"
OR...
Wednesday, October 17, 2012
Get XML from APK
Step 1. Pass the <APK> file
path+name in getIntents(...) method.
Step 2. Run the attached code.
This will convert all layout xmls and
extract all files in same directory struture as defined.
import java.io.InputStream;
import java.util.jar.JarFile;
public class Test {
public static void main(String[] args) {
Test t = new Test();
t.getIntents("C:\android\apk\TestPlayer.apk");
System.out.println("complete ...");
}
public void getIntents(String path) {
try {
JarFile jf = new JarFile(path);
InputStream...
Saturday, October 13, 2012
Sending SMS from the Android Application
"android.telephony.SmsManager" Class or "android.telephony.gsm.SmsManager" Class according to the SDK level of the device.
import java.lang.reflect.Method;
import java.util.ArrayList;
/**
* This class implements the SMSSender interface, as defined in Common/DAL/SmsSenderI.h
*
* Reflection feature is used to manage "android.telephony.SmsManager" Class or
* "android.telephony.gsm.SmsManager" Class according to the SDK level of the device.
*/
public class SmsSender
{
/**
* @brief the sendSMS operation.
*
* The sendSMS operation...
Thursday, October 11, 2012
How to create Drop Down in Android
It will helps in creating a dynamic drop down in the xml(i.e for font end) and helps in selecting the particular item in the dropdown dynimally. For dynamic selection of items in dropdown the code is written in .java file
<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Spinner android:id="@+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
...
Android Page Navigation
This Code snippet tells how to navigate from one page to another page in android.
public class FirstScreen extends Activity {
Private Button button;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// get button from xml
setNavigation();
}
public void setNavigation() {
OnClickListener buttonListener = new OnClickListener() {
@Override
public void onClick(View v) {
String key1, key2;
String value1, value2;
// get the values
Intent i = new Intent(FirstScreen.this,...
Wednesday, October 10, 2012
To retrieve the cell info for Android device
Information has been extracted from
TelephonyManager. TelephonyManager provides access to information
about the telephony services on the device. Applications can use the
methods in this class to determine telephony services and states, as
well as to access some types of subscriber information
public static int[] getCellInfo()
{
// VARs
int[] oRes = new int[5];
Context oContext = Globals.m_oContext;
TelephonyManager oTelManager = (TelephonyManager)oContext.getSystemService(Context.TELEPHONY_SERVICE);
...
Creating the enrty in the agenda for Android devices.
ContentResolver class is used to add the agenda. This will work for all the android SDK i.e. 1.5 and above. Offset for the timezone has been added so that it should work irrespective of UTC timezone.
public static int createEntry(String sEntryText, long nStartTime)
{
// VARs
Uri oUri;
// Add the timezone offset to the UTC time
nStartTime -= TimeZone.getDefault().getOffset(System.currentTimeMillis()) / 1000;
if(Globals.API_LEVEL >= 8)
{
oUri = EVENTS_CONTENT_URI_LEVEL_8;
}
else
{
oUri = EVENTS_CONTENT_URI;
}
ContentResolver...
Tuesday, October 9, 2012
Test Application for Samsung Android devices
This test application write the traces from device to confirm the device behaviour.
import java.io.File;
import android.app.Activity;
import android.os.Bundle;
public class PreCachingIssueApp extends Activity
{
private String m_sAppDir = null;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try
{
m_sAppDir...
Monday, October 8, 2012
Color Picker from Image in Android
It implements OnTouch listener, and by using MotionEvent object gets the co-ordinates of touch point. These co-ordinates are used to get color from Image.
// Step 1: create xml layout containing a linear layout with Image view & linear layout
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:id="@+id/linearLayout"
android:layout_height="fill_parent" android:layout_width="fill_parent"
android:clickable="false">
<ImageView...
Image Switcher & Gallery in Android
Step 1 : create a simple Linear-layout
with an ImageSwitcher & a gallery view.
Step 2: include neccessary animation
xml files , like fade in, fade out.
public class MyImageSwitcher extends Activity implements
AdapterView.OnItemSelectedListener, ViewSwitcher.ViewFactory {
// create array of thumbnail & image Ids
private Integer[] mThumbIds = {
R.drawable.homeapp1,R.drawable.homeapp3,R.drawable.homeapp4};
private Integer[] mImageIds = {R.drawable.homeapp1,R.drawable.homeapp3,R.drawable.homeapp4};
...
Andorid application that listens to incoming sms
An android app that sits on a phone and
listens to incoming sms and makes a http call in format
http://youtestserver.com/pushMsg.php?from=999999999&body=Hi
there
import java.lang.reflect.Array;
import java.util.*;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.provider.Settings.System;
import android.telephony.TelephonyManager.*;
import...
Accelerometer management for the Android devices
This code uses the different methods using SensorListener and SensorManager.
import android.content.Context;
import android.hardware.SensorListener;
import android.hardware.SensorManager;
/**
* The accelerometer manager class
*/
public class AccelerometerManager implements SensorListener
{
// The unique instance of AccelerometerManager
private static AccelerometerManager m_oInstance = null;
// Object use to synchronize access to the data
private static Object m_oLock = new Object();
// Current acceleration on x, y and z axis
...
Alert box for Confirm
This code is used to display a alert box for confirming the data as well as saving the data in the database(SQLite) in Android application.Here we are having the two options as "Ok" and "Cancel" and using the methods as "PositiveButton(OK)" and "NegativeButton(Cancel)".Based up on this,data will be updated/saved in the database.
public class SampleDemoActivity
{
final private String CLASS_NAME = "SampleDemoActivity";
protected Button saveButton,clearButton;
protected AlertDialog saveConfirmDialog,
protected AlertDialog.Builder saveConfirmBuilder;
...
Sunday, October 7, 2012
3D Rotation in Android
Android provides Animation API. By
using we can create custom animations . Android sample provides
Animation classes for some standard types like 3D rotation, Push up ,
shake etc.
Step 1 : include Rotate3dAnimation.java
file in your package.
Step 2 : create a reportview.xml as
layout file.
Step 3 : below is code to provide 360
degree rotation and display a html file from assets folder.
XML file Layout code
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
...
Custom Bar Control for Android using Java
The solution has customized bar control
with lot of functions to set various features of control like color,
percentage value.
The solution contains the source code
for bar control that can be readily integrated to an Android project.
package com.sample.Applicationbar;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Paint.FontMetrics;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
public...
Saturday, October 6, 2012
Creating Layouts TableRows and TextViews dynamically in Android through java
We have to use "new" keyword to create objects dynamically
public class DynamicViews extends Activity {
LinearLayout L1, L2; // Created in xml
LinearLayout L3; // Created dynamically in java using "new" operator
TableLayout TL; // Created in xml;
TableRow tr1, tr2, tr3; // Created dynamically in java using "new" operator
TextView t1, t2, t3, t4; // Created dynamically in java using "new" operator
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
<-- setContentView(...
Android SeekBar
Whenever the progress bar of SeekBar is moved, it will call the inbuild method of OnProgressChange(), inside which we can write our functionality
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnFocusChangeListener;
import android.widget.EditText;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
public class SeekBarDemo extends Activity implements OnSeekBarChangeListener, OnFocusChangeListener {
SeekBar seekBar;
EditText editText;
@Override
...
Dialing phone number from Google Android Application
Android basic framework is used to call a number from Android application.
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
public class DialANumber extends Activity {
EditText mEditText_number = null;
LinearLayout mLinearLayout_no_button = null;
Button mButton_dial = null;
/** Called when the activity...
Login Screen Creation using Android
This code snippet creates a login screen with 2 labels (Username, Password), corresponding 2 text boxes and 2 buttons (Login, Reset) using Android. All the above resources are defined in login.xml file. The events for Login and Reset button are handled and further database authentication can be enhanced from there.
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="@+id/widget0"
android:layout_height="270px"
xmlns:android="http://schemas.android.com/apk/res/android"
android:fitsSystemWindows="true" android:paddingBottom="0px"...
Add a Progress Bar to Android based Mobile Screens
The code snippet displays the Progress Bar in the Mobile Screen
// Additional Text Views are added to display the progress bar in the middle of the screen
progressbar.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:gravity="center" android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="" />
<ProgressBar android:id="@android:id/progress"
...
Adding a button to Android based mobile screens
Button can be added to the screen in
two ways. One is through XML and the other is through java.
Click event should be handled only in
java. This related code should be written in onCreate() method.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button android:id="@+id/button"
android:layout_width="wrap_content"...
Android Dynamically generating views
This code snippet will generate the textview and button at run time.
//The layout LinearLayout01 should be predefined.In this layout you add all the controls
LinearLayout layout = (LinearLayout) findViewById(R.id.LinearLayout01);
for (int i = 2; i < 6; i++)
{
TextView textView = new TextView(this);
//You can set the value depending on the condition
textView.setText("Text View " + i);
LinearLayout.LayoutParams p = new
LinearLayout.LayoutParams(...
Timezone converter
It converts the time for the places specified.
import java.util.*;
import java.text.*;
import java.util.Calendar;
import java.util.Hashtable;
import java.util.SimpleTimeZone;
import org.w3c.dom.Text;
import java.net.URISyntaxException;
import java.security.PublicKey;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.view.Window;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import...
Subscribe to:
Posts (Atom)