Skip to content

Instantly share code, notes, and snippets.

View gvsharma's full-sized avatar
🎯
Focusing

GVSharma gvsharma

🎯
Focusing
View GitHub Profile
@gvsharma
gvsharma / XML Parser and ServiceResponce Listener
Last active August 29, 2015 14:01
A java class very useful for SAX parsing
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.StringReader;
import java.net.MalformedURLException;
import java.net.URL;
@gvsharma
gvsharma / Timer Task
Created May 26, 2014 11:18
code snippet to do a task repeatedly using timer in android
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
fetchallMessages(match_id,true);
@gvsharma
gvsharma / ViewPager inside a Fragment
Created May 26, 2014 11:31
ViewPager in Fragment to swipe items
In the Fragment :
TabsPagerAdapter mAdapter = new TabsPagerAdapter(getChildFragmentManager(),itemsList);
viewPager.setAdapter(mAdapter);
viewPager.setOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageSelected(int arg0) {
}
@gvsharma
gvsharma / JSON Service Handler
Last active April 12, 2018 07:25
android JSON service Handler
public class ServiceHandler {
static String response = null;
public final static int GET = 1;
public final static int POST = 2;
public ServiceHandler() {
}
@gvsharma
gvsharma / calculateInSampleSize method
Created June 5, 2014 05:16
upload an image to server(provided webservice) using POST,
public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
if (width > height) {
inSampleSize = Math.round((float) height / (float) reqHeight);
} else {
inSampleSize = Math.round((float) width / (float) reqWidth);
@gvsharma
gvsharma / download an image from server
Created June 5, 2014 05:21
dounloading an image from server and save it in file
Here arg[0] --> is the image url that we have to pass to this asynctask as parameter.
public class DownloadImage extends AsyncTask<String, Integer, Bitmap> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@gvsharma
gvsharma / dataIntoPdf method
Last active August 29, 2015 14:02
Generating pdf with qPDF(qoppa software) library(refer http://www.qoppa.com/android/pdfsdk/)
public void dataIntoPdf(int noOfLines, ArrayList<Info> bookInfosById, PDFCanvas canvasId){
try {
float x = 40f;
float y = 60f;
for (int j = 0; j < bookInfosById.size();j++) {
int z = j;
Info myInfos = bookInfosById.get(j);
if (z < noOfLines) {
for (int v = 0; v <= z; v++) {
if (z == v) {
@gvsharma
gvsharma / getTmepFile() method
Created June 5, 2014 05:49
getting an image from camera or gallery and set it as
private Uri getTempFile(){
File root = new File(Environment.getExternalStorageDirectory(), "fashion_swap");
if (!root.exists()){
root.mkdirs();
}
String filename=""+System.currentTimeMillis();
File file = new File(root,filename+".jpeg" );
Uri muri = Uri.fromFile(file);
selectedImagePath = muri.getPath();
Log.v("take picture path",selectedImagePath);
import java.io.UnsupportedEncodingException;
import java.util.Map;
import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;
import com.android.volley.AuthFailureError;
import com.android.volley.NetworkResponse;
import com.android.volley.ParseError;
import com.android.volley.Request;
public class BlurUtil {
public static Bitmap blur(Context context, Bitmap sentBitmap, int radius) {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
Bitmap bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);
final RenderScript rs = RenderScript.create(context);
final Allocation input = Allocation.createFromBitmap(rs, sentBitmap, Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT);