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
;
37 import com
.actionbarsherlock
.app
.ActionBar
;
38 import com
.actionbarsherlock
.app
.SherlockPreferenceActivity
;
39 import com
.actionbarsherlock
.view
.Menu
;
40 import com
.actionbarsherlock
.view
.MenuItem
;
41 import com
.owncloud
.android
.Log_OC
;
42 import com
.owncloud
.android
.OwnCloudSession
;
43 import com
.owncloud
.android
.R
;
44 import com
.owncloud
.android
.db
.DbHandler
;
47 * An Activity that allows the user to change the application's settings.
49 * @author Bartek Przybylski
52 public class Preferences
extends SherlockPreferenceActivity
implements OnPreferenceChangeListener
{
54 private static final String TAG
= "OwnCloudPreferences";
55 private final int mNewSession
= 47;
56 private final int mEditSession
= 48;
57 private DbHandler mDbHandler
;
58 private Vector
<OwnCloudSession
> mSessions
;
59 private ListPreference mTrackingUpdateInterval
;
60 private CheckBoxPreference mDeviceTracking
;
61 private CheckBoxPreference pCode
;
62 private CheckBoxPreference pLogging
;
63 private Preference pLoggingHistory
;
64 private Preference pAboutApp
;
65 private int mSelectedMenuItem
;
68 @SuppressWarnings("deprecation")
70 public void onCreate(Bundle savedInstanceState
) {
71 super.onCreate(savedInstanceState
);
72 mDbHandler
= new DbHandler(getBaseContext());
73 mSessions
= new Vector
<OwnCloudSession
>();
74 addPreferencesFromResource(R
.xml
.preferences
);
75 //populateAccountList();
76 ActionBar actionBar
= getSherlock().getActionBar();
77 actionBar
.setDisplayHomeAsUpEnabled(true
);
78 Preference p
= findPreference("manage_account");
80 p
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
82 public boolean onPreferenceClick(Preference preference
) {
83 Intent i
= new Intent(getApplicationContext(), AccountSelectActivity
.class);
89 pCode
= (CheckBoxPreference
) findPreference("set_pincode");
91 pCode
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
93 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
94 Intent i
= new Intent(getApplicationContext(), PinCodeActivity
.class);
95 i
.putExtra(PinCodeActivity
.EXTRA_ACTIVITY
, "preferences");
96 i
.putExtra(PinCodeActivity
.EXTRA_NEW_STATE
, newValue
.toString());
103 pAboutApp
= (Preference
) findPreference("about_app");
104 if (pAboutApp
!= null
) {
105 pAboutApp
.setTitle(String
.format(getString(R
.string
.about_android
), getString(R
.string
.app_name
)));
108 pkg
= getPackageManager().getPackageInfo(getPackageName(), 0);
109 pAboutApp
.setSummary(String
.format(getString(R
.string
.about_version
), pkg
.versionName
));
110 } catch (NameNotFoundException e
) {
111 Log_OC
.e(TAG
, "Error while showing about dialog", e
);
115 pLogging
= (CheckBoxPreference
) findPreference("log_to_file");
116 if (pLogging
!= null
) {
117 pLogging
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
119 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
121 String logpath
= Environment
.getExternalStorageDirectory()+File
.separator
+"owncloud"+File
.separator
+"log";
123 if(!pLogging
.isChecked()) {
124 Log_OC
.d("Debug", "start logging");
125 Log_OC
.v("PATH", logpath
);
126 Log_OC
.startLogging(logpath
);
129 Log_OC
.d("Debug", "stop logging");
130 Log_OC
.stopLogging();
137 pLoggingHistory
= (Preference
) findPreference("log_history");
138 if (pLoggingHistory
!= null
) {
139 pLoggingHistory
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
142 public boolean onPreferenceClick(Preference preference
) {
143 Intent intent
= new Intent(getApplicationContext(),LogHistoryActivity
.class);
144 startActivity(intent
);
153 protected void onResume() {
154 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
155 boolean state
= appPrefs
.getBoolean("set_pincode", false
);
156 pCode
.setChecked(state
);
161 public boolean onCreateOptionsMenu(Menu menu
) {
162 super.onCreateOptionsMenu(menu
);
167 public boolean onMenuItemSelected(int featureId
, MenuItem item
) {
168 super.onMenuItemSelected(featureId
, item
);
171 switch (item
.getItemId()) {
172 //case R.id.addSessionItem:
174 intent
= new Intent(this, PreferencesNewSession
.class);
175 startActivityForResult(intent
, mNewSession
);
177 case R
.id
.SessionContextEdit
:
178 intent
= new Intent(this, PreferencesNewSession
.class);
179 intent
.putExtra("sessionId", mSessions
.get(mSelectedMenuItem
)
181 intent
.putExtra("sessionName", mSessions
.get(mSelectedMenuItem
)
183 intent
.putExtra("sessionURL", mSessions
.get(mSelectedMenuItem
)
185 startActivityForResult(intent
, mEditSession
);
187 case android
.R
.id
.home
:
188 intent
= new Intent(getBaseContext(), FileDisplayActivity
.class);
189 intent
.addFlags(Intent
.FLAG_ACTIVITY_CLEAR_TOP
);
190 startActivity(intent
);
193 Log_OC
.w(TAG
, "Unknown menu item triggered");
200 protected void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
201 super.onActivityResult(requestCode
, resultCode
, data
);
205 protected void onDestroy() {
212 * Updates various summaries after updates. Also starts and stops
215 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
216 // Update current account summary
217 /*if (preference.equals(mAccountList)) {
218 mAccountList.setSummary(newValue.toString());
221 // Update tracking interval summary
222 else*/ if (preference
.equals(mTrackingUpdateInterval
)) {
223 String trackingSummary
= getResources().getString(
224 R
.string
.prefs_trackmydevice_interval_summary
);
225 trackingSummary
= String
.format(trackingSummary
,
226 newValue
.toString());
227 mTrackingUpdateInterval
.setSummary(trackingSummary
);
230 // Start or stop tracking service
231 else if (preference
.equals(mDeviceTracking
)) {
232 Intent locationServiceIntent
= new Intent();
233 locationServiceIntent
234 .setAction("com.owncloud.android.location.LocationLauncher");
235 locationServiceIntent
.putExtra("TRACKING_SETTING",
237 sendBroadcast(locationServiceIntent
);