Example usage for android.app Activity getApplicationContext

List of usage examples for android.app Activity getApplicationContext

Introduction

In this page you can find the example usage for android.app Activity getApplicationContext.

Prototype

@Override
    public Context getApplicationContext() 

Source Link

Usage

From source file:Main.java

/**
 * A method to create a toast message on any screen.
 *
 * @param activity : screen on which the toast message should be shown.
 * @param msg      : the message to be shown.
 *//*w ww .  j  a  v a 2 s  . c  o  m*/
public static void createToastMessage(final Activity activity, final String msg) {
    if (!isNullOrEmpty(msg))
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Toast toast = Toast.makeText(activity.getApplicationContext(), msg, Toast.LENGTH_SHORT);
                toast.show();

            }
        });
}

From source file:com.freshdigitable.udonroad.ReplyActivity.java

public static void start(Activity activity, long statusId, @TweetType int type, View view) {
    ViewCompat.setTransitionName(view, TRANSITION_NAME);
    final Intent intent = new Intent(activity.getApplicationContext(), ReplyActivity.class);
    intent.putExtra(EXTRA_STATUS_ID, statusId);
    intent.putExtra(EXTRA_TWEET_TYPE, type);
    ActivityCompat.startActivity(activity, intent,
            ActivityOptionsCompat.makeSceneTransitionAnimation(activity, view, TRANSITION_NAME).toBundle());
}

From source file:Main.java

/**
 * Recreate account/*ww  w  .ja v  a 2  s  .  co  m*/
 * @param account account
 * @param authTokenType authTokenType
 * @param requiredFeatures requiredFeatures, could be <code>null</code>
 * @param options options, could be <code>null</code>
 * @param activity activity (cannot be <code>null</code>)
 */
public static void reCreateAccount(Account account, String accountType, String authTokenType,
        String[] requiredFeatures, Bundle options, Activity activity) {
    if (activity == null) {
        throw new IllegalArgumentException("activity cannot be null");
    }

    final AccountManager accountManager = AccountManager.get(activity.getApplicationContext());
    if (isAccountExist(activity, account)) {
        accountManager.removeAccount(account, null, null);
    }

    accountManager.addAccount(accountType, authTokenType, requiredFeatures, options, activity, null, null);
}

From source file:com.poguico.palmabici.widgets.SidebarMenu.java

public static void setDrawer(final Activity activity) {
    context = activity.getApplicationContext();
    elements = initElements();//  w  ww  . j a  va 2 s  . c om

    mDrawerLayout = (DrawerLayout) activity.findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) activity.findViewById(R.id.left_drawer);

    mDrawerList.setAdapter(new SidebarElementAdapter(context, elements));
    mDrawerList.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View view, int position, long id) {
            if (position == 0) {
                Intent preferencesActivity = new Intent(activity, PreferencesActivity.class);
                activity.startActivity(preferencesActivity);
            } else if (position == 1) {
                Intent issueIntent = new Intent(Intent.ACTION_VIEW);
                issueIntent.setData(Uri.parse(GPLAY_URL));
                activity.startActivity(issueIntent);
            } else if (position == 2) {
                Intent shareActivity = new Intent(activity, ShareActivity.class);
                activity.startActivity(shareActivity);
            } else if (position == 3) {
                Intent issueIntent = new Intent(Intent.ACTION_VIEW);
                issueIntent.setData(Uri.parse(CONTACT_URL));
                activity.startActivity(issueIntent);
            } else if (position == 4) {
                new CreditsDialog(activity).show();
            }

            new Handler().postDelayed(closeDrawerRunnable(), 200);
        }
    });

    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);

    mDrawerToggle = new ActionBarDrawerToggle(activity, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description for accessibility */
            R.string.drawer_close /* "close drawer" description for accessibility */
    ) {

        /** Called when a drawer has settled in a completely closed state. */
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
        }

        /** Called when a drawer has settled in a completely open state. */
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
        }
    };

    mDrawerLayout.post(new Runnable() {
        @Override
        public void run() {
            mDrawerToggle.syncState();
        }
    });

    mDrawerLayout.setDrawerListener(mDrawerToggle);

}

From source file:Main.java

/**
 * Invalidate auth token for specified account
 * @param account account to invalidate auth token
 * @param authTokenType auth token type//w  ww. j  a  v  a2s. co  m
 * @param requiredFeatures requiredFeatures, could be <code>null</code>
 * @param options options, could be <code>null</code>
 * @param activity activity (cannot be <code>null</code>)
 */
public static void invalidateAuthToken(Account account, String authTokenType, String[] requiredFeatures,
        Bundle options, Activity activity) {
    if (activity == null) {
        throw new IllegalArgumentException("activity cannot be null");
    }
    if (account == null) {
        throw new IllegalArgumentException("account cannot be null");
    }
    Context context = activity.getApplicationContext();
    final AccountManager am = AccountManager.get(context);
    String authToken = am.peekAuthToken(account, authTokenType);
    if (!TextUtils.isEmpty(authToken)) {
        am.invalidateAuthToken(account.type, authToken);
    }
    am.addAccount(account.type, authTokenType, requiredFeatures, options, activity, null, null);
}

From source file:com.dimasdanz.kendalipintu.NFCOpenDoorActivity.java

public static void setupForegroundDispatch(final Activity activity, NfcAdapter adapter) {
    final Intent intent = new Intent(activity.getApplicationContext(), activity.getClass());
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

    final PendingIntent pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), 0, intent,
            0);/*  w w w .  jav a2s.  c o  m*/

    IntentFilter[] filters = new IntentFilter[1];
    String[][] techList = new String[][] {};
    filters[0] = new IntentFilter();
    filters[0].addAction(NfcAdapter.ACTION_NDEF_DISCOVERED);
    filters[0].addCategory(Intent.CATEGORY_DEFAULT);
    try {
        filters[0].addDataType(MIME_TEXT_PLAIN);
    } catch (MalformedMimeTypeException e) {
        throw new RuntimeException("Check your mime type.");
    }
    adapter.enableForegroundDispatch(activity, pendingIntent, filters, techList);
}

From source file:Main.java

@SuppressLint("SetJavaScriptEnabled")
public static void webView_Settings(final Activity from, final WebView webView) {

    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(from);
    String fontSizeST = sharedPref.getString("font", "100");
    int fontSize = Integer.parseInt(fontSizeST);

    webView.getSettings().setAppCachePath(from.getApplicationContext().getCacheDir().getAbsolutePath());
    webView.getSettings().setAllowFileAccess(true);
    webView.getSettings().setAppCacheEnabled(true);
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setDisplayZoomControls(false);
    webView.getSettings().setTextZoom(fontSize);
    webView.getSettings().setGeolocationEnabled(false);
    webView.getSettings().setDomStorageEnabled(true);
    webView.getSettings().setUseWideViewPort(true);
    webView.getSettings().setLoadWithOverviewMode(true);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); // load online by default
}

From source file:com.ouyangzn.github.utils.Actions.java

/**
 * ?fragment//from  w  w w .  j  a v  a  2  s .  c  om
 *
 * @param activity ?activity
 * @param clazz fragment
 * @param bundle ??
 * @param requestCode ?
 */
public static void startActivity(Activity activity, Class<? extends BaseFragment> clazz, Bundle bundle,
        int requestCode) {
    Intent intent = new Intent(activity.getApplicationContext(), BaseFragmentActivity.class);
    if (bundle != null) {
        intent.putExtras(bundle);
    }
    intent.putExtra(BaseFragmentActivity.DATA_FRAGMENT_NAME, clazz.getName());
    activity.startActivityForResult(intent, requestCode);
}

From source file:com.freshdigitable.udonroad.UserInfoActivity.java

public static void start(Activity activity, User user, View userIcon) {
    final Intent intent = createIntent(activity.getApplicationContext(), user.getId());
    ViewCompat.setTransitionName(userIcon, "user_icon");
    ActivityCompat.startActivity(activity, intent,
            ActivityOptionsCompat.makeSceneTransitionAnimation(activity, userIcon, "user_icon").toBundle());
}

From source file:com.mercandalli.android.apps.files.main.Config.java

public static Config getInstance(final Activity activity) {
    if (sInstance == null) {
        sInstance = new Config(activity.getApplicationContext());
    }//from   w  ww  .  ja  va  2 s. com
    return sInstance;
}