List of usage examples for java.lang NoSuchFieldException printStackTrace
public void printStackTrace()
From source file:android.support.v7.internal.widget.ListViewCompat.java
public ListViewCompat(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); try {//from w w w . ja va 2 s . c o m mIsChildViewEnabled = AbsListView.class.getDeclaredField("mIsChildViewEnabled"); mIsChildViewEnabled.setAccessible(true); } catch (NoSuchFieldException e) { e.printStackTrace(); } }
From source file:com.bilibili.magicasakura.utils.GradientDrawableUtils.java
@Override protected Drawable inflateDrawable(Context context, XmlPullParser parser, AttributeSet attrs) throws XmlPullParserException, IOException { GradientDrawable gradientDrawable = new GradientDrawable(); inflateGradientRootElement(context, attrs, gradientDrawable); int type;// w w w.ja va 2s. c om final int innerDepth = parser.getDepth() + 1; int depth; while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && ((depth = parser.getDepth()) >= innerDepth || type != XmlPullParser.END_TAG)) { if (type != XmlPullParser.START_TAG) { continue; } if (depth > innerDepth) { continue; } String name = parser.getName(); if (name.equals("size")) { final int width = getAttrDimensionPixelSize(context, attrs, android.R.attr.width); final int height = getAttrDimensionPixelSize(context, attrs, android.R.attr.height); gradientDrawable.setSize(width, height); } else if (name.equals("gradient") && Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) { final float centerX = getAttrFloatOrFraction(context, attrs, android.R.attr.centerX, 0.5f, 1.0f, 1.0f); final float centerY = getAttrFloatOrFraction(context, attrs, android.R.attr.centerY, 0.5f, 1.0f, 1.0f); gradientDrawable.setGradientCenter(centerX, centerY); final boolean useLevel = getAttrBoolean(context, attrs, android.R.attr.useLevel, false); gradientDrawable.setUseLevel(useLevel); final int gradientType = getAttrInt(context, attrs, android.R.attr.type, 0); gradientDrawable.setGradientType(gradientType); final int startColor = getAttrColor(context, attrs, android.R.attr.startColor, Color.TRANSPARENT); final int centerColor = getAttrColor(context, attrs, android.R.attr.centerColor, Color.TRANSPARENT); final int endColor = getAttrColor(context, attrs, android.R.attr.endColor, Color.TRANSPARENT); if (!getAttrHasValue(context, attrs, android.R.attr.centerColor)) { gradientDrawable.setColors(new int[] { startColor, endColor }); } else { gradientDrawable.setColors(new int[] { startColor, centerColor, endColor }); setStGradientPositions(gradientDrawable.getConstantState(), 0.0f, centerX != 0.5f ? centerX : centerY, 1f); } if (gradientType == GradientDrawable.LINEAR_GRADIENT) { int angle = (int) getAttrFloat(context, attrs, android.R.attr.angle, 0.0f); angle %= 360; if (angle % 45 != 0) { throw new XmlPullParserException( "<gradient> tag requires" + "'angle' attribute to " + "be a multiple of 45"); } setStGradientAngle(gradientDrawable.getConstantState(), angle); switch (angle) { case 0: gradientDrawable.setOrientation(GradientDrawable.Orientation.LEFT_RIGHT); break; case 45: gradientDrawable.setOrientation(GradientDrawable.Orientation.BL_TR); break; case 90: gradientDrawable.setOrientation(GradientDrawable.Orientation.BOTTOM_TOP); break; case 135: gradientDrawable.setOrientation(GradientDrawable.Orientation.BR_TL); break; case 180: gradientDrawable.setOrientation(GradientDrawable.Orientation.RIGHT_LEFT); break; case 225: gradientDrawable.setOrientation(GradientDrawable.Orientation.TR_BL); break; case 270: gradientDrawable.setOrientation(GradientDrawable.Orientation.TOP_BOTTOM); break; case 315: gradientDrawable.setOrientation(GradientDrawable.Orientation.TL_BR); break; } } else { setGradientRadius(context, attrs, gradientDrawable, gradientType); } } else if (name.equals("solid")) { int color = getAttrColor(context, attrs, android.R.attr.color, Color.TRANSPARENT); gradientDrawable .setColor(getAlphaColor(color, getAttrFloat(context, attrs, android.R.attr.alpha, 1.0f))); } else if (name.equals("stroke")) { final float alphaMod = getAttrFloat(context, attrs, android.R.attr.alpha, 1.0f); final int strokeColor = getAttrColor(context, attrs, android.R.attr.color, Color.TRANSPARENT); final int strokeWidth = getAttrDimensionPixelSize(context, attrs, android.R.attr.width); final float dashWidth = getAttrDimension(context, attrs, android.R.attr.dashWidth); if (dashWidth != 0.0f) { final float dashGap = getAttrDimension(context, attrs, android.R.attr.dashGap); gradientDrawable.setStroke(strokeWidth, getAlphaColor(strokeColor, alphaMod), dashWidth, dashGap); } else { gradientDrawable.setStroke(strokeWidth, getAlphaColor(strokeColor, alphaMod)); } } else if (name.equals("corners")) { final int radius = getAttrDimensionPixelSize(context, attrs, android.R.attr.radius); gradientDrawable.setCornerRadius(radius); final int topLeftRadius = getAttrDimensionPixelSize(context, attrs, android.R.attr.topLeftRadius, radius); final int topRightRadius = getAttrDimensionPixelSize(context, attrs, android.R.attr.topRightRadius, radius); final int bottomLeftRadius = getAttrDimensionPixelSize(context, attrs, android.R.attr.bottomLeftRadius, radius); final int bottomRightRadius = getAttrDimensionPixelSize(context, attrs, android.R.attr.bottomRightRadius, radius); if (topLeftRadius != radius || topRightRadius != radius || bottomLeftRadius != radius || bottomRightRadius != radius) { // The corner radii are specified in clockwise order (see Path.addRoundRect()) gradientDrawable.setCornerRadii( new float[] { topLeftRadius, topLeftRadius, topRightRadius, topRightRadius, bottomRightRadius, bottomRightRadius, bottomLeftRadius, bottomLeftRadius }); } } else if (name.equals("padding")) { final int paddingLeft = getAttrDimensionPixelOffset(context, attrs, android.R.attr.left); final int paddingTop = getAttrDimensionPixelOffset(context, attrs, android.R.attr.top); final int paddingRight = getAttrDimensionPixelOffset(context, attrs, android.R.attr.right); final int paddingBottom = getAttrDimensionPixelOffset(context, attrs, android.R.attr.bottom); if (paddingLeft != 0 || paddingTop != 0 || paddingRight != 0 || paddingBottom != 0) { final Rect pad = new Rect(); pad.set(paddingLeft, paddingTop, paddingRight, paddingBottom); try { if (sPaddingField == null) { sPaddingField = GradientDrawable.class.getDeclaredField("mPadding"); sPaddingField.setAccessible(true); } sPaddingField.set(gradientDrawable, pad); if (sStPaddingField == null) { sStPaddingField = Class .forName("android.graphics.drawable.GradientDrawable$GradientState") .getDeclaredField("mPadding"); sStPaddingField.setAccessible(true); } sStPaddingField.set(gradientDrawable.getConstantState(), pad); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } } } else { Log.w("drawable", "Bad element under <shape>: " + name); } } return gradientDrawable; }
From source file:org.openmrs.module.diagnosiscapturerwanda.MetadataDictionary.java
/** * This method uses reflection to set fields in this class for all property keys found in the global property with the same name. * @param fieldName/*from w w w . j a v a 2 s .c o m*/ * @param value */ private void setField(String fieldName, Object value) { Field field = null; try { field = this.getClass().getField(fieldName); } catch (NoSuchFieldException nsfe) { log.error(fieldName + " found in the global property is not a field in the MetadataDictionary. Ignoring."); nsfe.printStackTrace(); } if (field != null) { try { field.setAccessible(true); field.set(this, value); log.debug("DiagnosisCaptureRwanda setting " + field.getName() + " to " + value); } catch (Exception ex) { log.error("Unable to set field " + fieldName); ex.printStackTrace(); } } }
From source file:com.bilibili.magicasakura.utils.GradientDrawableInflateImpl.java
@Override public Drawable inflateDrawable(Context context, XmlPullParser parser, AttributeSet attrs) throws XmlPullParserException, IOException { GradientDrawable gradientDrawable = new GradientDrawable(); inflateGradientRootElement(context, attrs, gradientDrawable); int type;/*from ww w. ja v a 2 s. c o m*/ final int innerDepth = parser.getDepth() + 1; int depth; while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && ((depth = parser.getDepth()) >= innerDepth || type != XmlPullParser.END_TAG)) { if (type != XmlPullParser.START_TAG) { continue; } if (depth > innerDepth) { continue; } String name = parser.getName(); if (name.equals("size")) { final int width = DrawableUtils.getAttrDimensionPixelSize(context, attrs, android.R.attr.width); final int height = DrawableUtils.getAttrDimensionPixelSize(context, attrs, android.R.attr.height); gradientDrawable.setSize(width, height); } else if (name.equals("gradient") && Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) { final float centerX = getAttrFloatOrFraction(context, attrs, android.R.attr.centerX, 0.5f, 1.0f, 1.0f); final float centerY = getAttrFloatOrFraction(context, attrs, android.R.attr.centerY, 0.5f, 1.0f, 1.0f); gradientDrawable.setGradientCenter(centerX, centerY); final boolean useLevel = DrawableUtils.getAttrBoolean(context, attrs, android.R.attr.useLevel, false); gradientDrawable.setUseLevel(useLevel); final int gradientType = DrawableUtils.getAttrInt(context, attrs, android.R.attr.type, 0); gradientDrawable.setGradientType(gradientType); final int startColor = DrawableUtils.getAttrColor(context, attrs, android.R.attr.startColor, Color.TRANSPARENT); final int centerColor = DrawableUtils.getAttrColor(context, attrs, android.R.attr.centerColor, Color.TRANSPARENT); final int endColor = DrawableUtils.getAttrColor(context, attrs, android.R.attr.endColor, Color.TRANSPARENT); if (!DrawableUtils.getAttrHasValue(context, attrs, android.R.attr.centerColor)) { gradientDrawable.setColors(new int[] { startColor, endColor }); } else { gradientDrawable.setColors(new int[] { startColor, centerColor, endColor }); setStGradientPositions(gradientDrawable.getConstantState(), 0.0f, centerX != 0.5f ? centerX : centerY, 1f); } if (gradientType == GradientDrawable.LINEAR_GRADIENT) { int angle = (int) DrawableUtils.getAttrFloat(context, attrs, android.R.attr.angle, 0.0f); angle %= 360; if (angle % 45 != 0) { throw new XmlPullParserException( "<gradient> tag requires" + "'angle' attribute to " + "be a multiple of 45"); } setStGradientAngle(gradientDrawable.getConstantState(), angle); switch (angle) { case 0: gradientDrawable.setOrientation(GradientDrawable.Orientation.LEFT_RIGHT); break; case 45: gradientDrawable.setOrientation(GradientDrawable.Orientation.BL_TR); break; case 90: gradientDrawable.setOrientation(GradientDrawable.Orientation.BOTTOM_TOP); break; case 135: gradientDrawable.setOrientation(GradientDrawable.Orientation.BR_TL); break; case 180: gradientDrawable.setOrientation(GradientDrawable.Orientation.RIGHT_LEFT); break; case 225: gradientDrawable.setOrientation(GradientDrawable.Orientation.TR_BL); break; case 270: gradientDrawable.setOrientation(GradientDrawable.Orientation.TOP_BOTTOM); break; case 315: gradientDrawable.setOrientation(GradientDrawable.Orientation.TL_BR); break; } } else { setGradientRadius(context, attrs, gradientDrawable, gradientType); } } else if (name.equals("solid")) { int color = DrawableUtils.getAttrColor(context, attrs, android.R.attr.color, Color.TRANSPARENT); gradientDrawable.setColor(getAlphaColor(color, DrawableUtils.getAttrFloat(context, attrs, android.R.attr.alpha, 1.0f))); } else if (name.equals("stroke")) { final float alphaMod = DrawableUtils.getAttrFloat(context, attrs, android.R.attr.alpha, 1.0f); final int strokeColor = DrawableUtils.getAttrColor(context, attrs, android.R.attr.color, Color.TRANSPARENT); final int strokeWidth = DrawableUtils.getAttrDimensionPixelSize(context, attrs, android.R.attr.width); final float dashWidth = DrawableUtils.getAttrDimension(context, attrs, android.R.attr.dashWidth); if (dashWidth != 0.0f) { final float dashGap = DrawableUtils.getAttrDimension(context, attrs, android.R.attr.dashGap); gradientDrawable.setStroke(strokeWidth, getAlphaColor(strokeColor, alphaMod), dashWidth, dashGap); } else { gradientDrawable.setStroke(strokeWidth, getAlphaColor(strokeColor, alphaMod)); } } else if (name.equals("corners")) { final int radius = DrawableUtils.getAttrDimensionPixelSize(context, attrs, android.R.attr.radius); gradientDrawable.setCornerRadius(radius); final int topLeftRadius = DrawableUtils.getAttrDimensionPixelSize(context, attrs, android.R.attr.topLeftRadius, radius); final int topRightRadius = DrawableUtils.getAttrDimensionPixelSize(context, attrs, android.R.attr.topRightRadius, radius); final int bottomLeftRadius = DrawableUtils.getAttrDimensionPixelSize(context, attrs, android.R.attr.bottomLeftRadius, radius); final int bottomRightRadius = DrawableUtils.getAttrDimensionPixelSize(context, attrs, android.R.attr.bottomRightRadius, radius); if (topLeftRadius != radius || topRightRadius != radius || bottomLeftRadius != radius || bottomRightRadius != radius) { // The corner radii are specified in clockwise order (see Path.addRoundRect()) gradientDrawable.setCornerRadii( new float[] { topLeftRadius, topLeftRadius, topRightRadius, topRightRadius, bottomRightRadius, bottomRightRadius, bottomLeftRadius, bottomLeftRadius }); } } else if (name.equals("padding")) { final int paddingLeft = DrawableUtils.getAttrDimensionPixelOffset(context, attrs, android.R.attr.left); final int paddingTop = DrawableUtils.getAttrDimensionPixelOffset(context, attrs, android.R.attr.top); final int paddingRight = DrawableUtils.getAttrDimensionPixelOffset(context, attrs, android.R.attr.right); final int paddingBottom = DrawableUtils.getAttrDimensionPixelOffset(context, attrs, android.R.attr.bottom); if (paddingLeft != 0 || paddingTop != 0 || paddingRight != 0 || paddingBottom != 0) { final Rect pad = new Rect(); pad.set(paddingLeft, paddingTop, paddingRight, paddingBottom); try { if (sPaddingField == null) { sPaddingField = GradientDrawable.class.getDeclaredField("mPadding"); sPaddingField.setAccessible(true); } sPaddingField.set(gradientDrawable, pad); if (sStPaddingField == null) { sStPaddingField = Class .forName("android.graphics.drawable.GradientDrawable$GradientState") .getDeclaredField("mPadding"); sStPaddingField.setAccessible(true); } sStPaddingField.set(gradientDrawable.getConstantState(), pad); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } } } else { Log.w("drawable", "Bad element under <shape>: " + name); } } return gradientDrawable; }
From source file:org.zkoss.zk.grails.web.ZKGrailsPageFilter.java
private Content applyLive(HttpServletRequest request, Content content) throws IOException { if (Environment.getCurrent() == Environment.DEVELOPMENT) { // if ZK Grails in the Dev mode // insert z-it-live.js if (content instanceof GSPSitemeshPage) { GSPSitemeshPage page = (GSPSitemeshPage) content; String pageContent = page.getPage(); if (pageContent == null) { return content; }//from w ww . j a va2 s . c o m String contextPath = request.getContextPath(); // // src="/zello/zkau/ if (pageContent.indexOf("src=\"" + contextPath + "/zkau/") > 0) { StreamCharBuffer buffer = new StreamCharBuffer(); LinkGenerator grailsLinkGenerator = (LinkGenerator) applicationContext .getBean("grailsLinkGenerator"); String link = grailsLinkGenerator.resource(new HashMap() { { put("dir", "ext/js"); put("file", "z-it-live.js"); put("plugin", "zk"); } }); link = link.replaceAll("/plugins", "/static/plugins"); buffer.getWriter() .write(pageContent.replace("</head>", "<script type=\"text/javascript\" src=\"" + link + "\" charset=\"UTF-8\"></script>\n</head>")); page.setPageBuffer(buffer); } return content; } else if (content instanceof HTMLPage2Content) { HTMLPage2Content page2Content = (HTMLPage2Content) content; try { Field fPage = HTMLPage2Content.class.getDeclaredField("page"); fPage.setAccessible(true); GrailsTokenizedHTMLPage htmlPage = (GrailsTokenizedHTMLPage) fPage.get(page2Content); String pageContent = htmlPage.getPage(); String head = htmlPage.getHead(); String body = htmlPage.getBody(); String contextPath = request.getContextPath(); // // src="/zello/zkau/ if (pageContent.indexOf("src=\"" + contextPath + "/zkau/") > 0) { LinkGenerator grailsLinkGenerator = (LinkGenerator) applicationContext .getBean("grailsLinkGenerator"); String link = grailsLinkGenerator.resource(new HashMap() { { put("dir", "ext/js"); put("file", "z-it-live.js"); put("plugin", "zk"); } }); link = link.replaceAll("/plugins", "/static/plugins"); pageContent = pageContent.replace("</head>", "<script type=\"text/javascript\" src=\"" + link + "\" charset=\"UTF-8\"></script>\n</head>"); head = head + "\n<script type=\"text/javascript\" src=\"" + link + "\" charset=\"UTF-8\"></script>\n"; CharArray newBody = new CharArray(body.length()); newBody.append(body); CharArray newHead = new CharArray(head.length()); newHead.append(head); GrailsTokenizedHTMLPage newHtmlPage = new GrailsTokenizedHTMLPage(pageContent.toCharArray(), newBody, newHead); return new HTMLPage2Content(newHtmlPage); } } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } } return content; }
From source file:com.happyblueduck.lembas.datastore.LembasEntity.java
/** * Builds lembas object from entity, setup properties * @param entity//from w ww . j av a 2 s . c om */ protected void setEntity(Entity entity) { this.entity = entity; //this.objectKey = entity.getKey().getName(); this.objectKey = KeyFactory.keyToString(entity.getKey()); Method[] methods = this.getClass().getMethods(); for (String fieldName : this.entity.getProperties().keySet()) { try { Object value = this.entity.getProperty(fieldName); // reading lembas identifier if (fieldName.startsWith(LEMBAS_PROPERTY_IDENTIFIER)) { fieldName = fieldName.substring(2); Field f = this.getClass().getField(fieldName); setLembasField(f, value); continue; } Field f = this.getClass().getField(fieldName); boolean consumed = setupFieldWithMethod(fieldName, value, methods); if (!consumed) { //f.set(this, value); readField(f, value); } } catch (NoSuchFieldException e) { logger.info("no such field, will skip:" + fieldName); } catch (IllegalAccessException | InvocationTargetException e) { e.printStackTrace(); } } }
From source file:org.hfoss.posit.android.plugin.csv.CsvListFindsFragment.java
/** * Attempts to parse a comma-delimited String as a CsvFind object. * This is a simplified version of the method Ryan McLeod wrote for * Sms Plugin./* w w w . ja va2 s. c o m*/ * @param csv The comma delimited string * @return A CsvFind object, or null if it couldn't be parsed. */ private CsvFind parseCsvFind(String csv, String mapstring) { String map[] = mapstring.split(","); String values[] = csv.split(","); Log.i(TAG, csv); // Attempt to construct a Find CsvFind find; FindPlugin plugin = FindPluginManager.mFindPlugin; if (plugin == null) { Log.e(TAG, "Could not retrieve Find Plugin."); return null; } find = new CsvFind(); Log.i(TAG, "Processing " + find.getClass()); // Need to get attributes for the Find Bundle bundle = find.getDbEntries(); List<String> keys = new ArrayList<String>(bundle.keySet()); Log.i(TAG, "mapstring=" + mapstring); Log.i(TAG, "keys=" + keys); Log.i(TAG, "values=" + values); for (int i = 0; i < values.length; i++) { String key = map[i]; // Get type of this entry Class<Object> type = null; if (keys.contains(key)) { try { type = find.getType(key); } catch (NoSuchFieldException e) { Log.e(TAG, "Encountered no such field exception on field: " + key); e.printStackTrace(); continue; } } else { continue; } // See if we can decode this value. If not, then we can't make a Find. Serializable obj; try { obj = (Serializable) ObjectCoder.decode(values[i], type); } catch (IllegalArgumentException e) { Log.e(TAG, "Failed to decode value for attribute \"" + key + "\", string was \"" + values[i] + "\""); return null; } // Decode successful! bundle.putSerializable(key, obj); } // Make Find find.updateObject(bundle); return find; }
From source file:com.web.server.util.ClassLoaderUtil.java
public static CopyOnWriteArrayList closeClassLoader(ClassLoader cl) { CopyOnWriteArrayList jars = new CopyOnWriteArrayList(); boolean res = false; Class classURLClassLoader = null; if (cl instanceof URLClassLoader) classURLClassLoader = URLClassLoader.class; else if (cl instanceof VFSClassLoader) { classURLClassLoader = VFSClassLoader.class; }//from www . j av a2 s .co m Field f = null; try { f = classURLClassLoader.getDeclaredField("ucp"); System.out.println(f); } catch (NoSuchFieldException e1) { // e1.printStackTrace(); // log.info(e1.getMessage(), e1); } if (f != null) { f.setAccessible(true); Object obj = null; try { obj = f.get(cl); } catch (IllegalAccessException e1) { // e1.printStackTrace(); // log.info(e1.getMessage(), e1); } if (obj != null) { final Object ucp = obj; f = null; try { f = ucp.getClass().getDeclaredField("loaders"); System.out.println(f); } catch (NoSuchFieldException e1) { // e1.printStackTrace(); // log.info(e1.getMessage(), e1); } if (f != null) { f.setAccessible(true); ArrayList loaders = null; try { loaders = (ArrayList) f.get(ucp); res = true; } catch (IllegalAccessException e1) { // e1.printStackTrace(); } for (int i = 0; loaders != null && i < loaders.size(); i++) { obj = loaders.get(i); f = null; try { f = obj.getClass().getDeclaredField("jar"); // log.info(f); } catch (NoSuchFieldException e) { // e.printStackTrace(); // log.info(e.getMessage(), e); } if (f != null) { f.setAccessible(true); try { obj = f.get(obj); } catch (IllegalAccessException e1) { // e1.printStackTrace(); // log.info(e1.getMessage(), e1); } if (obj instanceof JarFile) { final JarFile jarFile = (JarFile) obj; System.out.println(jarFile.getName()); jars.add(jarFile.getName().replace("/", "\\").trim().toUpperCase()); // try { // jarFile.getManifest().clear(); // } catch (IOException e) { // // ignore // } try { jarFile.close(); } catch (IOException e) { e.printStackTrace(); // ignore // log.info(e.getMessage(), e); } } } } } } } return jars; }
From source file:ren.qinc.markdowneditors.base.BaseActivity.java
/** * ???ActionMode??/*from www .j a v a 2 s .co m*/ * * @param activity * @param mode */ private void fixActionModeCallback(AppCompatActivity activity, ActionMode mode) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return; if (!(mode instanceof StandaloneActionMode)) return; try { final Field mCallbackField = mode.getClass().getDeclaredField("mCallback"); mCallbackField.setAccessible(true); final Object mCallback = mCallbackField.get(mode); final Field mWrappedField = mCallback.getClass().getDeclaredField("mWrapped"); mWrappedField.setAccessible(true); final ActionMode.Callback mWrapped = (ActionMode.Callback) mWrappedField.get(mCallback); final Field mDelegateField = AppCompatActivity.class.getDeclaredField("mDelegate"); mDelegateField.setAccessible(true); final Object mDelegate = mDelegateField.get(activity); mCallbackField.set(mode, new ActionMode.Callback() { @Override public boolean onCreateActionMode(android.support.v7.view.ActionMode mode, Menu menu) { return mWrapped.onCreateActionMode(mode, menu); } @Override public boolean onPrepareActionMode(android.support.v7.view.ActionMode mode, Menu menu) { return mWrapped.onPrepareActionMode(mode, menu); } @Override public boolean onActionItemClicked(android.support.v7.view.ActionMode mode, MenuItem item) { return mWrapped.onActionItemClicked(mode, item); } @Override public void onDestroyActionMode(final android.support.v7.view.ActionMode mode) { Class mDelegateClass = mDelegate.getClass().getSuperclass(); Window mWindow = null; PopupWindow mActionModePopup = null; Runnable mShowActionModePopup = null; ActionBarContextView mActionModeView = null; AppCompatCallback mAppCompatCallback = null; ViewPropertyAnimatorCompat mFadeAnim = null; android.support.v7.view.ActionMode mActionMode = null; Field mFadeAnimField = null; Field mActionModeField = null; while (mDelegateClass != null) { try { if (TextUtils.equals("AppCompatDelegateImplV7", mDelegateClass.getSimpleName())) { Field mActionModePopupField = mDelegateClass.getDeclaredField("mActionModePopup"); mActionModePopupField.setAccessible(true); mActionModePopup = (PopupWindow) mActionModePopupField.get(mDelegate); Field mShowActionModePopupField = mDelegateClass .getDeclaredField("mShowActionModePopup"); mShowActionModePopupField.setAccessible(true); mShowActionModePopup = (Runnable) mShowActionModePopupField.get(mDelegate); Field mActionModeViewField = mDelegateClass.getDeclaredField("mActionModeView"); mActionModeViewField.setAccessible(true); mActionModeView = (ActionBarContextView) mActionModeViewField.get(mDelegate); mFadeAnimField = mDelegateClass.getDeclaredField("mFadeAnim"); mFadeAnimField.setAccessible(true); mFadeAnim = (ViewPropertyAnimatorCompat) mFadeAnimField.get(mDelegate); mActionModeField = mDelegateClass.getDeclaredField("mActionMode"); mActionModeField.setAccessible(true); mActionMode = (android.support.v7.view.ActionMode) mActionModeField.get(mDelegate); } else if (TextUtils.equals("AppCompatDelegateImplBase", mDelegateClass.getSimpleName())) { Field mAppCompatCallbackField = mDelegateClass .getDeclaredField("mAppCompatCallback"); mAppCompatCallbackField.setAccessible(true); mAppCompatCallback = (AppCompatCallback) mAppCompatCallbackField.get(mDelegate); Field mWindowField = mDelegateClass.getDeclaredField("mWindow"); mWindowField.setAccessible(true); mWindow = (Window) mWindowField.get(mDelegate); } mDelegateClass = mDelegateClass.getSuperclass(); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } if (mActionModePopup != null) { mWindow.getDecorView().removeCallbacks(mShowActionModePopup); } if (mActionModeView != null) { if (mFadeAnim != null) { mFadeAnim.cancel(); } mFadeAnim = ViewCompat.animate(mActionModeView).alpha(0.0F); final PopupWindow mActionModePopupFinal = mActionModePopup; final ActionBarContextView mActionModeViewFinal = mActionModeView; final ViewPropertyAnimatorCompat mFadeAnimFinal = mFadeAnim; final AppCompatCallback mAppCompatCallbackFinal = mAppCompatCallback; final android.support.v7.view.ActionMode mActionModeFinal = mActionMode; final Field mFadeAnimFieldFinal = mFadeAnimField; final Field mActionModeFieldFinal = mActionModeField; mFadeAnim.setListener(new ViewPropertyAnimatorListenerAdapter() { public void onAnimationEnd(View view) { mActionModeViewFinal.setVisibility(View.GONE); if (mActionModePopupFinal != null) { mActionModePopupFinal.dismiss(); } else if (mActionModeViewFinal.getParent() instanceof View) { ViewCompat.requestApplyInsets((View) mActionModeViewFinal.getParent()); } mActionModeViewFinal.removeAllViews(); mFadeAnimFinal.setListener((ViewPropertyAnimatorListener) null); try { if (mFadeAnimFieldFinal != null) { mFadeAnimFieldFinal.set(mDelegate, null); } } catch (IllegalAccessException e) { e.printStackTrace(); } mWrapped.onDestroyActionMode(mode); if (mAppCompatCallbackFinal != null) { mAppCompatCallbackFinal.onSupportActionModeFinished(mActionModeFinal); } try { if (mActionModeFieldFinal != null) { mActionModeFieldFinal.set(mDelegate, null); } } catch (IllegalAccessException e) { e.printStackTrace(); } } }); } } }); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } }
From source file:com.google.api.ads.adwords.awreporting.model.persistence.sql.SqlReportEntitiesPersister.java
/** * Create a new Index on the "key" column */// w ww . j a v a 2 s .com @Override @Transactional public <T> void createIndex(Class<T> t, String key) { try { Table table = t.getAnnotation(Table.class); String tableName = table.name(); Field property = getField(t, key); Column column = property.getAnnotation(Column.class); String columnName = column.name(); String checkIndex = "SELECT COUNT(1) IndexIsThere FROM INFORMATION_SCHEMA.STATISTICS WHERE " + "Table_name='" + tableName + "' AND index_name='AW_INDEX_" + columnName + "'"; String newIndex = "ALTER TABLE " + tableName + " ADD INDEX " + "AW_INDEX_" + columnName + " ( " + columnName + " )"; Session session = this.sessionFactory.getCurrentSession(); List<?> list = session.createSQLQuery(checkIndex).list(); if (String.valueOf(list.get(0)).equals("0")) { System.out.println("Creating Index AW_INDEX_" + columnName + " ON " + tableName); SQLQuery sqlQuery = session.createSQLQuery(newIndex); sqlQuery.executeUpdate(); } } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } }