Example usage for android.widget ImageView setScaleType

List of usage examples for android.widget ImageView setScaleType

Introduction

In this page you can find the example usage for android.widget ImageView setScaleType.

Prototype

public void setScaleType(ScaleType scaleType) 

Source Link

Document

Controls how the image should be resized or moved to match the size of this ImageView.

Usage

From source file:com.keylesspalace.tusky.activity.ComposeActivity.java

private void addMediaToQueue(QueuedMedia.Type type, Bitmap preview, Uri uri, long mediaSize) {
    final QueuedMedia item = new QueuedMedia(type, uri, new ImageView(this), mediaSize);
    ImageView view = item.preview;
    Resources resources = getResources();
    int side = resources.getDimensionPixelSize(R.dimen.compose_media_preview_side);
    int margin = resources.getDimensionPixelSize(R.dimen.compose_media_preview_margin);
    int marginBottom = resources.getDimensionPixelSize(R.dimen.compose_media_preview_margin_bottom);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(side, side);
    layoutParams.setMargins(margin, 0, margin, marginBottom);
    view.setLayoutParams(layoutParams);//from   w w w  .jav  a  2s  .  c  o m
    view.setScaleType(ImageView.ScaleType.CENTER_CROP);
    view.setImageBitmap(preview);

    view.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            removeMediaFromQueue(item);
        }
    });
    mediaPreviewBar.addView(view);
    mediaQueued.add(item);
    int queuedCount = mediaQueued.size();
    if (queuedCount == 1) {
        /* The media preview bar is actually not inset in the EditText, it just overlays it and
         * is aligned to the bottom. But, so that text doesn't get hidden under it, extra
         * padding is added at the bottom of the EditText. */
        int totalHeight = side + margin + marginBottom;
        textEditor.setPadding(textEditor.getPaddingLeft(), textEditor.getPaddingTop(),
                textEditor.getPaddingRight(), totalHeight);
        // If there's one video in the queue it is full, so disable the button to queue more.
        if (item.type == QueuedMedia.Type.VIDEO) {
            disableMediaPicking();
        }
    } else if (queuedCount >= Status.MAX_MEDIA_ATTACHMENTS) {
        // Limit the total media attachments, also.
        disableMediaPicking();
    }
    if (queuedCount >= 1) {
        showMarkSensitive(true);
    }
    waitForMediaLatch.countUp();
    if (mediaSize > STATUS_MEDIA_SIZE_LIMIT && type == QueuedMedia.Type.IMAGE) {
        downsizeMedia(item);
    } else {
        uploadMedia(item);
    }
}

From source file:com.mishiranu.dashchan.ui.navigator.DrawerForm.java

public DrawerForm(Context context, Context unstyledContext, Callback callback,
        WatcherService.Client watcherServiceClient) {
    this.context = context;
    this.unstyledContext = unstyledContext;
    this.callback = callback;
    this.watcherServiceClient = watcherServiceClient;
    float density = ResourceUtils.obtainDensity(context);
    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setLayoutParams(new SortableListView.LayoutParams(SortableListView.LayoutParams.MATCH_PARENT,
            SortableListView.LayoutParams.WRAP_CONTENT));
    LinearLayout editTextContainer = new LinearLayout(context);
    editTextContainer.setGravity(Gravity.CENTER_VERTICAL);
    linearLayout.addView(editTextContainer);
    searchEdit = new SafePasteEditText(context);
    searchEdit.setOnKeyListener((v, keyCode, event) -> {
        if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
            v.clearFocus();// w  w w.ja  v a  2 s . c o m
        }
        return false;
    });
    searchEdit.setHint(context.getString(R.string.text_code_number_address));
    searchEdit.setOnEditorActionListener(this);
    searchEdit.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
    searchEdit.setImeOptions(EditorInfo.IME_ACTION_GO | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
    ImageView searchIcon = new ImageView(context, null, android.R.attr.buttonBarButtonStyle);
    searchIcon.setImageResource(ResourceUtils.getResourceId(context, R.attr.buttonForward, 0));
    searchIcon.setScaleType(ImageView.ScaleType.CENTER);
    searchIcon.setOnClickListener(this);
    editTextContainer.addView(searchEdit,
            new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1));
    editTextContainer.addView(searchIcon, (int) (40f * density), (int) (40f * density));
    if (C.API_LOLLIPOP) {
        editTextContainer.setPadding((int) (12f * density), (int) (8f * density), (int) (8f * density), 0);
    } else {
        editTextContainer.setPadding(0, (int) (2f * density), (int) (4f * density), (int) (2f * density));
    }
    LinearLayout selectorContainer = new LinearLayout(context);
    selectorContainer.setBackgroundResource(
            ResourceUtils.getResourceId(context, android.R.attr.selectableItemBackground, 0));
    selectorContainer.setOrientation(LinearLayout.HORIZONTAL);
    selectorContainer.setGravity(Gravity.CENTER_VERTICAL);
    selectorContainer.setOnClickListener(v -> {
        hideKeyboard();
        setChanSelectMode(!chanSelectMode);
    });
    linearLayout.addView(selectorContainer);
    selectorContainer.setMinimumHeight((int) (40f * density));
    if (C.API_LOLLIPOP) {
        selectorContainer.setPadding((int) (16f * density), 0, (int) (16f * density), 0);
        ((LinearLayout.LayoutParams) selectorContainer.getLayoutParams()).topMargin = (int) (4f * density);
    } else {
        selectorContainer.setPadding((int) (8f * density), 0, (int) (12f * density), 0);
    }
    chanNameView = new TextView(context, null, android.R.attr.textAppearanceListItem);
    chanNameView.setTextSize(TypedValue.COMPLEX_UNIT_SP, C.API_LOLLIPOP ? 14f : 16f);
    if (C.API_LOLLIPOP) {
        chanNameView.setTypeface(GraphicsUtils.TYPEFACE_MEDIUM);
    } else {
        chanNameView.setFilters(new InputFilter[] { new InputFilter.AllCaps() });
    }
    selectorContainer.addView(chanNameView,
            new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1));
    chanSelectorIcon = new ImageView(context);
    chanSelectorIcon.setImageResource(ResourceUtils.getResourceId(context, R.attr.buttonDropDownDrawer, 0));
    selectorContainer.addView(chanSelectorIcon, (int) (24f * density), (int) (24f * density));
    ((LinearLayout.LayoutParams) chanSelectorIcon.getLayoutParams()).gravity = Gravity.CENTER_VERTICAL
            | Gravity.END;
    headerView = linearLayout;
    inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    chans.add(new ListItem(ListItem.ITEM_DIVIDER, 0, 0, null));
    int color = ResourceUtils.getColor(context, R.attr.drawerIconColor);
    ChanManager manager = ChanManager.getInstance();
    Collection<String> availableChans = manager.getAvailableChanNames();
    for (String chanName : availableChans) {
        ChanConfiguration configuration = ChanConfiguration.get(chanName);
        if (configuration.getOption(ChanConfiguration.OPTION_READ_POSTS_COUNT)) {
            watcherSupportSet.add(chanName);
        }
        Drawable drawable = manager.getIcon(chanName, color);
        chanIcons.put(chanName, drawable);
        chans.add(
                new ListItem(ListItem.ITEM_CHAN, chanName, null, null, configuration.getTitle(), 0, drawable));
    }
    if (availableChans.size() == 1) {
        selectorContainer.setVisibility(View.GONE);
    }
}

From source file:org.pouyadr.ui.LocationActivity.java

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    if (AndroidUtilities.isTablet()) {
        actionBar.setOccupyStatusBar(false);
    }//from  www . ja  v  a  2 s  . c  om
    actionBar.setAddToContainer(messageObject != null);

    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == map_list_menu_map) {
                if (googleMap != null) {
                    googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
                }
            } else if (id == map_list_menu_satellite) {
                if (googleMap != null) {
                    googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
                }
            } else if (id == map_list_menu_hybrid) {
                if (googleMap != null) {
                    googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
                }
            } else if (id == share) {
                try {
                    double lat = messageObject.messageOwner.media.geo.lat;
                    double lon = messageObject.messageOwner.media.geo._long;
                    getParentActivity().startActivity(new Intent(android.content.Intent.ACTION_VIEW,
                            Uri.parse("geo:" + lat + "," + lon + "?q=" + lat + "," + lon)));
                } catch (Exception e) {
                    FileLog.e("tmessages", e);
                }
            }
        }
    });

    ActionBarMenu menu = actionBar.createMenu();
    if (messageObject != null) {
        if (messageObject.messageOwner.media.title != null
                && messageObject.messageOwner.media.title.length() > 0) {
            actionBar.setTitle(messageObject.messageOwner.media.title);
            if (messageObject.messageOwner.media.address != null
                    && messageObject.messageOwner.media.address.length() > 0) {
                actionBar.setSubtitle(messageObject.messageOwner.media.address);
            }
        } else {
            actionBar.setTitle(LocaleController.getString("ChatLocation", R.string.ChatLocation));
        }
        menu.addItem(share, R.drawable.share);
    } else {
        actionBar.setTitle(LocaleController.getString("ShareLocation", R.string.ShareLocation));

        ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true)
                .setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
                    @Override
                    public void onSearchExpand() {
                        searching = true;
                        listView.setVisibility(View.GONE);
                        mapViewClip.setVisibility(View.GONE);
                        searchListView.setVisibility(View.VISIBLE);
                        searchListView.setEmptyView(emptyTextLayout);
                    }

                    @Override
                    public void onSearchCollapse() {
                        searching = false;
                        searchWas = false;
                        searchListView.setEmptyView(null);
                        listView.setVisibility(View.VISIBLE);
                        mapViewClip.setVisibility(View.VISIBLE);
                        searchListView.setVisibility(View.GONE);
                        emptyTextLayout.setVisibility(View.GONE);
                        searchAdapter.searchDelayed(null, null);
                    }

                    @Override
                    public void onTextChanged(EditText editText) {
                        if (searchAdapter == null) {
                            return;
                        }
                        String text = editText.getText().toString();
                        if (text.length() != 0) {
                            searchWas = true;
                        }
                        searchAdapter.searchDelayed(text, userLocation);
                    }
                });
        item.getSearchField().setHint(LocaleController.getString("Search", R.string.Search));
    }

    ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_other);
    item.addSubItem(map_list_menu_map, LocaleController.getString("Map", R.string.Map), 0);
    item.addSubItem(map_list_menu_satellite, LocaleController.getString("Satellite", R.string.Satellite), 0);
    item.addSubItem(map_list_menu_hybrid, LocaleController.getString("Hybrid", R.string.Hybrid), 0);
    fragmentView = new FrameLayout(context) {
        private boolean first = true;

        @Override
        protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
            super.onLayout(changed, left, top, right, bottom);

            if (changed) {
                fixLayoutInternal(first);
                first = false;
            }
        }
    };
    FrameLayout frameLayout = (FrameLayout) fragmentView;

    locationButton = new ImageView(context);
    locationButton.setBackgroundResource(R.drawable.floating_user_states);
    locationButton.setImageResource(R.drawable.myloc_on);
    locationButton.setScaleType(ImageView.ScaleType.CENTER);
    if (Build.VERSION.SDK_INT >= 21) {
        StateListAnimator animator = new StateListAnimator();
        animator.addState(new int[] { android.R.attr.state_pressed },
                ObjectAnimator
                        .ofFloat(locationButton, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4))
                        .setDuration(200));
        animator.addState(new int[] {},
                ObjectAnimator
                        .ofFloat(locationButton, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2))
                        .setDuration(200));
        locationButton.setStateListAnimator(animator);
        locationButton.setOutlineProvider(new ViewOutlineProvider() {
            @Override
            public void getOutline(View view, Outline outline) {
                outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56));
            }
        });
    }

    if (messageObject != null) {
        mapView = new MapView(context);
        frameLayout.setBackgroundDrawable(new MapPlaceholderDrawable());
        mapView.onCreate(null);
        try {
            MapsInitializer.initialize(context);
            //                googleMap = mapView.getMap();
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }

        FrameLayout bottomView = new FrameLayout(context);
        bottomView.setBackgroundResource(R.drawable.location_panel);
        frameLayout.addView(bottomView,
                LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 60, Gravity.LEFT | Gravity.BOTTOM));
        bottomView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (userLocation != null) {
                    LatLng latLng = new LatLng(userLocation.getLatitude(), userLocation.getLongitude());
                    if (googleMap != null) {
                        CameraUpdate position = CameraUpdateFactory.newLatLngZoom(latLng,
                                googleMap.getMaxZoomLevel() - 4);
                        googleMap.animateCamera(position);
                    }
                }
            }
        });

        avatarImageView = new BackupImageView(context);
        avatarImageView.setRoundRadius(AndroidUtilities.dp(20));
        bottomView.addView(avatarImageView,
                LayoutHelper.createFrame(40, 40,
                        Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT),
                        LocaleController.isRTL ? 0 : 12, 12, LocaleController.isRTL ? 12 : 0, 0));

        nameTextView = new TextView(context);
        nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
        nameTextView.setTextColor(0xff212121);
        nameTextView.setMaxLines(1);
        nameTextView.setTypeface(AndroidUtilities.getTypeface(org.pouyadr.finalsoft.Fonts.CurrentFont()));
        nameTextView.setEllipsize(TextUtils.TruncateAt.END);
        nameTextView.setSingleLine(true);
        nameTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
        bottomView.addView(nameTextView,
                LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT,
                        Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT),
                        LocaleController.isRTL ? 12 : 72, 10, LocaleController.isRTL ? 72 : 12, 0));

        distanceTextView = new TextView(context);
        distanceTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
        distanceTextView.setTextColor(0xff2f8cc9);
        distanceTextView.setMaxLines(1);
        distanceTextView.setEllipsize(TextUtils.TruncateAt.END);
        distanceTextView.setSingleLine(true);
        distanceTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
        bottomView.addView(distanceTextView,
                LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT,
                        Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT),
                        LocaleController.isRTL ? 12 : 72, 33, LocaleController.isRTL ? 72 : 12, 0));

        userLocation = new Location("network");
        userLocation.setLatitude(messageObject.messageOwner.media.geo.lat);
        userLocation.setLongitude(messageObject.messageOwner.media.geo._long);
        if (googleMap != null) {
            LatLng latLng = new LatLng(userLocation.getLatitude(), userLocation.getLongitude());
            try {
                googleMap.addMarker(new MarkerOptions().position(latLng)
                        .icon(BitmapDescriptorFactory.fromResource(R.drawable.map_pin)));
            } catch (Exception e) {
                FileLog.e("tmessages", e);
            }
            CameraUpdate position = CameraUpdateFactory.newLatLngZoom(latLng, googleMap.getMaxZoomLevel() - 4);
            googleMap.moveCamera(position);
        }

        ImageView routeButton = new ImageView(context);
        routeButton.setBackgroundResource(R.drawable.floating_states);
        routeButton.setImageResource(R.drawable.navigate);
        routeButton.setScaleType(ImageView.ScaleType.CENTER);
        if (Build.VERSION.SDK_INT >= 21) {
            StateListAnimator animator = new StateListAnimator();
            animator.addState(new int[] { android.R.attr.state_pressed }, ObjectAnimator
                    .ofFloat(routeButton, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4))
                    .setDuration(200));
            animator.addState(new int[] {}, ObjectAnimator
                    .ofFloat(routeButton, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2))
                    .setDuration(200));
            routeButton.setStateListAnimator(animator);
            routeButton.setOutlineProvider(new ViewOutlineProvider() {
                @Override
                public void getOutline(View view, Outline outline) {
                    outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56));
                }
            });
        }
        frameLayout.addView(routeButton,
                LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT,
                        (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.BOTTOM,
                        LocaleController.isRTL ? 14 : 0, 0, LocaleController.isRTL ? 0 : 14, 28));
        routeButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (Build.VERSION.SDK_INT >= 23) {
                    Activity activity = getParentActivity();
                    if (activity != null) {
                        if (activity.checkSelfPermission(
                                Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                            showPermissionAlert(true);
                            return;
                        }
                    }
                }
                if (myLocation != null) {
                    try {
                        Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
                                Uri.parse(String.format(Locale.US,
                                        "http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f",
                                        myLocation.getLatitude(), myLocation.getLongitude(),
                                        messageObject.messageOwner.media.geo.lat,
                                        messageObject.messageOwner.media.geo._long)));
                        getParentActivity().startActivity(intent);
                    } catch (Exception e) {
                        FileLog.e("tmessages", e);
                    }
                }
            }
        });

        frameLayout.addView(locationButton,
                LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT,
                        (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.BOTTOM,
                        LocaleController.isRTL ? 14 : 0, 0, LocaleController.isRTL ? 0 : 14, 100));
        locationButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (Build.VERSION.SDK_INT >= 23) {
                    Activity activity = getParentActivity();
                    if (activity != null) {
                        if (activity.checkSelfPermission(
                                Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                            showPermissionAlert(true);
                            return;
                        }
                    }
                }
                if (myLocation != null && googleMap != null) {
                    googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(
                            new LatLng(myLocation.getLatitude(), myLocation.getLongitude()),
                            googleMap.getMaxZoomLevel() - 4));
                }
            }
        });
    } else {
        searchWas = false;
        searching = false;
        mapViewClip = new FrameLayout(context);
        mapViewClip.setBackgroundDrawable(new MapPlaceholderDrawable());
        if (adapter != null) {
            adapter.destroy();
        }
        if (searchAdapter != null) {
            searchAdapter.destroy();
        }

        listView = new ListView(context);
        listView.setAdapter(adapter = new LocationActivityAdapter(context));
        listView.setVerticalScrollBarEnabled(false);
        listView.setDividerHeight(0);
        listView.setDivider(null);
        frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
                LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP));
        listView.setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {

            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
                    int totalItemCount) {
                if (totalItemCount == 0) {
                    return;
                }
                updateClipView(firstVisibleItem);
            }
        });
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (position == 1) {
                    if (delegate != null && userLocation != null) {
                        TLRPC.TL_messageMediaGeo location = new TLRPC.TL_messageMediaGeo();
                        location.geo = new TLRPC.TL_geoPoint();
                        location.geo.lat = userLocation.getLatitude();
                        location.geo._long = userLocation.getLongitude();
                        delegate.didSelectLocation(location);
                    }
                    finishFragment();
                } else {
                    TLRPC.TL_messageMediaVenue object = adapter.getItem(position);
                    if (object != null && delegate != null) {
                        delegate.didSelectLocation(object);
                    }
                    finishFragment();
                }
            }
        });
        adapter.setDelegate(new BaseLocationAdapter.BaseLocationAdapterDelegate() {
            @Override
            public void didLoadedSearchResult(ArrayList<TLRPC.TL_messageMediaVenue> places) {
                if (!wasResults && !places.isEmpty()) {
                    wasResults = true;
                }
            }
        });
        adapter.setOverScrollHeight(overScrollHeight);

        frameLayout.addView(mapViewClip, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
                LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP));

        mapView = new MapView(context) {
            @Override
            public boolean onInterceptTouchEvent(MotionEvent ev) {
                if (Build.VERSION.SDK_INT >= 11) {
                    if (ev.getAction() == MotionEvent.ACTION_DOWN) {
                        if (animatorSet != null) {
                            animatorSet.cancel();
                        }
                        animatorSet = new AnimatorSet();
                        animatorSet.setDuration(200);
                        animatorSet.playTogether(
                                ObjectAnimator.ofFloat(markerImageView, "translationY",
                                        markerTop + -AndroidUtilities.dp(10)),
                                ObjectAnimator.ofFloat(markerXImageView, "alpha", 1.0f));
                        animatorSet.start();
                    } else if (ev.getAction() == MotionEvent.ACTION_UP) {
                        if (animatorSet != null) {
                            animatorSet.cancel();
                        }
                        animatorSet = new AnimatorSet();
                        animatorSet.setDuration(200);
                        animatorSet.playTogether(
                                ObjectAnimator.ofFloat(markerImageView, "translationY", markerTop),
                                ObjectAnimator.ofFloat(markerXImageView, "alpha", 0.0f));
                        animatorSet.start();
                    }
                }
                if (ev.getAction() == MotionEvent.ACTION_MOVE) {
                    if (!userLocationMoved) {
                        if (Build.VERSION.SDK_INT >= 11) {
                            AnimatorSet animatorSet = new AnimatorSet();
                            animatorSet.setDuration(200);
                            animatorSet.play(ObjectAnimator.ofFloat(locationButton, "alpha", 1.0f));
                            animatorSet.start();
                        } else {
                            locationButton.setVisibility(VISIBLE);
                        }
                        userLocationMoved = true;
                    }
                    if (googleMap != null && userLocation != null) {
                        userLocation.setLatitude(googleMap.getCameraPosition().target.latitude);
                        userLocation.setLongitude(googleMap.getCameraPosition().target.longitude);
                    }
                    adapter.setCustomLocation(userLocation);
                }
                return super.onInterceptTouchEvent(ev);
            }
        };
        try {
            mapView.onCreate(null);
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }
        try {
            MapsInitializer.initialize(context);
            //                googleMap = mapView.getMap();
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }

        View shadow = new View(context);
        shadow.setBackgroundResource(R.drawable.header_shadow_reverse);
        mapViewClip.addView(shadow,
                LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3, Gravity.LEFT | Gravity.BOTTOM));

        markerImageView = new ImageView(context);
        markerImageView.setImageResource(R.drawable.map_pin);
        mapViewClip.addView(markerImageView,
                LayoutHelper.createFrame(24, 42, Gravity.TOP | Gravity.CENTER_HORIZONTAL));

        if (Build.VERSION.SDK_INT >= 11) {
            markerXImageView = new ImageView(context);
            markerXImageView.setAlpha(0.0f);
            markerXImageView.setImageResource(R.drawable.place_x);
            mapViewClip.addView(markerXImageView,
                    LayoutHelper.createFrame(14, 14, Gravity.TOP | Gravity.CENTER_HORIZONTAL));
        }

        mapViewClip.addView(locationButton,
                LayoutHelper.createFrame(Build.VERSION.SDK_INT >= 21 ? 56 : 60,
                        Build.VERSION.SDK_INT >= 21 ? 56 : 60,
                        (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.BOTTOM,
                        LocaleController.isRTL ? 14 : 0, 0, LocaleController.isRTL ? 0 : 14, 14));
        locationButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (Build.VERSION.SDK_INT >= 23) {
                    Activity activity = getParentActivity();
                    if (activity != null) {
                        if (activity.checkSelfPermission(
                                Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                            showPermissionAlert(false);
                            return;
                        }
                    }
                }
                if (myLocation != null && googleMap != null) {
                    if (Build.VERSION.SDK_INT >= 11) {
                        AnimatorSet animatorSet = new AnimatorSet();
                        animatorSet.setDuration(200);
                        animatorSet.play(ObjectAnimator.ofFloat(locationButton, "alpha", 0.0f));
                        animatorSet.start();
                    } else {
                        locationButton.setVisibility(View.INVISIBLE);
                    }
                    adapter.setCustomLocation(null);
                    userLocationMoved = false;
                    googleMap.animateCamera(CameraUpdateFactory
                            .newLatLng(new LatLng(myLocation.getLatitude(), myLocation.getLongitude())));
                }
            }
        });
        if (Build.VERSION.SDK_INT >= 11) {
            locationButton.setAlpha(0.0f);
        } else {
            locationButton.setVisibility(View.INVISIBLE);
        }

        emptyTextLayout = new LinearLayout(context);
        emptyTextLayout.setVisibility(View.GONE);
        emptyTextLayout.setOrientation(LinearLayout.VERTICAL);
        frameLayout.addView(emptyTextLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
                LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 0, 100, 0, 0));
        emptyTextLayout.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return true;
            }
        });

        TextView emptyTextView = new TextView(context);
        emptyTextView.setTextColor(0xff808080);
        emptyTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
        emptyTextView.setGravity(Gravity.CENTER);
        emptyTextView.setText(LocaleController.getString("NoResult", R.string.NoResult));
        emptyTextLayout.addView(emptyTextView,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 0.5f));

        FrameLayout frameLayoutEmpty = new FrameLayout(context);
        emptyTextLayout.addView(frameLayoutEmpty,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 0.5f));

        searchListView = new ListView(context);
        searchListView.setVisibility(View.GONE);
        searchListView.setDividerHeight(0);
        searchListView.setDivider(null);
        searchListView.setAdapter(searchAdapter = new LocationActivitySearchAdapter(context));
        frameLayout.addView(searchListView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
                LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP));
        searchListView.setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {
                if (scrollState == SCROLL_STATE_TOUCH_SCROLL && searching && searchWas) {
                    AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
                }
            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
                    int totalItemCount) {

            }
        });
        searchListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                TLRPC.TL_messageMediaVenue object = searchAdapter.getItem(position);
                if (object != null && delegate != null) {
                    delegate.didSelectLocation(object);
                }
                finishFragment();
            }
        });

        if (googleMap != null) {
            userLocation = new Location("network");
            userLocation.setLatitude(20.659322);
            userLocation.setLongitude(-11.406250);
        }

        frameLayout.addView(actionBar);
    }

    if (googleMap != null) {
        try {
            googleMap.setMyLocationEnabled(true);
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }
        googleMap.getUiSettings().setMyLocationButtonEnabled(false);
        googleMap.getUiSettings().setZoomControlsEnabled(false);
        googleMap.getUiSettings().setCompassEnabled(false);
        googleMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() {
            @Override
            public void onMyLocationChange(Location location) {
                positionMarker(location);
            }
        });
        positionMarker(myLocation = getLastLocation());
    }

    return fragmentView;
}

From source file:com.fa.mastodon.activity.ComposeActivity.java

private void addMediaToQueue(QueuedMedia.Type type, Bitmap preview, Uri uri, long mediaSize) {
    final QueuedMedia item = new QueuedMedia(type, uri, new ImageView(this), mediaSize);
    ImageView view = item.preview;
    Resources resources = getResources();
    int side = resources.getDimensionPixelSize(R.dimen.compose_media_preview_side);
    int margin = resources.getDimensionPixelSize(R.dimen.compose_media_preview_margin);
    int marginBottom = resources.getDimensionPixelSize(R.dimen.compose_media_preview_margin_bottom);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(side, side);
    layoutParams.setMargins(margin, 0, margin, marginBottom);
    view.setLayoutParams(layoutParams);/*from  w  w w .  j  a v a 2 s.  com*/
    view.setScaleType(ImageView.ScaleType.CENTER_CROP);
    view.setImageBitmap(preview);

    view.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            removeMediaFromQueue(item);
        }
    });
    mediaPreviewBar.addView(view);
    mediaQueued.add(item);
    int queuedCount = mediaQueued.size();
    if (queuedCount == 1) {
        /* The media preview bar is actually not inset in the EditText, it just overlays it and
         * is aligned to the bottom. But, so that text doesn't get hidden under it, extra
         * padding is added at the bottom of the EditText. */
        int totalHeight = side + margin + marginBottom;
        textEditor.setPadding(textEditor.getPaddingLeft(), textEditor.getPaddingTop(),
                textEditor.getPaddingRight(), totalHeight);
        // If there's one video in the queue it is full, so disable the button to queue more.
        if (item.type == QueuedMedia.Type.VIDEO) {
            disableMediaButtons();
        }
    } else if (queuedCount >= Status.MAX_MEDIA_ATTACHMENTS) {
        // Limit the total media attachments, also.
        disableMediaButtons();
    }
    if (queuedCount >= 1) {
        showMarkSensitive(true);
    }
    waitForMediaLatch.countUp();
    if (mediaSize > STATUS_MEDIA_SIZE_LIMIT && type == QueuedMedia.Type.IMAGE) {
        downsizeMedia(item);
    } else {
        uploadMedia(item);
    }
}

From source file:com.vonglasow.michael.satstat.ui.RadioSectionFragment.java

private final void addWifiResult(ScanResult result) {
    // needed to pass a persistent reference to the OnClickListener
    final ScanResult r = result;
    android.view.View.OnClickListener clis = new android.view.View.OnClickListener() {

        @Override/*from   ww w .jav a2 s  . co  m*/
        public void onClick(View v) {
            onWifiEntryClick(r.BSSID);
        }
    };

    LinearLayout wifiLayout = new LinearLayout(wifiAps.getContext());
    wifiLayout.setLayoutParams(
            new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    wifiLayout.setOrientation(LinearLayout.HORIZONTAL);
    wifiLayout.setWeightSum(22);
    wifiLayout.setMeasureWithLargestChildEnabled(false);

    ImageView wifiType = new ImageView(wifiAps.getContext());
    wifiType.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.MATCH_PARENT, 3));
    if (WifiCapabilities.isAdhoc(result)) {
        wifiType.setImageResource(R.drawable.ic_content_wifi_adhoc);
    } else if ((WifiCapabilities.isEnterprise(result))
            || (WifiCapabilities.getScanResultSecurity(result) == WifiCapabilities.EAP)) {
        wifiType.setImageResource(R.drawable.ic_content_wifi_eap);
    } else if (WifiCapabilities.getScanResultSecurity(result) == WifiCapabilities.PSK) {
        wifiType.setImageResource(R.drawable.ic_content_wifi_psk);
    } else if (WifiCapabilities.getScanResultSecurity(result) == WifiCapabilities.WEP) {
        wifiType.setImageResource(R.drawable.ic_content_wifi_wep);
    } else if (WifiCapabilities.getScanResultSecurity(result) == WifiCapabilities.OPEN) {
        wifiType.setImageResource(R.drawable.ic_content_wifi_open);
    } else {
        wifiType.setImageResource(R.drawable.ic_content_wifi_unknown);
    }

    wifiType.setScaleType(ScaleType.CENTER);
    wifiLayout.addView(wifiType);

    TableLayout wifiDetails = new TableLayout(wifiAps.getContext());
    wifiDetails.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 19));
    TableRow innerRow1 = new TableRow(wifiAps.getContext());
    TextView newMac = new TextView(wifiAps.getContext());
    newMac.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 14));
    newMac.setTextAppearance(wifiAps.getContext(), android.R.style.TextAppearance_Medium);
    newMac.setText(result.BSSID);
    innerRow1.addView(newMac);
    TextView newCh = new TextView(wifiAps.getContext());
    newCh.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 2));
    newCh.setTextAppearance(wifiAps.getContext(), android.R.style.TextAppearance_Medium);
    newCh.setText(getChannelFromFrequency(result.frequency));
    innerRow1.addView(newCh);
    TextView newLevel = new TextView(wifiAps.getContext());
    newLevel.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 3));
    newLevel.setTextAppearance(wifiAps.getContext(), android.R.style.TextAppearance_Medium);
    newLevel.setText(String.valueOf(result.level));
    innerRow1.addView(newLevel);
    innerRow1.setOnClickListener(clis);
    wifiDetails.addView(innerRow1,
            new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    TableRow innerRow2 = new TableRow(wifiAps.getContext());
    TextView newSSID = new TextView(wifiAps.getContext());
    newSSID.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 19));
    newSSID.setTextAppearance(wifiAps.getContext(), android.R.style.TextAppearance_Small);
    newSSID.setText(result.SSID);
    innerRow2.addView(newSSID);
    innerRow2.setOnClickListener(clis);
    wifiDetails.addView(innerRow2,
            new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    wifiLayout.addView(wifiDetails);
    wifiLayout.setOnClickListener(clis);
    wifiAps.addView(wifiLayout);
}

From source file:com.mobicage.rogerthat.plugins.messaging.ServiceMessageDetailActivity.java

private RelativeLayout createParticipantView(MemberStatusTO ms) {
    RelativeLayout rl = new RelativeLayout(this);
    int rlW = UIUtils.convertDipToPixels(this, 55);
    rl.setLayoutParams(new RelativeLayout.LayoutParams(rlW, rlW));

    getLayoutInflater().inflate(R.layout.avatar, rl);
    ImageView avatar = (ImageView) rl.getChildAt(rl.getChildCount() - 1);
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(avatar.getLayoutParams());
    params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
    avatar.setLayoutParams(params);//from  w w  w .j  a v  a 2s  .c om
    setAvatar(avatar, ms.member);

    ImageView statusView = new ImageView(this);
    int w = UIUtils.convertDipToPixels(this, 12);
    RelativeLayout.LayoutParams iconParams = new RelativeLayout.LayoutParams(w, w);
    iconParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
    iconParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
    statusView.setLayoutParams(iconParams);
    statusView.setAdjustViewBounds(true);
    statusView.setScaleType(ScaleType.CENTER_CROP);
    setStatusIcon(statusView, ms);
    rl.addView(statusView);
    return rl;
}

From source file:org.egov.android.view.activity.ComplaintDetailActivity.java

/**
 * Function called when the activity was created to show the images attached
 * with the complaints Get the files from the complaint folder path and show
 * that images in horizontal scroll view
 *//*from   www. jav a  2s  . c  om*/
private void _showComplaintImages() {
    File folder = new File(complaintFolderName);
    if (!folder.exists()) {
        return;
    }
    File[] listOfFiles = folder.listFiles();

    int imageidx = 0;

    for (int i = 0; i < listOfFiles.length; i++) {

        if (listOfFiles[i].isFile()) {
            Log.d("EGOV_JOB", "File path" + complaintFolderName + File.separator + listOfFiles[i].getName());

            if (listOfFiles[i].getName().startsWith("photo_")) {
                continue;
            }

            ImageView image = new ImageView(this);
            Bitmap bmp = _getBitmapImage(complaintFolderName + File.separator + listOfFiles[i].getName());
            image.setImageBitmap(bmp);
            image.setId(imageidx);
            imageidx = imageidx + 1;
            image.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent photo_viewer = new Intent(ComplaintDetailActivity.this, PhotoViewerActivity.class);
                    photo_viewer.putExtra("path", complaintFolderName);
                    photo_viewer.putExtra("complaintId", complaintId);
                    photo_viewer.putExtra("imageId", v.getId());
                    startActivity(photo_viewer);
                }
            });
            LinearLayout.LayoutParams inner_container_params = new LinearLayout.LayoutParams(_dpToPix(90),
                    _dpToPix(90));
            inner_container_params.setMargins(0, 0, 10, 0);
            image.setLayoutParams(inner_container_params);
            image.setPadding(2, 2, 2, 2);
            image.setBackgroundDrawable(getResources().getDrawable(R.drawable.edittext_border));
            image.setScaleType(ScaleType.CENTER_INSIDE);
            imageCntainer.addView(image);
        }
    }
}

From source file:org.telegram.ui.Components.AudioPlayerAlert.java

public AudioPlayerAlert(final Context context) {
    super(context, true);

    MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
    if (messageObject != null) {
        currentAccount = messageObject.currentAccount;
    } else {/*from w  ww  .j a  va  2s. com*/
        currentAccount = UserConfig.selectedAccount;
    }

    parentActivity = (LaunchActivity) context;
    noCoverDrawable = context.getResources().getDrawable(R.drawable.nocover).mutate();
    noCoverDrawable.setColorFilter(
            new PorterDuffColorFilter(Theme.getColor(Theme.key_player_placeholder), PorterDuff.Mode.MULTIPLY));

    TAG = DownloadController.getInstance(currentAccount).generateObserverTag();
    NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.messagePlayingDidReset);
    NotificationCenter.getInstance(currentAccount).addObserver(this,
            NotificationCenter.messagePlayingPlayStateChanged);
    NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.messagePlayingDidStart);
    NotificationCenter.getInstance(currentAccount).addObserver(this,
            NotificationCenter.messagePlayingProgressDidChanged);
    NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.musicDidLoad);

    shadowDrawable = context.getResources().getDrawable(R.drawable.sheet_shadow).mutate();
    shadowDrawable.setColorFilter(
            new PorterDuffColorFilter(Theme.getColor(Theme.key_player_background), PorterDuff.Mode.MULTIPLY));
    paint.setColor(Theme.getColor(Theme.key_player_placeholderBackground));

    containerView = new FrameLayout(context) {

        private boolean ignoreLayout = false;

        @Override
        public boolean onInterceptTouchEvent(MotionEvent ev) {
            if (ev.getAction() == MotionEvent.ACTION_DOWN && scrollOffsetY != 0 && ev.getY() < scrollOffsetY
                    && placeholderImageView.getTranslationX() == 0) {
                dismiss();
                return true;
            }
            return super.onInterceptTouchEvent(ev);
        }

        @Override
        public boolean onTouchEvent(MotionEvent e) {
            return !isDismissed() && super.onTouchEvent(e);
        }

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            int height = MeasureSpec.getSize(heightMeasureSpec);
            int contentSize = AndroidUtilities.dp(178) + playlist.size() * AndroidUtilities.dp(56)
                    + backgroundPaddingTop + ActionBar.getCurrentActionBarHeight()
                    + AndroidUtilities.statusBarHeight;
            int padding;
            heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
            if (searching) {
                padding = AndroidUtilities.dp(178) + ActionBar.getCurrentActionBarHeight()
                        + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0);
            } else {
                if (contentSize < height) {
                    padding = height - contentSize;
                } else {
                    padding = (contentSize < height ? 0 : height - (height / 5 * 3));
                }
                padding += ActionBar.getCurrentActionBarHeight()
                        + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0);
            }
            if (listView.getPaddingTop() != padding) {
                ignoreLayout = true;
                listView.setPadding(0, padding, 0, AndroidUtilities.dp(8));
                ignoreLayout = false;
            }
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
            inFullSize = getMeasuredHeight() >= height;
            int availableHeight = height - ActionBar.getCurrentActionBarHeight()
                    - (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0)
                    - AndroidUtilities.dp(120);
            int maxSize = Math.max(availableHeight, getMeasuredWidth());
            thumbMaxX = (getMeasuredWidth() - maxSize) / 2 - AndroidUtilities.dp(17);
            thumbMaxY = AndroidUtilities.dp(19);
            panelEndTranslation = getMeasuredHeight() - playerLayout.getMeasuredHeight();
            thumbMaxScale = maxSize / (float) placeholderImageView.getMeasuredWidth() - 1.0f;

            endTranslation = ActionBar.getCurrentActionBarHeight() + AndroidUtilities.dp(5);
            int scaledHeight = (int) Math
                    .ceil(placeholderImageView.getMeasuredHeight() * (1.0f + thumbMaxScale));
            if (scaledHeight > availableHeight) {
                endTranslation -= (scaledHeight - availableHeight);
            }
        }

        @Override
        protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
            super.onLayout(changed, left, top, right, bottom);
            int y = actionBar.getMeasuredHeight();
            shadow.layout(shadow.getLeft(), y, shadow.getRight(), y + shadow.getMeasuredHeight());
            updateLayout();

            setFullAnimationProgress(fullAnimationProgress);
        }

        @Override
        public void requestLayout() {
            if (ignoreLayout) {
                return;
            }
            super.requestLayout();
        }

        @Override
        protected void onDraw(Canvas canvas) {
            shadowDrawable.setBounds(0,
                    Math.max(actionBar.getMeasuredHeight(), scrollOffsetY) - backgroundPaddingTop,
                    getMeasuredWidth(), getMeasuredHeight());
            shadowDrawable.draw(canvas);
        }
    };
    containerView.setWillNotDraw(false);
    containerView.setPadding(backgroundPaddingLeft, 0, backgroundPaddingLeft, 0);

    actionBar = new ActionBar(context);
    actionBar.setBackgroundColor(Theme.getColor(Theme.key_player_actionBar));
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setItemsColor(Theme.getColor(Theme.key_player_actionBarItems), false);
    actionBar.setItemsBackgroundColor(Theme.getColor(Theme.key_player_actionBarSelector), false);
    actionBar.setTitleColor(Theme.getColor(Theme.key_player_actionBarTitle));
    actionBar.setSubtitleColor(Theme.getColor(Theme.key_player_actionBarSubtitle));
    actionBar.setAlpha(0.0f);
    actionBar.setTitle("1");
    actionBar.setSubtitle("1");
    actionBar.getTitleTextView().setAlpha(0.0f);
    actionBar.getSubtitleTextView().setAlpha(0.0f);
    avatarContainer = new ChatAvatarContainer(context, null, false);
    avatarContainer.setEnabled(false);
    avatarContainer.setTitleColors(Theme.getColor(Theme.key_player_actionBarTitle),
            Theme.getColor(Theme.key_player_actionBarSubtitle));
    if (messageObject != null) {
        long did = messageObject.getDialogId();
        int lower_id = (int) did;
        int high_id = (int) (did >> 32);
        if (lower_id != 0) {
            if (lower_id > 0) {
                TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(lower_id);
                if (user != null) {
                    avatarContainer.setTitle(ContactsController.formatName(user.first_name, user.last_name));
                    avatarContainer.setUserAvatar(user);
                }
            } else {
                TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-lower_id);
                if (chat != null) {
                    avatarContainer.setTitle(chat.title);
                    avatarContainer.setChatAvatar(chat);
                }
            }
        } else {
            TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance(currentAccount)
                    .getEncryptedChat(high_id);
            if (encryptedChat != null) {
                TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(encryptedChat.user_id);
                if (user != null) {
                    avatarContainer.setTitle(ContactsController.formatName(user.first_name, user.last_name));
                    avatarContainer.setUserAvatar(user);
                }
            }
        }
    }
    avatarContainer.setSubtitle(LocaleController.getString("AudioTitle", R.string.AudioTitle));
    actionBar.addView(avatarContainer, 0, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT,
            LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 56, 0, 40, 0));

    ActionBarMenu menu = actionBar.createMenu();
    menuItem = menu.addItem(0, R.drawable.ic_ab_other);
    menuItem.addSubItem(1, LocaleController.getString("Forward", R.string.Forward));
    menuItem.addSubItem(2, LocaleController.getString("ShareFile", R.string.ShareFile));
    //menuItem.addSubItem(3, LocaleController.getString("Delete", R.string.Delete));
    menuItem.addSubItem(4, LocaleController.getString("ShowInChat", R.string.ShowInChat));
    menuItem.setTranslationX(AndroidUtilities.dp(48));
    menuItem.setAlpha(0.0f);

    searchItem = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true)
            .setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
                @Override
                public void onSearchCollapse() {
                    avatarContainer.setVisibility(View.VISIBLE);
                    if (hasOptions) {
                        menuItem.setVisibility(View.INVISIBLE);
                    }
                    if (searching) {
                        searchWas = false;
                        searching = false;
                        setAllowNestedScroll(true);
                        listAdapter.search(null);
                    }
                }

                @Override
                public void onSearchExpand() {
                    searchOpenPosition = layoutManager.findLastVisibleItemPosition();
                    View firstVisView = layoutManager.findViewByPosition(searchOpenPosition);
                    searchOpenOffset = ((firstVisView == null) ? 0 : firstVisView.getTop())
                            - listView.getPaddingTop();

                    avatarContainer.setVisibility(View.GONE);
                    if (hasOptions) {
                        menuItem.setVisibility(View.GONE);
                    }
                    searching = true;
                    setAllowNestedScroll(false);
                    listAdapter.notifyDataSetChanged();
                }

                @Override
                public void onTextChanged(EditText editText) {
                    if (editText.length() > 0) {
                        listAdapter.search(editText.getText().toString());
                    } else {
                        searchWas = false;
                        listAdapter.search(null);
                    }
                }
            });
    EditTextBoldCursor editText = searchItem.getSearchField();
    editText.setHint(LocaleController.getString("Search", R.string.Search));
    editText.setTextColor(Theme.getColor(Theme.key_player_actionBarTitle));
    editText.setHintTextColor(Theme.getColor(Theme.key_player_time));
    editText.setCursorColor(Theme.getColor(Theme.key_player_actionBarTitle));

    if (!AndroidUtilities.isTablet()) {
        actionBar.showActionModeTop();
        actionBar.setActionModeTopColor(Theme.getColor(Theme.key_player_actionBarTop));
    }
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                dismiss();
            } else {
                onSubItemClick(id);
            }
        }
    });

    shadow = new View(context);
    shadow.setAlpha(0.0f);
    shadow.setBackgroundResource(R.drawable.header_shadow);

    shadow2 = new View(context);
    shadow2.setAlpha(0.0f);
    shadow2.setBackgroundResource(R.drawable.header_shadow);

    playerLayout = new FrameLayout(context);
    playerLayout.setBackgroundColor(Theme.getColor(Theme.key_player_background));

    placeholderImageView = new BackupImageView(context) {

        private RectF rect = new RectF();

        @Override
        protected void onDraw(Canvas canvas) {
            if (hasNoCover == 1 || hasNoCover == 2
                    && (!getImageReceiver().hasBitmapImage() || getImageReceiver().getCurrentAlpha() != 1.0f)) {
                rect.set(0, 0, getMeasuredWidth(), getMeasuredHeight());
                canvas.drawRoundRect(rect, getRoundRadius(), getRoundRadius(), paint);
                float plusScale = thumbMaxScale / getScaleX() / 3;
                int s = (int) (AndroidUtilities.dp(63)
                        * Math.max(plusScale / thumbMaxScale, 1.0f / thumbMaxScale));
                int x = (int) (rect.centerX() - s / 2);
                int y = (int) (rect.centerY() - s / 2);
                noCoverDrawable.setBounds(x, y, x + s, y + s);
                noCoverDrawable.draw(canvas);
            }
            if (hasNoCover != 1) {
                super.onDraw(canvas);
            }
        }
    };
    placeholderImageView.setRoundRadius(AndroidUtilities.dp(20));
    placeholderImageView.setPivotX(0);
    placeholderImageView.setPivotY(0);
    placeholderImageView.setOnClickListener(view -> {
        if (animatorSet != null) {
            animatorSet.cancel();
            animatorSet = null;
        }
        animatorSet = new AnimatorSet();
        if (scrollOffsetY <= actionBar.getMeasuredHeight()) {
            animatorSet.playTogether(ObjectAnimator.ofFloat(AudioPlayerAlert.this, "fullAnimationProgress",
                    isInFullMode ? 0.0f : 1.0f));
        } else {
            animatorSet.playTogether(
                    ObjectAnimator.ofFloat(AudioPlayerAlert.this, "fullAnimationProgress",
                            isInFullMode ? 0.0f : 1.0f),
                    ObjectAnimator.ofFloat(actionBar, "alpha", isInFullMode ? 0.0f : 1.0f),
                    ObjectAnimator.ofFloat(shadow, "alpha", isInFullMode ? 0.0f : 1.0f),
                    ObjectAnimator.ofFloat(shadow2, "alpha", isInFullMode ? 0.0f : 1.0f));
        }

        animatorSet.setInterpolator(new DecelerateInterpolator());
        animatorSet.setDuration(250);
        animatorSet.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if (animation.equals(animatorSet)) {
                    if (!isInFullMode) {
                        listView.setScrollEnabled(true);
                        if (hasOptions) {
                            menuItem.setVisibility(View.INVISIBLE);
                        }
                        searchItem.setVisibility(View.VISIBLE);
                    } else {
                        if (hasOptions) {
                            menuItem.setVisibility(View.VISIBLE);
                        }
                        searchItem.setVisibility(View.INVISIBLE);
                    }
                    animatorSet = null;
                }
            }
        });
        animatorSet.start();
        if (hasOptions) {
            menuItem.setVisibility(View.VISIBLE);
        }
        searchItem.setVisibility(View.VISIBLE);
        isInFullMode = !isInFullMode;
        listView.setScrollEnabled(false);
        if (isInFullMode) {
            shuffleButton.setAdditionalOffset(-AndroidUtilities.dp(20 + 48));
        } else {
            shuffleButton.setAdditionalOffset(-AndroidUtilities.dp(10));
        }
    });

    titleTextView = new TextView(context);
    titleTextView.setTextColor(Theme.getColor(Theme.key_player_actionBarTitle));
    titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
    titleTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    titleTextView.setEllipsize(TextUtils.TruncateAt.END);
    titleTextView.setSingleLine(true);
    playerLayout.addView(titleTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 72, 18, 60, 0));

    authorTextView = new TextView(context);
    authorTextView.setTextColor(Theme.getColor(Theme.key_player_time));
    authorTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    authorTextView.setEllipsize(TextUtils.TruncateAt.END);
    authorTextView.setSingleLine(true);
    playerLayout.addView(authorTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 72, 40, 60, 0));

    optionsButton = new ActionBarMenuItem(context, null, 0, Theme.getColor(Theme.key_player_actionBarItems));
    optionsButton.setLongClickEnabled(false);
    optionsButton.setIcon(R.drawable.ic_ab_other);
    optionsButton.setAdditionalOffset(-AndroidUtilities.dp(120));
    playerLayout.addView(optionsButton,
            LayoutHelper.createFrame(40, 40, Gravity.TOP | Gravity.RIGHT, 0, 19, 10, 0));
    optionsButton.addSubItem(1, LocaleController.getString("Forward", R.string.Forward));
    optionsButton.addSubItem(2, LocaleController.getString("ShareFile", R.string.ShareFile));
    //optionsButton.addSubItem(3, LocaleController.getString("Delete", R.string.Delete));
    optionsButton.addSubItem(4, LocaleController.getString("ShowInChat", R.string.ShowInChat));
    optionsButton.setOnClickListener(v -> optionsButton.toggleSubMenu());
    optionsButton.setDelegate(this::onSubItemClick);

    seekBarView = new SeekBarView(context);
    seekBarView.setDelegate(progress -> MediaController.getInstance()
            .seekToProgress(MediaController.getInstance().getPlayingMessageObject(), progress));
    playerLayout.addView(seekBarView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 30, Gravity.TOP | Gravity.LEFT, 8, 62, 8, 0));

    progressView = new LineProgressView(context);
    progressView.setVisibility(View.INVISIBLE);
    progressView.setBackgroundColor(Theme.getColor(Theme.key_player_progressBackground));
    progressView.setProgressColor(Theme.getColor(Theme.key_player_progress));
    playerLayout.addView(progressView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 2, Gravity.TOP | Gravity.LEFT, 20, 78, 20, 0));

    timeTextView = new SimpleTextView(context);
    timeTextView.setTextSize(12);
    timeTextView.setText("0:00");
    timeTextView.setTextColor(Theme.getColor(Theme.key_player_time));
    playerLayout.addView(timeTextView,
            LayoutHelper.createFrame(100, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 20, 92, 0, 0));

    durationTextView = new TextView(context);
    durationTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
    durationTextView.setTextColor(Theme.getColor(Theme.key_player_time));
    durationTextView.setGravity(Gravity.CENTER);
    playerLayout.addView(durationTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT,
            LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.RIGHT, 0, 90, 20, 0));

    FrameLayout bottomView = new FrameLayout(context) {
        @Override
        protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
            int dist = ((right - left) - AndroidUtilities.dp(8 + 48 * 5)) / 4;
            for (int a = 0; a < 5; a++) {
                int l = AndroidUtilities.dp(4 + 48 * a) + dist * a;
                int t = AndroidUtilities.dp(9);
                buttons[a].layout(l, t, l + buttons[a].getMeasuredWidth(), t + buttons[a].getMeasuredHeight());
            }
        }
    };
    playerLayout.addView(bottomView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 66, Gravity.TOP | Gravity.LEFT, 0, 106, 0, 0));

    buttons[0] = shuffleButton = new ActionBarMenuItem(context, null, 0, 0);
    shuffleButton.setLongClickEnabled(false);
    shuffleButton.setAdditionalOffset(-AndroidUtilities.dp(10));
    bottomView.addView(shuffleButton, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP));
    shuffleButton.setOnClickListener(v -> shuffleButton.toggleSubMenu());

    TextView textView = shuffleButton.addSubItem(1,
            LocaleController.getString("ReverseOrder", R.string.ReverseOrder));
    textView.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(16), 0);
    playOrderButtons[0] = context.getResources().getDrawable(R.drawable.music_reverse).mutate();
    textView.setCompoundDrawablePadding(AndroidUtilities.dp(8));
    textView.setCompoundDrawablesWithIntrinsicBounds(playOrderButtons[0], null, null, null);

    textView = shuffleButton.addSubItem(2, LocaleController.getString("Shuffle", R.string.Shuffle));
    textView.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(16), 0);
    playOrderButtons[1] = context.getResources().getDrawable(R.drawable.pl_shuffle).mutate();
    textView.setCompoundDrawablePadding(AndroidUtilities.dp(8));
    textView.setCompoundDrawablesWithIntrinsicBounds(playOrderButtons[1], null, null, null);

    shuffleButton.setDelegate(id -> {
        MediaController.getInstance().toggleShuffleMusic(id);
        updateShuffleButton();
        listAdapter.notifyDataSetChanged();
    });

    ImageView prevButton;
    buttons[1] = prevButton = new ImageView(context);
    prevButton.setScaleType(ImageView.ScaleType.CENTER);
    prevButton.setImageDrawable(Theme.createSimpleSelectorDrawable(context, R.drawable.pl_previous,
            Theme.getColor(Theme.key_player_button), Theme.getColor(Theme.key_player_buttonActive)));
    bottomView.addView(prevButton, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP));
    prevButton.setOnClickListener(v -> MediaController.getInstance().playPreviousMessage());

    buttons[2] = playButton = new ImageView(context);
    playButton.setScaleType(ImageView.ScaleType.CENTER);
    playButton.setImageDrawable(Theme.createSimpleSelectorDrawable(context, R.drawable.pl_play,
            Theme.getColor(Theme.key_player_button), Theme.getColor(Theme.key_player_buttonActive)));
    bottomView.addView(playButton, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP));
    playButton.setOnClickListener(v -> {
        if (MediaController.getInstance().isDownloadingCurrentMessage()) {
            return;
        }
        if (MediaController.getInstance().isMessagePaused()) {
            MediaController.getInstance().playMessage(MediaController.getInstance().getPlayingMessageObject());
        } else {
            MediaController.getInstance().pauseMessage(MediaController.getInstance().getPlayingMessageObject());
        }
    });

    ImageView nextButton;
    buttons[3] = nextButton = new ImageView(context);
    nextButton.setScaleType(ImageView.ScaleType.CENTER);
    nextButton.setImageDrawable(Theme.createSimpleSelectorDrawable(context, R.drawable.pl_next,
            Theme.getColor(Theme.key_player_button), Theme.getColor(Theme.key_player_buttonActive)));
    bottomView.addView(nextButton, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP));
    nextButton.setOnClickListener(v -> MediaController.getInstance().playNextMessage());

    buttons[4] = repeatButton = new ImageView(context);
    repeatButton.setScaleType(ImageView.ScaleType.CENTER);
    repeatButton.setPadding(0, 0, AndroidUtilities.dp(8), 0);
    bottomView.addView(repeatButton, LayoutHelper.createFrame(50, 48, Gravity.LEFT | Gravity.TOP));
    repeatButton.setOnClickListener(v -> {
        SharedConfig.toggleRepeatMode();
        updateRepeatButton();
    });

    listView = new RecyclerListView(context) {

        boolean ignoreLayout;

        @Override
        protected void onLayout(boolean changed, int l, int t, int r, int b) {
            super.onLayout(changed, l, t, r, b);

            if (searchOpenPosition != -1 && !actionBar.isSearchFieldVisible()) {
                ignoreLayout = true;
                layoutManager.scrollToPositionWithOffset(searchOpenPosition, searchOpenOffset);
                super.onLayout(false, l, t, r, b);
                ignoreLayout = false;
                searchOpenPosition = -1;
            } else if (scrollToSong) {
                scrollToSong = false;
                boolean found = false;
                MessageObject playingMessageObject = MediaController.getInstance().getPlayingMessageObject();
                if (playingMessageObject != null) {
                    int count = listView.getChildCount();
                    for (int a = 0; a < count; a++) {
                        View child = listView.getChildAt(a);
                        if (child instanceof AudioPlayerCell) {
                            if (((AudioPlayerCell) child).getMessageObject() == playingMessageObject) {
                                if (child.getBottom() <= getMeasuredHeight()) {
                                    found = true;
                                }
                                break;
                            }
                        }
                    }
                    if (!found) {
                        int idx = playlist.indexOf(playingMessageObject);
                        if (idx >= 0) {
                            ignoreLayout = true;
                            if (SharedConfig.playOrderReversed) {
                                layoutManager.scrollToPosition(idx);
                            } else {
                                layoutManager.scrollToPosition(playlist.size() - idx);
                            }
                            super.onLayout(false, l, t, r, b);
                            ignoreLayout = false;
                        }
                    }
                }
            }
        }

        @Override
        public void requestLayout() {
            if (ignoreLayout) {
                return;
            }
            super.requestLayout();
        }

        @Override
        protected boolean allowSelectChildAtPosition(float x, float y) {
            float p = playerLayout.getY() + playerLayout.getMeasuredHeight();
            return playerLayout == null || y > playerLayout.getY() + playerLayout.getMeasuredHeight();
        }

        @Override
        public boolean drawChild(Canvas canvas, View child, long drawingTime) {
            canvas.save();
            canvas.clipRect(0,
                    (actionBar != null ? actionBar.getMeasuredHeight() : 0) + AndroidUtilities.dp(50),
                    getMeasuredWidth(), getMeasuredHeight());
            boolean result = super.drawChild(canvas, child, drawingTime);
            canvas.restore();
            return result;
        }
    };
    listView.setPadding(0, 0, 0, AndroidUtilities.dp(8));
    listView.setClipToPadding(false);
    listView.setLayoutManager(
            layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
    listView.setHorizontalScrollBarEnabled(false);
    listView.setVerticalScrollBarEnabled(false);
    containerView.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));
    listView.setAdapter(listAdapter = new ListAdapter(context));
    listView.setGlowColor(Theme.getColor(Theme.key_dialogScrollGlow));
    listView.setOnItemClickListener((view, position) -> {
        if (view instanceof AudioPlayerCell) {
            ((AudioPlayerCell) view).didPressedButton();
        }
    });
    listView.setOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            if (newState == RecyclerView.SCROLL_STATE_DRAGGING && searching && searchWas) {
                AndroidUtilities.hideKeyboard(getCurrentFocus());
            }
        }

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            updateLayout();
        }
    });

    playlist = MediaController.getInstance().getPlaylist();
    listAdapter.notifyDataSetChanged();

    containerView.addView(playerLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 178));
    containerView.addView(shadow2, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3));
    containerView.addView(placeholderImageView,
            LayoutHelper.createFrame(40, 40, Gravity.TOP | Gravity.LEFT, 17, 19, 0, 0));
    containerView.addView(shadow, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3));
    containerView.addView(actionBar);

    updateTitle(false);
    updateRepeatButton();
    updateShuffleButton();
}

From source file:com.keylesspalace.tusky.ComposeActivity.java

private void addMediaToQueue(@Nullable String id, QueuedMedia.Type type, Bitmap preview, Uri uri,
        long mediaSize, QueuedMedia.ReadyStage readyStage, @Nullable String description) {
    final QueuedMedia item = new QueuedMedia(type, uri, new ProgressImageView(this), mediaSize, description);
    item.id = id;//w  ww .  j  a v  a 2s.c om
    item.readyStage = readyStage;
    ImageView view = item.preview;
    Resources resources = getResources();
    int margin = resources.getDimensionPixelSize(R.dimen.compose_media_preview_margin);
    int marginBottom = resources.getDimensionPixelSize(R.dimen.compose_media_preview_margin_bottom);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(thumbnailViewSize,
            thumbnailViewSize);
    layoutParams.setMargins(margin, 0, margin, marginBottom);
    view.setLayoutParams(layoutParams);
    view.setScaleType(ImageView.ScaleType.CENTER_CROP);
    view.setImageBitmap(preview);
    view.setOnClickListener(v -> onMediaClick(item, v));
    view.setContentDescription(getString(R.string.action_delete));
    mediaPreviewBar.addView(view);
    mediaQueued.add(item);
    int queuedCount = mediaQueued.size();
    if (queuedCount == 1) {
        // If there's one video in the queue it is full, so disable the button to queue more.
        if (item.type == QueuedMedia.Type.VIDEO) {
            enableButton(pickButton, false, false);
        }
    } else if (queuedCount >= Status.MAX_MEDIA_ATTACHMENTS) {
        // Limit the total media attachments, also.
        enableButton(pickButton, false, false);
    }

    updateHideMediaToggle();

    if (item.readyStage != QueuedMedia.ReadyStage.UPLOADED) {
        waitForMediaLatch.countUp();

        try {
            if (type == QueuedMedia.Type.IMAGE && (mediaSize > STATUS_MEDIA_SIZE_LIMIT || MediaUtils
                    .getImageSquarePixels(getContentResolver(), item.uri) > STATUS_MEDIA_PIXEL_SIZE_LIMIT)) {
                downsizeMedia(item);
            } else {
                uploadMedia(item);
            }
        } catch (FileNotFoundException e) {
            onUploadFailure(item, false);
        }
    }
}

From source file:org.telegram.ui.Components.ChatAttachAlert.java

@TargetApi(16)
public void showCamera() {
    if (cameraView == null) {
        cameraView = new CameraView(baseFragment.getParentActivity());
        container.addView(cameraView, 1, LayoutHelper.createFrame(80, 80));
        cameraView.setDelegate(new CameraView.CameraViewDelegate() {
            @Override//from ww w . j a va2 s .  c  om
            public void onCameraInit() {
                int count = attachPhotoRecyclerView.getChildCount();
                for (int a = 0; a < count; a++) {
                    View child = attachPhotoRecyclerView.getChildAt(a);
                    if (child instanceof PhotoAttachCameraCell) {
                        child.setVisibility(View.INVISIBLE);
                        break;
                    }
                }

                String current = cameraView.getCameraSession().getCurrentFlashMode();
                String next = cameraView.getCameraSession().getNextFlashMode();
                if (current.equals(next)) {
                    for (int a = 0; a < 2; a++) {
                        flashModeButton[a].setVisibility(View.INVISIBLE);
                        flashModeButton[a].setAlpha(0.0f);
                        flashModeButton[a].setTranslationY(0.0f);
                    }
                } else {
                    setCameraFlashModeIcon(flashModeButton[0],
                            cameraView.getCameraSession().getCurrentFlashMode());
                    for (int a = 0; a < 2; a++) {
                        flashModeButton[a].setVisibility(a == 0 ? View.VISIBLE : View.INVISIBLE);
                        flashModeButton[a].setAlpha(a == 0 && cameraOpened ? 1.0f : 0.0f);
                        flashModeButton[a].setTranslationY(0.0f);
                    }
                }
                switchCameraButton.setImageResource(
                        cameraView.isFrontface() ? R.drawable.camera_revert1 : R.drawable.camera_revert2);
                switchCameraButton
                        .setVisibility(cameraView.hasFrontFaceCamera() ? View.VISIBLE : View.INVISIBLE);
            }
        });

        cameraIcon = new FrameLayout(baseFragment.getParentActivity());
        container.addView(cameraIcon, 2, LayoutHelper.createFrame(80, 80));

        ImageView cameraImageView = new ImageView(baseFragment.getParentActivity());
        cameraImageView.setScaleType(ImageView.ScaleType.CENTER);
        cameraImageView.setImageResource(R.drawable.instant_camera);
        cameraIcon.addView(cameraImageView, LayoutHelper.createFrame(80, 80, Gravity.RIGHT | Gravity.BOTTOM));
    }
    cameraView.setTranslationX(cameraViewLocation[0]);
    cameraView.setTranslationY(cameraViewLocation[1]);
    cameraIcon.setTranslationX(cameraViewLocation[0]);
    cameraIcon.setTranslationY(cameraViewLocation[1]);
}