Tuesday, 26 November 2013

Auto-complete Text view in android.

0 comments
In this post we look into the auto complete text view and how it will be used in your app.

Steps 1)Include the Auto-complete Text-view in your XML as following:-

<AutoCompleteTextView
                    android:id="@+id/txt_autoview"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:singleLine="true"
                    android:text=""
                    android:textColor="#000000"
   />

Steps 2)Implements an interface as following:-

public class Depots extends Activity implements TextWatcher {

AutoCompleteTextView  txt_market;
List<String> market;

}

Steps 3)Add the following in your onCreate():-

market = new ArrayList<String>();
txt_market = (AutoCompleteTextView) findViewById(R.id.txt_autoview);

//Before you setting an adapter to the textview you have to add an items to the arraylist.

txt_market.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, market));


Steps 4)Add the Unimplemented methods for your Text Watcher interface.


Thanks..
Read full post »

Thursday, 14 November 2013

How To Change Modes Of Phone(Normal,Silent,vibrate) Programmatically.

0 comments
Today we have seen how to change the modes of phone using audio manager in Android.

1)Declare the Audio manager class.

   AudioManager am;

   am= (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE);

2)Next, we have to perform an action on particular button to change the mode.

   @Override
   public void onClick(View view) {

        switch (view.getId())
        {

   //For Normal Mode
            case R.id.btn_normal:

                         am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
            break;

   //For Silent Mode
            case R.id.btn_silent:

                        am.setRingerMode(AudioManager.RINGER_MODE_SILENT);
            break;

   //For Vibrate Mode
            case R.id.btn_dnd:
          
                      am.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
          break;
      }
 }

Thanks..
Read full post »

Thursday, 31 October 2013

Webview Demo in android

0 comments
Today,we look into a web-view to open a simple link without using browser.

1)Add the web-view in your XML with the following.

        <WebView
        android:id="@+id/webView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />

2)Then write the following code in your activity to display the link in your web-view.

        WebView web;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

web = (WebView) findViewById(R.id.webView1);

web.setWebViewClient(new myWebClient());
web.loadUrl("http://uniqueandroidtutorials.blogspot.in");
}

public class myWebClient extends WebViewClient {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// TODO Auto-generated method stub
super.onPageStarted(view, url, favicon);
}

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub

view.loadUrl(url);
return true;

}
}

// To handle "Back" key press event for WebView to go back to previous screen.
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && web.canGoBack()) {
web.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}

Done..Thanks..

To download the demo Click Here..
Read full post »

Tuesday, 29 October 2013

Android-To draw a line and rounded corner view(like rounded-corner Editext and Button).

0 comments
1)First,To Draw a line in XML by using simple View,Just add this following.

        <View
          android:layout_width="match_parent"
          android:layout_height="1dp"
          android:background="@android:color/black" />

2)Next,For rounded corner view just create an XML in /drawable folder and add this following code.

   round_corner.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <corners
        android:bottomLeftRadius="3dp"
        android:bottomRightRadius="3dp"
        android:radius="3dp"
        android:topLeftRadius="3dp"
        android:topRightRadius="3dp" />
   <solid
       android:color="@android:color/white"/>
   </shape>

3)At last you add this xml in a background to your view like following:-

<EditText
          android:id="@+id/ed1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:background="@drawable/round_corner"
        />

Done..Thanks.
Read full post »

Thursday, 24 October 2013

How To Get The Power And Back Key Event In Android.

0 comments
Hello friends,If you want to perform an action with power and back key pressed look into following.

1)Add this following method in your Activity.(For Power Button Pressed)

 public boolean dispatchKeyEvent(KeyEvent event)
 {
 if (event.getKeyCode() == KeyEvent.KEYCODE_POWER) {
  
 Toast.makeText(getApplicationContext(), "Power button clicked",Toast.LENGTH_LONG).show();

       return true;
 }
     return super.dispatchKeyEvent(event);
}



2)Next,Add this following in your Activity.(For Back Key Pressed)

 @Override
 public void onBackPressed() 
{
        finish();
}

Thanks..
Read full post »

Monday, 7 October 2013

Flurry Agent In Your Android App(To Survey your App)

0 comments
Hello Friends..This post is based how to add Flurry Agent in your App ,the concept is based on track your app through out the world..

1)This will track your app,when you publish your app in market this will give you all the details that how many user's with different area around the world are using the app.From this you will survey your app.

To include Flurry in your App you will perform  following steps in your project:-

1 - Go to flurry.com and register for your app, which will generate you a unique tracking code.

2 - Download  FlurryAgent. jar and add it to your project libraries. In Eclipse, right-click your project folder, select properties, select Java Build Path, and choose Add External JARs.and select this .jar file.

3)Next, In your activities(.java code) you need to add this two methods.
public void onStart()
{
   super.onStart();
   FlurryAgent.onStartSession(this, "Your Key");
   
}

public void onStop()
{
   super.onStop();
   FlurryAgent.onEndSession(this);
}
4)Final Steps to Add android.permission.INTERNET to your AndroidManifest.xml.
For the Unique tracking code(API Key) refer the following steps:-
 -From the Flurry dashboard, under Manage Applications click Add a New Application. Next select the application's platform,enter the application name and category, and then Create App. This will showing you the API key. 
            
                 When your app published to the market you will find all your survey details in your Flurry dashboard.

Thanks..


Read full post »

Saturday, 5 October 2013

Performing Operation On GPS (like checking gps connection,turn on gps,turn off gps)

0 comments
Hello Friends

On today's post you will find  all the operations  regarding GPS. In that you handle your GPS connection and perform operation  Pro-grammatically.

A)First, find solution of Checking the GPS Connection Pro-grammatically with the few simple steps:-

  public Boolean checkGPSProvider() {
LocationManager service = (LocationManager) _context
.getSystemService(_context.LOCATION_SERVICE);
boolean enabled = service
.isProviderEnabled(LocationManager.GPS_PROVIDER);

return enabled;
}

B)Next, You find how to Automatically Turn On GPS Connection.:-

  public void turnGPSOn() {
String provider = Settings.Secure.getString(
_context.getContentResolver(),
Settings.Secure.LOCATION_PROVIDERS_ALLOWED);

if (!provider.contains("gps")) { // if gps is disabled
final Intent poke = new Intent();
poke.setClassName("com.android.settings",
"com.android.settings.widget.SettingsAppWidgetProvider");
poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
poke.setData(Uri.parse("3"));
_context.sendBroadcast(poke);
}

}

C)Last, You find  how to Automatically Turn Off GPS Connection.:-

  public void turnGPSOff() {
String provider = Settings.Secure.getString(
_context.getContentResolver(),
Settings.Secure.LOCATION_PROVIDERS_ALLOWED);

if (provider.contains("gps")) { // if gps is enabled
final Intent poke = new Intent();
poke.setClassName("com.android.settings",
"com.android.settings.widget.SettingsAppWidgetProvider");
poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
poke.setData(Uri.parse("3"));
_context.sendBroadcast(poke);
}
}

For download File....Click Here

Download this file,Copy it into your project and just call this above method..it works..

Thanks..

Read full post »

Monday, 18 February 2013

How To Use Various Font(like Marathi) In Your App

8 comments
Android doesn't support various fonts like Marathi so this tutorial gives you idea about how to use various font like Marathi in your app.So you can display your data in various languages using the font combination in your app.

Step1)First you have to download the .ttf file like (akshar.ttf for marathi font) which will be used for converting your text according to this font.

Step2)After Downloading this file,You have to copy this file and paste in your asset folder.

Step3)Suppose you take a text view to display to your data which is stored in your string.xml,then you have to write this following code for displaying this data with this font format.

           a)  TextView  t1 = (TextView) findViewById(R.id.t1); 

           b)  Typeface tf = Typeface.createFromAsset(getAssets(), "akshar.ttf");
                  t1.setTypeface(tf, Typeface.BOLD);


 Step4)Next,You have to write this following in your XML.   
       
                  <TextView
                    android:id="@+id/t1"
                   android:layout_width="fill_parent"
                   android:layout_height="fill_parent"
                   android:text="@string/sindhu"
                   android:textColor="#000000"
                   android:textSize="6pt" />


Step5)Then you write you string.xml with the following.
              
             <string name="sindhu">सिंधुदुर्ग जिल्हा हा १५.३७ आणि १६.४० उत्तर अक्षवृत्त व ७३.१९ आणि     ७४.१८  पूर्व रेखावृत्त या दरम्यान वसलेला आहे. 

Thank u....
 
Read full post »

Wednesday, 13 February 2013

Code To Start Camera with Build-in Intent

0 comments
This code will show you how to start camera using intent and save the image to the file name.

Step1)Private constants & variable uses in the class:

 private static int TAKE_PIC = 1;
 private Uri FileUri;
 
Step2)Once the code is run, the camera pops up, just take your photo, and click on “Done” button on the screen. That would close the camera app and returns to your own App.
          
  private void ClickPhoto() {
  Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  File file = new File(Environment.getExternalStorageDirectory(), "img1.jpg");
 
  FileUri = Uri.fromFile(file);
  intent.putExtra(MediaStore.EXTRA_OUTPUT, FileUri);
  startActivityForResult(intent, TAKE_PICTURE);
 
}

Step3)You need to override the onActivityResult to handle when the camera returns to your app:
                         
 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data){
 
  if (requestCode == TAKE_PIC){
   //do whatever you want
  }
 
 }

 Thank U....
Read full post »

Sunday, 10 February 2013

How To Add Spinner dynamically on AlertDialog-Box

0 comments
Sometimes you face the problem regarding adding spinner on AlertdialogBox.So dont worry I give
the solution here:

Step1)Create a method name ViewDemo() and call it in your onCreate() method.

Setp2)Then Add this following

    AlertDialog.Builder Dialog = new AlertDialog.Builder(this);
    Dialog.setTitle("Select Option");

     LayoutInflater li = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
     View dialogView = li.inflate(R.layout.option, null);
     Dialog.setView(dialogView);

      Dialog.setPositiveButton("Ok",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                    }
                });

      Dialog.setNegativeButton("Cancel",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                    }
                });
        Dialog.show();
        Spinner spinnercategory = (Spinner) dialogView
                .findViewById(R.id.viewSpin);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
                this, R.array.category, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinnercategory.setAdapter(adapter);

        spinnercategory.setOnItemSelectedListener(new OnItemSelectedListener() {

            public void onItemSelected(AdapterView<?> parent, View arg1,
                    int arg2, long arg3) {
                //String selItem = parent.getSelectedItem().toString();
            }

            public void onNothingSelected(AdapterView<?> arg0) {
                // TODO Auto-generated method stub
            }
        });

    }

Step3)Then Write the xml file option.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:paddingLeft="10dip" >

    <Spinner
        android:id="@+id/viewSpin"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:prompt="@array/category" />

</LinearLayout>

Step4)At last You create an array of option in val/array.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="category">
        <item>A +VE</item>
        <item>A -VE</item>
        <item>B +VE</item>
        <item>B -VE</item>
        <item>O +VE</item>
        <item>O -VE</item>
         <item>AB +VE</item>
        <item>AB -VE</item>
       
        </string-array>
</resources>

For Download Source Click Here

    Thanks..
Read full post »

Saturday, 9 February 2013

How To Add Tabs In Android

0 comments
 This tutorial is based on adding tabs in your activity in android.Also you give background
  image to your tabs.So follows the step:

Step1) First you add the following code in your Xml file,This will have three basic components
                             a)Tab-Host     b)Frame-layout     c)Tab-widget

        tab_layout.xml

        <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:orientation="vertical"
        android:layout_weight="1">

        <TabHost
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@android:id/tabhost"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical" >

                <FrameLayout
                    android:id="@android:id/tabcontent"
                    android:layout_width="fill_parent"
                    android:layout_height="0dip"
                    android:layout_gravity="center_vertical"
                    android:layout_weight="1"
                    android:editable="false"
                    android:textSize="10sp" />

                <TabWidget
                    android:id="@android:id/tabs"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />
            </LinearLayout>
        </TabHost>
    </LinearLayout>         

 Step2)          
                  Then coming to the Java file you add the following code: 

          TabDemo.class 

        a)  Tabhost tabHost = (TabHost)findViewById(android.R.id.tabhost);

        b) Add the tabspec to your Tabhost

             TabSpec firstTabSpec = tabHost.newTabSpec("Type1");
             TabSpec secndTabSpec = tabHost.newTabSpec("Type2");


        c)Set the action for the tabspec and background image for spec.
        
             
//Type1
              Intent i1=new Intent(ClassActivity.this,Type1Activity.class);
              firstTabSpec.setIndicator("",getResources().getDrawable(R.drawable.type1)).setContent(i1);
          
              //Type2
              Intent i2=new Intent(ClassActivity.this,Type2Activity.class);
              secndTabSpec.setIndicator("",getResources().getDrawable(R.drawable.type2)).setContent(i2);

                    
         d)Add the tab to the tabhost.
 
            
  tabHost.addTab(firstTabSpec);
               tabHost.addTab(secondTabSpec);




   Thnks...
          

   
Read full post »

Friday, 8 February 2013

How to add view dynamically on AlertDialogBox

3 comments
 This tutorial relates to the adding view(such as text view,edit-text,etc) to the Alert dialog
 dynamically in a java code.This will be used for creating the log in screen with Alert dialog.

Step1)First,create the object of the Alert Dialog builder as follows:

              AlertDialog.Builder alert = new AlertDialog.Builder(this);
              alert.setTitle("Login Screen");

Step2) After you create object of the views you want and add properties to them with following:
 
             LinearLayout lila1 = new LinearLayout(this);
             lila1.setOrientation(1);
             TextView t1 = new TextView(this);
             TextView t2 = new TextView(this);
             t1.setText("Enter your Login ID:");
             t1.setTextColor(Color.parseColor("#FFFFFF"));
             input1 = new EditText(this);
             t2.setText("Enter your Password:");
             t2.setTextColor(Color.parseColor("#FFFFFF"));
             input2 = new EditText(this);
             input2.setInputType(0x00000081);

Step3)Then,you add the view and set the view with the following:

             lila1.addView(t1);
             lila1.addView(input1);
             lila1.addView(t2);
             lila1.addView(input2);
             alert.setView(lila1);

Step4) Last,To add the buttons to the alert dialog you do the following:

              alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int whichButton) {

               }
              });

              alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int whichButton) {
                    
                }
                });

 Step5)    
                alert.show();

Thanks..

                  
            
Read full post »

Creating a dynamic row in TableLayout..

4 comments

All of you know to add a no.of rows in Table-layout by using XML.but here i will provide you the
guideline for generating rows dynamically in your android code.


Step:1)First of all you add Table-layout in your XML file.like following

         <TableLayout
                       android:id="@+id/tbl_product"
                       android:layout_width="fill_parent"
                      android:layout_height="wrap_content" >

        </TableLayout>


Step:2)Then u add the follwing code in your java file.


A) First,you set up the control for table layout.

         TableLayout prodlist = (Table Layout) findViewById(R.id.tbl_product);


B) Second,you will create a method name display(). in that u create a row using follwing:

        void display(String id, String name) {

        Table Row tr2 = new Table Row(this);
        tr2.layout(0, 0, 0, 0);


C) Third,you will create a two text view which will be added in that above row and set the argument value of display() method to that text view.


First text-view:


      TextView lblid = new TextView(this);
        lblid.setText("" + id);
        lblid.setTextColor(Color.BLACK);
        lblid.setTextSize((float) 11.5);
        lblid.setTypeface(null, 1);
        lblid.setBackgroundColor(Color.TRANSPARENT);
        lblid.setPadding(30, 0, 0, 0);


        tr2.setPadding(0, 1, 0, 0);
        tr2.addView(lblid);


Second text-view:


      TextView lblname = new TextView(this);
        lblname.setText("" + name);
        lblname.setTextColor(Color.BLACK);
        lblname.setTextSize((float) 11.5);
        lblname.setTypeface(null, 1);
        lblname.setBackgroundColor(Color.TRANSPARENT);
        lblname.setPadding(30, 0, 20, 0);
        tr2.setPadding(0, 1, 0, 1);
        tr2.addView(lblname);

 

Step:3)

Next most important thing is add the table row to the tableLayout by the following:


       prodlist.addView(tr2, new TableLayout.LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));



Thanks...
Read full post »

How to set up android developement environment

0 comments

 Here you can get step by step description of how to set up the android development  environment.

Basic Tools:
                  1)Windows machine(you also use mac/Linux)
                  2)Eclipse IDE for Java Developer(With ADT Plugins)
                  3)JDK(updated)
                  4)Android SDK
                
Step1)
                     First step you download ADT Bundle For Windows From here:

                     link: http://developer.android.com/sdk/index.html

                    With a single download, the ADT Bundle includes everything
                     you need to begin developing apps:
                      -Eclipse + ADT plugin
                      -Android SDK Tools
                      -Android Platform-tools
                      -The latest Android platform
                      -The latest Android system image for the emulator
Step2)
                    Next Step is double-Click On the SDK Manager.exe it automatically 
                    starts to download all packages includes emulators,google-api,etc
                    (from android1.6-onwords).

Step3)
                   Last Step is Launch the emulator and starts developing..

Thanks..
Read full post »
 

Copyright © Unique Android Tutorial.. Design by Free CSS Templates | Blogger Theme by BTDesigner | Powered by Blogger