Thursday, December 4, 2014

Android Using custom progress Bar Horizontal


Source Code:
==========

Xml File:
========
 <Button
          android:id="@+id/button1"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_below="@+id/textView1"
          android:layout_marginTop="31dp"
          android:background="@drawable/button"
          android:onClick="startProgressDialog"
          android:text="Start Downloading File" />

Java file:
========

package com.example.customizedprogressbar;



import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;

public class MainActivity extends ActionBarActivity
{

                     ProgressDialog progressBar;
                     private int progressBarStatus = 0;
                     private Handler progressBarHandler = new Handler();
                     Button click_circle;
                     private long fileSize = 0;
 
                    @Override
                    public void onCreate(Bundle savedInstanceState)
                    {
                                super.onCreate(savedInstanceState);
                                setContentView(R.layout.activity_main);
                                click_circle = (Button)findViewById(R.id.button2);
                                click_circle.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent fadein = new Intent(MainActivity.this, CircleProgress.class);
startActivity(fadein);

}
});
                               
                     }

                    public void startProgressDialog(View V)
                  {
       

                 
           
                                  // prepare for a progress bar dialog
           
                                  progressBar = new ProgressDialog(V.getContext());
                                  progressBar.setCancelable(true);
                                  progressBar.show();
                                  progressBar.setMessage("Downloading File...");
                                  progressBar.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
                                  progressBar.setProgress(0);
                                  progressBar.setMax(100);
         
                                  // Get the Drawable custom_progressbar
                                 
                           
                                // Drawable customDrawable= getResources().getDrawable(R.drawable.progressbar2);
                         

                                  // set the drawable as progress drawable

                                  progressBar.setProgressDrawable(customDrawable);

                                  progressBar.show();

                                 //reset progress bar status
                                  progressBarStatus = 0;

                                 //reset filesize
                                  fileSize = 0;

                                  new Thread(new Runnable() {
                                  public void run() {
                                         while (progressBarStatus < 100) {

                                    // process some tasks
                                progressBarStatus = fileDownloadStatus();

                                //  sleep 1 second to show the progress
                                try {
                                        Thread.sleep(1000);
                                    }
                                catch (InterruptedException e) {
                                        e.printStackTrace();
                                    }

                                // Update the progress bar
                                progressBarHandler.post(new Runnable() {
                                    public void run() {
                                        progressBar.setProgress(progressBarStatus);
                                    }
                                });
                            }

                            // when, file is downloaded 100%,
                            if (progressBarStatus >= 100) {

                                // sleep for  2 seconds, so that you can see the 100% of file download
                                try {
                                    Thread.sleep(2000);
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                }

                                // close the progress bar dialog
                                progressBar.dismiss();
                             
                            }
                        }
                    }).start();

      }


     
//method returns the % of file downloaded
    public int fileDownloadStatus()
    {

        while (fileSize <= 10000000) {

            fileSize++;

            if (fileSize == 100000) {
                return 10;
            } else if (fileSize == 200000) {
                return 20;
            } else if (fileSize == 300000) {
                return 30;
            }
            else if (fileSize == 400000) {
                return 40;
            } else if (fileSize == 500000) {
                return 50;
            } else if (fileSize == 600000) {
                return 60;
            }
            else if (fileSize == 700000) {
                return 70;
            }
            else if (fileSize == 800000) {
                return 80;
            }
            else if (fileSize == 900000) {
                return 90;
            }
            else if (fileSize == 1000000) {
           
                return 100;
            }
         
            // write your code here

        }

        return 100;

    }
   
    /*protected void onProgressUpdate(Integer... progress) {
    progressBar.setProgress(progress[0]);
     
   }*/
}

Drawable file :
===========
this xml file include to  res folder

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:id="@android:id/background">
        <shape>
            <corners android:radius="5dip" />
            <gradient
                android:angle="270"
                android:centerColor="#ff5a5d5a"
                android:centerY="0.5"
                android:endColor="#ff747674"
                android:startColor="#ff9d9e9d" />
        </shape>
    </item>
    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <corners android:radius="5dip" />
                <gradient
                    android:angle="0"
                    android:endColor="#ff009900"
                    android:startColor="#ff000099" />
            </shape>
        </clip>
    </item>
</layer-list>


Screenshot:
============






Tuesday, December 2, 2014

Android animation using override pending transitions

Source code:
=========

Slide  right screen

==============

U can create two Activity:

Animation file:
=============

Note :  you can store to anim folder

Slide in right
=============

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >
    <translate android:duration="5000" android:fromXDelta="100%" android:toXDelta="0%" />
    <alpha android:duration="5000" android:fromAlpha="0.0" android:toAlpha="1.0" />
</set>

Slide Out right:
==============

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >
    <translate android:duration="5000" android:fromXDelta="0%" android:toXDelta="100%"/>
    <alpha android:duration="5000" android:fromAlpha="1.0" android:toAlpha="0.0" />
</set>

java file:
=======

Intent a = new Intent(MainActivity.this,
Pushupin.class);
startActivity(a);
overridePendingTransition(R.anim.slideinright, R.anim.slideoutright);


Screenshot:
============
screen one:

screen change progress:




Monday, December 1, 2014

Android using text binking with color interval

Android  using text blinking  and color change for every 20 mins......using timetcount

source code:

xml file:

<TextView
        android:id="@+id/textview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world" />


java file:

package com.example.blinking;

import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.TextView;

public class MainActivity extends ActionBarActivity {
TextView text;
Animation animBlink;
private static final int RED = 0xffFF8080;
private static final int BLUE = 0xff8080FF;

private CountDownTimer countDownTimer;
private final long startTime = 30 * 1000;
private final long interval = 1 * 1000;

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

text = (TextView) findViewById(R.id.textview);


countDownTimer = new MyCountDownTimer(startTime, interval);
countDownTimer.start();
Log.d("timecounter", ""+String.valueOf(startTime / 1000));

Animation anim = new AlphaAnimation(0.0f, 1.0f);
anim.setDuration(50); // You can manage the blinking time with this//
// parameter
anim.setStartOffset(20);
anim.setRepeatMode(Animation.REVERSE);
anim.setRepeatCount(Animation.INFINITE);
text.startAnimation(anim);
text.setTextColor(RED);


}

public class MyCountDownTimer extends CountDownTimer {

public MyCountDownTimer(long startTime, long interval) {

super(startTime, interval);

}

@Override
public void onFinish() {

//text.setText("Time's up!");
text.setTextColor(RED);
countDownTimer.cancel();
countDownTimer.start();
}

@Override
public void onTick(long millisUntilFinished) {

//text.setText("" + millisUntilFinished / 1000);

long tir =millisUntilFinished / 1000;
if(tir <=20)
{
text.setTextColor(BLUE);
}
}

}


}







Tuesday, August 5, 2014

android using images store to sdcard

Android using image store to sdcard
============================

image convert to bitmap

private void SaveImage(Bitmap finalBitmap) {


    String root = Environment.getExternalStorageDirectory().toString();
    File myDir = new File(root + "/coupon");  
    myDir.mkdirs();
    Random generator = new Random();
    int n = 10000;
    n = generator.nextInt(n);
    String fname = "image"+".jpg";
    File file = new File (myDir, fname);
    if (file.exists ()) file.delete ();
    try {
           FileOutputStream out = new FileOutputStream(file);
           finalBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
           out.flush();
           out.close();

    } catch (Exception e) {
           e.printStackTrace();
           Toast.makeText(Mycoupon_detail.this, "SAVE IMAGE FAIL", Toast.LENGTH_LONG).show();
    }
}

Monday, August 4, 2014

Android camera using autofocus

Android Camera using autofocus using surfaceview
=======================================
 AutoFocusCallback myAutoFocusCallback = new AutoFocusCallback(){

 @Override
 public void onAutoFocus(boolean success, Camera arg1) {
  // TODO Auto-generated method stub
//  buttonTakePicture.setEnabled(true);
 Camera.Parameters params = camera.getParameters();
       if (params.isAutoExposureLockSupported()) {
           params.setAutoExposureLock(true);
           camera.setParameters(params);
           Log.d("isAutoExposureLockSupported", "true");
           camera.setParameters(params);
          
       }
 Log.d("autofocus", "data"+success);
 Log.d("autofocus camera", "cam"+arg1);
 
          //   success = true;
             return;

 }};  

android camera using flash on and flash off controls

Camera funcationality using flash on and flash off
=======================================
                        Camera.Parameters p= camera.getParameters();
                          if (Constants.on_flash == true) {
  toggleButton.setChecked(true);
   Log.i("info", "torch is turn on!");
   p.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
   camera.setParameters(p);
   camera.startPreview();
  } else {
   Log.i("info", "torch is turn off!");
   p.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
   camera.setParameters(p);
   camera.startPreview();

  }

camera using zoomin-zoomout

Android camera funcationality using Zoomin / Zoomout
======================================

Exampple code:

final Parameters p = camera.getParameters();
   final int maxZoomLevel = p.getMaxZoom();
if (p.isZoomSupported()) {
       //final int maxZoomLevel = p.getMaxZoom();
       Log.i("max ZOOM ", "is " + maxZoomLevel);
       zoomControls.setIsZoomInEnabled(true);
       zoomControls.setIsZoomOutEnabled(true);
       
       zoomControls.setOnZoomInClickListener(new OnClickListener(){
           public void onClick(View v){
            //int currentZoomLevel = 0;
               if(Constants.currentzoom < maxZoomLevel){
                Constants.currentzoom++;
                   Log.i("max ZOOM in ", "in " + Constants.currentzoom);
                  // Constants.currentzoom= currentZoomLevel;
                   p.setZoom(Constants.currentzoom);
                   camera.startSmoothZoom(Constants.currentzoom);
                   camera.setParameters(p);
                                }
           }
       });

       zoomControls.setOnZoomOutClickListener(new OnClickListener(){
           public void onClick(View v){
            camera.autoFocus(myAutoFocusCallback);
           // int currentZoomLevel = 0;
               if(Constants.currentzoom > 0){
                Constants.currentzoom--;
                   Log.i("max ZOOM in ", "out " + Constants.currentzoom);
                   p.setZoom(Constants.currentzoom);
                   camera.startSmoothZoom(Constants.currentzoom);
                   camera.autoFocus(myAutoFocusCallback);
                   camera.setParameters(p);
                   camera.startPreview();
               }
           }
       });    
   }

Thursday, June 19, 2014

Android using intent based get MapDirection


Android using intent based get MapDirection :





Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
Uri.parse("http://maps.google.com/maps?saddr="+my_lat+","+my_long+"&daddr="+13.0820617+","+ 80.2755867));
startActivity(intent);

android using latlong based get zipcode

Latlong based get zipcode
======================


new asynctask_zipcode(Activity name.this).execute();


public class asynctask_zipcode extends AsyncTask<Void, Integer, Void> {
public asynctask_zipcode(Activity activity) {
context = activity;
}

private Context context;

@Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
XPath xpath = XPathFactory.newInstance().newXPath();
          String expression = "//GeocodeResponse/result/address_component[type=\"postal_code\"]/long_name/text()";
          InputSource inputSource = new InputSource("https://maps.googleapis.com/maps/api/geocode/xml?latlng="+"latStr" +","+ "longStr" +"&sensor=true");
         
try {
zipcode = (String) xpath.evaluate(expression, inputSource, XPathConstants.STRING);
} catch (XPathExpressionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}

@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
Toast.makeText(context, zipcode, 1000).show();
}

}

Thursday, May 15, 2014

Android using sharing data and images in all social networks.

Android  using sharing data and images  in all social networks.


shareBtn.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {

//Toast.makeText(getApplicationContext(),Declarations.coupon_imgbg, 1000).show();
String text = "data_text";
String sub = "data_subject";
// String text = "See our Coupons on Qcrazy for<a href="+Declarations.share_store_website+">"+Declarations.share_store_title+"</a> For more coupons Download FREE"+"<a href=http://www.qcrazy.com/download-qcrazy>"+"QCrazy App"+"</a>";
//String text = Declarations.coupon_desci;
Resources resources = getResources();
Intent emailIntent = new Intent();
emailIntent.setAction(Intent.ACTION_SEND);
//Native email client doesn't currently support HTML, but it
//doesn't hurt to try in case they fix it
emailIntent.putExtra(Intent.EXTRA_TEXT, text);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, sub);
emailIntent.setType("message/rfc822");
PackageManager pm = getPackageManager();
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("text/html");
sendIntent.setType("image/*");
Intent openInChooser = Intent.createChooser(emailIntent,"SHARE...");
List<ResolveInfo> resInfo = pm.queryIntentActivities(sendIntent, 0);
List<LabeledIntent> intentList = new ArrayList<LabeledIntent>();
for (int i = 0; i < resInfo.size(); i++) {
// Extract the label, append it, and repackage it in a
// LabeledIntent
ResolveInfo ri = resInfo.get(i);
String packageName = ri.activityInfo.packageName;

if (packageName.contains("android.email")) {
emailIntent.setPackage(packageName);
} else if (packageName.contains("twitter")
|| packageName.contains("facebook")
|| packageName.contains("mms")
|| packageName.contains("android.gm")
|| packageName.contains("com.google.android.apps.plus")
|| packageName.contains("com.instagram.android")
|| packageName.contains("com.pinterest")) {
Intent intent = new Intent();
intent.setComponent(new ComponentName(packageName,ri.activityInfo.name));
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
if (packageName.contains("twitter")) {
intent.putExtra(Intent.EXTRA_TEXT,  text);
Uri screenshotUri = Uri.parse("file://" + "/storage/emulated/0/coupon/image.jpg");
intent.putExtra(Intent.EXTRA_STREAM,screenshotUri);
} else if (packageName.contains("facebook")) {
intent.putExtra(Intent.EXTRA_TEXT, text);
intent.setType("image/jpeg");
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, sub);
intent.putExtra(Intent.EXTRA_TITLE, text);
Uri screenshotUri = Uri.parse("file://" + "/storage/emulated/0/coupon/image.jpg");
intent.putExtra(Intent.EXTRA_STREAM,screenshotUri);
} else if (packageName.contains("mms")) {
intent.putExtra(Intent.EXTRA_TEXT,  text);
Uri screenshotUri = Uri.parse("file://" + "/storage/emulated/0/coupon/image.jpg");
intent.putExtra(Intent.EXTRA_STREAM,screenshotUri);
} else if (packageName.contains("android.gm")) {
intent.putExtra(Intent.EXTRA_TEXT,text);
intent.putExtra(Intent.EXTRA_SUBJECT, sub);
Uri screenshotUri = Uri.parse("file://" + "/storage/emulated/0/coupon/image.jpg");
intent.putExtra(Intent.EXTRA_STREAM,screenshotUri);
intent.setType("message/rfc822");
} else if (packageName.contains("com.google.android.apps.plus")) {
Uri screenshotUri = Uri.parse("file://" + "/storage/emulated/0/coupon/image.jpg");
intent.putExtra(Intent.EXTRA_TEXT,  text);
intent.putExtra(Intent.EXTRA_SUBJECT, sub);
intent.putExtra(Intent.EXTRA_STREAM,screenshotUri);
intent.setType("text/plain");
} else if (packageName.contains("com.instagram.android")) {
Uri screenshotUri = Uri.parse("file://" + "/storage/emulated/0/coupon/image.jpg");
screenshotUri = Uri.parse("file://" + "/storage/emulated/0/coupon/image.jpg");
intent.setType("image/*");
intent.setPackage("com.instagram.android");
intent.putExtra(Intent.EXTRA_STREAM,screenshotUri);
intent.putExtra(Intent.EXTRA_TEXT,text);
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, sub);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

} else if (packageName.contains("com.pinterest")) {
Uri screenshotUri = Uri.parse("file://" + "/storage/emulated/0/coupon/image.jpg");
//Uri screenshotUri = Uri.parse("android.resource://com.coupon.qcrazy/drawable/appicon");
intent.setType("image/*");
intent.setPackage("com.pinterest");
intent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
intent.putExtra(Intent.EXTRA_TEXT, text);
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, sub);
intent.addFlags(Intent.FLAG
_GRANT_READ_URI_PERMISSION);

}
intentList.add(new LabeledIntent(intent, packageName,
ri.loadLabel(pm), ri.icon));
}
}

// convert intentList to array
LabeledIntent[] extraIntents = intentList.toArray(new LabeledIntent[intentList.size()]);
openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS,extraIntents);
startActivity(openInChooser);
}

});