Example usage for android.util DisplayMetrics DisplayMetrics

List of usage examples for android.util DisplayMetrics DisplayMetrics

Introduction

In this page you can find the example usage for android.util DisplayMetrics DisplayMetrics.

Prototype

public DisplayMetrics() 

Source Link

Usage

From source file:com.malgon.applecrunch.Game1.java

public void onCreate() {
    DisplayMetrics dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);

    createEngine("graphics/splash.png", dm.widthPixels, dm.heightPixels, true);

    alertDialog = new AlertDialog.Builder(Game1.this).create();
    alertDialog.setTitle("Game1 Finished");
    alertDialog.setButton("Play again", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            score = 0;/*from  ww w . j ava2 s.  com*/
            appleTouch = 0;
            androidTouch = 0;
            time = timeToPlay / 1000;
            rokon.unfreeze();

            timer.postDelayed(endOfGame1, timeToPlay);
        }
    });
    alertDialog.setButton2("Quit", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            System.exit(0);
            Game1.this.finish();
        }
    });

    scoreDialog = new AlertDialog.Builder(Game1.this).create();
    scoreDialog.setTitle("Send score ?");
    scoreDialog.setButton("Yes", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(Game1.this);

            HttpClient httpclient = new DefaultHttpClient();
            HttpGet get = new HttpGet(url + "?key=o2BY3XUF0AgytDdaLmugnXiFUfRRQF&username="
                    + pref.getString("username", "Player Default").replace(" ", "+") + "&score=" + score
                    + "&type=1");
            try {
                httpclient.execute(get);
            } catch (ClientProtocolException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }

            String msg = "Game1 finished, you've crush apple " + appleTouch + " time ! ";

            if (androidTouch > 0) {
                msg += "But you killed Android " + androidTouch + " time :( ";
                msg += "Next time don't crush Android, because it will eat apples :D ";
            } else if (appleTouch == 0) {
                msg += "Don't be afraid of apple ;) ";
            } else
                msg += "You are now an Android lover, and an apple killer :D ";

            msg += "Your final score is " + score;

            alertDialog.setMessage(msg);

            alertDialog.show();
        }
    });
    scoreDialog.setButton2("No", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            String msg = "Game1 finished, you've crush apple " + appleTouch + " time ! ";

            if (androidTouch > 0) {
                msg += "But you killed Android " + androidTouch + " time :( ";
                msg += "Next time don't crush Android, because it will eat apples :D ";
            } else if (appleTouch == 0) {
                msg += "Don't be afraid of apple ;) ";
            } else
                msg += "You are now an Android lover, and an apple killer :D ";

            msg += "Your final score is " + score;

            alertDialog.setMessage(msg);

            alertDialog.show();
        }
    });

    goalDialog = new AlertDialog.Builder(Game1.this).create();
    goalDialog.setTitle("Goal");
    goalDialog
            .setMessage("The goal of this game, is to crush apple sprites, without crushing Android sprites !");
    goalDialog.setButton("Ok", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            timer.postDelayed(endOfGame1, timeToPlay);
            timerTime.postDelayed(checkTime, 1000);
            timerAndroid.postDelayed(checkAndroid, 0);
        }
    });
}

From source file:net.exclaimindustries.geohashdroid.wiki.WikiPictureEditor.java

@Override
protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    // Get some display metrics.  We need to scale the gallery thumbnails
    // accordingly, else they look too small on big screens and too big on
    // small screens.  We do this here to save calculations later, else
    // we'd be doing floating-point multiplication on EVERY SINGLE
    // THUMBNAIL, and we can't guarantee that won't be painful on every
    // Android phone.
    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    THUMB_DIMEN = (int) (getResources().getDimensionPixelSize(R.dimen.nominal_icon_size) * metrics.density);

    Log.d(DEBUG_TAG, "Thumbnail dimensions: " + THUMB_DIMEN);

    mInfo = (Info) getIntent().getParcelableExtra(GeohashDroid.INFO);

    setContentView(R.layout.pictureselect);

    Button submitButton = (Button) findViewById(R.id.wikieditbutton);
    ImageButton galleryButton = (ImageButton) findViewById(R.id.GalleryButton);

    galleryButton.setOnClickListener(new View.OnClickListener() {
        @Override//w  w  w.j a  v  a  2  s  .  c o  m
        public void onClick(View v) {
            // Fire off the Gallery!
            startActivityForResult(new Intent(Intent.ACTION_PICK,
                    android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI), REQUEST_PICTURE);
        }
    });

    submitButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // We don't want to let the Activity handle the dialog.  That WILL
            // cause it to show up properly and all, but after a configuration
            // change (i.e. orientation shift), it won't show or update any text
            // (as far as I know), as we can't reassign the handler properly.
            // So, we'll handle it ourselves.
            mProgress = ProgressDialog.show(WikiPictureEditor.this, "", "", true, true, WikiPictureEditor.this);
            mConnectionHandler = new PictureConnectionRunner(mProgressHandler, WikiPictureEditor.this);
            mWikiConnectionThread = new Thread(mConnectionHandler, "WikiConnectionThread");
            mWikiConnectionThread.start();
        }
    });

    // We can set the background on the thumbnail view right away, even if
    // it's not actually visible.
    ImageView thumbView = (ImageView) findViewById(R.id.ThumbnailImage);
    thumbView.setBackgroundResource(R.drawable.gallery_selected_default);
    thumbView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);

    // Now, let's see if we have anything retained...
    try {
        RetainedThings retain = (RetainedThings) getLastNonConfigurationInstance();
        if (retain != null) {
            // We have something retained!  Thus, we need to construct the
            // popup and update it with the right status, assuming the
            // thread's still going.
            if (retain.thread != null && retain.thread.isAlive()) {
                mProgress = ProgressDialog.show(WikiPictureEditor.this, "", "", true, true,
                        WikiPictureEditor.this);
                mConnectionHandler = retain.handler;
                mConnectionHandler.resetHandler(mProgressHandler);
                mWikiConnectionThread = retain.thread;
            }

            // And in any event, put the image info back up.
            mCurrentFile = retain.currentFile;
            mCurrentThumbnail = retain.thumbnail;
            mPictureLocation = retain.picLocation;

            setThumbnail();
        } else {
            // If there was nothing to retain, maybe we've got a bundle.
            if (icicle != null) {
                if (icicle.containsKey(STORED_FILE))
                    mCurrentFile = icicle.getString(STORED_FILE);
                if (icicle.containsKey(STORED_LOCATION))
                    mPictureLocation = icicle.getParcelable(STORED_LOCATION);
            }

            // Rebuild it all in any event.
            buildThumbnail();
            setThumbnail();
        }
    } catch (Exception ex) {
        // If we got an exception, reset the thumbnail info with whatever
        // we have handy.
        buildThumbnail();
        setThumbnail();
    }

    // Rebuild the thumbnail and display it as need be.

}

From source file:fr.univsavoie.ltp.client.map.Popup.java

/**
 * Afficher sur la map un popup qui propose a l'utilisateur
 * de mettre a jours son status//from   w ww . j  a  va2s.co m
 */
public final void popupPublishStatus() {
    DisplayMetrics dm = new DisplayMetrics();
    this.activity.getWindowManager().getDefaultDisplay().getMetrics(dm);

    //final int height = dm.heightPixels;
    final int width = dm.widthPixels;

    int popupWidth = (int) (width * 0.75);
    //int popupHeight = height / 2;

    // Inflate the popup_layout.xml
    ScrollView viewGroup = (ScrollView) this.activity.findViewById(R.id.popupStatus);
    LayoutInflater layoutInflater = (LayoutInflater) this.activity
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    final View layout = layoutInflater.inflate(R.layout.popup_set_status, viewGroup);
    layout.setBackgroundResource(R.drawable.popup_gradient);

    // Crer le PopupWindow
    final PopupWindow popupPublishStatus = new PopupWindow(layout, popupWidth, LayoutParams.WRAP_CONTENT, true);
    popupPublishStatus.setBackgroundDrawable(new BitmapDrawable());
    popupPublishStatus.setOutsideTouchable(true);

    // Some offset to align the popup a bit to the right, and a bit down, relative to button's position.
    final int OFFSET_X = 0;
    final int OFFSET_Y = 0;

    // Displaying the popup at the specified location, + offsets.
    this.activity.findViewById(R.id.layoutMain).post(new Runnable() {
        public void run() {
            popupPublishStatus.showAtLocation(layout, Gravity.CENTER, OFFSET_X, OFFSET_Y);
        }
    });

    /*
     * Evenements composants du PopupWindow
     */

    // Ecouteur d'vnement sur le bouton pour se dconnecter
    Button publish = (Button) layout.findViewById(R.id.btStatusPublish);
    publish.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            EditText userStatus = (EditText) layout.findViewById(R.id.fieldUserStatus);
            if (userStatus.getText().toString().length() == 0) {
                Toast.makeText(activity, "Impossible de publi ton status !", Toast.LENGTH_LONG).show();
                popupPublishStatus.dismiss();
            } else if (userStatus.getText().toString().length() < 3) {
                Toast.makeText(activity, "Impossible de publi ton status !", Toast.LENGTH_LONG).show();
                popupPublishStatus.dismiss();
            } else {
                String json = "{\"ltp\":{\"application\":\"Client LTP\",\"status\":{\"lon\" : \""
                        + String.valueOf(activity.getLongitude()) + "\",\"lat\" : \""
                        + String.valueOf(activity.getLatitude()) + "\",\"content\" : \""
                        + userStatus.getText().toString() + "\"}}}";
                activity.getSession().postJSON("https://jibiki.univ-savoie.fr/ltpdev/rest.php/api/1/statuses",
                        "STATUSES", json);

                Toast.makeText(activity, "Status mise a jours !", Toast.LENGTH_LONG).show();
                popupPublishStatus.dismiss();

                // Actualise les marqueurs
                activity.displayFriends();
            }
        }
    });
}

From source file:com.example.aaron.test.MyGLSurfaceView.java

public MyGLSurfaceView(Context context, float f[], turtle turtleList[]) {
    super(context);
    context1 = context;/*from   w w w .  j a  v a  2  s  . c  o  m*/
    v = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
    vor = new Voronoi(.001);
    DisplayMetrics metrics = new DisplayMetrics();
    ((Activity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(metrics);
    width1 = metrics.widthPixels;
    height1 = metrics.heightPixels;
    mapLeft = (width1 - 100) / height1;
    mapTop = (height1 - 5) / height1;
    mapBottom = -(height1 - 5) / height1;

    poseData = f;
    // Create an OpenGL ES 2.0 context.
    setEGLContextClientVersion(2);
    for (int i = 0; i < maxBots; i++) {
        tList[i] = new turtle();
        state[i] = 0;
    }

    // Set the Renderer for drawing on the GLSurfaceView
    mRenderer = new MyGLRenderer(context, f, tList, width1, height1);
    //float posTemp[]=f;
    setEGLConfigChooser(new MultisampleConfigChooser());
    setRenderer(mRenderer);

    // Render the view only when there is a change in the drawing data
    setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);

}

From source file:com.aniruddhc.acemusic.player.LauncherActivity.LauncherActivity.java

@SuppressLint("NewApi")
@Override//from w  w  w.ja  v  a2  s  .  c o  m
public void onCreate(Bundle savedInstanceState) {

    setTheme(R.style.AppThemeNoActionBar);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_launcher);

    mContext = this;
    mActivity = this;
    mApp = (Common) mContext.getApplicationContext();
    mHandler = new Handler();

    //Increment the start count. This value will be used to determine when the library should be rescanned.
    int startCount = mApp.getSharedPreferences().getInt("START_COUNT", 1);
    mApp.getSharedPreferences().edit().putInt("START_COUNT", startCount + 1).commit();

    //Save the dimensions of the layout for later use on KitKat devices.
    final RelativeLayout launcherRootView = (RelativeLayout) findViewById(R.id.launcher_root_view);
    launcherRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {

            try {

                int screenDimens[] = new int[2];
                int screenHeight = 0;
                int screenWidth = 0;
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
                    //API levels 14, 15 and 16.
                    screenDimens = getTrueDeviceResolution();
                    screenWidth = screenDimens[0];
                    screenHeight = screenDimens[1];

                } else {
                    //API levels 17+.
                    Display display = getWindowManager().getDefaultDisplay();
                    DisplayMetrics metrics = new DisplayMetrics();
                    display.getRealMetrics(metrics);
                    screenHeight = metrics.heightPixels;
                    screenWidth = metrics.widthPixels;

                }

                int layoutHeight = launcherRootView.getHeight();
                int layoutWidth = launcherRootView.getWidth();

                int extraHeight = screenHeight - layoutHeight;
                int extraWidth = screenWidth = layoutWidth;

                mApp.getSharedPreferences().edit().putInt("KITKAT_HEIGHT", layoutHeight).commit();
                mApp.getSharedPreferences().edit().putInt("KITKAT_WIDTH", layoutWidth).commit();
                mApp.getSharedPreferences().edit().putInt("KITKAT_HEIGHT_LAND", layoutWidth - extraHeight)
                        .commit();
                mApp.getSharedPreferences().edit().putInt("KITKAT_WIDTH_LAND", screenHeight).commit();

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

        }

    });

    //Build the music library based on the user's scan frequency preferences.
    int scanFrequency = mApp.getSharedPreferences().getInt("SCAN_FREQUENCY", 5);
    int updatedStartCount = mApp.getSharedPreferences().getInt("START_COUNT", 1);

    //Launch the appropriate activity based on the "FIRST RUN" flag.
    if (mApp.getSharedPreferences().getBoolean(Common.FIRST_RUN, true) == true) {

        //Create the default Playlists directory if it doesn't exist.
        File playlistsDirectory = new File(Environment.getExternalStorageDirectory() + "/Playlists/");
        if (!playlistsDirectory.exists() || !playlistsDirectory.isDirectory()) {
            playlistsDirectory.mkdir();
        }

        //Disable equalizer for HTC devices by default.
        if (mApp.getSharedPreferences().getBoolean(Common.FIRST_RUN, true) == true
                && Build.PRODUCT.contains("HTC")) {
            mApp.getSharedPreferences().edit().putBoolean("EQUALIZER_ENABLED", false).commit();
        }

        //Send out a test broadcast to initialize the homescreen/lockscreen widgets.
        sendBroadcast(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME));

        Intent intent = new Intent(this, WelcomeActivity.class);
        startActivity(intent);
        overridePendingTransition(R.anim.fade_in, R.anim.fade_out);

    } else if (mApp.isBuildingLibrary()) {
        buildingLibraryMainText = (TextView) findViewById(R.id.building_music_library_text);
        buildingLibraryInfoText = (TextView) findViewById(R.id.building_music_library_info);
        buildingLibraryLayout = (RelativeLayout) findViewById(R.id.building_music_library_layout);

        buildingLibraryInfoText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryInfoText.setPaintFlags(
                buildingLibraryInfoText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryMainText.setPaintFlags(
                buildingLibraryMainText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setText(R.string.jams_is_building_library);
        buildingLibraryLayout.setVisibility(View.VISIBLE);

        //Initialize the runnable that will fire once the scan process is complete.
        mHandler.post(scanFinishedCheckerRunnable);

    } else if (mApp.getSharedPreferences().getBoolean("RESCAN_ALBUM_ART", false) == true) {

        buildingLibraryMainText = (TextView) findViewById(R.id.building_music_library_text);
        buildingLibraryInfoText = (TextView) findViewById(R.id.building_music_library_info);
        buildingLibraryLayout = (RelativeLayout) findViewById(R.id.building_music_library_layout);

        buildingLibraryInfoText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryInfoText.setPaintFlags(
                buildingLibraryInfoText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryMainText.setPaintFlags(
                buildingLibraryMainText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setText(R.string.jams_is_caching_artwork);
        initScanProcess(0);

    } else if ((mApp.getSharedPreferences().getBoolean("REBUILD_LIBRARY", false) == true)
            || (scanFrequency == 0 && mApp.isScanFinished() == false)
            || (scanFrequency == 1 && mApp.isScanFinished() == false && updatedStartCount % 3 == 0)
            || (scanFrequency == 2 && mApp.isScanFinished() == false && updatedStartCount % 5 == 0)
            || (scanFrequency == 3 && mApp.isScanFinished() == false && updatedStartCount % 10 == 0)
            || (scanFrequency == 4 && mApp.isScanFinished() == false && updatedStartCount % 20 == 0)) {

        buildingLibraryMainText = (TextView) findViewById(R.id.building_music_library_text);
        buildingLibraryInfoText = (TextView) findViewById(R.id.building_music_library_info);
        buildingLibraryLayout = (RelativeLayout) findViewById(R.id.building_music_library_layout);

        buildingLibraryInfoText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryInfoText.setPaintFlags(
                buildingLibraryInfoText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryMainText.setPaintFlags(
                buildingLibraryMainText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        initScanProcess(1);

    } else {

        //Check if this activity was called from Settings.
        if (getIntent().hasExtra("UPGRADE")) {
            if (getIntent().getExtras().getBoolean("UPGRADE") == true) {
                mExplicitShowTrialFragment = true;
            } else {
                mExplicitShowTrialFragment = false;
            }

        }

        //initInAppBilling();
        launchMainActivity();
    }

    //Fire away a report to Google Analytics.
    try {
        if (mApp.isGoogleAnalyticsEnabled() == true) {
            EasyTracker easyTracker = EasyTracker.getInstance(this);
            easyTracker.send(MapBuilder.createEvent("ACE startup.", // Event category (required)
                    "User started ACE.", // Event action (required)
                    "User started ACE.", // Event label
                    null) // Event value
                    .build());
        }

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

}

From source file:com.tealeaf.NativeShim.java

public DisplayMetrics getDisplayMetrics() {
    DisplayMetrics metrics = new DisplayMetrics();
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    windowManager.getDefaultDisplay().getMetrics(metrics);
    return metrics;
}

From source file:com.Duo.music.player.LauncherActivity.LauncherActivity.java

@SuppressLint("NewApi")
@Override//w  w w. j av a 2  s .  com
public void onCreate(Bundle savedInstanceState) {

    setTheme(R.style.AppThemeNoActionBar);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_launcher);

    mContext = this;
    mActivity = this;
    mApp = (Common) mContext.getApplicationContext();
    mHandler = new Handler();

    //Increment the start count. This value will be used to determine when the library should be rescanned.
    int startCount = mApp.getSharedPreferences().getInt("START_COUNT", 1);
    mApp.getSharedPreferences().edit().putInt("START_COUNT", startCount + 1).commit();

    //Save the dimensions of the layout for later use on KitKat devices.
    final RelativeLayout launcherRootView = (RelativeLayout) findViewById(R.id.launcher_root_view);
    launcherRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {

            try {

                int screenDimens[] = new int[2];
                int screenHeight = 0;
                int screenWidth = 0;
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
                    //API levels 14, 15 and 16.
                    screenDimens = getTrueDeviceResolution();
                    screenWidth = screenDimens[0];
                    screenHeight = screenDimens[1];

                } else {
                    //API levels 17+.
                    Display display = getWindowManager().getDefaultDisplay();
                    DisplayMetrics metrics = new DisplayMetrics();
                    display.getRealMetrics(metrics);
                    screenHeight = metrics.heightPixels;
                    screenWidth = metrics.widthPixels;

                }

                int layoutHeight = launcherRootView.getHeight();
                int layoutWidth = launcherRootView.getWidth();

                int extraHeight = screenHeight - layoutHeight;
                int extraWidth = screenWidth = layoutWidth;

                mApp.getSharedPreferences().edit().putInt("KITKAT_HEIGHT", layoutHeight).commit();
                mApp.getSharedPreferences().edit().putInt("KITKAT_WIDTH", layoutWidth).commit();
                mApp.getSharedPreferences().edit().putInt("KITKAT_HEIGHT_LAND", layoutWidth - extraHeight)
                        .commit();
                mApp.getSharedPreferences().edit().putInt("KITKAT_WIDTH_LAND", screenHeight).commit();

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

        }

    });

    //Build the music library based on the user's scan frequency preferences.
    int scanFrequency = mApp.getSharedPreferences().getInt("SCAN_FREQUENCY", 5);
    int updatedStartCount = mApp.getSharedPreferences().getInt("START_COUNT", 1);

    //Launch the appropriate activity based on the "FIRST RUN" flag.
    if (mApp.getSharedPreferences().getBoolean(Common.FIRST_RUN, true) == true) {

        //Create the default Playlists directory if it doesn't exist.
        File playlistsDirectory = new File(Environment.getExternalStorageDirectory() + "/Playlists/");
        if (!playlistsDirectory.exists() || !playlistsDirectory.isDirectory()) {
            playlistsDirectory.mkdir();
        }

        //Disable equalizer for HTC devices by default.
        if (mApp.getSharedPreferences().getBoolean(Common.FIRST_RUN, true) == true
                && Build.PRODUCT.contains("HTC")) {
            mApp.getSharedPreferences().edit().putBoolean("EQUALIZER_ENABLED", false).commit();
        }

        //Send out a test broadcast to initialize the homescreen/lockscreen widgets.
        sendBroadcast(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME));

        Intent intent = new Intent(this, WelcomeActivity.class);
        startActivity(intent);
        overridePendingTransition(R.anim.fade_in, R.anim.fade_out);

    } else if (mApp.isBuildingLibrary()) {
        buildingLibraryMainText = (TextView) findViewById(R.id.building_music_library_text);
        buildingLibraryInfoText = (TextView) findViewById(R.id.building_music_library_info);
        buildingLibraryLayout = (RelativeLayout) findViewById(R.id.building_music_library_layout);

        buildingLibraryInfoText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryInfoText.setPaintFlags(
                buildingLibraryInfoText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryMainText.setPaintFlags(
                buildingLibraryMainText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setText(R.string.jams_is_building_library);
        buildingLibraryLayout.setVisibility(View.VISIBLE);

        //Initialize the runnable that will fire once the scan process is complete.
        mHandler.post(scanFinishedCheckerRunnable);

    } else if (mApp.getSharedPreferences().getBoolean("RESCAN_ALBUM_ART", false) == true) {

        buildingLibraryMainText = (TextView) findViewById(R.id.building_music_library_text);
        buildingLibraryInfoText = (TextView) findViewById(R.id.building_music_library_info);
        buildingLibraryLayout = (RelativeLayout) findViewById(R.id.building_music_library_layout);

        buildingLibraryInfoText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryInfoText.setPaintFlags(
                buildingLibraryInfoText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryMainText.setPaintFlags(
                buildingLibraryMainText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setText(R.string.jams_is_caching_artwork);
        initScanProcess(0);

    } else if ((mApp.getSharedPreferences().getBoolean("REBUILD_LIBRARY", false) == true)
            || (scanFrequency == 0 && mApp.isScanFinished() == false)
            || (scanFrequency == 1 && mApp.isScanFinished() == false && updatedStartCount % 3 == 0)
            || (scanFrequency == 2 && mApp.isScanFinished() == false && updatedStartCount % 5 == 0)
            || (scanFrequency == 3 && mApp.isScanFinished() == false && updatedStartCount % 10 == 0)
            || (scanFrequency == 4 && mApp.isScanFinished() == false && updatedStartCount % 20 == 0)) {

        buildingLibraryMainText = (TextView) findViewById(R.id.building_music_library_text);
        buildingLibraryInfoText = (TextView) findViewById(R.id.building_music_library_info);
        buildingLibraryLayout = (RelativeLayout) findViewById(R.id.building_music_library_layout);

        buildingLibraryInfoText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryInfoText.setPaintFlags(
                buildingLibraryInfoText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryMainText.setPaintFlags(
                buildingLibraryMainText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        initScanProcess(1);

    } else {

        //Check if this activity was called from Settings.
        if (getIntent().hasExtra("UPGRADE")) {
            if (getIntent().getExtras().getBoolean("UPGRADE") == true) {
                mExplicitShowTrialFragment = true;
            } else {
                mExplicitShowTrialFragment = false;
            }

        }

        //initInAppBilling();
        launchMainActivity();
    }

    //Fire away a report to Google Analytics.
    try {
        if (mApp.isGoogleAnalyticsEnabled() == true) {
            EasyTracker easyTracker = EasyTracker.getInstance(this);
            easyTracker.send(MapBuilder.createEvent("Jams startup.", // Event category (required)
                    "User started Jams.", // Event action (required)
                    "User started Jams.", // Event label
                    null) // Event value
                    .build());
        }

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

}

From source file:com.jams.music.player.LauncherActivity.LauncherActivity.java

@SuppressLint("NewApi")
@Override/*from   w  w w . j  a va2  s .  c  o  m*/
public void onCreate(Bundle savedInstanceState) {

    setTheme(R.style.AppThemeNoActionBar);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_launcher);

    mContext = this;
    mActivity = this;
    mApp = (Common) mContext.getApplicationContext();
    mHandler = new Handler();

    //Increment the start count. This value will be used to determine when the library should be rescanned.
    int startCount = mApp.getSharedPreferences().getInt("START_COUNT", 1);
    mApp.getSharedPreferences().edit().putInt("START_COUNT", startCount + 1).commit();

    //Save the dimensions of the layout for later use on KitKat devices.
    final RelativeLayout launcherRootView = (RelativeLayout) findViewById(R.id.launcher_root_view);
    launcherRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {

            try {

                int screenDimens[] = new int[2];
                int screenHeight = 0;
                int screenWidth = 0;
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
                    //API levels 14, 15 and 16.
                    screenDimens = getTrueDeviceResolution();
                    screenWidth = screenDimens[0];
                    screenHeight = screenDimens[1];

                } else {
                    //API levels 17+.
                    Display display = getWindowManager().getDefaultDisplay();
                    DisplayMetrics metrics = new DisplayMetrics();
                    display.getRealMetrics(metrics);
                    screenHeight = metrics.heightPixels;
                    screenWidth = metrics.widthPixels;

                }

                int layoutHeight = launcherRootView.getHeight();
                int layoutWidth = launcherRootView.getWidth();

                int extraHeight = screenHeight - layoutHeight;
                int extraWidth = screenWidth = layoutWidth;

                mApp.getSharedPreferences().edit().putInt("KITKAT_HEIGHT", layoutHeight).commit();
                mApp.getSharedPreferences().edit().putInt("KITKAT_WIDTH", layoutWidth).commit();
                mApp.getSharedPreferences().edit().putInt("KITKAT_HEIGHT_LAND", layoutWidth - extraHeight)
                        .commit();
                mApp.getSharedPreferences().edit().putInt("KITKAT_WIDTH_LAND", screenHeight).commit();

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

        }

    });

    //Build the music library based on the user's scan frequency preferences.
    int scanFrequency = mApp.getSharedPreferences().getInt("SCAN_FREQUENCY", 5);
    int updatedStartCount = mApp.getSharedPreferences().getInt("START_COUNT", 1);

    //Launch the appropriate activity based on the "FIRST RUN" flag.
    if (mApp.getSharedPreferences().getBoolean(Common.FIRST_RUN, true) == true) {

        //Create the default Playlists directory if it doesn't exist.
        File playlistsDirectory = new File(Environment.getExternalStorageDirectory() + "/Playlists/");
        if (!playlistsDirectory.exists() || !playlistsDirectory.isDirectory()) {
            playlistsDirectory.mkdir();
        }

        //Disable equalizer for HTC devices by default.
        if (mApp.getSharedPreferences().getBoolean(Common.FIRST_RUN, true) == true
                && Build.PRODUCT.contains("HTC")) {
            mApp.getSharedPreferences().edit().putBoolean("EQUALIZER_ENABLED", false).commit();
        }

        //Send out a test broadcast to initialize the homescreen/lockscreen widgets.
        sendBroadcast(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME));

        Intent intent = new Intent(this, WelcomeActivity.class);
        startActivity(intent);
        overridePendingTransition(R.anim.fade_in, R.anim.fade_out);

    } else if (mApp.isBuildingLibrary()) {
        buildingLibraryMainText = (TextView) findViewById(R.id.building_music_library_text);
        buildingLibraryInfoText = (TextView) findViewById(R.id.building_music_library_info);
        buildingLibraryLayout = (RelativeLayout) findViewById(R.id.building_music_library_layout);

        buildingLibraryInfoText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryInfoText.setPaintFlags(
                buildingLibraryInfoText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryMainText.setPaintFlags(
                buildingLibraryMainText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setText(R.string.jams_is_building_library);
        buildingLibraryLayout.setVisibility(View.VISIBLE);

        //Initialize the runnable that will fire once the scan process is complete.
        mHandler.post(scanFinishedCheckerRunnable);

    } else if (mApp.getSharedPreferences().getBoolean("RESCAN_ALBUM_ART", false) == true) {

        buildingLibraryMainText = (TextView) findViewById(R.id.building_music_library_text);
        buildingLibraryInfoText = (TextView) findViewById(R.id.building_music_library_info);
        buildingLibraryLayout = (RelativeLayout) findViewById(R.id.building_music_library_layout);

        buildingLibraryInfoText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryInfoText.setPaintFlags(
                buildingLibraryInfoText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryMainText.setPaintFlags(
                buildingLibraryMainText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setText(R.string.jams_is_caching_artwork);
        initScanProcess(0);

    } else if ((mApp.getSharedPreferences().getBoolean("REBUILD_LIBRARY", false) == true)
            || (scanFrequency == 0 && mApp.isScanFinished() == false)
            || (scanFrequency == 1 && mApp.isScanFinished() == false && updatedStartCount % 3 == 0)
            || (scanFrequency == 2 && mApp.isScanFinished() == false && updatedStartCount % 5 == 0)
            || (scanFrequency == 3 && mApp.isScanFinished() == false && updatedStartCount % 10 == 0)
            || (scanFrequency == 4 && mApp.isScanFinished() == false && updatedStartCount % 20 == 0)) {

        buildingLibraryMainText = (TextView) findViewById(R.id.building_music_library_text);
        buildingLibraryInfoText = (TextView) findViewById(R.id.building_music_library_info);
        buildingLibraryLayout = (RelativeLayout) findViewById(R.id.building_music_library_layout);

        buildingLibraryInfoText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryInfoText.setPaintFlags(
                buildingLibraryInfoText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryMainText.setPaintFlags(
                buildingLibraryMainText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        initScanProcess(1);

    } else {

        //Check if this activity was called from Settings.
        if (getIntent().hasExtra("UPGRADE")) {
            if (getIntent().getExtras().getBoolean("UPGRADE") == true) {
                mExplicitShowTrialFragment = true;
            } else {
                mExplicitShowTrialFragment = false;
            }

        }

        //initInAppBilling();
        launchMainActivity();
    }

    //Fire away a report to Google Analytics.
    try {
        if (mApp.isGoogleAnalyticsEnabled() == true) {
            EasyTracker easyTracker = EasyTracker.getInstance(this);
            easyTracker.send(MapBuilder.createEvent("Genesis Music startup.", // Event category (required)
                    "User started Genesis Music.", // Event action (required)
                    "User started Genesis Music.", // Event label
                    null) // Event value
                    .build());
        }

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

}

From source file:com.nike.plusgps.nikeplusgallery.MainActivity.java

/**
 * Handles the screen layouts based on the orientation.
 * The activity is not restarted when the orientation changes.
 *//* w  w  w .  ja  v a2s  . c  o  m*/
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    // In Portrait mode the grid view is displayed
    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {

        setContentView(R.layout.activity_main_port);
        GridView view = (GridView) findViewById(R.id.gridView);
        adapter = new FlickrFeedAdapter(getApplicationContext(), R.layout.single_elem_port, flickrFeedList,
                dbHelper, mMemoryCache);
        view.setAdapter(adapter);

    } else { // In Landscape mode the carousel view is displayed

        setContentView(R.layout.activity_main_land);
        carouselElement = (LinearLayout) findViewById(R.id.carousel);
        // Compute width of a carousel item based on screen width and initial item count
        final DisplayMetrics displayMetrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
        final int imageWidth = (int) (displayMetrics.widthPixels / INITIAL_ITEMS_COUNT);

        // Fetches image url from SQLite cache
        ImageView imageItem;
        String imgURL;
        for (int i = 0; i < flickrFeedList.size(); ++i) {
            imageItem = new ImageView(this);
            imgURL = flickrFeedList.get(i).getMedia();
            new DownloadImageTask(imageItem).execute(imgURL);
            imageItem.setLayoutParams(new LinearLayout.LayoutParams(imageWidth, imageWidth));
            carouselElement.addView(imageItem);
        }
    }
}