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:edu.umbc.cs.ebiquity.mithril.parserapp.contentparsers.contacts.ContactsListFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity.getApplicationContext());

    try {//from  ww w  .ja va  2 s .co m
        // Assign callback listener which the holding activity must implement. This is used
        // so that when a contact item is interacted with (selected by the user) the holding
        // activity will be notified and can take further action such as populating the contact
        // detail pane (if in multi-pane layout) or starting a new activity with the contact
        // details (single pane layout).
        mOnContactSelectedListener = (OnContactsInteractionListener) activity;
    } catch (ClassCastException e) {
        throw new ClassCastException(activity.toString() + " must implement OnContactsInteractionListener");
    }
}

From source file:fr.cph.chicago.util.Util.java

public static void setWindowsColor(@NonNull final Activity activity, @NonNull final Toolbar toolbar,
        @NonNull final TrainLine trainLine) {
    int backgroundColor = 0;
    int statusBarColor = 0;
    //int navigationBarColor = 0;
    int textTitleColor = R.color.white;
    switch (trainLine) {
    case BLUE:/*w  w w.  j a v a2 s  . c o m*/
        backgroundColor = R.color.blueLine;
        statusBarColor = R.color.blueLineDark;
        break;
    case BROWN:
        backgroundColor = R.color.brownLine;
        statusBarColor = R.color.brownLineDark;
        break;
    case GREEN:
        backgroundColor = R.color.greenLine;
        statusBarColor = R.color.greenLineDark;
        break;
    case ORANGE:
        backgroundColor = R.color.orangeLine;
        statusBarColor = R.color.orangeLineDarker;
        break;
    case PINK:
        backgroundColor = R.color.pinkLine;
        statusBarColor = R.color.pinkLineDark;
        break;
    case PURPLE:
        backgroundColor = R.color.purpleLine;
        statusBarColor = R.color.purpleLineDark;
        break;
    case RED:
        backgroundColor = R.color.redLine;
        statusBarColor = R.color.redLineDark;
        break;
    case YELLOW:
        backgroundColor = R.color.yellowLine;
        statusBarColor = R.color.yellowLineDark;
        break;
    case NA:
        backgroundColor = R.color.primaryColor;
        statusBarColor = R.color.primaryColorDark;
        break;
    }
    toolbar.setBackgroundColor(ContextCompat.getColor(activity.getApplicationContext(), backgroundColor));
    toolbar.setTitleTextColor(ContextCompat.getColor(activity.getApplicationContext(), textTitleColor));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().setStatusBarColor(ContextCompat.getColor(activity, statusBarColor));
        activity.getWindow()
                .setNavigationBarColor(ContextCompat.getColor(activity, R.color.primaryColorDarker));
    }
}

From source file:uk.org.rivernile.edinburghbustracker.android.fragments.general.NearestStopsFragment.java

/**
 * {@inheritDoc}/*  w ww. j ava  2  s.  c  o m*/
 */
@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final Activity activity = getActivity();
    // Get references to required resources.
    locMan = (LocationManager) activity.getSystemService(Context.LOCATION_SERVICE);
    sp = activity.getSharedPreferences(PreferencesActivity.PREF_FILE, 0);
    bsd = BusStopDatabase.getInstance(activity.getApplicationContext());
    sd = SettingsDatabase.getInstance(activity.getApplicationContext());
    // Create the ArrayAdapter for the ListView.
    ad = new NearestStopsArrayAdapter(activity);

    // Initialise the services chooser Dialog.
    services = bsd.getBusServiceList();

    if (savedInstanceState != null) {
        chosenServices = savedInstanceState.getStringArray(ARG_CHOSEN_SERVICES);
    } else {
        // Check to see if GPS is enabled then check to see if the GPS
        // prompt dialog has been disabled.
        if (!locMan.isProviderEnabled(LocationManager.GPS_PROVIDER)
                && !sp.getBoolean(PreferencesActivity.PREF_DISABLE_GPS_PROMPT, false)) {
            // Get the list of Activities which can handle the enabling of
            // location services.
            final List<ResolveInfo> packages = activity.getPackageManager()
                    .queryIntentActivities(TurnOnGpsDialogFragment.TURN_ON_GPS_INTENT, 0);
            // If the list is not empty, this means Activities do exist.
            // Show Dialog asking users if they want to turn on GPS.
            if (packages != null && !packages.isEmpty()) {
                callbacks.onAskTurnOnGps();
            }
        }
    }

    // Tell the underlying Activity that this Fragment contains an options
    // menu.
    setHasOptionsMenu(true);
}

From source file:com.amazonaws.mobile.auth.google.GoogleSignInProvider.java

/** {@inheritDoc} */
@Override//from  w ww.  j  av  a 2s. co  m
public View.OnClickListener initializeSignInButton(final Activity signInActivity, final View buttonView,
        final SignInProviderResultHandler providerResultsHandler) {
    this.resultsHandler = providerResultsHandler;
    final GoogleApiAvailability api = GoogleApiAvailability.getInstance();
    final int code = api.isGooglePlayServicesAvailable(context.getApplicationContext());

    if (ConnectionResult.SUCCESS != code) {
        if (api.isUserResolvableError(code)) {
            Log.w(LOG_TAG, "Google Play services recoverable error.");
            api.showErrorDialogFragment(signInActivity, code, REQUEST_GOOGLE_PLAY_SERVICES);
        } else {
            final boolean isDebugBuild = (0 != (signInActivity.getApplicationContext()
                    .getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE));

            if (!isDebugBuild) {
                buttonView.setVisibility(View.GONE);
            } else {
                Log.w(LOG_TAG,
                        "Google Play Services are not available, "
                                + "but we are showing the Google Sign-in Button, anyway, "
                                + "because this is a debug build.");
            }
        }
        return null;
    }

    final View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(final View v) {
            if (!signingIn) {
                signingIn = true;
                if (getPermissionsIfNecessary(signInActivity)) {
                    return;
                }

                initiateGoogleSignIn(signInActivity);
            }
        }
    };
    buttonView.setOnClickListener(listener);
    return listener;
}

From source file:com.yourkey.billing.util.InAppBilling.java

public InAppBilling(Activity parentActivity, final InAppBillingListener inAppBillingListener,
        String appPublicKeyStr, int purchaseRequestCode) {
    // context initialization
    this.parentActivity = parentActivity;
    this.applicationContext = parentActivity.getApplicationContext();
    this.packageName = applicationContext.getPackageName();

    // listening class
    this.inAppBillingListener = inAppBillingListener;

    // google provided public key for this application
    this.appPublicKeyStr = appPublicKeyStr;

    // request code
    this.purchaseRequestCode = purchaseRequestCode;
    return;/*from  ww w.j a  v a 2s .  c om*/
}

From source file:org.artoolkit.ar.base.camera.CaptureCameraPreview.java

/**
 * Constructor takes a {@link CameraEventListener} which will be called on
 * to handle camera related events.//from   w ww  .  ja  v a  2 s . c o m
 *
 * @param cel CameraEventListener to use. Can be null.
 */
@SuppressWarnings("deprecation")
public CaptureCameraPreview(Activity activity, CameraEventListener cel) {
    super(activity);

    Log.i(TAG, "CaptureCameraPreview(): ctor called");
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(activity,
                    Manifest.permission.CAMERA)) {
                mustAskPermissionFirst = true;
                if (activity.shouldShowRequestPermissionRationale(Manifest.permission.CAMERA)) {
                    // Will drop in here if user denied permissions access camera before.
                    // Or no uses-permission CAMERA element is in the
                    // manifest file. Must explain to the end user why the app wants
                    // permissions to the camera devices.
                    Toast.makeText(activity.getApplicationContext(),
                            "App requires access to camera to be granted", Toast.LENGTH_SHORT).show();
                }
                // Request permission from the user to access the camera.
                Log.i(TAG, "CaptureCameraPreview(): must ask user for camera access permission");
                activity.requestPermissions(new String[] { Manifest.permission.CAMERA },
                        REQUEST_CAMERA_PERMISSION_RESULT);
                return;
            }
        }
    } catch (Exception ex) {
        Log.e(TAG, "CaptureCameraPreview(): exception caught, " + ex.getMessage());
        return;
    }

    SurfaceHolder holder = getHolder();
    holder.addCallback(this);
    holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); // Deprecated in API level 11. Still required for API levels <= 10.

    setCameraEventListener(cel);
}

From source file:com.granita.tasks.EditTaskFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    mAuthority = getString(R.string.org_dmfs_tasks_authority);
    Bundle bundle = getArguments();// w w  w.ja v  a  2  s.  c  o  m

    // check for supplied task information from intent
    if (bundle.containsKey(PARAM_CONTENT_SET)) {
        mValues = bundle.getParcelable(PARAM_CONTENT_SET);
        if (!mValues.isInsert()) {
            mTaskUri = mValues.getUri();
        }
    } else {
        mTaskUri = bundle.getParcelable(PARAM_TASK_URI);
    }
    mAppContext = activity.getApplicationContext();

}

From source file:com.android.launcher3.Utilities.java

public static void turnOnWifi(Activity activity) {
    WifiManager wifimanager = (WifiManager) activity.getApplicationContext()
            .getSystemService(Context.WIFI_SERVICE);
    wifimanager.setWifiEnabled(true);/*from  w  w  w .  jav a  2  s .  co  m*/
    isWifiOn = true;
}

From source file:com.android.launcher3.Utilities.java

public static void turnOffWifi(Activity activity) {
    WifiManager wifimanager = (WifiManager) activity.getApplicationContext()
            .getSystemService(Context.WIFI_SERVICE);
    wifimanager.setWifiEnabled(false);/*w  w w.  j a  va  2s .c om*/
    isWifiOn = false;
}

From source file:crittercism.CrittercismModuleModule.java

@Kroll.method
public void start(KrollDict dict) {
    String app_id = (String) dict.get("appID");
    Boolean should_collect_logcat = (Boolean) dict.get("setLogcatReportingEnabled");
    String custom_app_version = (String) dict.get("customAppVersion");

    Activity activity = TiApplication.getAppCurrentActivity();

    if (app_id != null) {
        // We have an app id, now we can do this

        try {//from   w w  w  . j  a  v a 2s . co m

            CrittercismConfig config = new CrittercismConfig();

            // Set the version name
            if (custom_app_version != null) {
                config.setCustomVersionName(custom_app_version);
                config.setVersionCodeToBeIncludedInVersionString(false);
            } else {
                config.setCustomVersionName(
                        activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0).versionName);
                config.setVersionCodeToBeIncludedInVersionString(true);
            }

            // Send logcat info
            if (should_collect_logcat != null && should_collect_logcat) {
                config.setLogcatReportingEnabled(should_collect_logcat);
            }

            // Initialize.
            Crittercism.initialize(activity.getApplicationContext(), app_id, config);

            handleLastCrash();
        } catch (Exception e) {
            // Well... we couldn't start...
            // Log.e(LCAT, "Can't inialize because of: "+e);
        }
        ;
    } else {
        // There's no app id... we can't start it
        // Log.e(LCAT, "Crittercism cannot be initialized without an app id!");
    }
}