public class SettingsActivity extends Activity implements OnClickListener ,IServerResponse {
private RelativeLayout _myprofileRelativeLayout=null;
private RelativeLayout _profilepicRelativeLayout=null;
private RelativeLayout _coverpicRelativeLayout=null;
private RelativeLayout _passwordRelativeLayout=null;
private RelativeLayout _picilikedRelativeLayout=null;
private ToggleButton _mypicsToggleButton=null;
private Button _backButton=null;
private String _email=null;
private String _password=null;
private String _name=null;
private RelativeLayout _sendinviteRelativeLayout=null;
private RelativeLayout _findfriendsRelativeLayout=null;
private RelativeLayout _searchtagsRelativeLayout=null;
private RadioButton _maleRadioButton=null;
private RadioButton _femaleRadioButton=null;
private RadioButton _bothRadioButton=null;
private RadioButton _userRadioButton=null;
private RadioButton _brandRadioButton=null;
private RadioButton _retailerRadioButton=null;
private RelativeLayout _sharesettingRelativeLayout=null;
private RelativeLayout _notificationRelativeLayout=null;
private RelativeLayout _supportRelativeLayout=null;
private RelativeLayout _logoutRelativeLayout=null;
private RelativeLayout _aboutRelativeLayout=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
_myprofileRelativeLayout=(RelativeLayout)findViewById(R.id.myprofile_layout);
_profilepicRelativeLayout=(RelativeLayout)findViewById(R.id.profilepic_layout);
_coverpicRelativeLayout=(RelativeLayout)findViewById(R.id.coverpic_layout);
_passwordRelativeLayout=(RelativeLayout)findViewById(R.id.password_layout);
_picilikedRelativeLayout=(RelativeLayout)findViewById(R.id.picliked_layout);
_mypicsToggleButton=(ToggleButton)findViewById(R.id.mypic_toggleButton);
_sendinviteRelativeLayout=(RelativeLayout)findViewById(R.id.sendinvite_layout);
_findfriendsRelativeLayout=(RelativeLayout)findViewById(R.id.findfriends_layout);
_searchtagsRelativeLayout=(RelativeLayout)findViewById(R.id.searchtag_layout);
_maleRadioButton=(RadioButton)findViewById(R.id.male_checkbox);
_femaleRadioButton=(RadioButton)findViewById(R.id.female_checkbox);
_bothRadioButton=(RadioButton)findViewById(R.id.both_checkbox);
_userRadioButton=(RadioButton)findViewById(R.id.user_checkbox);
_brandRadioButton=(RadioButton)findViewById(R.id.brand_checkbox);
_retailerRadioButton=(RadioButton)findViewById(R.id.retailer_checkbox);
_sharesettingRelativeLayout=(RelativeLayout)findViewById(R.id.sharesetting_layout);
_notificationRelativeLayout=(RelativeLayout)findViewById(R.id.notisetting_layout);
_supportRelativeLayout=(RelativeLayout)findViewById(R.id.supportsetting_layout);
_aboutRelativeLayout=(RelativeLayout)findViewById(R.id.aboutsetting_layout);
_logoutRelativeLayout=(RelativeLayout)findViewById(R.id.logoutsetting_layout);
_backButton=(Button)findViewById(R.id.back_btn);
_myprofileRelativeLayout.setOnClickListener(this);
_profilepicRelativeLayout.setOnClickListener(this);
_coverpicRelativeLayout.setOnClickListener(this);
_passwordRelativeLayout.setOnClickListener(this);
_picilikedRelativeLayout.setOnClickListener(this);
_sendinviteRelativeLayout.setOnClickListener(this);
_findfriendsRelativeLayout.setOnClickListener(this);
_searchtagsRelativeLayout.setOnClickListener(this);
_sharesettingRelativeLayout.setOnClickListener(this);
_notificationRelativeLayout.setOnClickListener(this);
_supportRelativeLayout.setOnClickListener(this);
_aboutRelativeLayout.setOnClickListener(this);
_logoutRelativeLayout.setOnClickListener(this);
_backButton.setOnClickListener(this);
}
@Override
public void onClick(View v) {
TabGroupActivity parentActivity=(TabGroupActivity)getParent();
Intent intent =null;
switch (v.getId()) {
case R.id.back_btn:
this.finish();
break;
case R.id.myprofile_layout:
intent = new Intent(getApplicationContext(),EditProfileActivity.class);
parentActivity.startChildActivity("editprofile", intent);
break;
case R.id.password_layout:
intent=new Intent(this, ChangePasswordActivity.class);
parentActivity.startChildActivity("changepassword", intent);
break;
case R.id.profilepic_layout:
chooseImageDialog("", "Choose profile pic ?", this.getParent(), false);
break;
case R.id.coverpic_layout:
chooseImageDialog("", "Choose profile pic ?", this.getParent(), false);
break;
case R.id.picliked_layout:
intent=new Intent(this, PicsILikedActivity.class);
parentActivity.startChildActivity("pics", intent);
break;
case R.id.sendinvite_layout:
break;
case R.id.findfriends_layout:
intent= new Intent(getApplicationContext(),FindFriendsActivity.class);
parentActivity.startChildActivity("findfriends", intent);
break;
case R.id.searchtag_layout:
break;
case R.id.sharesetting_layout:
intent= new Intent(getApplicationContext(),ShareSettingSocialActivity.class);
parentActivity.startChildActivity("sharesettings", intent);
break;
case R.id.notisetting_layout:
intent = new Intent(getApplicationContext(),NotificationActivity.class);
parentActivity.startChildActivity("notif", intent);
break;
case R.id.supportsetting_layout:
break;
case R.id.aboutsetting_layout:
break;
case R.id.logoutsetting_layout:
TabGroupActivity tabgroupactivity = (TabGroupActivity) getParent();
tabgroupactivity.finish();
intent=new Intent(this, LoginScreenActivity.class);
startActivity(intent);
break;
default:
break;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case 1:
if (resultCode == RESULT_OK)
{
Uri chosenImageUri = data.getData();
String imagepath= getpath(chosenImageUri);
Bitmap bitmap = BitmapFactory.decodeFile(imagepath);
getprofilepic();
Constant._profilePicBase64=Constant.convertBitmapToBase64(bitmap);
}else{
Toast.makeText(SettingsActivity.this, "Unable to get Image", Toast.LENGTH_SHORT).show();
}
break;
case 2:
if (resultCode == RESULT_OK)
{
try{
Bitmap bitmap = (Bitmap) data.getExtras().get("data");
Constant._profilePicBase64=Constant.convertBitmapToBase64(bitmap);
}catch (OutOfMemoryError e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}else{
Toast.makeText(SettingsActivity.this, "Unable to get Image", Toast.LENGTH_SHORT).show();
}
break;
}
}
private void getprofilepic() {
if (NetworkAvailablity.checkNetworkStatus(SettingsActivity.this)) {
ArrayList<NameValuePair> requestParaList = new ArrayList<NameValuePair>();
requestParaList.add(new BasicNameValuePair("user_id",Constant.USER_ID));
requestParaList.add(new BasicNameValuePair("photo",Constant._profilePicBase64));
// CALL WEBSERVICE
WebServiceCommunicator.getInstance().registerForServerResponse(
(IServerResponse) SettingsActivity.this);
WebServiceCommunicator.getInstance().callGetAppWebService(false,
this, WSConstant.getUrl(WSConstant.METHOD_CHANGE_PROFILE_PHOTO),
SettingsActivity.this, WSConstant.PID_CHANGE_PROFILE_PHOTO, false,
requestParaList);
}
}
private String getpath(Uri chosenImageUri) {
String[] projection={MediaStore.Images.Media.DATA};
Cursor cursor=managedQuery(chosenImageUri, projection,null,null,null);
int column=cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column);
}
public void chooseImageDialog(final String title, String message,
final Context context, final boolean redirectToPreviousScreen) {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
alertDialog.setTitle(title);
alertDialog.setMessage(message);
alertDialog.setPositiveButton("Gallery", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which) {
Intent intent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(intent, 1);
}
});
alertDialog.setNegativeButton("Camera", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent intentfile = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(intentfile, 2);
dialog.dismiss();
}
});
alertDialog.show();
}
@Override
protected void onResume() {
super.onResume();
if(Constant.choosePhotoBitmap!=null){
runOnUiThread(new Runnable() {
public void run() {
}
});
}
}
@Override
public void serverResponse(String response, int processid) {
// TODO Auto-generated method stub
Message msg = new Message();
msg.obj = response;
msg.arg1 = processid;
_handler.sendMessage(msg);
}
private Handler _handler = new Handler(){
public void handleMessage(Message msg) {
switch (msg.arg1) {
case WSConstant.PID_CHANGE_PROFILE_PHOTO:
getJsonResponse(msg.obj.toString());
break;
default:
break;
}
}
private void getJsonResponse(String response) {
JSONObject json=null;
try {
json = new JSONObject(response);
JSONArray jsonArray = json.getJSONArray("posts");
for(int i=0;i<jsonArray.length();i++){
JSONObject jsonObject =jsonArray.optJSONObject(i);
String message= jsonObject.getString("status");
if(message.equalsIgnoreCase("YES"))
{
runOnUiThread(new Runnable() {
@Override
public void run() {
Constant.showAlertDialog("status","YES",SettingsActivity.this.getParent(),false);
Intent intent = new Intent(SettingsActivity.this, ProfileScreenActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
});
}
else if (message.equalsIgnoreCase("NO")) {
Constant.showAlertDialog("status","NO",SettingsActivity.this.getParent(),false);
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
};
}
我正在使用webservice来更改我的个人资料图片,我已经使用了tabactivity with onactivityresult。,但问题是数据没有进入onactivity结果。,当我调试我的代码。,我做什么。,请帮助我