OSDN Git Service

Initial commit
[worldopac/WorldOpac.git] / WorldOpac / src / de / geeksfactory / opacclient / frontend / WelcomeActivity.java
1 /**
2  * Copyright (C) 2013 by Raphael Michel under the MIT license:
3  * 
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), 
6  * to deal in the Software without restriction, including without limitation 
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense, 
8  * and/or sell copies of the Software, and to permit persons to whom the Software 
9  * is furnished to do so, subject to the following conditions:
10  * 
11  * The above copyright notice and this permission notice shall be included in 
12  * all copies or substantial portions of the Software.
13  * 
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
17  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
18  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
20  * DEALINGS IN THE SOFTWARE.
21  */
22 package de.geeksfactory.opacclient.frontend;
23
24 import java.io.InterruptedIOException;
25
26 import org.acra.ACRA;
27 import org.holoeverywhere.app.Activity;
28 import org.holoeverywhere.app.AlertDialog;
29
30 import android.content.Intent;
31 import android.os.Bundle;
32 import android.view.View;
33 import android.view.View.OnClickListener;
34 import android.widget.Button;
35 import de.geeksfactory.opacclient.OpacClient;
36 import de.geeksfactory.opacclient.OpacTask;
37 import jp.sourceforge.worldopac.R;
38
39 public class WelcomeActivity extends Activity {
40         protected OpacClient app;
41         protected AlertDialog dialog;
42
43         public static int getLayoutResource() {
44                 return R.layout.activity_welcome;
45         }
46
47         @Override
48         public void onCreate(Bundle savedInstanceState) {
49                 super.onCreate(savedInstanceState);
50                 app = (OpacClient) getApplication();
51                 setContentView(getLayoutResource());
52
53                 Button btAddAccount = (Button) findViewById(R.id.btAddAccount);
54                 btAddAccount.setOnClickListener(new OnClickListener() {
55                         @Override
56                         public void onClick(View arg0) {
57                                 add();
58                         }
59                 });
60         }
61
62         @Override
63         public void onBackPressed() {
64                 System.exit(0);
65                 super.onBackPressed();
66         }
67
68         public void add() {
69                 Intent i = new Intent(this, LibraryListActivity.class);
70                 i.putExtra("welcome", true);
71                 startActivity(i);
72         }
73
74         public class InitTask extends OpacTask<Integer> {
75                 @Override
76                 protected Integer doInBackground(Object... arg0) {
77                         super.doInBackground(arg0);
78                         try {
79                                 app.getApi().start();
80                         } catch (java.net.UnknownHostException e) {
81                                 e.printStackTrace();
82                         } catch (java.net.SocketException e) {
83                                 e.printStackTrace();
84                         } catch (InterruptedIOException e) {
85                                 e.printStackTrace();
86                         } catch (Exception e) {
87                                 ACRA.getErrorReporter().handleException(e);
88                         }
89                         return 0;
90                 }
91
92                 @Override
93                 protected void onPostExecute(Integer result) {
94                         dialog.dismiss();
95                         Intent intent = new Intent(WelcomeActivity.this, MainActivity.class);
96                         startActivity(intent);
97                 }
98         }
99
100         @Override
101         protected void onStop() {
102                 super.onStop();
103                 if (dialog != null) {
104                         if (dialog.isShowing()) {
105                                 dialog.cancel();
106                         }
107                 }
108         }
109
110 }