Example usage for android.widget ImageView ImageView

List of usage examples for android.widget ImageView ImageView

Introduction

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

Prototype

public ImageView(Context context) 

Source Link

Usage

From source file:cl.gisred.android.InspActivity.java

private void abrirEsquema(View view) {
    ImageView image = new ImageView(this);
    image.setImageResource(R.drawable.esquema_conexion);

    AlertDialog.Builder builder = new AlertDialog.Builder(this)
            .setPositiveButton("CERRAR", new DialogInterface.OnClickListener() {
                @Override//from  w w  w .j a  va 2  s  .  c  o  m
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            }).setView(image);

    builder.create().show();
}

From source file:com.amaze.filemanager.activities.MainActivity.java

public void bbar(final Main main) {
    final String text = main.CURRENT_PATH;
    try {/*w  ww  . j  a  va2  s.c  o m*/
        buttons.removeAllViews();
        buttons.setMinimumHeight(pathbar.getHeight());
        Drawable arrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_holo_dark);
        Bundle b = utils.getPaths(text, this);
        ArrayList<String> names = b.getStringArrayList("names");
        ArrayList<String> rnames = new ArrayList<String>();

        for (int i = names.size() - 1; i >= 0; i--) {
            rnames.add(names.get(i));
        }

        ArrayList<String> paths = b.getStringArrayList("paths");
        final ArrayList<String> rpaths = new ArrayList<String>();

        for (int i = paths.size() - 1; i >= 0; i--) {
            rpaths.add(paths.get(i));
        }
        View view = new View(this);
        LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(toolbar.getContentInsetLeft(),
                LinearLayout.LayoutParams.WRAP_CONTENT);
        view.setLayoutParams(params1);
        buttons.addView(view);
        for (int i = 0; i < names.size(); i++) {
            final int k = i;
            ImageView v = new ImageView(this);
            v.setImageDrawable(arrow);
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            params.gravity = Gravity.CENTER_VERTICAL;
            v.setLayoutParams(params);
            final int index = i;
            if (rpaths.get(i).equals("/")) {
                ImageButton ib = new ImageButton(this);
                ib.setImageDrawable(icons.getRootDrawable());
                ib.setBackgroundColor(Color.parseColor("#00ffffff"));
                ib.setOnClickListener(new View.OnClickListener() {

                    public void onClick(View p1) {
                        main.loadlist(("/"), false, main.openMode);
                        timer.cancel();
                        timer.start();
                    }
                });
                ib.setLayoutParams(params);
                buttons.addView(ib);
                if (names.size() - i != 1)
                    buttons.addView(v);
            } else if (isStorage(rpaths.get(i))) {
                ImageButton ib = new ImageButton(this);
                ib.setImageDrawable(icons.getSdDrawable());
                ib.setBackgroundColor(Color.parseColor("#00ffffff"));
                ib.setOnClickListener(new View.OnClickListener() {

                    public void onClick(View p1) {
                        main.loadlist((rpaths.get(k)), false, main.openMode);
                        timer.cancel();
                        timer.start();
                    }
                });
                ib.setLayoutParams(params);
                buttons.addView(ib);
                if (names.size() - i != 1)
                    buttons.addView(v);
            } else {
                Button button = new Button(this);
                button.setText(rnames.get(index));
                button.setTextColor(getResources().getColor(android.R.color.white));
                button.setTextSize(13);
                button.setLayoutParams(params);
                button.setBackgroundResource(0);
                button.setOnClickListener(new Button.OnClickListener() {

                    public void onClick(View p1) {
                        main.loadlist((rpaths.get(k)), false, main.openMode);
                        main.loadlist((rpaths.get(k)), false, main.openMode);
                        timer.cancel();
                        timer.start();
                    }
                });
                button.setOnLongClickListener(new View.OnLongClickListener() {
                    @Override
                    public boolean onLongClick(View view) {

                        File file1 = new File(rpaths.get(index));
                        copyToClipboard(MainActivity.this, file1.getPath());
                        Toast.makeText(MainActivity.this, getResources().getString(R.string.pathcopied),
                                Toast.LENGTH_SHORT).show();
                        return false;
                    }
                });

                buttons.addView(button);
                if (names.size() - i != 1)
                    buttons.addView(v);
            }
        }

        scroll.post(new Runnable() {
            @Override
            public void run() {
                sendScroll(scroll);
                sendScroll(scroll1);
            }
        });

        if (buttons.getVisibility() == View.VISIBLE) {
            timer.cancel();
            timer.start();
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("button view not available");
    }
}

From source file:de.ub0r.android.websms.WebSMS.java

/**
 * Create a Emoticons {@link Dialog}.//from  w w w  . ja  v a2s.c  o  m
 *
 * @return Emoticons {@link Dialog}
 */
private Dialog createEmoticonsDialog() {
    final Dialog d = new Dialog(this);
    d.setTitle(R.string.emo_);
    d.setContentView(R.layout.emo);
    d.setCancelable(true);
    final String[] emoticons = this.getResources().getStringArray(R.array.emoticons);
    final GridView gridview = (GridView) d.findViewById(R.id.gridview);
    gridview.setAdapter(new BaseAdapter() {
        // references to our images
        // keep order and count synced with string-array!
        private Integer[] mThumbIds = { R.drawable.emo_im_angel, R.drawable.emo_im_cool,
                R.drawable.emo_im_crying, R.drawable.emo_im_foot_in_mouth, R.drawable.emo_im_happy,
                R.drawable.emo_im_kissing, R.drawable.emo_im_laughing, R.drawable.emo_im_lips_are_sealed,
                R.drawable.emo_im_money_mouth, R.drawable.emo_im_sad, R.drawable.emo_im_surprised,
                R.drawable.emo_im_tongue_sticking_out, R.drawable.emo_im_undecided, R.drawable.emo_im_winking,
                R.drawable.emo_im_wtf, R.drawable.emo_im_yelling };

        @Override
        public long getItemId(final int position) {
            return 0;
        }

        @Override
        public Object getItem(final int position) {
            return null;
        }

        @Override
        public int getCount() {
            return this.mThumbIds.length;
        }

        @Override
        public View getView(final int position, final View convertView, final ViewGroup parent) {
            ImageView imageView;
            if (convertView == null) { // if it's not recycled,
                // initialize some attributes
                imageView = new ImageView(WebSMS.this);
                imageView.setLayoutParams(new GridView.LayoutParams(EMOTICONS_SIZE, EMOTICONS_SIZE));
                imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                imageView.setPadding(EMOTICONS_PADDING, EMOTICONS_PADDING, EMOTICONS_PADDING,
                        EMOTICONS_PADDING);
            } else {
                imageView = (ImageView) convertView;
            }

            imageView.setImageResource(this.mThumbIds[position]);
            return imageView;
        }
    });
    gridview.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(final AdapterView<?> adapter, final View v, final int id, final long arg3) {
            EditText et = WebSMS.this.etText;
            final String e = emoticons[id];
            int i = et.getSelectionStart();
            int j = et.getSelectionEnd();
            if (i > j) {
                int x = i;
                i = j;
                j = x;
            }
            String t = et.getText().toString();
            et.setText(t.substring(0, i) + e + t.substring(j));
            et.setSelection(i + e.length());
            d.dismiss();
            et.requestFocus();
        }
    });
    return d;
}

From source file:com.filemanager.free.activities.MainActivity.java

public void bbar(final Main main) {
    final String text = main.CURRENT_PATH;
    try {//from  www .  j  a v a  2s  .  c  o  m
        buttons.removeAllViews();
        buttons.setMinimumHeight(pathbar.getHeight());
        Drawable arrow = ContextCompat.getDrawable(con, R.drawable.abc_ic_ab_back_holo_dark);
        Bundle b = utils.getPaths(text, this);
        ArrayList<String> names = b.getStringArrayList("names");
        ArrayList<String> rnames = new ArrayList<String>();

        assert names != null;
        for (int i = names.size() - 1; i >= 0; i--) {
            rnames.add(names.get(i));
        }

        ArrayList<String> paths = b.getStringArrayList("paths");
        final ArrayList<String> rpaths = new ArrayList<String>();

        assert paths != null;
        for (int i = paths.size() - 1; i >= 0; i--) {
            rpaths.add(paths.get(i));
        }
        View view = new View(this);
        LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(toolbar.getContentInsetLeft(),
                LinearLayout.LayoutParams.WRAP_CONTENT);
        view.setLayoutParams(params1);
        buttons.addView(view);
        for (int i = 0; i < names.size(); i++) {
            final int k = i;
            ImageView v = new ImageView(this);
            v.setImageDrawable(arrow);
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            params.gravity = Gravity.CENTER_VERTICAL;
            v.setLayoutParams(params);
            final int index = i;
            if (rpaths.get(i).equals("/")) {
                ImageButton ib = new ImageButton(this);
                ib.setImageDrawable(icons.getRootDrawable());
                ib.setBackgroundColor(Color.parseColor("#00ffffff"));
                ib.setOnClickListener(new View.OnClickListener() {

                    public void onClick(View p1) {
                        main.loadlist(("/"), false, main.openMode);
                        timer.cancel();
                        timer.start();
                    }
                });
                ib.setLayoutParams(params);
                buttons.addView(ib);
                if (names.size() - i != 1)
                    buttons.addView(v);
            } else if (isStorage(rpaths.get(i))) {
                ImageButton ib = new ImageButton(this);
                ib.setImageDrawable(icons.getSdDrawable());
                ib.setBackgroundColor(Color.parseColor("#00ffffff"));
                ib.setOnClickListener(new View.OnClickListener() {

                    public void onClick(View p1) {
                        main.loadlist((rpaths.get(k)), false, main.openMode);
                        timer.cancel();
                        timer.start();
                    }
                });
                ib.setLayoutParams(params);
                buttons.addView(ib);
                if (names.size() - i != 1)
                    buttons.addView(v);
            } else {
                Button button = new Button(this);
                button.setText(rnames.get(index));
                button.setTextColor(ContextCompat.getColor(con, android.R.color.white));
                button.setTextSize(13);
                button.setLayoutParams(params);
                button.setBackgroundResource(0);
                button.setOnClickListener(new Button.OnClickListener() {

                    public void onClick(View p1) {
                        main.loadlist((rpaths.get(k)), false, main.openMode);
                        main.loadlist((rpaths.get(k)), false, main.openMode);
                        timer.cancel();
                        timer.start();
                    }
                });
                button.setOnLongClickListener(new View.OnLongClickListener() {
                    @Override
                    public boolean onLongClick(View view) {
                        File file1 = new File(rpaths.get(index));
                        copyToClipboard(MainActivity.this, file1.getPath());
                        Toast.makeText(MainActivity.this, getResources().getString(R.string.pathcopied),
                                Toast.LENGTH_SHORT).show();
                        return false;
                    }
                });

                buttons.addView(button);
                if (names.size() - i != 1)
                    buttons.addView(v);
            }
        }

        scroll.post(new Runnable() {
            @Override
            public void run() {
                sendScroll(scroll);
                sendScroll(scroll1);
            }
        });

        if (buttons.getVisibility() == View.VISIBLE) {
            timer.cancel();
            timer.start();
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("button view not available");
    }
}

From source file:net.bluehack.ui.PhotoViewer.java

public void setParentActivity(final Activity activity) {
    if (parentActivity == activity) {
        return;//  ww w .java  2s  .c  o  m
    }
    parentActivity = activity;
    actvityContext = new ContextThemeWrapper(parentActivity, R.style.Theme_TMessages);

    if (progressDrawables == null) {
        progressDrawables = new Drawable[4];
        progressDrawables[0] = parentActivity.getResources().getDrawable(R.drawable.circle_big);
        progressDrawables[1] = parentActivity.getResources().getDrawable(R.drawable.cancel_big);
        progressDrawables[2] = parentActivity.getResources().getDrawable(R.drawable.load_big);
        progressDrawables[3] = parentActivity.getResources().getDrawable(R.drawable.play_big);
    }

    scroller = new Scroller(activity);

    windowView = new FrameLayout(activity) {

        private Runnable attachRunnable;

        @Override
        public boolean onInterceptTouchEvent(MotionEvent ev) {
            return isVisible && super.onInterceptTouchEvent(ev);
        }

        @Override
        public boolean onTouchEvent(MotionEvent event) {
            return isVisible && PhotoViewer.this.onTouchEvent(event);
        }

        @Override
        protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
            boolean result = super.drawChild(canvas, child, drawingTime);
            if (Build.VERSION.SDK_INT >= 21 && child == animatingImageView && lastInsets != null) {
                WindowInsets insets = (WindowInsets) lastInsets;
                canvas.drawRect(0, getMeasuredHeight(), getMeasuredWidth(),
                        getMeasuredHeight() + insets.getSystemWindowInsetBottom(), blackPaint);
            }
            return result;
        }

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            int widthSize = MeasureSpec.getSize(widthMeasureSpec);
            int heightSize = MeasureSpec.getSize(heightMeasureSpec);
            if (Build.VERSION.SDK_INT >= 21 && lastInsets != null) {
                WindowInsets insets = (WindowInsets) lastInsets;
                if (AndroidUtilities.incorrectDisplaySizeFix) {
                    if (heightSize > AndroidUtilities.displaySize.y) {
                        heightSize = AndroidUtilities.displaySize.y;
                    }
                    heightSize += AndroidUtilities.statusBarHeight;
                }
                heightSize -= insets.getSystemWindowInsetBottom();
                widthSize -= insets.getSystemWindowInsetRight();
            } else {
                if (heightSize > AndroidUtilities.displaySize.y) {
                    heightSize = AndroidUtilities.displaySize.y;
                }
            }
            setMeasuredDimension(widthSize, heightSize);
            ViewGroup.LayoutParams layoutParams = animatingImageView.getLayoutParams();
            animatingImageView.measure(MeasureSpec.makeMeasureSpec(layoutParams.width, MeasureSpec.AT_MOST),
                    MeasureSpec.makeMeasureSpec(layoutParams.height, MeasureSpec.AT_MOST));
            containerView.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY),
                    MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY));
        }

        @SuppressWarnings("DrawAllocation")
        @Override
        protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
            animatingImageView.layout(0, 0, animatingImageView.getMeasuredWidth(),
                    animatingImageView.getMeasuredHeight());
            containerView.layout(0, 0, containerView.getMeasuredWidth(), containerView.getMeasuredHeight());
            wasLayout = true;
            if (changed) {
                if (!dontResetZoomOnFirstLayout) {
                    scale = 1;
                    translationX = 0;
                    translationY = 0;
                    updateMinMax(scale);
                }

                if (checkImageView != null) {
                    checkImageView.post(new Runnable() {
                        @Override
                        public void run() {
                            FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) checkImageView
                                    .getLayoutParams();
                            WindowManager manager = (WindowManager) ApplicationLoader.applicationContext
                                    .getSystemService(Activity.WINDOW_SERVICE);
                            int rotation = manager.getDefaultDisplay().getRotation();
                            layoutParams.topMargin = AndroidUtilities
                                    .dp(rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90 ? 58
                                            : 68)
                                    + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0);
                            checkImageView.setLayoutParams(layoutParams);
                        }
                    });
                }
            }
            if (dontResetZoomOnFirstLayout) {
                setScaleToFill();
                dontResetZoomOnFirstLayout = false;
            }
        }

        @Override
        protected void onAttachedToWindow() {
            super.onAttachedToWindow();
            attachedToWindow = true;
        }

        @Override
        protected void onDetachedFromWindow() {
            super.onDetachedFromWindow();
            attachedToWindow = false;
            wasLayout = false;
        }

        @Override
        public boolean dispatchKeyEventPreIme(KeyEvent event) {
            if (event != null && event.getKeyCode() == KeyEvent.KEYCODE_BACK
                    && event.getAction() == KeyEvent.ACTION_UP) {
                if (captionEditText.isPopupShowing() || captionEditText.isKeyboardVisible()) {
                    closeCaptionEnter(false);
                    return false;
                }
                PhotoViewer.getInstance().closePhoto(true, false);
                return true;
            }
            return super.dispatchKeyEventPreIme(event);
        }

        @Override
        public ActionMode startActionModeForChild(View originalView, ActionMode.Callback callback, int type) {
            if (Build.VERSION.SDK_INT >= 23) {
                View view = parentActivity.findViewById(android.R.id.content);
                if (view instanceof ViewGroup) {
                    try {
                        return ((ViewGroup) view).startActionModeForChild(originalView, callback, type);
                    } catch (Throwable e) {
                        FileLog.e("tmessages", e);
                    }
                }
            }
            return super.startActionModeForChild(originalView, callback, type);
        }
    };
    windowView.setBackgroundDrawable(backgroundDrawable);
    windowView.setClipChildren(true);
    windowView.setFocusable(false);

    animatingImageView = new ClippingImageView(activity);
    animatingImageView.setAnimationValues(animationValues);
    windowView.addView(animatingImageView, LayoutHelper.createFrame(40, 40));

    containerView = new FrameLayoutDrawer(activity);
    containerView.setFocusable(false);
    windowView.addView(containerView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));
    if (Build.VERSION.SDK_INT >= 21) {
        //containerView.setFitsSystemWindows(true);
        containerView.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
            @SuppressLint("NewApi")
            @Override
            public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
                lastInsets = insets;
                windowView.requestLayout();
                return insets.consumeSystemWindowInsets();
            }
        });
        //containerView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);*/
    }

    windowLayoutParams = new WindowManager.LayoutParams();
    windowLayoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
    windowLayoutParams.format = PixelFormat.TRANSLUCENT;
    windowLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
    windowLayoutParams.gravity = Gravity.TOP | Gravity.LEFT;
    windowLayoutParams.type = WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
    if (Build.VERSION.SDK_INT >= 21) {
        windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
                | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
    } else {
        windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
    }

    actionBar = new ActionBar(activity);
    actionBar.setBackgroundColor(Theme.ACTION_BAR_PHOTO_VIEWER_COLOR);
    actionBar.setOccupyStatusBar(Build.VERSION.SDK_INT >= 21);
    actionBar.setItemsBackgroundColor(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR);
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setTitle(LocaleController.formatString("Of", R.string.Of, 1, 1));
    containerView.addView(actionBar,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                if (needCaptionLayout
                        && (captionEditText.isPopupShowing() || captionEditText.isKeyboardVisible())) {
                    closeCaptionEnter(false);
                    return;
                }
                closePhoto(true, false);
            } else if (id == gallery_menu_save) {
                if (Build.VERSION.SDK_INT >= 23 && parentActivity.checkSelfPermission(
                        Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                    parentActivity
                            .requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 4);
                    return;
                }

                File f = null;
                if (currentMessageObject != null) {
                    f = FileLoader.getPathToMessage(currentMessageObject.messageOwner);
                } else if (currentFileLocation != null) {
                    f = FileLoader.getPathToAttach(currentFileLocation, avatarsDialogId != 0);
                }

                if (f != null && f.exists()) {
                    MediaController.saveFile(f.toString(), parentActivity,
                            currentMessageObject != null && currentMessageObject.isVideo() ? 1 : 0, null, null);
                } else {
                    AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
                    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
                    builder.setMessage(LocaleController.getString("PleaseDownload", R.string.PleaseDownload));
                    showAlertDialog(builder);
                }
            } else if (id == gallery_menu_showall) {
                if (opennedFromMedia) {
                    closePhoto(true, false);
                } else if (currentDialogId != 0) {
                    disableShowCheck = true;
                    Bundle args2 = new Bundle();
                    args2.putLong("dialog_id", currentDialogId);
                    MediaActivity mediaActivity = new MediaActivity(args2);
                    if (parentChatActivity != null) {
                        mediaActivity.setChatInfo(parentChatActivity.getCurrentChatInfo());
                    }
                    closePhoto(false, false);
                    ((LaunchActivity) parentActivity).presentFragment(mediaActivity, false, true);
                }
            } else if (id == gallery_menu_send) {
                /*Intent intent = new Intent(this, MessagesActivity.class);
                intent.putExtra("onlySelect", true);
                startActivityForResult(intent, 10);
                if (requestCode == 10) {
                int chatId = data.getIntExtra("chatId", 0);
                int userId = data.getIntExtra("userId", 0);
                int dialog_id = 0;
                if (chatId != 0) {
                    dialog_id = -chatId;
                } else if (userId != 0) {
                    dialog_id = userId;
                }
                TLRPC.FileLocation location = getCurrentFile();
                if (dialog_id != 0 && location != null) {
                    Intent intent = new Intent(GalleryImageViewer.this, ChatActivity.class);
                    if (chatId != 0) {
                        intent.putExtra("chatId", chatId);
                    } else {
                        intent.putExtra("userId", userId);
                    }
                    startActivity(intent);
                    NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats);
                    finish();
                    if (withoutBottom) {
                        MessagesController.getInstance().sendMessage(location, dialog_id);
                    } else {
                        int item = mViewPager.getCurrentItem();
                        MessageObject obj = localPagerAdapter.imagesArr.get(item);
                        MessagesController.getInstance().sendMessage(obj, dialog_id);
                    }
                }
                }*/
            } else if (id == gallery_menu_delete) {
                if (parentActivity == null) {
                    return;
                }
                AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
                if (currentMessageObject != null && currentMessageObject.isVideo()) {
                    builder.setMessage(LocaleController.formatString("AreYouSureDeleteVideo",
                            R.string.AreYouSureDeleteVideo));
                } else if (currentMessageObject != null && currentMessageObject.isGif()) {
                    builder.setMessage(LocaleController.formatString("AreYouSure", R.string.AreYouSure));
                } else {
                    builder.setMessage(LocaleController.formatString("AreYouSureDeletePhoto",
                            R.string.AreYouSureDeletePhoto));
                }
                builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                builder.setPositiveButton(LocaleController.getString("OK", R.string.OK),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                if (!imagesArr.isEmpty()) {
                                    if (currentIndex < 0 || currentIndex >= imagesArr.size()) {
                                        return;
                                    }
                                    MessageObject obj = imagesArr.get(currentIndex);
                                    if (obj.isSent()) {
                                        closePhoto(false, false);
                                        ArrayList<Integer> arr = new ArrayList<>();
                                        arr.add(obj.getId());

                                        ArrayList<Long> random_ids = null;
                                        TLRPC.EncryptedChat encryptedChat = null;
                                        if ((int) obj.getDialogId() == 0 && obj.messageOwner.random_id != 0) {
                                            random_ids = new ArrayList<>();
                                            random_ids.add(obj.messageOwner.random_id);
                                            encryptedChat = MessagesController.getInstance()
                                                    .getEncryptedChat((int) (obj.getDialogId() >> 32));
                                        }

                                        MessagesController.getInstance().deleteMessages(arr, random_ids,
                                                encryptedChat, obj.messageOwner.to_id.channel_id);
                                    }
                                } else if (!avatarsArr.isEmpty()) {
                                    if (currentIndex < 0 || currentIndex >= avatarsArr.size()) {
                                        return;
                                    }
                                    TLRPC.Photo photo = avatarsArr.get(currentIndex);
                                    TLRPC.FileLocation currentLocation = imagesArrLocations.get(currentIndex);
                                    if (photo instanceof TLRPC.TL_photoEmpty) {
                                        photo = null;
                                    }
                                    boolean current = false;
                                    if (currentUserAvatarLocation != null) {
                                        if (photo != null) {
                                            for (TLRPC.PhotoSize size : photo.sizes) {
                                                if (size.location.local_id == currentUserAvatarLocation.local_id
                                                        && size.location.volume_id == currentUserAvatarLocation.volume_id) {
                                                    current = true;
                                                    break;
                                                }
                                            }
                                        } else if (currentLocation.local_id == currentUserAvatarLocation.local_id
                                                && currentLocation.volume_id == currentUserAvatarLocation.volume_id) {
                                            current = true;
                                        }
                                    }
                                    if (current) {
                                        MessagesController.getInstance().deleteUserPhoto(null);
                                        closePhoto(false, false);
                                    } else if (photo != null) {
                                        TLRPC.TL_inputPhoto inputPhoto = new TLRPC.TL_inputPhoto();
                                        inputPhoto.id = photo.id;
                                        inputPhoto.access_hash = photo.access_hash;
                                        MessagesController.getInstance().deleteUserPhoto(inputPhoto);
                                        MessagesStorage.getInstance().clearUserPhoto(avatarsDialogId, photo.id);
                                        imagesArrLocations.remove(currentIndex);
                                        imagesArrLocationsSizes.remove(currentIndex);
                                        avatarsArr.remove(currentIndex);
                                        if (imagesArrLocations.isEmpty()) {
                                            closePhoto(false, false);
                                        } else {
                                            int index = currentIndex;
                                            if (index >= avatarsArr.size()) {
                                                index = avatarsArr.size() - 1;
                                            }
                                            currentIndex = -1;
                                            setImageIndex(index, true);
                                        }
                                    }
                                }
                            }
                        });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                showAlertDialog(builder);
            } else if (id == gallery_menu_caption_done) {
                closeCaptionEnter(true);
            } else if (id == gallery_menu_share) {
                onSharePressed();
            } else if (id == gallery_menu_openin) {
                try {
                    AndroidUtilities.openForView(currentMessageObject, parentActivity);
                    closePhoto(false, false);
                } catch (Exception e) {
                    FileLog.e("tmessages", e);
                }
            } else if (id == gallery_menu_mute) {
                muteVideo = !muteVideo;
                if (videoPlayer != null) {
                    videoPlayer.setMute(muteVideo);
                }
                if (muteVideo) {
                    actionBar.setTitle(LocaleController.getString("AttachGif", R.string.AttachGif));
                    muteItem.setIcon(R.drawable.volume_off);
                } else {
                    actionBar.setTitle(LocaleController.getString("AttachVideo", R.string.AttachVideo));
                    muteItem.setIcon(R.drawable.volume_on);
                }
            } else if (id == gallery_menu_masks) {
                if (parentActivity == null || currentMessageObject == null
                        || currentMessageObject.messageOwner.media == null
                        || currentMessageObject.messageOwner.media.photo == null) {
                    return;
                }
                StickersAlert stickersAlert = new StickersAlert(parentActivity,
                        currentMessageObject.messageOwner.media.photo);
                stickersAlert.show();
            }
        }

        @Override
        public boolean canOpenMenu() {
            if (currentMessageObject != null) {
                File f = FileLoader.getPathToMessage(currentMessageObject.messageOwner);
                if (f.exists()) {
                    return true;
                }
            } else if (currentFileLocation != null) {
                File f = FileLoader.getPathToAttach(currentFileLocation, avatarsDialogId != 0);
                if (f.exists()) {
                    return true;
                }
            }
            return false;
        }
    });

    ActionBarMenu menu = actionBar.createMenu();

    masksItem = menu.addItem(gallery_menu_masks, R.drawable.ic_masks_msk1);
    muteItem = menu.addItem(gallery_menu_mute, R.drawable.volume_on);

    menuItem = menu.addItem(0, R.drawable.ic_ab_other);
    menuItem.addSubItem(gallery_menu_openin,
            LocaleController.getString("OpenInExternalApp", R.string.OpenInExternalApp), 0);
    menuItem.addSubItem(gallery_menu_showall, LocaleController.getString("ShowAllMedia", R.string.ShowAllMedia),
            0);
    menuItem.addSubItem(gallery_menu_share, LocaleController.getString("ShareFile", R.string.ShareFile), 0);
    menuItem.addSubItem(gallery_menu_save, LocaleController.getString("SaveToGallery", R.string.SaveToGallery),
            0);
    menuItem.addSubItem(gallery_menu_delete, LocaleController.getString("Delete", R.string.Delete), 0);

    captionDoneItem = menu.addItemWithWidth(gallery_menu_caption_done, R.drawable.ic_done,
            AndroidUtilities.dp(56));

    bottomLayout = new FrameLayout(actvityContext);
    bottomLayout.setBackgroundColor(0x7f000000);
    containerView.addView(bottomLayout,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.BOTTOM | Gravity.LEFT));

    captionTextViewOld = new TextView(actvityContext);
    captionTextViewOld.setMaxLines(10);
    captionTextViewOld.setBackgroundColor(0x7f000000);
    captionTextViewOld.setPadding(AndroidUtilities.dp(20), AndroidUtilities.dp(8), AndroidUtilities.dp(20),
            AndroidUtilities.dp(8));
    captionTextViewOld.setLinkTextColor(0xffffffff);
    captionTextViewOld.setTextColor(0xffffffff);
    captionTextViewOld.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
    captionTextViewOld.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    captionTextViewOld.setVisibility(View.INVISIBLE);
    containerView.addView(captionTextViewOld, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | Gravity.LEFT, 0, 0, 0, 48));
    captionTextViewOld.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (cropItem.getVisibility() == View.VISIBLE) {
                openCaptionEnter();
            }
        }
    });

    captionTextView = captionTextViewNew = new TextView(actvityContext);
    captionTextViewNew.setMaxLines(10);
    captionTextViewNew.setBackgroundColor(0x7f000000);
    captionTextViewNew.setPadding(AndroidUtilities.dp(20), AndroidUtilities.dp(8), AndroidUtilities.dp(20),
            AndroidUtilities.dp(8));
    captionTextViewNew.setLinkTextColor(0xffffffff);
    captionTextViewNew.setTextColor(0xffffffff);
    captionTextViewNew.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
    captionTextViewNew.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    captionTextViewNew.setVisibility(View.INVISIBLE);
    containerView.addView(captionTextViewNew, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | Gravity.LEFT, 0, 0, 0, 48));
    captionTextViewNew.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (cropItem.getVisibility() == View.VISIBLE) {
                openCaptionEnter();
            }
        }
    });

    radialProgressViews[0] = new RadialProgressView(containerView.getContext(), containerView);
    radialProgressViews[0].setBackgroundState(0, false);
    radialProgressViews[1] = new RadialProgressView(containerView.getContext(), containerView);
    radialProgressViews[1].setBackgroundState(0, false);
    radialProgressViews[2] = new RadialProgressView(containerView.getContext(), containerView);
    radialProgressViews[2].setBackgroundState(0, false);

    shareButton = new ImageView(containerView.getContext());
    shareButton.setImageResource(R.drawable.share);
    shareButton.setScaleType(ImageView.ScaleType.CENTER);
    shareButton.setBackgroundDrawable(Theme.createBarSelectorDrawable(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR));
    bottomLayout.addView(shareButton,
            LayoutHelper.createFrame(50, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.RIGHT));
    shareButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onSharePressed();
        }
    });

    nameTextView = new TextView(containerView.getContext());
    nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    nameTextView.setSingleLine(true);
    nameTextView.setMaxLines(1);
    nameTextView.setEllipsize(TextUtils.TruncateAt.END);
    nameTextView.setTextColor(0xffffffff);
    nameTextView.setGravity(Gravity.LEFT);
    bottomLayout.addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 16, 5, 60, 0));

    dateTextView = new TextView(containerView.getContext());
    dateTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
    dateTextView.setSingleLine(true);
    dateTextView.setMaxLines(1);
    dateTextView.setEllipsize(TextUtils.TruncateAt.END);
    dateTextView.setTextColor(0xffffffff);
    dateTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    dateTextView.setGravity(Gravity.LEFT);
    bottomLayout.addView(dateTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 16, 25, 50, 0));

    if (Build.VERSION.SDK_INT >= 16) {
        videoPlayerSeekbar = new SeekBar(containerView.getContext());
        videoPlayerSeekbar.setColors(0x66ffffff, 0xffffffff, 0xffffffff);
        videoPlayerSeekbar.setDelegate(new SeekBar.SeekBarDelegate() {
            @Override
            public void onSeekBarDrag(float progress) {
                if (videoPlayer != null) {
                    videoPlayer.getPlayerControl().seekTo((int) (progress * videoPlayer.getDuration()));
                }
            }
        });

        videoPlayerControlFrameLayout = new FrameLayout(containerView.getContext()) {

            @Override
            public boolean onTouchEvent(MotionEvent event) {
                int x = (int) event.getX();
                int y = (int) event.getY();
                if (videoPlayerSeekbar.onTouch(event.getAction(), event.getX() - AndroidUtilities.dp(48),
                        event.getY())) {
                    getParent().requestDisallowInterceptTouchEvent(true);
                    invalidate();
                    return true;
                }
                return super.onTouchEvent(event);
            }

            @Override
            protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
                super.onMeasure(widthMeasureSpec, heightMeasureSpec);
                long duration;
                if (videoPlayer != null) {
                    duration = videoPlayer.getDuration();
                    if (duration == ExoPlayer.UNKNOWN_TIME) {
                        duration = 0;
                    }
                } else {
                    duration = 0;
                }
                duration /= 1000;
                int size = (int) Math
                        .ceil(videoPlayerTime.getPaint().measureText(String.format("%02d:%02d / %02d:%02d",
                                duration / 60, duration % 60, duration / 60, duration % 60)));
                videoPlayerSeekbar.setSize(getMeasuredWidth() - AndroidUtilities.dp(48 + 16) - size,
                        getMeasuredHeight());
            }

            @Override
            protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
                super.onLayout(changed, left, top, right, bottom);
                float progress = 0;
                if (videoPlayer != null) {
                    PlayerControl playerControl = videoPlayer.getPlayerControl();
                    progress = playerControl.getCurrentPosition() / (float) playerControl.getDuration();
                }
                videoPlayerSeekbar.setProgress(progress);
            }

            @Override
            protected void onDraw(Canvas canvas) {
                canvas.save();
                canvas.translate(AndroidUtilities.dp(48), 0);
                videoPlayerSeekbar.draw(canvas);
                canvas.restore();
            }
        };
        videoPlayerControlFrameLayout.setWillNotDraw(false);
        bottomLayout.addView(videoPlayerControlFrameLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
                LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));

        videoPlayButton = new ImageView(containerView.getContext());
        videoPlayButton.setScaleType(ImageView.ScaleType.CENTER);
        videoPlayerControlFrameLayout.addView(videoPlayButton,
                LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP));
        videoPlayButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (videoPlayer != null) {
                    if (isPlaying) {
                        videoPlayer.getPlayerControl().pause();
                    } else {
                        videoPlayer.getPlayerControl().start();
                    }
                }
            }
        });

        videoPlayerTime = new TextView(containerView.getContext());
        videoPlayerTime.setTextColor(0xffffffff);
        videoPlayerTime.setGravity(Gravity.CENTER_VERTICAL);
        videoPlayerTime.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
        videoPlayerControlFrameLayout.addView(videoPlayerTime, LayoutHelper.createFrame(
                LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.RIGHT | Gravity.TOP, 0, 0, 8, 0));
    }

    pickerView = new PickerBottomLayoutViewer(actvityContext);
    pickerView.setBackgroundColor(0x7f000000);
    containerView.addView(pickerView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.BOTTOM | Gravity.LEFT));
    pickerView.cancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (placeProvider instanceof EmptyPhotoViewerProvider) {
                closePhoto(false, false);
            } else if (placeProvider != null) {
                closePhoto(!placeProvider.cancelButtonPressed(), false);
            }
        }
    });
    pickerView.doneButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (placeProvider != null) {
                placeProvider.sendButtonPressed(currentIndex);
                closePhoto(false, false);
            }
        }
    });

    LinearLayout itemsLayout = new LinearLayout(parentActivity);
    itemsLayout.setOrientation(LinearLayout.HORIZONTAL);
    pickerView.addView(itemsLayout,
            LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 48, Gravity.TOP | Gravity.CENTER_HORIZONTAL));

    tuneItem = new ImageView(parentActivity);
    tuneItem.setScaleType(ImageView.ScaleType.CENTER);
    tuneItem.setImageResource(R.drawable.photo_tools);
    tuneItem.setBackgroundDrawable(Theme.createBarSelectorDrawable(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR));
    itemsLayout.addView(tuneItem, LayoutHelper.createLinear(56, 48));
    tuneItem.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switchToEditMode(2);
        }
    });

    paintItem = new ImageView(parentActivity);
    paintItem.setScaleType(ImageView.ScaleType.CENTER);
    paintItem.setImageResource(R.drawable.photo_paint);
    paintItem.setBackgroundDrawable(Theme.createBarSelectorDrawable(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR));
    itemsLayout.addView(paintItem, LayoutHelper.createLinear(56, 48));
    paintItem.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switchToEditMode(3);
        }
    });

    cropItem = new ImageView(parentActivity);
    cropItem.setScaleType(ImageView.ScaleType.CENTER);
    cropItem.setImageResource(R.drawable.photo_crop);
    cropItem.setBackgroundDrawable(Theme.createBarSelectorDrawable(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR));
    itemsLayout.addView(cropItem, LayoutHelper.createLinear(56, 48));
    cropItem.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switchToEditMode(1);
        }
    });

    editorDoneLayout = new PickerBottomLayoutViewer(actvityContext);
    editorDoneLayout.setBackgroundColor(0x7f000000);
    editorDoneLayout.updateSelectedCount(0, false);
    editorDoneLayout.setVisibility(View.GONE);
    containerView.addView(editorDoneLayout,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.BOTTOM));
    editorDoneLayout.cancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (currentEditMode == 1) {
                photoCropView.cancelAnimationRunnable();
            }
            switchToEditMode(0);
        }
    });
    editorDoneLayout.doneButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (currentEditMode == 1) {
                photoCropView.cancelAnimationRunnable();
                if (imageMoveAnimation != null) {
                    return;
                }
            }
            applyCurrentEditMode();
            switchToEditMode(0);
        }
    });

    ImageView rotateButton = new ImageView(actvityContext);
    rotateButton.setScaleType(ImageView.ScaleType.CENTER);
    rotateButton.setImageResource(R.drawable.tool_rotate);
    rotateButton.setBackgroundDrawable(Theme.createBarSelectorDrawable(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR));
    editorDoneLayout.addView(rotateButton, LayoutHelper.createFrame(48, 48, Gravity.CENTER));
    rotateButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            centerImage.setOrientation(centerImage.getOrientation() - 90, false);
            photoCropView.setOrientation(centerImage.getOrientation());
            containerView.invalidate();
        }
    });

    gestureDetector = new GestureDetector(containerView.getContext(), this);
    gestureDetector.setOnDoubleTapListener(this);

    ImageReceiver.ImageReceiverDelegate imageReceiverDelegate = new ImageReceiver.ImageReceiverDelegate() {
        @Override
        public void didSetImage(ImageReceiver imageReceiver, boolean set, boolean thumb) {
            if (imageReceiver == centerImage && set && placeProvider != null && placeProvider.scaleToFill()) {
                if (!wasLayout) {
                    dontResetZoomOnFirstLayout = true;
                } else {
                    setScaleToFill();
                }
            }
        }
    };

    centerImage.setParentView(containerView);
    centerImage.setCrossfadeAlpha((byte) 2);
    centerImage.setInvalidateAll(true);
    centerImage.setDelegate(imageReceiverDelegate);
    leftImage.setParentView(containerView);
    leftImage.setCrossfadeAlpha((byte) 2);
    leftImage.setInvalidateAll(true);
    leftImage.setDelegate(imageReceiverDelegate);
    rightImage.setParentView(containerView);
    rightImage.setCrossfadeAlpha((byte) 2);
    rightImage.setInvalidateAll(true);
    rightImage.setDelegate(imageReceiverDelegate);

    WindowManager manager = (WindowManager) ApplicationLoader.applicationContext
            .getSystemService(Activity.WINDOW_SERVICE);
    int rotation = manager.getDefaultDisplay().getRotation();

    checkImageView = new CheckBox(containerView.getContext(), R.drawable.selectphoto_large);
    checkImageView.setDrawBackground(true);
    checkImageView.setSize(45);
    checkImageView.setCheckOffset(AndroidUtilities.dp(1));
    checkImageView.setColor(0xff3ccaef);
    checkImageView.setVisibility(View.GONE);
    containerView.addView(checkImageView, LayoutHelper.createFrame(45, 45, Gravity.RIGHT | Gravity.TOP, 0,
            rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90 ? 58 : 68, 10, 0));
    if (Build.VERSION.SDK_INT >= 21) {
        ((FrameLayout.LayoutParams) checkImageView
                .getLayoutParams()).topMargin += AndroidUtilities.statusBarHeight;
    }
    checkImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (placeProvider != null) {
                placeProvider.setPhotoChecked(currentIndex);
                checkImageView.setChecked(placeProvider.isPhotoChecked(currentIndex), true);
                updateSelectedCount();
            }
        }
    });

    captionEditText = new PhotoViewerCaptionEnterView(actvityContext, containerView, windowView);
    captionEditText.setDelegate(new PhotoViewerCaptionEnterView.PhotoViewerCaptionEnterViewDelegate() {
        @Override
        public void onCaptionEnter() {
            closeCaptionEnter(true);
        }

        @Override
        public void onTextChanged(CharSequence text) {
            if (mentionsAdapter != null && captionEditText != null && parentChatActivity != null
                    && text != null) {
                mentionsAdapter.searchUsernameOrHashtag(text.toString(), captionEditText.getCursorPosition(),
                        parentChatActivity.messages);
            }
        }

        @Override
        public void onWindowSizeChanged(int size) {
            int height = AndroidUtilities.dp(36 * Math.min(3, mentionsAdapter.getItemCount())
                    + (mentionsAdapter.getItemCount() > 3 ? 18 : 0));
            if (size - ActionBar.getCurrentActionBarHeight() * 2 < height) {
                allowMentions = false;
                if (mentionListView != null && mentionListView.getVisibility() == View.VISIBLE) {
                    mentionListView.setVisibility(View.INVISIBLE);
                }
            } else {
                allowMentions = true;
                if (mentionListView != null && mentionListView.getVisibility() == View.INVISIBLE) {
                    mentionListView.setVisibility(View.VISIBLE);
                }
            }
        }
    });
    containerView.addView(captionEditText, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | Gravity.LEFT, 0, 0, 0, -400));

    mentionListView = new RecyclerListView(actvityContext);
    mentionListView.setTag(5);
    mentionLayoutManager = new LinearLayoutManager(actvityContext) {
        @Override
        public boolean supportsPredictiveItemAnimations() {
            return false;
        }
    };
    mentionLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    mentionListView.setLayoutManager(mentionLayoutManager);
    mentionListView.setBackgroundColor(0x7f000000);
    mentionListView.setVisibility(View.GONE);
    mentionListView.setClipToPadding(true);
    mentionListView.setOverScrollMode(ListView.OVER_SCROLL_NEVER);
    containerView.addView(mentionListView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 110, Gravity.LEFT | Gravity.BOTTOM));

    mentionListView.setAdapter(mentionsAdapter = new MentionsAdapter(actvityContext, true, 0,
            new MentionsAdapter.MentionsAdapterDelegate() {
                @Override
                public void needChangePanelVisibility(boolean show) {
                    if (show) {
                        FrameLayout.LayoutParams layoutParams3 = (FrameLayout.LayoutParams) mentionListView
                                .getLayoutParams();
                        int height = 36 * Math.min(3, mentionsAdapter.getItemCount())
                                + (mentionsAdapter.getItemCount() > 3 ? 18 : 0);
                        layoutParams3.height = AndroidUtilities.dp(height);
                        layoutParams3.topMargin = -AndroidUtilities.dp(height);
                        mentionListView.setLayoutParams(layoutParams3);

                        if (mentionListAnimation != null) {
                            mentionListAnimation.cancel();
                            mentionListAnimation = null;
                        }

                        if (mentionListView.getVisibility() == View.VISIBLE) {
                            mentionListView.setAlpha(1.0f);
                            return;
                        } else {
                            mentionLayoutManager.scrollToPositionWithOffset(0, 10000);
                        }
                        if (allowMentions) {
                            mentionListView.setVisibility(View.VISIBLE);
                            mentionListAnimation = new AnimatorSet();
                            mentionListAnimation
                                    .playTogether(ObjectAnimator.ofFloat(mentionListView, "alpha", 0.0f, 1.0f));
                            mentionListAnimation.addListener(new AnimatorListenerAdapterProxy() {
                                @Override
                                public void onAnimationEnd(Animator animation) {
                                    if (mentionListAnimation != null
                                            && mentionListAnimation.equals(animation)) {
                                        mentionListAnimation = null;
                                    }
                                }
                            });
                            mentionListAnimation.setDuration(200);
                            mentionListAnimation.start();
                        } else {
                            mentionListView.setAlpha(1.0f);
                            mentionListView.setVisibility(View.INVISIBLE);
                        }
                    } else {
                        if (mentionListAnimation != null) {
                            mentionListAnimation.cancel();
                            mentionListAnimation = null;
                        }

                        if (mentionListView.getVisibility() == View.GONE) {
                            return;
                        }
                        if (allowMentions) {
                            mentionListAnimation = new AnimatorSet();
                            mentionListAnimation
                                    .playTogether(ObjectAnimator.ofFloat(mentionListView, "alpha", 0.0f));
                            mentionListAnimation.addListener(new AnimatorListenerAdapterProxy() {
                                @Override
                                public void onAnimationEnd(Animator animation) {
                                    if (mentionListAnimation != null
                                            && mentionListAnimation.equals(animation)) {
                                        mentionListView.setVisibility(View.GONE);
                                        mentionListAnimation = null;
                                    }
                                }
                            });
                            mentionListAnimation.setDuration(200);
                            mentionListAnimation.start();
                        } else {
                            mentionListView.setVisibility(View.GONE);
                        }
                    }
                }

                @Override
                public void onContextSearch(boolean searching) {

                }

                @Override
                public void onContextClick(TLRPC.BotInlineResult result) {

                }
            }));
    mentionsAdapter.setAllowNewMentions(false);

    mentionListView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() {
        @Override
        public void onItemClick(View view, int position) {
            Object object = mentionsAdapter.getItem(position);
            int start = mentionsAdapter.getResultStartPosition();
            int len = mentionsAdapter.getResultLength();
            if (object instanceof TLRPC.User) {
                TLRPC.User user = (TLRPC.User) object;
                if (user != null) {
                    captionEditText.replaceWithText(start, len, "@" + user.username + " ");
                }
            } else if (object instanceof String) {
                captionEditText.replaceWithText(start, len, object + " ");
            }
        }
    });

    mentionListView.setOnItemLongClickListener(new RecyclerListView.OnItemLongClickListener() {
        @Override
        public boolean onItemClick(View view, int position) {
            Object object = mentionsAdapter.getItem(position);
            if (object instanceof String) {
                AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
                builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                builder.setMessage(LocaleController.getString("ClearSearch", R.string.ClearSearch));
                builder.setPositiveButton(
                        LocaleController.getString("ClearButton", R.string.ClearButton).toUpperCase(),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                mentionsAdapter.clearRecentHashtags();
                            }
                        });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                showAlertDialog(builder);
                return true;
            }
            return false;
        }
    });
}

From source file:com.lifehackinnovations.siteaudit.FloorPlanActivity.java

public void getscaledialog() {

    ImageView googlemaps = new ImageView(this);
    googlemaps.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    googlemaps.setPadding(25, 25, 25, 25);
    googlemaps.setImageResource(R.drawable.google_maps256x256);
    googlemaps.setOnClickListener(new ImageView.OnClickListener() {
        public void onClick(View v) {

            startActivity(u.intent("Getscalefromgooglemaps"));
            getscaledialog.cancel();//  ww  w .j a v a2  s  .co  m

        }
    });

    ImageView twopoints = new ImageView(this);
    twopoints.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    twopoints.setPadding(25, 25, 25, 25);
    twopoints.setImageResource(R.drawable.pointsonmapicon);
    twopoints.setOnClickListener(new ImageView.OnClickListener() {

        public void onClick(View v) {

            ACTION = ACTION_GETSCALEFROMPOINTS;
            toptoolbar.setVisibility(View.INVISIBLE);
            righttoolbar.setVisibility(View.INVISIBLE);

            floorplantitle.setVisibility(View.VISIBLE);
            floorplantitle.setText("Please select first point");

            GETSCALESTAGE = STAGE_GETFIRSTPOINT;

            getscaledialog.cancel();

        }

    });

    LinearLayout choosepicturelocationlayout;
    choosepicturelocationlayout = new LinearLayout(this);
    choosepicturelocationlayout
            .setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    choosepicturelocationlayout.setOrientation(LinearLayout.HORIZONTAL);
    choosepicturelocationlayout.addView(googlemaps);
    choosepicturelocationlayout.addView(twopoints);
    choosepicturelocationlayout.setGravity(Gravity.CENTER_HORIZONTAL);

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Choose Method for Getting Scale")
            .setMessage("Please choose Google Maps, or Two Points on Map").setView(choosepicturelocationlayout)
            .setCancelable(false).setIcon(R.drawable.ic_launcher)

            .setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            }).setCancelable(true);

    getscaledialog = builder.create();
    getscaledialog.show();

}

From source file:kr.wdream.ui.PhotoViewer.java

public void setParentActivity(final Activity activity) {
    if (parentActivity == activity) {
        return;/*from w ww  . j  a v  a  2s .  c  om*/
    }
    parentActivity = activity;
    actvityContext = new ContextThemeWrapper(parentActivity, kr.wdream.storyshop.R.style.Theme_TMessages);

    if (progressDrawables == null) {
        progressDrawables = new Drawable[4];
        progressDrawables[0] = parentActivity.getResources()
                .getDrawable(kr.wdream.storyshop.R.drawable.circle_big);
        progressDrawables[1] = parentActivity.getResources()
                .getDrawable(kr.wdream.storyshop.R.drawable.cancel_big);
        progressDrawables[2] = parentActivity.getResources()
                .getDrawable(kr.wdream.storyshop.R.drawable.load_big);
        progressDrawables[3] = parentActivity.getResources()
                .getDrawable(kr.wdream.storyshop.R.drawable.play_big);
    }

    scroller = new Scroller(activity);

    windowView = new FrameLayout(activity) {

        private Runnable attachRunnable;

        @Override
        public boolean onInterceptTouchEvent(MotionEvent ev) {
            return isVisible && super.onInterceptTouchEvent(ev);
        }

        @Override
        public boolean onTouchEvent(MotionEvent event) {
            return isVisible && PhotoViewer.this.onTouchEvent(event);
        }

        @Override
        protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
            boolean result = super.drawChild(canvas, child, drawingTime);
            if (Build.VERSION.SDK_INT >= 21 && child == animatingImageView && lastInsets != null) {
                WindowInsets insets = (WindowInsets) lastInsets;
                canvas.drawRect(0, getMeasuredHeight(), getMeasuredWidth(),
                        getMeasuredHeight() + insets.getSystemWindowInsetBottom(), blackPaint);
            }
            return result;
        }

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            int widthSize = MeasureSpec.getSize(widthMeasureSpec);
            int heightSize = MeasureSpec.getSize(heightMeasureSpec);
            if (Build.VERSION.SDK_INT >= 21 && lastInsets != null) {
                WindowInsets insets = (WindowInsets) lastInsets;
                if (AndroidUtilities.incorrectDisplaySizeFix) {
                    if (heightSize > AndroidUtilities.displaySize.y) {
                        heightSize = AndroidUtilities.displaySize.y;
                    }
                    heightSize += AndroidUtilities.statusBarHeight;
                }
                heightSize -= insets.getSystemWindowInsetBottom();
                widthSize -= insets.getSystemWindowInsetRight();
            } else {
                if (heightSize > AndroidUtilities.displaySize.y) {
                    heightSize = AndroidUtilities.displaySize.y;
                }
            }
            setMeasuredDimension(widthSize, heightSize);
            ViewGroup.LayoutParams layoutParams = animatingImageView.getLayoutParams();
            animatingImageView.measure(MeasureSpec.makeMeasureSpec(layoutParams.width, MeasureSpec.AT_MOST),
                    MeasureSpec.makeMeasureSpec(layoutParams.height, MeasureSpec.AT_MOST));
            containerView.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY),
                    MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY));
        }

        @SuppressWarnings("DrawAllocation")
        @Override
        protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
            animatingImageView.layout(0, 0, animatingImageView.getMeasuredWidth(),
                    animatingImageView.getMeasuredHeight());
            containerView.layout(0, 0, containerView.getMeasuredWidth(), containerView.getMeasuredHeight());
            wasLayout = true;
            if (changed) {
                if (!dontResetZoomOnFirstLayout) {
                    scale = 1;
                    translationX = 0;
                    translationY = 0;
                    updateMinMax(scale);
                }

                if (checkImageView != null) {
                    checkImageView.post(new Runnable() {
                        @Override
                        public void run() {
                            FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) checkImageView
                                    .getLayoutParams();
                            WindowManager manager = (WindowManager) ApplicationLoader.applicationContext
                                    .getSystemService(Activity.WINDOW_SERVICE);
                            int rotation = manager.getDefaultDisplay().getRotation();
                            layoutParams.topMargin = AndroidUtilities
                                    .dp(rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90 ? 58
                                            : 68)
                                    + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0);
                            checkImageView.setLayoutParams(layoutParams);
                        }
                    });
                }
            }
            if (dontResetZoomOnFirstLayout) {
                setScaleToFill();
                dontResetZoomOnFirstLayout = false;
            }
        }

        @Override
        protected void onAttachedToWindow() {
            super.onAttachedToWindow();
            attachedToWindow = true;
        }

        @Override
        protected void onDetachedFromWindow() {
            super.onDetachedFromWindow();
            attachedToWindow = false;
            wasLayout = false;
        }

        @Override
        public boolean dispatchKeyEventPreIme(KeyEvent event) {
            if (event != null && event.getKeyCode() == KeyEvent.KEYCODE_BACK
                    && event.getAction() == KeyEvent.ACTION_UP) {
                if (captionEditText.isPopupShowing() || captionEditText.isKeyboardVisible()) {
                    closeCaptionEnter(false);
                    return false;
                }
                PhotoViewer.getInstance().closePhoto(true, false);
                return true;
            }
            return super.dispatchKeyEventPreIme(event);
        }

        @Override
        public ActionMode startActionModeForChild(View originalView, ActionMode.Callback callback, int type) {
            if (Build.VERSION.SDK_INT >= 23) {
                View view = parentActivity.findViewById(android.R.id.content);
                if (view instanceof ViewGroup) {
                    try {
                        return ((ViewGroup) view).startActionModeForChild(originalView, callback, type);
                    } catch (Throwable e) {
                        FileLog.e("tmessages", e);
                    }
                }
            }
            return super.startActionModeForChild(originalView, callback, type);
        }
    };
    windowView.setBackgroundDrawable(backgroundDrawable);
    windowView.setClipChildren(true);
    windowView.setFocusable(false);

    animatingImageView = new ClippingImageView(activity);
    animatingImageView.setAnimationValues(animationValues);
    windowView.addView(animatingImageView, LayoutHelper.createFrame(40, 40));

    containerView = new FrameLayoutDrawer(activity);
    containerView.setFocusable(false);
    windowView.addView(containerView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));
    if (Build.VERSION.SDK_INT >= 21) {
        //containerView.setFitsSystemWindows(true);
        containerView.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
            @SuppressLint("NewApi")
            @Override
            public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
                lastInsets = insets;
                windowView.requestLayout();
                return insets.consumeSystemWindowInsets();
            }
        });
        //containerView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);*/
    }

    windowLayoutParams = new WindowManager.LayoutParams();
    windowLayoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
    windowLayoutParams.format = PixelFormat.TRANSLUCENT;
    windowLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
    windowLayoutParams.gravity = Gravity.TOP | Gravity.LEFT;
    windowLayoutParams.type = WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
    if (Build.VERSION.SDK_INT >= 21) {
        windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
                | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
    } else {
        windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
    }

    actionBar = new ActionBar(activity);
    actionBar.setBackgroundColor(Theme.ACTION_BAR_PHOTO_VIEWER_COLOR);
    actionBar.setOccupyStatusBar(Build.VERSION.SDK_INT >= 21);
    actionBar.setItemsBackgroundColor(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR);
    actionBar.setBackButtonImage(kr.wdream.storyshop.R.drawable.ic_ab_back);
    actionBar.setTitle(LocaleController.formatString("Of", kr.wdream.storyshop.R.string.Of, 1, 1));
    containerView.addView(actionBar,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                if (needCaptionLayout
                        && (captionEditText.isPopupShowing() || captionEditText.isKeyboardVisible())) {
                    closeCaptionEnter(false);
                    return;
                }
                closePhoto(true, false);
            } else if (id == gallery_menu_save) {
                if (Build.VERSION.SDK_INT >= 23 && parentActivity.checkSelfPermission(
                        Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                    parentActivity
                            .requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 4);
                    return;
                }

                File f = null;
                if (currentMessageObject != null) {
                    f = FileLoader.getPathToMessage(currentMessageObject.messageOwner);
                } else if (currentFileLocation != null) {
                    f = FileLoader.getPathToAttach(currentFileLocation, avatarsDialogId != 0);
                }

                if (f != null && f.exists()) {
                    MediaController.saveFile(f.toString(), parentActivity,
                            currentMessageObject != null && currentMessageObject.isVideo() ? 1 : 0, null, null);
                } else {
                    AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
                    builder.setTitle(
                            LocaleController.getString("AppName", kr.wdream.storyshop.R.string.AppName));
                    builder.setPositiveButton(LocaleController.getString("OK", kr.wdream.storyshop.R.string.OK),
                            null);
                    builder.setMessage(LocaleController.getString("PleaseDownload",
                            kr.wdream.storyshop.R.string.PleaseDownload));
                    showAlertDialog(builder);
                }
            } else if (id == gallery_menu_showall) {
                if (opennedFromMedia) {
                    closePhoto(true, false);
                } else if (currentDialogId != 0) {
                    disableShowCheck = true;
                    Bundle args2 = new Bundle();
                    args2.putLong("dialog_id", currentDialogId);
                    MediaActivity mediaActivity = new MediaActivity(args2);
                    if (parentChatActivity != null) {
                        mediaActivity.setChatInfo(parentChatActivity.getCurrentChatInfo());
                    }
                    closePhoto(false, false);
                    ((LaunchActivity) parentActivity).presentFragment(mediaActivity, false, true);
                }
            } else if (id == gallery_menu_send) {
                /*Intent intent = new Intent(this, MessagesActivity.class);
                intent.putExtra("onlySelect", true);
                startActivityForResult(intent, 10);
                if (requestCode == 10) {
                int chatId = data.getIntExtra("chatId", 0);
                int userId = data.getIntExtra("userId", 0);
                int dialog_id = 0;
                if (chatId != 0) {
                    dialog_id = -chatId;
                } else if (userId != 0) {
                    dialog_id = userId;
                }
                TLRPC.FileLocation location = getCurrentFile();
                if (dialog_id != 0 && location != null) {
                    Intent intent = new Intent(GalleryImageViewer.this, ChatActivity.class);
                    if (chatId != 0) {
                        intent.putExtra("chatId", chatId);
                    } else {
                        intent.putExtra("userId", userId);
                    }
                    startActivity(intent);
                    NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats);
                    finish();
                    if (withoutBottom) {
                        MessagesController.getInstance().sendMessage(location, dialog_id);
                    } else {
                        int item = mViewPager.getCurrentItem();
                        MessageObject obj = localPagerAdapter.imagesArr.get(item);
                        MessagesController.getInstance().sendMessage(obj, dialog_id);
                    }
                }
                }*/
            } else if (id == gallery_menu_delete) {
                if (parentActivity == null) {
                    return;
                }
                AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
                if (currentMessageObject != null && currentMessageObject.isVideo()) {
                    builder.setMessage(LocaleController.formatString("AreYouSureDeleteVideo",
                            kr.wdream.storyshop.R.string.AreYouSureDeleteVideo));
                } else if (currentMessageObject != null && currentMessageObject.isGif()) {
                    builder.setMessage(LocaleController.formatString("AreYouSure",
                            kr.wdream.storyshop.R.string.AreYouSure));
                } else {
                    builder.setMessage(LocaleController.formatString("AreYouSureDeletePhoto",
                            kr.wdream.storyshop.R.string.AreYouSureDeletePhoto));
                }
                builder.setTitle(LocaleController.getString("AppName", kr.wdream.storyshop.R.string.AppName));
                builder.setPositiveButton(LocaleController.getString("OK", kr.wdream.storyshop.R.string.OK),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                if (!imagesArr.isEmpty()) {
                                    if (currentIndex < 0 || currentIndex >= imagesArr.size()) {
                                        return;
                                    }
                                    MessageObject obj = imagesArr.get(currentIndex);
                                    if (obj.isSent()) {
                                        closePhoto(false, false);
                                        ArrayList<Integer> arr = new ArrayList<>();
                                        arr.add(obj.getId());

                                        ArrayList<Long> random_ids = null;
                                        TLRPC.EncryptedChat encryptedChat = null;
                                        if ((int) obj.getDialogId() == 0 && obj.messageOwner.random_id != 0) {
                                            random_ids = new ArrayList<>();
                                            random_ids.add(obj.messageOwner.random_id);
                                            encryptedChat = MessagesController.getInstance()
                                                    .getEncryptedChat((int) (obj.getDialogId() >> 32));
                                        }

                                        MessagesController.getInstance().deleteMessages(arr, random_ids,
                                                encryptedChat, obj.messageOwner.to_id.channel_id);
                                    }
                                } else if (!avatarsArr.isEmpty()) {
                                    if (currentIndex < 0 || currentIndex >= avatarsArr.size()) {
                                        return;
                                    }
                                    TLRPC.Photo photo = avatarsArr.get(currentIndex);
                                    TLRPC.FileLocation currentLocation = imagesArrLocations.get(currentIndex);
                                    if (photo instanceof TLRPC.TL_photoEmpty) {
                                        photo = null;
                                    }
                                    boolean current = false;
                                    if (currentUserAvatarLocation != null) {
                                        if (photo != null) {
                                            for (TLRPC.PhotoSize size : photo.sizes) {
                                                if (size.location.local_id == currentUserAvatarLocation.local_id
                                                        && size.location.volume_id == currentUserAvatarLocation.volume_id) {
                                                    current = true;
                                                    break;
                                                }
                                            }
                                        } else if (currentLocation.local_id == currentUserAvatarLocation.local_id
                                                && currentLocation.volume_id == currentUserAvatarLocation.volume_id) {
                                            current = true;
                                        }
                                    }
                                    if (current) {
                                        MessagesController.getInstance().deleteUserPhoto(null);
                                        closePhoto(false, false);
                                    } else if (photo != null) {
                                        TLRPC.TL_inputPhoto inputPhoto = new TLRPC.TL_inputPhoto();
                                        inputPhoto.id = photo.id;
                                        inputPhoto.access_hash = photo.access_hash;
                                        MessagesController.getInstance().deleteUserPhoto(inputPhoto);
                                        MessagesStorage.getInstance().clearUserPhoto(avatarsDialogId, photo.id);
                                        imagesArrLocations.remove(currentIndex);
                                        imagesArrLocationsSizes.remove(currentIndex);
                                        avatarsArr.remove(currentIndex);
                                        if (imagesArrLocations.isEmpty()) {
                                            closePhoto(false, false);
                                        } else {
                                            int index = currentIndex;
                                            if (index >= avatarsArr.size()) {
                                                index = avatarsArr.size() - 1;
                                            }
                                            currentIndex = -1;
                                            setImageIndex(index, true);
                                        }
                                    }
                                }
                            }
                        });
                builder.setNegativeButton(
                        LocaleController.getString("Cancel", kr.wdream.storyshop.R.string.Cancel), null);
                showAlertDialog(builder);
            } else if (id == gallery_menu_caption_done) {
                closeCaptionEnter(true);
            } else if (id == gallery_menu_share) {
                onSharePressed();
            } else if (id == gallery_menu_openin) {
                try {
                    AndroidUtilities.openForView(currentMessageObject, parentActivity);
                    closePhoto(false, false);
                } catch (Exception e) {
                    FileLog.e("tmessages", e);
                }
            } else if (id == gallery_menu_mute) {
                muteVideo = !muteVideo;
                if (videoPlayer != null) {
                    videoPlayer.setMute(muteVideo);
                }
                if (muteVideo) {
                    actionBar.setTitle(
                            LocaleController.getString("AttachGif", kr.wdream.storyshop.R.string.AttachGif));
                    muteItem.setIcon(kr.wdream.storyshop.R.drawable.volume_off);
                } else {
                    actionBar.setTitle(LocaleController.getString("AttachVideo",
                            kr.wdream.storyshop.R.string.AttachVideo));
                    muteItem.setIcon(kr.wdream.storyshop.R.drawable.volume_on);
                }
            } else if (id == gallery_menu_masks) {
                if (parentActivity == null || currentMessageObject == null
                        || currentMessageObject.messageOwner.media == null
                        || currentMessageObject.messageOwner.media.photo == null) {
                    return;
                }
                StickersAlert stickersAlert = new StickersAlert(parentActivity,
                        currentMessageObject.messageOwner.media.photo);
                stickersAlert.show();
            }
        }

        @Override
        public boolean canOpenMenu() {
            if (currentMessageObject != null) {
                File f = FileLoader.getPathToMessage(currentMessageObject.messageOwner);
                if (f.exists()) {
                    return true;
                }
            } else if (currentFileLocation != null) {
                File f = FileLoader.getPathToAttach(currentFileLocation, avatarsDialogId != 0);
                if (f.exists()) {
                    return true;
                }
            }
            return false;
        }
    });

    ActionBarMenu menu = actionBar.createMenu();

    masksItem = menu.addItem(gallery_menu_masks, kr.wdream.storyshop.R.drawable.ic_masks_msk1);
    muteItem = menu.addItem(gallery_menu_mute, kr.wdream.storyshop.R.drawable.volume_on);

    menuItem = menu.addItem(0, kr.wdream.storyshop.R.drawable.ic_ab_other);
    menuItem.addSubItem(gallery_menu_openin,
            LocaleController.getString("OpenInExternalApp", kr.wdream.storyshop.R.string.OpenInExternalApp), 0);
    menuItem.addSubItem(gallery_menu_showall,
            LocaleController.getString("ShowAllMedia", kr.wdream.storyshop.R.string.ShowAllMedia), 0);
    menuItem.addSubItem(gallery_menu_share,
            LocaleController.getString("ShareFile", kr.wdream.storyshop.R.string.ShareFile), 0);
    menuItem.addSubItem(gallery_menu_save,
            LocaleController.getString("SaveToGallery", kr.wdream.storyshop.R.string.SaveToGallery), 0);
    menuItem.addSubItem(gallery_menu_delete,
            LocaleController.getString("Delete", kr.wdream.storyshop.R.string.Delete), 0);

    captionDoneItem = menu.addItemWithWidth(gallery_menu_caption_done, kr.wdream.storyshop.R.drawable.ic_done,
            AndroidUtilities.dp(56));

    bottomLayout = new FrameLayout(actvityContext);
    bottomLayout.setBackgroundColor(0x7f000000);
    containerView.addView(bottomLayout,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.BOTTOM | Gravity.LEFT));

    captionTextViewOld = new TextView(actvityContext);
    captionTextViewOld.setMaxLines(10);
    captionTextViewOld.setBackgroundColor(0x7f000000);
    captionTextViewOld.setPadding(AndroidUtilities.dp(20), AndroidUtilities.dp(8), AndroidUtilities.dp(20),
            AndroidUtilities.dp(8));
    captionTextViewOld.setLinkTextColor(0xffffffff);
    captionTextViewOld.setTextColor(0xffffffff);
    captionTextViewOld.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
    captionTextViewOld.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    captionTextViewOld.setVisibility(View.INVISIBLE);
    containerView.addView(captionTextViewOld, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | Gravity.LEFT, 0, 0, 0, 48));
    captionTextViewOld.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (cropItem.getVisibility() == View.VISIBLE) {
                openCaptionEnter();
            }
        }
    });

    captionTextView = captionTextViewNew = new TextView(actvityContext);
    captionTextViewNew.setMaxLines(10);
    captionTextViewNew.setBackgroundColor(0x7f000000);
    captionTextViewNew.setPadding(AndroidUtilities.dp(20), AndroidUtilities.dp(8), AndroidUtilities.dp(20),
            AndroidUtilities.dp(8));
    captionTextViewNew.setLinkTextColor(0xffffffff);
    captionTextViewNew.setTextColor(0xffffffff);
    captionTextViewNew.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
    captionTextViewNew.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    captionTextViewNew.setVisibility(View.INVISIBLE);
    containerView.addView(captionTextViewNew, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | Gravity.LEFT, 0, 0, 0, 48));
    captionTextViewNew.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (cropItem.getVisibility() == View.VISIBLE) {
                openCaptionEnter();
            }
        }
    });

    radialProgressViews[0] = new RadialProgressView(containerView.getContext(), containerView);
    radialProgressViews[0].setBackgroundState(0, false);
    radialProgressViews[1] = new RadialProgressView(containerView.getContext(), containerView);
    radialProgressViews[1].setBackgroundState(0, false);
    radialProgressViews[2] = new RadialProgressView(containerView.getContext(), containerView);
    radialProgressViews[2].setBackgroundState(0, false);

    shareButton = new ImageView(containerView.getContext());
    shareButton.setImageResource(kr.wdream.storyshop.R.drawable.share);
    shareButton.setScaleType(ImageView.ScaleType.CENTER);
    shareButton.setBackgroundDrawable(Theme.createBarSelectorDrawable(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR));
    bottomLayout.addView(shareButton,
            LayoutHelper.createFrame(50, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.RIGHT));
    shareButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onSharePressed();
        }
    });

    nameTextView = new TextView(containerView.getContext());
    nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    nameTextView.setSingleLine(true);
    nameTextView.setMaxLines(1);
    nameTextView.setEllipsize(TextUtils.TruncateAt.END);
    nameTextView.setTextColor(0xffffffff);
    nameTextView.setGravity(Gravity.LEFT);
    bottomLayout.addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 16, 5, 60, 0));

    dateTextView = new TextView(containerView.getContext());
    dateTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
    dateTextView.setSingleLine(true);
    dateTextView.setMaxLines(1);
    dateTextView.setEllipsize(TextUtils.TruncateAt.END);
    dateTextView.setTextColor(0xffffffff);
    dateTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    dateTextView.setGravity(Gravity.LEFT);
    bottomLayout.addView(dateTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 16, 25, 50, 0));

    if (Build.VERSION.SDK_INT >= 16) {
        videoPlayerSeekbar = new SeekBar(containerView.getContext());
        videoPlayerSeekbar.setColors(0x66ffffff, 0xffffffff, 0xffffffff);
        videoPlayerSeekbar.setDelegate(new SeekBar.SeekBarDelegate() {
            @Override
            public void onSeekBarDrag(float progress) {
                if (videoPlayer != null) {
                    videoPlayer.getPlayerControl().seekTo((int) (progress * videoPlayer.getDuration()));
                }
            }
        });

        videoPlayerControlFrameLayout = new FrameLayout(containerView.getContext()) {

            @Override
            public boolean onTouchEvent(MotionEvent event) {
                int x = (int) event.getX();
                int y = (int) event.getY();
                if (videoPlayerSeekbar.onTouch(event.getAction(), event.getX() - AndroidUtilities.dp(48),
                        event.getY())) {
                    getParent().requestDisallowInterceptTouchEvent(true);
                    invalidate();
                    return true;
                }
                return super.onTouchEvent(event);
            }

            @Override
            protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
                super.onMeasure(widthMeasureSpec, heightMeasureSpec);
                long duration;
                if (videoPlayer != null) {
                    duration = videoPlayer.getDuration();
                    if (duration == ExoPlayer.UNKNOWN_TIME) {
                        duration = 0;
                    }
                } else {
                    duration = 0;
                }
                duration /= 1000;
                int size = (int) Math
                        .ceil(videoPlayerTime.getPaint().measureText(String.format("%02d:%02d / %02d:%02d",
                                duration / 60, duration % 60, duration / 60, duration % 60)));
                videoPlayerSeekbar.setSize(getMeasuredWidth() - AndroidUtilities.dp(48 + 16) - size,
                        getMeasuredHeight());
            }

            @Override
            protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
                super.onLayout(changed, left, top, right, bottom);
                float progress = 0;
                if (videoPlayer != null) {
                    PlayerControl playerControl = videoPlayer.getPlayerControl();
                    progress = playerControl.getCurrentPosition() / (float) playerControl.getDuration();
                }
                videoPlayerSeekbar.setProgress(progress);
            }

            @Override
            protected void onDraw(Canvas canvas) {
                canvas.save();
                canvas.translate(AndroidUtilities.dp(48), 0);
                videoPlayerSeekbar.draw(canvas);
                canvas.restore();
            }
        };
        videoPlayerControlFrameLayout.setWillNotDraw(false);
        bottomLayout.addView(videoPlayerControlFrameLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
                LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));

        videoPlayButton = new ImageView(containerView.getContext());
        videoPlayButton.setScaleType(ImageView.ScaleType.CENTER);
        videoPlayerControlFrameLayout.addView(videoPlayButton,
                LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP));
        videoPlayButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (videoPlayer != null) {
                    if (isPlaying) {
                        videoPlayer.getPlayerControl().pause();
                    } else {
                        videoPlayer.getPlayerControl().start();
                    }
                }
            }
        });

        videoPlayerTime = new TextView(containerView.getContext());
        videoPlayerTime.setTextColor(0xffffffff);
        videoPlayerTime.setGravity(Gravity.CENTER_VERTICAL);
        videoPlayerTime.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
        videoPlayerControlFrameLayout.addView(videoPlayerTime, LayoutHelper.createFrame(
                LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.RIGHT | Gravity.TOP, 0, 0, 8, 0));
    }

    pickerView = new PickerBottomLayoutViewer(actvityContext);
    pickerView.setBackgroundColor(0x7f000000);
    containerView.addView(pickerView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.BOTTOM | Gravity.LEFT));
    pickerView.cancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (placeProvider instanceof EmptyPhotoViewerProvider) {
                closePhoto(false, false);
            } else if (placeProvider != null) {
                closePhoto(!placeProvider.cancelButtonPressed(), false);
            }
        }
    });
    pickerView.doneButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (placeProvider != null) {
                placeProvider.sendButtonPressed(currentIndex);
                closePhoto(false, false);
            }
        }
    });

    LinearLayout itemsLayout = new LinearLayout(parentActivity);
    itemsLayout.setOrientation(LinearLayout.HORIZONTAL);
    pickerView.addView(itemsLayout,
            LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 48, Gravity.TOP | Gravity.CENTER_HORIZONTAL));

    tuneItem = new ImageView(parentActivity);
    tuneItem.setScaleType(ImageView.ScaleType.CENTER);
    tuneItem.setImageResource(kr.wdream.storyshop.R.drawable.photo_tools);
    tuneItem.setBackgroundDrawable(Theme.createBarSelectorDrawable(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR));
    itemsLayout.addView(tuneItem, LayoutHelper.createLinear(56, 48));
    tuneItem.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switchToEditMode(2);
        }
    });

    paintItem = new ImageView(parentActivity);
    paintItem.setScaleType(ImageView.ScaleType.CENTER);
    paintItem.setImageResource(kr.wdream.storyshop.R.drawable.photo_paint);
    paintItem.setBackgroundDrawable(Theme.createBarSelectorDrawable(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR));
    itemsLayout.addView(paintItem, LayoutHelper.createLinear(56, 48));
    paintItem.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switchToEditMode(3);
        }
    });

    cropItem = new ImageView(parentActivity);
    cropItem.setScaleType(ImageView.ScaleType.CENTER);
    cropItem.setImageResource(kr.wdream.storyshop.R.drawable.photo_crop);
    cropItem.setBackgroundDrawable(Theme.createBarSelectorDrawable(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR));
    itemsLayout.addView(cropItem, LayoutHelper.createLinear(56, 48));
    cropItem.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switchToEditMode(1);
        }
    });

    editorDoneLayout = new PickerBottomLayoutViewer(actvityContext);
    editorDoneLayout.setBackgroundColor(0x7f000000);
    editorDoneLayout.updateSelectedCount(0, false);
    editorDoneLayout.setVisibility(View.GONE);
    containerView.addView(editorDoneLayout,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.BOTTOM));
    editorDoneLayout.cancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (currentEditMode == 1) {
                photoCropView.cancelAnimationRunnable();
            }
            switchToEditMode(0);
        }
    });
    editorDoneLayout.doneButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (currentEditMode == 1) {
                photoCropView.cancelAnimationRunnable();
                if (imageMoveAnimation != null) {
                    return;
                }
            }
            applyCurrentEditMode();
            switchToEditMode(0);
        }
    });

    ImageView rotateButton = new ImageView(actvityContext);
    rotateButton.setScaleType(ImageView.ScaleType.CENTER);
    rotateButton.setImageResource(kr.wdream.storyshop.R.drawable.tool_rotate);
    rotateButton.setBackgroundDrawable(Theme.createBarSelectorDrawable(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR));
    editorDoneLayout.addView(rotateButton, LayoutHelper.createFrame(48, 48, Gravity.CENTER));
    rotateButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            centerImage.setOrientation(centerImage.getOrientation() - 90, false);
            photoCropView.setOrientation(centerImage.getOrientation());
            containerView.invalidate();
        }
    });

    gestureDetector = new GestureDetector(containerView.getContext(), this);
    gestureDetector.setOnDoubleTapListener(this);

    ImageReceiver.ImageReceiverDelegate imageReceiverDelegate = new ImageReceiver.ImageReceiverDelegate() {
        @Override
        public void didSetImage(ImageReceiver imageReceiver, boolean set, boolean thumb) {
            if (imageReceiver == centerImage && set && placeProvider != null && placeProvider.scaleToFill()) {
                if (!wasLayout) {
                    dontResetZoomOnFirstLayout = true;
                } else {
                    setScaleToFill();
                }
            }
        }
    };

    centerImage.setParentView(containerView);
    centerImage.setCrossfadeAlpha((byte) 2);
    centerImage.setInvalidateAll(true);
    centerImage.setDelegate(imageReceiverDelegate);
    leftImage.setParentView(containerView);
    leftImage.setCrossfadeAlpha((byte) 2);
    leftImage.setInvalidateAll(true);
    leftImage.setDelegate(imageReceiverDelegate);
    rightImage.setParentView(containerView);
    rightImage.setCrossfadeAlpha((byte) 2);
    rightImage.setInvalidateAll(true);
    rightImage.setDelegate(imageReceiverDelegate);

    WindowManager manager = (WindowManager) ApplicationLoader.applicationContext
            .getSystemService(Activity.WINDOW_SERVICE);
    int rotation = manager.getDefaultDisplay().getRotation();

    checkImageView = new CheckBox(containerView.getContext(), kr.wdream.storyshop.R.drawable.selectphoto_large);
    checkImageView.setDrawBackground(true);
    checkImageView.setSize(45);
    checkImageView.setCheckOffset(AndroidUtilities.dp(1));
    checkImageView.setColor(0xff3ccaef);
    checkImageView.setVisibility(View.GONE);
    containerView.addView(checkImageView, LayoutHelper.createFrame(45, 45, Gravity.RIGHT | Gravity.TOP, 0,
            rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90 ? 58 : 68, 10, 0));
    if (Build.VERSION.SDK_INT >= 21) {
        ((FrameLayout.LayoutParams) checkImageView
                .getLayoutParams()).topMargin += AndroidUtilities.statusBarHeight;
    }
    checkImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (placeProvider != null) {
                placeProvider.setPhotoChecked(currentIndex);
                checkImageView.setChecked(placeProvider.isPhotoChecked(currentIndex), true);
                updateSelectedCount();
            }
        }
    });

    captionEditText = new PhotoViewerCaptionEnterView(actvityContext, containerView, windowView);
    captionEditText.setDelegate(new PhotoViewerCaptionEnterView.PhotoViewerCaptionEnterViewDelegate() {
        @Override
        public void onCaptionEnter() {
            closeCaptionEnter(true);
        }

        @Override
        public void onTextChanged(CharSequence text) {
            if (mentionsAdapter != null && captionEditText != null && parentChatActivity != null
                    && text != null) {
                mentionsAdapter.searchUsernameOrHashtag(text.toString(), captionEditText.getCursorPosition(),
                        parentChatActivity.messages);
            }
        }

        @Override
        public void onWindowSizeChanged(int size) {
            int height = AndroidUtilities.dp(36 * Math.min(3, mentionsAdapter.getItemCount())
                    + (mentionsAdapter.getItemCount() > 3 ? 18 : 0));
            if (size - ActionBar.getCurrentActionBarHeight() * 2 < height) {
                allowMentions = false;
                if (mentionListView != null && mentionListView.getVisibility() == View.VISIBLE) {
                    mentionListView.setVisibility(View.INVISIBLE);
                }
            } else {
                allowMentions = true;
                if (mentionListView != null && mentionListView.getVisibility() == View.INVISIBLE) {
                    mentionListView.setVisibility(View.VISIBLE);
                }
            }
        }
    });
    containerView.addView(captionEditText, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | Gravity.LEFT, 0, 0, 0, -400));

    mentionListView = new RecyclerListView(actvityContext);
    mentionListView.setTag(5);
    mentionLayoutManager = new LinearLayoutManager(actvityContext) {
        @Override
        public boolean supportsPredictiveItemAnimations() {
            return false;
        }
    };
    mentionLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    mentionListView.setLayoutManager(mentionLayoutManager);
    mentionListView.setBackgroundColor(0x7f000000);
    mentionListView.setVisibility(View.GONE);
    mentionListView.setClipToPadding(true);
    mentionListView.setOverScrollMode(ListView.OVER_SCROLL_NEVER);
    containerView.addView(mentionListView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 110, Gravity.LEFT | Gravity.BOTTOM));

    mentionListView.setAdapter(mentionsAdapter = new MentionsAdapter(actvityContext, true, 0,
            new MentionsAdapter.MentionsAdapterDelegate() {
                @Override
                public void needChangePanelVisibility(boolean show) {
                    if (show) {
                        FrameLayout.LayoutParams layoutParams3 = (FrameLayout.LayoutParams) mentionListView
                                .getLayoutParams();
                        int height = 36 * Math.min(3, mentionsAdapter.getItemCount())
                                + (mentionsAdapter.getItemCount() > 3 ? 18 : 0);
                        layoutParams3.height = AndroidUtilities.dp(height);
                        layoutParams3.topMargin = -AndroidUtilities.dp(height);
                        mentionListView.setLayoutParams(layoutParams3);

                        if (mentionListAnimation != null) {
                            mentionListAnimation.cancel();
                            mentionListAnimation = null;
                        }

                        if (mentionListView.getVisibility() == View.VISIBLE) {
                            mentionListView.setAlpha(1.0f);
                            return;
                        } else {
                            mentionLayoutManager.scrollToPositionWithOffset(0, 10000);
                        }
                        if (allowMentions) {
                            mentionListView.setVisibility(View.VISIBLE);
                            mentionListAnimation = new AnimatorSet();
                            mentionListAnimation
                                    .playTogether(ObjectAnimator.ofFloat(mentionListView, "alpha", 0.0f, 1.0f));
                            mentionListAnimation.addListener(new AnimatorListenerAdapterProxy() {
                                @Override
                                public void onAnimationEnd(Animator animation) {
                                    if (mentionListAnimation != null
                                            && mentionListAnimation.equals(animation)) {
                                        mentionListAnimation = null;
                                    }
                                }
                            });
                            mentionListAnimation.setDuration(200);
                            mentionListAnimation.start();
                        } else {
                            mentionListView.setAlpha(1.0f);
                            mentionListView.setVisibility(View.INVISIBLE);
                        }
                    } else {
                        if (mentionListAnimation != null) {
                            mentionListAnimation.cancel();
                            mentionListAnimation = null;
                        }

                        if (mentionListView.getVisibility() == View.GONE) {
                            return;
                        }
                        if (allowMentions) {
                            mentionListAnimation = new AnimatorSet();
                            mentionListAnimation
                                    .playTogether(ObjectAnimator.ofFloat(mentionListView, "alpha", 0.0f));
                            mentionListAnimation.addListener(new AnimatorListenerAdapterProxy() {
                                @Override
                                public void onAnimationEnd(Animator animation) {
                                    if (mentionListAnimation != null
                                            && mentionListAnimation.equals(animation)) {
                                        mentionListView.setVisibility(View.GONE);
                                        mentionListAnimation = null;
                                    }
                                }
                            });
                            mentionListAnimation.setDuration(200);
                            mentionListAnimation.start();
                        } else {
                            mentionListView.setVisibility(View.GONE);
                        }
                    }
                }

                @Override
                public void onContextSearch(boolean searching) {

                }

                @Override
                public void onContextClick(TLRPC.BotInlineResult result) {

                }
            }));
    mentionsAdapter.setAllowNewMentions(false);

    mentionListView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() {
        @Override
        public void onItemClick(View view, int position) {
            Object object = mentionsAdapter.getItem(position);
            int start = mentionsAdapter.getResultStartPosition();
            int len = mentionsAdapter.getResultLength();
            if (object instanceof TLRPC.User) {
                TLRPC.User user = (TLRPC.User) object;
                if (user != null) {
                    captionEditText.replaceWithText(start, len, "@" + user.username + " ");
                }
            } else if (object instanceof String) {
                captionEditText.replaceWithText(start, len, object + " ");
            }
        }
    });

    mentionListView.setOnItemLongClickListener(new RecyclerListView.OnItemLongClickListener() {
        @Override
        public boolean onItemClick(View view, int position) {
            Object object = mentionsAdapter.getItem(position);
            if (object instanceof String) {
                AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
                builder.setTitle(LocaleController.getString("AppName", kr.wdream.storyshop.R.string.AppName));
                builder.setMessage(
                        LocaleController.getString("ClearSearch", kr.wdream.storyshop.R.string.ClearSearch));
                builder.setPositiveButton(LocaleController
                        .getString("ClearButton", kr.wdream.storyshop.R.string.ClearButton).toUpperCase(),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                mentionsAdapter.clearRecentHashtags();
                            }
                        });
                builder.setNegativeButton(
                        LocaleController.getString("Cancel", kr.wdream.storyshop.R.string.Cancel), null);
                showAlertDialog(builder);
                return true;
            }
            return false;
        }
    });
}

From source file:com.google.android.apps.santatracker.rocketsleigh.RocketSleighActivity.java

private void addSpaceOrPresent(int width) {
    if (width > 0) {
        mLastObstacle = 0;/*  ww  w  .j  a  v  a2s .co m*/
        // 1/3 chance of a present.
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(width,
                LinearLayout.LayoutParams.MATCH_PARENT);
        if (mRandom.nextInt(3) == 0) {
            // Present!

            // Which one?
            Bitmap bmp = mGiftBoxes[mRandom.nextInt(mGiftBoxes.length)];
            ImageView iv = new ImageView(this);
            iv.setLayerType(View.LAYER_TYPE_HARDWARE, null);
            iv.setImageBitmap(bmp);

            // Position the present
            int left = mRandom.nextInt(width / 2) + (width / 4)
                    - ((int) ((float) bmp.getWidth() * mScaleX) / 2);
            int top = mRandom.nextInt(mScreenHeight / 2) + (mScreenHeight / 4)
                    - ((int) ((float) bmp.getHeight() * mScaleY) / 2);

            FrameLayout frame = new FrameLayout(this);
            LayoutParams flp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            frame.addView(iv, flp);
            iv.setTranslationX(left);
            iv.setTranslationY(top);

            mObstacleLayout.addView(frame, lp);
        } else {
            // Space
            View view = new View(this);
            mObstacleLayout.addView(view, lp);
        }
    }
}

From source file:com.google.android.apps.santatracker.rocketsleigh.RocketSleighActivity.java

private void addNextImages(int level, boolean recycle) {
    if (level < BACKGROUNDS.length) {
        // Add the background image
        ImageView iv = new ImageView(this);
        iv.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        // This is being background loaded.  Should already be loaded, but if not, wait.
        while (mBackgrounds[level] == null) {
            synchronized (mBackgrounds) {
                if (mBackgrounds[level] == null) {
                    try {
                        mBackgrounds.wait();
                    } catch (InterruptedException e) {
                    }/*from w  w  w  .j a  v  a 2 s  .  c o m*/
                }
            }
        }
        iv.setImageBitmap(mBackgrounds[level]);
        if (recycle) {
            iv.setTag(new Pair<Integer, Integer>(0, level));
        }
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        mBackgroundLayout.addView(iv, lp);
        iv = new ImageView(this);
        iv.setLayerType(View.LAYER_TYPE_HARDWARE, null);

        if (recycle) {
            iv.setTag(new Pair<Integer, Integer>(0, level));
        }
        iv.setImageBitmap(mBackgrounds2[level]);
        mBackgroundLayout.addView(iv, lp);

        // Add the foreground image
        if (FOREGROUNDS[level] == -1) {
            View view = new View(this);
            lp = new LinearLayout.LayoutParams(mScreenWidth * 2, 10);
            mForegroundLayout.addView(view, lp);
        } else {
            iv = new ImageView(this);
            iv.setBackgroundResource(R.drawable.img_snow_ground_tiles);
            if (recycle) {
                iv.setTag(level);
            }
            lp = new LinearLayout.LayoutParams(mScreenWidth * 2, LinearLayout.LayoutParams.WRAP_CONTENT);
            mForegroundLayout.addView(iv, lp);
            iv = new ImageView(this);
            if (recycle) {
                iv.setTag(level);
            }
            iv.setBackgroundResource(R.drawable.img_snow_ground_tiles);
            mForegroundLayout.addView(iv, lp);
        }
    }
}