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 de
.mobilcom
.debitel
.cloud
.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
;
42 import de
.mobilcom
.debitel
.cloud
.android
.Log_OC
;
43 import de
.mobilcom
.debitel
.cloud
.android
.OwnCloudSession
;
44 import de
.mobilcom
.debitel
.cloud
.android
.R
;
45 import de
.mobilcom
.debitel
.cloud
.android
.db
.DbHandler
;
48 * An Activity that allows the user to change the application's settings.
50 * @author Bartek Przybylski
53 public class Preferences
extends SherlockPreferenceActivity
implements OnPreferenceChangeListener
{
55 private static final String TAG
= "OwnCloudPreferences";
56 private final int mNewSession
= 47;
57 private final int mEditSession
= 48;
58 private DbHandler mDbHandler
;
59 private Vector
<OwnCloudSession
> mSessions
;
60 private ListPreference mTrackingUpdateInterval
;
61 private CheckBoxPreference mDeviceTracking
;
62 private CheckBoxPreference pCode
;
63 //private CheckBoxPreference pLogging;
64 //private Preference pLoggingHistory;
65 private Preference pAboutApp
;
66 private int mSelectedMenuItem
;
69 @SuppressWarnings("deprecation")
71 public void onCreate(Bundle savedInstanceState
) {
72 super.onCreate(savedInstanceState
);
73 mDbHandler
= new DbHandler(getBaseContext());
74 mSessions
= new Vector
<OwnCloudSession
>();
75 addPreferencesFromResource(R
.xml
.preferences
);
76 //populateAccountList();
77 ActionBar actionBar
= getSherlock().getActionBar();
78 actionBar
.setDisplayHomeAsUpEnabled(true
);
80 Preference p
= findPreference("manage_account");
82 p
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
84 public boolean onPreferenceClick(Preference preference
) {
85 Intent i
= new Intent(getApplicationContext(), AccountSelectActivity
.class);
91 pCode
= (CheckBoxPreference
) findPreference("set_pincode");
93 pCode
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
95 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
96 Intent i
= new Intent(getApplicationContext(), PinCodeActivity
.class);
97 i
.putExtra(PinCodeActivity
.EXTRA_ACTIVITY
, "preferences");
98 i
.putExtra(PinCodeActivity
.EXTRA_NEW_STATE
, newValue
.toString());
109 PreferenceCategory preferenceCategory
= (PreferenceCategory
) findPreference("more");
111 boolean helpEnabled
= getResources().getBoolean(R
.bool
.help_enabled
);
112 Preference pHelp
= findPreference("help");
115 pHelp
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
117 public boolean onPreferenceClick(Preference preference
) {
118 String helpWeb
=(String
) getText(R
.string
.url_help
);
119 if (helpWeb
!= null
&& helpWeb
.length() > 0) {
120 Uri uriUrl
= Uri
.parse(helpWeb
);
121 Intent intent
= new Intent(Intent
.ACTION_VIEW
, uriUrl
);
122 startActivity(intent
);
128 preferenceCategory
.removePreference(pHelp
);
134 boolean recommendEnabled
= getResources().getBoolean(R
.bool
.recommend_enabled
);
135 Preference pRecommend
= findPreference("recommend");
136 if (pRecommend
!= null
){
137 if (recommendEnabled
) {
138 pRecommend
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
140 public boolean onPreferenceClick(Preference preference
) {
142 Intent intent
= new Intent(Intent
.ACTION_SENDTO
);
143 intent
.setType("text/plain");
144 //Account currentAccount = AccountUtils.getCurrentOwnCloudAccount(Preferences.this);
145 String appName
= getString(R
.string
.app_name
);
146 //String username = currentAccount.name.substring(0, currentAccount.name.lastIndexOf('@'));
147 //String recommendSubject = String.format(getString(R.string.recommend_subject), username, appName);
148 String recommendSubject
= String
.format(getString(R
.string
.recommend_subject
), appName
);
149 intent
.putExtra(Intent
.EXTRA_SUBJECT
, recommendSubject
);
150 //String recommendText = String.format(getString(R.string.recommend_text), getString(R.string.app_name), username);
151 String recommendText
= String
.format(getString(R
.string
.recommend_text
), getString(R
.string
.app_name
), getString(R
.string
.url_app_download
));
152 intent
.putExtra(Intent
.EXTRA_TEXT
, recommendText
);
154 intent
.setData(Uri
.parse(getString(R
.string
.mail_recommend
)));
155 intent
.addFlags(Intent
.FLAG_ACTIVITY_NEW_TASK
);
156 startActivity(intent
);
164 preferenceCategory
.removePreference(pRecommend
);
169 boolean feedbackEnabled
= getResources().getBoolean(R
.bool
.feedback_enabled
);
170 Preference pFeedback
= findPreference("feedback");
171 if (pFeedback
!= null
){
172 if (feedbackEnabled
) {
173 pFeedback
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
175 public boolean onPreferenceClick(Preference preference
) {
176 String feedbackMail
=(String
) getText(R
.string
.mail_feedback
);
177 String feedback
=(String
) getText(R
.string
.prefs_feedback
);
178 Intent intent
= new Intent(Intent
.ACTION_SENDTO
);
179 intent
.setType("text/plain");
180 intent
.putExtra(Intent
.EXTRA_SUBJECT
, feedback
);
182 intent
.setData(Uri
.parse(feedbackMail
));
183 intent
.addFlags(Intent
.FLAG_ACTIVITY_NEW_TASK
);
184 startActivity(intent
);
190 preferenceCategory
.removePreference(pFeedback
);
195 boolean imprintEnabled
= getResources().getBoolean(R
.bool
.imprint_enabled
);
196 Preference pImprint
= findPreference("imprint");
197 if (pImprint
!= null
) {
198 if (imprintEnabled
) {
199 pImprint
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
201 public boolean onPreferenceClick(Preference preference
) {
202 String imprintWeb
= (String
) getText(R
.string
.url_imprint
);
203 if (imprintWeb
!= null
&& imprintWeb
.length() > 0) {
204 Uri uriUrl
= Uri
.parse(imprintWeb
);
205 Intent intent
= new Intent(Intent
.ACTION_VIEW
, uriUrl
);
206 startActivity(intent
);
208 //ImprintDialog.newInstance(true).show(preference.get, "IMPRINT_DIALOG");
213 preferenceCategory
.removePreference(pImprint
);
218 pAboutApp
= (Preference
) findPreference("about_app");
219 if (pAboutApp
!= null
) {
220 pAboutApp
.setTitle(String
.format(getString(R
.string
.about_android
), getString(R
.string
.app_name
)));
223 pkg
= getPackageManager().getPackageInfo(getPackageName(), 0);
224 pAboutApp
.setSummary(String
.format(getString(R
.string
.about_version
), pkg
.versionName
));
225 } catch (NameNotFoundException e
) {
226 Log_OC
.e(TAG
, "Error while showing about dialog", e
);
230 /* DISABLED FOR RELEASE UNTIL FIXED
231 pLogging = (CheckBoxPreference) findPreference("log_to_file");
232 if (pLogging != null) {
233 pLogging.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
235 public boolean onPreferenceChange(Preference preference, Object newValue) {
237 String logpath = Environment.getExternalStorageDirectory()+File.separator+"owncloud"+File.separator+"log";
239 if(!pLogging.isChecked()) {
240 Log_OC.d("Debug", "start logging");
241 Log_OC.v("PATH", logpath);
242 Log_OC.startLogging(logpath);
245 Log_OC.d("Debug", "stop logging");
246 Log_OC.stopLogging();
253 pLoggingHistory = (Preference) findPreference("log_history");
254 if (pLoggingHistory != null) {
255 pLoggingHistory.setOnPreferenceClickListener(new OnPreferenceClickListener() {
258 public boolean onPreferenceClick(Preference preference) {
259 Intent intent = new Intent(getApplicationContext(),LogHistoryActivity.class);
260 startActivity(intent);
270 protected void onResume() {
271 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
272 boolean state
= appPrefs
.getBoolean("set_pincode", false
);
273 pCode
.setChecked(state
);
278 public boolean onCreateOptionsMenu(Menu menu
) {
279 super.onCreateOptionsMenu(menu
);
284 public boolean onMenuItemSelected(int featureId
, MenuItem item
) {
285 super.onMenuItemSelected(featureId
, item
);
288 switch (item
.getItemId()) {
289 //case R.id.addSessionItem:
291 intent
= new Intent(this, PreferencesNewSession
.class);
292 startActivityForResult(intent
, mNewSession
);
294 case R
.id
.SessionContextEdit
:
295 intent
= new Intent(this, PreferencesNewSession
.class);
296 intent
.putExtra("sessionId", mSessions
.get(mSelectedMenuItem
)
298 intent
.putExtra("sessionName", mSessions
.get(mSelectedMenuItem
)
300 intent
.putExtra("sessionURL", mSessions
.get(mSelectedMenuItem
)
302 startActivityForResult(intent
, mEditSession
);
304 case android
.R
.id
.home
:
305 intent
= new Intent(getBaseContext(), FileDisplayActivity
.class);
306 intent
.addFlags(Intent
.FLAG_ACTIVITY_CLEAR_TOP
);
307 startActivity(intent
);
310 Log_OC
.w(TAG
, "Unknown menu item triggered");
317 protected void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
318 super.onActivityResult(requestCode
, resultCode
, data
);
322 protected void onDestroy() {
329 * Updates various summaries after updates. Also starts and stops
332 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
333 // Update current account summary
334 /*if (preference.equals(mAccountList)) {
335 mAccountList.setSummary(newValue.toString());
338 // Update tracking interval summary
339 else*/ if (preference
.equals(mTrackingUpdateInterval
)) {
340 String trackingSummary
= getResources().getString(
341 R
.string
.prefs_trackmydevice_interval_summary
);
342 trackingSummary
= String
.format(trackingSummary
,
343 newValue
.toString());
344 mTrackingUpdateInterval
.setSummary(trackingSummary
);
347 // Start or stop tracking service
348 else if (preference
.equals(mDeviceTracking
)) {
349 Intent locationServiceIntent
= new Intent();
350 locationServiceIntent
351 .setAction("de.mobilcom.debitel.cloud.android.location.LocationLauncher");
352 locationServiceIntent
.putExtra("TRACKING_SETTING",
354 sendBroadcast(locationServiceIntent
);