Skip to content

Commit

Permalink
Create separate activity for each functionality
Browse files Browse the repository at this point in the history
* Get bitmap from PDF

* Bitmap of PDF

* Delete deploymentTargetDropDown.xml

* Delete gradle.xml

* Delete misc.xml

* Bitmap of PDF

* Bitmap of PDF

* Updated

* Update runConfigurations.xml

* Update runConfigurations.xml

* Update runConfigurations.xml

* Changes done

* Get Youtube video thumbnail

* Youtube video thumbnail

* Delete gradle.xml

* Delete misc.xml

* Youtube video thumbnail

* Update MainActivity.kt

* Update activity_main.xml

* Update Previewer.kt

* Update strings.xml

* Update build.gradle

* Changes done

* Remove gradle.xml & runConfigurations.xml from changelog

* Changes in comments and tried using URL

* Add suspend function for fetching thumbnail

* Return null instead of throwing exception

Co-authored-by: arpit <arpitshukla62@gmail.com>

* Reformat files

Co-authored-by: Raina Jain <84968175+RainaJain5@users.noreply.github.com>
Co-authored-by: arpit <arpitshukla62@gmail.com>

* Add support for generating video thumbnail

* Added glide dependency

* Added support for generating video thumbnail

* added necessary imports

* Bitmap of PDF

* Delete deploymentTargetDropDown.xml

* Delete gradle.xml

* Delete misc.xml

* Bitmap of PDF

* Bitmap of PDF

* Updated

* Update runConfigurations.xml

* Update runConfigurations.xml

* Update runConfigurations.xml

* Changes done

* Added Demo code to get video from storage and show its thumbnail

* removed blank line

* removed .asBitmap()

* removed Previewer.init() call from MainActivity.kt

* Implemented viewBinding

* Removed unused imports

* renamed getVideoThumbnail function to setVideoThumbnailFromUri

* renamed activityLauncher to activityResultLauncherForVideoUri

* added code to demonstrate creation of thumbnail from Internet Video

* added empty line after declaration

* renamed uriVideo to videoUri

* Removed redundant code

* Added internet permission

* Fixed the typo

* Reformat files

Co-authored-by: ayushigupta931 <ayushigupta931@gmail.com>
Co-authored-by: Ayushi Gupta <85010904+ayushigupta931@users.noreply.github.com>
Co-authored-by: arpit <arpitshukla62@gmail.com>

* Create separate activities for all functions

* change image view size

* apply suggested changes

* Apply suggestions

Co-authored-by: Ayushi Gupta <85010904+ayushigupta931@users.noreply.github.com>
Co-authored-by: Raina Jain <84968175+RainaJain5@users.noreply.github.com>
Co-authored-by: arpit <arpitshukla62@gmail.com>
Co-authored-by: Puranjay Khanijo <85157266+puranjayK@users.noreply.github.com>
Co-authored-by: ayushigupta931 <ayushigupta931@gmail.com>
  • Loading branch information
6 people authored Dec 7, 2021
1 parent da2c5c0 commit d808763
Show file tree
Hide file tree
Showing 11 changed files with 418 additions and 151 deletions.
12 changes: 10 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cops.iitbhu.previewer">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".DemoApplication"
Expand All @@ -12,12 +12,20 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Previewer">
<activity
android:name=".VideoToBitmapActivity"
android:exported="false" />
<activity
android:name=".YoutubeVideoToBitmapActivity"
android:exported="false" />
<activity
android:name=".PdfToBitmapActivity"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Expand Down
57 changes: 8 additions & 49 deletions app/src/main/java/com/cops/iitbhu/previewer/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,71 +1,30 @@
package com.cops.iitbhu.previewer

import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import com.cops.iitbhu.previewer.databinding.ActivityMainBinding
import com.cops.iitbhu.previewer.lib.Previewer

class MainActivity : AppCompatActivity() {

private lateinit var binding: ActivityMainBinding

// private val activityResultLauncherForVideoUri =
// registerForActivityResult(ActivityResultContracts.GetContent()) { videoUri: Uri ->
// Previewer.setVideoThumbnailFromUri(videoUri, binding.imgThumbnail)
// }

private val getUriOfPdf =
registerForActivityResult(ActivityResultContracts.OpenDocument()) { uri ->

if (uri != null) {
val bitmap = Previewer.generateBitmapFromPdf(uri)
if (bitmap != null)
binding.img.setImageBitmap(bitmap)
else
Toast.makeText(this, "Unable to generate bitmap!", Toast.LENGTH_SHORT).show()
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)

binding.selectFile.setOnClickListener(View.OnClickListener {
getUriOfPdf.launch(arrayOf("application/pdf"))
})

binding.generateThumbnailForYoutube.setOnClickListener {
val youtubeLink = binding.youtubeLink.text.toString()

if (youtubeLink.isNotEmpty()) {
setThumbnail(youtubeLink)
// Previewer.setThumbnailFromYouTubeVideoUrl(youtubeLink, binding.img)
} else {
Toast.makeText(this, "Please enter valid Youtube URL", Toast.LENGTH_SHORT).show()
}
binding.pdf.setOnClickListener {
startActivity(Intent(this, PdfToBitmapActivity::class.java))
}

// binding.btnVideoThumbnailFromUri.setOnClickListener {
// activityResultLauncherForVideoUri.launch("video/*")
// }
//
// binding.btnVideoThumbnailFromUrl.setOnClickListener {
// Previewer.setVideoThumbnailFromUri(
// Uri.parse("https://assets.mixkit.co/videos/preview/mixkit-forest-stream-in-the-sunlight-529-large.mp4"),
// binding.imgThumbnail
// )
// }
}
binding.youtubeLink.setOnClickListener {
startActivity(Intent(this, YoutubeVideoToBitmapActivity::class.java))
}

private fun setThumbnail(youtubeLink: String) {
lifecycleScope.launchWhenCreated {
val bitmap = Previewer.getThumbnailFromVideoUrl(youtubeLink)
binding.img.setImageBitmap(bitmap)
binding.videoUri.setOnClickListener {
startActivity(Intent(this, VideoToBitmapActivity::class.java))
}
}
}
34 changes: 34 additions & 0 deletions app/src/main/java/com/cops/iitbhu/previewer/PdfToBitmapActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.cops.iitbhu.previewer

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
import com.cops.iitbhu.previewer.databinding.ActivityPdfToBitmapBinding
import com.cops.iitbhu.previewer.lib.Previewer

class PdfToBitmapActivity : AppCompatActivity() {
private lateinit var binding: ActivityPdfToBitmapBinding

private val getUriOfPdf =
registerForActivityResult(ActivityResultContracts.OpenDocument()) { uri ->
if (uri != null) {
val bitmap = Previewer.generateBitmapFromPdf(uri)
if (bitmap != null)
binding.image.setImageBitmap(bitmap)
else
Toast.makeText(this, "Unable to generate bitmap!", Toast.LENGTH_SHORT).show()
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityPdfToBitmapBinding.inflate(layoutInflater)
setContentView(binding.root)

binding.selectFile.setOnClickListener {
getUriOfPdf.launch(arrayOf("application/pdf"))
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.cops.iitbhu.previewer

import android.net.Uri
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.activity.result.contract.ActivityResultContracts
import androidx.lifecycle.lifecycleScope
import com.cops.iitbhu.previewer.databinding.ActivityVideoToBitmapBinding
import com.cops.iitbhu.previewer.lib.Previewer

class VideoToBitmapActivity : AppCompatActivity() {
private lateinit var binding: ActivityVideoToBitmapBinding

private val activityResultLauncherForVideoUri =
registerForActivityResult(ActivityResultContracts.GetContent()) { videoUri: Uri ->
val bitmap = Previewer.getThumbnailFromLocalVideoUri(videoUri)
binding.image.setImageBitmap(bitmap)
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityVideoToBitmapBinding.inflate(layoutInflater)
setContentView(binding.root)

binding.selectLocalVideo.setOnClickListener {
activityResultLauncherForVideoUri.launch("video/*")
}

binding.remoteVideo.setOnClickListener {
lifecycleScope.launchWhenCreated {
val url =
"https://assets.mixkit.co/videos/preview/mixkit-forest-stream-in-the-sunlight-529-large.mp4%22"
val bitmap = Previewer.getThumbnailFromRemoteVideoUri(url)
binding.image.setImageBitmap(bitmap)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.cops.iitbhu.previewer

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import androidx.lifecycle.lifecycleScope
import com.cops.iitbhu.previewer.databinding.ActivityYoutubeVideoToBitmapBinding
import com.cops.iitbhu.previewer.lib.Previewer

class YoutubeVideoToBitmapActivity : AppCompatActivity() {
private lateinit var binding: ActivityYoutubeVideoToBitmapBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityYoutubeVideoToBitmapBinding.inflate(layoutInflater)
setContentView(binding.root)

binding.generateThumbnailForYoutubeSuspendFunc.setOnClickListener {
val youtubeLink = binding.youtubeLink.text.toString()
if (youtubeLink.isNotEmpty()) {
setThumbnail(youtubeLink)
} else {
Toast.makeText(this, "Please enter valid Youtube URL", Toast.LENGTH_SHORT).show()
}
}

binding.generateThumbnailForYoutubeNonSuspendFunc.setOnClickListener {
val youtubeLink = binding.youtubeLink.text.toString()
if (youtubeLink.isNotEmpty()) {
Previewer.setThumbnailFromYouTubeVideoUrl(youtubeLink, binding.image)
} else {
Toast.makeText(this, "Please enter valid Youtube URL", Toast.LENGTH_SHORT).show()
}
}
}

private fun setThumbnail(youtubeLink: String) {
lifecycleScope.launchWhenCreated {
val bitmap = Previewer.getThumbnailFromYoutubeVideoUrl(youtubeLink)
binding.image.setImageBitmap(bitmap)
}
}
}
128 changes: 33 additions & 95 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,118 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:padding="10dp"
tools:context=".MainActivity">

<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/generate_pdf_bitmap"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
android:contentDescription="@string/img"
android:scaleType="centerCrop" />

<TextView
android:id="@+id/generate_pdf_bitmap"
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/select_file"
android:layout_centerHorizontal="true"
android:text="@string/bitmap_of_pdf"
android:textSize="20sp" />
android:layout_marginTop="40dp"
android:text="@string/previewer_demo_application"
android:textColor="@color/black"
android:textSize="26sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/select_file"
android:id="@+id/pdf"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:backgroundTint="@color/black"
android:text="@string/select_file" />

<TextView
android:id="@+id/thumbnail_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/select_file"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text="@string/thumbnail_of_youtube_video"
android:textAlignment="center"
android:textSize="20sp" />

<EditText
android:id="@+id/youtube_link"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/thumbnail_text"
android:hint="@string/youtube_link"
android:inputType="textUri"
android:textAlignment="center"
android:textSize="15sp" />
android:layout_marginTop="100dp"
android:text="@string/bitmap_from_pdf"
android:textColor="@color/white"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />

<Button
android:id="@+id/generate_thumbnail_for_youtube"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/youtube_link"
android:layout_centerInParent="true"
android:backgroundTint="@color/black"
android:text="@string/generate_thumbnail" />

<TextView
android:id="@+id/thumbnail_of_vdo"
android:id="@+id/youtube_link"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/generate_thumbnail_for_youtube"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text="@string/thumbnail_of_video"
android:textSize="20sp" />
android:layout_marginTop="50dp"
android:text="@string/bitmap_from_youtube"
android:textColor="@color/white"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/pdf" />

<Button
android:id="@+id/select_video"
android:id="@+id/video_uri"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/thumbnail_of_vdo"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:backgroundTint="@color/black"
android:text="@string/select_video" />


<!-- <Button-->
<!-- android:id="@+id/btnVideoThumbnailFromUri"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_marginBottom="150dp"-->
<!-- android:text="Video Thumbnail\nfrom Storage"-->
<!-- android:textAllCaps="false"-->
<!-- app:layout_constraintBottom_toBottomOf="parent"-->
<!-- android:layout_marginStart="16dp"-->
<!-- app:layout_constraintStart_toStartOf="parent" />-->
<!-- <Button-->
<!-- android:id="@+id/btnVideoThumbnailFromUrl"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_marginBottom="152dp"-->
<!-- android:text="Video Thumbnail\nfrom URL"-->
<!-- android:textAllCaps="false"-->
<!-- app:layout_constraintBottom_toBottomOf="parent"-->
<!-- android:layout_marginStart="16dp"-->
<!-- app:layout_constraintStart_toEndOf="@id/btnVideoThumbnailFromUri" />-->

<!-- <ImageView-->
<!-- android:id="@+id/imgThumbnail"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- app:layout_constraintBottom_toBottomOf="parent"-->
<!-- app:layout_constraintEnd_toEndOf="parent"-->
<!-- app:layout_constraintStart_toStartOf="parent"-->
<!-- app:layout_constraintTop_toTopOf="parent" />-->
android:layout_marginTop="50dp"
android:text="@string/bitmap_of_video"
android:textColor="@color/white"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/youtube_link" />

</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Loading

0 comments on commit d808763

Please sign in to comment.