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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations