lazy-android-programmer

A set of one-liners and helper functions for Android development

License

License

Categories

Categories

GUI User Interface Hermes Application Layer Libs Messaging
GroupId

GroupId

com.github.guilhermestorck
ArtifactId

ArtifactId

lazy-android-programmer
Last Version

Last Version

0.0.3
Release Date

Release Date

Type

Type

aar
Description

Description

lazy-android-programmer
A set of one-liners and helper functions for Android development
Project URL

Project URL

https://github.com/guilhermestorck/lazy-android-programmer
Source Code Management

Source Code Management

https://github.com/guilhermestorck/lazy-android-programmer

Download lazy-android-programmer

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.guilhermestorck/lazy-android-programmer/ -->
<dependency>
    <groupId>com.github.guilhermestorck</groupId>
    <artifactId>lazy-android-programmer</artifactId>
    <version>0.0.3</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/com.github.guilhermestorck/lazy-android-programmer/
implementation 'com.github.guilhermestorck:lazy-android-programmer:0.0.3'
// https://jarcasting.com/artifacts/com.github.guilhermestorck/lazy-android-programmer/
implementation ("com.github.guilhermestorck:lazy-android-programmer:0.0.3")
'com.github.guilhermestorck:lazy-android-programmer:aar:0.0.3'
<dependency org="com.github.guilhermestorck" name="lazy-android-programmer" rev="0.0.3">
  <artifact name="lazy-android-programmer" type="aar" />
</dependency>
@Grapes(
@Grab(group='com.github.guilhermestorck', module='lazy-android-programmer', version='0.0.3')
)
libraryDependencies += "com.github.guilhermestorck" % "lazy-android-programmer" % "0.0.3"
[com.github.guilhermestorck/lazy-android-programmer "0.0.3"]

Dependencies

compile (1)

Group / Artifact Type Version
com.android.support » appcompat-v7 jar 23.1.1

Project Modules

There are no modules declared in this project.

Lazy Android Programmer

One liners for the lazy folks

When writing Android code sometimes we feel that the code we are writing could be expressed more briefly. Depending on how lazy one is, creating tons of xml layout files even for the simplest layout is a challenge.

Instalation

Just add the following line to your build.gradle

compile 'com.github.guilhermestorck:lazy-android-programmer:0.0.9'

This library is available at jcenter. Notice that this library depends on a few Android support libraries. If your project also depends on those and you are getting some version issues, add the following to override the library dependencies with yours.

compile ('com.github.guilhermestorck:lazy-android-programmer:0.0.9') {
    exclude group: 'com.android.support'
}

Layout Fluent Builder

It would be cool if, instead of lots of xml and lines of code, we could create views by just writing

import static com.github.guilhermestorck.lap.LazyAndroidProgrammer.*;

class MyActivity extends Activity {

    ...

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(
            build(this,
                LAPVerticalLayout(
                    LAPTextView("Oh, look! I'm a text view!").fillWidth().padding(32),
                    LAPButton("And I'm a button!").fillWidth().weight(1)
                )
            )
        );
    }

    ...

}

Check the example application for more examples

Just import all the statics from the com.github.guilhermestorck.lap.LazyAndroidProgrammer class (or just the ones you need, if you're not that lazy) and start using them. By using those builder methods and the chain setters of each class it is possible to create layouts in a very concise way.

Creating components

LAPTextView
LAPTextView(String label);
LAPTextView(String labelRes);
LAPButton
LAPButton(String label);
LAPButton(String label, View.OnClickListener callback);

LAPButton(Integer labelRes);
LAPButton(Integer labelRes, View.OnClickListener callback);
LAPListView
LAPListView(ListAdapter adapter);
LAPListView(List<T> items);
LAPListView(List<T> items, LAPViewMaker<T> viewMaker);
LAPListView(List<T> items, LAPBindableViewMaker<T> viewMaker);
LAPCheckBox
LAPCheckBox(String label);
LAPCheckBox(String label, View.OnClickListener callback);

LAPCheckBox(Integer labelRes);
LAPCheckBox(Integer labelRes, View.OnClickListener callback);
LAPLinearLayout
LAPLinearLayout(int orientation, LAPView... views);
LAPVerticalLayout(LAPView... views);
LAPHorizontalLayout(LAPView... views);

where orientation can be one of LinearLayout.VERTICAL or LinearLayout.VERTICAL.

LAPFrameLayout
LAPFrameLayout(LAPView view)
LAPRelativeLayout
LAPRelativeLayout(LAPView... views)
LAPFragment
LAPFragment(View view);
LAPFragment(Context ctx, LAPView view);
LAP
LAP(View view);

Building View objects

To create a view from a LAPView object, just call the build method

View build(Activity activity, LAPView lapView)

Modifying components

Modifier Modifiable components
id(Integer id) All
onClick(OnClickListener onClick) All
afterBuild(LAPView.OnViewBuilt onViewBuilt) All
onLongClick(OnLongClickListener onLongClick) All
alpha(Float alpha) All
background(Drawable background) All
backgroundColor(Integer backgroundColor) All
backgroundColorRes(Integer backgroundColorResource) All
backgroundResource(Integer backgroundResource) All
enabled(Boolean enabled) All
minHeight(Integer minHeight) All
minWidth(Integer minWidth) All
paddingLeft(Integer paddingLeft) All
paddingRight(Integer paddingRight) All
paddingTop(Integer paddingTop) All
paddingBottom(Integer padding) All
padding(Integer paddingTopBottom, Integer paddingLeftRight) All
padding(Integer padding) All
marginLeft(Integer marginLeft) All
marginRight(Integer marginRight) All
marginTop(Integer marginTop) All
marginBottom(Integer margin) All
margin(Integer marginTopBottom, Integer marginLeftRight) All
margin(Integer padding) All
visibility(Integer visibility) All
invisible() All
visible() All
gone() All
width(Integer width) All
fillWidth() All
wrapWidth() All
height(Integer height) All
fillHeight() All
wrapHeight() All
weight(Integer weight) All
add(LAPView view) LAPLinearLayout
add(LAPView view, int index) LAPLinearLayout
text(CharSequence text) LAPTextView, LAPButton, LAPCheckbox
textRes(Integer res) LAPTextView, LAPButton, LAPCheckbox
allCaps(Boolean allCaps) LAPTextView, LAPButton, LAPCheckbox
autoLinkMask(Integer autoLinkMask) LAPTextView, LAPButton, LAPCheckbox
ems(Integer ems) LAPTextView, LAPButton, LAPCheckbox
gravity(Integer gravity) LAPTextView, LAPButton, LAPCheckbox, LAPLinearLayout
height(Integer height) LAPTextView, LAPButton, LAPCheckbox
checked(Boolean checked) LAPCheckbox
onCheckedChange(CompoundButton.OnCheckedChangeListener onCheckedChange) LAPCheckbox
dividerDrawable(Drawable dividerDrawable) LAPLinearLayout
orientation(Integer orientation) LAPLinearLayout
weightSum(Float weightSum) LAPLinearLayout
adapter(ListAdapter adapter) LAPListView
adapter(List items) LAPListView
adapter(List items, LAPViewMaker viewMaker) LAPListView
adapter(List items, LAPBindableViewMaker viewMaker) LAPListView
dividerDrawable(Drawable dividerDrawable) LAPListView
dividerHeight(int height) LAPListView

Other functions

dp(int n) //converts n dp to pixels
sp(int n) //converts n sp to pixels
generateId() //create a new id to be used on views
Copyright 2015 Guilherme Storck

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.

Versions

Version
0.0.3