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.tweetlanes.android.core.view.ComposeBaseFragment.java

protected 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 a  va2s. com*/
    }
}

From source file:com.example.janicduplessis.myapplication.CameraFragment.java

/**
 * Sets up member variables related to camera.
 *
 * @param width  The width of available size for camera preview
 * @param height The height of available size for camera preview
 *///from w ww .  j ava  2  s  . c  om
private void setUpCameraOutputs(int width, int height) {
    Activity activity = getActivity();
    CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);
    try {
        for (String cameraId : manager.getCameraIdList()) {
            CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);

            // We don't use a front facing camera in this sample.
            Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
            if (facing != null && facing == CameraCharacteristics.LENS_FACING_FRONT) {
                continue;
            }

            StreamConfigurationMap map = characteristics
                    .get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
            if (map == null) {
                continue;
            }

            // For still image captures, we use the largest available size.
            Size largest = Collections.max(Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)),
                    new CompareSizesByArea());

            Size smalest = Collections.min(Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)),
                    new CompareSizesByArea());

            //mImageReader = ImageReader.newInstance(largest.getWidth(), largest.getHeight(), ImageFormat.JPEG, /*maxImages*/2);
            mImageReader = ImageReader.newInstance(smalest.getWidth(), smalest.getHeight(), ImageFormat.JPEG,
                    2);
            mImageReader.setOnImageAvailableListener(mOnImageAvailableListener, mBackgroundHandler);

            // Danger, W.R.! Attempting to use too large a preview size could  exceed the camera
            // bus' bandwidth limitation, resulting in gorgeous previews but the storage of
            // garbage capture data.
            mPreviewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class), width, height, largest);

            // We fit the aspect ratio of TextureView to the size of preview we picked.
            int orientation = getResources().getConfiguration().orientation;
            if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
                mTextureView.setAspectRatio(mPreviewSize.getWidth(), mPreviewSize.getHeight());
            } else {
                mTextureView.setAspectRatio(mPreviewSize.getHeight(), mPreviewSize.getWidth());
            }

            mCameraId = cameraId;
            return;
        }
    } catch (CameraAccessException e) {
        e.printStackTrace();
    } catch (NullPointerException e) {
        // Currently an NPE is thrown when the Camera2API is used but not supported on the
        // device this code runs.
        ErrorDialog.newInstance(getString(R.string.camera_error)).show(getChildFragmentManager(),
                FRAGMENT_DIALOG);
    }
}

From source file:com.nttec.everychan.ui.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Logger.d(TAG, "main activity creating");
    settings = MainApplication.getInstance().settings.getStaticSettings();
    autohideRulesHash = MainApplication.getInstance().settings.getAutohideRulesJson().hashCode();
    rootViewWeight = MainApplication.getInstance().settings.getRootViewWeight();
    tabsPanelRight = MainApplication.getInstance().settings.isTabsPanelOnRight();
    openSpoilers = MainApplication.getInstance().settings.openSpoilers();
    highlightSubscriptions = MainApplication.getInstance().settings.highlightSubscriptions();
    swipeToHideThread = MainApplication.getInstance().settings.swipeToHideThread();
    isHorizontalOrientation = getResources()
            .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
    (theme = MainApplication.getInstance().settings.getTheme()).setTo(this);
    super.onCreate(savedInstanceState);
    if (MainApplication.getInstance().settings.showSidePanel()) {
        setContentView(tabsPanelRight ? R.layout.main_activity_tablet_right : R.layout.main_activity_tablet);
        LinearLayout.LayoutParams sidebarLayoutParams = (LinearLayout.LayoutParams) findViewById(R.id.sidebar)
                .getLayoutParams();/*from  w ww  .  j a  va 2  s  .  co  m*/
        Point displaySize = AppearanceUtils.getDisplaySize(getWindowManager().getDefaultDisplay());
        int rootWidth = (int) (displaySize.x * rootViewWeight);
        sidebarLayoutParams.width = displaySize.x - rootWidth;
        findViewById(R.id.sidebar).setLayoutParams(sidebarLayoutParams);
    } else {
        setContentView(R.layout.main_activity_drawer);
        updateTabPanelTabletWeight();
    }
    initDrawer();

    View[] sidebarButtons = new View[] { findViewById(R.id.sidebar_btn_newtab),
            findViewById(R.id.sidebar_btn_history), findViewById(R.id.sidebar_btn_favorites) };
    hiddenTabsSection = new HiddenTabsSection(sidebarButtons);

    DragSortListView list = (DragSortListView) findViewById(R.id.sidebar_tabs_list);
    TabsState state = MainApplication.getInstance().tabsState;
    tabsAdapter = initTabsListView(list, state);
    handleUriIntent(getIntent());
    notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    broadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (action == null) {
                Logger.e(TAG, "received broadcast with NULL action");
                return;
            }
            if (action.equals(PostingService.BROADCAST_ACTION_STATUS)) {
                int progress = intent.getIntExtra(PostingService.EXTRA_BROADCAST_PROGRESS_STATUS, -1);
                switch (progress) {
                case PostingService.BROADCAST_STATUS_SUCCESS:
                    UrlHandler.open(intent.getStringExtra(PostingService.EXTRA_TARGET_URL), MainActivity.this);
                    notificationManager.cancel(PostingService.POSTING_NOTIFICATION_ID);
                    break;
                case PostingService.BROADCAST_STATUS_ERROR:
                    Intent toPostForm = new Intent(MainActivity.this, PostFormActivity.class);
                    toPostForm.putExtra(PostingService.EXTRA_PAGE_HASH,
                            intent.getStringExtra(PostingService.EXTRA_PAGE_HASH));
                    toPostForm.putExtra(PostingService.EXTRA_SEND_POST_MODEL,
                            intent.getSerializableExtra(PostingService.EXTRA_SEND_POST_MODEL));
                    toPostForm.putExtra(PostingService.EXTRA_BOARD_MODEL,
                            intent.getSerializableExtra(PostingService.EXTRA_BOARD_MODEL));
                    toPostForm.putExtra(PostingService.EXTRA_RETURN_FROM_SERVICE, true);
                    toPostForm.putExtra(PostingService.EXTRA_RETURN_REASON,
                            intent.getIntExtra(PostingService.EXTRA_RETURN_REASON, 0));
                    String error = intent.getStringExtra(PostingService.EXTRA_RETURN_REASON_ERROR);
                    Serializable interactiveException = intent
                            .getSerializableExtra(PostingService.EXTRA_RETURN_REASON_INTERACTIVE_EXCEPTION);
                    if (error != null) {
                        toPostForm.putExtra(PostingService.EXTRA_RETURN_REASON_ERROR, error);
                    }
                    if (interactiveException != null) {
                        toPostForm.putExtra(PostingService.EXTRA_RETURN_REASON_INTERACTIVE_EXCEPTION,
                                interactiveException);
                    }
                    startActivity(toPostForm);
                    notificationManager.cancel(PostingService.POSTING_NOTIFICATION_ID);
                    break;
                }
            } else if (action.equals(TabsTrackerService.BROADCAST_ACTION_NOTIFY)) {
                tabsAdapter.notifyDataSetChanged(false);
                TabsTrackerService.clearUnread();
            }
        }
    };
    intentFilter = new IntentFilter();
    intentFilter.addAction(PostingService.BROADCAST_ACTION_STATUS);
    intentFilter.addAction(TabsTrackerService.BROADCAST_ACTION_NOTIFY);

    if (!TabsTrackerService.isRunning() && MainApplication.getInstance().settings.isAutoupdateEnabled())
        startService(new Intent(this, TabsTrackerService.class));

    if (MainApplication.getInstance().settings.isSFWRelease())
        NewsReader.checkNews(this);
}

From source file:de.sourcestream.movieDB.MainActivity.java

/**
 * First configure the Universal Image Downloader,
 * then we set the main layout to be activity_main.xml
 * and we add the slide menu items.// w  ww .j  a va  2 s . c  o  m
 *
 * @param savedInstanceState If non-null, this activity is being re-constructed from a previous saved state as given here.
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    mTitle = mDrawerTitle = getTitle();

    // load slide menu items
    navMenuTitles = getResources().getStringArray(R.array.nav_drawer_items);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.list_slidermenu);
    ViewGroup header = (ViewGroup) getLayoutInflater().inflate(R.layout.drawer_header, null, false);
    ImageView drawerBackButton = (ImageView) header.findViewById(R.id.drawerBackButton);
    drawerBackButton.setOnClickListener(onDrawerBackButton);
    mDrawerList.addHeaderView(header);
    mDrawerList.setOnItemClickListener(new SlideMenuClickListener());
    // setting the nav drawer list adapter
    mDrawerList.setAdapter(new ArrayAdapter<>(this, R.layout.drawer_list_item, R.id.title, navMenuTitles));

    toolbar = (Toolbar) findViewById(R.id.toolbar);
    if (toolbar != null) {
        setSupportActionBar(toolbar);
        toolbar.bringToFront();
    }

    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            toolbar, R.string.app_name, // nav drawer open - description for accessibility
            R.string.app_name // nav drawer close - description for accessibility
    ) {
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            // calling onPrepareOptionsMenu() to show search view
            invalidateOptionsMenu();
            syncState();
        }

        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            // calling onPrepareOptionsMenu() to hide search view
            invalidateOptionsMenu();
            syncState();
        }

        // updates the title, toolbar transparency and search view
        public void onDrawerSlide(View drawerView, float slideOffset) {
            super.onDrawerSlide(drawerView, slideOffset);
            if (slideOffset > .55 && !isDrawerOpen) {
                // opening drawer
                // mDrawerTitle is app title
                getSupportActionBar().setTitle(mDrawerTitle);
                invalidateOptionsMenu();
                isDrawerOpen = true;
            } else if (slideOffset < .45 && isDrawerOpen) {
                // closing drawer
                // mTitle is title of the current view, can be movies, tv shows or movie title
                getSupportActionBar().setTitle(mTitle);
                invalidateOptionsMenu();
                isDrawerOpen = false;
            }
        }

    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    // Get the action bar title to set padding
    TextView titleTextView = null;

    try {
        Field f = toolbar.getClass().getDeclaredField("mTitleTextView");
        f.setAccessible(true);
        titleTextView = (TextView) f.get(toolbar);
    } catch (NoSuchFieldException e) {

    } catch (IllegalAccessException e) {

    }
    if (titleTextView != null) {
        float scale = getResources().getDisplayMetrics().density;
        titleTextView.setPadding((int) scale * 15, 0, 0, 0);
    }

    phone = getResources().getBoolean(R.bool.portrait_only);

    searchDB = new SearchDB(getApplicationContext());

    if (savedInstanceState == null) {
        // Check orientation and lock to portrait if we are on phone
        if (phone) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }

        // on first time display view for first nav item
        displayView(1);

        // Use hockey module to check for updates
        checkForUpdates();

        // Universal Loader options and configuration.
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                // Bitmaps in RGB_565 consume 2 times less memory than in ARGB_8888.
                .bitmapConfig(Bitmap.Config.RGB_565).imageScaleType(ImageScaleType.EXACTLY).cacheInMemory(false)
                .showImageOnLoading(R.drawable.placeholder_default)
                .showImageForEmptyUri(R.drawable.placeholder_default)
                .showImageOnFail(R.drawable.placeholder_default).cacheOnDisk(true).build();
        Context context = this;
        File cacheDir = StorageUtils.getCacheDirectory(context);
        // Create global configuration and initialize ImageLoader with this config
        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this)
                .diskCache(new UnlimitedDiscCache(cacheDir)) // default
                .defaultDisplayImageOptions(options).build();
        ImageLoader.getInstance().init(config);

        // Check cache size
        long size = 0;
        File[] filesCache = cacheDir.listFiles();
        for (File file : filesCache) {
            size += file.length();
        }
        if (cacheDir.getUsableSpace() < MinFreeSpace || size > CacheSize) {
            ImageLoader.getInstance().getDiskCache().clear();
            searchDB.cleanSuggestionRecords();
        }

    } else {
        oldPos = savedInstanceState.getInt("oldPos");
        currentMovViewPagerPos = savedInstanceState.getInt("currentMovViewPagerPos");
        currentTVViewPagerPos = savedInstanceState.getInt("currentTVViewPagerPos");
        restoreMovieDetailsState = savedInstanceState.getBoolean("restoreMovieDetailsState");
        restoreMovieDetailsAdapterState = savedInstanceState.getBoolean("restoreMovieDetailsAdapterState");
        movieDetailsBundle = savedInstanceState.getParcelableArrayList("movieDetailsBundle");
        castDetailsBundle = savedInstanceState.getParcelableArrayList("castDetailsBundle");
        tvDetailsBundle = savedInstanceState.getParcelableArrayList("tvDetailsBundle");
        currOrientation = savedInstanceState.getInt("currOrientation");
        lastVisitedSimMovie = savedInstanceState.getInt("lastVisitedSimMovie");
        lastVisitedSimTV = savedInstanceState.getInt("lastVisitedSimTV");
        lastVisitedMovieInCredits = savedInstanceState.getInt("lastVisitedMovieInCredits");
        saveInMovieDetailsSimFragment = savedInstanceState.getBoolean("saveInMovieDetailsSimFragment");

        FragmentManager fm = getFragmentManager();
        // prevent the following bug: go to gallery preview -> swap orientation ->
        // go to movies list -> swap orientation -> action bar bugged
        // so if we are not on gallery preview we show toolbar
        if (fm.getBackStackEntryCount() == 0
                || !fm.getBackStackEntryAt(fm.getBackStackEntryCount() - 1).getName().equals("galleryList")) {
            new Handler().post(new Runnable() {
                @Override
                public void run() {
                    if (getSupportActionBar() != null && !getSupportActionBar().isShowing())
                        getSupportActionBar().show();
                }
            });
        }
    }

    // Get reference for the imageLoader
    imageLoader = ImageLoader.getInstance();

    // Options used for the backdrop image in movie and tv details and gallery
    optionsWithFade = new DisplayImageOptions.Builder()
            // Bitmaps in RGB_565 consume 2 times less memory than in ARGB_8888.
            .bitmapConfig(Bitmap.Config.RGB_565).displayer(new FadeInBitmapDisplayer(500))
            .imageScaleType(ImageScaleType.EXACTLY).cacheInMemory(false).showImageOnLoading(R.color.black)
            .showImageForEmptyUri(R.color.black).showImageOnFail(R.color.black).cacheOnDisk(true).build();
    optionsWithoutFade = new DisplayImageOptions.Builder()
            // Bitmaps in RGB_565 consume 2 times less memory than in ARGB_8888.
            .bitmapConfig(Bitmap.Config.RGB_565).imageScaleType(ImageScaleType.EXACTLY).cacheInMemory(false)
            .showImageOnLoading(R.color.black).showImageForEmptyUri(R.color.black)
            .showImageOnFail(R.color.black).cacheOnDisk(true).build();

    // Options used for the backdrop image in movie and tv details and gallery
    backdropOptionsWithFade = new DisplayImageOptions.Builder()
            // Bitmaps in RGB_565 consume 2 times less memory than in ARGB_8888.
            .bitmapConfig(Bitmap.Config.RGB_565).displayer(new FadeInBitmapDisplayer(500))
            .imageScaleType(ImageScaleType.EXACTLY).cacheInMemory(false)
            .showImageOnLoading(R.drawable.placeholder_backdrop)
            .showImageForEmptyUri(R.drawable.placeholder_backdrop)
            .showImageOnFail(R.drawable.placeholder_backdrop).cacheOnDisk(true).build();
    backdropOptionsWithoutFade = new DisplayImageOptions.Builder()
            // Bitmaps in RGB_565 consume 2 times less memory than in ARGB_8888.
            .bitmapConfig(Bitmap.Config.RGB_565).imageScaleType(ImageScaleType.EXACTLY).cacheInMemory(false)
            .showImageOnLoading(R.drawable.placeholder_backdrop)
            .showImageForEmptyUri(R.drawable.placeholder_backdrop)
            .showImageOnFail(R.drawable.placeholder_backdrop).cacheOnDisk(true).build();

    trailerListView = new TrailerList();
    galleryListView = new GalleryList();

    if (currOrientation != getResources().getConfiguration().orientation)
        orientationChanged = true;

    currOrientation = getResources().getConfiguration().orientation;

    iconConstantSpecialCase = 0;
    if (phone) {
        iconMarginConstant = 0;
        iconMarginLandscape = 0;
        DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
        int width = displayMetrics.widthPixels;
        int height = displayMetrics.heightPixels;
        if (width <= 480 && height <= 800)
            iconConstantSpecialCase = -70;

        // used in MovieDetails, CastDetails, TVDetails onMoreIconClick
        // to check whether the animation should be in up or down direction
        threeIcons = 128;
        threeIconsToolbar = 72;
        twoIcons = 183;
        twoIconsToolbar = 127;
        oneIcon = 238;
        oneIconToolbar = 182;
    } else {
        if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
            iconMarginConstant = 232;
            iconMarginLandscape = 300;

            threeIcons = 361;
            threeIconsToolbar = 295;
            twoIcons = 416;
            twoIconsToolbar = 351;
            oneIcon = 469;
            oneIconToolbar = 407;
        } else {
            iconMarginConstant = 82;
            iconMarginLandscape = 0;

            threeIcons = 209;
            threeIconsToolbar = 146;
            twoIcons = 264;
            twoIconsToolbar = 200;
            oneIcon = 319;
            oneIconToolbar = 256;
        }

    }

    dateFormat = android.text.format.DateFormat.getDateFormat(this);
}

From source file:com.example.SimpleTestClient.Activities.TestMainActivity.java

private ShowMode getShowMode() {
    if (this.getResources().getBoolean(R.bool.has_two_panes) == true) {
        return ShowMode.Landscape;
    }// w  w  w  .  java 2  s .c om
    if (this.getResources().getBoolean(R.bool.has_two_panes) == false) {
        return ShowMode.Portrait;
    }

    if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
        if (findViewById(R.id.activity_test_main_drawer_layout) != null) {
            return ShowMode.Landscape_mini;
        } else {
            return ShowMode.Landscape;
        }
    }
    if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
        return ShowMode.Portrait;
    }
    return ShowMode.Landscape;
}

From source file:augsburg.se.alltagsguide.overview.OverviewActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_columns:
        if (getResources() != null) {
            Configuration config = getResources().getConfiguration();
            if (config != null) {
                switch (config.orientation) {
                case android.content.res.Configuration.ORIENTATION_LANDSCAPE:
                    mPrefUtilities.setMultipleColumnsLandscape(!mPrefUtilities.useMultipleColumnsLandscape());
                    break;
                case android.content.res.Configuration.ORIENTATION_PORTRAIT:
                    mPrefUtilities.setMultipleColumnsPortrait(!mPrefUtilities.useMultipleColumnsPortrait());
                    break;
                }/*from ww w  . jav  a  2s  . c o m*/
            }
        }

        updateMenu();
        break;
    case android.R.id.home:
        goBackPageOverview();
        break;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.cypress.cysmart.RDKEmulatorView.RemoteControlEmulatorFragment.java

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
        LayoutInflater inflater = (LayoutInflater) getActivity()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mParentView = inflater.inflate(R.layout.rgb_view_landscape, null);
        ViewGroup rootViewG = (ViewGroup) getView();
        // Remove all the existing views from the root view.
        try {//  ww  w. j ava  2 s  .  c  o  m
            assert rootViewG != null;
            rootViewG.removeAllViews();
            rootViewG.addView(mParentView);
        } catch (Exception e) {
            e.printStackTrace();
        }

    } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
        LayoutInflater inflater = (LayoutInflater) getActivity()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mParentView = inflater.inflate(R.layout.rgb_view_portrait, null);
        ViewGroup rootViewG = (ViewGroup) getView();
        // Remove all the existing views from the root view.
        try {
            assert rootViewG != null;
            rootViewG.removeAllViews();
            rootViewG.addView(mParentView);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

From source file:com.android.dialer.DialtactsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log.e(TAG, " --- onCreate(Bundle savedInstanceState) ---  start ");
    Trace.beginSection(TAG + " onCreate");
    View retView = null;//from www  .  j  a v a  2  s.  c  om
    super.onCreateView(inflater, container, savedInstanceState);

    //??
    iControlDeleteBtn = (IControlDeleteBtn) getActivity();

    //mFirstLaunch = true;

    final Resources resources = getResources();
    int temp = resources.getDimensionPixelSize(R.dimen.floating_action_button_width);
    //?actionbar
    mActionBarHeight = resources.getDimensionPixelSize(R.dimen.action_bar_height_large);

    Trace.beginSection(TAG + " setContentView");
    //setContentView(R.layout.dialtacts_activity);
    retView = inflater.inflate(R.layout.dialtacts_activity, container, false);
    Trace.endSection();

    Trace.beginSection(TAG + " setup Views");
    final ActionBar actionBar = getActivity().getActionBar();
    //actionbar?
    //actionBar.setCustomView(R.layout.dialtacts_actionbar);
    //actionBar.setDisplayShowCustomEnabled(true);
    TextView actionbarNameTxt = (TextView) actionBar.getCustomView().findViewById(R.id.actionbar_name);
    actionbarNameTxt.setOnClickListener(this);
    ImageView actionbarMenu = (ImageView) actionBar.getCustomView().findViewById(R.id.actionbar_menu);
    actionbarMenu.setOnClickListener(this);
    TextView editerToCalldetail = (TextView) actionBar.getCustomView()
            .findViewById(R.id.actionbar_call_dialtacts_action_editer);
    editerToCalldetail.setOnClickListener(this);
    TextView cancelTxt = (TextView) actionBar.getCustomView()
            .findViewById(R.id.actionbar_call_dialtacts_action_cancel);
    cancelTxt.setOnClickListener(this);
    actionbarNameTxt.setText(getString(R.string.all_calls));
    mSearchView = (EditText) actionBar.getCustomView().findViewById(R.id.edittext);
    mSearchView.setVisibility(View.GONE);
    mDialtactsActionBarController = new DialtactsActionBarController(actionbarMenu, editerToCalldetail,
            cancelTxt, actionbarNameTxt, this);
    //        actionBar.setBackgroundDrawable(null);

    SearchEditTextLayout searchEditTextLayout = (SearchEditTextLayout) actionBar.getCustomView()
            .findViewById(R.id.search_view_container);
    //        searchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener);

    //        mActionBarController = new DialtactsActionBarController(this, searchEditTextLayout);

    //        mSearchView = (EditText) searchEditTextLayout.findViewById(R.id.search_view);
    mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
    //        mVoiceSearchButton = searchEditTextLayout.findViewById(R.id.voice_search_button);
    //        mSearchView.setOnClickListener(mSearchViewOnClickListener);
    //        searchEditTextLayout.findViewById(R.id.search_box_start_search)
    //                .setOnClickListener(mSearchViewOnClickListener);
    //        searchEditTextLayout.setOnClickListener(mSearchViewOnClickListener);
    //        searchEditTextLayout.setCallback(new SearchEditTextLayout.Callback() {
    //            @Override
    //            public void onBackButtonClicked() {
    //                onBackPressed();
    //            }
    //
    //            @Override
    //            public void onSearchViewClicked() {
    //                // Hide FAB, as the keyboard is shown.
    ////                mFloatingActionButtonController.scaleOut();
    //            }
    //        });
    mIsLandscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;

    //        ImageButton optionsMenuButton =
    //                (ImageButton) searchEditTextLayout.findViewById(R.id.dialtacts_options_menu_button);
    //        optionsMenuButton.setOnClickListener(this);
    //        mOverflowMenu = buildOptionsMenu(searchEditTextLayout);
    //        optionsMenuButton.setOnTouchListener(mOverflowMenu.getDragToOpenListener());

    // Add the favorites fragment but only if savedInstanceState is null. Otherwise the
    // fragment manager is responsible for recreating it.
    //???
    if (savedInstanceState == null) {
        getChildFragmentManager().beginTransaction()
                .add(R.id.dialtacts_container, new DialpadFragment(getActivity()), TAG_DIALPAD_FRAGMENT)
                //                   .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT)
                .commit();
    } else {
        mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY);
        mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI);
        mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI);
        mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH);
        mShowDialpadOnResume = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN);
        //            mActionBarController.restoreInstanceState(savedInstanceState);
    }

    final boolean isLayoutRtl = DialerUtils.isRtl();
    //??????
    if (mIsLandscape) {
        //??
        mSlideIn = AnimationUtils.loadAnimation(getActivity(),
                isLayoutRtl ? R.anim.dialpad_slide_in_left : R.anim.dialpad_slide_in_right);
        mSlideOut = AnimationUtils.loadAnimation(getActivity(),
                isLayoutRtl ? R.anim.dialpad_slide_out_left : R.anim.dialpad_slide_out_right);
    } else {
        mSlideIn = AnimationUtils.loadAnimation(getActivity(), R.anim.dialpad_slide_in_bottom);
        mSlideOut = AnimationUtils.loadAnimation(getActivity(), R.anim.dialpad_slide_out_bottom);
    }

    //        mSlideIn.setInterpolator(AnimUtils.EASE_IN);
    mSlideOut.setInterpolator(AnimUtils.EASE_OUT);

    mSlideIn.setAnimationListener(mSlideInListener);
    mSlideOut.setAnimationListener(mSlideOutListener);

    Trace.endSection();

    Trace.beginSection(TAG + " initialize smart dialing");
    mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(getActivity());
    SmartDialPrefix.initializeNanpSettings(getActivity());
    Trace.endSection();
    Trace.endSection();
    initFlushHandler();

    Log.e(TAG, " onCreate()  dialerFragment  " + mIsDialpadShown);
    return retView;
}

From source file:com.oddsix.nutripro.fragments.Camera2Fragment.java

/**
 * Sets up member variables related to camera.
 *
 * @param width  The width of available size for camera preview
 * @param height The height of available size for camera preview
 *///from  w ww.  ja v  a 2s .co m
private void setUpCameraOutputs(int width, int height) {
    Activity activity = getActivity();
    CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);
    try {
        for (String cameraId : manager.getCameraIdList()) {
            CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);

            // We don't use a front facing camera in this sample.
            Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
            if (facing != null && facing == CameraCharacteristics.LENS_FACING_FRONT) {
                continue;
            }

            StreamConfigurationMap map = characteristics
                    .get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
            if (map == null) {
                continue;
            }

            // For still image captures, we use the largest available size.
            Size largest = Collections.max(Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)),
                    new CompareSizesByArea());
            mImageReader = ImageReader.newInstance(largest.getWidth(), largest.getHeight(), ImageFormat.JPEG,
                    /*maxImages*/2);
            mImageReader.setOnImageAvailableListener(mOnImageAvailableListener, mBackgroundHandler);

            // Find out if we need to swap dimension to get the preview size relative to sensor
            // coordinate.
            int displayRotation = activity.getWindowManager().getDefaultDisplay().getRotation();
            //noinspection ConstantConditions
            mSensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
            boolean swappedDimensions = false;
            switch (displayRotation) {
            case Surface.ROTATION_0:
            case Surface.ROTATION_180:
                if (mSensorOrientation == 90 || mSensorOrientation == 270) {
                    swappedDimensions = true;
                }
                break;
            case Surface.ROTATION_90:
            case Surface.ROTATION_270:
                if (mSensorOrientation == 0 || mSensorOrientation == 180) {
                    swappedDimensions = true;
                }
                break;
            default:
                Log.e(TAG, "Display rotation is invalid: " + displayRotation);
            }

            Point displaySize = new Point();
            activity.getWindowManager().getDefaultDisplay().getSize(displaySize);
            int rotatedPreviewWidth = width;
            int rotatedPreviewHeight = height;
            int maxPreviewWidth = displaySize.x;
            int maxPreviewHeight = displaySize.y;

            if (swappedDimensions) {
                rotatedPreviewWidth = height;
                rotatedPreviewHeight = width;
                maxPreviewWidth = displaySize.y;
                maxPreviewHeight = displaySize.x;
            }

            if (maxPreviewWidth > MAX_PREVIEW_WIDTH) {
                maxPreviewWidth = MAX_PREVIEW_WIDTH;
            }

            if (maxPreviewHeight > MAX_PREVIEW_HEIGHT) {
                maxPreviewHeight = MAX_PREVIEW_HEIGHT;
            }

            // Danger, W.R.! Attempting to use too large a preview size could  exceed the camera
            // bus' bandwidth limitation, resulting in gorgeous previews but the storage of
            // garbage capture data.
            mPreviewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class), rotatedPreviewWidth,
                    rotatedPreviewHeight, maxPreviewWidth, maxPreviewHeight, largest);

            // We fit the aspect ratio of TextureView to the size of preview we picked.
            int orientation = getResources().getConfiguration().orientation;
            if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
                mTextureView.setAspectRatio(mPreviewSize.getWidth(), mPreviewSize.getHeight());
            } else {
                mTextureView.setAspectRatio(mPreviewSize.getHeight(), mPreviewSize.getWidth());
            }

            // Check if the flash is supported.
            Boolean available = characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
            mFlashSupported = available == null ? false : available;

            mCameraId = cameraId;
            return;
        }
    } catch (CameraAccessException e) {
        e.printStackTrace();
    } catch (NullPointerException e) {
        // Currently an NPE is thrown when the Camera2API is used but not supported on the
        // device this code runs.
        //            ErrorDialog.newInstance("asdasdasdasdada")
        //                    .show(getChildFragmentManager(), FRAGMENT_DIALOG);
    }
}

From source file:com.team254.cheezdroid.SelfieModeFragment.java

/**
 * Sets up member variables related to camera.
 *
 * @param width  The width of available size for camera preview
 * @param height The height of available size for camera preview
 *//*  ww w  .ja v a 2 s .c om*/
private void setUpCameraOutputs(int width, int height) {
    Activity activity = getActivity();
    CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);
    try {
        for (String cameraId : manager.getCameraIdList()) {
            Log.i("CameraId", cameraId);
            CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);

            // We don't use a front facing camera in this sample.
            Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
            if (facing != null && facing == CameraCharacteristics.LENS_FACING_BACK) {
                Log.w(TAG, "Skipped for facing " + cameraId);
                continue;
            }

            StreamConfigurationMap map = characteristics
                    .get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
            if (map == null) {
                Log.w(TAG, "Skipped for null map " + cameraId);
                continue;
            }

            // For still image captures, we use the largest available size.
            Size[] imgSizes = map.getOutputSizes(ImageFormat.YUV_420_888);
            Size selected = imgSizes[imgSizes.length - 1];
            for (Size s : imgSizes) {
                if (s.getWidth() <= 352) {
                    selected = s;
                    break;
                }
            }
            mImageReader = ImageReader.newInstance(selected.getWidth(), selected.getHeight(),
                    ImageFormat.YUV_420_888, /*maxImages*/3);
            mImageReader.setOnImageAvailableListener(mOnImageAvailableListener, mBackgroundHandler);

            // Find out if we need to swap dimension to get the preview size relative to sensor
            // coordinate.
            int displayRotation = activity.getWindowManager().getDefaultDisplay().getRotation();
            int sensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
            boolean swappedDimensions = false;
            switch (displayRotation) {
            case Surface.ROTATION_0:
            case Surface.ROTATION_180:
                if (sensorOrientation == 90 || sensorOrientation == 270) {
                    swappedDimensions = true;
                }
                break;
            case Surface.ROTATION_90:
            case Surface.ROTATION_270:
                if (sensorOrientation == 0 || sensorOrientation == 180) {
                    swappedDimensions = true;
                }
                break;
            default:
                Log.e(TAG, "Display rotation is invalid: " + displayRotation);
            }

            Point displaySize = new Point();
            activity.getWindowManager().getDefaultDisplay().getSize(displaySize);
            int rotatedPreviewWidth = width;
            int rotatedPreviewHeight = height;
            int maxPreviewWidth = displaySize.x;
            int maxPreviewHeight = displaySize.y;

            if (swappedDimensions) {
                rotatedPreviewWidth = height;
                rotatedPreviewHeight = width;
                maxPreviewWidth = displaySize.y;
                maxPreviewHeight = displaySize.x;
            }

            if (maxPreviewWidth > MAX_PREVIEW_WIDTH) {
                maxPreviewWidth = MAX_PREVIEW_WIDTH;
            }

            if (maxPreviewHeight > MAX_PREVIEW_HEIGHT) {
                maxPreviewHeight = MAX_PREVIEW_HEIGHT;
            }

            // Danger, W.R.! Attempting to use too large a preview size could  exceed the camera
            // bus' bandwidth limitation, resulting in gorgeous previews but the storage of
            // garbage capture data.
            mPreviewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class), rotatedPreviewWidth,
                    rotatedPreviewHeight, maxPreviewWidth, maxPreviewHeight, selected);

            Log.i(TAG, "Size : " + mPreviewSize);

            // We fit the aspect ratio of TextureView to the size of preview we picked.
            int orientation = getResources().getConfiguration().orientation;
            if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
                mTextureView.setAspectRatio(mPreviewSize.getWidth(), mPreviewSize.getHeight());
            } else {
                mTextureView.setAspectRatio(mPreviewSize.getHeight(), mPreviewSize.getWidth());
            }

            // Check if the flash is supported.
            Boolean available = characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
            mFlashSupported = available == null ? false : available;

            mCameraId = cameraId;
            return;
        }
    } catch (CameraAccessException e) {
        e.printStackTrace();
    } catch (NullPointerException e) {
        e.printStackTrace();
        // Currently an NPE is thrown when the Camera2API is used but not supported on the
        // device this code runs.
        ErrorDialog.newInstance("Camera error").show(getChildFragmentManager(), FRAGMENT_DIALOG);
    }
}