1/*
2 * Copyright (C) 2008 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
17package com.android.mms.ui;
18
19import android.content.Context;
20import android.text.ClipboardManager;
21import android.util.AttributeSet;
22import android.view.KeyEvent;
23import android.widget.ListView;
24
25public final class MessageListView extends ListView {
26    private OnSizeChangedListener mOnSizeChangedListener;
27
28    public MessageListView(Context context) {
29        super(context);
30    }
31
32    public MessageListView(Context context, AttributeSet attrs) {
33        super(context, attrs);
34    }
35
36    @Override
37    public boolean onKeyShortcut(int keyCode, KeyEvent event) {
38        switch (keyCode) {
39        case KeyEvent.KEYCODE_C:
40            MessageListItem view = (MessageListItem)getSelectedView();
41            if (view == null) {
42                break;
43            }
44            MessageItem item = view.getMessageItem();
45            if (item != null && item.isSms()) {
46                ClipboardManager clip =
47                    (ClipboardManager)getContext().getSystemService(Context.CLIPBOARD_SERVICE);
48                clip.setText(item.mBody);
49                return true;
50            }
51            break;
52        }
53
54        return super.onKeyShortcut(keyCode, event);
55    }
56
57    @Override
58    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
59        super.onSizeChanged(w, h, oldw, oldh);
60
61        if (mOnSizeChangedListener != null) {
62            mOnSizeChangedListener.onSizeChanged(w, h, oldw, oldh);
63        }
64    }
65
66    /**
67     * Set the listener which will be triggered when the size of
68     * the view is changed.
69     */
70    void setOnSizeChangedListener(OnSizeChangedListener l) {
71        mOnSizeChangedListener = l;
72    }
73
74    public interface OnSizeChangedListener {
75        void onSizeChanged(int width, int height, int oldWidth, int oldHeight);
76    }
77}
78
79