View Javadoc
1   /*
2    * Copyright (C) 2003-2014 eXo Platform SAS.
3    *
4    * This is free software; you can redistribute it and/or modify it
5    * under the terms of the GNU Lesser General Public License as
6    * published by the Free Software Foundation; either version 3 of
7    * the License, or (at your option) any later version.
8    *
9    * This software is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   * Lesser General Public License for more details.
13   *
14   * You should have received a copy of the GNU Lesser General Public
15   * License along with this software; if not, write to the Free
16   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
18   */
19  package org.exoplatform.widget;
20  
21  import org.exoplatform.R;
22  import org.exoplatform.controller.social.ComposeMessageController;
23  import org.exoplatform.ui.DocumentActionDialog;
24  import org.exoplatform.utils.PhotoUtils;
25  
26  import android.app.Activity;
27  import android.app.Dialog;
28  import android.view.View;
29  import android.view.Window;
30  import android.widget.Button;
31  
32  public class AddPhotoDialog extends Dialog implements android.view.View.OnClickListener {
33  
34    private Button                   takePhotoButton;
35  
36    private Button                   libraryButton;
37  
38    private Button                   cancelButton;
39  
40    private Activity                 mActivity;
41  
42    private ComposeMessageController messageController;
43  
44    private DocumentActionDialog     fileActionDialog;
45  
46    public AddPhotoDialog(Activity callingActivity, DocumentActionDialog dialog) {
47      super(callingActivity);
48      requestWindowFeature(Window.FEATURE_NO_TITLE);
49      setContentView(R.layout.add_photo_dialog_layout);
50      mActivity = callingActivity;
51      fileActionDialog = dialog;
52  
53      init();
54  
55    }
56  
57    public AddPhotoDialog(Activity callingActivity, ComposeMessageController controller) {
58      super(callingActivity);
59      requestWindowFeature(Window.FEATURE_NO_TITLE);
60      setContentView(R.layout.add_photo_dialog_layout);
61      mActivity = callingActivity;
62      messageController = controller;
63  
64      init();
65    }
66  
67    private void init() {
68  
69      takePhotoButton = (Button) findViewById(R.id.add_photo_take_button);
70      takePhotoButton.setOnClickListener(this);
71      libraryButton = (Button) findViewById(R.id.add_photo_library_button);
72      libraryButton.setOnClickListener(this);
73      cancelButton = (Button) findViewById(R.id.add_photo_cancel_button);
74      cancelButton.setOnClickListener(this);
75  
76    }
77  
78    public void onClick(View view) {
79      if (view.equals(cancelButton)) {
80        dismiss();
81      } else {
82        if (view.equals(takePhotoButton)) {
83          // take photo
84          dismiss();
85            startCapture();
86        } else if (view.equals(libraryButton)) {
87          // pick photo from gallery
88          dismiss();
89            pickPhoto();
90        }
91      }
92    }
93    
94    private void startCapture() {
95      if (messageController == null)
96        fileActionDialog._documentActionAdapter.initCamera();
97      else
98        messageController.initCamera();
99    }
100   
101   private void pickPhoto() {
102     PhotoUtils.pickPhotoForActivity(mActivity);
103   }
104 }