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
.R
;
40 import com
.owncloud
.android
.db
.DbHandler
;
41 import com
.owncloud
.android
.utils
.Log_OC
;
42 import com
.owncloud
.android
.utils
.OwnCloudSession
;
46 * An Activity that allows the user to change the application's settings.
48 * @author Bartek Przybylski
49 * @author David A. Velasco
51 public class Preferences
extends SherlockPreferenceActivity
{
53 private static final String TAG
= "OwnCloudPreferences";
54 private final int mNewSession
= 47;
55 private final int mEditSession
= 48;
56 private DbHandler mDbHandler
;
57 private Vector
<OwnCloudSession
> mSessions
;
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
);
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());
105 PreferenceCategory preferenceCategory
= (PreferenceCategory
) findPreference("more");
107 boolean helpEnabled
= getResources().getBoolean(R
.bool
.help_enabled
);
108 Preference pHelp
= findPreference("help");
111 pHelp
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
113 public boolean onPreferenceClick(Preference preference
) {
114 String helpWeb
=(String
) getText(R
.string
.url_help
);
115 if (helpWeb
!= null
&& helpWeb
.length() > 0) {
116 Uri uriUrl
= Uri
.parse(helpWeb
);
117 Intent intent
= new Intent(Intent
.ACTION_VIEW
, uriUrl
);
118 startActivity(intent
);
124 preferenceCategory
.removePreference(pHelp
);
130 boolean recommendEnabled
= getResources().getBoolean(R
.bool
.recommend_enabled
);
131 Preference pRecommend
= findPreference("recommend");
132 if (pRecommend
!= null
){
133 if (recommendEnabled
) {
134 pRecommend
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
136 public boolean onPreferenceClick(Preference preference
) {
138 Intent intent
= new Intent(Intent
.ACTION_SENDTO
);
139 intent
.setType("text/plain");
140 //Account currentAccount = AccountUtils.getCurrentOwnCloudAccount(Preferences.this);
141 String appName
= getString(R
.string
.app_name
);
142 //String username = currentAccount.name.substring(0, currentAccount.name.lastIndexOf('@'));
143 //String recommendSubject = String.format(getString(R.string.recommend_subject), username, appName);
144 String recommendSubject
= String
.format(getString(R
.string
.recommend_subject
), appName
);
145 intent
.putExtra(Intent
.EXTRA_SUBJECT
, recommendSubject
);
146 //String recommendText = String.format(getString(R.string.recommend_text), getString(R.string.app_name), username);
147 String recommendText
= String
.format(getString(R
.string
.recommend_text
), getString(R
.string
.app_name
), getString(R
.string
.url_app_download
));
148 intent
.putExtra(Intent
.EXTRA_TEXT
, recommendText
);
150 intent
.setData(Uri
.parse(getString(R
.string
.mail_recommend
)));
151 intent
.addFlags(Intent
.FLAG_ACTIVITY_NEW_TASK
);
152 startActivity(intent
);
160 preferenceCategory
.removePreference(pRecommend
);
165 boolean feedbackEnabled
= getResources().getBoolean(R
.bool
.feedback_enabled
);
166 Preference pFeedback
= findPreference("feedback");
167 if (pFeedback
!= null
){
168 if (feedbackEnabled
) {
169 pFeedback
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
171 public boolean onPreferenceClick(Preference preference
) {
172 String feedbackMail
=(String
) getText(R
.string
.mail_feedback
);
173 String feedback
=(String
) getText(R
.string
.prefs_feedback
);
174 Intent intent
= new Intent(Intent
.ACTION_SENDTO
);
175 intent
.setType("text/plain");
176 intent
.putExtra(Intent
.EXTRA_SUBJECT
, feedback
);
178 intent
.setData(Uri
.parse(feedbackMail
));
179 intent
.addFlags(Intent
.FLAG_ACTIVITY_NEW_TASK
);
180 startActivity(intent
);
186 preferenceCategory
.removePreference(pFeedback
);
191 boolean imprintEnabled
= getResources().getBoolean(R
.bool
.imprint_enabled
);
192 Preference pImprint
= findPreference("imprint");
193 if (pImprint
!= null
) {
194 if (imprintEnabled
) {
195 pImprint
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
197 public boolean onPreferenceClick(Preference preference
) {
198 String imprintWeb
= (String
) getText(R
.string
.url_imprint
);
199 if (imprintWeb
!= null
&& imprintWeb
.length() > 0) {
200 Uri uriUrl
= Uri
.parse(imprintWeb
);
201 Intent intent
= new Intent(Intent
.ACTION_VIEW
, uriUrl
);
202 startActivity(intent
);
204 //ImprintDialog.newInstance(true).show(preference.get, "IMPRINT_DIALOG");
209 preferenceCategory
.removePreference(pImprint
);
214 pAboutApp
= (Preference
) findPreference("about_app");
215 if (pAboutApp
!= null
) {
216 pAboutApp
.setTitle(String
.format(getString(R
.string
.about_android
), getString(R
.string
.app_name
)));
219 pkg
= getPackageManager().getPackageInfo(getPackageName(), 0);
220 pAboutApp
.setSummary(String
.format(getString(R
.string
.about_version
), pkg
.versionName
));
221 } catch (NameNotFoundException e
) {
222 Log_OC
.e(TAG
, "Error while showing about dialog", e
);
226 /* DISABLED FOR RELEASE UNTIL FIXED
227 pLogging = (CheckBoxPreference) findPreference("log_to_file");
228 if (pLogging != null) {
229 pLogging.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
231 public boolean onPreferenceChange(Preference preference, Object newValue) {
233 String logpath = Environment.getExternalStorageDirectory()+File.separator+"owncloud"+File.separator+"log";
235 if(!pLogging.isChecked()) {
236 Log_OC.d("Debug", "start logging");
237 Log_OC.v("PATH", logpath);
238 Log_OC.startLogging(logpath);
241 Log_OC.d("Debug", "stop logging");
242 Log_OC.stopLogging();
249 pLoggingHistory = (Preference) findPreference("log_history");
250 if (pLoggingHistory != null) {
251 pLoggingHistory.setOnPreferenceClickListener(new OnPreferenceClickListener() {
254 public boolean onPreferenceClick(Preference preference) {
255 Intent intent = new Intent(getApplicationContext(),LogHistoryActivity.class);
256 startActivity(intent);
266 protected void onResume() {
267 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
268 boolean state
= appPrefs
.getBoolean("set_pincode", false
);
269 pCode
.setChecked(state
);
274 public boolean onCreateOptionsMenu(Menu menu
) {
275 super.onCreateOptionsMenu(menu
);
280 public boolean onMenuItemSelected(int featureId
, MenuItem item
) {
281 super.onMenuItemSelected(featureId
, item
);
284 switch (item
.getItemId()) {
285 case android
.R
.id
.home
:
286 intent
= new Intent(getBaseContext(), FileDisplayActivity
.class);
287 intent
.addFlags(Intent
.FLAG_ACTIVITY_CLEAR_TOP
);
288 startActivity(intent
);
291 Log_OC
.w(TAG
, "Unknown menu item triggered");
298 protected void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
299 super.onActivityResult(requestCode
, resultCode
, data
);
303 protected void onDestroy() {