1 /* 2 * Copyright (C) 2012 Google Inc. 3 * Licensed to 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 18 package com.android.mail.browse; 19 20 import android.content.AsyncQueryHandler; 21 import android.content.ContentValues; 22 import android.content.Context; 23 import android.content.Intent; 24 import android.util.AttributeSet; 25 import android.view.View; 26 import android.widget.LinearLayout; 27 28 import com.android.mail.R; 29 import com.android.mail.providers.Message; 30 import com.android.mail.providers.UIProvider; 31 import com.android.mail.utils.LogUtils; 32 import com.android.mail.utils.Utils; 33 34 public class MessageInviteView extends LinearLayout implements View.OnClickListener { 35 36 private Message mMessage; 37 private final Context mContext; 38 private InviteCommandHandler mCommandHandler = new InviteCommandHandler(); 39 40 public MessageInviteView(Context c) { 41 this(c, null); 42 } 43 44 public MessageInviteView(Context c, AttributeSet attrs) { 45 super(c, attrs); 46 mContext = c; 47 } 48 49 @Override 50 protected void onFinishInflate() { 51 super.onFinishInflate(); 52 53 findViewById(R.id.invite_calendar_view).setOnClickListener(this); 54 findViewById(R.id.accept).setOnClickListener(this); 55 findViewById(R.id.tentative).setOnClickListener(this); 56 findViewById(R.id.decline).setOnClickListener(this); 57 } 58 59 public void bind(Message message) { 60 mMessage = message; 61 } 62 63 @Override 64 public void onClick(View v) { 65 Integer command = null; 66 67 final int id = v.getId(); 68 69 if (id == R.id.invite_calendar_view) { 70 if (!Utils.isEmpty(mMessage.eventIntentUri)) { 71 Intent intent = new Intent(Intent.ACTION_VIEW); 72 intent.setData(mMessage.eventIntentUri); 73 mContext.startActivity(intent); 74 } 75 } else if (id == R.id.accept) { 76 command = UIProvider.MessageOperations.RESPOND_ACCEPT; 77 } else if (id == R.id.tentative) { 78 command = UIProvider.MessageOperations.RESPOND_TENTATIVE; 79 } else if (id == R.id.decline) { 80 command = UIProvider.MessageOperations.RESPOND_DECLINE; 81 } 82 83 if (command != null) { 84 ContentValues params = new ContentValues(); 85 LogUtils.w("UnifiedEmail", "SENDING INVITE COMMAND, VALUE=%s", command); 86 params.put(UIProvider.MessageOperations.RESPOND_COLUMN, command); 87 mCommandHandler.sendCommand(params); 88 } 89 } 90 91 private class InviteCommandHandler extends AsyncQueryHandler { 92 93 public InviteCommandHandler() { 94 super(getContext().getContentResolver()); 95 } 96 97 public void sendCommand(ContentValues params) { 98 startUpdate(0, null, mMessage.uri, params, null, null); 99 } 100 101 } 102 } 103