1/*
2 * Copyright (C) 2008 Esmertec AG.
3 * Copyright (C) 2008 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18package com.android.im.app;
19
20import com.android.im.R;
21import com.android.im.provider.Imps;
22
23import android.content.Context;
24import android.content.res.Resources;
25import android.graphics.Rect;
26import android.graphics.drawable.Drawable;
27import android.view.View;
28
29public class ChatBackgroundMaker {
30    private final Drawable mIncomingBg;
31    private final Drawable mDivider;
32    private final Rect mPadding;
33
34    public ChatBackgroundMaker(Context context) {
35        Resources res = context.getResources();
36        mIncomingBg = res.getDrawable(R.drawable.textfield_im_received);
37        mDivider = res.getDrawable(R.drawable.text_divider_horizontal);
38        mPadding = new Rect();
39        mIncomingBg.getPadding(mPadding);
40    }
41
42    public void setBackground(MessageView view, String contact, int type) {
43        View msgText = view.findViewById(R.id.message);
44
45        switch (type) {
46            case Imps.MessageType.INCOMING:
47                // TODO: set color according different contact
48                msgText.setBackgroundDrawable(mIncomingBg);
49                break;
50
51            case Imps.MessageType.OUTGOING:
52            case Imps.MessageType.POSTPONED:
53                msgText.setBackgroundDrawable(null);
54                msgText.setPadding(mPadding.left, mPadding.top, mPadding.right,
55                      mPadding.bottom);
56                break;
57
58            default:
59                msgText.setBackgroundDrawable(mDivider);
60        }
61    }
62}
63