Skip to content

Instantly share code, notes, and snippets.

@gvr23
Last active July 31, 2018 07:17
Show Gist options
  • Save gvr23/7c37138a134f31a36e426d5637d27ece to your computer and use it in GitHub Desktop.
Save gvr23/7c37138a134f31a36e426d5637d27ece to your computer and use it in GitHub Desktop.
Create a Dialog Fragment Full Screen
ANDROID
THIS IS THE ACTIVITY CLASS
=============================================================================================================================
public class AyudaEntelDialog extends android.support.v4.app.DialogFragment{
private ImageView ivExit;
private VideoView vvTutorial;
private View rootView;
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
return dialog;
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.dialog_ayuda_dialog, container, false);
findViewsByIds();
preCargar();
eventos();
return rootView;
}
private void findViewsByIds() {
ivExit = rootView.findViewById(R.id.ivExit);
vvTutorial = rootView.findViewById(R.id.vvTutorial);
}
private void preCargar() {
playTutorial();
Drawable myIcon = getResources().getDrawable(R.drawable.letter_x);
ColorFilter filter = new LightingColorFilter( getResources().getColor(R.color.colorOrange), getResources().getColor(R.color.colorOrange));
myIcon.setColorFilter(filter);
ivExit.setImageDrawable(myIcon);
}
private void eventos() {
vvTutorial.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
dismiss();
}
});
ivExit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
}
@Override
public void onResume() {
super.onResume();
Window window = getDialog().getWindow();
WindowManager.LayoutParams layoutParams = getDialog().getWindow().getAttributes();
layoutParams.dimAmount = 0;
window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
window.setGravity(Gravity.CENTER);
getDialog().getWindow().setAttributes(layoutParams);
}
private void playTutorial(){
try{
vvTutorial.setVideoPath(Constantes.VIDEO_TUTORIAL);
vvTutorial.start();
vvTutorial.setOnErrorListener(new MediaPlayer.OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
mp.stop();
dismiss();
return true;
}
});
}catch(Exception e){
e.printStackTrace();
Toast.makeText(getContext() ,"No se cargo el video", Toast.LENGTH_SHORT).show();
}
}
}
THIS IS THE LAYOUT OF THE DIALOG
=============================================================================================================================
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="com.dsbmobile.entel.autoasistido.view.dialog.AyudaEntelDialog">
<VideoView
android:id="@+id/vvTutorial"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<ImageView
android:id="@+id/ivExit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:padding="24dp"/>
</FrameLayout>
METHOD THAT EXECUTES IT
===============================================================================================================================
private void mostrarDialog(String titulo, String mensaje, int tipoDialog){
MensajeErrorDialog mensajeErrorDialog = MensajeErrorDialog.newInstance(titulo, mensaje, tipoDialog);
mensajeErrorDialog.show(getSupportFragmentManager(), "mensajeDialog");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment