use of cn.hadcn.keyboard.emoticon.EmoticonSetBean in project ChatKeyboard by CPPAlien.
the class ChatKeyboardLayout method getBuilder.
private EmoticonsKeyboardBuilder getBuilder(Context context) {
if (context == null) {
throw new RuntimeException("Context is null, cannot create db helper");
}
EmoticonDBHelper emoticonDbHelper = new EmoticonDBHelper(context);
ArrayList<EmoticonSetBean> mEmoticonSetBeanList = emoticonDbHelper.queryAllEmoticonSet();
emoticonDbHelper.cleanup();
return new EmoticonsKeyboardBuilder.Builder().setEmoticonSetBeanList(mEmoticonSetBeanList).build();
}
use of cn.hadcn.keyboard.emoticon.EmoticonSetBean in project ChatKeyboard by CPPAlien.
the class EmoticonDBHelper method queryEmoticonSet.
public synchronized ArrayList<EmoticonSetBean> queryEmoticonSet(String sql) {
SQLiteDatabase db = mOpenDbHelper.getReadableDatabase();
Cursor cursor = null;
try {
cursor = db.rawQuery(sql, null);
int count = cursor.getCount();
ArrayList<EmoticonSetBean> beanList = new ArrayList<EmoticonSetBean>();
if (count > 0) {
cursor.moveToFirst();
for (int i = 0; i < count; i++) {
String name = cursor.getString(cursor.getColumnIndex(TableColumns.EmoticonSetColumns.NAME));
int line = cursor.getInt(cursor.getColumnIndex(TableColumns.EmoticonSetColumns.LINE));
int row = cursor.getInt(cursor.getColumnIndex(TableColumns.EmoticonSetColumns.ROW));
String iconUri = cursor.getString(cursor.getColumnIndex(TableColumns.EmoticonSetColumns.ICON_URI));
boolean isshowdelbtn = cursor.getInt(cursor.getColumnIndex(TableColumns.EmoticonSetColumns.IS_SHOW_DEL_BTN)) == 1;
int itempadding = cursor.getInt(cursor.getColumnIndex(TableColumns.EmoticonSetColumns.ITEM_PADDING));
int horizontalspacing = cursor.getInt(cursor.getColumnIndex(TableColumns.EmoticonSetColumns.HORIZONTAL_SPACING));
int verticalSpacing = cursor.getInt(cursor.getColumnIndex(TableColumns.EmoticonSetColumns.VERTICAL_SPACING));
boolean isShownName = cursor.getInt(cursor.getColumnIndex(TableColumns.EmoticonSetColumns.IS_SHOWN_NAME)) == 1;
ArrayList<EmoticonBean> emoticonList = null;
if (!TextUtils.isEmpty(name)) {
String sqlGetEmoticonBean = "select * from " + TABLE_NAME_EMOTICONS + " where " + TableColumns.EmoticonColumns.EMOTICON_SET_NAME + " = '" + name + "'";
emoticonList = queryEmoticonBeanList(sqlGetEmoticonBean);
}
int pageCount = 0;
if (emoticonList != null) {
int del = isshowdelbtn ? 1 : 0;
int everyPageMaxSum = row * line - del;
pageCount = (int) Math.ceil((double) emoticonList.size() / everyPageMaxSum);
}
EmoticonSetBean bean = new EmoticonSetBean(name, line, row, iconUri, isshowdelbtn, isShownName, itempadding, horizontalspacing, verticalSpacing, emoticonList);
beanList.add(bean);
cursor.moveToNext();
}
return beanList;
}
} catch (SQLiteException e) {
Log.e(TAG, "query failed", e);
} finally {
if (cursor != null)
cursor.close();
}
return null;
}
use of cn.hadcn.keyboard.emoticon.EmoticonSetBean in project ChatKeyboard by CPPAlien.
the class EmoticonsPageView method updateView.
private void updateView() {
if (mEmoticonSetBeanList == null)
return;
if (mEmoticonsViewPagerAdapter == null) {
mEmoticonsViewPagerAdapter = new EmoticonsViewPagerAdapter();
setAdapter(mEmoticonsViewPagerAdapter);
setOnPageChangeListener(new PageChangeListener());
}
int screenWidth = Utils.getDisplayWidthPixels(mContext);
int maxPagerHeight = mHeight;
mEmoticonPageViews.clear();
mEmoticonsViewPagerAdapter.notifyDataSetChanged();
for (EmoticonSetBean bean : mEmoticonSetBeanList) {
List<EmoticonBean> emoticonList = bean.getEmoticonList();
if (emoticonList != null) {
int emoticonSetSum = emoticonList.size();
int row = bean.getRow();
int line = bean.getLine();
int del = bean.isShowDelBtn() ? 1 : 0;
int everyPageMaxSum = row * line - del;
int pageCount = getPageCount(bean);
mMaxEmoticonSetPageCount = Math.max(mMaxEmoticonSetPageCount, pageCount);
int start = 0;
int end = everyPageMaxSum > emoticonSetSum ? emoticonSetSum : everyPageMaxSum;
RelativeLayout.LayoutParams gridParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
gridParams.addRule(SoftListenLayout.CENTER_VERTICAL);
int itemHeight = Math.min((screenWidth - (bean.getRow() - 1) * Utils.dip2px(mContext, bean.getHorizontalSpacing())) / bean.getRow(), (maxPagerHeight - (bean.getLine() - 1) * Utils.dip2px(mContext, bean.getVerticalSpacing())) / bean.getLine());
for (int i = 0; i < pageCount; i++) {
RelativeLayout rl = new RelativeLayout(mContext);
GridView gridView = new GridView(mContext);
gridView.setNumColumns(bean.getRow());
gridView.setBackgroundColor(Color.TRANSPARENT);
gridView.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
gridView.setCacheColorHint(0);
gridView.setHorizontalSpacing(Utils.dip2px(mContext, bean.getHorizontalSpacing()));
gridView.setVerticalSpacing(Utils.dip2px(mContext, bean.getVerticalSpacing()));
gridView.setSelector(new ColorDrawable(Color.TRANSPARENT));
gridView.setGravity(Gravity.CENTER);
gridView.setVerticalScrollBarEnabled(false);
List<EmoticonBean> list = new ArrayList<>();
for (int j = start; j < end; j++) {
list.add(emoticonList.get(j));
}
if (bean.isShowDelBtn()) {
int count = bean.getLine() * bean.getRow();
while (list.size() < count - 1) {
list.add(null);
}
list.add(new EmoticonBean(EmoticonBean.FACE_TYPE_DEL, "drawable://icon_del", null, null));
} else {
int count = bean.getLine() * bean.getRow();
while (list.size() < count) {
list.add(null);
}
}
EmoticonsAdapter adapter = new EmoticonsAdapter(mContext, list, bean.isShownName());
adapter.setHeight(itemHeight, Utils.dip2px(mContext, bean.getItemPadding()));
gridView.setAdapter(adapter);
rl.addView(gridView, gridParams);
mEmoticonPageViews.add(rl);
adapter.setOnItemListener(this);
start = everyPageMaxSum + i * everyPageMaxSum;
end = everyPageMaxSum + (i + 1) * everyPageMaxSum;
if (end >= emoticonSetSum) {
end = emoticonSetSum;
}
}
}
}
mEmoticonsViewPagerAdapter.notifyDataSetChanged();
}
use of cn.hadcn.keyboard.emoticon.EmoticonSetBean in project ChatKeyboard by CPPAlien.
the class EmoticonsToolBarView method setEmoticonContents.
public void setEmoticonContents(EmoticonsKeyboardBuilder builder) {
mEmoticonSetBeanList = builder.builder == null ? null : builder.builder.getEmoticonSetBeanList();
if (mEmoticonSetBeanList == null) {
return;
}
int i = 0;
for (EmoticonSetBean bean : mEmoticonSetBeanList) {
View toolBtnView = inflate(mContext, R.layout.emoticonstoolbar_item, null);
ImageView iv_icon = (ImageView) toolBtnView.findViewById(R.id.iv_icon);
LinearLayout.LayoutParams imgParams = new LinearLayout.LayoutParams(Utils.dip2px(mContext, mBtnWidth), LayoutParams.MATCH_PARENT);
iv_icon.setLayoutParams(imgParams);
ly_tool.addView(toolBtnView);
iv_icon.setImageDrawable(EmoticonLoader.getInstance(mContext).getDrawable(bean.getIconUri()));
mToolBtnList.add(iv_icon);
final int finalI = i;
iv_icon.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
if (mItemClickListeners != null && !mItemClickListeners.isEmpty()) {
for (OnToolBarItemClickListener listener : mItemClickListeners) {
listener.onToolBarItemClick(finalI);
}
}
}
});
i++;
}
setToolBtnSelect(0);
}
use of cn.hadcn.keyboard.emoticon.EmoticonSetBean in project ChatKeyboard by CPPAlien.
the class Utils method ParseEmoticons.
public static EmoticonSetBean ParseEmoticons(Context context, String path, EmoticonBase.Scheme scheme) throws IOException, XmlPullParserException {
String arrayParentKey = "EmoticonBean";
EmoticonSetBean emoticonSetBean = new EmoticonSetBean();
ArrayList<EmoticonBean> emoticonList = new ArrayList<>();
emoticonSetBean.setEmoticonList(emoticonList);
EmoticonBean emoticonBeanTemp = null;
EmoticonLoader emoticonLoader = EmoticonLoader.getInstance(context);
InputStream inStream = emoticonLoader.getConfigStream(path, scheme);
if (inStream == null) {
throw new IOException("Read config.xml in emoticon directory failed");
}
boolean isChildCheck = false;
XmlPullParser pullParser = Xml.newPullParser();
pullParser.setInput(inStream, "UTF-8");
int event = pullParser.getEventType();
while (event != XmlPullParser.END_DOCUMENT) {
if (event == XmlPullParser.START_TAG) {
String sKeyName = pullParser.getName();
if (isChildCheck) {
switch(sKeyName) {
case "eventType":
{
String value = pullParser.nextText();
emoticonBeanTemp.setEventType(Integer.parseInt(value));
break;
}
case "iconUri":
{
String value = pullParser.nextText();
emoticonBeanTemp.setIconUri(scheme.toUri(path + "/" + value));
break;
}
case "msgUri":
{
String value = pullParser.nextText();
emoticonBeanTemp.setMsgUri(scheme.toUri(path + "/" + value));
break;
}
case "tag":
{
String value = pullParser.nextText();
emoticonBeanTemp.setTag(value);
break;
}
case "name":
{
String value = pullParser.nextText();
emoticonBeanTemp.setName(value);
break;
}
}
} else {
switch(sKeyName) {
case "name":
{
String value = pullParser.nextText();
emoticonSetBean.setName(value);
break;
}
case "line":
{
String value = pullParser.nextText();
emoticonSetBean.setLine(Integer.parseInt(value));
break;
}
case "row":
{
String value = pullParser.nextText();
emoticonSetBean.setRow(Integer.parseInt(value));
break;
}
case "iconUri":
{
String value = pullParser.nextText();
emoticonSetBean.setIconUri(scheme.toUri(path + "/" + value));
break;
}
case "isShowDelBtn":
{
String value = pullParser.nextText();
emoticonSetBean.setShowDelBtn(Integer.parseInt(value) == 1);
break;
}
case "itemPadding":
{
String value = pullParser.nextText();
emoticonSetBean.setItemPadding(Integer.parseInt(value));
break;
}
case "horizontalSpacing":
{
String value = pullParser.nextText();
emoticonSetBean.setHorizontalSpacing(Integer.parseInt(value));
break;
}
case "verticalSpacing":
{
String value = pullParser.nextText();
emoticonSetBean.setVerticalSpacing(Integer.parseInt(value));
break;
}
case "isShowName":
{
String value = pullParser.nextText();
emoticonSetBean.setIsShownName(Integer.parseInt(value) == 1);
break;
}
}
}
if (sKeyName.equals(arrayParentKey)) {
isChildCheck = true;
emoticonBeanTemp = new EmoticonBean();
}
} else if (event == XmlPullParser.END_TAG) {
String ekeyName = pullParser.getName();
if (isChildCheck && ekeyName.equals(arrayParentKey)) {
isChildCheck = false;
emoticonList.add(emoticonBeanTemp);
}
}
event = pullParser.next();
}
return emoticonSetBean;
}
Aggregations