Example usage for android.content.res Configuration ORIENTATION_LANDSCAPE

List of usage examples for android.content.res Configuration ORIENTATION_LANDSCAPE

Introduction

In this page you can find the example usage for android.content.res Configuration ORIENTATION_LANDSCAPE.

Prototype

int ORIENTATION_LANDSCAPE

To view the source code for android.content.res Configuration ORIENTATION_LANDSCAPE.

Click Source Link

Document

Constant for #orientation , value corresponding to the land resource qualifier.

Usage

From source file:com.tkjelectronics.balanduino.BalanduinoActivity.java

@Override
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    activity = this;
    context = getApplicationContext();/*from  w ww.  j  ava  2s  .c  o m*/

    if (!getResources().getBoolean(R.bool.isTablet))
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // Set portrait mode only - for small screens like phones
    else {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2)
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_USER); // Full screen rotation
        else
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR); // Full screen rotation
        new Handler().postDelayed(new Runnable() { // Hack to hide keyboard when the layout it rotated
            @Override
            public void run() {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); // Hide the keyboard - this is needed when the device is rotated
                imm.hideSoftInputFromWindow(getWindow().getDecorView().getApplicationWindowToken(), 0);
            }
        }, 1000);
    }

    setContentView(R.layout.activity_main);

    // Get local Bluetooth adapter
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2)
        mBluetoothAdapter = ((BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter();
    else
        mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

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

    // get sensorManager and initialize sensor listeners
    SensorManager mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
    mSensorFusion = new SensorFusion(getApplicationContext(), mSensorManager);

    // Set up the action bar.
    final ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.setDisplayHomeAsUpEnabled(true);

    // Create the adapter that will return a fragment for each of the primary sections of the app.
    ViewPagerAdapter mViewPagerAdapter = new ViewPagerAdapter(getApplicationContext(),
            getSupportFragmentManager());

    // Set up the ViewPager with the adapter.
    CustomViewPager mViewPager = (CustomViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mViewPagerAdapter);

    if (getResources().getBoolean(R.bool.isTablet))
        mViewPager.setOffscreenPageLimit(2); // Since two fragments is selected in landscape mode, this is used to smooth things out

    // Bind the underline indicator to the adapter
    mUnderlinePageIndicator = (UnderlinePageIndicator) findViewById(R.id.indicator);
    mUnderlinePageIndicator.setViewPager(mViewPager);
    mUnderlinePageIndicator.setFades(false);

    // When swiping between different sections, select the corresponding
    // tab. We can also use ActionBar.Tab#select() to do this if we have
    // a reference to the Tab.
    mUnderlinePageIndicator.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            if (D)
                Log.d(TAG, "ViewPager position: " + position);
            if (position < actionBar.getTabCount()) // Needed for when in landscape mode
                actionBar.setSelectedNavigationItem(position);
            else
                mUnderlinePageIndicator.setCurrentItem(position - 1);
        }
    });

    int count = mViewPagerAdapter.getCount();
    Resources mResources = getResources();
    boolean landscape = false;
    if (mResources.getBoolean(R.bool.isTablet)
            && mResources.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
        landscape = true;
        count -= 1; // There is one less tab when in landscape mode
    }

    for (int i = 0; i < count; i++) { // For each of the sections in the app, add a tab to the action bar
        String text;
        if (landscape && i == count - 1)
            text = mViewPagerAdapter.getPageTitle(i) + " & " + mViewPagerAdapter.getPageTitle(i + 1); // Last tab in landscape mode have two titles in one tab
        else
            text = mViewPagerAdapter.getPageTitle(i).toString();

        // Create a tab with text corresponding to the page title defined by
        // the adapter. Also specify this Activity object, which implements
        // the TabListener interface, as the callback (listener) for when
        // this tab is selected.
        actionBar.addTab(actionBar.newTab().setText(text).setTabListener(this));
    }
    try {
        PackageManager mPackageManager = getPackageManager();
        if (mPackageManager != null)
            BalanduinoActivity.appVersion = mPackageManager.getPackageInfo(getPackageName(), 0).versionName; // Read the app version name
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:com.dvdprime.mobile.android.ui.DocumentViewActivity.java

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
        mLayout.findViewById(mAdView.getId()).setVisibility(View.GONE);
        mWebView.loadUrl("javascript:configurationChanged(" + wvHeight + ")");
    } else {/*from   ww  w .  j a  v  a 2s . c  o  m*/
        mLayout.findViewById(mAdView.getId()).setVisibility(View.VISIBLE);
        mWebView.loadUrl("javascript:configurationChanged(" + wvWidth + ")");
    }
}

From source file:com.edutech.eBalanbot.eBalanbotActivity.java

@Override
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    activity = this;
    context = getApplicationContext();//w  w  w . ja v  a2  s .c  o  m

    if (!getResources().getBoolean(R.bool.isTablet))
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // Set portrait mode only - for small screens like phones
    else {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2)
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_USER); // Full screen rotation
        else
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR); // Full screen rotation
        new Handler().postDelayed(new Runnable() { // Hack to hide keyboard when the layout it rotated
            @Override
            public void run() {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); // Hide the keyboard - this is needed when the device is rotated
                imm.hideSoftInputFromWindow(getWindow().getDecorView().getApplicationWindowToken(), 0);
            }
        }, 1000);
    }

    setContentView(R.layout.activity_main);

    // Get local Bluetooth adapter
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2)
        mBluetoothAdapter = ((BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter();
    else
        mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

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

    // get sensorManager and initialize sensor listeners
    SensorManager mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
    mSensorFusion = new SensorFusion(getApplicationContext(), mSensorManager);

    // Set up the action bar.
    final ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.setDisplayHomeAsUpEnabled(true);
    // Create the adapter that will return a fragment for each of the primary sections of the app.
    ViewPagerAdapter mViewPagerAdapter = new ViewPagerAdapter(getApplicationContext(),
            getSupportFragmentManager());

    // Set up the ViewPager with the adapter.
    CustomViewPager mViewPager = (CustomViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mViewPagerAdapter);

    if (getResources().getBoolean(R.bool.isTablet))
        mViewPager.setOffscreenPageLimit(2); // Since two fragments is selected in landscape mode, this is used to smooth things out

    // Bind the underline indicator to the adapter
    mUnderlinePageIndicator = (UnderlinePageIndicator) findViewById(R.id.indicator);
    mUnderlinePageIndicator.setViewPager(mViewPager);
    mUnderlinePageIndicator.setFades(false);

    // When swiping between different sections, select the corresponding
    // tab. We can also use ActionBar.Tab#select() to do this if we have
    // a reference to the Tab.
    mUnderlinePageIndicator.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            if (D)
                Log.d(TAG, "ViewPager position: " + position);
            if (position < actionBar.getTabCount()) // Needed for when in landscape mode
                actionBar.setSelectedNavigationItem(position);
            else
                mUnderlinePageIndicator.setCurrentItem(position - 1);
        }
    });

    int count = mViewPagerAdapter.getCount();
    Resources mResources = getResources();
    boolean landscape = false;
    if (mResources.getBoolean(R.bool.isTablet)
            && mResources.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
        landscape = true;
        count -= 1; // There is one less tab when in landscape mode
    }

    for (int i = 0; i < count; i++) { // For each of the sections in the app, add a tab to the action bar
        String text;
        if (landscape && i == count - 1)
            text = mViewPagerAdapter.getPageTitle(i) + " & " + mViewPagerAdapter.getPageTitle(i + 1); // Last tab in landscape mode have two titles in one tab
        else
            text = mViewPagerAdapter.getPageTitle(i).toString();

        // Create a tab with text corresponding to the page title defined by
        // the adapter. Also specify this Activity object, which implements
        // the TabListener interface, as the callback (listener) for when
        // this tab is selected.
        actionBar.addTab(actionBar.newTab().setText(text).setTabListener(this));
    }
    try {
        PackageManager mPackageManager = getPackageManager();
        if (mPackageManager != null)
            eBalanbotActivity.appVersion = mPackageManager.getPackageInfo(getPackageName(), 0).versionName; // Read the app version name
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:com.duinopeak.balanbot.BalanbotActivity.java

@Override
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    activity = this;
    context = getApplicationContext();// w w  w. j  a v  a  2 s  .  c o m

    if (!getResources().getBoolean(R.bool.isTablet))
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // Set portrait mode only - for small screens like phones
    else {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2)
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_USER); // Full screen rotation
        else
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR); // Full screen rotation
        new Handler().postDelayed(new Runnable() { // Hack to hide keyboard when the layout it rotated
            @Override
            public void run() {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); // Hide the keyboard - this is needed when the device is rotated
                imm.hideSoftInputFromWindow(getWindow().getDecorView().getApplicationWindowToken(), 0);
            }
        }, 1000);
    }

    setContentView(R.layout.activity_main);

    // Get local Bluetooth adapter
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2)
        mBluetoothAdapter = ((BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter();
    else
        mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

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

    // get sensorManager and initialize sensor listeners
    SensorManager mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
    mSensorFusion = new SensorFusion(getApplicationContext(), mSensorManager);

    // Set up the action bar.
    final ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.setDisplayHomeAsUpEnabled(true);

    // Create the adapter that will return a fragment for each of the primary sections of the app.
    ViewPagerAdapter mViewPagerAdapter = new ViewPagerAdapter(getApplicationContext(),
            getSupportFragmentManager());

    // Set up the ViewPager with the adapter.
    CustomViewPager mViewPager = (CustomViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mViewPagerAdapter);

    if (getResources().getBoolean(R.bool.isTablet))
        mViewPager.setOffscreenPageLimit(2); // Since two fragments is selected in landscape mode, this is used to smooth things out

    // Bind the underline indicator to the adapter
    mUnderlinePageIndicator = (UnderlinePageIndicator) findViewById(R.id.indicator);
    mUnderlinePageIndicator.setViewPager(mViewPager);
    mUnderlinePageIndicator.setFades(false);

    // When swiping between different sections, select the corresponding
    // tab. We can also use ActionBar.Tab#select() to do this if we have
    // a reference to the Tab.
    mUnderlinePageIndicator.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            if (D)
                Log.d(TAG, "ViewPager position: " + position);
            if (position < actionBar.getTabCount()) // Needed for when in landscape mode
                actionBar.setSelectedNavigationItem(position);
            else
                mUnderlinePageIndicator.setCurrentItem(position - 1);
        }
    });

    int count = mViewPagerAdapter.getCount();
    Resources mResources = getResources();
    boolean landscape = false;
    if (mResources.getBoolean(R.bool.isTablet)
            && mResources.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
        landscape = true;
        count -= 1; // There is one less tab when in landscape mode
    }

    for (int i = 0; i < count; i++) { // For each of the sections in the app, add a tab to the action bar
        String text;
        if (landscape && i == count - 1)
            text = mViewPagerAdapter.getPageTitle(i) + " & " + mViewPagerAdapter.getPageTitle(i + 1); // Last tab in landscape mode have two titles in one tab
        else
            text = mViewPagerAdapter.getPageTitle(i).toString();

        // Create a tab with text corresponding to the page title defined by
        // the adapter. Also specify this Activity object, which implements
        // the TabListener interface, as the callback (listener) for when
        // this tab is selected.
        actionBar.addTab(actionBar.newTab().setText(text).setTabListener(this));
    }
    try {
        PackageManager mPackageManager = getPackageManager();
        if (mPackageManager != null)
            BalanbotActivity.appVersion = mPackageManager.getPackageInfo(getPackageName(), 0).versionName; // Read the app version name
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:com.github.guwenk.smuradio.SignInDialog.java

private void uploadFile() {

    if (filepath != null) {
        Log.d(AuthTag, "UPLOAD FILE " + filepath);

        final ProgressDialog progressDialog = new ProgressDialog(getActivity());
        progressDialog.setTitle(getString(R.string.uploading));
        progressDialog.setCancelable(false);
        progressDialog.show();/*from   w  w  w .  j a v a  2  s. c  om*/

        int currentOrientation = getResources().getConfiguration().orientation;
        if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
            getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
        } else {
            getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
        }

        Log.d(AuthTag, "UPLOAD FILE progress dialog showing");

        StorageReference musicRef = mStorageRef.child("audio/" + songTitle);

        Log.d(AuthTag, "UPLOAD FILE storage referense: " + musicRef);

        try {
            user = mAuth.getCurrentUser();
        } catch (Exception ignored) {
        }

        StorageMetadata metadata = new StorageMetadata.Builder().setCustomMetadata("By", user.getUid()).build();

        musicRef.putFile(filepath, metadata)
                .addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                    @Override
                    public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                        // if upload success
                        progressDialog.dismiss();
                        Toast.makeText(getActivity(), R.string.file_uploaded, Toast.LENGTH_SHORT).show();
                        alert.dismiss();
                        Log.d(AuthTag, "UPLOAD FILE success");
                        getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
                    }
                }).addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception exception) {
                        // if upload failed
                        progressDialog.dismiss();
                        Toast.makeText(getActivity(),
                                getString(R.string.uploading_error) + exception.getMessage(),
                                Toast.LENGTH_SHORT).show();
                        alert.dismiss();
                        Log.d(AuthTag, "UPLOAD FILE FAILED");
                        getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
                    }
                }).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
                    @Override
                    public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
                        double progress = (100.0 * taskSnapshot.getBytesTransferred())
                                / taskSnapshot.getTotalByteCount();
                        try {
                            progressDialog.setMessage((int) progress + getString(R.string.uploaded_procents));
                            Log.d(AuthTag, "UPLOAD FILE progress update: " + progress);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                });
    } else {
        Toast.makeText(getActivity(), R.string.wrong_file, Toast.LENGTH_SHORT).show();
    }
}

From source file:com.saarang.samples.apps.iosched.ui.SessionLivestreamActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(com.saarang.samples.apps.iosched.R.menu.session_livestream, menu);
    mCaptionsMenuItem = menu.findItem(com.saarang.samples.apps.iosched.R.id.menu_captions);
    mShareMenuItem = menu.findItem(com.saarang.samples.apps.iosched.R.id.menu_share);
    if (mShareMenuDeferredSetup != null) {
        mShareMenuDeferredSetup.run();//  ww  w .j  av a  2 s. c o m
    }
    if (!mIsTablet && Configuration.ORIENTATION_LANDSCAPE == getResources().getConfiguration().orientation) {
        mCaptionsMenuItem.setVisible(true);
    }
    return super.onCreateOptionsMenu(menu);
}

From source file:com.gelakinetic.mtgfam.activities.MainActivity.java

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

    /* http://stackoverflow.com/questions/13179620/force-overflow-menu-in-actionbarsherlock/13180285
     * /*from w  w  w. ja va  2  s.co  m*/
     * Open ActionBarSherlock/src/com/actionbarsherlock/internal/view/menu/ActionMenuPresenter.java, go to method reserveOverflow
     * Replace the original with:
     * public static boolean reserveOverflow(Context context) { return true; }
     */
    if (DEVICE_VERSION >= DEVICE_HONEYCOMB) {
        try {
            ViewConfiguration config = ViewConfiguration.get(this);
            Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
            if (menuKeyField != null) {
                menuKeyField.setAccessible(true);
                menuKeyField.setBoolean(config, false);
            }
        } catch (Exception ex) {
            // Ignore
        }
    }

    mFragmentManager = getSupportFragmentManager();

    try {
        pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
    } catch (NameNotFoundException e) {
        pInfo = null;
    }

    if (prefAdapter == null) {
        prefAdapter = new PreferencesAdapter(this);
    }

    int lastVersion = prefAdapter.getLastVersion();
    if (pInfo.versionCode != lastVersion) {
        // Clear the robospice cache on upgrade. This way, no cached values w/o foil prices will exist
        try {
            spiceManager.removeAllDataFromCache();
        } catch (NullPointerException e) {
            // eat it. tasty
        }
        showDialogFragment(CHANGELOGDIALOG);
        prefAdapter.setLastVersion(pInfo.versionCode);
        bounceMenu = lastVersion <= 15; //Only bounce if the last version is 1.8.1 or lower (or a fresh install) 
    }

    File mtr = new File(getFilesDir(), JudgesCornerFragment.MTR_LOCAL_FILE);
    File ipg = new File(getFilesDir(), JudgesCornerFragment.IPG_LOCAL_FILE);
    if (!mtr.exists()) {
        try {
            InputStream in = getResources().openRawResource(R.raw.mtr);
            FileOutputStream fos = new FileOutputStream(mtr);
            IOUtils.copy(in, fos);
        } catch (FileNotFoundException e) {
            Log.w("MainActivity", "MTR file could not be copied: " + e.getMessage());
        } catch (IOException e) {
            Log.w("MainActivity", "MTR file could not be copied: " + e.getMessage());
        }
    }
    if (!ipg.exists()) {
        try {
            InputStream in = getResources().openRawResource(R.raw.ipg);
            FileOutputStream fos = new FileOutputStream(ipg);
            IOUtils.copy(in, fos);
        } catch (FileNotFoundException e) {
            Log.w("MainActivity", "IPG file could not be copied: " + e.getMessage());
        } catch (IOException e) {
            Log.w("MainActivity", "IPG file could not be copied: " + e.getMessage());
        }
    }

    ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setIcon(R.drawable.sliding_menu_icon);

    SlidingMenu slidingMenu = getSlidingMenu();
    slidingMenu.setBehindWidthRes(R.dimen.sliding_menu_width);
    slidingMenu.setBehindScrollScale(0.0f);
    slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
    slidingMenu.setShadowWidthRes(R.dimen.shadow_width);
    slidingMenu.setShadowDrawable(R.drawable.sliding_menu_shadow);
    setSlidingActionBarEnabled(false);
    setBehindContentView(R.layout.fragment_menu);

    me = this;

    boolean autoupdate = prefAdapter.getAutoUpdate();
    if (autoupdate) {
        // Only update the banning list if it hasn't been updated recently
        long curTime = new Date().getTime();
        int updatefrequency = Integer.valueOf(prefAdapter.getUpdateFrequency());
        int lastLegalityUpdate = prefAdapter.getLastLegalityUpdate();
        // days to ms
        if (((curTime / 1000) - lastLegalityUpdate) > (updatefrequency * 24 * 60 * 60)) {
            startService(new Intent(this, DbUpdaterService.class));
        }
    }

    timerHandler = new Handler();
    registerReceiver(endTimeReceiver, new IntentFilter(RoundTimerFragment.RESULT_FILTER));
    registerReceiver(startTimeReceiver, new IntentFilter(RoundTimerService.START_FILTER));
    registerReceiver(cancelTimeReceiver, new IntentFilter(RoundTimerService.CANCEL_FILTER));

    updatingDisplay = false;
    timeShowing = false;

    getSlidingMenu().setOnOpenedListener(new OnOpenedListener() {

        @Override
        public void onOpened() {
            // Close the keyboard if the slidingMenu is opened
            hideKeyboard();
        }
    });

    setContentView(R.layout.fragment_activity);
    getSupportFragmentManager().beginTransaction().replace(R.id.frag_menu, new MenuFragment()).commit();

    showOnePane();
    if (findViewById(R.id.middle_container) != null) {
        // The detail container view will be present only in the
        // large-screen layouts (res/values-large and
        // res/values-sw600dp). If this view is present, then the
        // activity should be in two-pane mode.
        mIsATablet = true;
        if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
            mThreePane = true;
        } else {
            mThreePane = false;
        }
    } else {
        mThreePane = false;
        mIsATablet = false;
        if (findViewById(R.id.middle_container) != null) {
            findViewById(R.id.middle_container).setVisibility(View.GONE);
            findViewById(R.id.right_container).setVisibility(View.GONE);
        }
    }

    Intent intent = getIntent();

    if (savedInstanceState == null) {
        try {
            if (intent.getAction().equals(Intent.ACTION_VIEW)) { //apparently this can NPE on 4.3. because why not. if we catch it, launch the default frag
                // handles a click on a search suggestion; launches activity to show word
                Uri u = intent.getData();
                long id = Long.parseLong(u.getLastPathSegment());

                // add a fragment
                Bundle args = new Bundle();
                args.putBoolean("isSingle", true);
                args.putLong("id", id);
                CardViewFragment rlFrag = new CardViewFragment();
                rlFrag.setArguments(args);

                attachSingleFragment(rlFrag, "left_frag", false, false);
                showOnePane();
                hideKeyboard();
            } else if (intent.getAction().equals(Intent.ACTION_SEARCH)) {
                boolean consolidate = prefAdapter.getConsolidateSearch();
                String query = intent.getStringExtra(SearchManager.QUERY);
                SearchCriteria sc = new SearchCriteria();
                sc.Name = query;
                sc.Set_Logic = (consolidate ? CardDbAdapter.FIRSTPRINTING : CardDbAdapter.ALLPRINTINGS);

                // add a fragment
                Bundle args = new Bundle();
                args.putBoolean(SearchViewFragment.RANDOM, false);
                args.putSerializable(SearchViewFragment.CRITERIA, sc);
                if (mIsATablet) {
                    SearchViewFragment svFrag = new SearchViewFragment();
                    svFrag.setArguments(args);
                    attachSingleFragment(svFrag, "left_frag", false, false);
                } else {
                    ResultListFragment rlFrag = new ResultListFragment();
                    rlFrag.setArguments(args);
                    attachSingleFragment(rlFrag, "left_frag", false, false);
                }
                hideKeyboard();
            } else if (intent.getAction().equals(ACTION_FULL_SEARCH)) {
                attachSingleFragment(new SearchViewFragment(), "left_frag", false, false);
                showOnePane();
            } else if (intent.getAction().equals(ACTION_WIDGET_SEARCH)) {
                attachSingleFragment(new SearchWidgetFragment(), "left_frag", false, false);
                showOnePane();
            } else if (intent.getAction().equals(ACTION_ROUND_TIMER)) {
                attachSingleFragment(new RoundTimerFragment(), "left_frag", false, false);
                showOnePane();
            } else {
                launchDefaultFragment();
            }
        } catch (NullPointerException e) {
            launchDefaultFragment();
        }
    }
}

From source file:com.android.deskclock.AlarmClockFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
    // Inflate the layout for this fragment
    final View v = inflater.inflate(R.layout.alarm_clock, container, false);

    long expandedId = INVALID_ID;
    long[] repeatCheckedIds = null;
    long[] selectedAlarms = null;
    Bundle previousDayMap = null;/* w  ww .  java  2s. co  m*/
    if (savedState != null) {
        expandedId = savedState.getLong(KEY_EXPANDED_ID);
        repeatCheckedIds = savedState.getLongArray(KEY_REPEAT_CHECKED_IDS);
        mRingtoneTitleCache = savedState.getBundle(KEY_RINGTONE_TITLE_CACHE);
        mDeletedAlarm = savedState.getParcelable(KEY_DELETED_ALARM);
        mUndoShowing = savedState.getBoolean(KEY_UNDO_SHOWING);
        selectedAlarms = savedState.getLongArray(KEY_SELECTED_ALARMS);
        previousDayMap = savedState.getBundle(KEY_PREVIOUS_DAY_MAP);
        mSelectedAlarm = savedState.getParcelable(KEY_SELECTED_ALARM);
    }

    mExpandInterpolator = new DecelerateInterpolator(EXPAND_DECELERATION);
    mCollapseInterpolator = new DecelerateInterpolator(COLLAPSE_DECELERATION);

    if (USE_TRANSITION_FRAMEWORK) {
        mAddRemoveTransition = new AutoTransition();
        mAddRemoveTransition.setDuration(ANIMATION_DURATION);

        /// M: Scrap the views in ListView and request layout again, then alarm item will be
        /// attached correctly. This is to avoid the case when some items are not correctly
        ///  attached after animation end  @{
        mAddRemoveTransition.addListener(new Transition.TransitionListenerAdapter() {
            @Override
            public void onTransitionEnd(Transition transition) {
                mAlarmsList.clearScrapViewsIfNeeded();
            }
        });
        /// @}

        mRepeatTransition = new AutoTransition();
        mRepeatTransition.setDuration(ANIMATION_DURATION / 2);
        mRepeatTransition.setInterpolator(new AccelerateDecelerateInterpolator());

        mEmptyViewTransition = new TransitionSet().setOrdering(TransitionSet.ORDERING_SEQUENTIAL)
                .addTransition(new Fade(Fade.OUT)).addTransition(new Fade(Fade.IN))
                .setDuration(ANIMATION_DURATION);
    }

    boolean isLandscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
    View menuButton = v.findViewById(R.id.menu_button);
    if (menuButton != null) {
        if (isLandscape) {
            menuButton.setVisibility(View.GONE);
        } else {
            menuButton.setVisibility(View.VISIBLE);
            setupFakeOverflowMenuButton(menuButton);
        }
    }

    mEmptyView = v.findViewById(R.id.alarms_empty_view);

    mMainLayout = (FrameLayout) v.findViewById(R.id.main);
    mAlarmsList = (ListView) v.findViewById(R.id.alarms_list);

    mUndoBar = (ActionableToastBar) v.findViewById(R.id.undo_bar);
    mUndoFrame = v.findViewById(R.id.undo_frame);
    mUndoFrame.setOnTouchListener(this);

    mFooterView = v.findViewById(R.id.alarms_footer_view);
    mFooterView.setOnTouchListener(this);

    mAdapter = new AlarmItemAdapter(getActivity(), expandedId, repeatCheckedIds, selectedAlarms, previousDayMap,
            mAlarmsList);
    mAdapter.registerDataSetObserver(new DataSetObserver() {

        private int prevAdapterCount = -1;

        @Override
        public void onChanged() {

            final int count = mAdapter.getCount();
            if (mDeletedAlarm != null && prevAdapterCount > count) {
                showUndoBar();
            }

            if (USE_TRANSITION_FRAMEWORK && ((count == 0 && prevAdapterCount > 0) || /* should fade  in */
            (count > 0 && prevAdapterCount == 0) /* should fade out */)) {
                TransitionManager.beginDelayedTransition(mMainLayout, mEmptyViewTransition);
            }
            mEmptyView.setVisibility(count == 0 ? View.VISIBLE : View.GONE);

            // Cache this adapter's count for when the adapter changes.
            prevAdapterCount = count;
            super.onChanged();
        }
    });

    if (mRingtoneTitleCache == null) {
        mRingtoneTitleCache = new Bundle();
    }

    mAlarmsList.setAdapter(mAdapter);
    mAlarmsList.setVerticalScrollBarEnabled(true);
    mAlarmsList.setOnCreateContextMenuListener(this);

    if (mUndoShowing) {
        showUndoBar();
    }
    return v;
}

From source file:dev.ronlemire.validation.MainActivity.java

private void ReturnToValidationList() {
    ClearMessageBox();/* w ww.ja va 2s .c o  m*/
    PopFragmentBackStack();

    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE && isTablet()) {
        StartValidationListFragment();
        StartEmptyFragment();
    } else {
        ValidationListFragment validationListFragment = ValidationListFragment.newInstance("List");
        getSupportFragmentManager().beginTransaction()
                .replace(MainActivity.validationListView.getId(), validationListFragment).commit();
    }
}