List of usage examples for android.content Context getApplicationContext
public abstract Context getApplicationContext();
From source file:Main.java
public static void showToast(final Context mContext, final int resId) { sharedHandler(mContext).post(() -> { if (toast != null) { toast.setText(resId);/*from w w w. j a v a2 s . c o m*/ toast.setDuration(Toast.LENGTH_SHORT); } else { toast = Toast.makeText(mContext.getApplicationContext(), resId, Toast.LENGTH_SHORT); } toast.show(); }); }
From source file:Main.java
public static void showLongToast(final Context mContext, final String text) { sharedHandler(mContext).post(() -> { if (toast != null) { toast.setText(text);// w ww .j a va 2 s.co m toast.setDuration(Toast.LENGTH_LONG); } else { toast = Toast.makeText(mContext.getApplicationContext(), text, Toast.LENGTH_LONG); } toast.show(); }); }
From source file:Main.java
public static void showToast(final Context mContext, final String text) { sharedHandler(mContext).post(() -> { if (toast != null) { toast.setText(text);//from w w w . ja v a 2s .co m toast.setDuration(Toast.LENGTH_SHORT); } else { toast = Toast.makeText(mContext.getApplicationContext(), text, Toast.LENGTH_SHORT); } toast.show(); }); }
From source file:Main.java
public static Object get(Context context, String name) { if (context == null || name == null) { throw new IllegalArgumentException("Context and key must not be null"); }/*from ww w. j a va 2 s.c o m*/ Object systemService = context.getSystemService(name); if (systemService == null) { context = context.getApplicationContext(); systemService = context.getSystemService(name); } if (systemService == null) { throw new IllegalStateException(name + " not available"); } return systemService; }
From source file:de.sevenpass.sample.AuthStateManager.java
@AnyThread public static AuthStateManager getInstance(@NonNull Context context) { AuthStateManager manager = INSTANCE_REF.get().get(); if (manager == null) { manager = new AuthStateManager(context.getApplicationContext()); INSTANCE_REF.set(new WeakReference<>(manager)); }/*from w ww . ja va2 s. c o m*/ return manager; }
From source file:au.org.ala.fielddata.mobile.dao.DatabaseHelper.java
public synchronized static DatabaseHelper getInstance(Context ctx) { if (instance == null) { instance = new DatabaseHelper(ctx.getApplicationContext()); }// www . ja va2s . co m return instance; }
From source file:Main.java
public static void showSingleToast(Context ctx, @StringRes int msgID, int duration) { String msg = ctx.getString(msgID); int showDuration = duration <= Toast.LENGTH_SHORT ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT; if (null == toast) { toast = Toast.makeText(ctx.getApplicationContext(), msgID, showDuration); toast.show();/*from w w w. jav a2s.c o m*/ oneTime = System.currentTimeMillis(); } else { twoTime = System.currentTimeMillis(); if (msg.equals(oldMsg)) { if (twoTime - oneTime > showDuration) { toast.show(); } } else { oldMsg = msg; toast.setText(msg); toast.show(); } } oneTime = twoTime; }
From source file:key.secretkey.utils.PasswordStorage.java
public static File getRepositoryDirectory(Context context) { File dir = null;/* w w w . j ava 2 s. c o m*/ SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext()); if (settings.getBoolean("git_external", false)) { String external_repo = settings.getString("git_external_repo", null); if (external_repo != null) { dir = new File(external_repo); } } else { dir = new File(context.getFilesDir() + "/store"); } return dir; }
From source file:com.mobiperf.speedometer.AccountSelector.java
/** * Return the list of account names for users to select *///from w w w . jav a2s .co m public static String[] getAccountList(Context context) { AccountManager accountManager = AccountManager.get(context.getApplicationContext()); Account[] accounts = accountManager.getAccountsByType(ACCOUNT_TYPE); String[] accountNames = null; if (accounts != null && accounts.length > 0) { accountNames = new String[accounts.length]; for (int i = 0; i < accounts.length; i++) { accountNames[i] = accounts[i].name; } } return accountNames; }
From source file:io.vit.vitio.Managers.DataHandler.java
public static DataHandler getInstance(Context context) { if (mInstance == null) mInstance = new DataHandler(context.getApplicationContext()); return mInstance; }