Search in sources :

Example 6 with ConstraintLayout

use of androidx.constraintlayout.widget.ConstraintLayout in project Signal-Android by WhisperSystems.

the class CreatePaymentFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    Toolbar toolbar = view.findViewById(R.id.create_payment_fragment_toolbar);
    toolbar.setNavigationOnClickListener(this::goBack);
    CreatePaymentFragmentArgs arguments = CreatePaymentFragmentArgs.fromBundle(requireArguments());
    CreatePaymentViewModel.Factory factory = new CreatePaymentViewModel.Factory(arguments.getPayee(), arguments.getNote());
    CreatePaymentViewModel viewModel = new ViewModelProvider(Navigation.findNavController(view).getViewModelStoreOwner(R.id.payments_create), factory).get(CreatePaymentViewModel.class);
    constraintLayout = view.findViewById(R.id.create_payment_fragment_amount_header);
    request = view.findViewById(R.id.create_payment_fragment_request);
    amount = view.findViewById(R.id.create_payment_fragment_amount);
    exchange = view.findViewById(R.id.create_payment_fragment_exchange);
    pay = view.findViewById(R.id.create_payment_fragment_pay);
    balance = view.findViewById(R.id.create_payment_fragment_balance);
    note = view.findViewById(R.id.create_payment_fragment_note);
    addNote = view.findViewById(R.id.create_payment_fragment_add_note);
    toggle = view.findViewById(R.id.create_payment_fragment_toggle);
    TextView decimal = view.findViewById(R.id.create_payment_fragment_keyboard_decimal);
    decimal.setText(String.valueOf(DecimalFormatSymbols.getInstance().getDecimalSeparator()));
    View infoTapTarget = view.findViewById(R.id.create_payment_fragment_info_tap_region);
    // noinspection CodeBlock2Expr
    infoTapTarget.setOnClickListener(v -> {
        new AlertDialog.Builder(requireContext()).setMessage(R.string.CreatePaymentFragment__conversions_are_just_estimates).setPositiveButton(android.R.string.ok, (dialog, which) -> dialog.dismiss()).setNegativeButton(R.string.LearnMoreTextView_learn_more, (dialog, which) -> {
            dialog.dismiss();
            CommunicationActions.openBrowserLink(requireContext(), getString(R.string.CreatePaymentFragment__learn_more__conversions));
        }).show();
    });
    initializeInfoIcon();
    note.setOnClickListener(v -> SafeNavigation.safeNavigate(Navigation.findNavController(v), R.id.action_createPaymentFragment_to_editPaymentNoteFragment));
    addNote.setOnClickListener(v -> SafeNavigation.safeNavigate(Navigation.findNavController(v), R.id.action_createPaymentFragment_to_editPaymentNoteFragment));
    pay.setOnClickListener(v -> {
        NavDirections directions = CreatePaymentFragmentDirections.actionCreatePaymentFragmentToConfirmPaymentFragment(viewModel.getCreatePaymentDetails()).setFinishOnConfirm(arguments.getFinishOnConfirm());
        SafeNavigation.safeNavigate(Navigation.findNavController(v), directions);
    });
    toggle.setOnClickListener(v -> viewModel.toggleMoneyInputTarget());
    initializeConstraintSets();
    initializeKeyboardButtons(view, viewModel);
    viewModel.getInputState().observe(getViewLifecycleOwner(), inputState -> {
        updateAmount(inputState);
        updateExchange(inputState);
        updateMoneyInputTarget(inputState.getInputTarget());
    });
    viewModel.getIsPaymentsSupportedByPayee().observe(getViewLifecycleOwner(), isSupported -> {
        if (!isSupported)
            RecipientHasNotEnabledPaymentsDialog.show(requireContext(), () -> goBack(requireView()));
    });
    viewModel.isValidAmount().observe(getViewLifecycleOwner(), this::updateRequestAmountButtons);
    viewModel.getNote().observe(getViewLifecycleOwner(), this::updateNote);
    viewModel.getSpendableBalance().observe(getViewLifecycleOwner(), this::updateBalance);
    viewModel.getCanSendPayment().observe(getViewLifecycleOwner(), this::updatePayAmountButtons);
}
Also used : Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) AppCompatResources(androidx.appcompat.content.res.AppCompatResources) DecimalFormatSymbols(java.text.DecimalFormatSymbols) EmojiTextView(org.thoughtcrime.securesms.components.emoji.EmojiTextView) TransitionManager(androidx.transition.TransitionManager) ViewUtil(org.thoughtcrime.securesms.util.ViewUtil) HashMap(java.util.HashMap) Currency(java.util.Currency) DrawableCompat(androidx.core.graphics.drawable.DrawableCompat) Drawable(android.graphics.drawable.Drawable) R(org.thoughtcrime.securesms.R) FiatMoneyUtil(org.thoughtcrime.securesms.payments.FiatMoneyUtil) SafeNavigation(org.thoughtcrime.securesms.util.navigation.SafeNavigation) FormatterOptions(org.whispersystems.signalservice.api.payments.FormatterOptions) Map(java.util.Map) View(android.view.View) RecipientHasNotEnabledPaymentsDialog(org.thoughtcrime.securesms.payments.preferences.RecipientHasNotEnabledPaymentsDialog) ContextCompat(androidx.core.content.ContextCompat) ViewModelProvider(androidx.lifecycle.ViewModelProvider) NavDirections(androidx.navigation.NavDirections) MoneyView(org.thoughtcrime.securesms.payments.MoneyView) TextUtils(android.text.TextUtils) SpanUtil(org.thoughtcrime.securesms.util.SpanUtil) CommunicationActions(org.thoughtcrime.securesms.util.CommunicationActions) ConstraintSet(androidx.constraintlayout.widget.ConstraintSet) AlertDialog(android.app.AlertDialog) Objects(java.util.Objects) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) ConstraintLayout(androidx.constraintlayout.widget.ConstraintLayout) Toolbar(androidx.appcompat.widget.Toolbar) Navigation(androidx.navigation.Navigation) LoggingFragment(org.thoughtcrime.securesms.LoggingFragment) Money(org.whispersystems.signalservice.api.payments.Money) EmojiTextView(org.thoughtcrime.securesms.components.emoji.EmojiTextView) TextView(android.widget.TextView) EmojiTextView(org.thoughtcrime.securesms.components.emoji.EmojiTextView) View(android.view.View) MoneyView(org.thoughtcrime.securesms.payments.MoneyView) TextView(android.widget.TextView) Toolbar(androidx.appcompat.widget.Toolbar) ViewModelProvider(androidx.lifecycle.ViewModelProvider) NavDirections(androidx.navigation.NavDirections)

Example 7 with ConstraintLayout

use of androidx.constraintlayout.widget.ConstraintLayout in project Gadgetbridge by Freeyourgadget.

the class SleepChartFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_sleepchart, container, false);
    mActivityChart = rootView.findViewById(R.id.sleepchart);
    mSleepAmountChart = rootView.findViewById(R.id.sleepchart_pie_light_deep);
    mSleepchartInfo = rootView.findViewById(R.id.sleepchart_info);
    heartRateIcon = rootView.findViewById(R.id.heartrate_widget_icon);
    heartRateAverageLabel = rootView.findViewById(R.id.heartrate_widget_label);
    intensityTotalIcon = rootView.findViewById(R.id.intensity_widget_icon);
    intensityTotalLabel = rootView.findViewById(R.id.intensity_widget_label);
    ConstraintLayout intensityTotalWidgetLayout = rootView.findViewById(R.id.intensity_widget_layout);
    ConstraintLayout heartRateWidgetLayout = rootView.findViewById(R.id.heartrate_widget_layout);
    View.OnClickListener listener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            DecimalFormat df = new DecimalFormat("###.#");
            String detailedDuration = String.format(getString(R.string.charts_min_max_heartrate_popup), heartRateMin, heartRateMax, df.format(intensityTotal));
            new ChartsActivity.ShowDurationDialog(detailedDuration, getContext()).show();
        }
    };
    heartRateWidgetLayout.setOnClickListener(listener);
    intensityTotalWidgetLayout.setOnClickListener(listener);
    intensityTotalIcon.setOnClickListener(listener);
    intensityTotalLabel.setOnClickListener(listener);
    setupActivityChart();
    setupSleepAmountChart();
    // refresh immediately instead of use refreshIfVisible(), for perceived performance
    refresh();
    return rootView;
}
Also used : DecimalFormat(java.text.DecimalFormat) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ConstraintLayout(androidx.constraintlayout.widget.ConstraintLayout)

Example 8 with ConstraintLayout

use of androidx.constraintlayout.widget.ConstraintLayout in project FirebaseUI-Android by firebase.

the class AuthMethodPickerActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FlowParameters params = getFlowParams();
    customLayout = params.authMethodPickerLayout;
    mHandler = new ViewModelProvider(this).get(SocialProviderResponseHandler.class);
    mHandler.init(params);
    mProviders = new ArrayList<>();
    if (customLayout != null) {
        setContentView(customLayout.getMainLayout());
        // Setup using custom layout
        populateIdpListCustomLayout(params.providers);
    } else {
        setContentView(R.layout.fui_auth_method_picker_layout);
        // UI only with default layout
        mProgressBar = findViewById(R.id.top_progress_bar);
        mProviderHolder = findViewById(R.id.btn_holder);
        populateIdpList(params.providers);
        int logoId = params.logoId;
        if (logoId == AuthUI.NO_LOGO) {
            findViewById(R.id.logo).setVisibility(View.GONE);
            ConstraintLayout layout = findViewById(R.id.root);
            ConstraintSet constraints = new ConstraintSet();
            constraints.clone(layout);
            constraints.setHorizontalBias(R.id.container, 0.5f);
            constraints.setVerticalBias(R.id.container, 0.5f);
            constraints.applyTo(layout);
        } else {
            ImageView logo = findViewById(R.id.logo);
            logo.setImageResource(logoId);
        }
    }
    boolean tosAndPpConfigured = getFlowParams().isPrivacyPolicyUrlProvided() && getFlowParams().isTermsOfServiceUrlProvided();
    int termsTextId = customLayout == null ? R.id.main_tos_and_pp : customLayout.getTosPpView();
    if (termsTextId >= 0) {
        TextView termsText = findViewById(termsTextId);
        // No ToS or PP provided, so we should hide the view entirely
        if (!tosAndPpConfigured) {
            termsText.setVisibility(View.GONE);
        } else {
            PrivacyDisclosureUtils.setupTermsOfServiceAndPrivacyPolicyText(this, getFlowParams(), termsText);
        }
    }
    // Handler for both
    mHandler.getOperation().observe(this, new ResourceObserver<IdpResponse>(this, R.string.fui_progress_dialog_signing_in) {

        @Override
        protected void onSuccess(@NonNull IdpResponse response) {
            startSaveCredentials(mHandler.getCurrentUser(), response, null);
        }

        @Override
        protected void onFailure(@NonNull Exception e) {
            if (e instanceof UserCancellationException) {
                // User pressed back, there is no error.
                return;
            }
            if (e instanceof FirebaseAuthAnonymousUpgradeException) {
                finish(ErrorCodes.ANONYMOUS_UPGRADE_MERGE_CONFLICT, ((FirebaseAuthAnonymousUpgradeException) e).getResponse().toIntent());
            } else if (e instanceof FirebaseUiException) {
                FirebaseUiException fue = (FirebaseUiException) e;
                finish(RESULT_CANCELED, IdpResponse.from(fue).toIntent());
            } else {
                String text = getString(R.string.fui_error_unknown);
                Toast.makeText(AuthMethodPickerActivity.this, text, Toast.LENGTH_SHORT).show();
            }
        }
    });
}
Also used : ConstraintSet(androidx.constraintlayout.widget.ConstraintSet) FirebaseAuthAnonymousUpgradeException(com.firebase.ui.auth.FirebaseAuthAnonymousUpgradeException) UserCancellationException(com.firebase.ui.auth.data.model.UserCancellationException) FirebaseUiException(com.firebase.ui.auth.FirebaseUiException) FirebaseAuthAnonymousUpgradeException(com.firebase.ui.auth.FirebaseAuthAnonymousUpgradeException) ConstraintLayout(androidx.constraintlayout.widget.ConstraintLayout) FlowParameters(com.firebase.ui.auth.data.model.FlowParameters) SocialProviderResponseHandler(com.firebase.ui.auth.viewmodel.idp.SocialProviderResponseHandler) UserCancellationException(com.firebase.ui.auth.data.model.UserCancellationException) TextView(android.widget.TextView) ImageView(android.widget.ImageView) FirebaseUiException(com.firebase.ui.auth.FirebaseUiException) ViewModelProvider(androidx.lifecycle.ViewModelProvider) IdpResponse(com.firebase.ui.auth.IdpResponse)

Example 9 with ConstraintLayout

use of androidx.constraintlayout.widget.ConstraintLayout in project android by owncloud.

the class ReceiveExternalFilesActivity method initToolbar.

/**
 * This activity is special, so we won't use the ToolbarActivity method to initialize the actionbar.
 */
private void initToolbar(String current_dir) {
    Toolbar toolbar = findViewById(R.id.standard_toolbar);
    ConstraintLayout rootToolbar = findViewById(R.id.root_toolbar);
    toolbar.setVisibility(View.VISIBLE);
    rootToolbar.setVisibility(View.GONE);
    String actionBarTitle;
    if (current_dir.equals("")) {
        actionBarTitle = getString(R.string.uploader_top_message);
    } else {
        actionBarTitle = current_dir;
    }
    toolbar.setTitle(actionBarTitle);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    boolean notRoot = (mParents.size() > 1);
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(notRoot);
        actionBar.setHomeButtonEnabled(notRoot);
    }
}
Also used : ActionBar(androidx.appcompat.app.ActionBar) Toolbar(androidx.appcompat.widget.Toolbar) ConstraintLayout(androidx.constraintlayout.widget.ConstraintLayout)

Example 10 with ConstraintLayout

use of androidx.constraintlayout.widget.ConstraintLayout in project android by owncloud.

the class FileListListAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View view = convertView;
    OCFile file = null;
    LayoutInflater inflator = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    if (mFiles != null && mFiles.size() > position) {
        file = mFiles.get(position);
    }
    // Find out which layout should be displayed
    final ViewType viewType;
    if (parent instanceof GridView) {
        if (file != null && file.isImage()) {
            viewType = ViewType.GRID_IMAGE;
        } else {
            viewType = ViewType.GRID_ITEM;
        }
    } else {
        viewType = ViewType.LIST_ITEM;
    }
    // create view only if differs, otherwise reuse
    if (convertView == null || convertView.getTag() != viewType) {
        switch(viewType) {
            case GRID_IMAGE:
                view = inflator.inflate(R.layout.grid_image, parent, false);
                view.setTag(ViewType.GRID_IMAGE);
                break;
            case GRID_ITEM:
                view = inflator.inflate(R.layout.grid_item, parent, false);
                view.setTag(ViewType.GRID_ITEM);
                break;
            case LIST_ITEM:
                view = inflator.inflate(R.layout.item_file_list, parent, false);
                view.setTag(ViewType.LIST_ITEM);
                // Allow or disallow touches with other visible windows
                view.setFilterTouchesWhenObscured(PreferenceUtils.shouldDisallowTouchesWithOtherVisibleWindows(mContext));
                break;
        }
    }
    if (file != null) {
        final ImageView localStateView = view.findViewById(R.id.localFileIndicator);
        final ImageView fileIcon = view.findViewById(R.id.thumbnail);
        fileIcon.setTag(file.getFileId());
        TextView fileName;
        String name = file.getFileName();
        final LinearLayout linearLayout = view.findViewById(R.id.ListItemLayout);
        if (linearLayout != null) {
            linearLayout.setContentDescription("LinearLayout-" + name);
            // Allow or disallow touches with other visible windows
            linearLayout.setFilterTouchesWhenObscured(PreferenceUtils.shouldDisallowTouchesWithOtherVisibleWindows(mContext));
        }
        switch(viewType) {
            case LIST_ITEM:
                ConstraintLayout constraintLayout = view.findViewById(R.id.file_list_constraint_layout);
                // Allow or disallow touches with other visible windows
                constraintLayout.setFilterTouchesWhenObscured(PreferenceUtils.shouldDisallowTouchesWithOtherVisibleWindows(mContext));
                TextView fileSizeTV = view.findViewById(R.id.file_list_size);
                TextView lastModTV = view.findViewById(R.id.file_list_last_mod);
                fileSizeTV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength(), mContext));
                lastModTV.setText(DisplayUtils.getRelativeTimestamp(mContext, file.getModificationTimestamp()));
                if (mOnlyAvailableOffline || mSharedByLinkFiles) {
                    TextView filePath = view.findViewById(R.id.file_list_path);
                    filePath.setVisibility(View.VISIBLE);
                    filePath.setText(file.getRemotePath());
                }
            case GRID_ITEM:
                // filename
                fileName = view.findViewById(R.id.Filename);
                name = file.getFileName();
                fileName.setText(name);
            case GRID_IMAGE:
                // sharedIcon
                ImageView sharedIconV = view.findViewById(R.id.sharedIcon);
                if (file.isSharedViaLink()) {
                    sharedIconV.setImageResource(R.drawable.ic_shared_by_link);
                    sharedIconV.setVisibility(View.VISIBLE);
                    sharedIconV.bringToFront();
                } else if (file.isSharedWithSharee() || file.isSharedWithMe()) {
                    sharedIconV.setImageResource(R.drawable.shared_via_users);
                    sharedIconV.setVisibility(View.VISIBLE);
                    sharedIconV.bringToFront();
                } else {
                    sharedIconV.setVisibility(View.GONE);
                }
                break;
        }
        // For all Views
        setIconPinAccordingToFilesLocalState(localStateView, file);
        final ImageView checkBoxV = view.findViewById(R.id.custom_checkbox);
        checkBoxV.setVisibility(View.GONE);
        view.setBackgroundColor(Color.WHITE);
        AbsListView parentList = (AbsListView) parent;
        if (parentList.getChoiceMode() != AbsListView.CHOICE_MODE_NONE && parentList.getCheckedItemCount() > 0) {
            if (parentList.isItemChecked(position)) {
                view.setBackgroundColor(mContext.getResources().getColor(R.color.selected_item_background));
                checkBoxV.setImageResource(R.drawable.ic_checkbox_marked);
            } else {
                view.setBackgroundColor(Color.WHITE);
                checkBoxV.setImageResource(R.drawable.ic_checkbox_blank_outline);
            }
            checkBoxV.setVisibility(View.VISIBLE);
        }
        if (file.isFolder()) {
            // Folder
            fileIcon.setImageResource(MimetypeIconUtil.getFolderTypeIconId(file.isSharedWithMe() || file.isSharedWithSharee(), file.isSharedViaLink()));
        } else {
            // Set file icon depending on its mimetype. Ask for thumbnail later.
            fileIcon.setImageResource(MimetypeIconUtil.getFileTypeIconId(file.getMimetype(), file.getFileName()));
            if (file.getRemoteId() != null) {
                // Thumbnail in Cache?
                Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(file.getRemoteId());
                if (thumbnail != null) {
                    fileIcon.setImageBitmap(thumbnail);
                }
                if (file.needsUpdateThumbnail()) {
                    // generate new Thumbnail
                    if (ThumbnailsCacheManager.cancelPotentialThumbnailWork(file, fileIcon)) {
                        final ThumbnailsCacheManager.ThumbnailGenerationTask task = new ThumbnailsCacheManager.ThumbnailGenerationTask(fileIcon, mStorageManager, mAccount);
                        final ThumbnailsCacheManager.AsyncThumbnailDrawable asyncDrawable = new ThumbnailsCacheManager.AsyncThumbnailDrawable(mContext.getResources(), thumbnail, task);
                        // If drawable is not visible, do not update it.
                        if (asyncDrawable.getMinimumHeight() > 0 && asyncDrawable.getMinimumWidth() > 0) {
                            fileIcon.setImageDrawable(asyncDrawable);
                        }
                        task.execute(file);
                    }
                }
                if (file.getMimetype().equalsIgnoreCase("image/png")) {
                    fileIcon.setBackgroundColor(mContext.getResources().getColor(R.color.background_color));
                }
            }
        }
    }
    return view;
}
Also used : AbsListView(android.widget.AbsListView) GridView(android.widget.GridView) ImageView(android.widget.ImageView) View(android.view.View) AbsListView(android.widget.AbsListView) TextView(android.widget.TextView) ConstraintLayout(androidx.constraintlayout.widget.ConstraintLayout) OCFile(com.owncloud.android.datamodel.OCFile) Bitmap(android.graphics.Bitmap) ThumbnailsCacheManager(com.owncloud.android.datamodel.ThumbnailsCacheManager) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) GridView(android.widget.GridView) ImageView(android.widget.ImageView) LinearLayout(android.widget.LinearLayout)

Aggregations

ConstraintLayout (androidx.constraintlayout.widget.ConstraintLayout)14 TextView (android.widget.TextView)5 View (android.view.View)4 LinearLayout (android.widget.LinearLayout)4 Bundle (android.os.Bundle)3 ImageView (android.widget.ImageView)3 Toolbar (androidx.appcompat.widget.Toolbar)3 ConstraintSet (androidx.constraintlayout.widget.ConstraintSet)3 ViewModelProvider (androidx.lifecycle.ViewModelProvider)3 AlertDialog (android.app.AlertDialog)2 Drawable (android.graphics.drawable.Drawable)2 TextUtils (android.text.TextUtils)2 LayoutInflater (android.view.LayoutInflater)2 Spinner (android.widget.Spinner)2 NonNull (androidx.annotation.NonNull)2 Nullable (androidx.annotation.Nullable)2 AppCompatResources (androidx.appcompat.content.res.AppCompatResources)2 ContextCompat (androidx.core.content.ContextCompat)2 DrawableCompat (androidx.core.graphics.drawable.DrawableCompat)2 NavDirections (androidx.navigation.NavDirections)2