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 Uri uriUrl
= Uri
.parse(helpWeb
);
110 Intent intent
= new Intent(Intent
.ACTION_VIEW
, uriUrl
);
111 startActivity(intent
);
117 Preference pRecommend
= findPreference("recommend");
118 if (pRecommend
!= null
){
119 pRecommend
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
121 public boolean onPreferenceClick(Preference preference
) {
123 Intent intent
= new Intent(Intent
.ACTION_SENDTO
);
124 intent
.setType("text/plain");
125 //Account currentAccount = AccountUtils.getCurrentOwnCloudAccount(Preferences.this);
126 String appName
= getString(R
.string
.app_name
);
127 //String username = currentAccount.name.substring(0, currentAccount.name.lastIndexOf('@'));
128 //String recommendSubject = String.format(getString(R.string.recommend_subject), username, appName);
129 String recommendSubject
= String
.format(getString(R
.string
.recommend_subject
), appName
);
130 intent
.putExtra(Intent
.EXTRA_SUBJECT
, recommendSubject
);
131 //String recommendText = String.format(getString(R.string.recommend_text), getString(R.string.app_name), username);
132 String recommendText
= String
.format(getString(R
.string
.recommend_text
), getString(R
.string
.app_name
), getString(R
.string
.url_app_download
));
133 intent
.putExtra(Intent
.EXTRA_TEXT
, recommendText
);
135 intent
.setData(Uri
.parse(getString(R
.string
.mail_recommend
)));
136 intent
.addFlags(Intent
.FLAG_ACTIVITY_NEW_TASK
);
137 startActivity(intent
);
145 Preference pFeedback
= findPreference("feedback");
146 if (pFeedback
!= null
){
147 pFeedback
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
149 public boolean onPreferenceClick(Preference preference
) {
150 String feedbackMail
=(String
) getText(R
.string
.mail_feedback
);
151 String feedback
=(String
) getText(R
.string
.prefs_feedback
);
152 Intent intent
= new Intent(Intent
.ACTION_SENDTO
);
153 intent
.setType("text/plain");
154 intent
.putExtra(Intent
.EXTRA_SUBJECT
, feedback
);
156 intent
.setData(Uri
.parse(feedbackMail
));
157 intent
.addFlags(Intent
.FLAG_ACTIVITY_NEW_TASK
);
158 startActivity(intent
);
166 Preference pImprint = findPreference("imprint");
167 if (pImprint != null){
168 pImprint.setOnPreferenceClickListener(new OnPreferenceClickListener() {
170 public boolean onPreferenceClick(Preference preference) {
171 /*String imprintWeb = (String) getText(R.string.url_imprint);
172 Uri uriUrl = Uri.parse(imprintWeb);
173 Intent intent = new Intent(Intent.ACTION_VIEW, uriUrl);
174 startActivity(intent);*-/
175 ImprintDialog.newInstance(true).show(preference.get, "IMPRINT_DIALOG");
181 pAboutApp
= (Preference
) findPreference("about_app");
182 if (pAboutApp
!= null
) {
183 pAboutApp
.setTitle(String
.format(getString(R
.string
.about_android
), getString(R
.string
.app_name
)));
186 pkg
= getPackageManager().getPackageInfo(getPackageName(), 0);
187 pAboutApp
.setSummary(String
.format(getString(R
.string
.about_version
), pkg
.versionName
));
188 } catch (NameNotFoundException e
) {
189 Log_OC
.e(TAG
, "Error while showing about dialog", e
);
193 /* DISABLED FOR RELEASE UNTIL FIXED
194 pLogging = (CheckBoxPreference) findPreference("log_to_file");
195 if (pLogging != null) {
196 pLogging.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
198 public boolean onPreferenceChange(Preference preference, Object newValue) {
200 String logpath = Environment.getExternalStorageDirectory()+File.separator+"owncloud"+File.separator+"log";
202 if(!pLogging.isChecked()) {
203 Log_OC.d("Debug", "start logging");
204 Log_OC.v("PATH", logpath);
205 Log_OC.startLogging(logpath);
208 Log_OC.d("Debug", "stop logging");
209 Log_OC.stopLogging();
216 pLoggingHistory = (Preference) findPreference("log_history");
217 if (pLoggingHistory != null) {
218 pLoggingHistory.setOnPreferenceClickListener(new OnPreferenceClickListener() {
221 public boolean onPreferenceClick(Preference preference) {
222 Intent intent = new Intent(getApplicationContext(),LogHistoryActivity.class);
223 startActivity(intent);
233 protected void onResume() {
234 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
235 boolean state
= appPrefs
.getBoolean("set_pincode", false
);
236 pCode
.setChecked(state
);
241 public boolean onCreateOptionsMenu(Menu menu
) {
242 super.onCreateOptionsMenu(menu
);
247 public boolean onMenuItemSelected(int featureId
, MenuItem item
) {
248 super.onMenuItemSelected(featureId
, item
);
251 switch (item
.getItemId()) {
252 //case R.id.addSessionItem:
254 intent
= new Intent(this, PreferencesNewSession
.class);
255 startActivityForResult(intent
, mNewSession
);
257 case R
.id
.SessionContextEdit
:
258 intent
= new Intent(this, PreferencesNewSession
.class);
259 intent
.putExtra("sessionId", mSessions
.get(mSelectedMenuItem
)
261 intent
.putExtra("sessionName", mSessions
.get(mSelectedMenuItem
)
263 intent
.putExtra("sessionURL", mSessions
.get(mSelectedMenuItem
)
265 startActivityForResult(intent
, mEditSession
);
267 case android
.R
.id
.home
:
268 intent
= new Intent(getBaseContext(), FileDisplayActivity
.class);
269 intent
.addFlags(Intent
.FLAG_ACTIVITY_CLEAR_TOP
);
270 startActivity(intent
);
273 Log_OC
.w(TAG
, "Unknown menu item triggered");
280 protected void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
281 super.onActivityResult(requestCode
, resultCode
, data
);
285 protected void onDestroy() {
292 * Updates various summaries after updates. Also starts and stops
295 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
296 // Update current account summary
297 /*if (preference.equals(mAccountList)) {
298 mAccountList.setSummary(newValue.toString());
301 // Update tracking interval summary
302 else*/ if (preference
.equals(mTrackingUpdateInterval
)) {
303 String trackingSummary
= getResources().getString(
304 R
.string
.prefs_trackmydevice_interval_summary
);
305 trackingSummary
= String
.format(trackingSummary
,
306 newValue
.toString());
307 mTrackingUpdateInterval
.setSummary(trackingSummary
);
310 // Start or stop tracking service
311 else if (preference
.equals(mDeviceTracking
)) {
312 Intent locationServiceIntent
= new Intent();
313 locationServiceIntent
314 .setAction("com.owncloud.android.location.LocationLauncher");
315 locationServiceIntent
.putExtra("TRACKING_SETTING",
317 sendBroadcast(locationServiceIntent
);