Example usage for android.content.res Configuration UI_MODE_NIGHT_YES

List of usage examples for android.content.res Configuration UI_MODE_NIGHT_YES

Introduction

In this page you can find the example usage for android.content.res Configuration UI_MODE_NIGHT_YES.

Prototype

int UI_MODE_NIGHT_YES

To view the source code for android.content.res Configuration UI_MODE_NIGHT_YES.

Click Source Link

Document

Constant for #uiMode : a #UI_MODE_NIGHT_MASK value that corresponds to the night resource qualifier.

Usage

From source file:Main.java

public static boolean isNightMode(Resources resources) {
    return ((resources.getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_YES) > 0);
}

From source file:com.shalzz.attendance.controllers.DayController.java

public DayController(Context context, DayFragment view) {
    mContext = context;/*from  w  w w .j a v a2s  .co  m*/
    mView = view;
    mAdapter = new DayListAdapter();
    String unit_id;
    int currentNightMode = mContext.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;

    if (currentNightMode == Configuration.UI_MODE_NIGHT_YES)
        unit_id = mContext.getString(R.string.native_black_timetable_ad);
    else
        unit_id = mContext.getString(R.string.native_white_timetable_ad);

    adapterWrapper = new AdmobExpressRecyclerAdapterWrapper(mContext, unit_id,
            new AdSize(AdSize.FULL_WIDTH, 80));

    adapterWrapper.setAdapter(mAdapter);

    adapterWrapper.setLimitOfAds(1);
    adapterWrapper.setFirstAdIndex(3);
    mView.mRecyclerView.setAdapter(adapterWrapper);
}

From source file:com.shalzz.attendance.controllers.AttendanceController.java

@Inject
public AttendanceController(Context context, AttendanceListFragment view, DataAPI api) {
    mContext = context;//  w  w  w .  j a v  a  2s  .c om
    mResources = context.getResources();
    mView = view;
    db = new DatabaseHandler(mContext);
    this.api = api;

    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(mContext);
    int expandLimit = Integer
            .parseInt(sharedPref.getString(mContext.getString(R.string.pref_key_sub_limit), "3"));

    mAdapter = new ExpandableListAdapter(mContext, mView);
    mAdapter.setLimit(expandLimit);
    LayoutInflater inflater = mView.getActivity().getLayoutInflater();
    mFooter = inflater.inflate(R.layout.list_footer, mView.mRecyclerView, false);
    mFooter.setVisibility(View.INVISIBLE);
    mAdapter.addFooter(mFooter);

    String unit_id;
    int currentNightMode = mContext.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;

    if (currentNightMode == Configuration.UI_MODE_NIGHT_YES)
        unit_id = mContext.getString(R.string.native_black_attendance_ad);
    else
        unit_id = mContext.getString(R.string.native_white_attendance_ad);

    adapterWrapper = new AdmobExpressRecyclerAdapterWrapper(mContext, unit_id,
            new AdSize(AdSize.FULL_WIDTH, 100));

    adapterWrapper.setAdapter(mAdapter);

    adapterWrapper.setLimitOfAds(1);
    adapterWrapper.setNoOfDataBetweenAds(5);
    adapterWrapper.setFirstAdIndex(5);

    mView.mRecyclerView.setAdapter(adapterWrapper);
}

From source file:com.example.ray.firstapp.bottombar.MiscUtils.java

/**
 * Determine if the current UI Mode is Night Mode.
 *
 * @param context Context to get the configuration.
 * @return true if the night mode is enabled, otherwise false.
 *//*www .  ja  v a2s  . co  m*/
protected static boolean isNightMode(Context context) {
    int currentNightMode = context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
    return currentNightMode == Configuration.UI_MODE_NIGHT_YES;
}

From source file:com.pagenews.zhihudaily.homepage.MainActivity.java

@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {

    drawer.closeDrawer(GravityCompat.START);

    int id = item.getItemId();
    if (id == R.id.nav_home) {
        showMainFragment();/*from  w ww. j  ava 2  s . co  m*/
    } else if (id == R.id.nav_bookmarks) {
        showBookmarksFragment();
    } else if (id == R.id.nav_change_theme) {

        // change the day/night mode after the drawer closed
        drawer.addDrawerListener(new DrawerLayout.DrawerListener() {
            @Override
            public void onDrawerSlide(View drawerView, float slideOffset) {

            }

            @Override
            public void onDrawerOpened(View drawerView) {

            }

            @Override
            public void onDrawerClosed(View drawerView) {
                SharedPreferences sp = getSharedPreferences("user_settings", MODE_PRIVATE);
                if ((getResources().getConfiguration().uiMode
                        & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES) {
                    sp.edit().putInt("theme", 0).apply();
                    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
                } else {
                    sp.edit().putInt("theme", 1).apply();
                    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
                }
                getWindow().setWindowAnimations(R.style.WindowAnimationFadeInOut);
                recreate();
            }

            @Override
            public void onDrawerStateChanged(int newState) {

            }
        });

    } else if (id == R.id.nav_settings) {
        startActivity(new Intent(this, SettingsPreferenceActivity.class));
    } else if (id == R.id.nav_about) {
        startActivity(new Intent(this, AboutPreferenceActivity.class));
    }

    return true;
}

From source file:com.white.bihudaily.module.dailys.DailyActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        // Open the navigation drawer when the home icon is selected from the toolbar.
        mDrawerLayout.openDrawer(GravityCompat.START);
        return true;
    case R.id.action_setting:
        ActivityUtils.toSettingActivity(this);
        break;/*from ww w . j a  v a  2 s  .  co m*/
    case R.id.action_night:
        int uiMode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
        switch (uiMode) {
        case Configuration.UI_MODE_NIGHT_NO://??
            SPUtils.put(DailyActivity.this, Constant.KEY_NIGHT, true);
            getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);
            break;
        case Configuration.UI_MODE_NIGHT_YES://??
            SPUtils.put(DailyActivity.this, Constant.KEY_NIGHT, false);
            getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);
            break;
        }
        getSupportFragmentManager().getFragments().clear();
        recreate();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:io.github.marktony.espresso.mvp.packages.MainActivity.java

/**
 * Handle different items of the navigation drawer
 * @param item The selected item./*from w w  w  .  j  av a  2 s  .  c om*/
 * @return Selected or not.
 */
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {

    int id = item.getItemId();

    if (id == R.id.nav_home) {

        showPackagesFragment();

    } else if (id == R.id.nav_companies) {

        showCompaniesFragment();

    } else if (id == R.id.nav_switch_theme) {

        drawer.addDrawerListener(new DrawerLayout.DrawerListener() {
            @Override
            public void onDrawerSlide(View drawerView, float slideOffset) {

            }

            @Override
            public void onDrawerOpened(View drawerView) {

            }

            @Override
            public void onDrawerClosed(View drawerView) {
                SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
                if ((getResources().getConfiguration().uiMode
                        & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES) {
                    sp.edit().putBoolean(SettingsUtil.KEY_NIGHT_MODE, false).apply();
                    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
                } else {
                    sp.edit().putBoolean(SettingsUtil.KEY_NIGHT_MODE, true).apply();
                    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
                }
                getWindow().setWindowAnimations(R.style.WindowAnimationFadeInOut);
                recreate();
            }

            @Override
            public void onDrawerStateChanged(int newState) {

            }
        });

    } else if (id == R.id.nav_settings) {

        Intent intent = new Intent(MainActivity.this, PrefsActivity.class);
        intent.putExtra(PrefsActivity.EXTRA_FLAG, PrefsActivity.FLAG_SETTINGS);
        startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(this).toBundle());

    } else if (id == R.id.nav_about) {

        Intent intent = new Intent(MainActivity.this, PrefsActivity.class);
        intent.putExtra(PrefsActivity.EXTRA_FLAG, PrefsActivity.FLAG_ABOUT);
        startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(this).toBundle());

    }

    drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

From source file:com.bilibili.magicasakura.utils.ThemeUtils.java

public static Resources updateNightMode(Resources resource, boolean on) {
    DisplayMetrics dm = resource.getDisplayMetrics();
    Configuration config = resource.getConfiguration();
    final int uiModeNightMaskOrigin = config.uiMode &= ~Configuration.UI_MODE_TYPE_MASK;
    final int uiModeNightMaskNew = on ? Configuration.UI_MODE_NIGHT_YES : Configuration.UI_MODE_NIGHT_NO;
    if (uiModeNightMaskOrigin != uiModeNightMaskNew) {
        config.uiMode &= ~Configuration.UI_MODE_NIGHT_MASK;
        config.uiMode |= uiModeNightMaskNew;
        resource.updateConfiguration(config, dm);
    }//from   ww w.  j av a  2s .c  om
    return resource;
}

From source file:org.bottiger.podcast.utils.UIUtils.java

public static boolean isInNightMode(@NonNull Resources argResources) {

    if (AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES)
        return true;

    if (AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_NO)
        return false;

    int currentNightMode = argResources.getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;

    switch (currentNightMode) {
    case Configuration.UI_MODE_NIGHT_UNDEFINED:
        // We don't know what mode we're in, assume notnight
        return false;
    case Configuration.UI_MODE_NIGHT_NO:
        // Night mode is not active, we're in day time
        return false;
    case Configuration.UI_MODE_NIGHT_YES: {
        // Night mode is active, we're at night!
        //color = (int) (color * 0.2);
        //color = darken(color, 1f);
        return true;
    }/* www  .j  a v a2  s  . com*/
    }

    return false;
}

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

private void init(Context context) {
    shadowDrawable = context.getResources().getDrawable(R.drawable.sheet_shadow);

    containerView = new FrameLayout(context) {

        private int lastNotifyWidth;

        @Override/*from w  ww .  ja  v a  2s. co m*/
        public boolean onInterceptTouchEvent(MotionEvent ev) {
            if (ev.getAction() == MotionEvent.ACTION_DOWN && scrollOffsetY != 0 && ev.getY() < scrollOffsetY) {
                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);
            if (Build.VERSION.SDK_INT >= 21) {
                height -= AndroidUtilities.statusBarHeight;
            }
            int contentSize;
            if (stickerSetCovereds != null) {
                contentSize = AndroidUtilities.dp(48 + 8) + AndroidUtilities.dp(60) * stickerSetCovereds.size()
                        + adapter.stickersRowCount * AndroidUtilities.dp(82);
            } else {
                contentSize = AndroidUtilities.dp(48 + 48) + Math.max(3,
                        (stickerSet != null ? (int) Math.ceil(stickerSet.documents.size() / 5.0f) : 0))
                        * AndroidUtilities.dp(82) + backgroundPaddingTop;
            }
            int padding = contentSize < (height / 5 * 3.2) ? 0 : (height / 5 * 2);
            if (padding != 0 && contentSize < height) {
                padding -= (height - contentSize);
            }
            if (padding == 0) {
                padding = backgroundPaddingTop;
            }
            if (stickerSetCovereds != null) {
                padding += AndroidUtilities.dp(8);
            }
            if (gridView.getPaddingTop() != padding) {
                ignoreLayout = true;
                gridView.setPadding(AndroidUtilities.dp(10), padding, AndroidUtilities.dp(10), 0);
                emptyView.setPadding(0, padding, 0, 0);
                ignoreLayout = false;
            }
            super.onMeasure(widthMeasureSpec,
                    MeasureSpec.makeMeasureSpec(Math.min(contentSize, height), MeasureSpec.EXACTLY));
        }

        @Override
        protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
            if (lastNotifyWidth != right - left) {
                lastNotifyWidth = right - left;
                if (adapter != null && stickerSetCovereds != null) {
                    adapter.notifyDataSetChanged();
                }
            }
            super.onLayout(changed, left, top, right, bottom);
            updateLayout();
        }

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

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

    titleTextView = new TextView(context);
    titleTextView.setLines(1);
    titleTextView.setSingleLine(true);
    titleTextView.setTextColor(
            ContextCompat.getColor(context, R.color.primary_text) /*Theme.STICKERS_SHEET_TITLE_TEXT_COLOR*/);
    titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
    titleTextView.setEllipsize(TextUtils.TruncateAt.MIDDLE);
    titleTextView.setPadding(AndroidUtilities.dp(18), 0, AndroidUtilities.dp(18), 0);
    titleTextView.setGravity(Gravity.CENTER_VERTICAL);
    titleTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    containerView.addView(titleTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48));
    titleTextView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });

    shadow[0] = new View(context);
    shadow[0].setBackgroundResource(R.drawable.header_shadow);
    shadow[0].setAlpha(0.0f);
    shadow[0].setVisibility(View.INVISIBLE);
    shadow[0].setTag(1);
    containerView.addView(shadow[0],
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3, Gravity.TOP | Gravity.LEFT, 0, 48, 0, 0));

    gridView = new RecyclerListView(context) {
        @Override
        public boolean onInterceptTouchEvent(MotionEvent event) {
            boolean result = StickerPreviewViewer.getInstance().onInterceptTouchEvent(event, gridView, 0);
            return super.onInterceptTouchEvent(event) || result;
        }

        @Override
        public void requestLayout() {
            if (ignoreLayout) {
                return;
            }
            super.requestLayout();
        }
    };
    gridView.setTag(14);
    gridView.setLayoutManager(layoutManager = new GridLayoutManager(getContext(), 5));
    layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
        @Override
        public int getSpanSize(int position) {
            if (stickerSetCovereds != null && adapter.cache.get(position) instanceof Integer
                    || position == adapter.totalItems) {
                return adapter.stickersPerRow;
            }
            return 1;
        }
    });
    gridView.setAdapter(adapter = new GridAdapter(context));
    gridView.setVerticalScrollBarEnabled(false);
    gridView.addItemDecoration(new RecyclerView.ItemDecoration() {
        @Override
        public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
            outRect.left = 0;
            outRect.right = 0;
            outRect.bottom = 0;
            outRect.top = 0;
        }
    });
    gridView.setPadding(AndroidUtilities.dp(10), 0, AndroidUtilities.dp(10), 0);
    gridView.setClipToPadding(false);
    gridView.setEnabled(true);
    gridView.setGlowColor(0xfff5f6f7);
    gridView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return StickerPreviewViewer.getInstance().onTouch(event, gridView, 0, stickersOnItemClickListener);
        }
    });
    gridView.setOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            updateLayout();
        }
    });
    stickersOnItemClickListener = new RecyclerListView.OnItemClickListener() {
        @Override
        public void onItemClick(View view, int position) {
            if (stickerSetCovereds != null) {
                TLRPC.StickerSetCovered pack = adapter.positionsToSets.get(position);
                if (pack != null) {
                    dismiss();
                    TLRPC.TL_inputStickerSetID inputStickerSetID = new TLRPC.TL_inputStickerSetID();
                    inputStickerSetID.access_hash = pack.set.access_hash;
                    inputStickerSetID.id = pack.set.id;
                    StickersAlert alert = new StickersAlert(parentActivity, parentFragment, inputStickerSetID,
                            null, null);
                    alert.show();
                }
            } else {
                if (stickerSet == null || position < 0 || position >= stickerSet.documents.size()) {
                    return;
                }
                selectedSticker = stickerSet.documents.get(position);

                boolean set = false;
                for (int a = 0; a < selectedSticker.attributes.size(); a++) {
                    TLRPC.DocumentAttribute attribute = selectedSticker.attributes.get(a);
                    if (attribute instanceof TLRPC.TL_documentAttributeSticker) {
                        if (attribute.alt != null && attribute.alt.length() > 0) {
                            stickerEmojiTextView.setText(Emoji.replaceEmoji(attribute.alt,
                                    stickerEmojiTextView.getPaint().getFontMetricsInt(),
                                    AndroidUtilities.dp(30), false));
                            set = true;
                        }
                        break;
                    }
                }
                if (!set) {
                    stickerEmojiTextView
                            .setText(Emoji.replaceEmoji(StickersQuery.getEmojiForSticker(selectedSticker.id),
                                    stickerEmojiTextView.getPaint().getFontMetricsInt(),
                                    AndroidUtilities.dp(30), false));
                }

                stickerImageView.getImageReceiver().setImage(selectedSticker, null,
                        selectedSticker.thumb.location, null, "webp", true);
                FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) stickerPreviewLayout
                        .getLayoutParams();
                layoutParams.topMargin = scrollOffsetY;
                stickerPreviewLayout.setLayoutParams(layoutParams);
                stickerPreviewLayout.setVisibility(View.VISIBLE);
                AnimatorSet animatorSet = new AnimatorSet();
                animatorSet.playTogether(ObjectAnimator.ofFloat(stickerPreviewLayout, "alpha", 0.0f, 1.0f));
                animatorSet.setDuration(200);
                animatorSet.start();
            }
        }
    };
    gridView.setOnItemClickListener(stickersOnItemClickListener);
    containerView.addView(gridView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 48, 0, 48));

    emptyView = new FrameLayout(context) {
        @Override
        public void requestLayout() {
            if (ignoreLayout) {
                return;
            }
            super.requestLayout();
        }
    };
    containerView.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 0, 0, 48));
    gridView.setEmptyView(emptyView);
    emptyView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });

    ProgressBar progressView = new ProgressBar(context);
    emptyView.addView(progressView,
            LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));

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

    pickerBottomLayout = new PickerBottomLayout(context, false);
    containerView.addView(pickerBottomLayout,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.BOTTOM));
    pickerBottomLayout.cancelButton.setPadding(AndroidUtilities.dp(18), 0, AndroidUtilities.dp(18), 0);
    pickerBottomLayout.cancelButton.setTextColor(Theme.STICKERS_SHEET_CLOSE_TEXT_COLOR);
    pickerBottomLayout.cancelButton.setText(LocaleController.getString("Close", R.string.Close).toUpperCase());
    pickerBottomLayout.cancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            dismiss();
        }
    });
    pickerBottomLayout.doneButton.setPadding(AndroidUtilities.dp(18), 0, AndroidUtilities.dp(18), 0);
    pickerBottomLayout.doneButtonBadgeTextView.setBackgroundResource(R.drawable.stickercounter);

    stickerPreviewLayout = new FrameLayout(context);
    if ((context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_YES) != 0) {
        stickerPreviewLayout.setBackgroundColor(
                0x00ffffff & ContextCompat.getColor(context, R.color.card_background) | 0xdf000000);
    } else {
        stickerPreviewLayout.setBackgroundColor(0xdfffffff);
    }
    stickerPreviewLayout.setVisibility(View.GONE);
    stickerPreviewLayout.setSoundEffectsEnabled(false);
    containerView.addView(stickerPreviewLayout,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    stickerPreviewLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            hidePreview();
        }
    });

    ImageView closeButton = new ImageView(context);
    closeButton.setImageResource(R.drawable.delete_reply);
    closeButton.setScaleType(ImageView.ScaleType.CENTER);
    if (Build.VERSION.SDK_INT >= 21) {
        closeButton.setBackgroundDrawable(Theme.createBarSelectorDrawable(Theme.INPUT_FIELD_SELECTOR_COLOR));
    }
    stickerPreviewLayout.addView(closeButton, LayoutHelper.createFrame(48, 48, Gravity.RIGHT | Gravity.TOP));
    closeButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            hidePreview();
        }
    });

    stickerImageView = new BackupImageView(context);
    stickerImageView.setAspectFit(true);
    stickerPreviewLayout.addView(stickerImageView);

    stickerEmojiTextView = new TextView(context);
    stickerEmojiTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 30);
    stickerEmojiTextView.setGravity(Gravity.BOTTOM | Gravity.RIGHT);
    stickerPreviewLayout.addView(stickerEmojiTextView);

    previewSendButton = new TextView(context);
    previewSendButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    previewSendButton.setTextColor(Theme.STICKERS_SHEET_SEND_TEXT_COLOR);
    previewSendButton.setGravity(Gravity.CENTER);
    previewSendButton.setBackgroundColor(ContextCompat.getColor(context, R.color.background));
    previewSendButton.setPadding(AndroidUtilities.dp(29), 0, AndroidUtilities.dp(29), 0);
    previewSendButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    stickerPreviewLayout.addView(previewSendButton,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.BOTTOM | Gravity.LEFT));
    previewSendButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            delegate.onStickerSelected(selectedSticker);
            dismiss();
        }
    });

    previewSendButtonShadow = new View(context);
    previewSendButtonShadow.setBackgroundResource(R.drawable.header_shadow_reverse);
    stickerPreviewLayout.addView(previewSendButtonShadow,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3, Gravity.BOTTOM | Gravity.LEFT, 0, 0, 0, 48));
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.emojiDidLoaded);

    updateFields();
    updateSendButton();
    adapter.notifyDataSetChanged();
}