List of usage examples for android.app AlertDialog.Builder create
public void create()
From source file:com.mobicage.rogerthat.registration.RegistrationActivity2.java
private void popupRegisterFirst(Uri uri) { String invitorName = uri.getQueryParameter("u"); if (invitorName != null) invitorName = invitorName.replaceAll("\\+", " "); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage(getString(R.string.friend_invitation_register_first, invitorName)); builder.setPositiveButton(R.string.rogerthat, null); builder.create().show(); }
From source file:com.dev.pygmy.game.GameHomePageActivity.java
private void onReportClick() { final ArrayList<String> selectedItems = new ArrayList<String>(); final String[] reasons = getResources().getStringArray(R.array.report_reasons); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Report: " + ((TextView) findViewById(R.id.name_game)).getText()); builder.setMultiChoiceItems(reasons, null, new DialogInterface.OnMultiChoiceClickListener() { @Override/*from w ww .j a v a2 s . c om*/ public void onClick(DialogInterface dialog, int indexSelected, boolean isChecked) { String reason = reasons[indexSelected]; if (isChecked) { selectedItems.add(reason); } else if (selectedItems.contains(reason)) { selectedItems.remove(reason); } Button positiveButton = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE); positiveButton.setEnabled((selectedItems.size() != 0)); } }) // Assign action buttons .setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { new GameReportTask(GameHomePageActivity.this, selectedItems).execute(mGame.name); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { Toast.makeText(GameHomePageActivity.this, "Report canceled", Toast.LENGTH_SHORT).show(); } }); reportDialog = builder.create(); reportDialog.show(); reportDialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(false); }
From source file:org.span.manager.MainActivity.java
@Override protected Dialog onCreateDialog(int id, Bundle args) { Log.d(TAG, "onCreateDialog()"); // DEBUG if (id == ID_DIALOG_STARTING) { return onCreateDialog(id); } else if (id == ID_DIALOG_STOPPING) { return onCreateDialog(id); } else if (id == ID_DIALOG_CONNECTING) { return onCreateDialog(id); } else if (id == ID_DIALOG_CONFIG) { //Config load dialogue AlertDialog.Builder builder = new AlertDialog.Builder(this); final String filepath = args.getString("filepath"); final String filename = filepath.substring(filepath.indexOf(':') + 3); builder.setMessage("Are you sure you want to load this external configuration file?\n" + filepath) .setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { //Load the Configuration String command = "cp " + filename + " /data/data/org.span/conf/manet.conf"; System.out.println(command);//debug //CoreTask.runCommand(command); app.manet.sendManetConfigLoadCommand(filename); dialog.cancel(); }/*from w w w . j a v a 2 s .c o m*/ }).setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alert = builder.create(); return alert; } return null; }
From source file:com.juick.android.MessageMenu.java
protected void runActions() { if (!isDialogMode()) { AlertDialog.Builder builder = new AlertDialog.Builder(activity); final CharSequence[] items = new CharSequence[menuActions.size()]; for (int j = 0; j < items.length; j++) { items[j] = menuActions.get(j).title; }//from ww w .j a v a2 s . c om builder.setItems(items, this); final AlertDialog alertDialog = builder.create(); alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { ColorsTheme.ColorTheme colorTheme = JuickMessagesAdapter.getColorTheme(activity); ColorDrawable divider = new ColorDrawable( colorTheme.getColor(ColorsTheme.ColorKey.COMMON_BACKGROUND, 0xFFFFFFFF)); alertDialog.getListView().setDivider(divider); alertDialog.getListView().setDividerHeight(1); } }); alertDialog.show(); final ListAdapter adapter = alertDialog.getListView().getAdapter(); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(activity); float menuFontScale = 1; try { menuFontScale = Float.parseFloat(sp.getString("menuFontScale", "1.0")); } catch (Exception e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } final boolean compressedMenu = sp.getBoolean("compressedMenu", false); final boolean singleLineMenu = sp.getBoolean("singleLineMenu", false); final float finalMenuFontScale = menuFontScale; final int screenHeight = activity.getWindow().getWindowManager().getDefaultDisplay().getHeight(); alertDialog.getListView().setAdapter(new ListAdapter() { @Override public boolean areAllItemsEnabled() { return adapter.areAllItemsEnabled(); } @Override public boolean isEnabled(int position) { return adapter.isEnabled(position); } @Override public void registerDataSetObserver(DataSetObserver observer) { adapter.registerDataSetObserver(observer); } @Override public void unregisterDataSetObserver(DataSetObserver observer) { adapter.unregisterDataSetObserver(observer); } @Override public int getCount() { return items.length; } @Override public Object getItem(int position) { return adapter.getItem(position); } @Override public long getItemId(int position) { return adapter.getItemId(position); } @Override public boolean hasStableIds() { return adapter.hasStableIds(); } @Override public View getView(int position, View convertView, ViewGroup parent) { View retval = adapter.getView(position, null, parent); if (retval instanceof TextView) { TextView tv = (TextView) retval; if (compressedMenu) { int minHeight = (int) ((screenHeight * 0.7) / getCount()); tv.setMinHeight(minHeight); tv.setMinimumHeight(minHeight); } if (singleLineMenu) { tv.setSingleLine(true); tv.setEllipsize(TextUtils.TruncateAt.MIDDLE); } tv.setTextSize(22 * finalMenuFontScale); } return retval; } @Override public int getItemViewType(int position) { return adapter.getItemViewType(position); } @Override public int getViewTypeCount() { return adapter.getViewTypeCount(); } @Override public boolean isEmpty() { return adapter.isEmpty(); } }); } else { AlertDialog.Builder builder = new AlertDialog.Builder( new ContextThemeWrapper(activity, R.style.Theme_Sherlock)); View dialogView = activity.getLayoutInflater().inflate(R.layout.message_menu2, null); builder.setView(dialogView); builder.setCancelable(true); int width = activity.getWindowManager().getDefaultDisplay().getWidth(); View scrollView = dialogView.findViewById(R.id.scrollView); scrollView.getLayoutParams().width = (int) (width * 0.90); final AlertDialog alertDialog = builder.create(); alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { //MainActivity.restyleChildrenOrWidget(alertDialog.getWindow().getDecorView()); } }); TextView messageNo = (TextView) dialogView.findViewById(R.id.message_no); messageNo.setText(listSelectedItem.getDisplayMessageNo()); Spinner openUrl = (Spinner) dialogView.findViewById(R.id.open_url); Button singleURL = (Button) dialogView.findViewById(R.id.single_url); if (urls != null && urls.size() == 1) { singleURL.setVisibility(View.VISIBLE); openUrl.setVisibility(View.GONE); SpannableStringBuilder sb = new SpannableStringBuilder(); sb.append(urls.get(0)); sb.setSpan(new UnderlineSpan(), 0, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); singleURL.setText(sb); singleURL.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); launchURL(listSelectedItem.getMID(), urls.get(0)); } }); } else if (urls != null && urls.size() > 0) { singleURL.setVisibility(View.GONE); openUrl.setVisibility(View.VISIBLE); openUrl.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (position != 0) { alertDialog.dismiss(); launchURL(listSelectedItem.getMID(), urls.get(position)); } } @Override public void onNothingSelected(AdapterView<?> parent) { //To change body of implemented methods use File | Settings | File Templates. } }); urls.add(0, activity.getString(R.string.ClickToSelectURL)); openUrl.setAdapter(new BaseAdapter() { @Override public int getCount() { return urls.size(); } @Override public Object getItem(int position) { return position; } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { View rowView = activity.getLayoutInflater().inflate(android.R.layout.simple_list_item_1, null); TextView textView = (TextView) rowView.findViewById(android.R.id.text1); textView.setSingleLine(false); textView.setMaxLines(5); SpannableStringBuilder sb = new SpannableStringBuilder(); sb.append(urls.get(position)); if (position == 0) { textView.setTextColor(0xFF808080); } else { sb.setSpan(new UnderlineSpan(), 0, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } textView.setText(sb); return rowView; } }); } else { openUrl.setVisibility(View.GONE); singleURL.setVisibility(View.GONE); } final String UName = listSelectedItem.User.UName; View recommendMessage = dialogView.findViewById(R.id.recommend_message); View deleteMessage = dialogView.findViewById(R.id.delete_message); View saveMessage = dialogView.findViewById(R.id.save_message); View unsaveMessage = dialogView.findViewById(R.id.unsave_message); //View subscribeUser = dialogView.findViewById(R.id.subscribe_user); View subscribeMessage = dialogView.findViewById(R.id.subscribe_message); //View unsubscribeUser = dialogView.findViewById(R.id.unsubscribe_user); View unsubscribeMessage = dialogView.findViewById(R.id.unsubscribe_message); View translateMessage = dialogView.findViewById(R.id.translate_message); View shareMessage = dialogView.findViewById(R.id.share_message); //View blacklistUser = dialogView.findViewById(R.id.blacklist_user); //View filterUser = dialogView.findViewById(R.id.filter_user); //View userBlog = dialogView.findViewById(R.id.user_blog); //View userStats = dialogView.findViewById(R.id.user_stats); View openMessageInBrowser = dialogView.findViewById(R.id.open_message_in_browser); Button userCenter = (Button) dialogView.findViewById(R.id.user_center); if (null == dialogView.findViewById(R.id.column_3)) { // only for portrait userCenter.setText("@" + listSelectedItem.User.UName + " " + userCenter.getText()); } unsubscribeMessage.setEnabled(listSelectedItem.getRID() == 0); subscribeMessage.setEnabled(listSelectedItem.getRID() == 0); unsaveMessage.setEnabled(listSelectedItem.getRID() == 0); recommendMessage.setEnabled(listSelectedItem.getRID() == 0); if (UName.equalsIgnoreCase(JuickAPIAuthorizer.getJuickAccountName(activity.getApplicationContext()))) { recommendMessage.setVisibility(View.GONE); } else { deleteMessage.setVisibility(View.GONE); } if (messagesSource instanceof SavedMessagesSource) { saveMessage.setVisibility(View.GONE); } else { unsaveMessage.setVisibility(View.GONE); } recommendMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionRecommendMessage(); } }); deleteMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionDeleteMessage(); } }); saveMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionSaveMessage(); } }); unsaveMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionUnsaveMessage(); } }); // subscribeUser.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionSubscribeUser(); // } // }); subscribeMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionSubscribeMessage(); } }); // unsubscribeUser.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionUnsubscribeUser(); // } // }); unsubscribeMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionUnsubscribeMessage(); } }); translateMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionTranslateMessage(); } }); shareMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionShareMessage(); } }); // blacklistUser.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionBlacklistUser(); // } // }); // filterUser.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionFilterUser(UName); // } // }); // userBlog.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionUserBlog(); // } // }); // userStats.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionUserStats(); // } // }); openMessageInBrowser.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionOpenMessageInBrowser(); } }); userCenter.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionUserCenter(); } }); completeInitDialogMode(alertDialog, dialogView); alertDialog.show(); } }
From source file:cm.aptoide.pt.ManageRepo.java
@Override public boolean onMenuItemSelected(int featureId, MenuItem item) { LayoutInflater li = LayoutInflater.from(this); switch (item.getItemId()) { case ADD_REPO: View view = li.inflate(R.layout.addrepo, null); final TextView sec_msg = (TextView) view.findViewById(R.id.sec_msg); final TextView sec_msg2 = (TextView) view.findViewById(R.id.sec_msg2); 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); }// w w w. j a v a 2s . c om } }); Builder p = new AlertDialog.Builder(this).setView(view); alrt = p.create(); alrt.setIcon(android.R.drawable.ic_menu_add); alrt.setTitle("Add new repository"); alrt.setButton("Add", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Message msg = new Message(); EditText uri = (EditText) alrt.findViewById(R.id.edit_uri); String uri_str = uri.getText().toString(); sec_msg.setVisibility(View.GONE); sec_msg2.setVisibility(View.GONE); if (sec.isChecked()) { String user = sec_user.getText().toString(); String pwd = sec_pwd.getText().toString(); int result = checkServer(uri_str, user, pwd); if (result == 200) { msg.obj = 0; db.addServer(uri_str); db.addLogin(user, pwd, uri_str); change = true; redraw(); } else if (result == 401) { sec_msg2.setText("Login is wrong"); sec_msg2.setVisibility(View.VISIBLE); msg.obj = 1; } else { sec_msg.setText("Can't connect to server"); sec_msg.setVisibility(View.VISIBLE); msg.obj = 1; } } else { int result = checkServer(uri_str, null, null); if (result == 200) { msg.obj = 0; db.addServer(uri_str); change = true; redraw(); } else if (result == 401) { sec_msg2.setText("Login required"); sec_msg2.setVisibility(View.VISIBLE); msg.obj = 1; } else { sec_msg.setText("Can't connect to server"); sec_msg.setVisibility(View.VISIBLE); msg.obj = 1; } } new_repo.sendMessage(msg); } }); alrt.setButton2("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { alrt.dismiss(); } }); alrt.show(); break; case REM_REPO: final Vector<String> rem_lst = new Vector<String>(); CharSequence[] b = new CharSequence[server_lst.size()]; for (int i = 0; i < server_lst.size(); i++) { b[i] = server_lst.get(i).uri; } AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Chose repository to remove"); builder.setIcon(android.R.drawable.ic_menu_close_clear_cancel); builder.setMultiChoiceItems(b, null, new DialogInterface.OnMultiChoiceClickListener() { public void onClick(DialogInterface dialog, int whichButton, boolean isChecked) { if (isChecked) { rem_lst.addElement(server_lst.get(whichButton).uri); } else { rem_lst.removeElement(server_lst.get(whichButton).uri); } } }); builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { db.removeServer(rem_lst); change = true; redraw(); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { return; } }); AlertDialog alert = builder.create(); alert.show(); break; case EDIT_REPO: CharSequence[] b2 = new CharSequence[server_lst.size()]; for (int i = 0; i < server_lst.size(); i++) { b2[i] = server_lst.get(i).uri; } AlertDialog.Builder builder2 = new AlertDialog.Builder(this); builder2.setTitle("Chose repository to edit"); builder2.setIcon(android.R.drawable.ic_menu_edit); builder2.setSingleChoiceItems(b2, -1, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { updt_repo = server_lst.get(which).uri; } }); builder2.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { editRepo(updt_repo); return; } }); builder2.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { return; } }); alert2 = builder2.create(); alert2.show(); break; } return super.onMenuItemSelected(featureId, item); }
From source file:com.zertinteractive.wallpaper.MainActivity.java
public void helpDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(this); LayoutInflater inflater = getLayoutInflater(); builder.setView(inflater.inflate(R.layout.info_dialog, null)); AlertDialog ad = builder.create(); ad.setTitle("Mood Wallpaper"); ad.setButton(AlertDialog.BUTTON_NEGATIVE, "OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { }/*from w w w. j a v a 2 s.c o m*/ }); ad.show(); TextView noteView = (TextView) ad.findViewById(R.id.web_link); noteView.setText("www.somthing.com/zert"); Linkify.addLinks(noteView, Linkify.ALL); TextView email = (TextView) ad.findViewById(R.id.email_zert); email.setText("zert@gmail.com"); Linkify.addLinks(email, Linkify.EMAIL_ADDRESSES); }
From source file:pl.bcichecki.rms.client.android.activities.EditEventActivity.java
private void createRecipentsListDialog() { usernames = new String[participants.size()]; chosenParticipants = new boolean[participants.size()]; for (int i = 0; i < participants.size(); i++) { usernames[i] = participants.get(i).getUsername(); }/*from w w w .ja v a2 s .co m*/ AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context); dialogBuilder.setTitle(R.string.activity_edit_event_pick_participants); dialogBuilder.setMultiChoiceItems(usernames, chosenParticipants, new DialogInterface.OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialog, int which, boolean isChecked) { if (isChecked) { pickedParticipants.add(participants.get(which)); participantsText.setError(null); } else { pickedParticipants.remove(participants.get(which)); } updateParticipantsText(); } }); dialogBuilder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Nothing to do... } }); participantsListDialog = dialogBuilder.create(); }
From source file:com.mobicage.rogerthat.registration.RegistrationActivity2.java
private void requestPin() { final String email = mEnterEmailAutoCompleteTextView.getText().toString().toLowerCase().trim(); // Validate input if (!RegexPatterns.EMAIL.matcher(email).matches()) { AlertDialog.Builder builder = new AlertDialog.Builder(RegistrationActivity2.this); builder.setMessage(R.string.registration_email_not_valid); builder.setPositiveButton(R.string.rogerthat, null); AlertDialog dialog = builder.create(); dialog.show();//from www .j a v a 2 s .c o m return; } // Check network connectivity if (!mService.getNetworkConnectivityManager().isConnected()) { UIUtils.showNoNetworkDialog(this); return; } UIUtils.hideKeyboard(this, mEnterEmailAutoCompleteTextView); sendRegistrationRequest(email); }
From source file:de.da_sense.moses.client.FormFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); //============ HANDLING OF BUTTONS SHOWN IN FRAGMENT ======================== LinearLayout formButtonContainer = (LinearLayout) mLayoutInflater.inflate(R.layout.form_button_container, generateQuestionContainer((ViewGroup) mRoot.findViewById(R.id.ll_quest))); final ViewPager viewPager = (ViewPager) mRoot.getParent().getParent(); Button buttonPrevious = (Button) formButtonContainer.findViewById(R.id.button_form_previous); Button buttonNext = (Button) formButtonContainer.findViewById(R.id.button_form_next); if (mIsFirst) buttonPrevious.setVisibility(View.GONE); else/*from w w w. java 2 s . c o m*/ buttonPrevious.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { int curPosition = viewPager.getCurrentItem(); viewPager.setCurrentItem(curPosition - 1, true); } }); if (mIsLast) { buttonNext.setText(getString(R.string.q_send)); buttonNext.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // User clicked SEND button // special care for text questions Set<Question> questions = mQuestionEditTextMappings.keySet(); for (Question question : questions) { String finalAnswerOfUser = mQuestionEditTextMappings.get(question).getText().toString(); question.setAnswer(finalAnswerOfUser); } // ===== MANDATORY QUESTION FILLED CHECK ====== // Survey theSurvey = InstalledExternalApplicationsManager.getInstance().getAppForId(mAPKID) .getSurvey(); List<Form> forms = theSurvey.getForms(); Collections.sort(forms); // iterate over all forms and the over all questions and check if there is // a mandatory question that is not filled boolean mayBeSent = true; // set to true only if the survey may be sent for (Form form : forms) { boolean formWithUnansweredQuestionFound = false; List<Question> questionsToCheck = form.getQuestions(); Collections.sort(questionsToCheck); for (Question questionToCheck : questionsToCheck) { if (questionToCheck.isMandatory()) { // check if we have an answer if (questionToCheck.getAnswer().equals(Question.ANSWER_UNANSWERED)) { // the question is unanswered although mandatory, take action mayBeSent = false; int formPosition = forms.indexOf(form); // go to the tab with containing the question Toaster.showToast(getActivity(), getString(R.string.notification_mandatory_question_unanswered)); if (mPosition == formPosition) { // the unanswered mandatory question is in this FormFragment // just scroll to the question (EditText representing the title of the question) scrollToQuestion(questionToCheck); formWithUnansweredQuestionFound = true; break; } else { // the question is not in this FormFragment // leave a message to this fragment and page to his position // that fragment should take care of scrolling Intent activityIntent = getActivity().getIntent(); activityIntent.putExtra(KEY_POSITION_OF_FRAGMENT_WHICH_SHOULD_SCROLL, formPosition); activityIntent.putExtra(KEY_QUESTION_TO_SCROLL_TO, questionToCheck.getId()); viewPager.setCurrentItem(formPosition, true); formWithUnansweredQuestionFound = true; break; } } } } if (formWithUnansweredQuestionFound) break; } // ===== END MANDATORY QUESTION CHECK END ========= // if (mayBeSent) {// send to server only if all mandatory questions were filled AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); // Add the buttons builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { sendAnswersToServer(); } }); builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // User cancelled the dialog dialog.dismiss(); } }); builder.setMessage(R.string.surveySendToServerMessage) .setTitle(R.string.surveySendToServerTitle); // Create the AlertDialog AlertDialog dialog = builder.create(); dialog.show(); } } }); if (mBelongsTo == WelcomeActivityPagerAdapter.TAB_HISTORY) buttonNext.setVisibility(View.GONE); // disable sending button if we are viewing the survey from history tab } else buttonNext.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { int curPosition = viewPager.getCurrentItem(); viewPager.setCurrentItem(curPosition + 1, true); } }); //============ END HANDLING OF BUTTONS SHOWN IN FRAGMENT END ======================== }
From source file:app.hacked.ChatFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.chat_fragment, null); Message = (EditText) view.findViewById(R.id.chatText); ((ImageButton) view.findViewById(R.id.sendButton)).setOnClickListener(new View.OnClickListener() { @Override//from w w w. ja va2 s. com public void onClick(View view) { if (!canPost) { //Toast.makeText(getActivity(), "You need to agree to the Hacked.io Terms of Attendance before posting", Toast.LENGTH_SHORT).show(); //return; if (settings.getBoolean("agreetoChat", false)) { canPost = true; } else { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); // Add the buttons builder.setPositiveButton("I agree", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { SharedPreferences.Editor editor = PreferenceManager .getDefaultSharedPreferences(getActivity()).edit(); editor.putBoolean("agreetoChat", true); editor.commit(); dialog.dismiss(); canPost = true; } }); builder.setNegativeButton("Nope", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { SharedPreferences.Editor editor = PreferenceManager .getDefaultSharedPreferences(getActivity()).edit(); editor.putBoolean("agreetoChat", false); editor.commit(); dialog.dismiss(); canPost = false; } }); builder.setMessage(getString(R.string.ChatTandC)); // Create the AlertDialog AlertDialog dialog = builder.create(); dialog.setCancelable(false); dialog.show(); } return; } progressBar.setVisibility(View.VISIBLE); Message.setEnabled(false); final String msg = Message.getText().toString(); JSONObject post = new JSONObject(); try { try { post.put("name", accounts[0].name); } catch (Exception e) { e.printStackTrace(); post.put("name", "Anon"); } post.put("msg", msg); post.put("auth", API.md5(API.BETTER_THAN_NOTHING_STUFF_TO_PREVENT_INJECTION_ATTEMPTS + msg)); } catch (Exception e) { e.printStackTrace(); Toast.makeText(getActivity(), "An Error Was encountered parsing the entered details: " + e.getMessage(), Toast.LENGTH_SHORT).show(); return; } JsonObjectRequest jsObjRequest = new JsonObjectRequest(Request.Method.POST, "http://hackedioapp.networksaremadeofstring.co.uk/addchatmsg.php", post, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { Log.e("response", response.toString()); try { if (response.has("success") && response.getBoolean("success")) { //Toast.makeText(getActivity(), "Project added successfully!", Toast.LENGTH_SHORT).show(); //adapter.ChatMessages.add(new ChatMessage(accounts[0].name,msg)); //adapter.notifyDataSetChanged(); Message.setText(""); progressBar.setVisibility(View.INVISIBLE); Message.setEnabled(true); } else { Toast.makeText(getActivity(), "An Error Was encountered", Toast.LENGTH_SHORT).show(); Message.setEnabled(true); } } catch (Exception e) { e.printStackTrace(); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { // TODO Auto-generated method stub Toast.makeText(getActivity(), "An Error Was encountered: " + error.getMessage(), Toast.LENGTH_SHORT).show(); } }); queue.add(jsObjRequest); } }); progressBar = view.findViewById(R.id.progressBar); return view; }