List of usage examples for android.content Context getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:Main.java
public static void d(Context context, String message, boolean printTime) { String tag = context.getClass().getSimpleName(); d(tag, message, printTime);//from www. j ava 2s.co m }
From source file:Main.java
public static String getJsonDataFromAssets(Context context, String fileName) { StringBuilder stringBuilder = new StringBuilder(); InputStream inputStream = context.getClass().getClassLoader().getResourceAsStream("assets/" + fileName); try {/*www. java 2s . c o m*/ byte[] buffer = new byte[inputStream.available()]; inputStream.read(buffer); String json = new String(buffer, "utf-8"); stringBuilder = stringBuilder.append(json); } catch (IOException e) { e.printStackTrace(); } finally { try { inputStream.close(); } catch (IOException e) { e.printStackTrace(); } } return stringBuilder.toString(); }
From source file:com.seamusdawkins.gcmcustom.MainActivity.java
/** * This method checks if there is already preference registered or not. * * @param context//from w ww . j a v a 2 s .co m */ public static void checkPrefsExists(Context context) { PrefsGcm pHelper = new PrefsGcm(context); if (!pHelper.isPrefExists(context.getClass().getName())) { pHelper.savePref(context.getClass().getName(), true); } }
From source file:it.cdpaf.helper.DrawableManager.java
public static Drawable returnDrawable(String urlString, Context ctx) { Log.d(ctx.getClass().getSimpleName(), "return ------DRAWABLE MAN:" + "RIUSO: " + urlString + " Size:" + drawableMap.size()); Drawable d = drawableMap.get(urlString); return d;/*from w ww. j a v a2 s . com*/ }
From source file:com.learnit.LearnIt.data_types.NotificationBuilder.java
public static void show(Context context) { Log.d(LOG_TAG, "context class = " + context.getClass().getName()); sp = PreferenceManager.getDefaultSharedPreferences(context); String old_ids = sp.getString("current_ids", ""); deleteOldNotifications(context, old_ids); int wayToLearn = getWayToLearn(context, sp); int numberOfWords = setNumberOfWords(context, sp); Log.d(LOG_TAG, "number of notifications = " + numberOfWords); ArrayList<ArticleWordId> randWords = getRandWordsFromDB(wayToLearn, numberOfWords, context); CreateNotifications(randWords, context, wayToLearn); SharedPreferences.Editor editor = sp.edit(); editor.putString("current_ids", currentIds); editor.commit();//from ww w.ja va 2 s .com }
From source file:Main.java
public static Activity getActivity(View view) { Context context = view.getContext(); while (!(context instanceof Activity)) { if (context instanceof ContextWrapper) { context = ((ContextWrapper) context).getBaseContext(); } else {//from w ww . j a va2 s. c o m throw new IllegalStateException("Got a context of class " + context.getClass() + " and I don't know how to get the Activity from it"); } } return (Activity) context; }
From source file:it.cdpaf.helper.DrawableManager.java
public static Drawable fetchDrawable(String urlString, Context ctx) { if (drawableMap.containsKey(urlString)) { Log.d(ctx.getClass().getSimpleName(), "DRAWABLE MANAGER FD:" + "RIUSO: " + urlString + " Size:" + drawableMap.size()); return drawableMap.get(urlString); }//from w w w. j a v a 2 s . c om Log.d(ctx.getClass().getSimpleName(), "image url:" + urlString); try { InputStream is = fetch(urlString, ctx); Drawable drawable = Drawable.createFromStream(is, "src"); if (drawable != null) { drawableMap.put(urlString, drawable); Log.d(ctx.getClass().getSimpleName(), "got a thumbnail drawable: " + drawable.getBounds() + ", " + drawable.getIntrinsicHeight() + "," + drawable.getIntrinsicWidth() + ", " + drawable.getMinimumHeight() + "," + drawable.getMinimumWidth()); } else { Log.w(ctx.getClass().getSimpleName(), "could not get thumbnail"); } return drawable; } catch (MalformedURLException e) { Log.e(ctx.getClass().getSimpleName(), "MALFORMEDURL EXC fetchDrawable failed", e); return null; } catch (IOException e) { Log.e(ctx.getClass().getSimpleName(), "IO EXCP fetchDrawable failed", e); return null; } }
From source file:edu.ucla.cens.systemlog.Analytics.java
/** * Appends the beginning of the log message. * <p>//from ww w . j a va 2 s. co m * 'login-name class-name' * </p> * * @param context * @param builder * @return */ private static StringBuilder appendPreamble(Context context, StringBuilder builder) { //builder.append(loginName()).append(" "); if (context != null) builder.append(context.getClass().getSimpleName()).append(" "); else builder.append("null "); return builder; }
From source file:Main.java
/** * @param context//from w w w . jav a2 s.com * @param folder "assets/json/" * @param fileName * @return */ public static final String getString(Context context, String folder, String fileName) { if (TextUtils.isEmpty(folder)) { folder = JSON_FOLDER; } StringBuffer stringBuffer = new StringBuffer(); try { // InputStream abpath = context.getClass().getResourceAsStream(folder + fileName); InputStream abpath = context.getClass().getClassLoader().getResourceAsStream(folder + fileName); if (abpath == null) { return ""; } // BufferedReader bufferedReader = new BufferedReader(new // FileReader( // new File("file:///android_asset/json/" + fileName))); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(abpath)); String str = ""; while ((str = bufferedReader.readLine()) != null) { stringBuffer.append(str); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return stringBuffer.toString(); }
From source file:Main.java
public static boolean startActivityUsingScheme(Context a, String scheme) { Uri uri = Uri.parse(scheme + "://"); Intent intent = new Intent(Intent.ACTION_RUN, uri); boolean result = true; try {/*from w ww . j a va2 s . c o m*/ intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); a.startActivity(intent); } catch (Exception e) { Log.e(a.getClass().getName(), e.getMessage(), e); result = false; } return result; }