RxUnfurl RxUnfurl is a reactive extension to generate URL previews. This library parses available open graph data from the provided url and returns them as a simple model class. Otherwise, the library searches for other fallbacks and returns them instead. Image dimensions are read from its uri by feRead more
RxUnfurl
RxUnfurl is a reactive extension to generate URL previews.
This library parses available open graph data from the provided url and returns them as a simple model class. Otherwise, the library searches for other fallbacks and returns them instead.
Image dimensions are read from its uri by fetching the required bytes and then sorted according to their resolution. The library uses RxJava2 as of the time of pulishing this.
Step 1 – Install
To install the library add the following implementation statement in your module-level build.gradle:
To generate previews, simply subscribe to RxUnfurl.generatePreview(yourURL)
Here is an example:
OkHttpClient okhttpClient = new OkHttpClient();
RxUnfurl inst = new RxUnfurl.Builder()
.client(okhttpClient) // You can supply your okhttp client here
.scheduler(Schedulers.io())
.build();
inst.generatePreview("http://9gag.com")
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new DisposableSingleObserver<PreviewData>() {
@Override
public void onSuccess(PreviewData previewData) { // Observable has been changed to Single
}
@Override
public void onError(Throwable e) {
}
});
Android MaterialRatingBar Another way for you to use a rating bar is the usage of a third party library. Through this you get a more beautiful and customizable library than the standard ratingbar. One of those libraries is material rating bar. It's basically a material Design `RatingBar` with betterRead more
Android MaterialRatingBar
Another way for you to use a rating bar is the usage of a third party library. Through this you get a more beautiful and customizable library than the standard ratingbar.
One of those libraries is material rating bar. It’s basically a material Design RatingBar with better appearance, compatible with Android 3.0+.
Here are its features:
Consistent appearance on Android 3.0+.
Extends framework RatingBar.
Get the 2dp star border background as in Material Icons and Google apps.
Correct custom tinting across platforms.
Able to render correctly when layout_width is set to match_parent, as in Google Play Store.
Able to scale correctly when layout_height is set to values other than 16dp, 36dp and 48dp.
Able to display ratings such as 4.3 correctly, which will be filled to 4.5 by framework’s incorrect implementation.
Avoid framework’s sunken half star visual glitch.
Used as a drop-in replacement for framework RatingBar.
Here are the steps to use it:
Step 1- Installation
Install it from jcenter using the following statement:
Swipe Cards with SwipeView SwipeView is a a Tinder style StackSwipeview gesture library. It supports android API 15 and above. Here is how to use it. Step 1 - Installation To Install the library first add jitpack in your project level's build.gradle: maven { url 'https://jitpack.io' } Then the depenRead more
Swipe Cards with SwipeView
SwipeView is a a Tinder style StackSwipeview gesture library. It supports android API 15 and above.
Here is how to use it.
Step 1 – Installation
To Install the library first add jitpack in your project level’s build.gradle:
maven { url 'https://jitpack.io' }
Then the dependency statement in your app level’s build.gradle:
then set CardLayoutManager for RecyclerView and CardItemTouchHelperCallback for ItemTouchHelper . In addition , don’t forget set OnSwipeListener for CardItemTouchHelperCallback :
// dataList means dataSource for adapter
CardItemTouchHelperCallback cardCallback = new CardItemTouchHelperCallback(recyclerView.getAdapter(), dataList);
ItemTouchHelper touchHelper = new ItemTouchHelper(cardCallback); CardLayoutManager cardLayoutManager = new CardLayoutManager(recyclerView, touchHelper);
recyclerView.setLayoutManager(cardLayoutManager);
touchHelper.attachToRecyclerView(recyclerView);
cardCallback.setOnSwipedListener(new OnSwipeListener<T>() {
@Override
public void onSwiping(RecyclerView.ViewHolder viewHolder, float ratio, int direction) {
/**
* will callback when the card are swiping by user
* viewHolder : thee viewHolder of swiping card
* ratio : the ratio of swiping , you can add some animation by the ratio
* direction : CardConfig.SWIPING_LEFT means swiping from left;CardConfig.SWIPING_RIGHT means swiping from right
* CardConfig.SWIPING_NONE means not left nor right
*/
}
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, T t, int direction) {
/**
* will callback when the card swiped from screen by user
* you can also clean animation from the itemview of viewHolder in this method
* viewHolder : the viewHolder of swiped cards
* t : the data of swiped cards from dataList
* direction : CardConfig.SWIPED_LEFT means swiped from left;CardConfig.SWIPED_RIGHT means swiped from right
*/
}
@Override
public void onSwipedClear() {
/**
* will callback when all cards swiped clear
* you can load more data
*/
}
});
### step 3
java
/*
*Create stack photoview list
*/
private void initData() {
list.add(R.drawable.img_avatar_01);
list.add(R.drawable.img_avatar_02);
list.add(R.drawable.img_avatar_03);
list.add(R.drawable.img_avatar_04);
list.add(R.drawable.img_avatar_05);
list.add(R.drawable.img_avatar_06);
list.add(R.drawable.img_avatar_07);
}
Full Example
Here is a full example of how to use swipe view.
(a). MainActivity
Here is the code for our only class, the main activity.
public class MainActivity extends AppCompatActivity {
private List<Integer> list = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
initData();
}
private void initView() {
final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(new StackViewAdapter());
StackItemTouchHelperCallback cardCallback = new StackItemTouchHelperCallback(recyclerView.getAdapter(), list);
cardCallback.setOnSwipedListener(new OnSwipeListener<Integer>() {
@Override
public void onSwiping(RecyclerView.ViewHolder viewHolder, float ratio, int direction) {
StackViewAdapter.MyViewHolder myHolder = (StackViewAdapter.MyViewHolder) viewHolder;
viewHolder.itemView.setAlpha(1 - Math.abs(ratio) * 0.2f);
if (direction == Utility.SWIPING_LEFT) {
myHolder.dislikeImageView.setAlpha(Math.abs(ratio));
} else if (direction == Utility.SWIPING_RIGHT) {
myHolder.likeImageView.setAlpha(Math.abs(ratio));
} else {
myHolder.dislikeImageView.setAlpha(0f);
myHolder.likeImageView.setAlpha(0f);
}
}
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, Integer o, int direction) {
StackViewAdapter.MyViewHolder myHolder = (StackViewAdapter.MyViewHolder) viewHolder;
viewHolder.itemView.setAlpha(1f);
myHolder.dislikeImageView.setAlpha(0f);
myHolder.likeImageView.setAlpha(0f);
Toast.makeText(MainActivity.this, direction == Utility.SWIPED_LEFT ? "dislike" : "like", Toast.LENGTH_SHORT).show();
}
@Override
public void onSwipedClear() {
Toast.makeText(MainActivity.this, "finish data", Toast.LENGTH_SHORT).show();
recyclerView.postDelayed(new Runnable() {
@Override
public void run() {
initData();
recyclerView.getAdapter().notifyDataSetChanged();
}
}, 3000L);
}
});
final ItemTouchHelper touchHelper = new ItemTouchHelper(cardCallback);
final StackLayoutViewManager cardLayoutManager = new StackLayoutViewManager(recyclerView, touchHelper);
recyclerView.setLayoutManager(cardLayoutManager);
touchHelper.attachToRecyclerView(recyclerView);
}
private void initData() {
list.add(R.drawable.img_avatar_01);
list.add(R.drawable.img_avatar_02);
list.add(R.drawable.img_avatar_03);
list.add(R.drawable.img_avatar_04);
list.add(R.drawable.img_avatar_05);
list.add(R.drawable.img_avatar_06);
list.add(R.drawable.img_avatar_07);
}
private class StackViewAdapter extends RecyclerView.Adapter {
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item, parent, false);
return new MyViewHolder(view);
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
ImageView avatarImageView = ((MyViewHolder) holder).avatarImageView;
avatarImageView.setImageResource(list.get(position));
}
@Override
public int getItemCount() {
return list.size();
}
class MyViewHolder extends RecyclerView.ViewHolder {
StackImageView avatarImageView;
ImageView likeImageView;
ImageView dislikeImageView;
MyViewHolder(View itemView) {
super(itemView);
avatarImageView = (StackImageView) itemView.findViewById(R.id.iv_avatar);
likeImageView = (ImageView) itemView.findViewById(R.id.iv_like);
dislikeImageView = (ImageView) itemView.findViewById(R.id.iv_dislike);
}
}
}
}
Easily Implement Shared Transition on Images You can easily implement shared element transition on images using this library known as Transitional ImageView. Let's show you how to. Step 1 - Install the Library First register jitpack as a repository in your app level build.gradle: allprojects { reposRead more
Easily Implement Shared Transition on Images
You can easily implement shared element transition on images using this library known as Transitional ImageView.
Let’s show you how to.
Step 1 – Install the Library
First register jitpack as a repository in your app level build.gradle:
Kotlin Shared Transition RecyclerView and Fragments This is also a simple shared transitions example written in Kotlin. This time round however a recyclerview is the shared element among two fragments. Tools Here are the things to keep in mind: Programming Language - Kotlin Minimum SDK - 21 1. CreatRead more
Kotlin Shared Transition RecyclerView and Fragments
This is also a simple shared transitions example written in Kotlin. This time round however a recyclerview is the shared element among two fragments.
Tools
Here are the things to keep in mind:
Programming Language – Kotlin
Minimum SDK – 21
1. Create Transitions
In a folder known as transitions under resources add the following:
Java Shared Transition with Fragments and FloatingActionButton This is a simple one-class example to utilize a shared element transition within fragments in an android activity. The programming language is Java. While it is not written in androidx, you can easily update it to androidx fragments andRead more
Java Shared Transition with Fragments and FloatingActionButton
This is a simple one-class example to utilize a shared element transition within fragments in an android activity. The programming language is Java. While it is not written in androidx, you can easily update it to androidx fragments and it doesn’t utilize any third partt library.
shared
Transitions
These are written in XML. Tyically you create a transition resource directory and place the XML.
EmailIntentBuilder This an Android Library for the creation of SendTo Intents with mailto: URI. Step 1 - Installation Install the library by adding the following statement in your build.gradle file: implementation 'de.cketti.mailto:email-intent-builder:2.0.0' Step 2 Then set the appropriateRead more
EmailIntentBuilder
This an Android Library for the creation of SendTo Intents with mailto: URI.
Step 1 – Installation
Install the library by adding the following statement in your build.gradle file:
EmailIntentBuilder.from(activity)
.to("alice@example.org")
.cc("bob@example.org")
.bcc("charles@example.org")
.subject("Message from an app")
.body("Some text here")
.start();
FULL EXAMPLE
Here is a full example to use this library to send email:
PickiT This is an Android library that you can use to return real paths from Uri's. Follow the following steps to use it. Step 1 - Installation The library is hosted in jitpack so go to your project-level build.gradle and specify jitpack URL: allprojects { repositories { ... maven { url 'httRead more
PickiT
This is an Android library that you can use to return real paths from Uri’s.
Follow the following steps to use it.
Step 1 – Installation
The library is hosted in jitpack so go to your project-level build.gradle and specify jitpack URL:
So for example assume that using your Filepicker you’ve selected the file and now you want to convert the Uri to a real path inside the onActivityResult:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == SELECT_VIDEO_REQUEST) {
if (resultCode == RESULT_OK) {
pickiT.getPath(data.getData(), Build.VERSION.SDK_INT);
}
}
}
NB/= If you are targeting SDK 29> add android:requestLegacyExternalStorage="true" in your manifest:
The reason for this is, in Android 10 file path access was removed and it returned in Android 11.
If you are targiting SDK 29> and you do not add this, you will get EACCES (Permission denied)
FULL EXAMPLE
Here is a full example.
(a). MainActivity.java
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Environment;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.view.ContextThemeWrapper;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.hbisoft.pickit.PickiT;
import com.hbisoft.pickit.PickiTCallbacks;
public class MainActivity extends AppCompatActivity implements PickiTCallbacks {
//Permissions
private static final int SELECT_VIDEO_REQUEST = 777;
private static final int PERMISSION_REQ_ID_RECORD_AUDIO = 22;
private static final int PERMISSION_REQ_ID_WRITE_EXTERNAL_STORAGE = PERMISSION_REQ_ID_RECORD_AUDIO + 1;
//Declare PickiT
PickiT pickiT;
//Views
Button button_pick;
TextView pickitTv, originalTv, originalTitle, pickitTitle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
buttonClickEvent();
//Initialize PickiT
pickiT = new PickiT(this, this, this);
}
//Show Toast
private void showLongToast(final String msg) {
Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
}
private void init() {
button_pick = findViewById(R.id.button_pick);
pickitTv = findViewById(R.id.pickitTv);
originalTv = findViewById(R.id.originalTv);
originalTitle = findViewById(R.id.originalTitle);
pickitTitle = findViewById(R.id.pickitTitle);
}
private void buttonClickEvent() {
button_pick.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openGallery();
// Make TextView's invisible
originalTitle.setVisibility(View.INVISIBLE);
originalTv.setVisibility(View.INVISIBLE);
pickitTitle.setVisibility(View.INVISIBLE);
pickitTv.setVisibility(View.INVISIBLE);
}
});
}
private void openGallery() {
// first check if permissions was granted
if (checkSelfPermission()) {
Intent intent;
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
} else {
intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Video.Media.INTERNAL_CONTENT_URI);
}
// In this example we will set the type to video
intent.setType("video/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.putExtra("return-data", true);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivityForResult(intent, SELECT_VIDEO_REQUEST);
}
}
// Check if permissions was granted
private boolean checkSelfPermission() {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE}, MainActivity.PERMISSION_REQ_ID_WRITE_EXTERNAL_STORAGE);
return false;
}
return true;
}
// Handle permissions
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == PERMISSION_REQ_ID_WRITE_EXTERNAL_STORAGE) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// Permissions was granted, open the gallery
openGallery();
}
// Permissions was not granted
else {
showLongToast("No permission for " + Manifest.permission.WRITE_EXTERNAL_STORAGE);
}
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == SELECT_VIDEO_REQUEST) {
if (resultCode == RESULT_OK) {
// Get path from PickiT (The path will be returned in PickiTonCompleteListener)
//
// If the selected file is from Dropbox/Google Drive or OnDrive:
// Then it will be "copied" to your app directory (see path example below) and when done the path will be returned in PickiTonCompleteListener
// /storage/emulated/0/Android/data/your.package.name/files/Temp/tempDriveFile.mp4
//
// else the path will directly be returned in PickiTonCompleteListener
pickiT.getPath(data.getData(), Build.VERSION.SDK_INT);
originalTv.setText(String.valueOf(data.getData()));
}
}
}
//
// PickiT Listeners
//
// The listeners can be used to display a Dialog when a file is selected from Dropbox/Google Drive or OnDrive.
// The listeners are callbacks from an AsyncTask that creates a new File of the original in /storage/emulated/0/Android/data/your.package.name/files/Temp/
//
// PickiTonUriReturned()
// When selecting a file from Google Drive, for example, the Uri will be returned before the file is available(if it has not yet been cached/downloaded).
// Google Drive will first have to download the file before we have access to it.
// This can be used to let the user know that we(the application), are waiting for the file to be returned.
//
// PickiTonStartListener()
// This will be call once the file creations starts and will only be called if the selected file is not local
//
// PickiTonProgressUpdate(int progress)
// This will return the progress of the file creation (in percentage) and will only be called if the selected file is not local
//
// PickiTonCompleteListener(String path, boolean wasDriveFile)
// If the selected file was from Dropbox/Google Drive or OnDrive, then this will be called after the file was created.
// If the selected file was a local file then this will be called directly, returning the path as a String
// Additionally, a boolean will be returned letting you know if the file selected was from Dropbox/Google Drive or OnDrive.
ProgressBar mProgressBar;
TextView percentText;
private AlertDialog mdialog;
ProgressDialog progressBar;
@Override
public void PickiTonUriReturned() {
progressBar = new ProgressDialog(this);
progressBar.setMessage("Waiting to receive file...");
progressBar.setCancelable(false);
progressBar.show();
}
@Override
public void PickiTonStartListener() {
if (progressBar.isShowing()){
progressBar.cancel();
}
final AlertDialog.Builder mPro = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.myDialog));
@SuppressLint("InflateParams") final View mPView = LayoutInflater.from(this).inflate(R.layout.dailog_layout, null);
percentText = mPView.findViewById(R.id.percentText);
percentText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
pickiT.cancelTask();
if (mdialog != null && mdialog.isShowing()) {
mdialog.cancel();
}
}
});
mProgressBar = mPView.findViewById(R.id.mProgressBar);
mProgressBar.setMax(100);
mPro.setView(mPView);
mdialog = mPro.create();
mdialog.show();
}
@Override
public void PickiTonProgressUpdate(int progress) {
String progressPlusPercent = progress + "%";
percentText.setText(progressPlusPercent);
mProgressBar.setProgress(progress);
}
@Override
public void PickiTonCompleteListener(String path, boolean wasDriveFile, boolean wasUnknownProvider, boolean wasSuccessful, String reason) {
if (mdialog != null && mdialog.isShowing()) {
mdialog.cancel();
}
// Check if it was a Drive/local/unknown provider file and display a Toast
if (wasDriveFile){
showLongToast("Drive file was selected");
}else if (wasUnknownProvider){
showLongToast("File was selected from unknown provider");
}else {
showLongToast("Local file was selected");
}
// Chick if it was successful
if (wasSuccessful) {
// Set returned path to TextView
pickitTv.setText(path);
// Make TextView's visible
originalTitle.setVisibility(View.VISIBLE);
originalTv.setVisibility(View.VISIBLE);
pickitTitle.setVisibility(View.VISIBLE);
pickitTv.setVisibility(View.VISIBLE);
}else {
showLongToast("Error, please see the log..");
pickitTv.setVisibility(View.VISIBLE);
pickitTv.setText(reason);
}
}
//
// Lifecycle methods
//
// Deleting the temporary file if it exists
@Override
public void onBackPressed() {
pickiT.deleteTemporaryFile(this);
super.onBackPressed();
}
// Deleting the temporary file if it exists
// As we know, this might not even be called if the system kills the application before onDestroy is called
// So, it is best to call pickiT.deleteTemporaryFile(); as soon as you are done with the file
@Override
public void onDestroy() {
super.onDestroy();
if (!isChangingConfigurations()) {
pickiT.deleteTemporaryFile(this);
}
}
}
Some Utility Uri Examples Here are some important utility methods you may need when coding. (a). Get Path from Uri You need to return a real path as a string and you have a Uri. public static String getPath(final Context context, final Uri uri) { //check for KITKAT or above final boolean isKitKat =Read more
Some Utility Uri Examples
Here are some important utility methods you may need when coding.
(a). Get Path from Uri
You need to return a real path as a string and you have a Uri.
public static String getPath(final Context context, final Uri uri) {
//check for KITKAT or above
final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
// DocumentProvider
if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
// ExternalStorageProvider
if (isExternalStorageDocument(uri)) {
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
final String type = split[0];
if ("primary".equalsIgnoreCase(type)) {
return Environment.getExternalStorageDirectory() + "/" + split[1];
}
}
// DownloadsProvider
else if (isDownloadsDocument(uri)) {
return getDownloadFilePath(context, uri);
}
// MediaProvider
else if (isMediaDocument(uri)) {
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
final String type = split[0];
Uri contentUri = null;
if ("image".equals(type)) {
contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
} else if ("video".equals(type)) {
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
} else if ("audio".equals(type)) {
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
}
final String selection = "_id=?";
final String[] selectionArgs = new String[] {
split[1]
};
return getDataColumn(context, contentUri, selection, selectionArgs);
}
}
// MediaStore (and general)
else if ("content".equalsIgnoreCase(uri.getScheme())) {
// Return the remote address
if (isGooglePhotosUri(uri))
return uri.getLastPathSegment();
return getDataColumn(context, uri, null, null);
}
// File
else if ("file".equalsIgnoreCase(uri.getScheme())) {
return uri.getPath();
}
return null;
}
(b). Get Data Column when given Uri
public static String getDataColumn(Context context, Uri uri, String selection,
String[] selectionArgs) {
Cursor cursor = null;
final String column = "_data";
final String[] projection = {
column
};
try {
cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
null);
if (cursor != null && cursor.moveToFirst()) {
final int index = cursor.getColumnIndexOrThrow(column);
return cursor.getString(index);
}
} finally {
if (cursor != null)
cursor.close();
}
return null;
}
(c). Get Downloads Path
You have a Uri and you want to return the downloads path.
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
public static String getDownloadFilePath(Context context, Uri uri){
Cursor cursor = null;
final String[] projection = {
MediaStore.MediaColumns.DISPLAY_NAME
};
try {
cursor = context.getContentResolver().query(uri, projection, null, null, null);
if (cursor != null && cursor.moveToFirst()) {
String fileName=cursor.getString(0);
String path =Environment.getExternalStorageDirectory().toString() + "/Download/" + fileName;
if (!TextUtils.isEmpty(path)){
return path;
}
}
} finally {
cursor.close();
}
String id = DocumentsContract.getDocumentId(uri);
if (id.startsWith("raw:")) {
return id.replaceFirst("raw:", "");
}
Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads"), java.lang.Long.valueOf(id));
return getDataColumn(context, contentUri, null, null);
}
Here are more examples:
public static boolean isExternalStorageDocument(Uri uri) {
return "com.android.externalstorage.documents".equals(uri.getAuthority());
}
public static boolean isDownloadsDocument(Uri uri) {
return "com.android.providers.downloads.documents".equals(uri.getAuthority());
}
public static boolean isMediaDocument(Uri uri) {
return "com.android.providers.media.documents".equals(uri.getAuthority());
}
public static boolean isGooglePhotosUri(Uri uri) {
return "com.google.android.apps.photos.content".equals(uri.getAuthority());
}
Android URL Preview
Oclemy
RxUnfurl RxUnfurl is a reactive extension to generate URL previews. This library parses available open graph data from the provided url and returns them as a simple model class. Otherwise, the library searches for other fallbacks and returns them instead. Image dimensions are read from its uri by feRead more
RxUnfurl
RxUnfurl is a reactive extension to generate URL previews.
This library parses available open graph data from the provided url and returns them as a simple model class. Otherwise, the library searches for other fallbacks and returns them instead.
Image dimensions are read from its uri by fetching the required bytes and then sorted according to their resolution. The library uses RxJava2 as of the time of pulishing this.
Step 1 – Install
To install the library add the following implementation statement in your module-level build.gradle:
Usage
To generate previews, simply subscribe to
RxUnfurl.generatePreview(yourURL)
Here is an example:
Find more here.
See lessAndroid Firebase RecyclerView MasterDetail CRUD Images Text – Upload, READ, DELETE
Oclemy
Can you cnofirm that it is being uploaded?
Can you cnofirm that it is being uploaded?
See lessAndroid RatingBar
Oclemy
Android MaterialRatingBar Another way for you to use a rating bar is the usage of a third party library. Through this you get a more beautiful and customizable library than the standard ratingbar. One of those libraries is material rating bar. It's basically a material Design `RatingBar` with betterRead more
Android MaterialRatingBar
Another way for you to use a rating bar is the usage of a third party library. Through this you get a more beautiful and customizable library than the standard ratingbar.
One of those libraries is material rating bar. It’s basically a material Design
RatingBar
with better appearance, compatible with Android 3.0+.Here are its features:
RatingBar
.layout_width
is set tomatch_parent
, as in Google Play Store.layout_height
is set to values other than 16dp, 36dp and 48dp.4.3
correctly, which will be filled to4.5
by framework’s incorrect implementation.RatingBar
.Here are the steps to use it:
Step 1- Installation
Install it from jcenter using the following statement:
Step 2 – Layout
Simply replace your
RatingBar
withMaterialRatingBar
, and remember to apply a corresponding style for correct behavior.For example, to create a normal
MaterialRatingBar
:Demos
Here is the demo:
Links
Best Android Swipe Cards Libraries and Examples
Oclemy
Swipe Cards with SwipeView SwipeView is a a Tinder style StackSwipeview gesture library. It supports android API 15 and above. Here is how to use it. Step 1 - Installation To Install the library first add jitpack in your project level's build.gradle: maven { url 'https://jitpack.io' } Then the depenRead more
Swipe Cards with SwipeView
SwipeView is a a Tinder style StackSwipeview gesture library. It supports android API 15 and above.
Here is how to use it.
Step 1 – Installation
To Install the library first add jitpack in your project level’s build.gradle:
Then the dependency statement in your app level’s build.gradle:
Step 2 – Layout
Add the SwipeView in your layout:
Step 3 – Code
In your activity or fragment start by initializing your recyclerview as usual:
then set
CardLayoutManager
for RecyclerView andCardItemTouchHelperCallback
for ItemTouchHelper . In addition , don’t forget setOnSwipeListener
forCardItemTouchHelperCallback
:Full Example
Here is a full example of how to use swipe view.
(a). MainActivity
Here is the code for our only class, the main activity.
Run
If you run the project you get the following:

See lessAndroid Shared Element Transition
Oclemy
Easily Implement Shared Transition on Images You can easily implement shared element transition on images using this library known as Transitional ImageView. Let's show you how to. Step 1 - Install the Library First register jitpack as a repository in your app level build.gradle: allprojects { reposRead more
Easily Implement Shared Transition on Images
You can easily implement shared element transition on images using this library known as Transitional ImageView.
Let’s show you how to.
Step 1 – Install the Library
First register jitpack as a repository in your app level build.gradle:
Then install the library:
Step 2
Create Transitional ImageView in your layout by pasting the following code:
Step 3
Now build a TransitionImageObject and set it to the TransitionalImageView:
Full Example
Here is a beautiful example for using this library.
(a). Shoe.java
The model class to define a single shoe.
(b). ShoeAdapter.java
Then the recyclerview adapter.
(c). ShoeListActivity.java
The shoe list activity:
(d). MainActivity.java
And finally the main activity.
Demo
Here is the demo of what you get when you run the project.
Download
Here are the download links.
Android Shared Element Transition
Oclemy
Kotlin Shared Transition RecyclerView and Fragments This is also a simple shared transitions example written in Kotlin. This time round however a recyclerview is the shared element among two fragments. Tools Here are the things to keep in mind: Programming Language - Kotlin Minimum SDK - 21 1. CreatRead more
Kotlin Shared Transition RecyclerView and Fragments
This is also a simple shared transitions example written in Kotlin. This time round however a recyclerview is the shared element among two fragments.
Tools
Here are the things to keep in mind:
1. Create Transitions
In a folder known as transitions under resources add the following:
(a). change_bounds.xml
(b). change_image_transform.xml
Then:
2. Design Layouts
You will find the layouts in the code.
3. Write Code
Code is written in Kotlin in this case.
(a). Fragment1.kt
Here is the code for the first fragment.
(b). Fragment2.kt
Add the following code in second fragment.
(c). ScndActivity.kt
Then the second activity.
(d). MainActivity.kt
And lastly the main activity,
Demo
Here is what you get when you run the project.
Download
Android Shared Element Transition
Oclemy
Java Shared Transition with Fragments and FloatingActionButton This is a simple one-class example to utilize a shared element transition within fragments in an android activity. The programming language is Java. While it is not written in androidx, you can easily update it to androidx fragments andRead more
Java Shared Transition with Fragments and FloatingActionButton
This is a simple one-class example to utilize a shared element transition within fragments in an android activity. The programming language is Java. While it is not written in androidx, you can easily update it to androidx fragments and it doesn’t utilize any third partt library.
shared
Transitions
These are written in XML. Tyically you create a transition resource directory and place the XML.
(a). shared_enter_transition.xml
Here is the code:
Activities
Here are the activities
(a). MainActivity.java
Here is the main activity:
Demo
Here is the demo of what you get when you run the project.
Download Links
Android Email
Oclemy
EmailIntentBuilder This an Android Library for the creation of SendTo Intents with mailto: URI. Step 1 - Installation Install the library by adding the following statement in your build.gradle file: implementation 'de.cketti.mailto:email-intent-builder:2.0.0' Step 2 Then set the appropriateRead more
EmailIntentBuilder
This an Android Library for the creation of SendTo Intents with mailto: URI.
Step 1 – Installation
Install the library by adding the following statement in your build.gradle file:
Step 2
Then set the appropriate fields to be sent:
FULL EXAMPLE
Here is a full example to use this library to send email:
(a). MainActivity.java
Download
Here are the links:
Android Uri
Oclemy
PickiT This is an Android library that you can use to return real paths from Uri's. Follow the following steps to use it. Step 1 - Installation The library is hosted in jitpack so go to your project-level build.gradle and specify jitpack URL: allprojects { repositories { ... maven { url 'httRead more
PickiT
This is an Android library that you can use to return real paths from Uri’s.
Follow the following steps to use it.
Step 1 – Installation
The library is hosted in jitpack so go to your project-level build.gradle and specify jitpack URL:
Then go to your app level build.gradle and add the dependency then sync:
Step 2 – Usage
Implement PickiTCallback as follows:
Then:
So for example assume that using your Filepicker you’ve selected the file and now you want to convert the Uri to a real path inside the onActivityResult:
NB/= If you are targeting SDK 29> add
android:requestLegacyExternalStorage="true"
in your manifest:The reason for this is, in Android 10 file path access was removed and it returned in Android 11.
If you are targiting SDK 29> and you do not add this, you will get
EACCES (Permission denied)
FULL EXAMPLE
Here is a full example.
(a). MainActivity.java
Demo
Download
Here are the links:
Android Uri
Oclemy
Some Utility Uri Examples Here are some important utility methods you may need when coding. (a). Get Path from Uri You need to return a real path as a string and you have a Uri. public static String getPath(final Context context, final Uri uri) { //check for KITKAT or above final boolean isKitKat =Read more
Some Utility Uri Examples
Here are some important utility methods you may need when coding.
(a). Get Path from Uri
You need to return a real path as a string and you have a Uri.
(b). Get Data Column when given Uri
(c). Get Downloads Path
You have a Uri and you want to return the downloads path.
Here are more examples:
Download
Here are the links: