Skip to content
Browse files

Removed Dropbox consumer key and secret values from public source

* Developer must explicitly set them into the new dropbox.xml config file
* Added dropbox.xml to .gitignore
* Added sample-dropbox.xml file template
* Eclipse file formatting
* Upped version number to 5
  • Loading branch information...
1 parent 4c9812e commit 4dd1824cd21e88d27f739d5fd5cd094926eebb23 @ginatrapani ginatrapani committed Jan 6, 2011
View
1 .gitignore
@@ -8,3 +8,4 @@ build.xml
local.properties
bin/
gen/
+res/values/dropbox.xml
View
4 AndroidManifest.xml
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.todotxt.todotxttouch"
- android:versionCode="4"
- android:versionName="0.0.4">
+ android:versionCode="5"
+ android:versionName="0.0.5">
<!--
java warning 'is lower than the project target API level' should be ok
-->
View
8 res/values/sample-dropbox.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+<!--
+First, copy this file to dropbox.xml, then delete this line and fill in the appropriate values
+ <string name="dropbox_consumer_key">Enter your Dropbox app consumer key here</string>
+ <string name="dropbox_consumer_secret">Enter your Dropbox app consumer secret here</string>
+-->
+</resources>
View
15 src/com/todotxt/todotxttouch/Constants.java
@@ -6,23 +6,20 @@
public class Constants {
- public static final String CONSUMER_KEY = "24uvvbp09jcgkv0";
- public static final String CONSUMER_SECRET = "arl24x8l1jgqy7p";
-
public static final String PREF_FIRSTRUN = "firstrun";
public static final String PREF_ACCESSTOKEN_KEY = "accesstokenkey";
public static final String PREF_ACCESSTOKEN_SECRET = "accesstokensecret";
public static final String REMOTE_FILE = "/todo.txt";
- public final static File TODOFILE = new File(Environment
- .getExternalStorageDirectory(),
+ public final static File TODOFILE = new File(
+ Environment.getExternalStorageDirectory(),
"data/com.todotxt.todotxttouch/todo.txt");
-
- public final static File TODOFILETMP = new File(Environment
- .getExternalStorageDirectory(),
+
+ public final static File TODOFILETMP = new File(
+ Environment.getExternalStorageDirectory(),
"data/com.todotxt.todotxttouch/tmp/todo.txt");
-
+
public final static long INVALID_ID = -1;
public final static int INVALID_POSITION = -1;
View
80 src/com/todotxt/todotxttouch/TodoApplication.java
@@ -11,7 +11,8 @@
import com.dropbox.client.DropboxClient;
import com.dropbox.client.DropboxClientHelper;
-public class TodoApplication extends Application implements OnSharedPreferenceChangeListener {
+public class TodoApplication extends Application implements
+ OnSharedPreferenceChangeListener {
private final static String TAG = TodoApplication.class.getSimpleName();
@@ -22,9 +23,8 @@
public void onCreate() {
super.onCreate();
- m_prefs = PreferenceManager
- .getDefaultSharedPreferences(this);
-
+ m_prefs = PreferenceManager.getDefaultSharedPreferences(this);
+
m_prefs.registerOnSharedPreferenceChangeListener(this);
}
@@ -35,9 +35,8 @@ public void onTerminate() {
}
@Override
- public void onSharedPreferenceChanged(SharedPreferences prefs,
- String key) {
- if(getString(R.string.PREFCLEAR_key).equals(key)){
+ public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
+ if (getString(R.string.PREFCLEAR_key).equals(key)) {
Log.i(TAG, "Clearing current user data!");
Editor editor = prefs.edit();
editor.clear();
@@ -47,60 +46,79 @@ public void onSharedPreferenceChanged(SharedPreferences prefs,
Util.showToastShort(this, "Logged out!");
}
}
-
+
public DropboxClient getClient(Activity cxt) {
- if(m_client == null){
+ if (m_client == null) {
initDropboxClient(cxt);
}
return m_client;
}
- private void initDropboxClient(final Activity act){
- String accessToken = m_prefs.getString(Constants.PREF_ACCESSTOKEN_KEY, null);
- String accessTokenSecret = m_prefs.getString(Constants.PREF_ACCESSTOKEN_SECRET, null);
- if(!Util.isEmpty(accessToken) && !Util.isEmpty(accessTokenSecret)){
- DropboxClient tempClient = DropboxClientHelper.newAuthenticatedClient(
- Constants.CONSUMER_KEY, Constants.CONSUMER_SECRET,
- accessToken, accessTokenSecret);
+ private void initDropboxClient(final Activity act) {
+ String accessToken = m_prefs.getString(Constants.PREF_ACCESSTOKEN_KEY,
+ null);
+ String accessTokenSecret = m_prefs.getString(
+ Constants.PREF_ACCESSTOKEN_SECRET, null);
+ if (!Util.isEmpty(accessToken) && !Util.isEmpty(accessTokenSecret)) {
+ String consumerKey = getResources().getText(
+ R.string.dropbox_consumer_key).toString();
+ String consumerSecret = getText(R.string.dropbox_consumer_secret)
+ .toString();
+ Log.i(TAG, "Using Dropbox key " + consumerKey + " and secret "
+ + consumerSecret);
+ DropboxClient tempClient = DropboxClientHelper
+ .newAuthenticatedClient(consumerKey, consumerSecret,
+ accessToken, accessTokenSecret);
boolean valid = DropboxClientHelper.isValidClient(tempClient);
- if(valid){
+ if (valid) {
m_client = tempClient;
return;
}
}
- //Show login dialog
- act.runOnUiThread(new Runnable(){
+ // Show login dialog
+ act.runOnUiThread(new Runnable() {
@Override
public void run() {
- Util.LoginDialogListener dialogListener = new Util.LoginDialogListener(){
+ Util.LoginDialogListener dialogListener = new Util.LoginDialogListener() {
@Override
public void onClick(String username, String password) {
try {
+ String consumerKey = getResources().getText(
+ R.string.dropbox_consumer_key).toString();
+ String consumerSecret = getResources().getText(
+ R.string.dropbox_consumer_secret)
+ .toString();
+ Log.i(TAG, "Using Dropbox key " + consumerKey
+ + " and secret " + consumerSecret);
DropboxClient tempClient = DropboxClientHelper
- .newClient(Constants.CONSUMER_KEY,
- Constants.CONSUMER_SECRET,
+ .newClient(consumerKey, consumerSecret,
username, password);
- boolean valid = DropboxClientHelper.isValidClient(tempClient);
- if(valid){
+ boolean valid = DropboxClientHelper
+ .isValidClient(tempClient);
+ if (valid) {
Editor editor = m_prefs.edit();
- editor.putString(Constants.PREF_ACCESSTOKEN_KEY,
+ editor.putString(
+ Constants.PREF_ACCESSTOKEN_KEY,
tempClient.getAccessToken());
- editor.putString(Constants.PREF_ACCESSTOKEN_SECRET,
+ editor.putString(
+ Constants.PREF_ACCESSTOKEN_SECRET,
tempClient.getAccessTokenSecret());
editor.commit();
m_client = tempClient;
}
} catch (Exception e) {
Util.showToastLong(TodoApplication.this,
- "Could not create dropbox client!");
+ "Could not create Dropbox client!");
+ Log.i(TAG,
+ "Could not create Dropbox client! Exception details: "
+ + e.getLocalizedMessage());
}
}
};
- Util.showLoginDialog(act,
- R.string.dropbox_authentication, R.string.login, "",
- dialogListener, R.drawable.menu_sync);
+ Util.showLoginDialog(act, R.string.dropbox_authentication,
+ R.string.login, "", dialogListener,
+ R.drawable.menu_sync);
}
});
}
-
}

0 comments on commit 4dd1824

Please sign in to comment.
Something went wrong with that request. Please try again.