Skip to content

Instantly share code, notes, and snippets.

View arthtilva's full-sized avatar

Arth Tilva arthtilva

  • Tilva Artsoft
  • Rajkot, Gujarat, India
View GitHub Profile
@arthtilva
arthtilva / InternetCheck.java
Created June 3, 2016 17:07
To check internet
public static boolean isConnectedToInternet(Context context) {
ConnectivityManager connectivity = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity != null) {
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null)
for (int i = 0; i < info.length; i++)
if (info[i].getState() == NetworkInfo.State.CONNECTED) {
return true;
}
@arthtilva
arthtilva / StoreUserData.java
Last active September 3, 2016 05:45
SharedPrefrences class
public class StoreUserData {
private SharedPreferences pref = null;
private Context parentActivity;
public static String APP_KEY;
public StoreUserData(Context context) {
parentActivity = context;
APP_KEY = context.getPackageName().replaceAll("\\.", "_").toLowerCase();
}
static ProgressDialog progressDialog;
public static void showProgress(Activity activity) {
progressDialog = new ProgressDialog(activity);
progressDialog.setIndeterminate(false);
progressDialog.setCancelable(false);
progressDialog.setMessage("Loading...");
progressDialog.show();
}
@arthtilva
arthtilva / Utils.java
Last active September 9, 2016 18:39
Utils comman method for all project
public class Utils {
static ProgressDialog progressDialog;
public static void showProgress(Activity activity) {
progressDialog = new ProgressDialog(activity);
progressDialog.setIndeterminate(false);
progressDialog.setCancelable(false);
progressDialog.setMessage("Loading...");
progressDialog.show();
@arthtilva
arthtilva / permission.java
Last active September 1, 2016 18:47
Multiple Permission Check - Marshmallow
public class MainActivity extends AppCompatActivity{
List<String> permissionsList = new ArrayList<>();
boolean askOnceAgain = false;
Activity activity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
activity = this;
@arthtilva
arthtilva / bottom_line.xml
Created June 13, 2016 19:09
drawable for line in bottom
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:bottom="0dp"
android:left="-6dp"
android:right="-6dp"
android:top="-6dp">
<shape android:shape="rectangle">
<solid android:color="@android:color/transparent" />
@arthtilva
arthtilva / download.java
Last active March 21, 2023 12:15
DownloadManager - download files using DownloadManager
public class NewsDetailActivity extends AppCompatActivity implements View.OnClickListener {
Activity activity;
Toolbar toolbar;
File TEMP_FILE_SAVE_PATH = Environment.getExternalStorageDirectory();
String TEMP_FILE_NAME = "news_";
String URL="";
private DownloadManager downloadManager;
@Override
@arthtilva
arthtilva / ExpandCollapse.java
Created June 20, 2016 06:35
Expand - Collapse Animation JAVA
public static void expand(final View v) {
v.measure(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
final int targetHeight = v.getMeasuredHeight();
// Older versions of android (pre API 21) cancel animations for views with a height of 0.
v.getLayoutParams().height = 1;
v.setVisibility(View.VISIBLE);
Animation a = new Animation() {
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
@arthtilva
arthtilva / ImageFilePath.java
Created June 23, 2016 05:24
FilePath is different in pre-kitkat and above kitkat
public class ImageFilePath
{
/**
* Method for return file path of Gallery image
*
* @param context
* @param uri
* @return path of the selected image file from gallery
@arthtilva
arthtilva / ChooseDialog.java
Last active May 18, 2019 17:17
Choose Image and other media from gallery or camera
Uri ImagefileUri;
int hasStoragePermission, hasCameraPermission, GALLERY_CLICK = 100, CAMERA_CLICK = 101;
File appImageFolder;
boolean askOnceAgain = false;
hasStoragePermission = ContextCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (hasStoragePermission != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
11);
} else {