List of usage examples for android.content Context getApplicationContext
public abstract Context getApplicationContext();
From source file:Main.java
public static Typeface getTypeface(Context context) { if (typeface == null) { typeface = Typeface.createFromAsset(context.getApplicationContext().getAssets(), "Helvetica.ttf"); }/* w w w . j a v a 2s .co m*/ return typeface; }
From source file:Main.java
public static boolean canNetworkUseful(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getApplicationContext() .getSystemService(Context.CONNECTIVITY_SERVICE); if (manager == null) { return false; }/*from ww w . j av a 2 s . c o m*/ NetworkInfo networkinfo = manager.getActiveNetworkInfo(); if (networkinfo == null || !networkinfo.isAvailable()) { return false; } return true; }
From source file:Main.java
public static void copyFileOrDir(Context ctx, String path) throws IOException { String assets[] = ctx.getApplicationContext().getAssets().list(path); if (assets.length == 0) { copyFile(ctx, path);//from www. j a va2 s . co m } else { StringBuilder fullPath = new StringBuilder(); fullPath.append(DATA_DIR).append(ctx.getPackageName()).append("/").append(path); File dir = new File(fullPath.toString()); if (!dir.exists()) dir.mkdir(); for (int i = 0; i < assets.length; ++i) { copyFileOrDir(ctx, path + "/" + assets[i]); } } }
From source file:Main.java
public static void showLong(Context context, String msg) { if (context != null && !TextUtils.isEmpty(msg)) { Toast.makeText(context.getApplicationContext(), msg, Toast.LENGTH_LONG).show(); }/* w w w. j a v a 2 s. co m*/ }
From source file:Main.java
public static void showShort(Context context, String msg) { if (context != null && !TextUtils.isEmpty(msg)) { Toast.makeText(context.getApplicationContext(), msg, Toast.LENGTH_SHORT).show(); }/* w w w.j a v a2s. c o m*/ }
From source file:Main.java
public static boolean IsWiFiConnected(Context context) { ConnectivityManager connectivity = (ConnectivityManager) context.getApplicationContext() .getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity != null) { NetworkInfo[] info = connectivity.getAllNetworkInfo(); if (info != null) { for (int i = 0; i < info.length; i++) { if (info[i].getTypeName().equals("WIFI") && info[i].isConnected()) return true; }/*from w ww. j a va2s . co m*/ } } return false; }
From source file:Main.java
public static Typeface getBoldTypeface(Context context) { if (typefaceBold == null) { typefaceBold = Typeface.createFromAsset(context.getApplicationContext().getAssets(), "Helvetica_Bold.ttf"); }//from w w w . j a va 2 s .co m return typefaceBold; }
From source file:Main.java
public static String getRelation(Context context) { DisplayMetrics dm = new DisplayMetrics(); WindowManager windowMgr = (WindowManager) context.getApplicationContext() .getSystemService(Context.WINDOW_SERVICE); windowMgr.getDefaultDisplay().getMetrics(dm); int width = dm.widthPixels; int height = dm.heightPixels; return String.valueOf(width) + "*" + String.valueOf(height); }
From source file:Main.java
/** * Returns typeface font from assets. If cached returns the cached value, otherwise loads from * assets and caches it.//from www .j ava 2s . com * * @param context * @param fontName * @return */ public static final Typeface getCachedFont(Context context, String fontName) { Typeface tf = null; Context appContext = context.getApplicationContext(); try { // check if the font is cached if (mCachedFonts.containsKey(fontName) && mCachedFonts.get(fontName) != null) { tf = mCachedFonts.get(fontName); } else { // get the font from assets tf = Typeface.createFromAsset(appContext.getAssets(), "fonts/" + fontName); // cache the font mCachedFonts.put(fontName, tf); } } catch (Exception e) { } return tf; }
From source file:Main.java
@SuppressLint("ShowToast") public synchronized static Toast getInstance(Context context, String text, int duration) { if (null == mToast) { mToast = Toast.makeText(context.getApplicationContext(), text, duration); } else {/*from w ww.ja v a 2 s . c o m*/ mToast.setText(text); mToast.setDuration(duration); } return mToast; }