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

The following examples show how to use android.app.Activity#getApplication() . 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 File: ProxyUtils.java    From JumpGo with 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 2
Source File: RestartModule.java    From react-native-restart with 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 3
Source File: DomDistillerUIUtils.java    From AndroidChromium with 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 4
Source File: ContactsListFragment.java    From Zom-Android-XMPP with GNU General Public License v3.0 6 votes vote down vote up
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 5
Source File: ProxyUtils.java    From Xndroid with 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 6
Source File: RUM.java    From raygun4android with 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 7
Source File: DomDistillerUIUtils.java    From delion with 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 8
Source File: UVCDeviceListFragment.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
/**
 * 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 9
Source File: PictureScanner.java    From PicturePicker with 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 10
Source File: ChildAccountFeedbackReporter.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
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 11
Source File: BaseConfirmationFragment.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
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 12
Source File: TaskExecutor.java    From android-task with 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 13
Source File: SceneViewModelProviders.java    From scene with 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 14
Source File: BaseConfirmationFragment.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
@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 15
Source File: Task.java    From android-task with 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 16
Source File: SettingsFragment.java    From android_gisapp with GNU General Public License v3.0 5 votes vote down vote up
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 17
Source File: DebugViewContainer.java    From u2020 with 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;
}
 
Example 18
Source File: BaseFragment.java    From sms-ticket with 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 19
Source File: NaviSetLinePresenter.java    From AssistantBySDK with Apache License 2.0 4 votes vote down vote up
public NaviSetLinePresenter(INaviSetLine.INaviSetLineView view) {
    this.mSetLineView = view;
    mContext = (Activity) view;
    appConfig = (AppConfig) mContext.getApplication();
}
 
Example 20
Source File: TrafficShowPresenter.java    From AssistantBySDK with Apache License 2.0 4 votes vote down vote up
public TrafficShowPresenter(ITrafficShow.INaviSetPointView view, MapView mapView) {
    this.mTrafficShowView = view;
    this.mapView = mapView;
    mContext = (Activity) view;
    mAppConfig = (AppConfig) mContext.getApplication();
}