title: textView.getSelectionEnd() returning start index value on Samsung Marshmallow 6.0 devices
body: <p>This issue is observed on <strong>Samsung devices with Android 6.0</strong> only. It is working fine on all other devices, including non - Samsung devices with android 6.0 and Samsung devices with Android 5.1 and below.</p>
  
  <p>Currently we don`t have any Samsung device with Android 6.0 to readily check things on it, but we are arranging it soon.</p>
  
  <hr>
  
  <p>The feature where we are using this :</p>
  
  <p>The user long presses on a word from a sentence in a TextView and then user can edit the selected word.</p>
  
  <hr>
  
  <p>We accomplish this by :</p>
  
  <ul>
  <li>Making the TextView selectable and adding a LongClickListener.</li>
  <li>Adding a custom Selection Action Mode CallBack and overriding onCreateActionMode() to return false, since we don`t need the default cut-copy-paste action mode.</li>
  <li>Handling the onLongClickListener to get the exact selected word and provide a UI to correct and replace the word.</li>
  </ul>
  
  <hr>
  
  <p>The issue we are facing :</p>
  
  <p><strong>textView.getSelectionStart()</strong> returns the correct start index but <strong>textView.getSelectionEnd()</strong> returns the value of start index instead of end index. We have a guard condition that whenever start and end index are same then the selection is for a space and hence we ignore it, thus all the word selections on Samsung devices with Android 6.0 and up are ignored resulting into the feature failure.</p>
  
  <hr>
  
  <p>Things we tried :</p>
  
  <ul>
  <li>We tried replacing the <strong>ActionMode.Callback</strong> with
  <strong>ActionMode.Callback2</strong> as mentioned under "Text Selection" section on page <a href="https://developer.android.com/about/versions/marshmallow/android-6.0-changes.html">Android 6.0 Changes</a> but it didn`t help in fixing this
  issue.</li>
  <li>Tried searching for any extra samsung setting available related to text selection, clipboard etc but no luck. I know this can be a lame option but i do not take chances with Samsung Touchwiz. I did found a setting to alter the delay for touch selection ranging from 0.5 to 2.0 seconds.</li>
  </ul>
  
  <p>The code snippets :</p>
  
  <pre><code>tvText.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
          @Override
          public boolean onCreateActionMode(ActionMode mode, Menu menu) {
              return false; // true = create the ActionMode
          }
  
          @Override
          public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
              return false;
          }
  
          @Override
          public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
              return false;
          }
  
          @Override
          public void onDestroyActionMode(ActionMode mode) {
          }
      });
  
      tvText.setOnLongClickListener(new View.OnLongClickListener() { 
  
          @Override
          public boolean onLongClick(View v) {
  
              final TextView textView = (TextView) v;
              new Handler().postDelayed(new Runnable() {
  
                  @Override
                  public void run() {
  
                      //This works correct on all devices with Android 6.0
                      int startIndex = textView.getSelectionStart();
  
                      //This works wrong on Samsung devices with Android 6.0, result is same as getSelectionStart()
                      int endIndex = textView.getSelectionEnd();
  
                      //The guard condition where we ignore the empty selections
                      if ((endIndex - startIndex) &lt;= 0) {
                          return;
                      }
  
                      // Do bunch of things to UI like applying some different foreground colors to the selected word, striking out selected word etc.
                  }
              }, TEXT_LONG_PRESS_DELAY);
              return false;
          }
      }); 
  </code></pre>
  
  <p>The xml code for the TextView and it`s style :</p>
  
  <pre><code>&lt;TextView
      android:id="@+id/tvText"
      style="@style/StyleChatBubbleText"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginBottom="2dp"/&gt;
  
  &lt;style name="StyleChatBubbleText"&gt;
      &lt;item name="android:layout_width"&gt;wrap_content&lt;/item&gt;
      &lt;item name="android:layout_height"&gt;wrap_content&lt;/item&gt;
      &lt;item name="android:textSize"&gt;16dp&lt;/item&gt;
      &lt;item name="android:textColor"&gt;@color/text_black&lt;/item&gt;
      &lt;item name="android:textIsSelectable"&gt;true&lt;/item&gt;
      &lt;item name="typeface"&gt;roboto_regular&lt;/item&gt;
  </code></pre>
  
  <p></p>
  
  <hr>
  
  <p>Any help regarding this issue is appreciated.</p>