Search in sources :

Example 11 with MaterialButton

use of com.google.android.material.button.MaterialButton in project android by nextcloud.

the class NotificationListAdapter method setButtons.

public void setButtons(NotificationViewHolder holder, Notification notification) {
    // add action buttons
    holder.binding.buttons.removeAllViews();
    MaterialButton button;
    Resources resources = notificationsActivity.getResources();
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    params.setMargins(resources.getDimensionPixelOffset(R.dimen.standard_half_margin), 0, resources.getDimensionPixelOffset(R.dimen.standard_half_margin), 0);
    int primaryColor = ThemeColorUtils.primaryColor(notificationsActivity);
    List<Action> overflowActions = new ArrayList<>();
    if (notification.getActions().size() > 2) {
        for (Action action : notification.getActions()) {
            if (action.primary) {
                button = new MaterialButton(notificationsActivity);
                button.setAllCaps(false);
                button.setText(action.label);
                button.setCornerRadiusResource(R.dimen.button_corner_radius);
                button.setLayoutParams(params);
                button.setGravity(Gravity.CENTER);
                button.setOnClickListener(v -> {
                    setButtonEnabled(holder, false);
                    if (ACTION_TYPE_WEB.equals(action.type)) {
                        Intent intent = new Intent(Intent.ACTION_VIEW);
                        intent.setData(Uri.parse(action.link));
                        notificationsActivity.startActivity(intent);
                    } else {
                        new NotificationExecuteActionTask(client, holder, notification, notificationsActivity).execute(action);
                    }
                });
                ThemeButtonUtils.colorPrimaryButton(button, notificationsActivity);
                holder.binding.buttons.addView(button);
            } else {
                overflowActions.add(action);
            }
        }
        // further actions
        button = new MaterialButton(notificationsActivity);
        button.setBackgroundColor(resources.getColor(R.color.grey_200));
        button.setTextColor(primaryColor);
        button.setAllCaps(false);
        button.setText(R.string.more);
        button.setCornerRadiusResource(R.dimen.button_corner_radius);
        button.setLayoutParams(params);
        button.setGravity(Gravity.CENTER);
        MaterialButton finalButton = button;
        button.setOnClickListener(v -> {
            PopupMenu popup = new PopupMenu(notificationsActivity, finalButton);
            for (Action action : overflowActions) {
                popup.getMenu().add(action.label).setOnMenuItemClickListener(item -> {
                    setButtonEnabled(holder, false);
                    if (ACTION_TYPE_WEB.equals(action.type)) {
                        Intent intent = new Intent(Intent.ACTION_VIEW);
                        intent.setData(Uri.parse(action.link));
                        notificationsActivity.startActivity(intent);
                    } else {
                        new NotificationExecuteActionTask(client, holder, notification, notificationsActivity).execute(action);
                    }
                    return true;
                });
            }
            popup.show();
        });
        holder.binding.buttons.addView(button);
    } else {
        for (Action action : notification.getActions()) {
            button = new MaterialButton(notificationsActivity);
            if (action.primary) {
                ThemeButtonUtils.colorPrimaryButton(button, notificationsActivity);
            } else {
                button.setBackgroundColor(resources.getColor(R.color.grey_200));
                button.setTextColor(primaryColor);
            }
            button.setAllCaps(false);
            button.setText(action.label);
            button.setCornerRadiusResource(R.dimen.button_corner_radius);
            button.setLayoutParams(params);
            button.setGravity(Gravity.CENTER);
            button.setOnClickListener(v -> {
                setButtonEnabled(holder, false);
                if (ACTION_TYPE_WEB.equals(action.type)) {
                    Intent intent = new Intent(Intent.ACTION_VIEW);
                    intent.setData(Uri.parse(action.link));
                    notificationsActivity.startActivity(intent);
                } else {
                    new NotificationExecuteActionTask(client, holder, notification, notificationsActivity).execute(action);
                }
            });
            holder.binding.buttons.addView(button);
        }
    }
}
Also used : Action(com.owncloud.android.lib.resources.notifications.models.Action) NotificationExecuteActionTask(com.owncloud.android.ui.asynctasks.NotificationExecuteActionTask) ArrayList(java.util.ArrayList) Intent(android.content.Intent) Resources(android.content.res.Resources) MaterialButton(com.google.android.material.button.MaterialButton) LinearLayout(android.widget.LinearLayout) PopupMenu(androidx.appcompat.widget.PopupMenu)

Example 12 with MaterialButton

use of com.google.android.material.button.MaterialButton in project fdroidclient by f-droid.

the class SwapWorkflowActivity method setUpStartVisibility.

private void setUpStartVisibility() {
    bluetoothStatusReceiver.onReceive(this, new Intent(BluetoothManager.ACTION_STATUS));
    bonjourStatusReceiver.onReceive(this, new Intent(BonjourManager.ACTION_STATUS));
    TextView viewWifiNetwork = findViewById(R.id.wifi_network);
    SwitchMaterial wifiSwitch = findViewById(R.id.switch_wifi);
    MaterialButton scanQrButton = findViewById(R.id.btn_scan_qr);
    MaterialButton appsButton = findViewById(R.id.btn_apps);
    if (viewWifiNetwork == null || wifiSwitch == null || scanQrButton == null || appsButton == null) {
        return;
    }
    viewWifiNetwork.setOnClickListener(v -> promptToSelectWifiNetwork());
    wifiSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            Context context = getApplicationContext();
            if (isChecked) {
                if (wifiApControl != null && wifiApControl.isEnabled()) {
                    setupWifiAP();
                } else {
                    wifiManager.setWifiEnabled(true);
                }
                BonjourManager.start(context);
            }
            BonjourManager.setVisible(context, isChecked);
            SwapService.putWifiVisibleUserPreference(isChecked);
        }
    });
    scanQrButton.setOnClickListener(v -> inflateSwapView(R.layout.swap_wifi_qr));
    appsButton.setOnClickListener(v -> inflateSwapView(R.layout.swap_select_apps));
    appsButton.setEllipsize(TextUtils.TruncateAt.END);
    if (SwapService.getWifiVisibleUserPreference()) {
        wifiSwitch.setChecked(true);
    } else {
        wifiSwitch.setChecked(false);
    }
}
Also used : Context(android.content.Context) SwitchMaterial(com.google.android.material.switchmaterial.SwitchMaterial) Intent(android.content.Intent) TextView(android.widget.TextView) MaterialButton(com.google.android.material.button.MaterialButton) CompoundButton(android.widget.CompoundButton)

Aggregations

MaterialButton (com.google.android.material.button.MaterialButton)12 TextView (android.widget.TextView)7 Intent (android.content.Intent)5 View (android.view.View)5 ActivityNotFoundException (android.content.ActivityNotFoundException)3 Bundle (android.os.Bundle)3 Manifest (android.Manifest)2 LocationManager (android.location.LocationManager)2 WifiManager (android.net.wifi.WifiManager)2 Settings (android.provider.Settings)2 LinkMovementMethod (android.text.method.LinkMovementMethod)2 Button (android.widget.Button)2 ListView (android.widget.ListView)2 Toast (android.widget.Toast)2 OnBackPressedCallback (androidx.activity.OnBackPressedCallback)2 NonNull (androidx.annotation.NonNull)2 Nullable (androidx.annotation.Nullable)2 StringRes (androidx.annotation.StringRes)2 AlertDialog (androidx.appcompat.app.AlertDialog)2 Group (androidx.constraintlayout.widget.Group)2