Home | History | Annotate | Download | only in openwnn
      1 /*
      2  * Copyright (C) 2008,2009  OMRON SOFTWARE Co., Ltd.
      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 jp.co.omronsoft.openwnn;
     18 
     19 import android.widget.Button;
     20 import android.view.MotionEvent;
     21 import android.view.View;
     22 import android.graphics.drawable.Drawable;
     23 import android.util.AttributeSet;
     24 import android.content.Context;
     25 
     26 /**
     27  * The button for the candidate-view
     28  * @author Copyright (C) 2009, OMRON SOFTWARE CO., LTD.  All Rights Reserved.
     29  */
     30 public class CandidateViewButton extends Button {
     31 
     32     /** The state of up */
     33     private int[] mUpState;
     34 
     35     /** Constructor */
     36     public CandidateViewButton(Context context) {
     37         super(context);
     38     }
     39 
     40     /** Constructor */
     41     public CandidateViewButton(Context context, AttributeSet attrs) {
     42         super(context, attrs);
     43     }
     44 
     45     /** @see android.view.View#onTouchEvent */
     46     public boolean onTouchEvent(MotionEvent me) {
     47         /* for changing the button on CandidateView when it is pressed. */
     48 
     49         boolean ret = super.onTouchEvent(me);
     50         Drawable d = getBackground();
     51 
     52         switch (me.getAction()) {
     53         case MotionEvent.ACTION_DOWN:
     54             mUpState = d.getState();
     55             d.setState(View.PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET);
     56             break;
     57         case MotionEvent.ACTION_UP:
     58         default:
     59             d.setState(mUpState);
     60             break;
     61         }
     62 
     63         return ret;
     64     }
     65 }
     66