1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package android.databinding.testapp.vo; 17 18 import android.databinding.Bindable; 19 import android.databinding.adapters.TextViewBindingAdapter; 20 import android.databinding.testapp.BR; 21 import android.text.Editable; 22 import android.text.InputType; 23 import android.text.method.KeyListener; 24 import android.text.method.TextKeyListener; 25 import android.text.util.Linkify; 26 import android.view.KeyEvent; 27 import android.view.View; 28 import android.widget.TextView; 29 30 public class TextViewBindingObject extends BindingAdapterBindingObject { 31 32 @Bindable 33 private int mAutoLink = Linkify.WEB_URLS; 34 35 @Bindable 36 private int mDrawablePadding; 37 38 @Bindable 39 private int mInputType = InputType.TYPE_CLASS_PHONE; 40 41 @Bindable 42 private boolean mScrollHorizontally; 43 44 @Bindable 45 private boolean mTextAllCaps; 46 47 @Bindable 48 private int mTextColorHighlight; 49 50 @Bindable 51 private int mTextColorHint; 52 53 @Bindable 54 private int mTextColorLink; 55 56 @Bindable 57 private boolean mAutoText; 58 59 @Bindable 60 private TextKeyListener.Capitalize mCapitalize = TextKeyListener.Capitalize.NONE; 61 62 @Bindable 63 private TextView.BufferType mBufferType = TextView.BufferType.NORMAL; 64 65 @Bindable 66 private String mDigits = "abcdefg"; 67 68 @Bindable 69 private int mNumeric = TextViewBindingAdapter.DECIMAL; 70 71 @Bindable 72 private boolean mPhoneNumber; 73 74 @Bindable 75 private int mDrawableBottom; 76 77 @Bindable 78 private int mDrawableTop; 79 80 @Bindable 81 private int mDrawableLeft; 82 83 @Bindable 84 private int mDrawableRight; 85 86 @Bindable 87 private int mDrawableStart; 88 89 @Bindable 90 private int mDrawableEnd; 91 92 @Bindable 93 private String mImeActionLabel; 94 95 @Bindable 96 private int mImeActionId; 97 98 @Bindable 99 private String mInputMethod 100 = "android.databinding.testapp.vo.TextViewBindingObject$KeyListener1"; 101 102 @Bindable 103 private float mLineSpacingExtra; 104 105 @Bindable 106 private float mLineSpacingMultiplier; 107 108 @Bindable 109 private int mMaxLength; 110 111 @Bindable 112 private int mShadowColor; 113 114 @Bindable 115 private float mShadowDx; 116 117 @Bindable 118 private float mShadowDy; 119 120 @Bindable 121 private float mShadowRadius; 122 123 @Bindable 124 private float mTextSize = 10f; 125 126 @Bindable 127 private String mText; 128 getBufferType()129 public TextView.BufferType getBufferType() { 130 return mBufferType; 131 } 132 getLineSpacingExtra()133 public float getLineSpacingExtra() { 134 return mLineSpacingExtra; 135 } 136 getLineSpacingMultiplier()137 public float getLineSpacingMultiplier() { 138 return mLineSpacingMultiplier; 139 } 140 getShadowDx()141 public float getShadowDx() { 142 return mShadowDx; 143 } 144 getShadowDy()145 public float getShadowDy() { 146 return mShadowDy; 147 } 148 getShadowRadius()149 public float getShadowRadius() { 150 return mShadowRadius; 151 } 152 getTextSize()153 public float getTextSize() { 154 return mTextSize; 155 } 156 getAutoLink()157 public int getAutoLink() { 158 return mAutoLink; 159 } 160 getDrawableBottom()161 public int getDrawableBottom() { 162 return mDrawableBottom; 163 } 164 getDrawableEnd()165 public int getDrawableEnd() { 166 return mDrawableEnd; 167 } 168 getDrawableLeft()169 public int getDrawableLeft() { 170 return mDrawableLeft; 171 } 172 getDrawablePadding()173 public int getDrawablePadding() { 174 return mDrawablePadding; 175 } 176 getDrawableRight()177 public int getDrawableRight() { 178 return mDrawableRight; 179 } 180 getDrawableStart()181 public int getDrawableStart() { 182 return mDrawableStart; 183 } 184 getDrawableTop()185 public int getDrawableTop() { 186 return mDrawableTop; 187 } 188 getImeActionId()189 public int getImeActionId() { 190 return mImeActionId; 191 } 192 getInputType()193 public int getInputType() { 194 return mInputType; 195 } 196 getMaxLength()197 public int getMaxLength() { 198 return mMaxLength; 199 } 200 getNumeric()201 public int getNumeric() { 202 return mNumeric; 203 } 204 getShadowColor()205 public int getShadowColor() { 206 return mShadowColor; 207 } 208 getTextColorHighlight()209 public int getTextColorHighlight() { 210 return mTextColorHighlight; 211 } 212 getTextColorHint()213 public int getTextColorHint() { 214 return mTextColorHint; 215 } 216 getTextColorLink()217 public int getTextColorLink() { 218 return mTextColorLink; 219 } 220 getDigits()221 public String getDigits() { 222 return mDigits; 223 } 224 getImeActionLabel()225 public String getImeActionLabel() { 226 return mImeActionLabel; 227 } 228 getInputMethod()229 public String getInputMethod() { 230 return mInputMethod; 231 } 232 isAutoText()233 public boolean isAutoText() { 234 return mAutoText; 235 } 236 getCapitalize()237 public TextKeyListener.Capitalize getCapitalize() { 238 return mCapitalize; 239 } 240 setCapitalize(TextKeyListener.Capitalize capitalize)241 public void setCapitalize(TextKeyListener.Capitalize capitalize) { 242 mCapitalize = capitalize; 243 notifyPropertyChanged(BR.capitalize); 244 } 245 isPhoneNumber()246 public boolean isPhoneNumber() { 247 return mPhoneNumber; 248 } 249 isScrollHorizontally()250 public boolean isScrollHorizontally() { 251 return mScrollHorizontally; 252 } 253 isTextAllCaps()254 public boolean isTextAllCaps() { 255 return mTextAllCaps; 256 } 257 getText()258 public String getText() { 259 return mText; 260 } 261 setText(String text)262 public void setText(String text) { 263 mText = text; 264 notifyPropertyChanged(BR.text); 265 } 266 changeValues()267 public void changeValues() { 268 mAutoLink = Linkify.EMAIL_ADDRESSES; 269 mDrawablePadding = 10; 270 mInputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_WORDS; 271 mScrollHorizontally = true; 272 mTextAllCaps = true; 273 mTextColorHighlight = 0xFF00FF00; 274 mTextColorHint = 0xFFFF0000; 275 mTextColorLink = 0xFF0000FF; 276 mAutoText = true; 277 mCapitalize = TextKeyListener.Capitalize.SENTENCES; 278 mBufferType = TextView.BufferType.SPANNABLE; 279 mDigits = "hijklmno"; 280 mNumeric = TextViewBindingAdapter.SIGNED; 281 mPhoneNumber = true; 282 mDrawableBottom = 0xFF880088; 283 mDrawableTop = 0xFF111111; 284 mDrawableLeft = 0xFF222222; 285 mDrawableRight = 0xFF333333; 286 mDrawableStart = 0xFF444444; 287 mDrawableEnd = 0xFF555555; 288 mImeActionLabel = "Hello World"; 289 mImeActionId = 3; 290 mInputMethod = "android.databinding.testapp.vo.TextViewBindingObject$KeyListener2"; 291 mLineSpacingExtra = 2; 292 mLineSpacingMultiplier = 3; 293 mMaxLength = 100; 294 mShadowColor = 0xFF666666; 295 mShadowDx = 2; 296 mShadowDy = 3; 297 mShadowRadius = 4; 298 mTextSize = 20f; 299 notifyChange(); 300 } 301 302 public static class KeyListener1 implements KeyListener { 303 304 @Override getInputType()305 public int getInputType() { 306 return InputType.TYPE_CLASS_TEXT; 307 } 308 309 @Override onKeyDown(View view, Editable text, int keyCode, KeyEvent event)310 public boolean onKeyDown(View view, Editable text, int keyCode, KeyEvent event) { 311 return false; 312 } 313 314 @Override onKeyUp(View view, Editable text, int keyCode, KeyEvent event)315 public boolean onKeyUp(View view, Editable text, int keyCode, KeyEvent event) { 316 return false; 317 } 318 319 @Override onKeyOther(View view, Editable text, KeyEvent event)320 public boolean onKeyOther(View view, Editable text, KeyEvent event) { 321 return false; 322 } 323 324 @Override clearMetaKeyState(View view, Editable content, int states)325 public void clearMetaKeyState(View view, Editable content, int states) { 326 } 327 } 328 329 public static class KeyListener2 extends KeyListener1 { 330 331 } 332 } 333