Kaffeine is a Kotlin-flavored Android library for accelerating development.

Related tags

Kotlin kaffeine
Overview

Kaffeine

Kaffeine is a Kotlin-flavored Android library for accelerating development.

Several Words of Caution

Besides the obvious productivity advantages, if you are using this project - be prepared to shoot yourself in the foot or to blow your legs off. This is an experimental project that I am working on while I learn Kotlin and functional programming. Some of the lucrative approaches used in this project may not be best practices and I don't have any guarantees over the API. Don't be surprised if the API changes for every SNAPSHOT. If you are trending along a safe path, this project is definitely not for you. I may highlight caveats in some of the approaches if I am smart enough to figure them out. But, feel free to throw some light if you spot some dumbness (or a lot) along the lane.

Activities & Services

Example: Start an Activity

Java

Intent intent = new Intent(this, SuperPowersActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);

Kotlin

val flags = flags(Intent.FLAG_ACTIVITY_NEW_TASK, Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity<SuperPowersActivity>(flags)

Layout Inflation

Java

LayoutInflater layoutInflater = LayoutInflater.from(this);
View awesomeView = layoutInflater.inflate(R.layout.my_awesome_layout, null);

Kotlin

val awesomeView = inflateLayout(R.layout.my_awesome_layout)

Logs

Example: Logging

Java

String tag = this.getClass().getName();
Log.i(tag, "Howdy! Info");
Log.d(tag, "Knock knock! Debug");
Log.e(tag, "Grim, Error");
Log.wtf(tag, "Damn! WTF"); // Nope, not what you think. Refer the docs :P

Kotlin

i("Howdy! Info")
d("Knock knock! Debug")
e("Grim, Error")
wtf("Damn! WTF")

Preferences

Example: Single Preference

Java

SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
Editor editor = preferences.edit();
editor.putBoolean("KEY_WALKTHROUGH_COMPLETE", complete);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) {
  editor.commit();
} else {
  editor.apply();
}

Kotlin

getDefaultSharedPreferences().putBoolean("KEY_WALKTHROUGH_COMPLETE", complete)

Example: Bulk Preferences

Kotlin

getDefaultSharedPreferences()
  .bulk()
  .putBoolean("KEY_WALKTHROUGH_COMPLETE", complete)
  .putString("KEY_LAST_USED", lastUsedIso8601Date)
  .applyBulk()

Toasts

Example: Short Message

Java

Toast.makeText(this, R.string.welcome, Toast.LENGTH_SHORT).show();

Kotlin

showShortToast(R.string.welcome)

Example: Custom Toast

Java

Toast toast = new Toast(this);
toast.setView(view);
toast.setDuration(Toast.LENGTH_LONG);
toast.show();

Kotlin

showShortToast(view)

System Services

Java

AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

Kotlin

val alarmManager = context.alarmManager()
val notificationManager = context.notificationManager()

Resources

Example: Typeface from Assets

Java

AssetManager assetManager = getAssets();
Typeface sourceSansPro = Typeface.createFromAsset(assetManager, "fonts/source-sans-pro.ttf");

Kotlin

val sourceSansPro = typefaceFromAssets("fonts/source-sans-pro.ttf")

More...

More extensions under development.

Maven

<dependency>
    <groupId>com.mobsandgeeks</groupId>
    <artifactId>kaffeine</artifactId>
    <version>0.1-SNAPSHOT</version>
</dependency>

Gradle

dependencies {
    compile 'com.mobsandgeeks:kaffeine:0.1-SNAPSHOT'
}

Snapshots

In your {project_base}/build.gradle file, include the following.

allprojects {
    repositories {
        mavenCentral()
        maven {
            url "https://oss.sonatype.org/content/repositories/snapshots/"
        }
    }
}

License

Copyright 2015 Mobs & Geeks

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
You might also like...
The most essential libraries for Kotlin Multiplatform development
The most essential libraries for Kotlin Multiplatform development

Essenty The most essential libraries for Kotlin Multiplatform development. Supported targets: android jvm js (IR and LEGACY) iosArm64, iosX64 watchosA

This is a demo android app representing implementation of SE principles in android app development

Articles Demo This repository contains a sample Android App that shows most popular articles data from NY Times API. This is a sample app that shows h

Android-Boilerplate - Base project for android development with new technology

Android-Boilerplate Base project for android development with new technology, in

Pleasant Android application development
Pleasant Android application development

⚠️ Anko is deprecated. Please see this page for more information. Anko is a Kotlin library which makes Android application development faster and easi

REST countries sample app that loads information from REST countries API V3 to show an approach to using some of the best practices in Android Development.
REST countries sample app that loads information from REST countries API V3 to show an approach to using some of the best practices in Android Development.

MAJORITY assignment solution in Kotlin via MVVM Repository Pattern. REST countries sample app that loads information from REST countries API V3 to sho

A simple project that describes the relationship between the view and it's viewmodel in android development
A simple project that describes the relationship between the view and it's viewmodel in android development

View-ViewModel-Communication A simple project that describes the relationship between the view and it's viewmodel in android development In MVVM archi

CleanArchitecture is a sample project that presents a modern, 2021 approach to Android application development.
CleanArchitecture is a sample project that presents a modern, 2021 approach to Android application development.

CleanArchitecture is a sample project that presents a modern, 2021 approach to Android application development. The goal of the pro

AndroidappTemplate - A GitHub template repository intended to kickstart development on an Android application

Android App Template This is a GitHub template repository intended to kickstart

Rick-and-morty-app - Android mobile application development with clean architecture
Rick-and-morty-app - Android mobile application development with clean architecture

Android - Rick And Morty App MVVM architecture Dependency Injection (Dagger) Ret

Comments
  • View and intents, Fragments and less dependencies

    View and intents, Fragments and less dependencies

    • Added views listener.
    • Added header () -> Unit instead of runnable.
    • Added new resources support - drawable, dimen...
    • Fragment support for intents
    • Api stuff (no more Build.SDK.VERSION_INT >= __)
    opened by yoavst 1
Owner
Ragunath Jawahar
Ragunath Jawahar
Koi, a lightweight kotlin library for Android Development.

Koi - A lightweight Kotlin library for Android Koi include many useful extensions and functions, they can help reducing the boilerplate code in Androi

Hello World 514 Nov 29, 2022
Lightweight compiler plugin intended for Kotlin/JVM library development and symbol visibility control.

Restrikt A Kotlin/JVM compiler plugin to restrict symbols access, from external project sources. This plugin offers two ways to hide symbols: An autom

Lorris Creantor 18 Nov 24, 2022
👋 A common toolkit (utils) ⚒️ built to help you further reduce Kotlin boilerplate code and improve development efficiency. Do you think 'kotlin-stdlib' or 'android-ktx' is not sweet enough? You need this! 🍭

Toolkit [ ?? Work in progress ⛏ ?? ??️ ?? ] Snapshot version: repositories { maven("https://s01.oss.sonatype.org/content/repositories/snapshots") }

凛 35 Jul 23, 2022
This is a sample app to use [Molecule library] and solve some scoping problems in Android development.

Android sample app Problem It's started when P.Y. in Twitter shared this tweet and his post, which is a correct complain about introducing a new set o

Hadi 37 Oct 28, 2022
Gits-android-extensions - A collection of Kotlin extensions to simplify Android development

gits-android-extensions A collection of Kotlin extensions to simplify Android de

GITS Indonesia 3 Feb 3, 2022
Android Clean Architecture in Rorty is a sample project that presents modern, approach to Android application development using Kotlin and latest tech-stack.

Android Clean Architecture in Rorty is a sample project that presents modern, approach to Android application development using Kotlin and latest tech-stack.

Mr.Sanchez 176 Jan 4, 2023
📒 NotyKT is a complete 💎Kotlin-stack (Backend + Android) 📱 application built to demonstrate the use of Modern development tools with best practices implementation🦸.

NotyKT ??️ NotyKT is the complete Kotlin-stack note taking ??️ application ?? built to demonstrate a use of Kotlin programming language in server-side

Shreyas Patil 1.4k Jan 4, 2023
Ethereum Web3 implementation for mobile (android & ios) Kotlin Multiplatform development

Mobile Kotlin web3 This is a Kotlin MultiPlatform library that ... Table of Contents Features Requirements Installation Usage Samples Set Up Locally C

IceRock Development 32 Aug 26, 2022
Kotlin Multiplatform is an SDK for cross-platform mobile development, which enables teams to use the same business logic in both Android and iOS client applications.

Kotlin Multiplatform is an SDK for cross-platform mobile development, which enables teams to use the same business logic in both Android and iOS client applications.

Chris Russell 1 Feb 11, 2022
An under development minecraft plugin (1.8.8) to learning Kotlin language

CorePlus CorePlus is a minecraft plugin coded with Kotlin language. Still under development CorePlus will be an essential for each minecraft servers !

Gonz 3 Jun 16, 2021