Added animated edittext hint from support library.

This commit is contained in:
Dmitry Yunitsky 2015-06-03 19:06:12 +03:00 committed by Alex Zolotarev
parent 2aa4a028cb
commit 564134d3dd
5 changed files with 97 additions and 73 deletions

View file

@ -18,10 +18,11 @@ apply plugin: 'com.android.application'
dependencies {
// android support libs
compile 'com.android.support:support-v4:22.1.1'
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.android.support:cardview-v7:22.1.1'
compile 'com.android.support:recyclerview-v7:22.1.1'
compile 'com.android.support:support-v4:22.2.0'
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:cardview-v7:22.2.0'
compile 'com.android.support:recyclerview-v7:22.2.0'
compile 'com.android.support:design:22.2.0'
// google play services
compile 'com.google.android.gms:play-services-location:7.3.0'
compile 'com.google.android.gms:play-services-analytics:7.3.0'

View file

@ -20,38 +20,29 @@
android:layout_marginTop="@dimen/margin_medium"
android:src="@drawable/ic_text_bookmark"/>
<TextView
android:id="@+id/tv__bookmark_title"
<com.mapswithme.maps.widget.CustomTextInputLayout
android:id="@+id/layout__bookmark_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="@id/iv__bookmark"
android:layout_toRightOf="@id/iv__bookmark"
android:lineSpacingMultiplier="1.67"
android:text="@string/name"
android:textColor="@color/text_place_page_subtitle"
android:textSize="@dimen/place_page_sub_subtitle"/>
android:layout_toRightOf="@id/iv__bookmark">
<EditText
android:id="@+id/et__bookmark_name"
style="@style/MwmWidget.PlacePage.EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/tv__bookmark_title"
android:layout_marginTop="@dimen/margin_tiny"
android:layout_toRightOf="@id/iv__bookmark"
android:hint="@string/name"
android:inputType="textCapWords"
android:lineSpacingMultiplier="1.43"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:singleLine="true"
android:textColor="@color/text_place_page"
android:textSize="@dimen/place_page_subtitle"/>
<EditText
android:id="@+id/et__bookmark_name"
style="@style/MwmWidget.PlacePage.EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/name"
android:inputType="textCapWords"
android:singleLine="true"
android:textSize="@dimen/place_page_subtitle"/>
</com.mapswithme.maps.widget.CustomTextInputLayout>
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_below="@id/et__bookmark_name"
android:layout_below="@id/layout__bookmark_name"
android:layout_marginTop="@dimen/margin_small"
android:background="?attr/dividerHorizontal"/>
@ -59,7 +50,7 @@
android:id="@+id/tv__bookmark_group_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/et__bookmark_name"
android:layout_below="@id/layout__bookmark_name"
android:layout_marginTop="@dimen/margin_medium_and_half"
android:layout_toRightOf="@id/iv__bookmark"
android:lineSpacingMultiplier="1.67"
@ -111,29 +102,24 @@
android:src="@drawable/color_picker_red_on"/>
</RelativeLayout>
<TextView
android:id="@+id/tv__bookmark_notes_title"
<com.mapswithme.maps.widget.CustomTextInputLayout
android:id="@+id/layout__bookmark_notes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/ll__group"
android:layout_marginTop="@dimen/margin_medium"
android:layout_toRightOf="@id/iv__bookmark"
android:lineSpacingMultiplier="1.67"
android:text="@string/description"
android:textColor="@color/text_place_page_subtitle"
android:textSize="@dimen/place_page_sub_subtitle"/>
android:layout_toRightOf="@id/iv__bookmark">
<EditText
android:id="@+id/et__bookmark_notes"
style="@style/MwmWidget.PlacePage.EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/description"
android:inputType="textMultiLine"
android:textCursorDrawable="@null"
android:textSize="@dimen/place_page_subtitle"/>
</com.mapswithme.maps.widget.CustomTextInputLayout>
<EditText
android:id="@+id/et__bookmark_notes"
style="@style/MwmWidget.PlacePage.EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/tv__bookmark_notes_title"
android:layout_marginBottom="@dimen/margin_medium"
android:layout_marginTop="@dimen/margin_tiny"
android:layout_toRightOf="@id/iv__bookmark"
android:inputType="textMultiLine"
android:lineSpacingMultiplier="1.43"
android:textColor="@color/text_place_page"
android:textSize="@dimen/place_page_subtitle"/>
</RelativeLayout>

View file

@ -73,6 +73,8 @@
<style name="MwmWidget.PlacePage.EditText" parent="Widget.AppCompat.EditText">
<item name="android:imeOptions">actionDone</item>
<item name="android:lineSpacingMultiplier">1.43</item>
<item name="android:textColor">@color/text_place_page</item>
</style>
<style name="MwmWidget.Toolbar" parent="ThemeOverlay.AppCompat.Dark.ActionBar">

View file

@ -0,0 +1,59 @@
package com.mapswithme.maps.widget;
import android.content.Context;
import android.graphics.Canvas;
import android.support.design.widget.TextInputLayout;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
/**
* Fixes bug mentioned here https://code.google.com/p/android/issues/detail?id=175228
*/
public class CustomTextInputLayout extends TextInputLayout
{
private boolean mIsHintSet;
private CharSequence mHint;
public CustomTextInputLayout(Context context)
{
super(context);
}
public CustomTextInputLayout(Context context, AttributeSet attrs)
{
super(context, attrs);
}
@Override
public void addView(View child, int index, ViewGroup.LayoutParams params)
{
if (child instanceof EditText)
// Since hint will be nullify on EditText once on parent addView, store hint value locally
mHint = ((EditText) child).getHint();
super.addView(child, index, params);
}
@Override
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
if (!mIsHintSet && ViewCompat.isLaidOut(this))
{
// We have to reset the previous hint so that equals check pass
setHint(null);
// In case that hint is changed programatically
CharSequence currentEditTextHint = getEditText().getHint();
if (currentEditTextHint != null && currentEditTextHint.length() > 0)
mHint = currentEditTextHint;
setHint(mHint);
mIsHintSet = true;
}
}
}

View file

@ -14,10 +14,8 @@ import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.Html;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.method.LinkMovementMethod;
import android.util.AttributeSet;
import android.view.LayoutInflater;
@ -92,7 +90,6 @@ public class PlacePageView extends RelativeLayout implements View.OnClickListene
// Bookmark
private ImageView mIvColor;
private EditText mEtBookmarkName;
private TextView mTvBookmarkNotes;
private EditText mEtBookmarkNotes;
private TextView mTvBookmarkGroup;
// Place page buttons
@ -189,28 +186,8 @@ public class PlacePageView extends RelativeLayout implements View.OnClickListene
}
mEtBookmarkName = (EditText) mPpDetails.findViewById(R.id.et__bookmark_name);
mTvBookmarkNotes = (TextView) mPpDetails.findViewById(R.id.tv__bookmark_notes_title);
mEtBookmarkNotes = (EditText) mPpDetails.findViewById(R.id.et__bookmark_notes);
mEtBookmarkNotes.addTextChangedListener(new TextWatcher()
{
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after)
{
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count)
{
mTvBookmarkNotes.setVisibility(s.length() == 0 ? View.VISIBLE : View.INVISIBLE);
}
@Override
public void afterTextChanged(Editable s)
{
}
});
mTvBookmarkGroup = (TextView) mPpDetails.findViewById(R.id.tv__bookmark_group);
mTvBookmarkGroup.setOnClickListener(this);
@ -362,7 +339,6 @@ public class PlacePageView extends RelativeLayout implements View.OnClickListene
final String notes = bookmark.getBookmarkDescription();
mEtBookmarkNotes.setText(Html.fromHtml(notes));
mEtBookmarkNotes.setMovementMethod(LinkMovementMethod.getInstance());
mTvBookmarkNotes.setVisibility(notes.isEmpty() ? View.VISIBLE : View.INVISIBLE);
mTvBookmarkGroup.setText(bookmark.getCategoryName(getContext()));
mIvColor.setImageResource(bookmark.getIcon().getSelectedResId());
mIvBookmark.setImageResource(R.drawable.ic_bookmark_on);