tag:blogger.com,1999:blog-52157774275120854702024-03-13T22:29:14.857+05:30Android Developers BlogAndroid developer blog for beginners - Learn Android Programming and how to develop android app. It covers Android programming tutorials, with complete source code available for download, also android tutorial with full example, including Android UI controls, layouts, and solution of all development related issue.Mukesh Kumarhttp://www.blogger.com/profile/02072401063614368529noreply@blogger.comBlogger126125tag:blogger.com,1999:blog-5215777427512085470.post-22968046682027683322023-07-03T22:15:00.007+05:302023-07-03T22:19:44.595+05:30JetPack Compose: Basic TextView Sample in JetPack Compose<p> Hi All,</p><p> This is the very basic Text View Sample Jetpack compose. </p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyYx1sfg0F36sPGcmRaznHqC-RGRE_9GutA6ecjaE5xpUdaJEcGBoSlBOvpAtsUTBqURZFWCeb-PUyvKBDJCQywJeF9O7ZRVYbB8RWX0SGstbVGjSgyovtTyF1ZOWy0iDW6nDTSGsJVeOij7Dhk13e1QRoHPp_S1y8G_ksMmpkG531uhyoSyhhFFy9ays/s1300/1_2v6zotc8p-bt9oX2mI0vkQ.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" data-original-height="400" data-original-width="1300" height="82" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyYx1sfg0F36sPGcmRaznHqC-RGRE_9GutA6ecjaE5xpUdaJEcGBoSlBOvpAtsUTBqURZFWCeb-PUyvKBDJCQywJeF9O7ZRVYbB8RWX0SGstbVGjSgyovtTyF1ZOWy0iDW6nDTSGsJVeOij7Dhk13e1QRoHPp_S1y8G_ksMmpkG531uhyoSyhhFFy9ays/w268-h82/1_2v6zotc8p-bt9oX2mI0vkQ.png" width="268" /></a></div><p></p><b><div><b><br /></b></div>1. Text Color:</b> Change the text color using color parameter
<pre>@Composable
fun ColorText() {
Text("Text in Red Color", color = Color.Red , modifier = Modifier
.padding(8.dp) // margin
.padding(8.dp) // padding
)
}
<b>2. Text Size:</b> Change the text size using fontSize parameter
<pre>@Composable
fun TextWithSize(label : String, size : TextUnit) {
Text(label, fontSize = size)
}
//TextWithSize("Big text",40.sp) -- call this method
</pre>
<b>3.Bold Text:</b> Use fontWeight parameter to making the bold text
<pre>@Composable
fun BoldText() {
Text("Text in Bold", fontWeight = FontWeight.Bold, modifier = Modifier
.padding(8.dp) // margin
.padding(8.dp)) // padding
}
</pre>
<b>4. Italic Text:</b> Use fontStyle paramter to making the italic text
<pre>@Composable
fun ItalicText() {
Text("Italic Text", fontStyle = FontStyle.Italic, modifier = Modifier
.padding(8.dp) // margin
.padding(8.dp)) // padding
}
</pre>
<b>5. Maximum number of lines:</b> To limit the number of visible lines in a
Text composable, set the maxLines parameter,
<pre>@Composable
fun MaxLines() {
Text("Text with Max line 2 ".repeat(50), maxLines = 2, modifier = Modifier
.padding(8.dp) // margin
.padding(8.dp)) // padding
}
</pre>
<b>6. Text Overflow:</b> When limiting a long text, you may want to indicate
a text overflow, which is only shown if the displayed text is truncated.
To do so, set the textOverflow parameter
<pre>@Composable
fun OverflowedText() {
Text("Text with three dot at end, Text Overflow ".repeat(150),
maxLines = 3, overflow = TextOverflow.Ellipsis,
modifier = Modifier
.padding(8.dp)) // margin
}
</pre>
<br />
Download code from <a href="https://github.com/mukesh4u/Jetpack-Compose-TextViewSample">here</a>
<br /><br /></pre>Mukesh Kumarhttp://www.blogger.com/profile/02072401063614368529noreply@blogger.com0tag:blogger.com,1999:blog-5215777427512085470.post-55696224467510661462021-10-21T14:51:00.011+05:302021-10-21T17:26:04.399+05:30Splash Screen API in Android 12 | Android 12 Splash Screen Example | Splash screens in Android 12 | Splash screen demo Using Splash Screen API | Splash Screen API Example<div style="text-align: left;"> <span style="font-family: inherit;">Hi All,</span></div><div style="text-align: left;"><span style="font-family: inherit;"> Today I am going to share a tutotial and a sample demo of Android 12 </span></div><div style="text-align: left;"><span style="font-family: inherit;">Splash Screen Api. Android 12 Splash screen api introduce in Android 12.</span></div><div style="text-align: left;"><span style="font-family: inherit;"><br /></span></div><div style="text-align: left;"><span style="font-family: inherit;">Android 12 adds the SplashScreen API, which enables a new app launch animation</span></div><div style="text-align: left;"><span style="font-family: inherit;">for all apps when running on a device with Android 12 or higher. This includes an</span></div><div style="text-align: left;"><span style="font-family: inherit;">into-app motion at launch, a splash screen showing your app icon, and a transition</span></div><div style="text-align: left;"><span style="font-family: inherit;">to your app itself. </span></div><div style="text-align: left;"><span style="font-family: inherit;"><br /></span></div><div style="text-align: left;"><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_aZvt2wM31WzDoElYTB_lBK5R7yGEM9TPf3XRsjovdyWp03KdVda0XaM3_8XlTyIh4XeXtPZYeFZviW5ZCYADGEARc0jMOtjEeduWFxb-UKljFBWutpcrrSp6rT-4pxcUckIuC3E-MaE/s1386/splash-screen-gmail-example.gif" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1386" data-original-width="640" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_aZvt2wM31WzDoElYTB_lBK5R7yGEM9TPf3XRsjovdyWp03KdVda0XaM3_8XlTyIh4XeXtPZYeFZviW5ZCYADGEARc0jMOtjEeduWFxb-UKljFBWutpcrrSp6rT-4pxcUckIuC3E-MaE/w296-h640/splash-screen-gmail-example.gif" width="296" /></a></div><br /><span style="font-family: inherit;"><br /></span></div><div style="text-align: left;"><br /></div><div style="text-align: left;"><span style="font-family: inherit;"><b>Note: </b>As Splash Screen introduced in Android 12 so it will work on Android </span></div><div style="text-align: left;"><span style="font-family: inherit;">Api level 31 and above. </span></div><div style="text-align: left;"><br /></div><div style="text-align: left;"><b><span style="font-family: inherit;">We can Customize the Splash Screen Theme:</span></b></div><div style="text-align: left;"><span style="font-family: inherit;"><span style="font-weight: bold;"> </span><span style="font-weight: bold;"> </span><span style="font-weight: bold;"> </span><b> - </b>With the help of below attribute we can customize our Splash activity theme.</span></div><div style="text-align: left;"><span style="font-family: inherit;"><br /></span></div><div style="text-align: left;"><span style="font-family: inherit;">1.<b> </b><span color="var(--devsite-code-strings-color)"><b>android:windowSplashScreenBackground : </b>Used for Splash Screen background color.</span></span></div><div style="text-align: left;"><span style="font-family: inherit;"><span color="var(--devsite-code-strings-color)"><br /></span></span></div><div style="text-align: left;"><span color="var(--devsite-code-strings-color)"><span style="font-family: inherit;">
<pre class="java" name="code"><!--splash screen background color-->
<item name="android:windowSplashScreenBackground">#FFFFFF</item>
</pre>
<br /></span></span></div><div style="text-align: left;"><span style="font-family: inherit;">2. <span color="var(--devsite-code-strings-color)"><b>android:windowSplashScreenAnimatedIcon</b>: Used </span>to replace an icon in</span></div><div style="text-align: left;"><span style="font-family: inherit;">the center </span><span style="font-family: inherit;">of the starting window. If the object is animatable and drawable through </span><b style="font-family: inherit;">AnimationDrawable </b><span style="font-family: inherit;">and </span><b style="font-family: inherit;">AnimatedVectorDrawable</b><span style="font-family: inherit;">, you also need to set windowSplashScreenAnimationDuration to play the animation while showing the</span></div><div style="text-align: left;"><span style="font-family: inherit;">starting window.</span></div>
<pre class="java" name="code"><!--provide animatedly drawable-->
<item name="android:windowSplashScreenAnimatedIcon">
@drawable/splash_screen_animateable_icon
</item>
</pre>
3. <span color="var(--devsite-code-strings-color)" style="font-size: 14px;"><b>android:windowSplashScreenAnimationDuration : </b>Used </span><span style="font-size: 14px;">to indicate the duration of the splash screen icon animation. Max duration is 1000ms.</span><div><span style="font-size: 14px;"><br /></span></div><div><span style="font-size: 14px;"><br /></span></div><div><span style="font-size: 14px;">
<pre class="java" name="code"><!--max duration is 1000ms-->
<item name="android:windowSplashScreenAnimationDuration">800</item>
</pre>
<br />4. </span><span color="var(--devsite-code-strings-color)" style="font-size: 14px;"><b>android:windowSplashScreenIconBackgroundColor :</b> Used</span><span style="font-size: 14px;"> to set a background behind</span></div><div><span style="font-size: 14px;"> the splash screen icon. This is useful if there isn’t enough contrast between the window</span></div><div><span style="font-size: 14px;"> background and the icon.</span></div><div><span style="font-size: 14px;"><br /></span></div><div><span style="font-size: 14px;">
<pre class="java" name="code"><!--icon background color-->
<item name="android:windowSplashScreenIconBackgroundColor">#004d28</item>
</pre>
<br /></span></div><div><span style="font-size: 14px;">5. <span color="var(--devsite-code-strings-color)"><b>android:windowSplashScreenBrandingImage: </b></span></span><span style="font-size: 14px;">We can use this to set an image to be shown at the bottom of the splash screen. The design guidelines recommend against using a branding image.</span></div><div><span style="font-size: 14px;"><br /></span></div><div><span style="font-size: 14px;">
<pre class="java" name="code"><!--splash screen branding image-->
<item name="android:windowSplashScreenBrandingImage">@drawable/ic_logo_12</item>
</pre>
<br /></span></div><h1 style="text-align: left;"><span style="font-size: 14px;"><b>Keep the splash screen on-screen for longer periods:</b></span></h1><div><span style="font-size: 14px;"><div>The splash screen is dismissed as soon as your app draws its first frame. If you need to load a small amount of data such as in-app settings from a local disk asynchronously, you can use ViewTreeObserver.OnPreDrawListener to suspend the app to draw its first frame.</div><div><br /></div><div>If your starting activity finishes before drawing (for example, by not setting the content view and finishing before onResume), the pre-draw listener is not needed.</div><div><br /></div><div><br /></div><div><br /></div></span></div><div><span style="font-size: 14px;">
<pre class="java" name="code">override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
mainViewModel = ViewModelProvider(this).get(MainViewModel::class.java)
content = findViewById(android.R.id.content)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
Log.d("MainActivity", "onCreate: I AM RUNNING ON API 12 or higher")
content.viewTreeObserver.addOnPreDrawListener(object :
ViewTreeObserver.OnPreDrawListener {
override fun onPreDraw(): Boolean =
when {
mainViewModel.mockDataLoading() -> {
content.viewTreeObserver.removeOnPreDrawListener(this)
true
}
else -> false
}
})
}
} </pre></span></div><b>
Customizing Splash Screen Animation: </b>In Android 12 we get the Splash screen <div>instance by calling getSplashScreen() from Activity class. So we can further customize</div><div>the animation of the splash screen through <b>Activity.getSplashScreen().</b><div>
<pre class="java" name="code"> splashScreen.setOnExitAnimationListener { splashScreenView ->
val slideUp = ObjectAnimator.ofFloat(
splashScreenView,
View.TRANSLATION_Y,
0f,
-splashScreenView.height.toFloat()
)
slideUp.interpolator = AnticipateInterpolator()
slideUp.duration = 200L
// Call SplashScreenView.remove at the end of your custom animation.
slideUp.doOnEnd { splashScreenView.remove() }
// Run your animation.
slideUp.start()
}
</pre>
<b>Code: MainActivity.kt</b></div><div><b>
<pre class="java" name="code">package com.example.android12splashscreenapi
import android.animation.ObjectAnimator
import android.os.Build
import android.os.Bundle
import android.util.Log
import android.view.View
import android.view.ViewTreeObserver
import android.view.animation.AnticipateInterpolator
import androidx.appcompat.app.AppCompatActivity
import androidx.core.animation.doOnEnd
import androidx.lifecycle.ViewModelProvider
class MainActivity : AppCompatActivity() {
lateinit var content: View
lateinit var mainViewModel: MainViewModel
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
mainViewModel = ViewModelProvider(this).get(MainViewModel::class.java)
content = findViewById(android.R.id.content)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
Log.d("MainActivity", "onCreate: I AM RUNNING ON API 12 or higher")
content.viewTreeObserver.addOnPreDrawListener(object :
ViewTreeObserver.OnPreDrawListener {
override fun onPreDraw(): Boolean =
when {
mainViewModel.mockDataLoading() -> {
content.viewTreeObserver.removeOnPreDrawListener(this)
true
}
else -> false
}
})
// custom exit on splashScreen
splashScreen.setOnExitAnimationListener { splashScreenView ->
val slideUp = ObjectAnimator.ofFloat(
splashScreenView,
View.TRANSLATION_Y,
0f,
-splashScreenView.height.toFloat()
)
slideUp.interpolator = AnticipateInterpolator()
slideUp.duration = 200L
// Call SplashScreenView.remove at the end of your custom animation.
slideUp.doOnEnd { splashScreenView.remove() }
// Run your animation.
slideUp.start()
}
}
}
}
</pre>
<br /></b></div><div><b><br /></b></div><div><b><br />
Reference</b>:</div><div>1.<a href=" https://developer.android.com/guide/topics/ui/splash-screen#suspend-drawing"> https://developer.android.com/guide/topics/ui/splash-screen#suspend-drawing</a></div><div><br /></div><div><b>Note</b>: For updating/migraating your older app for Android 12 please check below</div><div>tutorial.</div><div>1.<a href=" https://developer.android.com/guide/topics/ui/splash-screen/migrate"> https://developer.android.com/guide/topics/ui/splash-screen/migrate</a></div><div><br /></div><div><br /></div><div>Download Complete Code <a href="https://github.com/mukesh4u/Android12SplashScreenApiSample">Here</a></div><div>Hope this will help Someone.</div><div>Enjoy Coding .......................... :)</div><div><br /></div><div><br /></div><div><br /></div></div>Mukesh Kumarhttp://www.blogger.com/profile/02072401063614368529noreply@blogger.com0tag:blogger.com,1999:blog-5215777427512085470.post-11435362968546395212021-09-28T22:29:00.002+05:302021-09-28T22:31:30.776+05:30Android Jetpack Compose Toolbar example | Jetpack Compose TopAppBar<div>Hi Friends,</div><div> Many of us looking for Toolbar example in Jetpack Compose or</div><div>TopAppBar example in Jetpack compose. Today I am going to share you </div><div>a sample which helps you in creating Toolbar in Jetpack compose.</div><div>Also in this tutoriail I am providing you how to create toolbar menu item using</div><div>JetPack Compose.</div><div><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEt784IVrlxKWeYSXGAcdtPLHra-1AMdfIqIqTVtsMRfpOnvnZjGGmGE8fQebCaHqlfWKyWKTrNlkYr7y4CXD6OPPQq_67oIp70V7HzOxnv0hi8HAHRbv6bD2eCwbwbTDzxEy5kSrhJEY/s846/toolbar.PNG" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="846" data-original-width="403" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEt784IVrlxKWeYSXGAcdtPLHra-1AMdfIqIqTVtsMRfpOnvnZjGGmGE8fQebCaHqlfWKyWKTrNlkYr7y4CXD6OPPQq_67oIp70V7HzOxnv0hi8HAHRbv6bD2eCwbwbTDzxEy5kSrhJEY/w298-h400/toolbar.PNG" width="298" /></a></div><div class="separator" style="clear: both; text-align: center;"><br /></div><div class="separator" style="clear: both; text-align: left;"><b>Source Code:</b></div><div class="separator" style="clear: both; text-align: left;"><br /></div><br /> <script src="https://gist.github.com/mukesh4u/3c9f9e486d268b968fc7a6788c50b06c.js"></script><div><div><b>Complete Activity class</b><br /><script src="https://gist.github.com/mukesh4u/1e360b0dade00556ea43e680d2f7a523.js"></script></div><br /><br />Download code from <a href="https://github.com/mukesh4u/JetpackComposeToolbar" target="_blank">here</a></div><div><br /></div><div>Hope this will help someone.</div><div>Enjoy Coding............... :)</div><div><br /></div>Mukesh Kumarhttp://www.blogger.com/profile/02072401063614368529noreply@blogger.com0tag:blogger.com,1999:blog-5215777427512085470.post-73634928213543608612021-09-28T13:06:00.001+05:302021-09-28T13:09:56.291+05:30Android Jetpack Compose Dropdown menu Example | Dropdown menu using DropdownMenu Composable<div style="text-align: left;"><b>Dropdown menu:</b></div><div style="text-align: left;"><span style="font-weight: bold;"> </span><b> </b>We are going to use<b> DropdownMenu</b> Composable for creating dropdown menu.</div><div style="text-align: left;"><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjd3tLJy28PAMCju5h24IJCqKcHSjGIn2w_GXy5hYMajFMMSQPLkHdDW29PpZeUAHC8eVtGVdnuzG3oLrO8T7b8uAWtKCsq_z_9wDFQTHDCD2kB4AmmDKkNK5za2MP3TpRPTgmaKHlP8jk/s851/dropdownmenu.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="851" data-original-width="418" height="286" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjd3tLJy28PAMCju5h24IJCqKcHSjGIn2w_GXy5hYMajFMMSQPLkHdDW29PpZeUAHC8eVtGVdnuzG3oLrO8T7b8uAWtKCsq_z_9wDFQTHDCD2kB4AmmDKkNK5za2MP3TpRPTgmaKHlP8jk/w253-h286/dropdownmenu.PNG" width="253" /></a></div><br /><div style="text-align: left;"><br /></div><div style="text-align: left;"><pre style="background-color: white; font-family: "JetBrains Mono", monospace; font-size: 9.8pt;"><span style="color: navy; font-weight: bold;">fun </span>DropdownMenu(<br /> expanded: Boolean,<br /> onDismissRequest: () -> Unit,<br /> modifier: Modifier = Modifier,<br /> offset: DpOffset = DpOffset(<span style="color: blue;">0</span>.dp, <span style="color: blue;">0</span>.dp),<br /> properties: PopupProperties = PopupProperties(<span style="color: #4a86e8;">focusable = </span><span style="color: navy; font-weight: bold;">true</span>),<br /> content: @Composable ColumnScope.() -> Unit<br />)</pre><br />In Above code if <b>expanded</b> is true, the popup menu with dropdown content will be shown.</div><div style="text-align: left;"><b>onDismissRequest</b> will be called when the menu should be dismiss,</div><div style="text-align: left;"><pre>@Composable
fun DropdownDemo() {
var expanded by remember { mutableStateOf(false) }
val items = listOf(
"Apple", "Banana", "Cherry", "Grapes",
"Mango", "Pineapple", "Pear"
)
var selectedIndex by remember { mutableStateOf(0) }
Column(
modifier = Modifier
.fillMaxSize()
.wrapContentSize(Alignment.TopStart)
.padding(all = 5.dp)
) {
Text(
items[selectedIndex],
modifier = Modifier
.fillMaxWidth()
.clickable(onClick = { expanded = true })
.background(
Color.Red
),
color = Color.White,
fontSize = 20.sp,
textAlign = TextAlign.Start
)
DropdownMenu(
expanded = expanded,
onDismissRequest = { expanded = false },
modifier = Modifier
.fillMaxWidth()
.background(
Color.Gray
)
) {
items.forEachIndexed { index, s ->
DropdownMenuItem(onClick = {
selectedIndex = index
expanded = false
}) {
Text(text = s)
}
}
}
}
}</pre><br />Hope this will help someone.<br />Enjoy Coding.......... :)
</div>Mukesh Kumarhttp://www.blogger.com/profile/02072401063614368529noreply@blogger.com0tag:blogger.com,1999:blog-5215777427512085470.post-89256384703926739512021-09-24T17:37:00.000+05:302021-09-26T07:56:55.234+05:30Android Jetpack Compose Button Example | How to center a button in jetpack Compose | How to onclick listener on button in Jetpack ComposeHi Friends,<div> Today I am sharing a Sample of Jetpack Compose Button view. I will show you how</div><div>to set onclick listener on button in Jetpack Compose. How to style on Button in</div><div>Jetpack Compse , how to set height and width of button in Jetpack compose.</div><div><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwFgQjKn33k0SKTcqwVKyRqJSPk-4tOsnzkBE1NZc7drUAsQBOyZjOFYMJ-7o2PQrXiADX7-sGl3kQli_7bqzUuG6zbr0I5YXap8tEJWmnIOCkyJWt0DS3GHQ6scpCoZnHGeY1Zji41Lc/s861/button.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="861" data-original-width="423" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwFgQjKn33k0SKTcqwVKyRqJSPk-4tOsnzkBE1NZc7drUAsQBOyZjOFYMJ-7o2PQrXiADX7-sGl3kQli_7bqzUuG6zbr0I5YXap8tEJWmnIOCkyJWt0DS3GHQ6scpCoZnHGeY1Zji41Lc/w196-h400/button.PNG" width="196" /></a></div><div class="separator" style="clear: both; text-align: left;"> <b> Code:</b></div><div class="separator" style="clear: both; text-align: left;"><b> </b></div><div class="separator" style="clear: both; text-align: left;"><br /><script src="https://gist.github.com/mukesh4u/31dc71a0adf7e5fc24a4e0887f23cee8.js"></script></div><div class="separator" style="clear: both; text-align: left;"><b> </b>Hope this will help someone.</div><div class="separator" style="clear: both; text-align: left;"><b> </b>Enjoy Coding........... :)<b> </b></div><div class="separator" style="clear: both; text-align: left;"><b><br /></b></div><div class="separator" style="clear: both; text-align: left;"><br /></div><div class="separator" style="clear: both; text-align: left;"><br /></div><br /><div><br /></div>Mukesh Kumarhttp://www.blogger.com/profile/02072401063614368529noreply@blogger.com2tag:blogger.com,1999:blog-5215777427512085470.post-50256809576966373802021-09-24T17:35:00.002+05:302021-09-28T13:35:13.144+05:30Android Jetpack compose- Android Listview using Jetpack compose | Jetpack compose listview clicklistener<div style="text-align: left;"> Hello all, </div><div style="text-align: left;"><span> </span><span> Today I am going to share my anothere Android Jetpack Compose tutoria.</span><br /></div><div style="text-align: left;"><span>How to set clicklistener on listview in android Jetpack Compses, how to set </span>clicklistener </div><div style="text-align: left;">on button using Jetpack Compse.<div class="separator" style="clear: both; text-align: center;"><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghNIGVcyiLTsFDLKaZZkCvoXqZMm37L0AB0UjbZvX5Dk6aYUQ8n3tyw6wyHomjfCmecTkGYgMoh6SFD1eB2IqAA_secQYITOqaDbgHpHTMrn4sDGetPegx3sQLpn_FDXD-G07G7Qdi8Qw/s1300/1_2v6zotc8p-bt9oX2mI0vkQ.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="400" data-original-width="1300" height="61" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghNIGVcyiLTsFDLKaZZkCvoXqZMm37L0AB0UjbZvX5Dk6aYUQ8n3tyw6wyHomjfCmecTkGYgMoh6SFD1eB2IqAA_secQYITOqaDbgHpHTMrn4sDGetPegx3sQLpn_FDXD-G07G7Qdi8Qw/w200-h61/1_2v6zotc8p-bt9oX2mI0vkQ.png" width="200" /></a></div></div><br /><br /><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3tc1x7H-dsRTaUUQ7rElGblGM-wKxzUD2mnEsBKtssNzfTzNL7_xQeAQ9II0S2Yun6TgTaWN8H1G3Yn2IHqANE_S0zj_SVFeCukWhAhDSuMiYZasBn_4690jhFU5z_ddz0g5o56tOpL8/s853/Capture.PNG" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" data-original-height="853" data-original-width="413" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3tc1x7H-dsRTaUUQ7rElGblGM-wKxzUD2mnEsBKtssNzfTzNL7_xQeAQ9II0S2Yun6TgTaWN8H1G3Yn2IHqANE_S0zj_SVFeCukWhAhDSuMiYZasBn_4690jhFU5z_ddz0g5o56tOpL8/s320/Capture.PNG" width="155" /></a></div><div style="text-align: left;"><br /></div><div style="text-align: left;">I am sharing below code where I am handling list item click in jetpack compose.</div><div style="text-align: left;"><br /></div><div style="text-align: left;">
<script src="https://gist.github.com/mukesh4u/b2ebf8b7aa3e1c1e7c405911f7f76e0a.js"></script><br/>
<div style="text-align: left;"> Downlaod complete code from <a href="https://github.com/mukesh4u/JetPackComposeList">here</a></div><div style="text-align: left;">Hope this will help someone.</div><div style="text-align: left;">Enjoy Coding....... :)</div>Mukesh Kumarhttp://www.blogger.com/profile/02072401063614368529noreply@blogger.com0tag:blogger.com,1999:blog-5215777427512085470.post-2254107161327267462021-09-24T13:09:00.002+05:302021-09-26T23:18:26.077+05:30Android Jetpack Compose Alert Dialog Sample | Jetpack Compose Dialog<div style="text-align: left;"> Hi Friends, </div><div style="text-align: left;"><span> </span><span> </span><span> </span><span> </span>Today I am sharing the Jetpack Compse Alert Dialog Sample.</div><div style="text-align: left;"><br /></div><div style="text-align: left;"><b>What is Alert Dialog?</b></div><div style="text-align: left;"><span style="background-color: white;"></span><span style="background-color: white; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;">- Alert dialog is a Dialog which interrupts the user with </span></div><div style="text-align: left;"><span style="background-color: white; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;">urgent information, details or actions.</span></div><div style="text-align: left;"><span style="background-color: white; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><br /></span></div><div style="text-align: left;"><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTcEZnOYu1JgthrSLZMirZYMxK4UdAUSqIiR77C1loGEqeFCN6ZWRWIBlPNDHoENZlCYstohSockpmWBWBgUCweEvDwTQHYRcdYD1OqxCTwri0WSrXeZ6Vx00x0hJRl4TDdKPwpgYgIJM/s846/alert+dialog.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="846" data-original-width="420" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTcEZnOYu1JgthrSLZMirZYMxK4UdAUSqIiR77C1loGEqeFCN6ZWRWIBlPNDHoENZlCYstohSockpmWBWBgUCweEvDwTQHYRcdYD1OqxCTwri0WSrXeZ6Vx00x0hJRl4TDdKPwpgYgIJM/w199-h400/alert+dialog.PNG" width="199" /></a></div><div style="text-align: left;"><br /></div><b>Code:</b></div><div style="text-align: left;"><br /><script src="https://gist.github.com/mukesh4u/31dc71a0adf7e5fc24a4e0887f23cee8.js"></script></div><div style="text-align: left;">Hope this will help someone.</div><div style="text-align: left;">Enjoy Coding........ :)</div><div style="text-align: left;"><br /></div><div style="text-align: left;"><b><br /></b><span style="background-color: white; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><br /></span></div>Mukesh Kumarhttp://www.blogger.com/profile/02072401063614368529noreply@blogger.com0tag:blogger.com,1999:blog-5215777427512085470.post-60544838122829880402021-09-23T22:12:00.001+05:302021-09-23T22:12:51.597+05:30How to get Context in Jetpack Compose<div style="text-align: left;">Hello All,</div><div style="text-align: left;"><span> </span><span> </span><span> Many of us facing issue in using/getting context in JetPack Compose.</span></div><div style="text-align: left;"><span>Here I am sharing a composbale function where I am using context for showing toast message.</span></div><div style="text-align: left;"><span><br /></span></div><div style="text-align: left;"><span> </span>
<script src="https://gist.github.com/mukesh4u/57f56fc3386fc47a8c4f5527d953f9ec.js"></script><br /></div>Mukesh Kumarhttp://www.blogger.com/profile/02072401063614368529noreply@blogger.com0tag:blogger.com,1999:blog-5215777427512085470.post-46683714195470289922021-09-23T20:54:00.000+05:302021-09-23T20:54:49.588+05:30Android Jetpack Compose- An easy way to RecyclerView | How to create a RecyclerView in Jetpack Compose | LazyColumn-JetPack Compose<div style="text-align: left;"> Hello Friends,</div><div style="text-align: left;"><span> </span><span> Today I am going to share a my another JetPack Compose tutorial.</span><br /></div><div style="text-align: left;"><span>Here I am going to share you the creation of listview/recyclerview using </span></div><div style="text-align: left;"><span>Compose.</span></div><div style="text-align: left;"><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyjE7fWvA0HQOrB6dYXPCBaD1tWTwvHb3DP4IJwqfEUMGs2aajpOOE_2QvUhIjAzaG9D7Ctxaenq06aNGeDD1pJOMNXPMq-K8fHC8RLTFNZbcPNwRwZxl1JkamWMbK97TWTB84XAnXjT4/s853/Capture.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="853" data-original-width="413" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyjE7fWvA0HQOrB6dYXPCBaD1tWTwvHb3DP4IJwqfEUMGs2aajpOOE_2QvUhIjAzaG9D7Ctxaenq06aNGeDD1pJOMNXPMq-K8fHC8RLTFNZbcPNwRwZxl1JkamWMbK97TWTB84XAnXjT4/w194-h400/Capture.PNG" width="194" /></a></div><br /><span><br /></span></div><div style="text-align: left;"><span><br /></span></div><div style="text-align: left;"><span><b>Creating a listview/recyclerview in Compose:</b></span></div><div style="text-align: left;"><span><b><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span> <span> </span><span> </span><span> </span></span></b></span>Creating a listview/recyclerview in Compose is easy.</div><div style="text-align: left;">No Adapter. No View holder.</div><div style="text-align: left;"><br /></div><div style="text-align: left;"><br /></div><div style="text-align: left;"><b>What is LazyColumn?</b></div><div style="text-align: left;"><b>-</b> A <span style="color: #2b00fe;">LazyColumn</span> is a vertically scrolling list that only composes and lays out the currently visible items. It’s similar to a Recyclerview in the classic Android View system.</div><div style="text-align: left;"><br /></div><div style="text-align: left;">
<script src="https://gist.github.com/mukesh4u/49a6ac7044c01ed2fcdbf31f92a699dc.js"></script>
<br /></div><div>Download code from <a href="https://github.com/mukesh4u/JetPackComposeList" target="_blank">here</a></div>Hope this will help someone.<div>Enjoy Coding......................... :)</div><div><br /></div>Mukesh Kumarhttp://www.blogger.com/profile/02072401063614368529noreply@blogger.com0tag:blogger.com,1999:blog-5215777427512085470.post-28875335752355145952021-09-22T14:45:00.005+05:302021-09-22T14:57:32.724+05:30Android Jetpack- Jetpack cardview sample<div style="text-align: left;"> Hi All,</div><div style="text-align: left;"><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipVjLmZq8NJHW1UV8AbVr0bftzyznMfZ7vkF1Zp3C3xDOj0xUQR79qaLsfWxIw-L1LXEivivzSjAsw-pAs67jD5HoqPTdlfH7bGqe61pZQUZCB2bAFv7Kk58NfKKKsSVd7zWzxqp6uyYc/s1300/1_2v6zotc8p-bt9oX2mI0vkQ.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" data-original-height="400" data-original-width="1300" height="98" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipVjLmZq8NJHW1UV8AbVr0bftzyznMfZ7vkF1Zp3C3xDOj0xUQR79qaLsfWxIw-L1LXEivivzSjAsw-pAs67jD5HoqPTdlfH7bGqe61pZQUZCB2bAFv7Kk58NfKKKsSVd7zWzxqp6uyYc/w320-h98/1_2v6zotc8p-bt9oX2mI0vkQ.png" width="320" /></a></div> Today I am going to share <b>Jetpack</b> <b>CardView</b> sample. Here I am going to create a simple android cardview UI withoutt using the android Xml and layout editor.</div><div style="text-align: left;"><br /></div><div style="text-align: left;">We are going to build the UI using <b>Composable funtion(</b>i.e: using <b>Jetpack</b> <b>Compse</b>).</div><div style="text-align: left;"><br /></div><div style="text-align: left;"><b>Column : </b> We are going to use <b>Column</b> <b>function</b> for arranging the view vertically.</div><div style="text-align: left;">For arranging the view horizontally you can use <b>Row</b> <b>function</b>.</div><div style="text-align: left;"><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBe66KNG948n914j803PII6mKBqlrCfuV_GaZMXfw_tK1hpzQ3blrK62CMvNpAN_7yatY_knpxB821gHiW-tzTmzQRdoEk7HlZ2k-iz8S0zGISRVr4D1Ew54qzKG-s3tcX90RChhjIOIg/s838/Capture.PNG" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="838" data-original-width="403" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBe66KNG948n914j803PII6mKBqlrCfuV_GaZMXfw_tK1hpzQ3blrK62CMvNpAN_7yatY_knpxB821gHiW-tzTmzQRdoEk7HlZ2k-iz8S0zGISRVr4D1Ew54qzKG-s3tcX90RChhjIOIg/w193-h400/Capture.PNG" width="193" /></a></div><div class="separator" style="clear: both; text-align: center;"> </div><div class="separator" style="clear: both; text-align: left;"><br /></div><div class="separator" style="clear: both; text-align: left;"> <b>Check MainActivity.kt file for Code,</b></div><br /><div style="text-align: left;"><br /></div>
<script src="https://gist.github.com/mukesh4u/22e099feabc279341376eb280d2c5581.js"></script><br />Download complete code <a href="https://github.com/mukesh4u/JetPackCardView" target="_blank">here</a><div><br /><div>
Hope this will help someone.<br />Enjoy coding.... :)
</div></div>Mukesh Kumarhttp://www.blogger.com/profile/02072401063614368529noreply@blogger.com0tag:blogger.com,1999:blog-5215777427512085470.post-48631085221469630842021-09-21T21:31:00.007+05:302021-09-22T14:54:29.187+05:30Android Jetpack- Composable functions<div style="text-align: left;"><span style="background-color: white; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><b><br /></b></span></div><div style="text-align: left;"><span style="background-color: white; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi65V99FQOhd1xJmLIbg5QTyQ7zqIC19yVqLIxZKADyl8MH9dG6391cZ0J8L9difs-EqrN_RR8bj6jVuVF7Jc_MO7icI3B1Uz8WFFEJECzv4SVdJKmER9IcRKbiS2pWnDI-_J11M0NvTYI/s1300/1_2v6zotc8p-bt9oX2mI0vkQ.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="400" data-original-width="1300" height="122" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi65V99FQOhd1xJmLIbg5QTyQ7zqIC19yVqLIxZKADyl8MH9dG6391cZ0J8L9difs-EqrN_RR8bj6jVuVF7Jc_MO7icI3B1Uz8WFFEJECzv4SVdJKmER9IcRKbiS2pWnDI-_J11M0NvTYI/w400-h122/1_2v6zotc8p-bt9oX2mI0vkQ.png" width="400" /></a></div><br /><b><br /></b></span></div><div style="text-align: left;"><span style="background-color: white; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><b>Jetpack Compose</b> is built around composable functions. These functions </span></div><div style="text-align: left;"><span style="background-color: white; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;">let you define your app's UI programmatically by describing how it</span></div><div style="text-align: left;"><span style="background-color: white; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;">should look and </span><span style="background-color: white; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;">providing data dependencies, rather than </span></div><div style="text-align: left;"><span style="background-color: white; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;">focusing on the process of </span><span style="background-color: white; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;">the UI's construction (initializing an </span></div><div style="text-align: left;"><span style="background-color: white; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;">element, attaching </span><span style="background-color: white; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;">it to a parent, etc.).</span></div><div style="background-color: white; font-family: Consolas, "Courier New", monospace; font-size: 14px; line-height: 19px; white-space: pre;"><div>To create a composable function, just add the <b>@Composable</b> annotation</div><div>to the function name.</div></div><div><br /><br /><script src="https://gist.github.com/mukesh4u/44002a1254467c3da98ac50b92d9fd8a.js"></script></div><br /><br />
Enjoy Coding.... :)Mukesh Kumarhttp://www.blogger.com/profile/02072401063614368529noreply@blogger.com0tag:blogger.com,1999:blog-5215777427512085470.post-2079952217298220032021-09-04T22:35:00.001+05:302021-09-04T22:35:20.320+05:30Android Jetpack Compose-Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8<div style="text-align: left;"> Hi All, </div><div> Many of us facing below issue while running the Android Jetpack </div><div>Compose Project.</div><div><br /></div><div><pre class="default s-code-block" style="border-radius: 5px; border: 0px; box-sizing: inherit; font-family: var(--ff-mono); font-size: 13px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: 1.30769; margin-bottom: calc(var(--s-prose-spacing) + 0.4em); margin-top: 0px; max-height: 600px; overflow-wrap: normal; overflow: auto; padding: 12px; vertical-align: baseline; width: auto;"><code class="hljs language-erlang" style="border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;"><span style="color: red;"><b>> Failed to apply plugin 'com.android.internal.application'.
> Android Gradle plugin requires Java <span class="hljs-number" style="border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">11</span> to run. You are currently using Java <span class="hljs-number" style="border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">1.8</span>.
You can <span class="hljs-keyword" style="border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">try</span> some <span class="hljs-keyword" style="border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">of</span> the following options:
- changing the IDE settings.
- changing the JAVA_HOME environment variable.
- changing `org.gradle.java.home` in `gradle.properties`.</b></span></code></pre><div><br /></div>In order to fix this issue we need to use Java 11. You can find it in Preferences > Build, Execution, Deployment > Build Tools > Gradle > Gradle JDK.</div><div><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEguB1bkvgCyR-uTUrxqD-44V4_JPziVbfOmvRGxW5cq8rHTBEXJqv0NQhGUDAgdHSzqWMEHp2RRURwaIvRXprX-RN3c_AhYwTapaLBbsaawGORk2Dvm8UAe5Vv6CIhj33FPWswdram0Qxw/s1219/jdk11+error.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="803" data-original-width="1219" height="286" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEguB1bkvgCyR-uTUrxqD-44V4_JPziVbfOmvRGxW5cq8rHTBEXJqv0NQhGUDAgdHSzqWMEHp2RRURwaIvRXprX-RN3c_AhYwTapaLBbsaawGORk2Dvm8UAe5Vv6CIhj33FPWswdram0Qxw/w523-h286/jdk11+error.png" width="523" /></a></div><div class="separator" style="clear: both; text-align: center;"><br /></div><div class="separator" style="clear: both; text-align: center;"><br /></div><div class="separator" style="clear: both; text-align: left;">Hope this will help some one.</div><div class="separator" style="clear: both; text-align: left;">Enjoy Coding....... :)</div><br /><div><br /><pre class="default s-code-block" style="border-radius: 5px; border: 0px; box-sizing: inherit; font-family: var(--ff-mono); font-size: 13px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: 1.30769; margin-bottom: calc(var(--s-prose-spacing) + 0.4em); margin-top: 0px; max-height: 600px; overflow-wrap: normal; overflow: auto; padding: 12px; vertical-align: baseline; width: auto;"><code class="hljs language-erlang" style="border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;"><span style="color: red;"><b><br /></b></span></code></pre></div>Mukesh Kumarhttp://www.blogger.com/profile/02072401063614368529noreply@blogger.com0tag:blogger.com,1999:blog-5215777427512085470.post-6280099759398898792021-09-01T23:22:00.006+05:302021-09-04T22:42:03.445+05:30Android Jetpack Compose- Android Studio with Jetpack Compose Getting Started | Jetpack Compose Tutoria <div style="text-align: left;"><br /></div><div style="text-align: left;">Hi All,</div><div style="text-align: left;"> </div>Today I am going to share my first JetPack Compose Tutorial. Here we learn how\nto setup android compose in android studio. We see the rquired dependency and other settings.<div><br /></div><div><b>Step 1: Installation:</b> First we have to download <a href="https://www.blogger.com/#">Android Studio Arctic Fox</a>. That’s because when we use Android Studio to develop our app with Jetpack Compose, we can benefit from <a href="https://www.blogger.com/#">smart editor features</a>, such as New Project templates and the ability to immediately <br />preview our Compose UI.</div><div><span face="Roboto, "Noto Sans", "Noto Sans JP", "Noto Sans KR", "Noto Naskh Arabic", "Noto Sans Thai", "Noto Sans Hebrew", "Noto Sans Bengali", sans-serif" style="background-color: white; color: #202124; font-size: 16px;"><br /></span></div><div><span face="Roboto, "Noto Sans", "Noto Sans JP", "Noto Sans KR", "Noto Naskh Arabic", "Noto Sans Thai", "Noto Sans Hebrew", "Noto Sans Bengali", sans-serif" style="background-color: white; color: #202124; font-size: 16px;">Step2: <b>Create android app : </b> After the installint of latest android studio from link<b> </b>now lets </span></div><div><span face="Roboto, "Noto Sans", "Noto Sans JP", "Noto Sans KR", "Noto Naskh Arabic", "Noto Sans Thai", "Noto Sans Hebrew", "Noto Sans Bengali", sans-serif" style="background-color: white; color: #202124; font-size: 16px;">create an app.</span></div><div><ul style="text-align: left;"><li><span face="Roboto, "Noto Sans", "Noto Sans JP", "Noto Sans KR", "Noto Naskh Arabic", "Noto Sans Thai", "Noto Sans Hebrew", "Noto Sans Bengali", sans-serif" style="background-color: white; color: #202124; font-size: 16px;">Open <b>Android Studio</b> > select <span style="box-sizing: inherit; font-weight: 700;">File > New > New Project</span> from the menu bar. </span></li><li style="box-sizing: inherit; margin: 12px 0px; padding: 0px;">In the <span style="box-sizing: inherit; font-weight: 700;">Select a Project Template</span> window, select <span style="box-sizing: inherit; font-weight: 700;">Empty Compose Activity</span> and click <span style="box-sizing: inherit; font-weight: 700;">Next</span>.</li><li style="box-sizing: inherit; margin: 12px 0px; padding: 0px;">In the <span style="box-sizing: inherit; font-weight: 700;">Configure your project</span> window, do the following:<ol style="box-sizing: inherit; list-style: outside lower-alpha; margin: 0px; padding-left: 40px;"><li style="box-sizing: inherit; margin: 12px 0px; padding: 0px;">Set the <span style="box-sizing: inherit; font-weight: 700;">Name</span>, <span style="box-sizing: inherit; font-weight: 700;">Package name</span>, and <span style="box-sizing: inherit; font-weight: 700;">Save location</span> as you normally would.</li><li style="box-sizing: inherit; margin: 12px 0px; padding: 0px;">Note that, in the <span style="box-sizing: inherit; font-weight: 700;">Language</span> dropdown menu, <span style="box-sizing: inherit; font-weight: 700;">Kotlin</span> is the only available option because Jetpack Compose works only with classes written in Kotlin.</li><li style="box-sizing: inherit; margin: 12px 0px; padding: 0px;">In the <span style="box-sizing: inherit; font-weight: 700;">Minimum API level dropdown</span> menu, select API level 21 or higher.</li></ol></li><li>Click <span style="box-sizing: inherit; font-weight: 700;">Finish</span>. </li></ul><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFGMTXS99AEAcglCPefVrH293bsmKUv5GIeAYLrwasS9VcpC0vrj7O6pv7pEK-cZICJqzVvj57FaiW0ATL0zb7xhaun23GaS_7JTO0qeOS-Zu3LTqyjv_4-McLjbqc_AgWDMTgW04VYxw/s1219/compose_template.PNG" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="795" data-original-width="1219" height="261" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFGMTXS99AEAcglCPefVrH293bsmKUv5GIeAYLrwasS9VcpC0vrj7O6pv7pEK-cZICJqzVvj57FaiW0ATL0zb7xhaun23GaS_7JTO0qeOS-Zu3LTqyjv_4-McLjbqc_AgWDMTgW04VYxw/w400-h261/compose_template.PNG" width="400" /></a></div><div class="separator" style="clear: both; text-align: center;"><br /></div><div class="separator" style="clear: both; text-align: left;"> You can see below dependecny in your app <b>build.gradle</b> file which is required for Compose.</div><div class="separator" style="clear: both; text-align: left;"> </div><div class="separator" style="clear: both;"> <div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTR3uGBQ2i94hDNNdAfuZyXLJtlo6DDJKAoFmnAq5mOpj_ULgVs5TsJ2XrGt0oZJsHv6huAs4Yqp3PXociKUaCCR6oAqVpmKutIBr9EIne04Us8LpRJhH6T0IqUijN2pExJJjFjQj0A2w/s737/compose_template3.PNG" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="286" data-original-width="737" height="155" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTR3uGBQ2i94hDNNdAfuZyXLJtlo6DDJKAoFmnAq5mOpj_ULgVs5TsJ2XrGt0oZJsHv6huAs4Yqp3PXociKUaCCR6oAqVpmKutIBr9EIne04Us8LpRJhH6T0IqUijN2pExJJjFjQj0A2w/w400-h155/compose_template3.PNG" width="400" /></a></div><br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqrr-dnzBw-nOXHHzMF2s1KubU6-EfqMPpc9VMuu6YLz04ukGVjPpw7wFH7Fe25tajo1KzKTuzuJVen3EXvxKF_uREd7EZWA0-7-F0Rk1zcMe7Nguik6yPhMh2yYtUK_HGLQKwFfwv8n0/s861/compose_template2.PNG" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="425" data-original-width="861" height="198" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqrr-dnzBw-nOXHHzMF2s1KubU6-EfqMPpc9VMuu6YLz04ukGVjPpw7wFH7Fe25tajo1KzKTuzuJVen3EXvxKF_uREd7EZWA0-7-F0Rk1zcMe7Nguik6yPhMh2yYtUK_HGLQKwFfwv8n0/w400-h198/compose_template2.PNG" width="400" /></a></div><div class="separator" style="clear: both; text-align: center;"><br /></div><div class="separator" style="clear: both; text-align: left;"> For more check this <a href="https://developer.android.com/jetpack/compose/setup?authuser=2#sample" target="_blank">tutorial</a></div><div class="separator" style="clear: both; text-align: left;"><br /></div><div class="separator" style="clear: both; text-align: left;">While setting it if you are facing issue of <span style="color: red;">"Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8". </span>Plesase check this <a href="https://www.androiddevelopersolutions.com/2021/09/android-jetpack-compose-android-gradle.html" target="_blank">tutorial</a></div><div class="separator" style="clear: both; text-align: left;"><br /></div><div class="separator" style="clear: both; text-align: left;">Hope this will help some one.</div><div class="separator" style="clear: both; text-align: left;">Enjoy Coding....... :)</div><div class="separator" style="clear: both; text-align: left;"><br /></div></div>Mukesh Kumarhttp://www.blogger.com/profile/02072401063614368529noreply@blogger.com0tag:blogger.com,1999:blog-5215777427512085470.post-80825181463926341212020-05-11T23:03:00.004+05:302020-05-11T23:09:54.313+05:30Kotlin - Enum Classes in Kotlin | Enum Methods | Enum Properties<div dir="ltr" style="text-align: left;" trbidi="on">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgq2pnhi2L4JtHX3OaKxEo6v6dfZhT_UhjmWwswA8JuNXAkcQKBJVc_GWPEht0HKVWXwXIs7Gq6Ky2_mgvafGdEbONM9LmTVmG_EaxWjeAqHHTe4hf4L7sfCR_3XzQ_taZHVCTaCpqO5Hc/s1600/download.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" data-original-height="225" data-original-width="225" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgq2pnhi2L4JtHX3OaKxEo6v6dfZhT_UhjmWwswA8JuNXAkcQKBJVc_GWPEht0HKVWXwXIs7Gq6Ky2_mgvafGdEbONM9LmTVmG_EaxWjeAqHHTe4hf4L7sfCR_3XzQ_taZHVCTaCpqO5Hc/s200/download.jpg" width="200" /></a>Hello Friend,<br />
Today I am going to share about Enum class in Kotlin<br />
<br />
<br />
- How to create/initialize enum classes<br />
- methods and properties of enum classes.<br />
<br />
<br />
<br />
<b>Initializing enums –</b><br />
<br />
<script src="https://gist.github.com/mukesh4u/9d00a60454540a18db21dd69533ee838.js"></script>
<br />
Now we can easily access the color of fruits,<br />
<script src="https://gist.github.com/mukesh4u/6629d1878d73c8d7d23cb09f8a6a0eb5.js"></script>
<b>Enum Methods-</b><br />
<br />
<ol style="text-align: left;">
<li><b>values</b>: This method returns a list of all the constants defined within the enum class.</li>
<li><b>valueOf</b>: This methods returns the enum constant defined in enum, matching the input string. If the constant, is not present in the enum, then an IllegalArgumentException is thrown.</li>
</ol>
<br />
<b>Enum Properties-</b><br />
<br />
<ol style="text-align: left;">
<li><b>ordinal: </b>This property stores the ordinal value of the constant, which is usually a zero-based index.</li>
<li><b>name</b>: This property stores the name of the constant.</li>
</ol>
<div>
Below is the example which help us to understand the uses of Enum method and Properties.</div>
<div>
<script src="https://gist.github.com/mukesh4u/d53812ee68d104da0155c53b882df4c8.js"></script>
</div>
<div>
Outputs:
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEivWfsIiL_lyo3f480-9IR79pnpyF21oOgVUnZrRNbNIBMjSN4WfX4CoADyoZgN0CWyypkBGWXDUDOYa2RfzKavECa8cBGDYpe4HniwGU7O6Hr1nrK1WzUkgadkNBph-KoiEAm2EZ4vGHk/s1600/Capture.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="265" data-original-width="898" height="117" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEivWfsIiL_lyo3f480-9IR79pnpyF21oOgVUnZrRNbNIBMjSN4WfX4CoADyoZgN0CWyypkBGWXDUDOYa2RfzKavECa8cBGDYpe4HniwGU7O6Hr1nrK1WzUkgadkNBph-KoiEAm2EZ4vGHk/s400/Capture.PNG" width="400" /></a></div>
<br />
Hope this will help some one.<br />
Enjoy Coding... :)
</div>
Mukesh Kumarhttp://www.blogger.com/profile/02072401063614368529noreply@blogger.com0tag:blogger.com,1999:blog-5215777427512085470.post-84012992978225073982020-05-11T15:44:00.000+05:302020-05-11T16:00:27.788+05:30Kotlin - Android notification in kotlin | Android MVP in Kotlin<div dir="ltr" style="text-align: left;" trbidi="on">
Hello Friends,<br />
Lets first tell you what is notification.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUarui5AVaCFdyTJL9RrzjJ1PbPfclmbUmAfSG8FzdiNHNUvm0mBIfyKCFhv6XdJJtgm4PBXVbgsQH6NYWjQQ16fb13wzv_XsvoA-sA5dFYESqwkKUM2CexuYlpTWlMOOc5vxwQ0hwvG8/s1600/android-software-development-kotlin-mobile-app-development-java-png-favpng-X0wXNu6XMsar3s2Emu2stttCS.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="574" data-original-width="820" height="224" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUarui5AVaCFdyTJL9RrzjJ1PbPfclmbUmAfSG8FzdiNHNUvm0mBIfyKCFhv6XdJJtgm4PBXVbgsQH6NYWjQQ16fb13wzv_XsvoA-sA5dFYESqwkKUM2CexuYlpTWlMOOc5vxwQ0hwvG8/s320/android-software-development-kotlin-mobile-app-development-java-png-favpng-X0wXNu6XMsar3s2Emu2stttCS.jpg" width="320" /></a></div>
<br />
<b>Notification </b>is a message that is used to display some short messages outside of our main application. Even if the app is not running, notifications will still work. Notifications have the following contents: an icon, title of notification and some text content.<br />
<br />
Now today I am going to share , how create notification in Kotlin.<br />
<br />
<script src="https://gist.github.com/mukesh4u/50fa140ad149ac281b205ce136834de3.js"></script>
Download code from <a href="https://github.com/mukesh4u/KotlinNotification" target="_blank">here</a><br />
Hope this will helps someone..<br />
Enjoy Coding.... :)</div>
Mukesh Kumarhttp://www.blogger.com/profile/02072401063614368529noreply@blogger.com0tag:blogger.com,1999:blog-5215777427512085470.post-6242355447239845112020-01-03T22:07:00.000+05:302020-01-03T22:12:31.225+05:30Mobile World : The next version of Android is officially Android 11 | About android 11 release in 2020 | Android 11 name | Features coming in Android 11 <div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPEWH5PUO5ODOeboBUMHwx3dVhFzyDh8OzLfQNbiB-75ctb4FXF8229mUrfefMf6C8ywQ013DZ6y5BAb3VBEzUNVlO7L0EN6OFbWBM-Q7-4wUwKFtea4KMCnZmrdFsWlFQoG_gIxPQY8c/s1600/android-11.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="900" data-original-width="1600" height="225" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPEWH5PUO5ODOeboBUMHwx3dVhFzyDh8OzLfQNbiB-75ctb4FXF8229mUrfefMf6C8ywQ013DZ6y5BAb3VBEzUNVlO7L0EN6OFbWBM-Q7-4wUwKFtea4KMCnZmrdFsWlFQoG_gIxPQY8c/s400/android-11.jpg" width="400" /></a></div>
<br />
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;"><span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;">Android 11:<span style="mso-spacerun: yes;"> </span>Next Alphabet R Android 11 soon to Arrive<o:p></o:p></span></b></div>
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;"><span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><br /></span></b></div>
<div class="MsoNormal">
<span lang="EN-IN" style="line-height: 115%;">Google is all set to introduce <b style="mso-bidi-font-weight: normal;">Android 11</b> after success of its Android 9 and Android 10 in queue. Much
of the information is not disclosed for now but is awaited and speculation is
that Android 11 will be more oriented on dual display. <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;"><span lang="EN-IN" style="line-height: 115%;">Android</span></b><span lang="EN-IN" style="line-height: 115%;"> <b style="mso-bidi-font-weight: normal;">launch
date</b> is expected around September 2020 but rumours had started already. <b style="mso-bidi-font-weight: normal;">Android 11</b> will be available for
free.<span style="mso-spacerun: yes;"> </span>After Android Q version this
Android 11 will be called Android R as expected alphabetically. Also, the
trends of naming their android after desserts is also said to be maintained. <span style="mso-spacerun: yes;"> </span>Android 10 was in some non-Google company like
Oneplus 7T and 7T Pro but possibly it could be different for Android 11.
Although it will be available for smart phones who want to be upgrade possibly.<span style="font-size: 14pt;"><o:p></o:p></span></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;"><span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;">Android 11</span></b><span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"> in Smart phones<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="line-height: 115%;">If
to put in simple language Android is an open source operating system that
powers Google and Smart phones. Also, this operating system is based on a modified
version of the Linux Kernel. It’s a decade old and the most popular mobile
operating system in world.<span style="mso-spacerun: yes;"> </span><b style="mso-bidi-font-weight: normal;">Android 11</b> like other Android software
is for smart phones and tablets. Although to compare it with iPhones, Androids
varies a lot. But today both are multitasking. <b style="mso-bidi-font-weight: normal;">Android 11</b> like other old version will be empowering Samsung
series, Xperia, HTC series and many more.<span style="mso-spacerun: yes;">
</span>It is at least believes to be on pixel phones. <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;"><span lang="EN-IN" style="line-height: 115%;">Android 11 features<o:p></o:p></span></b></div>
<div class="MsoNormal">
<span lang="EN-IN" style="line-height: 115%;">Now
if talking about <b style="mso-bidi-font-weight: normal;">Android 11</b>
features, most of it is unknown for now and soon expected to be disclosed but
expectation are “Scoped Storage” which is supposed to be in Android 10 but
Google pushed it back due to complaints from Android developers. This feature
makes memory read speeds much quicker, improves security, and stops you needing
to give every new apps permission.<span style="mso-spacerun: yes;"> </span>Also
all those features which is gone missing or not as expected in Android 10 will
be anticipated to be there in Android 11. Just to name few:<o:p></o:p></span></div>
<br />
<br />
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<span lang="EN-IN" style="line-height: 115%;"><span style="color: blue;">1.<span style="mso-spacerun: yes;"> </span>Near field Communication (NFC)</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="line-height: 115%;">NFC
determines how your Android phone connects or interacts with the nearest
device. This connection does not depend on Wi-Fi, 3G or LTE.<span style="mso-spacerun: yes;"> </span>It helped users to share videos, photos,
music by not using any apps but by pressing phone against each other.<span style="mso-spacerun: yes;"> </span>But this feature is gone now and causes
hindrance to share. NFC is expected in Android 11 to get away with this problem
of sharing.<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="line-height: 115%;"><span style="color: blue;">2.
Improvement in Dark Mode</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="line-height: 115%;">Using
phone in darker made is a treat to eye. It makes different apps look way far
better than it is normally.<span style="mso-spacerun: yes;"> </span>Android 10
has lots of problem regarding it. Every app does not have to have its darker
mode feature, so if smart phone has it already it will reduce much inconvenience
of jumping to different apps. Also on apps that do have dark mode some text
aren’t colour wrapped and go invisible. Having better dark mode option is what
in line of expectation from <b style="mso-bidi-font-weight: normal;">Android 11.<o:p></o:p></b></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0Z9eN2BgHmJD-k_ILws6bdG6zWFprPlK4rVnGBNToBbkPeITrRwrrPrcOXdTRZbmM18WBVHDfbCtNssNBsznVcH6aDbmxVGpbAhdk_kbyYGCk56OK87bZ1uAM_9g5cpTbl9KjsbOpBs0/s1600/dark+mode.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="420" data-original-width="800" height="210" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0Z9eN2BgHmJD-k_ILws6bdG6zWFprPlK4rVnGBNToBbkPeITrRwrrPrcOXdTRZbmM18WBVHDfbCtNssNBsznVcH6aDbmxVGpbAhdk_kbyYGCk56OK87bZ1uAM_9g5cpTbl9KjsbOpBs0/s400/dark+mode.png" width="400" /></a></div>
<span lang="EN-IN" style="line-height: 115%;"><b style="mso-bidi-font-weight: normal;"><br /></b></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="line-height: 115%;"><b style="mso-bidi-font-weight: normal;"><br /></b></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="line-height: 115%;"><span style="color: blue;">3.
Easy access like “Chat bubbles”<span style="mso-spacerun: yes;"> </span></span><o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="line-height: 115%;">Chat
bubbles over the top of the apps which enables you to see your whole
conversations while you are on other apps. Isn’t amazing feature?<span style="mso-spacerun: yes;"> </span>Like Facebook messenger, it should be an <b style="mso-bidi-font-weight: normal;">Android feature</b> as well.<span style="mso-spacerun: yes;"> </span>It allows you to use other apps while
chatting. User does not have to dodge every time they get a message. It’s of
utmost use when we need notification while working on other apps. Especially
with Instagram, , Twitter, WhatsApp, Facebook . You can easily continue with
your conversation anytime.<o:p></o:p></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgWvyR6MIiU35egderOiZYXYwzTXbf2MoO4-gMAybgZX3rM-vm_1-tS9vdrLk_riSqywk-7O6te46JGe18Ofr1IfHeR-ePHcsxTKkw-YCIkH0W8R0Zbr8sVxxjB2Q0Oy0lN3reR5s7uGLA/s1600/chat+bubble.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="393" data-original-width="750" height="208" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgWvyR6MIiU35egderOiZYXYwzTXbf2MoO4-gMAybgZX3rM-vm_1-tS9vdrLk_riSqywk-7O6te46JGe18Ofr1IfHeR-ePHcsxTKkw-YCIkH0W8R0Zbr8sVxxjB2Q0Oy0lN3reR5s7uGLA/s400/chat+bubble.jpg" width="400" /></a></div>
<span lang="EN-IN" style="line-height: 115%;"><br /></span></div>
<br />
<br />
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;"><span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><span style="color: blue;">Android 11</span></span></b><span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><span style="color: blue;"> Updates over different
phones</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"> </span><span lang="EN-IN" style="line-height: 115%;"> So
the phone that going to have this Android version is:<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="line-height: 115%;"> </span><span lang="EN-IN" style="font-family: "wingdings"; line-height: 115%; text-indent: -0.25in;">Ø<span style="font-family: "times new roman"; font-stretch: normal; line-height: normal;"> </span></span><span lang="EN-IN" style="line-height: 115%; text-indent: -0.25in;">Nokia: After google, Nokia is the next original
equipment</span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="line-height: 115%; text-indent: -0.25in;"> Manufacturer (OEM) which is expected to do software</span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="line-height: 115%; text-indent: -0.25in;"> upgrade. </span><span style="text-indent: -0.25in;">Their 'Android R' OTA update is to be done </span></div>
<div class="MsoNormal">
<span style="text-indent: -0.25in;"> is –
Nokia 9 Pure View</span></div>
Nokia 6.2<br />
<div class="MsoListParagraphCxSpLast">
<span lang="EN-IN" style="line-height: 115%;">
Nokia 7.2<o:p></o:p></span></div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<span lang="EN-IN" style="line-height: 115%;"> </span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="line-height: 115%;"> </span><span lang="EN-IN" style="font-family: "wingdings"; line-height: 115%; text-indent: -0.25in;">Ø<span style="font-family: "times new roman"; font-stretch: normal; line-height: normal;"> </span></span><span lang="EN-IN" style="line-height: 115%; text-indent: -0.25in;">Samsung: Needless to mention that Samsung Galaxy S10
and </span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="line-height: 115%; text-indent: -0.25in;"> Samsung Galaxy Note 10 will going to be upgraded</span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="line-height: 115%; text-indent: -0.25in;"> to </span><b style="text-indent: -0.25in;"> Android 11 Features</b><span style="text-indent: -0.25in;">.</span></div>
<div class="MsoListParagraph" style="margin-left: 1.0in; mso-add-space: auto;">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN" style="line-height: 115%; text-indent: -0.25in;">
<span lang="EN-IN" style="font-family: "calibri" , "sans-serif"; line-height: 115%;"><span lang="EN-IN" style="line-height: 21.4667px;"> </span><span lang="EN-IN" style="font-family: "wingdings"; line-height: 21.4667px; text-indent: -0.25in;">Ø</span>Xiaomi: The MIUI 12 will be expected to be based on </span></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="line-height: 115%; text-indent: -0.25in;"><span lang="EN-IN" style="font-family: "calibri" , "sans-serif"; line-height: 115%;"> Android R version.</span></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="line-height: 115%; text-indent: -0.25in;"><span lang="EN-IN" style="font-family: "calibri" , "sans-serif"; line-height: 115%;"><br /></span></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="line-height: 115%; text-indent: -0.25in;"><span lang="EN-IN" style="font-family: "calibri" , "sans-serif"; line-height: 115%;"><br /></span></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="line-height: 115%; text-indent: -0.25in;"><span lang="EN-IN" style="font-family: "calibri" , "sans-serif"; line-height: 115%;"><br /></span></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="line-height: 115%; text-indent: -0.25in;"><span lang="EN-IN" style="font-family: "calibri" , "sans-serif"; line-height: 115%;">Hope you like this article.</span></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="line-height: 115%; text-indent: -0.25in;"><span lang="EN-IN" style="font-family: "calibri" , "sans-serif"; line-height: 115%;">Enjoy reading article :)</span></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14pt; line-height: 115%; text-indent: -0.25in;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14pt; line-height: 115%; text-indent: -0.25in;"> </span></div>
<br />
<div class="MsoListParagraphCxSpLast">
<br /></div>
<div class="MsoNormal">
</div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<br /></div>
</div>
Mukesh Kumarhttp://www.blogger.com/profile/02072401063614368529noreply@blogger.com0tag:blogger.com,1999:blog-5215777427512085470.post-87442605347861726272019-10-08T21:06:00.002+05:302020-07-27T23:11:41.783+05:30Android MVP template | Android MVP Plugin <div dir="ltr" style="text-align: left;" trbidi="on">
Hello Friends,<br />
Today I am sharing the android MVP template which make the development<br />
Faster. This is an android studio template inspired by android view-model template.<br />
<br />
When we follow Android MVP architecture in any project, for each module or feature<br />
we need to create an Activity/Fragment, a Presenter and a Contract class and also<br />
a layout file corresponding to them. This is really an time taking process.<br />
<br />
So Taking advantage of Android Studio template I created a MVP template<br />
which creates all this file at the start.<br />
<br />
<b><span style="font-family: "georgia" , "times new roman" , serif;">Getting Started</span></b><br />
<br />
<span style="font-family: inherit;">1. Download the MVPActivity Teamplate ,which you found at the bottom of this blog.</span><br />
<span style="font-family: inherit;">2. For <b>WINDOW</b>, </span>Just copy directory MVPActivity<br />
to <span style="font-size: x-small;">$ANDROID_STUDIO_FOLDER$\plugins\android\lib\templates\activities\</span><br />
<span style="font-family: inherit;">3. For <b>Mac,</b> </span><span style="font-family: inherit;"> </span>Just copy directory MVPActivity<br />
to<span style="font-size: x-small;"> $ANDROID_STUDIO_FOLDER$/Contents/plugins/android/lib/templates/activities/</span><br />
<div>
<span style="font-size: x-small;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='320' height='266' src='https://www.blogger.com/video.g?token=AD6v5dzA6u4r6oSdnpF6qN94_QpxX03RzyUy4ih05W5FKOBzqWibngAXTjDTTVHW37LFVhaJZOGRJoOolWCDX6ywqA' class='b-hbp-video b-uploaded' frameborder='0'></iframe></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
4. Below are the few common files,</div>
<div class="separator" style="clear: both; text-align: left;">
</div>
<b> A. template.xml</b><b> – </b>This will contain information about the template<br />
<div>
name, minSdkVersion, etc <b> </b><br />
<div>
<br />
<script src="https://gist.github.com/mukesh4u/cab49fe0aaf33c4ba9d94bded701480c.js"></script>
</div>
<br />
<b>B. recipe.xml.ftl</b> <b>-</b> This will contain instructions explaining how to<br />
create the template,
including what variables to ask the user for and<br />
what should be done with those variables.<br />
<script src="https://gist.github.com/mukesh4u/92afbed90144596f024827b3bb95d63c.js"></script>
<b>C. globals.xml.ftl</b> – This defines global variables<br />
<br />
<script src="https://gist.github.com/mukesh4u/4dacd4e79ac4b0d654d589aefbac16ac.js"></script>
<b>D. root/ folder – </b>this will contain the template code.
<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8vfIM973BV71lmt17XfD2sn3MgyzOmbK7Pd6j_s2aA-b2DAdppXM1MdlVysA5FgaJj0mJQi-q_xC0_cZ5uQQ37elCPaRdcPRRLVUoOdCwgrftsxzasrPdahzYsn03ztUgONkWBnAcyx8/s1600/mcp1.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="687" data-original-width="1033" height="211" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8vfIM973BV71lmt17XfD2sn3MgyzOmbK7Pd6j_s2aA-b2DAdppXM1MdlVysA5FgaJj0mJQi-q_xC0_cZ5uQQ37elCPaRdcPRRLVUoOdCwgrftsxzasrPdahzYsn03ztUgONkWBnAcyx8/s320/mcp1.PNG" width="320" /></a></div>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5DCOoR7roZrJMlbv7MPBW6WXH-Agg5hdubkjgmHEnpw9hhp-GIroy7MpPz48qoz2Qms-eFxXtz-F4I3WOUR4UqL3OMoWG6Yff4nurFoSy90NfbqLI_-7618fYR4y18m6Sx09X8IPYEsc/s1600/mvp2.PNG" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" data-original-height="610" data-original-width="476" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5DCOoR7roZrJMlbv7MPBW6WXH-Agg5hdubkjgmHEnpw9hhp-GIroy7MpPz48qoz2Qms-eFxXtz-F4I3WOUR4UqL3OMoWG6Yff4nurFoSy90NfbqLI_-7618fYR4y18m6Sx09X8IPYEsc/s320/mvp2.PNG" width="248" /></a><br />
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Download code from <a href="https://github.com/mukesh4u/MVPActivity" target="_blank">here</a></div>
<div class="separator" style="clear: both; text-align: left;">
Hope this will helps some one...</div>
<div class="separator" style="clear: both; text-align: left;">
Enjoy Coding........... :)</div>
<br /></div>
</div>
Mukesh Kumarhttp://www.blogger.com/profile/02072401063614368529noreply@blogger.com0tag:blogger.com,1999:blog-5215777427512085470.post-4731438720299941092019-10-07T18:07:00.002+05:302019-10-07T18:07:28.695+05:30Kotlin Android - RecyclerView Example<div dir="ltr" style="text-align: left;" trbidi="on">
Hello Friends,<br />
Today I am sharing the demo of <b><span style="color: blue;">RecyclerView</span></b> in Kotlin.<br />
A <b><span style="color: blue;">RecyclerView</span></b> is essentially a <b>ViewGroup </b>of containers called <b>ViewHolders </b>which<br />
populate a particular item.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgM4D9sGS5T6cEuJ3tlywEqFFelTdEpFH7lsOdAPrp55m_hBuGlavHynuYoDux_jDz7dWSafzTONK5k_d4B8AXc8oMqlmIwRkACPB0Nhx1BaoYi9QJZuoWqYfTT2ec2UDXkCJBskdGDdeY/s1600/recyclerview_kotlin.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="876" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgM4D9sGS5T6cEuJ3tlywEqFFelTdEpFH7lsOdAPrp55m_hBuGlavHynuYoDux_jDz7dWSafzTONK5k_d4B8AXc8oMqlmIwRkACPB0Nhx1BaoYi9QJZuoWqYfTT2ec2UDXkCJBskdGDdeY/s320/recyclerview_kotlin.png" width="175" /></a></div>
<br />
<br />
So lets first familiar with <b>RecyclerView </b>and What <b>RecyclerView </b>requires:<br />
1. It requires <b>a set of data objects</b> to work with<br />
2. An <b>xml file of the individual view item</b><br />
3. An <b>adapter </b>to bind that data to the views shown in the ViewHolders<br />
4. <b>ViewHolder </b>to populate the UI from the xml item file<br />
<br />
<u><br /></u>
<b><span style="font-family: "georgia" , "times new roman" , serif;"><u>Getting Started</u></span></b><br />
<script src="https://gist.github.com/mukesh4u/da5a7bf5b89084bc6b84085a4953071f.js"></script>
<br />
Download code from <a href="https://github.com/mukesh4u/KotlinExample">here</a><br />
Hope this will helps someone.<br />
Enjoy coding.... :)
</div>
Mukesh Kumarhttp://www.blogger.com/profile/02072401063614368529noreply@blogger.com0tag:blogger.com,1999:blog-5215777427512085470.post-81978601730691455552019-10-05T23:10:00.001+05:302019-10-07T09:56:13.528+05:30Kotlin Android – AlertDialog – Example<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
Hello Friends,<br />
Here is the demo Alert Dialog in <b><span style="color: blue;">Kotlin</span></b>. Android <b>AlertDialog </b>class<br />
is used to display a dialog box to user with positive and negative buttons.<br />
It Appears on top of the activity layout. You may not physically access any other<br />
UI components of activity. It will be run on UI thread.<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieSRb66XzgDId8t_Za6SyQ87PQjzY_I9NS6FiaEXxENxs8WlK02Szg_FV70sPAK7IGcSmKdN3BKIglzq8If1guvKt0ClIG-9TXUtKFFO_izMf2gr1oR6ecKuU9sdb3UgWoo73pPtAJRhY/s1600/screen1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="876" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieSRb66XzgDId8t_Za6SyQ87PQjzY_I9NS6FiaEXxENxs8WlK02Szg_FV70sPAK7IGcSmKdN3BKIglzq8If1guvKt0ClIG-9TXUtKFFO_izMf2gr1oR6ecKuU9sdb3UgWoo73pPtAJRhY/s320/screen1.png" width="175" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmlUEqW0Io2kTH_ZvvjH-n68mx2iLloO1h5j-ABpmnH7pWrvRHIDbXuQnhLzH830KL4s_HokGTeEKUZmNene8vr3KeCmUc0LWquffG2uaKmpQcoDMXEBQKtuDKZ7OSOl6ToUKrL3_vNSg/s1600/screen2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="876" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmlUEqW0Io2kTH_ZvvjH-n68mx2iLloO1h5j-ABpmnH7pWrvRHIDbXuQnhLzH830KL4s_HokGTeEKUZmNene8vr3KeCmUc0LWquffG2uaKmpQcoDMXEBQKtuDKZ7OSOl6ToUKrL3_vNSg/s320/screen2.png" width="175" /></a></div>
<br />
<br />
<br />
<br />
To <b>Create </b>an <b>AlertDialog</b>, step by step process is :<br />
<br />
1. Create an AlertDialog Builder using the activity’s context.<br />
2. Set message content using the builder.<br />
3. Set Positive Button Text and Action to be taken when the button is clicked using the builder.<br />
4. Set Negative Button Text and Action to be taken when the button is clicked using the builder.<br />
5. Create AlertDialog from the builder.<br />
6. You may set the title to the AlertDialog box using setTitle() method.<br />
<br />
1. <span style="background-color: white; font-family: "courier new"; font-size: 9pt;">MainActivity.kt</span><br />
<pre class="java" name="code">package com.android.developer.soulutions.myapplication
import android.content.DialogInterface
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v7.app.AlertDialog
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
btnShowAlert.setOnClickListener {
// build alert dialog
val dialogBuilder = AlertDialog.Builder(this)
// set message of alert dialog
dialogBuilder.setMessage("Do you want to close this ?")
// if the dialog is cancelable
.setCancelable(false)
// positive button text and action
.setPositiveButton("OK", DialogInterface.OnClickListener { dialog, id ->
finish()
})
// negative button text and action
.setNegativeButton("Cancel", DialogInterface.OnClickListener { dialog, id ->
dialog.cancel()
})
// create dialog box
val alert = dialogBuilder.create()
// set title for alert dialog box
alert.setTitle("AlertDialogExample")
// show alert dialog
alert.show()
};
}
}
</pre>
<div>
<br />
Download the code from <a href="https://github.com/mukesh4u/KotlinExample" target="_blank">here</a><br />
<br />
Hope this will helps someone.<br />
Enjoy Coding................... :)<br />
<br />
<br /></div>
</div>
</div>
Mukesh Kumarhttp://www.blogger.com/profile/02072401063614368529noreply@blogger.com0tag:blogger.com,1999:blog-5215777427512085470.post-75190943491548567702018-12-14T17:26:00.002+05:302018-12-14T17:31:36.820+05:30React Native- Invariant Violation: The navigation prop is missing for this navigator | react-navigation 3- navigation prop is missing for this navigator.<div dir="ltr" style="text-align: left;" trbidi="on">
Hello Friend,<br />
Recently I faced few issue while implementing the react-navigation in my app.<br />
I spent lots of time in it and then finally I found the actual cause of it.<br />
<br />
1. <span style="color: red;">undefined is not an object (evaluating 'RNGestureHandlerModule.State')</span><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7epf39MVYFI4AWpz2n0laxwBMgxDzkXKUwHZZ4Q65kO28fJ40IIJzAqOlqLpon3ogyo7kND8oohRFvdv-IMC0dod3Y8QI5pHf5_BH8qn8GCQcGE737oU6xhCz3Ufu4mpE66QAqTWdsaI/s1600/40913265-9e74c068-6826-11e8-8bc5-316098311ed3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="960" data-original-width="540" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7epf39MVYFI4AWpz2n0laxwBMgxDzkXKUwHZZ4Q65kO28fJ40IIJzAqOlqLpon3ogyo7kND8oohRFvdv-IMC0dod3Y8QI5pHf5_BH8qn8GCQcGE737oU6xhCz3Ufu4mpE66QAqTWdsaI/s400/40913265-9e74c068-6826-11e8-8bc5-316098311ed3.png" width="225" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
Then I follow following steps to resolve this,<br />
<br />
<div>
<ol style="text-align: left;">
<li>remove node_modules and package-lock.json</li>
<li>npm install</li>
<li>npm install --save react-navigation</li>
<li>npm install --save react-native-gesture-handler</li>
<li>react-native link</li>
</ol>
<div>
After following this I face another issue i:e,</div>
</div>
<br />
<br />
2.<span style="color: red;"> Invariant Violation: The navigation prop is missing for this navigator. In </span><br />
<span style="color: red;">react-navigation 3 you must set up your app container directly. More info: </span><br />
<span style="color: red;">https://reactnavigation.org/docs/en/app-containers.html</span><br />
<span style="color: red;"> </span><br />
<div class="separator" style="clear: both; text-align: center;">
<span style="color: red;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGf5NzERR2JvxCvDpqwCTYZ8gd2vxB5fGhKY_HOpEs5NDKyD8oYpRNqormhfyq7AWPtkeblH38WSJWfnQRiKUjHRuUoiJdQmDxJFcIaMkeXLMJRGe8axbpjyXDMpUm4Ot0mY3JwGlKI4U/s1600/Screen+Shot+2018-12-14+at+4.33.37+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="708" data-original-width="350" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGf5NzERR2JvxCvDpqwCTYZ8gd2vxB5fGhKY_HOpEs5NDKyD8oYpRNqormhfyq7AWPtkeblH38WSJWfnQRiKUjHRuUoiJdQmDxJFcIaMkeXLMJRGe8axbpjyXDMpUm4Ot0mY3JwGlKI4U/s400/Screen+Shot+2018-12-14+at+4.33.37+PM.png" width="197" /></a></span></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="color: red;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="color: red;"><b><br /></b></span></div>
<br />
<span style="color: red;"><b>Note</b></span><span style="color: red;"> </span><span style="color: red;">: </span><span style="color: red;">This is an react-navigation 3.0 bug. You can go through the below link for more details.</span><span style="color: red;"> </span><br />
<br />
- React Navigation 3.0 has a number of <a href="https://reactnavigation.org/blog/#breaking-changes" target="_blank">breaking changes</a> including an explicit app container required for the root navigator.<br />
<br />
In the past, any navigator could act as the navigation container at the top-level of your app because they were all wrapped in “navigation containers”. The navigation container, now known as an app container, is a higher-order-component that maintains the navigation state of your app and handles interacting with the outside world to turn linking events into navigation actions and so on.<br />
<br />
In v2 and earlier, the containers in React Navigation are automatically provided by the create Navigator functions. As of v3, you are required to use the container directly. In v3 we also renamed createNavigationContainer to createAppContainer.<br />
<br />
<br />
Below are the complete code,<br />
<br />
<pre class="html" name="code">/**
* This is an example code for Navigator
*/
import React, { Component } from 'react';
import {createStackNavigator,createAppContainer} from 'react-navigation';
import FirstPage from './src/component/FirstPage';
import SecondPage from './src/component/SecondPage';
//import all the screens we are going to switch
const RootStack = createStackNavigator({
//Constant which holds all the screens like index of any book
FirstPage: { screen: FirstPage },
//First entry by default be our first screen if we do not define initialRouteName
SecondPage: { screen: SecondPage },
},
{
initialRouteName: 'FirstPage',
}
);
const App = createAppContainer(RootStack);</pre>
<br />
<br />
Download complet code from <a href="https://github.com/mukesh4u/ReactNavigation" target="_blank">here</a><br />
Hope this will helps someone........<br />
<br />
Enjoy coding..... :)<br />
<br />
<br /></div>
Mukesh Kumarhttp://www.blogger.com/profile/02072401063614368529noreply@blogger.com0tag:blogger.com,1999:blog-5215777427512085470.post-74106114522918006232018-12-05T17:16:00.004+05:302018-12-05T17:16:27.522+05:30Kotlin-Create TextView Programatically<div dir="ltr" style="text-align: left;" trbidi="on">
Hello Friends,<br />
In this tutorial I am going create a textview dynamically in <span style="color: blue;"><b>kotlin</b></span> and add it to <b><span style="color: blue;">Linearlayout</span></b> layout.<br />
<b><br /></b>
<b>1. activity_main.xml:</b> Following is the activity_main.xml containing the TextView with the text .<br />
<br />
<pre class="xml" name="code"><?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="https://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"
tools:context=".TextViewSample">
<LinearLayout
android:id="@+id/ll_main_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/tv_static"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:padding="20sp"
android:justificationMode="inter_word"
android:text="This textview is created from xml"/>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
</pre>
<b>2. Creation of textview dynamically,</b>
<br />
<pre class="java" name="code">val tv_programtically = TextView(this)
tv_programtically.textSize = 20f
tv_programtically.text = "This textview is an dynamic textview in kotlin"
</pre>
<br />
3. Finally the complete code is:<br />
<br />
<b><span style="color: blue;">TextViewSample.kt</span></b>
<br />
<pre class="java" name="code">package com.android.developer.kotlinsample
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.widget.LinearLayout
import android.widget.TextView
class TextViewSample : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_text_view_sample)
/** Dynamic creation of text view */
val tv_programtically = TextView(this)
tv_programtically.textSize = 20f
tv_programtically.text = "This textview is an dynamic textview in kotlin"
/**------end--------**/
// add TextView to LinearLayout
val ll_main_layout = findViewById(R.id.ll_main_layout) as LinearLayout
ll_main_layout.addView(tv_programtically)
}
}</pre>
Hope this will help some one.
Enjoy Coding.... :)
</div>
Mukesh Kumarhttp://www.blogger.com/profile/02072401063614368529noreply@blogger.com0tag:blogger.com,1999:blog-5215777427512085470.post-18835513411286146222018-12-05T17:16:00.002+05:302018-12-05T17:16:09.254+05:30Kotlin-bind OnClickListener on view<div dir="ltr" style="text-align: left;" trbidi="on">
Hello Friends,<br />
In this tutorial I am showing you how to bind the click listener on View in Kotlin.
<br />
<br />
<b>1. Code snippet to set OnClickListener on Textview in Kotlin Android</b><br />
<pre class="java" name="code">val tvStatic = findViewById(R.id.tv_static) as TextView
tvStatic.setOnClickListener {
// your code to perform when the user clicks on the TextView
Toast.makeText(this, "You clicked on TextView 'Click Me'.", Toast.LENGTH_SHORT).show()
}
</pre>
<br />
<b>2. </b><b>Code snippet to set OnClickListener</b><b> on Button in Kotlin Android</b><br />
<pre class="java" name="code">// get reference to button
val btn_click = findViewById(R.id.btn_click_me) as Button
// set on-click listener
btn_click.setOnClickListener {
Toast.makeText(this@MainActivity, "You clicked on Button.", Toast.LENGTH_SHORT).show()
}
</pre>
<b><br /></b>
<b>3. </b><b>Code snippet to set OnClickListener</b><b> on ImageView in Kotlin Android</b><br />
<pre class="java" name="code">// get reference to ImageView
val iv_profile = findViewById(R.id.image_view) as ImageView
// set on-click listener for ImageView
iv_profile.setOnClickListener {
// your code here
}
</pre>
<b><br /></b>
Hope this will help someone.<br />
Enjoy Coding..... :)</div>
Mukesh Kumarhttp://www.blogger.com/profile/02072401063614368529noreply@blogger.com0tag:blogger.com,1999:blog-5215777427512085470.post-70426687140437708852018-06-23T22:13:00.002+05:302018-12-05T14:12:13.656+05:30Android Live Data Tutorial | Live Data | Data Binding | Architecture Components<div dir="ltr" style="text-align: left;" trbidi="on">
<head>
</head>
<body>
<div dir="ltr" style="text-align: left;" trbidi="on">
Hello Friends,<br />
Today I am going to share me small tutorial of <b>LiveData </b>with <b>Data Binding.</b><br />
<br />
<b>-What is LiveData?</b><br />
<b>LiveData </b>is an observable data holder class that can be observed within<br />
a given lifecycle. It lets the components in your app, usually the UI,<br />
observe LiveData objects for changes.<br />
<br />
<b>-The advantages of using LiveData</b><br />
<br />
<ul style="text-align: left;">
<li><b> </b>Ensures your UI matches your data state</li>
<li> No memory leaks</li>
<li> No crashes due to stopped activities</li>
<li> No more manual lifecycle handling</li>
<li> Always up to date data</li>
<li> Proper configuration changes</li>
<li> Sharing resources</li>
</ul>
<div>
<b>-How to use it in our app</b></div>
<br />
<b> a</b>. Add below dependency in <b>app/build.gradle</b><br />
<br />
<pre class="java" name="code">implementation "android.arch.lifecycle:extensions:1.1.1"
</pre>
<b><br /></b>
<br />
<b> </b><br />
<b> b. UserViewModel.java : </b>Creating a <b>ViewModel</b> class<br />
<br />
<pre class="java" name="code">package com.android.developer.livedatademo.model;
import android.arch.lifecycle.MutableLiveData;
import android.arch.lifecycle.ViewModel;
/**
* Created by mukesh on 13/6/18.
*/
public class UserViewModel extends ViewModel {
// Create a LiveData with a String
private MutableLiveData<user> mUser;
public MutableLiveData<user> getUser() {
if (mUser == null) {
mUser = new MutableLiveData<user>();
}
return mUser;
}
}
</user></user></user></pre>
<br />
In Activity class we creates an observer which updates the ui.<br />
<pre class="java" name="code">final Observer<user> nameObserver = new Observer<user>() {
@Override
public void onChanged(@Nullable final User user) {
// Update the UI, in this case, a TextView.
binding.tvUserName.setText(user.getName());
}
};
</user></user></pre>
<br />
Next step is observe the livedata, passing in the activity as a LifecycleOwner and the Observer.
<br />
<pre class="java" name="code">userViewModel.getUser().observe(this, nameObserver);
binding.btnClick.setOnClickListener(this);
</pre>
<br />
The complete code,<br />
<br />
<pre class="java" name="code">package com.android.developer.livedatademo;
import android.arch.lifecycle.Observer;
import android.arch.lifecycle.ViewModelProviders;
import android.databinding.DataBindingUtil;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import com.android.developer.livedatademo.databinding.ActivityMainBinding;
import com.android.developer.livedatademo.model.User;
import com.android.developer.livedatademo.model.UserViewModel;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
UserViewModel userViewModel;
ActivityMainBinding binding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
// Get the ViewModel.
userViewModel = ViewModelProviders.of(this).get(UserViewModel.class);
// Create the observer which updates the UI.
final Observer<user> nameObserver = new Observer<user>() {
@Override
public void onChanged(@Nullable final User user) {
// Update the UI, in this case, a TextView.
binding.tvUserName.setText(user.getName());
}
};
// Observe the LiveData, passing in this activity as the LifecycleOwner and the observer.
userViewModel.getUser().observe(this, nameObserver);
binding.btnClick.setOnClickListener(this);
}
@Override
public void onClick(View v) {
User user = new User();
user.setName("Mukesh Yadav");
user.setAge("25");
userViewModel.getUser().setValue(user);
}
}
</user></user></pre>
<br />
<b>Download the complete code <a href="https://github.com/mukesh4u/LiveDataDemo" target="_blank">here</a></b><br />
<br />
Hope this will helps someone.<br />
Enjoy Coding... :)<br />
</div>
</body>
</div>
Mukesh Kumarhttp://www.blogger.com/profile/02072401063614368529noreply@blogger.com0tag:blogger.com,1999:blog-5215777427512085470.post-60468917602530188662017-12-17T12:09:00.001+05:302017-12-18T10:53:36.983+05:30Android MVP for Beginners | Android MVP tutorial | Model-View-Presenter: Android | Android Architecture with MVP<div dir="ltr" style="text-align: left;" trbidi="on">
Hello Friends,<br />
Today I am going to share a very simple example of <b>Android MVP.</b><br />
In this sample I am using MVP pattern for network call and and user<br />
form(login form) data validation which is mainly used in most of the android<br />
application.<br />
<br />
<b>Model View Presenter</b> divides application into three layers i.e: Model, View and Presenter.<br />
<ol style="text-align: left;">
<li><b>Model</b>: This handles the data part of our application</li>
<li><b>Presenter</b>: It acts as a bridge that connects a Model and a View.</li>
<li><b>View</b>: This is responsible for laying out views with the relevant data as instructed by the Presenter </li>
</ol>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJCP1BBgk89gJyTs6QvkCKAHU62yfANFyqLOxU6OwUa3VxrBuLXUAeXBqT6oK61RBOfz4QZD1uvSWqrYazfx_Rq-uGe-2JuKBN1zyLKPUL_f5IX-LGKAYc4BXQeNhkA1PUoU7KAwsWuXY/s1600/mvp.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="793" data-original-width="1024" height="308" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJCP1BBgk89gJyTs6QvkCKAHU62yfANFyqLOxU6OwUa3VxrBuLXUAeXBqT6oK61RBOfz4QZD1uvSWqrYazfx_Rq-uGe-2JuKBN1zyLKPUL_f5IX-LGKAYc4BXQeNhkA1PUoU7KAwsWuXY/s400/mvp.png" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<b>Note: </b>The View never communicates with Model directly</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<b>1. LoginActivity.java </b></div>
<div>
<pre class="java" name="code">package android.developer.solutions.androidmvp.activity.login.view;
import android.content.Intent;
import android.developer.solutions.androidmvp.R;
import android.developer.solutions.androidmvp.activity.home.view.HomeActivity;
import android.developer.solutions.androidmvp.activity.login.interactor.LoginInteractorImpl;
import android.developer.solutions.androidmvp.activity.login.presenter.ILoginPresenter;
import android.developer.solutions.androidmvp.activity.login.presenter.LoginPresenterImpl;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
public class LoginActivity extends AppCompatActivity implements ILoginView {
EditText username;
EditText password;
ProgressBar progress;
Button button;
private ILoginPresenter presenter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
progress = (ProgressBar) findViewById(R.id.progress);
button = (Button) findViewById(R.id.btnLogin);
password = (EditText) findViewById(R.id.password);
username = (EditText) findViewById(R.id.username);
presenter = new LoginPresenterImpl(this, new LoginInteractorImpl());
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
presenter.validateCredentials(username.getText().toString(), password.getText().toString());
}
});
}
@Override
protected void onDestroy() {
presenter.onDestroy();
super.onDestroy();
}
@Override
public void showProgress() {
progress.setVisibility(View.VISIBLE);
}
@Override
public void hideProgress() {
progress.setVisibility(View.GONE);
}
@Override
public void setUsernameError() {
username.setError("Invalid user name");
}
@Override
public void setPasswordError() {
password.setError("Invalid password");
}
@Override
public void navigateToHome() {
startActivity(new Intent(this, HomeActivity.class));
finish();
}
}
</pre>
<br /></div>
<div>
<b>2. ILoginView.java</b><br />
<br />
<pre class="java" name="code">package android.developer.solutions.androidmvp.activity.login.view;
/**
* Created by Mukesh on 12/16/2017.
* androiddevelopersolutions.com
*/
public interface ILoginView {
void showProgress();
void hideProgress();
void setUsernameError();
void setPasswordError();
void navigateToHome();
}
</pre>
<br />
<b>Download complete code from</b> <a href="https://github.com/mukesh4u/AndroidMVP" target="_blank">here</a><br />
<br />
Hope this will helps some one.<br />
<b>Enjoy Coding............ </b>:)<br />
<br /></div>
</div>
Mukesh Kumarhttp://www.blogger.com/profile/02072401063614368529noreply@blogger.com0tag:blogger.com,1999:blog-5215777427512085470.post-35728677533955266102017-11-27T15:32:00.002+05:302017-11-27T15:54:57.394+05:30Android O: Fonts – Part 1 | Working with custom font Android O | Custom font | Fonts in XML<div dir="ltr" style="text-align: left;" trbidi="on">
Hello Friends,<br />
<b>Android 8.0 </b>(<b>API level 26</b>) introduces a new feature, Fonts in <b>XML</b>, which lets you use fonts as resources. You can add the font file in the <span style="color: #38761d;">res/font/</span> folder to bundle fonts as resources. These fonts are compiled in your R file and are automatically available in Android Studio. You can access the font resources with the help of a new resource type, font. For example, to access a font resource, use <span style="color: #38761d;">@font/myfont</span>, or <span style="color: #38761d;">R.font.myfont.</span><br />
<br />
To use the <b>Fonts</b> in <b>XML</b> feature on devices running Android <b>API version 14 and higher</b>, use the <b>Support Library 26</b>. For more information on using the support library, refer to the <a href="https://developer.android.com/guide/topics/ui/look-and-feel/fonts-in-xml.html#using-support-lib" target="_blank">Using the support library</a> section.<br />
<br />
<b>Steps</b><br />
<br />
<ul style="text-align: left;">
<li>To add fonts as resources, perform the following steps in the Android Studio</li>
</ul>
<ol style="text-align: left;"><h2>
</h2>
<h3>
</h3>
<h4>
</h4>
<h4>
<ul>
<li><span style="font-weight: normal;">Right-click the res folder and go to New > Android resource directory </span></li>
</ul>
<ul>
<li><span style="font-weight: normal;">The New Resource Directory window appears.</span></li>
</ul>
</h4>
</ol>
<div class="separator" style="clear: both; text-align: left;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfDfVasYr4HYBNft7MLghf_FJiqnBR0WAxLD9uZGmtRoGt2FUnl9cq-UydUO_uaJTGsaEMF339V96AEyZPWvkLBobblqbRFrSKR0XclAIOs-c-ly3JvE5O5x0GuCvtwRA7ygDPkhjG1GI/s1600/font1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="705" data-original-width="1010" height="278" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfDfVasYr4HYBNft7MLghf_FJiqnBR0WAxLD9uZGmtRoGt2FUnl9cq-UydUO_uaJTGsaEMF339V96AEyZPWvkLBobblqbRFrSKR0XclAIOs-c-ly3JvE5O5x0GuCvtwRA7ygDPkhjG1GI/s400/font1.png" width="400" /></a></div>
<div>
<br /></div>
<ul style="text-align: left;"><ul>
<li>In the Resource type list, select font, and then click OK.</li>
</ul>
</ul>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2FTdCHW-mr5Rc11rPi20tL0QAIDhL8bhz1ogWXN7XvSQ9RcEn8Uptk2cSt8VD7yoQ6FjtodRb3PfhcijGSZF9ChDRVG7A3D1pdpVEmr8fC1DfXXeTGUbPpfNzetq-rOh_p0l1NfaAjbM/s1600/font2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="476" data-original-width="368" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2FTdCHW-mr5Rc11rPi20tL0QAIDhL8bhz1ogWXN7XvSQ9RcEn8Uptk2cSt8VD7yoQ6FjtodRb3PfhcijGSZF9ChDRVG7A3D1pdpVEmr8fC1DfXXeTGUbPpfNzetq-rOh_p0l1NfaAjbM/s400/font2.png" width="308" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3qwhv4s73l64GQ60FEC_1mjL3a-aBv9151ZYo5tH6Qh3ZWvK8RHHzuEvVAL8N3IlibSLuIH4vyUyEmRvy_GWFrcfE6VgMPSU_I5UPb6tAVNx78E7pmRUtoIfwJBb_uQaudA-x8CrYdTs/s1600/font3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="501" data-original-width="1472" height="135" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3qwhv4s73l64GQ60FEC_1mjL3a-aBv9151ZYo5tH6Qh3ZWvK8RHHzuEvVAL8N3IlibSLuIH4vyUyEmRvy_GWFrcfE6VgMPSU_I5UPb6tAVNx78E7pmRUtoIfwJBb_uQaudA-x8CrYdTs/s400/font3.png" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<b>Note:</b> The name of the resource directory must be font.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
</div>
<ul style="text-align: left;">
<li><b>Using fonts in XML layouts </b></li>
<ul>
<li>In the layout XML file, set the font Family attribute to the font file you want to access.</li>
</ul>
</ul>
<br />
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxLgo8O51tuT4gt7uReGufgrK-iUfRiKql0W4CoEy_IvCtT8Es64669wo_x7V5GwLdi3sCEQ8scqieflNetdODvVqgWDDjz5KjEROYR0hKi5bRIoKhqrBH5P2B7mnXB-WIME_pZpBmIJ4/s1600/font_xml.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="188" data-original-width="557" height="216" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxLgo8O51tuT4gt7uReGufgrK-iUfRiKql0W4CoEy_IvCtT8Es64669wo_x7V5GwLdi3sCEQ8scqieflNetdODvVqgWDDjz5KjEROYR0hKi5bRIoKhqrBH5P2B7mnXB-WIME_pZpBmIJ4/s640/font_xml.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-BvRGQAv23s5MG9JbsU-CGA2dCOYTB2LHFv1PyWnws-4IJcKmbDQ6KPnrRmRyl4aNnqEFuC1CV4ffnXmLPcwzHoIu4-of43J2DSEhwDKqoUxvjxUs5lNaI4DC-OXRuoW68oB6UaFnWmo/s1600/font.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="876" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-BvRGQAv23s5MG9JbsU-CGA2dCOYTB2LHFv1PyWnws-4IJcKmbDQ6KPnrRmRyl4aNnqEFuC1CV4ffnXmLPcwzHoIu4-of43J2DSEhwDKqoUxvjxUs5lNaI4DC-OXRuoW68oB6UaFnWmo/s640/font.png" width="348" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Download Complete code from <a href="https://github.com/mukesh4u/Font" target="_blank">here</a>.</div>
<div class="separator" style="clear: both; text-align: left;">
Hope this will help some one.</div>
<div class="separator" style="clear: both;">
Enjoy coding.................. ;) </div>
</div>
Mukesh Kumarhttp://www.blogger.com/profile/02072401063614368529noreply@blogger.com0