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
.Preference
;
30 import android
.preference
.Preference
.OnPreferenceChangeListener
;
31 import android
.preference
.Preference
.OnPreferenceClickListener
;
32 import android
.preference
.PreferenceCategory
;
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
48 * @author David A. Velasco
50 public class Preferences
extends SherlockPreferenceActivity
{
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 CheckBoxPreference pCode
;
58 //private CheckBoxPreference pLogging;
59 //private Preference pLoggingHistory;
60 private Preference pAboutApp
;
61 private int mSelectedMenuItem
;
64 @SuppressWarnings("deprecation")
66 public void onCreate(Bundle savedInstanceState
) {
67 super.onCreate(savedInstanceState
);
68 mDbHandler
= new DbHandler(getBaseContext());
69 mSessions
= new Vector
<OwnCloudSession
>();
70 addPreferencesFromResource(R
.xml
.preferences
);
71 //populateAccountList();
72 ActionBar actionBar
= getSherlock().getActionBar();
73 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());
104 PreferenceCategory preferenceCategory
= (PreferenceCategory
) findPreference("more");
106 boolean helpEnabled
= getResources().getBoolean(R
.bool
.help_enabled
);
107 Preference pHelp
= findPreference("help");
110 pHelp
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
112 public boolean onPreferenceClick(Preference preference
) {
113 String helpWeb
=(String
) getText(R
.string
.url_help
);
114 if (helpWeb
!= null
&& helpWeb
.length() > 0) {
115 Uri uriUrl
= Uri
.parse(helpWeb
);
116 Intent intent
= new Intent(Intent
.ACTION_VIEW
, uriUrl
);
117 startActivity(intent
);
123 preferenceCategory
.removePreference(pHelp
);
129 boolean recommendEnabled
= getResources().getBoolean(R
.bool
.recommend_enabled
);
130 Preference pRecommend
= findPreference("recommend");
131 if (pRecommend
!= null
){
132 if (recommendEnabled
) {
133 pRecommend
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
135 public boolean onPreferenceClick(Preference preference
) {
137 Intent intent
= new Intent(Intent
.ACTION_SENDTO
);
138 intent
.setType("text/plain");
139 //Account currentAccount = AccountUtils.getCurrentOwnCloudAccount(Preferences.this);
140 String appName
= getString(R
.string
.app_name
);
141 //String username = currentAccount.name.substring(0, currentAccount.name.lastIndexOf('@'));
142 //String recommendSubject = String.format(getString(R.string.recommend_subject), username, appName);
143 String recommendSubject
= String
.format(getString(R
.string
.recommend_subject
), appName
);
144 intent
.putExtra(Intent
.EXTRA_SUBJECT
, recommendSubject
);
145 //String recommendText = String.format(getString(R.string.recommend_text), getString(R.string.app_name), username);
146 String recommendText
= String
.format(getString(R
.string
.recommend_text
), getString(R
.string
.app_name
), getString(R
.string
.url_app_download
));
147 intent
.putExtra(Intent
.EXTRA_TEXT
, recommendText
);
149 intent
.setData(Uri
.parse(getString(R
.string
.mail_recommend
)));
150 intent
.addFlags(Intent
.FLAG_ACTIVITY_NEW_TASK
);
151 startActivity(intent
);
159 preferenceCategory
.removePreference(pRecommend
);
164 boolean feedbackEnabled
= getResources().getBoolean(R
.bool
.feedback_enabled
);
165 Preference pFeedback
= findPreference("feedback");
166 if (pFeedback
!= null
){
167 if (feedbackEnabled
) {
168 pFeedback
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
170 public boolean onPreferenceClick(Preference preference
) {
171 String feedbackMail
=(String
) getText(R
.string
.mail_feedback
);
172 String feedback
=(String
) getText(R
.string
.prefs_feedback
);
173 Intent intent
= new Intent(Intent
.ACTION_SENDTO
);
174 intent
.setType("text/plain");
175 intent
.putExtra(Intent
.EXTRA_SUBJECT
, feedback
);
177 intent
.setData(Uri
.parse(feedbackMail
));
178 intent
.addFlags(Intent
.FLAG_ACTIVITY_NEW_TASK
);
179 startActivity(intent
);
185 preferenceCategory
.removePreference(pFeedback
);
190 boolean imprintEnabled
= getResources().getBoolean(R
.bool
.imprint_enabled
);
191 Preference pImprint
= findPreference("imprint");
192 if (pImprint
!= null
) {
193 if (imprintEnabled
) {
194 pImprint
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
196 public boolean onPreferenceClick(Preference preference
) {
197 String imprintWeb
= (String
) getText(R
.string
.url_imprint
);
198 if (imprintWeb
!= null
&& imprintWeb
.length() > 0) {
199 Uri uriUrl
= Uri
.parse(imprintWeb
);
200 Intent intent
= new Intent(Intent
.ACTION_VIEW
, uriUrl
);
201 startActivity(intent
);
203 //ImprintDialog.newInstance(true).show(preference.get, "IMPRINT_DIALOG");
208 preferenceCategory
.removePreference(pImprint
);
213 pAboutApp
= (Preference
) findPreference("about_app");
214 if (pAboutApp
!= null
) {
215 pAboutApp
.setTitle(String
.format(getString(R
.string
.about_android
), getString(R
.string
.app_name
)));
218 pkg
= getPackageManager().getPackageInfo(getPackageName(), 0);
219 pAboutApp
.setSummary(String
.format(getString(R
.string
.about_version
), pkg
.versionName
));
220 } catch (NameNotFoundException e
) {
221 Log_OC
.e(TAG
, "Error while showing about dialog", e
);
225 /* DISABLED FOR RELEASE UNTIL FIXED
226 pLogging = (CheckBoxPreference) findPreference("log_to_file");
227 if (pLogging != null) {
228 pLogging.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
230 public boolean onPreferenceChange(Preference preference, Object newValue) {
232 String logpath = Environment.getExternalStorageDirectory()+File.separator+"owncloud"+File.separator+"log";
234 if(!pLogging.isChecked()) {
235 Log_OC.d("Debug", "start logging");
236 Log_OC.v("PATH", logpath);
237 Log_OC.startLogging(logpath);
240 Log_OC.d("Debug", "stop logging");
241 Log_OC.stopLogging();
248 pLoggingHistory = (Preference) findPreference("log_history");
249 if (pLoggingHistory != null) {
250 pLoggingHistory.setOnPreferenceClickListener(new OnPreferenceClickListener() {
253 public boolean onPreferenceClick(Preference preference) {
254 Intent intent = new Intent(getApplicationContext(),LogHistoryActivity.class);
255 startActivity(intent);
265 protected void onResume() {
266 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
267 boolean state
= appPrefs
.getBoolean("set_pincode", false
);
268 pCode
.setChecked(state
);
273 public boolean onCreateOptionsMenu(Menu menu
) {
274 super.onCreateOptionsMenu(menu
);
279 public boolean onMenuItemSelected(int featureId
, MenuItem item
) {
280 super.onMenuItemSelected(featureId
, item
);
283 switch (item
.getItemId()) {
284 case android
.R
.id
.home
:
285 intent
= new Intent(getBaseContext(), FileDisplayActivity
.class);
286 intent
.addFlags(Intent
.FLAG_ACTIVITY_CLEAR_TOP
);
287 startActivity(intent
);
290 Log_OC
.w(TAG
, "Unknown menu item triggered");
297 protected void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
298 super.onActivityResult(requestCode
, resultCode
, data
);
302 protected void onDestroy() {