我正在尝试制作一个与 facebook 集成的应用程序,并按照 facebook 的说明进行操作。但是,“ProfilePictureView”在注销后并没有返回空白。有没有办法“空白” ProfilePictureView 或者它只是不提供这样的功能?
我的代码如下:
package com.nick.militarycounter;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.facebook.FacebookAuthorizationException;
import com.facebook.FacebookOperationCanceledException;
import com.facebook.Request;
import com.facebook.Response;
import com.facebook.Session;
import com.facebook.SessionState;
import com.facebook.UiLifecycleHelper;
import com.facebook.model.GraphUser;
import com.facebook.widget.LoginButton;
import com.facebook.widget.ProfilePictureView;
public class RegisterActivity extends Activity {
private static final String TAG = "RegisterActivity";
private LoginButton loginButton;
private EditText editTextAccount;
private EditText editTextEnterDate;
private Button button1;
private EditText editTextPassword;
private EditText editTextDiscountDays;
private ProfilePictureView facebookProfilePic;
UiLifecycleHelper uiHelper;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.register_activity);
loginButton = (LoginButton) findViewById(R.id.login_button);
editTextAccount = (EditText) findViewById(R.id.editText_account);
editTextEnterDate = (EditText) findViewById(R.id.editText_enterDate);
button1 = (Button) findViewById(R.id.button1);
editTextPassword = (EditText) findViewById(R.id.editText_password);
editTextDiscountDays = (EditText) findViewById(R.id.editText_discountDays);
facebookProfilePic = (ProfilePictureView) findViewById(R.id.facebook_profile_pic);
textView_userName = (TextView) findViewById(R.id.textview_loginStatus);
uiHelper = new UiLifecycleHelper(this, FBLoginCallback);
uiHelper.onCreate(savedInstanceState);
loginButton = (LoginButton) findViewById(R.id.login_button);
loginButton
.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() {
@Override
public void onUserInfoFetched(GraphUser user) {
RegisterActivity.this.mUser = user;
}
});
// Find the user's profile picture custom view
ProfilePictureView profilePictureView = (ProfilePictureView) findViewById(R.id.facebook_profile_pic);
profilePictureView.setCropped(true);
}
ProfilePictureView profilePictureView;
GraphUser mUser;
TextView textView_userName;
// The "callback" defined how to handle the login result.
private Session.StatusCallback FBLoginCallback = new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state,
Exception exception) {
// Failed
if ((exception instanceof FacebookOperationCanceledException || exception instanceof FacebookAuthorizationException)) {
new AlertDialog.Builder(RegisterActivity.this).setTitle("取消")
.setMessage("登入失敗!").setPositiveButton("ok", null)
.show();
textView_userName.setText("登入失敗");
} // Successed
else if (state.isClosed()) {
textView_userName.setText("請按登入鍵登入");
// should reset image of profilePictureView HERE!
} else {
textView_userName.setText("登入中...");
makeMeRequest(session);
}
}
};
/**
* Set the user name and image
*
* @param session
*/
private void makeMeRequest(final Session session) {
// Make an API call to get user data and define a
// new callback to handle the response.
Request request = Request.newMeRequest(session,
new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user, Response response) {
// If the response is successful
if (session == Session.getActiveSession()) {
if (user != null) {
mUser = user;
facebookProfilePic.setProfileId(user.getId());
textView_userName.setText(user.getName());
}
}
if (response.getError() != null) {
// Handle errors, will do so later.
}
}
});
request.executeAsync();
}
@Override
protected void onResume() {
super.onResume();
uiHelper.onResume();
Log.d(TAG, " onResume");
// 這個是用來檢查是不是由facebook中notification連結而來
// 同時讀取相關的資訊
// checkReceivedRequest();
loginButton = (LoginButton) findViewById(R.id.login_button);
loginButton
.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() {
@Override
public void onUserInfoFetched(GraphUser user) {
RegisterActivity.this.mUser = user;
}
});
// Find the user's profile picture custom view
profilePictureView = (ProfilePictureView) findViewById(R.id.facebook_profile_pic);
profilePictureView.setCropped(true);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
uiHelper.onSaveInstanceState(outState);
Log.d(TAG, "onSaveInstanceState");
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d(TAG, "onActivityResult");
uiHelper.onActivityResult(requestCode, resultCode, data);
}
@Override
public void onPause() {
super.onPause();
uiHelper.onPause();
Log.d(TAG, "onPause");
}
@Override
public void onDestroy() {
super.onDestroy();
uiHelper.onDestroy();
Log.d(TAG, "onDestroy");
}
}
提前致谢!