Example usage for android.content Context POWER_SERVICE

List of usage examples for android.content Context POWER_SERVICE

Introduction

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

Prototype

String POWER_SERVICE

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

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.os.PowerManager for controlling power management, including "wake locks," which let you keep the device on while you're running long tasks.

Usage

From source file:org.csp.everyaware.offline.Map.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d("Map", "******************************onCreate()******************************");
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.map_container);

    mToBeHideBtn = (Button) findViewById(R.id.startStopBtn);
    mToBeHideBtn.setVisibility(View.GONE);

    mPowerMan = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = mPowerMan.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "CPUalwaysOn");

    Utils.setStep(Constants.TRACK_MAP, getApplicationContext());

    mDbManager = DbManager.getInstance(getApplicationContext());
    mDbManager.openDb();//from  w ww  . ja  v a 2 s .c om

    //it will contain  displayed latlng points
    mLatLngPoints = new ArrayList<ExtendedLatLng>();

    //istantiate custom implementation of LocationSource interface
    mLocationSource = new MyLocationSource();

    //google map initialization
    setUpMapIfNeeded(savedInstanceState);

    //obtaining references to buttons and defining listeners
    getButtonRefs();

    mHandler = new Handler();

    mKmlParser = new KmlParser();

    //starting store'n'forward service and saving reference to it
    Intent serviceIntent = new Intent(getApplicationContext(), StoreAndForwardService.class);
    Utils.storeForwServIntent = serviceIntent;
    startService(serviceIntent);

    //set appropriate colors in all seven black carbon levels under black carbon text box
    setBcLevelColors();
}

From source file:ca.nehil.rter.streamingapp.StreamingActivity.java

@Override
protected void onResume() {
    super.onResume();
    if (mWakeLock == null) {
        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, CLASS_LABEL);
        mWakeLock.acquire();/*from w  w  w. j av a 2  s .  c  om*/
    }

    initLayout();
    mSensorSource.initListeners();
    attemptHandshake(); // Start recording.
}

From source file:com.easemob.chatuidemo.activity.BaseChatActivity.java

private void setUpView() {
    iv_emoticons_normal.setOnClickListener(this);
    iv_emoticons_checked.setOnClickListener(this);
    // position = getIntent().getIntExtra("position", -1);
    clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    wakeLock = ((PowerManager) getSystemService(Context.POWER_SERVICE))
            .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "demo");
    // ???/*from  ww w .j a v a2  s .  co  m*/
    chatType = getIntent().getIntExtra("chatType", CHATTYPE_SINGLE);

    if (chatType == CHATTYPE_SINGLE) { // ??
        toChatUsername = getIntent().getStringExtra("userId");
        Map<String, RobotUser> robotMap = ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getRobotList();
        if (robotMap != null && robotMap.containsKey(toChatUsername)) {
            isRobot = true;
            String nick = robotMap.get(toChatUsername).getNick();
            if (!TextUtils.isEmpty(nick)) {
                setName(nick);
            } else {
                setName(toChatUsername);
            }
        } else {
            setName(toChatUsername);
        }
    }

    onConversationInit();
    onListViewCreation();
}

From source file:info.guardianproject.otr.app.im.service.RemoteImService.java

@Override
public void onCreate() {
    debug("ImService started");
    final String prev = Debug.getTrail(this, SERVICE_CREATE_TRAIL_KEY);
    if (prev != null)
        Debug.recordTrail(this, PREV_SERVICE_CREATE_TRAIL_TAG, prev);
    Debug.recordTrail(this, SERVICE_CREATE_TRAIL_KEY, new Date());
    final String prevConnections = Debug.getTrail(this, CONNECTIONS_TRAIL_TAG);
    if (prevConnections != null)
        Debug.recordTrail(this, PREV_CONNECTIONS_TRAIL_TAG, prevConnections);
    Debug.recordTrail(this, CONNECTIONS_TRAIL_TAG, "0");

    mConnections = new Hashtable<String, ImConnectionAdapter>();
    mHandler = new Handler();

    Debug.onServiceStart();//from   ww  w .  ja  v a 2 s  .  co  m

    PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "IM_WAKELOCK");

    // Clear all account statii to logged-out, since we just got started and we don't want
    // leftovers from any previous crash.
    clearConnectionStatii();

    mStatusBarNotifier = new StatusBarNotifier(this);
    mServiceHandler = new ServiceHandler();

    //mSettingsMonitor = new SettingsMonitor();

    /*
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(ConnectivityManager.ACTION_BACKGROUND_DATA_SETTING_CHANGED);
    registerReceiver(mSettingsMonitor, intentFilter);
    */

    //  setBackgroundData(ImApp.getApplication().isNetworkAvailableAndConnected());

    mPluginHelper = ImPluginHelper.getInstance(this);
    mPluginHelper.loadAvailablePlugins();

    // Have the heartbeat start autoLogin, unless onStart turns this off
    mNeedCheckAutoLogin = true;

    HeartbeatService.startBeating(getApplicationContext());
}

From source file:org.moire.ultrasonic.service.DownloadServiceImpl.java

@SuppressLint("NewApi")
@Override//from w  w w .j a va  2  s .c o m
public void onCreate() {
    super.onCreate();

    new Thread(new Runnable() {
        @Override
        public void run() {
            Thread.currentThread().setName("DownloadServiceImpl");

            Looper.prepare();

            if (mediaPlayer != null) {
                mediaPlayer.release();
            }

            mediaPlayer = new MediaPlayer();
            mediaPlayer.setWakeMode(DownloadServiceImpl.this, PowerManager.PARTIAL_WAKE_LOCK);

            mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
                @Override
                public boolean onError(MediaPlayer mediaPlayer, int what, int more) {
                    handleError(new Exception(String.format("MediaPlayer error: %d (%d)", what, more)));
                    return false;
                }
            });

            try {
                Intent i = new Intent(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION);
                i.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, mediaPlayer.getAudioSessionId());
                i.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName());
                sendBroadcast(i);
            } catch (Throwable e) {
                // Froyo or lower
            }

            mediaPlayerLooper = Looper.myLooper();
            mediaPlayerHandler = new Handler(mediaPlayerLooper);
            Looper.loop();
        }
    }).start();

    audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
    setUpRemoteControlClient();

    if (equalizerAvailable) {
        equalizerController = new EqualizerController(this, mediaPlayer);
        if (!equalizerController.isAvailable()) {
            equalizerController = null;
        } else {
            equalizerController.loadSettings();
        }
    }
    if (visualizerAvailable) {
        visualizerController = new VisualizerController(mediaPlayer);
        if (!visualizerController.isAvailable()) {
            visualizerController = null;
        }
    }

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this.getClass().getName());
    wakeLock.setReferenceCounted(false);

    instance = this;
    lifecycleSupport.onCreate();
}

From source file:org.ado.minesync.gui.fragment.DropboxFragment.java

private boolean isScreenOn() {
    return ((PowerManager) activity.getApplicationContext().getSystemService(Context.POWER_SERVICE))
            .isScreenOn();
}

From source file:com.android.cts.verifier.sensors.SignificantMotionTestActivity.java

@Override
protected void activitySetUp() {
    mSensorManager = (SensorManager) getApplicationContext().getSystemService(Context.SENSOR_SERVICE);
    mSensorSignificantMotion = mSensorManager.getDefaultSensor(Sensor.TYPE_SIGNIFICANT_MOTION);
    if (mSensorSignificantMotion == null) {
        throw new SensorNotSupportedException(Sensor.TYPE_SIGNIFICANT_MOTION);
    }//from  w  ww. java 2  s.  c  om

    mScreenManipulator = new SensorTestScreenManipulator(this);
    try {
        mScreenManipulator.initialize(this);
    } catch (InterruptedException e) {
    }
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    LocalBroadcastManager.getInstance(this).registerReceiver(myBroadCastReceiver,
            new IntentFilter(ACTION_ALARM));
}

From source file:com.smc.tw.waltz.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (DEBUG)//w  ww . ja v  a 2  s . c  om
        Log.d(TAG, "onCreate");

    overridePendingTransition(R.anim.slide_right_in, R.anim.slide_left_out);

    super.onCreate(savedInstanceState);

    Fabric.with(this, new Crashlytics());

    setContentView(R.layout.activity_main);

    mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

    mWakeLock = mPowerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, TAG);

    mPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    mFragmentManager = getSupportFragmentManager();

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    mAudioRecordBufferSize = 5600;//AudioRecord.getMinBufferSize(8000, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT)*10;
    mAudioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC, 8000, AudioFormat.CHANNEL_IN_MONO,
            AudioFormat.ENCODING_PCM_16BIT, mAudioRecordBufferSize);

    mNotifyChannelList = new ArrayList<String>();

    setupLayout();

    if (savedInstanceState != null) {
        mCurrentSelectedPosition = savedInstanceState.getInt(STATE_SELECTED_POSITION);
    }

    //      mRegistrationBroadcastReceiver = new BroadcastReceiver() {
    //         @Override
    //         public void onReceive(Context context, Intent intent) {
    //
    //            // checking for type intent filter
    //            if (intent.getAction().equals(MainApplication.REGISTRATION_COMPLETE)) {
    //               // gcm successfully registered
    //               // now subscribe to `global` topic to receive app wide notifications
    //               String token = intent.getStringExtra("token");
    //
    //               //Toast.makeText(getApplicationContext(), "GCM registration token: " + token, Toast.LENGTH_LONG).show();
    //
    //            } else if (intent.getAction().equals(MainApplication.SENT_TOKEN_TO_SERVER)) {
    //               // gcm registration id is stored in our server's MySQL
    //
    //               Toast.makeText(getApplicationContext(), "GCM registration token is stored in server!", Toast.LENGTH_LONG).show();
    //
    //            } else if (intent.getAction().equals(MainApplication.PUSH_NOTIFICATION)) {
    //               // new push notification is received
    //
    //               Toast.makeText(getApplicationContext(), "Push notification is received!", Toast.LENGTH_LONG).show();
    //            }
    //         }
    //      };
    //
    if (checkPlayServices()) {
        registerGCM();
    }

}

From source file:com.wifiafterconnect.WifiAuthenticator.java

public boolean checkTNCShown(ParsedHttpInput parsed) {
    String ssid = WifiTools.getSSID(getContext());
    WifiAuthDatabase wifiDb = getDb();//  w ww .j a v  a 2  s .  c  om
    if (wifiDb == null || ssid == null || ssid.isEmpty())
        return true;

    if (wifiDb.isKnownSSID(ssid))
        return true;
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    Context context = getContext();
    boolean urlOpened = false;
    if (pm.isScreenOn() && context != null) {
        try {
            debug("TNC not shown previously. Redirecting to page in browser.");
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(parsed.getURL().toURI().toString()));
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);
            urlOpened = true;
        } catch (URISyntaxException e) { // don't care
        }
    } else {
        // what should we do when the screen is locked???
    }
    wifiDb.storeSSID(ssid);
    return !urlOpened;
}

From source file:com.nbplus.vbroadlauncher.service.BroadcastChatHeadService.java

public void acquireCpuWakeLock() {
    Log.e(TAG, "Acquiring cpu wake lock");
    if (mCpuWakeLock != null) {
        return;/*  ww w  .  j a  v  a  2 s  .  c om*/
    }

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);

    mCpuWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP
            | PowerManager.ON_AFTER_RELEASE, "I'm your father");
    mCpuWakeLock.acquire();
}