Disabled logging options until fixed
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / activity / Preferences.java
1 /* ownCloud Android client application
2 * Copyright (C) 2011 Bartek Przybylski
3 * Copyright (C) 2012-2013 ownCloud Inc.
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2,
7 * as published by the Free Software Foundation.
8 *
9 * This program 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
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18 package com.owncloud.android.ui.activity;
19
20 import java.io.File;
21 import java.util.Vector;
22
23 import android.content.Intent;
24 import android.content.SharedPreferences;
25 import android.content.pm.PackageInfo;
26 import android.content.pm.PackageManager.NameNotFoundException;
27 import android.os.Bundle;
28 import android.os.Environment;
29 import android.preference.CheckBoxPreference;
30 import android.preference.ListPreference;
31 import android.preference.Preference;
32 import android.preference.Preference.OnPreferenceChangeListener;
33 import android.preference.Preference.OnPreferenceClickListener;
34 import android.preference.PreferenceManager;
35
36 import com.actionbarsherlock.app.ActionBar;
37 import com.actionbarsherlock.app.SherlockPreferenceActivity;
38 import com.actionbarsherlock.view.Menu;
39 import com.actionbarsherlock.view.MenuItem;
40 import com.owncloud.android.Log_OC;
41 import com.owncloud.android.OwnCloudSession;
42 import com.owncloud.android.R;
43 import com.owncloud.android.db.DbHandler;
44
45 /**
46 * An Activity that allows the user to change the application's settings.
47 *
48 * @author Bartek Przybylski
49 *
50 */
51 public class Preferences extends SherlockPreferenceActivity implements OnPreferenceChangeListener {
52
53 private static final String TAG = "OwnCloudPreferences";
54 private final int mNewSession = 47;
55 private final int mEditSession = 48;
56 private DbHandler mDbHandler;
57 private Vector<OwnCloudSession> mSessions;
58 private ListPreference mTrackingUpdateInterval;
59 private CheckBoxPreference mDeviceTracking;
60 private CheckBoxPreference pCode;
61 private CheckBoxPreference pLogging;
62 private Preference pLoggingHistory;
63 private Preference pAboutApp;
64 private int mSelectedMenuItem;
65
66
67 @SuppressWarnings("deprecation")
68 @Override
69 public void onCreate(Bundle savedInstanceState) {
70 super.onCreate(savedInstanceState);
71 mDbHandler = new DbHandler(getBaseContext());
72 mSessions = new Vector<OwnCloudSession>();
73 addPreferencesFromResource(R.xml.preferences);
74 //populateAccountList();
75 ActionBar actionBar = getSherlock().getActionBar();
76 actionBar.setDisplayHomeAsUpEnabled(true);
77 Preference p = findPreference("manage_account");
78 if (p != null)
79 p.setOnPreferenceClickListener(new OnPreferenceClickListener() {
80 @Override
81 public boolean onPreferenceClick(Preference preference) {
82 Intent i = new Intent(getApplicationContext(), AccountSelectActivity.class);
83 startActivity(i);
84 return true;
85 }
86 });
87
88 pCode = (CheckBoxPreference) findPreference("set_pincode");
89 if (pCode != null){
90 pCode.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
91 @Override
92 public boolean onPreferenceChange(Preference preference, Object newValue) {
93 Intent i = new Intent(getApplicationContext(), PinCodeActivity.class);
94 i.putExtra(PinCodeActivity.EXTRA_ACTIVITY, "preferences");
95 i.putExtra(PinCodeActivity.EXTRA_NEW_STATE, newValue.toString());
96 startActivity(i);
97 return true;
98 }
99 });
100
101 /* About App */
102 pAboutApp = (Preference) findPreference("about_app");
103 if (pAboutApp != null) {
104 pAboutApp.setTitle(String.format(getString(R.string.about_android), getString(R.string.app_name)));
105 PackageInfo pkg;
106 try {
107 pkg = getPackageManager().getPackageInfo(getPackageName(), 0);
108 pAboutApp.setSummary(String.format(getString(R.string.about_version), pkg.versionName));
109 } catch (NameNotFoundException e) {
110 Log_OC.e(TAG, "Error while showing about dialog", e);
111 }
112 }
113
114 /* DISABLED FOR RELEASE UNTIL FIXED
115 pLogging = (CheckBoxPreference) findPreference("log_to_file");
116 if (pLogging != null) {
117 pLogging.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
118 @Override
119 public boolean onPreferenceChange(Preference preference, Object newValue) {
120
121 String logpath = Environment.getExternalStorageDirectory()+File.separator+"owncloud"+File.separator+"log";
122
123 if(!pLogging.isChecked()) {
124 Log_OC.d("Debug", "start logging");
125 Log_OC.v("PATH", logpath);
126 Log_OC.startLogging(logpath);
127 }
128 else {
129 Log_OC.d("Debug", "stop logging");
130 Log_OC.stopLogging();
131 }
132 return true;
133 }
134 });
135 }
136
137 pLoggingHistory = (Preference) findPreference("log_history");
138 if (pLoggingHistory != null) {
139 pLoggingHistory.setOnPreferenceClickListener(new OnPreferenceClickListener() {
140
141 @Override
142 public boolean onPreferenceClick(Preference preference) {
143 Intent intent = new Intent(getApplicationContext(),LogHistoryActivity.class);
144 startActivity(intent);
145 return true;
146 }
147 });
148 }
149 */
150
151 }
152 }
153
154 @Override
155 protected void onResume() {
156 SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
157 boolean state = appPrefs.getBoolean("set_pincode", false);
158 pCode.setChecked(state);
159 super.onResume();
160 }
161
162 @Override
163 public boolean onCreateOptionsMenu(Menu menu) {
164 super.onCreateOptionsMenu(menu);
165 return true;
166 }
167
168 @Override
169 public boolean onMenuItemSelected(int featureId, MenuItem item) {
170 super.onMenuItemSelected(featureId, item);
171 Intent intent;
172
173 switch (item.getItemId()) {
174 //case R.id.addSessionItem:
175 case 1:
176 intent = new Intent(this, PreferencesNewSession.class);
177 startActivityForResult(intent, mNewSession);
178 break;
179 case R.id.SessionContextEdit:
180 intent = new Intent(this, PreferencesNewSession.class);
181 intent.putExtra("sessionId", mSessions.get(mSelectedMenuItem)
182 .getEntryId());
183 intent.putExtra("sessionName", mSessions.get(mSelectedMenuItem)
184 .getName());
185 intent.putExtra("sessionURL", mSessions.get(mSelectedMenuItem)
186 .getUrl());
187 startActivityForResult(intent, mEditSession);
188 break;
189 case android.R.id.home:
190 intent = new Intent(getBaseContext(), FileDisplayActivity.class);
191 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
192 startActivity(intent);
193 break;
194 default:
195 Log_OC.w(TAG, "Unknown menu item triggered");
196 return false;
197 }
198 return true;
199 }
200
201 @Override
202 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
203 super.onActivityResult(requestCode, resultCode, data);
204 }
205
206 @Override
207 protected void onDestroy() {
208 mDbHandler.close();
209 super.onDestroy();
210 }
211
212 @Override
213 /**
214 * Updates various summaries after updates. Also starts and stops
215 * the
216 */
217 public boolean onPreferenceChange(Preference preference, Object newValue) {
218 // Update current account summary
219 /*if (preference.equals(mAccountList)) {
220 mAccountList.setSummary(newValue.toString());
221 }
222
223 // Update tracking interval summary
224 else*/ if (preference.equals(mTrackingUpdateInterval)) {
225 String trackingSummary = getResources().getString(
226 R.string.prefs_trackmydevice_interval_summary);
227 trackingSummary = String.format(trackingSummary,
228 newValue.toString());
229 mTrackingUpdateInterval.setSummary(trackingSummary);
230 }
231
232 // Start or stop tracking service
233 else if (preference.equals(mDeviceTracking)) {
234 Intent locationServiceIntent = new Intent();
235 locationServiceIntent
236 .setAction("com.owncloud.android.location.LocationLauncher");
237 locationServiceIntent.putExtra("TRACKING_SETTING",
238 (Boolean) newValue);
239 sendBroadcast(locationServiceIntent);
240 }
241 return true;
242 }
243 }