Search in sources :

Example 56 with PowerManager

use of android.os.PowerManager in project android_frameworks_base by ParanoidAndroid.

the class MediaFrameworkTest method onCreate.

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.surface_view);
    mSurfaceView = (SurfaceView) findViewById(R.id.surface_view);
    mOverlayView = (ImageView) findViewById(R.id.overlay_layer);
    ViewGroup.LayoutParams lp = mSurfaceView.getLayoutParams();
    mSurfaceHolder = mSurfaceView.getHolder();
    mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    mSurfaceHolder.addCallback(this);
    //Get the midi fd
    midiafd = this.getResources().openRawResourceFd(R.raw.testmidi);
    //Get the mp3 fd
    mp3afd = this.getResources().openRawResourceFd(R.raw.testmp3);
    mOverlayView.setLayoutParams(lp);
    mDestBitmap = Bitmap.createBitmap((int) 640, (int) 480, Bitmap.Config.ARGB_8888);
    mOverlayView.setImageBitmap(mDestBitmap);
    //Acquire the full wake lock to keep the device up
    PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "MediaFrameworkTest");
    mWakeLock.acquire();
}
Also used : PowerManager(android.os.PowerManager) ViewGroup(android.view.ViewGroup)

Example 57 with PowerManager

use of android.os.PowerManager in project android-uploader by nightscout.

the class SyncingService method handleActionSync.

/**
     * Handle action Sync in the provided background thread with the provided
     * parameters.
     */
protected void handleActionSync(int numOfPages, Context context, DeviceTransport serialDriver) {
    boolean broadcastSent = false;
    AndroidPreferences preferences = new AndroidPreferences(context);
    Tracker tracker = ((Nightscout) context).getTracker();
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "NSDownload");
    wl.acquire();
    if (serialDriver != null) {
        AbstractUploaderDevice uploaderDevice = AndroidUploaderDevice.getUploaderDevice(context);
        AbstractDevice device = new DexcomG4(serialDriver, preferences, uploaderDevice);
        ((DexcomG4) device).setNumOfPages(numOfPages);
        ((CdcAcmSerialDriver) serialDriver).setPowerManagementEnabled(preferences.isRootEnabled());
        try {
            DownloadResults results = device.download();
            G4Download download = results.getDownload();
            Uploader uploader = new Uploader(context, preferences);
            boolean uploadStatus;
            if (numOfPages < 20) {
                uploadStatus = uploader.upload(results, 1);
            } else {
                uploadStatus = uploader.upload(results);
            }
            EGVRecord recentEGV;
            if (download.download_status == DownloadStatus.SUCCESS) {
                recentEGV = new EGVRecord(download.sgv.get(download.sgv.size() - 1));
            } else {
                recentEGV = new EGVRecord(-1, TrendArrow.NONE, new Date(), new Date(), G4Noise.NOISE_NONE);
            }
            broadcastSGVToUI(recentEGV, uploadStatus, results.getNextUploadTime() + TIME_SYNC_OFFSET, results.getDisplayTime(), results.getResultArray(), download.receiver_battery);
            broadcastSent = true;
        } catch (ArrayIndexOutOfBoundsException e) {
            Log.wtf("Unable to read from the dexcom, maybe it will work next time", e);
            tracker.send(new HitBuilders.ExceptionBuilder().setDescription("Array Index out of bounds").setFatal(false).build());
        } catch (NegativeArraySizeException e) {
            Log.wtf("Negative array exception from receiver", e);
            tracker.send(new HitBuilders.ExceptionBuilder().setDescription("Negative Array size").setFatal(false).build());
        } catch (IndexOutOfBoundsException e) {
            Log.wtf("IndexOutOfBounds exception from receiver", e);
            tracker.send(new HitBuilders.ExceptionBuilder().setDescription("IndexOutOfBoundsException").setFatal(false).build());
        } catch (CRCFailError e) {
            // FIXME: may consider localizing this catch at a lower level (like ReadData) so that
            // if the CRC check fails on one type of record we can capture the values if it
            // doesn't fail on other types of records. This means we'd need to broadcast back
            // partial results to the UI. Adding it to a lower level could make the ReadData class
            // more difficult to maintain - needs discussion.
            Log.wtf("CRC failed", e);
            tracker.send(new HitBuilders.ExceptionBuilder().setDescription("CRC Failed").setFatal(false).build());
        } catch (Exception e) {
            Log.wtf("Unhandled exception caught", e);
            tracker.send(new HitBuilders.ExceptionBuilder().setDescription("Catch all exception in handleActionSync").setFatal(false).build());
        }
    }
    if (!broadcastSent)
        broadcastSGVToUI();
    wl.release();
}
Also used : AndroidPreferences(com.nightscout.android.preferences.AndroidPreferences) Tracker(com.google.android.gms.analytics.Tracker) HitBuilders(com.google.android.gms.analytics.HitBuilders) DownloadResults(com.nightscout.core.model.DownloadResults) DexcomG4(com.nightscout.core.drivers.DexcomG4) CdcAcmSerialDriver(com.nightscout.android.drivers.USB.CdcAcmSerialDriver) AbstractUploaderDevice(com.nightscout.core.drivers.AbstractUploaderDevice) CRCFailError(com.nightscout.core.dexcom.CRCFailError) EGVRecord(com.nightscout.core.dexcom.records.EGVRecord) Date(java.util.Date) G4Download(com.nightscout.core.model.G4Download) PowerManager(android.os.PowerManager) AbstractDevice(com.nightscout.core.drivers.AbstractDevice) Uploader(com.nightscout.android.upload.Uploader)

Example 58 with PowerManager

use of android.os.PowerManager in project KeepScore by nolanlawson.

the class GameActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    createGame();
    PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, getPackageName());
    setContentView(R.layout.game);
    setUpWidgets();
    scheduleAutomaticBackup();
}
Also used : PowerManager(android.os.PowerManager)

Example 59 with PowerManager

use of android.os.PowerManager in project AndEngine by nicolasgramlich.

the class BaseGameActivity method acquireWakeLock.

private void acquireWakeLock(final WakeLockOptions pWakeLockOptions) {
    if (pWakeLockOptions == WakeLockOptions.SCREEN_ON) {
        ActivityUtils.keepScreenOn(this);
    } else {
        final PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE);
        this.mWakeLock = pm.newWakeLock(pWakeLockOptions.getFlag() | PowerManager.ON_AFTER_RELEASE, Constants.DEBUGTAG);
        try {
            this.mWakeLock.acquire();
        } catch (final SecurityException pSecurityException) {
            Debug.e("You have to add\n\t<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>\nto your AndroidManifest.xml !", pSecurityException);
        }
    }
}
Also used : PowerManager(android.os.PowerManager)

Example 60 with PowerManager

use of android.os.PowerManager in project Timber by naman14.

the class MusicService method onCreate.

@Override
public void onCreate() {
    if (D)
        Log.d(TAG, "Creating service");
    super.onCreate();
    mNotificationManager = NotificationManagerCompat.from(this);
    // gets a pointer to the playback state store
    mPlaybackStateStore = MusicPlaybackState.getInstance(this);
    mSongPlayCount = SongPlayCount.getInstance(this);
    mRecentStore = RecentStore.getInstance(this);
    mHandlerThread = new HandlerThread("MusicPlayerHandler", android.os.Process.THREAD_PRIORITY_BACKGROUND);
    mHandlerThread.start();
    mPlayerHandler = new MusicPlayerHandler(this, mHandlerThread.getLooper());
    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    mMediaButtonReceiverComponent = new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName());
    mAudioManager.registerMediaButtonEventReceiver(mMediaButtonReceiverComponent);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        setUpMediaSession();
    mPreferences = getSharedPreferences("Service", 0);
    mCardId = getCardId();
    registerExternalStorageListener();
    mPlayer = new MultiPlayer(this);
    mPlayer.setHandler(mPlayerHandler);
    // Initialize the intent filter and each action
    final IntentFilter filter = new IntentFilter();
    filter.addAction(SERVICECMD);
    filter.addAction(TOGGLEPAUSE_ACTION);
    filter.addAction(PAUSE_ACTION);
    filter.addAction(STOP_ACTION);
    filter.addAction(NEXT_ACTION);
    filter.addAction(PREVIOUS_ACTION);
    filter.addAction(PREVIOUS_FORCE_ACTION);
    filter.addAction(REPEAT_ACTION);
    filter.addAction(SHUFFLE_ACTION);
    // Attach the broadcast listener
    registerReceiver(mIntentReceiver, filter);
    mMediaStoreObserver = new MediaStoreObserver(mPlayerHandler);
    getContentResolver().registerContentObserver(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, true, mMediaStoreObserver);
    getContentResolver().registerContentObserver(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, true, mMediaStoreObserver);
    // Initialize the wake lock
    final PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName());
    mWakeLock.setReferenceCounted(false);
    final Intent shutdownIntent = new Intent(this, MusicService.class);
    shutdownIntent.setAction(SHUTDOWN);
    mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    mShutdownIntent = PendingIntent.getService(this, 0, shutdownIntent, 0);
    scheduleDelayedShutdown();
    reloadQueueAfterPermissionCheck();
    notifyChange(QUEUE_CHANGED);
    notifyChange(META_CHANGED);
}
Also used : PowerManager(android.os.PowerManager) IntentFilter(android.content.IntentFilter) HandlerThread(android.os.HandlerThread) ComponentName(android.content.ComponentName) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent)

Aggregations

PowerManager (android.os.PowerManager)289 IntentFilter (android.content.IntentFilter)50 Intent (android.content.Intent)44 Handler (android.os.Handler)33 RemoteException (android.os.RemoteException)31 PendingIntent (android.app.PendingIntent)29 HandlerThread (android.os.HandlerThread)26 Context (android.content.Context)24 IPowerManager (android.os.IPowerManager)21 View (android.view.View)19 Resources (android.content.res.Resources)15 AlarmManager (android.app.AlarmManager)11 SharedPreferences (android.content.SharedPreferences)11 TextView (android.widget.TextView)11 NotificationCompat (android.support.v4.app.NotificationCompat)10 ComponentName (android.content.ComponentName)9 KeyguardManager (android.app.KeyguardManager)8 Vibrator (android.os.Vibrator)8 MotionEvent (android.view.MotionEvent)8 ContentResolver (android.content.ContentResolver)7