Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added ability to wrap long floating labels #385

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ MaterialEditText
================
[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-MaterialEditText-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/1085)

> ## NOTE: 2.0 is NOT BACKWARDS COMPATIBLE! See more on [wiki](https://github.com/rengwuxian/MaterialEditText/wiki) or [中文看这里](http://www.rengwuxian.com/post/materialedittext)

> ## This is a fork of MaterialEditText from [here](https://github.com/rengwuxian/MaterialEditText). In this fork, the following functionality has been added:-
> 1. ability to wrap long floating labels
> 2.

![MaterialEditText](./images/material_edittext.png)

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.0'
classpath 'com.android.tools.build:gradle:2.2.0'
}
}

Expand Down
28 changes: 14 additions & 14 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
VERSION_NAME=2.1.4
VERSION_CODE=43
GROUP=com.rengwuxian.materialedittext
VERSION_NAME=2.1.6-SNAPSHOT
VERSION_CODE=44
GROUP=org.smartregister

POM_DESCRIPTION=Android EditText in Material Design
POM_URL=https://github.com/rengwuxian/MaterialEditText
POM_SCM_URL=https://github.com/rengwuxian/MaterialEditText
POM_SCM_CONNECTION=scm:[email protected]:rengwuxian/MaterialEditText.git
POM_SCM_DEV_CONNECTION=scm:[email protected]:rengwuxian/MaterialEditText.git
POM_LICENCE_NAME=The Apache Software License, Version 2.0
POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
POM_LICENCE_DIST=repo
POM_DEVELOPER_ID=rengwuxian
POM_DEVELOPER_NAME=Kai Zhu
POM_SETTING_DESCRIPTION=Android EditText in Material Design
POM_SETTING_URL=https://github.com/OpenSRP/MaterialEditText
POM_SETTING_SCM_URL=https://github.com/OpenSRP/MaterialEditText
POM_SETTING_SCM_CONNECTION=scm:[email protected]:OpenSRP/MaterialEditText.git
POM_SETTING_SCM_DEV_CONNECTION=scm:[email protected]:OpenSRP/MaterialEditText.git
POM_SETTING_LICENCE_NAME=The Apache Software License, Version 2.0
POM_SETTING_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
POM_SETTING_LICENCE_DIST=repo
POM_SETTING_DEVELOPER_ID=opensrp
POM_SETTING_DEVELOPER_NAME=OpenSRP Onadev

ANDROID_BUILD_TARGET_SDK_VERSION=22
ANDROID_BUILD_TOOLS_VERSION=22.0.1
ANDROID_BUILD_SDK_VERSION=22
ANDROID_BUILD_SDK_VERSION=22
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sun Dec 07 22:23:47 CST 2014
#Mon Jul 29 17:53:44 EAT 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
4 changes: 2 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.library'

android {
compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
buildToolsVersion '22.0.1'

defaultConfig {
minSdkVersion 7
Expand All @@ -23,4 +23,4 @@ dependencies {
}

// Used to push in maven
apply from: '../maven_push.gradle'
apply from: '../maven.gradle'
6 changes: 3 additions & 3 deletions library/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
POM_NAME=Material EditText Library
POM_ARTIFACT_ID=library
POM_PACKAGING=aar
POM_SETTING_NAME=Material EditText Library
POM_SETTING_ARTIFACT_ID=opensrp-client-materialedittext
POM_SETTING_PACKAGING=aar
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,29 @@ protected void onDraw(@NonNull Canvas canvas) {
textPaint.setAlpha(alpha);

// draw the floating label
canvas.drawText(floatingLabelText.toString(), floatingLabelStartX, floatingLabelStartY, textPaint);
int count = floatingLabelText.toString().length() - floatingLabelText.toString().replace("\n",
"").length();
if (count == 0) {
canvas.drawText(floatingLabelText.toString(), floatingLabelStartX, floatingLabelStartY, textPaint);
} else {
int i = 1;
for (String label: floatingLabelText.toString().split("\n")) {
// recalculate horizontal position
floatingLabelWidth = textPaint.measureText(label);
if ((getGravity() & Gravity.RIGHT) == Gravity.RIGHT || isRTL()) {
floatingLabelStartX = (int) (endX - floatingLabelWidth);
} else if ((getGravity() & Gravity.LEFT) == Gravity.LEFT) {
floatingLabelStartX = startX;
} else {
floatingLabelStartX = startX + (int) (getInnerPaddingLeft() + (getWidth() - getInnerPaddingLeft() - getInnerPaddingRight() - floatingLabelWidth) / 2);
}
// end of horizontal position recalculation

floatingLabelStartY = (innerPaddingTop + floatingLabelTextSize * i + floatingLabelPadding - distance * (floatingLabelAlwaysShown ? 1 : 2) + getScrollY());
canvas.drawText(label, floatingLabelStartX, floatingLabelStartY, textPaint);
i++;
}
}
}

// draw the bottom ellipsis
Expand Down
134 changes: 134 additions & 0 deletions maven.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
apply plugin: 'maven'
apply plugin: 'signing'

def sonatypeRepositoryURL
def mavenLocalFlag = hasProperty('mavenLocal') ? mavenLocal.toBoolean() : true;

if (isReleaseBuild()) {
println 'PROCESSING MAVEN ' + (mavenLocalFlag ? 'LOCAL' : 'REMOTE') + ' RELEASE BUILD VERSION ' + project.VERSION_NAME + '...'
sonatypeRepositoryURL = hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL
: "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
} else {
println 'PROCESSING MAVEN ' + (mavenLocalFlag ? 'LOCAL' : 'REMOTE') + ' SNAPSHOT BUILD VERSION ' + project.VERSION_NAME + '...'
sonatypeRepositoryURL = hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL
: "https://oss.sonatype.org/content/repositories/snapshots/"

}

def getRepositoryPassword() {
return hasProperty('sonatypePassword') ? sonatypePassword : ""
}

def getRepositoryUsername() {
return hasProperty('sonatypeUsername') ? sonatypeUsername : ""
}

afterEvaluate { project ->
uploadArchives {
repositories {

if (mavenLocalFlag) {

mavenDeployer {

pom.artifactId = POM_SETTING_ARTIFACT_ID

repository(url: mavenLocal().url)

pom.project {
name POM_SETTING_NAME
packaging POM_SETTING_PACKAGING
description POM_SETTING_DESCRIPTION
url POM_SETTING_URL

scm {
url POM_SETTING_SCM_URL
connection POM_SETTING_SCM_CONNECTION
developerConnection POM_SETTING_SCM_DEV_CONNECTION
}

licenses {
license {
name POM_SETTING_LICENCE_NAME
url POM_SETTING_LICENCE_URL
distribution POM_SETTING_LICENCE_DIST
}
}

developers {
developer {
id POM_SETTING_DEVELOPER_ID
name POM_SETTING_DEVELOPER_NAME
}
}
}
}
} else {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }

pom.artifactId = POM_SETTING_ARTIFACT_ID

repository(url: sonatypeRepositoryURL) {
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
}

pom.project {
name POM_SETTING_NAME
packaging POM_SETTING_PACKAGING
description POM_SETTING_DESCRIPTION
url POM_SETTING_URL

scm {
url POM_SETTING_SCM_URL
connection POM_SETTING_SCM_CONNECTION
developerConnection POM_SETTING_SCM_DEV_CONNECTION
}

licenses {
license {
name POM_SETTING_LICENCE_NAME
url POM_SETTING_LICENCE_URL
distribution POM_SETTING_LICENCE_DIST
}
}

developers {
developer {
id POM_SETTING_DEVELOPER_ID
name POM_SETTING_DEVELOPER_NAME
}
}
}
}

}
}
}

signing {
required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
sign configurations.archives
}

task androidJavadocs(type: Javadoc) {
}

task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
classifier = 'javadoc'
}

task androidSourcesJar(type: Jar) {
classifier = 'sources'
}

artifacts {
archives androidSourcesJar
archives androidJavadocsJar
}

/*nexusStaging {
username getRepositoryUsername()
password getRepositoryPassword()
}*/
}
92 changes: 0 additions & 92 deletions maven_push.gradle

This file was deleted.

15 changes: 13 additions & 2 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,21 @@
android:textSize="14sp" />

<com.rengwuxian.materialedittext.MaterialEditText
android:id="@+id/edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Floating Label"
app:met_floatingLabel="normal" />
android:layout_alignParentTop="true"
android:layout_marginEnd="12dp"
android:layout_marginRight="12dp"
android:hint="Floating Label way tooooo\nlong text sample here\nthird line test here"
android:layout_toStartOf="@+id/material_edit_text_edit_button"
android:layout_toLeftOf="@+id/material_edit_text_edit_button"
android:textSize="20dp"
app:met_floatingLabel="normal"
app:met_floatingLabelTextSize="20dp"
app:met_primaryColor="?colorAccent"
app:met_textColorHint="#808080" />


<TextView
android:layout_width="match_parent"
Expand Down