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:com.mbientlab.metawear.app.ModuleListFragment.java

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

    // Activities containing this fragment must implement its callbacks.
    if (!(activity instanceof Callbacks)) {
        throw new IllegalStateException("Activity must implement fragment's callbacks.");
    }//  w w  w .j  a v  a2  s. co  m

    mCallbacks = (Callbacks) activity;
    activity.getApplicationContext().bindService(new Intent(activity, MetaWearBleService.class), this,
            Context.BIND_AUTO_CREATE);
}

From source file:es.javocsoft.android.lib.toolbox.ads.AdBase.java

private AdRequest requestAds(Activity activity) {
    Log.i(ToolBox.TAG, "Ads: Creating adRequest.");

    // Create ad request.
    AdRequest.Builder adBuilder = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR);

    if (ToolBox.application_isAppInDebugMode(activity)) {
        //We exclude current device to avoid being penalized by AdMob.
        String deviceAdmobId = getAdmobDeviceId(activity.getApplicationContext());
        Log.i(ToolBox.TAG, "AdMob -> Debug Mode ON. Adding current device AdMobId '" + deviceAdmobId + "' "
                + "to test device list.");
        adBuilder.addTestDevice(deviceAdmobId);
    }//from  w  w  w  . j a va 2  s .  co m

    AdRequest adRequest = adBuilder.build();

    return adRequest;
}

From source file:com.mirasense.scanditsdk.plugin.SubViewPickerController.java

@Override
public void show(final JSONObject settings, final Bundle options, final Bundle overlayOptions,
        boolean legacyMode) {
    mPendingClose.set(false);//  www  .  j av a  2s .co  m
    mLegacyMode = legacyMode;
    mContinuousMode = PhonegapParamParser.shouldRunInContinuousMode(options);
    mOrientationHandler = new SubViewPickerOrientationHandler(Looper.getMainLooper(), mPlugin, null);
    mCloseWhenDidScanCallbackFinishes = false;
    mOrientationHandler.start(true);
    final Activity pluginActivity = mPlugin.cordova.getActivity();
    DisplayMetrics display = pluginActivity.getApplicationContext().getResources().getDisplayMetrics();
    int width = (int) (display.widthPixels * 160.f / display.densityDpi);
    int height = (int) (display.heightPixels * 160.f / display.densityDpi);
    mScreenDimensions = new Point(Math.min(width, height), Math.max(width, height));

    // initialization must be performed on main thread.
    this.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            ScanSettings scanSettings;
            if (settings == null) {
                scanSettings = LegacySettingsParamParser.getSettings(options);
            } else {
                try {
                    scanSettings = ScanSettings.createWithJson(settings);
                } catch (JSONParseException e) {
                    Log.e("ScanditSDK", "Exception while creating settings");
                    e.printStackTrace();
                    sendRuntimeError("Exception while creating settings: " + e.getMessage()
                            + ". Falling back to default scan settings.");
                    scanSettings = ScanSettings.create();
                }
            }
            BarcodePickerWithSearchBar picker = new BarcodePickerWithSearchBar(pluginActivity, scanSettings);
            picker.setOnScanListener(SubViewPickerController.this);
            mPickerStateMachine = new PickerStateMachine(picker, SubViewPickerController.this);
            mOrientationHandler.setScreenDimensions(mScreenDimensions);
            mOrientationHandler.setPicker(mPickerStateMachine.getPicker());
            // Set all the UI options.
            PhonegapParamParser.updatePicker(picker, options, SubViewPickerController.this);
            internalUpdateUI(overlayOptions, options);
            // Create the layout to add the picker to and add it on top of the web view.
            mLayout = new RelativeLayout(pluginActivity);
            ViewGroup viewGroup = getPickerParent();
            if (viewGroup == null)
                return; // couldn't determine view group, nothing to be done.
            viewGroup.addView(mLayout);
            RelativeLayout.LayoutParams rLayoutParams = new RelativeLayout.LayoutParams(
                    RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
            mLayout.addView(mPickerStateMachine.getPicker(), rLayoutParams);
            PhonegapParamParser.updateLayout(pluginActivity, mPickerStateMachine.getPicker(), options,
                    mScreenDimensions);

            if (mPendingClose.compareAndSet(true, false)) {
                // picker was closed(canceled) in the meantime. close it now.
                SubViewPickerController.this.close();
            }
            if (!mLegacyMode)
                return;

            // In legacy mode, start scanning when show is called.
            int state = PhonegapParamParser.shouldStartInPausedState(options) ? PickerStateMachine.PAUSED
                    : PickerStateMachine.ACTIVE;
            mPickerStateMachine.setState(state);

        }
    });
}

From source file:net.niyonkuru.koodroid.ui.PageFragment.java

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

    mContext = activity.getApplicationContext();

    mSettings = App.getSettings();//from   w  w w .j a  va 2 s.  c o m

    Locale locale = new Locale(getString(R.string.locale), "CA");

    mNumberFormat = DecimalFormat.getInstance(locale);
    mCurrencyFormat = CurrencyUtils.getCurrencyFormat(locale);

    try {
        mCallBack = (BaseCallBack) activity;
    } catch (ClassCastException e) {
        throw new ClassCastException(activity.toString() + " must implement BaseCallBack type");
    }
}

From source file:com.anysoftkeyboard.ui.dev.DeveloperToolsFragment.java

private void onUserClickedMemoryDump() {
    DeveloperAsyncTask<Void, Void, File> task = new DeveloperAsyncTask<Void, Void, File>(this) {

        @Override//from  w w  w . ja  va2s  .c  om
        protected File doAsyncTask(Void[] params) throws Exception {
            return DeveloperUtils.createMemoryDump();
        }

        @Override
        protected void applyResults(File result, Exception backgroundException) {
            Activity activity = getActivity();
            if (activity == null)
                return;
            View rootView = getView();
            if (rootView == null)
                return;

            if (backgroundException != null) {
                Toast.makeText(activity.getApplicationContext(),
                        getString(R.string.failed_to_create_mem_dump, backgroundException.getMessage()),
                        Toast.LENGTH_LONG).show();
            } else {
                Toast.makeText(activity.getApplicationContext(),
                        getString(R.string.created_mem_dump_file, result.getAbsolutePath()), Toast.LENGTH_LONG)
                        .show();
                View shareMemFile = rootView.findViewById(R.id.dev_share_mem_file);
                shareMemFile.setTag(result);
                shareMemFile.setEnabled(result.exists() && result.isFile());
            }
        }
    };
    task.execute();
}

From source file:org.chromium.chrome.browser.media.remote.RemoteMediaPlayerController.java

/**
 * Links this object to the Activity that owns the video, if it exists.
 *
 *//*w  w w  .j a  v a 2 s. c  o  m*/
private void linkToBrowserActivity() {

    Activity currentActivity = ApplicationStatus.getLastTrackedFocusedActivity();
    if (currentActivity != null) {
        mChromeVideoActivity = new WeakReference<Activity>(currentActivity);

        mCastContextApplicationContext = currentActivity.getApplicationContext();
        createMediaRouteControllers(currentActivity);
    }
}

From source file:com.amazon.android.navigator.Navigator.java

public Navigator(Activity activity, String navigatorFilePath) {

    mCurrentActivity = activity;/*from  w ww.  java 2  s  .  c om*/
    mContext = activity.getApplicationContext();
    ((Application) mContext.getApplicationContext()).registerActivityLifecycleCallbacks(this);

    try {
        mNavigatorModel = NavigatorModelParser.parse(mContext, navigatorFilePath);

        // Traverse graph nodes.
        for (String entry : mNavigatorModel.getGraph().keySet()) {
            Graph.Node node = mNavigatorGraph.getNodeByName(entry);
            if (node == null) {
                node = new Graph.Node(entry);
                mNavigatorGraph.addNode(node);
            }

            // Add UI node.
            UINode uiNode = mNavigatorModel.getGraph().get(entry);
            node.setObject(uiNode);

            // Set screen name maps.
            mScreenNameClassMap.put(uiNode.getOnAction(), Class.forName(entry));
            mScreenNameMap.put(entry, uiNode.getOnAction());

            List<String> connections = uiNode.getNodes();
            if (connections != null) {
                for (String connection : connections) {
                    Graph.Node connectionNode = mNavigatorGraph.getNodeByName(connection);
                    if (connectionNode == null) {
                        connectionNode = new Graph.Node(connection);
                    }
                    mNavigatorGraph.addConnection(node, connectionNode);
                }
            }
        }
    } catch (Exception e) {
        Log.e(TAG, "Error traversing the graph nodes. ", e);
    }

    Log.v(TAG, "Navigator Graph: " + mNavigatorGraph);
}

From source file:com.example.android.apprestrictionenforcer.SetupProfileFragment.java

/**
 * Initiates the managed profile provisioning. If we already have a managed profile set up on
 * this device, we will get an error dialog in the following provisioning phase.
 *///from  w ww .  ja v  a2  s .  com
private void provisionManagedProfile() {
    Activity activity = getActivity();
    if (null == activity) {
        return;
    }
    Intent intent = new Intent(ACTION_PROVISION_MANAGED_PROFILE);
    if (Build.VERSION.SDK_INT >= 24) {
        intent.putExtra(EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME,
                EnforcerDeviceAdminReceiver.getComponentName(activity));
    } else {
        intent.putExtra(EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME,
                activity.getApplicationContext().getPackageName());
        intent.putExtra(EXTRA_DEVICE_ADMIN, EnforcerDeviceAdminReceiver.getComponentName(activity));
    }
    if (intent.resolveActivity(activity.getPackageManager()) != null) {
        startActivityForResult(intent, REQUEST_PROVISION_MANAGED_PROFILE);
        activity.finish();
    } else {
        Toast.makeText(activity, "Device provisioning is not enabled. Stopping.", Toast.LENGTH_SHORT).show();
    }
}

From source file:com.smedic.tubtub.YouTubeSearch.java

public YouTubeSearch(Activity activity, Fragment playlistFragment) {
    this.activity = activity;
    this.playlistFragment = playlistFragment;
    handler = new Handler();
    credential = GoogleAccountCredential.usingOAuth2(activity.getApplicationContext(),
            Arrays.asList(Auth.SCOPES));
    credential.setBackOff(new ExponentialBackOff());
    appName = activity.getResources().getString(R.string.app_name);
}

From source file:ly.kite.facebookphotopicker.FacebookAgent.java

private FacebookAgent(Activity activity) {
    mActivity = activity;

    FacebookSdk.sdkInitialize(activity.getApplicationContext());

    mCallbackManager = CallbackManager.Factory.create();
}