Example usage for android.graphics.drawable.shapes RectShape RectShape

List of usage examples for android.graphics.drawable.shapes RectShape RectShape

Introduction

In this page you can find the example usage for android.graphics.drawable.shapes RectShape RectShape.

Prototype

public RectShape() 

Source Link

Usage

From source file:git.egatuts.nxtremotecontroller.activity.ControllerActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    super.setActiveTheme(super.getPreferenceTheme());
    super.setContentView(R.layout.controller_layout);
    toolbar = (Toolbar) this.findViewById(R.id.toolbar);
    super.setSupportToolbar();
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override//from  w  w w .  j a v  a2s .  co  m
        public void onClick(View v) {
            ControllerActivity.this.onBackPressed();
        }
    });

    /*
     *  We get the device from the extra data of the intent.
     */
    this.device = this.getIntent().getParcelableExtra("device");

    /*
     *  We create the final variables we will use in the listeners, etc.
     */
    final ControllerActivity self = this;
    final GlobalUtils utils = this.getGlobalUtils();

    /*
     *  We create the AlertDialog.Builder we will show to ask the user to reconnect with the device.
     */
    this.builder = utils
            .createAlertDialog(utils.getStringResource(R.string.connecting_reconnect_title),
                    utils.format(R.string.connecting_reconnect_message, this.device.getName()))
            .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    self.finish();
                }
            }).setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    self.resume();
                }
            });

    /*
     *  Now we define the progress dialog we will show while we are connecting with the device.
     *  When the progress dialog has been cancelled it means the connection process has been cancelled.
     *  But on dismiss we have to check if the connection failed or it succeed.
     */
    this.progressDialog = this.getLongProgressDialog();
    this.progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            self.aborted = true;
            utils.showToast(R.string.connecting_aborted);
            self.connector.closeConnectThread();
            self.finish();
        }
    });

    /*
     *  Now we declare the handler that will handle (so obviously) the messages
     *  sent by the threads that are in the background connecting with the device.
     */
    this.handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if ((self.connector.getConnectThread() == null || self.aborted)
                    && self.connector.getConnectedThread() == null) {
                return;
            }
            int category = msg.what;
            int state;
            int error;
            if (category == NXTConnector.WHAT_CHANGE_STATE) {
                progressDialog.show();
                state = msg.arg1;
                error = msg.arg2;
                if (NXTConnector.isPreparingConnection(state)) {
                    progressDialog.setText(R.string.connecting_preparing_connection);
                } else if (NXTConnector.isCreatingSocket(state)) {
                    progressDialog.setText(R.string.connecting_creating_socket);
                } else if (NXTConnector.isConnecting(state)) {
                    progressDialog.setText(R.string.connecting_connecting);
                } else if (NXTConnector.isConnected(state)) {
                    progressDialog.dismiss();
                    utils.showToast(R.string.connecting_connected, device.getName());
                    self.connected();
                }
            } else if (category == NXTConnector.WHAT_ERROR_ENCOUNTERED) {
                progressDialog.dismiss();
                self.connector.closeAllThreads();
                error = msg.arg1;
                state = msg.arg2;
                boolean notReconnect = false;
                if (NXTConnector.connectionClosed(state, error)) {
                    utils.showToast(R.string.connecting_connection_closed);
                    notReconnect = true;
                    ControllerActivity.this.finish();
                } else if (NXTConnector.connectionLost(state, error)) {
                    utils.showToast(R.string.connecting_connection_lost);
                    if (!self.connector.getBluetoothUtils().isEnabled()) {
                        notReconnect = true;
                        ControllerActivity.this.finish();
                    }
                } else if (NXTConnector.connectionSocketFailed(state, error)) {
                    utils.showToast(R.string.connecting_socket_error);
                } else if (NXTConnector.connectionRequestFailed(state, error)) {
                    utils.showToast(R.string.connecting_request_failed);
                } else if (NXTConnector.connectionUnexpectedFailed(state, error)) {
                    utils.showToast(R.string.connecting_unexpected_error);
                }
                if (!notReconnect) {
                    self.builder.show();
                }
            }
        }
    };

    /*
     *  Now we create the connector with the device and the handler
     *  which we will use to connect and send messages to the robot.
     */
    this.connector = new NXTConnector(this, this.device, this.handler);

    /*
     *  We set the title with the device name.
     */
    String title = utils.getStringResource(R.string.controller_window_title);
    this.setTitle(title + this.device.getName());

    /*
     *  We set the colors we will use with the drawables used in the tabs.
     */
    final int underlineColor = utils.getAttribute(R.attr.toolbar_color);
    final int backgroundColor = utils.getAttribute(R.attr.toolbar_background);
    final int lightBackgroundColor = GlobalUtils.mixColors(backgroundColor, 0x55FFFFFF);

    /*
     *  Now we create the drawables used in all the states of the tabs and then we assign
     *  them to a StateListDrawable to add it to the tabs.
     */
    ShapeDrawable.ShaderFactory tabSelectedFactory = new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            return new LinearGradient(0, 0, /* Origin of the background (top left corner) */
                    0, height, /* End of the background (bottom left corner) */
                    new int[] { backgroundColor,
                            backgroundColor, /* The first gradient doesn't change color so it's like a rectangle shape */
                            underlineColor, underlineColor /* The same for the second one */
            }, new float[] { 0, 51f / 55f, /* The first background covers 51dp out of 55dp */
                    51f / 55f, 1 /* And the second one takes the rest of the space */
            }, Shader.TileMode.REPEAT /* The repeat mode doesn't mind but this would look prettier in case of error */
            );
        }
    };
    PaintDrawable tabSel = new PaintDrawable();
    tabSel.setShape(new RectShape());
    tabSel.setShaderFactory(tabSelectedFactory);

    ShapeDrawable.ShaderFactory tabSelectedAndPressedFactory = new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            return new LinearGradient(0, 0, /* Origin of the background (top left corner) */
                    0, height, /* End of the background (bottom left corner) */
                    new int[] { lightBackgroundColor,
                            lightBackgroundColor, /* The first gradient doesn't change color so it's like a rectangle shape */
                            underlineColor, underlineColor /* The same for the second one */
            }, new float[] { 0, 51f / 55f, /* The first background covers 51dp out of 55dp */
                    51f / 55f, 1 /* And the second one takes the rest of the space */
            }, Shader.TileMode.REPEAT /* The repeat mode doesn't mind but this would look prettier in case of error */
            );
        }
    };
    PaintDrawable tabSelAndPress = new PaintDrawable();
    tabSelAndPress.setShape(new RectShape());
    tabSelAndPress.setShaderFactory(tabSelectedAndPressedFactory);

    /*
     *  Now we create the states lists for the drawables and the colors.
     */
    StateListDrawable drawableList = new StateListDrawable();
    drawableList.addState(new int[] { -android.R.attr.state_selected, android.R.attr.state_pressed },
            new ColorDrawable(lightBackgroundColor));
    drawableList.addState(new int[] { -android.R.attr.state_selected, android.R.attr.state_pressed,
            android.R.attr.state_focused }, new ColorDrawable(lightBackgroundColor));
    drawableList.addState(new int[] { android.R.attr.state_selected, -android.R.attr.state_pressed }, tabSel);
    drawableList.addState(new int[] { android.R.attr.state_selected, -android.R.attr.state_pressed,
            -android.R.attr.state_focused }, tabSel);
    drawableList.addState(new int[] { android.R.attr.state_selected, android.R.attr.state_pressed },
            tabSelAndPress);
    drawableList.addState(new int[] { android.R.attr.state_selected, android.R.attr.state_pressed,
            android.R.attr.state_focused }, tabSelAndPress);
    drawableList.addState(new int[] {}, new ColorDrawable(backgroundColor));

    int darkColor = utils.getAttribute(R.attr.toolbar_color);
    int lightColor = Color.argb(0xAA, Color.red(darkColor), Color.green(darkColor), Color.blue(darkColor));
    int[][] states = new int[][] { new int[] { -android.R.attr.state_selected, android.R.attr.state_pressed },
            new int[] { -android.R.attr.state_selected, android.R.attr.state_pressed,
                    android.R.attr.state_focused },
            new int[] { android.R.attr.state_selected, -android.R.attr.state_pressed },
            new int[] { android.R.attr.state_selected, -android.R.attr.state_pressed,
                    -android.R.attr.state_focused },
            new int[] { android.R.attr.state_selected, android.R.attr.state_pressed },
            new int[] { android.R.attr.state_selected, android.R.attr.state_pressed,
                    android.R.attr.state_focused },
            new int[] { -android.R.attr.state_selected, -android.R.attr.state_pressed,
                    -android.R.attr.state_focused },
            new int[] {} };
    int[] colors = new int[] { lightColor, /* Text color when pressed and not selected */
            lightColor, /* Text color when pressed (with focused fallback) */
            darkColor, /* Text color when selected and not pressed */
            darkColor, /* Text color when selected and not pressed (with focused fallback) */
            darkColor, /* Text color when selected and pressed */
            darkColor, /* Text color when selected and pressed (with focused fallback) */
            lightColor, /* Normal color when not pressed, selected or focused */
            lightColor /* Default text color */
    };
    ColorStateList colorList = new ColorStateList(states, colors);

    /*
     *  We assign the drawable and the list to the activity instance to be accessible everywhere.
     */
    this.tabSelected = tabSel;
    this.tabSelectedAndPressed = tabSelAndPress;
    this.tabDrawableList = drawableList;
    this.tabColorList = colorList;

    /*
     *  Now we setup the tab host and add the tabs to the view.
     */
    this.tabHost = (FragmentTabHost) this.findViewById(R.id.tabhost);
    this.tabHost.setup(this, super.fragmentManager, R.id.tabcontent);
    this.tabHost.getTabWidget().setDividerDrawable(null);
    this.addTab(this.createTabView(R.layout.controller_tab, R.string.controller_tab_local_title),
            R.string.controller_tab_local_spec, LocalControllerFragment.class);
    this.addTab(this.createTabView(R.layout.controller_tab, R.string.controller_tab_online_title),
            R.string.controller_tab_online_spec, OnlineControllerFragment.class);
}

From source file:com.gm.grecyclerview.GmRecyclerView.java

private void addDividerItemDecoration(@ColorInt int color, int orientation, int paddingLeft, int paddingTop,
        int paddingRight, int paddingBottom) {
    DividerItemDecoration decor = new DividerItemDecoration(getContext(), orientation);
    if (color != 0) {
        ShapeDrawable shapeDrawable = new ShapeDrawable(new RectShape());
        shapeDrawable.setIntrinsicHeight(Utils.dpToPx(getContext(), 1));
        shapeDrawable.setIntrinsicWidth(Utils.dpToPx(getContext(), 1));
        shapeDrawable.getPaint().setColor(color);
        InsetDrawable insetDrawable = new InsetDrawable(shapeDrawable, paddingLeft, paddingTop, paddingRight,
                paddingBottom);/*  www  .  ja va2s  . c o m*/
        decor.setDrawable(insetDrawable);
    }
    decor.setShowLastDivider(showLastDivider);
    addItemDecoration(decor);
}

From source file:com.skytree.epubtest.BookViewActivity.java

public View makeResultItem(SearchResult sr, int mode) {
    int inlineColor = Color.rgb(133, 105, 75);
    int headColor = Color.rgb(94, 61, 34);
    int textColor = Color.rgb(50, 40, 40);

    SkyLayout view = new SkyLayout(this);
    int itemWidth = ps(370);
    int itemHeight = ps(190);

    this.setFrame(view, 0, 0, itemWidth, itemHeight);

    TextView chapterLabel = null;//w  w w  .  j a  v  a 2s .c o  m
    TextView positionLabel = null;
    TextView textLabel = null;
    Button itemButton = null;
    itemButton = new Button(this);
    itemButton.setBackgroundColor(Color.TRANSPARENT);
    itemButton.setOnClickListener(listener);
    this.setFrame(itemButton, 0, 0, itemWidth, itemHeight);

    if (mode == 0) { // Normal case
        int ci = sr.chapterIndex;
        String chapterText = "";
        chapterText = sr.chapterTitle;
        String positionText = String.format("%d/%d", sr.pageIndex + 1, sr.numberOfPagesInChapter);
        if (chapterText == null || chapterText.isEmpty()) {
            chapterText = "Chapter " + ci;
        }
        if (sr.pageIndex < 0 || sr.numberOfPagesInChapter < 0) {
            positionText = "";
        }
        chapterLabel = this.makeLabel(3090, chapterText, Gravity.LEFT, 15, headColor);
        positionLabel = this.makeLabel(3091, positionText, Gravity.LEFT, 15, headColor);
        textLabel = this.makeLabel(3092, sr.text, Gravity.LEFT, 15, textColor);
        itemButton.setId(100000 + searchResults.size());
    } else if (mode == 1) { // Paused
        chapterLabel = this.makeLabel(3090, getString(R.string.searchmore) + "....", Gravity.CENTER, 18,
                headColor);
        //         positionLabel    = this.makeLabel(3091, String.format("%d/%d",sr.pageIndex+1,sr.numberOfPagesInChapter), Gravity.LEFT, 15, headColor);
        textLabel = this.makeLabel(3092, sr.numberOfSearched + " " + getString(R.string.searchfound) + ".",
                Gravity.CENTER, 16, textColor);
        itemButton.setId(3093);
    } else if (mode == 2) { // finished
        chapterLabel = this.makeLabel(3090, getString(R.string.searchfinished), Gravity.CENTER, 18, headColor);
        //         positionLabel    = this.makeLabel(3091, String.format("%d/%d",sr.pageIndex+1,sr.numberOfPagesInChapter), Gravity.LEFT, 15, headColor);
        textLabel = this.makeLabel(3092, sr.numberOfSearched + " " + getString(R.string.searchfound) + ".",
                Gravity.CENTER, 16, textColor);
        itemButton.setId(3094);
    }

    textLabel.setMaxLines(3);

    if (mode == 0) {
        this.setFrame(chapterLabel, ps(20), ps(20), ps(270), ps(30));
        this.setFrame(positionLabel, itemWidth - ps(85), ps(20), ps(70), ps(30));
        this.setFrame(textLabel, ps(20), ps(80), itemWidth - ps(40), itemHeight - ps(80 + 20));
    } else {
        this.setFrame(chapterLabel, ps(20), ps(20), ps(350), ps(40));
        //         this.setFrame(positionLabel, itemWidth-ps(80), ps(20),ps(70),ps(30));
        this.setFrame(textLabel, ps(20), ps(80), itemWidth - ps(40), itemHeight - ps(80 + 20));
    }

    view.addView(chapterLabel);
    if (mode == 0)
        view.addView(positionLabel);
    view.addView(textLabel);
    view.addView(itemButton);

    RectShape crs = new RectShape();
    SkyDrawable cd = new SkyDrawable(crs, Color.TRANSPARENT, inlineColor, 1);
    view.setBackgroundDrawable(cd);

    return view;
}

From source file:com.skytree.epubtest.BookViewActivity.java

public void makeControls() {
    this.removeControls();
    Theme theme = getCurrentTheme();/*from www .  ja  va2 s.c  om*/

    int bs = 38;
    if (this.isRotationLocked)
        rotationButton = this.makeImageButton(9000, R.drawable.rotationlocked2x, ps(42), ps(42));
    else
        rotationButton = this.makeImageButton(9000, R.drawable.rotation2x, ps(42), ps(42));
    listButton = this.makeImageButton(9001, R.drawable.list2x, getPS(bs), getPS(bs));
    fontButton = this.makeImageButton(9002, R.drawable.font2x, getPS(bs), getPS(bs));
    searchButton = this.makeImageButton(9003, R.drawable.search2x, getPS(bs), getPS(bs));
    rotationButton.setOnTouchListener(new ImageButtonHighlighterOnTouchListener(rotationButton));
    listButton.setOnTouchListener(new ImageButtonHighlighterOnTouchListener(listButton));
    fontButton.setOnTouchListener(new ImageButtonHighlighterOnTouchListener(fontButton));
    searchButton.setOnTouchListener(new ImageButtonHighlighterOnTouchListener(searchButton));

    titleLabel = this.makeLabel(3000, title, Gravity.CENTER_HORIZONTAL, 17, Color.argb(240, 94, 61, 35)); // setTextSize in android uses sp (Scaled Pixel) as default, they say that sp guarantees the device dependent size, but as usual in android it can't be 100% sure.    
    authorLabel = this.makeLabel(3000, author, Gravity.CENTER_HORIZONTAL, 17, Color.argb(240, 94, 61, 35));
    pageIndexLabel = this.makeLabel(3000, "......", Gravity.CENTER_HORIZONTAL, 13, Color.argb(240, 94, 61, 35));
    secondaryIndexLabel = this.makeLabel(3000, "......", Gravity.CENTER_HORIZONTAL, 13,
            Color.argb(240, 94, 61, 35));

    //      rv.customView.addView(rotationButton);
    //      rv.customView.addView(listButton);
    //      rv.customView.addView(fontButton);
    //      rv.customView.addView(searchButton);      
    rv.customView.addView(titleLabel);
    rv.customView.addView(authorLabel);

    ePubView.addView(rotationButton);
    ePubView.addView(listButton);
    ePubView.addView(fontButton);
    if (!rv.isScrollMode())
        ePubView.addView(searchButton);
    //      ePubView.addView(titleLabel);
    //      ePubView.addView(authorLabel);

    ePubView.addView(pageIndexLabel);
    ePubView.addView(secondaryIndexLabel);

    seekBar = new SkySeekBar(this);
    seekBar.setMax(999);
    seekBar.setId(999);
    RectShape rectShape = new RectShape();
    ShapeDrawable thumb = new ShapeDrawable(rectShape);

    thumb.getPaint().setColor(theme.seekThumbColor);
    thumb.setIntrinsicHeight(getPS(28));
    thumb.setIntrinsicWidth(getPS(28));
    seekBar.setThumb(thumb);
    seekBar.setBackgroundColor(Color.TRANSPARENT);
    seekBar.setOnSeekBarChangeListener(new SeekBarDelegate());
    seekBar.setProgressDrawable(new DottedDrawable(theme.seekBarColor));
    seekBar.setThumbOffset(-3);
    seekBar.setMinimumHeight(24);

    int filterColor = theme.controlColor;
    rotationButton.setColorFilter(filterColor);
    listButton.setColorFilter(filterColor);
    fontButton.setColorFilter(filterColor);
    searchButton.setColorFilter(filterColor);

    authorLabel.setTextColor(filterColor);
    titleLabel.setTextColor(filterColor);
    pageIndexLabel.setTextColor(filterColor);
    secondaryIndexLabel.setTextColor(filterColor);

    ePubView.addView(seekBar);
}