Skip to content

Commit

Permalink
Re add measureLayout for dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
J-Jamet committed Feb 1, 2019
1 parent a49b142 commit 8f89adf
Showing 1 changed file with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AlertDialog;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;

import com.kunzisoft.androidclearchroma.colormode.ColorMode;
import com.kunzisoft.androidclearchroma.fragment.ChromaColorFragment;
Expand Down Expand Up @@ -174,7 +176,38 @@ public void onClick(DialogInterface dialog, int which) {

alertDialogBuilder.setView(rootView);

return alertDialogBuilder.create();
Dialog dialog = alertDialogBuilder.create();
// request a window without the title
if (dialog.getWindow() != null) {
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
}

dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
measureLayout((Dialog) dialog);
}
});

return dialog;
}

/**
* Set new dimensions to dialog
* @param ad dialog
*/
private void measureLayout(Dialog ad) {
TypedValue typedValue = new TypedValue();
getResources().getValue(R.dimen.chroma_dialog_height_multiplier, typedValue, true);
float heightMultiplier = typedValue.getFloat();
int height = (int) ((ad.getContext().getResources().getDisplayMetrics().heightPixels) * heightMultiplier);

getResources().getValue(R.dimen.chroma_dialog_width_multiplier, typedValue, true);
float widthMultiplier = typedValue.getFloat();
int width = (int) ((ad.getContext().getResources().getDisplayMetrics().widthPixels) * widthMultiplier);

if (ad.getWindow() != null)
ad.getWindow().setLayout(width, height);
}

@Nullable
Expand Down

0 comments on commit 8f89adf

Please sign in to comment.