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
.PreferenceManager
;
35 import com
.actionbarsherlock
.app
.ActionBar
;
36 import com
.actionbarsherlock
.app
.SherlockPreferenceActivity
;
37 import com
.actionbarsherlock
.view
.Menu
;
38 import com
.actionbarsherlock
.view
.MenuItem
;
39 import com
.owncloud
.android
.Log_OC
;
40 import com
.owncloud
.android
.OwnCloudSession
;
41 import com
.owncloud
.android
.R
;
42 import com
.owncloud
.android
.db
.DbHandler
;
45 * An Activity that allows the user to change the application's settings.
47 * @author Bartek Przybylski
50 public class Preferences
extends SherlockPreferenceActivity
implements OnPreferenceChangeListener
{
52 private static final String TAG
= "OwnCloudPreferences";
53 private final int mNewSession
= 47;
54 private final int mEditSession
= 48;
55 private DbHandler mDbHandler
;
56 private Vector
<OwnCloudSession
> mSessions
;
57 private ListPreference mTrackingUpdateInterval
;
58 private CheckBoxPreference mDeviceTracking
;
59 private CheckBoxPreference pCode
;
60 //private CheckBoxPreference pLogging;
61 //private Preference pLoggingHistory;
62 private Preference pAboutApp
;
63 private int mSelectedMenuItem
;
66 @SuppressWarnings("deprecation")
68 public void onCreate(Bundle savedInstanceState
) {
69 super.onCreate(savedInstanceState
);
70 mDbHandler
= new DbHandler(getBaseContext());
71 mSessions
= new Vector
<OwnCloudSession
>();
72 addPreferencesFromResource(R
.xml
.preferences
);
73 //populateAccountList();
74 ActionBar actionBar
= getSherlock().getActionBar();
75 actionBar
.setDisplayHomeAsUpEnabled(true
);
76 Preference p
= findPreference("manage_account");
78 p
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
80 public boolean onPreferenceClick(Preference preference
) {
81 Intent i
= new Intent(getApplicationContext(), AccountSelectActivity
.class);
87 pCode
= (CheckBoxPreference
) findPreference("set_pincode");
89 pCode
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
91 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
92 Intent i
= new Intent(getApplicationContext(), PinCodeActivity
.class);
93 i
.putExtra(PinCodeActivity
.EXTRA_ACTIVITY
, "preferences");
94 i
.putExtra(PinCodeActivity
.EXTRA_NEW_STATE
, newValue
.toString());
103 Preference pHelp
= findPreference("help");
105 pHelp
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
107 public boolean onPreferenceClick(Preference preference
) {
108 String helpWeb
=(String
) getText(R
.string
.url_help
);
109 if (helpWeb
!= null
&& helpWeb
.length() > 0) {
110 Uri uriUrl
= Uri
.parse(helpWeb
);
111 Intent intent
= new Intent(Intent
.ACTION_VIEW
, uriUrl
);
112 startActivity(intent
);
119 Preference pRecommend
= findPreference("recommend");
120 if (pRecommend
!= null
){
121 pRecommend
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
123 public boolean onPreferenceClick(Preference preference
) {
125 Intent intent
= new Intent(Intent
.ACTION_SENDTO
);
126 intent
.setType("text/plain");
127 //Account currentAccount = AccountUtils.getCurrentOwnCloudAccount(Preferences.this);
128 String appName
= getString(R
.string
.app_name
);
129 //String username = currentAccount.name.substring(0, currentAccount.name.lastIndexOf('@'));
130 //String recommendSubject = String.format(getString(R.string.recommend_subject), username, appName);
131 String recommendSubject
= String
.format(getString(R
.string
.recommend_subject
), appName
);
132 intent
.putExtra(Intent
.EXTRA_SUBJECT
, recommendSubject
);
133 //String recommendText = String.format(getString(R.string.recommend_text), getString(R.string.app_name), username);
134 String recommendText
= String
.format(getString(R
.string
.recommend_text
), getString(R
.string
.app_name
), getString(R
.string
.url_app_download
));
135 intent
.putExtra(Intent
.EXTRA_TEXT
, recommendText
);
137 intent
.setData(Uri
.parse(getString(R
.string
.mail_recommend
)));
138 intent
.addFlags(Intent
.FLAG_ACTIVITY_NEW_TASK
);
139 startActivity(intent
);
147 Preference pFeedback
= findPreference("feedback");
148 if (pFeedback
!= null
){
149 pFeedback
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
151 public boolean onPreferenceClick(Preference preference
) {
152 String feedbackMail
=(String
) getText(R
.string
.mail_feedback
);
153 String feedback
=(String
) getText(R
.string
.prefs_feedback
);
154 Intent intent
= new Intent(Intent
.ACTION_SENDTO
);
155 intent
.setType("text/plain");
156 intent
.putExtra(Intent
.EXTRA_SUBJECT
, feedback
);
158 intent
.setData(Uri
.parse(feedbackMail
));
159 intent
.addFlags(Intent
.FLAG_ACTIVITY_NEW_TASK
);
160 startActivity(intent
);
167 Preference pImprint
= findPreference("imprint");
168 if (pImprint
!= null
) {
169 pImprint
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
171 public boolean onPreferenceClick(Preference preference
) {
172 String imprintWeb
= (String
) getText(R
.string
.url_imprint
);
173 if (imprintWeb
!= null
&& imprintWeb
.length() > 0) {
174 Uri uriUrl
= Uri
.parse(imprintWeb
);
175 Intent intent
= new Intent(Intent
.ACTION_VIEW
, uriUrl
);
176 startActivity(intent
);
178 //ImprintDialog.newInstance(true).show(preference.get, "IMPRINT_DIALOG");
185 pAboutApp
= (Preference
) findPreference("about_app");
186 if (pAboutApp
!= null
) {
187 pAboutApp
.setTitle(String
.format(getString(R
.string
.about_android
), getString(R
.string
.app_name
)));
190 pkg
= getPackageManager().getPackageInfo(getPackageName(), 0);
191 pAboutApp
.setSummary(String
.format(getString(R
.string
.about_version
), pkg
.versionName
));
192 } catch (NameNotFoundException e
) {
193 Log_OC
.e(TAG
, "Error while showing about dialog", e
);
197 /* DISABLED FOR RELEASE UNTIL FIXED
198 pLogging = (CheckBoxPreference) findPreference("log_to_file");
199 if (pLogging != null) {
200 pLogging.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
202 public boolean onPreferenceChange(Preference preference, Object newValue) {
204 String logpath = Environment.getExternalStorageDirectory()+File.separator+"owncloud"+File.separator+"log";
206 if(!pLogging.isChecked()) {
207 Log_OC.d("Debug", "start logging");
208 Log_OC.v("PATH", logpath);
209 Log_OC.startLogging(logpath);
212 Log_OC.d("Debug", "stop logging");
213 Log_OC.stopLogging();
220 pLoggingHistory = (Preference) findPreference("log_history");
221 if (pLoggingHistory != null) {
222 pLoggingHistory.setOnPreferenceClickListener(new OnPreferenceClickListener() {
225 public boolean onPreferenceClick(Preference preference) {
226 Intent intent = new Intent(getApplicationContext(),LogHistoryActivity.class);
227 startActivity(intent);
237 protected void onResume() {
238 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
239 boolean state
= appPrefs
.getBoolean("set_pincode", false
);
240 pCode
.setChecked(state
);
245 public boolean onCreateOptionsMenu(Menu menu
) {
246 super.onCreateOptionsMenu(menu
);
251 public boolean onMenuItemSelected(int featureId
, MenuItem item
) {
252 super.onMenuItemSelected(featureId
, item
);
255 switch (item
.getItemId()) {
256 //case R.id.addSessionItem:
258 intent
= new Intent(this, PreferencesNewSession
.class);
259 startActivityForResult(intent
, mNewSession
);
261 case R
.id
.SessionContextEdit
:
262 intent
= new Intent(this, PreferencesNewSession
.class);
263 intent
.putExtra("sessionId", mSessions
.get(mSelectedMenuItem
)
265 intent
.putExtra("sessionName", mSessions
.get(mSelectedMenuItem
)
267 intent
.putExtra("sessionURL", mSessions
.get(mSelectedMenuItem
)
269 startActivityForResult(intent
, mEditSession
);
271 case android
.R
.id
.home
:
272 intent
= new Intent(getBaseContext(), FileDisplayActivity
.class);
273 intent
.addFlags(Intent
.FLAG_ACTIVITY_CLEAR_TOP
);
274 startActivity(intent
);
277 Log_OC
.w(TAG
, "Unknown menu item triggered");
284 protected void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
285 super.onActivityResult(requestCode
, resultCode
, data
);
289 protected void onDestroy() {
296 * Updates various summaries after updates. Also starts and stops
299 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
300 // Update current account summary
301 /*if (preference.equals(mAccountList)) {
302 mAccountList.setSummary(newValue.toString());
305 // Update tracking interval summary
306 else*/ if (preference
.equals(mTrackingUpdateInterval
)) {
307 String trackingSummary
= getResources().getString(
308 R
.string
.prefs_trackmydevice_interval_summary
);
309 trackingSummary
= String
.format(trackingSummary
,
310 newValue
.toString());
311 mTrackingUpdateInterval
.setSummary(trackingSummary
);
314 // Start or stop tracking service
315 else if (preference
.equals(mDeviceTracking
)) {
316 Intent locationServiceIntent
= new Intent();
317 locationServiceIntent
318 .setAction("com.owncloud.android.location.LocationLauncher");
319 locationServiceIntent
.putExtra("TRACKING_SETTING",
321 sendBroadcast(locationServiceIntent
);