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:com.bukanir.android.utils.Utils.java

public static boolean isServiceRunning(Context context) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (Torrent2HttpService.class.getName().equals(service.service.getClassName())) {
            return true;
        }//from   www.j a v a  2s  .co m
    }
    return false;
}

From source file:com.dazone.crewchat.libGallery.async.VideoLoadAsync.java

public VideoLoadAsync(Fragment fragment, ImageView imageView, boolean isScrolling, int width) {
    mImageView = imageView;//from  w  w  w  .  j  ava2 s  . c o m
    this.fragment = fragment;
    mWidth = width;
    mIsScrolling = isScrolling;

    final int memClass = ((ActivityManager) fragment.getActivity().getSystemService(Context.ACTIVITY_SERVICE))
            .getMemoryClass();
    final int size = 1024 * 1024 * memClass / 8;

    // Handle orientation change.
    GalleryRetainCache c = GalleryRetainCache.getOrCreateRetainableCache();
    mCache = c.mRetainedCache;

    if (mCache == null) {
        // The maximum bitmap pixels allowed in respective direction.
        // If exceeding, the cache will automatically scale the
        // bitmaps.
        /*   final int MAX_PIXELS_WIDTH  = 100;
        final int MAX_PIXELS_HEIGHT = 100;*/
        mCache = new GalleryCache(size, mWidth, mWidth);
        c.mRetainedCache = mCache;
    }
}

From source file:com.micabytes.gfx.ImageHandler.java

private static void initCache() {
    int memoryClass = ((ActivityManager) GameApplication.getInstance()
            .getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass();
    int memoryCacheSize = MEGABYTE * MEGABYTE * memoryClass / 8;
    memoryCache = new LruCache<Integer, Bitmap>(memoryCacheSize) {
        @Override//  ww  w  .j  a  v  a 2s .com
        protected int sizeOf(Integer key, Bitmap value) {
            return value.getRowBytes() * value.getHeight();
        }
    };
}

From source file:com.farsight.golf.asyn.VideoLoadAsync.java

@SuppressLint("NewApi")
public VideoLoadAsync(LocalVideoActivity videoFragment, ImageView imageView, boolean isScrolling, int width) {
    mImageView = imageView;/*from  w w w.  j  av a  2s  . com*/
    this.fragment = videoFragment;
    mWidth = width;
    mIsScrolling = isScrolling;

    final int memClass = ((ActivityManager) videoFragment.getSystemService(Context.ACTIVITY_SERVICE))
            .getMemoryClass();
    final int size = 1024 * 1024 * memClass / 8;

    // Handle orientation change.
    GalleryRetainCache c = GalleryRetainCache.getOrCreateRetainableCache();
    mCache = c.mRetainedCache;

    if (mCache == null) {
        // The maximum bitmap pixels allowed in respective direction.
        // If exceeding, the cache will automatically scale the
        // bitmaps.
        /*   final int MAX_PIXELS_WIDTH  = 100;
        final int MAX_PIXELS_HEIGHT = 100;*/
        mCache = new GalleryCache(size, mWidth, mWidth);
        c.mRetainedCache = mCache;
    }
}

From source file:org.tigase.messenger.phone.pro.utils.ImageHelper.java

protected static void initialize(Context context) {
    if (memCache == null) {
        // Get memory class of this device, exceeding this amount will throw
        // an OutOfMemory exception.
        final int memClass = ((android.app.ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE))
                .getMemoryClass();/*from  ww  w  .j ava  2s  . c o m*/

        // Use 1/8th of the available memory for this memory cache.
        final int cacheSize = 1024 * 1024 * memClass / 8;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
            memCache = new LruCache<String, Bitmap>(cacheSize) {
                @TargetApi(12)
                @Override
                protected int sizeOf(String key, Bitmap bitmap) {
                    // The cache size will be measured in bytes rather than
                    // number of items. Ignoring placeholder bitmap as well.
                    return placeHolders.contains(bitmap) ? 0 : bitmap.getByteCount();
                }
            };
        } else {
            // below SDK 12 there is no getByteCount method
            memCache = new LruCache<String, Bitmap>(cacheSize) {
                @Override
                protected int sizeOf(String key, Bitmap bitmap) {
                    // The cache size will be measured in bytes rather than
                    // number of items. Ignoring placeholder bitmap as well.
                    return placeHolders.contains(bitmap) ? 0 : (bitmap.getRowBytes() * bitmap.getHeight());
                }
            };
        }

        // maps images cache
        BitmapDiskLruCache diskCache = new BitmapDiskLruCache();
        diskCache.initialize(context, "maps", 10 * 1024 * 1024);
        diskCaches.put("maps", diskCache);

        // images from files shared with or by us
        diskCache = new BitmapDiskLruCache();
        diskCache.initialize(context, "images-mini", 10 * 1024 * 1024);
        diskCaches.put("images-mini", diskCache);
    }
}

From source file:org.xwalk.runtime.extension.api.device_capabilities.DeviceCapabilitiesMemory.java

private void readMemoryInfo() {
    MemoryInfo mem_info = new MemoryInfo();
    ActivityManager activityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
    activityManager.getMemoryInfo(mem_info);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        mCapacity = mem_info.totalMem;/*  w  w  w .j av  a  2 s  . co  m*/
    } else {
        mCapacity = getTotalMemFromFile();
    }
    mAvailableCapacity = mem_info.availMem;
}

From source file:com.dycode.jepretstory.mediachooser.async.VideoLoadAsync.java

public VideoLoadAsync(Fragment fragment, ImageView imageView, boolean isScrolling, int width, int height) {
    mImageView = imageView;//from w  w w. ja  v a  2s. c  o  m
    this.fragment = fragment;
    mWidth = width;
    mHeight = height;
    mIsScrolling = isScrolling;

    FragmentActivity act = fragment.getActivity();
    if (act == null) {
        return;
    }

    final int memClass = ((ActivityManager) act.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass();
    final int size = 1024 * 1024 * memClass / 8;

    // Handle orientation change.
    GalleryRetainCache c = GalleryRetainCache.getOrCreateRetainableCache();
    mCache = c.mRetainedCache;

    if (mCache == null) {
        // The maximum bitmap pixels allowed in respective direction.
        // If exceeding, the cache will automatically scale the
        // bitmaps.
        /*   final int MAX_PIXELS_WIDTH  = 100;
        final int MAX_PIXELS_HEIGHT = 100;*/
        mCache = new GalleryCache(size, mWidth, mHeight);
        c.mRetainedCache = mCache;
    }
}

From source file:id.zelory.tanipedia.util.Utils.java

public static boolean isMyAppRunning(Context context) {
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
    boolean run = false;
    for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) {
        if (appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
            if (appProcess.processName.equals("id.zelory.tanipedia")) {
                run = true;//  w  w w . j a va  2 s.  c om
                break;
            }
        }
    }

    return run;
}

From source file:com.badou.mworking.net.bitmap.BitmapLruCache.java

public static void init(Context context) {
    int memClass = ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass();
    // Use 1/8th of the available memory for this memory cache.
    int cacheSize = 1024 * 1024 * memClass / 8;
    mBitmapLruCache = new BitmapLruCache(cacheSize);
}

From source file:com.pixelpixel.pyp.SplashActivity.java

/** Called when the activity is first created. */
@Override// w  ww.  ja  v  a 2s  .co m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);

    //Initializing the application cache
    final int memClass = ((ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass();
    final int cacheSize = 1024 * 1024 * memClass / 4;
    mMemoryCache = new LruCache<String, Object>(cacheSize);

    /*
     * Setting up the animation for the logo
     * */
    final ImageView splash_logo = (ImageView) findViewById(R.id.SplashLogo);
    Animation sa1 = AnimationUtils.loadAnimation(this, R.anim.splash_anim);
    sa1.setAnimationListener(new AnimationListener() {

        public void onAnimationEnd(Animation arg0) {
            /*
             * After the end of the "growing" animation, we call the "shrinking" animation.
             * */
            Animation sa2 = AnimationUtils.loadAnimation(SplashActivity.this, R.anim.splash_anim2);
            sa2.setAnimationListener(new AnimationListener() {

                public void onAnimationEnd(Animation animation) {
                    /*
                     * After the end of the "shrinking" animation, we proceed to the
                     * next screen, the start screen.
                     * */
                    Handler mHandler = new Handler();
                    mHandler.postDelayed(new Runnable() {
                        public void run() {
                            startActivity(new Intent(SplashActivity.this, StartActivity.class));
                            SplashActivity.this.finish();
                        }
                    }, 5000);
                }

                public void onAnimationRepeat(Animation animation) {
                }

                public void onAnimationStart(Animation animation) {
                }

            });
            splash_logo.startAnimation(sa2);
        }

        public void onAnimationRepeat(Animation animation) {
        }

        public void onAnimationStart(Animation animation) {
        }

    });

    splash_logo.startAnimation(sa1);
}