Skip to content

Instantly share code, notes, and snippets.

View pawanchauhan05's full-sized avatar

Pawan Singh Chauhan pawanchauhan05

View GitHub Profile
@pawanchauhan05
pawanchauhan05 / layout.xml
Created October 21, 2017 09:34
disable by default focus getting by EditText
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainLayout"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true" >
<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
@pawanchauhan05
pawanchauhan05 / RoundCorner.java
Created October 21, 2017 09:31
add round corner drawable to view using java
public GradientDrawable getRoundDrawable(Context context, int solidColor, int strokeColor) {
GradientDrawable drawable = new GradientDrawable();
drawable.setShape(GradientDrawable.RECTANGLE);
drawable.setStroke(3, context.getResources().getColor(strokeColor));
drawable.setCornerRadius(6);
drawable.setColor(context.getResources().getColor(solidColor));
drawable.mutate();
return drawable;
}
@pawanchauhan05
pawanchauhan05 / round_corner_with_stroke.xml
Created October 21, 2017 09:30
round corner with stroke to view
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:angle="270"
android:color="@color/color_F9F9F9" />
<corners android:radius="5px"/>
<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
<stroke
android:width="1dp"
@pawanchauhan05
pawanchauhan05 / round_corner.xml
Created October 21, 2017 09:28
round corner to view using xml.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners
android:radius="5px"/>
/>
<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
<solid android:color="@color/white"></solid>
</shape>
public class FCM {
public static final String SERVER_KEY = "DEFINE_FCM_SERVER_KEY";
public static final String DEVICE_TOKEN = "DEFINE_DEVICE_TOKEN";
/**
* use new NotificationTask().execute();
* to send notification
*/
@pawanchauhan05
pawanchauhan05 / CropImge.java
Last active May 19, 2020 01:47
this code is useful for select image from camera and gallery then crop it like whatsapp, hike etc. to save cropped avatar to gallery you have to add a permission in AndroidManifest file. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
private String cameraFileName;
public static final int CHOICE_AVATAR_FROM_CAMERA = 0;
public static final int CHOICE_AVATAR_FROM_GALLERY = 1;
public static final int CHOICE_AVATAR_FROM_CAMERA_CROP = 3;
public void choiceAvatarFromCamera() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cameraFileName = "file" + System.currentTimeMillis() + ".png";
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC), cameraFileName);
if(!file.exists()){
@pawanchauhan05
pawanchauhan05 / FileDownload.java
Last active February 2, 2017 10:51
download any content( eg. audio, video, image etc ) using url via AsyncTask in Android.
class DownloadMusicFile extends AsyncTask<String, String, String> {
@Override
protected String doInBackground(String... musicURL) {
int count;
try {
URL url = new URL(musicURL[0]);
URLConnection connection = url.openConnection();
connection.connect();
InputStream input = new BufferedInputStream(url.openStream(), 8192);