Sunday, 24 August 2014

Android Toggle Button Example

Toggle Button Example
The Toggle Button requires the use of the Toggle Button tag in XML activity

Create test_activity.xml


<ToggleButton 
android:id="@+id/togglebutton" 
android:layout_width="100px" 
android:layout_height="50px" 
android:layout_centerVertical="true" 
android:layout_centerHorizontal="true"
android:onClick="toggleclick"/>
Test.java
All we need to do is check the isChecked() method of the toggle button object inside our toggleclick() function.
public class Test extends Activity {

private ToggleButton togglebutton;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    togglebutton = (ToggleButton) findViewById(R.id.togglebutton);
}

public void toggleclick(View v){
    if(togglebutton.isChecked())
        Toast.makeText(TestActivity.this, "ON", Toast.LENGTH_SHORT).show();
    else
        Toast.makeText(TestActivity.this, "OFF", Toast.LENGTH_SHORT).show();
    }
}

Wednesday, 13 August 2014

Android L Camera 2 API Features Burst Mode, HDR+ and more

Camera 2 API

     The most important aspects of the new Camera API is a dramatic increase in performance over the previous interface. The Camera 2 system is now capable of delivering full resolution images at the same speed the hardware can capture them thanks to a fully synchronized pipeline model. This allows the Nexus 5 to achieve 30 frames per second while capturing 8 at it's maximum of 8 megapixels.
     In addition to the profound performance improvements, the new camera API also includes burst mode, Digital Negative format (similar to RAW), HDR+, and full manual control of capture and post-processing. Many of the finer control configurations can also be modified, including:


  • Exposure time
  • ISO Sensitivity
  • Frame duration
  • Lens focus distance
  • Flash trigger
  • Color correction matrix
  • JPEG metadata
  • Tonemap curve
  • Crop region
  • AE / AF / AWB mode
  • AE / AWB lock
  • AF trigger
  • Precapture AE trigger
  • Metering regions
  • Exposure compensation

Android L Preview API Changes

Type
Additions
Changes
Removals
Total
Packages
8
43
0
51
Classes and Interfaces
87
232
0
319
Constructors
84
2
0
86
Methods
408
69
17
494
Fields
754
22
1
777
Total
1341
368
18
1727

The overall difference between API Levels 20 and L-preview is approximately 3.77%.

Developers will be able to do more with your phone's camera in the L release



 New Packages


1. android.app.job
2. android.bluetooth.le
3. android.hardware.camera2
4. android.hardware.camera2.params
5. android.media.session
6. android.media.tv
7. android.service.voice
8. android.system






       This new camera API will be officially released in Android L, and it’s already usable on the Android L preview for the Nexus 5. While there are currently no third party applications that take advantage of this API, there is a great deal of potential to make camera applications that greatly improve upon OEM camera applications. However, the most critical point to take away is that the new camera API will open up the possibility for applications that no one has thought of yet. While there are still issues with the Android camera ecosystem, with the release of Android L software won’t be one of them.

       Last Google updated its Camera app in May with version 2.2 for devices running Android 4.4+ KitKat OS. The update featured two new Panorama capturing modes, besides the existing horizontal and vertical Panorama modes. The two new Panorama modes are said to be fisheye mode and wide-angle mode. The update also let users the option to click images in 16:9 ratio along with a timer mode with 10 seconds and 3 seconds option.

Android API 20 l preview features

L Preview Features 


     The Android team has been work replacing old code that hasn't scaled well with newer and more powerful hardware. We've long known that the camera API was destined to see a massive update, but we were missing details like a release date or exactly what was coming. Thanks to the L release, we can finally see what has been in the works for all these many months.

 Camera 2 API

     The most important aspects of the new Camera API is a dramatic increase in performance over the previous interface. The Camera 2 system is now capable of delivering full resolution images at the same speed the hardware can capture them thanks to a fully synchronized pipeline model. This allows the Nexus 5 to achieve 30 frames per second while capturing 8 at it's maximum of 8 megapixels.

     In addition to the profound performance improvements, the new camera API also includes burst mode, Digital Negative format (similar to RAW), HDR+, and full manual control of capture and post-processing. Many of the finer control configurations can also be modified, including:
  • Exposure time
  • ISO Sensitivity
  • Frame duration
  • Lens focus distance
  • Flash trigger
  • Color correction matrix
  • JPEG metadata
  • Tonemap curve
  • Crop region
  • AE / AF / AWB mode
  • AE / AWB lock
  • AF trigger
  • Precapture AE trigger
  • Metering regions
  • Exposure compensation
        This new camera API will be officially released in Android L, and it’s already usable on the Android L preview for the Nexus 5. While there are currently no third party applications that take advantage of this API, there is a great deal of potential to make camera applications that greatly improve upon OEM camera applications. However, the most critical point to take away is that the new camera API will open up the possibility for applications that no one has thought of yet. While there are still issues with the Android camera ecosystem, with the release of Android L software won’t be one of them.

Saturday, 5 July 2014

Android API Level 20 L Preview

Android L Developer Preview

 The L Developer Preview

            The L Developer Preview includes updated SDK tools, system images for testing on an emulator, and system images for testing.

You can download link - http://developer.android.com/sdk/installing/adding-packages.html
  • L Developer Preview SDK Tools
  • L Developer Preview Emulator System Image - 32-bit (64-bit experimental emulator image coming soon)
  • L Developer Preview Emulator System Image for Android TV (32-bit)

Android Studio Beta

            To help you develop your apps for the upcoming Android version and for new Android device types, we’re also happy to announce Android Studio Beta. Android Studio Beta helps you develop apps by enabling you to:
        > Incorporate the new material design and interaction elements of the L Developer Preview SDK
        > Quickly create and build apps with a new app wizard and layout editor support for Android Wear and Android TV

Building on top of the build variants and flavors features we introduced last year, the Android Studio build system now supports creating multiple apks, such as for devices like Android Wear. You can try out all the new features with the L Developer Preview by downloading the Android Studio Beta today.
How to get started
To get started with the L Developer Preview and prepare your apps for the full release, just follow these steps:
  • Try out Android Studio Beta
  • Visit the L Developer Preview site
  • Explore the new APIs
  • Enable the material theme and try out material design on your apps
  • Get the emulator system images through the SDK Manager or download the Nexus device system images.
  • Test your app on the new Android Runtime (ART) with your device or emulator
  • Give us feedback
  • As you use the new developer features and APIs in the L Developer Preview.
You try the L Developer Preview as you start building the next generation of Android user experiences.

Saturday, 28 June 2014

PhoneGap Cordova tutorial for beginners

Android with PhoneGap in Eclipse


       You need the Android SDK installed on your computer to build an Android version of your application using the steps below.
To build the project in the workshop/platforms/android folder and run it on an Android device connected to your computer using a USB cable, type:
cordova run android
To build the project in the workshop/platforms/android folder and run it in the Android emulator, type:
cordova emulate android

Setting Up the Workshop Files

  1. Download the assets for the workshop here or clone this repository
  2. Unzip the file anywhere on your file system.
  3. Delete the contents of your project’s workshop/www folder with the exception of the config.xml file.
  4. Copy the contents of cordova-tutorial-master/www into your project’s workshop/www folder.
  5. Build and test your application: If you have a Mobile SDK installed on your system, repeat the steps in Part 2 above. If you don’t, simply open index.html in a browser on your computer.
  6. Type a few characters in the search box to search employees by name. Clicking an employee link doesn't produce any result at this time.
 The following <uses-permission> XML nodes and paste them as children of the root <manifest> node in the AndroidManifest.xml file: 
<uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.RECEIVE_SMS" /> <uses-permission android:name="android.permission.RECORD_AUDIO" /> <uses-permission android:name="android.permission.RECORD_VIDEO"/> <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> <uses-permission android:name="android.permission.READ_CONTACTS" /> <uses-permission android:name="android.permission.WRITE_CONTACTS" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.BROADCAST_STICKY" /> The <uses-permission>
XML values identify the features that you want to be enabled for your application. The lines above enable all permissions required for all features of PhoneGap to function. After you have built your application, you may want to remove any permissions that you are not actually using; this will remove security warnings during application installation. To read more about Android permissions and the <uses-permission> element, visit the Android developer topic on the uses-permission element.. After you have configured application permissions, you need to modify the existing <activity> node. 
 Locate the <activity> node, which is a child of the <application> XML node. Add the following attribute to the <activity> node:
 android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale">
Thank you....

Sunday, 22 June 2014

How to config Phone Gap Application in Android

Phone Gap for Android on a Windows machine.

Download and install PhoneGap

Download link-  http://phonegap.com/install/
Download Phone Gap Latest version and install in eclipse

Steps:
Launch Eclipse, and then, from the File menu, select New -> Android Project.
In the root directory of the project, create two new directories:
/libs
/assets/www
Copy phonegap.js from your PhoneGap download earlier to /assets/www.
Copy phonegap.jar from your PhoneGap download earlier to /libs.
Now, you must make the following adjustments to the project’s main Java file found in the
src folder in Eclipse
Change the class extend from Activity to DroidGap.
Replace the setContentView() line with
super.loadUrl(“file:///android_asset/www/index.html”);.
Add import com.phonegap.*;.

Create your own Phone Gap Android Application..

Thank You........
 

Sunday, 18 May 2014

How to connect sqlite database in android

Connect sqlite database in android

Using the Android SQLite Database

Try this

    public class Database extends SQLiteOpenHelper {

private static final int DATABASE_VERSION=1 ;

private static final String DATABASE_NAME="DB_NAME";

public static final String TABLE_NAME="T_NAME";

public static final String FIELD1="field_name";

    public Database(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}


public void onCreate(SQLiteDatabase db) {
String CREATE_TABLE = "CREATE TABLE " +
+"("+TABLE_NAME+ " TEXT,")";
System.out.println(CREATE_TABLE);
db.execSQL(CREATE_TABLE);
}

public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS "+CREATE_TABLE);

onCreate(db);
}


Friday, 9 May 2014

How to set Date picker in Android

Date picker in Android :

datebutton.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// On button click datepicker dialog show
showDialog(DATE_PICKER_ID);
}
});

Set Date in textview

private DatePickerDialog.OnDateSetListener pickerListener = new DatePickerDialog.OnDateSetListener() {
// when dialog box is closed, below method will be called.
@Override
public void onDateSet(DatePicker view, int selectedYear,
int selectedMonth, int selectedDay) {
year  = selectedYear;
month = selectedMonth;
day   = selectedDay;
// Show selected date
dob.setText(new StringBuilder().append(month + 1)
.append("-").append(day).append("-").append(year)
.append(""));
}
};

Use this......

Thursday, 8 May 2014

How to create Grid layout or Grid menu in android

Grid layout:

Try this :

grid_view.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<GridView
        android:id="@+id/grid"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"    
        android:gravity="center"
        android:numColumns="auto_fit"
        android:stretchMode="spacingWidthUniform" >
    </GridView>

</RelativeLayout>

Create Grid View Adapter class file

public class GridViewAdapter extends ArrayAdapter<Listitem> {
Context context;
int layoutResourceId;
ArrayList<Listitem> data = new ArrayList<Listitem>();
public GridViewAdapter(Context context, int layoutResourceId,ArrayList<Listitem>gridArray) {
super(context, layoutResourceId, gridArray);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = gridArray;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
RecordHolder holder = null;
if (row == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new RecordHolder();
holder.txtTitle = (TextView) row.findViewById(R.id.item_text);
holder.imageItem = (ImageView) row.findViewById(R.id.item_image);
row.setTag(holder);
} else {
holder = (RecordHolder) row.getTag();
}
Listitem item = data.get(position);
holder.txtTitle.setText(item.getTitle());
holder.imageItem.setImageBitmap(item.getImage());
return row;
}
static class RecordHolder {
TextView txtTitle;
ImageView imageItem;
}
}

Create class file Activity_menu.java


public class Activity_menu extends Activity {
      
       GridViewAdapter GridViewAdapter;
       GridView gridView;
      
       @Override
       protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.grid_view);
             
              Bitmap bus = BitmapFactory.decodeResource(this.getResources(), R.drawable.bus);
              Bitmap train = BitmapFactory.decodeResource(this.getResources(), R.drawable.train);            
              Bitmap travel = BitmapFactory.decodeResource(this.getResources(), R.drawable.travel);
              Bitmap busroute = BitmapFactory.decodeResource(this.getResources(), R.drawable.busrr);

              gridArray.add(new Listitem(bus,"Bus"));
              gridArray.add(new Listitem(train, "Train"));
              gridArray.add(new Listitem(travel,"Flight"));
              gridArray.add(new Listitem(busroute, "Bus"));
             
              gridView = (GridView) findViewById(R.id.StugridView);
             
              GridViewAdapter = new GridViewAdapter(this, R.layout.gridlist, gridArray);
              gridView.setAdapter(GridViewAdapter);             
              gridView.setOnItemClickListener(new OnItemClickListener() {

                     @Override
                     public void onItemClick(AdapterView<?> parent, View v,
                                  int position, long id) {

                           switch(position)
                           {
                           case 0:
                                 
                                  ProgressDialog pDialog = new ProgressDialog(Activity_menu.this);
                                  pDialog.setMessage("Loading..");
                                  pDialog.setIndeterminate(false);
                                  pDialog.setCancelable(true);
                                  pDialog.show();
                                  Intent intent = new Intent(getApplicationContext(), Bus.class);
                                  startActivity(intent);
                                  break;
                           case 1:
                                 
                                  ProgressDialog pDialog1 = new ProgressDialog(Activity_menu.this);
                                  pDialog1.setMessage("Loading..");
                                  pDialog1.setIndeterminate(false);
                                  pDialog1.setCancelable(true);
                                  pDialog1.show();
                                  Intent intent1 = new Intent(getApplicationContext(), Train.class);
                                  startActivity(intent1);
                                  break;
                           case 2:
                                  ProgressDialog pDialog2 = new ProgressDialog(Activity_menu.this);
                                  pDialog2.setMessage("Loading..");
                                  pDialog2.setIndeterminate(false);
                                  pDialog2.setCancelable(true);
                                  pDialog2.show();
                                  Intent intent2 = new Intent(getApplicationContext(), Flight.class);
                                  startActivity(intent2);
                                  break;
                           case 3:
                                  ProgressDialog pDialog3 = new ProgressDialog(Activity_menu.this);
                                  pDialog3.setMessage("Loading..");
                                  pDialog3.setIndeterminate(false);
                                  pDialog3.setCancelable(true);
                                  pDialog3.show();
                                  Intent intent3 = new Intent(getApplicationContext(), Bus.class);
                                  startActivity(intent3);
                                  break;                                 
                           }
                     }
              });
         }
}

add reference library file
gridlayout_v7 .jar download link : https://github.com/jacobmoncur/gridlayout_v7/tree/master/bin