Search in sources :

Example 96 with ActivityManager

use of android.app.ActivityManager in project android_frameworks_base by ResurrectionRemix.

the class LauncherActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ActivityManager activities = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    Intent intent = findTask(activities);
    if (intent != null) {
        restoreTask(intent);
    } else {
        startTask();
    }
    finish();
}
Also used : Intent(android.content.Intent) ActivityManager(android.app.ActivityManager)

Example 97 with ActivityManager

use of android.app.ActivityManager in project android_frameworks_base by ResurrectionRemix.

the class DirectoryFragment method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    final Context context = getActivity();
    final State state = getDisplayState();
    // Read arguments when object created for the first time.
    // Restore state if fragment recreated.
    Bundle args = savedInstanceState == null ? getArguments() : savedInstanceState;
    mRoot = args.getParcelable(Shared.EXTRA_ROOT);
    mDocument = args.getParcelable(Shared.EXTRA_DOC);
    mStateKey = buildStateKey(mRoot, mDocument);
    mQuery = args.getString(Shared.EXTRA_QUERY);
    mType = args.getInt(Shared.EXTRA_TYPE);
    final Selection selection = args.getParcelable(Shared.EXTRA_SELECTION);
    mSelection = selection != null ? selection : new Selection();
    mSearchMode = args.getBoolean(Shared.EXTRA_SEARCH_MODE);
    mIconHelper = new IconHelper(context, MODE_GRID);
    mAdapter = new SectionBreakDocumentsAdapterWrapper(this, new ModelBackedDocumentsAdapter(this, mIconHelper));
    mRecView.setAdapter(mAdapter);
    // Switch Access Accessibility API needs an {@link AccessibilityDelegate} to know the proper
    // route when user selects an UI element. It usually guesses this if the element has an
    // {@link OnClickListener}, but since we do not have one for itemView, we will need to
    // manually route it to the right behavior. RecyclerView has its own AccessibilityDelegate,
    // and routes it to its LayoutManager; so we must override the LayoutManager's accessibility
    // methods to route clicks correctly.
    mLayout = new GridLayoutManager(getContext(), mColumnCount) {

        @Override
        public void onInitializeAccessibilityNodeInfoForItem(RecyclerView.Recycler recycler, RecyclerView.State state, View host, AccessibilityNodeInfoCompat info) {
            super.onInitializeAccessibilityNodeInfoForItem(recycler, state, host, info);
            info.addAction(AccessibilityActionCompat.ACTION_CLICK);
        }

        @Override
        public boolean performAccessibilityActionForItem(RecyclerView.Recycler recycler, RecyclerView.State state, View view, int action, Bundle args) {
            // We are only handling click events; route all other to default implementation
            if (action == AccessibilityNodeInfoCompat.ACTION_CLICK) {
                RecyclerView.ViewHolder vh = mRecView.getChildViewHolder(view);
                if (vh instanceof DocumentHolder) {
                    DocumentHolder dh = (DocumentHolder) vh;
                    if (dh.mEventListener != null) {
                        dh.mEventListener.onActivate(dh);
                        return true;
                    }
                }
            }
            return super.performAccessibilityActionForItem(recycler, state, view, action, args);
        }
    };
    SpanSizeLookup lookup = mAdapter.createSpanSizeLookup();
    if (lookup != null) {
        mLayout.setSpanSizeLookup(lookup);
    }
    mRecView.setLayoutManager(mLayout);
    mGestureDetector = new ListeningGestureDetector(this.getContext(), mDragHelper, new GestureListener());
    mRecView.addOnItemTouchListener(mGestureDetector);
    // TODO: instead of inserting the view into the constructor, extract listener-creation code
    // and set the listener on the view after the fact.  Then the view doesn't need to be passed
    // into the selection manager.
    mSelectionManager = new MultiSelectManager(mRecView, mAdapter, state.allowMultiple ? MultiSelectManager.MODE_MULTIPLE : MultiSelectManager.MODE_SINGLE, null);
    mSelectionManager.addCallback(new SelectionModeListener());
    mModel = new Model();
    mModel.addUpdateListener(mAdapter);
    mModel.addUpdateListener(mModelUpdateListener);
    // Make sure this is done after the RecyclerView is set up.
    mFocusManager = new FocusManager(context, mRecView, mModel);
    mTuner = FragmentTuner.pick(getContext(), state);
    mClipper = new DocumentClipper(context);
    final ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    boolean svelte = am.isLowRamDevice() && (mType == TYPE_RECENT_OPEN);
    mIconHelper.setThumbnailsEnabled(!svelte);
    // Kick off loader at least once
    getLoaderManager().restartLoader(LOADER_ID, null, this);
}
Also used : Selection(com.android.documentsui.dirlist.MultiSelectManager.Selection) ActivityManager(android.app.ActivityManager) ViewHolder(android.support.v7.widget.RecyclerView.ViewHolder) Context(android.content.Context) Bundle(android.os.Bundle) AccessibilityNodeInfoCompat(android.support.v4.view.accessibility.AccessibilityNodeInfoCompat) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) TextView(android.widget.TextView) Recycler(android.support.v7.widget.RecyclerView.Recycler) Point(android.graphics.Point) SpanSizeLookup(android.support.v7.widget.GridLayoutManager.SpanSizeLookup) DocumentClipper(com.android.documentsui.DocumentClipper) GridLayoutManager(android.support.v7.widget.GridLayoutManager) State(com.android.documentsui.State) RecyclerView(android.support.v7.widget.RecyclerView)

Example 98 with ActivityManager

use of android.app.ActivityManager in project android_frameworks_base by ResurrectionRemix.

the class AppCircleSidebar method killApp.

private void killApp(String packageName) {
    final ActivityManager am = (ActivityManager) mContext.getSystemService(Activity.ACTIVITY_SERVICE);
    am.forceStopPackage(packageName);
}
Also used : ActivityManager(android.app.ActivityManager)

Example 99 with ActivityManager

use of android.app.ActivityManager in project android_frameworks_base by ResurrectionRemix.

the class RecentPanelView method removeAllApplications.

/**
     * Remove all applications. Call from controller class
     */
protected boolean removeAllApplications() {
    final ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
    boolean hasFavorite = false;
    int size = mCardAdapter.getItemCount() - 1;
    for (int i = size; i >= 0; i--) {
        RecentCard card = (RecentCard) mCardAdapter.getCard(i);
        TaskDescription td = card.task;
        // User favorites are not removed.
        if (td.getIsFavorite()) {
            hasFavorite = true;
            continue;
        }
        // Remove from task stack.
        if (am != null) {
            am.removeTask(td.persistentTaskId);
        }
        // Remove the card.
        removeRecentCard(card);
        // Remove expanded state.
        removeExpandedTaskState(td.identifier);
    }
    return !hasFavorite;
}
Also used : ActivityManager(android.app.ActivityManager) Paint(android.graphics.Paint)

Example 100 with ActivityManager

use of android.app.ActivityManager in project android_frameworks_base by ResurrectionRemix.

the class BaseStatusBar method getLastApp.

private void getLastApp() {
    int lastAppId = 0;
    int looper = 1;
    String packageName;
    final Intent intent = new Intent(Intent.ACTION_MAIN);
    final ActivityManager am = (ActivityManager) mContext.getSystemService(Activity.ACTIVITY_SERVICE);
    String defaultHomePackage = "com.android.launcher";
    intent.addCategory(Intent.CATEGORY_HOME);
    final ResolveInfo res = mContext.getPackageManager().resolveActivity(intent, 0);
    if (res.activityInfo != null && !res.activityInfo.packageName.equals("android")) {
        defaultHomePackage = res.activityInfo.packageName;
    }
    List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(5);
    // Note, we'll only get as many as the system currently has - up to 5
    while ((lastAppId == 0) && (looper < tasks.size())) {
        packageName = tasks.get(looper).topActivity.getPackageName();
        if (!packageName.equals(defaultHomePackage) && !packageName.equals("com.android.systemui")) {
            lastAppId = tasks.get(looper).id;
        }
        looper++;
    }
    if (lastAppId != 0) {
        am.moveTaskToFront(lastAppId, am.MOVE_TASK_NO_USER_ACTION);
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) ActivityManager(android.app.ActivityManager)

Aggregations

ActivityManager (android.app.ActivityManager)325 Intent (android.content.Intent)42 Context (android.content.Context)31 RunningAppProcessInfo (android.app.ActivityManager.RunningAppProcessInfo)28 ComponentName (android.content.ComponentName)24 PackageManager (android.content.pm.PackageManager)21 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)17 IActivityManager (android.app.IActivityManager)16 ConfigurationInfo (android.content.pm.ConfigurationInfo)16 RunningServiceInfo (android.app.ActivityManager.RunningServiceInfo)15 View (android.view.View)15 ImageView (android.widget.ImageView)15 IOException (java.io.IOException)15 Point (android.graphics.Point)14 TextView (android.widget.TextView)14 ArrayList (java.util.ArrayList)13 RunningTaskInfo (android.app.ActivityManager.RunningTaskInfo)12 ResolveInfo (android.content.pm.ResolveInfo)12 RemoteException (android.os.RemoteException)12 TargetApi (android.annotation.TargetApi)11