Search in sources :

Example 96 with PopupMenu

use of android.widget.PopupMenu in project bitcoin-wallet by bitcoin-wallet.

the class WalletTransactionsFragment method onTransactionMenuClick.

@Override
public void onTransactionMenuClick(final View view, final Transaction tx) {
    final boolean txSent = tx.getValue(wallet).signum() < 0;
    final Address txAddress = txSent ? WalletUtils.getToAddressOfSent(tx, wallet) : WalletUtils.getWalletAddressOfReceived(tx, wallet);
    final byte[] txSerialized = tx.unsafeBitcoinSerialize();
    final boolean txRotation = tx.getPurpose() == Purpose.KEY_ROTATION;
    final PopupMenu popupMenu = new PopupMenu(activity, view);
    popupMenu.inflate(R.menu.wallet_transactions_context);
    final MenuItem editAddressMenuItem = popupMenu.getMenu().findItem(R.id.wallet_transactions_context_edit_address);
    if (!txRotation && txAddress != null) {
        editAddressMenuItem.setVisible(true);
        final boolean isAdd = AddressBookProvider.resolveLabel(activity, txAddress.toBase58()) == null;
        final boolean isOwn = wallet.isPubKeyHashMine(txAddress.getHash160());
        if (isOwn)
            editAddressMenuItem.setTitle(isAdd ? R.string.edit_address_book_entry_dialog_title_add_receive : R.string.edit_address_book_entry_dialog_title_edit_receive);
        else
            editAddressMenuItem.setTitle(isAdd ? R.string.edit_address_book_entry_dialog_title_add : R.string.edit_address_book_entry_dialog_title_edit);
    } else {
        editAddressMenuItem.setVisible(false);
    }
    popupMenu.getMenu().findItem(R.id.wallet_transactions_context_show_qr).setVisible(!txRotation && txSerialized.length < SHOW_QR_THRESHOLD_BYTES);
    popupMenu.getMenu().findItem(R.id.wallet_transactions_context_raise_fee).setVisible(RaiseFeeDialogFragment.feeCanLikelyBeRaised(wallet, tx));
    popupMenu.getMenu().findItem(R.id.wallet_transactions_context_browse).setVisible(Constants.ENABLE_BROWSE);
    popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(final MenuItem item) {
            switch(item.getItemId()) {
                case R.id.wallet_transactions_context_edit_address:
                    handleEditAddress(tx);
                    return true;
                case R.id.wallet_transactions_context_show_qr:
                    handleShowQr();
                    return true;
                case R.id.wallet_transactions_context_raise_fee:
                    RaiseFeeDialogFragment.show(getFragmentManager(), tx);
                    return true;
                case R.id.wallet_transactions_context_report_issue:
                    handleReportIssue(tx);
                    return true;
                case R.id.wallet_transactions_context_browse:
                    if (!txRotation) {
                        final String txHash = tx.getHashAsString();
                        final Uri blockExplorerUri = config.getBlockExplorer();
                        log.info("Viewing transaction {} on {}", txHash, blockExplorerUri);
                        startActivity(new Intent(Intent.ACTION_VIEW, Uri.withAppendedPath(blockExplorerUri, "tx/" + txHash)));
                    } else {
                        startActivity(new Intent(Intent.ACTION_VIEW, KEY_ROTATION_URI));
                    }
                    return true;
            }
            return false;
        }

        private void handleEditAddress(final Transaction tx) {
            EditAddressBookEntryFragment.edit(getFragmentManager(), txAddress);
        }

        private void handleShowQr() {
            final Bitmap qrCodeBitmap = Qr.bitmap(Qr.encodeCompressBinary(txSerialized));
            BitmapFragment.show(getFragmentManager(), qrCodeBitmap);
        }

        private void handleReportIssue(final Transaction tx) {
            final StringBuilder contextualData = new StringBuilder();
            try {
                contextualData.append(tx.getValue(wallet).toFriendlyString()).append(" total value");
            } catch (final ScriptException x) {
                contextualData.append(x.getMessage());
            }
            contextualData.append('\n');
            if (tx.hasConfidence())
                contextualData.append("  confidence: ").append(tx.getConfidence()).append('\n');
            contextualData.append(tx.toString());
            ReportIssueDialogFragment.show(getFragmentManager(), R.string.report_issue_dialog_title_transaction, R.string.report_issue_dialog_message_issue, Constants.REPORT_SUBJECT_ISSUE, contextualData.toString());
        }
    });
    popupMenu.show();
}
Also used : Address(org.bitcoinj.core.Address) SpannableStringBuilder(android.text.SpannableStringBuilder) OnMenuItemClickListener(android.widget.PopupMenu.OnMenuItemClickListener) MenuItem(android.view.MenuItem) Intent(android.content.Intent) Uri(android.net.Uri) ScriptException(org.bitcoinj.core.ScriptException) Bitmap(android.graphics.Bitmap) Transaction(org.bitcoinj.core.Transaction) PopupMenu(android.widget.PopupMenu)

Example 97 with PopupMenu

use of android.widget.PopupMenu in project cloudrail-si-android-sdk by CloudRail.

the class FileViewer method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_file_viewer, container, false);
    this.listView = (ListView) v.findViewById(R.id.fileListView);
    this.spinner = (ProgressBar) v.findViewById(R.id.spinner);
    switch(mServiceString) {
        case "amazon":
            {
                // service = new AmazonS3(context, "[Your S3 Access Key ID]", "[Your S3 Secret Access Key]", "[Your AWS region]");
                service = new AmazonS3(context, MainActivity.AMAZON_ACCESS_KEY, MainActivity.AMAZON_SECRET_ACCESS_KEY, MainActivity.AMAZON_REGION);
                break;
            }
        case "backblaze":
            {
                service = new Backblaze(context, MainActivity.BACKBLAZE_ACCOUNT_ID, MainActivity.BACKBLACE_APP_KEY);
                break;
            }
        case "google":
            {
                service = new GoogleCloudPlatform(context, MainActivity.GOOGLE_CLIENT_EMAIL, MainActivity.GOOGLE_PRIVATE_KEY, MainActivity.GOOGLE_PROJECT_ID);
                break;
            }
        case "microsoft":
            {
                service = new MicrosoftAzure(context, MainActivity.AZURE_ACCOUNT_NAME, MainActivity.AZURE_ACCESS_KEY);
                break;
            }
        case "rackspace":
            {
                service = new Rackspace(context, MainActivity.RACKSPACE_USER_NAME, MainActivity.RACKSPACE_API_KEY, MainActivity.RACKSPACE_REGION);
                break;
            }
    }
    refreshList();
    this.listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            selectedItem = view;
            selectedItemPosition = position;
            PopupMenu popupMenu = new PopupMenu(context, view);
            MenuInflater menuInflater = ((Activity) context).getMenuInflater();
            menuInflater.inflate(R.menu.selected_file_bar, popupMenu.getMenu());
            popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    switch(item.getItemId()) {
                        case R.id.action_delete_file:
                            {
                                removeItem();
                                return true;
                            }
                        case R.id.action_download_file:
                            {
                                downloadItem();
                                return true;
                            }
                        default:
                            return false;
                    }
                }
            });
            popupMenu.show();
            return true;
        }
    });
    ((TextView) v.findViewById(R.id.text2)).setText("Bucket \"" + mBucketName + "\"");
    return v;
}
Also used : AmazonS3(com.cloudrail.si.services.AmazonS3) MenuInflater(android.view.MenuInflater) Rackspace(com.cloudrail.si.services.Rackspace) MenuItem(android.view.MenuItem) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) MicrosoftAzure(com.cloudrail.si.services.MicrosoftAzure) Backblaze(com.cloudrail.si.services.Backblaze) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) GoogleCloudPlatform(com.cloudrail.si.services.GoogleCloudPlatform) PopupMenu(android.widget.PopupMenu)

Example 98 with PopupMenu

use of android.widget.PopupMenu in project cloudrail-si-android-sdk by CloudRail.

the class ChargeViewer method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_charge_viewer, container, false);
    this.listView = (ListView) v.findViewById(R.id.chargeListView);
    this.spinner = (ProgressBar) v.findViewById(R.id.spinner);
    switch(mServiceString) {
        case "paypal":
            {
                service = new PayPal(context, true, MainActivity.PAYPAL_CLIENT_IDENTIFIER, MainActivity.PAYPAL_CLIENT_SECRET);
                break;
            }
        case "stripe":
            {
                service = new Stripe(context, MainActivity.STRIPE_SECRET_KEY);
                break;
            }
    }
    refreshList();
    this.listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, final View view, final int position, long id) {
            selectedItem = view;
            final PopupMenu popupMenu = new PopupMenu(context, view);
            MenuInflater menuInflater = ((Activity) context).getMenuInflater();
            menuInflater.inflate(R.menu.selected_item_bar, popupMenu.getMenu());
            popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    switch(item.getItemId()) {
                        case R.id.action_refund_fully:
                            {
                                refundCharge(listAdapter.getItem(position));
                                refreshList();
                                return true;
                            }
                        case R.id.action_refund_partially:
                            {
                                refundPartially(listAdapter.getItem(position));
                                refreshList();
                                return true;
                            }
                        default:
                            return false;
                    }
                }
            });
            popupMenu.show();
            return true;
        }
    });
    this.listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, final View v, int position, long id) {
            final Charge charge = listAdapter.getItem(position);
            new Thread(new Runnable() {

                @Override
                public void run() {
                    final List<Refund> refunds = service.getRefundsForCharge(charge.getId());
                    ((Activity) context).runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            String[] refundStrings = new String[refunds.size()];
                            int i = 0;
                            for (Refund r : refunds) {
                                refundStrings[i] = formatAmount(r.getAmount()) + r.getCurrency() + "   (" + formatTime(r.getCreated()) + ")";
                                i++;
                            }
                            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                            View layout = inflater.inflate(R.layout.display_charge, (ViewGroup) ((Activity) context).findViewById(R.id.display_charge_root));
                            enterContents(layout, charge, refunds);
                            PopupWindow pw = new PopupWindow(layout, 900, 1000, true);
                            pw.showAtLocation(v, Gravity.CENTER, 0, 0);
                            ListView lv = layout.findViewById(R.id.refunds_list_view);
                            lv.setAdapter(new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1, refundStrings));
                        }
                    });
                }
            }).start();
        }
    });
    ((TextView) v.findViewById(R.id.text2)).setText(mServiceString);
    return v;
}
Also used : PopupWindow(android.widget.PopupWindow) Activity(android.app.Activity) ListView(android.widget.ListView) Stripe(com.cloudrail.si.services.Stripe) List(java.util.List) TextView(android.widget.TextView) PayPal(com.cloudrail.si.services.PayPal) MenuInflater(android.view.MenuInflater) Charge(com.cloudrail.si.types.Charge) MenuItem(android.view.MenuItem) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) Refund(com.cloudrail.si.types.Refund) LayoutInflater(android.view.LayoutInflater) AdapterView(android.widget.AdapterView) PopupMenu(android.widget.PopupMenu)

Example 99 with PopupMenu

use of android.widget.PopupMenu in project bugzy by cpunq.

the class MyCasesFragment method showSortOrderSelectionMenu.

public void showSortOrderSelectionMenu(View v, int replaceWith) {
    PopupMenu popupMenu = new PopupMenu(getActivity(), v);
    popupMenu.setOnMenuItemClickListener(item -> {
        mViewModel.onSortSelected(item.getTitle().toString(), replaceWith);
        return true;
    });
    for (String sortOrder : mViewModel.getAvailableSortOrders()) {
        popupMenu.getMenu().add(sortOrder);
    }
    popupMenu.show();
}
Also used : PopupMenu(android.widget.PopupMenu)

Aggregations

PopupMenu (android.widget.PopupMenu)99 MenuItem (android.view.MenuItem)60 View (android.view.View)44 TextView (android.widget.TextView)41 ImageView (android.widget.ImageView)30 RecyclerView (android.support.v7.widget.RecyclerView)22 TargetApi (android.annotation.TargetApi)20 SlowTest (io.github.hidroh.materialistic.test.suite.SlowTest)19 Test (org.junit.Test)19 ShadowPopupMenu (org.robolectric.shadows.ShadowPopupMenu)19 RoboMenuItem (org.robolectric.fakes.RoboMenuItem)18 Intent (android.content.Intent)14 Context (android.content.Context)12 DialogAction (com.afollestad.materialdialogs.DialogAction)12 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)12 MenuInflater (android.view.MenuInflater)10 AdapterView (android.widget.AdapterView)10 ListView (android.widget.ListView)10 Menu (android.view.Menu)9 NonNull (android.support.annotation.NonNull)8