Example usage for android.app AlertDialog.Builder create

List of usage examples for android.app AlertDialog.Builder create

Introduction

In this page you can find the example usage for android.app AlertDialog.Builder create.

Prototype

public void create() 

Source Link

Document

Forces immediate creation of the dialog.

Usage

From source file:com.njlabs.amrita.aid.info.Calender.java

@Override
public void init(Bundle savedInstanceState) {
    setupLayout(R.layout.activity_calender, Color.parseColor("#fe5352"));

    final Calender thisContext = this;

    descriptions = new HashMap<>();
    backgroundColors = new HashMap<>();
    textColors = new HashMap<>();

    SharedPreferences preferences = getSharedPreferences("app_extra", Context.MODE_PRIVATE);
    Boolean AgreeStatus = preferences.getBoolean("calender_agree", false);

    if (!AgreeStatus) {
        AlertDialog.Builder builder = new AlertDialog.Builder(thisContext);
        builder.setTitle("Academic Calender").setIcon(R.drawable.ic_action_info_small).setMessage(
                "Red denotes that it's an Exam day. Blue denotes an event (not a Holiday). Whereas Green denotes a Holiday. I'm not resposibile for the accuracy of the dates")
                .setCancelable(false).setPositiveButton("I Agree", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        SharedPreferences preferences = getSharedPreferences("app_extra", Context.MODE_PRIVATE);
                        SharedPreferences.Editor editor = preferences.edit();
                        editor.putBoolean("calender_agree", true);
                        editor.apply();//from ww w  . j a v  a 2s  .co  m
                    }
                });
        AlertDialog alert = builder.create();
        alert.show();
    }

    caldroidFragment = new CaldroidFragment();

    if (savedInstanceState != null) {
        caldroidFragment.restoreStatesFromKey(savedInstanceState, "CALDROID_SAVED_STATE");
    } else {
        Bundle args = new Bundle();
        Calendar cal = Calendar.getInstance();
        args.putInt(CaldroidFragment.MONTH, cal.get(Calendar.MONTH) + 1);
        args.putInt(CaldroidFragment.YEAR, cal.get(Calendar.YEAR));
        args.putBoolean(CaldroidFragment.ENABLE_SWIPE, true);
        caldroidFragment.setArguments(args);
    }

    setCustomResourceForDates();

    FragmentTransaction t = getSupportFragmentManager().beginTransaction();
    t.replace(R.id.calendar, caldroidFragment);
    t.commit();

    final CaldroidListener listener = new CaldroidListener() {
        @Override
        public void onSelectDate(Date date, View view) {
            if (!formatter.format(date).equals("")) {
                String description = descriptions.get(formatter.format(date));
                if (description != null && !description.equals("")) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(thisContext);
                    builder.setMessage(description).setCancelable(true).setPositiveButton("Close",
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int id) {
                                    dialog.cancel();
                                }
                            });
                    AlertDialog alert = builder.create();
                    alert.show();
                }
            }
        }
    };
    caldroidFragment.setCaldroidListener(listener);
}

From source file:com.nokia.example.capturetheflag.Controller.java

private void showEnableGPSDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setMessage(getResources().getText(R.string.gps_not_enabled));

    builder.setPositiveButton(getResources().getText(R.string.action_settings), new OnClickListener() {
        @Override/*  www.j a va 2  s.co m*/
        public void onClick(DialogInterface dialog, int which) {
            Intent i = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            getActivity().startActivity(i);
        }
    });

    builder.setNegativeButton(getResources().getText(R.string.cancel), new OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    builder.create().show();
}

From source file:com.njlabs.amrita.aid.landing.Landing.java

private void setupGrid() {

    GridView gridView = (GridView) findViewById(R.id.landing_grid);
    gridView.setAdapter(new LandingAdapter(baseContext));
    gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override/*from www  . j  av a 2 s.com*/
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            String name = ((TextView) view.getTag(R.id.landing_text)).getText().toString();
            switch (name) {
            case "About Amrita":
                // ABOUT AMRITA
                startActivity(new Intent(baseContext, Amrita.class));
                break;
            case "Announcements":
                Snackbar.make(parentView, "Announcements is under construction", Snackbar.LENGTH_SHORT).show();
                break;
            case "Academic Calender":
                // ACADEMIC CALENDER
                startActivity(new Intent(baseContext, Calender.class));
                break;
            case "Amrita UMS Login":
                // AUMS
                startActivity(new Intent(baseContext, AumsActivity.class));
                break;
            case "Train & Bus Timings":
                // TRAIN & BUS INFO
                final CharSequence[] transportationOptions = { "Trains from Coimbatore", "Trains from Palghat",
                        "Trains to Coimbatore", "Trains to Palghat", "Buses from Coimbatore",
                        "Buses to Coimbatore" };
                AlertDialog.Builder transportationDialogBuilder = new AlertDialog.Builder(baseContext);
                transportationDialogBuilder.setTitle("View timings of ?");
                transportationDialogBuilder.setItems(transportationOptions,
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int item) {
                                // Showing Alert Message
                                Intent trainBusOpen = new Intent(baseContext, TrainBusInfo.class);
                                trainBusOpen.putExtra("type", transportationOptions[item]);
                                startActivity(trainBusOpen);
                            }
                        });
                AlertDialog transportationDialog = transportationDialogBuilder.create();
                transportationDialog.show();
                break;

            case "GPMS Login":
                // GPMS LOGIN
                startActivity(new Intent(baseContext, GpmsActivity.class));
                break;
            case "Curriculum Info":
                // CURRICULUM INFO
                final CharSequence[] items_c = { "Aerospace Engineering", "Civil Engineering",
                        "Chemical Engineering", "Computer Science Engineering",
                        "Electrical & Electronics Engineering", "Electronics & Communication Engineering",
                        "Electronics & Instrumentation Engineering", "Mechanical Engineering" };
                AlertDialog.Builder departmentDialogBuilder = new AlertDialog.Builder(baseContext);
                departmentDialogBuilder.setTitle("Select your Department");
                departmentDialogBuilder.setItems(items_c, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int item) {
                        // Showing Alert Message
                        Intent curriculum_open = new Intent(baseContext, Curriculum.class);
                        curriculum_open.putExtra("department", items_c[item]);
                        startActivity(curriculum_open);
                    }
                });
                AlertDialog departmentDialog = departmentDialogBuilder.create();
                departmentDialog.show();
                break;

            case "News":
                // NEWS
                startActivity(new Intent(baseContext, NewsActivity.class));
                break;
            default:
                Toast.makeText(baseContext, String.valueOf(i), Toast.LENGTH_SHORT).show();
            }
        }
    });
}

From source file:com.jeremyhaberman.playgrounds.Playgrounds.java

/**
 * Display an error about failing to load playground data. Called by
 * displayErrorTask/*from   w w  w  . jav a  2s  .co m*/
 */
protected void displayLocationError() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    // builder.setTitle("ERROR");

    builder.setMessage(getString(R.string.unable_to_get_current_location));
    builder.setCancelable(false);
    builder.setPositiveButton("Try Again", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            alertDialog.dismiss();
            mHandler.post(showPlaygrounds);
        }
    });
    builder.setNegativeButton("Close", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            alertDialog.dismiss();
        }
    });
    alertDialog = builder.create();
    alertDialog.show();
    mHandler.sendEmptyMessage(0);
}

From source file:de.dmxcontrol.fragment.ActionSelectorFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log.d(TAG, "onCreateView");

    LinearLayout actionButtons = (LinearLayout) inflater.inflate(R.layout.action_selector_fragment, container,
            false);/* www .  j  a v a2  s .c o  m*/

    ViewGroup vg = (ViewGroup) actionButtons.findViewById(R.id.action_selector_scroll);
    scrollView = vg;

    bDeviceAction = (Button) actionButtons.findViewById(R.id.button_device_action);
    bDeviceAction.setOnClickListener(this);
    bDeviceAction.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            try {
                AlertDialog.Builder alert = new AlertDialog.Builder(v.getContext());
                alert.setTitle("Parameter");
                final DeviceManagerDialog view = new DeviceManagerDialog(alert.getContext());
                alert.setView(view);
                alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        try {
                            ServiceFrontend.get().sendMessage(view.GetDeviceMetadata().getBytes());
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                });
                AlertDialog alertDialog = alert.create();
                alertDialog.show();
                return true;
            } catch (Exception e) {
                return false;
            }
        }
    });

    bColorAction = (Button) actionButtons.findViewById(R.id.button_color_action);
    bColorAction.setOnClickListener(this);

    bIntensityAction = (Button) actionButtons.findViewById(R.id.button_intensity_action);
    bIntensityAction.setOnClickListener(this);

    bPanTiltAction = (Button) actionButtons.findViewById(R.id.button_pantilt_action);
    bPanTiltAction.setOnClickListener(this);

    bGoboAction = (Button) actionButtons.findViewById(R.id.button_gobo_action);
    bGoboAction.setOnClickListener(this);

    bOpticAction = (Button) actionButtons.findViewById(R.id.button_optic_action);
    bOpticAction.setOnClickListener(this);

    bPrismAction = (Button) actionButtons.findViewById(R.id.button_prism_action);
    bPrismAction.setOnClickListener(this);
    //bOpticAction.setVisibility(View.INVISIBLE);
    //actionButtons.removeView(bOpticAction);

    bRawAction = (Button) actionButtons.findViewById(R.id.button_raw_action);
    bRawAction.setOnClickListener(this);
    //bRawAction.setVisibility(View.INVISIBLE);
    //actionButtons.removeView(bRawAction);

    bEffectAction = (Button) actionButtons.findViewById(R.id.button_effect_action);
    bEffectAction.setOnClickListener(this);
    //bEffectAction.setVisibility(View.INVISIBLE);
    //actionButtons.removeView(bEffectAction);

    bPresetAction = (Button) actionButtons.findViewById(R.id.button_preset_action);
    bPresetAction.setOnClickListener(this);

    bProgrammerAction = (Button) actionButtons.findViewById(R.id.button_programmer_action);
    bProgrammerAction.setOnClickListener(this);

    updateStateSelected();
    return actionButtons;
}

From source file:com.lovejoy777sarootool.rootool.dialogs.FilePropertiesDialog.java

@Override
public Dialog onCreateDialog(Bundle state) {
    activity = getActivity();//from w  w w. ja  va2s  . c om
    final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    mAdapter = new PropertiesAdapter(activity, mFile);
    builder.setTitle(mFile.getName());
    builder.setNeutralButton(R.string.cancel, null);
    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            final FilePermissionsPagerItem fragment = (FilePermissionsPagerItem) mAdapter.getItem(1);
            fragment.applyPermissions(activity);
        }
    });
    final View content = activity.getLayoutInflater().inflate(R.layout.dialog_properties_container, null);
    this.initView(content);
    builder.setView(content);
    return builder.create();
}

From source file:com.wirelessmoves.cl.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
    case RESET_COUNTER:

        NumberOfCellChanges = 0;//from  w  w  w. j  av a  2 s  . c  o m
        NumberOfLacChanges = 0;
        NumberOfSignalStrengthUpdates = 0;

        NumberOfUniqueCellChanges = 0;

        /* Initialize PreviousCells Array to a defined value */
        for (int x = 0; x < PreviousCells.length; x++)
            PreviousCells[x] = 0;

        return true;

    case ABOUT:
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(
                "Cell Logger\r\n2012, Martin Sauter\r\n2014, rong zedong.\r\nhttp://www.wirelessmoves.com")
                .setCancelable(false).setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });

        AlertDialog alert = builder.create();
        alert.show();

        return true;

    case TOGGLE_DEBUG:
        /* Toggle the debug behavior of the program when the user selects this menu item */
        if (outputDebugInfo == false) {
            outputDebugInfo = true;
        } else {
            outputDebugInfo = false;
        }

        return true;

    default:
        return super.onOptionsItemSelected(item);

    }
}

From source file:com.dragon4.owo.ar_trace.ARCore.MixState.java

public void DialogSelectOption(final MixContext ctx, final String markerTitle, final PhysicalPlace log,
        final String onPress) {
    final String items[] = { "?  ", "?" };
    AlertDialog.Builder ab = new AlertDialog.Builder(ctx);
    ab.setTitle(markerTitle);/*from www  . j  a  v  a  2  s .c o m*/
    ab.setItems(items, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            // ? 
            Toast.makeText(ctx, items[id] + " ?.", Toast.LENGTH_SHORT).show();
            dialog.dismiss();

            if (id == 0) {
                try {
                    ctx.loadMixViewWebPage(onPress);
                } catch (Exception e) {
                }
            } else if (id == 1) {
                Navigator navigator = Navigator.getNavigator();
                if (navigator != null)
                    navigator.run(log.getLatitude(), log.getLongitude());
                else
                    Toast.makeText(ctx, "? ?   .",
                            Toast.LENGTH_LONG).show();
            }

        }
    });
    // ? ?
    AlertDialog alertDialog = ab.create();
    // ? 
    alertDialog.show();
}

From source file:com.f16gaming.pathofexilestatistics.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);//from w w  w .  j ava  2s  . co  m

    LayoutInflater inflater = getLayoutInflater();

    poeEntries = new ArrayList<PoeEntry>();

    statsView = (ListView) findViewById(R.id.statsView);

    listFooter = inflater.inflate(R.layout.list_footer, null);

    statsView.addFooterView(listFooter);

    statsView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            onStatsViewClick(position);
        }
    });

    AlertDialog.Builder refreshWarningBuilder = new AlertDialog.Builder(this);
    refreshWarningBuilder.setTitle(R.string.refresh_warning).setMessage(R.string.refresh_warning_message)
            .setCancelable(true)
            .setNegativeButton(R.string.refresh_warning_reset, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    resetList();
                }
            }).setPositiveButton(R.string.refresh_warning_confirm, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    refreshList(true);
                }
            });

    refreshWarningDialog = refreshWarningBuilder.create();

    AlertDialog.Builder rankGoBuilder = new AlertDialog.Builder(this);
    View view = inflater.inflate(R.layout.rank_go_dialog, null);

    numberPicker = (net.simonvt.numberpicker.NumberPicker) view.findViewById(R.id.number_picker);
    numberPicker.setMinValue(1);
    numberPicker.setMaxValue(max);

    rankGoBuilder.setTitle(R.string.rank_go_dialog_title).setView(view).setCancelable(true)
            .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    // Do nothing
                }
            }).setPositiveButton(R.string.go, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    int rawOffset = numberPicker.getValue() - 1;
                    if (rawOffset >= limit * offset && rawOffset <= limit + limit * offset)
                        showToast(String.format(getString(R.string.toast_rank_showing), rawOffset + 1));
                    else
                        updateList(showHardcore, false, rawOffset);
                }
            });

    rankGoDialog = rankGoBuilder.create();

    resetList();
}

From source file:company.test.Test.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    switch (id) {
    case R.id.add_item:
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Add a task");
        builder.setMessage("What do you want to do?");
        final EditText inputField = new EditText(this);
        builder.setView(inputField);//  w  ww .  ja va 2  s. c  o m
        builder.setPositiveButton("Add", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                String task = inputField.getText().toString();
                Log.d("MainActivity", task);

                SQLiteDatabase db = helper.getWritableDatabase();
                ContentValues values = new ContentValues();

                values.clear();
                values.put(ItemContract.Columns.ITEM, task);

                db.insertWithOnConflict(ItemContract.TABLE, null, values, SQLiteDatabase.CONFLICT_IGNORE);

                activity.updateUI();
            }
        });

        builder.setNegativeButton("Cancel", null);

        builder.create().show();
        return true;
    case R.id.action_settings:
        Log.d("MainActivity", "Settings");
        return true;
    default:
        return false;
    }
}