Skip to content

Commit

Permalink
Added a FloatingLabel template
Browse files Browse the repository at this point in the history
Added a FloatingLabel template based on [Chris Banes
code](https://gist.github.com/chrisbanes/11247418)
  • Loading branch information
gabrielemariotti committed Apr 30, 2014
1 parent 8736a27 commit 52f9ffa
Show file tree
Hide file tree
Showing 19 changed files with 519 additions and 4 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
@@ -0,0 +1,11 @@
Change Log
===============================================================================

Version 1.1 *(2014-04-30)*
----------------------------
* Added: `FloatingLabelLayout` [template](https://github.com/gabrielemariotti/AndroidStudioTemplate/tree/master/templates/custom/FloatingLabel)


Version 1.0
----------------------------
* Initial release with SwipeRefreshLayout and Array Adapter templates
17 changes: 16 additions & 1 deletion README.md
Expand Up @@ -29,16 +29,29 @@ Restart Android Studio, and you will find it in: **New -> Activity -> SwipeRefre

Copy the `custom` folder in your Android Studio installation in this folder: `<androidStudio-folder>/plugins/android/lib/templates/`

Restart Android Studio, and you will find it in: **New -> Adapter**
Restart Android Studio, and you will find it in: **New -> xxxx**


It contains these templates:

- **Array Adapter**: Creates a new Custom Array Adapter with a ViewHolder pattern.

- **Array Adapter + Activity**: Creates a new Custom Array Adapter with a ViewHolder pattern, and an Activity with a List.

- **FloatingLabelLayout**: Creates a Floating Label Layout based on [FloatingLabelLayout] code by [Chris Banes]. You can read more info in this [post](https://plus.google.com/+ChrisBanes/posts/5Ejaq51UWGo). ( in: **New -> Custom View**)


## ChangeLog

* [Changelog:](https://github.com/gabrielemariotti/AndroidStudioTemplate/tree/master/CHANGELOG.md) A complete changelog


Acknowledgements
--------------------

* Thanks to [Chris Banes] for [FloatingLabelLayout] class.


Credits
-------

Expand Down Expand Up @@ -79,3 +92,5 @@ License

[SwipeRefreshLayout]:https://github.com/gabrielemariotti/AndroidStudioTemplate#swiperefreshlayout
[Custom]:https://github.com/gabrielemariotti/AndroidStudioTemplate#custom
[Chris Banes]:https://plus.google.com/+ChrisBanes
[FloatingLabelLayout]:https://gist.github.com/chrisbanes/11247418
2 changes: 1 addition & 1 deletion templates/activities/SwipeRefreshLayout/template.xml
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<template
format="3"
revision="4"
revision="1"
name="SwipeRefreshLayout"
minApi="7"
minBuildApi="14"
Expand Down
2 changes: 1 addition & 1 deletion templates/custom/ArrayAdapter/template.xml
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<template
format="4"
revision="2"
revision="1"
name="Custom ArrayAdapter"
description="Creates a new array adapter with the ViewHolder pattern"
minApi="7"
Expand Down
2 changes: 1 addition & 1 deletion templates/custom/ArrayAdapterWithActivity/template.xml
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<template
format="3"
revision="4"
revision="1"
name="CustomArrayAdapter + Activity"
minApi="7"
minBuildApi="14"
Expand Down
9 changes: 9 additions & 0 deletions templates/custom/FloatingLabel/globals.xml.ftl
@@ -0,0 +1,9 @@
<?xml version="1.0"?>
<globals>
<global id="manifestOut" value="${manifestDir}" />
<global id="appCompat" value="${(minApiLevel lt 14)?string('1','')}" />
<!-- e.g. getSupportActionBar vs. getActionBar -->
<global id="Support" value="${(minApiLevel lt 14)?string('Support','')}" />
<global id="srcOut" value="${srcDir}/${slashedPackageName(packageName)}" />
<global id="resOut" value="${resDir}" />
</globals>
39 changes: 39 additions & 0 deletions templates/custom/FloatingLabel/recipe.xml.ftl
@@ -0,0 +1,39 @@
<?xml version="1.0"?>
<recipe>

<#if appCompat?has_content><dependency mavenUrl="com.android.support:appcompat-v7:19.+"/></#if>
<dependency mavenUrl="com.android.support:support-v4:19.+"/>

<#if isActivityAdded>
<merge from="AndroidManifest.xml.ftl"
to="${escapeXmlAttribute(manifestOut)}/AndroidManifest.xml" />

<merge from="res/values/floatinglabel_strings.xml.ftl"
to="${escapeXmlAttribute(resOut)}/values/floatinglabel_strings.xml" />

<merge from="res/values/dimens.xml.ftl"
to="${escapeXmlAttribute(resOut)}/values/dimens.xml" />

<!-- Decide what kind of layout(s) to add -->
<instantiate from="res/layout/floatinglabel_layout.xml.ftl"
to="${escapeXmlAttribute(resOut)}/layout/${layoutActivityName}.xml" />

<!-- Decide which activity code to add -->
<instantiate from="src/app_package/SimpleActivity.java.ftl"
to="${escapeXmlAttribute(srcOut)}/${activityClass}.java" />

</#if>

<instantiate from="src/app_package/FloatLabelLayout.java.ftl"
to="${escapeXmlAttribute(srcOut)}/${floatLabelLayoutClass}.java" />

<merge from="res/values/floatinglabel_attrs.xml.ftl"
to="${escapeXmlAttribute(resOut)}/values/floatinglabel_attrs.xml" />

<merge from="res/color/floatinglabel_colors.xml.ftl"
to="${escapeXmlAttribute(resOut)}/color/floatinglabel_colors.xml" />

<merge from="res/values/floatinglabel_styles.xml.ftl"
to="${escapeXmlAttribute(resOut)}/values/floatinglabel_styles.xml" />

</recipe>
14 changes: 14 additions & 0 deletions templates/custom/FloatingLabel/root/AndroidManifest.xml.ftl
@@ -0,0 +1,14 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" >

<application>
<activity android:name="${packageName}.${activityClass}"
<#if isNewProject>
android:label="@string/app_name"
<#else>
android:label="@string/title_${activityToLayout(activityClass)}"
</#if>>

</activity>
</application>

</manifest>
7 changes: 7 additions & 0 deletions templates/custom/FloatingLabel/root/build.gradle.ftl
@@ -0,0 +1,7 @@
dependencies {
<#if dependencyList?? >
<#list dependencyList as dependency>
compile '${dependency}'
</#list>
</#if>
}
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Change this selector to customize your FloatingLabel
Original source: https://gist.github.com/chrisbanes/11247418
Original blog: https://plus.google.com/+ChrisBanes/posts/5Ejaq51UWGo
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<!-- The color when activated/focused (usually your app's accent color) -->
<item android:color="#0099CC" android:state_activated="true" />

<!-- The color when not activated/focused (usually grey) -->
<item android:color="#FF888888" />

</selector>
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<${packageName}.${floatLabelLayoutClass}
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
app:floatLabelTextAppearance="@style/TextAppearance.YourApp.FloatLabel">

<EditText
android:id="@+id/edit_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/account_username_hint"
android:singleLine="true"
android:inputType="textNoSuggestions"
android:imeOptions="actionNext"
android:nextFocusDown="@+id/edit_password" />

</${packageName}.${floatLabelLayoutClass}>

<${packageName}.${floatLabelLayoutClass}
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
app:floatLabelTextAppearance="@style/TextAppearance.YourApp.FloatLabel">

<EditText
android:id="@+id/edit_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/account_password_hint"
android:singleLine="true"
android:inputType="textNoSuggestions"
android:imeOptions="actionDone" />

</${packageName}.${floatLabelLayoutClass}>

</LinearLayout>
7 changes: 7 additions & 0 deletions templates/custom/FloatingLabel/root/res/values/dimens.xml.ftl
@@ -0,0 +1,7 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>


</resources>
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Original source: https://gist.github.com/chrisbanes/11247418
Original blog: https://plus.google.com/+ChrisBanes/posts/5Ejaq51UWGo
Copyright (C) 2014 Chris Banes
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.
-->
<resources>

<declare-styleable name="FloatLabelLayout">
<attr name="floatLabelTextAppearance" format="reference" />
<attr name="floatLabelSidePadding" format="reference|dimension" />
</declare-styleable>

</resources>
@@ -0,0 +1,11 @@
<resources>
<#if !isNewProject>
<string name="title_${activityToLayout(activityClass)}">${escapeXmlString(activityTitle)}</string>
</#if>

<!-- Custom strings for floating label example -->
<string name="account_username_hint">Username</string>
<string name="account_password_hint">Password</string>


</resources>
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<!-- Change this style to customize your FloatingLabel
Original source: https://gist.github.com/chrisbanes/11247418
Original blog: https://plus.google.com/+ChrisBanes/posts/5Ejaq51UWGo
-->
<style name="TextAppearance.YourApp.FloatLabel" parent="android:TextAppearance.Small">
<item name="android:textColor">@color/floatinglabel_colors</item>
<item name="android:textSize">11sp</item>
<item name="android:textStyle">bold</item>
</style>
</resources>

0 comments on commit 52f9ffa

Please sign in to comment.