Example usage for android.app Dialog getWindow

List of usage examples for android.app Dialog getWindow

Introduction

In this page you can find the example usage for android.app Dialog getWindow.

Prototype

public @Nullable Window getWindow() 

Source Link

Document

Retrieve the current Window for the activity.

Usage

From source file:net.named_data.accessmanager.ScheduleCreateDialogFragment.java

@NonNull
@Override// w  ww  .j  av a  2 s.  c o m
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View view = inflater.inflate(R.layout.dialog_create_schedule, null);
    ListView listView = (ListView) view.findViewById(R.id.schedule_data_type);
    final DataTypeAdapter dataTypeAdapter = new DataTypeAdapter(getContext(), R.layout.data_type_list_item,
            Common.DATA_TYPES);
    listView.setAdapter(dataTypeAdapter);
    builder.setView(view).setPositiveButton(R.string.schedule_add_dialog_create_schedule,
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    try {
                        EditText scheduleNameView = (EditText) getDialog().findViewById(R.id.schedule_name);
                        String scheduleName = scheduleNameView.getText().toString();
                        EditText startDateView = (EditText) getDialog().findViewById(R.id.schedule_start_date);
                        String startDate = startDateView.getText().toString();
                        df.parse(startDate);
                        EditText endDateView = (EditText) getDialog().findViewById(R.id.schedule_end_date);
                        String endDate = endDateView.getText().toString();
                        df.parse(endDate);
                        EditText startHourView = (EditText) getDialog().findViewById(R.id.schedule_start_hour);
                        int startHour = Integer.parseInt(startHourView.getText().toString());
                        EditText endHourView = (EditText) getDialog().findViewById(R.id.schedule_end_hour);
                        int endHour = Integer.parseInt(endHourView.getText().toString());

                        if (startHour < 0 || startHour > 23 || endHour < 1 || endHour > 24
                                || startHour >= endHour || startDate.compareTo(endDate) >= 0
                                || scheduleName.trim().isEmpty()) {
                            Toast.makeText(getContext(), "Please correct the input", Toast.LENGTH_LONG).show();
                        } else {
                            ScheduleDetail scheduleDetail = new ScheduleDetail(scheduleName.trim(),
                                    Common.DATA_TYPE_PREFIXES[dataTypeAdapter.getselectedPosition()], startDate,
                                    endDate, startHour, endHour);
                            ((OnScheduleAddRequested) getTargetFragment()).addSchedule(scheduleDetail);
                        }
                    } catch (ParseException e) {
                        Toast.makeText(getContext(), "Please correct the input", Toast.LENGTH_LONG).show();
                    }
                }
            }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    ScheduleCreateDialogFragment.this.getDialog().cancel();
                }
            });
    Dialog scheduleCreateDialog = builder.create();
    scheduleCreateDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
    return scheduleCreateDialog;
}

From source file:com.codetroopers.betterpickers.timezonepicker.TimeZonePickerDialogFragment.java

@NonNull
@Override/*from  ww w  .  j  av a2  s.co  m*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Dialog dialog = super.onCreateDialog(savedInstanceState);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    return dialog;
}

From source file:nz.ac.otago.psyanlab.common.designer.util.EditDataColumnDialogueFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Bundle args = getArguments();/*from   ww  w  .  ja v  a 2 s .c  o  m*/
    mPosition = args.getInt(ARG_POSITION);
    mField = new Field();
    mField.id = args.getInt(ARG_FIELD_ID);
    mField.type = args.getInt(ARG_FIELD_TYPE);
    mField.name = args.getString(ARG_FIELD_NAME);
    mRequestCode = args.getInt(ARG_REQUEST_CODE);

    LayoutInflater inflater = getActivity().getLayoutInflater();
    View view = inflater.inflate(R.layout.dialogue_edit_channel_field, null);

    mViews = new ViewHolder(view);
    mViews.setViewValues(getActivity(), mField);

    // Build dialogue.
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(R.string.title_edit_channel_field).setView(view);
    if (mPosition == POSITION_UNASSIGNED) {
        builder.setPositiveButton(R.string.action_create, mPositiveListener)
                .setNegativeButton(R.string.action_discard, mNegativeListener);
    } else {
        builder.setPositiveButton(R.string.action_done, mPositiveListener)
                .setNegativeButton(R.string.action_cancel, mNegativeListener)
                .setNeutralButton(R.string.action_delete, mDeleteListener);
    }

    // Create the AlertDialog object and return it
    Dialog dialog = builder.create();
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    return dialog;
}

From source file:com.loloof64.android.chess_position_manager.file_explorer.file_clipboard.ExistingFileDialogFragment.java

@NonNull
@Override/*from  w  w  w  .  j  a v  a2 s.  c  om*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    LayoutInflater inflater = getActivity().getLayoutInflater();
    final View view = inflater.inflate(R.layout.existing_file_dialog_layout, null);
    final EditText userValueComp = (EditText) view.findViewById(R.id.existing_file_user_value);
    final Button purposeNameButton = (Button) view.findViewById(R.id.existing_file_purpose_button);
    final Button validateButton = (Button) view.findViewById(R.id.existing_file_validate_button);
    final TextView mainLabel = (TextView) view.findViewById(R.id.existing_file_label);

    purposeNameButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            purposeName();
            userValueComp.setText(currentPurpose);
        }
    });

    validateButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String purposedName = userValueComp.getText().toString();
            String realFileName = fileName + EPDData.POSITION_FILE_EXTENSION;
            boolean hasContent = purposedName.length() > 0;
            boolean nameIsDifferent = !fileName.equals(purposedName);
            if (hasContent) {
                if (nameIsDifferent) {
                    if (listener != null)
                        listener.onExitingFileDialogPositiveClick(realFileName);
                    getDialog().cancel();
                } else {
                    String message = String.format(getResources().getString(R.string.error_still_same_filename),
                            purposedName);
                    Toast.makeText(getActivity(), message, Toast.LENGTH_SHORT).show();
                }
            } else {
                Toast.makeText(getActivity(), R.string.error_no_name_entered, Toast.LENGTH_SHORT).show();
            }
        }
    });

    Bundle arguments = getArguments();
    if (arguments != null) {
        fileName = arguments.getString(FILE_NAME_TAG);
        if (fileName.endsWith(EPDData.POSITION_FILE_EXTENSION)) {
            int length = fileName.length();
            fileName = fileName.substring(0, length - 4);
        }
    }

    mainLabel.setText(String.format(getResources().getString(R.string.file_already_exists),
            fileName + EPDData.POSITION_FILE_EXTENSION));

    builder.setTitle(R.string.title_file_already_exists).setView(view);

    Dialog dialog = builder.create();
    // Very important for the edit view.
    dialog.getWindow().clearFlags(
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
    return dialog;
}

From source file:io.github.jhcpokemon.expressassist.fragment.SettingFragment.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.clear:
        SharedPreferences sharedPreferences = getContext().getSharedPreferences("user_msg",
                Context.MODE_APPEND);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("email", "");
        editor.putString("password", "");
        editor.putBoolean("save", false);
        editor.putBoolean("auto", false);
        editor.apply();/*from w w w  .  ja v  a 2s  . c o m*/
        ExpressLog.deleteAll(ExpressLog.class);
        getActivity().finishAffinity();
        break;
    case R.id.version:
        if (count == 0) {
            Dialog imageDialog = new Dialog(getContext());
            ViewGroup.LayoutParams params = imageDialog.getWindow().getAttributes();
            params.width = WindowManager.LayoutParams.MATCH_PARENT;
            params.height = WindowManager.LayoutParams.MATCH_PARENT;
            imageDialog.getWindow().setAttributes((WindowManager.LayoutParams) params);
            imageDialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
            imageDialog.setContentView(R.layout.image_dialog);
            imageDialog.setCancelable(true);
            imageDialog.show();
            versionBtn.setClickable(false);
        } else {
            count--;
        }
        break;
    case R.id.policy:
        Dialog policyDialog = new Dialog(getContext()) {
            @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setTitle(R.string.policy);
                View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_policy, null, false);
                TextView policyTextView = (TextView) view.findViewById(R.id.policy);
                policyTextView.setText(policy);
                setContentView(view);
                setCancelable(true);
                ViewGroup.LayoutParams params = getWindow().getAttributes();
                params.width = WindowManager.LayoutParams.MATCH_PARENT;
                getWindow().setAttributes((WindowManager.LayoutParams) params);
            }
        };

        policyDialog.show();
        break;
    default:
        break;
    }
}

From source file:nz.ac.otago.psyanlab.common.designer.util.NumberPickerDialogueFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    LayoutInflater inflater = getActivity().getLayoutInflater();

    int min = 0;/* w  ww. jav  a  2  s .  c  o m*/
    int defaultValue = 0;
    int max = Integer.MAX_VALUE;
    int title = R.string.title_pick_number;
    boolean canBeInfinite = false;

    Bundle args = getArguments();
    if (args == null) {
        throw new RuntimeException("Expect arguments for number picker dialogue.");
    }
    defaultValue = args.getInt(ARG_DEFAULT_VALUE, 0);
    min = args.getInt(ARG_MIN, 0);
    max = args.getInt(ARG_MAX, Integer.MAX_VALUE);
    title = args.getInt(ARG_TITLE, R.string.title_pick_number);
    mRequestCode = args.getInt(ARG_REQUEST_CODE);
    canBeInfinite = args.getBoolean(ARG_INFINITE);

    View view = inflater.inflate(R.layout.dialogue_number_picker, null);
    mViews = new ViewHolder(view);
    mViews.initViews(min, max);
    mViews.setViewValues(defaultValue);

    // Build dialogue.
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(title).setView(view).setPositiveButton(R.string.action_confirm, mPositiveListener)
            .setNegativeButton(R.string.action_discard, mNegativeListener);

    if (canBeInfinite) {
        builder.setNeutralButton("Infinite", mNeutralListener);
    }

    // Create the AlertDialog object and return it
    Dialog dialog = builder.create();
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    return dialog;
}

From source file:ch.gianulli.trelloapi.ui.AuthenticationDialogFragment.java

@Override
public void onStart() {
    super.onStart();

    Dialog dialog = getDialog();
    if (dialog != null) {
        dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    }//  www . j a va 2  s.  c o m
}

From source file:cn.stj.fphealth.views.dialog.DeviceBindDialog.java

/**
 * Set the dialog edit text and other attribute
 *///from w ww.  j a v a 2s  . com
@Override
public void onResume() {
    super.onResume();

    Dialog dialog = getDialog();
    dialog.setCanceledOnTouchOutside(false);
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE
            | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
    dialog.setOnKeyListener(new SaveDialogKeyListener());
}

From source file:net.named_data.accessmanager.MemberCrateDialogFragment.java

@NonNull
@Override//from ww  w .j a va  2 s .  c  o  m
public Dialog onCreateDialog(@Nullable final Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View view = inflater.inflate(R.layout.dialog_create_member, null);
    ListView predefinedMemberListView = (ListView) view.findViewById(R.id.member_predefined_members);
    final PredefinedMemberAdapter predefinedMemberTypeAdapter = new PredefinedMemberAdapter(getContext(),
            R.layout.predefined_entity_list_item, Common.PREDEFINED_ENTITY_NAMES);
    predefinedMemberListView.setAdapter(predefinedMemberTypeAdapter);
    ListView existingScheduleListView = (ListView) view.findViewById(R.id.member_existing_schedules);
    final String[] allScheduleNames = DataBase.getInstance(getContext()).getAllScheduleNames();
    final ExistingScheduleAdapter existingScheduleAdapter = new ExistingScheduleAdapter(getContext(),
            R.layout.existing_schedule_list_item, allScheduleNames);
    existingScheduleListView.setAdapter(existingScheduleAdapter);
    builder.setView(view)
            .setPositiveButton(R.string.member_add_dialog_create_member, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    int memberPosition = predefinedMemberTypeAdapter.getselectedPosition();
                    Set<Integer> scheduleSet = existingScheduleAdapter.getSelectedPositions();
                    if (scheduleSet == null || scheduleSet.isEmpty()) {
                        Toast.makeText(getContext(), "Please correct the input", Toast.LENGTH_LONG).show();
                    } else {
                        String memberName = Common.PREDEFINED_ENTITY_NAMES[memberPosition];
                        EntityInfo entityInfo = Common.PREDEFINED_ENTITY_NAME_MAP.get(memberName);
                        List<String> scheduleList = new ArrayList<>();
                        for (int onePosition : scheduleSet) {
                            scheduleList.add(allScheduleNames[onePosition]);
                        }
                        MembershipDetail membershipDetail = new MembershipDetail(entityInfo, scheduleList);
                        ((OnMemberAddRequested) getTargetFragment()).addMember(membershipDetail);
                    }
                }
            }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    MemberCrateDialogFragment.this.getDialog().cancel();
                }
            });
    Dialog scheduleCreateDialog = builder.create();
    scheduleCreateDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
    return scheduleCreateDialog;
}

From source file:nz.ac.otago.psyanlab.common.designer.util.EditStringDialogueFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    LayoutInflater inflater = getActivity().getLayoutInflater();

    String defaultValue;/*from  w w w  .  j  av a  2  s  . com*/
    int hintResId;
    int layoutResId;
    int titleResId;
    boolean deleteEnabled;

    Bundle args = getArguments();
    if (args != null) {
        defaultValue = args.getString(ARG_DEFAULT_VALUE, "");
        hintResId = args.getInt(ARG_HINT, NO_HINT);
        titleResId = args.getInt(ARG_TITLE, R.string.title_edit_string);
        layoutResId = args.getInt(ARG_LAYOUT, R.layout.dialogue_edit_string);
        deleteEnabled = args.getBoolean(ARG_DELETE_ENABLED, false);
        if (args.containsKey(ARG_REQUEST_CODE)) {
            mRequestCode = args.getInt(ARG_REQUEST_CODE);
        } else {
            throw new RuntimeException("Dialogue not properly initialised. Missing request code.");
        }
    } else {
        throw new RuntimeException("Dialogue not properly initialised.");
    }

    View view = inflater.inflate(layoutResId, null);
    mViews = new ViewHolder(view);
    mViews.initViews(hintResId);
    mViews.setViewValues(defaultValue);

    // Build dialogue.
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(titleResId).setView(view).setPositiveButton(R.string.action_confirm, mPositiveListener)
            .setNegativeButton(R.string.action_discard, mNegativeListener);

    if (deleteEnabled) {
        builder.setNeutralButton(R.string.action_delete, mDeleteListener);
    }

    // Create the AlertDialog object and return it
    Dialog dialog = builder.create();
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    return dialog;
}