DialogBase.java 1.21 KB
package com.dinhcv.lifelogpedometer.activity;

import android.content.Context;
import android.support.v7.app.AppCompatDialog;
import android.view.Gravity;
import android.view.WindowManager;
import android.widget.TextView;

import com.dinhcv.lifelogpedometer.utils.Debug;


public class DialogBase extends AppCompatDialog {

    public DialogBase(Context context) {
        super(context);
    }

    public DialogBase(Context context, int style) {
        super(context, style);
    }

    @Override
    protected void onStart() {
        super.onStart();
        // In order to not be too narrow, set the window size based on the screen resolution:
        final int screenWidth    = getContext().getResources().getDisplayMetrics().widthPixels;
        final int newScreenWidth = screenWidth * 100 / 100;
        WindowManager.LayoutParams layout = getWindow().getAttributes();
        layout.width = Math.max(layout.width, newScreenWidth );

        TextView textView = (TextView) findViewById(android.R.id.title);

        if(textView != null) {
            Debug.normal("Set title dialog ----------------------------------");
            textView.setSingleLine(false);
            textView.setGravity(Gravity.CENTER);
        }
    }
}