Example usage for android.app AlertDialog show

List of usage examples for android.app AlertDialog show

Introduction

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

Prototype

public void show() 

Source Link

Document

Start the dialog and display it on screen.

Usage

From source file:com.fvd.nimbus.MainActivity.java

@SuppressLint("NewApi")
@Override/*ww  w .ja  v  a  2s  .c  om*/
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == TAKE_PHOTO) {
        if (resultCode == -1) {
            try {
                if (data != null) {
                    if (data.hasExtra("data")) {
                        Bitmap bm = data.getParcelableExtra("data");
                        photoFileName = appSettings.saveTempBitmap(bm);
                        bm.recycle();
                    }
                } else {
                    if (outputFileUri != null)
                        photoFileName = outputFileUri.getPath();
                    else
                        photoFileName = getImagePath();
                }

                if (appSettings.isFileExists(photoFileName)) {
                    Intent iPaint = new Intent();
                    iPaint.putExtra("temp", true);
                    iPaint.putExtra("path", photoFileName);
                    iPaint.setClassName("com.fvd.nimbus", "com.fvd.nimbus.PaintActivity");
                    startActivity(iPaint);
                }
                showProgress(false);
            } catch (Exception e) {
                appSettings.appendLog("main:onActivityResult: exception -  " + e.getMessage());
                showProgress(false);
            }
        } else
            showProgress(false);
    } else if (requestCode == TAKE_PICTURE) {
        if (resultCode == -1 && data != null) {
            boolean temp = false;

            try {
                Uri resultUri = data.getData();
                String drawString = resultUri.getPath();
                String galleryString = getGalleryPath(resultUri);
                if (galleryString != null && galleryString.length() > 0) {
                    drawString = galleryString;
                } else {
                    try {
                        InputStream input = getApplicationContext().getContentResolver()
                                .openInputStream(resultUri);
                        Bitmap bm = BitmapFactory.decodeStream(input);
                        drawString = appSettings.saveTempBitmap(bm);
                        bm.recycle();
                        temp = true;

                    } catch (Exception e) {
                        drawString = "";
                        showProgress(false);
                    }
                }

                if (drawString.length() > 0 && drawString.indexOf("/exposed_content/") == -1) {
                    try {
                        Intent iPaint = new Intent();
                        iPaint.putExtra("temp", temp);
                        iPaint.putExtra("path", drawString);
                        iPaint.setClassName("com.fvd.nimbus", "com.fvd.nimbus.PaintActivity");
                        startActivity(iPaint);
                    } catch (Exception e) {

                    }
                }
                showProgress(false);

            } catch (Exception e) {
                appSettings.appendLog("main:onActivityResult  " + e.getMessage());
                showProgress(false);
            }
        } else
            showProgress(false);
    } else if (requestCode == 5) {
        if (resultCode == RESULT_OK) {
            userMail = data.getStringExtra("userMail");
            userPass = data.getStringExtra("userPass");
            serverHelper.getInstance().sendOldRequest("user_register", String.format(
                    "{\"action\": \"user_register\",\"email\":\"%s\",\"password\":\"%s\",\"_client_software\": \"ff_addon\"}",
                    userMail, userPass), "");
        }
    } else if (requestCode == 6) {
        showLogin();
    } else if (requestCode == SHOW_SETTINGS) {
        switch (resultCode) {
        case RESULT_FIRST_USER + 1:
            Intent i = new Intent(getApplicationContext(), PrefsActivity.class);
            startActivity(i);
            //overridePendingTransition( R.anim.slide_in_up, R.anim.slide_out_up );
            overridePendingTransition(R.anim.carbon_slide_in, R.anim.carbon_slide_out);
            break;
        case RESULT_FIRST_USER + 2:
            if (appSettings.sessionId.length() == 0)
                showLogin();
            else {
                if (true || appSettings.service == "") {
                    appSettings.sessionId = "";
                    Editor e = prefs.edit();
                    e.putString("userMail", userMail);
                    e.putString("userPass", "");
                    e.putString("sessionId", appSettings.sessionId);
                    e.commit();
                    showLogin();
                } else {
                    i = new Intent(getApplicationContext(), loginWithActivity.class);
                    i.putExtra("logout", "true");
                    i.putExtra("service", appSettings.service);
                    startActivity(i);
                    overridePendingTransition(R.anim.carbon_slide_in, R.anim.carbon_slide_out);
                }
            }
            break;
        case RESULT_FIRST_USER + 3:
            try {
                startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse("market://details?id=" + getApplicationInfo().packageName)));
            } catch (Exception e) {
            }
        case RESULT_FIRST_USER + 4:
            Uri uri = Uri.parse(
                    "http://help.everhelper.me/customer/portal/articles/1376820-nimbus-clipper-for-android---quick-guide");
            Intent it = new Intent(Intent.ACTION_VIEW, uri);
            startActivity(it);
            //overridePendingTransition( R.anim.slide_in_up, R.anim.slide_out_up );
            overridePendingTransition(R.anim.carbon_slide_in, R.anim.carbon_slide_out);
            break;
        case RESULT_FIRST_USER + 5:
            final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this,
                    AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
            alertDialogBuilder.setMessage(getScriptContent("license.txt")).setCancelable(false)
                    .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            // no alert dialog shown
                            //alertDialogShown = null;
                            // canceled
                            setResult(RESULT_CANCELED);
                            // and finish
                            //finish();
                        }
                    });
            // create alert dialog
            final AlertDialog alertDialog = alertDialogBuilder.create();
            alertDialog.setTitle(getString(R.string.license_title));

            // and show
            //alertDialogShown = alertDialog;
            try {
                alertDialog.show();
            } catch (final java.lang.Exception e) {
                // nothing to do
            } catch (final java.lang.Error e) {
                // nothing to do
            }
            break;
        default:
            break;
        }
    }
}

From source file:com.nps.micro.view.TestsSectionFragment.java

@Override
protected View buildRootView(LayoutInflater inflater, ViewGroup container) {
    View rootView = inflater.inflate(layout, container, false);

    runButton = (Button) rootView.findViewById(R.id.runButton);
    runButton.setOnClickListener(new OnClickListener() {
        @Override/*  w w w .  j av  a  2s  .co m*/
        public void onClick(View v) {
            prepareScenarios();
        }
    });

    repeatsInput = (EditText) rootView.findViewById(R.id.repeatsInput);
    repeatsInput.setText(String.valueOf(model.getRepeats()));
    repeatsInput.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable s) {
            String val = s.toString();
            if (!val.isEmpty() && StringUtils.isNumeric(val)) {
                model.setRepeats(Integer.valueOf(s.toString()));
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });

    repeatsButton = (Button) rootView.findViewById(R.id.setRepeatsButton);
    repeatsButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setTitle(R.string.repeats).setItems(R.array.repeats_array,
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            repeatsInput.setText(getResources().getStringArray(R.array.repeats_array)[which]);
                            dialog.dismiss();
                        }
                    });
            AlertDialog alert = builder.create();
            alert.show();
        }
    });

    outSizeInput = (EditText) rootView.findViewById(R.id.packetOutSizeInput);
    outSizeInput.setText(String.valueOf(model.getStreamOutSize()));
    outSizeInput.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable s) {
            String val = s.toString();
            if (!val.isEmpty() && StringUtils.isNumeric(val)) {
                model.setStreamOutSize(Short.valueOf(s.toString()));
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });

    outSizeButton = (Button) rootView.findViewById(R.id.setOutSizeButton);
    outSizeButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setTitle(R.string.out_size).setItems(R.array.out_size_array,
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            outSizeInput.setText(getResources().getStringArray(R.array.out_size_array)[which]);
                            dialog.dismiss();
                        }
                    });
            AlertDialog alert = builder.create();
            alert.show();
        }
    });

    inSizeInput = (EditText) rootView.findViewById(R.id.packetInSizeInput);
    inSizeInput.setText(String.valueOf(model.getStreamInSizes()[0]));
    inSizeInput.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable s) {
            String[] vals = s.toString().split(" ");
            List<Short> intVals = new ArrayList<Short>();
            for (String val : vals) {
                try {
                    intVals.add(Short.valueOf(val));
                } catch (NumberFormatException e) {
                    // TODO Auto-generated catch block
                }
            }
            short[] array = new short[intVals.size()];
            for (int i = 0; i < intVals.size(); i++)
                array[i] = intVals.get(i);
            model.setStreamInSize(array);
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });

    inSizeButton = (Button) rootView.findViewById(R.id.setInSizeButton);
    inSizeButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setTitle(R.string.in_size).setItems(R.array.in_size_array,
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            inSizeInput.setText(getResources().getStringArray(R.array.in_size_array)[which]);
                            dialog.dismiss();
                        }
                    });
            AlertDialog alert = builder.create();
            alert.show();
        }
    });

    radioStorageGroup = (RadioGroup) rootView.findViewById(R.id.storageRadioGroup);
    externalStorageRadio = (RadioButton) rootView.findViewById(R.id.externalStorageRadio);
    internalStorageRadio = (RadioButton) rootView.findViewById(R.id.internalStorageRadio);
    switch (model.getStorageType()) {
    case EXTERNAL:
        externalStorageRadio.setChecked(true);
        break;
    case INTERNAL:
        internalStorageRadio.setChecked(true);
        break;
    }
    externalStorageRadio.setEnabled(model.isSaveStreams() || model.isSaveLogs());
    internalStorageRadio.setEnabled(model.isSaveStreams() || model.isSaveLogs());

    radioStorageGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            switch (checkedId) {
            case R.id.internalStorageRadio:
                model.setStorageType(Storage.Type.INTERNAL);
                break;
            case R.id.externalStorageRadio:
                model.setStorageType(Storage.Type.EXTERNAL);
                break;
            }
        }
    });

    saveLogsCheckBox = (CheckBox) rootView.findViewById(R.id.saveLogsCheckBox);
    saveLogsCheckBox.setChecked(model.isSaveLogs());
    saveLogsCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            model.setSaveLogs(isChecked);
            externalStorageRadio.setEnabled(model.isSaveStreams() || model.isSaveLogs());
            internalStorageRadio.setEnabled(model.isSaveStreams() || model.isSaveLogs());

        }
    });

    streamBufferSizeInput = (EditText) rootView.findViewById(R.id.bufferSizeEditText);
    streamBufferSizeInput.setText(String.valueOf(model.getStreamBufferSize()));
    streamBufferSizeInput.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable s) {
            String val = s.toString();
            if (!val.isEmpty() && StringUtils.isNumeric(val)) {
                model.setStreamBufferSize(Integer.valueOf(s.toString()));
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });

    memoryUnitSpinner = (Spinner) rootView.findViewById(R.id.memoryUnitSpinner);
    memoryUnitSpinner.setSelection(model.getStreamBufferUnit().getIndex());
    memoryUnitSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
            model.setStreamBufferUnit(MemoryUnit.fromIndex(pos));
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            // do nothing
        }
    });

    saveStreamCheckBox = (CheckBox) rootView.findViewById(R.id.saveStreamDataCheckbox);
    saveStreamCheckBox.setChecked(model.isSaveStreams());
    streamBufferSizeInput.setEnabled(saveStreamCheckBox.isChecked());
    memoryUnitSpinner.setEnabled(saveStreamCheckBox.isChecked());
    streamQueueSize = (EditText) rootView.findViewById(R.id.streamQueueSize);
    streamQueueSize.setText(String.valueOf(model.getStreamQueueSize()));
    streamQueueSize.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable s) {
            String val = s.toString();
            if (!val.isEmpty() && StringUtils.isNumeric(val)) {
                model.setStreamQueueSize(Integer.valueOf(s.toString()));
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });
    streamQueueSize.setEnabled(model.isSaveStreams() && !model.isAutoStreamQueueSize());
    radioQueueGroup = (RadioGroup) rootView.findViewById(R.id.queueRadioGroup);
    autoStreamQueueSizeRadio = (RadioButton) rootView.findViewById(R.id.autoBufferRadio);
    manualStreamQueueSizeRadio = (RadioButton) rootView.findViewById(R.id.manualBufferRadio);
    if (model.isAutoStreamQueueSize()) {
        autoStreamQueueSizeRadio.setChecked(true);
    } else {
        manualStreamQueueSizeRadio.setChecked(true);
    }
    autoStreamQueueSizeRadio.setEnabled(model.isSaveStreams());
    manualStreamQueueSizeRadio.setEnabled(model.isSaveStreams());
    radioQueueGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            switch (checkedId) {
            case R.id.autoBufferRadio:
                model.setAutoStreamQueueSize(true);
                streamQueueSize.setEnabled(false);
                break;
            case R.id.manualBufferRadio:
                model.setAutoStreamQueueSize(false);
                streamQueueSize.setEnabled(true);
                break;
            }
        }
    });

    saveStreamCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            model.setSaveStreams(isChecked);
            externalStorageRadio.setEnabled(model.isSaveStreams() || model.isSaveLogs());
            internalStorageRadio.setEnabled(model.isSaveStreams() || model.isSaveLogs());
            streamBufferSizeInput.setEnabled(isChecked);
            memoryUnitSpinner.setEnabled(isChecked);
            autoStreamQueueSizeRadio.setEnabled(model.isSaveStreams());
            manualStreamQueueSizeRadio.setEnabled(model.isSaveStreams());
            streamQueueSize.setEnabled(model.isSaveStreams() && !model.isAutoStreamQueueSize());
        }
    });

    simulateEditText = (EditText) rootView.findViewById(R.id.simulateComputationsEditText);
    simulateEditText.setText(String.valueOf(model.getSimulateComputations()));
    simulateEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            model.setSimulateComputations(Short.valueOf(s.toString()));
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });

    normalPriorityCheckBox = (CheckBox) rootView.findViewById(R.id.normalPriorityCheckbox);
    normalPriorityCheckBox.setChecked(model.isNormalThreadPriority());
    normalPriorityCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            model.setNormalThreadPriority(isChecked);
        }
    });

    hiPriorityAndroidCheckBox = (CheckBox) rootView.findViewById(R.id.hiAndroidPriorityCheckbox);
    hiPriorityAndroidCheckBox.setChecked(model.isHiAndroidThreadPriority());
    hiPriorityAndroidCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            model.setHiAndroidThreadPriority(isChecked);
        }
    });

    hiPriorityJavaCheckBox = (CheckBox) rootView.findViewById(R.id.hiJavaPriorityCheckbox);
    hiPriorityJavaCheckBox.setChecked(model.isHiJavaThreadPriority());
    hiPriorityJavaCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            model.setHiJavaThreadPriority(isChecked);
        }
    });

    extendedDevicesCombination = (CheckBox) rootView.findViewById(R.id.extendedDevicesCheckBox);
    extendedDevicesCombination.setChecked(model.isExtendedDevicesCombination());
    extendedDevicesCombination.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            model.setExtendedDevicesCombination(isChecked);
        }
    });

    fastHub = (CheckBox) rootView.findViewById(R.id.fastHubCheckBox);
    fastHub.setChecked(model.isFastHub());
    fastHub.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            model.setFastHub(isChecked);
        }
    });

    autoEnableGraphCheckBox = (CheckBox) rootView.findViewById(R.id.autoEnableGraphCheckBox);
    autoEnableGraphCheckBox.setChecked(model.isAutoEnableGraph());
    autoEnableGraphCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            model.setAutoEnableGraph(isChecked);
        }
    });

    createSequenceChooser(rootView);
    createDeviceChooser(rootView, runButton);
    updateStatus(rootView);
    return rootView;
}

From source file:org.loon.framework.android.game.LGameActivity.java

/**
 * ??Alter// w  w w.  jav  a2 s  .co m
 * 
 * @param message
 */
public void showAndroidAlert(final String title, final String message) {
    Runnable showAlert = new Runnable() {
        public void run() {
            final AlertDialog alert = new AlertDialog.Builder(LGameActivity.this).create();
            alert.setTitle(title);
            alert.setMessage(message);
            alert.setButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    alert.dismiss();
                }
            });
            alert.show();
        }
    };
    runOnUiThread(showAlert);
}

From source file:com.frostwire.android.gui.util.UIUtils.java

/**
 * @param context                         -  containing Context.
 * @param showInstallationCompleteSection - true if you want to display "Your installation is now complete. Thank You" section
 * @param dismissListener                 - what happens when the dialog is dismissed.
 * @param referrerContextSuffix           - string appended at the end of social pages click urls's ?ref=_android_ parameter.
 *///from ww w.  java2  s .c o m
public static void showSocialLinksDialog(final Context context, boolean showInstallationCompleteSection,
        DialogInterface.OnDismissListener dismissListener, String referrerContextSuffix) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    View customView = View.inflate(context, R.layout.view_social_buttons, null);
    builder.setView(customView);
    builder.setPositiveButton(context.getString(android.R.string.ok), (dialog, which) -> dialog.dismiss());
    final AlertDialog socialLinksDialog = builder.create();
    socialLinksDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    socialLinksDialog.setOnDismissListener(dismissListener);
    ImageButton fbButton = customView.findViewById(R.id.view_social_buttons_facebook_button);
    ImageButton twitterButton = customView.findViewById(R.id.view_social_buttons_twitter_button);
    ImageButton redditButton = customView.findViewById(R.id.view_social_buttons_reddit_button);
    final String referrerParam = "?ref=android_"
            + ((referrerContextSuffix != null) ? referrerContextSuffix.trim() : "");
    fbButton.setOnClickListener(
            v -> UIUtils.openURL(v.getContext(), Constants.SOCIAL_URL_FACEBOOK_PAGE + referrerParam));
    twitterButton.setOnClickListener(
            v -> UIUtils.openURL(v.getContext(), Constants.SOCIAL_URL_TWITTER_PAGE + referrerParam));
    redditButton.setOnClickListener(
            v -> UIUtils.openURL(v.getContext(), Constants.SOCIAL_URL_REDDIT_PAGE + referrerParam));
    if (showInstallationCompleteSection) {
        LinearLayout installationCompleteLayout = customView
                .findViewById(R.id.view_social_buttons_installation_complete_layout);
        installationCompleteLayout.setVisibility(View.VISIBLE);
        ImageButton dismissCheckButton = customView.findViewById(R.id.view_social_buttons_dismiss_check);
        dismissCheckButton.setOnClickListener(v -> socialLinksDialog.dismiss());
    }
    socialLinksDialog.show();
}

From source file:net.networksaremadeofstring.cyllell.ViewRoles_Fragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    list = (ListView) this.getActivity().findViewById(R.id.rolesListView);
    settings = this.getActivity().getSharedPreferences("Cyllell", 0);
    try {/* w w w . ja va2s.  com*/
        Cut = new Cuts(getActivity());
    } catch (Exception e) {
        e.printStackTrace();
    }

    dialog = new ProgressDialog(getActivity());
    dialog.setTitle("Contacting Chef");
    dialog.setMessage("Please wait: Prepping Authentication protocols");
    dialog.setIndeterminate(true);
    if (listOfRoles.size() < 1) {
        dialog.show();
    }

    updateListNotify = new Handler() {
        public void handleMessage(Message msg) {
            int tag = msg.getData().getInt("tag", 999999);

            if (msg.what == 0) {
                if (tag != 999999) {
                    listOfRoles.get(tag).SetSpinnerVisible();
                }
            } else if (msg.what == 1) {
                //Get rid of the lock
                CutInProgress = false;

                //the notifyDataSetChanged() will handle the rest
            } else if (msg.what == 99) {
                if (tag != 999999) {
                    Toast.makeText(ViewRoles_Fragment.this.getActivity(),
                            "An error occured during that operation.", Toast.LENGTH_LONG).show();
                    listOfRoles.get(tag).SetErrorState();
                }
            }
            RoleAdapter.notifyDataSetChanged();
        }
    };

    final Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            //Once we've checked the data is good to use start processing it
            if (msg.what == 0) {
                OnClickListener listener = new OnClickListener() {
                    public void onClick(View v) {
                        GetMoreDetails((Integer) v.getTag());
                    }
                };

                OnLongClickListener listenerLong = new OnLongClickListener() {
                    public boolean onLongClick(View v) {
                        selectForCAB((Integer) v.getTag());
                        return true;
                    }
                };

                RoleAdapter = new RoleListAdaptor(getActivity(), listOfRoles, listener, listenerLong);
                list = (ListView) getView().findViewById(R.id.rolesListView);
                if (list != null) {
                    if (RoleAdapter != null) {
                        list.setAdapter(RoleAdapter);
                    } else {
                        //Log.e("CookbookAdapter","CookbookAdapter is null");
                    }
                } else {
                    //Log.e("List","List is null");
                }

                dialog.dismiss();
            } else if (msg.what == 200) {
                dialog.setMessage("Sending request to Chef...");
            } else if (msg.what == 201) {
                dialog.setMessage("Parsing JSON.....");
            } else if (msg.what == 202) {
                dialog.setMessage("Populating UI!");
            } else {
                //Close the Progress dialog
                dialog.dismiss();

                //Alert the user that something went terribly wrong
                AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).create();
                alertDialog.setTitle("API Error");
                alertDialog.setMessage("There was an error communicating with the API:\n"
                        + msg.getData().getString("exception"));
                alertDialog.setButton2("Back", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        //getActivity().finish();
                    }
                });
                alertDialog.setIcon(R.drawable.icon);
                alertDialog.show();
            }
        }
    };

    Thread dataPreload = new Thread() {
        public void run() {
            if (listOfRoles.size() > 0) {
                handler.sendEmptyMessage(0);
            } else {
                try {
                    handler.sendEmptyMessage(200);
                    Roles = Cut.GetRoles();
                    handler.sendEmptyMessage(201);

                    JSONArray Keys = Roles.names();

                    for (int i = 0; i < Keys.length(); i++) {
                        listOfRoles.add(new Role(Keys.getString(i), Roles.getString(Keys.getString(i))
                                .replaceFirst("^(https://|http://).*/roles/", "")));
                    }

                    handler.sendEmptyMessage(202);
                    handler.sendEmptyMessage(0);
                } catch (Exception e) {
                    Message msg = new Message();
                    Bundle data = new Bundle();
                    data.putString("exception", e.getMessage());
                    msg.setData(data);
                    msg.what = 1;
                    handler.sendMessage(msg);
                }
            }
            return;
        }
    };

    dataPreload.start();
    return inflater.inflate(R.layout.roles_landing, container, false);
}

From source file:com.aikidonord.fragments.FragmentDate.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    View view = inflater.inflate(R.layout.fragment_date, null /*container, false*/);

    View rlLoading = view.findViewById(R.id.loadingPanel);
    //View listView = view.getListView();

    if (VerifConnexion.isOnline(this.getActivity())) {
        rlLoading.setVisibility(View.VISIBLE);

        // on va fair l'impasse l dessus vu que je ne suis pas bien sr
        // de la manire dont il faut oprer tant que la vue n'a pas t renvoye.
        //listView.setVisibility(View.GONE);
        this.lancementAsync();
    } else {/*  www.  j av a 2s . c  om*/

        AlertDialog alertDialog = new AlertDialog.Builder(this.getActivity()).create();
        alertDialog.setTitle(getResources().getString(R.string.app_name));
        alertDialog.setMessage(getResources().getString(R.string.no_network));
        alertDialog.setIcon(R.drawable.ic_launcher);
        alertDialog.setCancelable(false);
        alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, getResources().getString(R.string.close),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        // if this button is clicked, close
                        // current activity
                        FragmentDate.this.getActivity().finish();
                    }
                });
        alertDialog.show();
    }

    return view;
}

From source file:com.aikidonord.fragments.FragmentLieu.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    View view = inflater.inflate(R.layout.fragment_lieu, null /*container, false*/);

    View rlLoading = view.findViewById(R.id.loadingPanel);
    //View listView = view.getListView();

    if (VerifConnexion.isOnline(this.getActivity())) {
        rlLoading.setVisibility(View.VISIBLE);

        // on va fair l'impasse l dessus vu que je ne suis pas bien sr
        // de la manire dont il faut oprer tant que la vue n'a pas t renvoye.
        //listView.setVisibility(View.GONE);
        this.lancementAsync();
    } else {//from  w w w. j a  v  a 2s  . com

        AlertDialog alertDialog = new AlertDialog.Builder(this.getActivity()).create();
        alertDialog.setTitle(getResources().getString(R.string.app_name));
        alertDialog.setMessage(getResources().getString(R.string.no_network));
        alertDialog.setIcon(R.drawable.ic_launcher);
        alertDialog.setCancelable(false);
        alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, getResources().getString(R.string.close),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        // if this button is clicked, close
                        // current activity
                        FragmentLieu.this.getActivity().finish();
                    }
                });
        alertDialog.show();
    }

    return view;
}

From source file:com.aikidonord.fragments.FragmentType.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    View view = inflater.inflate(R.layout.fragment_type, null /*container, false*/);

    View rlLoading = view.findViewById(R.id.loadingPanel);
    //View listView = view.getListView();

    if (VerifConnexion.isOnline(this.getActivity())) {
        rlLoading.setVisibility(View.VISIBLE);

        // on va fair l'impasse l dessus vu que je ne suis pas bien sr
        // de la manire dont il faut oprer tant que la vue n'a pas t renvoye.
        //listView.setVisibility(View.GONE);
        this.lancementAsync();
    } else {// w w w . jav  a 2  s .co  m

        AlertDialog alertDialog = new AlertDialog.Builder(this.getActivity()).create();
        alertDialog.setTitle(getResources().getString(R.string.app_name));
        alertDialog.setMessage(getResources().getString(R.string.no_network));
        alertDialog.setIcon(R.drawable.ic_launcher);
        alertDialog.setCancelable(false);
        alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, getResources().getString(R.string.close),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        // if this button is clicked, close
                        // current activity
                        FragmentType.this.getActivity().finish();
                    }
                });
        alertDialog.show();
    }

    return view;
}

From source file:edu.mum.ml.group7.guessasketch.android.EasyPaint.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    mPaint.setXfermode(null);// ww w  . j  av a  2s. co m
    mPaint.setAlpha(0xFF);

    switch (item.getItemId()) {
    case R.id.normal_brush_menu:
        mPaint.setShader(null);
        mPaint.setMaskFilter(null);
        return true;
    case R.id.color_menu:
        new ColorPickerDialog(this, this, mPaint.getColor()).show();
        return true;

    case R.id.size_menu: {
        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(R.layout.brush, (ViewGroup) findViewById(R.id.root));
        AlertDialog.Builder builder = new AlertDialog.Builder(this).setView(layout);
        builder.setTitle(R.string.choose_width);
        final AlertDialog alertDialog = builder.create();
        alertDialog.show();
        SeekBar sb = (SeekBar) layout.findViewById(R.id.brushSizeSeekBar);
        sb.setProgress(getStrokeSize());
        final TextView txt = (TextView) layout.findViewById(R.id.sizeValueTextView);
        txt.setText(
                String.format(getResources().getString(R.string.your_selected_size_is), getStrokeSize() + 1));
        sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            public void onProgressChanged(SeekBar seekBar, final int progress, boolean fromUser) {
                // Do something here with new value
                mPaint.setStrokeWidth(progress);
                txt.setText(
                        String.format(getResources().getString(R.string.your_selected_size_is), progress + 1));
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub
            }
        });
        return true;
    }
    case R.id.erase_menu: {
        LayoutInflater inflater_e = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View layout_e = inflater_e.inflate(R.layout.brush, (ViewGroup) findViewById(R.id.root));
        AlertDialog.Builder builder_e = new AlertDialog.Builder(this).setView(layout_e);
        builder_e.setTitle(R.string.choose_width);
        final AlertDialog alertDialog_e = builder_e.create();
        alertDialog_e.show();
        SeekBar sb_e = (SeekBar) layout_e.findViewById(R.id.brushSizeSeekBar);
        sb_e.setProgress(getStrokeSize());
        final TextView txt_e = (TextView) layout_e.findViewById(R.id.sizeValueTextView);
        txt_e.setText(
                String.format(getResources().getString(R.string.your_selected_size_is), getStrokeSize() + 1));
        sb_e.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            public void onProgressChanged(SeekBar seekBar, final int progress, boolean fromUser) {
                // Do something here with new value
                mPaint.setStrokeWidth(progress);
                txt_e.setText(
                        String.format(getResources().getString(R.string.your_selected_size_is), progress + 1));
            }

            public void onStartTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub
            }

            public void onStopTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub
            }
        });
        mPaint.setShader(null);
        mPaint.setXfermode(new PorterDuffXfermode(Mode.CLEAR));
        return true;
    }
    case R.id.clear_all_menu: {
        contentView.mBitmap.eraseColor(Color.TRANSPARENT);
        if (predictions != null) {
            resetPredictionsView(predictions, true);
        }
        return true;
    }
    case R.id.save_menu:
        sendScreenshot(false, ApiCallType.GUESS_IMAGE, "");
        break;

    case R.id.about_menu:
        startActivity(new Intent(this, AboutActivity.class));
        break;
    }
    return super.onOptionsItemSelected(item);
}

From source file:org.umit.icm.mobile.gui.ControlActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.controlactivity);
    WebsiteSuggestButton = (Button) this.findViewById(R.id.suggestWebsite);
    ServiceSuggestButton = (Button) this.findViewById(R.id.suggestService);
    scanButton = (Button) this.findViewById(R.id.scanButton);
    //        filterButton = (Button) this.findViewById(R.id.filterButton);
    //       servicesFilterButton = (Button) this.findViewById(R.id.serviceFilterButton);
    mapSelectionButton = (Button) this.findViewById(R.id.mapSelectionButton);
    enableTwitterButton = (Button) this.findViewById(R.id.enableTwitterButton);
    bugReportButton = (Button) this.findViewById(R.id.bugReportButton);
    aboutButton = (Button) this.findViewById(R.id.aboutButton);
    scanButton.setText(getString(R.string.scan_text) + " " + getString(R.string.scan_off));
    try {//from  w w  w  . j  a va 2  s  .c o m
        if (Globals.runtimeParameters.getTwitter().equals("Off")) {
            enableTwitterButton.setText(getString(R.string.enable_twitter_button));
        } else {
            enableTwitterButton.setText(getString(R.string.disable_twitter_button));
        }
    } catch (RuntimeException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    BroadcastReceiver receiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals("org.umit.icm.mobile.CONTROL_ACTIVITY")) {
                scanButton.setText(getString(R.string.scan_text) + " " + getString(R.string.scan_on));
            }
        }
    };

    registerReceiver(receiver, new IntentFilter("org.umit.icm.mobile.CONTROL_ACTIVITY"));

    WebsiteSuggestButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            WebsiteSuggestionDialog websiteSuggestionDialog = new WebsiteSuggestionDialog(ControlActivity.this,
                    "", new OnReadyListener());
            websiteSuggestionDialog.show();
        }

    });

    ServiceSuggestButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            ServiceSuggestionDialog suggestionDialog = new ServiceSuggestionDialog(ControlActivity.this, "",
                    new OnReadyListener());
            suggestionDialog.show();
        }

    });

    enableTwitterButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            try {
                if (Globals.runtimeParameters.getTwitter().equals("Off")) {
                    progressDialog = ProgressDialog.show(ControlActivity.this, getString(R.string.loading),
                            getString(R.string.retrieving_website), true, false);
                    new LaunchBrowser().execute();
                    TwitterDialog twitterDialog = new TwitterDialog(ControlActivity.this, "");
                    twitterDialog.show();
                    enableTwitterButton.setText(getString(R.string.disable_twitter_button));
                } else {
                    Globals.runtimeParameters.setTwitter("Off");
                    enableTwitterButton.setText(getString(R.string.enable_twitter_button));
                }
            } catch (RuntimeException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }

    });

    mapSelectionButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            MapSelectionDialog MapSelectionDialog = new MapSelectionDialog(ControlActivity.this, "");
            MapSelectionDialog.show();
        }

    });

    /*      filterButton.setOnClickListener(new OnClickListener() { 
     public void onClick(View v) {                                           
        Intent intent = new Intent(ControlActivity.this, WebsiteFilterActivity.class);                
       startActivity(intent); 
     }
            
           }  );
                  
          servicesFilterButton.setOnClickListener(new OnClickListener() { 
     public void onClick(View v) {                                           
        Intent intent = new Intent(ControlActivity.this, ServiceFilterActivity.class);                
       startActivity(intent); 
     }
            
           }  );*/

    bugReportButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent intent = new Intent(ControlActivity.this, BugReportActivity.class);
            startActivity(intent);
        }

    });

    aboutButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {

            String msg = getString(R.string.about_text) + "\n" + getString(R.string.link_to_open_monitor) + "\n"
                    + getString(R.string.link_to_umit) + "\n" + getString(R.string.icons_by);

            final SpannableString spannableString = new SpannableString(msg);
            Linkify.addLinks(spannableString, Linkify.ALL);

            AlertDialog alertDialog = new AlertDialog.Builder(ControlActivity.this).create();
            alertDialog.setTitle(getString(R.string.about_button));
            alertDialog.setMessage(spannableString);
            alertDialog.setIcon(R.drawable.umit_128);
            alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {

                    dialog.dismiss();

                }
            });
            alertDialog.show();

        }

    });

    scanButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if (Globals.scanStatus.equalsIgnoreCase(getString(R.string.scan_on))) {
                scanButton.setText(getString(R.string.scan_text) + " " + getString(R.string.scan_on));
                Globals.scanStatus = getString(R.string.scan_off);
                stopService(new Intent(ControlActivity.this, ConnectivityService.class));
            }

            else {
                scanButton.setText(getString(R.string.scan_text) + " " + getString(R.string.scan_off));
                Globals.scanStatus = getString(R.string.scan_on);
                startService(new Intent(ControlActivity.this, ConnectivityService.class));
            }

            try {
                Globals.runtimeParameters.setScanStatus(Globals.scanStatus);
            } catch (RuntimeException e) {
                e.printStackTrace();
            }

            Context context = getApplicationContext();
            CharSequence text = getString(R.string.toast_scan_change) + " " + Globals.scanStatus;
            int duration = Toast.LENGTH_SHORT;

            Toast toast = Toast.makeText(context, text, duration);
            toast.show();
        }

    });

}