android - Facebook ProfilePictureView did not goes blank after logout -
i trying make make app integrated facebook , followed instruction facebook. however, "profilepictureview" did not return blank after logout. there ways "blank" profilepictureview or don't provide such function?
my code following:
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 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; // "callback" defined how handle 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 user name , image * * @param session */ private void makemerequest(final session session) { // make api call user data , define // new callback handle response. request request = request.newmerequest(session, new request.graphusercallback() { @override public void oncompleted(graphuser user, response response) { // if response 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, 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 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"); } }
thanks in advance!
please try :
// remaining above code : else if (state.isclosed()) { textview_username.settext("請按登入鍵登入"); // should reset image of profilepictureview here! profilepictureview.setimagebitmap(null); } else { textview_username.settext("登入中..."); makemerequest(session); } }
or use below method:
public final void setdefaultprofilepicture(bitmap inputbitmap)
the profilepictureview display provided image while specified profile being loaded, or if specified profile not available. parameters inputbitmap bitmap render until actual profile loaded.
Comments
Post a Comment