Example usage for android.content.pm ActivityInfo SCREEN_ORIENTATION_PORTRAIT

List of usage examples for android.content.pm ActivityInfo SCREEN_ORIENTATION_PORTRAIT

Introduction

In this page you can find the example usage for android.content.pm ActivityInfo SCREEN_ORIENTATION_PORTRAIT.

Prototype

int SCREEN_ORIENTATION_PORTRAIT

To view the source code for android.content.pm ActivityInfo SCREEN_ORIENTATION_PORTRAIT.

Click Source Link

Document

Constant corresponding to portrait in the android.R.attr#screenOrientation attribute.

Usage

From source file:com.tweetlanes.android.core.view.DirectMessageFeedFragment.java

private void lockScreenRotation() {
    if (getActivity() != null) {
        switch (getActivity().getResources().getConfiguration().orientation) {
        case Configuration.ORIENTATION_PORTRAIT:
            getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            break;
        case Configuration.ORIENTATION_LANDSCAPE:
            getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            break;
        }//from  w  w w . j  av  a  2 s .c  o m
    }
}

From source file:tr.com.turkcellteknoloji.turkcellupdater.Utilities.java

@SuppressLint("NewApi")
static int getScreenOrientation(Activity activity) {
    if (Build.VERSION.SDK_INT < 8) {
        switch (activity.getResources().getConfiguration().orientation) {
        case Configuration.ORIENTATION_PORTRAIT:
            return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
        case Configuration.ORIENTATION_LANDSCAPE:
            return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
        default://w  w  w  .ja va2 s  .  c  om
            return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
        }
    }

    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    DisplayMetrics dm = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
    int width = dm.widthPixels;
    int height = dm.heightPixels;
    int orientation;
    // if the device's natural orientation is portrait:
    if ((rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) && height > width
            || (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) && width > height) {
        switch (rotation) {
        case Surface.ROTATION_0:
            orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
            break;
        case Surface.ROTATION_90:
            orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
            break;
        case Surface.ROTATION_180:
            orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
            break;
        case Surface.ROTATION_270:
            orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
            break;
        default:
            orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
            break;
        }
    }
    // if the device's natural orientation is landscape or if the device
    // is square:
    else {
        switch (rotation) {
        case Surface.ROTATION_0:
            orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
            break;
        case Surface.ROTATION_90:
            orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
            break;
        case Surface.ROTATION_180:
            orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
            break;
        case Surface.ROTATION_270:
            orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
            break;
        default:
            orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
            break;
        }
    }

    return orientation;
}

From source file:uk.co.pjmobile.mobile_apps.page_turner_reader.ReadingActivity.java

private void updateFromPrefs() {

    //      this.progressService.setConfig(this.config);

    bookView.setTextSize(config.getTextSize());

    int marginH = config.getHorizontalMargin();
    int marginV = config.getVerticalMargin();

    bookView.setFontFamily(config.getFontFamily());

    bookView.setHorizontalMargin(marginH);
    bookView.setVerticalMargin(marginV);

    if (!isAnimating()) {
        bookView.setEnableScrolling(config.isScrollingEnabled());
    }//from  w ww  .  j a v a2  s  .  c  om

    bookView.setStripWhiteSpace(config.isStripWhiteSpaceEnabled());
    bookView.setLineSpacing(config.getLineSpacing());

    if (config.isFullScreenEnabled()) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    } else {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }

    restoreColorProfile();

    // Check if we need a restart
    if (config.isBrightnessControlEnabled() != oldBrightness
            || config.isStripWhiteSpaceEnabled() != oldStripWhiteSpace
            || !this.oldFontName.equalsIgnoreCase(config.getFontFamily().getName())) {
        restartReader();
    }

    Configuration.OrientationLock orientation = config.getScreenOrientation();

    switch (orientation) {
    case PORTRAIT:
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        break;
    case LANDSCAPE:
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        break;
    case REVERSE_LANDSCAPE:
        setRequestedOrientation(8); // Android 2.3+ value
        break;
    case REVERSE_PORTRAIT:
        setRequestedOrientation(9); // Android 2.3+ value
        break;
    default:
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
    }
}

From source file:com.gigabytedevelopersinc.app.calculator.Calculator.java

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

    // Disable IME for this application
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
            WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

    setContentView(R.layout.main);// w  w w.  ja  va  2s .c o  m
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    // Prepare the interstitial Ad
    mInterstitialAd = new InterstitialAd(getApplicationContext());
    // Insert the Ad Unit ID
    mInterstitialAd.setAdUnitId(getString(R.string.interstitial_ads));
    AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build();
    // Load requested Ad
    mInterstitialAd.loadAd(adRequest);

    mPager = findViewById(R.id.panelswitch);
    mSmallPager = findViewById(R.id.smallPanelswitch);
    mLargePager = findViewById(R.id.largePanelswitch);

    isTelevision = Utils.isTelevision(this);

    mDrawerList = findViewById(R.id.navList);
    mDrawerLayout = findViewById(R.id.drawer_layout);

    addDrawerItems();
    setupDrawer();
    if (getActionBar() != null) {
        getActionBar().setDisplayHomeAsUpEnabled(true);
        getActionBar().setHomeButtonEnabled(true);
    }

    if (mClearButton == null) {
        mClearButton = findViewById(R.id.clear);
        mClearButton.setOnClickListener(mListener);
        mClearButton.setOnLongClickListener(mListener);
    }
    if (mBackspaceButton == null) {
        mBackspaceButton = findViewById(R.id.del);
        mBackspaceButton.setOnClickListener(mListener);
        mBackspaceButton.setOnLongClickListener(mListener);
    }

    mPersist = new Persist(this);
    mPersist.load();

    mHistory = mPersist.history;

    mDisplay = findViewById(R.id.display);

    mLogic = new Logic(this, mHistory, mDisplay);
    mLogic.setListener(this);
    if (mPersist.getMode() != null)
        mLogic.mBaseModule.setMode(mPersist.getMode());

    mLogic.setDeleteMode(mPersist.getDeleteMode());
    mLogic.setLineLength(mDisplay.getMaxDigits());

    mHistoryAdapter = new HistoryAdapter(this, mHistory);
    mHistory.setObserver(mHistoryAdapter);

    mPulldown = findViewById(R.id.pulldown);
    mPulldown.setBarHeight(getResources().getDimensionPixelSize(R.dimen.history_bar_height));
    mPulldown.setSlideDirection(Direction.DOWN);
    if (CalculatorSettings.clickToOpenHistory(this)) {
        mPulldown.enableClick(true);
        mPulldown.enableTouch(false);
    }
    mPulldown.setBackgroundResource(R.color.mainbackground);
    mHistoryView = mPulldown.findViewById(R.id.history);
    setUpHistory();

    mGraph = new Graph(mLogic);

    if (mPager != null) {
        mPager.setAdapter(new PageAdapter(mPager, mListener, mGraph, mLogic));
        mPager.setCurrentItem(state == null ? Panel.BASIC.getOrder()
                : state.getInt(STATE_CURRENT_VIEW, Panel.BASIC.getOrder()));
        mPager.addOnPageChangeListener(this);
        runCling(false);
        mListener.setHandler(this, mLogic, mPager);
    } else if (mSmallPager != null && mLargePager != null) {
        // Expanded UI
        mSmallPager.setAdapter(new SmallPageAdapter(mSmallPager, mLogic));
        mLargePager.setAdapter(new LargePageAdapter(mLargePager, mGraph, mLogic));
        mSmallPager.setCurrentItem(state == null ? SmallPanel.ADVANCED.getOrder()
                : state.getInt(STATE_CURRENT_VIEW_SMALL, SmallPanel.ADVANCED.getOrder()));
        mLargePager.setCurrentItem(state == null ? LargePanel.BASIC.getOrder()
                : state.getInt(STATE_CURRENT_VIEW_LARGE, LargePanel.BASIC.getOrder()));
        mSmallPager.addOnPageChangeListener(this);
        mLargePager.addOnPageChangeListener(this);
        runCling(false);
        mListener.setHandler(this, mLogic, mSmallPager, mLargePager);
    }

    mDisplay.setOnKeyListener(mListener);

    if (!ViewConfiguration.get(this).hasPermanentMenuKey()) {
        createFakeMenu();
    }

    mLogic.resumeWithHistory();
    updateDeleteMode();

    mPulldown.bringToFront();
}

From source file:es.rgmf.libresportgps.MainActivity.java

/**
 * These methods are called from fragments through callback in these
 * fragments to show and dismiss loading dialog.
 *///from ww  w . ja v a 2  s  .  c  om
@Override
public void onPreExecute() {
    // Create the progress dialog.
    mProgressDialog = new ProgressDialog(this);
    mProgressDialog.setCancelable(false);
    mProgressDialog.setMessage(getString(R.string.loading_file));
    mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);

    // Stop rotation screen.
    int current_orientation = getResources().getConfiguration().orientation;
    if (current_orientation == Configuration.ORIENTATION_LANDSCAPE) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    } else {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }

    // Show the progress dialog.
    mProgressDialog.show();
}

From source file:org.huxizhijian.hhcomicviewer.ui.entry.GalleryActivity.java

private void preferencesSet() {
    //?//from  ww w. j  ava  2s. c om
    SharedPreferencesManager preferencesManager = new SharedPreferencesManager(this);

    //
    if (!preferencesManager.getBoolean("time_visible", true)) {
        //?
        mTv_time.setVisibility(View.GONE);
    }
    if (!preferencesManager.getBoolean("page_visible", true)) {
        //??
        mTv_progress.setVisibility(View.GONE);
    }
    if (!preferencesManager.getBoolean("charge_visible", true)) {
        //??
        mIv_battery.setVisibility(View.GONE);
    }
    if (!preferencesManager.getBoolean("number_visible", false)) {
        //??
        mIsCenterPositionVisible = false;
    }
    if (preferencesManager.getBoolean("keep_screen_on", false)) {
        //?
        mMenu.setKeepScreenOn(true);
    }
    loadOnLineFullSizeImage = preferencesManager.getBoolean("reading_full_size_image", false);
    useVolButtonChangePage = preferencesManager.getBoolean("use_volume_key", false);

    String rotate = preferencesManager.getString("reading_screen_rotate", "none");
    if ("portrait".equals(rotate)) {
        //???
        if (getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }
    } else if ("landscape".equals(rotate)) {
        //???
        if (getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        }
    }

    //
    String directionValue = preferencesManager.getString("reading_direction", "view_pager");
    if ("view_pager".equals(directionValue)) {
        mReadingDirection = VIEW_PAGER;
    } else if ("list_view".equals(directionValue)) {
        mReadingDirection = LIST_VIEW;
        mTv_position.setVisibility(View.GONE);
    }

}

From source file:com.slushpupie.deskclock.DeskClock.java

private void loadPrefs() {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    boolean b = false;
    int i = 0;/*from   w  w w  .j av a  2s  . c o  m*/
    String s = null;

    i = prefs.getInt("pref_version", 1);
    if (i != PREF_VERSION) {
        upgradePrefs(prefs);
    }

    lastChangelog = prefs.getString("last_changelog", "");

    s = prefs.getString("pref_keep_screen_on", "no");
    if ("auto".equals(s))
        prefsKeepSreenOn = 1;
    else if ("manual".equals(s))
        prefsKeepSreenOn = 2;
    else
        prefsKeepSreenOn = 0;

    prefsScreenBrightness = prefs.getInt("pref_screen_brightness", 50);
    prefsTempScreenBrightness = prefs.getInt("pref_screen_temp_brightness", 70);
    prefsButtonBrightness = prefs.getInt("pref_button_brightness", 50);

    setScreenLock(prefsKeepSreenOn, prefsScreenBrightness, prefsButtonBrightness);

    s = prefs.getString("pref_screen_orientation", "auto");
    if ("portrait".equals(s))
        prefsScreenOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
    else if ("landscape".equals(s))
        prefsScreenOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
    else
        prefsScreenOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;

    setRequestedOrientation(prefsScreenOrientation);

    b = prefs.getBoolean("pref_military_time", false);
    if (b != prefsMilitaryTime) {
        prefsMilitaryTime = b;
        needsResizing = true;
    }

    b = prefs.getBoolean("pref_leading_zero", false);
    if (b != prefsLeadingZero) {
        prefsLeadingZero = b;
        needsResizing = true;
    }

    b = prefs.getBoolean("pref_meridiem", false);
    if (b != prefsShowMeridiem) {
        prefsShowMeridiem = b;
        needsResizing = true;
    }

    try {
        prefsFontColor = prefs.getInt("pref_color", Color.WHITE);
    } catch (NumberFormatException e) {
        prefsFontColor = Color.WHITE;
    }
    display.setColor(prefsFontColor);

    try {
        prefsBackgroundColor = prefs.getInt("pref_background_color", Color.BLACK);
    } catch (NumberFormatException e) {
        prefsBackgroundColor = Color.BLACK;
    }
    //layout.setBackgroundColor(prefsBackgroundColor);
    display.setBackgroundColor(prefsBackgroundColor);

    b = prefs.getBoolean("pref_show_seconds", false);
    if (b != prefsShowSeconds) {
        prefsShowSeconds = b;
        needsResizing = true;
    }

    prefsBlinkColon = prefs.getBoolean("pref_blink_seconds", false);

    try {
        i = Integer.valueOf(prefs.getString("pref_font", getString(R.string.pref_default_font)));
        if (i != prefsFont) {
            prefsFont = i;
            needsResizing = true;
        }
    } catch (NumberFormatException e) {
        if (prefsFont != Integer.valueOf(getString(R.string.pref_default_font))) {
            prefsFont = Integer.valueOf(getString(R.string.pref_default_font));
            needsResizing = true;
        }
    }

    prefsScreenSaverSpeed = prefs.getInt("pref_screensaver_speed", 500);
    if (prefsScreenSaverSpeed < 500)
        prefsScreenSaverSpeed = 500;
    if (prefsScreenSaverSpeed > 10000)
        prefsScreenSaverSpeed = 10000;
    b = prefs.getBoolean("pref_screensaver", false);
    if (b != prefsScreenSaver) {
        prefsScreenSaver = b;
        display.setScreenSaver(prefsScreenSaver);
        handler.removeCallbacks(runMoveDisplay);
        handler.postDelayed(runMoveDisplay, prefsScreenSaverSpeed);
        needsResizing = true;
    }

    i = prefs.getInt("pref_scale", 100);
    if (i != prefsScale) {
        prefsScale = i;
        needsResizing = true;
    }

    prefsShowHints = prefs.getBoolean("pref_hints", true);

    prefsUndockExit = prefs.getBoolean("pref_undock_exit", false);

}

From source file:com.t2.compassionMeditation.MeditationActivity.java

/** Called when the activity is first created. */
@Override/*from  w w  w.j ava  2  s .  c  o  m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.i(TAG, this.getClass().getSimpleName() + ".onCreate()");

    mInstance = this;
    mRateOfChange = new RateOfChange(mRateOfChangeSize);

    mIntroFade = 255;

    // We don't want the screen to timeout in this activity
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE); // This needs to happen BEFORE setContentView

    setContentView(R.layout.buddah_activity_layout);

    sharedPref = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

    currentMindsetData = new MindsetData(this);
    mSaveRawWave = SharedPref.getBoolean(this, BioZenConstants.PREF_SAVE_RAW_WAVE,
            BioZenConstants.PREF_SAVE_RAW_WAVE_DEFAULT);

    mShowAGain = SharedPref.getBoolean(this, BioZenConstants.PREF_SHOW_A_GAIN,
            BioZenConstants.PREF_SHOW_A_GAIN_DEFAULT);

    mAllowComments = SharedPref.getBoolean(this, BioZenConstants.PREF_COMMENTS,
            BioZenConstants.PREF_COMMENTS_DEFAULT);

    mShowForeground = SharedPref.getBoolean(this, "show_lotus", true);
    mShowToast = SharedPref.getBoolean(this, "show_toast", true);

    mAudioTrackResourceName = SharedPref.getString(this, "audio_track", "None");
    mBaseImageResourceName = SharedPref.getString(this, "background_images", "Sunset");

    mBioHarnessParameters = getResources().getStringArray(R.array.bioharness_parameters_array);

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    String s = SharedPref.getString(this, BioZenConstants.PREF_SESSION_LENGTH, "10");
    mSecondsRemaining = Integer.parseInt(s) * 60;
    mSecondsTotal = mSecondsRemaining;

    s = SharedPref.getString(this, BioZenConstants.PREF_ALPHA_GAIN, "5");
    mAlphaGain = Float.parseFloat(s);

    mMovingAverage = new TMovingAverageFilter(mMovingAverageSize);
    mMovingAverageROC = new TMovingAverageFilter(mMovingAverageSizeROC);

    View v1 = findViewById(R.id.buddahView);
    v1.setOnTouchListener(this);

    Resources resources = this.getResources();
    AssetManager assetManager = resources.getAssets();

    // Set up member variables to UI Elements
    mTextInfoView = (TextView) findViewById(R.id.textViewInfo);
    mTextBioHarnessView = (TextView) findViewById(R.id.textViewBioHarness);
    mCountdownTextView = (TextView) findViewById(R.id.countdownTextView);
    mCountdownImageView = (ImageView) findViewById(R.id.imageViewCountdown);

    mPauseButton = (ImageButton) findViewById(R.id.buttonPause);
    mSignalImage = (ImageView) findViewById(R.id.imageView1);
    mTextViewInstructions = (TextView) findViewById(R.id.textViewInstructions);

    // Note that the seek bar is a debug thing - used only to set the
    // alpha of the buddah image manually for visual testing
    mSeekBar = (SeekBar) findViewById(R.id.seekBar1);
    mSeekBar.setOnSeekBarChangeListener(this);

    // Scale such that values to the right of center are scaled 1 - 10
    // and values to the left of center are scaled 0 = .99999
    if (mAlphaGain > 1.0) {
        mSeekBar.setProgress(50 + (int) (mAlphaGain * 5));
    } else {
        int i = (int) (mAlphaGain * 50);
        mSeekBar.setProgress(i);
    }
    //      mSeekBar.setProgress((int) mAlphaGain * 10);      

    // Controls start as invisible, need to touch screen to activate them
    mCountdownTextView.setVisibility(View.INVISIBLE);
    mCountdownImageView.setVisibility(View.INVISIBLE);
    mTextInfoView.setVisibility(View.INVISIBLE);
    mTextBioHarnessView.setVisibility(View.INVISIBLE);
    mPauseButton.setVisibility(View.INVISIBLE);
    mPauseButton.setVisibility(View.VISIBLE);
    mSeekBar.setVisibility(View.INVISIBLE);

    mBackgroundImage = (ImageView) findViewById(R.id.buddahView);
    mForegroundImage = (ImageView) findViewById(R.id.lotusView);
    mBaseImage = (ImageView) findViewById(R.id.backgroundView);

    if (!mShowForeground) {
        mForegroundImage.setVisibility(View.INVISIBLE);
    }

    int resource = 0;
    if (mBaseImageResourceName.equalsIgnoreCase("Buddah")) {
        mBackgroundImage.setImageResource(R.drawable.buddha);
        mForegroundImage.setImageResource(R.drawable.lotus_flower);
        mBaseImage.setImageResource(R.drawable.none_bg);
    } else if (mBaseImageResourceName.equalsIgnoreCase("Bob")) {
        mBackgroundImage.setImageResource(R.drawable.bigbob);
        mForegroundImage.setImageResource(R.drawable.red_nose);
        mBaseImage.setImageResource(R.drawable.none_bg);
    } else if (mBaseImageResourceName.equalsIgnoreCase("Sunset")) {
        mBackgroundImage.setImageResource(R.drawable.eeg_layer);
        mForegroundImage.setImageResource(R.drawable.breathing_rate);
        mBaseImage.setImageResource(R.drawable.meditation_bg);
    }

    // Initialize SPINE by passing the fileName with the configuration properties
    try {
        mManager = SPINEFactory.createSPINEManager("SPINETestApp.properties", resources);
    } catch (InstantiationException e) {
        Log.e(TAG, "Exception creating SPINE manager: " + e.toString());
        e.printStackTrace();
    }

    // Since Mindset is a static node we have to manually put it in the active node list
    // Note that the sensor id 0xfff1 (-15) is a reserved id for this particular sensor
    Node mindsetNode = null;
    mindsetNode = new Node(new Address("" + Constants.RESERVED_ADDRESS_MINDSET));
    mManager.getActiveNodes().add(mindsetNode);

    Node zepherNode = null;
    zepherNode = new Node(new Address("" + Constants.RESERVED_ADDRESS_ZEPHYR));
    mManager.getActiveNodes().add(zepherNode);

    // The arduino node is programmed to look like a static Spine node
    // Note that currently we don't have  to turn it on or off - it's always streaming
    // Since Spine (in this case) is a static node we have to manually put it in the active node list
    // Since the 
    final int RESERVED_ADDRESS_ARDUINO_SPINE = 1; // 0x0001
    mSpineNode = new Node(new Address("" + RESERVED_ADDRESS_ARDUINO_SPINE));
    mManager.getActiveNodes().add(mSpineNode);

    // Create a broadcast receiver. Note that this is used ONLY for command messages from the service
    // All data from the service goes through the mail SPINE mechanism (received(Data data)).
    // See public void received(Data data)
    this.mCommandReceiver = new SpineReceiver(this);

    try {
        PackageManager packageManager = this.getPackageManager();
        PackageInfo info = packageManager.getPackageInfo(this.getPackageName(), 0);
        mApplicationVersion = info.versionName;
        Log.i(TAG, "BioZen Application Version: " + mApplicationVersion + ", Activity Version: "
                + mActivityVersion);
    } catch (NameNotFoundException e) {
        Log.e(TAG, e.toString());
    }

    // First create GraphBioParameters for each of the ECG static params (ie mindset)      
    int itemId = 0;
    eegPos = itemId; // eeg always comes first
    mBioParameters.clear();

    for (itemId = 0; itemId < MindsetData.NUM_BANDS + 2; itemId++) { // 2 extra, for attention and meditation
        GraphBioParameter param = new GraphBioParameter(itemId, MindsetData.spectralNames[itemId], "", true);
        param.isShimmer = false;
        mBioParameters.add(param);
    }

    // Now create all of the potential dynamic GBraphBioParameters (GSR, EMG, ECG, HR, Skin Temp, Resp Rate
    String[] paramNamesStringArray = getResources().getStringArray(R.array.parameter_names);

    for (String paramName : paramNamesStringArray) {
        if (paramName.equalsIgnoreCase("not assigned"))
            continue;

        if (paramName.equalsIgnoreCase("EEG"))
            continue;

        GraphBioParameter param = new GraphBioParameter(itemId, paramName, "", true);

        if (paramName.equalsIgnoreCase("gsr")) {
            gsrPos = itemId;
            param.isShimmer = true;
            param.shimmerSensorConstant = SPINESensorConstants.SHIMMER_GSR_SENSOR;
            param.shimmerNode = getShimmerNode();
        }

        if (paramName.equalsIgnoreCase("emg")) {
            emgPos = itemId;
            param.isShimmer = true;
            param.shimmerSensorConstant = SPINESensorConstants.SHIMMER_EMG_SENSOR;
            param.shimmerNode = getShimmerNode();
        }

        if (paramName.equalsIgnoreCase("ecg")) {
            ecgPos = itemId;
            param.isShimmer = true;
            param.shimmerSensorConstant = SPINESensorConstants.SHIMMER_ECG_SENSOR;
            param.shimmerNode = getShimmerNode();
        }

        if (paramName.equalsIgnoreCase("heart rate")) {
            heartRatePos = itemId;
            param.isShimmer = false;
        }

        if (paramName.equalsIgnoreCase("resp rate")) {
            respRatePos = itemId;
            param.isShimmer = false;
        }

        if (paramName.equalsIgnoreCase("skin temp")) {
            skinTempPos = itemId;
            param.isShimmer = false;
        }

        if (paramName.equalsIgnoreCase("EHealth Airflow")) {
            eHealthAirFlowPos = itemId;
            param.isShimmer = false;
        }

        if (paramName.equalsIgnoreCase("EHealth Temp")) {
            eHealthTempPos = itemId;
            param.isShimmer = false;
        }

        if (paramName.equalsIgnoreCase("EHealth SpO2")) {
            eHealthSpO2Pos = itemId;
            param.isShimmer = false;
        }

        if (paramName.equalsIgnoreCase("EHealth Heartrate")) {
            eHealthHeartRatePos = itemId;
            param.isShimmer = false;
        }

        if (paramName.equalsIgnoreCase("EHealth GSR")) {
            eHealthGSRPos = itemId;
            param.isShimmer = false;
        }

        itemId++;
        mBioParameters.add(param);
    }

    // The session start time will be used as session id
    // Note this also sets session start time
    // **** This session ID will be prepended to all JSON data stored
    //      in the external database until it's changed (by the start
    //      of a new session.
    Calendar cal = Calendar.getInstance();
    SharedPref.setBioSessionId(sharedPref, cal.getTimeInMillis());

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.US);
    String sessionDate = sdf.format(new Date());
    long sessionId = SharedPref.getLong(this, "bio_session_start_time", 0);

    mUserId = SharedPref.getString(this, "SelectedUser", "");

    // Now get the database object associated with this user

    try {
        mBioUserDao = getHelper().getBioUserDao();
        mBioSessionDao = getHelper().getBioSessionDao();

        QueryBuilder<BioUser, Integer> builder = mBioUserDao.queryBuilder();
        builder.where().eq(BioUser.NAME_FIELD_NAME, mUserId);
        builder.limit(1);
        //         builder.orderBy(ClickCount.DATE_FIELD_NAME, false).limit(30);
        List<BioUser> list = mBioUserDao.query(builder.prepare());

        if (list.size() == 1) {
            mCurrentBioUser = list.get(0);
        } else if (list.size() == 0) {
            try {
                mCurrentBioUser = new BioUser(mUserId, System.currentTimeMillis());
                mBioUserDao.create(mCurrentBioUser);
            } catch (SQLException e1) {
                Log.e(TAG, "Error creating user " + mUserId, e1);
            }
        } else {
            Log.e(TAG, "General Database error" + mUserId);
        }

    } catch (SQLException e) {
        Log.e(TAG, "Can't find user: " + mUserId, e);

    }

    mSignalImage.setImageResource(R.drawable.signal_bars0);

    // Check to see of there a device configured for EEG, if so then show the skin conductance meter
    String tmp = SharedPref.getString(this, "EEG", null);

    if (tmp != null) {
        mSignalImage.setVisibility(View.VISIBLE);
        mTextViewInstructions.setVisibility(View.VISIBLE);

    } else {
        mSignalImage.setVisibility(View.INVISIBLE);
        mTextViewInstructions.setVisibility(View.INVISIBLE);
    }

    mDataOutHandler = new DataOutHandler(this, mUserId, sessionDate, mAppId,
            DataOutHandler.DATA_TYPE_EXTERNAL_SENSOR, sessionId);

    if (mDatabaseEnabled) {
        TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
        String myNumber = telephonyManager.getLine1Number();

        String remoteDatabaseUri = SharedPref.getString(this, "database_sync_name",
                getString(R.string.database_uri));
        //            remoteDatabaseUri += myNumber; 

        Log.d(TAG, "Initializing database at " + remoteDatabaseUri); // TODO: remove
        try {
            mDataOutHandler.initializeDatabase(dDatabaseName, dDesignDocName, dDesignDocId, byDateViewName,
                    remoteDatabaseUri);
        } catch (DataOutHandlerException e) {
            Log.e(TAG, e.toString());
            e.printStackTrace();
        }
        mDataOutHandler.setRequiresAuthentication(false);
    }

    mBioDataProcessor.initialize(mDataOutHandler);

    mLoggingEnabled = SharedPref.getBoolean(this, "enable_logging", true);
    mDatabaseEnabled = SharedPref.getBoolean(this, "database_enabled", false);
    mAntHrmEnabled = SharedPref.getBoolean(this, "enable_ant_hrm", false);

    mInternalSensorMonitoring = SharedPref.getBoolean(this, "inernal_sensor_monitoring_enabled", false);

    if (mAntHrmEnabled) {
        mHeartRateSource = HEARTRATE_ANT;
    } else {
        mHeartRateSource = HEARTRATE_ZEPHYR;
    }

    if (mLoggingEnabled) {
        mDataOutHandler.enableLogging(this);
    }

    if (mLogCatEnabled) {
        mDataOutHandler.enableLogCat();
    }

    // Log the version
    try {
        PackageManager packageManager = getPackageManager();
        PackageInfo info = packageManager.getPackageInfo(getPackageName(), 0);
        mApplicationVersion = info.versionName;
        String versionString = mAppId + " application version: " + mApplicationVersion;

        DataOutPacket packet = new DataOutPacket();
        packet.add(DataOutHandlerTags.version, versionString);
        try {
            mDataOutHandler.handleDataOut(packet);
        } catch (DataOutHandlerException e) {
            Log.e(TAG, e.toString());
            e.printStackTrace();
        }

    } catch (NameNotFoundException e) {
        Log.e(TAG, e.toString());
    }

    if (mInternalSensorMonitoring) {
        // IntentSender Launches our service scheduled with with the alarm manager 
        mBigBrotherService = PendingIntent.getService(MeditationActivity.this, 0,
                new Intent(MeditationActivity.this, BigBrotherService.class), 0);

        long firstTime = SystemClock.elapsedRealtime();
        // Schedule the alarm!
        AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
        am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, mPollingPeriod * 1000,
                mBigBrotherService);

        // Tell the user about what we did.
        Toast.makeText(MeditationActivity.this, R.string.service_scheduled, Toast.LENGTH_LONG).show();

    }

}

From source file:net.henryco.opalette.application.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
    if (preferences.getBoolean(GodConfig.PREF_KEY_ANALYTICS_ENABLE, false)) {
        Utils.log("ANALYTICS ENABLE");
        firebaseAnalytics = FirebaseAnalytics.getInstance(this);
    } else/*from w  w  w.j ava2 s  .  c o  m*/
        firebaseAnalytics = null;

    Utils.log("SAVE AFTER SHARE stat: " + preferences.getBoolean(GodConfig.PREF_KEY_SAVE_AFTER, false));

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    imageToggle = (ToggleButton) toolbar.findViewById(R.id.toolbarButtonImage);
    paletteToggle = (ToggleButton) toolbar.findViewById(R.id.toolbarButtonPalette);
    filterToggle = (ToggleButton) toolbar.findViewById(R.id.toolbarButtonFilter);
    toggleGroup = new ToggleButton[] { imageToggle, paletteToggle, filterToggle };

    imageContainer = findViewById(R.id.imageOptionsContainer);
    paletteContainer = findViewById(R.id.paletteOptionsContainer);
    filterContainer = findViewById(R.id.filterOptionsContainer);
    containerGroup = new View[] { imageContainer, paletteContainer, filterContainer };

    imageToggle.setOnClickListener(this::toggleImage);
    paletteToggle.setOnClickListener(this::togglePalette);
    filterToggle.setOnClickListener(this::toggleFilter);

    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowHomeEnabled(true);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().setStatusBarColor(ContextCompat.getColor(this, R.color.DARK));
        findViewById(R.id.fragmentSuperContainer).setElevation(0);
    }

    OPallUniRenderer renderer = new UniRenderer(this, new ProgramPipeLine());
    stateRequester.addRequestListener(renderer);

    OPallSurfaceView oPallSurfaceView = (OPallSurfaceView) findViewById(R.id.opallView);
    oPallSurfaceView.setDimProportions(OPallSurfaceView.DimensionProcessors.RELATIVE_SQUARE);
    oPallSurfaceView.setRenderer(renderer);

    oPallSurfaceView.addToGLContextQueue(gl -> stateRequester
            .sendNonSyncRequest(new Request(send_bitmap_to_program, StartUpActivity.BitmapPack.get())));

    switchToScrollOptionsView();
}

From source file:apps.junkuvo.alertapptowalksafely.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Fabric.with(this, new Crashlytics());

    ActionBar actionbar = getSupportActionBar();
    if (actionbar != null) {
        actionbar.show();// www. j a  va2  s.c om
    }
    // ????APK???????BG???onCreate??Activity??
    // Intent??????????????
    if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) {
        finish();
        return;
    }

    if (!isRunningJunit) {
        setContentView(R.layout.activity_main);

        FirebaseRemoteConfigUtil.initialize();

        LikeView likeView = (LikeView) findViewById(R.id.like_view);
        likeView.setObjectIdAndType(String.format(getString(R.string.app_googlePlay_url), getPackageName()),
                LikeView.ObjectType.PAGE);

        // Create the interstitial.
        mInterstitialAd = new InterstitialAd(this);
        mInterstitialAd.setAdUnitId(getString(R.string.ad_mob_id));

        // Create ad request.
        final AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR) // All emulators
                .addTestDevice("1BEC3806A9717F2A87F4D1FC2039D5F2") // An device ID ASUS
                .addTestDevice("64D37FCE47B679A7F4639D180EC4C547").build();

        // Begin loading your interstitial.
        mInterstitialAd.loadAd(adRequest);
        mInterstitialAd.setAdListener(new AdListener() {
            @Override
            public void onAdLeftApplication() {
                super.onAdLeftApplication();
                enableNewFunction = true;
                supportInvalidateOptionsMenu();
            }

            @Override
            public void onAdClosed() {
                super.onAdClosed();
                // ?????????????
                if (!enableNewFunction) {
                    // Begin loading your interstitial.
                    mInterstitialAd.loadAd(adRequest);
                } else {
                    LayoutInflater inflater = LayoutInflater.from(MainActivity.this);
                    final View layout = inflater.inflate(R.layout.new_function_dialog,
                            (ViewGroup) findViewById(R.id.layout_root_new));
                    new MaterialStyledDialog(MainActivity.this).setTitle("?").setDescription(
                            "????????\n???????????")
                            .setCustomView(layout).setIcon(R.drawable.ic_fiber_new_white_48dp)
                            .setHeaderDrawable(R.drawable.pattern_bg_blue)
                            .setPositive(getString(R.string.ok), null).show();

                    RealmUtil.insertHistoryItemAsync(realm, createHistoryItemData(),
                            new RealmUtil.realmTransactionCallbackListener() {
                                @Override
                                public void OnSuccess() {

                                }

                                @Override
                                public void OnError() {

                                }
                            });
                }
            }
        });

        // FIXME : ??????
        AdView mAdView = (AdView) findViewById(R.id.adView);
        //            mAdView.loadAd(adRequest);

        DefaultLayoutPromptView promptView = (DefaultLayoutPromptView) findViewById(R.id.prompt_view);

        final BasePromptViewConfig basePromptViewConfig = new BasePromptViewConfig.Builder()
                .setUserOpinionQuestionTitle(getString(R.string.prompt_title))
                .setUserOpinionQuestionPositiveButtonLabel(getString(R.string.prompt_btn_yes))
                .setUserOpinionQuestionNegativeButtonLabel(getString(R.string.prompt_btn_no))
                .setPositiveFeedbackQuestionTitle(getString(R.string.prompt_title_feedback))
                .setPositiveFeedbackQuestionPositiveButtonLabel(getString(R.string.prompt_btn_sure))
                .setPositiveFeedbackQuestionNegativeButtonLabel(getString(R.string.prompt_btn_notnow))
                .setCriticalFeedbackQuestionTitle(getString(R.string.prompt_title_feedback_2))
                .setCriticalFeedbackQuestionNegativeButtonLabel(getString(R.string.prompt_btn_notnow))
                .setCriticalFeedbackQuestionPositiveButtonLabel(getString(R.string.prompt_btn_sure))
                .setThanksTitle(getString(R.string.prompt_thanks)).build();

        promptView.applyBaseConfig(basePromptViewConfig);
        Amplify.getSharedInstance().promptIfReady(promptView);

        mAnimationBlink = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.blink);

        int buttonColor = ContextCompat.getColor(this, R.color.colorPrimary);
        int buttonPressedColor = ContextCompat.getColor(this, R.color.colorPrimaryDark);
        mbtnStart = (ActionButton) findViewById(R.id.fabStart);
        mbtnStart.setButtonColor(buttonColor);
        mbtnStart.setButtonColorPressed(buttonPressedColor);

        // ?
        new MaterialIntroView.Builder(this).enableDotAnimation(false).enableIcon(true)
                .setFocusGravity(FocusGravity.CENTER).setFocusType(Focus.MINIMUM).setDelayMillis(500)
                .enableFadeAnimation(true).performClick(true).setInfoText(getString(R.string.intro_description))
                .setTarget(mbtnStart).setUsageId(TUTORIAL_ID) //THIS SHOULD BE UNIQUE ID
                .dismissOnTouch(true).show();

        mbtnStart.setOnClickListener(this);

        Intent mAlertServiceIntent = new Intent(MainActivity.this, AlertService.class);

        // ?????????????(???????)
        // ????????
        if (!Utility.isTabletNotPhone(this)) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }
        mTwitter = TwitterUtility.getTwitterInstance(this);
        mCallbackURL = getString(R.string.twitter_callback_url);

        mPlusOneButton = (PlusOneButton) findViewById(R.id.plus_one_button);
        // Refresh the state of the +1 button each time the activity receives focus.
        mPlusOneButton.initialize(
                String.format(getString(R.string.app_googlePlay_url_plusOne), getPackageName()),
                PLUS_ONE_REQUEST_CODE);

        RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.rtlMain);
        relativeLayout.setOnClickListener(this);

        findViewById(R.id.llStepCount).setVisibility(mShouldShowPedometer ? View.VISIBLE : View.INVISIBLE);

        //        // Service?????Activity?Destroy????Activity??????
        //        // UI?Service????????Service??????????Bind????????
        //        // Application????
        //        if (((AlertApplication) getApplication()).IsRunningService()) {
        //            btnIsStarted = false;
        //            setStartButtonFunction(findViewById(R.id.fabStart));
        //        }
        // 
        //            startService(mAlertServiceIntent);
        bindService(mAlertServiceIntent, mConnection, Context.BIND_AUTO_CREATE);

    }

    mIsToastOn = SharedPreferencesUtil.getBoolean(this, SETTING_SHAREDPREF_NAME, "message", true);
    mIsVibrationOn = SharedPreferencesUtil.getBoolean(this, SETTING_SHAREDPREF_NAME, "vibrate", true);
    mToastPosition = SharedPreferencesUtil.getInt(this, SETTING_SHAREDPREF_NAME, "toastPosition",
            Gravity.CENTER);
    mAlertStartAngle = SharedPreferencesUtil.getInt(this, SETTING_SHAREDPREF_NAME, "progress",
            ALERT_ANGLE_INITIAL_VALUE) + ALERT_ANGLE_INITIAL_OFFSET;
    mShouldShowPedometer = SharedPreferencesUtil.getBoolean(this, SETTING_SHAREDPREF_NAME, "pedometer", true);

    // ?????(update??) or ???
    enableNewFunction = RealmUtil.hasHistoryItem(realm) || SharedPreferencesUtil.getBoolean(this,
            AD_STATUS_SHAREDPREF_NAME, "AD_STATUS_SHAREDPREF_NAME", false);

}