Example usage for android.app AlertDialog setTitle

List of usage examples for android.app AlertDialog setTitle

Introduction

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

Prototype

@Override
    public void setTitle(CharSequence title) 

Source Link

Usage

From source file:cm.aptoide.pt.ManageRepo.java

private void editRepo(final String repo) {
    LayoutInflater li = LayoutInflater.from(this);
    View view = li.inflate(R.layout.addrepo, null);
    Builder p = new AlertDialog.Builder(this).setView(view);
    final AlertDialog alrt = p.create();
    final EditText uri = (EditText) view.findViewById(R.id.edit_uri);
    uri.setText(repo);/*from   w ww  . j  av  a2 s  . c o m*/

    final EditText sec_user = (EditText) view.findViewById(R.id.sec_user);
    final EditText sec_pwd = (EditText) view.findViewById(R.id.sec_pwd);
    final CheckBox sec = (CheckBox) view.findViewById(R.id.secure_chk);
    sec.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                sec_user.setEnabled(true);
                sec_pwd.setEnabled(true);
            } else {
                sec_user.setEnabled(false);
                sec_pwd.setEnabled(false);
            }
        }
    });

    String[] logins = null;
    logins = db.getLogin(repo);
    if (logins != null) {
        sec.setChecked(true);
        sec_user.setText(logins[0]);
        sec_pwd.setText(logins[1]);
    } else {
        sec.setChecked(false);
    }

    alrt.setIcon(android.R.drawable.ic_menu_add);
    alrt.setTitle("Edit repository");
    alrt.setButton("Done", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            String new_repo = uri.getText().toString();
            db.updateServer(repo, new_repo);
            if (sec.isChecked()) {
                db.addLogin(sec_user.getText().toString(), sec_pwd.getText().toString(), new_repo);
            } else {
                db.disableLogin(new_repo);
            }
            change = true;
            redraw();
        }
    });

    alrt.setButton2("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            return;
        }
    });
    alert2.dismiss();
    alrt.show();
}

From source file:com.xperia64.timidityae.TimidityActivity.java

public void dynExport() {
    localfinished = false;//  w  w  w.  j  a v  a 2  s  .  com
    if (Globals.isMidi(currSongName) && Globals.isPlaying == 0) {

        AlertDialog.Builder alert = new AlertDialog.Builder(this);

        alert.setTitle(getResources().getString(R.string.dynex_alert1));
        alert.setMessage(getResources().getString(R.string.dynex_alert1_msg));
        InputFilter filter = new InputFilter() {
            public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
                    int dend) {
                for (int i = start; i < end; i++) {
                    String IC = "*/*\n*\r*\t*\0*\f*`*?***\\*<*>*|*\"*:*";
                    if (IC.contains("*" + source.charAt(i) + "*")) {
                        return "";
                    }
                }
                return null;
            }
        };
        final EditText input = new EditText(this);
        input.setFilters(new InputFilter[] { filter });
        alert.setView(input);

        alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                String value = input.getText().toString();
                if (!value.toLowerCase(Locale.US).endsWith(".wav"))
                    value += ".wav";
                String parent = currSongName.substring(0, currSongName.lastIndexOf('/') + 1);
                boolean alreadyExists = new File(parent + value).exists();
                boolean aWrite = true;
                String needRename = null;
                String probablyTheRoot = "";
                String probablyTheDirectory = "";
                try {
                    new FileOutputStream(parent + value, true).close();
                } catch (FileNotFoundException e) {
                    aWrite = false;
                } catch (IOException e) {
                    e.printStackTrace();
                }

                if (aWrite && !alreadyExists)
                    new File(parent + value).delete();

                if (aWrite && new File(parent).canWrite()) {
                    value = parent + value;
                } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && Globals.theFold != null) {
                    String[] tmp = Globals.getDocFilePaths(TimidityActivity.this, parent);
                    probablyTheDirectory = tmp[0];
                    probablyTheRoot = tmp[1];
                    if (probablyTheDirectory.length() > 1) {
                        needRename = parent
                                .substring(parent.indexOf(probablyTheRoot) + probablyTheRoot.length()) + value;
                        value = probablyTheDirectory + '/' + value;
                    } else {
                        value = Environment.getExternalStorageDirectory().getAbsolutePath() + '/' + value;
                    }
                } else {
                    value = Environment.getExternalStorageDirectory().getAbsolutePath() + '/' + value;
                }
                final String finalval = value;
                final boolean canWrite = aWrite;
                final String needToRename = needRename;
                final String probRoot = probablyTheRoot;
                if (new File(finalval).exists()
                        || (new File(probRoot + needRename).exists() && needToRename != null)) {
                    AlertDialog dialog2 = new AlertDialog.Builder(TimidityActivity.this).create();
                    dialog2.setTitle(getResources().getString(R.string.warning));
                    dialog2.setMessage(getResources().getString(R.string.dynex_alert2_msg));
                    dialog2.setCancelable(false);
                    dialog2.setButton(DialogInterface.BUTTON_POSITIVE,
                            getResources().getString(android.R.string.yes),
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int buttonId) {
                                    if (!canWrite && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                                        if (needToRename != null) {
                                            Globals.tryToDeleteFile(TimidityActivity.this,
                                                    probRoot + needToRename);
                                            Globals.tryToDeleteFile(TimidityActivity.this, finalval);
                                        } else {
                                            Globals.tryToDeleteFile(TimidityActivity.this, finalval);
                                        }
                                    } else {
                                        new File(finalval).delete();
                                    }
                                    saveWavPart2(finalval, needToRename);
                                }
                            });
                    dialog2.setButton(DialogInterface.BUTTON_NEGATIVE,
                            getResources().getString(android.R.string.no),
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int buttonId) {

                                }
                            });
                    dialog2.show();
                } else {
                    saveWavPart2(finalval, needToRename);
                }

            }
        });

        alert.setNegativeButton(getResources().getString(R.string.cancel),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        // Canceled.
                    }
                });

        alerty = alert.show();

    }
}

From source file:com.xperia64.timidityae.TimidityActivity.java

public void saveCfg() {
    localfinished = false;//w  w  w. j av a 2  s. co m
    if (Globals.isMidi(currSongName) && Globals.isPlaying == 0) {

        AlertDialog.Builder alert = new AlertDialog.Builder(this);

        alert.setTitle("Save Cfg");
        alert.setMessage("Save a MIDI configuration file");
        InputFilter filter = new InputFilter() {
            public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
                    int dend) {
                for (int i = start; i < end; i++) {
                    String IC = "*/*\n*\r*\t*\0*\f*`*?***\\*<*>*|*\"*:*";
                    if (IC.contains("*" + source.charAt(i) + "*")) {
                        return "";
                    }
                }
                return null;
            }
        };
        // Set an EditText view to get user input 
        final EditText input = new EditText(this);
        input.setFilters(new InputFilter[] { filter });
        alert.setView(input);

        alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                String value = input.getText().toString();
                if (!value.toLowerCase(Locale.US).endsWith(Globals.compressCfg ? ".tzf" : ".tcf"))
                    value += (Globals.compressCfg ? ".tzf" : ".tcf");
                String parent = currSongName.substring(0, currSongName.lastIndexOf('/') + 1);
                boolean aWrite = true;
                boolean alreadyExists = new File(parent + value).exists();
                String needRename = null;
                String probablyTheRoot = "";
                String probablyTheDirectory = "";
                try {
                    new FileOutputStream(parent + value, true).close();
                } catch (FileNotFoundException e) {
                    aWrite = false;
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (!alreadyExists && aWrite)
                    new File(parent + value).delete();
                if (aWrite && new File(parent).canWrite()) {
                    value = parent + value;
                } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && Globals.theFold != null) {
                    //TODO
                    // Write the file to getExternalFilesDir, then move it with the Uri
                    // We need to tell JNIHandler that movement is needed.

                    String[] tmp = Globals.getDocFilePaths(TimidityActivity.this, parent);
                    probablyTheDirectory = tmp[0];
                    probablyTheRoot = tmp[1];
                    if (probablyTheDirectory.length() > 1) {
                        needRename = parent
                                .substring(parent.indexOf(probablyTheRoot) + probablyTheRoot.length()) + value;
                        value = probablyTheDirectory + '/' + value;
                    } else {
                        value = Environment.getExternalStorageDirectory().getAbsolutePath() + '/' + value;
                        return;
                    }
                } else {
                    value = Environment.getExternalStorageDirectory().getAbsolutePath() + '/' + value;
                }
                final String finalval = value;
                final boolean canWrite = aWrite;
                final String needToRename = needRename;
                final String probRoot = probablyTheRoot;
                if (new File(finalval).exists()
                        || (new File(probRoot + needRename).exists() && needToRename != null)) {
                    AlertDialog dialog2 = new AlertDialog.Builder(TimidityActivity.this).create();
                    dialog2.setTitle("Warning");
                    dialog2.setMessage("Overwrite config file?");
                    dialog2.setCancelable(false);
                    dialog2.setButton(DialogInterface.BUTTON_POSITIVE,
                            getResources().getString(android.R.string.yes),
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int buttonId) {
                                    if (!canWrite && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                                        if (needToRename != null) {
                                            Globals.tryToDeleteFile(TimidityActivity.this,
                                                    probRoot + needToRename);
                                            Globals.tryToDeleteFile(TimidityActivity.this, finalval);
                                        } else {
                                            Globals.tryToDeleteFile(TimidityActivity.this, finalval);
                                        }
                                    } else {
                                        new File(finalval).delete();
                                    }
                                    saveCfgPart2(finalval, needToRename);
                                }
                            });
                    dialog2.setButton(DialogInterface.BUTTON_NEGATIVE,
                            getResources().getString(android.R.string.no),
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int buttonId) {

                                }
                            });
                    dialog2.show();
                } else {
                    saveCfgPart2(finalval, needToRename);
                }
            }
        });

        alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                // Canceled.
            }
        });

        alerty = alert.show();
    }
}

From source file:no.barentswatch.fiskinfo.BaseActivity.java

/**
 * This functions creates a dialog which allows the user to export different
 * map layers./*from  w w w . ja v a 2 s. c  om*/
 * 
 * @param ActivityContext
 *            The context of the current activity.
 * @return True if the export succeeded, false otherwise.
 */
public boolean exportMapLayerToUser(Context activityContext) {
    LayoutInflater layoutInflater = getLayoutInflater();
    View view = layoutInflater.inflate(R.layout.dialog_export_metadata, (null));

    Button downloadButton = (Button) view.findViewById(R.id.metadataDownloadButton);
    Button cancelButton = (Button) view.findViewById(R.id.cancel_button);

    final AlertDialog builder = new AlertDialog.Builder(activityContext).create();
    builder.setTitle(R.string.map_export_metadata_title);
    builder.setView(view);
    final AtomicReference<String> selectedHeader = new AtomicReference<String>();
    final AtomicReference<String> selectedFormat = new AtomicReference<String>();
    final ExpandableListView expListView = (ExpandableListView) view
            .findViewById(R.id.exportMetadataMapServices);
    final List<String> listDataHeader = new ArrayList<String>();
    final HashMap<String, List<String>> listDataChild = new HashMap<String, List<String>>();
    final Map<String, String> nameToApiNameResolver = new HashMap<String, String>();

    JSONArray availableSubscriptions = getSharedCacheOfAvailableSubscriptions();
    if (availableSubscriptions == null) {
        availableSubscriptions = authenticatedGetRequestToBarentswatchAPIService(
                getString(R.string.my_page_geo_data_service));
        setSharedCacheOfAvailableSubscriptions(availableSubscriptions);
    }

    for (int i = 0; i < availableSubscriptions.length(); i++) {
        try {
            JSONObject currentSub = availableSubscriptions.getJSONObject(i);
            nameToApiNameResolver.put(currentSub.getString("Name"), currentSub.getString("ApiName"));
            listDataHeader.add(currentSub.getString("Name"));
            List<String> availableDownloadFormatsOfCurrentLayer = new ArrayList<String>();
            JSONArray availableFormats = currentSub.getJSONArray("Formats");
            for (int j = 0; j < availableFormats.length(); j++) {
                availableDownloadFormatsOfCurrentLayer.add(availableFormats.getString(j));
            }
            listDataChild.put(listDataHeader.get(i), availableDownloadFormatsOfCurrentLayer);

            System.out
                    .println("item: " + currentSub.getString("Name") + ", " + currentSub.getString("ApiName"));
        } catch (JSONException e) {
            e.printStackTrace();
            Log.d("ExportMapLAyerToUser", "Invalid JSON returned from API CALL");
            return false;
        }
    }
    final ExpandableListAdapter listAdapter = new ExpandableListAdapter(activityContext, listDataHeader,
            listDataChild);
    expListView.setAdapter(listAdapter);

    // Listview on child click listener
    expListView.setOnChildClickListener(new OnChildClickListener() {

        @Override
        public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition,
                long id) {
            selectedHeader.set(nameToApiNameResolver.get(listDataHeader.get(groupPosition)));
            selectedHeader.set(listDataHeader.get(groupPosition));
            selectedFormat.set(listDataChild.get(listDataHeader.get(groupPosition)).get(childPosition));

            LinearLayout currentlySelected = (LinearLayout) parent.findViewWithTag("currentlySelectedRow");
            if (currentlySelected != null) {
                currentlySelected.getChildAt(0).setBackgroundColor(Color.WHITE);
                currentlySelected.setTag(null);
            }

            ((LinearLayout) v).getChildAt(0).setBackgroundColor(Color.rgb(214, 214, 214));
            v.setTag("currentlySelectedRow");

            return true;
        }
    });

    downloadButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            new DownloadMapLayerFromBarentswatchApiInBackground()
                    .execute(nameToApiNameResolver.get(selectedHeader.get()), selectedFormat.get());
            builder.dismiss();
        }
    });

    cancelButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            builder.dismiss();
        }
    });

    builder.setCanceledOnTouchOutside(false);
    builder.show();

    return true;
}

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

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // if statement prevents force close error when picture isn't selected
    if (progressDialog != null) {
        progressDialog.dismiss();/*from  w w  w.ja  v  a2  s.c o  m*/
    }
    if (requestCode == 6) {
        serverHelper.getInstance().setCallback(this, this);
        saveCSS = prefs.getString("clipStyle", "1").equals("1");
        //Log.i("nimbus",saveCSS==true?"true":"false");
        wv.eval(String.format("javascript:android.fvdSaveCss(%s)", saveCSS == true ? "true" : "false"));
        if ("1".equals(prefs.getString("userAgent", "1"))) {
            wv.setUserAgent(null);
        } else
            wv.setUserAgent(deskAgent);
    } else if (requestCode == 3) {
        if (resultCode == RESULT_OK || resultCode == RESULT_FIRST_USER) {
            userMail = data.getStringExtra("userMail");
            userPass = data.getStringExtra("userPass");
            //sendRequest("user:auth", String.format("\"email\":\"%s\",\"password\":\"%s\"",userMail,userPass));
            if (resultCode == RESULT_OK)
                sendRequest("user:auth",
                        String.format("\"email\":\"%s\",\"password\":\"%s\"", userMail, userPass));
            else
                serverHelper.getInstance().sendOldRequest("user_register", String.format(
                        "{\"action\": \"user_register\",\"email\":\"%s\",\"password\":\"%s\",\"_client_software\": \"ff_addon\"}",
                        userMail, userPass), "");
        }
    } else if (requestCode == 4) {
        if (resultCode == RESULT_OK) {
            if (serverHelper.getInstance().canShare()) {
                serverHelper.getInstance().shareNote();
            }
        }
    } else if (requestCode == 5) {
        if (resultCode == RESULT_OK) {
            DataExchange cl = (DataExchange) data.getExtras().getSerializable("content");
            if (sessionId.length() == 0 || userPass.length() == 0)
                showSettings();
            else {
                if (prefs.getBoolean("check_fast", false)) {
                    sendNote(wv.getTitle(), cl.getContent(), parent, tag);
                    clipData.setContent("");
                } else {
                    serverHelper.getInstance().setCallback(this, this);
                    if (appSettings.sessionId.length() > 0) {
                        serverHelper.getInstance().sendRequest("notes:getFolders", "", "");
                    }
                }
            }
        }
        wv.endSelectionMode();
    } else if (requestCode == 11) {
        if (appSettings.sessionId != "") {
            sessionId = appSettings.sessionId;
            userPass = appSettings.userPass;
            if (lastAction != "") {
                serverHelper.getInstance().sendRequest(lastAction, "", "");
            } else if (clipData != null && clipData.getContent().length() > 0) {
                if (prefs.getBoolean("check_fast", false)) {
                    sendNote(clipData.getTitle(), clipData.getContent(), parent, tag);
                    clipData.setContent("");
                } else {
                    serverHelper.getInstance().setCallback(this, this);
                    if (appSettings.sessionId.length() > 0) {
                        serverHelper.getInstance().sendRequest("notes:getFolders", "", "");
                    }
                }
            }
        }
    } else if (requestCode == 7) {

        if (resultCode == RESULT_OK && data != null) {
            try {
                DataExchange xdata = (DataExchange) data.getExtras().getSerializable("xdata");
                parent = xdata.getId();
                tag = xdata.getTags();
                String xtitle = xdata.getTitle();
                clipData.setTitle(xtitle);
                //clipData.setTags(tag);
                if (sessionId.length() == 0 || userPass.length() == 0)
                    showSettings();
                else {
                    sendNote(xtitle, clipData.getContent(), parent, tag);
                    clipData.setContent("");
                }
            } catch (Exception e) {
                BugReporter.Send("BrowseAct", e.getMessage());
            }
        }

    } else if (requestCode == SHOW_SETTINGS) {
        switch (resultCode) {
        case RESULT_FIRST_USER + 1:
            Intent i = new Intent(getApplicationContext(), PrefsActivity.class);
            startActivity(i);

            overridePendingTransition(R.anim.carbon_slide_in, R.anim.carbon_slide_out);
            break;
        case RESULT_FIRST_USER + 2:
            if (appSettings.sessionId.length() == 0)
                showLogin();
            else {
                appSettings.sessionId = "";
                //serverHelper.getInstance().setSessionId(appSettings.sessionId);
                Editor e = prefs.edit();
                e.putString("userMail", userMail);
                e.putString("userPass", "");
                e.putString("sessionId", appSettings.sessionId);
                e.commit();
                showLogin();
            }
            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:org.opendatakit.survey.android.activities.MainMenuActivity.java

protected void createPasswordDialog() {
    if (mAlertDialog != null) {
        mAlertDialog.dismiss();/*from   w  w w. j  a  va 2  s.  co m*/
        mAlertDialog = null;
    }
    final AlertDialog passwordDialog = new AlertDialog.Builder(this).create();

    passwordDialog.setTitle(getString(R.string.enter_admin_password));
    final EditText input = new EditText(this);
    input.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
    input.setTransformationMethod(PasswordTransformationMethod.getInstance());
    passwordDialog.setView(input, 20, 10, 20, 10);

    passwordDialog.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.ok),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    String value = input.getText().toString();
                    String pw = PropertiesSingleton.getProperty(appName, AdminPreferencesActivity.KEY_ADMIN_PW);
                    if (pw != null && pw.compareTo(value) == 0) {
                        Intent i = new Intent(getApplicationContext(), AdminPreferencesActivity.class);
                        // TODO: convert this activity into a preferences fragment
                        i.putExtra(APP_NAME, getAppName());
                        startActivity(i);
                        input.setText("");
                        passwordDialog.dismiss();
                    } else {
                        Toast.makeText(MainMenuActivity.this, getString(R.string.admin_password_incorrect),
                                Toast.LENGTH_SHORT).show();
                    }
                }
            });

    passwordDialog.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.cancel),
            new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {
                    input.setText("");
                    return;
                }
            });

    passwordDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
    mAlertDialog = passwordDialog;
    mAlertDialog.show();
}

From source file:cm.aptoide.pt.ApkInfo.java

public void loadMalware(final MalwareStatus malwareStatus) {
    runOnUiThread(new Runnable() {

        @Override//  ww w  .  ja  va  2  s  .c  o  m
        public void run() {
            try {
                EnumApkMalware apkStatus = EnumApkMalware
                        .valueOf(malwareStatus.getStatus().toUpperCase(Locale.ENGLISH));
                Log.d("ApkInfoMalware-malwareStatus", malwareStatus.getStatus());
                Log.d("ApkInfoMalware-malwareReason", malwareStatus.getReason());

                switch (apkStatus) {
                case SCANNED:
                    ((TextView) findViewById(R.id.app_badge_text)).setText(getString(R.string.trusted));
                    ((ImageView) findViewById(R.id.app_badge)).setImageResource(R.drawable.badge_scanned);
                    ((LinearLayout) findViewById(R.id.badge_layout)).setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            View trustedView = LayoutInflater.from(ApkInfo.this)
                                    .inflate(R.layout.dialog_anti_malware, null);
                            AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(ApkInfo.this)
                                    .setView(trustedView);
                            final AlertDialog trustedDialog = dialogBuilder.create();
                            trustedDialog.setIcon(R.drawable.badge_scanned);
                            trustedDialog.setTitle(getString(R.string.app_trusted, viewApk.getName()));
                            trustedDialog.setCancelable(true);

                            TextView tvSignatureValidation = (TextView) trustedView
                                    .findViewById(R.id.tv_signature_validation);
                            tvSignatureValidation.setText(getString(R.string.signature_verified));
                            ImageView check_signature = (ImageView) trustedView
                                    .findViewById(R.id.check_signature);
                            check_signature.setImageResource(R.drawable.ic_yes);

                            trustedDialog.setButton(Dialog.BUTTON_NEUTRAL, "Ok", new Dialog.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface arg0, int arg1) {
                                    trustedDialog.dismiss();
                                }
                            });
                            trustedDialog.show();
                        }
                    });
                    break;
                //             case UNKNOWN:
                //                ((TextView) findViewById(R.id.app_badge_text)).setText(getString(R.string.unknown));
                //                ((ImageView) findViewById(R.id.app_badge)).setImageResource(R.drawable.badge_unknown);
                //                break;
                case WARN:
                    ((TextView) findViewById(R.id.app_badge_text)).setText(getString(R.string.warning));
                    ((ImageView) findViewById(R.id.app_badge)).setImageResource(R.drawable.badge_warn);
                    ((LinearLayout) findViewById(R.id.badge_layout)).setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            View warnView = LayoutInflater.from(ApkInfo.this)
                                    .inflate(R.layout.dialog_anti_malware, null);
                            AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(ApkInfo.this)
                                    .setView(warnView);
                            final AlertDialog warnDialog = dialogBuilder.create();
                            warnDialog.setIcon(R.drawable.badge_warn);
                            warnDialog.setTitle(getString(R.string.app_warning, viewApk.getName()));
                            warnDialog.setCancelable(true);

                            TextView tvSignatureValidation = (TextView) warnView
                                    .findViewById(R.id.tv_signature_validation);
                            tvSignatureValidation.setText(getString(R.string.signature_not_verified));
                            ImageView check_signature = (ImageView) warnView.findViewById(R.id.check_signature);
                            check_signature.setImageResource(R.drawable.ic_failed);

                            warnDialog.setButton(Dialog.BUTTON_NEUTRAL, "Ok", new Dialog.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface arg0, int arg1) {
                                    warnDialog.dismiss();
                                }
                            });
                            warnDialog.show();
                        }
                    });
                    break;
                //             case CRITICAL:
                //                ((TextView) findViewById(R.id.app_badge_text)).setText(getString(R.string.critical));
                //                ((ImageView) findViewById(R.id.app_badge)).setImageResource(R.drawable.badge_critical);
                //                break;
                default:
                    break;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    });

}

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

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    ContentResolver cr;/*from   w  w w  .ja va  2s.c o  m*/
    InputStream is;
    if (requestCode == TAKE_PHOTO) {
        showProgress(false);
        if (resultCode == -1) {
            try {
                if (data != null) {
                    if (data.hasExtra("data")) {
                        //Bitmap bm = ;
                        drawView.setVisibility(View.INVISIBLE);
                        drawView.recycle();
                        drawView.setBitmap((Bitmap) data.getParcelableExtra("data"), 0);
                        drawView.setVisibility(View.VISIBLE);

                    }
                } else {
                    if (outputFileUri != null) {
                        cr = getContentResolver();
                        try {
                            is = cr.openInputStream(outputFileUri);
                            Bitmap bmp = BitmapFactory.decodeStream(is);
                            if (bmp.getWidth() != -1 && bmp.getHeight() != -1) {
                                drawView.setVisibility(View.INVISIBLE);
                                drawView.recycle();
                                drawView.setBitmap(bmp, 0);
                                drawView.setVisibility(View.VISIBLE);
                            }
                        } catch (Exception e) {
                            appSettings.appendLog("paint:onCreate  " + e.getMessage());
                        }
                    }
                }
            } catch (Exception e) {
                appSettings.appendLog("main:onActivityResult: exception -  " + e.getMessage());
            }
        }
        ((ViewAnimator) findViewById(R.id.top_switcher)).setDisplayedChild(0);
    } else if (requestCode == TAKE_PICTURE) {
        showProgress(false);
        if (resultCode == -1 && data != null) {
            boolean temp = false;
            try {
                Uri resultUri = data.getData();
                String drawString = resultUri.getPath();
                InputStream input = getContentResolver().openInputStream(resultUri);

                drawView.setVisibility(View.INVISIBLE);
                drawView.recycle();
                drawView.setBitmap(BitmapFactory.decodeStream(input), 0);
                //drawView.forceRedraw();
                drawView.setVisibility(View.VISIBLE);
            } catch (Exception e) {
                appSettings.appendLog("main:onActivityResult  " + e.getMessage());

            }
        }
        ((ViewAnimator) findViewById(R.id.top_switcher)).setDisplayedChild(0);
    } 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 {
                appSettings.sessionId = "";
                //serverHelper.getInstance().setSessionId(appSettings.sessionId);
                Editor e = prefs.edit();
                e.putString("userMail", userMail);
                e.putString("userPass", "");
                e.putString("sessionId", appSettings.sessionId);
                e.commit();
                showLogin();
            }
            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;
        }
    }

    if (requestCode == 3) {
        if (resultCode == RESULT_OK || resultCode == RESULT_FIRST_USER) {
            userMail = data.getStringExtra("userMail");
            userPass = data.getStringExtra("userPass");
            if (resultCode == RESULT_OK)
                sendRequest("user:auth",
                        String.format("\"email\":\"%s\",\"password\":\"%s\"", userMail, userPass));
            else
                serverHelper.getInstance().sendOldRequest("user_register", String.format(
                        "{\"action\": \"user_register\",\"email\":\"%s\",\"password\":\"%s\",\"_client_software\": \"ff_addon\"}",
                        userMail, userPass), "");
        }
    } else if (requestCode == 11) {
        if (appSettings.sessionId != "") {
            sessionId = appSettings.sessionId;
            userPass = appSettings.userPass;
            sendShot();
        }
    } else if (requestCode == 4) {
        if (resultCode == RESULT_OK) {
            String id = data.getStringExtra("id").toString();
            serverHelper.getInstance().shareShot(id);
        }
    } else if (resultCode == RESULT_OK) {
        drawView.setColour(dColor);
        setPaletteColor(dColor);
        Uri resultUri = data.getData();
        String drawString = resultUri.getPath();
        String galleryString = getGalleryPath(resultUri);

        if (galleryString != null) {
            drawString = galleryString;
        }
        // else another file manager was used
        else {
            if (drawString.contains("//")) {
                drawString = drawString.substring(drawString.lastIndexOf("//"));
            }
        }

        // set the background to the selected picture
        if (drawString.length() > 0) {
            Drawable drawBackground = Drawable.createFromPath(drawString);
            drawView.setBackgroundDrawable(drawBackground);
        }

    }
}

From source file:es.javocsoft.android.lib.toolbox.ToolBox.java

/**
 * Creates and shows a custom Alert dialog that will execute
 * the actions specified for positive, negative and 
 * neutral buttons./*from w w w. j av  a  2s.  c o m*/
 * 
 * @param context
 * @param title
 * @param message
 * @param positiveBtnActions   Can be null. When null button is not shown.
 * @param negativeBtnActions   Can be null. When null button is not shown.
 * @param neutralBtnActions   Can be null.
 */
public static void dialog_showCustomActionsDialog(Context context, String title, String message,
        String positiveBtnText, final Runnable positiveBtnActions, String negativeBtnText,
        final Runnable negativeBtnActions, String neutralBtnText, final Runnable neutralBtnActions) {

    AlertDialog dialog = new AlertDialog.Builder(context).create();

    dialog.setTitle(title);
    dialog.setMessage(message);

    dialog.setCancelable(true);
    dialog.setButton(AlertDialog.BUTTON_NEUTRAL, neutralBtnText, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            if (neutralBtnActions != null) {
                neutralBtnActions.run();
            }
            dialog.dismiss();
        }
    });

    if (negativeBtnActions != null) {
        dialog.setButton(AlertDialog.BUTTON_NEGATIVE, negativeBtnText, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                negativeBtnActions.run();
            }
        });
    }

    if (positiveBtnActions != null) {
        dialog.setButton(AlertDialog.BUTTON_POSITIVE, positiveBtnText, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                positiveBtnActions.run();
            }
        });
    }

    dialog.show();
}

From source file:es.javocsoft.android.lib.toolbox.ToolBox.java

/**
 * Creates a application informative dialog with options to
 * uninstall/launch or cancel./*from   w  ww  .  j a va  2  s . c om*/
 * 
 * @param context
 * @param appPackage
 */
public static void appInfo_getLaunchUninstallDialog(final Context context, String appPackage) {

    try {

        final PackageManager packageManager = context.getPackageManager();
        final PackageInfo app = packageManager.getPackageInfo(appPackage, PackageManager.GET_META_DATA);

        AlertDialog dialog = new AlertDialog.Builder(context).create();

        dialog.setTitle(app.applicationInfo.loadLabel(packageManager));

        String description = null;
        if (app.applicationInfo.loadDescription(packageManager) != null) {
            description = app.applicationInfo.loadDescription(packageManager).toString();
        }

        String msg = app.applicationInfo.loadLabel(packageManager) + "\n\n" + "Version " + app.versionName
                + " (" + app.versionCode + ")" + "\n" + (description != null ? (description + "\n") : "")
                + app.applicationInfo.sourceDir + "\n" + appInfo_getSize(app.applicationInfo.sourceDir);
        dialog.setMessage(msg);

        dialog.setCancelable(true);
        dialog.setButton(AlertDialog.BUTTON_NEUTRAL, "Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.dismiss();
            }
        });
        dialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Uninstall", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                Intent intent = new Intent(Intent.ACTION_DELETE);
                intent.setData(Uri.parse("package:" + app.packageName));
                context.startActivity(intent);
            }
        });
        dialog.setButton(AlertDialog.BUTTON_POSITIVE, "Launch", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                Intent i = packageManager.getLaunchIntentForPackage(app.packageName);
                context.startActivity(i);
            }
        });

        dialog.show();
    } catch (Exception e) {
        if (LOG_ENABLE) {
            Log.e(TAG, "Dialog could not be made for the specified application '" + appPackage + "'. ["
                    + e.getMessage() + "].", e);
        }
    }
}