Skip to content

Instantly share code, notes, and snippets.

View oluwabajio's full-sized avatar

Ismail Osunlana oluwabajio

  • Tingtel
  • lagos
View GitHub Profile
@oluwabajio
oluwabajio / PathUtils.java
Created January 12, 2020 13:04 — forked from pratikbutani/PathUtils.java
Get Path from URI or URI from Path Utils.
public class PathUtils {
/**
* To get URI from Path
*
* @param context context
* @param file file
* @return Uri
*/
public static Uri getUriFromPath(Context context, File file) {
String filePath = file.getAbsolutePath();
@oluwabajio
oluwabajio / Mp3Decoder
Created January 12, 2020 13:42
Decode Mp3 File to byte Array for Audio Manipulation or play with AudioTrack - Android Studio.
public static byte[] decode(String path, int startMs, int maxMs)
throws IOException, com.mindtherobot.libs.mpg.DecoderException {
ByteArrayOutputStream outStream = new ByteArrayOutputStream(1024);
float totalMs = 0;
boolean seeking = true;
File file = new File(path);
InputStream inputStream = new BufferedInputStream(new FileInputStream(file), 8 * 1024);
try {
@oluwabajio
oluwabajio / Mp3Decoder.java
Last active April 2, 2022 11:25
Decode Mp3 File to byte Array for Audio Manipulation or play with AudioTrack - Android Studio. This is done using the java jlayer library.
public static byte[] decode(String path, int startMs, int maxMs)
throws IOException, com.mindtherobot.libs.mpg.DecoderException {
ByteArrayOutputStream outStream = new ByteArrayOutputStream(1024);
float totalMs = 0;
boolean seeking = true;
File file = new File(path);
InputStream inputStream = new BufferedInputStream(new FileInputStream(file), 8 * 1024);
try {
@oluwabajio
oluwabajio / Capture Full Screen Android
Created September 8, 2020 21:08
Capture Full Screen Android
private Bitmap captureScreen() {
View v = getWindow().getDecorView().getRootView();
v.setDrawingCacheEnabled(true);
Bitmap bmp = Bitmap.createBitmap(v.getDrawingCache());
v.setDrawingCacheEnabled(false);
return bmp;
}
@oluwabajio
oluwabajio / Android Permission Helper Class
Last active April 26, 2021 12:10
Android Permission Helper Class
import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
@oluwabajio
oluwabajio / RealPathUtil.kt
Created April 4, 2021 18:27 — forked from MeNiks/RealPathUtil.kt
Kotlin code to get real path / sd card path from intent data while browsing file.
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
@oluwabajio
oluwabajio / AnimationHelper
Created April 4, 2021 23:35
Animation Helper class
public class AnimatorHelper {
private static final int DURATION_LIST = 700;
public static void buttonVanish(View... views){
for(final View view:views){
view.setEnabled(false);
view.animate()
.scaleX(0)
.scaleY(0)
@oluwabajio
oluwabajio / Bitmap from uri
Created April 26, 2021 12:43
Bitmap from uri
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), clipData.getItemAt(i).getUri());
binding.imgLogo.setImageBitmap(bitmap);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
private void saveVideo(Uri uri) {
String videoFileName = "video_" + System.currentTimeMillis() + ".mp4";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
ContentValues valuesvideos = new ContentValues();
valuesvideos.put(MediaStore.Video.Media.RELATIVE_PATH, Environment.DIRECTORY_MOVIES + "VidFolder");
valuesvideos.put(MediaStore.Video.Media.TITLE, videoFileName);
valuesvideos.put(MediaStore.Video.Media.DISPLAY_NAME, videoFileName);
valuesvideos.put(MediaStore.Video.Media.MIME_TYPE, "video/mp4");
//time conversion
public String timeConversion(long value) {
String videoTime;
int dur = (int) value;
int hrs = (dur / 3600000);
int mns = (dur / 60000) % 60000;
int scs = dur % 60000 / 1000;
if (hrs > 0) {
videoTime = String.format("%02d:%02d:%02d", hrs, mns, scs);