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:com.cellbots.eyes.EyesActivity.java

/** Called when the activity is first created. */
@Override// w  ww .j  av a 2 s  . co m
public void onCreate(Bundle savedInstanceState) {
    Log.e("remote eyes", "started");
    super.onCreate(savedInstanceState);

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(
            PowerManager.FULL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE | PowerManager.ACQUIRE_CAUSES_WAKEUP,
            "Cellbot Eyes");
    mWakeLock.acquire();

    mTorchMode = false;

    out = new ByteArrayOutputStream();

    if ((getIntent() != null) && (getIntent().getData() != null)) {
        putUrl = getIntent().getData().toString();
        server = putUrl.replace("http://", "");
        server = server.substring(0, server.indexOf("/"));
        Bundle extras = getIntent().getExtras();
        if ((extras != null) && (extras.getBoolean("TORCH", false))) {
            mTorchMode = true;
        }
    } else {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        putUrl = prefs.getString("REMOTE_EYES_PUT_URL", "");
        Log.e("prefs", putUrl);
        if (putUrl.length() < 1) {
            Intent i = new Intent();
            i.setClass(this, PrefsActivity.class);
            startActivity(i);
            finish();
            return;
        } else {
            server = putUrl.replace("http://", "");
            server = server.substring(0, server.indexOf("/"));
        }
    }

    resetConnection();
    mHttpState = new HttpState();

    setContentView(R.layout.eyes_main);
    mPreview = (SurfaceView) findViewById(R.id.eyes_preview);
    mHolder = mPreview.getHolder();
    mHolder.addCallback(this);
    mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

    mPreview.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            setTorchMode(!mTorchMode);
        }
    });

    mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            boolean useTorch = intent.getBooleanExtra("TORCH", false);
            boolean shouldTakePicture = intent.getBooleanExtra("PICTURE", false);
            setTorchMode(useTorch);
            setTakePicture(shouldTakePicture);
        }
    };

    this.registerReceiver(mReceiver, new IntentFilter(EyesActivity.EYES_COMMAND));

    mFrame = (FrameLayout) findViewById(R.id.eyes_frame);
    mWebView = new WebView(this);
    mWebView.getSettings().setJavaScriptEnabled(true);
    // Use this if you want to load content locally
    // mWebView.loadUrl("content://com.cellbot.localpersonas/default/index.html");
    mWebView.loadUrl("http://personabots.appspot.com/expressions/tuby");

    mFrame.addView(mWebView);
}

From source file:com.xbh.tmi.ui.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    DemoApplication.getInstance().addActivity(this);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        String packageName = getPackageName();
        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        if (!pm.isIgnoringBatteryOptimizations(packageName)) {
            Intent intent = new Intent();
            intent.setAction(android.provider.Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
            intent.setData(Uri.parse("package:" + packageName));
            startActivity(intent);/*  w w  w. j av  a  2s  . co  m*/
        }
    }

    //make sure activity will not in background if user is logged into another device or removed
    if (savedInstanceState != null && savedInstanceState.getBoolean(Constant.ACCOUNT_REMOVED, false)) {
        DemoHelper.getInstance().logout(false, null);
        finish();
        startActivity(new Intent(this, LoginActivity.class));
        return;
    } else if (savedInstanceState != null && savedInstanceState.getBoolean("isConflict", false)) {
        finish();
        startActivity(new Intent(this, LoginActivity.class));
        return;
    }
    setContentView(R.layout.em_activity_main);
    // runtime permission for android 6.0, just require all permissions here for simple

    SharedPreferences sp = getSharedPreferences("sp_demo", Context.MODE_PRIVATE);
    int age = sp.getInt("head", 0);
    final String headPath = "/mnt/sdcard/" + "head" + ".jpg";
    switch (age) {
    case 2://?
        new Thread() {
            @Override
            public void run() {
                SharedPreferences sharedPre = MainActivity.this.getSharedPreferences("config",
                        MainActivity.this.MODE_PRIVATE);
                String userId = sharedPre.getString("username", "");
                PersonManager.SubmitPost(new File(headPath), userId, 1, mHandler);

                SharedPreferences sp = getSharedPreferences("sp_demo", Context.MODE_PRIVATE);
                SharedPreferences.Editor editor = sp.edit();
                editor.putInt("head", 20);
                editor.commit();
            }
        }.start();
        break;
    case 3://
        new Thread() {
            @Override
            public void run() {
                SharedPreferences sharedPre = MainActivity.this.getSharedPreferences("config",
                        MainActivity.this.MODE_PRIVATE);
                String userId = sharedPre.getString("username", "");
                PersonManager.SubmitPost(new File(headPath), userId, 1, mHandler);

                SharedPreferences sp = getSharedPreferences("sp_demo", Context.MODE_PRIVATE);
                SharedPreferences.Editor editor = sp.edit();
                editor.putInt("head", 30);
                editor.commit();
            }
        }.start();
        break;
    case 4://QQ
        new Thread() {
            @Override
            public void run() {
                SharedPreferences sharedPre = MainActivity.this.getSharedPreferences("config",
                        MainActivity.this.MODE_PRIVATE);
                String userId = sharedPre.getString("username", "");
                PersonManager.SubmitPost(new File(headPath), userId, 1, mHandler);

                SharedPreferences sp = getSharedPreferences("sp_demo", Context.MODE_PRIVATE);
                SharedPreferences.Editor editor = sp.edit();
                editor.putInt("head", 40);
                editor.commit();
            }
        }.start();
        break;
    default:
        Log.e("Lking", "???");
        break;
    }

    requestPermissions();

    initView();

    //umeng api
    MobclickAgent.updateOnlineConfig(this);
    UmengUpdateAgent.setUpdateOnlyWifi(false);
    UmengUpdateAgent.update(this);

    if (getIntent().getBooleanExtra(Constant.ACCOUNT_CONFLICT, false) && !isConflictDialogShow) {
        showConflictDialog();
    } else if (getIntent().getBooleanExtra(Constant.ACCOUNT_REMOVED, false) && !isAccountRemovedDialogShow) {
        showAccountRemovedDialog();
    }

    inviteMessgeDao = new InviteMessgeDao(this);
    UserDao userDao = new UserDao(this);
    conversationListFragment = new ConversationListFragment();
    tmFragment = new TmFragment();
    myFragment = new MyFragment();
    huihuaFragment = new HuihuaFragment();
    fragments = new Fragment[] { huihuaFragment, conversationListFragment, tmFragment, myFragment };

    getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, huihuaFragment).commit();

    //register broadcast receiver to receive the change of group from DemoHelper
    registerBroadcastReceiver();

    EMClient.getInstance().contactManager().setContactListener(new MyContactListener());
    //debug purpose only
    registerInternalDebugReceiver();
}

From source file:org.jonblack.bluetrack.activities.LiveTrackingFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    Log.d(TAG, "onActivityCreated");

    super.onActivityCreated(savedInstanceState);

    PowerManager pm = (PowerManager) getActivity().getSystemService(Context.POWER_SERVICE);
    wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Bluetrack");

    // Restore state
    if (savedInstanceState != null) {
        mSessionId = savedInstanceState.getLong("sessionId");
        mTracking = savedInstanceState.getBoolean("tracking");

        Log.v(TAG, String.format("Restoring state: mSessionId=%d mTracking=%s", mSessionId, mTracking));

        if (mTracking) {
            // This should get the loader that was already created.
            getLoaderManager().initLoader(0, null, this);
        }//from  www .jav a2  s .c om
    }

    // Register broadcast receiver for bluetooth status changes
    getActivity().registerReceiver(this.mBtStateChangedReceiver,
            new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));

    // Configure the ListView adapter, which will connect to the database.
    mAdapter = new LiveTrackingCursorAdapter(getActivity(), null, 0);
    setListAdapter(mAdapter);
}

From source file:de.qspool.clementineremote.backend.ClementinePlayerConnection.java

public void run() {
    // Start the thread
    mNotificationManager = (NotificationManager) App.mApp.getSystemService(Context.NOTIFICATION_SERVICE);

    Looper.prepare();/*from  w w  w .  jav a 2s .  c  o m*/
    mHandler = new ClementineConnectionHandler(this);

    mPebble = new Pebble();

    // Get a Wakelock Object
    PowerManager pm = (PowerManager) App.mApp.getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Clementine");

    Resources res = App.mApp.getResources();
    mNotificationHeight = (int) res.getDimension(android.R.dimen.notification_large_icon_height);
    mNotificationWidth = (int) res.getDimension(android.R.dimen.notification_large_icon_width);

    mAudioManager = (AudioManager) App.mApp.getSystemService(Context.AUDIO_SERVICE);
    mClementineMediaButtonEventReceiver = new ComponentName(App.mApp.getPackageName(),
            ClementineMediaButtonEventReceiver.class.getName());

    mMediaButtonBroadcastReceiver = new ClementineMediaButtonEventReceiver();

    fireOnConnectionReady();

    Looper.loop();
}

From source file:org.restcomm.app.utillib.Reporters.WebReporter.WebReporter.java

public WebReporter(Context context) {
    mContext = context;//from   w w w. j  av  a  2  s  . c  o  m

    //Retrieve api key if it exists
    mApiKey = Global.getApiKey(mContext);
    //Retrieve the host from the strings.xml

    mHost = Global.getApiUrl(context);
    mStaticAssetURL = Global.getString(context, "MMC_STATIC_ASSET_URL");

    //mRequestQueue = new ConcurrentLinkedQueue<Request>();

    mFlushQueueWakeLock = ((PowerManager) mContext.getSystemService(Context.POWER_SERVICE))
            .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
    mFlushQueueWakeLock.setReferenceCounted(false);
}

From source file:pandroid.agent.PandroidAgentListener.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    WakeLock wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakeLock");
    wakeLock.acquire();// w w  w.  j  a  va2 s. c om
    new loadConfThenContinueAsyncTask().execute();

    wakeLock.release();

    return START_NOT_STICKY;
}

From source file:net.olejon.spotcommander.WebViewActivity.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Google API client
    mGoogleApiClient = new GoogleApiClient.Builder(mContext).addApiIfAvailable(Wearable.API).build();

    // Allow landscape?
    if (!mTools.allowLandscape())
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    // Hide status bar?
    if (mTools.getDefaultSharedPreferencesBoolean("HIDE_STATUS_BAR"))
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

    // Power manager
    final PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);

    //noinspection deprecation
    mWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "wakeLock");

    // Settings//from   w  w w.  ja  va2  s. c om
    mTools.setSharedPreferencesBoolean("CAN_CLOSE_COVER", false);

    // Current network
    mCurrentNetwork = mTools.getCurrentNetwork();

    // Computer
    final long computerId = mTools.getSharedPreferencesLong("LAST_COMPUTER_ID");

    final String[] computer = mTools.getComputer(computerId);

    final String uri = computer[0];
    final String username = computer[1];
    final String password = computer[2];

    // Layout
    setContentView(R.layout.activity_webview);

    // Status bar color
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mStatusBarPrimaryColor = getWindow().getStatusBarColor();
        mStatusBarCoverArtColor = mStatusBarPrimaryColor;
    }

    // Notification
    mPersistentNotificationIsSupported = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN);

    if (mPersistentNotificationIsSupported) {
        final Intent launchActivityIntent = new Intent(mContext, MainActivity.class);
        launchActivityIntent.setAction("android.intent.action.MAIN");
        launchActivityIntent.addCategory("android.intent.category.LAUNCHER");
        mLaunchActivityPendingIntent = PendingIntent.getActivity(mContext, 0, launchActivityIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);

        final Intent hideIntent = new Intent(mContext, RemoteControlIntentService.class);
        hideIntent.setAction("hide_notification");
        hideIntent.putExtra(RemoteControlIntentService.REMOTE_CONTROL_INTENT_SERVICE_EXTRA, computerId);
        mHidePendingIntent = PendingIntent.getService(mContext, 0, hideIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);

        final Intent previousIntent = new Intent(mContext, RemoteControlIntentService.class);
        previousIntent.setAction("previous");
        previousIntent.putExtra(RemoteControlIntentService.REMOTE_CONTROL_INTENT_SERVICE_EXTRA, computerId);
        mPreviousPendingIntent = PendingIntent.getService(mContext, 0, previousIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);

        final Intent playPauseIntent = new Intent(mContext, RemoteControlIntentService.class);
        playPauseIntent.setAction("play_pause");
        playPauseIntent.putExtra(RemoteControlIntentService.REMOTE_CONTROL_INTENT_SERVICE_EXTRA, computerId);
        mPlayPausePendingIntent = PendingIntent.getService(mContext, 0, playPauseIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);

        final Intent nextIntent = new Intent(mContext, RemoteControlIntentService.class);
        nextIntent.setAction("next");
        nextIntent.putExtra(RemoteControlIntentService.REMOTE_CONTROL_INTENT_SERVICE_EXTRA, computerId);
        mNextPendingIntent = PendingIntent.getService(mContext, 0, nextIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);

        final Intent volumeDownIntent = new Intent(mContext, RemoteControlIntentService.class);
        volumeDownIntent.setAction("adjust_spotify_volume_down");
        volumeDownIntent.putExtra(RemoteControlIntentService.REMOTE_CONTROL_INTENT_SERVICE_EXTRA, computerId);
        mVolumeDownPendingIntent = PendingIntent.getService(mContext, 0, volumeDownIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);

        final Intent volumeUpIntent = new Intent(mContext, RemoteControlIntentService.class);
        volumeUpIntent.setAction("adjust_spotify_volume_up");
        volumeUpIntent.putExtra(RemoteControlIntentService.REMOTE_CONTROL_INTENT_SERVICE_EXTRA, computerId);
        mVolumeUpPendingIntent = PendingIntent.getService(mContext, 0, volumeUpIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);

        mNotificationManager = NotificationManagerCompat.from(mContext);
        mNotificationBuilder = new NotificationCompat.Builder(mContext);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
            mNotificationBuilder.setPriority(Notification.PRIORITY_MAX);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            mNotificationBuilder.setVisibility(Notification.VISIBILITY_PUBLIC);
            mNotificationBuilder.setCategory(Notification.CATEGORY_TRANSPORT);
        }
    }

    // Web view
    mWebView = (WebView) findViewById(R.id.webview_webview);

    mWebView.setBackgroundColor(ContextCompat.getColor(mContext, R.color.background));
    mWebView.setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY);

    mWebView.setWebViewClient(new WebViewClient() {
        @SuppressWarnings("deprecation")
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url != null && !url.contains(uri)
                    && !url.contains("olejon.net/code/spotcommander/api/1/spotify/")
                    && !url.contains("accounts.spotify.com/") && !url.contains("facebook.com/")) {
                view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));

                return true;
            }

            return false;
        }

        @Override
        public void onReceivedHttpAuthRequest(WebView view, @NonNull HttpAuthHandler handler, String host,
                String realm) {
            if (handler.useHttpAuthUsernamePassword()) {
                handler.proceed(username, password);
            } else {
                handler.cancel();

                mWebView.stopLoading();

                mTools.showToast(getString(R.string.webview_authentication_failed), 1);

                mTools.navigateUp(mActivity);
            }
        }

        @Override
        public void onReceivedError(WebView view, WebResourceRequest webResourceRequest,
                WebResourceError webResourceError) {
            mWebView.stopLoading();

            mTools.showToast(getString(R.string.webview_error), 1);

            mTools.navigateUp(mActivity);
        }

        @Override
        public void onReceivedSslError(WebView view, @NonNull SslErrorHandler handler, SslError error) {
            handler.cancel();

            mWebView.stopLoading();

            new MaterialDialog.Builder(mContext).title(R.string.webview_dialog_ssl_error_title)
                    .content(getString(R.string.webview_dialog_ssl_error_message))
                    .positiveText(R.string.webview_dialog_ssl_error_positive_button)
                    .onPositive(new MaterialDialog.SingleButtonCallback() {
                        @Override
                        public void onClick(@NonNull MaterialDialog materialDialog,
                                @NonNull DialogAction dialogAction) {
                            finish();
                        }
                    }).contentColorRes(R.color.black).show();
        }
    });

    // User agent
    mProjectVersionName = mTools.getProjectVersionName();

    final String uaAppend1 = (!username.equals("") && !password.equals("")) ? "AUTHENTICATION_ENABLED " : "";
    final String uaAppend2 = (mTools.getSharedPreferencesBoolean("WEAR_CONNECTED")) ? "WEAR_CONNECTED " : "";
    final String uaAppend3 = (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT
            && !mTools.getDefaultSharedPreferencesBoolean("HARDWARE_ACCELERATED_ANIMATIONS"))
                    ? "DISABLE_CSSTRANSITIONS DISABLE_CSSTRANSFORMS3D "
                    : "";

    // Web settings
    final WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setSupportZoom(false);
    webSettings.setUserAgentString(getString(R.string.webview_user_agent, webSettings.getUserAgentString(),
            mProjectVersionName, uaAppend1, uaAppend2, uaAppend3));

    // Load app
    if (savedInstanceState != null) {
        mWebView.restoreState(savedInstanceState);
    } else {
        mWebView.loadUrl(uri);
    }

    // JavaScript interface
    mWebView.addJavascriptInterface(new JavaScriptInterface(), "Android");
}

From source file:com.yisheng.ysim.main.fragment.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        String packageName = getPackageName();
        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        if (!pm.isIgnoringBatteryOptimizations(packageName)) {
            Intent intent = new Intent();
            intent.setAction(android.provider.Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
            intent.setData(Uri.parse("package:" + packageName));
            startActivity(intent);/* w  w w .ja  v  a2  s.  c  o m*/
        }
    }

    //make sure activity will not in background if user is logged into another device or removed
    if (savedInstanceState != null && savedInstanceState.getBoolean(Constant.ACCOUNT_REMOVED, false)) {
        DemoHelper.getInstance().logout(false, null);
        finish();
        startActivity(new Intent(this, LoginActivity.class));
        return;
    } else if (savedInstanceState != null && savedInstanceState.getBoolean("isConflict", false)) {
        finish();
        startActivity(new Intent(this, LoginActivity.class));
        return;
    }
    setContentView(R.layout.fx_activity_main);
    // runtime permission for android 6.0, just require all permissions here for simple
    requestPermissions();
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN
            | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
    initView();

    //umeng api
    MobclickAgent.updateOnlineConfig(this);
    UmengUpdateAgent.setUpdateOnlyWifi(false);
    UmengUpdateAgent.update(this);

    if (getIntent().getBooleanExtra(Constant.ACCOUNT_CONFLICT, false) && !isConflictDialogShow) {
        showConflictDialog();
    } else if (getIntent().getBooleanExtra(Constant.ACCOUNT_REMOVED, false) && !isAccountRemovedDialogShow) {
        showAccountRemovedDialog();
    }

    inviteMessgeDao = new InviteMessgeDao(this);
    userDao = new UserDao(this);
    //        conversationListFragment=(ConversationListFragment)getSupportFragmentManager().findFragmentByTag(TAG_COVERSATION);
    //        contactListFragment=(ContactListFragment)getSupportFragmentManager().findFragmentByTag(TAG_CONTACTS);
    //        fragmentFind=(FragmentFind)getSupportFragmentManager().findFragmentByTag(TAG_FIND);
    //        fragmentProfile=(FragmentProfile)getSupportFragmentManager().findFragmentByTag(TAG_PROFILE);
    //        FragmentTransaction manager = getSupportFragmentManager().beginTransaction();
    //        if(conversationListFragment==null){
    //            conversationListFragment = new ConversationListFragment();
    //            manager.add(R.id.fragment_container, conversationListFragment, TAG_COVERSATION);
    //        }
    //        if(contactListFragment==null){
    //            contactListFragment = new ContactListFragment();
    //            manager.add(R.id.fragment_container, contactListFragment, TAG_CONTACTS);
    //        }
    //        if(fragmentFind==null){
    //            fragmentFind = new FragmentFind();
    //            manager.add(R.id.fragment_container, fragmentFind, TAG_FIND).hide(fragmentFind);
    //        }
    //        if(fragmentProfile==null){
    //            fragmentProfile = new FragmentProfile();
    //            manager.add(R.id.fragment_container, fragmentProfile, TAG_PROFILE).hide(fragmentProfile);
    //        }
    //        manager.show(conversationListFragment).hide(contactListFragment).hide(fragmentFind).hide(fragmentProfile).commit();
    conversationListFragment = new ConversationListFragment();
    csFragment = new ChatFragment();
    Bundle csBundle = new Bundle();
    csBundle.putInt(EaseConstant.EXTRA_CHAT_TYPE, EaseConstant.CHATTYPE_SINGLE);
    csBundle.putString(EaseConstant.EXTRA_USER_ID, "22222");
    csFragment.setArguments(csBundle);
    contactListFragment = new ContactListFragment();
    fragmentFind = new FragmentFind();
    fragmentProfile = new FragmentProfile();
    getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, conversationListFragment)
            .add(R.id.fragment_container, contactListFragment).hide(contactListFragment)
            .show(conversationListFragment).commit();
    fragments = new Fragment[] { conversationListFragment, csFragment, contactListFragment, fragmentFind,
            fragmentProfile };
    //register broadcast receiver to receive the change of group from DemoHelper
    registerBroadcastReceiver();

    EMClient.getInstance().contactManager().setContactListener(new MyContactListener());
    //debug purpose only
    registerInternalDebugReceiver();
    Log.e("id", DemoHelper.getInstance().getCurrentUsernName());
    startService(new Intent(this, ContactsService.class));

    //        ----------
    //        if(!DemoHelper.getInstance().getCurrentUsernName().equals("22222")){
    //            Intent intent=new Intent(this, CsActivity.class);
    //            intent.putExtra("userId","22222");
    //            intent.putExtra(EaseConstant.EXTRA_CHAT_TYPE, Constant.CHATTYPE_SINGLE);
    //            startActivity(intent);
    //            this.finish();
    //        }

}

From source file:com.shrlnm.android.erm.ElmRenaultMonitor_Main.java

@Override
public void onCreate(Bundle savedInstanceState) {

    //Enter full screen mode
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    super.onCreate(savedInstanceState);
    if (D)//from  w w w  . jav  a2  s  .com
        Log.e(TAG, "+++ ON CREATE +++");

    powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "MyLock");

    // Get local Bluetooth adapter
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    // If the adapter is null, then Bluetooth is not supported
    if (mBluetoothAdapter == null) {
        Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show();
        finish();
        return;
    }

    LocalBroadcastManager.getInstance(this).registerReceiver(localMessageReceiver,
            new IntentFilter("ElmRenaultMonitor_Main"));

    // there we will save the mac address of BT device for not to ask it again
    sharedPref = this.getSharedPreferences(getString(R.string.preference_addr_key), MODE_PRIVATE);

    // Set up the window layout
    //setContentView(R.layout.main);
    iv = new InstrumentsView(this);
    setContentView(iv);

    eRsp = new ecu();

}

From source file:com.cubic9.android.droidglove.Main.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // prevent sleep
    PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "DroidGlove");

    // vibrator// w ww.  ja va 2s.co  m
    mVibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);

    // sensor
    mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

    // show error dialog if Wi-Fi off and Tethering off.
    WifiManager wifi = (WifiManager) getSystemService(WIFI_SERVICE);
    if ((!wifi.isWifiEnabled()) && (!isTethering(wifi))) {
        new AlertDialog.Builder(Main.this).setIcon(android.R.drawable.ic_dialog_alert)
                .setTitle(getString(R.string.dialog_error_title))
                .setMessage(getString(R.string.dialog_error_wifi_off))
                .setPositiveButton(R.string.dialog_error_ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        appEnd();
                    }
                }).create().show();
    }

    // get IP address
    getPreferences();

    // check IP address
    if (ip.equals("")) {
        showToast(R.string.toast_error_ip_null);
        Intent intent = new Intent(this, Settings.class);
        startActivityForResult(intent, 0);
    } else if (!ip.matches("^([0-9]{1,3}\\.){3}[0-9]{1,3}$")) {
        showToast(R.string.toast_error_ip_wrong);
        Intent intent = new Intent(this, Settings.class);
        startActivityForResult(intent, 0);
    }

    // init angle
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < AVERAGE_AMOUNT; j++) {
            mOrigAngles[i][j] = 0;
        }
    }

    // show screen
    setContentView(R.layout.main);

    // find views
    mTextViewMessage = (TextView) findViewById(R.id.textViewMessage);
    mTextViewIp = (TextView) findViewById(R.id.textViewIp);
    /*
     * textViewX = (TextView) findViewById(R.id.textViewX); textViewY =
     * (TextView) findViewById(R.id.textViewY); textViewZ = (TextView)
     * findViewById(R.id.textViewZ); textViewGrip = (TextView)
     * findViewById(R.id.textViewGrip);
     */
    Button button = (Button) findViewById(R.id.buttonReset);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mInitirizedSensor = false;
            mTextViewMessage.setText(R.string.message_swipe_down);
        }
    });
}