Skip to content

Commit

Permalink
Removed org.joda.time.DateTime import that was not used
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimeh committed Mar 27, 2012
1 parent 856ebb0 commit 9383d17
Showing 1 changed file with 51 additions and 48 deletions.
Expand Up @@ -6,8 +6,6 @@
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;


import org.joda.time.DateTime;

import com.google.api.client.extensions.android2.AndroidHttp; import com.google.api.client.extensions.android2.AndroidHttp;
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.extensions.android2.auth.GoogleAccountManager; import com.google.api.client.googleapis.extensions.android2.auth.GoogleAccountManager;
Expand Down Expand Up @@ -58,8 +56,8 @@




public class GoogleTasksClientActivity extends SherlockActivity { public class GoogleTasksClientActivity extends SherlockActivity {


/** Logging level for HTTP requests/responses. */ /** Logging level for HTTP requests/responses. */
private static final Level LOGGING_LEVEL = Level.OFF; private static final Level LOGGING_LEVEL = Level.OFF;


Expand All @@ -74,7 +72,7 @@ public class GoogleTasksClientActivity extends SherlockActivity {
private static final int REQUEST_AUTHENTICATE = 0; private static final int REQUEST_AUTHENTICATE = 0;


final HttpTransport transport = AndroidHttp.newCompatibleTransport(); final HttpTransport transport = AndroidHttp.newCompatibleTransport();

final JsonFactory jsonFactory = new JacksonFactory(); final JsonFactory jsonFactory = new JacksonFactory();


static final String PREF_ACCOUNT_NAME = "accountName"; static final String PREF_ACCOUNT_NAME = "accountName";
Expand All @@ -90,28 +88,29 @@ public class GoogleTasksClientActivity extends SherlockActivity {
GoogleCredential credential = new GoogleCredential(); GoogleCredential credential = new GoogleCredential();


com.google.api.services.tasks.Tasks service; com.google.api.services.tasks.Tasks service;

List<String> taskTitles = new ArrayList<String>(); List<String> taskTitles = new ArrayList<String>();

@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {

//add menu items to the action bar. look on onOptionsItemSelected to action code. //add menu items to the action bar. look on onOptionsItemSelected to action code.

menu.add(0,0,0,"Add New Task"); menu.add(0,0,0,"Add New Task");
menu.add(0,1,0,"Search"); menu.add(0,1,0,"Search");
menu.add(0,2,0,"Settings"); menu.add(0,2,0,"Settings");
menu.add(0,3,0,"Refresh"); menu.add(0,3,0,"Refresh");

return true; return true;
} }


//to Download All List and add items to listview. //to Download All List and add items to listview.
class RetreiveTask extends AsyncTask<String, Void, GoogleTasksClientActivity> { class RetreiveTask extends AsyncTask<String, Void, GoogleTasksClientActivity> {

ListView listView = (ListView) findViewById(R.id.mylist); ListView listView = (ListView) findViewById(R.id.mylist);
protected GoogleTasksClientActivity doInBackground(String... urls) { @Override
protected GoogleTasksClientActivity doInBackground(String... urls) {


try { try {
List<Task> tasks = service.tasks().list("@default").execute().getItems(); List<Task> tasks = service.tasks().list("@default").execute().getItems();
Expand All @@ -123,40 +122,41 @@ protected GoogleTasksClientActivity doInBackground(String... urls) {
} else { } else {
taskTitles.add("No tasks."); taskTitles.add("No tasks.");
} }

} catch (IOException e) { } catch (IOException e) {
handleGoogleException(e); handleGoogleException(e);
} }

return null; return null;


} }




@Override
protected void onPostExecute(GoogleTasksClientActivity feed) { protected void onPostExecute(GoogleTasksClientActivity feed) {
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(),
R.layout.list_item, R.layout.list_item,
taskTitles); taskTitles);
listView.setAdapter(adapter); listView.setAdapter(adapter);
} }
} }





@Override @Override
public boolean onOptionsItemSelected(MenuItem item) public boolean onOptionsItemSelected(MenuItem item)
{ {


switch(item.getItemId()) switch(item.getItemId())
{ {
case 0: case 0:
{ {
//Open AddTaskActivity to add new task. //Open AddTaskActivity to add new task.
Intent myIntent = new Intent(GoogleTasksClientActivity.this, AddTaskActivity.class); Intent myIntent = new Intent(GoogleTasksClientActivity.this, AddTaskActivity.class);
GoogleTasksClientActivity.this.startActivity(myIntent); GoogleTasksClientActivity.this.startActivity(myIntent);

return true; return true;
} }
case 1: case 1:
Expand All @@ -181,43 +181,44 @@ public boolean onOptionsItemSelected(MenuItem item)
default: default:
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }

} }

/** Called when the activity is first created. */ /** Called when the activity is first created. */
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);

settings = PreferenceManager.getDefaultSharedPreferences(this); settings = PreferenceManager.getDefaultSharedPreferences(this);





setContentView(R.layout.main); setContentView(R.layout.main);

service = com.google.api.services.tasks.Tasks.builder(transport, jsonFactory) service = com.google.api.services.tasks.Tasks.builder(transport, jsonFactory)
.setApplicationName("RedditGoogleTasks/1.0") .setApplicationName("RedditGoogleTasks/1.0")
.setHttpRequestInitializer(credential) .setHttpRequestInitializer(credential)
.setJsonHttpRequestInitializer(new JsonHttpRequestInitializer() { .setJsonHttpRequestInitializer(new JsonHttpRequestInitializer() {


public void initialize(JsonHttpRequest request) throws IOException { @Override
public void initialize(JsonHttpRequest request) throws IOException {
TasksRequest tasksRequest = (TasksRequest) request; TasksRequest tasksRequest = (TasksRequest) request;
tasksRequest.setKey(ClientCredentials.KEY); tasksRequest.setKey(ClientCredentials.KEY);

} }
}) })
.build(); .build();

//settings = getPreferences(MODE_PRIVATE); //settings = getPreferences(MODE_PRIVATE);


accountName = settings.getString(PREF_ACCOUNT_NAME, null); accountName = settings.getString(PREF_ACCOUNT_NAME, null);
credential.setAccessToken(settings.getString(PREF_AUTH_TOKEN, null)); credential.setAccessToken(settings.getString(PREF_AUTH_TOKEN, null));
Logger.getLogger("com.google.api.client").setLevel(LOGGING_LEVEL); Logger.getLogger("com.google.api.client").setLevel(LOGGING_LEVEL);

accountManager = new GoogleAccountManager(getApplicationContext()); accountManager = new GoogleAccountManager(getApplicationContext());
gotAccount(); gotAccount();


} }
//Put oauthToken on sharedPreferences //Put oauthToken on sharedPreferences
void setAuthToken(String authToken) { void setAuthToken(String authToken) {
Expand All @@ -226,7 +227,7 @@ void setAuthToken(String authToken) {
editor.commit(); editor.commit();
credential.setAccessToken(authToken); credential.setAccessToken(authToken);
} }

void gotAccount() { void gotAccount() {
Account account = accountManager.getAccountByName(accountName); Account account = accountManager.getAccountByName(accountName);
if (account == null) { if (account == null) {
Expand All @@ -241,7 +242,8 @@ void gotAccount() {
accountManager.manager.getAuthToken( accountManager.manager.getAuthToken(
account, AUTH_TOKEN_TYPE, true, new AccountManagerCallback<Bundle>() { account, AUTH_TOKEN_TYPE, true, new AccountManagerCallback<Bundle>() {


public void run(AccountManagerFuture<Bundle> future) { @Override
public void run(AccountManagerFuture<Bundle> future) {
try { try {
Bundle bundle = future.getResult(); Bundle bundle = future.getResult();
if (bundle.containsKey(AccountManager.KEY_INTENT)) { if (bundle.containsKey(AccountManager.KEY_INTENT)) {
Expand All @@ -258,7 +260,7 @@ public void run(AccountManagerFuture<Bundle> future) {
} }
}, null); }, null);
} }

private void chooseAccount() { private void chooseAccount() {
accountManager.manager.getAuthTokenByFeatures(GoogleAccountManager.ACCOUNT_TYPE, accountManager.manager.getAuthTokenByFeatures(GoogleAccountManager.ACCOUNT_TYPE,
AUTH_TOKEN_TYPE, AUTH_TOKEN_TYPE,
Expand All @@ -268,7 +270,8 @@ private void chooseAccount() {
null, null,
new AccountManagerCallback<Bundle>() { new AccountManagerCallback<Bundle>() {


public void run(AccountManagerFuture<Bundle> future) { @Override
public void run(AccountManagerFuture<Bundle> future) {
Bundle bundle; Bundle bundle;
try { try {
bundle = future.getResult(); bundle = future.getResult();
Expand All @@ -294,7 +297,7 @@ void setAccountName(String accountName) {
editor.commit(); editor.commit();
this.accountName = accountName; this.accountName = accountName;
} }





void handleGoogleException(IOException e) { void handleGoogleException(IOException e) {
Expand All @@ -313,10 +316,10 @@ void handleGoogleException(IOException e) {
} }
Log.e(TAG, e.getMessage(), e); Log.e(TAG, e.getMessage(), e);
} }

//Currently to refresh listView, we need to restart the main activity. this will be temporary fix. ||rheza //Currently to refresh listView, we need to restart the main activity. this will be temporary fix. ||rheza
public void refresh() { public void refresh() {

Intent intent = getIntent(); Intent intent = getIntent();
overridePendingTransition(0, 0); overridePendingTransition(0, 0);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
Expand All @@ -325,6 +328,6 @@ public void refresh() {
overridePendingTransition(0, 0); overridePendingTransition(0, 0);
startActivity(intent); startActivity(intent);
} }


} }

0 comments on commit 9383d17

Please sign in to comment.