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:de.gebatzens.sia.fragment.RemoteDataFragment.java

/**
 *
 * @return horizontal screen orientation
 *///from  w  w w  . ja v  a  2 s  .  c  o m
public boolean createRootLayout(LinearLayout l) {
    l.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    l.setOrientation(LinearLayout.VERTICAL);
    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
        l.setPadding(toPixels(55), toPixels(4), toPixels(55), toPixels(4));
        return true;
    } else if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
        l.setPadding(toPixels(4), toPixels(4), toPixels(4), toPixels(4));
    }
    return false;
}

From source file:com.anjalimacwan.fragment.NoteViewFragment.java

@SuppressLint("SetJavaScriptEnabled")
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override/*from   w ww  .  j a v a  2 s.  c o  m*/
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    // Set values
    setRetainInstance(true);
    setHasOptionsMenu(true);

    // Get filename of saved note
    filename = getArguments().getString("filename");

    // Change window title
    String title;

    try {
        title = listener.loadNoteTitle(filename);
    } catch (IOException e) {
        title = getResources().getString(R.string.view_note);
    }

    getActivity().setTitle(title);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription(title, null,
                ContextCompat.getColor(getActivity(), R.color.primary));
        getActivity().setTaskDescription(taskDescription);
    }

    // Show the Up button in the action bar.
    ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // Animate elevation change
    if (getActivity().findViewById(R.id.layoutMain).getTag().equals("main-layout-large")
            && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        LinearLayout noteViewEdit = (LinearLayout) getActivity().findViewById(R.id.noteViewEdit);
        LinearLayout noteList = (LinearLayout) getActivity().findViewById(R.id.noteList);

        noteList.animate().z(0f);
        if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
            noteViewEdit.animate()
                    .z(getResources().getDimensionPixelSize(R.dimen.note_view_edit_elevation_land));
        else
            noteViewEdit.animate().z(getResources().getDimensionPixelSize(R.dimen.note_view_edit_elevation));
    }

    // Set up content view
    TextView noteContents = (TextView) getActivity().findViewById(R.id.textView);
    markdownView = (MarkdownView) getActivity().findViewById(R.id.markdownView);

    // Apply theme
    SharedPreferences pref = getActivity().getSharedPreferences(getActivity().getPackageName() + "_preferences",
            Context.MODE_PRIVATE);
    ScrollView scrollView = (ScrollView) getActivity().findViewById(R.id.scrollView);
    String theme = pref.getString("theme", "light-sans");
    int textSize = -1;
    int textColor = -1;

    String fontFamily = null;

    if (theme.contains("light")) {
        if (noteContents != null) {
            noteContents.setTextColor(ContextCompat.getColor(getActivity(), R.color.text_color_primary));
            noteContents.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background));
        }

        if (markdownView != null) {
            markdownView.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background));
            textColor = ContextCompat.getColor(getActivity(), R.color.text_color_primary);
        }

        scrollView.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background));
    }

    if (theme.contains("dark")) {
        if (noteContents != null) {
            noteContents.setTextColor(ContextCompat.getColor(getActivity(), R.color.text_color_primary_dark));
            noteContents
                    .setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background_dark));
        }

        if (markdownView != null) {
            markdownView
                    .setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background_dark));
            textColor = ContextCompat.getColor(getActivity(), R.color.text_color_primary_dark);
        }

        scrollView.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background_dark));
    }

    if (theme.contains("sans")) {
        if (noteContents != null)
            noteContents.setTypeface(Typeface.SANS_SERIF);

        if (markdownView != null)
            fontFamily = "sans-serif";
    }

    if (theme.contains("serif")) {
        if (noteContents != null)
            noteContents.setTypeface(Typeface.SERIF);

        if (markdownView != null)
            fontFamily = "serif";
    }

    if (theme.contains("monospace")) {
        if (noteContents != null)
            noteContents.setTypeface(Typeface.MONOSPACE);

        if (markdownView != null)
            fontFamily = "monospace";
    }

    switch (pref.getString("font_size", "normal")) {
    case "smallest":
        textSize = 12;
        break;
    case "small":
        textSize = 14;
        break;
    case "normal":
        textSize = 16;
        break;
    case "large":
        textSize = 18;
        break;
    case "largest":
        textSize = 20;
        break;
    }

    if (noteContents != null)
        noteContents.setTextSize(textSize);

    if (markdownView != null) {
        String topBottom = " " + Float.toString(getResources().getDimension(R.dimen.padding_top_bottom)
                / getResources().getDisplayMetrics().density) + "px";
        String leftRight = " " + Float.toString(getResources().getDimension(R.dimen.padding_left_right)
                / getResources().getDisplayMetrics().density) + "px";
        String fontSize = " " + Integer.toString(textSize) + "px";
        String fontColor = " #" + StringUtils.remove(Integer.toHexString(textColor), "ff");

        final String css = "body { " + "margin:" + topBottom + topBottom + leftRight + leftRight + "; "
                + "font-family:" + fontFamily + "; " + "font-size:" + fontSize + "; " + "color:" + fontColor
                + "; " + "}";

        final String js = "var styleNode = document.createElement('style');\n"
                + "styleNode.type = \"text/css\";\n" + "var styleText = document.createTextNode('" + css
                + "');\n" + "styleNode.appendChild(styleText);\n"
                + "document.getElementsByTagName('head')[0].appendChild(styleNode);\n";

        markdownView.getSettings().setJavaScriptEnabled(true);
        markdownView.getSettings().setLoadsImagesAutomatically(false);
        markdownView.setWebViewClient(new WebViewClient() {
            @TargetApi(Build.VERSION_CODES.N)
            @Override
            public void onLoadResource(WebView view, String url) {
                view.stopLoading();
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));

                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
                    try {
                        startActivity(intent);
                    } catch (ActivityNotFoundException | FileUriExposedException e) {
                        /* Gracefully fail */ }
                else
                    try {
                        startActivity(intent);
                    } catch (ActivityNotFoundException e) {
                        /* Gracefully fail */ }
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
                    view.evaluateJavascript(js, null);
                else
                    view.loadUrl("javascript:" + js);
            }
        });
    }

    // Load note contents
    try {
        contentsOnLoad = listener.loadNote(filename);
    } catch (IOException e) {
        showToast(R.string.error_loading_note);

        // Add NoteListFragment or WelcomeFragment
        Fragment fragment;
        if (getActivity().findViewById(R.id.layoutMain).getTag().equals("main-layout-normal"))
            fragment = new NoteListFragment();
        else
            fragment = new WelcomeFragment();

        getFragmentManager().beginTransaction().replace(R.id.noteViewEdit, fragment, "NoteListFragment")
                .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN).commit();
    }

    // Set TextView contents
    if (noteContents != null)
        noteContents.setText(contentsOnLoad);

    if (markdownView != null)
        markdownView.loadMarkdown(contentsOnLoad);

    // Show a toast message if this is the user's first time viewing a note
    final SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
    firstLoad = sharedPref.getInt("first-load", 0);
    if (firstLoad == 0) {
        // Show dialog with info
        DialogFragment firstLoad = new FirstViewDialogFragment();
        firstLoad.show(getFragmentManager(), "firstloadfragment");

        // Set first-load preference to 1; we don't need to show the dialog anymore
        SharedPreferences.Editor editor = sharedPref.edit();
        editor.putInt("first-load", 1);
        editor.apply();
    }

    // Detect single and double-taps using GestureDetector
    final GestureDetector detector = new GestureDetector(getActivity(),
            new GestureDetector.OnGestureListener() {
                @Override
                public boolean onSingleTapUp(MotionEvent e) {
                    return false;
                }

                @Override
                public void onShowPress(MotionEvent e) {
                }

                @Override
                public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
                    return false;
                }

                @Override
                public void onLongPress(MotionEvent e) {
                }

                @Override
                public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                    return false;
                }

                @Override
                public boolean onDown(MotionEvent e) {
                    return false;
                }
            });

    detector.setOnDoubleTapListener(new GestureDetector.OnDoubleTapListener() {
        @Override
        public boolean onDoubleTap(MotionEvent e) {
            if (sharedPref.getBoolean("show_double_tap_message", true)) {
                SharedPreferences.Editor editor = sharedPref.edit();
                editor.putBoolean("show_double_tap_message", false);
                editor.apply();
            }

            Bundle bundle = new Bundle();
            bundle.putString("filename", filename);

            Fragment fragment = new NoteEditFragment();
            fragment.setArguments(bundle);

            getFragmentManager().beginTransaction().replace(R.id.noteViewEdit, fragment, "NoteEditFragment")
                    .commit();

            return false;
        }

        @Override
        public boolean onDoubleTapEvent(MotionEvent e) {
            return false;
        }

        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            if (sharedPref.getBoolean("show_double_tap_message", true) && showMessage) {
                showToastLong(R.string.double_tap);
                showMessage = false;
            }

            return false;
        }

    });

    if (noteContents != null)
        noteContents.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                detector.onTouchEvent(event);
                return false;
            }
        });

    if (markdownView != null)
        markdownView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                detector.onTouchEvent(event);
                return false;
            }
        });
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(R.style.Theme_Sherlock_Light);
    requestWindowFeature(Window.FEATURE_PROGRESS);
    super.onCreate(savedInstanceState);

    // Initialize WebView
    mWebView = new DpWebView(this);
    mWebView.setId(mWebView.hashCode());
    mWebView.setOnCreateContextMenuListener(this);

    // Initialize Ad.
    mAdManager = new DpAdManager();
    mAdManager.onCreate(this);

    mLayout = new RelativeLayout(this);
    mAdView = new DpAdViewCore(this);
    mAdView.setId(mAdView.hashCode());//  ww  w . ja v  a  2s. c  o  m

    RelativeLayout.LayoutParams layoutParams1 = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.MATCH_PARENT);
    layoutParams1.addRule(RelativeLayout.ABOVE, mAdView.getId());
    mLayout.addView(mWebView, layoutParams1);

    RelativeLayout.LayoutParams layoutParams2 = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    layoutParams2.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    mLayout.addView(mAdView, layoutParams2);
    mAdManager.bindCoreView(mAdView);

    setContentView(mLayout);

    // Initialize pull to refresh
    mPullToRefreshAttacher = PullToRefreshAttacher.get(this);
    mPullToRefreshAttacher.addRefreshableView(mWebView, this);

    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
        mLayout.findViewById(mAdView.getId()).setVisibility(View.GONE);
    }
    this.overridePendingTransition(R.anim.start_enter, R.anim.start_exit);
    this.mActivity = this;

    Bundle bundle = getIntent().getExtras();
    if (bundle != null) {
        try {
            index = bundle.getInt("index", 0);
            Document doc = (Document) DpApp.getDocumentList().get(this.index);
            getSupportActionBar().setTitle(doc.getUserName());
            getSupportActionBar().setSubtitle(doc.getTitle());
            mUrl = Config.getAbsoluteUrl("/bbs" + doc.getUrl());
        } catch (Exception e) {
        }
    }
    Uri uri = getIntent().getData();
    if (uri != null) {
        this.mUrl = uri.toString();
        if (getIntent().getExtras().getString("targetKey") != null) {
            mTargetKey = getIntent().getExtras().getString("targetKey");
        }
    }
    if (StringUtil.isBlank(this.mUrl)) {
        finish();
    }
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayUseLogoEnabled(true);

    // Initialize EventBus
    EventBusProvider.getInstance().register(this, String.class, new Class[] { Refresh.class });

    // Request Document View
    StringRequest req = new StringRequest(0, this.mUrl, createReqSuccessListener(), createReqErrorListener());
    req.setTag(this.TAG);
    DpApp.getRequestQueue().add(req);

    // Initialize Google Analytics
    EasyTracker.getInstance().setContext(this.mActivity);
    EasyTracker.getTracker().sendView("DocView");
    LogUtil.LOGD("Tracker", "DocView");
}

From source file:com.afayear.android.client.activity.DualPaneActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
    super.onCreate(savedInstanceState);
    final Resources res = getResources();
    final int orientation = res.getConfiguration().orientation;
    final int layout;
    final boolean is_large_screen = res.getBoolean(R.bool.is_large_screen);
    mDualPaneInPortrait = mPreferences.getBoolean(PREFERENCE_KEY_DUAL_PANE_IN_PORTRAIT, is_large_screen);
    mDualPaneInLandscape = mPreferences.getBoolean(PREFERENCE_KEY_DUAL_PANE_IN_LANDSCAPE, is_large_screen);
    switch (orientation) {
    case Configuration.ORIENTATION_LANDSCAPE:
        layout = mDualPaneInLandscape || shouldForceEnableDualPaneMode() ? getDualPaneLayoutRes()
                : getNormalLayoutRes();//from  ww  w.  j a  v a 2  s . co  m
        break;
    case Configuration.ORIENTATION_PORTRAIT:
        layout = mDualPaneInPortrait || shouldForceEnableDualPaneMode() ? getDualPaneLayoutRes()
                : getNormalLayoutRes();
        break;
    default:
        layout = getNormalLayoutRes();
        break;
    }
    setContentView(layout);
    if (mSlidingPane != null) {
        mSlidingPane.setRightPaneBackground(getPaneBackground());
    }
    final FragmentManager fm = getSupportFragmentManager();
    fm.addOnBackStackChangedListener(this);
    if (savedInstanceState != null) {
        final Fragment left_pane_fragment = fm.findFragmentById(PANE_LEFT);
        final View main_view = findViewById(R.id.main);
        final boolean left_pane_used = left_pane_fragment != null && left_pane_fragment.isAdded();
        if (main_view != null) {
            final int visibility = left_pane_used ? View.GONE : View.VISIBLE;
            main_view.setVisibility(visibility);
        }
    }
}

From source file:com.ameerhamza6733.xmlpullparser.RecyclerViewFragment.java

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

    try {//from w  w w .  jav  a2s.co  m

        // Checks the orientation of the screen
        if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
            mCurrentLayoutManagerType = LayoutManagerType.GRID_LAYOUT_MANAGER;

        } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
            mCurrentLayoutManagerType = LayoutManagerType.LINEAR_LAYOUT_MANAGER;

        }
        setRecyclerViewLayoutManager(mCurrentLayoutManagerType);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.farmerbb.notepad.fragment.NoteViewFragment.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override//from w w w . j  a v  a 2  s .  c o m
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    // Set values
    setRetainInstance(true);
    setHasOptionsMenu(true);

    // Get filename of saved note
    filename = getArguments().getString("filename");

    // Change window title
    String title;

    try {
        title = listener.loadNoteTitle(filename);
    } catch (IOException e) {
        title = getResources().getString(R.string.view_note);
    }

    getActivity().setTitle(title);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Bitmap bitmap = ((BitmapDrawable) ContextCompat.getDrawable(getActivity(), R.drawable.ic_recents_logo))
                .getBitmap();

        ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription(title, bitmap,
                ContextCompat.getColor(getActivity(), R.color.primary));
        getActivity().setTaskDescription(taskDescription);
    }

    // Show the Up button in the action bar.
    ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // Animate elevation change
    if (getActivity().findViewById(R.id.layoutMain).getTag().equals("main-layout-large")
            && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        LinearLayout noteViewEdit = getActivity().findViewById(R.id.noteViewEdit);
        LinearLayout noteList = getActivity().findViewById(R.id.noteList);

        noteList.animate().z(0f);
        if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
            noteViewEdit.animate()
                    .z(getResources().getDimensionPixelSize(R.dimen.note_view_edit_elevation_land));
        else
            noteViewEdit.animate().z(getResources().getDimensionPixelSize(R.dimen.note_view_edit_elevation));
    }

    // Set up content view
    TextView noteContents = getActivity().findViewById(R.id.textView);
    markdownView = getActivity().findViewById(R.id.markdownView);

    // Apply theme
    SharedPreferences pref = getActivity().getSharedPreferences(getActivity().getPackageName() + "_preferences",
            Context.MODE_PRIVATE);
    ScrollView scrollView = getActivity().findViewById(R.id.scrollView);
    String theme = pref.getString("theme", "light-sans");
    int textSize = -1;
    int textColor = -1;

    String fontFamily = null;

    if (theme.contains("light")) {
        if (noteContents != null) {
            noteContents.setTextColor(ContextCompat.getColor(getActivity(), R.color.text_color_primary));
            noteContents.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background));
        }

        if (markdownView != null) {
            markdownView.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background));
            textColor = ContextCompat.getColor(getActivity(), R.color.text_color_primary);
        }

        scrollView.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background));
    }

    if (theme.contains("dark")) {
        if (noteContents != null) {
            noteContents.setTextColor(ContextCompat.getColor(getActivity(), R.color.text_color_primary_dark));
            noteContents
                    .setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background_dark));
        }

        if (markdownView != null) {
            markdownView
                    .setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background_dark));
            textColor = ContextCompat.getColor(getActivity(), R.color.text_color_primary_dark);
        }

        scrollView.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background_dark));
    }

    if (theme.contains("sans")) {
        if (noteContents != null)
            noteContents.setTypeface(Typeface.SANS_SERIF);

        if (markdownView != null)
            fontFamily = "sans-serif";
    }

    if (theme.contains("serif")) {
        if (noteContents != null)
            noteContents.setTypeface(Typeface.SERIF);

        if (markdownView != null)
            fontFamily = "serif";
    }

    if (theme.contains("monospace")) {
        if (noteContents != null)
            noteContents.setTypeface(Typeface.MONOSPACE);

        if (markdownView != null)
            fontFamily = "monospace";
    }

    switch (pref.getString("font_size", "normal")) {
    case "smallest":
        textSize = 12;
        break;
    case "small":
        textSize = 14;
        break;
    case "normal":
        textSize = 16;
        break;
    case "large":
        textSize = 18;
        break;
    case "largest":
        textSize = 20;
        break;
    }

    if (noteContents != null)
        noteContents.setTextSize(textSize);

    String css = "";
    if (markdownView != null) {
        String topBottom = " " + Float.toString(getResources().getDimension(R.dimen.padding_top_bottom)
                / getResources().getDisplayMetrics().density) + "px";
        String leftRight = " " + Float.toString(getResources().getDimension(R.dimen.padding_left_right)
                / getResources().getDisplayMetrics().density) + "px";
        String fontSize = " " + Integer.toString(textSize) + "px";
        String fontColor = " #" + StringUtils.remove(Integer.toHexString(textColor), "ff");
        String linkColor = " #" + StringUtils.remove(
                Integer.toHexString(new TextView(getActivity()).getLinkTextColors().getDefaultColor()), "ff");

        css = "body { " + "margin:" + topBottom + topBottom + leftRight + leftRight + "; " + "font-family:"
                + fontFamily + "; " + "font-size:" + fontSize + "; " + "color:" + fontColor + "; " + "}"
                + "a { " + "color:" + linkColor + "; " + "}";

        markdownView.getSettings().setJavaScriptEnabled(false);
        markdownView.getSettings().setLoadsImagesAutomatically(false);
        markdownView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));

                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
                    try {
                        startActivity(intent);
                    } catch (ActivityNotFoundException | FileUriExposedException e) {
                        /* Gracefully fail */ }
                else
                    try {
                        startActivity(intent);
                    } catch (ActivityNotFoundException e) {
                        /* Gracefully fail */ }

                return true;
            }
        });
    }

    // Load note contents
    try {
        contentsOnLoad = listener.loadNote(filename);
    } catch (IOException e) {
        showToast(R.string.error_loading_note);

        // Add NoteListFragment or WelcomeFragment
        Fragment fragment;
        if (getActivity().findViewById(R.id.layoutMain).getTag().equals("main-layout-normal"))
            fragment = new NoteListFragment();
        else
            fragment = new WelcomeFragment();

        getFragmentManager().beginTransaction().replace(R.id.noteViewEdit, fragment, "NoteListFragment")
                .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN).commit();
    }

    // Set TextView contents
    if (noteContents != null)
        noteContents.setText(contentsOnLoad);

    if (markdownView != null)
        markdownView.loadMarkdown(contentsOnLoad,
                "data:text/css;base64," + Base64.encodeToString(css.getBytes(), Base64.DEFAULT));

    // Show a toast message if this is the user's first time viewing a note
    final SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
    firstLoad = sharedPref.getInt("first-load", 0);
    if (firstLoad == 0) {
        // Show dialog with info
        DialogFragment firstLoad = new FirstViewDialogFragment();
        firstLoad.show(getFragmentManager(), "firstloadfragment");

        // Set first-load preference to 1; we don't need to show the dialog anymore
        SharedPreferences.Editor editor = sharedPref.edit();
        editor.putInt("first-load", 1);
        editor.apply();
    }

    // Detect single and double-taps using GestureDetector
    final GestureDetector detector = new GestureDetector(getActivity(),
            new GestureDetector.OnGestureListener() {
                @Override
                public boolean onSingleTapUp(MotionEvent e) {
                    return false;
                }

                @Override
                public void onShowPress(MotionEvent e) {
                }

                @Override
                public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
                    return false;
                }

                @Override
                public void onLongPress(MotionEvent e) {
                }

                @Override
                public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                    return false;
                }

                @Override
                public boolean onDown(MotionEvent e) {
                    return false;
                }
            });

    detector.setOnDoubleTapListener(new GestureDetector.OnDoubleTapListener() {
        @Override
        public boolean onDoubleTap(MotionEvent e) {
            if (sharedPref.getBoolean("show_double_tap_message", true)) {
                SharedPreferences.Editor editor = sharedPref.edit();
                editor.putBoolean("show_double_tap_message", false);
                editor.apply();
            }

            Bundle bundle = new Bundle();
            bundle.putString("filename", filename);

            Fragment fragment = new NoteEditFragment();
            fragment.setArguments(bundle);

            getFragmentManager().beginTransaction().replace(R.id.noteViewEdit, fragment, "NoteEditFragment")
                    .commit();

            return false;
        }

        @Override
        public boolean onDoubleTapEvent(MotionEvent e) {
            return false;
        }

        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            if (sharedPref.getBoolean("show_double_tap_message", true) && showMessage) {
                showToastLong(R.string.double_tap);
                showMessage = false;
            }

            return false;
        }

    });

    if (noteContents != null)
        noteContents.setOnTouchListener((v, event) -> {
            detector.onTouchEvent(event);
            return false;
        });

    if (markdownView != null)
        markdownView.setOnTouchListener((v, event) -> {
            detector.onTouchEvent(event);
            return false;
        });
}

From source file:com.near.chimerarevo.activities.PostContainerActivity.java

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    if ((newConfig.screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE) {
        if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
            isLandscapeLarge = true;//from  w  ww . j  a  va 2  s. co m
        else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT)
            isLandscapeLarge = false;
    }
}

From source file:de.tlabs.ssr.g1.client.SourcesView.java

private void init() {
    // make this view focusable
    setFocusable(true);//  w w w  . j  a  va  2  s . co  m

    // init fields
    viewportTransformation = new Matrix();
    newViewportTransformation = new Matrix();
    inverseViewportTransformation = new Matrix();

    selectionOffset = new float[2];
    touchPoint = new float[2];

    buffer = ByteBuffer.allocate(1024);

    scalingInterpolator = new TimedInterpolator();
    scalingInterpolator.setDuration(800);
    translationXInterpolator = new TimedInterpolator();
    translationXInterpolator.setDuration(800);
    translationYInterpolator = new TimedInterpolator();
    translationYInterpolator.setDuration(800);
    rotationInterpolator = new TimedInterpolator();
    rotationInterpolator.setDuration(800);
    centerRotationInterpolator = new TimedInterpolator();
    centerRotationInterpolator.setDuration(800);

    currentOrientation = getContext().getResources().getConfiguration().orientation;
    setOrientationFlag(true);

    if (SourcesView.paint == null) {
        SourcesView.paint = new Paint();
        SourcesView.paint.setAntiAlias(false);
        SourcesView.paint.setStrokeWidth(0);
        SourcesView.paint.setTextAlign(Paint.Align.CENTER);
        SourcesView.paint.setTextSize(9.0f);
    }

    // set up orientation event listener
    orientationEventListener = new OrientationEventListener(getContext(), SensorManager.SENSOR_DELAY_NORMAL) {
        @Override
        public void onOrientationChanged(int orientation) {
            if ((orientation >= 80 && orientation <= 100) || (orientation >= 260 && orientation <= 280)) { // landscape
                setOrientation(Configuration.ORIENTATION_LANDSCAPE);
            } else if ((orientation >= 350 || orientation <= 10)
                    || (orientation >= 170 && orientation <= 190)) { // portrait
                setOrientation(Configuration.ORIENTATION_PORTRAIT);
            }
        }
    };
    if (!GlobalData.orientationTrackingEnabled) // orientation tracking and screen rotation tracking don't go together
        orientationEventListener.enable();

    // set up gesture detector
    gestureDetector = new GestureDetector(getContext(), this);
    gestureDetector.setIsLongpressEnabled(false);
    gestureDetector.setOnDoubleTapListener(this);

    // init viewport transformation matrix
    recalculateViewportTransformation();
}

From source file:com.fsm.storybook.launcher.WebViewActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.v(TAG, "onCreate");

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_web_view);

    context = this;
    bkdb = new BookDatabase(getApplicationContext());
    globalApp = (GlobalApplication) this.getApplicationContext();
    util = new ActivityUtil(this);
    currentOrientation = String.valueOf(util.getScreenOrientation());
    gestureListener = new ContentGestureListener(this);
    //gestureListener = new WebViewGestureDetector();

    mWebview = (WebView) findViewById(R.id.webview);
    //mWebview.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    mWebview.setOnClickListener(WebViewActivity.this);
    mWebview.setOnTouchListener(gestureListener);
    //mHiddenWebview = (WebView) findViewById(R.id.webview_hidden);
    //mHiddenWebview.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    mPageInfo = (TextView) findViewById(R.id.page_info);
    mPageSlider = (SeekBar) findViewById(R.id.page_slider);
    mPageSlider.setOnSeekBarChangeListener(this);
    mPageInfo.setVisibility(View.GONE);
    mPageSlider.setVisibility(View.GONE);

    Intent intent = getIntent();//from w w  w  .j  a  va  2  s  . co  m
    Bundle extras = intent.getExtras();

    if (extras == null)
        return;
    //if (intent.getFlags() == Intent.FLAG_ACTIVITY_NEW_TASK) {

    mContainer = ContainerHolder.getInstance().get(extras.getLong(Constants.CONTAINER_ID));
    if (mContainer == null) {
        finish();
        return;
    }
    mPackage = mContainer.getDefaultPackage();

    //?
    int bookCode = extras.getInt(Constants.BOOK_CODE);
    mBookData = bkdb.fetchBook(bookCode);
    setTitle(mBookData.getTitle());

    //??spineitem?spineitem??
    List<SpineItem> spineItems = mPackage.getSpineItems();
    for (SpineItem item : spineItems) {
        String idref = item.getIdRef();
        mBookData.setSpineItemPageCount(String.valueOf(Configuration.ORIENTATION_PORTRAIT), idref, 1);
        mBookData.setSpineItemPageCount(String.valueOf(Configuration.ORIENTATION_LANDSCAPE), idref, 1);
    }
    bkdb.updateBook(mBookData);

    /*
    mBookmarkList = bkdb.fetchBookmarkList(bookCode);
    mHighlightList = bkdb.fetchHighlightList(bookCode);
    */
    mViewerSettings = new ViewerSettings(mBookData.getSpreadCount() == 2, mBookData.getFontSize(), 20);
    try {
        Log.d(TAG, "openPageRequest JSON:" + extras.getString(Constants.OPEN_PAGE_REQUEST_DATA));
        mOpenPageRequestData = OpenPageRequest.fromJSON(extras.getString(Constants.OPEN_PAGE_REQUEST_DATA));
    } catch (JSONException e) {
        Log.e(TAG, "Constants.OPEN_PAGE_REQUEST_DATA must be a valid JSON object: " + e.getMessage(), e);
    }

    //???
    if (mBookData.getTotalPageCount(currentOrientation) <= 0) {
        pageCountCaculateStatus = PAGE_COUNT_CAL_STATUS_NONE;
    } else {
        pageCountCaculateStatus = PAGE_COUNT_CAL_STATUS_DONE;
    }

    //epub web server
    new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            mServer = new EpubServer(EpubServer.HTTP_HOST, EpubServer.HTTP_PORT, mPackage, false);
            mServer.startServer();
            return null;
        }
    }.execute();

    //??hidden webview
    /*
    initHiddenWebView();
    mHiddenWebview.loadUrl(HIDDEN_READER_SKELETON);
    mReadiumJSApiForHiddenWebView = new ReadiumJSApi(new ReadiumJSApi.JSLoader() {
     @Override
     public void loadJS(String javascript) {
        mHiddenWebview.loadUrl(javascript);
     }
    });
    */

    //?webview
    initWebView();
    mWebview.loadUrl(READER_SKELETON);
    mReadiumJSApi = new ReadiumJSApi(new ReadiumJSApi.JSLoader() {
        @Override
        public void loadJS(String javascript) {
            mWebview.loadUrl(javascript);
        }
    });

    //}

}

From source file:com.experiment.chickenjohn.materialdemo.MainActivity.java

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    int currentOrientation = this.getResources().getConfiguration().orientation;
    if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) {
        portLoading();//  ww  w .  j  av  a 2  s  .c om
        Message uiRefreshMessage = Message.obtain();
        uiRefreshMessage.what = 0;
        uiRefreshHandler.sendMessage(uiRefreshMessage);
    } else if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
        landLoading();
    }
    drawSurfaceView.resetSurfaceViewX();
}