List of usage examples for android.content Context getClassLoader
public abstract ClassLoader getClassLoader();
From source file:com.airbop.library.simple.AirBopGCMIntentService.java
private static void generateNotification(Context context, String title, String message, String url, String large_icon) {/* www .j a v a 2s. c o m*/ //int icon = R.drawable.ic_stat_gcm; AirBopManifestSettings airBop_settings = CommonUtilities.loadDataFromManifest(context); int icon = airBop_settings.mNotificationIcon; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); //if ((title == null) || (title.equals(""))) { if (title == null) { title = airBop_settings.mDefaultNotificationTitle; } Intent notificationIntent = null; if ((url == null) || (url.equals(""))) { //just bring up the app if (context != null) { ClassLoader class_loader = context.getClassLoader(); if (class_loader != null) { try { if (airBop_settings.mDefaultNotificationClass != null) { notificationIntent = new Intent(context, Class.forName(airBop_settings.mDefaultNotificationClass)); } } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); //notificationIntent = new Intent(Intent.ACTION_VIEW); } } } } else { //Launch the URL notificationIntent = new Intent(Intent.ACTION_VIEW); notificationIntent.setData(Uri.parse(url)); notificationIntent.addCategory(Intent.CATEGORY_BROWSABLE); } PendingIntent intent = null; // set intent so it does not start a new activity if (notificationIntent != null) { notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); } Builder notificationBuilder = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(message).setLargeIcon(decodeImage(large_icon)).setWhen(when) .setStyle(new NotificationCompat.BigTextStyle().bigText(message)); if (intent != null) { notificationBuilder.setContentIntent(intent); } if (icon != 0) { notificationBuilder.setSmallIcon(icon); } Notification notification = notificationBuilder.build(); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); }
From source file:com.airbop.library.simple.AirBopGCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *//*from w w w. j a va2 s .c o m*/ private static void generateNotification(Context context, String title, String message) { AirBopManifestSettings airBop_settings = CommonUtilities.loadDataFromManifest(context); //int icon = R.drawable.ic_stat_gcm; int icon = 0; Resources res = context.getResources(); if (res != null) { //icon = res.getIdentifier(airBop_settings.mDefaultNotificationIcon, null, null); icon = airBop_settings.mNotificationIcon; } long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); //if ((title == null) || (title.equals(""))) { if (title == null) { title = airBop_settings.mDefaultNotificationTitle; } Class intent_class = null; if (context != null) { ClassLoader class_loader = context.getClassLoader(); if (class_loader != null) { try { if (airBop_settings.mDefaultNotificationClass != null) { intent_class = Class.forName(airBop_settings.mDefaultNotificationClass); } } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } //Log.i(TAG, "intent_class: " + intent_class); } } Intent notificationIntent = null; if (intent_class != null) { notificationIntent = new Intent(context, intent_class); } else { notificationIntent = new Intent(Intent.ACTION_VIEW); } // set intent so it does not start a new activity notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); Notification notification = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(message).setContentIntent(intent).setSmallIcon(icon).setWhen(when) .setStyle(new NotificationCompat.BigTextStyle().bigText(message)).build(); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); }
From source file:com.framgia.android.emulator.EmulatorDetector.java
private String getProp(Context context, String property) { try {//from ww w . ja va 2s . c om ClassLoader classLoader = context.getClassLoader(); Class<?> systemProperties = classLoader.loadClass("android.os.SystemProperties"); Method get = systemProperties.getMethod("get", String.class); Object[] params = new Object[1]; params[0] = property; return (String) get.invoke(systemProperties, params); } catch (Exception exception) { // empty catch } return null; }
From source file:com.aware.ui.Plugins_Manager.java
/** * Given a package and class name, check if the class exists or not. * @param String package_name//from w ww.java2s. co m * @param String class_name * @return true if exists, false otherwise */ private boolean isClassAvailable(String package_name, String class_name) { try { Context package_context = createPackageContext(package_name, Context.CONTEXT_IGNORE_SECURITY | Context.CONTEXT_INCLUDE_CODE); package_context.getClassLoader().loadClass(package_name + "." + class_name); } catch (ClassNotFoundException e) { return false; } catch (NameNotFoundException e) { return false; } return true; }
From source file:com.nttec.everychan.ui.theme.CustomThemeHelper.java
private View instantiate(String name, Context context, AttributeSet attrs) { try {//from www . j a v a 2 s .com Constructor<? extends View> constructor = CONSTRUCTOR_MAP.get(name); if (constructor == null) { Class<? extends View> clazz = null; if (name.indexOf('.') != -1) { clazz = context.getClassLoader().loadClass(name).asSubclass(View.class); } else { for (String prefix : CLASS_PREFIX_LIST) { try { clazz = context.getClassLoader().loadClass(prefix + name).asSubclass(View.class); break; } catch (ClassNotFoundException e) { } } if (clazz == null) throw new ClassNotFoundException("couldn't find class: " + name); } constructor = clazz.getConstructor(CONSTRUCTOR_SIGNATURE); CONSTRUCTOR_MAP.put(name, constructor); } Object[] args = constructorArgs; args[0] = context; args[1] = attrs; constructor.setAccessible(true); View view = constructor.newInstance(args); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && view instanceof ViewStub) CompatibilityImpl.setLayoutInflater((ViewStub) view, inflater.cloneInContext(context)); return view; } catch (Exception e) { Logger.e(TAG, "couldn't instantiate class " + name, e); return null; } }
From source file:android.support.v7.app.AppCompatViewInflater.java
private View createView(Context context, String name, String prefix) throws ClassNotFoundException, InflateException { Constructor<? extends View> constructor = sConstructorMap.get(name); try {//ww w . j a va 2s. c om if (constructor == null) { // Class not found in the cache, see if it's real, and try to add it Class<? extends View> clazz = context.getClassLoader() .loadClass(prefix != null ? (prefix + name) : name).asSubclass(View.class); constructor = clazz.getConstructor(sConstructorSignature); sConstructorMap.put(name, constructor); } constructor.setAccessible(true); return constructor.newInstance(mConstructorArgs); } catch (Exception e) { // We do not want to catch these, lets return null and let the actual LayoutInflater // try return null; } }
From source file:com.li.utils.ui.mdbottom.BottomNavigation.java
static BadgeProvider parseBadgeProvider(final BottomNavigation navigation, final Context context, final String name) { if (TextUtils.isEmpty(name)) { return new BadgeProvider(navigation); }/* w ww . j av a 2s.c om*/ final String fullName; if (name.startsWith(".")) { fullName = context.getPackageName() + name; } else if (name.indexOf('.') >= 0) { fullName = name; } else { // Assume stock behavior in this package (if we have one) fullName = !TextUtils.isEmpty(WIDGET_PACKAGE_NAME) ? (WIDGET_PACKAGE_NAME + '.' + name) : name; } try { Map<String, Constructor<BadgeProvider>> constructors = S_CONSTRUCTORS.get(); if (constructors == null) { constructors = new HashMap<>(); S_CONSTRUCTORS.set(constructors); } Constructor<BadgeProvider> c = constructors.get(fullName); if (c == null) { final Class<BadgeProvider> clazz = (Class<BadgeProvider>) Class.forName(fullName, true, context.getClassLoader()); c = clazz.getConstructor(CONSTRUCTOR_PARAMS); c.setAccessible(true); constructors.put(fullName, c); } return c.newInstance(navigation); } catch (Exception e) { throw new RuntimeException("Could not inflate Behavior subclass " + fullName, e); } }
From source file:com.airbop.library.simple.AirBopGCMIntentService.java
private static void generateImageNotification(Context context, String title, String message, String url, String image_url, String large_icon) { // The bitmap to download Bitmap message_bitmap = null;/*from w ww. j a v a2 s. c om*/ // Should we download the image? if ((image_url != null) && (!image_url.equals(""))) { message_bitmap = AirBopImageDownloader.downloadBitmap(image_url, context); } // If we didn't get the image, we're out of here if (message_bitmap == null) { generateNotification(context, title, message, url, large_icon); return; } AirBopManifestSettings airBop_settings = CommonUtilities.loadDataFromManifest(context); int icon = airBop_settings.mNotificationIcon; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); //if ((title == null) || (title.equals(""))) { if (title == null) { title = airBop_settings.mDefaultNotificationTitle; } Intent notificationIntent = null; if ((url == null) || (url.equals(""))) { //just bring up the app if (context != null) { ClassLoader class_loader = context.getClassLoader(); if (class_loader != null) { try { if (airBop_settings.mDefaultNotificationClass != null) { notificationIntent = new Intent(context, Class.forName(airBop_settings.mDefaultNotificationClass)); } } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } else { //Launch the URL notificationIntent = new Intent(Intent.ACTION_VIEW); notificationIntent.setData(Uri.parse(url)); notificationIntent.addCategory(Intent.CATEGORY_BROWSABLE); } PendingIntent intent = null; // set intent so it does not start a new activity if (notificationIntent != null) { notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); } Builder notificationBuilder = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(message).setLargeIcon(decodeImage(large_icon)).setWhen(when) .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(message_bitmap)); if (intent != null) { notificationBuilder.setContentIntent(intent); } if (icon != 0) { notificationBuilder.setSmallIcon(icon); } Notification notification = notificationBuilder.build(); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); }
From source file:com.hyc.skin.core.SkinViewInflater.java
private View createView(Context context, String name, String prefix) throws ClassNotFoundException, InflateException { Constructor<? extends View> constructor = sConstructorMap.get(name); //Log.e("hyc-test-end",name); try {/*from w ww . jav a 2 s. co m*/ if (constructor == null) { // Class not found in the cache, see if it's real, and try to add it Class<? extends View> clazz = context.getClassLoader() .loadClass(prefix != null ? (prefix + name) : name).asSubclass(View.class); constructor = clazz.getConstructor(sConstructorSignature); sConstructorMap.put(name, constructor); } constructor.setAccessible(true); return constructor.newInstance(mConstructorArgs); } catch (Exception e) { // We do not want to catch these, lets return null and let the actual LayoutInflater // try return null; } }
From source file:it.sephiroth.android.library.bottomnavigation.BottomNavigation.java
static BadgeProvider parseBadgeProvider(final BottomNavigation navigation, final Context context, final String name) { log(TAG, INFO, "parseBadgeProvider: %s", name); if (TextUtils.isEmpty(name)) { return new BadgeProvider(navigation); }//from w w w. ja va2 s . c o m final String fullName; if (name.startsWith(".")) { fullName = context.getPackageName() + name; } else if (name.indexOf('.') >= 0) { fullName = name; } else { // Assume stock behavior in this package (if we have one) fullName = !TextUtils.isEmpty(WIDGET_PACKAGE_NAME) ? (WIDGET_PACKAGE_NAME + '.' + name) : name; } try { Map<String, Constructor<BadgeProvider>> constructors = S_CONSTRUCTORS.get(); if (constructors == null) { constructors = new HashMap<>(); S_CONSTRUCTORS.set(constructors); } Constructor<BadgeProvider> c = constructors.get(fullName); if (c == null) { final Class<BadgeProvider> clazz = (Class<BadgeProvider>) Class.forName(fullName, true, context.getClassLoader()); c = clazz.getConstructor(CONSTRUCTOR_PARAMS); c.setAccessible(true); constructors.put(fullName, c); } return c.newInstance(navigation); } catch (Exception e) { throw new RuntimeException("Could not inflate Behavior subclass " + fullName, e); } }