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; 18 19 import com.android.inputmethod.latin.R; 20 import com.android.inputmethod.latin.utils.ResourceUtils; 21 22 import android.content.res.Resources; 23 import android.support.v4.view.ViewPager; 24 import android.widget.ImageView; 25 import android.widget.LinearLayout; 26 27 public 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 40 public EmojiLayoutParams(Resources res) { 41 final int defaultKeyboardHeight = ResourceUtils.getDefaultKeyboardHeight(res); 42 final int defaultKeyboardWidth = ResourceUtils.getDefaultKeyboardWidth(res); 43 mKeyVerticalGap = (int) res.getFraction(R.fraction.key_bottom_gap_holo, 44 (int) defaultKeyboardHeight, (int) defaultKeyboardHeight); 45 mBottomPadding = (int) res.getFraction(R.fraction.keyboard_bottom_padding_holo, 46 (int) defaultKeyboardHeight, (int) defaultKeyboardHeight); 47 mTopPadding = (int) res.getFraction(R.fraction.keyboard_top_padding_holo, 48 (int) defaultKeyboardHeight, (int) defaultKeyboardHeight); 49 mKeyHorizontalGap = (int) (res.getFraction(R.fraction.key_horizontal_gap_holo, 50 defaultKeyboardWidth, defaultKeyboardWidth)); 51 mEmojiCategoryPageIdViewHeight = 52 (int) (res.getDimension(R.dimen.emoji_category_page_id_height)); 53 final int baseheight = defaultKeyboardHeight - mBottomPadding - mTopPadding 54 + mKeyVerticalGap; 55 mEmojiActionBarHeight = ((int) baseheight) / DEFAULT_KEYBOARD_ROWS 56 - (mKeyVerticalGap - mBottomPadding) / 2; 57 mEmojiPagerHeight = defaultKeyboardHeight - mEmojiActionBarHeight 58 - mEmojiCategoryPageIdViewHeight; 59 mEmojiPagerBottomMargin = 0; 60 mEmojiKeyboardHeight = mEmojiPagerHeight - mEmojiPagerBottomMargin - 1; 61 } 62 63 public void setPagerProperties(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 70 public void setCategoryPageIdViewProperties(LinearLayout ll) { 71 final LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) ll.getLayoutParams(); 72 lp.height = mEmojiCategoryPageIdViewHeight; 73 ll.setLayoutParams(lp); 74 } 75 76 public void setActionBarProperties(LinearLayout ll) { 77 final LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) ll.getLayoutParams(); 78 lp.height = mEmojiActionBarHeight - mBottomPadding; 79 ll.setLayoutParams(lp); 80 } 81 82 public void setKeyProperties(ImageView ib) { 83 final LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) ib.getLayoutParams(); 84 lp.leftMargin = mKeyHorizontalGap / 2; 85 lp.rightMargin = mKeyHorizontalGap / 2; 86 ib.setLayoutParams(lp); 87 } 88 } 89