Example usage for android.app Activity getApplication

List of usage examples for android.app Activity getApplication

Introduction

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

Prototype

public final Application getApplication() 

Source Link

Document

Return the application that owns this activity.

Usage

From source file:piuk.blockchain.android.ui.SendCoinsFragment.java

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final Activity activity = getActivity();

    application = (WalletApplication) activity.getApplication();

    activity.bindService(new Intent(activity, BlockchainServiceImpl.class), serviceConnection,
            Context.BIND_AUTO_CREATE);
}

From source file:com.microsoft.office365.starter.models.O365FileListModel.java

public void postDeleteSelectedFileFromServer(final Activity currentActivity, SharePointClient fileClient,
        int itemPosition) {
    if (itemPosition == ListView.INVALID_POSITION) {
        // Notify caller that no file was selected for the delete
        OperationResult opResult = new OperationResult("Post delete selected file ",
                "failed: No file selected to delete", "");
        mEventOperationCompleteListener.onOperationComplete(opResult);
        return;//from w  ww. j  a v  a  2 s . co  m
    }
    final int index = itemPosition; // cache this for the return trip thread
    // before reset at end
    // of this method
    O365FileModel fileToDelete = mApplication.getFileAdapterList().getItem(index);

    final O365APIsStart_Application application = (O365APIsStart_Application) currentActivity.getApplication();
    ListenableFuture future = fileClient.getfiles().getById(fileToDelete.getId()).asFile()
            .addHeader("If-Match", "*").delete();

    Futures.addCallback(future, new FutureCallback() {
        @Override
        public void onFailure(Throwable t) {
            Log.e("Asset", t.getMessage());
            // Notify caller that the Event update operation failed
            OperationResult opResult = new OperationResult("Post delete selected file ",
                    "failed: " + getErrorMessage(t.getMessage()), "");
            mEventOperationCompleteListener.onOperationComplete(opResult);
        }

        @Override
        public void onSuccess(Object obj) {
            currentActivity.runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    application.getFileListViewState().deleteSelectedFileFromList(index);
                }
            });
            // Notify caller that the Event update operation is complete and
            // succeeded
            OperationResult opResult = new OperationResult("Post delete selected file on server",
                    "Posted delete selected file on server", "FileDeleted");
            mEventOperationCompleteListener.onOperationComplete(opResult);
        }
    });
    // selectedItem = -1;
}

From source file:de.schildbach.litecoinwallet.ui.SendCoinsFragment.java

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

    this.activity = (AbstractBindServiceActivity) activity;
    this.application = (WalletApplication) activity.getApplication();
    this.prefs = PreferenceManager.getDefaultSharedPreferences(activity);
    this.wallet = application.getWallet();
    this.contentResolver = activity.getContentResolver();
    this.loaderManager = getLoaderManager();
}

From source file:com.microsoft.office365.starter.FilesFolders.O365FileListModel.java

public void postDeleteSelectedFileFromServer(final Activity currentActivity, SharePointClient fileClient,
        int itemPosition) {
    if (itemPosition == ListView.INVALID_POSITION) {
        // Notify caller that no file was selected for the delete
        OperationResult opResult = new OperationResult("Post delete selected file ",
                "failed: No file selected to delete", "");
        mEventOperationCompleteListener.onOperationComplete(opResult);
        return;/*from   w w  w.  j a  v  a2  s  .  co m*/
    }
    final int index = itemPosition; // cache this for the return trip thread
    // before reset at end
    // of this method
    O365FileModel fileToDelete = mApplication.getFileAdapterList().getItem(index);

    final O365APIsStart_Application application = (O365APIsStart_Application) currentActivity.getApplication();
    ListenableFuture future = fileClient.getfiles().getById(fileToDelete.getId()).addHeader("If-Match", "*")
            .delete();

    Futures.addCallback(future, new FutureCallback() {
        @Override
        public void onFailure(Throwable t) {
            Log.e("Asset", t.getMessage());
            // Notify caller that the Event update operation failed
            OperationResult opResult = new OperationResult("Post delete selected file ",
                    "failed: " + APIErrorMessageHelper.getErrorMessage(t.getMessage()), "");
            mEventOperationCompleteListener.onOperationComplete(opResult);
        }

        @Override
        public void onSuccess(Object obj) {
            currentActivity.runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    application.getFileListViewState().deleteSelectedFileFromList(index);
                }
            });
            // Notify caller that the Event update operation is complete and
            // succeeded
            OperationResult opResult = new OperationResult("Post delete selected file on server",
                    "Posted delete selected file on server", "FileDeleted");
            mEventOperationCompleteListener.onOperationComplete(opResult);
        }
    });
    // selectedItem = -1;
}

From source file:io.teak.sdk.Teak.java

/**
 * Initialize Teak and tell it to listen to the lifecycle events of {@link Activity}.
 * <p/>//from  w ww  . ja v  a2 s . co m
 * <p>Call this function from the {@link Activity#onCreate} function of your <code>Activity</code>
 * <b>before</b> the call to <code>super.onCreate()</code></p>
 *
 * @param activity The main <code>Activity</code> of your app.
 */
public static void onCreate(Activity activity) {
    Log.d(LOG_TAG, "Android SDK Version: " + Teak.SDKVersion);

    if (activity == null) {
        Log.e(LOG_TAG, "null Activity passed to onCreate, Teak is disabled.");
        Teak.setState(State.Disabled);
        return;
    }

    {
        String airSdkVersion = Helpers.getStringResourceByName("io_teak_air_sdk_version",
                activity.getApplicationContext());
        if (airSdkVersion != null) {
            Log.d(LOG_TAG, "Adobe AIR SDK Version: " + airSdkVersion);
        }
    }

    // Set up debug logging ASAP
    try {
        final Context context = activity.getApplicationContext();
        final ApplicationInfo applicationInfo = context.getApplicationInfo();
        Teak.debugConfiguration = new DebugConfiguration(context);
        Teak.isDebug = Teak.forceDebug || Teak.debugConfiguration.forceDebug || (applicationInfo != null
                && (0 != (applicationInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE)));
    } catch (Exception e) {
        Log.e(LOG_TAG, "Error creating DebugConfiguration. " + Log.getStackTraceString(e));
    }

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        Log.e(LOG_TAG, "Teak requires API level 14 to operate. Teak is disabled.");
        Teak.setState(State.Disabled);
    } else {
        try {
            Application application = activity.getApplication();
            synchronized (Teak.stateMutex) {
                if (Teak.state == State.Allocated) {
                    application.registerActivityLifecycleCallbacks(Teak.lifecycleCallbacks);
                }
            }
        } catch (Exception e) {
            Log.e(LOG_TAG, "Failed to register Activity lifecycle callbacks. Teak is disabled. "
                    + Log.getStackTraceString(e));
            Teak.setState(State.Disabled);
        }
    }
}

From source file:com.nextgis.maplibui.overlay.EditLayerOverlay.java

protected boolean movePointToLocation() {
    Activity parent = (Activity) mContext;
    GpsEventSource gpsEventSource = ((IGISApplication) parent.getApplication()).getGpsEventSource();
    Location location = gpsEventSource.getLastKnownLocation();

    if (null != location) {
        //change to screen coordinates
        GeoPoint pt = new GeoPoint(location.getLongitude(), location.getLatitude());
        pt.setCRS(GeoConstants.CRS_WGS84);
        pt.project(GeoConstants.CRS_WEB_MERCATOR);
        GeoPoint screenPt = mMap.mapToScreen(pt);
        return moveSelectedPoint((float) screenPt.getX(), (float) screenPt.getY());
    } else//from  ww  w.  jav a  2s  .  c o m
        Toast.makeText(parent, R.string.error_no_location, Toast.LENGTH_SHORT).show();

    return false;
}

From source file:cc.mintcoin.wallet.ui.SendCoinsFragment.java

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

    this.activity = (AbstractBindServiceActivity) activity;
    this.application = (WalletApplication) activity.getApplication();
    this.config = application.getConfiguration();
    this.wallet = application.getWallet();
    this.contentResolver = activity.getContentResolver();
    this.loaderManager = getLoaderManager();
}

From source file:com.bushstar.htmlcoin_android_wallet.ui.SendCoinsFragment.java

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

    this.activity = (AbstractBindServiceActivity) activity;
    this.application = (WalletApplication) activity.getApplication();
    this.config = application.getConfiguration();
    this.wallet = application.getWallet();
    this.contentResolver = activity.getContentResolver();
    this.loaderManager = getLoaderManager();
    this.fragmentManager = getFragmentManager();
}

From source file:org.onepf.opfiab.opfiab_uitest.tests.ui.UnifiedFragmentHelperTest.java

public static void registerUnregisterHomeButton(Instrumentation instrumentation, final Activity activity,
        UiDevice uiDevice) throws InterruptedException {

    final String providerName = String.format(TEST_PROVIDER_NAME_FMT, "HOME");
    final BillingProvider billingProvider = new MockBillingProviderBuilder().setWillPostSuccess(true)
            .setName(providerName).setIsAvailable(true).setSleepTime(WAIT_BILLING_PROVIDER).build();

    final TestManager testPurchaseManager = new TestManager.Builder()
            .expectEvent(new PurchaseResponseValidator(providerName, true))
            .expectEvent(new PurchaseResponseValidator(providerName, true))
            .expectEvent(new AlwaysFailValidator()).setTag("Purchase").setSkipWrongEvents(false).build();
    final BillingManagerAdapter purchaseListenerAdapter = new BillingManagerAdapter(testPurchaseManager);

    final TestManager testGlobalListenerManager = new TestManager.Builder()
            .expectEvent(new SetupStartedEventValidator()).expectEvent(new SetupResponseValidator(providerName))
            .expectEvent(new PurchaseRequestValidator(SKU_CONSUMABLE))
            .expectEvent(new PurchaseResponseValidator(providerName, true))
            .expectEvent(new PurchaseRequestValidator(SKU_CONSUMABLE))
            .expectEvent(new PurchaseResponseValidator(providerName, true))
            .expectEvent(new PurchaseRequestValidator(SKU_CONSUMABLE))
            .expectEvent(new PurchaseResponseValidator(providerName, true))
            .setStrategy(TestManager.Strategy.UNORDERED_EVENTS).setTag("Global").build();

    final TestManager[] managers = { testGlobalListenerManager, testPurchaseManager };

    final Configuration configuration = new Configuration.Builder().addBillingProvider(billingProvider)
            .setBillingListener(new BillingManagerAdapter(testGlobalListenerManager)).build();

    instrumentation.runOnMainSync(new Runnable() {
        @Override//from w w w  . ja v  a 2  s .com
        public void run() {
            OPFIab.init(activity.getApplication(), configuration);
        }
    });
    Thread.sleep(WAIT_INIT);
    final boolean isSupport = activity instanceof FragmentActivity;
    Object fragment = createFragment(isSupport, activity, instrumentation, R.color.blue);

    FragmentIabHelper helper = getHelper(isSupport, fragment, purchaseListenerAdapter, instrumentation);

    purchase(instrumentation, helper, SKU_CONSUMABLE);

    changeToHomeScreen(uiDevice);

    purchase(instrumentation, helper, SKU_CONSUMABLE);

    reopenActivity(instrumentation);

    fragment = getFragment(isSupport);
    helper = getHelper(isSupport, fragment, purchaseListenerAdapter, instrumentation);

    pressBackButton(uiDevice);

    purchase(instrumentation, helper, SKU_CONSUMABLE);

    purchaseListenerAdapter.validateEvent(AlwaysFailValidator.getStopObject());

    for (TestManager manager : managers) {
        Assert.assertTrue(manager.await(WAIT_TEST_MANAGER));
    }
}

From source file:org.onepf.opfiab.opfiab_uitest.tests.ui.UnifiedFragmentHelperTest.java

public static void registerUnregisterFragmentReplace(Instrumentation instrumentation, final Boolean isSupport,
        UiDevice uiDevice) throws InterruptedException {
    final String providerName = String.format(TEST_PROVIDER_NAME_FMT, "FRAGMENT_REPLACE");
    final Activity activity;
    if (isSupport) {
        activity = EmptyFragmentActivity.getLastInstance();
    } else {/*from ww  w  . ja va2s. co  m*/
        activity = EmptyActivity.getLastInstance();
    }

    final BillingProvider billingProvider = new MockBillingProviderBuilder().setWillPostSuccess(true)
            .setName(providerName).setIsAvailable(true).setSleepTime(WAIT_BILLING_PROVIDER).build();

    final TestManager testPurchaseManager = new TestManager.Builder()
            .expectEvent(new PurchaseResponseValidator(providerName, true))
            .expectEvent(new AlwaysFailValidator())
            .expectEvent(new PurchaseResponseValidator(providerName, true)).setTag("Purchase").build();
    final BillingManagerAdapter purchaseListenerAdapter = new BillingManagerAdapter(testPurchaseManager);

    final TestManager testGlobalListenerManager = new TestManager.Builder()
            .expectEvent(new SetupStartedEventValidator()).expectEvent(new SetupResponseValidator(providerName))
            .expectEvent(new PurchaseRequestValidator(SKU_CONSUMABLE))
            .expectEvent(new PurchaseResponseValidator(providerName, true))
            .expectEvent(new PurchaseRequestValidator(SKU_CONSUMABLE))
            .expectEvent(new PurchaseResponseValidator(providerName, true))
            .expectEvent(new PurchaseRequestValidator(SKU_CONSUMABLE))
            .expectEvent(new PurchaseResponseValidator(providerName, true))
            .setStrategy(TestManager.Strategy.UNORDERED_EVENTS).setTag("Global").build();

    final Configuration configuration = new Configuration.Builder().addBillingProvider(billingProvider)
            .setBillingListener(new BillingManagerAdapter(testGlobalListenerManager)).build();

    final TestManager[] managers = { testGlobalListenerManager, testPurchaseManager };

    final FragmentIabHelper[] helpers = new FragmentIabHelper[1];
    instrumentation.runOnMainSync(new Runnable() {
        @Override
        public void run() {
            OPFIab.init(activity.getApplication(), configuration);
        }
    });
    Thread.sleep(WAIT_INIT);
    final Object fragment = createFragment(isSupport, activity, instrumentation, R.color.green);
    final FragmentIabHelper helper = getHelper(isSupport, fragment, purchaseListenerAdapter, instrumentation);

    purchase(instrumentation, helper, SKU_CONSUMABLE);
    Thread.sleep(WAIT_PURCHASE);

    replaceFragment(activity);

    purchase(instrumentation, helper, SKU_CONSUMABLE);
    Thread.sleep(WAIT_LAUNCH_SCREEN);

    restoreFragment(activity);

    purchaseListenerAdapter.validateEvent(AlwaysFailValidator.getStopObject());

    purchase(instrumentation, helper, SKU_CONSUMABLE);
    Thread.sleep(WAIT_PURCHASE);

    for (TestManager manager : managers) {
        Assert.assertTrue(manager.await(WAIT_TEST_MANAGER));
    }
}