Skip to content

Instantly share code, notes, and snippets.

View john-lorrenz's full-sized avatar
🏠
Working from home

John lorrenz Cruz john-lorrenz

🏠
Working from home
View GitHub Profile
@john-lorrenz
john-lorrenz / CreateDialog.kt
Last active November 19, 2019 16:50
Create dialogs
fun createBasicAlertDialog(){
val builder = AlertDialog.Builder(this)
builder.setTitle("[DIALOG TITLE]")
builder.setMessage("[DIALOG MESSAGE]")
builder.setPositiveButton("[YES TEXT]") { dialog, which ->
// Action on click yes
}
builder.setCancelable(false)
@john-lorrenz
john-lorrenz / BitmapManipulation.kt
Last active November 13, 2019 09:51
Bitmap Manipulation
/*
Sample Parameter:
String: "file:///storage/emulated/0/Android/data/com.example.disappeardents/cache/roof_1.jpg"
*/
fun uriStringToBitmap(uriString : String) : Bitmap {
val uri = uriString.toUri()
val uriPath = uri.path
val bitmap = BitmapFactory.decodeFile(uriPath)
@john-lorrenz
john-lorrenz / AndroidManifest.xml
Last active November 6, 2019 10:13
Built-in Action Bar Manipulation
<!-- CHANGE TITLE -->
<activity android:name=".ActivityName"
android:label="[LABEL HERE]"/>
<!-- HIDE ACTION BAR -->
<activity android:name=".ActivityName"
android:theme="@style/AppTheme.NoActionBar"/>
@john-lorrenz
john-lorrenz / BadgeCount.kt
Last active November 7, 2019 05:56
Icon Badge Count
// Create action bar item (notification icon)
override fun onCreateOptionsMenu(menu: Menu): Boolean {
// Inflate the menu; this adds items to the action bar if it is present.
menuInflater.inflate(R.menu.action_bar_notifications, menu)
// Get the menu item
var menuItem = menu.findItem(R.id.notifications)
// Get the view of the menu item
@john-lorrenz
john-lorrenz / CustomCamera.kt
Last active December 22, 2019 21:34
Camera capture full quality
// uri exposure fix
var builder = StrictMode.VmPolicy.Builder()
StrictMode.setVmPolicy(builder.build())
// Class level variable
var photoURI: Uri? = null
// STEP 1: Call this where you need to do the capturing
fun openCamera(fileName: String, requestCode: Int){
val intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE);
@john-lorrenz
john-lorrenz / nested_layout.xml
Created October 13, 2019 12:55
Recycler view - whole page scrollable
<?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=".Schedule.ScheduleActivity">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
@john-lorrenz
john-lorrenz / RecyclerViewColumns.kt
Last active November 7, 2019 05:54
set recycler view column to more than 1
recycler_view.layoutManager = GridLayoutManager(this,2)
@john-lorrenz
john-lorrenz / CustomActionBar.kt
Last active November 7, 2019 05:53
Custom Action bar manipulation (e.g. making the title centered, displaying the up button)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Tell Android to use the Toolbar as the ActionBar
setSupportActionBar(toolbar)
// Remove default title, so we can use our custom title
supportActionBar!!.setDisplayShowTitleEnabled(false)
// Show the up/back button
@john-lorrenz
john-lorrenz / rounded_image_view.xml
Last active November 17, 2019 16:16
imageview - rounder corner
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardCornerRadius="20dp"
android:layout_gravity="center"
app:cardElevation="50dp">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
@john-lorrenz
john-lorrenz / basic_layout_template.xml
Last active November 7, 2019 05:53
Complete layout template (Action bar - FrameLayout - Bottom Navigation)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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=".Dashboard.DashboardActivity"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar