Example usage for android.widget RelativeLayout setAlpha

List of usage examples for android.widget RelativeLayout setAlpha

Introduction

In this page you can find the example usage for android.widget RelativeLayout setAlpha.

Prototype

public void setAlpha(@FloatRange(from = 0.0, to = 1.0) float alpha) 

Source Link

Document

Sets the opacity of the view to a value from 0 to 1, where 0 means the view is completely transparent and 1 means the view is completely opaque.

Usage

From source file:pl.kodujdlapolski.na4lapy.ui.introduction.IntroductionPageTransformer.java

public void transformPage(View view, float position) {
    int pageWidth = view.getWidth();
    View text = view.findViewById(R.id.introduction_text);
    ImageView tut_a_3 = (ImageView) view.findViewById(R.id.tut_a_3);
    ImageView tut_a_2 = (ImageView) view.findViewById(R.id.tut_a_2);

    ImageView tut_b_3 = (ImageView) view.findViewById(R.id.tut_b_3);
    ImageView tut_b_2 = (ImageView) view.findViewById(R.id.tut_b_2);

    ImageView tut_c_2 = (ImageView) view.findViewById(R.id.tut_c_2);
    ImageView tut_c_3 = (ImageView) view.findViewById(R.id.tut_c_3);

    ImageView tut_d_2 = (ImageView) view.findViewById(R.id.tut_d_2);
    ImageView tut_d_3 = (ImageView) view.findViewById(R.id.tut_d_3);
    ImageView tut_d_4 = (ImageView) view.findViewById(R.id.tut_d_4);

    ImageView tut_e_2 = (ImageView) view.findViewById(R.id.tut_e_2);
    ImageView tut_e_3 = (ImageView) view.findViewById(R.id.tut_e_3);
    ImageView tut_e_4 = (ImageView) view.findViewById(R.id.tut_e_4);
    RelativeLayout lastIntroContainer = (RelativeLayout) view.findViewById(R.id.last_intro_container);

    if (position <= -1.0f || position >= 1.0f) {
    } else if (position == 0.0f) {
    } else {//w  ww .  j  a v  a2s  .c  o m
        if (lastIntroContainer != null && position < 0) { // set alpha for fading last element to only one side
            lastIntroContainer.setAlpha(1.0f - Math.abs(position));
        }
        if (text != null) {
            text.setAlpha(1.0f - Math.abs(position));
        }
        if (tut_a_2 != null) {
            tut_a_2.setAlpha(1.0f - Math.abs(position * 2));
            tut_a_2.setTranslationY(pageWidth / 20 * position);
        }
        if (tut_a_3 != null) {
            tut_a_3.setTranslationX(pageWidth / 10 * position);
        }

        if (tut_a_2 != null) {
            tut_a_2.setAlpha(1.0f - Math.abs(position * 2));
        }
        if (tut_b_2 != null) {
            tut_b_2.setAlpha(1.0f - Math.abs(position * 2));
        }
        if (tut_b_3 != null) {
            tut_b_3.setTranslationX(pageWidth / 20 * position * -1);
        }
        if (tut_c_2 != null) {
            tut_c_2.setTranslationX(pageWidth / 20 * position * -1);
        }
        if (tut_c_3 != null) {
            tut_c_3.setTranslationX(pageWidth / 10 * position);
        }
        if (tut_d_2 != null) {
            tut_d_2.setTranslationX(pageWidth / 10 * position * -1);
        }
        if (tut_d_3 != null) {
            tut_d_3.setTranslationX(pageWidth / 10 * position);
        }
        if (tut_d_4 != null) {
            tut_d_4.setAlpha(1.0f - Math.abs(position * 2));
            tut_d_4.setTranslationY(pageWidth / 20 * position);
        }
        if (tut_e_2 != null) {
            tut_e_2.setTranslationX(pageWidth / 10 * position);
        }
        if (tut_e_3 != null) {
            tut_e_3.setTranslationX(pageWidth / 10 * position);
            tut_e_3.setAlpha(1.0f - Math.abs(position));
        }
        if (tut_e_4 != null) {
            tut_e_4.setTranslationY(pageWidth / 20 * position * -1);

        }
    }
}

From source file:org.thoughtcrime.securesms.ProfileFragment.java

private void refreshLayout() {
    gDataPreferences = new GDataPreferences(getActivity());
    boolean isMyProfile = (GUtil.numberToLong(gDataPreferences.getE164Number() + "") + "")
            .contains(GUtil.numberToLong(profileId) + "");

    layout_status = (RelativeLayout) getView().findViewById(R.id.layout_status);
    layout_phone = (RelativeLayout) getView().findViewById(R.id.layout_phone);
    layout_group = (RelativeLayout) getView().findViewById(R.id.layout_member);

    statusDate = (TextView) getView().findViewById(R.id.profile__date);
    leaveGroup = (Button) getView().findViewById(R.id.buttonLeaveGroup);
    profileHeader = (TextView) getView().findViewById(R.id.profile_header);
    profileStatus = (AutoCompleteTextView) getView().findViewById(R.id.profile_status);
    xCloseButton = (ImageView) getView().findViewById(R.id.profile_close);
    imageText = (TextView) getView().findViewById(R.id.image_text);
    profilePhone = (TextView) getView().findViewById(R.id.profile_phone);
    groupMember = (ListView) getView().findViewById(R.id.selected_contacts_list);
    historyLayout = (LinearLayout) getView().findViewById(R.id.historylayout);
    historyContentTextView = (TextView) getView().findViewById(R.id.history_content);
    historyScrollView = (HorizontalScrollView) getView().findViewById(R.id.horizontal_scroll);
    recipientsPanel = (PushRecipientsPanel) getView().findViewById(R.id.recipients);
    profilePhone.setText(phonenumber);//w ww .j a  v  a  2s. c  o m
    profilePicture = (ThumbnailView) getView().findViewById(R.id.profile_picture);
    phoneCall = (ImageView) getView().findViewById(R.id.phone_call);
    (getView().findViewById(R.id.contacts_button)).setOnClickListener(new AddRecipientButtonListener());
    historyLine = (RelativeLayout) getView().findViewById(R.id.layout_history);
    recipient = recipients.getPrimaryRecipient();
    attachmentAdapter = new ProfileImageTypeSelectorAdapter(getActivity());
    scrollView = (ScrollView) getView().findViewById(R.id.scrollView);
    seekBarFont = (SeekBar) getView().findViewById(R.id.seekbar_font);
    chatPartnersColor = (CheckBox) getView().findViewById(R.id.enabled_chat_partners_color);
    colorDefault = (CheckBox) getView().findViewById(R.id.color_default);
    layoutColor = (RelativeLayout) getView().findViewById(R.id.layout_color);
    floatingActionColorButton = (FloatingActionButton) getView().findViewById(R.id.fab_new_color);
    final ImageView profileStatusEdit = (ImageView) getView().findViewById(R.id.profile_status_edit);

    if (!isGroup) {
        ImageSlide slide = ProfileAccessor.getProfileAsImageSlide(getActivity(), masterSecret, profileId);
        if (slide != null && !isMyProfile) {
            if (masterSecret != null) {
                try {
                    profilePicture.setImageResource(slide, masterSecret);
                } catch (IllegalStateException e) {
                    Log.w("GDATA", "Unable to load profile image");
                }
                profileStatus.setText(ProfileAccessor.getProfileStatusForRecepient(getActivity(), profileId),
                        TextView.BufferType.EDITABLE);
                profileStatus.setEnabled(false);
                layout_status.setOnTouchListener(new View.OnTouchListener() {
                    @Override
                    public boolean onTouch(View view, MotionEvent motionEvent) {
                        profileStatusEdit.performClick();
                        return false;
                    }
                });
                statusDate.setText(GUtil.getLocalDate(
                        ProfileAccessor.getProfileUpdateTimeForRecepient(getActivity(), profileId),
                        getActivity().getApplicationContext()));
                imageText.setText(recipient.getName());
            }
            profilePicture.setThumbnailClickListener(new ThumbnailClickListener());
        } else if (ProfileAccessor.getMyProfilePicture(getActivity()).hasImage() && isMyProfile) {
            profileStatus.setText(ProfileAccessor.getProfileStatus(getActivity()),
                    TextView.BufferType.EDITABLE);
            imageText.setText(getString(R.string.MediaPreviewActivity_you));
            initColorSeekbar();
            profilePicture.setThumbnailClickListener(new ThumbnailClickListener());
            if ((ProfileAccessor.getMyProfilePicture(getActivity()).getUri() + "").equals("")) {
                profilePicture.setImageBitmap(ContactPhotoFactory.getDefaultContactPhoto(getActivity()));
            } else {
                profilePicture.setImageResource(ProfileAccessor.getMyProfilePicture(getActivity()));
            }
            historyLine.setVisibility(View.GONE);
        } else {
            imageText.setText(recipient.getName());
            profilePicture.setImageBitmap(recipient.getContactPhoto());
        }
        layout_group.setVisibility(View.GONE);
    } else {
        String groupName = recipient.getName();
        Bitmap avatar = recipient.getContactPhoto();
        String encodedGroupId = recipient.getNumber();
        if (encodedGroupId != null) {
            try {
                groupId = GroupUtil.getDecodedId(encodedGroupId);
            } catch (IOException ioe) {
                groupId = null;
            }
        }
        GroupDatabase db = DatabaseFactory.getGroupDatabase(getActivity());
        Recipients recipients = db.getGroupMembers(groupId, false);

        recipientsPanel.setPanelChangeListener(new PushRecipientsPanel.RecipientsPanelChangedListener() {
            @Override
            public void onRecipientsPanelUpdate(Recipients recipients) {
                Log.w("GDATA", "onRecipientsPanelUpdate received.");
                if (recipients != null) {
                    addAllSelectedContacts(recipients.getRecipientsList());
                    syncAdapterWithSelectedContacts();
                }
            }
        });

        if (recipients != null) {
            final List<Recipient> recipientList = recipients.getRecipientsList();
            if (recipientList != null) {
                if (existingContacts == null)
                    existingContacts = new HashSet<>(recipientList.size());
                existingContacts.addAll(recipientList);
            }
            if (recipientList != null) {
                if (existingContacts == null)
                    existingContacts = new HashSet<>(recipientList.size());
                existingContacts.addAll(recipientList);
            }

            SelectedRecipientsAdapter adapter = new SelectedRecipientsAdapter(getActivity(), android.R.id.text1,
                    new ArrayList<SelectedRecipientsAdapter.RecipientWrapper>());
            adapter.clear();

            if (existingContacts != null) {
                for (Recipient contact : existingContacts) {
                    adapter.add(new SelectedRecipientsAdapter.RecipientWrapper(contact, false));
                }
            }
            adapter.setMasterSecret(masterSecret);
            adapter.setThreadId(threadId);
            adapter.setOnRecipientDeletedListener(new SelectedRecipientsAdapter.OnRecipientDeletedListener() {
                @Override
                public void onRecipientDeleted(Recipient recipient) {
                    removeSelectedContact(recipient);
                }
            });
            groupMember.setAdapter(adapter);
            adapter.notifyDataSetChanged();
        }
        if (avatar != null) {
            profilePicture.setVisibility(View.GONE);
            getView().findViewById(R.id.profile_picture_group).setVisibility(View.VISIBLE);
            scaleImage((ImageView) getView().findViewById(R.id.profile_picture_group), avatar);
        }
        imageText.setText(groupName);
        if (profileStatusString.equals("")) {
            profileStatus.setText(groupName);
        }
        layout_phone.setVisibility(View.GONE);

        leaveGroup.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (isActiveGroup()) {
                    handleLeavePushGroup();
                } else {
                    handleDeleteThread();
                }
            }
        });
        if (!isActiveGroup()) {
            leaveGroup.setText(getString(R.string.conversation__menu_delete_thread));
        }

        heightMemberList = GUtil.setListViewHeightBasedOnChildren(groupMember);
    }
    ImageView profileImageEdit = (ImageView) getView().findViewById(R.id.profile_picture_edit);
    ImageView profileImageDelete = (ImageView) getView().findViewById(R.id.profile_picture_delete);
    if (!isMyProfile && !isGroup) {
        profileStatusEdit.setVisibility(View.GONE);
        profileImageDelete.setVisibility(View.GONE);
        profileImageEdit.setVisibility(View.GONE);
    } else {
        if (isGroup) {
            profileImageDelete.setVisibility(View.GONE);
            profileHeader.setText(getString(R.string.group_title));
        } else {
            profileImageDelete.setVisibility(View.VISIBLE);
        }
        profileStatusEdit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                profileStatus.setEnabled(!profileStatus.isEnabled());
                if (!profileStatus.isEnabled()) {
                    hasChanged = true;
                    hasLeft = false;
                    profileStatusEdit.setImageDrawable(getResources().getDrawable(R.drawable.ic_content_edit));

                    InputMethodManager imm = (InputMethodManager) getActivity()
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(profileStatus.getWindowToken(), 0);
                    if (isGroup) {
                        new UpdateWhisperGroupAsyncTask().execute();
                    } else {
                        ProfileAccessor.setProfileStatus(getActivity(), profileStatus.getText() + "");
                    }
                } else {
                    profileStatusEdit
                            .setImageDrawable(getResources().getDrawable(R.drawable.ic_send_sms_gdata));
                    profileStatus.showDropDown();
                    profileStatus.requestFocus();
                }
            }
        });
        profileImageDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                hasChanged = true;
                hasLeft = false;
                ProfileAccessor.deleteMyProfilePicture(getActivity());
                refreshLayout();
                profileStatus.dismissDropDown();
                gDataPreferences.hasProfileImageChanged(true);
            }
        });
        profileImageEdit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                gDataPreferences.hasProfileImageChanged(true);
                hasChanged = true;
                hasLeft = false;
                handleAddAttachment();
            }
        });
    }
    if (isMyProfile) {
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),
                android.R.layout.simple_dropdown_item_1line,
                getResources().getStringArray(R.array.status_suggestions));
        profileStatus.setAdapter(adapter);
        profileStatus.setCompletionHint(getString(R.string.status_hint));
        profileStatus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                profileStatus.dismissDropDown();
            }
        });
        profileStatus.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                profileStatus.setEnabled(!profileStatus.isEnabled());
                if (!profileStatus.isEnabled()) {
                    hasChanged = true;
                    hasLeft = false;
                    profileStatusEdit.setImageDrawable(getResources().getDrawable(R.drawable.ic_content_edit));

                    InputMethodManager imm = (InputMethodManager) getActivity()
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(profileStatus.getWindowToken(), 0);
                    if (isGroup) {
                        new UpdateWhisperGroupAsyncTask().execute();
                    } else {
                        ProfileAccessor.setProfileStatus(getActivity(), profileStatus.getText() + "");
                    }
                }
            }
        });
    } else {
        //        if(!isMyProfile) {
        setMediaHistoryImages();
    }
    xCloseButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            finishAndSave();
        }
    });
    phoneCall.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            handleDial(recipient);
        }
    });
    final RelativeLayout scrollContainer = (RelativeLayout) getView().findViewById(R.id.scrollContainer);
    final LinearLayout mainLayout = (LinearLayout) getView().findViewById(R.id.mainlayout);
    scrollView.setSmoothScrollingEnabled(true);
    ViewTreeObserver vto = scrollView.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        public void onGlobalLayout() {
            scrollView.scrollTo(0, mainLayout.getTop() - PADDING_TOP);
        }
    });
    scrollContainer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // getActivity().finish();
        }
    });
    onScrollChangeListener = new ViewTreeObserver.OnScrollChangedListener() {

        @Override
        public void onScrollChanged() {
            if (BuildConfig.VERSION_CODE >= 11) {
                scrollContainer.setBackgroundColor(Color.WHITE);
                scrollContainer
                        .setAlpha((float) ((1000.0 / scrollContainer.getHeight()) * scrollView.getHeight()));
            }
            int keyboardHeight = 150;
            int paddingBottom = 250;
            int scrollViewHeight = scrollView.getHeight();
            if (getActivity().getResources()
                    .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
                scrollViewHeight = 2 * scrollViewHeight;
            }
            int heightDiff = scrollView.getRootView().getHeight() - scrollView.getHeight();
            if (pxToDp(heightDiff) > keyboardHeight) {
                keyboardIsVisible = true;
            } else {
                keyboardIsVisible = false;
            }
            if (!keyboardIsVisible) {
                if ((mainLayout.getTop() - scrollViewHeight) > scrollView.getScrollY()
                        - pxToDp(paddingBottom)) {
                    finishAndSave();
                }
                if ((scrollViewHeight + (heightMemberList)) < (scrollView.getScrollY() - mainLayout.getTop())) {
                    finishAndSave();
                }
            }
        }
    };
    scrollView.getViewTreeObserver().addOnScrollChangedListener(onScrollChangeListener);
    scrollView.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {

            ViewTreeObserver observer = scrollView.getViewTreeObserver();
            observer.addOnScrollChangedListener(onScrollChangeListener);
            return false;
        }

    });
}