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 / ViewPager.kt
Created November 8, 2019 11:55
View Page - Image
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
var adapter = ViewPagerAdapter(this)
pager.adapter = adapter
}
internal inner class ViewPagerAdapter(val context: Context) : PagerAdapter() {
@john-lorrenz
john-lorrenz / GroupieRecyclerView.kt
Last active November 15, 2019 02:32
Basic Groupie Recycler View
override fun onCreate(savedInstanceState: Bundle?) {
reycler_view.isNestedScrollingEnabled = true
reycler_view.layoutManager = LinearLayoutManager(this)
var adapter = GroupAdapter<ViewHolder>()
adapter.add(storyItem())
adapter.add(storyItem())
adapter.add(storyItem())
@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
@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 / 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 / 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 / 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 / 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 / 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 / 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"/>