2 Copyright (C) 2014 Samsung Electronics Polska Sp. z o.o.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU AFFERO General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8 You may obtain a copy of the License at
10 http://www.gnu.org/licenses/agpl-3.0.txt
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 package com.samsung.srpol.ui;
23 import java.util.Timer;
24 import java.util.TimerTask;
25 import com.samsung.srpol.R;
26 import com.samsung.srpol.utils.Utils;
28 import android.app.Dialog;
29 import android.content.Context;
30 import android.graphics.Paint;
31 import android.view.View;
32 import android.widget.ImageButton;
33 import android.widget.ImageView;
34 import android.widget.ProgressBar;
35 import android.widget.TextView;
37 public class WelcomeDialog extends Dialog implements android.view.View.OnClickListener{
38 private boolean isFirstTime;
39 private ImageButton mOkButton;
40 private TextView mDescriptionTextLink;
41 private ImageView mNpLogo, mSamsungLogo, mGovLogo;
42 private ProgressBar mProgressBar;
43 private Context mContext;
44 private boolean attachedToWindow = false;
45 private boolean mCanBeClosed;
46 private boolean mOpenedFromMenu = false;
48 public WelcomeDialog(Context context, boolean openedFromMenu) {
49 super(context, R.style.WelcomeDialog);
51 mOpenedFromMenu = openedFromMenu;
52 setContentView(R.layout.welcome_dialog);
54 mOkButton = (ImageButton) this.findViewById(R.id.button);
55 mDescriptionTextLink = (TextView) this.findViewById(R.id.welcome_description_link);
56 mDescriptionTextLink.setPaintFlags(Paint.UNDERLINE_TEXT_FLAG);
57 mProgressBar = (ProgressBar) this.findViewById(R.id.progressBar);
58 mNpLogo = (ImageView) findViewById(R.id.fondation_logo);
59 mSamsungLogo = (ImageView) findViewById(R.id.samsung_logo);
60 mGovLogo = (ImageView) findViewById(R.id.gov_logo);
61 TextView versionName = (TextView) findViewById(R.id.app_version);
62 versionName.setText(Utils.getAppVersionCode(context));
63 mOkButton.setOnClickListener(this);
64 mDescriptionTextLink.setOnClickListener(this);
65 mNpLogo.setOnClickListener(this);
66 mSamsungLogo.setOnClickListener(this);
67 mGovLogo.setOnClickListener(this);
69 isFirstTime = Utils.isFirstRun(this.getContext());
73 if (!isFirstTime && !mOpenedFromMenu) {
74 new Timer().schedule(new TimerTask() {
78 synchronized (WelcomeDialog.this) {
80 WelcomeDialog.this.dismissDialog();
90 * @see android.app.Dialog#onBackPressed()
93 public void onBackPressed() {
94 if(mOkButton.getVisibility() == View.VISIBLE){
95 super.onBackPressed();
101 public void onClick(View v) {
103 this.dismissDialog();
104 } else if(v == mDescriptionTextLink){
105 Utils.startBrowser(mContext, mContext.getString(R.string.app_info_more_info));
106 } else if(v == mNpLogo){
107 Utils.startBrowser(mContext, mContext.getString(R.string.fond_site));
108 } else if(v == mSamsungLogo){
109 Utils.startBrowser(mContext, mContext.getString(R.string.samsung_site));
110 } else if(v == mGovLogo){
111 Utils.startBrowser(mContext, mContext.getString(R.string.gov_site));
115 * @see android.app.Dialog#onAttachedToWindow()
118 public void onAttachedToWindow() {
119 super.onAttachedToWindow();
120 attachedToWindow = true;
125 * @see android.app.Dialog#onDetachedFromWindow()
128 public void onDetachedFromWindow() {
129 attachedToWindow = false;
130 super.onDetachedFromWindow();
133 public void loadingDone() {
134 if (mOpenedFromMenu) {
138 mProgressBar.setVisibility(View.GONE);
139 mOkButton.setVisibility(View.VISIBLE);
141 synchronized (this) {
150 private void dismissDialog(){
151 if(attachedToWindow){
157 * @return the mOpenedFromMenu
159 public boolean ismOpenedFromMenu() {
160 return mOpenedFromMenu;
163 public void show(boolean openedFromMenu) {
164 mOpenedFromMenu = openedFromMenu;
165 if (openedFromMenu) {
166 mOkButton.setVisibility(View.VISIBLE);
167 mProgressBar.setVisibility(View.GONE);
169 mProgressBar.setVisibility(View.VISIBLE);
170 mOkButton.setVisibility(View.GONE);