Java Code Examples for android.app.Activity#getApplication()

The following examples show how to use android.app.Activity#getApplication() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: react-native-restart   File: RestartModule.java    License: MIT License 6 votes vote down vote up
private ReactInstanceManager resolveInstanceManager() throws NoSuchFieldException, IllegalAccessException {
    ReactInstanceManager instanceManager = getReactInstanceManager();
    if (instanceManager != null) {
        return instanceManager;
    }

    final Activity currentActivity = getCurrentActivity();
    if (currentActivity == null) {
        return null;
    }

    ReactApplication reactApplication = (ReactApplication) currentActivity.getApplication();
    instanceManager = reactApplication.getReactNativeHost().getReactInstanceManager();

    return instanceManager;
}
 
Example 2
private static void unarchiveContact (Activity activity, String address, int contactType, long providerId, long accountId)
{

    try {

        IImConnection mConn;
        ImApp app = ((ImApp)activity.getApplication());
        mConn = app.getConnection(providerId, accountId);
        //then delete the contact from our list
        IContactListManager manager = mConn.getContactListManager();

        int res = manager.archiveContact(address,contactType,false);
        if (res != ImErrorInfo.NO_ERROR) {
            //mHandler.showAlert(R.string.error,
            //      ErrorResUtils.getErrorRes(getResources(), res, address));
        }


    }
    catch (RemoteException re)
    {

    }


}
 
Example 3
Source Project: Xndroid   File: ProxyUtils.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Constants.Proxy
public static int setProxyChoice(int choice, @NonNull Activity activity) {
    switch (choice) {
        case Constants.PROXY_ORBOT:
            if (!OrbotHelper.isOrbotInstalled(activity)) {
                choice = Constants.NO_PROXY;
                Utils.showSnackbar(activity, R.string.install_orbot);
            }
            break;
        case Constants.PROXY_I2P:
            I2PAndroidHelper ih = new I2PAndroidHelper(activity.getApplication());
            if (!ih.isI2PAndroidInstalled()) {
                choice = Constants.NO_PROXY;
                ih.promptToInstall(activity);
            }
            break;
        case Constants.PROXY_MANUAL:
            break;
    }
    return choice;
}
 
Example 4
Source Project: delion   File: DomDistillerUIUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * A static method for native code to open the external feedback form UI.
 * @param webContents The WebContents containing the distilled content.
 * @param url The URL to report feedback for.
 * @param good True if the feedback is good and false if not.
 */
@CalledByNative
public static void reportFeedbackWithWebContents(
        WebContents webContents, String url, final boolean good) {
    ThreadUtils.assertOnUiThread();
    // TODO(mdjones): It would be better to get the WebContents from the manager so that the
    // native code does not need to depend on RenderFrame.
    Activity activity = getActivityFromWebContents(webContents);
    if (activity == null) return;

    if (sFeedbackReporter == null) {
        ChromeApplication application = (ChromeApplication) activity.getApplication();
        sFeedbackReporter = application.createFeedbackReporter();
    }
    FeedbackCollector.create(activity, Profile.getLastUsedProfile(), url,
            new FeedbackCollector.FeedbackResult() {
                @Override
                public void onResult(FeedbackCollector collector) {
                    String quality =
                            good ? DISTILLATION_QUALITY_GOOD : DISTILLATION_QUALITY_BAD;
                    collector.add(DISTILLATION_QUALITY_KEY, quality);
                    sFeedbackReporter.reportFeedback(collector);
                }
            });
}
 
Example 5
Source Project: raygun4android   File: RUM.java    License: MIT License 6 votes vote down vote up
private static void attach(Activity mainActivity) {

        RaygunLogger.v("attached RUM");
        if (RUM.rum == null && mainActivity != null) {
            Application application = mainActivity.getApplication();

            if (application != null) {
                RUM.mainActivity = new WeakReference<>(mainActivity);
                RUM.currentActivity = new WeakReference<>(mainActivity);
                RUM.startTime = System.nanoTime();

                RUM.rum = new RUM();
                application.registerActivityLifecycleCallbacks(RUM.rum);

                if (doesNeedSessionRotation()) {
                    rotateSession(currentSessionUser, currentSessionUser);
                }

                RaygunNetworkLogger.init();
            }
        }

        RUM.lastSeenTime = System.currentTimeMillis();
    }
 
Example 6
/**
 * A static method for native code to open the external feedback form UI.
 * @param webContents The WebContents containing the distilled content.
 * @param url The URL to report feedback for.
 * @param good True if the feedback is good and false if not.
 */
@CalledByNative
public static void reportFeedbackWithWebContents(
        WebContents webContents, String url, final boolean good) {
    ThreadUtils.assertOnUiThread();
    // TODO(mdjones): It would be better to get the WebContents from the manager so that the
    // native code does not need to depend on RenderFrame.
    Activity activity = getActivityFromWebContents(webContents);
    if (activity == null) return;

    if (sFeedbackReporter == null) {
        ChromeApplication application = (ChromeApplication) activity.getApplication();
        sFeedbackReporter = application.createFeedbackReporter();
    }
    FeedbackCollector.create(activity, Profile.getLastUsedProfile(), url,
            new FeedbackCollector.FeedbackResult() {
                @Override
                public void onResult(FeedbackCollector collector) {
                    String quality =
                            good ? DISTILLATION_QUALITY_GOOD : DISTILLATION_QUALITY_BAD;
                    collector.add(DISTILLATION_QUALITY_KEY, quality);
                    sFeedbackReporter.reportFeedback(collector);
                }
            });
}
 
Example 7
Source Project: JumpGo   File: ProxyUtils.java    License: Mozilla Public License 2.0 6 votes vote down vote up
@Constants.Proxy
public static int setProxyChoice(int choice, @NonNull Activity activity) {
    switch (choice) {
        case Constants.PROXY_ORBOT:
            if (!OrbotHelper.isOrbotInstalled(activity)) {
                choice = Constants.NO_PROXY;
                Utils.showSnackbar(activity, R.string.install_orbot);
            }
            break;
        case Constants.PROXY_I2P:
            I2PAndroidHelper ih = new I2PAndroidHelper(activity.getApplication());
            if (!ih.isI2PAndroidInstalled()) {
                choice = Constants.NO_PROXY;
                ih.promptToInstall(activity);
            }
            break;
        case Constants.PROXY_MANUAL:
            break;
    }
    return choice;
}
 
Example 8
Source Project: scene   File: SceneViewModelProviders.java    License: Apache License 2.0 5 votes vote down vote up
private static Application checkApplication(Activity activity) {
    Application application = activity.getApplication();
    if (application == null) {
        throw new IllegalStateException("Your activity is not yet attached to "
                + "Application. You can't request ViewModel before onCreate call.");
    }
    return application;
}
 
Example 9
public static void moveMap(
        Activity activity,
        File path)
{
    MainApplication application = (MainApplication) activity.getApplication();
    if (null == application) {
        return;
    }

    ContentResolver.cancelSync(null, application.getAuthority());

    BackgroundMoveTask moveTask = new BackgroundMoveTask(activity, application.getMap(), path);
    moveTask.execute();
}
 
Example 10
Source Project: android-task   File: Task.java    License: Apache License 2.0 5 votes vote down vote up
final void setCachedActivity(Activity activity) {
    synchronized (mMonitor) {
        if (mApplication == null) {
            mApplication = activity.getApplication();
        }
        mCachedActivity = new WeakReference<>(activity);
    }
}
 
Example 11
@Override
public void onDestroy() {
    super.onDestroy();
    Activity activity = getActivity();
    if (activity != null) {
        ThetaDeviceApplication app = (ThetaDeviceApplication) activity.getApplication();
        ThetaDeviceManager deviceManager = app.getDeviceManager();
        deviceManager.unregisterDeviceEventListener(this);
    }
}
 
Example 12
/**
 * Gets a instance of UVCDeviceManager.
 *
 * @return UVCDeviceManager
 */
private UVCDeviceManager getManager() {
    Activity activity = getActivity();
    if (activity == null) {
        return null;
    }
    UVCDeviceApplication application =
            (UVCDeviceApplication) activity.getApplication();
    return application.getDeviceManager();
}
 
Example 13
Source Project: android-task   File: TaskExecutor.java    License: Apache License 2.0 5 votes vote down vote up
private synchronized int executeInner(Task<?> task, Activity activity, String annotationId, String fragmentId) {
    if (isShutdown()) {
        return -1;
    }

    if (mApplication == null) {
        mApplication = activity.getApplication();
    }

    int key = TASK_COUNTER.incrementAndGet();

    task.setKey(key);
    task.setTaskExecutor(this);
    task.setCachedActivity(activity);
    task.setAnnotationId(annotationId);
    task.setFragmentId(fragmentId);

    mTasks.put(key, task);

    TaskRunnable<?> taskRunnable = new TaskRunnable<>(task, activity);

    mTaskRunnables.put(key, new WeakReference<TaskRunnable<?>>(taskRunnable));

    mApplication.registerActivityLifecycleCallbacks(taskRunnable);
    mExecutorService.execute(taskRunnable);

    return key;
}
 
Example 14
private ThetaDevice getConnectedDevice() {
    Activity activity = getActivity();
    if (activity != null) {
        ThetaDeviceApplication app = (ThetaDeviceApplication) activity.getApplication();
        ThetaDeviceManager deviceManager = app.getDeviceManager();
        return deviceManager.getConnectedDevice();
    } else {
        return null;
    }
}
 
Example 15
public static void reportFeedback(Activity activity, final String description, String url) {
    ThreadUtils.assertOnUiThread();
    if (sFeedbackReporter == null) {
        ChromeApplication application = (ChromeApplication) activity.getApplication();
        sFeedbackReporter = application.createFeedbackReporter();
    }
    FeedbackCollector.create(activity, Profile.getLastUsedProfile(), url,
            new FeedbackCollector.FeedbackResult() {
                @Override
                public void onResult(FeedbackCollector collector) {
                    collector.setDescription(description);
                    sFeedbackReporter.reportFeedback(collector);
                }
            });
}
 
Example 16
Source Project: PicturePicker   File: PictureScanner.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 开始扫描
 *
 * @param scanFinishListener 扫描完成监听
 */
public void startScanPicture(Activity activity, OnScanFinishListener scanFinishListener) {

    this.context = activity.getApplication();
    this.scanFinishListener = scanFinishListener;

    //先停止扫描
    stopScanPicture();

    loaderManager = activity.getLoaderManager();
    loaderManager.initLoader(SCANNER_ID, null, this);
}
 
Example 17
public TrafficShowPresenter(ITrafficShow.INaviSetPointView view, MapView mapView) {
    this.mTrafficShowView = view;
    this.mapView = mapView;
    mContext = (Activity) view;
    mAppConfig = (AppConfig) mContext.getApplication();
}
 
Example 18
public NaviSetLinePresenter(INaviSetLine.INaviSetLineView view) {
    this.mSetLineView = view;
    mContext = (Activity) view;
    appConfig = (AppConfig) mContext.getApplication();
}
 
Example 19
Source Project: sms-ticket   File: BaseFragment.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    mContext = activity.getApplicationContext();
    mApp = (App)activity.getApplication();
}
 
Example 20
Source Project: u2020   File: DebugViewContainer.java    License: Apache License 2.0 4 votes vote down vote up
@Override public ViewGroup forActivity(final Activity activity) {
  activity.setContentView(R.layout.debug_activity_frame);

  final ViewHolder viewHolder = new ViewHolder();
  ButterKnife.bind(viewHolder, activity);

  final Context drawerContext = new ContextThemeWrapper(activity, R.style.Theme_U2020_Debug);
  final DebugView debugView = new DebugView(drawerContext);
  viewHolder.debugDrawer.addView(debugView);

  // Set up the contextual actions to watch views coming in and out of the content area.
  ContextualDebugActions contextualActions = debugView.getContextualDebugActions();
  contextualActions.setActionClickListener(v -> viewHolder.drawerLayout.closeDrawers());
  viewHolder.content.setOnHierarchyChangeListener(
      HierarchyTreeChangeListener.wrap(contextualActions));

  viewHolder.drawerLayout.setDrawerShadow(R.drawable.debug_drawer_shadow, GravityCompat.END);
  viewHolder.drawerLayout.setDrawerListener(new DebugDrawerLayout.SimpleDrawerListener() {
    @Override public void onDrawerOpened(View drawerView) {
      debugView.onDrawerOpened();
    }
  });

  TelescopeLayout.cleanUp(activity); // Clean up any old screenshots.
  viewHolder.telescopeLayout.setLens(new BugReportLens(activity, lumberYard));

  // If you have not seen the debug drawer before, show it with a message
  if (!seenDebugDrawer.get()) {
    viewHolder.drawerLayout.postDelayed(() -> {
      viewHolder.drawerLayout.openDrawer(GravityCompat.END);
      Toast.makeText(drawerContext, R.string.debug_drawer_welcome, Toast.LENGTH_LONG).show();
    }, 1000);
    seenDebugDrawer.set(true);
  }

  final CompositeSubscription subscriptions = new CompositeSubscription();
  setupMadge(viewHolder, subscriptions);
  setupScalpel(viewHolder, subscriptions);

  final Application app = activity.getApplication();
  app.registerActivityLifecycleCallbacks(new EmptyActivityLifecycleCallbacks() {
    @Override public void onActivityDestroyed(Activity lifecycleActivity) {
      if (lifecycleActivity == activity) {
        subscriptions.unsubscribe();
        app.unregisterActivityLifecycleCallbacks(this);
      }
    }
  });

  riseAndShine(activity);
  return viewHolder.content;
}