OSDN Git Service

Initial commit
[worldopac/WorldOpac.git] / WorldOpac / src / de / geeksfactory / opacclient / frontend / MainPreferenceActivity.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 org.holoeverywhere.preference.Preference;
25 import org.holoeverywhere.preference.Preference.OnPreferenceClickListener;
26 import org.holoeverywhere.preference.PreferenceCategory;
27
28 import android.content.Intent;
29 import android.os.Build;
30 import android.os.Bundle;
31 import android.view.MenuItem;
32 import de.geeksfactory.opacclient.OpacClient;
33 import jp.sourceforge.worldopac.R;
34 import de.geeksfactory.opacclient.reminder.ReminderCheckService;
35 import de.geeksfactory.opacclient.storage.AccountDataSource;
36 import de.geeksfactory.opacclient.storage.MetaDataSource;
37 import de.geeksfactory.opacclient.storage.SQLMetaDataSource;
38
39 public class MainPreferenceActivity extends OpacPreferenceActivity {
40
41         protected boolean ebooksSupported() {
42                 return false;
43         }
44
45         @Override
46         @SuppressWarnings("deprecation")
47         public void onCreate(Bundle savedInstanceState) {
48                 super.onCreate(savedInstanceState);
49
50                 getSupportActionBar().setDisplayHomeAsUpEnabled(true);
51
52                 addPreferencesFromResource(R.xml.settings);
53
54                 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH
55                                 || !getPackageManager()
56                                                 .hasSystemFeature("android.hardware.nfc")) {
57                         findPreference("nfc_search").setEnabled(false);
58                 }
59
60                 Preference assistant = findPreference("accounts");
61                 assistant.setOnPreferenceClickListener(new OnPreferenceClickListener() {
62                         @Override
63                         public boolean onPreferenceClick(Preference arg0) {
64                                 ((OpacClient) getApplication())
65                                                 .openAccountList(MainPreferenceActivity.this);
66                                 return false;
67                         }
68                 });
69
70                 if (!ebooksSupported()) {
71                         ((PreferenceCategory) findPreference("cat_web_opac"))
72                                         .removePreference(findPreference("email"));
73                 }
74
75                 Preference meta = findPreference("meta_clear");
76                 meta.setOnPreferenceClickListener(new OnPreferenceClickListener() {
77                         @Override
78                         public boolean onPreferenceClick(Preference arg0) {
79                                 MetaDataSource data = new SQLMetaDataSource(
80                                                 MainPreferenceActivity.this);
81                                 try {
82                                         data.open();
83                                 } catch (Exception e) {
84                                         throw new RuntimeException(e);
85                                 }
86                                 data.clearMeta();
87                                 data.close();
88                                 AccountDataSource adata = new AccountDataSource(
89                                                 MainPreferenceActivity.this);
90                                 adata.open();
91                                 adata.invalidateCachedData();
92                                 adata.notificationClearCache(true);
93                                 adata.close();
94                                 Intent i = new Intent(MainPreferenceActivity.this,
95                                                 ReminderCheckService.class);
96                                 startService(i);
97                                 return false;
98                         }
99                 });
100         }
101
102         @Override
103         public boolean onOptionsItemSelected(MenuItem item) {
104                 switch (item.getItemId()) {
105                 }
106                 return super.onOptionsItemSelected(item);
107         }
108 }