Skip to content

Instantly share code, notes, and snippets.

@cliffgr
Created December 14, 2018 10:55
Show Gist options
  • Save cliffgr/1ab21b1ec25e6ca9d21736314b1aa236 to your computer and use it in GitHub Desktop.
Save cliffgr/1ab21b1ec25e6ca9d21736314b1aa236 to your computer and use it in GitHub Desktop.
asdasd
package wizzo.mbc.net.fragments;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import wizzo.mbc.net.R;
/**
* This dialog fragment allows user to select picture from Gallery
* or capture new picture using Camera app.
*/
public class AvatarDialogFragment extends DialogFragment {
private AvatarDialogListener listener;
public interface AvatarDialogListener {
void onCameraOptionClick(DialogFragment dialog);
void onGalleryOptionClick(DialogFragment dialog);
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
listener = (AvatarDialogListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString() + " must implement AvatarDialogListener");
}
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setIcon(android.R.drawable.ic_dialog_info);
builder.setTitle(getResources().getString(R.string.change_avatar));
builder.setCancelable(true); // Add this so as we can cancel this action
// TODO WE MUST ADD STH TO MAKE CANCELABLE THE DIALOG BECAUSE CURRENTLY THE DIALOG CANNOT CLOSE
// TODO THE USER MUST CAPTURE A PHOTO IN ORDER TO CLOSE THE DIALOG!!
// Should add something like that also: builder.setCanceledOnTouchOutside(true);
builder.setItems(R.array.change_avatar_options, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (getActivity() == null || isDetached()) {
return;
}
if (which == 0) {
listener.onCameraOptionClick(AvatarDialogFragment.this);
} else if (which == 1) {
listener.onGalleryOptionClick(AvatarDialogFragment.this);
}
}
});
return builder.create();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment