Home | History | Annotate | Download | only in compose
      1 /**
      2  * Copyright (c) 2014, Google Inc.
      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 
     17 package com.android.mail.compose;
     18 
     19 import android.content.Context;
     20 import android.util.AttributeSet;
     21 import android.widget.EditText;
     22 
     23 public class BodyView extends EditText {
     24 
     25     public interface SelectionChangedListener {
     26         /**
     27          * @param start new selection start
     28          * @param end new selection end
     29          * @return true to suppress normal selection change processing
     30          */
     31         boolean onSelectionChanged(int start, int end);
     32     }
     33 
     34     private SelectionChangedListener mSelectionListener;
     35 
     36     public BodyView(Context c) {
     37         this(c, null);
     38     }
     39 
     40     public BodyView(Context c, AttributeSet attrs) {
     41         super(c, attrs);
     42     }
     43 
     44     @Override
     45     protected void onSelectionChanged(int selStart, int selEnd) {
     46         if (mSelectionListener != null) {
     47             if (mSelectionListener.onSelectionChanged(selStart, selEnd)) {
     48                 return;
     49             }
     50         }
     51         super.onSelectionChanged(selStart, selEnd);
     52     }
     53 
     54     public void setSelectionChangedListener(SelectionChangedListener l) {
     55         mSelectionListener = l;
     56     }
     57 
     58 }
     59