Skip to content

Instantly share code, notes, and snippets.

View chiragthummar's full-sized avatar
🎯
Focusing

Chirag Thummar chiragthummar

🎯
Focusing
View GitHub Profile
@chiragthummar
chiragthummar / GeneratePDF.kt
Created April 11, 2024 04:06
Create pdf from your text
private fun GeneratePDF() {
try {
val path =
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
.toString() + "/MyPDF"
val file = File(path, "my_file.pdf")
val pdfWriter = PdfWriter(file)
val pdfDocument = PdfDocument(pdfWriter)
import android.content.ContentValues.TAG
import android.util.Log
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
@Composable
fun Stack018() {
val textToDraw =
val imageLoader = ImageLoader.Builder(context)
.components {
add(VideoFrameDecoder.Factory())
}.crossfade(true)
.build()
val painter = rememberAsyncImagePainter(
model = state.galleryFiles[page].uri,
imageLoader = imageLoader,
)
import android.content.Context
import android.webkit.JavascriptInterface
import android.widget.Toast
class JavaScriptInterface {
private val context : Context
constructor(context : Context){
import android.webkit.WebView
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.viewinterop.AndroidView
@Composable
fun WebViewCommunication(modifier: Modifier = Modifier) {
Column(modifier = Modifier.fillMaxSize()){
<!DOCTYPE >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function init()
{
var testVal = 'Hello Android !!';
AndroidFunction.showToast(testVal);
}
@Composable
fun MyListView(
images: List<Image>
) {
LazyVerticalGrid(
contentPadding = PaddingValues(4.dp),
columns = GridCells.Fixed(2),
modifier = Modifier.fillMaxSize()
) {
items(images, key = {
@OptIn(ExperimentalMaterial3Api::class, ExperimentalComposeUiApi::class)
@Composable
fun HomeScreen(state: HomeScreenState, onEvent: (HomeScreenEvents) -> Unit) {
val keyboardManager = LocalSoftwareKeyboardController.current
Scaffold(topBar = {
TopAppBar(
title = {
Text(text = "MVI App", color = MaterialTheme.colorScheme.onPrimary)
@HiltViewModel
class HomeScreenViewModel @Inject constructor(
private val imageRepository: ImageRepository
) : ViewModel() {
var state by mutableStateOf(HomeScreenState())
private set
fun onEvent(event: HomeScreenEvents) {
when (event) {
@Module
@InstallIn(SingletonComponent::class)
abstract class RepositoryModule {
@Binds
@Singleton
abstract fun bindImageRepository(
imageRepositoryImpl: ImageRepositoryImpl
): ImageRepository
}