Search in sources :

Example 1 with CropImageView

use of com.android.systemui.screenshot.CropImageView in project android_frameworks_base by ResurrectionRemix.

the class ScreenshotEditor method initButtons.

private void initButtons() {
    mainLayout.setSystemUiVisibility(getUiOptions());
    cropView = (CropImageView) mainLayout.findViewById(R.id.image);
    cropView.setFrameColor(getResources().getColor(R.color.crop_frame));
    cropView.setHandleColor(getResources().getColor(R.color.crop_handle));
    cropView.setGuideColor(getResources().getColor(R.color.crop_guide));
    cropView.setHandleSizeInDp(15);
    cropView.setTouchPaddingInDp(10);
    cropView.setGuideShowMode(CropImageView.ShowMode.SHOW_ON_TOUCH);
    cropModeButton = (ImageButton) mainLayout.findViewById(R.id.cropMode);
    final ListPopupWindow listPopupWindowCropMode = new ListPopupWindow(mContext);
    nCropMode = preferences.getInt(KEY_WORK_MODE, 0);
    ImageArrayAdapter cropModeAdapter = new ImageArrayAdapter(mContext, new Integer[] { R.drawable.ic_image_crop_free, R.drawable.ic_image_crop_square, R.drawable.ic_image_crop_circle });
    listPopupWindowCropMode.setAdapter(cropModeAdapter);
    listPopupWindowCropMode.setAnchorView(cropModeButton);
    listPopupWindowCropMode.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            nCropMode = position;
            setCropMode();
            preferences.edit().putInt(KEY_CROP_MODE, nCropMode).apply();
            setCropMode();
            listPopupWindowCropMode.dismiss();
        }
    });
    listPopupWindowCropMode.setOnDismissListener(new PopupWindow.OnDismissListener() {

        @Override
        public void onDismiss() {
            isPopUpCropModeShowing = false;
        }
    });
    cropModeButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!isPopUpCropModeShowing) {
                listPopupWindowCropMode.show();
                isPopUpCropModeShowing = true;
            } else
                listPopupWindowCropMode.dismiss();
        }
    });
    cropModeButton.setColorFilter(nOverlayColor, PorterDuff.Mode.MULTIPLY);
    cropButton = (ImageButton) mainLayout.findViewById(R.id.doneCrop);
    cropButton.setOnClickListener(this);
    cropButton.setColorFilter(nOverlayColor, PorterDuff.Mode.MULTIPLY);
    final ImageButton recoverButton = (ImageButton) mainLayout.findViewById(R.id.recover);
    recoverButton.setOnClickListener(this);
    recoverButton.setColorFilter(nOverlayColor, PorterDuff.Mode.MULTIPLY);
    final ImageButton deleteButton = (ImageButton) mainLayout.findViewById(R.id.delete);
    deleteButton.setOnClickListener(this);
    deleteButton.setColorFilter(nOverlayColor, PorterDuff.Mode.MULTIPLY);
    final ImageButton shareButton = (ImageButton) mainLayout.findViewById(R.id.share);
    shareButton.setOnClickListener(this);
    shareButton.setColorFilter(nOverlayColor, PorterDuff.Mode.MULTIPLY);
    final ImageButton saveButton = (ImageButton) mainLayout.findViewById(R.id.save);
    saveButton.setOnClickListener(this);
    saveButton.setColorFilter(nOverlayColor, PorterDuff.Mode.MULTIPLY);
    final Integer[] colors = new Integer[] { getResources().getColor(R.color.crop_draw_color_1), getResources().getColor(R.color.crop_draw_color_2), getResources().getColor(R.color.crop_draw_color_3), getResources().getColor(R.color.crop_draw_color_4), getResources().getColor(R.color.crop_draw_color_5), getResources().getColor(R.color.crop_draw_color_6), getResources().getColor(R.color.crop_draw_color_7), getResources().getColor(R.color.crop_draw_color_8) };
    final BitmapFactory.Options opt = new BitmapFactory.Options();
    opt.inJustDecodeBounds = true;
    BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_image_edit, opt);
    float scale = getResources().getDisplayMetrics().density;
    final ListPopupWindow listPopupWindowColorPicker = new ListPopupWindow(mContext);
    listPopupWindowColorPicker.setAdapter(new ColorArrayAdapter(mContext, colors));
    int width = mContext.getResources().getDimensionPixelSize(R.dimen.crop_buttons);
    final ImageButton drawColorButton = (ImageButton) mainLayout.findViewById(R.id.drawColor);
    listPopupWindowColorPicker.setAnchorView(drawColorButton);
    drawColor = preferences.getInt(KEY_DRAW_COLOR, getResources().getColor(R.color.crop_draw_color_1));
    cropView.setDrawColor(drawColor);
    drawColorButton.setImageDrawable(createColorImage(drawColor));
    listPopupWindowColorPicker.setDropDownGravity(Gravity.CENTER);
    drawColorButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!isPopUpColorShowing) {
                listPopupWindowColorPicker.show();
                isPopUpColorShowing = true;
            }
        }
    });
    listPopupWindowColorPicker.setOnDismissListener(new PopupWindow.OnDismissListener() {

        @Override
        public void onDismiss() {
            isPopUpColorShowing = false;
        }
    });
    listPopupWindowColorPicker.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            drawColor = colors[position];
            drawColorButton.setImageDrawable(createColorImage(drawColor));
            preferences.edit().putInt(KEY_DRAW_COLOR, drawColor).apply();
            cropView.setDrawColor(drawColor);
            listPopupWindowColorPicker.dismiss();
        }
    });
    final String[] penSizeValues = getResources().getStringArray(R.array.crop_pen_size_entries);
    final ListPopupWindow listPopupPenSizerPicker = new ListPopupWindow(mContext);
    listPopupPenSizerPicker.setAdapter(new PenSizeArrayAdapter(this, android.R.layout.simple_list_item_1, penSizeValues));
    final ImageButton penSizeButton = (ImageButton) mainLayout.findViewById(R.id.penSize);
    listPopupPenSizerPicker.setAnchorView(penSizeButton);
    final int penSizeValue = preferences.getInt(KEY_PEN_SIZE, 5);
    penSize = Math.round(penSizeValue * mDensity);
    cropView.setPenSize(penSize);
    penSizeButton.setImageDrawable(createPenSizeImage(penSize));
    listPopupPenSizerPicker.setDropDownGravity(Gravity.CENTER);
    penSizeButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!isPopUpColorShowing) {
                listPopupPenSizerPicker.show();
                isPopUpPenSizeShowing = true;
            }
        }
    });
    listPopupPenSizerPicker.setOnDismissListener(new PopupWindow.OnDismissListener() {

        @Override
        public void onDismiss() {
            isPopUpPenSizeShowing = false;
        }
    });
    listPopupPenSizerPicker.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            final int penSizeValue = Integer.valueOf(penSizeValues[position]);
            preferences.edit().putInt(KEY_PEN_SIZE, penSizeValue).apply();
            penSize = Math.round(penSizeValue * mDensity);
            penSizeButton.setImageDrawable(createPenSizeImage(penSize));
            cropView.setPenSize(penSize);
            listPopupPenSizerPicker.dismiss();
        }
    });
    layoutWorkModeCrop = (LinearLayout) mainLayout.findViewById(R.id.layout_work_mode_crop);
    layoutWorkModeDraw = (LinearLayout) mainLayout.findViewById(R.id.layout_work_mode_draw);
    final ListPopupWindow listPopupWindow = new ListPopupWindow(mContext);
    workModeButton = (ImageButton) mainLayout.findViewById(R.id.workMode);
    workMode = preferences.getInt(KEY_WORK_MODE, WORK_MODE_CROP);
    ImageArrayAdapter adapter = new ImageArrayAdapter(mContext, new Integer[] { R.drawable.ic_image_crop, R.drawable.ic_image_edit, R.drawable.ic_action_visibility });
    listPopupWindow.setAdapter(adapter);
    listPopupWindow.setAnchorView(workModeButton);
    listPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            preferences.edit().putInt(KEY_WORK_MODE, position).apply();
            workMode = position;
            setWorkMode();
            listPopupWindow.dismiss();
        }
    });
    listPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {

        @Override
        public void onDismiss() {
            isPopUpWorkModeShowing = false;
        }
    });
    workModeButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!isPopUpWorkModeShowing) {
                listPopupWindow.show();
                isPopUpWorkModeShowing = true;
            } else
                listPopupWindow.dismiss();
        }
    });
    setWorkMode();
}
Also used : ListPopupWindow(android.widget.ListPopupWindow) PopupWindow(android.widget.PopupWindow) ColorArrayAdapter(com.android.systemui.screenshot.ColorArrayAdapter) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) CropImageView(com.android.systemui.screenshot.CropImageView) Paint(android.graphics.Paint) Point(android.graphics.Point) ImageButton(android.widget.ImageButton) ListPopupWindow(android.widget.ListPopupWindow) ImageArrayAdapter(com.android.systemui.screenshot.ImageArrayAdapter) AdapterView(android.widget.AdapterView) BitmapFactory(android.graphics.BitmapFactory)

Aggregations

BitmapFactory (android.graphics.BitmapFactory)1 Paint (android.graphics.Paint)1 Point (android.graphics.Point)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ImageButton (android.widget.ImageButton)1 ListPopupWindow (android.widget.ListPopupWindow)1 PopupWindow (android.widget.PopupWindow)1 TextView (android.widget.TextView)1 ColorArrayAdapter (com.android.systemui.screenshot.ColorArrayAdapter)1 CropImageView (com.android.systemui.screenshot.CropImageView)1 ImageArrayAdapter (com.android.systemui.screenshot.ImageArrayAdapter)1