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:fr.forexperts.ui.MarketOverviewFragment.java

public void showAddDialog() {
    LayoutInflater inflater = LayoutInflater.from(getActivity());
    View alertView = inflater.inflate(R.layout.alertdialog_add_value, null);

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setView(alertView);//from   w  w  w  . j a v  a  2s  .  c om
    final AlertDialog dialog = builder.create();
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

    WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes();
    wmlp.gravity = Gravity.TOP | Gravity.CENTER;
    wmlp.x = 10;
    wmlp.y = 10;

    final EditText mStockName = (EditText) alertView.findViewById(R.id.stockName);
    mListViewStock = (ListView) alertView.findViewById(R.id.listViewStock);
    mListViewStock.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String text = (String) parent.getItemAtPosition(position);
            String[] result = text.split(" ");
            mCallback.onItemSelect(result[0]);
            dialog.dismiss();
        }
    });

    mStockName.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

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

        @Override
        public void afterTextChanged(Editable s) {
            SuggestStockTask task = new SuggestStockTask();
            task.execute(mStockName.getText().toString());
        }
    });

    // TODO: Change hard coded width
    mStockName.setWidth(10000);

    dialog.show();
}

From source file:com.aniruddhc.acemusic.player.FoldersFragment.FilesFoldersFragment.java

/**
 * Displays a "Rename" dialog and renames the specified file/folder.
 *
 * @param path The path of the folder/file that needs to be renamed.
 *///from   ww w.j  av  a 2s  . com
public void rename(String path) {

    final File renameFile = new File(path);
    final AlertDialog renameAlertDialog = new AlertDialog.Builder(getActivity()).create();
    final EditText fileEditText = new EditText(getActivity());

    fileEditText.setHint(R.string.file_name);
    fileEditText.setSingleLine(true);
    fileEditText.setText(renameFile.getName());

    renameAlertDialog.setView(fileEditText);
    renameAlertDialog.setTitle(R.string.rename);
    renameAlertDialog.setButton(DialogInterface.BUTTON_NEGATIVE,
            mContext.getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    renameAlertDialog.dismiss();
                }

            });

    renameAlertDialog.setButton(DialogInterface.BUTTON_POSITIVE,
            mContext.getResources().getString(R.string.rename), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {

                    //Check if the new file name is empty.
                    if (fileEditText.getText().toString().isEmpty()) {
                        Toast.makeText(getActivity(), R.string.enter_a_name_for_folder, Toast.LENGTH_LONG)
                                .show();
                    } else {

                        File newNameFile = null;
                        try {
                            newNameFile = new File(renameFile.getParentFile().getCanonicalPath() + "/"
                                    + fileEditText.getText().toString());
                        } catch (IOException e) {
                            e.printStackTrace();
                            Toast.makeText(getActivity(), R.string.folder_could_not_be_renamed,
                                    Toast.LENGTH_LONG).show();
                            return;
                        }

                        try {
                            if (renameFile.isDirectory())
                                FileUtils.moveDirectory(renameFile, newNameFile);
                            else
                                FileUtils.moveFile(renameFile, newNameFile);

                        } catch (IOException e) {
                            e.printStackTrace();
                            Toast.makeText(getActivity(), R.string.folder_could_not_be_renamed,
                                    Toast.LENGTH_LONG).show();
                            return;
                        }

                        Toast.makeText(getActivity(), R.string.folder_renamed, Toast.LENGTH_SHORT).show();
                        renameAlertDialog.dismiss();
                        refreshListView();

                    }

                }

            });

    renameAlertDialog.show();

}

From source file:com.dycode.jepretstory.mediachooser.activity.BucketHomeFragmentActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode == Activity.RESULT_OK) {

        if (requestCode == MediaChooserConstants.BUCKET_SELECT_IMAGE_CODE) {
            //reset
            //addMedia(mSelectedImage, data.getStringArrayListExtra("list"));
            addMediaModel(mSelectedImages, data.getParcelableArrayListExtra("selectedImages"));

            if (mImageFragment != null) {
                mImageFragment.setCurrentSelectedImages(mSelectedImages);
            }//from   ww w  .  j av  a  2s.c om

            onImageSelectedCount(mSelectedImages.size());

        } else if (requestCode == MediaChooserConstants.BUCKET_SELECT_VIDEO_CODE) {
            //reset
            //addMedia(mSelectedVideo, data.getStringArrayListExtra("list"));
            addMediaModel(mSelectedVideos, data.getParcelableArrayListExtra("selectedVideos"));

            if (mVideoFragment != null) {
                mVideoFragment.setCurrentSelectedVideos(mSelectedVideos);
            }

            onVideoSelectedCount(mSelectedVideos.size());

        } else if (requestCode == MediaChooserConstants.CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {

            sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, fileUri));

            final AlertDialog alertDialog = MediaChooserConstants.getDialog(BucketHomeFragmentActivity.this)
                    .create();
            alertDialog.show();

            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    // Do something after 2000ms
                    String fileUriString = fileUri.toString().replaceFirst("file:///", "/").trim();

                    if (mImageFragment != null) {
                        mImageFragment.getAdapter().addLatestEntry(fileUriString);
                        mImageFragment.getAdapter().notifyDataSetChanged();
                    }
                    alertDialog.dismiss();
                }
            }, 5000);

        } else if (requestCode == MediaChooserConstants.CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE) {

            sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, fileUri));

            final AlertDialog alertDialog = MediaChooserConstants.getDialog(BucketHomeFragmentActivity.this)
                    .create();
            alertDialog.show();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    // Do something after 2000ms
                    String fileUriString = fileUri.toString().replaceFirst("file:///", "/").trim();

                    if (mVideoFragment != null) {
                        mVideoFragment.getAdapter().addLatestEntry(fileUriString);
                        mVideoFragment.getAdapter().notifyDataSetChanged();
                    }

                    //add to mediastore
                    //addVideoToMediaStore(fileUri);

                    alertDialog.dismiss();
                }
            }, 5000);
        }
    }
}

From source file:com.xuejian.client.lxp.module.toolbox.im.IMMainActivity.java

private void showActionDialog() {
    final Activity act = this;
    final AlertDialog dialog = new AlertDialog.Builder(act).create();
    View contentView = View.inflate(act, R.layout.dialog_city_detail_action, null);
    Button btn = (Button) contentView.findViewById(R.id.btn_go_plan);
    btn.setText("Talk");
    btn.setOnClickListener(new View.OnClickListener() {
        @Override// w  ww . j  a  va2s  .  c  o  m
        public void onClick(View view) {
            MobclickAgent.onEvent(mContext, "event_create_new_talk");
            startActivityForResult(new Intent(IMMainActivity.this, PickContactsWithCheckboxActivity.class)
                    .putExtra("request", NEW_CHAT_REQUEST_CODE), NEW_CHAT_REQUEST_CODE);
            dialog.dismiss();
        }
    });
    Button btn1 = (Button) contentView.findViewById(R.id.btn_go_share);
    btn1.setText("?");
    btn1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            MobclickAgent.onEvent(mContext, "event_add_new_friend");
            startActivity(new Intent(IMMainActivity.this, AddContactActivity.class));
            dialog.dismiss();
        }
    });
    contentView.findViewById(R.id.btn_cancle).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
        }
    });
    dialog.show();
    WindowManager windowManager = act.getWindowManager();
    Window window = dialog.getWindow();
    window.setContentView(contentView);
    Display display = windowManager.getDefaultDisplay();
    WindowManager.LayoutParams lp = window.getAttributes();
    lp.width = (int) (display.getWidth()); // 
    window.setAttributes(lp);
    window.setGravity(Gravity.BOTTOM); // ?dialog?
    window.setWindowAnimations(R.style.SelectPicDialog); // 
}

From source file:fr.forexperts.ui.PortfolioFragment.java

public void showAddDialog() {
    LayoutInflater inflater = LayoutInflater.from(getActivity());
    View alertView = inflater.inflate(R.layout.alertdialog_add_value, null);

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setView(alertView);//w ww .j  av  a  2s .  c  o m
    final AlertDialog dialog = builder.create();
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

    WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes();
    wmlp.gravity = Gravity.TOP | Gravity.CENTER;
    wmlp.x = 10;
    wmlp.y = 10;

    final EditText mStockName = (EditText) alertView.findViewById(R.id.stockName);
    mListViewStock = (ListView) alertView.findViewById(R.id.listViewStock);
    mListViewStock.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String text = (String) parent.getItemAtPosition(position);
            String[] result = text.split(" ");

            AddTickerTask task = new AddTickerTask();
            task.execute(result[0]);

            dialog.dismiss();
        }
    });

    mStockName.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

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

        @Override
        public void afterTextChanged(Editable s) {
            SuggestStockTask task = new SuggestStockTask();
            task.execute(mStockName.getText().toString());
        }
    });

    // TODO: Change hard coded width
    mStockName.setWidth(10000);

    dialog.show();
}

From source file:org.apps8os.motivator.ui.MoodHistoryActivity.java

/**
 * Actions for the menu items.//from w  w  w  .  j  ava  2  s. c o m
 */
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    MoodHistoryWeekFragment weekFragment;
    switch (item.getItemId()) {
    // Search functionality for the search button
    case R.id.mood_history_search:
        // Spawn a dialog fragment so that the user can select a day.
        DialogFragment dialog = new DatePickerFragment();
        dialog.show(getFragmentManager(), "datePicker");
        return true;
    case R.id.mood_history_attribute_drinking:
        // Setting the selected attribute in landscape view.
        mSelectedAttribute = DayInHistory.AMOUNT_OF_DRINKS;
        weekFragment = mPagerAdapterWeek.getWeekFragment(mViewPager.getCurrentItem());
        weekFragment.updateSelectedAttribute(DayInHistory.AMOUNT_OF_DRINKS, false);
        return true;
    case R.id.mood_history_attribute_moods:
        mSelectedAttribute = DayInHistory.MOODS;
        weekFragment = mPagerAdapterWeek.getWeekFragment(mViewPager.getCurrentItem());
        weekFragment.updateSelectedAttribute(DayInHistory.MOODS, false);
        return true;
    case R.id.mood_history_change_sprint:
        // Spawn a dialog where the user can select the sprint depicted in this history.
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        final Sprint[] sprints = new SprintDataHandler(this).getSprints();

        // Get the string representations of the sprints.
        String[] sprintsAsString = new String[sprints.length];
        for (int i = 0; i < sprints.length; i++) {
            sprintsAsString[i] = sprints[i].getSprintTitle() + " " + sprints[i].getStartTimeInString(this);
        }
        builder.setTitle(getString(R.string.select_sprint)).setSingleChoiceItems(sprintsAsString,
                sprints.length - 1, null);
        final AlertDialog alertDialog = builder.create();
        final Activity thisActivity = this;
        alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.ok),
                new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // Start this activity again with the selected sprint as the passed Parcelable Sprint.
                        // This is done so that the activity can update itself to the selected sprint.
                        mCurrentSprint = sprints[alertDialog.getListView().getCheckedItemPosition()];
                        Intent intent = new Intent(thisActivity, MoodHistoryActivity.class);
                        intent.putExtra(Sprint.CURRENT_SPRINT, mCurrentSprint);
                        startActivity(intent);
                        alertDialog.dismiss();
                        thisActivity.finish();
                    }
                });
        alertDialog.show();
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.annuletconsulting.homecommand.node.MainActivity.java

private boolean openSettings() {
    final View layout = getLayoutInflater().inflate(R.layout.server_dialog, null);
    final AlertDialog dialog = new AlertDialog.Builder(this).setView(layout).create();
    ((EditText) layout.findViewById(R.id.server_ip)).setText(getValueFromSharedPreferences(SERVER));
    ((EditText) layout.findViewById(R.id.port)).setText(getValueFromSharedPreferences(PORT));
    ((EditText) layout.findViewById(R.id.shared_key)).setText(getValueFromSharedPreferences(SHARED_KEY));
    ((CheckBox) layout.findViewById(R.id.encrypt_checkbox))
            .setChecked("Y".equals(getValueFromSharedPreferences(ENCRPYT_CMD)));
    ((Button) layout.findViewById(R.id.dialog_save)).setOnClickListener(new OnClickListener() {
        @Override/*from   w  w  w. j  a  va2s.c o  m*/
        public void onClick(View v) {
            storeValueInSharedPreferences(SERVER,
                    ((EditText) layout.findViewById(R.id.server_ip)).getText().toString());
            storeValueInSharedPreferences(PORT,
                    ((EditText) layout.findViewById(R.id.port)).getText().toString());
            storeValueInSharedPreferences(SHARED_KEY,
                    ((EditText) layout.findViewById(R.id.shared_key)).getText().toString());
            storeValueInSharedPreferences(ENCRPYT_CMD,
                    ((CheckBox) layout.findViewById(R.id.encrypt_checkbox)).isChecked() ? "Y" : "N");
            dialog.dismiss();
        }
    });
    ((Button) layout.findViewById(R.id.dialog_close)).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
        }
    });
    dialog.show();
    return false;
}

From source file:com.ushahidi.android.app.ui.phone.AddReportActivity.java

/**
 * Create various dialog/* w w w .  j av a2s .co m*/
 */
@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DIALOG_ERROR_NETWORK: {
        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.network_error));
        dialog.setMessage(getString(R.string.network_error_msg));
        dialog.setButton2(getString(R.string.ok), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        dialog.setCancelable(false);
        return dialog;
    }
    case DIALOG_ERROR_SAVING: {
        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.network_error));
        dialog.setMessage(getString(R.string.file_system_error_msg));
        dialog.setButton2(getString(R.string.ok), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        dialog.setCancelable(false);
        return dialog;
    }

    case DIALOG_CHOOSE_IMAGE_METHOD: {

        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.choose_method));
        dialog.setMessage(getString(R.string.how_to_select_pic));
        dialog.setButton(getString(R.string.gallery_option), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_PICK);
                intent.setData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(intent, REQUEST_CODE_IMAGE);
                dialog.dismiss();
            }
        });
        dialog.setButton2(getString(R.string.cancel), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        dialog.setButton3(getString(R.string.camera_option), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                intent.putExtra(MediaStore.EXTRA_OUTPUT,
                        PhotoUtils.getPhotoUri(photoName, AddReportActivity.this));
                startActivityForResult(intent, REQUEST_CODE_CAMERA);
                dialog.dismiss();
            }
        });

        dialog.setCancelable(false);
        return dialog;
    }

    case DIALOG_MULTIPLE_CATEGORY: {
        if (showCategories() != null) {
            return new AlertDialog.Builder(this).setTitle(R.string.choose_categories)
                    .setMultiChoiceItems(showCategories(), setCheckedCategories(),
                            new DialogInterface.OnMultiChoiceClickListener() {
                                public void onClick(DialogInterface dialog, int whichButton,
                                        boolean isChecked) {
                                    // see if categories have previously

                                    if (isChecked) {
                                        mVectorCategories.add(mCategoriesId.get(whichButton));

                                        mError = false;
                                    } else {
                                        mVectorCategories.remove(mCategoriesId.get(whichButton));
                                    }

                                    setSelectedCategories(mVectorCategories);
                                }
                            })
                    .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {

                            /* User clicked Yes so do some stuff */
                        }
                    }).create();
        }
    }

    case TIME_DIALOG_ID:
        return new TimePickerDialog(this, mTimeSetListener, mCalendar.get(Calendar.HOUR),
                mCalendar.get(Calendar.MINUTE), false);

    case DATE_DIALOG_ID:
        return new DatePickerDialog(this, mDateSetListener, mCalendar.get(Calendar.YEAR),
                mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH));

    case DIALOG_SHOW_MESSAGE:
        AlertDialog.Builder messageBuilder = new AlertDialog.Builder(this);
        messageBuilder.setMessage(mErrorMessage).setPositiveButton(getString(R.string.ok),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });

        AlertDialog showDialog = messageBuilder.create();
        showDialog.show();
        break;

    case DIALOG_SHOW_REQUIRED:
        AlertDialog.Builder requiredBuilder = new AlertDialog.Builder(this);
        requiredBuilder.setTitle(R.string.required_fields);
        requiredBuilder.setMessage(mErrorMessage).setPositiveButton(getString(R.string.ok),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });

        AlertDialog showRequiredDialog = requiredBuilder.create();
        showRequiredDialog.show();
        break;

    // prompt for unsaved changes
    case DIALOG_SHOW_PROMPT: {
        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.unsaved_changes));
        dialog.setMessage(getString(R.string.want_to_cancel));
        dialog.setButton(getString(R.string.no), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {

                dialog.dismiss();
            }
        });
        dialog.setButton2(getString(R.string.yes), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                finish();
                dialog.dismiss();
            }
        });

        dialog.setCancelable(false);
        return dialog;
    }

    // prompt for report deletion
    case DIALOG_SHOW_DELETE_PROMPT: {
        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.delete_report));
        dialog.setMessage(getString(R.string.want_to_delete));
        dialog.setButton(getString(R.string.no), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {

                dialog.dismiss();
            }
        });
        dialog.setButton2(getString(R.string.yes), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                // delete report
                deleteReport();
                dialog.dismiss();
            }
        });

        dialog.setCancelable(false);
        return dialog;
    }

    }
    return null;
}

From source file:com.oasis.sdk.activity.OasisSdkPayEpinActivity.java

private void showResultDialog(final String res) {
    final AlertDialog d = new AlertDialog.Builder(this).create();
    d.show();//  w  w w .ja  v  a2 s .  co  m
    d.setContentView(BaseUtils.getResourceValue("layout", "oasisgames_sdk_common_dialog_notitle"));
    d.setCanceledOnTouchOutside(false);

    TextView tv_content = (TextView) d
            .findViewById(BaseUtils.getResourceValue("id", "oasisgames_sdk_common_dialog_notitle_content"));
    String content = getResources().getString(BaseUtils.getResourceValue("string",
            TextUtils.isEmpty(res) ? "oasisgames_sdk_epin_notice_3" : "oasisgames_sdk_epin_notice_4"));
    content = content.replace("DIAMOND", res);
    tv_content.setText(content);

    TextView tv_sure = (TextView) d
            .findViewById(BaseUtils.getResourceValue("id", "oasisgames_sdk_common_dialog_notitle_sure"));
    tv_sure.setText(
            getResources().getString(BaseUtils.getResourceValue("string", "oasisgames_sdk_common_btn_sure")));
    tv_sure.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            if (!TextUtils.isEmpty(res))
                et_code.setText("");
            d.dismiss();
        }
    });
    TextView tv_cancle = (TextView) d
            .findViewById(BaseUtils.getResourceValue("id", "oasisgames_sdk_common_dialog_notitle_cancle"));
    tv_cancle.setVisibility(View.GONE);

    TextView tv_text = (TextView) d
            .findViewById(BaseUtils.getResourceValue("id", "oasisgames_sdk_common_dialog_notitle_text"));
    tv_text.setVisibility(View.GONE);

}

From source file:org.dkf.jmule.util.UIUtils.java

/**
 *
 * @param context -  containing Context.
 * @param showInstallationCompleteSection - true if you want to display "Your installation is now complete. Thank You" section
 * @param dismissListener - what happens when the dialog is dismissed.
 * @param referrerContextSuffix - string appended at the end of social pages click urls's ?ref=_android_ parameter.
 *///w ww  .j av a  2  s. co  m
public static void showSocialLinksDialog(final Context context, boolean showInstallationCompleteSection,
        DialogInterface.OnDismissListener dismissListener, String referrerContextSuffix) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    View customView = View.inflate(context, R.layout.view_social_buttons, null);
    builder.setView(customView);
    builder.setPositiveButton(context.getString(android.R.string.ok), new OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    final AlertDialog socialLinksDialog = builder.create();
    socialLinksDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    socialLinksDialog.setOnDismissListener(dismissListener);

    ImageButton githubButton = (ImageButton) customView.findViewById(R.id.view_buttons_github);
    //ImageButton twitterButton = (ImageButton) customView.findViewById(R.id.view_social_buttons_twitter_button);
    //ImageButton redditButton = (ImageButton) customView.findViewById(R.id.view_social_buttons_reddit_button);

    //final String referrerParam  = "?ref=android_" + ((referrerContextSuffix!=null) ? referrerContextSuffix.trim() : "");

    githubButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            UIUtils.openURL(v.getContext(), Constants.GITHUB_PAGE);
        }
    });
    /*
            twitterButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        UIUtils.openURL(v.getContext(), Constants.SOCIAL_URL_TWITTER_PAGE + referrerParam);
    }
            });
            
            redditButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        UIUtils.openURL(v.getContext(), Constants.SOCIAL_URL_REDDIT_PAGE + referrerParam);
    }
            });
            
    */
    if (showInstallationCompleteSection) {
        LinearLayout installationCompleteLayout = (LinearLayout) customView
                .findViewById(R.id.view_social_buttons_installation_complete_layout);
        installationCompleteLayout.setVisibility(View.VISIBLE);
        ImageButton dismissCheckButton = (ImageButton) customView
                .findViewById(R.id.view_social_buttons_dismiss_check);
        dismissCheckButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                socialLinksDialog.dismiss();
            }
        });
    }

    socialLinksDialog.show();
}