Example usage for android.content.res Resources getDisplayMetrics

List of usage examples for android.content.res Resources getDisplayMetrics

Introduction

In this page you can find the example usage for android.content.res Resources getDisplayMetrics.

Prototype

public DisplayMetrics getDisplayMetrics() 

Source Link

Document

Return the current display metrics that are in effect for this resource object.

Usage

From source file:com.android.contacts.ShortcutIntentBuilder.java

/**
 * Generates a phone number shortcut icon. Adds an overlay describing the type of the phone
 * number, and if there is a photo also adds the call action icon.
 *//*from w ww  .  j ava2 s. co  m*/
private Bitmap generatePhoneNumberIcon(Drawable photo, int phoneType, String phoneLabel, int actionResId) {
    final Resources r = mContext.getResources();
    final float density = r.getDisplayMetrics().density;

    final Drawable phoneDrawable = r.getDrawableForDensity(actionResId, mIconDensity);
    // These icons have the same height and width so either is fine for the size.
    final Bitmap phoneIcon = BitmapUtil.drawableToBitmap(phoneDrawable, phoneDrawable.getIntrinsicHeight());

    Bitmap icon = generateQuickContactIcon(photo);
    Canvas canvas = new Canvas(icon);

    // Copy in the photo
    Paint photoPaint = new Paint();
    photoPaint.setDither(true);
    photoPaint.setFilterBitmap(true);
    Rect dst = new Rect(0, 0, mIconSize, mIconSize);

    // Create an overlay for the phone number type if we're pre-O. O created shortcuts have the
    // app badge which overlaps the type overlay.
    CharSequence overlay = Phone.getTypeLabel(r, phoneType, phoneLabel);
    if (!BuildCompat.isAtLeastO() && overlay != null) {
        TextPaint textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG);
        textPaint.setTextSize(r.getDimension(R.dimen.shortcut_overlay_text_size));
        textPaint.setColor(r.getColor(R.color.textColorIconOverlay));
        textPaint.setShadowLayer(4f, 0, 2f, r.getColor(R.color.textColorIconOverlayShadow));

        final FontMetricsInt fmi = textPaint.getFontMetricsInt();

        // First fill in a darker background around the text to be drawn
        final Paint workPaint = new Paint();
        workPaint.setColor(mOverlayTextBackgroundColor);
        workPaint.setStyle(Paint.Style.FILL);
        final int textPadding = r.getDimensionPixelOffset(R.dimen.shortcut_overlay_text_background_padding);
        final int textBandHeight = (fmi.descent - fmi.ascent) + textPadding * 2;
        dst.set(0, mIconSize - textBandHeight, mIconSize, mIconSize);
        canvas.drawRect(dst, workPaint);

        overlay = TextUtils.ellipsize(overlay, textPaint, mIconSize, TruncateAt.END);
        final float textWidth = textPaint.measureText(overlay, 0, overlay.length());
        canvas.drawText(overlay, 0, overlay.length(), (mIconSize - textWidth) / 2,
                mIconSize - fmi.descent - textPadding, textPaint);
    }

    // Draw the phone action icon as an overlay
    int iconWidth = icon.getWidth();
    if (BuildCompat.isAtLeastO()) {
        // On O we need to calculate where the phone icon goes slightly differently. The whole
        // canvas area is 108dp, a centered circle with a diameter of 66dp is the "safe zone".
        // So we start the drawing the phone icon at
        // 108dp - 21 dp (distance from right edge of safe zone to the edge of the canvas)
        // - 24 dp (size of the phone icon) on the x axis (left)
        // The y axis is simply 21dp for the distance to the safe zone (top).
        // See go/o-icons-eng for more details and a handy picture.
        final int left = (int) (mIconSize - (45 * density));
        final int top = (int) (21 * density);
        canvas.drawBitmap(phoneIcon, left, top, photoPaint);
    } else {
        dst.set(iconWidth - ((int) (20 * density)), -1, iconWidth, ((int) (19 * density)));
        canvas.drawBitmap(phoneIcon, null, dst, photoPaint);
    }

    canvas.setBitmap(null);
    return icon;
}

From source file:org.dalol.orthodoxmezmurmedia.utilities.widgets.AmharicKeyboardView.java

/**
 * This method is responsible to handle the keyboard height based on the current orientation
 *///from www.jav a 2  s  .c  o m
private void resolveKeyboardHeight() {
    Resources resources = getResources();
    DisplayMetrics displayMetrics = resources.getDisplayMetrics();
    int orientation = resources.getConfiguration().orientation;

    switch (orientation) {
    case Configuration.ORIENTATION_PORTRAIT:
        mKeyboardHeight = Math.round(displayMetrics.heightPixels / PORTRAIT_HEIGHT_SCALE);
        break;
    case Configuration.ORIENTATION_LANDSCAPE:
        mKeyboardHeight = Math.round(displayMetrics.heightPixels / LANDSCAPE_HEIGHT_SCALE);
        break;
    }
}

From source file:com.google.android.apps.muzei.gallery.GalleryEmptyStateGraphicView.java

public GalleryEmptyStateGraphicView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    final Resources res = getResources();
    mOffPaint.setAntiAlias(true);//from w w  w . j av  a 2s.com
    mOffPaint.setColor(ContextCompat.getColor(context, R.color.gallery_empty_state_dark));
    mOnPaint.setAntiAlias(true);
    mOnPaint.setColor(ContextCompat.getColor(context, R.color.gallery_empty_state_light));

    mCellSpacing = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, CELL_SPACING_DIP,
            res.getDisplayMetrics());
    mCellSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, CELL_SIZE_DIP,
            res.getDisplayMetrics());
    mCellRounding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, CELL_ROUNDING_DIP,
            res.getDisplayMetrics());
}

From source file:com.forrestguice.suntimeswidget.AlarmDialog.java

/**
 * @param savedInstanceState a Bundle containing dialog state
 * @return an AlarmDialog ready to be shown
 *//*from  ww  w. j av  a2s  . c  o  m*/
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final Activity myParent = getActivity();
    LayoutInflater inflater = myParent.getLayoutInflater();
    @SuppressLint("InflateParams")
    View dialogContent = inflater.inflate(R.layout.layout_dialog_schedalarm, null);

    Resources r = getResources();
    int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16, r.getDisplayMetrics());

    AlertDialog.Builder builder = new AlertDialog.Builder(myParent);
    builder.setView(dialogContent, 0, padding, 0, 0);
    builder.setTitle(myParent.getString(R.string.schedalarm_dialog_title));

    AlertDialog dialog = builder.create();
    dialog.setCanceledOnTouchOutside(false);

    dialog.setButton(AlertDialog.BUTTON_NEGATIVE, myParent.getString(R.string.schedalarm_dialog_cancel),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();

                    if (onCanceled != null) {
                        onCanceled.onClick(dialog, which);
                    }
                }
            });

    dialog.setButton(AlertDialog.BUTTON_POSITIVE, myParent.getString(R.string.schedalarm_dialog_ok),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    saveSettings(myParent);
                    dialog.dismiss();

                    if (onAccepted != null) {
                        onAccepted.onClick(dialog, which);
                    }
                }
            });

    initViews(myParent, dialogContent);
    if (savedInstanceState != null) {
        //Log.d("DEBUG", "AlarmDialog onCreate (restoreState)");
        loadSettings(savedInstanceState);

    } else {
        //Log.d("DEBUG", "AlarmDialog onCreate (newState)");
        loadSettings(myParent);
    }
    return dialog;
}

From source file:org.solovyev.android.widget.menu.CustomPopupMenuHelper.java

public CustomPopupMenuHelper(Context context, MenuBuilder menu, View anchorView, boolean overflowOnly,
        int popupStyleAttr, int popupStyleRes) {
    mContext = context;// w w  w.  j  a va 2 s .  c o  m
    mInflater = LayoutInflater.from(context);
    mMenu = menu;
    mAdapter = new MenuAdapter(mMenu);
    mOverflowOnly = overflowOnly;
    mPopupStyleAttr = popupStyleAttr;
    mPopupStyleRes = popupStyleRes;

    final Resources res = context.getResources();
    mPopupMaxWidth = Math.max(res.getDisplayMetrics().widthPixels / 2,
            res.getDimensionPixelSize(R.dimen.abc_config_prefDialogWidth));

    mAnchorView = anchorView;

    // Present the menu using our context, not the menu builder's context.
    menu.addMenuPresenter(this, context);
}

From source file:de.theknut.xposedgelsettings.ui.MainActivity.java

@SuppressWarnings("deprecation")
@Override/*from ww  w .  j a  v a2  s . c o m*/
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mContext = CommonUI.CONTEXT = mActivity = CommonUI.ACTIVITY = this;

    if (getSharedPreferences(Common.PREFERENCES_NAME, Context.MODE_WORLD_READABLE)
            .getBoolean("forceenglishlocale", false)) {
        Resources res = mContext.getResources();
        Configuration conf = res.getConfiguration();
        conf.locale = new Locale(Locale.US.getDisplayLanguage().toLowerCase());
        res.updateConfiguration(conf, res.getDisplayMetrics());
    }

    mTitle = mDrawerTitle = getTitle();
    mFragmentTitles = getResources().getStringArray(R.array.fragmenttitles_array);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);

    mDrawerLayout.getRootView().setBackgroundColor(CommonUI.UIColor);
    getActionBar().setBackgroundDrawable(new ColorDrawable(CommonUI.UIColor));

    // set a custom shadow that overlays the main content when the drawer opens
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    // set up the drawer's list view with items and click listener
    mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mFragmentTitles));
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
    mDrawerLayout.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {

            if (event.getRepeatCount() != 0)
                return false;

            if (!mDrawerLayout.isDrawerOpen(Gravity.LEFT)) {

                if ((keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_MENU)) {
                    mDrawerLayout.openDrawer(Gravity.LEFT);
                    return true;
                }
            } else {
                if (keyCode == KeyEvent.KEYCODE_BACK) {
                    MainActivity.this.finish();
                    return true;
                } else if (keyCode == KeyEvent.KEYCODE_MENU) {
                    mDrawerLayout.closeDrawer(Gravity.LEFT);
                    return true;
                }
            }

            return false;
        }
    });

    // enable ActionBar app icon to behave as action to toggle nav drawer
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);
    getActionBar().setBackgroundDrawable(new ColorDrawable(CommonUI.UIColor));

    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon
    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description for accessibility */
            R.string.drawer_close /* "close drawer" description for accessibility */
    ) {
        public void onDrawerClosed(View view) {
            getActionBar().setTitle(mTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }

        public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle(mDrawerTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    SharedPreferences prefs = getSharedPreferences(Common.PREFERENCES_NAME, Context.MODE_WORLD_READABLE);
    CommonUI.NO_BACKGROUND_IMAGE = prefs.getBoolean("nobackgroundimage", false);
    CommonUI.AUTO_BLUR_IMAGE = prefs.getBoolean("autoblurimage", false);

    if (savedInstanceState == null) {

        Intent i = getIntent();
        if (i != null && i.hasExtra("fragment")) {
            if (i.getStringExtra("fragment").equals("badges")) {
                selectItem(6);
            }
        } else {
            selectItem(0);
        }
    }
}

From source file:com.forrestguice.suntimeswidget.TimeZoneDialog.java

@NonNull
@Override//from w  w  w .j ava  2  s .  co  m
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    super.onCreateDialog(savedInstanceState);

    final Activity myParent = getActivity();
    LayoutInflater inflater = myParent.getLayoutInflater();
    @SuppressLint("InflateParams")
    View dialogContent = inflater.inflate(R.layout.layout_dialog_timezone, null);

    Resources r = getResources();
    int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16, r.getDisplayMetrics());

    AlertDialog.Builder builder = new AlertDialog.Builder(myParent);
    builder.setView(dialogContent, 0, padding, 0, 0);

    builder.setTitle(myParent.getString(R.string.timezone_dialog_title));

    AlertDialog dialog = builder.create();
    dialog.setCanceledOnTouchOutside(false);

    dialog.setButton(AlertDialog.BUTTON_NEGATIVE, myParent.getString(R.string.timezone_dialog_cancel),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();

                    if (onCanceled != null) {
                        onCanceled.onClick(dialog, which);
                    }
                }
            });

    dialog.setButton(AlertDialog.BUTTON_POSITIVE, myParent.getString(R.string.timezone_dialog_ok),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    saveSettings(myParent);
                    dialog.dismiss();

                    if (onAccepted != null) {
                        onAccepted.onClick(dialog, which);
                    }
                }
            });
    /**dialog.setOnShowListener(new DialogInterface.OnShowListener()
    {
    @Override
    public void onShow(DialogInterface dialogInterface) {}
    });*/
    /**dialog.setOnDismissListener(new DialogInterface.OnDismissListener()
    {
    @Override
    public void onDismiss(DialogInterface dialogInterface) {}
    });*/

    initViews(myParent, dialogContent);
    WidgetTimezones.TimeZoneSort sortZonesBy = AppSettings.loadTimeZoneSortPref(myParent);
    WidgetTimezones.TimeZonesLoadTask loadTask = new WidgetTimezones.TimeZonesLoadTask(myParent) {
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            spinner_timezone.setAdapter(
                    new WidgetTimezones.TimeZoneItemAdapter(myParent, R.layout.layout_listitem_timezone));
        }

        @Override
        protected void onPostExecute(WidgetTimezones.TimeZoneItemAdapter result) {
            super.onPostExecute(result);
            spinner_timezone_adapter = result;
            spinner_timezone.setAdapter(spinner_timezone_adapter);
            WidgetTimezones.selectTimeZone(spinner_timezone, spinner_timezone_adapter, customTimezoneID);
        }
    };

    if (savedInstanceState != null) {
        // saved dialog state; restore it
        //Log.d("DEBUG", "TimeZoneDialog onCreate (restoreState)");
        loadSettings(savedInstanceState);

    } else {
        // no saved dialog state; load from preferences
        //Log.d("DEBUG", "TimeZoneDialog onCreate (newState)");
        loadSettings(myParent);
    }
    loadTask.execute(sortZonesBy);
    return dialog;
}

From source file:br.com.frs.foodrestrictions.MessageCannibal.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.activity_message_cannibal, container, false);

    String language = getArguments().getString(MessageLanguageSelector.ARG_LANGUAGE);

    TextView tv = (TextView) v.findViewById(R.id.tvCannibal);

    /* Getting the current resource  and config info */
    Resources rsc = v.getContext().getResources();
    Configuration config = rsc.getConfiguration();
    /* Saving the original locale before changing to the new one
     * just to show the texts/* w w w .jav  a 2 s.c  o m*/
     */
    Locale orgLocale = config.locale;

    /* Changing the language to the one the user have selected based on the
     * Languages.xml file
     */
    if (language != null) {
        config.locale = new Locale(language);
    }

    /* Setting the new locale */
    rsc.updateConfiguration(config, rsc.getDisplayMetrics());
    /* Updating the layout with the new selected language */
    tv.setText(rsc.getString(R.string.msg_joke_cannibal));

    /* Return to last locale to keep the app as it was before */
    config.locale = orgLocale;
    rsc.updateConfiguration(config, rsc.getDisplayMetrics());

    return v;
}

From source file:de.niklasmerz.cordova.fingerprint.Fingerprint.java

/**
 * Executes the request and returns PluginResult.
 *
 * @param action          The action to execute.
 * @param args            JSONArry of arguments for the plugin.
 * @param callbackContext The callback id used when calling back into JavaScript.
 * @return A PluginResult object with a status and message.
 *//*from   w w w .ja  v a2s  . co m*/
public boolean execute(final String action, JSONArray args, CallbackContext callbackContext)
        throws JSONException {
    mCallbackContext = callbackContext;
    Log.v(TAG, "Fingerprint action: " + action);
    if (android.os.Build.VERSION.SDK_INT < 23) {
        Log.e(TAG, "minimum SDK version 23 required");
        mPluginResult = new PluginResult(PluginResult.Status.ERROR);
        mCallbackContext.error("minimum SDK version 23 required");
        mCallbackContext.sendPluginResult(mPluginResult);
        return true;
    }

    final JSONObject arg_object = args.getJSONObject(0);

    if (action.equals("authenticate")) {
        if (!arg_object.has("clientId") || !arg_object.has("clientSecret")) {
            mPluginResult = new PluginResult(PluginResult.Status.ERROR);
            mCallbackContext.error("Missing required parameters");
            mCallbackContext.sendPluginResult(mPluginResult);
            return true;
        }
        mClientId = arg_object.getString("clientId");
        mClientSecret = arg_object.getString("clientSecret");
        if (arg_object.has("disableBackup")) {
            mDisableBackup = arg_object.getBoolean("disableBackup");
        }
        // Set language
        Resources res = cordova.getActivity().getResources();
        // Change locale settings in the app.
        DisplayMetrics dm = res.getDisplayMetrics();
        Configuration conf = res.getConfiguration();
        //Do not change locale
        res.updateConfiguration(conf, dm);

        if (isFingerprintAuthAvailable()) {
            SecretKey key = getSecretKey();
            boolean isCipherInit = true;
            if (key == null) {
                if (createKey()) {
                    key = getSecretKey();
                }
            }
            if (key != null && !initCipher()) {
                isCipherInit = false;
            }
            if (key != null) {
                cordova.getActivity().runOnUiThread(new Runnable() {
                    public void run() {
                        // Set up the crypto object for later. The object will be authenticated by use
                        // of the fingerprint.
                        mFragment = new FingerprintAuthenticationDialogFragment();
                        Bundle bundle = new Bundle();
                        bundle.putBoolean("disableBackup", mDisableBackup);
                        mFragment.setArguments(bundle);

                        if (initCipher()) {
                            mFragment.setCancelable(false);
                            // Show the fingerprint dialog. The user has the option to use the fingerprint with
                            // crypto, or you can fall back to using a server-side verified password.
                            mFragment.setCryptoObject(new FingerprintManager.CryptoObject(mCipher));
                            mFragment.show(cordova.getActivity().getFragmentManager(), DIALOG_FRAGMENT_TAG);
                        } else {
                            if (!mDisableBackup) {
                                // This happens if the lock screen has been disabled or or a fingerprint got
                                // enrolled. Thus show the dialog to authenticate with their password
                                mFragment.setCryptoObject(new FingerprintManager.CryptoObject(mCipher));
                                mFragment.setStage(
                                        FingerprintAuthenticationDialogFragment.Stage.NEW_FINGERPRINT_ENROLLED);
                                mFragment.show(cordova.getActivity().getFragmentManager(), DIALOG_FRAGMENT_TAG);
                            } else {
                                mCallbackContext.error("Failed to init Cipher and backup disabled.");
                                mPluginResult = new PluginResult(PluginResult.Status.ERROR);
                                mCallbackContext.sendPluginResult(mPluginResult);
                            }
                        }
                    }
                });
                mPluginResult.setKeepCallback(true);
            } else {
                mCallbackContext.sendPluginResult(mPluginResult);
            }

        } else {
            mPluginResult = new PluginResult(PluginResult.Status.ERROR);
            mCallbackContext.error("Fingerprint authentication not available");
            mCallbackContext.sendPluginResult(mPluginResult);
        }
        return true;
    } else if (action.equals("isAvailable")) {
        if (isFingerprintAuthAvailable() && mFingerPrintManager.isHardwareDetected()
                && mFingerPrintManager.hasEnrolledFingerprints()) {
            mPluginResult = new PluginResult(PluginResult.Status.OK);
            mCallbackContext.success();
        } else {
            mPluginResult = new PluginResult(PluginResult.Status.ERROR);
            mCallbackContext.error("Fingerprint authentication not ready");
        }
        mCallbackContext.sendPluginResult(mPluginResult);
        return true;
    }
    return false;
}

From source file:com.esprit.droidcon.corruption.RelationListActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.maillist_layout);
    imageLoader = ImageLoader.getInstance();
    imageLoader.init(ImageLoaderConfiguration.createDefault(this));
    retry = (Button) findViewById(R.id.retry);
    ButterKnife.bind(this);
    mBackground = mImageView;//  w  w  w  .  jav  a 2  s .c o m
    moveBackground();
    initToolbar();

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    connexionlay = (RelativeLayout) findViewById(R.id.connexionlay);

    mang = new ArrayList<>();

    final ListView listView = (ListView) findViewById(R.id.list_view);

    final ConnectivityManager conMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo activeNetwork = conMgr.getActiveNetworkInfo();
    if (activeNetwork != null && activeNetwork.isConnected()) {

        connexionlay.setVisibility(View.GONE);
        // notify user you are online
        final ParseQuery<ParseObject> query = ParseQuery.getQuery("Corruption");
        query.whereEqualTo("Type", "Relation Avec Le Cityoen");
        query.findInBackground(new FindCallback<ParseObject>() {
            public void done(List<ParseObject> conThus, ParseException e) {
                if (e == null) {
                    //Log.d("score", "Retrieved " + scoreList.size() + " scores");
                    for (int i = conThus.size() - 1; i > 0; i--) {
                        ParseObject dong = conThus.get(i);
                        //System.out.println(dong.getParseFile("ImageFile").toString());
                        if (dong.getParseFile("AudioFile") != null) {
                            mang.add(new Corruption(dong.getString("Title"), dong.getString("Description"),
                                    dong.getString("Date"), dong.getString("Adress"),
                                    dong.getParseFile("Photo1").getUrl(), dong.getParseFile("Photo2").getUrl(),
                                    dong.getParseFile("Photo3").getUrl(),
                                    dong.getParseFile("AudioFile").getUrl(), dong.getDouble("Long"),
                                    dong.getDouble("Lat"), dong.getString("Heure"), dong.getString("Ville"),
                                    dong.getString("UserNom"), dong.getString("UserAdress"),
                                    dong.getString("UserTel"), dong.getString("UserMail"),
                                    dong.getString("Type"), dong.getString("VideoCode"), dong.getString("Etat")

                            ));

                            mGoogleCardsAdapter = new GoogleCardsTravelAdapter(getApplicationContext(), mang);
                            SwingBottomInAnimationAdapter swingBottomInAnimationAdapter = new SwingBottomInAnimationAdapter(
                                    mGoogleCardsAdapter);
                            swingBottomInAnimationAdapter.setAbsListView(listView);

                            assert swingBottomInAnimationAdapter.getViewAnimator() != null;
                            swingBottomInAnimationAdapter.getViewAnimator()
                                    .setInitialDelayMillis(INITIAL_DELAY_MILLIS);

                            listView.setClipToPadding(false);
                            listView.setDivider(null);
                            Resources r = getResources();
                            int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
                                    r.getDisplayMetrics());
                            listView.setDividerHeight(px);
                            listView.setFadingEdgeLength(0);
                            listView.setFitsSystemWindows(true);
                            px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 12,
                                    r.getDisplayMetrics());
                            listView.setPadding(px, px, px, px);
                            listView.setScrollBarStyle(ListView.SCROLLBARS_OUTSIDE_OVERLAY);
                            listView.setAdapter(swingBottomInAnimationAdapter);

                            /*   SwingBottomInAnimationAdapter swingBottomInAnimationAdapter = new SwingBottomInAnimationAdapter(
                                     new SwipeDismissAdapter(mGoogleCardsAdapter, this));
                               swingBottomInAnimationAdapter.setAbsListView(listView);*/
                        } else

                        {
                            mang.add(new Corruption(dong.getString("Title"), dong.getString("Description"),
                                    dong.getString("Date"), dong.getString("Adress"),
                                    dong.getParseFile("Photo1").getUrl(), dong.getParseFile("Photo2").getUrl(),
                                    dong.getParseFile("Photo3").getUrl(), dong.getDouble("Long"),
                                    dong.getDouble("Lat"), dong.getString("Heure"), dong.getString("Ville"),
                                    dong.getString("UserNom"), dong.getString("UserAdress"),
                                    dong.getString("UserTel"), dong.getString("UserMail"),
                                    dong.getString("Type"), dong.getString("VideoCode"), dong.getString("Etat")

                            ));

                            mGoogleCardsAdapter = new GoogleCardsTravelAdapter(getApplicationContext(), mang);
                            SwingBottomInAnimationAdapter swingBottomInAnimationAdapter = new SwingBottomInAnimationAdapter(
                                    mGoogleCardsAdapter);
                            swingBottomInAnimationAdapter.setAbsListView(listView);

                            assert swingBottomInAnimationAdapter.getViewAnimator() != null;
                            swingBottomInAnimationAdapter.getViewAnimator()
                                    .setInitialDelayMillis(INITIAL_DELAY_MILLIS);

                            listView.setClipToPadding(false);
                            listView.setDivider(null);
                            Resources r = getResources();
                            int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
                                    r.getDisplayMetrics());
                            listView.setDividerHeight(px);
                            listView.setFadingEdgeLength(0);
                            listView.setFitsSystemWindows(true);
                            px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 12,
                                    r.getDisplayMetrics());
                            listView.setPadding(px, px, px, px);
                            listView.setScrollBarStyle(ListView.SCROLLBARS_OUTSIDE_OVERLAY);
                            listView.setAdapter(swingBottomInAnimationAdapter);

                        }
                    }

                } else {
                    Log.d("score", "Error: " + e.getMessage());
                    Toast.makeText(getApplicationContext(), "Error: " + e.getMessage(), Toast.LENGTH_LONG)
                            .show();
                }
            }
        });

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                Corruption corp = (Corruption) parent.getItemAtPosition(position);
                SwipeImageAdapter.img1 = corp.getImage1();
                SwipeImageAdapter.img2 = corp.getImage2();
                SwipeImageAdapter.img3 = corp.getImage3();
                SwipeImageAdapter.title = corp.getTitle();
                SwipeImageAdapter.desc = corp.getDesc();
                //prodimg = prod.getProductImage();
                Intent i = new Intent(RelationListActivity.this, SingleCorruptionActivity.class);
                i.putExtra("audiourl", corp.getAudiofile());
                i.putExtra("longi", corp.getLongi());
                i.putExtra("lat", corp.getLat());
                i.putExtra("date", corp.getDate());
                i.putExtra("heure", corp.getHeure());
                i.putExtra("ville", corp.getVille());
                i.putExtra("title", corp.getTitle());
                i.putExtra("desc", corp.getDesc());
                i.putExtra("usernom", corp.getUserNom());
                i.putExtra("useradress", corp.getUserAdress());
                i.putExtra("usertel", corp.getUserTel());
                i.putExtra("usermail", corp.getUserMail());
                i.putExtra("type", corp.getType());
                i.putExtra("videocode", corp.getVideo());
                i.putExtra("etat", corp.getEtat());

                startActivity(i);
                finish();

            }
        });

    } else {
        // notify user you are not online
        connexionlay.setVisibility(View.VISIBLE);
        retry.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // fabProgressCircle.show();
                //  startYourAsynchronousJob();
                Intent refresh = new Intent(RelationListActivity.this, RelationListActivity.class);
                startActivity(refresh);
                finish();

            }
        });

    }

}