Pages

Thursday 24 May 2012

oDesk Profile View

Future date should not set in DatePicker dialog in android.

            int y = Integer.parseInt(String.valueOf(year));
            int m = Integer.parseInt(String.valueOf(monthOfYear+1));
            int d = Integer.parseInt(String.valueOf(dayOfMonth));
            if(y > currentYear)
            {
                Toast.makeText(SleepView.this, "Please select proper date.", Toast.LENGTH_LONG).show();
            }
            else if(m > currentMonth && y == currentYear)
            {
                Toast.makeText(SleepView.this, "Please select proper date.", Toast.LENGTH_LONG).show();
            }
            else if(d > currentDay && y == currentYear&& m == currentMonth)
            {
                Toast.makeText(SleepView.this, "Please select proper date.", Toast.LENGTH_LONG).show();
            }

Upload image on server in android.

class ImageUploadTask extends AsyncTask<Void, Void, String> {
        @Override
        protected String doInBackground(Void... unsued) {
   
            Looper.prepare();

                String pathToOurFile = getImagePath;
                String urlServer ="your url";
                String boundary =  "*****";
               

                try
                {
               
               
                    HttpClient httpClient = new DefaultHttpClient();
                    HttpContext localContext = new BasicHttpContext();
                    HttpPost httpPost = new HttpPost(urlServer);


                    MultipartEntity entittyy=new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
                    Bitmap bit=bitmap;
                   
                    ByteArrayOutputStream bos = new ByteArrayOutputStream();
                    bit.compress(CompressFormat.JPEG, 100, bos);
                    byte[] data = bos.toByteArray();
                   
                    //entity.addPart("returnformat", new StringBody("json"));
                    String name=String.valueOf(System.currentTimeMillis());
                    entittyy.addPart("filedata", new ByteArrayBody(data,name+".jpg"));
                    //entity.addPart("photoCaption", new StringBody(caption.getText().toString()));
                    httpPost.setEntity(entittyy);
                    HttpResponse response = httpClient.execute(httpPost,
                            localContext);
                    BufferedReader reader = new BufferedReader(
                            new InputStreamReader(
                                    response.getEntity().getContent(), "UTF-8"));

                    String sResponse = reader.readLine();
                    Log.e("RRRRRR","Response sent---"+sResponse);
                    return sResponse;
                   
                   
                }
                catch (Exception ex)
                {
                    Log.e("--------------","end exception"+ex);
                  
                }
               
              return null;
        }

        @Override
        protected void onProgressUpdate(Void... unsued) {

        }

        @Override
        protected void onPostExecute(String sResponse) {
            try {
                if (dialog.isShowing())
                    dialog.dismiss();
                   
               
            } catch (Exception e) {
                Toast.makeText(getApplicationContext(),
                        e.getMessage(),
                        Toast.LENGTH_LONG).show();
                Log.e(e.getClass().getName(), e.getMessage(), e);
            }
        }
    }