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
.net
.Uri
;
27 import android
.os
.Bundle
;
28 import android
.preference
.CheckBoxPreference
;
29 import android
.preference
.ListPreference
;
30 import android
.preference
.Preference
;
31 import android
.preference
.Preference
.OnPreferenceChangeListener
;
32 import android
.preference
.Preference
.OnPreferenceClickListener
;
33 import android
.preference
.PreferenceCategory
;
34 import android
.preference
.PreferenceManager
;
35 import android
.preference
.PreferenceScreen
;
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
);
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());
108 PreferenceCategory preferenceCategory
= (PreferenceCategory
) findPreference("more");
110 boolean helpEnabled
= getResources().getBoolean(R
.bool
.help_enabled
);
111 Preference pHelp
= findPreference("help");
114 pHelp
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
116 public boolean onPreferenceClick(Preference preference
) {
117 String helpWeb
=(String
) getText(R
.string
.url_help
);
118 if (helpWeb
!= null
&& helpWeb
.length() > 0) {
119 Uri uriUrl
= Uri
.parse(helpWeb
);
120 Intent intent
= new Intent(Intent
.ACTION_VIEW
, uriUrl
);
121 startActivity(intent
);
127 preferenceCategory
.removePreference(pHelp
);
133 boolean recommendEnabled
= getResources().getBoolean(R
.bool
.recommend_enabled
);
134 Preference pRecommend
= findPreference("recommend");
135 if (pRecommend
!= null
){
136 if (recommendEnabled
) {
137 pRecommend
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
139 public boolean onPreferenceClick(Preference preference
) {
141 Intent intent
= new Intent(Intent
.ACTION_SENDTO
);
142 intent
.setType("text/plain");
143 //Account currentAccount = AccountUtils.getCurrentOwnCloudAccount(Preferences.this);
144 String appName
= getString(R
.string
.app_name
);
145 //String username = currentAccount.name.substring(0, currentAccount.name.lastIndexOf('@'));
146 //String recommendSubject = String.format(getString(R.string.recommend_subject), username, appName);
147 String recommendSubject
= String
.format(getString(R
.string
.recommend_subject
), appName
);
148 intent
.putExtra(Intent
.EXTRA_SUBJECT
, recommendSubject
);
149 //String recommendText = String.format(getString(R.string.recommend_text), getString(R.string.app_name), username);
150 String recommendText
= String
.format(getString(R
.string
.recommend_text
), getString(R
.string
.app_name
), getString(R
.string
.url_app_download
));
151 intent
.putExtra(Intent
.EXTRA_TEXT
, recommendText
);
153 intent
.setData(Uri
.parse(getString(R
.string
.mail_recommend
)));
154 intent
.addFlags(Intent
.FLAG_ACTIVITY_NEW_TASK
);
155 startActivity(intent
);
163 preferenceCategory
.removePreference(pRecommend
);
168 boolean feedbackEnabled
= getResources().getBoolean(R
.bool
.feedback_enabled
);
169 Preference pFeedback
= findPreference("feedback");
170 if (pFeedback
!= null
){
171 if (feedbackEnabled
) {
172 pFeedback
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
174 public boolean onPreferenceClick(Preference preference
) {
175 String feedbackMail
=(String
) getText(R
.string
.mail_feedback
);
176 String feedback
=(String
) getText(R
.string
.prefs_feedback
);
177 Intent intent
= new Intent(Intent
.ACTION_SENDTO
);
178 intent
.setType("text/plain");
179 intent
.putExtra(Intent
.EXTRA_SUBJECT
, feedback
);
181 intent
.setData(Uri
.parse(feedbackMail
));
182 intent
.addFlags(Intent
.FLAG_ACTIVITY_NEW_TASK
);
183 startActivity(intent
);
189 preferenceCategory
.removePreference(pFeedback
);
194 boolean imprintEnabled
= getResources().getBoolean(R
.bool
.imprint_enabled
);
195 Preference pImprint
= findPreference("imprint");
196 if (pImprint
!= null
) {
197 if (imprintEnabled
) {
198 pImprint
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
200 public boolean onPreferenceClick(Preference preference
) {
201 String imprintWeb
= (String
) getText(R
.string
.url_imprint
);
202 if (imprintWeb
!= null
&& imprintWeb
.length() > 0) {
203 Uri uriUrl
= Uri
.parse(imprintWeb
);
204 Intent intent
= new Intent(Intent
.ACTION_VIEW
, uriUrl
);
205 startActivity(intent
);
207 //ImprintDialog.newInstance(true).show(preference.get, "IMPRINT_DIALOG");
212 preferenceCategory
.removePreference(pImprint
);
217 pAboutApp
= (Preference
) findPreference("about_app");
218 if (pAboutApp
!= null
) {
219 pAboutApp
.setTitle(String
.format(getString(R
.string
.about_android
), getString(R
.string
.app_name
)));
222 pkg
= getPackageManager().getPackageInfo(getPackageName(), 0);
223 pAboutApp
.setSummary(String
.format(getString(R
.string
.about_version
), pkg
.versionName
));
224 } catch (NameNotFoundException e
) {
225 Log_OC
.e(TAG
, "Error while showing about dialog", e
);
229 /* DISABLED FOR RELEASE UNTIL FIXED
230 pLogging = (CheckBoxPreference) findPreference("log_to_file");
231 if (pLogging != null) {
232 pLogging.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
234 public boolean onPreferenceChange(Preference preference, Object newValue) {
236 String logpath = Environment.getExternalStorageDirectory()+File.separator+"owncloud"+File.separator+"log";
238 if(!pLogging.isChecked()) {
239 Log_OC.d("Debug", "start logging");
240 Log_OC.v("PATH", logpath);
241 Log_OC.startLogging(logpath);
244 Log_OC.d("Debug", "stop logging");
245 Log_OC.stopLogging();
252 pLoggingHistory = (Preference) findPreference("log_history");
253 if (pLoggingHistory != null) {
254 pLoggingHistory.setOnPreferenceClickListener(new OnPreferenceClickListener() {
257 public boolean onPreferenceClick(Preference preference) {
258 Intent intent = new Intent(getApplicationContext(),LogHistoryActivity.class);
259 startActivity(intent);
269 protected void onResume() {
270 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
271 boolean state
= appPrefs
.getBoolean("set_pincode", false
);
272 pCode
.setChecked(state
);
277 public boolean onCreateOptionsMenu(Menu menu
) {
278 super.onCreateOptionsMenu(menu
);
283 public boolean onMenuItemSelected(int featureId
, MenuItem item
) {
284 super.onMenuItemSelected(featureId
, item
);
287 switch (item
.getItemId()) {
288 //case R.id.addSessionItem:
290 intent
= new Intent(this, PreferencesNewSession
.class);
291 startActivityForResult(intent
, mNewSession
);
293 case R
.id
.SessionContextEdit
:
294 intent
= new Intent(this, PreferencesNewSession
.class);
295 intent
.putExtra("sessionId", mSessions
.get(mSelectedMenuItem
)
297 intent
.putExtra("sessionName", mSessions
.get(mSelectedMenuItem
)
299 intent
.putExtra("sessionURL", mSessions
.get(mSelectedMenuItem
)
301 startActivityForResult(intent
, mEditSession
);
303 case android
.R
.id
.home
:
304 intent
= new Intent(getBaseContext(), FileDisplayActivity
.class);
305 intent
.addFlags(Intent
.FLAG_ACTIVITY_CLEAR_TOP
);
306 startActivity(intent
);
309 Log_OC
.w(TAG
, "Unknown menu item triggered");
316 protected void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
317 super.onActivityResult(requestCode
, resultCode
, data
);
321 protected void onDestroy() {
328 * Updates various summaries after updates. Also starts and stops
331 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
332 // Update current account summary
333 /*if (preference.equals(mAccountList)) {
334 mAccountList.setSummary(newValue.toString());
337 // Update tracking interval summary
338 else*/ if (preference
.equals(mTrackingUpdateInterval
)) {
339 String trackingSummary
= getResources().getString(
340 R
.string
.prefs_trackmydevice_interval_summary
);
341 trackingSummary
= String
.format(trackingSummary
,
342 newValue
.toString());
343 mTrackingUpdateInterval
.setSummary(trackingSummary
);
346 // Start or stop tracking service
347 else if (preference
.equals(mDeviceTracking
)) {
348 Intent locationServiceIntent
= new Intent();
349 locationServiceIntent
350 .setAction("com.owncloud.android.location.LocationLauncher");
351 locationServiceIntent
.putExtra("TRACKING_SETTING",
353 sendBroadcast(locationServiceIntent
);