Skip to content

Instantly share code, notes, and snippets.

Avatar
🇵🇰
Passion to help others 😊

Ali Azaz Alam AliAzaz

🇵🇰
Passion to help others 😊
View GitHub Profile
@AliAzaz
AliAzaz / JetpackMutableStateOf.kt
Created Aug 9, 2020
mutableStateOf approach using
View JetpackMutableStateOf.kt
//--------------Utils Class start--------------------
sealed class MenuOptions {
object TaskList : MenuOptions()
object AddTask : MenuOptions()
data class ModifyTask(val task: Task) : MenuOptions()
}
object AppMain {
private var current_screen: MenuOptions = MenuOptions.TaskList
var route_screen by mutableStateOf(current_screen)
@AliAzaz
AliAzaz / JetpackState.kt
Last active Aug 26, 2020
state approach using
View JetpackState.kt
@Composable
fun AddTask() {
val title = remember { mutableStateOf("") }
val titleExist = remember { mutableStateOf(false) }
if (titleExist.value) Text(
modifier = Modifier.padding(5.dp),
text = "Title already exist",
style = TextStyle(color = Color(0xFFF50B0B)) + MaterialTheme.typography.body1
)
@AliAzaz
AliAzaz / load.kt
Created Jul 12, 2020 — forked from mootoh/load.kt
Load remote image with Coil into Jetpack Compose Image
View load.kt
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MaterialTheme {
Column {
ItemCell(item = Item("cat 1", "https://thumbs-prod.si-cdn.com/s-rtW1rEAQTIGcmUVNFSSPC4s3I=/800x600/filters:no_upscale()/https://public-media.si-cdn.com/filer/56/4a/564a542d-5c37-4be7-8892-98201ab13180/cat-2083492_1280.jpg"))
ItemCell(item = Item("cat 2", "https://images.pexels.com/photos/104827/cat-pet-animal-domestic-104827.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260"))
}
View expandablelistview_oncreate.java
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.expandable, container, false);
ExpandableAdapter adapter = new ExpandableAdapter();
expandableListView.setAdapter(adapter);
setExpandableListViewHeight(expandableListView, -1);
expandableListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View v, int position, long id) {
@AliAzaz
AliAzaz / FullscreenFragment.java
Created Mar 3, 2020 — forked from gelldur/FullscreenFragment.java
FullscreenFragment - simple android fragment that will make fullscreen for you. Remember to: "You must manually call onKeyDown and onWindowFocusChanged."
View FullscreenFragment.java
package com.dexode.fragment;
import android.annotation.TargetApi;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.view.KeyEvent;
@AliAzaz
AliAzaz / RegistrationFragment.kt
Created Feb 22, 2020
Defines both the navigation and receiving arguments
View RegistrationFragment.kt
class RegistrationFragment : Fragment() {
private lateinit var bi: FragmentRegistrationBinding
lateinit var vModel: MainViewModel
private val flag: RegistrationFragmentArgs by navArgs()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
vModel = activity?.run {
@AliAzaz
AliAzaz / activity_main.xml
Created Feb 20, 2020
Defining NavHostFragment in host activity
View activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<fragment
@AliAzaz
AliAzaz / LocalBroadcastReceiver.java
Created Feb 4, 2020 — forked from shawnthye/LocalBroadcastReceiver.java
Push Notification - Local Broadcast Receiver and Result Receiver
View LocalBroadcastReceiver.java
public class LocalBroadcastReceiver extends BroadcastReceiver {
@Override public void onReceive(Context context, Intent intent) {
Log.d("LocalBroadcastReceiver", "onReceive()");
// Tell the result receiver to CANCEL some specific action.
// eg. do not display System Notification
setResultCode(Activity.RESULT_CANCELED);
}
}
@AliAzaz
AliAzaz / LocationListener.java
Last active Jan 10, 2020
Location listener service
View LocationListener.java
public class LocationService extends Service {
public static final String BROADCAST_ACTION = "GettingLoc";
private static final int TWO_MINUTES = 1000 * 60 * 2;
private static final long MINIMUM_DISTANCE_CHANGE_FOR_UPDATES = 1; // in Meters
private static final long MINIMUM_TIME_BETWEEN_UPDATES = 2000; // in Milliseconds
public LocationManager locationManager;
public GPSLocationListener listener;
public Location previousBestLocation = null;
Intent intent;
@AliAzaz
AliAzaz / Comparison.txt
Created Dec 30, 2019 — forked from tomaszpolanski/Comparison.txt
Kotlin Standard comparison
View Comparison.txt
╔══════════╦═════════════════╦═══════════════╦═══════════════╗
║ Function ║ Receiver (this) ║ Argument (it) ║ Result ║
╠══════════╬═════════════════╬═══════════════╬═══════════════╣
║ let ║ this@MyClass ║ String("...") ║ Int(42) ║
║ run ║ String("...") ║ N\A ║ Int(42) ║
║ run* ║ this@MyClass ║ N\A ║ Int(42) ║
║ with* ║ String("...") ║ N\A ║ Int(42) ║
║ apply ║ String("...") ║ N\A ║ String("...") ║
║ also ║ this@MyClass ║ String("...") ║ String("...") ║
╚══════════╩═════════════════╩═══════════════╩═══════════════╝