Search in sources :

Example 71 with WeakReference

use of java.lang.ref.WeakReference in project AndroidChromium by JackyAndroid.

the class IncognitoNotificationService method getTaskIdsForVisibleActivities.

private Set<Integer> getTaskIdsForVisibleActivities() {
    List<WeakReference<Activity>> runningActivities = ApplicationStatus.getRunningActivities();
    Set<Integer> visibleTaskIds = new HashSet<>();
    for (int i = 0; i < runningActivities.size(); i++) {
        Activity activity = runningActivities.get(i).get();
        if (activity == null)
            continue;
        int activityState = ApplicationStatus.getStateForActivity(activity);
        if (activityState != ActivityState.STOPPED && activityState != ActivityState.DESTROYED) {
            visibleTaskIds.add(activity.getTaskId());
        }
    }
    return visibleTaskIds;
}
Also used : WeakReference(java.lang.ref.WeakReference) ChromeLauncherActivity(org.chromium.chrome.browser.document.ChromeLauncherActivity) ChromeTabbedActivity(org.chromium.chrome.browser.ChromeTabbedActivity) Activity(android.app.Activity) HashSet(java.util.HashSet)

Example 72 with WeakReference

use of java.lang.ref.WeakReference in project AndroidChromium by JackyAndroid.

the class IncognitoNotificationService method focusChromeIfNecessary.

private void focusChromeIfNecessary() {
    Set<Integer> visibleTaskIds = getTaskIdsForVisibleActivities();
    int tabbedTaskId = -1;
    List<WeakReference<Activity>> runningActivities = ApplicationStatus.getRunningActivities();
    for (int i = 0; i < runningActivities.size(); i++) {
        Activity activity = runningActivities.get(i).get();
        if (activity == null)
            continue;
        if (activity instanceof ChromeTabbedActivity) {
            tabbedTaskId = activity.getTaskId();
            break;
        }
    }
    // snapshot that would need to be regenerated.
    if (visibleTaskIds.contains(tabbedTaskId))
        return;
    Context context = ContextUtils.getApplicationContext();
    Intent startIntent = new Intent(Intent.ACTION_MAIN);
    startIntent.setPackage(context.getPackageName());
    startIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(startIntent);
}
Also used : Context(android.content.Context) ChromeTabbedActivity(org.chromium.chrome.browser.ChromeTabbedActivity) WeakReference(java.lang.ref.WeakReference) ChromeLauncherActivity(org.chromium.chrome.browser.document.ChromeLauncherActivity) ChromeTabbedActivity(org.chromium.chrome.browser.ChromeTabbedActivity) Activity(android.app.Activity) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 73 with WeakReference

use of java.lang.ref.WeakReference in project AndroidChromium by JackyAndroid.

the class Tab method createBringTabToFrontIntent.

/**
     * @return Intent that tells Chrome to bring an Activity for a particular Tab back to the
     *         foreground, or null if this isn't possible.
     */
@Nullable
public static Intent createBringTabToFrontIntent(int tabId) {
    // Iterate through all {@link CustomTab}s and check whether the given tabId belongs to a
    // {@link CustomTab}. If so, return null as the client app's task cannot be foregrounded.
    List<WeakReference<Activity>> list = ApplicationStatus.getRunningActivities();
    for (WeakReference<Activity> ref : list) {
        Activity activity = ref.get();
        if (activity instanceof CustomTabActivity && ((CustomTabActivity) activity).getActivityTab() != null && tabId == ((CustomTabActivity) activity).getActivityTab().getId()) {
            return null;
        }
    }
    String packageName = ContextUtils.getApplicationContext().getPackageName();
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.putExtra(Browser.EXTRA_APPLICATION_ID, packageName);
    intent.putExtra(TabOpenType.BRING_TAB_TO_FRONT.name(), tabId);
    intent.setPackage(packageName);
    return intent;
}
Also used : WeakReference(java.lang.ref.WeakReference) ChromeLauncherActivity(org.chromium.chrome.browser.document.ChromeLauncherActivity) ChromeActivity(org.chromium.chrome.browser.ChromeActivity) CustomTabActivity(org.chromium.chrome.browser.customtabs.CustomTabActivity) Activity(android.app.Activity) CustomTabActivity(org.chromium.chrome.browser.customtabs.CustomTabActivity) Intent(android.content.Intent) Nullable(android.support.annotation.Nullable)

Example 74 with WeakReference

use of java.lang.ref.WeakReference in project AndroidChromium by JackyAndroid.

the class DocumentTabModelImpl method getTabAt.

@Override
public Tab getTabAt(int index) {
    if (index < 0 || index >= getCount())
        return null;
    // Return a live tab if the corresponding DocumentActivity is currently alive.
    int tabId = mTabIdList.get(index);
    List<WeakReference<Activity>> activities = ApplicationStatus.getRunningActivities();
    for (WeakReference<Activity> activityRef : activities) {
        Activity activity = activityRef.get();
        if (!(activity instanceof DocumentActivity) || !mActivityDelegate.isValidActivity(isIncognito(), activity.getIntent())) {
            continue;
        }
        Tab tab = ((DocumentActivity) activity).getActivityTab();
        int documentId = tab == null ? Tab.INVALID_TAB_ID : tab.getId();
        if (documentId == tabId)
            return tab;
    }
    // Try to create a Tab that will hold the Tab's info.
    Entry entry = mEntryMap.get(tabId);
    assert entry != null;
    // If a tab has already been initialized, use that.
    if (entry.placeholderTab != null && entry.placeholderTab.isInitialized()) {
        return entry.placeholderTab;
    }
    // Create a frozen Tab if we are capable, or if the previous Tab is just a placeholder.
    if (entry.getTabState() != null && isNativeInitialized() && (entry.placeholderTab == null || !entry.placeholderTab.isInitialized())) {
        entry.placeholderTab = getTabCreator(isIncognito()).createFrozenTab(entry.getTabState(), entry.tabId, TabModel.INVALID_TAB_INDEX);
        entry.placeholderTab.initializeNative();
    }
    // Create a placeholder Tab that just has the ID.
    if (entry.placeholderTab == null) {
        entry.placeholderTab = new Tab(tabId, isIncognito(), null);
    }
    return entry.placeholderTab;
}
Also used : DocumentActivity(org.chromium.chrome.browser.document.DocumentActivity) Tab(org.chromium.chrome.browser.tab.Tab) WeakReference(java.lang.ref.WeakReference) DocumentActivity(org.chromium.chrome.browser.document.DocumentActivity) Activity(android.app.Activity)

Example 75 with WeakReference

use of java.lang.ref.WeakReference in project ACS by ACS-Community.

the class MoveUpActionCopiedFromNetbeans method enable.

/* Manages enable - disable logic of this action */
protected boolean enable(Node[] activatedNodes) {
    initErr();
    if (err != null) {
        err.log(ErrorManager.UNKNOWN, "enable; activatedNodes=" + (activatedNodes == null ? null : Arrays.asList(activatedNodes)));
    }
    // remove old listener, if any
    Index idx = getCurIndexCookie();
    if (idx != null) {
        idx.removeChangeListener((ChangeListener) getProperty(PROP_ORDER_LISTENER));
    }
    Index cookie = getIndexCookie(activatedNodes);
    if (err != null) {
        err.log(ErrorManager.UNKNOWN, "enable; cookie=" + cookie);
    }
    if (cookie == null)
        return false;
    // now start listening to reordering changes
    cookie.addChangeListener((OrderingListener) getProperty(PROP_ORDER_LISTENER));
    curIndexCookie = new WeakReference(cookie);
    int index = cookie.indexOf(activatedNodes[0]);
    if (err != null) {
        err.log(ErrorManager.UNKNOWN, "enable; index=" + index);
        if (index == -1) {
            Node parent = activatedNodes[0].getParentNode();
            err.log(ErrorManager.UNKNOWN, "enable; parent=" + parent + "; parent.children=" + Arrays.asList(parent.getChildren().getNodes()));
        }
    }
    return index > 0;
}
Also used : WeakReference(java.lang.ref.WeakReference) Node(org.openide.nodes.Node) Index(org.openide.nodes.Index)

Aggregations

WeakReference (java.lang.ref.WeakReference)291 ArrayList (java.util.ArrayList)32 HashMap (java.util.HashMap)24 Map (java.util.Map)24 Field (java.lang.reflect.Field)19 Activity (android.app.Activity)17 Iterator (java.util.Iterator)17 IOException (java.io.IOException)16 Method (java.lang.reflect.Method)15 File (java.io.File)14 URLClassLoader (java.net.URLClassLoader)14 Test (org.junit.Test)13 Reference (java.lang.ref.Reference)12 ReferenceQueue (java.lang.ref.ReferenceQueue)12 Resources (android.content.res.Resources)10 Handler (android.os.Handler)10 AbstractModule (com.google.inject.AbstractModule)10 Injector (com.google.inject.Injector)10 ArrayMap (android.util.ArrayMap)9 URL (java.net.URL)8