Added facebook login button to the sharing login activity

pull/14/head
Tim Su 15 years ago
parent 6dbb814f02
commit 4d5b667243

@ -17,5 +17,6 @@
<classpathentry kind="lib" path="libs/framework.jar"/>
<classpathentry kind="src" path="GreenDroid_src"/>
<classpathentry kind="src" path="astridApi_src"/>
<classpathentry kind="src" path="facebook_src"/>
<classpathentry kind="output" path="ecbuild"/>
</classpath>

@ -47,5 +47,10 @@
<type>2</type>
<locationURI>_android_astridApi_98e6a2cf/src</locationURI>
</link>
<link>
<name>facebook_src</name>
<type>2</type>
<locationURI>_android_facebook_1da19ac6/src</locationURI>
</link>
</linkedResources>
</projectDescription>

@ -376,7 +376,7 @@
</intent-filter>
</receiver>
<!-- notes -->
<!-- sharing -->
<receiver android:name="com.todoroo.astrid.sharing.SharingDetailExposer">
<intent-filter>
<action android:name="com.todoroo.astrid.REQUEST_DETAILS" />
@ -389,6 +389,12 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<activity android:name="com.todoroo.astrid.sharing.SharingLoginActivity">
<intent-filter>
<action android:name="com.todoroo.astrid.SHARING" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<!-- timers -->
<receiver android:name="com.todoroo.astrid.timers.TimerActionExposer">

@ -5,20 +5,22 @@
<stringAttribute key="ch.zork.quicklaunch.icon" value="14.gif"/>
<intAttribute key="ch.zork.quicklaunch.index" value="0"/>
<stringAttribute key="ch.zork.quicklaunch.mode" value="run"/>
<intAttribute key="com.android.ide.eclipse.adt.action" value="0"/>
<stringAttribute key="com.android.ide.eclipse.adt.activity" value="com.todoroo.astrid.gtasks.GtasksPreferences"/>
<stringAttribute key="com.android.ide.eclipse.adt.avd" value="galaxy_tab"/>
<intAttribute key="com.android.ide.eclipse.adt.action" value="1"/>
<stringAttribute key="com.android.ide.eclipse.adt.activity" value="com.todoroo.astrid.sharing.SharingLoginActivity"/>
<stringAttribute key="com.android.ide.eclipse.adt.avd" value="android-23-wvga800"/>
<stringAttribute key="com.android.ide.eclipse.adt.commandline" value="-scale 0.7"/>
<intAttribute key="com.android.ide.eclipse.adt.delay" value="0"/>
<booleanAttribute key="com.android.ide.eclipse.adt.nobootanim" value="true"/>
<intAttribute key="com.android.ide.eclipse.adt.speed" value="0"/>
<booleanAttribute key="com.android.ide.eclipse.adt.target" value="false"/>
<booleanAttribute key="com.android.ide.eclipse.adt.target" value="true"/>
<booleanAttribute key="com.android.ide.eclipse.adt.wipedata" value="false"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/astrid"/>
<listEntry value="/astrid/AndroidManifest.xml"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="4"/>
<listEntry value="1"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>

@ -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();
}
}
}

@ -14,3 +14,4 @@ android.library.reference.1=../api/
target=android-8
apk-configurations=
android.library.reference.2=../greendroid/GreenDroid/
android.library.reference.3=../facebook/facebook/

@ -10,15 +10,12 @@ import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import com.timsu.astrid.R;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.api.TaskAction;
import com.todoroo.astrid.api.TaskDecoration;
import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.data.Task;
/**
* Exposes {@link TaskDecoration} for timers
@ -37,17 +34,19 @@ public class SharingActionExposer extends BroadcastReceiver {
if(taskId == -1)
return;
Task task = PluginServices.getTaskService().fetchById(taskId, Task.ID, Task.TITLE, Task.NOTES);
if(!task.containsNonNullValue(Task.NOTES) || TextUtils.isEmpty(task.getValue(Task.NOTES)))
return;
if(AstridApiConstants.BROADCAST_REQUEST_ACTIONS.equals(intent.getAction())) {
sendAction(context, taskId);
} else {
//
performAction(context, taskId);
}
}
private void performAction(Context context, long taskId) {
Intent intent = new Intent(context, SharingLoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
private void sendAction(Context context, long taskId) {
final String label = context.getString(R.string.sharing_action);
final Drawable drawable = context.getResources().getDrawable(R.drawable.tango_share);

@ -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

@ -7,6 +7,8 @@
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="5px"
android:paddingRight="5px"
android:orientation="vertical">
<ImageView
android:layout_width="fill_parent"
@ -29,10 +31,11 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingBottom="5dip"
android:paddingBottom="20dip"
android:textSize="20sp"
android:textColor="#333333"
android:text="@string/sharing_SLA_login" android:textStyle="bold"/>
android:text="@string/sharing_SLA_login"
android:textStyle="bold" />
<TextView
android:id="@+id/error"
android:layout_width="fill_parent"
@ -43,23 +46,50 @@
android:textSize="16sp"
android:textStyle="bold"
android:visibility="gone" />
<EditText
android:id="@+id/email"
android:layout_height="wrap_content"
<LinearLayout
android:layout_width="fill_parent"
android:hint="@string/gtasks_GLA_email"
android:inputType="textEmailAddress" />
<EditText
android:id="@+id/password"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.facebook.android.LoginButton
android:id="@+id/fb_login"
android:src="@drawable/facebook_64"
android:background="#00000000"
android:gravity="right"
android:paddingLeft="10px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
<ImageButton
android:id="@+id/google_login"
android:src="@drawable/google_64"
android:background="#00000000"
android:gravity="left"
android:paddingRight="10px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:hint="@string/gtasks_GLA_password"
android:inputType="textPassword" />
<Button
android:id="@+id/signIn"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingTop="10dip"
android:paddingBottom="20dip"
android:textSize="14sp"
android:textColor="#333333"
android:text="@string/sharing_SLA_next_step" />
<TextView
android:id="@+id/taskInfo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/gtasks_GLA_signIn" />
android:gravity="center"
android:textSize="20sp"
android:textColor="#333333"
android:text="@string/sharing_SLA_task"
android:textStyle="bold" />
</LinearLayout>
</ScrollView>

@ -7,14 +7,22 @@
<!-- task action: Share -->
<string name="sharing_action">Share</string>
<!-- task action: Sharing Description -->
<string name="sharing_SLA_body">MyAstrid lets you share your tasks with
<!-- share login: Title -->
<string name="sharing_SLA_title">Share This Task</string>
<!-- share login: Sharing Description -->
<string name="sharing_SLA_body">My Astrid lets you post tasks to the web to share with
others. Let your friends encourage and keep you accountable!</string>
<!-- task action: Sharing Login Prompt -->
<string name="sharing_SLA_login">Log in via Facebook or e-mail:</string>
<!-- share login: Sharing Login Prompt -->
<string name="sharing_SLA_login">Sign in using your Facebook or Google account:</string>
<!-- share login: Next Step information -->
<string name="sharing_SLA_next_step">On the next page,
you can choose how to share this task and choose recipients.</string>
<!-- share login: Sharing Task Information -->
<string name="sharing_SLA_task">Task to Share:</string>
</resources>

@ -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;

@ -9,4 +9,4 @@
android.library=true
# Project target.
target=android-3
target=android-4

Loading…
Cancel
Save