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
;
20 import java
.util
.Vector
;
22 import android
.content
.Intent
;
23 import android
.content
.SharedPreferences
;
24 import android
.content
.pm
.PackageInfo
;
25 import android
.content
.pm
.PackageManager
.NameNotFoundException
;
26 import android
.os
.Bundle
;
27 import android
.preference
.CheckBoxPreference
;
28 import android
.preference
.ListPreference
;
29 import android
.preference
.Preference
;
30 import android
.preference
.Preference
.OnPreferenceChangeListener
;
31 import android
.preference
.Preference
.OnPreferenceClickListener
;
32 import android
.preference
.PreferenceManager
;
34 import com
.actionbarsherlock
.app
.ActionBar
;
35 import com
.actionbarsherlock
.app
.SherlockPreferenceActivity
;
36 import com
.actionbarsherlock
.view
.Menu
;
37 import com
.actionbarsherlock
.view
.MenuItem
;
38 import com
.owncloud
.android
.Log_OC
;
39 import com
.owncloud
.android
.OwnCloudSession
;
40 import com
.owncloud
.android
.R
;
41 import com
.owncloud
.android
.db
.DbHandler
;
44 * An Activity that allows the user to change the application's settings.
46 * @author Bartek Przybylski
49 public class Preferences
extends SherlockPreferenceActivity
implements OnPreferenceChangeListener
{
51 private static final String TAG
= "OwnCloudPreferences";
52 private final int mNewSession
= 47;
53 private final int mEditSession
= 48;
54 private DbHandler mDbHandler
;
55 private Vector
<OwnCloudSession
> mSessions
;
56 private ListPreference mTrackingUpdateInterval
;
57 private CheckBoxPreference mDeviceTracking
;
58 private CheckBoxPreference pCode
;
59 private CheckBoxPreference pLogging
;
60 private Preference pLoggingHistory
;
61 private Preference pAboutApp
;
62 private int mSelectedMenuItem
;
65 @SuppressWarnings("deprecation")
67 public void onCreate(Bundle savedInstanceState
) {
68 super.onCreate(savedInstanceState
);
69 mDbHandler
= new DbHandler(getBaseContext());
70 mSessions
= new Vector
<OwnCloudSession
>();
71 addPreferencesFromResource(R
.xml
.preferences
);
72 //populateAccountList();
73 ActionBar actionBar
= getSherlock().getActionBar();
74 actionBar
.setDisplayHomeAsUpEnabled(true
);
75 Preference p
= findPreference("manage_account");
77 p
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
79 public boolean onPreferenceClick(Preference preference
) {
80 Intent i
= new Intent(getApplicationContext(), AccountSelectActivity
.class);
86 pCode
= (CheckBoxPreference
) findPreference("set_pincode");
88 pCode
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
90 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
91 Intent i
= new Intent(getApplicationContext(), PinCodeActivity
.class);
92 i
.putExtra(PinCodeActivity
.EXTRA_ACTIVITY
, "preferences");
93 i
.putExtra(PinCodeActivity
.EXTRA_NEW_STATE
, newValue
.toString());
100 pAboutApp
= (Preference
) findPreference("about_app");
101 if (pAboutApp
!= null
) {
102 pAboutApp
.setTitle(String
.format(getString(R
.string
.about_android
), getString(R
.string
.app_name
)));
105 pkg
= getPackageManager().getPackageInfo(getPackageName(), 0);
106 pAboutApp
.setSummary(String
.format(getString(R
.string
.about_version
), pkg
.versionName
));
107 } catch (NameNotFoundException e
) {
108 Log_OC
.e(TAG
, "Error while showing about dialog", e
);
112 /* DISABLED FOR RELEASE UNTIL FIXED
113 pLogging = (CheckBoxPreference) findPreference("log_to_file");
114 if (pLogging != null) {
115 pLogging.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
117 public boolean onPreferenceChange(Preference preference, Object newValue) {
119 String logpath = Environment.getExternalStorageDirectory()+File.separator+"owncloud"+File.separator+"log";
121 if(!pLogging.isChecked()) {
122 Log_OC.d("Debug", "start logging");
123 Log_OC.v("PATH", logpath);
124 Log_OC.startLogging(logpath);
127 Log_OC.d("Debug", "stop logging");
128 Log_OC.stopLogging();
135 pLoggingHistory = (Preference) findPreference("log_history");
136 if (pLoggingHistory != null) {
137 pLoggingHistory.setOnPreferenceClickListener(new OnPreferenceClickListener() {
140 public boolean onPreferenceClick(Preference preference) {
141 Intent intent = new Intent(getApplicationContext(),LogHistoryActivity.class);
142 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
);