Pages

Thursday 15 December 2011

Gradient Look For View in android

<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient  android:startColor="#C0C0C0"
   android:endColor="#505050"
            android:angle="90"/>  
   <corners android:radius="2px" />
</shape>
 
By:
Yours 
V.K.Hooda 

Wednesday 14 December 2011

Yesterday Date in Android


        Calendar cal = Calendar.getInstance();
        SimpleDateFormat dateFormatyes = new SimpleDateFormat("dd/MM/yyyy");
        cal.add(Calendar.DATE, -1);
        String yesterdaydate = dateFormatyes.format(cal.getTime());

        Log.e("Date", "Yesterday Date was :" + yesterdaydate);

By:
Yours
V.k.Hooda

Current Date and Time in Android


// Today Date Format:Two Methods
Method 1.

        long msTime = System.currentTimeMillis();
        Date todayformat = new Date(msTime);
        Log.e("Date", "Current Date is :" + todayformat);

        Time todaydate = new Time();
        Log.e("Date", "Current Time with zone is :" + timenow);

        String timenow = todaydate.format2445();
        Log.e("Date", "Current Time and zone is :" + todaydate);

Method 2.
        Calendar todaycal = Calendar.getInstance();
        SimpleDateFormat dateFormattoday = new SimpleDateFormat("dd/MM/yyyy");
        todaycal.add(Calendar.DATE, 0);// 1 for tommarow
        String caltodaydate = dateFormattoday.format(todaycal.getTime());
        Log.e("Date", "Method 2-Current Date  is :" + caltodaydate);

String currenttime = todaycal.get(Calendar.HOUR) + ":"
                + todaycal.get(Calendar.MINUTE) + ":"
                + todaycal.get(Calendar.SECOND);
        Log.e("Date", "Method 2-Current Time  is :" + currenttime);By:
Yours
V.k.Hooda

Audio Streaming In Android

 Hope this will help you :-)

public class ListenAudio extends Activity {
   

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        Intent in = getIntent();
        String path = in.getStringExtra("Path");
      
        MediaPlayer mediaPlayer = new MediaPlayer();
        mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        try {
            mediaPlayer.setDataSource(path);
        } catch (IllegalArgumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        try {
            mediaPlayer.prepare();
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } // might take long! (for buffering, etc)
        mediaPlayer.start();
      
            }
}
By:
Yours
V.K.Hooda

Video Streaming In Android

 Hope this will help you...:-)

public class WatchVideo extends Activity {
    VideoView mVideoView;
    String TAG = "Vikram_Hooda_Blogs";
    String current = "";
    String mPath="";
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.watchvideo);
        mVideoView = (VideoView) findViewById(R.id.video_view);
        Intent in = getIntent();
        String path = in.getStringExtra("path");
        playVideo(path);
    }
   
     private void playVideo(String path)
     {
                     try {  
                    
                         Log.v(TAG, "path: " + path);
                         if (path == null || path.length() == 0) {
                             Toast.makeText(WatchVideo.this, "File URL/path is empty",
                                     Toast.LENGTH_LONG).show();
            
                         } else {
                             // If the path has not changed, just start the media player
                             if (path.equals(current) && mVideoView != null) {
                                 mVideoView.start();
                                 mVideoView.requestFocus();
                                 return;
                             }
                             current = path;
                            
                             mVideoView.setVideoPath(getDataSource(path));
                             mVideoView.start();
                             mVideoView.requestFocus();
                            
            
                         }
                    } catch (Exception e) {
                     Log.e(TAG, "error: " + e.getMessage(), e);
                         if (mVideoView != null) {
                             mVideoView.stopPlayback();
                         }
                     }
                 }
           
                 private String getDataSource(String path) throws IOException {
                     if (!URLUtil.isNetworkUrl(path)) {
                         return path;
                     } else {
                         URL url = new URL(path);
                         URLConnection cn = url.openConnection();
                         cn.connect();
                         InputStream stream = cn.getInputStream();
                         if (stream == null)
                             throw new RuntimeException("stream is null");
                         File temp = File.createTempFile("mediaplayertmp", "dat");
                         temp.deleteOnExit();  
                         String tempPath = temp.getAbsolutePath();
                         FileOutputStream out = new FileOutputStream(temp);
                         byte buf[] = new byte[128];
                         do {
                             int numread = stream.read(buf);
                             if (numread <= 0)
                                 break;
                             out.write(buf, 0, numread);
                         } while (true);
                         try {
                             stream.close();
                         } catch (IOException ex) {
                         Log.e(TAG, "error: " + ex.getMessage(), ex);
                     }
                    return tempPath;
                 }
                 }
}








By:
Yours
V.K.Hooda