mirror of https://github.com/tasks/tasks
Added facebook login button to the sharing login activity
parent
6dbb814f02
commit
4d5b667243
@ -0,0 +1,12 @@
|
||||
package com.facebook.android;
|
||||
|
||||
|
||||
public interface AuthListener {
|
||||
|
||||
public void onFBAuthSucceed();
|
||||
|
||||
public void onFBAuthFail(String error);
|
||||
|
||||
public void onFBAuthCancel();
|
||||
|
||||
}
|
||||
@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright 2010 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.facebook.android;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.ImageButton;
|
||||
|
||||
import com.facebook.android.Facebook.DialogListener;
|
||||
|
||||
public class LoginButton extends ImageButton {
|
||||
|
||||
private Facebook mFb;
|
||||
private AuthListener mListener;
|
||||
private String[] mPermissions;
|
||||
private Activity mActivity;
|
||||
|
||||
public LoginButton(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public LoginButton(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public LoginButton(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
}
|
||||
|
||||
public void init(final Activity activity, final Facebook fb, AuthListener listener) {
|
||||
init(activity, fb, listener, new String[] {});
|
||||
}
|
||||
|
||||
public void init(final Activity activity, final Facebook fb, AuthListener listener,
|
||||
final String[] permissions) {
|
||||
mActivity = activity;
|
||||
mFb = fb;
|
||||
mPermissions = permissions;
|
||||
mListener = listener;
|
||||
|
||||
setBackgroundColor(Color.TRANSPARENT);
|
||||
setAdjustViewBounds(true);
|
||||
drawableStateChanged();
|
||||
|
||||
setOnClickListener(new ButtonOnClickListener());
|
||||
}
|
||||
|
||||
private final class ButtonOnClickListener implements OnClickListener {
|
||||
|
||||
public void onClick(View arg0) {
|
||||
if (mFb.isSessionValid()) {
|
||||
AsyncFacebookRunner asyncRunner = new AsyncFacebookRunner(mFb);
|
||||
asyncRunner.logout(getContext(), null);
|
||||
} else {
|
||||
mFb.authorize(mActivity, mPermissions,
|
||||
new LoginDialogListener());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final class LoginDialogListener implements DialogListener {
|
||||
public void onComplete(Bundle values) {
|
||||
mListener.onFBAuthSucceed();
|
||||
}
|
||||
|
||||
public void onFacebookError(FacebookError error) {
|
||||
mListener.onFBAuthFail(error.getMessage());
|
||||
}
|
||||
|
||||
public void onError(DialogError error) {
|
||||
mListener.onFBAuthFail(error.getMessage());
|
||||
}
|
||||
|
||||
public void onCancel() {
|
||||
mListener.onFBAuthCancel();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,124 @@
|
||||
/*
|
||||
* ASTRID: Android's Simple Task Recording Dashboard
|
||||
*
|
||||
* Copyright (c) 2009 Tim Su
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
package com.todoroo.astrid.sharing;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.facebook.android.AuthListener;
|
||||
import com.facebook.android.Facebook;
|
||||
import com.facebook.android.LoginButton;
|
||||
import com.timsu.astrid.R;
|
||||
import com.todoroo.andlib.service.Autowired;
|
||||
import com.todoroo.andlib.service.ContextManager;
|
||||
import com.todoroo.andlib.service.DependencyInjectionService;
|
||||
import com.todoroo.andlib.utility.DialogUtilities;
|
||||
import com.todoroo.astrid.data.Task;
|
||||
import com.todoroo.astrid.service.AstridDependencyInjector;
|
||||
import com.todoroo.astrid.service.TaskService;
|
||||
|
||||
/**
|
||||
* This activity allows users to sign in or log in to Producteev
|
||||
*
|
||||
* @author arne.jans
|
||||
*
|
||||
*/
|
||||
public class SharingLoginActivity extends Activity implements AuthListener {
|
||||
|
||||
public static final String APP_ID = "169904866369148"; //$NON-NLS-1$
|
||||
|
||||
@Autowired TaskService taskService;
|
||||
|
||||
private Facebook facebook;
|
||||
private TextView errors;
|
||||
|
||||
// --- ui initialization
|
||||
|
||||
static {
|
||||
AstridDependencyInjector.initialize();
|
||||
}
|
||||
|
||||
public String EXTRA_TASK_ID = "task"; //$NON-NLS-1$
|
||||
|
||||
public SharingLoginActivity() {
|
||||
super();
|
||||
DependencyInjectionService.getInstance().inject(this);
|
||||
}
|
||||
|
||||
@SuppressWarnings("nls")
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
ContextManager.setContext(this);
|
||||
|
||||
setContentView(R.layout.sharing_login_activity);
|
||||
setTitle(R.string.sharing_SLA_title);
|
||||
|
||||
long taskId = getIntent().getLongExtra(EXTRA_TASK_ID, 4L);
|
||||
Task task = taskService.fetchById(taskId, Task.TITLE);
|
||||
|
||||
TextView taskInfo = (TextView) findViewById(R.id.taskInfo);
|
||||
taskInfo.setText(taskInfo.getText() + "\n\n" + task.getValue(Task.TITLE));
|
||||
|
||||
facebook = new Facebook(APP_ID);
|
||||
|
||||
errors = (TextView) findViewById(R.id.error);
|
||||
LoginButton loginButton = (LoginButton) findViewById(R.id.fb_login);
|
||||
loginButton.init(this, facebook, this, new String[] {
|
||||
"email",
|
||||
"offline_access",
|
||||
"publish_stream"
|
||||
});
|
||||
}
|
||||
|
||||
// --- facebook handler
|
||||
|
||||
public void onFBAuthSucceed() {
|
||||
System.err.println("GOTCHA SUCCESS! " + facebook.getAccessToken());
|
||||
errors.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
public void onFBAuthFail(String error) {
|
||||
System.err.println("GOTCHA ERROR: " + error);
|
||||
DialogUtilities.okDialog(this, getString(R.string.sharing_SLA_title),
|
||||
android.R.drawable.ic_dialog_alert, error, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFBAuthCancel() {
|
||||
System.err.println("GOTCHA CANCEL");
|
||||
// do nothing
|
||||
}
|
||||
|
||||
// --- my astrid handler
|
||||
|
||||
/**
|
||||
* Create user account via FB
|
||||
*/
|
||||
public void createUserAccountFB() {
|
||||
String accessToken = facebook.getAccessToken();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.4 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.4 KiB |
@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
PROJECT=$(cd `dirname $0`/../astrid; pwd)
|
||||
for file in $(ls $PROJECT/res/drawable -l | awk '{ print $8}' | sed 's/\..\+//g'); do
|
||||
count=0;
|
||||
for SRCFILE in `find $PROJECT -name "*.xml" -print 2> /dev/null`; do
|
||||
let "count+=$(grep -c @drawable/$file $SRCFILE)";
|
||||
done
|
||||
for SRCFILE in `find $PROJECT -name "*.java" -print 2> /dev/null`; do
|
||||
let "count+=$(grep -c R.drawable.$file $SRCFILE)";
|
||||
done;
|
||||
if [ $count -lt 1 ]; then
|
||||
echo -e "\e[0;31m$file\e[0m not used";
|
||||
else
|
||||
echo -e "\e[0;32m$file\e[0m used";
|
||||
fi;
|
||||
done;
|
||||
Loading…
Reference in New Issue