1 /* ownCloud Android client application
2 * Copyright (C) 2011 Bartek Przybylski
3 * Copyright (C) 2012-2013 ownCloud Inc.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package com
.owncloud
.android
.ui
.activity
;
22 import java
.util
.Vector
;
24 import android
.content
.Intent
;
25 import android
.content
.SharedPreferences
;
26 import android
.content
.pm
.PackageInfo
;
27 import android
.content
.pm
.PackageManager
.NameNotFoundException
;
28 import android
.os
.Bundle
;
29 import android
.os
.Environment
;
30 import android
.preference
.CheckBoxPreference
;
31 import android
.preference
.ListPreference
;
32 import android
.preference
.Preference
;
33 import android
.preference
.Preference
.OnPreferenceChangeListener
;
34 import android
.preference
.Preference
.OnPreferenceClickListener
;
35 import android
.preference
.PreferenceManager
;
36 import android
.util
.Log
;
38 import com
.actionbarsherlock
.app
.ActionBar
;
39 import com
.actionbarsherlock
.app
.SherlockPreferenceActivity
;
40 import com
.actionbarsherlock
.view
.Menu
;
41 import com
.actionbarsherlock
.view
.MenuItem
;
42 import com
.owncloud
.android
.Log_OC
;
43 import com
.owncloud
.android
.OwnCloudSession
;
44 import com
.owncloud
.android
.R
;
45 import com
.owncloud
.android
.db
.DbHandler
;
48 * An Activity that allows the user to change the application's settings.
50 * @author Bartek Przybylski
53 public class Preferences
extends SherlockPreferenceActivity
implements OnPreferenceChangeListener
{
55 private static final String TAG
= "OwnCloudPreferences";
56 private final int mNewSession
= 47;
57 private final int mEditSession
= 48;
58 private DbHandler mDbHandler
;
59 private Vector
<OwnCloudSession
> mSessions
;
60 private ListPreference mTrackingUpdateInterval
;
61 private CheckBoxPreference mDeviceTracking
;
62 private CheckBoxPreference pCode
;
63 private CheckBoxPreference pLogging
;
64 private Preference pLoggingHistory
;
65 private Preference pAboutApp
;
66 private int mSelectedMenuItem
;
69 @SuppressWarnings("deprecation")
71 public void onCreate(Bundle savedInstanceState
) {
72 super.onCreate(savedInstanceState
);
73 mDbHandler
= new DbHandler(getBaseContext());
74 mSessions
= new Vector
<OwnCloudSession
>();
75 addPreferencesFromResource(R
.xml
.preferences
);
76 //populateAccountList();
77 ActionBar actionBar
= getSherlock().getActionBar();
78 actionBar
.setDisplayHomeAsUpEnabled(true
);
79 Preference p
= findPreference("manage_account");
81 p
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
83 public boolean onPreferenceClick(Preference preference
) {
84 Intent i
= new Intent(getApplicationContext(), AccountSelectActivity
.class);
90 pCode
= (CheckBoxPreference
) findPreference("set_pincode");
92 pCode
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
94 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
95 Intent i
= new Intent(getApplicationContext(), PinCodeActivity
.class);
96 i
.putExtra(PinCodeActivity
.EXTRA_ACTIVITY
, "preferences");
97 i
.putExtra(PinCodeActivity
.EXTRA_NEW_STATE
, newValue
.toString());
104 pAboutApp
= (Preference
) findPreference("about_app");
105 if (pAboutApp
!= null
) {
106 pAboutApp
.setTitle(getString(R
.string
.app_name
)+" "+getString(R
.string
.about_android
));
109 pkg
= getPackageManager().getPackageInfo(getPackageName(), 0);
110 pAboutApp
.setSummary(getString(R
.string
.about_version
)+" "+pkg
.versionName
);
111 } catch (NameNotFoundException e
) {
112 Log_OC
.e(TAG
, "Error while showing about dialog", e
);
116 pLogging
= (CheckBoxPreference
) findPreference("log_to_file");
117 if (pLogging
!= null
) {
118 pLogging
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
120 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
122 String logpath
= Environment
.getExternalStorageDirectory()+File
.separator
+"owncloud"+File
.separator
+"log";
124 if(!pLogging
.isChecked()) {
125 Log_OC
.d("Debug", "start logging");
126 Log_OC
.v("PATH", logpath
);
127 Log_OC
.startLogging(logpath
);
130 Log_OC
.d("Debug", "stop logging");
131 Log_OC
.stopLogging();
138 pLoggingHistory
= (Preference
) findPreference("log_history");
139 if (pLoggingHistory
!= null
) {
140 pLoggingHistory
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
143 public boolean onPreferenceClick(Preference preference
) {
144 Intent intent
= new Intent(getApplicationContext(),LogHistoryActivity
.class);
145 startActivity(intent
);
154 protected void onResume() {
155 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
156 boolean state
= appPrefs
.getBoolean("set_pincode", false
);
157 pCode
.setChecked(state
);
162 public boolean onCreateOptionsMenu(Menu menu
) {
163 super.onCreateOptionsMenu(menu
);
168 public boolean onMenuItemSelected(int featureId
, MenuItem item
) {
169 super.onMenuItemSelected(featureId
, item
);
172 switch (item
.getItemId()) {
173 //case R.id.addSessionItem:
175 intent
= new Intent(this, PreferencesNewSession
.class);
176 startActivityForResult(intent
, mNewSession
);
178 case R
.id
.SessionContextEdit
:
179 intent
= new Intent(this, PreferencesNewSession
.class);
180 intent
.putExtra("sessionId", mSessions
.get(mSelectedMenuItem
)
182 intent
.putExtra("sessionName", mSessions
.get(mSelectedMenuItem
)
184 intent
.putExtra("sessionURL", mSessions
.get(mSelectedMenuItem
)
186 startActivityForResult(intent
, mEditSession
);
188 case android
.R
.id
.home
:
189 intent
= new Intent(getBaseContext(), FileDisplayActivity
.class);
190 intent
.addFlags(Intent
.FLAG_ACTIVITY_CLEAR_TOP
);
191 startActivity(intent
);
194 Log_OC
.w(TAG
, "Unknown menu item triggered");
201 protected void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
202 super.onActivityResult(requestCode
, resultCode
, data
);
206 protected void onDestroy() {
213 * Updates various summaries after updates. Also starts and stops
216 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
217 // Update current account summary
218 /*if (preference.equals(mAccountList)) {
219 mAccountList.setSummary(newValue.toString());
222 // Update tracking interval summary
223 else*/ if (preference
.equals(mTrackingUpdateInterval
)) {
224 String trackingSummary
= getResources().getString(
225 R
.string
.prefs_trackmydevice_interval_summary
);
226 trackingSummary
= String
.format(trackingSummary
,
227 newValue
.toString());
228 mTrackingUpdateInterval
.setSummary(trackingSummary
);
231 // Start or stop tracking service
232 else if (preference
.equals(mDeviceTracking
)) {
233 Intent locationServiceIntent
= new Intent();
234 locationServiceIntent
235 .setAction("com.owncloud.android.location.LocationLauncher");
236 locationServiceIntent
.putExtra("TRACKING_SETTING",
238 sendBroadcast(locationServiceIntent
);