1 /*
2  * Copyright (C) 2013 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.inputmethod.keyboard.emoji;
18 
19 import android.content.res.Resources;
20 import androidx.viewpager.widget.ViewPager;
21 import android.view.View;
22 import android.widget.LinearLayout;
23 
24 import com.android.inputmethod.latin.R;
25 import com.android.inputmethod.latin.utils.ResourceUtils;
26 
27 final class EmojiLayoutParams {
28     private static final int DEFAULT_KEYBOARD_ROWS = 4;
29 
30     public final int mEmojiPagerHeight;
31     private final int mEmojiPagerBottomMargin;
32     public final int mEmojiKeyboardHeight;
33     private final int mEmojiCategoryPageIdViewHeight;
34     public final int mEmojiActionBarHeight;
35     public final int mKeyVerticalGap;
36     private final int mKeyHorizontalGap;
37     private final int mBottomPadding;
38     private final int mTopPadding;
39 
EmojiLayoutParams(final Resources res)40     public EmojiLayoutParams(final Resources res) {
41         final int defaultKeyboardHeight = ResourceUtils.getDefaultKeyboardHeight(res);
42         final int defaultKeyboardWidth = ResourceUtils.getDefaultKeyboardWidth(res);
43         mKeyVerticalGap = (int) res.getFraction(R.fraction.config_key_vertical_gap_holo,
44                 defaultKeyboardHeight, defaultKeyboardHeight);
45         mBottomPadding = (int) res.getFraction(R.fraction.config_keyboard_bottom_padding_holo,
46                 defaultKeyboardHeight, defaultKeyboardHeight);
47         mTopPadding = (int) res.getFraction(R.fraction.config_keyboard_top_padding_holo,
48                 defaultKeyboardHeight, defaultKeyboardHeight);
49         mKeyHorizontalGap = (int) (res.getFraction(R.fraction.config_key_horizontal_gap_holo,
50                 defaultKeyboardWidth, defaultKeyboardWidth));
51         mEmojiCategoryPageIdViewHeight =
52                 (int) (res.getDimension(R.dimen.config_emoji_category_page_id_height));
53         final int baseheight = defaultKeyboardHeight - mBottomPadding - mTopPadding
54                 + mKeyVerticalGap;
55         mEmojiActionBarHeight = baseheight / DEFAULT_KEYBOARD_ROWS
56                 - (mKeyVerticalGap - mBottomPadding) / 2;
57         mEmojiPagerHeight = defaultKeyboardHeight - mEmojiActionBarHeight
58                 - mEmojiCategoryPageIdViewHeight;
59         mEmojiPagerBottomMargin = 0;
60         mEmojiKeyboardHeight = mEmojiPagerHeight - mEmojiPagerBottomMargin - 1;
61     }
62 
setPagerProperties(final ViewPager vp)63     public void setPagerProperties(final ViewPager vp) {
64         final LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) vp.getLayoutParams();
65         lp.height = mEmojiKeyboardHeight;
66         lp.bottomMargin = mEmojiPagerBottomMargin;
67         vp.setLayoutParams(lp);
68     }
69 
setCategoryPageIdViewProperties(final View v)70     public void setCategoryPageIdViewProperties(final View v) {
71         final LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) v.getLayoutParams();
72         lp.height = mEmojiCategoryPageIdViewHeight;
73         v.setLayoutParams(lp);
74     }
75 
getActionBarHeight()76     public int getActionBarHeight() {
77         return mEmojiActionBarHeight - mBottomPadding;
78     }
79 
setActionBarProperties(final LinearLayout ll)80     public void setActionBarProperties(final LinearLayout ll) {
81         final LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) ll.getLayoutParams();
82         lp.height = getActionBarHeight();
83         ll.setLayoutParams(lp);
84     }
85 
setKeyProperties(final View v)86     public void setKeyProperties(final View v) {
87         final LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) v.getLayoutParams();
88         lp.leftMargin = mKeyHorizontalGap / 2;
89         lp.rightMargin = mKeyHorizontalGap / 2;
90         v.setLayoutParams(lp);
91     }
92 }
93