Example usage for android.content Context ACTIVITY_SERVICE

List of usage examples for android.content Context ACTIVITY_SERVICE

Introduction

In this page you can find the example usage for android.content Context ACTIVITY_SERVICE.

Prototype

String ACTIVITY_SERVICE

To view the source code for android.content Context ACTIVITY_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.app.ActivityManager for interacting with the global system state.

Usage

From source file:br.ajmarques.cordova.plugin.localnotification.Receiver.java

/**
 * Gibt an, ob die App im Hintergrund luft.
 *//*from w w  w . j a v a  2  s. co m*/
private boolean isInBackground(Context context) {
    return !context.getPackageName()
            .equalsIgnoreCase(((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE))
                    .getRunningTasks(1).get(0).topActivity.getPackageName());
}

From source file:info.awesomedevelopment.tvgrid.library.TVGridView.java

@SuppressWarnings("deprecation")
private void init(AttributeSet attrs) {
    ActivityManager am = (ActivityManager) getContext().getSystemService(Context.ACTIVITY_SERVICE);
    mCache = new LruCache<>(am.getMemoryClass() * 1024);

    mYSize = new ValueAnimator();
    mXSize = new ValueAnimator();
    mYLocation = new ValueAnimator();
    mXLocation = new ValueAnimator();

    mXSize.addUpdateListener(xSizeListener);
    mYSize.addUpdateListener(ySizeListener);
    mYLocation.addUpdateListener(yLocationListener);
    mXLocation.addUpdateListener(xLocationListener);

    mSelectorAnimationSet.playTogether(mXLocation, mYLocation, mXSize, mYSize);
    mSelectorAnimationSet.setInterpolator(new AccelerateDecelerateInterpolator());
    mSelectorAnimationSet.setDuration(ANIMATION_DURATION);

    TypedValue fillAlpha = new TypedValue();
    getResources().getValue(R.dimen.tvg_defFillAlpha, fillAlpha, true);

    TypedValue fillAlphaSelected = new TypedValue();
    getResources().getValue(R.dimen.tvg_defFillAlphaSelected, fillAlphaSelected, true);

    if (attrs != null) {
        TypedArray a = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.TVGridView, 0, 0);

        try {//from w  ww.jav a  2 s .c om
            //noinspection ResourceType
            mStrokePosition = a.getInteger(R.styleable.TVGridView_tvg_strokePosition, OUTSIDE);
            //noinspection ResourceType
            mSelectorPosition = a.getInteger(R.styleable.TVGridView_tvg_selectorPosition, OVER);
            //noinspection ResourceType
            mSelectorShape = a.getInteger(R.styleable.TVGridView_tvg_selectorShape, RECTANGLE);

            mAnimateSelectorChanges = a.getBoolean(R.styleable.TVGridView_tvg_animateSelectorChanges,
                    getResources().getInteger(R.integer.tvg_defAnimateSelectorChanges) == 1);
            mIsFilled = a.getBoolean(R.styleable.TVGridView_tvg_filled,
                    getResources().getInteger(R.integer.tvg_defIsFilled) == 1);
            mFillAlpha = a.getFloat(R.styleable.TVGridView_tvg_fillAlpha, fillAlpha.getFloat());
            mFillAlphaSelected = a.getFloat(R.styleable.TVGridView_tvg_fillAlphaSelected,
                    fillAlphaSelected.getFloat());
            mFillColor = a.getColor(R.styleable.TVGridView_tvg_fillColor,
                    getResources().getColor(R.color.tvg_defFillColor));
            mFillColorSelected = a.getColor(R.styleable.TVGridView_tvg_fillColorSelected,
                    getResources().getColor(R.color.tvg_defFillColorSelected));
            mCornerRadiusX = a.getDimension(R.styleable.TVGridView_tvg_cornerRadius,
                    getResources().getDimension(R.dimen.tvg_defCornerRadius));
            mCornerRadiusY = a.getDimension(R.styleable.TVGridView_tvg_cornerRadius,
                    getResources().getDimension(R.dimen.tvg_defCornerRadius));
            mStrokeWidth = a.getDimension(R.styleable.TVGridView_tvg_strokeWidth,
                    getResources().getDimension(R.dimen.tvg_defStrokeWidth));
            mStrokeColor = a.getColor(R.styleable.TVGridView_tvg_strokeColor,
                    getResources().getColor(R.color.tvg_defStrokeColor));
            mStrokeColorSelected = a.getColor(R.styleable.TVGridView_tvg_strokeColorSelected,
                    getResources().getColor(R.color.tvg_defStrokeColorSelected));
            mStrokeMarginLeft = a.getDimension(R.styleable.TVGridView_tvg_marginLeft,
                    getResources().getDimension(R.dimen.tvg_defStrokeMarginLeft));
            mStrokeMarginTop = a.getDimension(R.styleable.TVGridView_tvg_marginTop,
                    getResources().getDimension(R.dimen.tvg_defStrokeMarginTop));
            mStrokeMarginRight = a.getDimension(R.styleable.TVGridView_tvg_marginRight,
                    getResources().getDimension(R.dimen.tvg_defStrokeMarginRight));
            mStrokeMarginBottom = a.getDimension(R.styleable.TVGridView_tvg_marginBottom,
                    getResources().getDimension(R.dimen.tvg_defStrokeMarginBottom));
            mStrokeSpacingLeft = a.getDimension(R.styleable.TVGridView_tvg_spacingLeft,
                    getResources().getDimension(R.dimen.tvg_defStrokeSpacingLeft));
            mStrokeSpacingTop = a.getDimension(R.styleable.TVGridView_tvg_spacingTop,
                    getResources().getDimension(R.dimen.tvg_defStrokeSpacingTop));
            mStrokeSpacingRight = a.getDimension(R.styleable.TVGridView_tvg_spacingRight,
                    getResources().getDimension(R.dimen.tvg_defStrokeSpacingRight));
            mStrokeSpacingBottom = a.getDimension(R.styleable.TVGridView_tvg_spacingBottom,
                    getResources().getDimension(R.dimen.tvg_defStrokeSpacingBottom));
        } finally {
            a.recycle();
        }
    } else {
        mStrokePosition = OUTSIDE;
        mSelectorPosition = OVER;
        mSelectorShape = RECTANGLE;

        mAnimateSelectorChanges = getResources().getInteger(R.integer.tvg_defAnimateSelectorChanges) == 1;
        mIsFilled = getResources().getInteger(R.integer.tvg_defIsFilled) == 1;
        mFillAlpha = fillAlpha.getFloat();
        mFillAlphaSelected = fillAlphaSelected.getFloat();
        mFillColor = getResources().getColor(R.color.tvg_defFillColor);
        mFillColorSelected = getResources().getColor(R.color.tvg_defFillColorSelected);
        mCornerRadiusX = getResources().getDimension(R.dimen.tvg_defCornerRadius);
        mCornerRadiusY = getResources().getDimension(R.dimen.tvg_defCornerRadius);
        mStrokeWidth = getResources().getDimension(R.dimen.tvg_defStrokeWidth);
        mStrokeColor = getResources().getColor(R.color.tvg_defStrokeColor);
        mStrokeColorSelected = getResources().getColor(R.color.tvg_defStrokeColorSelected);
        mStrokeMarginLeft = getResources().getDimension(R.dimen.tvg_defStrokeMarginLeft);
        mStrokeMarginTop = getResources().getDimension(R.dimen.tvg_defStrokeMarginTop);
        mStrokeMarginRight = getResources().getDimension(R.dimen.tvg_defStrokeMarginRight);
        mStrokeMarginBottom = getResources().getDimension(R.dimen.tvg_defStrokeMarginBottom);
        mStrokeSpacingLeft = getResources().getDimension(R.dimen.tvg_defStrokeSpacingLeft);
        mStrokeSpacingTop = getResources().getDimension(R.dimen.tvg_defStrokeSpacingTop);
        mStrokeSpacingRight = getResources().getDimension(R.dimen.tvg_defStrokeSpacingRight);
        mStrokeSpacingBottom = getResources().getDimension(R.dimen.tvg_defStrokeSpacingBottom);
    }

    addOnScrollListener(new OnScrollListener() {
        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
            if (newState == SCROLL_STATE_IDLE) {
                mEdgeChange = false;
                mHardScrollChange = false;
            }
        }

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            mScrollY = mScrollY + dy;

            if (mStrokeCellCurrentBounds == null || mStrokeCell == null)
                return;

            if (useAnimations()) {
                mSelectorAnimationSet.cancel();

                mStrokeCellCurrentBounds.offsetTo(mStrokeCellCurrentBounds.left - dx,
                        mStrokeCellCurrentBounds.top - dy);

                performSelectorAnimation();
            } else if (mHardScrollChange || mEdgeChange) {
                mStrokeCellCurrentBounds.offsetTo(mStrokeCellCurrentBounds.left - dx,
                        mStrokeCellCurrentBounds.top - dy);
                setPrevBounds();

                mStrokeCell.setBounds(mStrokeCellPrevBounds);
                invalidate();
            }
        }
    });

    setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            clearHighlightedView();
            return false;
        }
    });
}

From source file:edu.iub.seclab.appguardian.AppGuardianService.java

public void killProcess(String pkgName) {
    ActivityManager activityManger = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    activityManger.killBackgroundProcesses(pkgName);
}

From source file:org.chromium.chrome.browser.enhancedbookmarks.EnhancedBookmarkManager.java

/**
 * Creates an instance of {@link EnhancedBookmarkManager}. It also initializes resources,
 * bookmark models and jni bridges.//from   ww w .j  a v  a 2s  . c  o m
 * @param activity The activity context to use.
 */
public EnhancedBookmarkManager(Activity activity) {
    mActivity = activity;
    mEnhancedBookmarksModel = new EnhancedBookmarksModel();
    mMainView = (ViewGroup) mActivity.getLayoutInflater().inflate(R.layout.eb_main, null);
    mDrawer = (DrawerLayout) mMainView.findViewById(R.id.eb_drawer_layout);
    mDrawerListView = (EnhancedBookmarkDrawerListView) mMainView.findViewById(R.id.eb_drawer_list);
    mContentView = (EnhancedBookmarkContentView) mMainView.findViewById(R.id.eb_content_view);
    mViewSwitcher = (ViewSwitcher) mMainView.findViewById(R.id.eb_view_switcher);
    mUndoController = new EnhancedBookmarkUndoController(activity, mEnhancedBookmarksModel,
            ((SnackbarManageable) activity).getSnackbarManager());
    mSearchView = (EnhancedBookmarkSearchView) getView().findViewById(R.id.eb_search_view);
    mEnhancedBookmarksModel.addObserver(mBookmarkModelObserver);
    initializeIfBookmarkModelLoaded();

    // Load partner bookmarks explicitly. We load partner bookmarks in the deferred startup
    // code, but that might be executed much later. Especially on L, showing loading
    // progress bar blocks that so it won't be loaded. http://crbug.com/429383
    PartnerBookmarksShim.kickOffReading(activity);

    mLargeIconBridge = new LargeIconBridge(Profile.getLastUsedProfile().getOriginalProfile());
    ActivityManager activityManager = ((ActivityManager) ApplicationStatus.getApplicationContext()
            .getSystemService(Context.ACTIVITY_SERVICE));
    int maxSize = Math.min(activityManager.getMemoryClass() / 4 * 1024 * 1024, FAVICON_MAX_CACHE_SIZE_BYTES);
    mLargeIconBridge.createCache(maxSize);
}

From source file:org.chronotext.cinder.CinderBridge.java

public synchronized String getMemoryInfo() {
    MemoryInfo memoryInfo = new MemoryInfo();
    ((ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryInfo(memoryInfo);

    JSONObject json = new JSONObject();

    try {//from  ww w.ja  va2 s.c  om
        json.put("availMem", memoryInfo.availMem);
        json.put("threshold", memoryInfo.threshold);
        json.put("lowMemory", memoryInfo.lowMemory);
    } catch (JSONException e) {
    }

    return json.toString();
}

From source file:edu.iub.seclab.appguardian.AppGuardianService.java

public void killProcessByPkg(String[] result) {
    boolean recover = false;
    //      sendStopBroadcast();
    ActivityManager activityManger = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningAppProcessInfo> list = activityManger.getRunningAppProcesses();
    if (list != null)
        for (int i = 0; i < list.size(); i++) {
            ActivityManager.RunningAppProcessInfo apinfo = list.get(i);

            for (int j = 0; j < result.length; j++) {
                mTargetList.getTarget(mActiveTarget).killList.add(result[j]);
                int pid = apinfo.pid;
                if (pid == Integer.parseInt(result[j])) {
                    String[] pkgList = apinfo.pkgList;
                    for (int k = 0; k < pkgList.length; k++) {
                        if (apinfo.importance <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_SERVICE) {
                            recover = true;
                        } else {
                            recover = false;
                        }/*from ww w  . j av  a  2s  . c o  m*/
                        activityManger.killBackgroundProcesses(pkgList[k]);
                        if (recover) {
                            recoverylist.add(pkgList[k]);
                        }
                    }
                }

            }
        }
}

From source file:org.wso2.emm.agent.api.RuntimeInfo.java

public List<Device.Property> getRAMInfo() throws AndroidAgentException {
    List<Device.Property> properties = new ArrayList<>();
    Device.Property property;/*from  www  .j  a  v  a  2 s.c  o m*/

    ActivityManager actManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
    actManager.getMemoryInfo(memInfo);
    long totalMemory = memInfo.totalMem;
    long availableMemory = memInfo.availMem;
    long threshold = memInfo.threshold;
    boolean lowMemory = memInfo.lowMemory;
    // The available memory on the system.
    property = new Device.Property();
    property.setName(Constants.Device.TOTAL_MEMORY);
    property.setValue(String.valueOf(totalMemory));
    properties.add(property);
    // The total memory accessible by the kernel.
    property = new Device.Property();
    property.setName(Constants.Device.AVAILABLE_MEMORY);
    property.setValue(String.valueOf(availableMemory));
    properties.add(property);
    // The threshold of availMem at which we consider memory to be low and start
    // killing background services and other non-extraneous processes.
    property = new Device.Property();
    property.setName(Constants.Device.THRESHOLD);
    property.setValue(String.valueOf(threshold));
    properties.add(property);
    // Set to true if the system considers itself to currently be in a low memory situation.
    property = new Device.Property();
    property.setName(Constants.Device.LOW_MEMORY);
    property.setValue(String.valueOf(lowMemory));
    properties.add(property);

    return properties;
}

From source file:org.chromium.chrome.browser.bookmarks.BookmarkManager.java

/**
 * Creates an instance of {@link BookmarkManager}. It also initializes resources,
 * bookmark models and jni bridges.// w  ww.ja  va  2 s  .c om
 * @param activity The activity context to use.
 * @param isDialogUi Whether the main bookmarks UI will be shown in a dialog, not a NativePage.
 */
public BookmarkManager(Activity activity, boolean isDialogUi) {
    mActivity = activity;
    mIsDialogUi = isDialogUi;

    mSelectionDelegate = new SelectionDelegate<BookmarkId>() {
        @Override
        public boolean toggleSelectionForItem(BookmarkId bookmark) {
            if (!mBookmarkModel.getBookmarkById(bookmark).isEditable())
                return false;
            return super.toggleSelectionForItem(bookmark);
        }
    };

    mBookmarkModel = new BookmarkModel();
    mMainView = (ViewGroup) mActivity.getLayoutInflater().inflate(R.layout.bookmark_main, null);
    mDrawer = (DrawerLayout) mMainView.findViewById(R.id.bookmark_drawer_layout);
    mDrawerListView = (BookmarkDrawerListView) mMainView.findViewById(R.id.bookmark_drawer_list);
    mContentView = (BookmarkContentView) mMainView.findViewById(R.id.bookmark_content_view);
    mViewSwitcher = (ViewSwitcher) mMainView.findViewById(R.id.bookmark_view_switcher);
    mUndoController = new BookmarkUndoController(activity, mBookmarkModel,
            ((SnackbarManageable) activity).getSnackbarManager());
    mSearchView = (BookmarkSearchView) getView().findViewById(R.id.bookmark_search_view);
    mBookmarkModel.addObserver(mBookmarkModelObserver);
    initializeToLoadingState();
    mBookmarkModel.runAfterBookmarkModelLoaded(mModelLoadedRunnable);

    // Load partner bookmarks explicitly. We load partner bookmarks in the deferred startup
    // code, but that might be executed much later. Especially on L, showing loading
    // progress bar blocks that so it won't be loaded. http://crbug.com/429383
    PartnerBookmarksShim.kickOffReading(activity);

    mLargeIconBridge = new LargeIconBridge(Profile.getLastUsedProfile().getOriginalProfile());
    ActivityManager activityManager = ((ActivityManager) ContextUtils.getApplicationContext()
            .getSystemService(Context.ACTIVITY_SERVICE));
    int maxSize = Math.min(activityManager.getMemoryClass() / 4 * 1024 * 1024, FAVICON_MAX_CACHE_SIZE_BYTES);
    mLargeIconBridge.createCache(maxSize);

    RecordUserAction.record("MobileBookmarkManagerOpen");
    if (!isDialogUi) {
        RecordUserAction.record("MobileBookmarkManagerPageOpen");
    }
}

From source file:pl.zajecia.cw3.MainActivity.java

/**
 * Checks if main service is already started.
 * Necessary in order not to mess with intervals 
 * (e.g register more than one broadcasts)
 *///from   w w  w  . j  a v a2 s . c  o  m
private boolean isServiceStarted() {
    ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (MainService.class.getName().equals(service.service.getClassName())) {
            return true;
        }
    }
    return false;
}

From source file:com.configurer.easyscreenlock.MainActivity.java

/**
 * Initialise below components :// w ww . j  a  va 2 s .co m
 * <li><b>Device Policy Manager </b> - Public interface for managing policies enforced on a device. </li>
 * <li><b>Activity Manager </b> - Interact with the overall activities running in the system. </li>
 * <li><b>Component Name </b> - Identifier for a specific application component.</li>
 */
private void initializeComponents() {
    try {
        deviceManger = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
        activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
        compName = new ComponentName(this, DeviceAdministratorReceiver.class);
    } catch (Exception e) {
        deviceManger = null;
        activityManager = null;
        compName = null;
        Log.e(TAG, e.getMessage());
    }
}