Example usage for android.widget Toast show

List of usage examples for android.widget Toast show

Introduction

In this page you can find the example usage for android.widget Toast show.

Prototype

public void show() 

Source Link

Document

Show the view for the specified duration.

Usage

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

public void onCheckedChanged(final CompoundButton buttonView, boolean isChecked) {
    if (isChecked) {
        // If NFC is on
        if (nfcAdapter.isEnabled()) {
            try {
                // If no PIN remembered, toast user to enter a PIN
                if (settings.getString("pin").equals("")) {
                    Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_lock_set_pin,
                            Toast.LENGTH_LONG);
                    toast.show();

                    buttonView.setChecked(false);
                }//from  w w w .j ava2  s.c om

                // If no NFC Tag remembered, toast user to scan an NFC Tag
                else if (tags.length() == 0) {
                    Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_lock_add_tag,
                            Toast.LENGTH_LONG);
                    toast.show();

                    // Set lockscreen false, stop service and store
                    try {
                        if (settings.getBoolean("lockscreen")) {
                            settings.put("lockscreen", false);

                            enabled_disabled.setText(R.string.lockscreen_disabled);
                            enabled_disabled.setTextColor(getResources().getColor(R.color.red));
                        }

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

                    writeToJSON();

                    killService(this);

                    buttonView.setChecked(false);
                }

                // If everything ok, set lockscreen true, start service and store
                else {
                    if (!onStart) {
                        try {
                            settings.put("lockscreen", true);

                            enabled_disabled.setText(R.string.lockscreen_enabled);
                            enabled_disabled.setTextColor(getResources().getColor(R.color.green));

                            startService(new Intent(this, ScreenLockService.class));

                            Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_lock_enabled,
                                    Toast.LENGTH_SHORT);
                            toast.show();

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

                        writeToJSON();
                        return;
                    }

                    onStart = false;
                    startService(new Intent(this, ScreenLockService.class));
                }

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

        // NFC is off, prompt user to enable it and send him to NFC settings
        else {
            new AlertDialog.Builder(this).setTitle(R.string.nfc_off_dialog_title)
                    .setMessage(R.string.nfc_off_dialog_message)
                    .setPositiveButton(R.string.yes_button, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Intent intent = new Intent(Settings.ACTION_NFC_SETTINGS);
                            startActivity(intent);
                        }
                    }).setNegativeButton(R.string.no_button, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            //Do nothing, close dialog
                        }
                    }).show();

            // Set lockscreen false, stop service and store
            try {
                if (settings.getBoolean("lockscreen"))
                    settings.put("lockscreen", false);

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

            writeToJSON();

            enabled_disabled.setText(R.string.lockscreen_disabled);
            enabled_disabled.setTextColor(getResources().getColor(R.color.red));

            killService(this);

            buttonView.setChecked(false);
        }
    }

    // If unchecked, set lockscreen false, stop service and store
    else {
        try {
            settings.put("lockscreen", false);

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

        writeToJSON();

        enabled_disabled.setText(R.string.lockscreen_disabled);
        enabled_disabled.setTextColor(getResources().getColor(R.color.red));

        killService(this);

        Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_lock_disabled, Toast.LENGTH_SHORT);
        toast.show();
    }
}

From source file:edu.sfsu.cs.orange.ocr.CaptureActivity.java

/**
 * Displays information relating to the result of OCR, and requests a translation if necessary.
 * /*from w ww .  ja  v  a  2 s.com*/
 * @param ocrResult Object representing successful OCR results
 * @return True if a non-null result was received for OCR
 */
boolean handleOcrDecode(OcrResult ocrResult) {
    lastResult = ocrResult;

    // Test whether the result is null
    if (ocrResult.getText() == null || ocrResult.getText().equals("")) {
        Toast toast = Toast.makeText(this, "OCR failed. Please try again.", Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.TOP, 0, 0);
        toast.show();
        return false;
    }

    // Turn off capture-related UI elements
    shutterButton.setVisibility(View.GONE);
    statusViewBottom.setVisibility(View.GONE);
    statusViewTop.setVisibility(View.GONE);
    cameraButtonView.setVisibility(View.GONE);
    viewfinderView.setVisibility(View.GONE);
    resultView.setVisibility(View.VISIBLE);

    ImageView bitmapImageView = (ImageView) findViewById(R.id.image_view);
    lastBitmap = ocrResult.getBitmap();
    if (lastBitmap == null) {
        bitmapImageView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher));
    } else {
        bitmapImageView.setImageBitmap(lastBitmap);
    }

    // Display the recognized text
    TextView sourceLanguageTextView = (TextView) findViewById(R.id.source_language_text_view);
    sourceLanguageTextView.setText(sourceLanguageReadable);
    TextView ocrResultTextView = (TextView) findViewById(R.id.ocr_result_text_view);
    ocrResultTextView.setText(ocrResult.getText());

    String rawText = ocrResult.getText();
    rawText.split("\n");
    String[] beerNames = rawText.split("\n");

    for (String beer : beerNames) {
        beerQuery.asyncBeerFetch(beer, aq);
    }

    ocrResultTextView.setText(aq.getText());

    // Crudely scale betweeen 22 and 32 -- bigger font for shorter text
    int scaledSize = Math.max(22, 32 - ocrResult.getText().length() / 4);
    ocrResultTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, scaledSize);

    TextView translationLanguageLabelTextView = (TextView) findViewById(
            R.id.translation_language_label_text_view);
    TextView translationLanguageTextView = (TextView) findViewById(R.id.translation_language_text_view);
    TextView translationTextView = (TextView) findViewById(R.id.translation_text_view);

    translationLanguageLabelTextView.setVisibility(View.GONE);
    translationLanguageTextView.setVisibility(View.GONE);
    translationTextView.setVisibility(View.GONE);
    progressView.setVisibility(View.GONE);
    setProgressBarVisibility(false);

    return true;
}

From source file:org.cryptsecure.Utility.java

/**
 * Show toast in ui thread./*from w  w  w  .  ja v a  2s .c o m*/
 * 
 * @param context
 *            the context
 * @param toastText
 *            the toast text
 */
public static void showToastInUIThread(final Context context, final String toastText) {
    int duration = Toast.LENGTH_SHORT;
    Toast toast = Toast.makeText(context, toastText, duration);
    toast.show();
}

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

@Override
public boolean onContextItemSelected(MenuItem item) {
    // Get pressed item information
    final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();

    // If Rename Tag pressed
    if (item.getTitle().equals(getResources().getString(R.string.rename_context_menu))) {
        // Create new EdiText and configure
        final EditText tagTitle = new EditText(this);
        tagTitle.setSingleLine(true);//from w  w w.j a  v a  2s .  c  o  m
        tagTitle.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);

        // Set tagTitle maxLength
        int maxLength = 50;
        InputFilter[] array = new InputFilter[1];
        array[0] = new InputFilter.LengthFilter(maxLength);
        tagTitle.setFilters(array);

        // Get tagName text into EditText
        try {
            assert info != null;
            tagTitle.setText(tags.getJSONObject(info.position).getString("tagName"));

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

        final LinearLayout l = new LinearLayout(this);

        l.setOrientation(LinearLayout.VERTICAL);
        l.addView(tagTitle);

        // Show rename dialog
        new AlertDialog.Builder(this).setTitle(R.string.rename_tag_dialog_title).setView(l)
                .setPositiveButton(R.string.rename_tag_dialog_button, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // 'Rename' pressed, change tagName and store
                        try {
                            JSONObject newTagName = tags.getJSONObject(info.position);
                            newTagName.put("tagName", tagTitle.getText());

                            tags.put(info.position, newTagName);
                            adapter.notifyDataSetChanged();

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

                        writeToJSON();

                        Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_tag_renamed,
                                Toast.LENGTH_SHORT);
                        toast.show();

                        imm.hideSoftInputFromWindow(tagTitle.getWindowToken(), 0);

                    }
                }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        imm.hideSoftInputFromWindow(tagTitle.getWindowToken(), 0);
                    }
                }).show();
        tagTitle.requestFocus();
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);

        return true;
    }

    // If Delete Tag pressed
    else if (item.getTitle().equals(getResources().getString(R.string.delete_context_menu))) {
        // Construct dialog message
        String dialogMessage = "";

        assert info != null;
        try {
            dialogMessage = getResources().getString(R.string.delete_context_menu_dialog1) + " '"
                    + tags.getJSONObject(info.position).getString("tagName") + "'?";

        } catch (JSONException e) {
            e.printStackTrace();
            dialogMessage = getResources().getString(R.string.delete_context_menu_dialog2);
        }

        // Show delete dialog
        new AlertDialog.Builder(this).setMessage(dialogMessage)
                .setPositiveButton(R.string.yes_button, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        JSONArray newArray = new JSONArray();

                        // Copy contents to new array, without the deleted item
                        for (int i = 0; i < tags.length(); i++) {
                            if (i != info.position) {
                                try {
                                    newArray.put(tags.get(i));

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

                        // Equal original array to new array
                        tags = newArray;

                        // Write to file
                        try {
                            settings.put("tags", tags);
                            root.put("settings", settings);

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

                        writeToJSON();

                        adapter.adapterData = tags;
                        adapter.notifyDataSetChanged();

                        updateListViewHeight(listView);

                        // If no tags, show 'Press + to add Tags' textView
                        if (tags.length() == 0)
                            noTags.setVisibility(View.VISIBLE);

                        else
                            noTags.setVisibility(View.INVISIBLE);

                        Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_tag_deleted,
                                Toast.LENGTH_SHORT);
                        toast.show();

                    }
                }).setNegativeButton(R.string.no_button, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // Do nothing, close dialog
                    }
                }).show();

        return true;
    }

    return super.onContextItemSelected(item);
}

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  www . j a  v a 2 s. com*/
                    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:org.cryptsecure.Utility.java

/**
 * Show toast short async from non-UI thread.
 * /*from   w  w  w . ja va2  s  . c om*/
 * @param context
 *            the context
 * @param toastText
 *            the toast text
 */
public static void showToastShortAsync(final Context context, final String toastText) {
    final Handler mUIHandler = new Handler(Looper.getMainLooper());
    mUIHandler.post(new Thread() {
        @Override
        public void run() {
            super.run();
            int duration = Toast.LENGTH_SHORT;
            Toast toast = Toast.makeText(context, toastText, duration);
            toast.show();
        }
    });
}

From source file:org.cryptsecure.Utility.java

/**
 * Show toast async from non-UI thread.//ww  w  .  j a v a  2s .c om
 * 
 * @param context
 *            the context
 * @param toastText
 *            the toast text
 */
public static void showToastAsync(final Context context, final String toastText) {
    final Handler mUIHandler = new Handler(Looper.getMainLooper());
    mUIHandler.post(new Thread() {
        @Override
        public void run() {
            super.run();
            int duration = Toast.LENGTH_LONG;
            Toast toast = Toast.makeText(context, toastText, duration);
            toast.show();
        }
    });
}

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

@Override
public void onClick(View v) {
    // If OK(setPin) clicked, ask user if sure; if yes, store PIN; else, go back
    if (v.getId() == R.id.setPin) {
        // If PIN length between 4 and 6, store PIN and toast successful
        if (pinEdit.length() >= 4 && pinEdit.length() <= 6) {
            new AlertDialog.Builder(this).setMessage(R.string.set_pin_confirmation)
                    .setPositiveButton(R.string.yes_button, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            try {
                                settings.put("pin", String.valueOf(pinEdit.getText()));

                            } catch (JSONException e) {
                                e.printStackTrace();
                            }// w  ww .  jav a 2s  .  co m

                            writeToJSON();

                            Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_pin_set,
                                    Toast.LENGTH_SHORT);
                            toast.show();

                            imm.hideSoftInputFromWindow(pinEdit.getWindowToken(), 0);

                        }
                    }).setNegativeButton(R.string.no_button, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            imm.hideSoftInputFromWindow(pinEdit.getWindowToken(), 0);
                            // Do nothing, close dialog
                        }
                    }).show();
        }

        // Toast user that PIN needs to be at least 4 digits long
        else {
            Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_pin_needs4digits,
                    Toast.LENGTH_LONG);
            toast.show();
        }
    }

    // If 'Refresh wallpaper' pressed, check if Android 4.2 or above, if yes
    // Store new blur var, if blur bigger than 0 re-blur wallpaper
    else if (v.getId() == R.id.refreshWallpaper) {
        if (Build.VERSION.SDK_INT > 16) {
            try {
                settings.put("blur", blur);

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

            writeToJSON();

            // If blur is 0, don't change anything, just toast
            if (blur == 0) {
                Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_wallpaper_refreshed,
                        Toast.LENGTH_SHORT);
                toast.show();
            }

            // If blur is bigger than 0, get default wallpaper - to bitmap - fastblur bitmap - store
            else {
                // Check if TapUnlock folder exists, if not, create directory
                File folder = new File(Environment.getExternalStorageDirectory() + "/TapUnlock");
                boolean folderSuccess = true;

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

                if (folderSuccess) {
                    WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
                    final Drawable wallpaperDrawable = wallpaperManager.peekFastDrawable();

                    if (wallpaperDrawable != null) {
                        // Display indeterminate progress bar while blurring
                        progressBar.setVisibility(View.VISIBLE);

                        new Thread(new Runnable() {
                            @Override
                            public void run() {
                                Bitmap bitmapToBlur = ImageUtils.drawableToBitmap(wallpaperDrawable);

                                Bitmap blurredWallpaper = null;
                                if (bitmapToBlur != null)
                                    blurredWallpaper = ImageUtils.fastBlur(MainActivity.this, bitmapToBlur,
                                            blur);

                                boolean stored = false;
                                if (blurredWallpaper != null) {
                                    stored = ImageUtils.storeImage(blurredWallpaper);

                                    final boolean finalStored = stored;
                                    runOnUiThread(new Runnable() {
                                        @Override
                                        public void run() {
                                            progressBar.setVisibility(View.INVISIBLE);

                                            if (finalStored) {
                                                Toast toast = Toast.makeText(getApplicationContext(),
                                                        R.string.toast_wallpaper_refreshed, Toast.LENGTH_SHORT);
                                                toast.show();
                                            }
                                        }
                                    });
                                }

                                if (bitmapToBlur == null || blurredWallpaper == null || !stored) {
                                    runOnUiThread(new Runnable() {
                                        @Override
                                        public void run() {
                                            progressBar.setVisibility(View.INVISIBLE);

                                            Toast toast = Toast.makeText(getApplicationContext(),
                                                    R.string.toast_wallpaper_not_refreshed, Toast.LENGTH_SHORT);
                                            toast.show();
                                        }
                                    });
                                }
                            }
                        }).start();
                    }

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

        // If Android version less than 4.2, display toast cannot blur
        else {
            Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_cannot_blur,
                    Toast.LENGTH_SHORT);
            toast.show();
        }
    }

    // If '+' pressed
    else if (v.getId() == R.id.newTag) {
        if (nfcAdapter != null) {
            // If NFC is on, show scan dialog and enableForegroundDispatch
            if (nfcAdapter.isEnabled()) {
                nfcAdapter.enableForegroundDispatch(this, pIntent,
                        new IntentFilter[] { new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED) },
                        new String[][] { new String[] { "android.nfc.tech.MifareClassic" },
                                new String[] { "android.nfc.tech.MifareUltralight" },
                                new String[] { "android.nfc.tech.NfcA" },
                                new String[] { "android.nfc.tech.NfcB" },
                                new String[] { "android.nfc.tech.NfcF" },
                                new String[] { "android.nfc.tech.NfcV" },
                                new String[] { "android.nfc.tech.Ndef" },
                                new String[] { "android.nfc.tech.IsoDep" },
                                new String[] { "android.nfc.tech.NdefFormatable" } });

                MainActivity.this.showDialog(DIALOG_READ);
            }

            // NFC is off, prompt user to enable it and send him to NFC settings
            else {
                new AlertDialog.Builder(this).setTitle(R.string.nfc_off_dialog_title)
                        .setMessage(R.string.nfc_off_dialog_message)
                        .setPositiveButton(R.string.yes_button, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                Intent intent = new Intent(Settings.ACTION_NFC_SETTINGS);
                                startActivity(intent);
                            }
                        }).setNegativeButton(R.string.no_button, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                // Do nothing, close dialog
                            }
                        }).show();
            }
        }

        // NFC adapter is null
        else {
            new AlertDialog.Builder(this).setTitle(R.string.nfc_off_dialog_title)
                    .setMessage(R.string.nfc_off_dialog_message)
                    .setPositiveButton(R.string.yes_button, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Intent intent = new Intent(Settings.ACTION_NFC_SETTINGS);
                            startActivity(intent);
                        }
                    }).setNegativeButton(R.string.no_button, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            // Do nothing, close dialog
                        }
                    }).show();
        }
    }
}

From source file:reportsas.com.formulapp.Formulario.java

public void insertarEncuentas(EncuestaRespuesta res) {
    try {//from  w  ww  . j a va  2 s  .  c o  m
        dbAdapter.abrir();
        ContentValues contentValues = new ContentValues();
        contentValues.put("IdUsuario", res.getIdUsuario());
        contentValues.put("IdEncuesta", res.getIdEncuesta());
        contentValues.put("Fecha_Realizacion", res.getFecha());
        contentValues.put("consecutivo", res.getConsecutivo());
        if (dbAdapter.Insertar("Encuesta_Repuesta", contentValues) > 0) {
            for (int i = 0; i < res.getRespuesta().size(); i++) {
                PreguntaRespuesta preguntR = res.getRespuesta().get(i);
                contentValues = new ContentValues();
                contentValues.put("IdUsuario", res.getIdUsuario());
                contentValues.put("IdEncuesta", res.getIdEncuesta());
                contentValues.put("consecutivo", res.getConsecutivo());
                contentValues.put("item", preguntR.getItem());
                contentValues.put("IdPregunta", preguntR.getIdPregunta());
                contentValues.put("repuesta", preguntR.getRespuesta());
                if (preguntR.getOpcion() != null) {

                    contentValues.put("opcion", preguntR.getOpcion());
                } else {
                    contentValues.putNull("opcion");
                }
                if (dbAdapter.Insertar("Pregunta_Respuesta", contentValues) > 0) {

                }
            }

            for (int k = 0; k < res.getParametros().size(); k++) {
                ParametrosRespuesta paramR = res.getParametros().get(k);
                contentValues = new ContentValues();
                contentValues.put("IdUsuario", res.getIdUsuario());
                contentValues.put("IdEncuesta", res.getIdEncuesta());
                contentValues.put("consecutivo", res.getConsecutivo());
                contentValues.put("IdParametro", paramR.getIdParametro());
                contentValues.put("valor", paramR.getValor());
                if (dbAdapter.Insertar("Parametro_Encuesta_Respuesta", contentValues) > 0) {

                }
            }

            Toast toast1 = Toast.makeText(Formulario.this, "Fromulario Enviado", Toast.LENGTH_SHORT);
            toast1.show();
            reiniciarActivity(this, idFormulario);
        }

        dbAdapter.cerrar();
    } catch (SQLException e) {
        e.printStackTrace();
    }
}

From source file:flex.android.magiccube.activity.ActivityBattleMode.java

private void ReadMessage(String Message) throws JSONException {

    JSONObject jobj = new JSONObject(Message);
    String value = "";

    if ((value = jobj.optString(BluetoothSignal.Leave)) != "") {
        this.HeartBeating = false;
        if (mChatService != null) {
            // mChatService.stop();
            // mChatService = null;
            Toast toast = Toast.makeText(this, "", Toast.LENGTH_LONG);
            toast.setGravity(Gravity.BOTTOM, 0, height / 11);
            toast.show();
        }/*from   ww w .  j av  a2 s  . c om*/
        this.opleaved = true;
    }
    if ((value = jobj.optString(BluetoothSignal.ReSetup)) != "") {
        ResetViews();
        if (MagiccubePreference.GetPreference(MagiccubePreference.ServerOrClient, this) == 1) {
            SetupGame();
        }
    }
    if ((value = jobj.optString(BluetoothSignal.MessUpCmd1)) != "") {
        // Log.e("MessUpCmd1","MessUpCmd1");
        HeartBeating = true;
        glView.MessUp(value);
    }
    if ((value = jobj.optString(BluetoothSignal.MessUpCmd2)) != "") {
        HeartBeating = true;
        glView2.MessUp(value);
    }
    if ((value = jobj.optString(BluetoothSignal.ObserveTime)) != "") {
        HeartBeating = true;
        TotalObTime = Integer.parseInt(value);

        uihandler.sendEmptyMessage(0);
    }
    if ((value = jobj.optString(BluetoothSignal.EndSetUp)) != "") {
        HeartBeating = true;
        JSONObject jobj2 = new JSONObject();
        jobj2.put(BluetoothSignal.ClientEndSetUp, "end");
        // Log.e("EndSetUp","EndSetUp");
        waitClose2();
        // Init();
        this.sendMessage(jobj2.toString());
        uihandler.sendEmptyMessage(0);
    }
    if ((value = jobj.optString(BluetoothSignal.ClientEndSetUp)) != "") {
        // Log.e("ClientEndSetUp","ClientEndSetUp");
        waitClose2();
        // Init();
        uihandler.sendEmptyMessage(0);
    }
    if ((value = jobj.optString(BluetoothSignal.Command)) != "") {
        glView2.SetCommand(value);
        if (MoveTimes2 == "") {
            MoveTimes2 += "" + this.MoveTime;
        } else {
            MoveTimes2 += " " + this.MoveTime;
        }
    }
    if ((value = jobj.optString(BluetoothSignal.StartObserve)) != "") {
        uihandler.sendEmptyMessage(5);
        StartOb();
    }
    if ((value = jobj.optString(BluetoothSignal.Win)) != "") {
        this.MoveTime = Integer.parseInt(value);
        this.txtTime.setText("" + Util.TimeFormat(ActivityBattleMode.this.MoveTime));
        glView.OnStateChanged(OnStateListener.LOSE);
        this.OnStateChanged(OnStateListener.LOSE);
    }

}