Example usage for android.graphics PorterDuffColorFilter PorterDuffColorFilter

List of usage examples for android.graphics PorterDuffColorFilter PorterDuffColorFilter

Introduction

In this page you can find the example usage for android.graphics PorterDuffColorFilter PorterDuffColorFilter.

Prototype

public PorterDuffColorFilter(@ColorInt int color, @NonNull PorterDuff.Mode mode) 

Source Link

Document

Create a color filter that uses the specified color and Porter-Duff mode.

Usage

From source file:com.nextgis.maplibui.util.ControlHelper.java

public static Drawable getIconByVectorType(Context context, int geometryType, int color, int defaultIcon,
        boolean syncable) {
    int drawableId;

    switch (geometryType) {
    case GTPoint:
        drawableId = R.drawable.ic_type_point;
        break;/*from   ww w. j a  v  a  2 s.c o  m*/
    case GTMultiPoint:
        drawableId = R.drawable.ic_type_multipoint;
        break;
    case GTLineString:
        drawableId = R.drawable.ic_type_line;
        break;
    case GTMultiLineString:
        drawableId = R.drawable.ic_type_multiline;
        break;
    case GTPolygon:
        drawableId = R.drawable.ic_type_polygon;
        break;
    case GTMultiPolygon:
        drawableId = R.drawable.ic_type_multipolygon;
        break;
    default:
        return ContextCompat.getDrawable(context, defaultIcon);
    }

    BitmapDrawable icon = (BitmapDrawable) ContextCompat.getDrawable(context, drawableId);
    if (icon != null) {
        Bitmap src = icon.getBitmap();
        Bitmap bitmap = Bitmap.createBitmap(src.getWidth(), src.getHeight(), src.getConfig());
        Canvas canvas = new Canvas(bitmap);

        Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        ColorFilter filter = new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP);
        paint.setColorFilter(filter);
        canvas.drawBitmap(src, 0, 0, paint);

        if (syncable) {
            int syncIconId = isDarkTheme(context) ? R.drawable.ic_action_refresh_dark
                    : R.drawable.ic_action_refresh_light;
            ;
            src = BitmapFactory.decodeResource(context.getResources(), syncIconId);
            src = Bitmap.createScaledBitmap(src, bitmap.getWidth() / 2, bitmap.getWidth() / 2, true);
            canvas.drawBitmap(src, bitmap.getWidth() - bitmap.getWidth() / 2,
                    bitmap.getWidth() - bitmap.getWidth() / 2, new Paint());
        }

        icon = new BitmapDrawable(context.getResources(), bitmap);
    }

    return icon;
}

From source file:ir.besteveryeverapp.ui.Cells.DrawerProfileCell.java

@Override
protected void onDraw(Canvas canvas) {
    int pic = SkinMan.currentSkin.actionPicture();
    Drawable backgroundDrawable = pic != 0 ? ContextCompat.getDrawable(getContext(), pic)
            : ApplicationLoader.getCachedWallpaper();
    int color = ApplicationLoader.getServiceMessageColor();
    if (currentColor != color) {
        currentColor = color;/*from   w w  w  . j av a 2 s  . co m*/
        shadowView.getDrawable()
                .setColorFilter(new PorterDuffColorFilter(color | 0xff000000, PorterDuff.Mode.MULTIPLY));
    }

    if (ApplicationLoader.isCustomTheme() || pic != 0 && backgroundDrawable != null) {
        phoneTextView.setTextColor(0xffffffff);
        shadowView.setVisibility(VISIBLE);
        if (backgroundDrawable instanceof ColorDrawable) {
            backgroundDrawable.setBounds(0, 0, getMeasuredWidth(), getMeasuredHeight());
            backgroundDrawable.draw(canvas);
        } else if (backgroundDrawable instanceof BitmapDrawable) {
            Bitmap bitmap = ((BitmapDrawable) backgroundDrawable).getBitmap();
            float scaleX = (float) getMeasuredWidth() / (float) bitmap.getWidth();
            float scaleY = (float) getMeasuredHeight() / (float) bitmap.getHeight();
            float scale = scaleX < scaleY ? scaleY : scaleX;
            int width = (int) (getMeasuredWidth() / scale);
            int height = (int) (getMeasuredHeight() / scale);
            int x = (bitmap.getWidth() - width) / 2;
            int y = (bitmap.getHeight() - height) / 2;
            srcRect.set(x, y, x + width, y + height);
            destRect.set(0, 0, getMeasuredWidth(), getMeasuredHeight());
            canvas.drawBitmap(bitmap, srcRect, destRect, paint);
        }
    } else {
        shadowView.setVisibility(INVISIBLE);
        phoneTextView.setTextColor(0xffc2e5ff);
        super.onDraw(canvas);
    }
}

From source file:org.onepf.opfmaps.osmdroid.model.BitmapDescriptor.java

@NonNull
private Drawable createDefault(@NonNull final Context context, final float hue) {
    final Drawable drawable = ContextCompat.getDrawable(context, R.drawable.ic_marker).mutate();
    drawable.setColorFilter(new PorterDuffColorFilter(Color.HSVToColor(new float[] { hue, SATURATION, VALUE }),
            PorterDuff.Mode.MULTIPLY));/* ww w.  j av  a  2 s .c  o m*/

    return drawable;
}

From source file:lewa.support.v7.internal.widget.TintManager.java

void tintDrawable(final int resId, final Drawable drawable) {
    PorterDuff.Mode tintMode = null;/*w ww  .j  av a  2 s  .  com*/
    boolean colorAttrSet = false;
    int colorAttr = 0;
    int alpha = -1;

    if (arrayContains(TINT_COLOR_CONTROL_NORMAL, resId)) {
        colorAttr = R.attr.colorControlNormal;
        colorAttrSet = true;
    } else if (arrayContains(TINT_COLOR_CONTROL_ACTIVATED, resId)) {
        colorAttr = R.attr.colorControlActivated;
        colorAttrSet = true;
    } else if (arrayContains(TINT_COLOR_BACKGROUND_MULTIPLY, resId)) {
        colorAttr = android.R.attr.colorBackground;
        colorAttrSet = true;
        tintMode = PorterDuff.Mode.MULTIPLY;
    } else if (resId == R.drawable.abc_list_divider_mtrl_alpha) {
        colorAttr = android.R.attr.colorForeground;
        colorAttrSet = true;
        alpha = Math.round(0.16f * 255);
    }

    if (colorAttrSet) {
        if (tintMode == null) {
            tintMode = DEFAULT_MODE;
        }
        final int color = getThemeAttrColor(colorAttr);

        // First, lets see if the cache already contains the color filter
        PorterDuffColorFilter filter = COLOR_FILTER_CACHE.get(color, tintMode);

        if (filter == null) {
            // Cache miss, so create a color filter and add it to the cache
            filter = new PorterDuffColorFilter(color, tintMode);
            COLOR_FILTER_CACHE.put(color, tintMode, filter);
        }

        // Finally set the color filter
        drawable.setColorFilter(filter);

        if (alpha != -1) {
            drawable.setAlpha(alpha);
        }

        if (DEBUG) {
            Log.d(TAG, "Tinted Drawable ID: " + mResources.getResourceName(resId) + " with color: #"
                    + Integer.toHexString(color));
        }
    }
}

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

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

    MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
    if (messageObject != null) {
        currentAccount = messageObject.currentAccount;
    } else {/*ww w  .  jav  a2 s  .  c o  m*/
        currentAccount = UserConfig.selectedAccount;
    }

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

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

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

    containerView = new FrameLayout(context) {

        private boolean ignoreLayout = false;

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

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

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

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

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

            setFullAnimationProgress(fullAnimationProgress);
        }

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

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

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

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

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

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

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

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

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

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

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

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

    placeholderImageView = new BackupImageView(context) {

        private RectF rect = new RectF();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    listView = new RecyclerListView(context) {

        boolean ignoreLayout;

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

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

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

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

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

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

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

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

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

From source file:org.runbuddy.tomahawk.views.PageIndicator.java

private void updateColors(int position) {
    for (int i = 0; i < mItems.size(); i++) {
        TextView textView = (TextView) mItems.get(i).findViewById(R.id.textview);
        ImageView imageView = (ImageView) mItems.get(i).findViewById(R.id.imageview);
        ImageView arrow = (ImageView) mItems.get(i).findViewById(R.id.arrow);
        if (i == position) {
            textView.setTextColor(getResources().getColor(R.color.primary_textcolor_inverted));
            imageView.clearColorFilter();
            arrow.clearColorFilter();/*from  w w  w.j  ava  2s  . c  om*/
        } else {
            textView.setTextColor(getResources().getColor(R.color.tertiary_textcolor_inverted));
            ColorFilter grayOutFilter = new PorterDuffColorFilter(
                    TomahawkApp.getContext().getResources().getColor(R.color.tertiary_textcolor_inverted),
                    PorterDuff.Mode.MULTIPLY);
            imageView.setColorFilter(grayOutFilter);
            arrow.setColorFilter(grayOutFilter);
        }
    }
}

From source file:org.telegram.ui.ThemePreviewActivity.java

@Override
public View createView(Context context) {
    page1 = new FrameLayout(context);
    ActionBarMenu menu = actionBar.createMenu();
    final ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true)
            .setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
                @Override/*  w  w w. jav a  2  s  .  c o  m*/
                public void onSearchExpand() {

                }

                @Override
                public boolean canCollapseSearch() {
                    return true;
                }

                @Override
                public void onSearchCollapse() {

                }

                @Override
                public void onTextChanged(EditText editText) {

                }
            });
    item.getSearchField().setHint(LocaleController.getString("Search", R.string.Search));

    actionBar.setBackButtonDrawable(new MenuDrawable());
    actionBar.setAddToContainer(false);
    actionBar.setTitle(LocaleController.getString("ThemePreview", R.string.ThemePreview));

    page1 = new FrameLayout(context) {
        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            int widthSize = MeasureSpec.getSize(widthMeasureSpec);
            int heightSize = MeasureSpec.getSize(heightMeasureSpec);

            setMeasuredDimension(widthSize, heightSize);

            measureChildWithMargins(actionBar, widthMeasureSpec, 0, heightMeasureSpec, 0);
            int actionBarHeight = actionBar.getMeasuredHeight();
            if (actionBar.getVisibility() == VISIBLE) {
                heightSize -= actionBarHeight;
            }
            FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
            layoutParams.topMargin = actionBarHeight;
            listView.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY),
                    MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY));

            measureChildWithMargins(floatingButton, widthMeasureSpec, 0, heightMeasureSpec, 0);
        }

        @Override
        protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
            boolean result = super.drawChild(canvas, child, drawingTime);
            if (child == actionBar && parentLayout != null) {
                parentLayout.drawHeaderShadow(canvas,
                        actionBar.getVisibility() == VISIBLE ? actionBar.getMeasuredHeight() : 0);
            }
            return result;
        }
    };
    page1.addView(actionBar, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

    listView = new RecyclerListView(context);
    listView.setVerticalScrollBarEnabled(true);
    listView.setItemAnimator(null);
    listView.setLayoutAnimation(null);
    listView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
    listView.setVerticalScrollbarPosition(LocaleController.isRTL ? RecyclerListView.SCROLLBAR_POSITION_LEFT
            : RecyclerListView.SCROLLBAR_POSITION_RIGHT);
    page1.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT,
            Gravity.LEFT | Gravity.TOP));

    floatingButton = new ImageView(context);
    floatingButton.setScaleType(ImageView.ScaleType.CENTER);

    Drawable drawable = Theme.createSimpleSelectorCircleDrawable(AndroidUtilities.dp(56),
            Theme.getColor(Theme.key_chats_actionBackground),
            Theme.getColor(Theme.key_chats_actionPressedBackground));
    if (Build.VERSION.SDK_INT < 21) {
        Drawable shadowDrawable = context.getResources().getDrawable(R.drawable.floating_shadow).mutate();
        shadowDrawable.setColorFilter(new PorterDuffColorFilter(0xff000000, PorterDuff.Mode.MULTIPLY));
        CombinedDrawable combinedDrawable = new CombinedDrawable(shadowDrawable, drawable, 0, 0);
        combinedDrawable.setIconSize(AndroidUtilities.dp(56), AndroidUtilities.dp(56));
        drawable = combinedDrawable;
    }
    floatingButton.setBackgroundDrawable(drawable);
    floatingButton.setColorFilter(
            new PorterDuffColorFilter(Theme.getColor(Theme.key_chats_actionIcon), PorterDuff.Mode.MULTIPLY));
    floatingButton.setImageResource(R.drawable.floating_pencil);
    if (Build.VERSION.SDK_INT >= 21) {
        StateListAnimator animator = new StateListAnimator();
        animator.addState(new int[] { android.R.attr.state_pressed },
                ObjectAnimator
                        .ofFloat(floatingButton, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4))
                        .setDuration(200));
        animator.addState(new int[] {},
                ObjectAnimator
                        .ofFloat(floatingButton, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2))
                        .setDuration(200));
        floatingButton.setStateListAnimator(animator);
        floatingButton.setOutlineProvider(new ViewOutlineProvider() {
            @SuppressLint("NewApi")
            @Override
            public void getOutline(View view, Outline outline) {
                outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56));
            }
        });
    }
    page1.addView(floatingButton,
            LayoutHelper.createFrame(Build.VERSION.SDK_INT >= 21 ? 56 : 60,
                    Build.VERSION.SDK_INT >= 21 ? 56 : 60,
                    (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.BOTTOM,
                    LocaleController.isRTL ? 14 : 0, 0, LocaleController.isRTL ? 0 : 14, 14));

    dialogsAdapter = new DialogsAdapter(context);
    listView.setAdapter(dialogsAdapter);

    page2 = new SizeNotifierFrameLayout(context) {
        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            int widthSize = MeasureSpec.getSize(widthMeasureSpec);
            int heightSize = MeasureSpec.getSize(heightMeasureSpec);

            setMeasuredDimension(widthSize, heightSize);

            measureChildWithMargins(actionBar2, widthMeasureSpec, 0, heightMeasureSpec, 0);
            int actionBarHeight = actionBar2.getMeasuredHeight();
            if (actionBar2.getVisibility() == VISIBLE) {
                heightSize -= actionBarHeight;
            }
            FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView2.getLayoutParams();
            layoutParams.topMargin = actionBarHeight;
            listView2.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY),
                    MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY));
        }

        @Override
        protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
            boolean result = super.drawChild(canvas, child, drawingTime);
            if (child == actionBar2 && parentLayout != null) {
                parentLayout.drawHeaderShadow(canvas,
                        actionBar2.getVisibility() == VISIBLE ? actionBar2.getMeasuredHeight() : 0);
            }
            return result;
        }
    };
    page2.setBackgroundImage(Theme.getCachedWallpaper());

    actionBar2 = createActionBar(context);
    actionBar2.setBackButtonDrawable(new BackDrawable(false));
    actionBar2.setTitle("Reinhardt");
    actionBar2.setSubtitle(LocaleController.formatDateOnline(System.currentTimeMillis() / 1000 - 60 * 60));
    page2.addView(actionBar2, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

    listView2 = new RecyclerListView(context);
    listView2.setVerticalScrollBarEnabled(true);
    listView2.setItemAnimator(null);
    listView2.setLayoutAnimation(null);
    listView2.setPadding(0, AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4));
    listView2.setClipToPadding(false);
    listView2.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, true));
    listView2.setVerticalScrollbarPosition(LocaleController.isRTL ? RecyclerListView.SCROLLBAR_POSITION_LEFT
            : RecyclerListView.SCROLLBAR_POSITION_RIGHT);
    page2.addView(listView2, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT,
            Gravity.LEFT | Gravity.TOP));

    messagesAdapter = new MessagesAdapter(context);
    listView2.setAdapter(messagesAdapter);

    fragmentView = new FrameLayout(context);
    FrameLayout frameLayout = (FrameLayout) fragmentView;

    final ViewPager viewPager = new ViewPager(context);
    viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int position) {
            dotsContainer.invalidate();
        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });
    viewPager.setAdapter(new PagerAdapter() {

        @Override
        public int getCount() {
            return 2;
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return object == view;
        }

        @Override
        public int getItemPosition(Object object) {
            return POSITION_UNCHANGED;
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            View view = position == 0 ? page1 : page2;
            container.addView(view);
            return view;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }

        @Override
        public void unregisterDataSetObserver(DataSetObserver observer) {
            if (observer != null) {
                super.unregisterDataSetObserver(observer);
            }
        }
    });
    AndroidUtilities.setViewPagerEdgeEffectColor(viewPager, Theme.getColor(Theme.key_actionBarDefault));
    frameLayout.addView(viewPager, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 0, 0, 0, 48));

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

    FrameLayout bottomLayout = new FrameLayout(context);
    bottomLayout.setBackgroundColor(0xffffffff);
    frameLayout.addView(bottomLayout,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.BOTTOM));

    dotsContainer = new View(context) {

        private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);

        @Override
        protected void onDraw(Canvas canvas) {
            int selected = viewPager.getCurrentItem();
            for (int a = 0; a < 2; a++) {
                paint.setColor(a == selected ? 0xff999999 : 0xffcccccc);
                canvas.drawCircle(AndroidUtilities.dp(3 + 15 * a), AndroidUtilities.dp(4),
                        AndroidUtilities.dp(3), paint);
            }
        }
    };
    bottomLayout.addView(dotsContainer, LayoutHelper.createFrame(22, 8, Gravity.CENTER));

    TextView cancelButton = new TextView(context);
    cancelButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    cancelButton.setTextColor(0xff19a7e8);
    cancelButton.setGravity(Gravity.CENTER);
    cancelButton.setBackgroundDrawable(Theme.createSelectorDrawable(0x2f000000, 0));
    cancelButton.setPadding(AndroidUtilities.dp(29), 0, AndroidUtilities.dp(29), 0);
    cancelButton.setText(LocaleController.getString("Cancel", R.string.Cancel).toUpperCase());
    cancelButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    bottomLayout.addView(cancelButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT,
            LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));
    cancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Theme.applyPreviousTheme();
            parentLayout.rebuildAllFragmentViews(false);
            finishFragment();
        }
    });

    TextView doneButton = new TextView(context);
    doneButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    doneButton.setTextColor(0xff19a7e8);
    doneButton.setGravity(Gravity.CENTER);
    doneButton.setBackgroundDrawable(Theme.createSelectorDrawable(0x2f000000, 0));
    doneButton.setPadding(AndroidUtilities.dp(29), 0, AndroidUtilities.dp(29), 0);
    doneButton.setText(LocaleController.getString("ApplyTheme", R.string.ApplyTheme).toUpperCase());
    doneButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    bottomLayout.addView(doneButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT,
            LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.RIGHT));
    doneButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            applied = true;
            parentLayout.rebuildAllFragmentViews(false);
            Theme.applyThemeFile(themeFile, applyingTheme.name, false);
            finishFragment();
        }
    });

    return fragmentView;
}

From source file:uk.ac.horizon.artcodes.scanner.ScannerActivity.java

/**
 * This function sets the colors of the scan screen (only if the experience contains colors).
 *//*from w w  w. j a v  a  2s.c o m*/
public void setExperienceStyle() {
    if (this.experience != null) {
        if (this.experience.getBackgroundColor() != null || this.experience.getForegroundColor() != null) {

            if (this.experience.getBackgroundColor() != null) {
                View topFrame = findViewById(R.id.topView);
                View bottomFrame = findViewById(R.id.bottomView);
                int backgroundColor = Color.parseColor(this.experience.getBackgroundColor());
                // If no transparency is set add default transparency to background:
                if (this.experience.getBackgroundColor().length() <= 7)
                    backgroundColor &= 0xbbffffff;
                if (topFrame != null)
                    topFrame.setBackgroundColor(backgroundColor);
                if (bottomFrame != null)
                    bottomFrame.setBackgroundColor(backgroundColor);
            }

            if (this.experience.getForegroundColor() != null) {
                int foregroundColor = Color.parseColor(this.experience.getForegroundColor());
                Toolbar v = (Toolbar) findViewById(R.id.toolbar);
                if (v != null) {
                    v.setTitleTextColor(foregroundColor);
                    // set back icon color:
                    try {
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                            v.getNavigationIcon().setTint(foregroundColor);
                        } else {
                            v.getNavigationIcon().setColorFilter(
                                    new PorterDuffColorFilter(foregroundColor, PorterDuff.Mode.MULTIPLY));
                        }
                    } catch (NullPointerException e) {
                        Log.w("", "Exception setting toolbar icon colour.", e);
                    }
                }

                TextView scanScreenTextTitle = (TextView) findViewById(R.id.scanScreenTextTitle);
                if (scanScreenTextTitle != null) {
                    scanScreenTextTitle.setTextColor(foregroundColor);
                }
                TextView scanScreenTextDesc = (TextView) findViewById(R.id.scanScreenTextDesc);
                if (scanScreenTextDesc != null) {
                    scanScreenTextDesc.setTextColor(foregroundColor);
                }
            }

        }

        if (this.experience.getHighlightBackgroundColor() != null
                && this.experience.getHighlightForegroundColor() != null) {
            int foregroundColor = Color.parseColor(this.experience.getHighlightForegroundColor());
            int backgroundColor = Color.parseColor(this.experience.getHighlightBackgroundColor());

            Button b = (Button) findViewById(R.id.scan_event_button);
            if (b != null) {
                b.setTextColor(foregroundColor);
                b.setBackgroundColor(backgroundColor);
            }
            ProgressBar pb = (ProgressBar) findViewById(R.id.progressBar);
            if (pb != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                pb.setIndeterminateTintList(ColorStateList.valueOf(backgroundColor));
            }
        }

        if (this.experience.getScanScreenTextTitle() != null) {
            TextView textView = (TextView) findViewById(R.id.scanScreenTextTitle);
            if (textView != null) {
                textView.setVisibility(View.VISIBLE);
                textView.setText(this.experience.getScanScreenTextTitle());
            }
        }
        if (this.experience.getScanScreenTextDesciption() != null) {
            TextView textView = (TextView) findViewById(R.id.scanScreenTextDesc);
            if (textView != null) {
                textView.setVisibility(View.VISIBLE);
                textView.setText(this.experience.getScanScreenTextDesciption());
            }
        }

    }
}

From source file:uk.co.brightec.ratetheapp.RateTheApp.java

private void initStars() {
    Drawable selected = ContextCompat.getDrawable(getContext(), mDrawableResSelected);
    selected = selected.mutate();//from   w w  w.j av  a2s .co  m
    selected.setColorFilter(new PorterDuffColorFilter(mSelectedStarColour, PorterDuff.Mode.SRC_ATOP));

    Drawable unselected = ContextCompat.getDrawable(getContext(), mDrawableResUnSelected);
    unselected = unselected.mutate();
    unselected.setColorFilter(new PorterDuffColorFilter(mUnselectedStarColour, PorterDuff.Mode.SRC_ATOP));

    LayerDrawable ld = (LayerDrawable) mRatingBar.getProgressDrawable();
    ld.setDrawableByLayerId(android.R.id.background, unselected);
    ld.setDrawableByLayerId(android.R.id.secondaryProgress, unselected);
    ld.setDrawableByLayerId(android.R.id.progress, selected);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mRatingBar.setProgressDrawableTiled(ld);
    } else {
        Drawable tiledDrawable = tileify(ld, false);
        mRatingBar.setProgressDrawable(tiledDrawable);
    }
}

From source file:com.koushikdutta.superuser.FragmentMain.java

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    context = getActivity();/*  w  w w  .  j  a va 2 s .c  om*/

    pref = PreferenceManager.getDefaultSharedPreferences(context);

    callback = (MainCallback) getActivity();

    LocalBroadcastManager.getInstance(context).registerReceiver(receiver,
            new IntentFilter(Common.INTENT_FILTER_MAIN));

    gridMode = pref.getBoolean("grid_mode", true);

    coordinatorLayout = (CoordinatorLayout) getActivity().findViewById(R.id.main_content);

    //tabLayout = (TabLayout) getActivity().findViewById(R.id.tabs);

    //viewPager = (ViewPager) getActivity().findViewById(R.id.container);

    int span = 0;

    if (gridMode) {
        layoutManager = new RecyclerViewSwipeable.LayoutManagerSwipeable(context, 1);

        if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
            span = pref.getInt("grid_size_port", 3);
            layoutManager.setSpanCount(span);

        } else if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
            span = pref.getInt("grid_size_land", 4);
            layoutManager.setSpanCount(span);
        }

        Drawable divider = ContextCompat.getDrawable(context, R.drawable.divider_grid);
        divider.setColorFilter(new PorterDuffColorFilter(ATHUtil.resolveColor(context, R.attr.dividerGrid),
                PorterDuff.Mode.SRC_ATOP));

        recycler.setLayoutManager(layoutManager);

        recycler.setLayoutAnimation(AnimationUtils.loadLayoutAnimation(context, R.anim.grid_layout_animation));

        recycler.addItemDecoration(new GridDividerItemDecoration(divider, divider, span));

        recycler.addItemDecoration(new GridTopOffsetItemDecoration(Util.toPx(context, 5), span));

    } else {
        recycler.setLayoutManager(new LinearLayoutManager(context));

        recycler.addItemDecoration(new StartOffsetItemDecoration(Util.toPx(context, 10)));
    }

    //recycler.setListener(clickListener);
    //recycler.setViewPager(viewPager);
    //recycler.setFragment(this);

    setData();
}