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 as published by
7 * the Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package com
.owncloud
.android
.ui
.activity
;
21 import java
.util
.Vector
;
23 import android
.content
.Intent
;
24 import android
.content
.SharedPreferences
;
25 import android
.content
.pm
.PackageInfo
;
26 import android
.content
.pm
.PackageManager
.NameNotFoundException
;
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
;
34 import android
.util
.Log
;
36 import com
.actionbarsherlock
.app
.ActionBar
;
37 import com
.actionbarsherlock
.app
.SherlockPreferenceActivity
;
38 import com
.actionbarsherlock
.view
.Menu
;
39 import com
.actionbarsherlock
.view
.MenuItem
;
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 Preference pAboutApp
;
61 private int mSelectedMenuItem
;
63 @SuppressWarnings("deprecation")
65 public void onCreate(Bundle savedInstanceState
) {
66 super.onCreate(savedInstanceState
);
67 mDbHandler
= new DbHandler(getBaseContext());
68 mSessions
= new Vector
<OwnCloudSession
>();
69 addPreferencesFromResource(R
.xml
.preferences
);
70 //populateAccountList();
71 ActionBar actionBar
= getSherlock().getActionBar();
72 actionBar
.setDisplayHomeAsUpEnabled(true
);
73 Preference p
= findPreference("manage_account");
75 p
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
77 public boolean onPreferenceClick(Preference preference
) {
78 Intent i
= new Intent(getApplicationContext(), AccountSelectActivity
.class);
84 pCode
= (CheckBoxPreference
) findPreference("set_pincode");
86 pCode
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
88 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
89 Intent i
= new Intent(getApplicationContext(), PinCodeActivity
.class);
90 i
.putExtra(PinCodeActivity
.EXTRA_ACTIVITY
, "preferences");
91 i
.putExtra(PinCodeActivity
.EXTRA_NEW_STATE
, newValue
.toString());
98 pAboutApp
= (Preference
) findPreference("about_app");
99 if (pAboutApp
!= null
) {
100 pAboutApp
.setTitle(getString(R
.string
.app_name
)+" "+getString(R
.string
.about_android
));
103 pkg
= getPackageManager().getPackageInfo(getPackageName(), 0);
104 pAboutApp
.setSummary(getString(R
.string
.about_version
)+" "+pkg
.versionName
);
105 } catch (NameNotFoundException e
) {
106 Log
.e(TAG
, "Error while showing about dialog", e
);
113 protected void onResume() {
114 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
115 boolean state
= appPrefs
.getBoolean("set_pincode", false
);
116 pCode
.setChecked(state
);
121 public boolean onCreateOptionsMenu(Menu menu
) {
122 super.onCreateOptionsMenu(menu
);
127 public boolean onMenuItemSelected(int featureId
, MenuItem item
) {
128 super.onMenuItemSelected(featureId
, item
);
131 switch (item
.getItemId()) {
132 //case R.id.addSessionItem:
134 intent
= new Intent(this, PreferencesNewSession
.class);
135 startActivityForResult(intent
, mNewSession
);
137 case R
.id
.SessionContextEdit
:
138 intent
= new Intent(this, PreferencesNewSession
.class);
139 intent
.putExtra("sessionId", mSessions
.get(mSelectedMenuItem
)
141 intent
.putExtra("sessionName", mSessions
.get(mSelectedMenuItem
)
143 intent
.putExtra("sessionURL", mSessions
.get(mSelectedMenuItem
)
145 startActivityForResult(intent
, mEditSession
);
147 case android
.R
.id
.home
:
148 intent
= new Intent(getBaseContext(), FileDisplayActivity
.class);
149 intent
.addFlags(Intent
.FLAG_ACTIVITY_CLEAR_TOP
);
150 startActivity(intent
);
153 Log
.w(TAG
, "Unknown menu item triggered");
160 protected void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
161 super.onActivityResult(requestCode
, resultCode
, data
);
165 protected void onDestroy() {
172 * Updates various summaries after updates. Also starts and stops
175 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
176 // Update current account summary
177 /*if (preference.equals(mAccountList)) {
178 mAccountList.setSummary(newValue.toString());
181 // Update tracking interval summary
182 else*/ if (preference
.equals(mTrackingUpdateInterval
)) {
183 String trackingSummary
= getResources().getString(
184 R
.string
.prefs_trackmydevice_interval_summary
);
185 trackingSummary
= String
.format(trackingSummary
,
186 newValue
.toString());
187 mTrackingUpdateInterval
.setSummary(trackingSummary
);
190 // Start or stop tracking service
191 else if (preference
.equals(mDeviceTracking
)) {
192 Intent locationServiceIntent
= new Intent();
193 locationServiceIntent
194 .setAction("com.owncloud.android.location.LocationLauncher");
195 locationServiceIntent
.putExtra("TRACKING_SETTING",
197 sendBroadcast(locationServiceIntent
);