List of usage examples for java.lang Class getField
@CallerSensitive public Field getField(String name) throws NoSuchFieldException, SecurityException
From source file:com.imalu.alyou.activity.ChatActivity.java
/** * ?gridview?view/*from www . j av a2 s. c om*/ * * @param i * @return */ private View getGridChildView(int i) { View view = View.inflate(this, R.layout.expression_gridview, null); ExpandGridView gv = (ExpandGridView) view.findViewById(R.id.gridview); List<String> list = new ArrayList<String>(); if (i == 1) { List<String> list1 = reslist.subList(0, 20); list.addAll(list1); } else if (i == 2) { list.addAll(reslist.subList(20, reslist.size())); } list.add("delete_expression"); final ExpressionAdapter expressionAdapter = new ExpressionAdapter(this, 1, list); gv.setAdapter(expressionAdapter); gv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String filename = expressionAdapter.getItem(position); try { // ???? // ????? if (buttonSetModeKeyboard.getVisibility() != View.VISIBLE) { if (filename != "delete_expression") { // ? // ????SmileUtils Class clz = Class.forName("com.imalu.alyou.utils.SmileUtils"); Field field = clz.getField(filename); mEditTextContent .append(SmileUtils.getSmiledText(ChatActivity.this, (String) field.get(null))); } else { // if (!TextUtils.isEmpty(mEditTextContent.getText())) { int selectionStart = mEditTextContent.getSelectionStart();// ?? if (selectionStart > 0) { String body = mEditTextContent.getText().toString(); String tempStr = body.substring(0, selectionStart); int i = tempStr.lastIndexOf("[");// ??? if (i != -1) { CharSequence cs = tempStr.substring(i, selectionStart); if (SmileUtils.containsKey(cs.toString())) mEditTextContent.getEditableText().delete(i, selectionStart); else mEditTextContent.getEditableText().delete(selectionStart - 1, selectionStart); } else { mEditTextContent.getEditableText().delete(selectionStart - 1, selectionStart); } } } } } } catch (Exception e) { } } }); return view; }
From source file:com.lnpdit.chatuidemo.activity.ChatActivity.java
/** * ?gridview?view/*from w w w . ja v a2 s . c o m*/ * * @param i * @return */ private View getGridChildView(int i) { View view = View.inflate(this, R.layout.expression_gridview, null); ExpandGridView gv = (ExpandGridView) view.findViewById(R.id.gridview); List<String> list = new ArrayList<String>(); if (i == 1) { List<String> list1 = reslist.subList(0, 20); list.addAll(list1); } else if (i == 2) { list.addAll(reslist.subList(20, reslist.size())); } list.add("delete_expression"); final ExpressionAdapter expressionAdapter = new ExpressionAdapter(this, 1, list); gv.setAdapter(expressionAdapter); gv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String filename = expressionAdapter.getItem(position); try { // ???? // ????? if (buttonSetModeKeyboard.getVisibility() != View.VISIBLE) { if (filename != "delete_expression") { // ? // ????SmileUtils Class clz = Class.forName("com.lnpdit.chatuidemo.utils.SmileUtils"); Field field = clz.getField(filename); mEditTextContent .append(SmileUtils.getSmiledText(ChatActivity.this, (String) field.get(null))); } else { // if (!TextUtils.isEmpty(mEditTextContent.getText())) { int selectionStart = mEditTextContent.getSelectionStart();// ?? if (selectionStart > 0) { String body = mEditTextContent.getText().toString(); String tempStr = body.substring(0, selectionStart); int i = tempStr.lastIndexOf("[");// ??? if (i != -1) { CharSequence cs = tempStr.substring(i, selectionStart); if (SmileUtils.containsKey(cs.toString())) mEditTextContent.getEditableText().delete(i, selectionStart); else mEditTextContent.getEditableText().delete(selectionStart - 1, selectionStart); } else { mEditTextContent.getEditableText().delete(selectionStart - 1, selectionStart); } } } } } } catch (Exception e) { } } }); return view; }
From source file:com.safeness.im.activity.ChatActivity.java
/** * ?gridview?view/* w w w. ja v a 2 s. com*/ * * @param i * @return */ private View getGridChildView(int i) { View view = View.inflate(this, R.layout.expression_gridview, null); ExpandGridView gv = (ExpandGridView) view.findViewById(R.id.gridview); List<String> list = new ArrayList<String>(); if (i == 1) { List<String> list1 = reslist.subList(0, 20); list.addAll(list1); } else if (i == 2) { list.addAll(reslist.subList(20, reslist.size())); } list.add("delete_expression"); final ExpressionAdapter expressionAdapter = new ExpressionAdapter(this, 1, list); gv.setAdapter(expressionAdapter); gv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String filename = expressionAdapter.getItem(position); try { // ???? // ????? if (buttonSetModeKeyboard.getVisibility() != View.VISIBLE) { if (filename != "delete_expression") { // ? // ????SmileUtils Class clz = Class.forName("com.safeness.im.utils.SmileUtils"); Field field = clz.getField(filename); mEditTextContent .append(SmileUtils.getSmiledText(ChatActivity.this, (String) field.get(null))); } else { // if (!TextUtils.isEmpty(mEditTextContent.getText())) { int selectionStart = mEditTextContent.getSelectionStart();// ?? if (selectionStart > 0) { String body = mEditTextContent.getText().toString(); String tempStr = body.substring(0, selectionStart); int i = tempStr.lastIndexOf("[");// ??? if (i != -1) { CharSequence cs = tempStr.substring(i, selectionStart); if (SmileUtils.containsKey(cs.toString())) mEditTextContent.getEditableText().delete(i, selectionStart); else mEditTextContent.getEditableText().delete(selectionStart - 1, selectionStart); } else { mEditTextContent.getEditableText().delete(selectionStart - 1, selectionStart); } } } } } } catch (Exception e) { } } }); return view; }
From source file:com.xxjwd.chat.ChatActivity.java
/** * ?gridview?view/*from w w w .ja va 2s . c o m*/ * * @param i * @return */ private View getGridChildView(int i) { View view = View.inflate(this, R.layout.chat_expression_gridview, null); ExpandGridView gv = (ExpandGridView) view.findViewById(R.id.gridview); List<String> list = new ArrayList<String>(); if (i == 1) { List<String> list1 = reslist.subList(0, 20); list.addAll(list1); } else if (i == 2) { list.addAll(reslist.subList(20, reslist.size())); } list.add("delete_expression"); final ExpressionAdapter expressionAdapter = new ExpressionAdapter(this, 1, list); gv.setAdapter(expressionAdapter); gv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String filename = expressionAdapter.getItem(position); try { // ???? // ????? if (buttonSetModeKeyboard.getVisibility() != View.VISIBLE) { if (filename != "delete_expression") { // ? // ????SmileUtils Class clz = Class.forName("com.easemob.chatuidemo.utils.SmileUtils"); Field field = clz.getField(filename); mEditTextContent.append(SmileUtils.getSmiledText(ChatActivity.this, (String) field.get(null))); } else { // if (!TextUtils.isEmpty(mEditTextContent.getText())) { int selectionStart = mEditTextContent.getSelectionStart();// ?? if (selectionStart > 0) { String body = mEditTextContent.getText().toString(); String tempStr = body.substring(0, selectionStart); int i = tempStr.lastIndexOf("[");// ??? if (i != -1) { CharSequence cs = tempStr.substring(i, selectionStart); if (SmileUtils.containsKey(cs.toString())) mEditTextContent.getEditableText().delete(i, selectionStart); else mEditTextContent.getEditableText().delete(selectionStart - 1, selectionStart); } else { mEditTextContent.getEditableText().delete(selectionStart - 1, selectionStart); } } } } } } catch (Exception e) { } } }); return view; }
From source file:com.xie.javacase.json.JSONObject.java
/** * Construct a JSONObject from an Object, using reflection to find the * public members. The resulting JSONObject's keys will be the strings * from the names array, and the values will be the field values associated * with those keys in the object. If a key is not found or not visible, * then it will not be copied into the new JSONObject. * @param object An object that has fields that should be used to make a * JSONObject.//from w ww . j a va 2s . com * @param names An array of strings, the names of the fields to be obtained * from the object. */ public JSONObject(Object object, String names[]) { this(); Class c = object.getClass(); for (int i = 0; i < names.length; i += 1) { String name = names[i]; try { putOpt(name, c.getField(name).get(object)); } catch (Exception e) { /* forget about it */ } } }
From source file:org.freebxml.omar.common.BindingUtility.java
public String getObjectTypeId(String rimClassName) throws JAXRException { String objectTypeId = null;//from w w w .j a v a 2 s . com try { Class clazz = this.getClass(); Field field = clazz.getField("CANONICAL_OBJECT_TYPE_ID_" + rimClassName); Object obj = field.get(this); objectTypeId = (String) obj; } catch (NoSuchFieldException e) { throw new JAXRException(e); } catch (SecurityException e) { throw new JAXRException(e); } catch (IllegalAccessException e) { throw new JAXRException(e); } return objectTypeId; }
From source file:com.parttime.activity.ChatActivity.java
/** * ?gridview?view//w w w . ja v a2s . c om * * @param i * @return */ private View getGridChildView(int i) { View view = View.inflate(this, R.layout.expression_gridview, null); ExpandGridView gv = (ExpandGridView) view.findViewById(R.id.gridview); List<String> list = new ArrayList<String>(); if (i == 1) { List<String> list1 = reslist.subList(0, 20); list.addAll(list1); } else if (i == 2) { list.addAll(reslist.subList(20, reslist.size())); } list.add("delete_expression"); final ExpressionAdapter expressionAdapter = new ExpressionAdapter(this, 1, list); gv.setAdapter(expressionAdapter); gv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String filename = expressionAdapter.getItem(position); try { // ???? // ????? if (buttonSetModeKeyboard.getVisibility() != View.VISIBLE) { if (filename != "delete_expression") { // ? // ????SmileUtils Class clz = Class.forName("com.easemob.applib.utils.SmileUtils"); Field field = clz.getField(filename); mEditTextContent .append(SmileUtils.getSmiledText(ChatActivity.this, (String) field.get(null))); } else { // if (!TextUtils.isEmpty(mEditTextContent.getText())) { int selectionStart = mEditTextContent.getSelectionStart();// ?? if (selectionStart > 0) { String body = mEditTextContent.getText().toString(); String tempStr = body.substring(0, selectionStart); int i = tempStr.lastIndexOf("[");// ??? if (i != -1) { CharSequence cs = tempStr.substring(i, selectionStart); if (SmileUtils.containsKey(cs.toString())) mEditTextContent.getEditableText().delete(i, selectionStart); else mEditTextContent.getEditableText().delete(selectionStart - 1, selectionStart); } else { mEditTextContent.getEditableText().delete(selectionStart - 1, selectionStart); } } } } } } catch (Exception e) { } } }); return view; }
From source file:com.wenwen.chatuidemo.activity.ChatActivity.java
/** * ?gridview?view/*from w w w. j av a 2 s. c o m*/ * * @param i * @return */ private View getGridChildView(int i) { View view = View.inflate(this, R.layout.expression_gridview, null); ExpandGridView gv = (ExpandGridView) view.findViewById(R.id.gridview); List<String> list = new ArrayList<String>(); if (i == 1) { List<String> list1 = reslist.subList(0, 20); list.addAll(list1); } else if (i == 2) { list.addAll(reslist.subList(20, reslist.size())); } list.add("delete_expression"); final ExpressionAdapter expressionAdapter = new ExpressionAdapter(this, 1, list); gv.setAdapter(expressionAdapter); gv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String filename = expressionAdapter.getItem(position); try { // ???? // ????? if (buttonSetModeKeyboard.getVisibility() != View.VISIBLE) { if (filename != "delete_expression") { // ? // ????SmileUtils Class clz = Class.forName("com.wenwen.chatuidemo.utils.SmileUtils"); Field field = clz.getField(filename); mEditTextContent .append(SmileUtils.getSmiledText(ChatActivity.this, (String) field.get(null))); } else { // if (!TextUtils.isEmpty(mEditTextContent.getText())) { int selectionStart = mEditTextContent.getSelectionStart();// ?? if (selectionStart > 0) { String body = mEditTextContent.getText().toString(); String tempStr = body.substring(0, selectionStart); int i = tempStr.lastIndexOf("[");// ??? if (i != -1) { CharSequence cs = tempStr.substring(i, selectionStart); if (SmileUtils.containsKey(cs.toString())) mEditTextContent.getEditableText().delete(i, selectionStart); else mEditTextContent.getEditableText().delete(selectionStart - 1, selectionStart); } else { mEditTextContent.getEditableText().delete(selectionStart - 1, selectionStart); } } } } } } catch (Exception e) { } } }); return view; }
From source file:com.siso.app.chat.ui.ChatActivity.java
/** * ?gridview?view/*from w w w .jav a 2s .c o m*/ * * @param i * @return */ private View getGridChildView(int i) { View view = View.inflate(this, R.layout.expression_gridview, null); ExpandGridView gv = (ExpandGridView) view.findViewById(R.id.gridview); List<String> list = new ArrayList<String>(); if (i == 1) { List<String> list1 = reslist.subList(0, 20); list.addAll(list1); } else if (i == 2) { list.addAll(reslist.subList(20, reslist.size())); } list.add("delete_expression"); final ExpressionAdapter expressionAdapter = new ExpressionAdapter(this, 1, list); gv.setAdapter(expressionAdapter); gv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String filename = expressionAdapter.getItem(position); try { // ???? // ????? if (buttonSetModeKeyboard.getVisibility() != View.VISIBLE) { if (filename != "delete_expression") { // ? // ????SmileUtils Class clz = Class.forName("com.siso.app.chat.utils.SmileUtils"); Field field = clz.getField(filename); mEditTextContent .append(SmileUtils.getSmiledText(ChatActivity.this, (String) field.get(null))); } else { // if (!TextUtils.isEmpty(mEditTextContent.getText())) { int selectionStart = mEditTextContent.getSelectionStart();// ?? if (selectionStart > 0) { String body = mEditTextContent.getText().toString(); String tempStr = body.substring(0, selectionStart); int i = tempStr.lastIndexOf("[");// ??? if (i != -1) { CharSequence cs = tempStr.substring(i, selectionStart); if (SmileUtils.containsKey(cs.toString())) mEditTextContent.getEditableText().delete(i, selectionStart); else mEditTextContent.getEditableText().delete(selectionStart - 1, selectionStart); } else { mEditTextContent.getEditableText().delete(selectionStart - 1, selectionStart); } } } } } } catch (Exception e) { } } }); return view; }
From source file:org.red5.io.amf3.Input.java
@SuppressWarnings("unchecked") public Object readObject(Deserializer deserializer) { int type = readAMF3Integer(); if ((type & 1) == 0) { // Reference return getReference(type >> 1); }/*w ww. j a v a 2 s .c om*/ type >>= 1; List<String> attributes = null; String className; Object result = null; boolean inlineClass = (type & 1) == 1; if (!inlineClass) { ClassReference info = classReferences.get(type >> 1); className = info.className; attributes = info.attributeNames; type = info.type; if (attributes != null) { type |= attributes.size() << 2; } } else { type >>= 1; className = readString(); } amf3_mode += 1; Object instance = newInstance(className); Map<String, Object> properties = null; PendingObject pending = new PendingObject(); int tempRefId = storeReference(pending); switch (type & 0x03) { case AMF3.TYPE_OBJECT_PROPERTY: // Load object properties into map int count = type >> 2; properties = new ObjectMap<String, Object>(); if (attributes == null) { attributes = new ArrayList<String>(count); for (int i = 0; i < count; i++) { attributes.add(readString()); } classReferences.add(new ClassReference(className, AMF3.TYPE_OBJECT_PROPERTY, attributes)); } for (int i = 0; i < count; i++) { String name = attributes.get(i); properties.put(name, deserializer.deserialize(this, getPropertyType(instance, name))); } break; case AMF3.TYPE_OBJECT_EXTERNALIZABLE: // Use custom class to deserialize the object if ("".equals(className)) throw new RuntimeException("need a classname to load an externalizable object"); result = newInstance(className); if (result == null) throw new RuntimeException("could not instantiate class"); if (!(result instanceof IExternalizable)) throw new RuntimeException("the class must implement the IExternalizable interface"); classReferences.add(new ClassReference(className, AMF3.TYPE_OBJECT_EXTERNALIZABLE, null)); storeReference(tempRefId, result); ((IExternalizable) result).readExternal(new DataInput(this, deserializer)); break; case AMF3.TYPE_OBJECT_VALUE: // Load object properties into map classReferences.add(new ClassReference(className, AMF3.TYPE_OBJECT_VALUE, null)); properties = new ObjectMap<String, Object>(); attributes = new LinkedList<String>(); String key = readString(); while (!"".equals(key)) { attributes.add(key); Object value = deserializer.deserialize(this, getPropertyType(instance, key)); properties.put(key, value); key = readString(); } break; default: case AMF3.TYPE_OBJECT_PROXY: if ("".equals(className)) throw new RuntimeException("need a classname to load an externalizable object"); result = newInstance(className); if (result == null) throw new RuntimeException("could not instantiate class"); if (!(result instanceof IExternalizable)) throw new RuntimeException("the class must implement the IExternalizable interface"); classReferences.add(new ClassReference(className, AMF3.TYPE_OBJECT_PROXY, null)); storeReference(tempRefId, result); ((IExternalizable) result).readExternal(new DataInput(this, deserializer)); } amf3_mode -= 1; if (result == null) { // Create result object based on classname if ("".equals(className)) { // "anonymous" object, load as Map // Resolve circular references for (Map.Entry<String, Object> entry : properties.entrySet()) { if (entry.getValue() == pending) { entry.setValue(properties); } } storeReference(tempRefId, properties); result = properties; } else if ("RecordSet".equals(className)) { // TODO: how are RecordSet objects encoded? throw new RuntimeException("Objects of type RecordSet not supported yet."); } else if ("RecordSetPage".equals(className)) { // TODO: how are RecordSetPage objects encoded? throw new RuntimeException("Objects of type RecordSetPage not supported yet."); } else { // Apply properties to object result = newInstance(className); if (result != null) { storeReference(tempRefId, result); Class resultClass = result.getClass(); pending.resolveProperties(result); for (Map.Entry<String, Object> entry : properties.entrySet()) { // Resolve circular references final String key = entry.getKey(); Object value = entry.getValue(); if (value == pending) { value = result; } if (value instanceof PendingObject) { // Deferr setting of value until real object is created ((PendingObject) value).addPendingProperty(result, resultClass, key); continue; } try { try { final Field field = resultClass.getField(key); final Class fieldType = field.getType(); if (!fieldType.isAssignableFrom(value.getClass())) { value = ConversionUtils.convert(value, fieldType); } field.set(result, value); } catch (Exception e) { BeanUtils.setProperty(result, key, value); } } catch (Exception e) { log.error("Error mapping property: {} ({})", key, value); } } } // else fall through } } return result; }