Example usage for android.view Display getSize

List of usage examples for android.view Display getSize

Introduction

In this page you can find the example usage for android.view Display getSize.

Prototype

public void getSize(Point outSize) 

Source Link

Document

Gets the size of the display, in pixels.

Usage

From source file:fr.cph.chicago.activity.MainActivity.java

private void displayUpdatePanel() {
    try {/*from ww w.  ja  v a2s  . com*/
        String versionName = this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionName;
        SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
        String versionNamePreferences = sharedPref.getString("version.name", null);
        if (versionNamePreferences == null || !versionNamePreferences.equals(versionName)) {
            SharedPreferences.Editor editor = sharedPref.edit();
            editor.putString("version.name", versionName);
            editor.commit();

            final Dialog dialog = new Dialog(this);
            dialog.setContentView(R.layout.update);
            dialog.setTitle("Update");

            InputStreamReader is = new InputStreamReader(
                    ChicagoTracker.getAppContext().getAssets().open("update.txt"));
            BufferedReader br = new BufferedReader(is);
            String read = br.readLine();
            StringBuilder sb = new StringBuilder();
            while (read != null) {
                sb.append(read + "\n");
                read = br.readLine();
            }

            TextView text = (TextView) dialog.findViewById(R.id.updateText);
            text.setText(sb.toString());

            Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
            dialogButton.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                }
            });

            Display display = getWindowManager().getDefaultDisplay();
            Point size = new Point();
            display.getSize(size);
            int width = size.x;
            int newWidth = width - (width * 20 / 100);
            int height = size.y;
            int newHeight = height - (height * 20 / 100);

            dialog.getWindow().setLayout(newWidth, newHeight);

            dialog.show();
        }

    } catch (NameNotFoundException e) {
        Log.w(TAG, e.getMessage(), e);
    } catch (IOException e) {
        Log.w(TAG, e.getMessage(), e);
    }
}

From source file:org.deviceconnect.android.deviceplugin.host.camera.CameraOverlay.java

/**
 * Display???./*  ww w  .j a  v  a2 s  . c om*/
 *
 * @return 
 */
private Point getDisplaySize() {
    Display disp = mWinMgr.getDefaultDisplay();
    Point size = new Point();
    disp.getSize(size);
    return size;
}

From source file:org.gots.allotment.adapter.ListAllotmentAdapter.java

@SuppressWarnings("deprecation")
@Override//from   www  . ja va  2 s.  c  o m
public View getView(final int position, View convertView, ViewGroup parent) {
    LinearLayout ll = (LinearLayout) convertView;
    Holder holder;
    if (ll == null) {
        holder = new Holder();
        ll = (LinearLayout) LayoutInflater.from(mContext).inflate(R.layout.list_allotments, parent, false);
        if (GotsPreferences.DEBUG) {
            TextView textView = new TextView(mContext);
            textView.setText("(" + getItem(position).getId() + ")" + getItem(position).getUUID());
            ll.addView(textView);
        }

        holder.listSeeds = (GridView) ll.findViewById(R.id.IdGrowingSeedList);
        holder.titlebar = (LinearLayout) ll.findViewById(R.id.idAllotmentTitlebar);
        holder.allotmentName = (TextView) ll.findViewById(R.id.textAllotmentName);
        holder.menu = (LinearLayout) ll.findViewById(R.id.idAllotmentMenu);

        holder.allotment = getItem(position);
        ll.setTag(holder);
        ll.setDescendantFocusability(LinearLayout.FOCUS_BLOCK_DESCENDANTS);
        // ll.setOnClickListener(this);

    } else
        holder = (Holder) ll.getTag();

    WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    int width;
    int sdk = android.os.Build.VERSION.SDK_INT;
    if (sdk < android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        width = display.getWidth();
    } else {
        Point size = new Point();
        display.getSize(size);
        width = size.x;
    }
    int layoutsize = 150;
    if (width <= 480)
        layoutsize = 50;
    int nbcolumn = (width - 200) / layoutsize;
    if (nbcolumn < 1)
        nbcolumn = 1;
    holder.listSeeds.setNumColumns(nbcolumn);

    listGrowingSeedAdapter = new ListGrowingSeedAdapter(mContext, getItem(position).getSeeds());
    holder.listSeeds.setAdapter(listGrowingSeedAdapter);
    holder.listSeeds.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, layoutsize));
    if (listGrowingSeedAdapter.getCount() > 0) {
        holder.listSeeds.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                (holder.listSeeds.getCount() / nbcolumn + 1) * layoutsize + layoutsize));
        // holder.listSeeds.setLayoutParams(new
        // LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
        // LayoutParams.WRAP_CONTENT));
    }
    // else
    // holder.listSeeds.setLayoutParams(new
    // LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
    // ((holder.listSeeds.getCount() / nbcolumn) + 1) * layoutsize));

    holder.allotmentName.setText(getItem(position).getName());

    // holder.titlebar.removeAllViews();

    holder.menu.setTag(holder);
    holder.menu.setOnClickListener(this);
    // SowingAction sow = new SowingAction(mContext);
    // ActionWidget widget = new ActionWidget(mContext, sow);
    // widget.setTag(position);

    if (isSelectable) {
        holder.menu.setBackgroundResource(R.anim.rotate_alerte);
        // Animation myFadeInAnimation =
        // AnimationUtils.loadAnimation(mContext, R.anim.rotate_alerte);
        // menu.startAnimation(myFadeInAnimation);
        AnimationDrawable frameAnimation = (AnimationDrawable) holder.menu.getBackground();
        frameAnimation.start();
        holder.menu.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                new AsyncTask<Void, Integer, GrowingSeedInterface>() {
                    @Override
                    protected GrowingSeedInterface doInBackground(Void... params) {

                        GotsGrowingSeedManager growingSeedManager = GotsGrowingSeedManager.getInstance()
                                .initIfNew(mContext);
                        GotsSeedManager seedManager = GotsSeedManager.getInstance().initIfNew(mContext);
                        // NuxeoGrowingSeedProvider provider = new
                        // NuxeoGrowingSeedProvider(mContext);
                        GrowingSeedInterface growingSeed = (GrowingSeedInterface) seedManager
                                .getSeedById(currentSeedId);
                        growingSeed.setDateSowing(Calendar.getInstance().getTime());

                        return growingSeedManager.plantingSeed(growingSeed, getItem(position));
                    }

                    @Override
                    protected void onPostExecute(GrowingSeedInterface seed) {
                        // notifyDataSetChanged();
                        Toast.makeText(mContext, "Sowing" + " " + SeedUtil.translateSpecie(mContext, seed),
                                Toast.LENGTH_LONG).show();
                        mContext.sendBroadcast(new Intent(BroadCastMessages.SEED_DISPLAYLIST));
                        ((Activity) mContext).finish();
                    }
                }.execute();
            }
        });
    }

    // widget.setPadding(4, 4, 4, 8);
    // holder.menu.addView(widget);

    // // SowingAction sow = new SowingAction(mContext);
    // ImageView widgetSensor = new ImageView(mContext);
    // widgetSensor.setImageDrawable(mContext.getResources().getDrawable(R.drawable.ic_sensor));
    // widgetSensor.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.action_selector));
    // widgetSensor.setTag(position);
    // widgetSensor.setOnClickListener(new View.OnClickListener() {
    //
    // @Override
    // public void onClick(View v) {
    //
    // GotsPurchaseItem purchaseItem = new GotsPurchaseItem(mContext);
    //
    // // if (!purchaseItem.getFeatureParrot() ? true :
    // purchaseItem.isPremium()) {
    // if (!purchaseItem.getFeatureParrot() || purchaseItem.isPremium()) {
    // FragmentManager fm = mContext.getSupportFragmentManager();
    // GotsBillingDialog editNameDialog = new
    // GotsBillingDialog(GotsPurchaseItem.SKU_FEATURE_PARROT);
    // editNameDialog.setStyle(DialogFragment.STYLE_NORMAL,
    // R.style.CustomDialog);
    // editNameDialog.show(fm, "fragment_edit_name");
    // } else {
    // Intent sensorIntent = new Intent(mContext, SensorActivity.class);
    // mContext.startActivity(sensorIntent);
    // }// new AsyncTask<Void, Void, List<ParrotLocation>>() {
    // // private LocationListAdapter sensorListAdapter;
    // //
    // // List<ParrotSampleFertilizer> samplesFertilizer = null;
    // //
    // // List<ParrotSampleTemperature> samplesTemp = null;
    // //
    // // @Override
    // // protected List<ParrotLocation> doInBackground(Void... params) {
    // // ParrotSensorProvider sensorProvider = new
    // ParrotSensorProvider(mContext);
    // // List<ParrotLocation> locations = sensorProvider.getLocations();
    // // sensorProvider.getStatus();
    // // samplesFertilizer =
    // sensorProvider.getSamples(locations.get(0).getLocation_identifier());
    // // samplesTemp =
    // sensorProvider.getSamples2(locations.get(0).getLocation_identifier());
    // //
    // // return locations;
    // // }
    // //
    // // protected void onPostExecute(List<ParrotLocation> result) {
    // // // sensorListAdapter = new SensorListAdapter(mContext, result);
    // // sensorListAdapter = new LocationListAdapter(mContext, result);
    // // // new AlertDialog.Builder(mContext).setAdapter(sensorListAdapter,
    // // // new DialogInterface.OnClickListener() {
    // // //
    // // // @Override
    // // // public void onClick(DialogInterface dialog, int which) {
    // // // Toast.makeText(mContext,
    // sensorListAdapter.getItem(which).getSensor_serial(),
    // // // Toast.LENGTH_SHORT).show();
    // // // ;
    // // // }
    // // // }).show();
    // //
    // // Intent sensorIntent = new Intent(mContext, SensorActivity.class);
    // // mContext.startActivity(sensorIntent);
    // //
    // // if (samplesFertilizer != null) {
    // // WebView webView = new WebView(mContext);
    // // String chd = new String();
    // // for (ParrotSampleFertilizer fertilizer : samplesFertilizer) {
    // // chd = chd.concat(String.valueOf(fertilizer.getFertilizer_level() *
    // 100));
    // // chd = chd.concat(",");
    // // }
    // // chd = chd.substring(0, chd.length() - 1);
    // // String url =
    // "http://chart.apis.google.com/chart?cht=ls&chs=250x100&chd=t:" + chd;
    // // webView.loadUrl(url);
    // // Log.d(ListAllotmentAdapter.class.getName(), url);
    // // AlertDialog.Builder alert = new AlertDialog.Builder(mContext);
    // // alert.setView(webView);
    // // alert.show();
    // // }
    // // if (samplesTemp != null) {
    // // WebView webView = new WebView(mContext);
    // // String chd = new String();
    // // int i = 0;
    // // for (ParrotSampleTemperature sampleTemp : samplesTemp) {
    // // chd =
    // chd.concat(String.valueOf(sampleTemp.getAir_temperature_celsius()));
    // // chd = chd.concat(",");
    // // if (i++ >= 50)
    // // break;
    // // }
    // // chd = chd.substring(0, chd.length() - 1);
    // // String url =
    // "http://chart.apis.google.com/chart?cht=ls&chs=250x100&chd=t:" + chd;
    // // webView.loadUrl(url);
    // // Log.d(ListAllotmentAdapter.class.getName(), url);
    // // AlertDialog.Builder alert = new AlertDialog.Builder(mContext);
    // // alert.setView(webView);
    // // alert.show();
    // // }
    // // };
    // // }.execute();
    // }
    // });
    //
    // widgetSensor.setPadding(4, 4, 4, 8);
    // holder.menu.addView(widgetSensor);
    return ll;
}

From source file:com.ferdi2005.secondgram.AndroidUtilities.java

public static void checkDisplaySize(Context context, Configuration newConfiguration) {
    try {// www.j a  va  2  s.c o  m
        density = context.getResources().getDisplayMetrics().density;
        Configuration configuration = newConfiguration;
        if (configuration == null) {
            configuration = context.getResources().getConfiguration();
        }
        usingHardwareInput = configuration.keyboard != Configuration.KEYBOARD_NOKEYS
                && configuration.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO;
        WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        if (manager != null) {
            Display display = manager.getDefaultDisplay();
            if (display != null) {
                display.getMetrics(displayMetrics);
                display.getSize(displaySize);
            }
        }
        if (configuration.screenWidthDp != Configuration.SCREEN_WIDTH_DP_UNDEFINED) {
            int newSize = (int) Math.ceil(configuration.screenWidthDp * density);
            if (Math.abs(displaySize.x - newSize) > 3) {
                displaySize.x = newSize;
            }
        }
        if (configuration.screenHeightDp != Configuration.SCREEN_HEIGHT_DP_UNDEFINED) {
            int newSize = (int) Math.ceil(configuration.screenHeightDp * density);
            if (Math.abs(displaySize.y - newSize) > 3) {
                displaySize.y = newSize;
            }
        }
        FileLog.e("display size = " + displaySize.x + " " + displaySize.y + " " + displayMetrics.xdpi + "x"
                + displayMetrics.ydpi);
    } catch (Exception e) {
        FileLog.e(e);
    }
}

From source file:com.flexvdi.androidlauncher.LoginActivity.java

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

    mContext = this;

    try {//from   w  ww.j  a v a 2s  .  co m
        GStreamer.init(mContext);
    } catch (Exception e) {
        Log.e(TAG, "Can't initialize GStreamer" + e.getMessage());
        finish();
    }

    settings = getSharedPreferences("flexVDI", MODE_PRIVATE);
    settingsEditor = settings.edit();
    /* Uncomment this for clearing preferences (useful when debugging) */
    //settingsEditor.clear();
    //settingsEditor.apply();
    //settingsEditor.commit();

    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

    setContentView(R.layout.activity_login);

    textUser = (EditText) findViewById(R.id.textUser);
    textServer = (EditText) findViewById(R.id.textServer);
    textPassword = (EditText) findViewById(R.id.textPassword);

    goButton = (Button) findViewById(R.id.buttonGO);
    goButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            ConnectivityManager cm = (ConnectivityManager) mContext
                    .getSystemService(Context.CONNECTIVITY_SERVICE);

            NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
            boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();

            if (!isConnected) {
                Toast.makeText(view.getContext(), getResources().getString(R.string.no_network),
                        Toast.LENGTH_LONG).show();
                return;
            }

            if (checkBoxGenericSpice.isChecked()) {
                String userField = textUser.getText().toString();
                if (userField.length() == 0 || !userField.contains(":")) {
                    Toast.makeText(view.getContext(), getResources().getString(R.string.invalid_spice_server),
                            Toast.LENGTH_LONG).show();
                    return;
                }

                String spiceAddress = userField.substring(0, userField.indexOf(":"));
                String spicePort = userField.substring(userField.indexOf(":") + 1);

                if (spiceAddress.length() == 0 || spicePort.length() == 0) {
                    Toast.makeText(view.getContext(), getResources().getString(R.string.invalid_spice_server),
                            Toast.LENGTH_LONG).show();
                    return;
                }

                String spicePassword = textPassword.getText().toString();

                settingsEditor.putBoolean("enableSound", checkBoxEnableSound.isChecked());
                settingsEditor.putBoolean("staticResolution", checkBoxStaticResolution.isChecked());
                settingsEditor.putBoolean("genericSpice", checkBoxGenericSpice.isChecked());
                settingsEditor.putString("flexServerName", textServer.getText().toString());

                settingsEditor.putString("spice_address", spiceAddress);
                settingsEditor.putString("spice_port", spicePort);
                settingsEditor.putString("spice_password", spicePassword);
                settingsEditor.putBoolean("use_ws", false);

                settingsEditor.apply();
                settingsEditor.commit();

                startMainActivity();
            } else {
                if (textServer.getText().length() == 0) {
                    Toast.makeText(view.getContext(), getResources().getString(R.string.empty_flexvdi_server),
                            Toast.LENGTH_LONG).show();
                } else {
                    if (textUser.getText().length() != 0 && textPassword.getText().length() != 0) {
                        new RequestTask().execute("authmode", textServer.getText().toString(),
                                textUser.getText().toString(), textPassword.getText().toString(), "");
                    } else
                        Toast.makeText(view.getContext(), getResources().getString(R.string.empty_credentials),
                                Toast.LENGTH_LONG).show();
                }
            }
        }
    });

    // The advanced settings button.
    checkBoxAdvancedOptions = (CheckBox) findViewById(R.id.checkBoxAdvancedSettings);
    layoutAdvancedOptions = (LinearLayout) findViewById(R.id.layoutAdvancedOptions2);
    checkBoxAdvancedOptions.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton arg0, boolean checked) {
            if (checked)
                layoutAdvancedOptions.setVisibility(View.VISIBLE);
            else
                layoutAdvancedOptions.setVisibility(View.GONE);
        }
    });

    textServer.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View field, boolean hasFocus) {
            if (!hasFocus && checkBoxGenericSpice.isChecked()) {
                if (textUser.getText().toString().length() == 0) {
                    textUser.setText(textServer.getText());
                }
            }
        }
    });

    checkBoxEnableSound = (CheckBox) findViewById(R.id.checkBoxEnableSound);
    if (settings.getBoolean("enableSound", true)) {
        checkBoxEnableSound.setChecked(true);
    } else {
        checkBoxEnableSound.setChecked(false);
    }

    if (!settings.contains("staticResolution")) {
        Display display = getWindowManager().getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        if ((size.x + size.y) > 2340) {
            /* 2340 = 1440+900 */
            settingsEditor.putBoolean("staticResolution", true);
        } else {
            settingsEditor.putBoolean("staticResolution", false);
        }
        settingsEditor.apply();
        settingsEditor.commit();
    }

    checkBoxStaticResolution = (CheckBox) findViewById(R.id.checkBoxStaticResolution);
    if (settings.getBoolean("staticResolution", true)) {
        checkBoxStaticResolution.setChecked(true);
    } else {
        checkBoxStaticResolution.setChecked(false);
    }

    checkBoxGenericSpice = (CheckBox) findViewById(R.id.checkBoxGenericSpice);
    if (settings.getBoolean("genericSpice", false)) {
        checkBoxGenericSpice.setChecked(true);
        checkBoxAdvancedOptions.setChecked(true);
        layoutAdvancedOptions.setVisibility(View.VISIBLE);

        if (settings.contains("flexServerName")) {
            textServer.setText(settings.getString("flexServerName", ""));
            textUser.setText(settings.getString("flexServerName", ""));
            textServer.setHint(getResources().getString(R.string.spice_server));
            textUser.setHint(getResources().getString(R.string.spice_server_port));
        }
    } else {
        checkBoxGenericSpice.setChecked(false);
        if (settings.contains("flexServerName")) {
            textServer.setText(settings.getString("flexServerName", ""));
            layoutAdvancedOptions.setVisibility(View.GONE);
        } else {
            textServer.setText("manager.flexvdi.com");
            checkBoxAdvancedOptions.setChecked(true);
        }
    }

    checkBoxGenericSpice.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton arg0, boolean checked) {
            if (checked) {
                textServer.setHint(getResources().getString(R.string.spice_server));
                textUser.setHint(getResources().getString(R.string.spice_server_port));
                String server = textServer.getText().toString();
                if (server.length() != 0) {
                    if (server.contains(":")) {
                        textUser.setText(server);
                    } else {
                        textUser.setText(server + ":5900");
                        textServer.setText(server + ":5900");
                    }
                }
            } else {
                textServer.setHint(getResources().getString(R.string.flexvdi_server));
                String server = textServer.getText().toString();
                if (server.length() != 0 && server.contains(":")) {
                    textServer.setText(server.substring(0, server.indexOf(":")));
                }
                textUser.setText("");
                textUser.setHint(getResources().getString(R.string.user));
            }
        }
    });

    deviceID = Settings.Secure.getString(mContext.getContentResolver(), Settings.Secure.ANDROID_ID);

    textViewDeviceID = (TextView) findViewById(R.id.textViewDeviceID);
    textViewDeviceID.setText("ID: " + deviceID + " (" + BuildConfig.VERSION_NAME + ")");

    try {
        HttpsURLConnection.setDefaultHostnameVerifier(new NullHostNameVerifier());
        SSLContext context = SSLContext.getInstance("TLS");
        context.init(null, new X509TrustManager[] { new NullX509TrustManager() }, new SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
    } catch (NoSuchAlgorithmException nsae) {
        Log.e(TAG, nsae.getMessage());
    } catch (KeyManagementException kme) {
        Log.e(TAG, kme.getMessage());
    }
}

From source file:app.sunstreak.yourpisd.LoginActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login_new);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    if (toolbar != null) {
        setSupportActionBar(toolbar);/*from   w  w w .j  a  va  2s  . com*/
    }
    final SharedPreferences sharedPrefs = getPreferences(Context.MODE_PRIVATE);
    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    height = size.y;
    mLoginFormView = findViewById(R.id.login_form);
    mLoginStatusView = (LinearLayout) findViewById(R.id.login_status);
    mLoginStatusMessageView = (TextView) findViewById(R.id.login_status_message);

    if (DateHelper.isAprilFools()) {
        LinearLayout container = (LinearLayout) mLoginFormView.findViewById(R.id.container);
        ImageView logo = (ImageView) container.findViewById(R.id.logo);
        InputStream is;
        try {
            is = getAssets().open("doge.png");
            logo.setImageBitmap(BitmapFactory.decodeStream(is));
            is.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    mAutoLogin = sharedPrefs.getBoolean("auto_login", false);
    System.out.println(mAutoLogin);

    session = ((YPApplication) getApplication()).session;

    try {
        boolean refresh = getIntent().getExtras().getBoolean("Refresh");

        if (refresh) {
            mEmail = session.getUsername();
            mPassword = session.getPassword();
            showProgress(true);
            mAuthTask = new UserLoginTask();
            mAuthTask.execute((Void) null);

            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(mPasswordView.getWindowToken(), 0);
        } else
            mLoginFormView.setVisibility(View.VISIBLE);
    } catch (NullPointerException e) {
        // Keep going.
    }

    if (sharedPrefs.getBoolean("patched", false)) {
        SharedPreferences.Editor editor = sharedPrefs.edit();
        editor.remove("password");
        editor.putBoolean("patched", true);
        editor.commit();
    }

    if (!sharedPrefs.getBoolean("AcceptedUserAgreement", false)) {

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(getResources().getString(R.string.user_agreement_title));
        builder.setMessage(getResources().getString(R.string.user_agreement));
        // Setting Positive "Yes" Button
        builder.setPositiveButton("Agree", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                sharedPrefs.edit().putBoolean("AcceptedUserAgreement", true).commit();
                dialog.cancel();
            }
        });

        // Setting Negative "NO" Button
        builder.setNegativeButton("Disagree", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                // Write your code here to invoke NO event
                sharedPrefs.edit().putBoolean("AcceptedUserAgreement", false).commit();
                Toast.makeText(LoginActivity.this, "Quitting app", Toast.LENGTH_SHORT).show();
                finish();
            }
        });

        AlertDialog alertDialog = builder.create();
        alertDialog.show();
    }

    // Set up the remember_password CheckBox
    mRememberPasswordCheckBox = (CheckBox) findViewById(R.id.remember_password);
    mRememberPasswordCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mRememberPassword = isChecked;
        }
    });

    mRememberPassword = sharedPrefs.getBoolean("remember_password", false);
    mRememberPasswordCheckBox.setChecked(mRememberPassword);

    // Set up the auto_login CheckBox
    mAutoLoginCheckBox = (CheckBox) findViewById(R.id.auto_login);
    mAutoLoginCheckBox.setChecked(mAutoLogin);
    mAutoLoginCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton button, boolean isChecked) {
            mAutoLogin = isChecked;
            if (isChecked) {
                mRememberPasswordCheckBox.setChecked(true);
            }
        }

    });

    // Set up the login form.
    mEmailView = (EditText) findViewById(R.id.email);

    mPasswordView = (EditText) findViewById(R.id.password);
    mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
            if (id == R.id.login || id == EditorInfo.IME_NULL) {
                attemptLogin();
                return true;
            }
            return false;
        }
    });

    //Load stored username/password
    mEmailView.setText(sharedPrefs.getString("email", mEmail));
    mPasswordView.setText(new String(Base64.decode(sharedPrefs.getString("e_password", ""), Base64.DEFAULT)));
    // If the password was not saved, give focus to the password.
    if (mPasswordView.getText().equals(""))
        mPasswordView.requestFocus();

    mLoginFormView = findViewById(R.id.login_form);
    mLoginStatusView = (LinearLayout) findViewById(R.id.login_status);
    mLoginStatusMessageView = (TextView) findViewById(R.id.login_status_message);

    findViewById(R.id.sign_in_button).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            attemptLogin();
        }
    });
    findViewById(R.id.sign_in_button).setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(mPasswordView.getWindowToken(), 0);
            return false;
        }
    });
    mLoginFormView.setVisibility(View.VISIBLE);
    // Login if auto-login is checked.
    if (mAutoLogin)
        attemptLogin();
}

From source file:tv.ouya.sdk.CordovaOuyaPlugin.java

private int getDisplayWidth() {
    Activity activity = cordova.getActivity();
    WindowManager windowManager = activity.getWindowManager();
    Display display = windowManager.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    return size.x;
}

From source file:tv.ouya.sdk.CordovaOuyaPlugin.java

private int getDisplayHeight() {
    Activity activity = cordova.getActivity();
    WindowManager windowManager = activity.getWindowManager();
    Display display = windowManager.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    return size.y;
}

From source file:com.kmagic.solitaire.DrawMaster.java

/**
 * Create a new instance of DrawMaster/*from   w  w w .  ja v  a2  s  . c  o  m*/
 * @param context activity/application context
 */
public DrawMaster(final Context context) {

    mContext = context;
    mResources = mContext.getResources();

    // Background
    mBGPaint = new Paint();
    mBGPaint.setARGB(255, 0, 128, 0);

    mShadePaint = new Paint();
    mShadePaint.setARGB(200, 0, 0, 0);

    mLightShadePaint = new Paint();
    mLightShadePaint.setARGB(100, 0, 0, 0);

    // Card related stuff
    mEmptyAnchorPaint = new Paint();
    mEmptyAnchorPaint.setARGB(255, 0, 64, 0);
    mDoneEmptyAnchorPaint = new Paint();
    mDoneEmptyAnchorPaint.setARGB(128, 255, 0, 0);

    mFontSize = mResources.getDimensionPixelSize(R.dimen.font_size);
    mTimePaint = getTextPaint(mFontSize, Paint.Align.RIGHT);
    mLastSeconds = -1;

    mCardBitmap = new Bitmap[52];
    Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    setScreenSize(size.x, size.y);
    drawCards(false);
}

From source file:com.example.javier.MaterialDesignApp.PlayerActivity.java

private float getCaptionFontSize() {
    Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    Point displaySize = new Point();
    display.getSize(displaySize);
    return Math.max(getResources().getDimension(R.dimen.subtitle_minimum_font_size),
            CAPTION_LINE_HEIGHT_RATIO * Math.min(displaySize.x, displaySize.y));
}