Example usage for android.view WindowManager getDefaultDisplay

List of usage examples for android.view WindowManager getDefaultDisplay

Introduction

In this page you can find the example usage for android.view WindowManager getDefaultDisplay.

Prototype

public Display getDefaultDisplay();

Source Link

Document

Returns the Display upon which this WindowManager instance will create new windows.

Usage

From source file:com.aimfire.demo.CameraActivity.java

public int getDeviceDefaultOrientation() {
    WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);

    Configuration config = getResources().getConfiguration();

    int rotation = windowManager.getDefaultDisplay().getRotation();

    if (((rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180)
            && config.orientation == Configuration.ORIENTATION_LANDSCAPE)
            || ((rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270)
                    && config.orientation == Configuration.ORIENTATION_PORTRAIT)) {
        return Configuration.ORIENTATION_LANDSCAPE;
    } else {/* w ww.  jav  a2  s  .  c om*/
        return Configuration.ORIENTATION_PORTRAIT;
    }
}

From source file:com.irccloud.android.NetworkConnection.java

@SuppressWarnings("deprecation")
public NetworkConnection() {
    String version;//from   w  w  w .j  a  v  a 2 s .co  m
    String network_type = null;
    try {
        version = "/" + IRCCloudApplication.getInstance().getPackageManager().getPackageInfo(
                IRCCloudApplication.getInstance().getApplicationContext().getPackageName(), 0).versionName;
    } catch (Exception e) {
        version = "";
    }

    try {
        ConnectivityManager cm = (ConnectivityManager) IRCCloudApplication.getInstance()
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo ni = cm.getActiveNetworkInfo();
        if (ni != null)
            network_type = ni.getTypeName();
    } catch (Exception e) {
    }

    try {
        config = new JSONObject(PreferenceManager
                .getDefaultSharedPreferences(IRCCloudApplication.getInstance().getApplicationContext())
                .getString("config", "{}"));
    } catch (JSONException e) {
        e.printStackTrace();
        config = new JSONObject();
    }

    useragent = "IRCCloud" + version + " (" + android.os.Build.MODEL + "; "
            + Locale.getDefault().getCountry().toLowerCase() + "; " + "Android "
            + android.os.Build.VERSION.RELEASE;

    WindowManager wm = (WindowManager) IRCCloudApplication.getInstance()
            .getSystemService(Context.WINDOW_SERVICE);
    useragent += "; " + wm.getDefaultDisplay().getWidth() + "x" + wm.getDefaultDisplay().getHeight();

    if (network_type != null)
        useragent += "; " + network_type;

    useragent += ")";

    WifiManager wfm = (WifiManager) IRCCloudApplication.getInstance().getApplicationContext()
            .getSystemService(Context.WIFI_SERVICE);
    wifiLock = wfm.createWifiLock(TAG);

    kms = new X509ExtendedKeyManager[1];
    kms[0] = new X509ExtendedKeyManager() {
        @Override
        public String chooseClientAlias(String[] keyTypes, Principal[] issuers, Socket socket) {
            return SSLAuthAlias;
        }

        @Override
        public String chooseServerAlias(String keyType, Principal[] issuers, Socket socket) {
            throw new UnsupportedOperationException();
        }

        @Override
        public X509Certificate[] getCertificateChain(String alias) {
            return SSLAuthCertificateChain;
        }

        @Override
        public String[] getClientAliases(String keyType, Principal[] issuers) {
            throw new UnsupportedOperationException();
        }

        @Override
        public String[] getServerAliases(String keyType, Principal[] issuers) {
            throw new UnsupportedOperationException();
        }

        @Override
        public PrivateKey getPrivateKey(String alias) {
            return SSLAuthKey;
        }
    };

    tms = new TrustManager[1];
    tms[0] = new X509TrustManager() {
        @Override
        public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
            throw new CertificateException("Not implemented");
        }

        @Override
        public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
            try {
                TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("X509");
                trustManagerFactory.init((KeyStore) null);

                for (TrustManager trustManager : trustManagerFactory.getTrustManagers()) {
                    if (trustManager instanceof X509TrustManager) {
                        X509TrustManager x509TrustManager = (X509TrustManager) trustManager;
                        x509TrustManager.checkServerTrusted(chain, authType);
                    }
                }
            } catch (KeyStoreException e) {
                throw new CertificateException(e);
            } catch (NoSuchAlgorithmException e) {
                throw new CertificateException(e);
            }

            if (BuildConfig.SSL_FPS != null && BuildConfig.SSL_FPS.length > 0) {
                try {
                    MessageDigest md = MessageDigest.getInstance("SHA-1");
                    byte[] sha1 = md.digest(chain[0].getEncoded());
                    // http://stackoverflow.com/questions/9655181/convert-from-byte-array-to-hex-string-in-java
                    final char[] hexArray = "0123456789ABCDEF".toCharArray();
                    char[] hexChars = new char[sha1.length * 2];
                    for (int j = 0; j < sha1.length; j++) {
                        int v = sha1[j] & 0xFF;
                        hexChars[j * 2] = hexArray[v >>> 4];
                        hexChars[j * 2 + 1] = hexArray[v & 0x0F];
                    }
                    String hexCharsStr = new String(hexChars);
                    boolean matched = false;
                    for (String fp : BuildConfig.SSL_FPS) {
                        if (fp.equals(hexCharsStr)) {
                            matched = true;
                            break;
                        }
                    }
                    if (!matched)
                        throw new CertificateException("Incorrect CN in cert chain");
                } catch (NoSuchAlgorithmException e) {
                    e.printStackTrace();
                }
            }
        }

        @Override
        public X509Certificate[] getAcceptedIssuers() {
            return null;
        }
    };
    WebSocketClient.setTrustManagers(tms);
}

From source file:com.mozilla.SUTAgentAndroid.service.DoCommand.java

public String GetScreenInfo() {
    String sRet = "";
    DisplayMetrics metrics = new DisplayMetrics();
    WindowManager wMgr = (WindowManager) contextWrapper.getSystemService(Context.WINDOW_SERVICE);
    wMgr.getDefaultDisplay().getMetrics(metrics);
    sRet = "X:" + metrics.widthPixels + " Y:" + metrics.heightPixels;
    return (sRet);
}

From source file:com.mozilla.SUTAgentAndroid.service.DoCommand.java

public int[] GetScreenXY() {
    int[] nRetXY = new int[2];
    DisplayMetrics metrics = new DisplayMetrics();
    WindowManager wMgr = (WindowManager) contextWrapper.getSystemService(Context.WINDOW_SERVICE);
    wMgr.getDefaultDisplay().getMetrics(metrics);
    nRetXY[0] = metrics.widthPixels;/* w w  w . ja v  a  2 s.co m*/
    nRetXY[1] = metrics.heightPixels;
    return (nRetXY);
}

From source file:com.mozilla.SUTAgentAndroid.service.DoCommand.java

public String GetRotationInfo() {
    WindowManager wMgr = (WindowManager) contextWrapper.getSystemService(Context.WINDOW_SERVICE);
    int nRotationDegrees = 0; // default
    switch (wMgr.getDefaultDisplay().getRotation()) {
    case Surface.ROTATION_90:
        nRotationDegrees = 90;//  ww  w  .j  av  a2  s  .c  o  m
        break;
    case Surface.ROTATION_180:
        nRotationDegrees = 180;
        break;
    case Surface.ROTATION_270:
        nRotationDegrees = 270;
        break;
    }
    return "ROTATION:" + nRotationDegrees;
}

From source file:com.aimfire.demo.CamcorderActivity.java

/**
 * get the default/natural device orientation. this should be PORTRAIT
 * for phones and LANDSCAPE for tablets/* www.  j  av a  2  s  .  co m*/
 */
public int getDeviceDefaultOrientation() {
    WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);

    Configuration config = getResources().getConfiguration();

    int rotation = windowManager.getDefaultDisplay().getRotation();

    if (((rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180)
            && config.orientation == Configuration.ORIENTATION_LANDSCAPE)
            || ((rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270)
                    && config.orientation == Configuration.ORIENTATION_PORTRAIT)) {
        return Configuration.ORIENTATION_LANDSCAPE;
    } else {
        return Configuration.ORIENTATION_PORTRAIT;
    }
}

From source file:com.xmobileapp.rockplayer.RockPlayer.java

/**********************************************
 * //  www .j  a  v  a2s  . c o m
 *  Called when the activity is first created
 *  
 **********************************************/
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    context = this;
    System.gc();

    //Log.i("PRFMC", "1");
    /*
    * Window Properties
    */
    //requestWindowFeature(Window.FEATURE_PROGRESS);
    //requestWindowFeature(Window.PROGRESS_VISIBILITY_ON);
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    /*
     * Blur&Dim the BG
     */
    // Have the system blur any windows behind this one.
    //        getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
    //                WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
    ////        getWindow().setFlags(WindowManager.LayoutParams.FLAG_DITHER, 
    ////              WindowManager.LayoutParams.FLAG_DITHER);
    //        getWindow().setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND, 
    //              WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    //        WindowManager.LayoutParams params = getWindow().getAttributes();
    //        params.dimAmount = 0.625f;
    //        getWindow().setAttributes(params);

    //        Resources.Theme theme = getTheme();
    //        theme.dump(arg0, arg1, arg2)

    //setContentView(R.layout.songfest_main);
    //Log.i("PRFMC", "2");

    /*
     * Initialize Display
     */
    WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
    this.display = windowManager.getDefaultDisplay();
    //Log.i("PRFMC", "3");

    /*
     * Set Bug Report Handler
     */
    fdHandler = new FilexDefaultExceptionHandler(this);

    /*
     * Check if Album Art Directory exists
     */
    checkAlbumArtDirectory();
    checkConcertDirectory();
    checkPreferencesDirectory();
    checkBackgroundDirectory();
    //Log.i("PRFMC", "7");

    /*
     * Get Preferences
     */
    readPreferences();

    /*
     * Force landscape or auto-rotate orientation if user requested
     */
    if (alwaysLandscape)
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    else if (autoRotate)
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);

    /*
      * Create UI and initialize UI vars
      */
    setContentView(R.layout.songfest_main);

    //getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    //if (true) return;

    //if(true)
    //   return;
    //Log.i("PRFMC", "4");
    initializeAnimations();
    //Log.i("PRFMC", "5");
    initializeUiVariables();
    //Log.i("PRFMC", "6");

    /*
     * Set Background
     */
    setBackground();

    /*
     * Set Current View
     */
    switch (VIEW_STATE) {
    case LIST_EXPANDED_VIEW:
        setListExpandedView();
        break;
    case FULLSCREEN_VIEW:
        setFullScreenView();
        break;
    default:
        setNormalView();
        break;
    }

    //        AlphaAnimation aAnim = new AlphaAnimation(0.0f, 0.92f);
    //        aAnim.setFillAfter(true);
    //        aAnim.setDuration(200);
    //        mainUIContainer.startAnimation(aAnim);

    /*
     * Check for SD Card
     */
    if (!android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) {
        Dialog noSDDialog = new Dialog(this);
        noSDDialog.setTitle("SD Card Error!");
        noSDDialog.setContentView(R.layout.no_sd_alert_layout);
        noSDDialog.show();
        return;
    }

    /*
     * Get a Content Resolver to browse
     * the phone audio database
     */
    contentResolver = getContentResolver();

    /*
     * Get Preferences
     */
    //SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
    RockOnPreferenceManager settings = new RockOnPreferenceManager(FILEX_PREFERENCES_PATH);
    settings = new RockOnPreferenceManager(this.FILEX_PREFERENCES_PATH);
    // Shuffle
    boolean shuffle = settings.getBoolean("Shuffle", false);
    this.SHUFFLE = shuffle;
    //Playlist
    if (playlist == constants.PLAYLIST_NONE)
        playlist = settings.getLong(constants.PREF_KEY_PLAYLIST, constants.PLAYLIST_ALL);
    Log.i("PLAYLIST PREF", constants.PREF_KEY_PLAYLIST + " " + constants.PLAYLIST_ALL + " " + playlist);

    /*
     * Check if the MediaScanner is scanning
     */
    //        ProgressDialog pD = null;
    //        while(isMediaScannerScanning(this, contentResolver) == true){
    //           if(pD == null){
    //              pD = new ProgressDialog(this);
    //              pD.setTitle("Scanning Media");
    //              pD.setMessage("Wait please...");
    //              pD.show();
    //           }
    //           try {
    //            wait(2000);
    //         } catch (InterruptedException e) {
    //            e.printStackTrace();
    //         }
    //        }
    //        if(pD != null)
    //           pD.dismiss();

    /*
     * Initialize mediaPlayer
     */
    //this.mediaPlayer = new MediaPlayer();
    //this.mediaPlayer.setOnCompletionListener(songCompletedListener);

    /*
     * Initialize (or connect to) BG Service
     *  - when connected it will call the method getCurrentPlaying()
     *     and will cause the Service to reset its albumCursor
     */
    initializeService();
    //Log.i("PRFMC", "8");
    musicChangedIntentReceiver = new MusicChangedIntentReceiver();
    albumChangedIntentReceiver = new AlbumChangedIntentReceiver();
    mediaButtonPauseIntentReceiver = new MediaButtonPauseIntentReceiver();
    mediaButtonPlayIntentReceiver = new MediaButtonPlayIntentReceiver();
    registerReceiver(musicChangedIntentReceiver, musicChangedIntentFilter);
    //Log.i("PRFMC", "9");
    registerReceiver(albumChangedIntentReceiver, albumChangedIntentFilter);
    //Log.i("PRFMC", "10");
    registerReceiver(mediaButtonPauseIntentReceiver, mediaButtonPauseIntentFilter);
    registerReceiver(mediaButtonPlayIntentReceiver, mediaButtonPlayIntentFilter);
    // calls also getCurrentPlaying() upon connection

    /*
     * Register Media Button Receiver
     */
    //        mediaButtonIntentReceiver = new MediaButtonIntentReceiver();
    //        registerReceiver(mediaButtonIntentReceiver, new IntentFilter("android.intent.action.MEDIA_BUTTON"));

    /*
      * Get album information on a new
      * thread
      */
    //new Thread(){
    //   public void run(){
    getAlbums(false);
    //Log.i("PRFMC", "11");
    //   }
    //}.start();

    /*
     * Check for first time run ----------
     * 
     * Save Software Version
     *    &
     * Show Help Screen
     */
    //            if(!settings.contains("Version")){
    //               Editor settingsEditor = settings.edit();
    //               settingsEditor.putLong("Version", VERSION);
    //               settingsEditor.commit();
    //               this.hideMainUI();
    //               this.showHelpUI();
    //            }
    Log.i("DBG", "Version - " + (new RockOnPreferenceManager(this.FILEX_PREFERENCES_PATH)).getLong("Version", 0)
            + " - " + VERSION);
    if (!(new RockOnPreferenceManager(this.FILEX_PREFERENCES_PATH)).contains("Version")
            || (new RockOnPreferenceManager(this.FILEX_PREFERENCES_PATH)).getLong("Version", 0) < VERSION) {

        (new RockOnPreferenceManager(this.FILEX_PREFERENCES_PATH)).putLong("Version", VERSION);

        /*
        * Clear previous Album Art
        */
        Builder aD = new AlertDialog.Builder(context);
        aD.setTitle("New Version");
        aD.setMessage(
                "The new version of RockOn supports album art download from higher quality sources. Do you want to download art now? "
                        + "Every 10 albums will take aproximately 1 minute to download. "
                        + "(You can always do this later by choosing the 'Get Art' menu option)");
        aD.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                //(new RockOnPreferenceManager(FILEX_PREFERENCES_PATH)).putLong("artImportDate", 0);
                try {
                    File albumArtDir = new File(FILEX_ALBUM_ART_PATH);
                    String[] fileList = albumArtDir.list();
                    File albumArtFile;
                    for (int i = 0; i < fileList.length; i++) {
                        albumArtFile = new File(albumArtDir.getAbsolutePath() + "/" + fileList[i]);
                        albumArtFile.delete();
                    }
                    checkAlbumArtDirectory();
                    triggerAlbumArtFetching();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

        });
        aD.setNegativeButton("No", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {

            }

        });
        aD.show();

        /*
        * Version 2 specific default preference changes
        */
        // version 2 specific
        if (albumCursor.getCount() > 100)
            (new RockOnPreferenceManager(this.FILEX_PREFERENCES_PATH))
                    .putBoolean(PREFS_SHOW_ART_WHILE_SCROLLING, false);
        else
            (new RockOnPreferenceManager(this.FILEX_PREFERENCES_PATH))
                    .putBoolean(PREFS_SHOW_ART_WHILE_SCROLLING, true);

        readPreferences();
        albumAdapter.showArtWhileScrolling = showArtWhileScrolling;
        albumAdapter.showFrame = showFrame;
        //

        /*
        * Show help screen
        */
        this.hideMainUI();
        this.showHelpUI();
    } else {
        /*
         * Run albumArt getter in background
         */
        long lastAlbumArtImportDate = settings.getLong("artImportDate", 0);
        Log.i("SYNCTIME",
                lastAlbumArtImportDate + " + " + this.ART_IMPORT_INTVL + " < " + System.currentTimeMillis());
        if (lastAlbumArtImportDate + this.ART_IMPORT_INTVL < System.currentTimeMillis()) {
            triggerAlbumArtFetching();
        }
        //Log.i("PRFMC", "13");
    }
}