title: TextView with ellipsize middle casues "ArrayIndexOutOfBoundsException" Exception
body: <p><strong>Edited:</strong></p>
  
  <p>I am getting <code>java.lang.ArrayIndexOutOfBoundsException:</code> <strong>Exception</strong> for a TextView with ellipsize <code>middle</code>. Here is my TextView</p>
  
  <pre><code>        &lt;TextView
          android:id="@+id/textView"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_marginLeft="25dp"
          android:layout_marginRight="25dp"
          android:ellipsize="middle"
          android:maxLines="1"
          android:paddingLeft="10dp"
          android:paddingRight="27dp"
          android:text="123456 123 1234567890123456"
          android:textSize="16sp" /&gt;
  </code></pre>
  
  <p>I have experimented with this <strong>Exception</strong> and its causing for <code>calculateEllipsis()</code> method with this given margin, padding,textSize and singleLine. </p>
  
  <p>Here is <strong>CrashLog</strong></p>
  
  <pre><code>FATAL EXCEPTION: main
      java.lang.ArrayIndexOutOfBoundsException: length=125; index=-1
          at android.text.StaticLayout.calculateEllipsis(StaticLayout.java:786)
          at android.text.StaticLayout.out(StaticLayout.java:705)
          at android.text.StaticLayout.generate(StaticLayout.java:410)
          at android.text.StaticLayout.&lt;init&gt;(StaticLayout.java:140)
          at android.widget.TextView.makeSingleLayout(TextView.java:6068)
          at android.widget.TextView.makeNewLayout(TextView.java:5925)
          at android.widget.TextView.onMeasure(TextView.java:6282)
          at android.view.View.measure(View.java:15635)
          at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4919)
          at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1411)
          at android.widget.LinearLayout.measureVertical(LinearLayout.java:698)
          at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
          at android.view.View.measure(View.java:15635)
          at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:681)
          at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
          at android.view.View.measure(View.java:15635)
          at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4919)
          at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
          at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)
          at android.view.View.measure(View.java:15635)
          at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4919)
          at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1411)
          at android.widget.LinearLayout.measureVertical(LinearLayout.java:698)
          at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
          at android.view.View.measure(View.java:15635)
          at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4919)
          at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
          at android.view.View.measure(View.java:15635)
          at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4919)
          at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1411)
          at android.widget.LinearLayout.measureVertical(LinearLayout.java:698)
          at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
          at android.view.View.measure(View.java:15635)
          at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4919)
          at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
          at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2200)
          at android.view.View.measure(View.java:15635)
          at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2165)
          at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1249)
          at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1443)
          at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1139)
          at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4872)
          at android.view.Choreographer$CallbackRecord.run(Choreographer.java:776)
          at android.view.Choreographer.doCallbacks(Choreographer.java:579)
          at android.view.Choreographer.doFrame(Choreographer.java:548)
          at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:762)
          at android.os.Handler.handleCallback(Handler.java:800)
          at android.os.Handler.dispatchMessage(Handler.java:100)
          at android.os.Looper.loop(Looper.java:194)
          at android.app.ActivityThread.main(ActivityThread.java:5371)
          at java.lang.reflect.Method.invokeNative(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:525)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
          at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>Here is some scenario where i am not getting <strong>Exception</strong> </p>
  
  <ol>
  <li>If i remove the last character( set text "123456 123 123456789012345" removed '6' from last ) then i don't get Exception</li>
  <li>If i set textSize <strong>14sp</strong> then i don't get any Exception </li>
  <li>IF i set ellipsize="end" it worked fine.</li>
  <li>Its working fine in high resolution devices with same TextView properties.</li>
  </ol>
  
  <p>I think making <strong>ellipsize middle</strong> with the large last word "1234567890123456" (16 character) caused This Exception.</p>
  
  <p>Here is my device Specification:</p>
  
  <ol>
  <li>Model: <strong>HUAWEI Y320-U30</strong> </li>
  <li>Android <strong>Version: 4.2.2</strong></li>
  </ol>
  
  <p>Can anyone explain whats wrong with <code>calculateEllipsis()</code> method with this scenario. </p>
  
  <p>Thanks in advance.</p>