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.ui.login;
20  
21  import org.exoplatform.R;
22  
23  import android.app.Dialog;
24  import android.content.Context;
25  import android.view.View;
26  import android.view.Window;
27  import android.widget.Button;
28  import android.widget.TextView;
29  
30  /**
31   * A dialog that display a warning message with an animation <br/>
32   */
33  public class LoginWarningDialog extends Dialog implements android.view.View.OnClickListener {
34  
35    private   TextView    mTitleTxt;
36  
37    private   TextView    mMessageTxt;
38  
39    protected Button      mBtn;
40  
41    private   int         mWindowsAnim = 0;
42  
43    public LoginWarningDialog(Context context) {
44      super(context);
45      requestWindowFeature(Window.FEATURE_NO_TITLE);
46      setContentView(R.layout.login_warning_dialog_layout);
47  
48      initSubViews();
49    }
50  
51    public LoginWarningDialog(Context context, String titleString, String contentString, String okString) {
52      super(context);
53      requestWindowFeature(Window.FEATURE_NO_TITLE);
54      setContentView(R.layout.login_warning_dialog_layout);
55  
56      initSubViews();
57  
58      mTitleTxt.setText(titleString);
59      mMessageTxt.setText(contentString);
60      mBtn.setText(okString);
61    }
62  
63    private void initSubViews() {
64      mTitleTxt   = (TextView) findViewById(R.id.warning_dialog_title_txt);
65      mMessageTxt = (TextView) findViewById(R.id.warning_dialog_message_txt);
66      mBtn        = (Button)   findViewById(R.id.warning_dialog_btn);
67      mBtn.setOnClickListener(this);
68    }
69  
70    public LoginWarningDialog setTitle(String title) {
71      mTitleTxt.setText(title);
72      return this;
73    }
74  
75    public LoginWarningDialog setMessage(String message) {
76      mMessageTxt.setText(message);
77      return this;
78    }
79  
80    public LoginWarningDialog setButtonText(String text) {
81      mBtn.setText(text);
82      return this;
83    }
84  
85    public LoginWarningDialog setWindowsAnimation(int anim) {
86      mWindowsAnim = anim;
87      return this;
88    }
89  
90    @Override
91    public void show() {
92      getWindow().getAttributes().windowAnimations = mWindowsAnim != 0
93          ? mWindowsAnim : R.style.Animations_Window;
94      super.show();
95    }
96  
97    public void onClick(View view) {
98      if (view.equals(mBtn)) {
99        dismiss();
100 
101       if (mViewListener != null) mViewListener.onClickOk(this);
102     }
103   }
104 
105   private ViewListener mViewListener;
106 
107   /* interface to listen to view event */
108   public interface ViewListener {
109 
110     void onClickOk(LoginWarningDialog dialog);
111   }
112 
113   public void setViewListener(ViewListener l) {
114     mViewListener = l;
115   }
116 }