Search in sources :

Example 26 with Application

use of android.app.Application in project platform_frameworks_base by android.

the class RemoteViews method getApplicationInfo.

private static ApplicationInfo getApplicationInfo(String packageName, int userId) {
    if (packageName == null) {
        return null;
    }
    // Get the application for the passed in package and user.
    Application application = ActivityThread.currentApplication();
    if (application == null) {
        throw new IllegalStateException("Cannot create remote views out of an aplication.");
    }
    ApplicationInfo applicationInfo = application.getApplicationInfo();
    if (UserHandle.getUserId(applicationInfo.uid) != userId || !applicationInfo.packageName.equals(packageName)) {
        try {
            Context context = application.getBaseContext().createPackageContextAsUser(packageName, 0, new UserHandle(userId));
            applicationInfo = context.getApplicationInfo();
        } catch (NameNotFoundException nnfe) {
            throw new IllegalArgumentException("No such package " + packageName);
        }
    }
    return applicationInfo;
}
Also used : Context(android.content.Context) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) UserHandle(android.os.UserHandle) ApplicationInfo(android.content.pm.ApplicationInfo) Application(android.app.Application)

Example 27 with Application

use of android.app.Application in project flow by square.

the class Installer method install.

@NonNull
public Context install() {
    if (InternalLifecycleIntegration.find(activity) != null) {
        throw new IllegalStateException("Flow is already installed in this Activity.");
    }
    Dispatcher dispatcher = this.dispatcher;
    if (dispatcher == null) {
        dispatcher = //
        KeyDispatcher.configure(activity, new DefaultKeyChanger(activity)).build();
    }
    final Object defState = defaultKey == null ? "Hello, World!" : defaultKey;
    final History defaultHistory = History.single(defState);
    final Application app = (Application) baseContext.getApplicationContext();
    final KeyManager keyManager = new KeyManager(contextFactories);
    InternalLifecycleIntegration.install(app, activity, parceler, defaultHistory, dispatcher, keyManager);
    return new InternalContextWrapper(baseContext, activity);
}
Also used : Application(android.app.Application) NonNull(android.support.annotation.NonNull)

Example 28 with Application

use of android.app.Application in project robospice by stephanenicolas.

the class JsonObjectPersisterFactoryTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    Thread.sleep(SMALL_THREAD_SLEEP);
    Application application = (Application) getContext().getApplicationContext();
    JsonObjectPersisterFactory factory = getJsonObjectPersisterFactory(application);
    inFileObjectPersister = factory.createInFileObjectPersister(WeatherResult.class, null);
}
Also used : WeatherResult(com.octo.android.robospice.googlehttpclient.test.model.WeatherResult) Application(android.app.Application)

Example 29 with Application

use of android.app.Application in project robospice by stephanenicolas.

the class InDatabaseWeatherPersisterTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    Application application = (Application) getInstrumentation().getTargetContext().getApplicationContext();
    List<Class<?>> classCollection = new ArrayList<Class<?>>();
    // add persisted classes to class collection
    classCollection.add(Weather.class);
    classCollection.add(CurrenWeather.class);
    classCollection.add(Day.class);
    classCollection.add(Forecast.class);
    classCollection.add(Night.class);
    classCollection.add(Wind.class);
    RoboSpiceDatabaseHelper databaseHelper = new RoboSpiceDatabaseHelper(application, "sample_database.db", 1);
    databaseHelper.clearTableFromDataBase(Weather.class);
    InDatabaseObjectPersisterFactory inDatabaseObjectPersisterFactory = new InDatabaseObjectPersisterFactory(application, databaseHelper, classCollection);
    dataPersistenceManager = inDatabaseObjectPersisterFactory.createObjectPersister(Weather.class);
    TEST_TEMP.setTemp("28");
    TEST_TEMP.setTemp_unit("C");
    TEST_TEMP2.setTemp("30");
    TEST_TEMP2.setTemp_unit("C");
}
Also used : CurrenWeather(com.octo.android.robospice.ormlite.test.model.CurrenWeather) Weather(com.octo.android.robospice.ormlite.test.model.Weather) ArrayList(java.util.ArrayList) Application(android.app.Application)

Example 30 with Application

use of android.app.Application in project robospice by stephanenicolas.

the class JsonObjectPersisterFactoryTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    Thread.sleep(SMALL_THREAD_SLEEP);
    Application application = (Application) getContext().getApplicationContext();
    RetrofitObjectPersisterFactory factory = getRetrofitObjectPersisterFactory(application);
    inFileObjectPersister = factory.createObjectPersister(WeatherResult.class);
}
Also used : WeatherResult(com.octo.android.robospice.retrofit.test.model.WeatherResult) Application(android.app.Application)

Aggregations

Application (android.app.Application)123 Test (org.junit.Test)26 Context (android.content.Context)24 Activity (android.app.Activity)22 ApplicationInfo (android.content.pm.ApplicationInfo)12 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)11 File (java.io.File)10 MvpPresenter (com.hannesdorfmann.mosby3.mvp.MvpPresenter)8 Before (org.junit.Before)8 MvpView (com.hannesdorfmann.mosby3.mvp.MvpView)7 ShadowApplication (org.robolectric.shadows.ShadowApplication)7 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)6 PrintWriter (java.io.PrintWriter)6 Date (java.util.Date)6 PackageInfo (android.content.pm.PackageInfo)5 PackageManager (android.content.pm.PackageManager)5 RemoteException (android.os.RemoteException)5 AbsoluteSizeSpan (android.text.style.AbsoluteSizeSpan)5 BackgroundColorSpan (android.text.style.BackgroundColorSpan)5 CharacterStyle (android.text.style.CharacterStyle)5