Skip to content

Instantly share code, notes, and snippets.

Avatar

Shivam Dhuria Shivamdhuria

View GitHub Profile
@Shivamdhuria
Shivamdhuria / RealPathUtil.java
Created Mar 5, 2019 — forked from skfaisal93/RealPathUtil.java
Real Path Utility class for Android, works for all API, also handle NumberFormatException for API 28
View RealPathUtil.java
import android.annotation.SuppressLint;
import android.content.ContentUris;
import android.content.Context;
import android.content.CursorLoader;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.provider.DocumentsContract;
import android.provider.MediaStore;
View item_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/parent_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginTop="16dp"
android:background="@color/colorPrimary"
android:orientation="vertical"
android:padding="20dp"
View activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="8dp"
View MainActivity.java
package elixer.com.threadpool;
public class MainActivity extends AppCompatActivity {
private ArrayList<String> mTaskNames = new ArrayList<>();
private RecyclerView recyclerView;
private RecyclerView.Adapter mAdapter;
private RecyclerView.LayoutManager layoutManager;
@Override
View Task.java
public class Task implements Runnable {
public static final String TAG = "RUNANABLE";
private String taskName;
private Context mContext;
private ProgressBar progressBar;
private TextView statusTextView;
public Task(Context mContext, String taskName, ProgressBar progressBar, TextView statusTextView) {
View Manager.java
public class Manager {
private static final int CORE_POOL_SIZE = 5;
private static final int MAX_POOL_SIZE = 10;
private static final int KEEP_ALIVE_TIME = 50;
private static Manager managerInstance = null;
//Queue for all the Tasks
final BlockingQueue<Runnable> WorkQueue;
View RecyclerViewAdapter.java
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder> {
private ArrayList<String> mTaskNames;
private Context mContext;
public RecyclerViewAdapter(Context mContext, ArrayList<String> mTaskNames) {
this.mTaskNames = mTaskNames;
this.mContext = mContext;
}
View activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="200dp">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
View App.java
public class App extends Application {
public static final String CHANNEL_ID = "exampleServiceChannel";
@Override
public void onCreate() {
super.onCreate();
createNotificationChannel();
}
private void createNotificationChannel() {
View MainActivity.java
public class MainActivity extends AppCompatActivity {
private Button startServiceButton;
private Button stopServiceButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
startServiceButton = findViewById(R.id.start_button);