Thursday, 9 May 2013

Transition Drawable In Android


MainActivity.java

 public class MainActivity extends Activity {

private ImageView image;
private TransitionDrawable trans;

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

    image = (ImageView) findViewById(R.id.image);
    Resources res = this.getResources();
    trans = (TransitionDrawable) res.getDrawable(R.drawable.transition);

    image.setOnClickListener(new OnClickListener() 
    {
        @Override
        public void onClick(View v) {
            image.setImageDrawable(trans);
            trans.reverseTransition(1000);
        }
    });
}  }



activity_main.xml
<LinearLayout 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"
    android:orientation="vertical"
    tools:context=".MainActivity" >
    
    <ImageView
        android:id="@+id/image"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/ic_launcher"
        />
    
</LinearLayout>
transition.xml
<?xml version="1.0" encoding="utf-8"?>
<transition xmlns:android="http://schemas.android.com/apk/res/android" >

    <item android:drawable="@drawable/ic_launcher"/>
    <item android:drawable="@drawable/hair_advice"/>

</transition>

Wednesday, 8 May 2013

How to Make a Directory in SDCARD


public String getFilename() {

    filepath = Environment.getExternalStorageDirectory().getPath();

    file = new File(filepath, "Hair");

    if (!file.exists()) {
        file.mkdirs();
    }

        return (file.getAbsolutePath() + "/"
            + String.valueOf(System.currentTimeMillis()) + ".png");
}

How to make global Class


public class AppConfig {

Context context;

public AppConfig(Context mxt) {

    context = mxt;
}

public static String filepath = null;
public static String imageupload = null;

public static Bitmap abjustbitmap = null;
}
other activity to use
AppConfig config;
Context context;
in oncreate method
    context = getApplicationContext();
    config = new AppConfig(context);

Tapping form field in WebView and open soft keyboard


webview.requestFocus(View.FOCUS_DOWN);
    webview.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                case MotionEvent.ACTION_UP:
                    if (!v.hasFocus()) {
                        v.requestFocus();
                    }
                    break;
            }
            return false;
        }
    });

Map in android

These are the important link for using map in android.

Display current location on Google Map:

http://wptrafficanalyzer.in/blog/showing-current-location-in-google-maps-with-gps-and-locationmanager-in-android/

http://www.androidhive.info/2012/01/android-working-with-google-maps/ 

http://android-er.blogspot.in/2009/11/display-marker-on-mapview-using.html 

http://android-codes-examples.blogspot.in/2011/04/google-map-example-in-android-with-info.html 

http://android-er.blogspot.in/2012/06/add-mylocationoverlay-on-openstreetmap.html 

http://android-er.blogspot.in/2012/05/create-multi-marker-openstreetmap-for.html 

Map with Map overlay: 
http://androidcodesnips.blogspot.in/2011/08/gooogle-maps-for-android.html 
http://android-coding.blogspot.in/2011/08/detect-touch-on-marker-in-mapview.html 

Route Map in Android: 

Uri uri = Uri.parse("http://maps.google.com/maps?&saddr=slat,slon&daddr=dlat,dlon"); 

Here saddr -> source address 
daddr -> destination address 
slat -> source latitude 
slon -> source longitude 
dlat -> destination latitude 
dlon -> destination longitude 
Intent intent = new Intent(Intent.ACTION_VIEW, uri); 
startActivity(intent); 

Google MapV2:
http://ramsandroid4all.blogspot.in/2013/03/google-maps-android-api-v2.html

I will be happy if you will provide your feedback or follow this blog. Any suggestion and help will be appreciated.

Thank you :)