Example usage for android.content DialogInterface cancel

List of usage examples for android.content DialogInterface cancel

Introduction

In this page you can find the example usage for android.content DialogInterface cancel.

Prototype

void cancel();

Source Link

Document

Cancels the dialog, invoking the OnCancelListener .

Usage

From source file:edu.mit.viral.shen.DroidFish.java

private final Dialog newNetworkEngineDialog() {
    View content = View.inflate(this, R.layout.create_network_engine, null);
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(content);//from ww w .j  av a 2  s.c  o m
    builder.setTitle(R.string.create_network_engine);
    final EditText engineNameView = (EditText) content.findViewById(R.id.create_network_engine);
    engineNameView.setText("");
    final Runnable createEngine = new Runnable() {
        public void run() {
            String engineName = engineNameView.getText().toString();
            String sep = File.separator;
            String pathName = Environment.getExternalStorageDirectory() + sep + engineDir + sep + engineName;
            File file = new File(pathName);
            boolean nameOk = true;
            int errMsg = -1;
            if (engineName.contains("/")) {
                nameOk = false;
                errMsg = R.string.slash_not_allowed;
            } else if (internalEngine(engineName) || file.exists()) {
                nameOk = false;
                errMsg = R.string.engine_name_in_use;
            }
            if (!nameOk) {
                Toast.makeText(getApplicationContext(), errMsg, Toast.LENGTH_LONG).show();
                removeDialog(NETWORK_ENGINE_DIALOG);
                showDialog(NETWORK_ENGINE_DIALOG);
                return;
            }
            networkEngineToConfig = pathName;
            removeDialog(NETWORK_ENGINE_CONFIG_DIALOG);
            showDialog(NETWORK_ENGINE_CONFIG_DIALOG);
        }
    };
    builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            createEngine.run();
        }
    });
    builder.setNegativeButton(R.string.cancel, new Dialog.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            removeDialog(NETWORK_ENGINE_DIALOG);
            showDialog(NETWORK_ENGINE_DIALOG);
        }
    });
    builder.setOnCancelListener(new Dialog.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            removeDialog(NETWORK_ENGINE_DIALOG);
            showDialog(NETWORK_ENGINE_DIALOG);
        }
    });

    final Dialog dialog = builder.create();
    engineNameView.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                createEngine.run();
                dialog.cancel();
                return true;
            }
            return false;
        }
    });
    return dialog;
}

From source file:com.dsi.ant.antplus.pluginsampler.watchdownloader.Activity_WatchScanList.java

/** Called when the activity is first created. */
@Override//w  w w . ja v a2 s  . c  o m
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_device_list);

    tv_status = (TextView) findViewById(R.id.textView_Status);

    deviceList_Display = new ArrayList<Map<String, String>>();
    adapter_deviceList_Display = new SimpleAdapter(this, deviceList_Display,
            android.R.layout.simple_list_item_2, new String[] { "title", "desc" },
            new int[] { android.R.id.text1, android.R.id.text2 });

    ListView listView_Devices = (ListView) findViewById(R.id.listView_deviceList);
    listView_Devices.setAdapter(adapter_deviceList_Display);

    //Set the list to download the data for the selected device and display it.
    listView_Devices.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, final int pos, long id) {
            if (!bDevicesInList || watchPcc == null)
                return;

            final CharSequence[] downloadOptions = { "All Activities", "New Activities",
                    "Wait For New Activities" };
            AlertDialog.Builder builder = new AlertDialog.Builder(Activity_WatchScanList.this);
            builder.setTitle("Download...");
            builder.setItems(downloadOptions, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int downloadSelection) {
                    antFsProgressDialog = new ProgressDialog(Activity_WatchScanList.this);
                    antFsProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
                    antFsProgressDialog.setMessage("Sending Request...");
                    antFsProgressDialog.setCancelable(false);
                    antFsProgressDialog.setIndeterminate(false);

                    fitFileList = new ArrayList<FitFile>();

                    if (downloadSelection == 0) // download all
                    {
                        if (watchPcc.requestDownloadAllActivities(deviceInfoArray[pos].getDeviceUUID(),
                                new DownloadActivitiesFinished(pos), new FileDownloadedReceiver(),
                                new AntFsUpdateReceiver())) {
                            antFsProgressDialog.show();
                        }

                    } else if (downloadSelection == 1) // download new
                    {
                        if (watchPcc.requestDownloadNewActivities(deviceInfoArray[pos].getDeviceUUID(),
                                new DownloadActivitiesFinished(pos), new FileDownloadedReceiver(),
                                new AntFsUpdateReceiver())) {
                            antFsProgressDialog.show();
                        }
                    } else if (downloadSelection == 2) {
                        boolean reqSubmitted = watchPcc.listenForNewActivities(
                                deviceInfoArray[pos].getDeviceUUID(),
                                new IDownloadActivitiesFinishedReceiver() {
                                    @Override
                                    public void onNewDownloadActivitiesFinished(AntFsRequestStatus status) {
                                        //Only received on cancel right now, only thing to do is cancel dialog, already taken care of below
                                    }
                                }, new FileDownloadedReceiver() {
                                    @Override
                                    public void onNewFitFileDownloaded(FitFile downloadedFitFile) {
                                        super.onNewFitFileDownloaded(downloadedFitFile);

                                        //Now show each file as we get it
                                        List<FitFile> newActivityOnly = new ArrayList<FitFile>(fitFileList);
                                        fitFileList.clear();
                                        final Dialog_WatchData dataDialog = new Dialog_WatchData(
                                                deviceInfoArray[pos], newActivityOnly);
                                        runOnUiThread(new Runnable() {
                                            @Override
                                            public void run() {
                                                dataDialog.show(getSupportFragmentManager(), "DeviceData");
                                            }
                                        });
                                    }
                                });

                        //Once the listener is started we leave this dialog open until it is cancelled
                        //Note: Because the listener is an asynchronous process, you do not need to block the UI like the sample app does with this, you can leave it invisible to the user
                        if (reqSubmitted) {
                            AlertDialog.Builder builder = new AlertDialog.Builder(Activity_WatchScanList.this);
                            LayoutInflater inflater = Activity_WatchScanList.this.getLayoutInflater();

                            // Inflate and set the layout for the dialog
                            // Pass null as the parent view because its going in the dialog layout
                            View detailsView = inflater.inflate(R.layout.dialog_progresswaiter, null);
                            TextView textView_status = (TextView) detailsView
                                    .findViewById(R.id.textView_Status);
                            textView_status.setText("Waiting for new activities on "
                                    + deviceInfoArray[pos].getDisplayName() + "...");
                            builder.setView(detailsView);
                            builder.setNegativeButton("Cancel", new OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    //Let onCancelListener take care of business
                                    dialog.cancel();
                                }
                            });
                            builder.setOnCancelListener(new OnCancelListener() {
                                @Override
                                public void onCancel(DialogInterface dialog) {
                                    if (watchPcc != null) {
                                        watchPcc.cancelListenForNewActivities(
                                                deviceInfoArray[pos].getDeviceUUID());
                                    }
                                }
                            });
                            AlertDialog waitDialog = builder.create();
                            waitDialog.show();
                        }
                    }
                }
            });

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

From source file:edu.mit.viral.shen.DroidFish.java

private final Dialog networkEngineConfigDialog() {
    View content = View.inflate(this, R.layout.network_engine_config, null);
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(content);/*from w w  w. j  a  v a 2 s  .  c o  m*/
    builder.setTitle(R.string.configure_network_engine);
    final EditText hostNameView = (EditText) content.findViewById(R.id.network_engine_host);
    final EditText portView = (EditText) content.findViewById(R.id.network_engine_port);
    String hostName = "";
    String port = "0";
    try {
        String[] lines = Util.readFile(networkEngineToConfig);
        if ((lines.length >= 1) && lines[0].equals("NETE")) {
            if (lines.length > 1)
                hostName = lines[1];
            if (lines.length > 2)
                port = lines[2];
        }
    } catch (IOException e1) {
    }
    hostNameView.setText(hostName);
    portView.setText(port);
    final Runnable writeConfig = new Runnable() {
        public void run() {
            String hostName = hostNameView.getText().toString();
            String port = portView.getText().toString();
            try {
                FileWriter fw = new FileWriter(new File(networkEngineToConfig), false);
                fw.write("NETE\n");
                fw.write(hostName);
                fw.write("\n");
                fw.write(port);
                fw.write("\n");
                fw.close();
                setEngineOptions(true);
            } catch (IOException e) {
                Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
            }
        }
    };
    builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            writeConfig.run();
            removeDialog(NETWORK_ENGINE_DIALOG);
            showDialog(NETWORK_ENGINE_DIALOG);
        }
    });
    builder.setNegativeButton(R.string.cancel, new Dialog.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            removeDialog(NETWORK_ENGINE_DIALOG);
            showDialog(NETWORK_ENGINE_DIALOG);
        }
    });
    builder.setOnCancelListener(new Dialog.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            removeDialog(NETWORK_ENGINE_DIALOG);
            showDialog(NETWORK_ENGINE_DIALOG);
        }
    });
    builder.setNeutralButton(R.string.delete, new Dialog.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            removeDialog(DELETE_NETWORK_ENGINE_DIALOG);
            showDialog(DELETE_NETWORK_ENGINE_DIALOG);
        }
    });

    final Dialog dialog = builder.create();
    portView.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                writeConfig.run();
                dialog.cancel();
                removeDialog(NETWORK_ENGINE_DIALOG);
                showDialog(NETWORK_ENGINE_DIALOG);
                return true;
            }
            return false;
        }
    });
    return dialog;
}

From source file:com.safecell.LoginActivity.java

void showProfileList() {
    try {// w w w .  j ava  2  s . c om
        JSONObject loginResponceJsonObject = new JSONObject(loginResponce);

        // Log.v("Safecell:", "JSONObject "
        // +loginResponceJsonObject.toString(4));
        accountJO = loginResponceJsonObject.getJSONObject("account");
        profilesJA = accountJO.getJSONArray("profiles");

        profileName = new String[profilesJA.length()];
        profileIDArray = new int[profilesJA.length()];

        for (int i = 0; i < profilesJA.length(); i++) {
            profileJO = profilesJA.getJSONObject(i);
            profileName[i] = profileJO.getString("first_name") + " " + profileJO.getString("last_name");
            profileIDArray[i] = profileJO.getInt("id");
        }

        selectedProfile = new JSONObject();

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Select Profile");
        builder.setItems(profileName, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int item) {
                if (NetWork_Information.isNetworkAvailable(LoginActivity.this)) {

                    try {
                        selectedProfile = profilesJA.getJSONObject(item);
                        // check that profile already logged in
                        boolean is_app_installed = selectedProfile.getBoolean("is_app_installed");
                        Log.v(TAG, "is_app_installed: " + is_app_installed);
                        if (is_app_installed) {
                            Log.e(TAG, "Blocking login...");
                            Toast.makeText(context, "Profile already in use in another device.",
                                    Toast.LENGTH_LONG).show();
                            quitDialog(context, "Profile in use", "Profile already in use in another device.");
                        } else {
                            Log.e(TAG, "Allowing login...");

                            progressDialog.setMessage("Loading Please Wait");

                            progressDialog.show();

                            progressDialog.setCancelable(cancelSelectProfile);
                            // setting selected index into
                            // preferences
                            new ConfigurePreferences(context).setProfileIndex(String.valueOf(item));
                            new ConfigurePreferences(context).setSelectedProfile(selectedProfile.toString());
                            // Checking profile license information
                            // empty or not
                            String manager_id = selectedProfile.getString("manager_id");
                            String start_date = selectedProfile.getString("license_startdate");
                            String subscription = selectedProfile.getString("license_subsription");

                            // store details in shared preferences
                            ConfigurePreferences preferences = new ConfigurePreferences(context);
                            preferences.set_ProfileID(selectedProfile.getString("id"));
                            preferences.set_AccountID(selectedProfile.getString("account_id"));
                            preferences.set_ManagerID(manager_id);
                            preferences.set_LicenseStartDate(start_date);
                            preferences.set_LicenseSubscription(subscription);

                            // check manager account
                            if (manager_id.equals("0")) {
                                Log.d(TAG, "Manager profile");
                                UIUtils.OkDialog(context,
                                        "Cannot login with Manager Account. Please provide a registered device user.");
                                progressDialog.dismiss();
                                return;
                            }

                            // Check account is active or inactive

                            // validate account activation
                            boolean account_status = validateAccountActive(selectedProfile);
                            if (account_status) {
                                Log.v(TAG, "Account is activated...");
                                TrackingService.AccountActive = true;
                            } else {
                                Log.v(TAG, "Account is not activated yet..");
                                quitDialog(context, "Activation", TAGS.TAG_INACTIVE);
                                return;
                            }
                            // check start date empty
                            if (start_date.isEmpty() || start_date.equalsIgnoreCase(" ") || start_date == "null"
                                    || start_date.equals("null") || subscription.isEmpty()
                                    || subscription.equalsIgnoreCase(" ") || subscription == "null"
                                    || subscription.equals("null")) {
                                Log.e(TAG, "Profile license null");
                                UIUtils.OkDialog(context, "No profile license information in server .");
                                progressDialog.dismiss();
                                return;
                            }

                            // check license start date of profile
                            boolean start_status = TrailCheck.validateStartDate(context, start_date);
                            Log.d(TAG, "start date validation status = " + start_status);
                            if (start_status) {
                                Log.e(TAG, "Your license not started yet");
                                String startdate = start_date.split("T")[0];
                                quitDialog(context, "Licence", "You are authorize to use the application from "
                                        + startdate + ". Please login on that date");
                                progressDialog.dismiss();
                                return;
                            }

                            Log.d(TAG, "License subscription: " + subscription);
                            // check license expire date of profile
                            boolean expire = TrailCheck.validateExpireOn(context, start_date, subscription);
                            long remain_days = TrailCheck.getRemain_days();
                            if (expire) {
                                String exipredate = TrailCheck.expire_date.split(" ")[0];
                                Log.e(TAG, "Trail expired");
                                quitDialog(context, TrailCheck.title, "You SafeCell license expired on "
                                        + exipredate
                                        + " .Please log on the www.safecellapp.mobi with your userid and password and renew the license.");
                                progressDialog.dismiss();
                                return;
                            }
                            if (remain_days < 30 && !expire) {

                                AlertDialog dialog_screen = new AlertDialog.Builder(context)
                                        .setMessage(TrailCheck.messsge)
                                        .setNeutralButton("Ok", new DialogInterface.OnClickListener() {

                                            @Override
                                            public void onClick(DialogInterface dialog, int which) {

                                                dialog.cancel();
                                                mThread1.start();

                                            }
                                        }).create();
                                dialog_screen.show();

                            } else {
                                mThread1.start();
                            }
                        }
                    } catch (Exception e) {
                        Log.d(TAG, "Exception while checking license");
                        e.printStackTrace();
                    }

                } else {

                    Log.d(TAG, "No network information available");
                    NetWork_Information.noNetworkConnectiondialog(LoginActivity.this);

                }

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

    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.moonpi.swiftnotes.MainActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    if (id == DIALOG_BACKUP_CHECK) {
        return new AlertDialog.Builder(this).setTitle(R.string.action_backup)
                .setMessage(R.string.dialog_check_backup_if_sure)
                .setPositiveButton(R.string.yes_button, new DialogInterface.OnClickListener() {
                    @Override/*from w ww.j av a  2s.c  o  m*/
                    public void onClick(DialogInterface dialog, int which) {
                        // If note array not empty, continue
                        if (notes.length() > 0) {
                            if (isExternalStorageWritable()) {
                                // Check if Swiftntotes folder exists, if not, create directory
                                File folder = new File(
                                        Environment.getExternalStorageDirectory() + "/Swiftnotes");
                                boolean folderCreated = true;

                                if (!folder.exists()) {
                                    folderCreated = folder.mkdir();
                                }

                                // Check if backup file exists, if yes, delete and create new, if not, just create new
                                File backupFile = new File(folder, "swiftnotes_backup.json");
                                boolean backupFileCreated = false;

                                if (backupFile.exists()) {
                                    boolean backupFileDeleted = backupFile.delete();

                                    if (backupFileDeleted) {
                                        try {
                                            backupFileCreated = backupFile.createNewFile();
                                            backupFilePath = backupFile.getAbsolutePath();

                                        } catch (IOException e) {
                                            e.printStackTrace();

                                            backupFileCreated = false;
                                        }
                                    }
                                }

                                // If backup file doesn't exist, create new
                                else {
                                    try {
                                        backupFileCreated = backupFile.createNewFile();
                                        backupFilePath = backupFile.getAbsolutePath();

                                    } catch (IOException e) {
                                        e.printStackTrace();

                                        backupFileCreated = false;
                                    }
                                }

                                // Check if notes.json exists
                                File notesFile = new File(getFilesDir() + "/notes.json");
                                boolean notesFileCreated = false;

                                if (notesFile.exists())
                                    notesFileCreated = true;

                                //If everything exists, stream content from notes.json to backup file
                                if (folderCreated && backupFileCreated && notesFileCreated) {
                                    backupSuccessful = true;

                                    InputStream is = null;
                                    OutputStream os = null;

                                    try {
                                        is = new FileInputStream(notesFile);
                                        os = new FileOutputStream(backupFile);

                                    } catch (FileNotFoundException e) {
                                        e.printStackTrace();
                                        backupSuccessful = false;
                                    }

                                    if (is != null && os != null) {
                                        byte[] buf = new byte[1024];
                                        int len;

                                        try {
                                            while ((len = is.read(buf)) > 0) {
                                                os.write(buf, 0, len);
                                            }

                                        } catch (IOException e) {
                                            e.printStackTrace();
                                            backupSuccessful = false;
                                        }

                                        try {
                                            is.close();
                                            os.close();

                                        } catch (IOException e) {
                                            e.printStackTrace();
                                            backupSuccessful = false;
                                        }
                                    }

                                    if (backupSuccessful) {
                                        showBackupSuccessfulDialog();
                                    }

                else {
                                        Toast toast = Toast.makeText(getApplicationContext(),
                                                getResources().getString(R.string.toast_backup_failed),
                                                Toast.LENGTH_SHORT);
                                        toast.show();
                                    }
                                }

                                // Either folder or files weren't successfully created, toast failed
                                else {
                                    Toast toast = Toast.makeText(getApplicationContext(),
                                            getResources().getString(R.string.toast_backup_failed),
                                            Toast.LENGTH_SHORT);
                                    toast.show();
                                }
                            }

                            // If external storage not writable, toast failed
                            else {
                                Toast toast = Toast.makeText(getApplicationContext(),
                                        getResources().getString(R.string.toast_backup_failed),
                                        Toast.LENGTH_SHORT);
                                toast.show();
                            }
                        }

                        // If notes array is empty, toast backup failed
                        else {
                            Toast toast = Toast.makeText(getApplicationContext(),
                                    getResources().getString(R.string.toast_backup_no_notes),
                                    Toast.LENGTH_SHORT);
                            toast.show();
                        }
                    }
                }).setNegativeButton(R.string.no_button, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                }).create();
    }

    else if (id == DIALOG_BACKUP_OK) {
        return new AlertDialog.Builder(this).setTitle(R.string.dialog_backup_created_title)
                .setMessage(getResources().getString(R.string.dialog_backup_created) + " " + backupFilePath)
                .setCancelable(true)
                .setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                }).create();
    }

    else if (id == DIALOG_RESTORE_CHECK) {
        return new AlertDialog.Builder(this).setTitle(R.string.action_restore)
                .setMessage(R.string.dialog_check_restore_if_sure)
                .setPositiveButton(R.string.yes_button, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (isExternalStorageReadable()) {
                            File folder = new File(Environment.getExternalStorageDirectory() + "/Swiftnotes");
                            boolean folderExists = false;

                            if (folder.exists()) {
                                folderExists = true;
                            }

                            File backupFile = new File(folder, "swiftnotes_backup.json");
                            boolean backupFileExists = false;

                            if (backupFile.exists()) {
                                backupFileExists = true;
                                backupFilePath = backupFile.getAbsolutePath();
                            }

                            File notesFile = new File(getFilesDir() + "/notes.json");
                            boolean notesFileExists = false;

                            if (notesFile.exists())
                                notesFileExists = true;

                            if (folderExists && backupFileExists && notesFileExists) {
                                restoreSuccessful = true;

                                InputStream is = null;
                                OutputStream os = null;

                                try {
                                    is = new FileInputStream(backupFile);
                                    os = new FileOutputStream(notesFile);

                                } catch (FileNotFoundException e) {
                                    e.printStackTrace();
                                    restoreSuccessful = false;
                                }

                                if (is != null && os != null) {
                                    byte[] buf = new byte[1024];
                                    int len;

                                    try {
                                        while ((len = is.read(buf)) > 0) {
                                            os.write(buf, 0, len);
                                        }

                                    } catch (IOException e) {
                                        e.printStackTrace();
                                        restoreSuccessful = false;
                                    }

                                    try {
                                        is.close();
                                        os.close();

                                    } catch (IOException e) {
                                        e.printStackTrace();
                                        restoreSuccessful = false;
                                    }
                                }

                                if (restoreSuccessful) {
                                    readFromJSON();
                                    writeToJSON();
                                    readFromJSON();

                                    adapter.notifyDataSetChanged();

                                    Toast toast = Toast.makeText(getApplicationContext(),
                                            getResources().getString(R.string.toast_restore_successful),
                                            Toast.LENGTH_SHORT);
                                    toast.show();

                                    // Recreate Activity so adapter can inflate the notes
                                    recreate();
                                }

                else {
                                    Toast toast = Toast.makeText(getApplicationContext(),
                                            getResources().getString(R.string.toast_restore_unsuccessful),
                                            Toast.LENGTH_SHORT);
                                    toast.show();
                                }
                            }

                            // Either folder or files weren't successfully created, dialog failed
                            else {
                                showRestoreFailedDialog();
                            }
                        }

                        // If external storage not readable, toast failed
                        else {
                            Toast toast = Toast.makeText(getApplicationContext(),
                                    getResources().getString(R.string.toast_restore_unsuccessful),
                                    Toast.LENGTH_SHORT);
                            toast.show();
                        }
                    }
                }).setNegativeButton(R.string.no_button, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                }).create();
    }

    else if (id == DIALOG_RESTORE_FAILED) {
        return new AlertDialog.Builder(this).setTitle(R.string.dialog_restore_failed_title)
                .setMessage(R.string.dialog_restore_failed).setCancelable(true)
                .setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                }).create();
    }

    return null;
}

From source file:com.ezac.gliderlogs.FlightOverviewActivity.java

public void DoSettings() {
    // get settings.xml view
    LayoutInflater li = LayoutInflater.from(context);
    settingsView = li.inflate(R.layout.settings, null);
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
    // set settings.xml to alertdialog builder
    alertDialogBuilder.setView(settingsView);
    // get user input for service code
    final EditText userInput = (EditText) settingsView.findViewById(R.id.editTextDialogUserInput);
    // set dialog message
    alertDialogBuilder.setCancelable(false).setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override/*  www .  ja  va 2s.co  m*/
        public void onClick(DialogInterface dialog, int id) {
            SharedPreferences prefs = context.getSharedPreferences("Share", Context.MODE_PRIVATE);
            prefs.edit().clear();
            SharedPreferences.Editor es = prefs.edit();
            String[] mTestArray;
            if (userInput.getText().toString().equals("NoAccess")) {
                // prefs URL
                EditText et1 = (EditText) settingsView.findViewById(R.id.setting_url);
                appURL = et1.getText().toString();
                es.putString("com.ezac.gliderlogs.url", appURL).apply();
            }
            // prefs PRE
            EditText et2 = (EditText) settingsView.findViewById(R.id.setting_pre);
            appPRE = et2.getText().toString().replace(" ", "");
            es.putString("com.ezac.gliderlogs.pre", appPRE).apply();
            if (userInput.getText().toString().equals("NoAccess")) {
                // prefs SCN
                EditText et3 = (EditText) settingsView.findViewById(R.id.setting_scn);
                appSCN = et3.getText().toString();
                es.putString("com.ezac.gliderlogs.scn", appSCN).apply();
                // prefs KEY
                EditText et4 = (EditText) settingsView.findViewById(R.id.setting_key);
                appKEY = et4.getText().toString();
                es.putString("com.ezac.gliderlogs.key", appKEY).apply();
                // prefs KEY
                EditText et5 = (EditText) settingsView.findViewById(R.id.setting_secret);
                appSCT = et5.getText().toString();
                es.putString("com.ezac.gliderlogs.sct", appSCT).apply();
                // prefs Meteo

                mTestArray = getResources().getStringArray(R.array.meteo_id_arrays);
                Spinner et6 = (Spinner) settingsView.findViewById(R.id.setting_station);
                String sel6 = (String) et6.getSelectedItem();
                //String sel6_id = "";
                for (int i = 0; i < et6.getCount(); i++) {
                    String s1 = (String) et6.getItemAtPosition(i);
                    if (s1.equalsIgnoreCase(sel6)) {
                        appMST = mTestArray[i];
                    }
                }
                es.putString("com.ezac.gliderlogs.mst", appMST).apply();
                // prefs Metar
                EditText et7 = (EditText) settingsView.findViewById(R.id.setting_metar);
                appMTR = et7.getText().toString();
                es.putString("com.ezac.gliderlogs.mst", appMST).apply();
            }
            // prefs Flags
            CheckBox et9a = (CheckBox) settingsView.findViewById(R.id.setting_menu01);
            CheckBox et9b = (CheckBox) settingsView.findViewById(R.id.setting_menu02);

            CheckBox et9c = (CheckBox) settingsView.findViewById(R.id.setting_menu11);
            CheckBox et9d = (CheckBox) settingsView.findViewById(R.id.setting_menu12);
            CheckBox et9e = (CheckBox) settingsView.findViewById(R.id.setting_menu13);
            CheckBox et9f = (CheckBox) settingsView.findViewById(R.id.setting_menu14);
            CheckBox et9g = (CheckBox) settingsView.findViewById(R.id.setting_menu21);
            CheckBox et9h = (CheckBox) settingsView.findViewById(R.id.setting_menu22);
            String et9aa, et9ab;
            String v[];
            if (userInput.getText().toString().equals("To3Myd4T")) {
                et9aa = et9a.isChecked() ? "true" : "false";
                et9ab = et9b.isChecked() ? "true" : "false";
            } else {
                v = appFLG.split(";");
                et9aa = v[0];
                et9ab = v[1];
            }
            String et9ac = et9c.isChecked() ? "true" : "false";
            String et9ad = et9d.isChecked() ? "true" : "false";
            String et9ae = et9e.isChecked() ? "true" : "false";
            String et9af = et9f.isChecked() ? "true" : "false";
            String et9ag = et9g.isChecked() ? "true" : "false";
            String et9ah = et9h.isChecked() ? "true" : "false";
            appFLG = et9aa + ";" + et9ab + ";" + et9ac + ";" + et9ad + ";" + et9ae + ";" + et9af + ";" + et9ag
                    + ";" + et9ah + ";false;false";
            v = appFLG.split(";");

            menu.findItem(R.id.action_ezac).setVisible(Boolean.parseBoolean(v[2]));
            menu.findItem(R.id.action_meteo_group).setVisible(Boolean.parseBoolean(v[3]));
            menu.findItem(R.id.action_ntm_nld).setVisible(Boolean.parseBoolean(v[4]));
            menu.findItem(R.id.action_ntm_blx).setVisible(Boolean.parseBoolean(v[4]));
            menu.findItem(R.id.action_ogn_flarm).setVisible(Boolean.parseBoolean(v[5]));
            menu.findItem(R.id.action_adsb).setVisible(Boolean.parseBoolean(v[6]));
            menu.findItem(R.id.action_adsb_lcl).setVisible(Boolean.parseBoolean(v[7]));
            es.putString("com.ezac.gliderlogs.flg", appFLG).apply();
            // adjust value in menu button to value in use
            MenuItem MenuItem_dur = menu.findItem(R.id.action_45min);
            MenuItem_dur.setTitle(" " + appPRE + " Min ");
            if (userInput.getText().toString().equals("To3Myd4T")) {
                // prefs airfield heading
                mTestArray = getResources().getStringArray(R.array.heading_arrays);
                Spinner et10 = (Spinner) settingsView.findViewById(R.id.setting_heading);
                String sel10 = (String) et10.getSelectedItem();
                //String sel10_id = "";
                for (int i = 0; i < et10.getCount(); i++) {
                    String s2 = (String) et10.getItemAtPosition(i);
                    if (s2.equalsIgnoreCase(sel10)) {
                        appLND = mTestArray[i];
                        es.putString("com.ezac.gliderlogs.lnd", appLND).apply();
                    }
                }
            }
        }
    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });
    // create alert dialog & and load it's data
    AlertDialog alertDialog = alertDialogBuilder.create();
    EditText et1 = (EditText) settingsView.findViewById(R.id.setting_url);
    EditText et2 = (EditText) settingsView.findViewById(R.id.setting_pre);
    EditText et3 = (EditText) settingsView.findViewById(R.id.setting_scn);
    EditText et4 = (EditText) settingsView.findViewById(R.id.setting_key);
    EditText et5 = (EditText) settingsView.findViewById(R.id.setting_secret);
    Spinner et6 = (Spinner) settingsView.findViewById(R.id.setting_station);
    EditText et7 = (EditText) settingsView.findViewById(R.id.setting_metar);
    //EditText et8 = (EditText) settingsView.findViewById(R.id.setting_ntp);
    CheckBox et9a = (CheckBox) settingsView.findViewById(R.id.setting_menu01);
    CheckBox et9b = (CheckBox) settingsView.findViewById(R.id.setting_menu02);
    CheckBox et9c = (CheckBox) settingsView.findViewById(R.id.setting_menu11);
    CheckBox et9d = (CheckBox) settingsView.findViewById(R.id.setting_menu12);
    CheckBox et9e = (CheckBox) settingsView.findViewById(R.id.setting_menu13);
    CheckBox et9f = (CheckBox) settingsView.findViewById(R.id.setting_menu14);
    CheckBox et9g = (CheckBox) settingsView.findViewById(R.id.setting_menu21);
    CheckBox et9h = (CheckBox) settingsView.findViewById(R.id.setting_menu22);
    Spinner et10 = (Spinner) settingsView.findViewById(R.id.setting_heading);
    et1.setText(appURL);
    et2.setText(appPRE);
    et3.setText(appSCN);
    et4.setText(appKEY);
    et5.setText(appSCT);
    // get settings value for meteo station and set spinner
    String[] mTestArray;
    mTestArray = getResources().getStringArray(R.array.meteo_id_arrays);
    for (int i = 0; i < mTestArray.length; i++) {
        String s = mTestArray[i];
        if (s.equals(appMST)) {
            et6.setSelection(i);
        }
    }
    et7.setText(appMTR);
    // get settings value for menu tabs and set checkboxes
    String v[] = appFLG.split(";");
    et9a.setChecked(Boolean.parseBoolean(v[0]));
    et9b.setChecked(Boolean.parseBoolean(v[1]));
    et9c.setChecked(Boolean.parseBoolean(v[2]));
    et9d.setChecked(Boolean.parseBoolean(v[3]));
    et9e.setChecked(Boolean.parseBoolean(v[4]));
    et9f.setChecked(Boolean.parseBoolean(v[5]));
    et9g.setChecked(Boolean.parseBoolean(v[6]));
    et9h.setChecked(Boolean.parseBoolean(v[7]));
    // re-use mTestArray
    mTestArray = getResources().getStringArray(R.array.heading_arrays);
    for (int i = 0; i < mTestArray.length; i++) {
        String s = mTestArray[i];
        if (s.equals(appLND)) {
            et10.setSelection(i);
        }
    }
    // show it
    alertDialog.show();
}

From source file:com.codename1.impl.android.AndroidImplementation.java

@Override
public Object showNativePicker(final int type, final Component source, final Object currentValue,
        final Object data) {
    if (getActivity() == null) {
        return null;
    }//from   w  ww  .j a va 2  s . c om
    final boolean[] canceled = new boolean[1];
    final boolean[] dismissed = new boolean[1];

    if (editInProgress()) {
        stopEditing(true);
    }
    if (type == Display.PICKER_TYPE_TIME) {

        class TimePick
                implements TimePickerDialog.OnTimeSetListener, TimePickerDialog.OnCancelListener, Runnable {
            int result = ((Integer) currentValue).intValue();

            public void onTimeSet(TimePicker tp, int hour, int minute) {
                result = hour * 60 + minute;
                dismissed[0] = true;
                synchronized (this) {
                    notify();
                }
            }

            public void run() {
                while (!dismissed[0]) {
                    synchronized (this) {
                        try {
                            wait(50);
                        } catch (InterruptedException er) {
                        }
                    }
                }
            }

            @Override
            public void onCancel(DialogInterface di) {
                dismissed[0] = true;
                canceled[0] = true;
                synchronized (this) {
                    notify();
                }
            }
        }
        final TimePick pickInstance = new TimePick();
        getActivity().runOnUiThread(new Runnable() {
            public void run() {
                int hour = ((Integer) currentValue).intValue() / 60;
                int minute = ((Integer) currentValue).intValue() % 60;
                TimePickerDialog tp = new TimePickerDialog(getActivity(), pickInstance, hour, minute, true) {

                    @Override
                    public void cancel() {
                        super.cancel();
                        dismissed[0] = true;
                        canceled[0] = true;
                    }

                    @Override
                    public void dismiss() {
                        super.dismiss();
                        dismissed[0] = true;
                    }

                };
                tp.setOnCancelListener(pickInstance);
                //DateFormat.is24HourFormat(activity));
                tp.show();
            }
        });
        Display.getInstance().invokeAndBlock(pickInstance);
        if (canceled[0]) {
            return null;
        }
        return new Integer(pickInstance.result);
    }
    if (type == Display.PICKER_TYPE_DATE) {
        final java.util.Calendar cl = java.util.Calendar.getInstance();
        if (currentValue != null) {
            cl.setTime((Date) currentValue);
        }
        class DatePick
                implements DatePickerDialog.OnDateSetListener, DatePickerDialog.OnCancelListener, Runnable {
            Date result = (Date) currentValue;

            public void onDateSet(DatePicker dp, int year, int month, int day) {
                java.util.Calendar c = java.util.Calendar.getInstance();
                c.set(java.util.Calendar.YEAR, year);
                c.set(java.util.Calendar.MONTH, month);
                c.set(java.util.Calendar.DAY_OF_MONTH, day);
                result = c.getTime();
                dismissed[0] = true;
                synchronized (this) {
                    notify();
                }
            }

            public void run() {
                while (!dismissed[0]) {
                    synchronized (this) {
                        try {
                            wait(50);
                        } catch (InterruptedException er) {
                        }
                    }
                }
            }

            public void onCancel(DialogInterface di) {
                result = null;
                dismissed[0] = true;
                canceled[0] = true;
                synchronized (this) {
                    notify();
                }
            }
        }
        final DatePick pickInstance = new DatePick();
        getActivity().runOnUiThread(new Runnable() {
            public void run() {
                DatePickerDialog tp = new DatePickerDialog(getActivity(), pickInstance,
                        cl.get(java.util.Calendar.YEAR), cl.get(java.util.Calendar.MONTH),
                        cl.get(java.util.Calendar.DAY_OF_MONTH)) {

                    @Override
                    public void cancel() {
                        super.cancel();
                        dismissed[0] = true;
                        canceled[0] = true;
                    }

                    @Override
                    public void dismiss() {
                        super.dismiss();
                        dismissed[0] = true;
                    }

                };
                tp.setOnCancelListener(pickInstance);
                tp.show();
            }
        });
        Display.getInstance().invokeAndBlock(pickInstance);
        return pickInstance.result;
    }
    if (type == Display.PICKER_TYPE_STRINGS) {
        final String[] values = (String[]) data;
        class StringPick implements Runnable, NumberPicker.OnValueChangeListener {
            int result = -1;

            StringPick() {
            }

            public void run() {
                while (!dismissed[0]) {
                    synchronized (this) {
                        try {
                            wait(50);
                        } catch (InterruptedException er) {
                        }
                    }
                }
            }

            public void cancel() {
                dismissed[0] = true;
                canceled[0] = true;
                synchronized (this) {
                    notify();
                }
            }

            public void ok() {
                canceled[0] = false;
                dismissed[0] = true;
                synchronized (this) {
                    notify();
                }
            }

            @Override
            public void onValueChange(NumberPicker np, int oldVal, int newVal) {
                result = newVal;
            }
        }

        final StringPick pickInstance = new StringPick();
        for (int iter = 0; iter < values.length; iter++) {
            if (values[iter].equals(currentValue)) {
                pickInstance.result = iter;
                break;
            }
        }
        if (pickInstance.result == -1 && values.length > 0) {
            // The picker will default to showing the first element anyways
            // If we don't set the result to 0, then the user has to first
            // scroll to a different number, then back to the first option
            // to pick the first option.
            pickInstance.result = 0;
        }

        getActivity().runOnUiThread(new Runnable() {
            public void run() {
                NumberPicker picker = new NumberPicker(getActivity());
                if (source.getClientProperty("showKeyboard") == null) {
                    picker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
                }
                picker.setMinValue(0);
                picker.setMaxValue(values.length - 1);
                picker.setDisplayedValues(values);
                picker.setOnValueChangedListener(pickInstance);
                if (pickInstance.result > -1) {
                    picker.setValue(pickInstance.result);
                }
                RelativeLayout linearLayout = new RelativeLayout(getActivity());
                RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(50, 50);
                RelativeLayout.LayoutParams numPicerParams = new RelativeLayout.LayoutParams(
                        RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
                numPicerParams.addRule(RelativeLayout.CENTER_HORIZONTAL);

                linearLayout.setLayoutParams(params);
                linearLayout.addView(picker, numPicerParams);

                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
                alertDialogBuilder.setView(linearLayout);
                alertDialogBuilder.setCancelable(false)
                        .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                pickInstance.ok();
                            }
                        }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.cancel();
                                pickInstance.cancel();
                            }
                        });
                AlertDialog alertDialog = alertDialogBuilder.create();
                alertDialog.show();
            }
        });
        Display.getInstance().invokeAndBlock(pickInstance);
        if (canceled[0]) {
            return null;
        }
        if (pickInstance.result < 0) {
            return null;
        }
        return values[pickInstance.result];
    }
    return null;
}

From source file:com.ezac.gliderlogs.FlightDetailActivity.java

@Override
protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    setContentView(R.layout.start_edit);
    // get references to our objects
    mDateText = (EditText) findViewById(R.id.flight_date);
    mRegiSpin = (Spinner) findViewById(R.id.flight_registration);
    mPilotSpin = (Spinner) findViewById(R.id.flight_pilot);
    mInstChck = (CheckBox) findViewById(R.id.flight_instruction);
    mCoPilotSpin = (Spinner) findViewById(R.id.flight_copilot);
    mStartText = (EditText) findViewById(R.id.flight_start);
    mLandText = (EditText) findViewById(R.id.flight_landing);
    mDuraText = (EditText) findViewById(R.id.flight_duration);
    // disable input, these are output only
    mDateText.setClickable(false);// w w  w .ja v a 2  s .  co  m
    mDateText.setFocusable(false);
    mStartText.setClickable(false);
    mStartText.setFocusable(false);
    mLandText.setClickable(false);
    mLandText.setFocusable(false);
    mDuraText.setClickable(false);
    mDuraText.setFocusable(false);
    mBodyText = (EditText) findViewById(R.id.flight_edit_notes);
    mDateText.setText(FlightOverviewActivity.ToDay);
    mTypeNorm = (CheckBox) findViewById(R.id.flight_type_norm);
    mTypePass = (CheckBox) findViewById(R.id.flight_type_pass);
    mTypeDona = (CheckBox) findViewById(R.id.flight_type_dona);
    mTypeClub = (CheckBox) findViewById(R.id.flight_type_club);

    mLaunchWinch = (CheckBox) findViewById(R.id.flight_launch_winch);
    mLaunchTow = (CheckBox) findViewById(R.id.flight_launch_tow);
    mLaunchMotor = (CheckBox) findViewById(R.id.flight_launch_motor);

    Button confirmButton = (Button) findViewById(R.id.flight_edit_button);
    Button exitButton = (Button) findViewById(R.id.flight_quit_button);
    Button againButton = (Button) findViewById(R.id.flight_again_button);
    Button timeSButton = (Button) findViewById(R.id.btnChangeSTime);
    Button timeLButton = (Button) findViewById(R.id.btnChangeLTime);
    Button clearSButton = (Button) findViewById(R.id.btnClearSTime);
    Button clearLButton = (Button) findViewById(R.id.btnClearLTime);
    Button gliderButton = (Button) findViewById(R.id.btn_ext_1);
    Button pilotButton = (Button) findViewById(R.id.btn_ext_2);
    Bundle extras = getIntent().getExtras();

    // get data from DB tables and load our glider/member list
    addItemSpinner1();
    addItemSpinner2();
    // only now check if these are still empty
    if (GliderList.isEmpty() || MemberList.isEmpty()) {
        makeToast("Opties -> Voer eerst de actie 'Dag opstarten' uit, mogelijk was er een netwerk probleem !.");
        setResult(RESULT_CANCELED);
        finish();
    }
    // check from the saved Instance
    flightUri = (bundle == null) ? null : (Uri) bundle.getParcelable(FlightsContentProvider.CONTENT_ITEM_TYPE);
    // Or passed from the other activity
    if (extras != null) {
        flightUri = extras.getParcelable(FlightsContentProvider.CONTENT_ITEM_TYPE);
        fillData(flightUri);
    }
    // bewaar ingevoerde informatie
    confirmButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (mPilotSpin.getSelectedItem().equals(mCoPilotSpin.getSelectedItem())) {
                makeToast("'Gezagvoerder' en 'Co-Piloot' kunnen niet het zelfde zijn !!");
            } else {
                if (TextUtils.isEmpty((String) mRegiSpin.getSelectedItem())) {
                    makeToast("Verplichte velden invullen aub");
                } else {
                    setResult(RESULT_OK);
                    finish();
                }
            }
        }
    });
    // dupliceer de geselecteerde vlucht
    againButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            new AlertDialog.Builder(FlightDetailActivity.this).setTitle("Bevestig deze opdracht")
                    .setMessage("Wilt u deze vlucht dupliceren ? ")
                    .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int whichButton) {
                            // put some caheck in place as t avoid bogus record to be created
                            if ((!mDateText.getText().toString().equals(""))
                                    && (!mStartText.getText().toString().equals(""))
                                    && (!mLandText.getText().toString().equals(""))
                                    && (!mRegiSpin.getSelectedItem().equals(""))
                                    && (!mPilotSpin.getSelectedItem().equals(""))) {
                                ContentValues values = new ContentValues();
                                values.put(GliderLogTables.F_DATE, mDateText.getText().toString());
                                values.put(GliderLogTables.F_REGISTRATION,
                                        (String) mRegiSpin.getSelectedItem());
                                String ftype = "";
                                if (mTypeNorm.isChecked()) {
                                    ftype = "";
                                }
                                if (mTypePass.isChecked()) {
                                    ftype = "PASS";
                                }
                                if (mTypeDona.isChecked()) {
                                    ftype = "DONA";
                                }
                                if (mTypeClub.isChecked()) {
                                    ftype = "CLUB";
                                }
                                values.put(GliderLogTables.F_TYPE, ftype);
                                values.put(GliderLogTables.F_INSTRUCTION, (mInstChck.isChecked()) ? "J" : "N");
                                String fPilo = (String) mPilotSpin.getSelectedItem();
                                values.put(GliderLogTables.F_PILOT, fPilo);
                                String fPilo_id = "";
                                for (int i = 0; i < mPilotSpin.getCount(); i++) {
                                    String s = (String) mPilotSpin.getItemAtPosition(i);
                                    if (s.equalsIgnoreCase(fPilo)) {
                                        fPilo_id = MemberIndexList.get(i);
                                    }
                                }
                                values.put(GliderLogTables.F_PILOT_ID, fPilo_id);
                                String fCoPi = (String) mCoPilotSpin.getSelectedItem();
                                values.put(GliderLogTables.F_COPILOT, fCoPi);
                                String fCoPi_id = "";
                                for (int i = 0; i < mCoPilotSpin.getCount(); i++) {
                                    String s = (String) mCoPilotSpin.getItemAtPosition(i);
                                    if (s.equalsIgnoreCase(fCoPi)) {
                                        fCoPi_id = MemberIndexList.get(i);
                                    }
                                }
                                values.put(GliderLogTables.F_COPILOT_ID, fCoPi_id);
                                values.put(GliderLogTables.F_STARTED, "");
                                values.put(GliderLogTables.F_LANDED, "");
                                values.put(GliderLogTables.F_DURATION, "");
                                String fLaun = "";
                                if (mLaunchWinch.isChecked()) {
                                    fLaun = "L";
                                }
                                if (mLaunchTow.isChecked()) {
                                    fLaun = "S";
                                }
                                if (mLaunchMotor.isChecked()) {
                                    fLaun = "M";
                                }
                                values.put(GliderLogTables.F_LAUNCH, fLaun);
                                values.put(GliderLogTables.F_SENT, "0");
                                values.put(GliderLogTables.F_ACK, "0");
                                values.put(GliderLogTables.F_NOTES, "");
                                // New flight
                                flightUri = getContentResolver()
                                        .insert(FlightsContentProvider.CONTENT_URI_FLIGHT, values);
                            }
                        }
                    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int whichButton) {
                            // Do nothing.
                        }
                    }).show();
        }
    });

    exitButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            flg_save = true;
            setResult(RESULT_CANCELED);
            finish();
        }
    });

    timeSButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            time_mde = 10;
            // Creating a bundle object to pass currently set time to the fragment
            Bundle b = new Bundle();
            if (!mStartText.getText().toString().isEmpty()) {
                String[] split = mStartText.getText().toString().split(":");
                hour = Integer.parseInt(split[0]);
                minute = Integer.parseInt(split[1]);
            } else {
                final Calendar c = Calendar.getInstance();
                hour = c.get(Calendar.HOUR_OF_DAY);
                minute = c.get(Calendar.MINUTE);
            }
            b.putInt("set_hour", hour);
            b.putInt("set_minute", minute);
            // Instantiating TimePickerDialogFragment & pass it' arguments
            TimePickerDialogFragment timePicker = new TimePickerDialogFragment(mHandler);
            timePicker.setArguments(b);
            // Getting fragment manger for this activity & start transaction
            FragmentManager fm = getSupportFragmentManager();
            FragmentTransaction ft = fm.beginTransaction();
            ft.add(timePicker, "time_picker");
            /** Opening the TimePicker fragment */
            ft.commit();
        }
    });

    timeLButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            time_mde = 20;
            // Creating a bundle object to pass currently set time to the fragment
            Bundle b = new Bundle();
            if (!mLandText.getText().toString().isEmpty()) {
                String[] split = mLandText.getText().toString().split(":");
                hour = Integer.parseInt(split[0]);
                minute = Integer.parseInt(split[1]);
            } else {
                final Calendar c = Calendar.getInstance();
                hour = c.get(Calendar.HOUR_OF_DAY);
                minute = c.get(Calendar.MINUTE);
            }
            b.putInt("set_hour", hour);
            b.putInt("set_minute", minute);
            // Instantiating TimePickerDialogFragment & pass it' arguments
            TimePickerDialogFragment timePicker = new TimePickerDialogFragment(mHandler);
            timePicker.setArguments(b);
            // Getting fragment manger for this activity & start transaction
            FragmentManager fm = getSupportFragmentManager();
            FragmentTransaction ft = fm.beginTransaction();
            ft.add(timePicker, "time_picker");
            /** Opening the TimePicker fragment */
            ft.commit();
        }
    });

    clearSButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String S_T = mStartText.getText().toString();
            if (S_T.isEmpty()) {
                final Calendar c = Calendar.getInstance();
                //second = c.get(Calendar.SECOND);
                //mStartText.setText(Common.TwoDigits(c.get(Calendar.HOUR_OF_DAY)) + ":" + Common.TwoDigits(c.get(Calendar.MINUTE)));
                mStartText.setText(new StringBuilder().append(Common.TwoDigits(c.get(Calendar.HOUR_OF_DAY)))
                        .append(":").append(Common.TwoDigits(c.get(Calendar.MINUTE))));
            } else {
                mStartText.setText("");
            }
        }
    });

    clearLButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String L_T = mLandText.getText().toString();
            if (L_T.isEmpty()) {
                final Calendar c = Calendar.getInstance();
                //second = c.get(Calendar.SECOND);
                //mLandText.setText(Common.TwoDigits(c.get(Calendar.HOUR_OF_DAY)) + ":" + Common.TwoDigits(c.get(Calendar.MINUTE)));
                mLandText.setText(new StringBuilder().append(Common.TwoDigits(c.get(Calendar.HOUR_OF_DAY)))
                        .append(":").append(Common.TwoDigits(c.get(Calendar.MINUTE))));
            } else {
                mLandText.setText("");
            }
        }
    });

    mRegiSpin.setOnItemSelectedListener(new Custom0_OnItemSelectedListener());
    mPilotSpin.setOnItemSelectedListener(new Custom1_OnItemSelectedListener());

    gliderButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // get add_glider.xml view
            LayoutInflater li = LayoutInflater.from(edi_con);
            View promptsView = li.inflate(R.layout.add_glider, null);
            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(edi_con);
            // set add_glider.xml to alertdialog builder
            alertDialogBuilder.setView(promptsView);
            final EditText userInput1 = (EditText) promptsView.findViewById(R.id.editTextInput1);
            final EditText userInput2 = (EditText) promptsView.findViewById(R.id.editTextInput2);
            final CheckBox userInput3 = (CheckBox) promptsView.findViewById(R.id.editCheckInput3);
            final CheckBox userInput4 = (CheckBox) promptsView.findViewById(R.id.editCheckInput4);
            // set dialog message
            alertDialogBuilder.setCancelable(false)
                    .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                        @Override
                        @SuppressLint("DefaultLocale")
                        public void onClick(DialogInterface dialog, int id) {
                            // user input, convert to UC, add to glider list & spinner
                            result = userInput1.getText().toString().toUpperCase();
                            if (GliderList.contains(result)) {
                                makeToast("Invoer extra, deze kist bestaat reeds !");
                                result = null;
                                dialog.cancel();
                            } else {
                                GliderList.add(result);
                                GliderCall.add(userInput2.getText().toString().toUpperCase());
                                GliderSeatsList.add(userInput3.isChecked() ? "2" : "1");
                                GliderPrivateList.add(userInput4.isChecked() ? "1" : "0");
                                ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(
                                        FlightDetailActivity.this, android.R.layout.simple_spinner_item,
                                        GliderList);
                                dataAdapter
                                        .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                                mRegiSpin.setAdapter(dataAdapter);
                                // add to DB table
                                try {
                                    ContentValues values = new ContentValues();
                                    values.put(GliderLogTables.G_REGISTRATION, result);
                                    getContentResolver().insert(FlightsContentProvider.CONTENT_URI_GLIDER,
                                            values);
                                    values = null;
                                } catch (Exception e) {
                                    Log.e("Exception", "Error: " + e.toString());
                                }
                            }
                        }
                    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int id) {
                            result = null;
                            dialog.cancel();
                        }
                    });
            // create alert dialog & show it
            AlertDialog alertDialog = alertDialogBuilder.create();
            alertDialog.show();
        }
    });

    pilotButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // get prompts.xml view
            LayoutInflater li = LayoutInflater.from(edi_con);
            View promptsView = li.inflate(R.layout.add_member, null);
            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(edi_con);
            // set prompts.xml to alertdialog builder
            alertDialogBuilder.setView(promptsView);
            final EditText userInput = (EditText) promptsView.findViewById(R.id.editTextDialogUserInput);
            // set dialog message
            alertDialogBuilder.setCancelable(false)
                    .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                        @Override
                        @SuppressLint("DefaultLocale")
                        public void onClick(DialogInterface dialog, int id) {
                            // get user input check for at least 2
                            // parts
                            result = userInput.getText().toString();
                            if (MemberList.contains(result)) {
                                makeToast("Invoer extra, deze naam bestaat reeds !");
                                result = null;
                                dialog.cancel();
                            } else {
                                String[] name = result.split(" ");
                                if (name.length < 2) {
                                    makeToast(
                                            "Invoer extra, formaat => Voornaam (tussenvoegsel(s)) Achternaam is vereist !");
                                    result = null;
                                    dialog.cancel();
                                }
                                // add to member list & spinners
                                MemberList.add(result);
                                MemberIndexList.add("" + ini_id);
                                MemberInstrList.add("0");
                                ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(
                                        FlightDetailActivity.this, android.R.layout.simple_spinner_item,
                                        MemberList);
                                dataAdapter
                                        .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                                mPilotSpin.setAdapter(dataAdapter);
                                mCoPilotSpin.setAdapter(dataAdapter);
                                // add parts to DB table fields
                                AddNewMember(name);
                            }
                        }
                    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int id) {
                            result = null;
                            dialog.cancel();
                        }
                    });
            // create alert dialog & show it
            AlertDialog alertDialog = alertDialogBuilder.create();
            alertDialog.show();
        }
    });

    setMode();
}