Friday, 19 December 2014
Thursday, 27 November 2014
Wednesday, 26 November 2014
How to push a project into git ?
For windows:
Install Git in your os
after installing the git go for search...
search gitbash..
open the gitbash...
so it is opened like command prompt
type
cd where is your project
ex: if u r project is in e drive:
Step 1:
cd /e
Step 2: cd typeyourprojectname/
Step3:git init
we are creating initialising the project to the git
observe in our project there is a folder with the name
.git
Step4:
git add*
add the all files to the git
step4:git status
check for the git status all files are added or not
step5:git commit -am "firstcommit"
Login to the git account in web with u r account:
create new repository:
How to push project to the globally:
and paste in u r commansd prompt :
git clone "your http url " and enter
git push origin master
asking for username :enter ur github username
asking for password: enter your github password.
you find the some thing htttp:url just copy that
Folow the link :
http://befused.com/git/existing-project-github
Create a branch in gitHub:
https://www.atlassian.com/git/tutorials/using-branches
Install Git in your os
after installing the git go for search...
search gitbash..
open the gitbash...
so it is opened like command prompt
type
cd where is your project
ex: if u r project is in e drive:
Step 1:
cd /e
Step 2: cd typeyourprojectname/
Step3:git init
we are creating initialising the project to the git
observe in our project there is a folder with the name
.git
Step4:
git add*
add the all files to the git
step4:git status
check for the git status all files are added or not
step5:git commit -am "firstcommit"
Login to the git account in web with u r account:
create new repository:
How to push project to the globally:
and paste in u r commansd prompt :
git clone "your http url " and enter
$ git remote add origin https://github.com/yourname/my_project.git
git push origin master
asking for username :enter ur github username
asking for password: enter your github password.
you find the some thing htttp:url just copy that
Folow the link :
http://befused.com/git/existing-project-github
Create a branch in gitHub:
https://www.atlassian.com/git/tutorials/using-branches
Thursday, 20 November 2014
How to run the android app with out usb cable ?
See here: http://forum.xda-developers.com/showpost.php?p=7594419&postcount=9
- Connect device via USB and make sure debugging is working.
adb tcpip 5555
adb connect <DEVICE_IP_ADDRESS>:5555
- Disconnect USB and proceed with wireless debugging.
adb -s <DEVICE_IP_ADDRESS>:5555 usb
to switch back when done.
No root required!
To find the IP address of the device: run
./adb shell
and then netcfg
. You'll see it there.Wednesday, 22 October 2014
how to sort data in array list in android ?
public class MainActivity extends Activity {
ArrayList<String> array_list;
SortAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView list = (ListView) findViewById(R.id.listView1);
array_list = new ArrayList<String>();
array_list.add("jhsghd");
array_list.add("kisghd");
array_list.add("ajhsghd");
array_list.add("abjhsghd");
array_list.add("bjhsghd");
array_list.add("cjhsghd");
array_list.add("djhsghd");
array_list.add("ejhsghd");
array_list.add("fjhsghd");
array_list.add("gjhsghd");
array_list.add("hjhsghd");
array_list.add("ijhsghd");
Collections.sort(array_list, StringDescComparator);
adapter = new SortAdapter(array_list);
list.setAdapter(adapter);
}
public static Comparator<String> StringAscComparator = new Comparator<String>() {
public int compare(String app1, String app2) {
String stringName1 = app1;
String stringName2 = app2;
return stringName1.compareToIgnoreCase(stringName2);
}
};
//Comparator for Descending Order
public static Comparator<String> StringDescComparator = new Comparator<String>() {
public int compare(String app1, String app2) {
String stringName1 = app1;
String stringName2 = app2;
return stringName2.compareToIgnoreCase(stringName1);
}
};
class SortAdapter extends BaseAdapter {
ArrayList<String> arraydata;
LayoutInflater inflater;
ViewHolder holder;
public SortAdapter(ArrayList<String> arraylist) {
arraydata = arraylist;
inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return arraydata.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
class ViewHolder {
TextView text;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
holder = new ViewHolder();
convertView = inflater.inflate(R.layout.attach, null);
holder.text = (TextView) convertView
.findViewById(R.id.textView1);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.text.setText(arraydata.get(position));
return convertView;
}
}
}
ArrayList<String> array_list;
SortAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView list = (ListView) findViewById(R.id.listView1);
array_list = new ArrayList<String>();
array_list.add("jhsghd");
array_list.add("kisghd");
array_list.add("ajhsghd");
array_list.add("abjhsghd");
array_list.add("bjhsghd");
array_list.add("cjhsghd");
array_list.add("djhsghd");
array_list.add("ejhsghd");
array_list.add("fjhsghd");
array_list.add("gjhsghd");
array_list.add("hjhsghd");
array_list.add("ijhsghd");
Collections.sort(array_list, StringDescComparator);
adapter = new SortAdapter(array_list);
list.setAdapter(adapter);
}
public static Comparator<String> StringAscComparator = new Comparator<String>() {
public int compare(String app1, String app2) {
String stringName1 = app1;
String stringName2 = app2;
return stringName1.compareToIgnoreCase(stringName2);
}
};
//Comparator for Descending Order
public static Comparator<String> StringDescComparator = new Comparator<String>() {
public int compare(String app1, String app2) {
String stringName1 = app1;
String stringName2 = app2;
return stringName2.compareToIgnoreCase(stringName1);
}
};
class SortAdapter extends BaseAdapter {
ArrayList<String> arraydata;
LayoutInflater inflater;
ViewHolder holder;
public SortAdapter(ArrayList<String> arraylist) {
arraydata = arraylist;
inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return arraydata.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
class ViewHolder {
TextView text;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
holder = new ViewHolder();
convertView = inflater.inflate(R.layout.attach, null);
holder.text = (TextView) convertView
.findViewById(R.id.textView1);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.text.setText(arraydata.get(position));
return convertView;
}
}
}
Paypal integration in android ?
Just refer the following link ?
http://www.androidhub4you.com/2014/07/android-paypal-gateway-example-paypal.html
http://www.androidhub4you.com/2014/07/android-paypal-gateway-example-paypal.html
Thursday, 16 October 2014
scroll up and down animation in android ?
Scroll-down
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromYDelta="-100%" android:toYDelta="0%" android:duration="1000"/>
</set>
Scroll-up
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromYDelta="0%" android:toYDelta="-100%" android:duration="500"/>
</set>
call them:
relatv.setOnTouchListener(new OnTouchListener () {
public boolean onTouch(View view, MotionEvent event) {
if (event.getAction() == android.view.MotionEvent.ACTION_DOWN) {
Animation slide = AnimationUtils.loadAnimation(
getApplicationContext(), R.anim.scrollup);
button.startAnimation(slide);
button.setVisibility(View.GONE);
} else if (event.getAction() == event.ACTION_UP) {
button.setVisibility(View.VISIBLE);
Animation slide1 = AnimationUtils.loadAnimation(
getApplicationContext(), R.anim.scrolldown);
button.startAnimation(slide1);
}
return false;
}
});
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromYDelta="-100%" android:toYDelta="0%" android:duration="1000"/>
</set>
Scroll-up
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromYDelta="0%" android:toYDelta="-100%" android:duration="500"/>
</set>
call them:
relatv.setOnTouchListener(new OnTouchListener () {
public boolean onTouch(View view, MotionEvent event) {
if (event.getAction() == android.view.MotionEvent.ACTION_DOWN) {
Animation slide = AnimationUtils.loadAnimation(
getApplicationContext(), R.anim.scrollup);
button.startAnimation(slide);
button.setVisibility(View.GONE);
} else if (event.getAction() == event.ACTION_UP) {
button.setVisibility(View.VISIBLE);
Animation slide1 = AnimationUtils.loadAnimation(
getApplicationContext(), R.anim.scrolldown);
button.startAnimation(slide1);
}
return false;
}
});
water drop animations /circular ripple animations in android ?
package com.example.samplebutton;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RadialGradient;
import android.graphics.Region;
import android.graphics.Shader;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.animation.AccelerateInterpolator;
import android.widget.Button;
import android.widget.RelativeLayout;
public class MainActivity extends Activity {
Button button;
RelativeLayout relatv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
relatv=(RelativeLayout)findViewById(R.id.relatv);
// button = (Button) findViewById(R.id.lll);
MyButton butto=new MyButton(MainActivity.this);
relatv.addView(butto);
}
// ///////////////////
public class MyButton extends Button {
private float mDownX;
private float mDownY;
private float mRadius;
private Paint mPaint;
public MyButton(final Context context) {
super(context);
init();
}
public MyButton(final Context context, final AttributeSet attrs) {
super(context, attrs);
init();
}
public MyButton(final Context context, final AttributeSet attrs,
final int defStyle) {
super(context, attrs, defStyle);
init();
}
private void init() {
mPaint = new Paint();
mPaint.setAlpha(100);
}
@Override
public boolean onTouchEvent(@NonNull final MotionEvent event) {
if (event.getActionMasked() == MotionEvent.ACTION_UP) {
mDownX = event.getX();
mDownY = event.getY();
ObjectAnimator animator = ObjectAnimator.ofFloat(this,
"radius", 0, getWidth() * 3.0f);
animator.setInterpolator(new AccelerateInterpolator());
animator.setDuration(400);
animator.start();
}
return super.onTouchEvent(event);
}
public void setRadius(final float radius) {
mRadius = radius;
if (mRadius > 0) {
RadialGradient radialGradient = new RadialGradient(mDownX,
mDownY, mRadius * 3, Color.TRANSPARENT, Color.BLACK,
Shader.TileMode.MIRROR);
mPaint.setShader(radialGradient);
}
invalidate();
}
private Path mPath = new Path();
private Path mPath2 = new Path();
@Override
protected void onDraw(@NonNull final Canvas canvas) {
super.onDraw(canvas);
mPath2.reset();
mPath2.addCircle(mDownX, mDownY, mRadius, Path.Direction.CW);
canvas.clipPath(mPath2);
mPath.reset();
mPath.addCircle(mDownX, mDownY, mRadius / 3, Path.Direction.CW);
canvas.clipPath(mPath, Region.Op.DIFFERENCE);
canvas.drawCircle(mDownX, mDownY, mRadius, mPaint);
}
}
// ///////////////////////
}
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RadialGradient;
import android.graphics.Region;
import android.graphics.Shader;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.animation.AccelerateInterpolator;
import android.widget.Button;
import android.widget.RelativeLayout;
public class MainActivity extends Activity {
Button button;
RelativeLayout relatv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
relatv=(RelativeLayout)findViewById(R.id.relatv);
// button = (Button) findViewById(R.id.lll);
MyButton butto=new MyButton(MainActivity.this);
relatv.addView(butto);
}
// ///////////////////
public class MyButton extends Button {
private float mDownX;
private float mDownY;
private float mRadius;
private Paint mPaint;
public MyButton(final Context context) {
super(context);
init();
}
public MyButton(final Context context, final AttributeSet attrs) {
super(context, attrs);
init();
}
public MyButton(final Context context, final AttributeSet attrs,
final int defStyle) {
super(context, attrs, defStyle);
init();
}
private void init() {
mPaint = new Paint();
mPaint.setAlpha(100);
}
@Override
public boolean onTouchEvent(@NonNull final MotionEvent event) {
if (event.getActionMasked() == MotionEvent.ACTION_UP) {
mDownX = event.getX();
mDownY = event.getY();
ObjectAnimator animator = ObjectAnimator.ofFloat(this,
"radius", 0, getWidth() * 3.0f);
animator.setInterpolator(new AccelerateInterpolator());
animator.setDuration(400);
animator.start();
}
return super.onTouchEvent(event);
}
public void setRadius(final float radius) {
mRadius = radius;
if (mRadius > 0) {
RadialGradient radialGradient = new RadialGradient(mDownX,
mDownY, mRadius * 3, Color.TRANSPARENT, Color.BLACK,
Shader.TileMode.MIRROR);
mPaint.setShader(radialGradient);
}
invalidate();
}
private Path mPath = new Path();
private Path mPath2 = new Path();
@Override
protected void onDraw(@NonNull final Canvas canvas) {
super.onDraw(canvas);
mPath2.reset();
mPath2.addCircle(mDownX, mDownY, mRadius, Path.Direction.CW);
canvas.clipPath(mPath2);
mPath.reset();
mPath.addCircle(mDownX, mDownY, mRadius / 3, Path.Direction.CW);
canvas.clipPath(mPath, Region.Op.DIFFERENCE);
canvas.drawCircle(mDownX, mDownY, mRadius, mPaint);
}
}
// ///////////////////////
}
Tuesday, 7 October 2014
how to use restful service calls in android ?
public static String doPost(Context ctx, String mUrl,
List<NameValuePair> nameValuePairs, String username, String password) {
HttpParams httpParameters = new BasicHttpParams();
int timeoutConnection = 20000;
HttpConnectionParams.setConnectionTimeout(httpParameters,
timeoutConnection);
int timeoutSocket = 20000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
DefaultHttpClient httpclient = new DefaultHttpClient(httpParameters);
String response_data = null;
HttpResponse response = null;
if (username != null && password != null) {
httpclient.getCredentialsProvider().setCredentials(
new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
new UsernamePasswordCredentials(username, password));
}
HttpPost postMethod = new HttpPost(mUrl);
try {
postMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs));
response = httpclient.execute(postMethod);
response_data = EntityUtils.toString(response.getEntity());
} catch (Exception e) {
}
return response_data;
}
}
List<NameValuePair> nameValuePairs, String username, String password) {
HttpParams httpParameters = new BasicHttpParams();
int timeoutConnection = 20000;
HttpConnectionParams.setConnectionTimeout(httpParameters,
timeoutConnection);
int timeoutSocket = 20000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
DefaultHttpClient httpclient = new DefaultHttpClient(httpParameters);
String response_data = null;
HttpResponse response = null;
if (username != null && password != null) {
httpclient.getCredentialsProvider().setCredentials(
new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
new UsernamePasswordCredentials(username, password));
}
HttpPost postMethod = new HttpPost(mUrl);
try {
postMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs));
response = httpclient.execute(postMethod);
response_data = EntityUtils.toString(response.getEntity());
} catch (Exception e) {
}
return response_data;
}
}
How to get the face book groups in android ?
public static String getFacebookGroupList(String token, Context context,
String fb_id) {
InputStream is = null;
String result = "";
try {
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(
"https://graph.facebook.com/"
+ fb_id
+ "/groups?access_token="
+ token);
HttpResponse response = httpclient.execute(httpGet);
HttpEntity entity = response.getEntity();
is = entity.getContent();
} catch (Exception e) {
e.printStackTrace();
}
// convert response to string
try {
BufferedReader reader = new BufferedReader(
new InputStreamReader(is), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result = sb.toString();
Log.i("RESULT", result);
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
String fb_id) {
InputStream is = null;
String result = "";
try {
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(
"https://graph.facebook.com/"
+ fb_id
+ "/groups?access_token="
+ token);
HttpResponse response = httpclient.execute(httpGet);
HttpEntity entity = response.getEntity();
is = entity.getContent();
} catch (Exception e) {
e.printStackTrace();
}
// convert response to string
try {
BufferedReader reader = new BufferedReader(
new InputStreamReader(is), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result = sb.toString();
Log.i("RESULT", result);
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
How to get the facebook friend albums in android ?
public static String getFacebookFriendAlbum(String token, Context context,
String fb_id) {
InputStream is = null;
String result = "";
try {
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet("https://graph.facebook.com/"+ fb_id+ "?fields=albums.limit(5).fields(id,name,cover_photo,photos.limit(10).fields(name,picture,source))&access_token="
+ token);
HttpResponse response = httpclient.execute(httpGet);
HttpEntity entity = response.getEntity();
is = entity.getContent();
} catch (Exception e) {
e.printStackTrace();
}
// convert response to string
try {
BufferedReader reader = new BufferedReader(
new InputStreamReader(is), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result = sb.toString();
Log.i("RESULT", result);
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
String fb_id) {
InputStream is = null;
String result = "";
try {
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet("https://graph.facebook.com/"+ fb_id+ "?fields=albums.limit(5).fields(id,name,cover_photo,photos.limit(10).fields(name,picture,source))&access_token="
+ token);
HttpResponse response = httpclient.execute(httpGet);
HttpEntity entity = response.getEntity();
is = entity.getContent();
} catch (Exception e) {
e.printStackTrace();
}
// convert response to string
try {
BufferedReader reader = new BufferedReader(
new InputStreamReader(is), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result = sb.toString();
Log.i("RESULT", result);
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
delete particular file and sub files in android ?
public static void deleteFile(File f) {
String[] flist = f.list();
for (int i = 0; i < flist.length; i++) {
File temp = new File(f.getAbsolutePath() + "/" + flist[i]);
if (temp.isDirectory()) {
deleteFile(temp);
temp.delete();
} else {
temp.delete();
}
}
f.delete();
}
String[] flist = f.list();
for (int i = 0; i < flist.length; i++) {
File temp = new File(f.getAbsolutePath() + "/" + flist[i]);
if (temp.isDirectory()) {
deleteFile(temp);
temp.delete();
} else {
temp.delete();
}
}
f.delete();
}
how to write Custom toast in android ?
public static void displayToast(Activity ctx, String title) {
LayoutInflater inflater = ctx.getLayoutInflater();
View layout = inflater.inflate(R.layout.customtoast,
(ViewGroup) ctx.findViewById(R.id.toast_layout_root));
TextView text = (TextView) layout.findViewById(R.id.text);
text.setText(title);
Toast toast = new Toast(ctx);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(1500);
toast.setView(layout);
toast.show();
}
LayoutInflater inflater = ctx.getLayoutInflater();
View layout = inflater.inflate(R.layout.customtoast,
(ViewGroup) ctx.findViewById(R.id.toast_layout_root));
TextView text = (TextView) layout.findViewById(R.id.text);
text.setText(title);
Toast toast = new Toast(ctx);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(1500);
toast.setView(layout);
toast.show();
}
Monday, 18 August 2014
Animations in android left/right ?
1)inFromRightAnimation
private Animation inFromRightAnimation() {
Animation inFromRight = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, +1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
inFromRight.setDuration(500);
inFromRight.setInterpolator(new AccelerateInterpolator());
return inFromRight;
}
2)outToLeftAnimation
private Animation outToLeftAnimation() {
Animation outtoLeft = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, -1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
outtoLeft.setDuration(500);
outtoLeft.setInterpolator(new AccelerateInterpolator());
return outtoLeft;
}
3)inFromLeftAnimation
private Animation inFromLeftAnimation() {
Animation inFromLeft = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, -1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
inFromLeft.setDuration(500);
inFromLeft.setInterpolator(new AccelerateInterpolator());
return inFromLeft;
}
4)outToRightAnimation
private Animation outToRightAnimation() {
Animation outtoRight = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, +1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
outtoRight.setDuration(500);
outtoRight.setInterpolator(new AccelerateInterpolator());
return outtoRight;
}
Thursday, 7 August 2014
how to get the facebook friend albums in android ?
public static String getFacebookFriendList(String token, Context context,
String fb_id) {
InputStream is = null;
String result = "";
try {
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(
"https://graph.facebook.com/"
+ fb_id
+ "?fields=albums.limit(5).fields(id,name,cover_photo,photos.limit(10).fields(name,picture,source))&access_token="
+ token);
System.out
.println("Data"
+ "https://graph.facebook.com/"
+ fb_id
+ "?fields=albums.limit(5).fields(id,name,cover_photo,photos.limit(10).fields(name,picture,source))&access_token="
+ token);
HttpResponse response = httpclient.execute(httpGet);
HttpEntity entity = response.getEntity();
is = entity.getContent();
} catch (Exception e) {
e.printStackTrace();
}
// convert response to string
try {
BufferedReader reader = new BufferedReader(
new InputStreamReader(is), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result = sb.toString();
Log.i("RESULT", result);
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
String fb_id) {
InputStream is = null;
String result = "";
try {
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(
"https://graph.facebook.com/"
+ fb_id
+ "?fields=albums.limit(5).fields(id,name,cover_photo,photos.limit(10).fields(name,picture,source))&access_token="
+ token);
System.out
.println("Data"
+ "https://graph.facebook.com/"
+ fb_id
+ "?fields=albums.limit(5).fields(id,name,cover_photo,photos.limit(10).fields(name,picture,source))&access_token="
+ token);
HttpResponse response = httpclient.execute(httpGet);
HttpEntity entity = response.getEntity();
is = entity.getContent();
} catch (Exception e) {
e.printStackTrace();
}
// convert response to string
try {
BufferedReader reader = new BufferedReader(
new InputStreamReader(is), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result = sb.toString();
Log.i("RESULT", result);
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
get the responce from server in json post android ?
public static <JSONObject> String postRequest(String url,
List<NameValuePair> postData, Context context) {
String response = null;
try {
HttpParams httpParameters = new BasicHttpParams();
int timeoutConnection = 20000;
HttpConnectionParams.setConnectionTimeout(httpParameters,
timeoutConnection);
int timeoutSocket = 20000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
HttpClient httpclient = new DefaultHttpClient(httpParameters);
HttpPost httppost = new HttpPost(url);
httppost.setEntity(new UrlEncodedFormEntity(postData));
HttpResponse httpResponse = null;
try {
httpResponse = httpclient.execute(httppost);
response = EntityUtils.toString(httpResponse.getEntity());
System.out.println("ResponceData" + response);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return null;
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (ConnectTimeoutException e) {
e.printStackTrace();
} catch (SocketTimeoutException e) {
Toast.makeText(context, "Poor network connection", 2000).show();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
return response;
}
List<NameValuePair> postData, Context context) {
String response = null;
try {
HttpParams httpParameters = new BasicHttpParams();
int timeoutConnection = 20000;
HttpConnectionParams.setConnectionTimeout(httpParameters,
timeoutConnection);
int timeoutSocket = 20000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
HttpClient httpclient = new DefaultHttpClient(httpParameters);
HttpPost httppost = new HttpPost(url);
httppost.setEntity(new UrlEncodedFormEntity(postData));
HttpResponse httpResponse = null;
try {
httpResponse = httpclient.execute(httppost);
response = EntityUtils.toString(httpResponse.getEntity());
System.out.println("ResponceData" + response);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return null;
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (ConnectTimeoutException e) {
e.printStackTrace();
} catch (SocketTimeoutException e) {
Toast.makeText(context, "Poor network connection", 2000).show();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
return response;
}
shared preferences in android sample ?
public static void saveStringPrefrence(String key, String value,
Context context) {
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(context);
Editor edit = prefs.edit();
edit.putString(key, value);
edit.commit();
}
public static String getPrefrenceValue(String key, Context context) {
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(context);
String string = prefs.getString(key, "");
return string;
}
Context context) {
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(context);
Editor edit = prefs.edit();
edit.putString(key, value);
edit.commit();
}
public static String getPrefrenceValue(String key, Context context) {
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(context);
String string = prefs.getString(key, "");
return string;
}
How to find the valid url from the server in android ?
public static boolean exists(String URLName) {
try {
HttpURLConnection.setFollowRedirects(false);
// note : you may also need
// HttpURLConnection.setInstanceFollowRedirects(false)
HttpURLConnection con = (HttpURLConnection) new URL(URLName)
.openConnection();
con.setRequestMethod("HEAD");
return (con.getResponseCode() == HttpURLConnection.HTTP_OK);
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
try {
HttpURLConnection.setFollowRedirects(false);
// note : you may also need
// HttpURLConnection.setInstanceFollowRedirects(false)
HttpURLConnection con = (HttpURLConnection) new URL(URLName)
.openConnection();
con.setRequestMethod("HEAD");
return (con.getResponseCode() == HttpURLConnection.HTTP_OK);
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
How to convert the bitmap to round corner bitmap in android ?
public Bitmap roundCornerImage(Bitmap src, float round) {
// Source image size
int width = src.getWidth();
int height = src.getHeight();
// create result bitmap output
Bitmap result = Bitmap.createBitmap(width, height, Config.ARGB_8888);
// set canvas for painting
Canvas canvas = new Canvas(result);
canvas.drawARGB(0, 0, 0, 0);
// configure paint
final Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(Color.BLACK);
// configure rectangle for embedding
final Rect rect = new Rect(0, 0, width, height);
final RectF rectF = new RectF(rect);
// draw Round rectangle to canvas
canvas.drawRoundRect(rectF, round, round, paint);
// create Xfer mode
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
// draw source image to canvas
canvas.drawBitmap(src, rect, rect, paint);
// return final image
return result;
}
// Source image size
int width = src.getWidth();
int height = src.getHeight();
// create result bitmap output
Bitmap result = Bitmap.createBitmap(width, height, Config.ARGB_8888);
// set canvas for painting
Canvas canvas = new Canvas(result);
canvas.drawARGB(0, 0, 0, 0);
// configure paint
final Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(Color.BLACK);
// configure rectangle for embedding
final Rect rect = new Rect(0, 0, width, height);
final RectF rectF = new RectF(rect);
// draw Round rectangle to canvas
canvas.drawRoundRect(rectF, round, round, paint);
// create Xfer mode
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
// draw source image to canvas
canvas.drawBitmap(src, rect, rect, paint);
// return final image
return result;
}
Tuesday, 17 June 2014
how to copy one file to another file in android
public static void copy(File src, File dst) throws IOException {
InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dst);
// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
}
InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dst);
// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
}
cancel or clear push notifications in android
public static void cancelPushNotification(Context ctx, int notificationType) {
NotificationManager notificationManager = (NotificationManager) ctx
.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(notificationType);
}
NotificationManager notificationManager = (NotificationManager) ctx
.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(notificationType);
}
how to take screenshot in android
public static void takeScreenShotForPage(RelativeLayout webView,
Context context, String path, String fileName) {
try {
webView.setDrawingCacheEnabled(true);
webView.buildDrawingCache(true);
Bitmap bitmap1 = null;
System.gc();
bitmap1 = Bitmap.createBitmap(webView.getDrawingCache(true));
Bitmap bmp = Common.getResizedBitmap(bitmap1, 150, 100);
webView.setDrawingCacheEnabled(false);
} catch (Exception e) {
e.printStackTrace();
}
}
Context context, String path, String fileName) {
try {
webView.setDrawingCacheEnabled(true);
webView.buildDrawingCache(true);
Bitmap bitmap1 = null;
System.gc();
bitmap1 = Bitmap.createBitmap(webView.getDrawingCache(true));
Bitmap bmp = Common.getResizedBitmap(bitmap1, 150, 100);
webView.setDrawingCacheEnabled(false);
} catch (Exception e) {
e.printStackTrace();
}
}
how to delete files in android
public static void deleteFile(File f) {
String[] flist = f.list();
for (int i = 0; i < flist.length; i++) {
File temp = new File(f.getAbsolutePath() + "/" + flist[i]);
if (temp.isDirectory()) {
deleteFile(temp);
temp.delete();
} else {
temp.delete();
}
}
f.delete();
}
String[] flist = f.list();
for (int i = 0; i < flist.length; i++) {
File temp = new File(f.getAbsolutePath() + "/" + flist[i]);
if (temp.isDirectory()) {
deleteFile(temp);
temp.delete();
} else {
temp.delete();
}
}
f.delete();
}
how to use custom toast in android
public static void displayToast(Activity ctx, String title) {
LayoutInflater inflater = ctx.getLayoutInflater();
View layout = inflater.inflate(R.layout.customtoast,
(ViewGroup) ctx.findViewById(R.id.toast_layout_root));
TextView text = (TextView) layout.findViewById(R.id.text);
text.setText(title);
Toast toast = new Toast(ctx);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(1500);
toast.setView(layout);
toast.show();
}
LayoutInflater inflater = ctx.getLayoutInflater();
View layout = inflater.inflate(R.layout.customtoast,
(ViewGroup) ctx.findViewById(R.id.toast_layout_root));
TextView text = (TextView) layout.findViewById(R.id.text);
text.setText(title);
Toast toast = new Toast(ctx);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(1500);
toast.setView(layout);
toast.show();
}
how to use shared preferences concepts in android
public static void saveStringPrefrence(String key, String value,
Context context) {
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(context);
Editor edit = prefs.edit();
edit.putString(key, value);
edit.commit();
}
public static String getPrefrenceValue(String key, Context context) {
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(context);
String string = prefs.getString(key, "");
return string;
}
Context context) {
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(context);
Editor edit = prefs.edit();
edit.putString(key, value);
edit.commit();
}
public static String getPrefrenceValue(String key, Context context) {
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(context);
String string = prefs.getString(key, "");
return string;
}
Subscribe to:
Posts (Atom)