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.kraker.myocmd.TestService1.DeviceControlActivity.java

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

    setContentView(R.layout.device_control);
    mTitle = mDrawerTitle = getTitle();/*from   ww w  .  j a v  a 2  s .  com*/
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    if (toolbar != null) {
        //setSupportActionBar(toolbar);
    }

    final Intent intent = getIntent();
    String mDeviceName = intent.getStringExtra(EXTRAS_DEVICE_NAME);
    mDeviceAddress = intent.getStringExtra(EXTRAS_DEVICE_ADDRESS);
    Intent gattServiceIntent = new Intent(this, BluetoothLeService.class);
    bindService(gattServiceIntent, mServiceConnection, BIND_AUTO_CREATE);
    mHandler = new android.os.Handler();
    mHandler.postDelayed(mStatusChecker, 5000);
    DisplayMetrics metrics = new DisplayMetrics();
}

From source file:com.playhaven.android.req.PlayHavenRequest.java

@SuppressWarnings("deprecation")
protected UriComponentsBuilder createUrl(Context context) throws PlayHavenException {
    try {/*w w w  . j  a  v  a 2  s .co  m*/
        SharedPreferences pref = PlayHaven.getPreferences(context);

        UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(getString(pref, APIServer));
        builder.path(context.getResources().getString(getApiPath(context)));
        builder.queryParam("app", getString(pref, AppPkg));
        builder.queryParam("opt_out", getString(pref, OptOut, "0"));
        builder.queryParam("app_version", getString(pref, AppVersion));
        builder.queryParam("os", getInt(pref, OSVersion, 0));
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        builder.queryParam("orientation", display.getRotation());
        builder.queryParam("hardware", getString(pref, DeviceModel));
        PlayHaven.ConnectionType connectionType = getConnectionType(context);
        builder.queryParam("connection", connectionType.ordinal());
        builder.queryParam("idiom",
                context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK);

        /**
         * For height/width we will use getSize(Point) not getRealSize(Point) as this will allow us to automatically
         * account for rotation and screen decorations like the status bar. We only want to know available space.
         *
         * @playhaven.apihack for SDK_INT < 13, have to use getHeight and getWidth!
         */
        Point size = new Point();
        if (Build.VERSION.SDK_INT >= 13) {
            display.getSize(size);
        } else {
            size.x = display.getWidth();
            size.y = display.getHeight();
        }
        builder.queryParam("width", size.x);
        builder.queryParam("height", size.y);

        /**
         * SDK Version needs to be reported as a dotted numeric value
         * So, if it is a -SNAPSHOT build, we will replace -SNAPSHOT with the date of the build
         * IE: 2.0.0.20130201
         * as opposed to an actual released build, which would be like 2.0.0
         */
        String sdkVersion = getString(pref, SDKVersion);
        String[] date = Version.PLUGIN_BUILD_TIME.split("[\\s]");
        sdkVersion = sdkVersion.replace("-SNAPSHOT", "." + date[0].replaceAll("-", ""));
        builder.queryParam("sdk_version", sdkVersion);

        builder.queryParam("plugin", getString(pref, PluginIdentifer));

        Locale locale = context.getResources().getConfiguration().locale;
        builder.queryParam("languages", String.format("%s,%s", locale.toString(), locale.getLanguage()));
        builder.queryParam("token", getString(pref, Token));

        builder.queryParam("device", getString(pref, DeviceId));
        DisplayMetrics metrics = new DisplayMetrics();
        display.getMetrics(metrics);
        builder.queryParam("dpi", metrics.densityDpi);

        String uuid = UUID.randomUUID().toString();
        String nonce = base64Digest(uuid);
        builder.queryParam("nonce", nonce);

        ktsid = KontagentUtil.getSenderId(context);
        if (ktsid != null)
            builder.queryParam("sid", ktsid);

        addSignature(builder, pref, nonce);

        // Setup for signature verification
        String secret = getString(pref, Secret);
        SecretKeySpec key = new SecretKeySpec(secret.getBytes(UTF8), HMAC);
        sigMac = Mac.getInstance(HMAC);
        sigMac.init(key);
        sigMac.update(nonce.getBytes(UTF8));

        return builder;
    } catch (Exception e) {
        throw new PlayHavenException(e);
    }
}

From source file:com.mk4droid.IMC_Activities.Fragment_Comments.java

private Resources setResources() {
    SharedPreferences mshPrefs = PreferenceManager.getDefaultSharedPreferences(ctx);
    LangSTR = mshPrefs.getString("LanguageAR", Constants_API.DefaultLanguage);
    UserNameSTR = mshPrefs.getString("UserNameAR", "");
    PasswordSTR = mshPrefs.getString("PasswordAR", "");
    IssuesNoSTR = mshPrefs.getString("IssuesNoAR", "40");
    AuthFlag = mshPrefs.getBoolean("AuthFlag", false);

    if (!Service_Data.HasInternet)
        AuthFlag = false;//from w  ww.  j av  a 2 s .c om

    UserID_STR = mshPrefs.getString("UserID_STR", "");

    Configuration conf = getResources().getConfiguration();
    conf.locale = new Locale(LangSTR.substring(0, 2)); //----- Convert Greek -> el ---------
    metrics = new DisplayMetrics();
    getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
    return new Resources(getActivity().getAssets(), metrics, conf);
}

From source file:com.paramonod.kikos.MainActivity.java

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

    FirebaseDatabase.getInstance().setPersistenceEnabled(true);
    myRef = FirebaseDatabase.getInstance().getReference("Shops");
    //ShopInterface shopInterface = new ShopInterface("asas","qaqa","wdwdwd","12","11","11");
    //myRef.child("Shops").child("1").setValue(shopInterface);
    //mAuth.signInAnonymously();
    myRef.keepSynced(true);//from  ww  w. j  a v a  2s .co  m
    myRef.orderByValue().addChildEventListener(new ChildEventListener() {
        @Override
        public void onChildAdded(DataSnapshot snapshot, String previousChild) {
            Log.e("here", Integer.toString(shopInterfaces.size() - 1));
            shopInterfaces.add(snapshot.getValue(ShopInterface.class));
            Log.e("here", Integer.toString(shopInterfaces.size() - 1));
            main.setupMap();
            //System.out.println(shopInterfaces.get(1).getCoordX());
        }

        @Override
        public void onChildChanged(DataSnapshot dataSnapshot, String s) {

        }

        @Override
        public void onChildRemoved(DataSnapshot dataSnapshot) {

        }

        @Override
        public void onChildMoved(DataSnapshot dataSnapshot, String s) {

        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });
    //mAuth.signOut();
    main = this;
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    toolbar.setTitle("OrgShop");
    DisplayMetrics displaymetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    final Display display = getWindowManager().getDefaultDisplay();
    android.graphics.Point size = new android.graphics.Point();
    display.getSize(size);
    X = size.x;
    Y = size.y;
    //  Y = displaymetrics.heightPixels;
    //  X = displaymetrics.widthPixels;
    System.out.println(X + " " + Y);
    // Adding Toolbar to Main screen
    int ii = 0;
    places.clear();
    while (true) {
        String connectionsJSONString = getPreferences(MODE_PRIVATE).getString("places" + ii, null);
        Pair p = new Gson().fromJson(connectionsJSONString, Pair.class);
        if (p != null)
            places.add(p);
        else
            break;
        ii++;
    }
    placesIDX = ii;
    bottomNavigationView = (BottomNavigationView) findViewById(R.id.navigation);

    Manager.findFragmentById(R.id.fragment1);

    bottomNavigationView
            .setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
                @Override
                public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                    //AsyncTask asyncTask = new NewAsyncTask();
                    switch (item.getItemId()) {
                    case R.id.Map:
                        //     Manager.beginTransaction()
                        //             .replace(R.id.fragment1, PrFr)
                        //             .commit();
                        Manager.beginTransaction().replace(R.id.fragment1, MapFr).addToBackStack("Map")
                                .commit();
                        //asyncTask.execute(R.id.Map);
                        break;
                    case R.id.Shops:
                        //     Manager.beginTransaction()
                        //            .replace(R.id.fragment1, PrFr)
                        //            .commit();

                        //  Listfr.flag = 0;
                        Manager.beginTransaction().replace(R.id.fragment1, CatFr).addToBackStack("Categories")
                                .commit();
                        //x = R.id.Shops;
                        //asyncTask.execute();
                        break;
                    case R.id.Third:
                        //    Manager.beginTransaction()
                        //           .replace(R.id.fragment1, PrFr)
                        //           .commit();
                        //     Manager.beginTransaction()
                        //             .replace(R.id.fragment1, PrFr)
                        //             .commit();
                        //      System.out.println(0);
                        int idx[] = new int[shopInterfaces.size()];
                        for (int i = 0; i < idx.length; i++) {
                            idx[i] = i;
                        }
                        try {
                            updateMyLoc();
                            idx = sortArraywithGeo(idx, myLoc);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        CardContentFragment.flag = 1;
                        CardContentFragment.idx = idx;
                        Manager.beginTransaction().replace(R.id.fragment1, Cardfr).addToBackStack(null)
                                .commit();
                        //new ImageLoad().execute();
                        //while (AsyncTest == 0){}
                        //System.out.println(1);
                        //Picturex();
                        //AsyncTest = -1;
                        /* Manager.beginTransaction()
                                  .replace(R.id.fragment1, Listfr)
                                  .commit();
                        */
                        // asyncTask.execute(R.id.Third);
                        break;
                    }
                    return false;
                }
            });

    // Setting ViewPager for each Tabs

    // Set Tabs inside Toolbar
    // Create Navigation drawer and inlfate layout

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer);
    // Adding menu icon to Toolbar
    ActionBar supportActionBar = getSupportActionBar();
    if (supportActionBar != null) {
        VectorDrawableCompat indicator = VectorDrawableCompat.create(getResources(), R.drawable.ic_menu,
                getTheme());
        indicator.setTint(ResourcesCompat.getColor(getResources(), R.color.white, getTheme()));
        supportActionBar.setHomeAsUpIndicator(indicator);
        supportActionBar.setDisplayHomeAsUpEnabled(true);
    }
    //Set behavior of Navigation drawer
    navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setCheckedItem(R.id.mapButton);
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        // This method will trigger on item Click of navigation menu
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            // Set item in checked state
            menuItem.setChecked(true);
            if (menuItem.getItemId() == R.id.favorite_button) {
                sPref = getPreferences(MODE_PRIVATE);
                String savedText = sPref.getString("q", "");
                boolean w = true;
                for (int i = 0; i < 10; i++) {
                    if (savedText.contains(Integer.toString(i))) {
                        w = false;
                    }
                }
                if (w) {
                    Toast.makeText(main, " ?     ",
                            Toast.LENGTH_LONG).show();
                    SharedPreferences.Editor editor = getPreferences(MODE_PRIVATE).edit();
                    editor.putString("q", "");
                    editor.commit();
                } else {
                    String[] q = savedText.split(" ");
                    int[] a = new int[q.length];
                    for (int i = 0; i < q.length; i++) {
                        a[i] = Integer.parseInt(q[i]);
                        System.out.println(a[i]);
                    }
                    try {
                        updateMyLoc();
                        a = sortArraywithGeo(a, myLoc);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    ListContentFragment l = new ListContentFragment();
                    l.flag = 1;
                    l.idx = a;
                    //  Manager.beginTransaction()
                    //          .replace(R.id.fragment1, PrFr)
                    //          .commit();
                    Manager.beginTransaction().replace(R.id.fragment1, l).addToBackStack("favorite").commit();
                }
            }
            if (menuItem.getItemId() == R.id.mapButton) {
                //  Manager.beginTransaction()
                //          .replace(R.id.fragment1, PrFr)
                //          .commit();
                Manager.beginTransaction().replace(R.id.fragment1, MapFr).addToBackStack("map").commit();
            }
            if (menuItem.getItemId() == R.id.clear_button) {
                AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                builder.setTitle("").setMessage(
                        "? ? ?? ? ? aka KiKoS,   aka paramomnod")
                        .setIcon(R.drawable.itkerk).setCancelable(false)
                        .setNegativeButton("    :)",
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int id) {
                                        dialog.cancel();
                                    }
                                });
                AlertDialog alert = builder.create();
                alert.show();

            }
            if (menuItem.getItemId() == R.id.login_button) {
                int ii = 0;
                places.clear();
                while (true) {
                    String connectionsJSONString = getPreferences(MODE_PRIVATE).getString("places" + ii, null);
                    Pair p = new Gson().fromJson(connectionsJSONString, Pair.class);
                    if (p != null)
                        places.add(p);
                    else
                        break;
                    ii++;
                }
                if (places.size() == 0) {
                    Toast.makeText(main, " ?   ?",
                            Toast.LENGTH_LONG).show();
                } else {
                    String q[] = new String[places.size()];
                    for (int i = 0; i < q.length; i++) {
                        q[i] = places.get(i).first;
                    }
                    new AlertDialog.Builder(main).setSingleChoiceItems(q, 0, null)
                            .setPositiveButton("", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int whichButton) {
                                    dialog.dismiss();
                                    int selectedPosition = ((AlertDialog) dialog).getListView()
                                            .getCheckedItemPosition();
                                    Pair p = places.get(selectedPosition);
                                    GeoPoint geo = p.second;
                                    int[] idx = new int[shopInterfaces.size()];
                                    for (int i = 0; i < idx.length; i++) {
                                        idx[i] = i;
                                    }
                                    idx = sortArraywithGeo(idx, geo);
                                    CardContentFragment c = new CardContentFragment();
                                    CardContentFragment.flag = 1;
                                    CardContentFragment.idx = idx;
                                    Manager.beginTransaction().replace(R.id.fragment1, c).addToBackStack("map")
                                            .commit();
                                }
                            }).setNegativeButton("", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                    int selectedPosition = ((AlertDialog) dialog).getListView()
                                            .getCheckedItemPosition();
                                    places.remove(selectedPosition);
                                    placesIDX--;
                                    for (int i = 0; i < placesIDX; i++) {
                                        SharedPreferences.Editor editor = getPreferences(MODE_PRIVATE).edit();
                                        String connectionsJSONString1 = new Gson().toJson(places.get(i));
                                        editor.putString("places" + i, connectionsJSONString1);
                                        editor.commit();
                                    }
                                    SharedPreferences.Editor editor = getPreferences(MODE_PRIVATE).edit();
                                    editor.putString("places" + placesIDX, null);
                                    editor.commit();
                                }
                            }).show();
                }
            }
            /*       if (menuItem.getItemId() == R.id.login_button) {
                    if (mAuth.getCurrentUser() == null) {
                        startActivity(new Intent(MainActivity.this, LoginActivity.class));
                    } else {
                        startActivity(new Intent(MainActivity.this, AccountActivity.class));
                    }
                    
                }
            */ // Closing drawer on item click
            mDrawerLayout.closeDrawers();
            return true;
        }
    });

    // Adding Floating Action Button to bottom right of main view
    /*FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Snackbar.make(v, "Hello Snackbar!",
                Snackbar.LENGTH_LONG).show();
    }
    });*/
    Manager.beginTransaction().replace(R.id.fragment1, MapFr).commit();
}

From source file:com.eyekabob.EventInfo.java

private void handleImageResponse(Bitmap img) {
    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    float metWidth = metrics.widthPixels;
    float imgWidth = img.getWidth();
    float ratio = metWidth / imgWidth;
    // Add a little buffer room
    int newWidth = (int) Math.floor(img.getWidth() * ratio) - 50;
    int newHeight = (int) Math.floor(img.getHeight() * ratio) - 50;

    ImageView iv = (ImageView) findViewById(R.id.infoImageView);
    Bitmap rescaledImg = Bitmap.createScaledBitmap(img, newWidth, newHeight, false);
    iv.setImageBitmap(rescaledImg);//from  w w w.j a  va2  s  .  c om
}

From source file:com.kaltura.playersdk.PlayerViewController.java

@SuppressLint("NewApi")
private Point getRealScreenSize() {
    Display display = mActivity.getWindowManager().getDefaultDisplay();
    int realWidth = 0;
    int realHeight = 0;

    if (Build.VERSION.SDK_INT >= 17) {
        //new pleasant way to get real metrics
        DisplayMetrics realMetrics = new DisplayMetrics();
        display.getRealMetrics(realMetrics);
        realWidth = realMetrics.widthPixels;
        realHeight = realMetrics.heightPixels;

    } else {/*from w w  w  . j  ava2s . c o m*/
        try {
            Method mGetRawH = Display.class.getMethod("getRawHeight");
            Method mGetRawW = Display.class.getMethod("getRawWidth");
            realWidth = (Integer) mGetRawW.invoke(display);
            realHeight = (Integer) mGetRawH.invoke(display);
        } catch (Exception e) {
            realWidth = display.getWidth();
            realHeight = display.getHeight();
            Log.e("Display Info", "Couldn't use reflection to get the real display metrics.");
        }

    }
    return new Point(realWidth, realHeight);
}

From source file:cm.aptoide.pt.Aptoide.java

private void proceed() {
    if (sPref.getInt("version", 0) < pkginfo.versionCode) {
        db.UpdateTables();/* w  ww.  ja  va2 s . co  m*/
        prefEdit.putBoolean("mode", true);
        prefEdit.putInt("version", pkginfo.versionCode);
        prefEdit.commit();
    }

    if (sPref.getString("myId", null) == null) {
        String rand_id = UUID.randomUUID().toString();
        prefEdit.putString("myId", rand_id);
        prefEdit.commit();
    }

    if (sPref.getInt("scW", 0) == 0 || sPref.getInt("scH", 0) == 0) {
        DisplayMetrics dm = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);
        prefEdit.putInt("scW", dm.widthPixels);
        prefEdit.putInt("scH", dm.heightPixels);
        prefEdit.commit();
    }

    if (sPref.getString("icdown", null) == null) {
        prefEdit.putString("icdown", "g3w");
        prefEdit.commit();
    }

    setContentView(R.layout.start);

    mProgress = (ProgressBar) findViewById(R.id.pbar);

    new Thread(new Runnable() {
        public void run() {

            Vector<ApkNode> apk_lst = db.getAll("abc");
            mProgress.setMax(apk_lst.size());
            PackageManager mPm;
            PackageInfo pkginfo;
            mPm = getPackageManager();

            keepScreenOn.acquire();

            for (ApkNode node : apk_lst) {
                if (node.status == 0) {
                    try {
                        pkginfo = mPm.getPackageInfo(node.apkid, 0);
                        String vers = pkginfo.versionName;
                        int verscode = pkginfo.versionCode;
                        db.insertInstalled(node.apkid, vers, verscode);
                    } catch (Exception e) {
                        //Not installed anywhere... does nothing
                    }
                } else {
                    try {
                        pkginfo = mPm.getPackageInfo(node.apkid, 0);
                        String vers = pkginfo.versionName;
                        int verscode = pkginfo.versionCode;
                        db.UpdateInstalled(node.apkid, vers, verscode);
                    } catch (Exception e) {
                        db.removeInstalled(node.apkid);
                    }
                }
                mProgressStatus++;
                // Update the progress bar
                mHandler.post(new Runnable() {
                    public void run() {
                        mProgress.setProgress(mProgressStatus);
                    }
                });
            }

            keepScreenOn.release();

            Message msg = new Message();
            msg.what = LOAD_TABS;
            startHandler.sendMessage(msg);

        }
    }).start();
}

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

/**
 * Afficher une boite au milieu de la carte si aucun utilisateur est connects
 * pour proposer a l'invit, de se connecter ou s'incrire aupres du service LTP.
 *//*from  w w w.j  av  a 2  s  .c om*/
public final void popupGuest() {
    DisplayMetrics dm = new DisplayMetrics();
    this.activity.getWindowManager().getDefaultDisplay().getMetrics(dm);

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

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

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

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

    // Crer le PopupWindow
    final PopupWindow popupGuest = new PopupWindow(layout, popupWidth, LayoutParams.WRAP_CONTENT, true);
    popupGuest.setBackgroundDrawable(new BitmapDrawable());
    popupGuest.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() {
            popupGuest.showAtLocation(layout, Gravity.CENTER, OFFSET_X, OFFSET_Y);
        }
    });

    /*
     * Evenements composants du PopupWindow
     */

    // Ecouteur d'vnement sur le bouton des paramtres
    Button btLogin = (Button) layout.findViewById(R.id.btnPopupLogin);
    btLogin.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            // La constante CODE_MON_ACTIVITE reprsente lidentifiant de la requte
            // (requestCode) qui sera utilis plus tard pour identifier lactivit
            // renvoyant la valeur de retour.
            Intent i = new Intent(activity, LoginActivity.class);
            activity.startActivityForResult(i, 1);

            popupGuest.dismiss();
        }
    });

    // Ecouteur d'vnement sur le bouton des paramtres
    Button btSignup = (Button) layout.findViewById(R.id.btnPopupSignup);
    btSignup.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            // La constante CODE_MON_ACTIVITE reprsente lidentifiant de la requte
            // (requestCode) qui sera utilis plus tard pour identifier lactivit
            // renvoyant la valeur de retour.
            Intent i = new Intent(activity, SignupActivity.class);
            activity.startActivityForResult(i, 3);

            popupGuest.dismiss();
        }
    });

    // Ecouteur d'vnement sur le bouton pour fermer l'application
    Button close = (Button) layout.findViewById(R.id.btnPopupClose);
    close.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            popupGuest.dismiss();
        }
    });
}

From source file:com.freshplanet.nativeExtensions.C2DMBroadcastReceiver.java

private boolean recurseGroup(Context context, ViewGroup gp) {
    final int count = gp.getChildCount();
    for (int i = 0; i < count; ++i) {
        if (gp.getChildAt(i) instanceof TextView) {
            final TextView text = (TextView) gp.getChildAt(i);
            final String szText = text.getText().toString();
            if (COLOR_SEARCH_RECURSE_TIP.equals(szText)) {
                notification_text_color = text.getTextColors().getDefaultColor();
                notification_text_size = text.getTextSize();
                DisplayMetrics metrics = new DisplayMetrics();
                WindowManager systemWM = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
                systemWM.getDefaultDisplay().getMetrics(metrics);
                notification_text_size /= metrics.scaledDensity;
                return true;
            }//  w w  w. j a va 2 s .  com
        } else if (gp.getChildAt(i) instanceof ViewGroup)
            return recurseGroup((Context) context, (ViewGroup) gp.getChildAt(i));
    }
    return false;
}