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 version 2,
7 * as published by the Free Software Foundation.
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.
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/>.
18 package com
.owncloud
.android
.ui
.activity
;
21 import java
.util
.Vector
;
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
;
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
;
46 * An Activity that allows the user to change the application's settings.
48 * @author Bartek Przybylski
51 public class Preferences
extends SherlockPreferenceActivity
implements OnPreferenceChangeListener
{
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
;
67 @SuppressWarnings("deprecation")
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");
79 p
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
81 public boolean onPreferenceClick(Preference preference
) {
82 Intent i
= new Intent(getApplicationContext(), AccountSelectActivity
.class);
88 pCode
= (CheckBoxPreference
) findPreference("set_pincode");
90 pCode
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
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());
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
)));
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
);
114 pLogging
= (CheckBoxPreference
) findPreference("log_to_file");
115 if (pLogging
!= null
) {
116 pLogging
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
118 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
120 String logpath
= Environment
.getExternalStorageDirectory()+File
.separator
+"owncloud"+File
.separator
+"log";
122 if(!pLogging
.isChecked()) {
123 Log_OC
.d("Debug", "start logging");
124 Log_OC
.v("PATH", logpath
);
125 Log_OC
.startLogging(logpath
);
128 Log_OC
.d("Debug", "stop logging");
129 Log_OC
.stopLogging();
136 pLoggingHistory
= (Preference
) findPreference("log_history");
137 if (pLoggingHistory
!= null
) {
138 pLoggingHistory
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
141 public boolean onPreferenceClick(Preference preference
) {
142 Intent intent
= new Intent(getApplicationContext(),LogHistoryActivity
.class);
143 startActivity(intent
);
152 protected void onResume() {
153 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
154 boolean state
= appPrefs
.getBoolean("set_pincode", false
);
155 pCode
.setChecked(state
);
160 public boolean onCreateOptionsMenu(Menu menu
) {
161 super.onCreateOptionsMenu(menu
);
166 public boolean onMenuItemSelected(int featureId
, MenuItem item
) {
167 super.onMenuItemSelected(featureId
, item
);
170 switch (item
.getItemId()) {
171 //case R.id.addSessionItem:
173 intent
= new Intent(this, PreferencesNewSession
.class);
174 startActivityForResult(intent
, mNewSession
);
176 case R
.id
.SessionContextEdit
:
177 intent
= new Intent(this, PreferencesNewSession
.class);
178 intent
.putExtra("sessionId", mSessions
.get(mSelectedMenuItem
)
180 intent
.putExtra("sessionName", mSessions
.get(mSelectedMenuItem
)
182 intent
.putExtra("sessionURL", mSessions
.get(mSelectedMenuItem
)
184 startActivityForResult(intent
, mEditSession
);
186 case android
.R
.id
.home
:
187 intent
= new Intent(getBaseContext(), FileDisplayActivity
.class);
188 intent
.addFlags(Intent
.FLAG_ACTIVITY_CLEAR_TOP
);
189 startActivity(intent
);
192 Log_OC
.w(TAG
, "Unknown menu item triggered");
199 protected void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
200 super.onActivityResult(requestCode
, resultCode
, data
);
204 protected void onDestroy() {
211 * Updates various summaries after updates. Also starts and stops
214 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
215 // Update current account summary
216 /*if (preference.equals(mAccountList)) {
217 mAccountList.setSummary(newValue.toString());
220 // Update tracking interval summary
221 else*/ if (preference
.equals(mTrackingUpdateInterval
)) {
222 String trackingSummary
= getResources().getString(
223 R
.string
.prefs_trackmydevice_interval_summary
);
224 trackingSummary
= String
.format(trackingSummary
,
225 newValue
.toString());
226 mTrackingUpdateInterval
.setSummary(trackingSummary
);
229 // Start or stop tracking service
230 else if (preference
.equals(mDeviceTracking
)) {
231 Intent locationServiceIntent
= new Intent();
232 locationServiceIntent
233 .setAction("com.owncloud.android.location.LocationLauncher");
234 locationServiceIntent
.putExtra("TRACKING_SETTING",
236 sendBroadcast(locationServiceIntent
);