Search in sources :

Example 51 with Builder

use of android.support.v7.app.AlertDialog.Builder in project MultiPhotoPicker by wangeason.

the class PhotoPickerActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    showCamera = getIntent().getBooleanExtra(EXTRA_SHOW_CAMERA, true);
    boolean showGif = getIntent().getBooleanExtra(EXTRA_SHOW_GIF, false);
    multiChoose = getIntent().getBooleanExtra(EXTRA_MULTI_CHOOSE, false);
    setShowGif(showGif);
    setContentView(R.layout.activity_photo_picker);
    captureManager = new ImageCaptureManager(getActivity());
    Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar);
    mToolbar.setTitle(R.string.images);
    setSupportActionBar(mToolbar);
    ActionBar actionBar = getSupportActionBar();
    assert actionBar != null;
    actionBar.setDisplayHomeAsUpEnabled(true);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        actionBar.setElevation(25);
    }
    maxCount = getIntent().getIntExtra(EXTRA_MAX_COUNT, DEFAULT_MAX_COUNT);
    minCount = getIntent().getIntExtra(EXTRA_MIN_COUNT, DEFAULT_MIN_COUNT);
    btnDoneItem = (Button) findViewById(R.id.done);
    btnDoneItem.setText(getString(R.string.done_with_count, 0, maxCount));
    btnDoneItem.setEnabled(false);
    btnDoneItem.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            ArrayList<String> selectedPhotos = pickerFragment.getPhotoGridAdapter().getSelectedPhotoPaths();
            if (selectedPhotos.size() >= minCount) {
                intent.putStringArrayListExtra(KEY_SELECTED_PHOTOS, selectedPhotos);
                setResult(RESULT_OK, intent);
                finish();
            } else {
                AlertDialog.Builder builder = new AlertDialog.Builder(PhotoPickerActivity.this);
                builder.setTitle(R.string.choose_more).setCancelable(true).setMessage(getString(R.string.min_count_tips, minCount)).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                }).create().show();
            }
        }
    });
    final Button btSwitchDirectory = (Button) findViewById(R.id.button);
    pickerFragment = (PhotoPickerFragment) getSupportFragmentManager().findFragmentById(R.id.photoPickerFragment);
    final ListPopupWindow listPopupWindow = new ListPopupWindow(getActivity());
    listPopupWindow.setWidth(ListPopupWindow.MATCH_PARENT);
    listPopupWindow.setAnchorView(findViewById(R.id.ll_control));
    listPopupWindow.setAdapter(pickerFragment.getListAdapter());
    listPopupWindow.setModal(true);
    listPopupWindow.setDropDownGravity(Gravity.BOTTOM);
    listPopupWindow.setAnimationStyle(R.style.Animation_AppCompat_DropDownUp);
    listPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            listPopupWindow.dismiss();
            PhotoDirectory directory = pickerFragment.getDirectories().get(position);
            btSwitchDirectory.setText(directory.getName());
            pickerFragment.getPhotoGridAdapter().setCurrentDirectoryIndex(position);
            pickerFragment.getPhotoGridAdapter().notifyDataSetChanged();
        }
    });
    btSwitchDirectory.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (listPopupWindow.isShowing()) {
                listPopupWindow.dismiss();
            } else if (!getActivity().isFinishing()) {
                listPopupWindow.setHeight(Math.round(pickerFragment.getView().getHeight() * 0.8f));
                listPopupWindow.show();
            }
        }
    });
    multiGridAdapter = pickerFragment.getPhotoGridAdapter();
    multiGridAdapter.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(int position, Photo photo, int selectedItemCount, int selectTimes) {
            if (multiChoose) {
                if (photo.getSelectedTimes() > 0) {
                    if (selectedItemCount >= maxCount) {
                        multiGridAdapter.del(photo);
                        multiGridAdapter.notifyItemChanged(position);
                    } else {
                        multiGridAdapter.add(photo);
                        multiGridAdapter.notifyItemChanged(position);
                    }
                } else {
                    if (selectedItemCount >= maxCount) {
                        Toast.makeText(getActivity(), getString(R.string.over_max_count_tips, maxCount), LENGTH_LONG).show();
                    } else {
                        multiGridAdapter.add(photo);
                        multiGridAdapter.notifyItemChanged(position);
                    }
                }
            } else {
                if (maxCount <= 1) {
                    if (photo.getSelectedTimes() > 0) {
                        multiGridAdapter.del(0);
                        multiGridAdapter.notifyItemChanged(position);
                    } else {
                        multiGridAdapter.clearSelection();
                        multiGridAdapter.add(photo);
                        multiGridAdapter.notifyDataSetChanged();
                    }
                } else {
                    if (photo.getSelectedTimes() > 0) {
                        multiGridAdapter.del(photo);
                        multiGridAdapter.notifyItemChanged(position);
                    } else {
                        if (selectedItemCount >= maxCount) {
                            Toast.makeText(getActivity(), getString(R.string.over_max_count_tips, maxCount), LENGTH_LONG).show();
                        } else {
                            multiGridAdapter.add(photo);
                            multiGridAdapter.notifyItemChanged(position);
                        }
                    }
                }
            }
            selectedPhotoAdapter.notifyDataSetChanged();
            refreshDoneBtn();
        }
    });
    selectedPhotoAdapter = new PhotoSelectedAdapter(getActivity(), multiGridAdapter.getSelectedPhotos());
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.selected_photos);
    LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setAdapter(selectedPhotoAdapter);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    selectedPhotoAdapter.setOnSelectedItemClickListener(new OnSelectedItemClickListener() {

        @Override
        public void onClick(View v, int position) {
            if (selectedPagerFragment != null && selectedPagerFragment.isVisible()) {
                selectedPagerFragment.getViewPager().setCurrentItem(position);
            } else {
                List<String> photos = multiGridAdapter.getSelectedPhotoPaths();
                int[] screenLocation = new int[2];
                v.getLocationOnScreen(screenLocation);
                ImagePagerFragment imagePagerFragment = ImagePagerFragment.newInstance(photos, position, screenLocation, v.getWidth(), v.getHeight());
                addImagePagerFragment(imagePagerFragment, true);
            }
        }
    });
    selectedPhotoAdapter.setOnSelectedItemDelListener(new OnSelectedItemDelListener() {

        @Override
        public void onClick(int position, MultiSelectedPhoto path) {
            multiGridAdapter.getSelectedPhotos().get(position).getPhoto().del();
            multiGridAdapter.getSelectedPhotos().remove(position);
            multiGridAdapter.notifyDataSetChanged();
            selectedPhotoAdapter.notifyDataSetChanged();
            refreshDoneBtn();
        }
    });
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) ImagePagerFragment(io.github.wangeason.multiphotopicker.fragment.ImagePagerFragment) Photo(io.github.wangeason.multiphotopicker.entity.Photo) MultiSelectedPhoto(io.github.wangeason.multiphotopicker.entity.MultiSelectedPhoto) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) ListPopupWindow(android.support.v7.widget.ListPopupWindow) Button(android.widget.Button) PhotoSelectedAdapter(io.github.wangeason.multiphotopicker.adapter.PhotoSelectedAdapter) OnSelectedItemClickListener(io.github.wangeason.multiphotopicker.event.OnSelectedItemClickListener) ArrayList(java.util.ArrayList) List(java.util.List) ImageCaptureManager(io.github.wangeason.multiphotopicker.utils.ImageCaptureManager) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar) PhotoDirectory(io.github.wangeason.multiphotopicker.entity.PhotoDirectory) OnItemClickListener(io.github.wangeason.multiphotopicker.event.OnItemClickListener) Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView) OnSelectedItemDelListener(io.github.wangeason.multiphotopicker.event.OnSelectedItemDelListener) MultiSelectedPhoto(io.github.wangeason.multiphotopicker.entity.MultiSelectedPhoto) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView)

Example 52 with Builder

use of android.support.v7.app.AlertDialog.Builder in project wire-android by wireapp.

the class PickUserFragment method onContactListContactClicked.

@Override
public void onContactListContactClicked(final ContactDetails contactDetails) {
    getStoreFactory().getNetworkStore().doIfHasInternetOrNotifyUser(new DefaultNetworkAction() {

        @Override
        public void execute(NetworkMode networkMode) {
            final int contactMethodsCount = contactDetails.getContactMethods().size();
            final ContactMethod[] contactMethods = contactDetails.getContactMethods().toArray(new ContactMethod[contactMethodsCount]);
            if (contactMethodsCount == 1 && contactMethods[0].getKind() == ContactMethod.Kind.SMS) {
                // Launch SMS app directly if contact only has phone numner
                final String number = contactMethods[0].getStringRepresentation();
                sendSMSInvite(number);
                ((BaseScalaActivity) getActivity()).injectJava(GlobalTrackingController.class).tagEvent(new OpenedGenericInviteMenuEvent(OpenedGenericInviteMenuEvent.EventContext.ADDRESSBOOK));
                return;
            }
            final CharSequence[] itemNames = new CharSequence[contactMethodsCount];
            for (int i = 0; i < contactMethodsCount; i++) {
                ContactMethod contactMethod = contactMethods[i];
                itemNames[i] = contactMethod.getStringRepresentation();
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setTitle(getResources().getString(R.string.people_picker__contact_list__invite_dialog__title)).setPositiveButton(getResources().getText(R.string.confirmation_menu__confirm_done), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    ListView lv = dialog.getListView();
                    int selected = lv.getCheckedItemPosition();
                    ContactMethod selectedContactMethod = null;
                    if (selected >= 0) {
                        selectedContactMethod = contactMethods[selected];
                    }
                    if (selectedContactMethod == null) {
                        return;
                    }
                    if (selectedContactMethod.getKind() == ContactMethod.Kind.SMS) {
                        final String number = String.valueOf(itemNames[selected]);
                        sendSMSInvite(number);
                        ((BaseScalaActivity) getActivity()).injectJava(GlobalTrackingController.class).tagEvent(new OpenedGenericInviteMenuEvent(OpenedGenericInviteMenuEvent.EventContext.ADDRESSBOOK));
                    } else {
                        selectedContactMethod.invite(" ", null);
                        Toast.makeText(getActivity(), getResources().getString(R.string.people_picker__invite__sent_feedback), Toast.LENGTH_LONG).show();
                        boolean fromSearch = TextUtils.isEmpty(getControllerFactory().getPickUserController().getSearchFilter());
                        TrackingUtils.tagSentInviteToContactEvent(((BaseScalaActivity) getActivity()).injectJava(GlobalTrackingController.class), selectedContactMethod.getKind(), contactDetails.hasBeenInvited(), fromSearch);
                    }
                }
            }).setNegativeButton(getResources().getText(R.string.confirmation_menu__cancel), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    dialogInterface.cancel();
                }
            }).setSingleChoiceItems(itemNames, DEFAULT_SELECTED_INVITE_METHOD, null);
            dialog = builder.create();
            dialog.show();
            ((BaseScalaActivity) getActivity()).injectJava(GlobalTrackingController.class).onApplicationScreen(ApplicationScreen.SEND_PERSONAL_INVITE_MENU);
        }
    });
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) BaseScalaActivity(com.waz.zclient.BaseScalaActivity) GlobalTrackingController(com.waz.zclient.tracking.GlobalTrackingController) DialogInterface(android.content.DialogInterface) NetworkMode(com.waz.api.NetworkMode) ListView(android.widget.ListView) OpenedGenericInviteMenuEvent(com.waz.zclient.controllers.tracking.events.connect.OpenedGenericInviteMenuEvent) DefaultNetworkAction(com.waz.zclient.core.stores.network.DefaultNetworkAction) ContactMethod(com.waz.api.ContactMethod)

Example 53 with Builder

use of android.support.v7.app.AlertDialog.Builder in project WordPress-Android by wordpress-mobile.

the class EditPostActivity method publishPost.

private boolean publishPost() {
    if (!NetworkUtils.isNetworkAvailable(this)) {
        ToastUtils.showToast(this, R.string.error_publish_no_network, Duration.SHORT);
        return false;
    }
    // Show an Alert Dialog asking the user if he wants to remove all failed media before upload
    if (mEditorFragment.hasFailedMediaUploads()) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(R.string.editor_toast_failed_uploads).setPositiveButton(R.string.editor_remove_failed_uploads, new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int id) {
                // Clear failed uploads
                mEditorFragment.removeAllFailedMediaUploads();
            }
        }).setNegativeButton(android.R.string.cancel, null);
        builder.create().show();
        return true;
    }
    // Update post, save to db and publish in its own Thread, because 1. update can be pretty slow with a lot of
    // text 2. better not to call `updatePostObject()` from the UI thread due to weird thread blocking behavior
    // on API 16 with the visual editor.
    new Thread(new Runnable() {

        @Override
        public void run() {
            boolean isFirstTimePublish = false;
            if (PostStatus.fromPost(mPost) == PostStatus.PUBLISHED && (mPost.isLocalDraft() || PostStatus.fromPost(mOriginalPost) == PostStatus.DRAFT)) {
                isFirstTimePublish = true;
            }
            try {
                updatePostObject(false);
            } catch (IllegalEditorStateException e) {
                AppLog.e(T.EDITOR, "Impossible to save and publish the post, we weren't able to update it.");
                return;
            }
            savePostToDb();
            // If the post is empty, don't publish
            if (!PostUtils.isPublishable(mPost)) {
                mHandler.post(new Runnable() {

                    @Override
                    public void run() {
                        ToastUtils.showToast(EditPostActivity.this, R.string.error_publish_empty_post, Duration.SHORT);
                    }
                });
                return;
            }
            PostUtils.trackSavePostAnalytics(mPost, mSiteStore.getSiteByLocalId(mPost.getLocalSiteId()));
            if (isFirstTimePublish) {
                PostUploadService.addPostToUploadAndTrackAnalytics(mPost);
            } else {
                PostUploadService.addPostToUpload(mPost);
            }
            PostUploadService.setLegacyMode(!mShowNewEditor && !mShowAztecEditor);
            startService(new Intent(EditPostActivity.this, PostUploadService.class));
            PendingDraftsNotificationsUtils.cancelPendingDraftAlarms(EditPostActivity.this, mPost.getId());
            setResult(RESULT_OK);
            finish();
        }
    }).start();
    return true;
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) PostUploadService(org.wordpress.android.ui.posts.services.PostUploadService) PostActionBuilder(org.wordpress.android.fluxc.generated.PostActionBuilder) MediaActionBuilder(org.wordpress.android.fluxc.generated.MediaActionBuilder) SpannableStringBuilder(android.text.SpannableStringBuilder) IllegalEditorStateException(org.wordpress.android.editor.EditorFragment.IllegalEditorStateException) Intent(android.content.Intent)

Example 54 with Builder

use of android.support.v7.app.AlertDialog.Builder in project WordPress-Android by wordpress-mobile.

the class DetailListPreference method showDialog.

@Override
protected void showDialog(Bundle state) {
    Context context = getContext();
    Resources res = context.getResources();
    AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.Calypso_AlertDialog);
    mWhichButtonClicked = DialogInterface.BUTTON_NEGATIVE;
    builder.setPositiveButton(R.string.ok, this);
    builder.setNegativeButton(res.getString(R.string.cancel).toUpperCase(), this);
    if (mDetails == null) {
        mDetails = new String[getEntries() == null ? 1 : getEntries().length];
    }
    mListAdapter = new DetailListAdapter(getContext(), R.layout.detail_list_preference, mDetails);
    mStartingValue = getValue();
    mSelectedIndex = findIndexOfValue(mStartingValue);
    builder.setSingleChoiceItems(mListAdapter, mSelectedIndex, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            mSelectedIndex = which;
        }
    });
    View titleView = View.inflate(getContext(), R.layout.detail_list_preference_title, null);
    if (titleView != null) {
        TextView titleText = (TextView) titleView.findViewById(R.id.title);
        if (titleText != null) {
            titleText.setText(getTitle());
        }
        builder.setCustomTitle(titleView);
    } else {
        builder.setTitle(getTitle());
    }
    if ((mDialog = builder.create()) == null)
        return;
    if (state != null) {
        mDialog.onRestoreInstanceState(state);
    }
    mDialog.setOnDismissListener(this);
    mDialog.show();
    ListView listView = mDialog.getListView();
    Button positive = mDialog.getButton(DialogInterface.BUTTON_POSITIVE);
    Button negative = mDialog.getButton(DialogInterface.BUTTON_NEGATIVE);
    if (listView != null) {
        listView.setDividerHeight(0);
        listView.setClipToPadding(true);
        listView.setPadding(0, 0, 0, res.getDimensionPixelSize(R.dimen.site_settings_divider_height));
    }
    if (positive != null) {
        //noinspection deprecation
        positive.setTextColor(res.getColor(R.color.blue_medium));
    }
    if (negative != null) {
        //noinspection deprecation
        negative.setTextColor(res.getColor(R.color.blue_medium));
    }
}
Also used : Context(android.content.Context) AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) TextView(android.widget.TextView) View(android.view.View) ListView(android.widget.ListView) ListView(android.widget.ListView) RadioButton(android.widget.RadioButton) Button(android.widget.Button) TextView(android.widget.TextView) Resources(android.content.res.Resources)

Example 55 with Builder

use of android.support.v7.app.AlertDialog.Builder in project HumaneApp by Ganesh1010.

the class DonationConfirmationActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_donation_confirmation);
    mainItemList = (LinearLayout) findViewById(R.id.mainItemNeedList);
    for (int i = 0; i < 2; i++) {
        ImageView mainItem = new ImageView(getApplicationContext());
        mainItem.setBackgroundResource(R.drawable.ic_cloth_black);
        mainItemList.addView(mainItem);
        LinearLayout.LayoutParams margins = new LinearLayout.LayoutParams(mainItem.getLayoutParams());
        margins.rightMargin = 20;
        margins.leftMargin = 20;
        mainItem.setLayoutParams(margins);
        mainItem.setMinimumHeight(100);
        mainItem.setMaxHeight(200);
        mainItem.setMinimumWidth(100);
        mainItem.setMaxWidth(200);
        mainItem.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                AlertDialog.Builder builder = new AlertDialog.Builder(DonationConfirmationActivity.this);
                builder.setTitle("Item Details");
                LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                View dialogView = inflater.inflate(R.layout.donation_confirmation_item_display, null);
                RecyclerView itemToDisplay = (RecyclerView) dialogView.findViewById(R.id.itemToDisplay);
                itemToDisplay.setAdapter(new DonationConfirmationItemDisplayAdapter());
                builder.setView(dialogView);
                itemToDisplay.setAdapter(new DonationConfirmationItemDisplayAdapter());
                builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int id) {
                        dialog.dismiss();
                    }
                });
                AlertDialog dialog = builder.create();
                dialog.show();
            }
        });
    }
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) RecyclerView(android.support.v7.widget.RecyclerView) ImageView(android.widget.ImageView) View(android.view.View) LayoutInflater(android.view.LayoutInflater) RecyclerView(android.support.v7.widget.RecyclerView) ImageView(android.widget.ImageView) LinearLayout(android.widget.LinearLayout)

Aggregations

AlertDialog (android.support.v7.app.AlertDialog)114 DialogInterface (android.content.DialogInterface)76 View (android.view.View)67 TextView (android.widget.TextView)48 Intent (android.content.Intent)36 RecyclerView (android.support.v7.widget.RecyclerView)27 ListView (android.widget.ListView)23 Dialog (android.app.Dialog)22 LayoutInflater (android.view.LayoutInflater)20 ImageView (android.widget.ImageView)20 EditText (android.widget.EditText)18 SuppressLint (android.annotation.SuppressLint)17 Context (android.content.Context)17 Bundle (android.os.Bundle)15 NonNull (android.support.annotation.NonNull)14 Button (android.widget.Button)13 ArrayList (java.util.ArrayList)12 BrowserDialog (acr.browser.lightning.dialog.BrowserDialog)10 OnClickListener (android.content.DialogInterface.OnClickListener)10 ScrollView (android.widget.ScrollView)10