Example usage for android.app AlertDialog dismiss

List of usage examples for android.app AlertDialog dismiss

Introduction

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

Prototype

@Override
public void dismiss() 

Source Link

Document

Dismiss this dialog, removing it from the screen.

Usage

From source file:org.smap.smapTask.android.activities.MainTabsActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case PROGRESS_DIALOG:
        mProgressDialog = new ProgressDialog(this);
        DialogInterface.OnClickListener loadingButtonListener = new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();//from  w  w  w  . j ava 2s . c  o m
                mDownloadTasks.setDownloaderListener(null, mContext);
                mDownloadTasks.cancel(true);
                // Refresh the task list
                Intent intent = new Intent("refresh");
                LocalBroadcastManager.getInstance(mContext).sendBroadcast(intent);
            }
        };
        mProgressDialog.setTitle(getString(R.string.downloading_data));
        mProgressDialog.setMessage(mProgressMsg);
        mProgressDialog.setIcon(android.R.drawable.ic_dialog_info);
        mProgressDialog.setIndeterminate(true);
        mProgressDialog.setCancelable(false);
        mProgressDialog.setButton(getString(R.string.cancel), loadingButtonListener);
        return mProgressDialog;
    case ALERT_DIALOG:
        mAlertDialog = new AlertDialog.Builder(this).create();
        mAlertDialog.setMessage(mAlertMsg);
        mAlertDialog.setTitle(getString(R.string.smap_get_tasks));
        DialogInterface.OnClickListener quitListener = new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int i) {
                dialog.dismiss();
            }
        };
        mAlertDialog.setCancelable(false);
        mAlertDialog.setButton(getString(R.string.ok), quitListener);
        mAlertDialog.setIcon(android.R.drawable.ic_dialog_info);
        return mAlertDialog;
    case PASSWORD_DIALOG:

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        final AlertDialog passwordDialog = builder.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 = mAdminPreferences.getString(AdminPreferencesActivity.KEY_ADMIN_PW, "");
                        if (pw.compareTo(value) == 0) {
                            Intent i = new Intent(getApplicationContext(), AdminPreferencesActivity.class);
                            startActivity(i);
                            input.setText("");
                            passwordDialog.dismiss();
                        } else {
                            Toast.makeText(MainTabsActivity.this, getString(R.string.admin_password_incorrect),
                                    Toast.LENGTH_SHORT).show();
                            Collect.getInstance().getActivityLogger().logAction(this, "adminPasswordDialog",
                                    "PASSWORD_INCORRECT");
                        }
                    }
                });

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

                    public void onClick(DialogInterface dialog, int which) {
                        Collect.getInstance().getActivityLogger().logAction(this, "adminPasswordDialog",
                                "cancel");
                        input.setText("");
                        return;
                    }
                });

        passwordDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
        return passwordDialog;
    }
    return null;
}

From source file:de.baumann.hhsmoodle.fragmentsMain.FragmentBrowser.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    switch (id) {

    case R.id.action_help:
        helper_main.switchToActivity(getActivity(), FragmentBrowser_Help.class, false);
        return true;

    case R.id.action_bookmark:
        helper_main.switchToActivity(getActivity(), Popup_bookmarks.class, false);
        return true;

    case R.id.action_saveBookmark:

        final Bookmarks_DbAdapter db = new Bookmarks_DbAdapter(getActivity());
        db.open();/*from w w  w  . j av a  2  s .  c  om*/

        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        View dialogView = View.inflate(getActivity(), R.layout.dialog_edit_title, null);

        final EditText edit_title = (EditText) dialogView.findViewById(R.id.pass_title);
        edit_title.setHint(R.string.bookmark_edit_title);
        edit_title.setText(mWebView.getTitle());

        builder.setView(dialogView);
        builder.setTitle(R.string.bookmark_edit_title);
        builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int whichButton) {

            }
        });
        builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int whichButton) {
                dialog.cancel();
            }
        });

        final AlertDialog dialog2 = builder.create();
        // Display the custom alert dialog on interface
        dialog2.show();
        helper_main.showKeyboard(getActivity(), edit_title);

        dialog2.getButton(android.app.AlertDialog.BUTTON_POSITIVE)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //Do stuff, possibly set wantToCloseDialog to true then...
                        String inputTag = edit_title.getText().toString().trim();

                        if (db.isExist(mWebView.getUrl())) {
                            Snackbar.make(edit_title, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG)
                                    .show();
                        } else {
                            db.insert(inputTag, mWebView.getUrl(), "04", "", createDate());
                            dialog2.dismiss();
                            Snackbar.make(mWebView, R.string.bookmark_added, Snackbar.LENGTH_LONG).show();
                        }
                    }
                });

        return true;

    case R.id.menu_share_screenshot:
        screenshot();

        if (shareFile.exists()) {
            Intent sharingIntent = new Intent(Intent.ACTION_SEND);
            sharingIntent.setType("image/png");
            sharingIntent.putExtra(Intent.EXTRA_SUBJECT, mWebView.getTitle());
            sharingIntent.putExtra(Intent.EXTRA_TEXT, mWebView.getUrl());
            Uri bmpUri = Uri.fromFile(shareFile);
            sharingIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
            startActivity(Intent.createChooser(sharingIntent, (getString(R.string.app_share_screenshot))));
        }
        return true;

    case R.id.menu_save_screenshot:
        screenshot();
        return true;

    case R.id.menu_share_link:
        Intent sharingIntent = new Intent(Intent.ACTION_SEND);
        sharingIntent.setType("text/plain");
        sharingIntent.putExtra(Intent.EXTRA_SUBJECT, mWebView.getTitle());
        sharingIntent.putExtra(Intent.EXTRA_TEXT, mWebView.getUrl());
        startActivity(Intent.createChooser(sharingIntent, (getString(R.string.app_share_link))));
        return true;

    case R.id.menu_share_link_browser:
        String url = mWebView.getUrl();
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        getActivity().startActivity(intent);
        return true;

    case R.id.menu_share_link_copy:
        String url2 = mWebView.getUrl();
        ClipboardManager clipboard = (ClipboardManager) getActivity()
                .getSystemService(Context.CLIPBOARD_SERVICE);
        clipboard.setPrimaryClip(ClipData.newPlainText("text", url2));
        Snackbar.make(mWebView, R.string.context_linkCopy_toast, Snackbar.LENGTH_LONG).show();
        return true;
    }
    return false;
}

From source file:de.baumann.hhsmoodle.data_count.Count_Fragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_screen_notes, container, false);

    PreferenceManager.setDefaultValues(getActivity(), R.xml.user_settings, false);
    sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity());

    imgHeader = (ImageView) rootView.findViewById(R.id.imageView_header);
    helper_main.setImageHeader(getActivity(), imgHeader);

    filter_layout = (RelativeLayout) rootView.findViewById(R.id.filter_layout);
    filter_layout.setVisibility(View.GONE);
    lv = (ListView) rootView.findViewById(R.id.listNotes);
    filter = (EditText) rootView.findViewById(R.id.myFilter);
    viewPager = (ViewPager) getActivity().findViewById(R.id.viewpager);

    ImageButton ib_hideKeyboard = (ImageButton) rootView.findViewById(R.id.ib_hideKeyboard);
    ib_hideKeyboard.setOnClickListener(new View.OnClickListener() {
        @Override//  w w w . j av  a2  s . c  om
        public void onClick(View view) {
            if (filter.getText().length() > 0) {
                filter.setText("");
            } else {
                setTitle();
                helper_main.hideFilter(getActivity(), filter_layout, imgHeader);
                setCountList();
            }
        }
    });

    fabLayout1 = (LinearLayout) rootView.findViewById(R.id.fabLayout1);
    fabLayout2 = (LinearLayout) rootView.findViewById(R.id.fabLayout2);
    fab = (FloatingActionButton) rootView.findViewById(R.id.fab);
    FloatingActionButton fab1 = (FloatingActionButton) rootView.findViewById(R.id.fab1);
    FloatingActionButton fab2 = (FloatingActionButton) rootView.findViewById(R.id.fab2);

    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (!isFABOpen) {
                showFABMenu();
            } else {
                closeFABMenu();
            }
        }
    });

    fab1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            closeFABMenu();
            final SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity());
            android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(getActivity());
            View dialogView = View.inflate(getActivity(), R.layout.dialog_edit_title, null);
            final EditText edit_title = (EditText) dialogView.findViewById(R.id.pass_title);
            edit_title.setHint(R.string.bookmark_edit_title);
            builder.setTitle(R.string.count_title);
            builder.setView(dialogView);
            builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {

                }
            });
            builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {
                    dialog.cancel();
                }
            });

            final android.app.AlertDialog dialog2 = builder.create();
            dialog2.show();

            dialog2.getButton(android.app.AlertDialog.BUTTON_POSITIVE)
                    .setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            //Do stuff, possibly set wantToCloseDialog to true then...

                            String inputTitle = edit_title.getText().toString().trim();

                            Count_DbAdapter db = new Count_DbAdapter(getActivity());
                            db.open();

                            if (db.isExist(inputTitle)) {
                                Snackbar.make(edit_title, getActivity().getString(R.string.toast_newTitle),
                                        Snackbar.LENGTH_LONG).show();
                            } else {
                                dialog2.dismiss();
                                db.insert(inputTitle, sharedPref.getString("count_content", ""), "3", "",
                                        helper_main.createDate());
                                sharedPref.edit().putString("count_content", "").apply();
                                setCountList();
                            }
                        }
                    });

            helper_main.showKeyboard(getActivity(), edit_title);
        }
    });

    fab2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            closeFABMenu();
            Intent mainIntent = new Intent(getActivity(), Popup_courseList.class);
            mainIntent.setAction("courseList_count");
            startActivity(mainIntent);
        }
    });

    //calling Notes_DbAdapter
    db = new Count_DbAdapter(getActivity());
    db.open();

    setCountList();
    setHasOptionsMenu(true);

    return rootView;
}

From source file:de.wikilab.android.friendica01.Max.java

/**
 * displays the login form (layout/loginscreen.xml) as a modal dialog and calls tryLogin
  * when user confirms the form//ww  w. ja v  a2 s.c o m
 * @param ctx     MUST IMPLEMENT LoginListener !!!
 * @param errmes  message which is displayed above the Login form (e.g. "wrong password entered")
 */
public static void showLoginForm(final Activity ctx, String errmes) {
    Log.v(TAG, "... showLoginForm");
    View myView = ctx.getLayoutInflater().inflate(R.layout.loginscreen, null, false);
    final AlertDialog alert = new AlertDialog.Builder(ctx).setTitle("Login to Friendica").setView(myView)
            .setOnCancelListener(new OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialog) {
                    ctx.finish();
                }
            }).show();

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
    String protocol = prefs.getString("login_protocol", "https");
    String server = prefs.getString("login_server", null);
    String userName = prefs.getString("login_user", null);

    if (errmes != null) {
        ((TextView) myView.findViewById(R.id.lblInfo)).setText(errmes);
    }

    final Spinner selProtocol = (Spinner) myView.findViewById(R.id.selProtocol);
    selProtocol.setSelection(protocol.equals("https") ? 1 : 0); //HACK !!!

    final EditText edtServer = (EditText) myView.findViewById(R.id.edtServer);
    edtServer.setText(server);

    final EditText edtUser = (EditText) myView.findViewById(R.id.edtUser);
    edtUser.setText(userName);

    final EditText edtPassword = (EditText) myView.findViewById(R.id.edtPassword);

    ((TextView) myView.findViewById(R.id.proxy_settings)).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ctx.startActivity(new Intent(ctx, PreferencesActivity.class));
        }
    });

    ((Button) myView.findViewById(R.id.button1)).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            SharedPreferences.Editor prefs = PreferenceManager.getDefaultSharedPreferences(ctx).edit();
            prefs.putString("login_protocol", selProtocol.getSelectedItem().toString());
            String server = edtServer.getText().toString();
            server = server.replaceAll("^https?://", "");
            prefs.putString("login_server", server);
            prefs.putString("login_user", edtUser.getText().toString());
            prefs.putString("login_password", edtPassword.getText().toString());
            prefs.commit();

            alert.dismiss();

            tryLogin(ctx);
        }
    });
}

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

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case UPDATE_REPO:
        final AlertDialog upd_alrt = new AlertDialog.Builder(this).create();
        if (!db.areServers()) {
            upd_alrt.setIcon(android.R.drawable.ic_dialog_alert);
            upd_alrt.setTitle("Empty");
            upd_alrt.setMessage(//w  w w . j ava2  s .  com
                    "There are no enabled repositories in your list.\nPlease add repository or enable the ones you have!");
            upd_alrt.setButton("Ok", new OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {

                }
            });
        } else {
            upd_alrt.setIcon(android.R.drawable.ic_dialog_alert);
            upd_alrt.setTitle("Update repositories");
            upd_alrt.setMessage(
                    "Do you wish to update repositories?\nThis can take a while (WiFi is advised)...");
            upd_alrt.setButton("Yes", new OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    updateRepos();
                }
            });
            upd_alrt.setButton2("No", new OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    upd_alrt.dismiss();
                }
            });
        }
        upd_alrt.show();
        return true;
    case MANAGE_REPO:
        Intent i = new Intent(this, ManageRepo.class);
        startActivityForResult(i, NEWREPO_FLAG);
        return true;
    case SEARCH_MENU:
        onSearchRequested();
        return true;
    case ABOUT:
        LayoutInflater li = LayoutInflater.from(this);
        View view = li.inflate(R.layout.about, null);
        Builder p = new AlertDialog.Builder(this).setView(view);
        final AlertDialog alrt = p.create();
        alrt.setIcon(R.drawable.icon);
        alrt.setTitle("APTOIDE");
        alrt.setButton("ChangeLog", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                Uri uri = Uri.parse("http://aptoide.com/changelog.html");
                startActivity(new Intent(Intent.ACTION_VIEW, uri));
            }
        });
        alrt.show();
        return true;
    case SETTINGS:
        Intent s = new Intent(RemoteInTab.this, Settings.class);
        s.putExtra("order", order_lst);
        startActivityForResult(s, SETTINGS_FLAG);
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.mobicage.rogerthat.util.ui.SendMessageView.java

private void processOnClickListenerForKey(final int key) {

    if (IMAGE_BUTTON_TEXT == key) {

    } else if (IMAGE_BUTTON_BUTTONS == key) {
        hideKeyboard();//from   w  w  w . j a  va2s .  c o  m
        try {
            Intent intent = new Intent(mActivity, SendMessageButtonActivity.class);
            intent.putExtra(SendMessageButtonActivity.CANNED_BUTTONS,
                    Pickler.getPickleFromObject(mCannedButtons));
            long[] primitiveLongArray = new long[mButtons.size()];
            Long[] longArray = mButtons.toArray(new Long[mButtons.size()]);
            for (int i = 0; i < longArray.length; i++) {
                primitiveLongArray[i] = longArray[i].longValue();
            }
            intent.putExtra(SendMessageButtonActivity.BUTTONS, primitiveLongArray);
            mActivity.startActivityForResult(intent, PICK_BUTTON);
        } catch (Exception e) {
            L.bug(e);
        }
    } else if (IMAGE_BUTTON_PICTURE == key) {
        hideKeyboard();
        getNewPicture();
    } else if (IMAGE_BUTTON_VIDEO == key) {
        hideKeyboard();
        getNewVideo();

    } else if (IMAGE_BUTTON_PRIORITY == key) {
        hideKeyboard();

        final View dialog = mActivity.getLayoutInflater().inflate(R.layout.msg_priority_picker, null);

        final RadioButton priorityNormalBtn = ((RadioButton) dialog.findViewById(R.id.priority_normal));
        final RadioButton priorityHighBtn = ((RadioButton) dialog.findViewById(R.id.priority_high));
        final RadioButton priorityUrgentBtn = ((RadioButton) dialog.findViewById(R.id.priority_urgent));
        final RadioButton priorityUrgentWithAlarmBtn = ((RadioButton) dialog
                .findViewById(R.id.priority_urgent_with_alarm));

        priorityNormalBtn.setChecked(false);
        priorityHighBtn.setChecked(false);
        priorityUrgentBtn.setChecked(false);
        priorityUrgentWithAlarmBtn.setChecked(false);

        if (mPriority == Message.PRIORITY_HIGH) {
            priorityHighBtn.setChecked(true);
        } else if (mPriority == Message.PRIORITY_URGENT) {
            priorityUrgentBtn.setChecked(true);
        } else if (mPriority == Message.PRIORITY_URGENT_WITH_ALARM) {
            priorityUrgentWithAlarmBtn.setChecked(true);
        } else {
            priorityNormalBtn.setChecked(true);
        }

        String title = mActivity.getString(R.string.priority);
        SafeDialogClick onPositiveClick = new SafeDialogClick() {
            @Override
            public void safeOnClick(DialogInterface di, int id) {
                if (priorityHighBtn.isChecked()) {
                    mPriority = Message.PRIORITY_HIGH;
                } else if (priorityUrgentBtn.isChecked()) {
                    mPriority = Message.PRIORITY_URGENT;
                } else if (priorityUrgentWithAlarmBtn.isChecked()) {
                    mPriority = Message.PRIORITY_URGENT_WITH_ALARM;
                } else {
                    mPriority = Message.PRIORITY_NORMAL;
                }
                initImageButtonsNavigation();
            }
        };
        UIUtils.showDialog(mActivity, title, null, R.string.ok, onPositiveClick, R.string.cancel, null, dialog);

    } else if (IMAGE_BUTTON_STICKY == key) {
        hideKeyboard();
        final View dialog = mActivity.getLayoutInflater().inflate(R.layout.msg_sticky_picker, null);

        final RadioButton stickyDisabled = ((RadioButton) dialog.findViewById(R.id.sticky_disabled));
        final RadioButton stickyEnabled = ((RadioButton) dialog.findViewById(R.id.sticky_enabled));
        stickyEnabled.setChecked(mIsSticky);
        stickyDisabled.setChecked(!mIsSticky);

        String title = mActivity.getString(R.string.sticky);
        SafeDialogClick onPositiveClick = new SafeDialogClick() {
            @Override
            public void safeOnClick(DialogInterface di, int id) {
                mIsSticky = stickyEnabled.isChecked();
                initImageButtonsNavigation();
            }
        };
        UIUtils.showDialog(mActivity, title, null, R.string.ok, onPositiveClick, R.string.cancel, null, dialog);

    } else if (IMAGE_BUTTON_MORE == key) {
        hideKeyboard();
        final View dialog = mActivity.getLayoutInflater().inflate(R.layout.msg_more_picker, null);
        final ListView pickMsgMore = (ListView) dialog.findViewById(R.id.pick_msg_more);

        List<PickMoreItem> items = new ArrayList<>();
        for (int i = mMaxImageButtonsOnScreen - 1; i < mImageButtons.size(); i++) {
            int k = mImageButtons.get(i);
            String t = "";
            if (k == IMAGE_BUTTON_TEXT) {
                t = mActivity.getString(R.string.title_message);
            } else if (k == IMAGE_BUTTON_BUTTONS) {
                t = mActivity.getString(R.string.title_buttons);
            } else if (k == IMAGE_BUTTON_PICTURE) {
                t = mActivity.getString(R.string.title_new_message_image);
            } else if (k == IMAGE_BUTTON_VIDEO) {
                t = mActivity.getString(R.string.title_new_message_video);
            } else if (k == IMAGE_BUTTON_PRIORITY) {
                t = mActivity.getString(R.string.priority);
            } else if (k == IMAGE_BUTTON_STICKY) {
                t = mActivity.getString(R.string.sticky);
            } else {
                L.d("Could not find more text for key: " + key);
            }

            items.add(new PickMoreItem(k, getImageResourceForKey(k), t));
        }
        pickMsgMore.setAdapter(new ListAdapter(mActivity, items));
        String title = mActivity.getString(R.string.more);
        String negativeCaption = mActivity.getString(R.string.cancel);
        final AlertDialog alertDialog = UIUtils.showDialog(mActivity, title, null, null, null, negativeCaption,
                null, dialog);

        pickMsgMore.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(final AdapterView<?> parent, final View view, final int position,
                    final long id) {
                alertDialog.dismiss();
                PickMoreItem item = (PickMoreItem) view.getTag();
                processOnClickListenerForKey(item.imageButtonKey);
            }
        });
    } else {
        L.d("Could not find processOnClickListener for key: " + key);
    }
}

From source file:produvia.com.lights.SmartLightsActivity.java

public void promptLogin(final JSONObject loginService, final JSONObject responseData) {

    runOnUiThread(new Runnable() {
        public void run() {
            try {
                String type = loginService.getString("type");
                //there was a login error. login again
                if (type.equals(WeaverSdk.FIRST_LOGIN_TYPE_NORMAL)) {
                    //prompt for username and password and retry:
                    promptUsernamePassword(loginService, responseData, false, null);

                } else if (type.equals(WeaverSdk.FIRST_LOGIN_TYPE_KEY)) {

                    promptUsernamePassword(loginService, responseData, true,
                            loginService.getString("description"));

                } else if (type.equals(WeaverSdk.FIRST_LOGIN_TYPE_PRESS2LOGIN)) {
                    //prompt for username and password and retry:
                    int countdown = loginService.has("login_timeout") ? loginService.getInt("login_timeout")
                            : 15;// w w w . java 2 s . c om
                    final AlertDialog alertDialog = new AlertDialog.Builder(SmartLightsActivity.this).create();
                    alertDialog.setTitle(loginService.getString("description"));
                    alertDialog.setCancelable(false);
                    alertDialog.setCanceledOnTouchOutside(false);
                    alertDialog.setMessage(loginService.getString("description") + "\n"
                            + "Attempting to login again in " + countdown + " seconds...");
                    alertDialog.show(); //

                    new CountDownTimer(countdown * 1000, 1000) {
                        @Override
                        public void onTick(long millisUntilFinished) {
                            try {
                                alertDialog.setMessage(loginService.getString("description") + "\n"
                                        + "Attempting to login again in " + millisUntilFinished / 1000
                                        + " seconds...");
                            } catch (JSONException e) {

                            }
                        }

                        @Override
                        public void onFinish() {
                            alertDialog.dismiss();
                            new Thread(new Runnable() {
                                public void run() {

                                    try {
                                        JSONArray services = new JSONArray();
                                        services.put(loginService);
                                        responseData.put("services", services);
                                        WeaverSdkApi.servicesSet(SmartLightsActivity.this, responseData);
                                    } catch (JSONException e) {

                                    }
                                }
                            }).start();

                        }
                    }.start();

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

        }

    });

}

From source file:com.prey.activities.CheckPasswordActivity.java

@Override
protected void onResume() {
    super.onResume();
    bindPasswordControls();// w ww  . ja va 2  s.  com
    TextView device_ready_h2_text = (TextView) findViewById(R.id.device_ready_h2_text);
    final TextView textForgotPassword = (TextView) findViewById(R.id.link_forgot_password);

    Button password_btn_login = (Button) findViewById(R.id.password_btn_login);
    EditText password_pass_txt = (EditText) findViewById(R.id.password_pass_txt);

    TextView textView1 = (TextView) findViewById(R.id.textView1);
    TextView textView2 = (TextView) findViewById(R.id.textView2);

    Typeface titilliumWebRegular = Typeface.createFromAsset(getAssets(),
            "fonts/Titillium_Web/TitilliumWeb-Regular.ttf");
    Typeface titilliumWebBold = Typeface.createFromAsset(getAssets(),
            "fonts/Titillium_Web/TitilliumWeb-Bold.ttf");
    Typeface magdacleanmonoRegular = Typeface.createFromAsset(getAssets(),
            "fonts/MagdaClean/magdacleanmono-regular.ttf");

    textView1.setTypeface(magdacleanmonoRegular);
    textView2.setTypeface(magdacleanmonoRegular);

    device_ready_h2_text.setTypeface(titilliumWebRegular);
    textForgotPassword.setTypeface(titilliumWebBold);
    password_btn_login.setTypeface(titilliumWebBold);
    password_pass_txt.setTypeface(magdacleanmonoRegular);

    try {

        textForgotPassword.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                try {
                    String url = PreyConfig.getPreyConfig(getApplicationContext()).getPreyPanelUrl();
                    Intent browserIntent = new Intent("android.intent.action.VIEW", Uri.parse(url));
                    startActivity(browserIntent);
                } catch (Exception e) {
                }
            }
        });
    } catch (Exception e) {
    }

    TextView textView5_1 = (TextView) findViewById(R.id.textView5_1);
    TextView textView5_2 = (TextView) findViewById(R.id.textView5_2);

    textView5_1.setTypeface(magdacleanmonoRegular);
    textView5_2.setTypeface(titilliumWebBold);

    TextView textViewUninstall = (TextView) findViewById(R.id.textViewUninstall);
    LinearLayout linearLayoutTour = (LinearLayout) findViewById(R.id.linearLayoutTour);
    textViewUninstall.setTypeface(titilliumWebBold);

    if (PreyConfig.getPreyConfig(getApplication()).getProtectTour()) {
        linearLayoutTour.setVisibility(View.GONE);
        textViewUninstall.setVisibility(View.VISIBLE);

        textViewUninstall.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String url = PreyConfig.getPreyConfig(getApplication()).getPreyUninstallUrl();

                Intent browserIntent = new Intent("android.intent.action.VIEW", Uri.parse(url));
                startActivity(browserIntent);

                finish();
            }
        });
    } else {

        linearLayoutTour.setVisibility(View.VISIBLE);
        textViewUninstall.setVisibility(View.GONE);
        try {

            linearLayoutTour.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(getApplication(), TourActivity1.class);
                    Bundle b = new Bundle();
                    b.putInt("id", 1);
                    intent.putExtras(b);
                    startActivity(intent);
                    finish();
                }
            });
        } catch (Exception e) {

        }
    }

    boolean showLocation = false;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        boolean canAccessFineLocation = PreyPermission.canAccessFineLocation(this);
        boolean canAccessCoarseLocation = PreyPermission.canAccessCoarseLocation(this);
        boolean canAccessCamera = PreyPermission.canAccessCamera(this);
        boolean canAccessReadPhoneState = PreyPermission.canAccessReadPhoneState(this);
        boolean canAccessReadExternalStorage = PreyPermission.canAccessReadExternalStorage(this);

        if (!canAccessFineLocation || !canAccessCoarseLocation || !canAccessCamera || !canAccessReadPhoneState
                || !canAccessReadExternalStorage) {

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

            final FrameLayout frameView = new FrameLayout(this);
            builder.setView(frameView);

            final AlertDialog alertDialog = builder.create();
            LayoutInflater inflater = alertDialog.getLayoutInflater();
            View dialoglayout = inflater.inflate(R.layout.warning, frameView);

            TextView warning_title = (TextView) dialoglayout.findViewById(R.id.warning_title);
            TextView warning_body = (TextView) dialoglayout.findViewById(R.id.warning_body);

            warning_title.setTypeface(magdacleanmonoRegular);
            warning_body.setTypeface(titilliumWebBold);

            Button button_ok = (Button) dialoglayout.findViewById(R.id.button_ok);
            Button button_close = (Button) dialoglayout.findViewById(R.id.button_close);
            button_ok.setTypeface(titilliumWebBold);
            button_close.setTypeface(titilliumWebBold);

            final Activity thisActivity = this;
            button_ok.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    PreyLogger.d("askForPermission");
                    askForPermission();
                    alertDialog.dismiss();

                }
            });

            button_close.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    PreyLogger.d("close ask");

                    alertDialog.dismiss();
                }
            });

            alertDialog.show();
            showLocation = false;

        } else {
            showLocation = true;
        }

    } else {
        showLocation = true;
    }
    if (showLocation) {
        LocationManager mlocManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
        boolean isGpsEnabled = mlocManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
        boolean isNetworkEnabled = mlocManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
        if (isGpsEnabled || isNetworkEnabled) {
            PreyLogger.d("isGpsEnabled || isNetworkEnabled");

        } else {
            PreyLogger.d("no gps ni red");
            AlertDialog.Builder builder = new AlertDialog.Builder(this);

            final AlertDialog alertDialog = builder.create();
            TextView textview = new TextView(this);
            textview.setText(getString(R.string.location_settings));
            textview.setMaxLines(10);
            textview.setTextSize(18F);
            textview.setPadding(20, 0, 20, 20);
            textview.setTextColor(Color.BLACK);
            builder.setView(textview);
            builder.setPositiveButton(getString(R.string.go_to_settings),
                    new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialoginterface, int i) {
                            dialoginterface.dismiss();
                            Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                            startActivityForResult(intent, 0);
                            return;

                        }

                    });
            builder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialoginterface, int i) {
                    dialoginterface.dismiss();
                }

            });
            builder.create().show();
        }
    }

}

From source file:produvia.com.scanner.DevicesActivity.java

public void promptLogin(final JSONObject loginService, final JSONObject responseData) {

    runOnUiThread(new Runnable() {
        public void run() {
            try {
                String type = loginService.getString("type");
                //there was a login error. login again
                if (type.equals(WeaverSdk.FIRST_LOGIN_TYPE_NORMAL)) {
                    //prompt for username and password and retry:
                    promptUsernamePassword(loginService, responseData, false, null);

                } else if (type.equals(WeaverSdk.FIRST_LOGIN_TYPE_KEY)) {

                    promptUsernamePassword(loginService, responseData, true,
                            loginService.getString("description"));

                } else if (type.equals(WeaverSdk.FIRST_LOGIN_TYPE_PRESS2LOGIN)) {
                    //prompt for username and password and retry:
                    int countdown = loginService.has("login_timeout") ? loginService.getInt("login_timeout")
                            : 15;/* w ww .  j  a v a2s.com*/
                    final AlertDialog alertDialog = new AlertDialog.Builder(DevicesActivity.this).create();
                    alertDialog.setTitle(loginService.getString("description"));
                    alertDialog.setCancelable(false);
                    alertDialog.setCanceledOnTouchOutside(false);
                    alertDialog.setMessage(loginService.getString("description") + "\n"
                            + "Attempting to login again in " + countdown + " seconds...");
                    alertDialog.show(); //

                    new CountDownTimer(countdown * 1000, 1000) {
                        @Override
                        public void onTick(long millisUntilFinished) {
                            try {
                                alertDialog.setMessage(loginService.getString("description") + "\n"
                                        + "Attempting to login again in " + millisUntilFinished / 1000
                                        + " seconds...");
                            } catch (JSONException e) {

                            }
                        }

                        @Override
                        public void onFinish() {
                            alertDialog.dismiss();
                            new Thread(new Runnable() {
                                public void run() {

                                    try {
                                        JSONArray services = new JSONArray();
                                        services.put(loginService);
                                        responseData.put("services", services);
                                        WeaverSdkApi.servicesSet(DevicesActivity.this, responseData);
                                    } catch (JSONException e) {

                                    }
                                }
                            }).start();

                        }
                    }.start();

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

        }

    });

}

From source file:org.projectbuendia.client.ui.dialogs.NewUserDialogFragment.java

@Override
public @NonNull Dialog onCreateDialog(Bundle savedInstanceState) {
    View fragment = mInflater.inflate(R.layout.new_user_dialog_fragment, null);
    ButterKnife.inject(this, fragment);

    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity()).setCancelable(false) // Disable auto-cancel.
            .setTitle(getResources().getString(R.string.title_new_user))
            .setPositiveButton(getResources().getString(R.string.ok), null)
            .setNegativeButton(getResources().getString(R.string.cancel), null).setView(fragment);

    final AlertDialog dialog = dialogBuilder.create();
    dialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override/*from  w w w.  java 2 s . c o  m*/
        public void onShow(DialogInterface dialogInterface) {
            dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    // Validate the user.
                    String givenName = mGivenName.getText() == null ? ""
                            : mGivenName.getText().toString().trim();
                    String familyName = mFamilyName.getText() == null ? ""
                            : mFamilyName.getText().toString().trim();
                    boolean valid = true;
                    if (givenName.isEmpty()) {
                        setError(mGivenName, R.string.given_name_cannot_be_null);
                        valid = false;
                    }
                    if (familyName.isEmpty()) {
                        setError(mFamilyName, R.string.family_name_cannot_be_null);
                        valid = false;
                    }
                    Utils.logUserAction("add_user_submitted", "valid", "" + valid, "given_name", givenName,
                            "family_name", familyName);
                    if (!valid)
                        return;

                    App.getUserManager().addUser(new JsonNewUser(givenName, familyName));
                    if (mActivityUi != null) {
                        mActivityUi.showSpinner(true);
                    }
                    dialog.dismiss();
                }
            });
        }
    });
    // Open the keyboard, ready to type into the given name field.
    dialog.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
    return dialog;
}