Example usage for android.view Gravity CENTER_HORIZONTAL

List of usage examples for android.view Gravity CENTER_HORIZONTAL

Introduction

In this page you can find the example usage for android.view Gravity CENTER_HORIZONTAL.

Prototype

int CENTER_HORIZONTAL

To view the source code for android.view Gravity CENTER_HORIZONTAL.

Click Source Link

Document

Place object in the horizontal center of its container, not changing its size.

Usage

From source file:com.muzakki.ahmad.widget.CollapsingTextHelper.java

private void calculateBaseOffsets() {
    final float currentTextSize = mCurrentTextSize;

    // We then calculate the collapsed text size, using the same logic
    calculateUsingTextSize(mCollapsedTextSize);
    calculateUsingSubSize(mCollapsedSubSize);

    float textHeight = mTextPaint.descent() - mTextPaint.ascent();
    float textOffset = (textHeight / 2);
    if (mSub != null) {
        float subHeight = mSubPaint.descent() - mSubPaint.ascent();
        float subOffset = (subHeight / 2) - mSubPaint.descent();
        float offset = ((mCollapsedBounds.height() - (textHeight + subHeight)) / 3);

        mCollapsedDrawY = mCollapsedBounds.top + offset - mTextPaint.ascent();
        mCollapsedSubY = mCollapsedBounds.top + (offset * 2) + textHeight - mSubPaint.ascent();
    } else { // title only
        mCollapsedDrawY = mCollapsedBounds.centerY() + textOffset;
    }//from w ww .j av a 2s . co  m

    float width = mText != null ? mTextPaint.measureText(mText, 0, mText.length()) : 0;
    float subWidth = mSub != null ? mSubPaint.measureText(mSub, 0, mSub.length()) : 0;
    final int collapsedAbsGravity = GravityCompat.getAbsoluteGravity(mCollapsedTextGravity,
            mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR);

    switch (collapsedAbsGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
    case Gravity.CENTER_HORIZONTAL:
        mCollapsedDrawX = mCollapsedBounds.centerX() - (width / 2);
        mCollapsedDrawSubX = mCollapsedBounds.centerX() - (subWidth / 2);
        break;
    case Gravity.RIGHT:
        mCollapsedDrawX = mCollapsedBounds.right - width;
        mCollapsedDrawSubX = mCollapsedBounds.right - subWidth;
        break;
    case Gravity.LEFT:
    default:
        mCollapsedDrawX = mCollapsedBounds.left;
        mCollapsedDrawSubX = mCollapsedBounds.left;
        break;
    }

    calculateUsingTextSize(mExpandedTextSize);
    calculateUsingSubSize(mExpandedSubSize);

    textHeight = mTextPaint.descent() - mTextPaint.ascent();
    textOffset = (textHeight / 2);
    if (mSub != null) {
        float subHeight = mSubPaint.descent() - mSubPaint.ascent();
        float subOffset = (subHeight / 2);

        mExpandedDrawY = mExpandedBounds.centerY() + textOffset;
        mExpandedSubY = mExpandedDrawY + subOffset - mSubPaint.ascent();
    } else { // title only
        mExpandedDrawY = mExpandedBounds.centerY() + textOffset;
    }

    width = mText != null ? mTextPaint.measureText(mText, 0, mText.length()) : 0;
    subWidth = mSub != null ? mSubPaint.measureText(mSub, 0, mSub.length()) : 0;
    final int expandedAbsGravity = GravityCompat.getAbsoluteGravity(mExpandedTextGravity,
            mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR);
    switch (expandedAbsGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
    case Gravity.CENTER_HORIZONTAL:
        mExpandedDrawX = mExpandedBounds.centerX() - (width / 2);
        mExpandedDrawSubX = mExpandedBounds.centerX() - (subWidth / 2);
        break;
    case Gravity.RIGHT:
        mExpandedDrawX = mExpandedBounds.right - width;
        mExpandedDrawSubX = mExpandedBounds.right - subWidth;
        break;
    case Gravity.LEFT:
    default:
        mExpandedDrawX = mExpandedBounds.left;
        mExpandedDrawSubX = mExpandedBounds.left;
        break;
    }

    // The bounds have changed so we need to clear the texture
    clearTexture();
    // Now reset the text size back to the original
    setInterpolatedTextSize(currentTextSize);
}

From source file:org.rm3l.ddwrt.DDWRTMainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.d(TAG, "onActivityResult(" + requestCode + "," + resultCode + "," + data);
    // Check which request we're responding to
    switch (requestCode) {
    case LISTENED_REQUEST_CODE:
        //Forward to listener
        if (mCurrentActivityResultListener != null) {
            final DDWRTTile.ActivityResultListener listener = mCurrentActivityResultListener;
            mCurrentActivityResultListener = null;
            listener.onResultCode(resultCode, data);
        }/*  w  ww.j a va2  s.c  o  m*/
        break;
    case ROUTER_SETTINGS_ACTIVITY_CODE:
        // Make sure the request was successful and reload U if necessary
        if (resultCode == RESULT_OK) {
            if (this.mCurrentSyncInterval != this.mPreferences.getLong(SYNC_INTERVAL_MILLIS_PREF, -1l)
                    || this.mCurrentTheme != this.mPreferences.getLong(THEMING_PREF, -1l)
                    || !this.mCurrentSortingStrategy
                            .equals(this.mPreferences.getString(SORTING_STRATEGY_PREF, ""))) {
                //Reload UI
                final AlertDialog alertDialog = Utils.buildAlertDialog(this, null, "Reloading UI...", false,
                        false);
                alertDialog.show();
                ((TextView) alertDialog.findViewById(android.R.id.message))
                        .setGravity(Gravity.CENTER_HORIZONTAL);
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        finish();
                        startActivity(getIntent());
                        alertDialog.cancel();
                    }
                }, 2000);
            }
        }
        break;
    }

    super.onActivityResult(requestCode, resultCode, data);
}

From source file:ca.mudar.parkcatcher.ui.fragments.DetailsFragment.java

private TextView getPanel(String desc, LayoutParams params, int textColor) {
    desc = desc.trim().toUpperCase();/*from   w  w w .  j a v  a  2  s .  com*/
    final TextView panelUi = new TextView(getSherlockActivity());

    panelUi.setGravity(Gravity.CENTER_HORIZONTAL);
    panelUi.setLayoutParams(params);
    panelUi.setTextColor(textColor);

    String prefix = (String) desc.subSequence(0, 2);
    prefix = prefix.trim();
    try {
        // Start with a figure: authorized duration
        Integer.valueOf(prefix.trim());
        panelUi.setBackgroundResource(R.drawable.bg_panel_parking);
    } catch (NumberFormatException e) {
        if (desc.subSequence(0, 1).equals("P")) {
            // Starts with "P " (trimmed): authorized
            panelUi.setBackgroundResource(R.drawable.bg_panel_parking);
            desc = desc.substring(1);
        } else if (desc.subSequence(0, 2).equals("\\A")) {
            panelUi.setBackgroundResource(R.drawable.bg_panel_no_stopping);
            desc = desc.substring(2);
        } else if (desc.subSequence(0, 2).equals("\\P")) {
            panelUi.setBackgroundResource(R.drawable.bg_panel_no_parking);
            desc = desc.substring(2);
        } else {
            panelUi.setBackgroundResource(R.drawable.bg_panel_no_parking);
        }
    }

    panelUi.setText(desc.trim());

    return panelUi;
}

From source file:com.astuetz.PagerSlidingTabStripPlus.java

/**
 * Add new text view to the linear layout that contains the tab title*
 * @param position of the linear layout in the tabsContainer
 * @param text is the text of the subtitle
 *//*  w  ww  . j a  v a2  s.co m*/
public void addSubtitleAtTab(int position, String text) {
    LinearLayout tab = getSingleTabLayoutAtPosition(position);
    tab.setWeightSum(tab.getChildCount() + 1);
    if (tab.getChildCount() == 1) {
        tab.getChildAt(0).setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0, 1));
    }

    ((TextView) tab.getChildAt(0)).setGravity(Gravity.CENTER_HORIZONTAL);

    TextView newSubTab = new TextView(getContext());
    newSubTab.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0, 1));
    newSubTab.setText(text);
    newSubTab.setGravity(Gravity.CENTER_HORIZONTAL);

    tab.addView(newSubTab);
    updateTabStyles();
}

From source file:com.taobao.weex.extend.module.actionsheet.WXActionSheet.java

private void ensureTitle() {
    if (!TextUtils.isEmpty(titleText) || !TextUtils.isEmpty(messageText)) {
        LinearLayout titleContainer = new LinearLayout(getActivity());
        titleContainer.setOrientation(LinearLayout.VERTICAL);
        titleContainer.setGravity(Gravity.CENTER);
        titleContainer.setBackgroundColor(Color.WHITE);
        titleContainer/*from  w ww .j av  a 2s .  c  o  m*/
                .setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dp2px(56)));

        if (!TextUtils.isEmpty(titleText)) {
            TextView title = new TextView(getActivity());
            title.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT));
            title.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
            title.setText(titleText);
            title.setGravity(Gravity.CENTER_HORIZONTAL);
            title.setTextColor(COLOR_TITLE);
            title.getPaint().setFakeBoldText(true);
            titleContainer.addView(title);
        }

        if (!TextUtils.isEmpty(messageText)) {
            TextView message = new TextView(getActivity());
            message.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT));
            message.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
            message.setGravity(Gravity.CENTER_HORIZONTAL);
            message.setText(messageText);
            message.setTextColor(COLOR_TITLE);
            titleContainer.addView(message);
        }

        titleContainer.setClickable(true);
        titleContainer.setFocusableInTouchMode(true);

        sheetContainer.addView(titleContainer);
        sheetContainer.addView(createLine());
    }
}

From source file:com.android.contacts.list.DefaultContactBrowseListFragment.java

private View getEmptyAccountView(LayoutInflater inflater) {
    final View emptyAccountView = inflater.inflate(R.layout.empty_account_view, null);
    // Set image margins.
    final ImageView image = (ImageView) emptyAccountView.findViewById(R.id.empty_account_image);
    final LayoutParams params = (LayoutParams) image.getLayoutParams();
    final int height = getResources().getDisplayMetrics().heightPixels;
    final int divisor = getResources().getInteger(R.integer.empty_account_view_image_margin_divisor);
    final int offset = getResources().getDimensionPixelSize(R.dimen.empty_account_view_image_offset);
    params.setMargins(0, height / divisor + offset, 0, 0);
    params.gravity = Gravity.CENTER_HORIZONTAL;
    image.setLayoutParams(params);// ww w.j  av  a2s . c om

    // Set up add contact button.
    final Button addContactButton = (Button) emptyAccountView.findViewById(R.id.add_contact_button);
    addContactButton.setOnClickListener(mAddContactListener);
    return emptyAccountView;
}

From source file:net.opendasharchive.openarchive.ReviewMediaActivity.java

private void deleteMedia() {
    final Switch swDeleteLocal = new Switch(this);
    final Switch swDeleteRemote = new Switch(this);

    LinearLayout linearLayoutGroup = new LinearLayout(this);
    linearLayoutGroup.setOrientation(LinearLayout.VERTICAL);
    linearLayoutGroup.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    swDeleteLocal.setTextOn(getString(R.string.answer_yes));
    swDeleteLocal.setTextOff(getString(R.string.answer_no));

    TextView tvLocal = new TextView(this);
    tvLocal.setText(R.string.delete_local);

    LinearLayout linearLayout = new LinearLayout(this);
    linearLayout.setOrientation(LinearLayout.HORIZONTAL);
    linearLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    linearLayout.setGravity(Gravity.CENTER_HORIZONTAL);

    linearLayout.addView(tvLocal);/*ww  w. j  av a2  s.  c  om*/
    linearLayout.addView(swDeleteLocal);

    linearLayoutGroup.addView(linearLayout);

    if (mMedia.getServerUrl() != null) {
        swDeleteRemote.setTextOn(getString(R.string.answer_yes));
        swDeleteRemote.setTextOff(getString(R.string.answer_no));

        TextView tvRemote = new TextView(this);
        tvRemote.setText(R.string.delete_remote);

        LinearLayout linearLayoutRemote = new LinearLayout(this);
        linearLayoutRemote.setOrientation(LinearLayout.HORIZONTAL);
        linearLayoutRemote.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
        linearLayoutRemote.setGravity(Gravity.CENTER_HORIZONTAL);

        linearLayoutRemote.addView(tvRemote);
        linearLayoutRemote.addView(swDeleteRemote);
        linearLayoutGroup.addView(linearLayoutRemote);

    }

    AlertDialog.Builder build = new AlertDialog.Builder(ReviewMediaActivity.this).setTitle(R.string.menu_delete)
            .setMessage(R.string.alert_delete_media).setView(linearLayoutGroup).setCancelable(true)
            .setNegativeButton(R.string.dialog_cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    //do nothing
                }
            })

            .setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {

                    deleteMedia(swDeleteLocal.isChecked(), swDeleteRemote.isChecked());
                    finish();

                }
            });

    build.create().show();
}

From source file:com.adarshahd.indianrailinfo.donate.PNRStat.java

private void createTableLayoutTrnDtls() {
    if (mPageResult.contains("FLUSHED PNR / ") || mPageResult.contains("Invalid PNR")) {
        mTextViewPNRSts.setText("The PNR entered is either invalid or expired! Please check.");
        mFrameLayout.removeAllViews();//from w w w  .java2  s.c  o m
        mFrameLayout.addView(mTextViewPNRSts);
        return;
    }
    if (mPageResult.contains("Connectivity Failure") || mPageResult.contains("try again")) {
        mTextViewPNRSts.setText("Looks like server is busy or currently unavailable. Please try again later!");
        mFrameLayout.removeAllViews();
        mFrameLayout.addView(mTextViewPNRSts);
        return;
    }
    List<String> trainList;
    if (mTrainDetails == null || mTrainDetails.getPNR() != mPNRNumber) {
        Elements eleTrain = Jsoup.parse(mPageResult).select("table tr tr td:containsOwn(Train Number)");
        Iterator iteTrain = null;
        try {
            iteTrain = eleTrain.first().parent().parent().parent().getElementsByTag("tr").iterator();
        } catch (Exception e) {
            Log.i("PNRStat", mPageResult);
            return;
        }
        trainList = new ArrayList<String>();
        Element tmp;
        //Get the third row for train details
        iteTrain.next();
        iteTrain.next();
        if (iteTrain.hasNext()) {
            tmp = (Element) iteTrain.next();
            trainList.add(tmp.select("td").get(0).text());
            trainList.add(tmp.select("td").get(1).text());
            trainList.add(tmp.select("td").get(2).text());
            trainList.add(tmp.select("td").get(5).text());
            trainList.add(tmp.select("td").get(6).text());
            trainList.add(tmp.select("td").get(7).text());
        }
        mTrainDetails = new TrainDetails(trainList, mPNRNumber);
    } else {
        trainList = mTrainDetails.getTrainDetails();
    }
    mTableLayoutTrn = new TableLayout(mActivity);
    mTableLayoutTrn.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    TableRow row = new TableRow(mActivity);
    mStrTrainDetails = new String();
    row.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    for (String list : trainList) {
        TextView tv = new TextView(mActivity);
        tv.setText(list);
        tv.setPadding(10, 10, 10, 10);
        tv.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Small);
        row.addView(tv);
        mStrTrainDetails += list + " ";
    }
    row.setBackgroundResource(R.drawable.card_background);
    row.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
    mTableLayoutTrn.addView(row);
}

From source file:com.near.chimerarevo.fragments.PostFragment.java

private void addImage(final String imgUrl) {
    final ImageView img = new ImageView(getActivity());
    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    params.setMargins(15, 0, 15, 0);/*w w w  . j  av  a2 s  .co  m*/
    params.gravity = Gravity.CENTER_HORIZONTAL;
    img.setLayoutParams(params);
    img.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    lay.addView(img);

    final DisplayImageOptions options = new DisplayImageOptions.Builder().cacheOnDisk(false).cacheInMemory(true)
            .showImageOnLoading(R.drawable.empty_cr).bitmapConfig(Bitmap.Config.RGB_565)
            .imageScaleType(ImageScaleType.EXACTLY).delayBeforeLoading(150).build();
    ImageLoader.getInstance().displayImage(imgUrl, img, options);

    img.setClickable(true);
    img.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            final Dialog dialog = new Dialog(getActivity());
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setContentView(R.layout.img_dialog_layout);
            ImageLoader.getInstance().displayImage(imgUrl.split("\\?resize=")[0],
                    ((TouchImageView) dialog.findViewById(R.id.dialog_image)), options);
            dialog.setCancelable(true);
            dialog.show();
        }
    });
}

From source file:org.telegram.ui.ProfileNotificationsActivity.java

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setTitle(LocaleController.getString("NotificationsAndSounds", R.string.NotificationsAndSounds));
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override/* www . j av  a  2s  .  com*/
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });

    fragmentView = new FrameLayout(context);
    FrameLayout frameLayout = (FrameLayout) fragmentView;
    frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background));

    listView = new ListView(context);
    listView.setDivider(null);
    listView.setDividerHeight(0);
    listView.setVerticalScrollBarEnabled(false);
    AndroidUtilities.setListViewEdgeEffectColor(listView, AvatarDrawable.getProfileBackColorForId(5));
    frameLayout.addView(listView);
    final FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    listView.setLayoutParams(layoutParams);
    listView.setAdapter(new ListAdapter(context));
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
            if (i == settingsVibrateRow) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(LocaleController.getString("Vibrate", R.string.Vibrate));
                builder.setItems(
                        new CharSequence[] {
                                LocaleController.getString("VibrationDisabled", R.string.VibrationDisabled),
                                LocaleController.getString("SettingsDefault", R.string.SettingsDefault),
                                LocaleController.getString("SystemDefault", R.string.SystemDefault),
                                LocaleController.getString("Short", R.string.Short),
                                LocaleController.getString("Long", R.string.Long) },
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                SharedPreferences preferences = ApplicationLoader.applicationContext
                                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                                SharedPreferences.Editor editor = preferences.edit();
                                if (which == 0) {
                                    editor.putInt("vibrate_" + dialog_id, 2);
                                } else if (which == 1) {
                                    editor.putInt("vibrate_" + dialog_id, 0);
                                } else if (which == 2) {
                                    editor.putInt("vibrate_" + dialog_id, 4);
                                } else if (which == 3) {
                                    editor.putInt("vibrate_" + dialog_id, 1);
                                } else if (which == 4) {
                                    editor.putInt("vibrate_" + dialog_id, 3);
                                }
                                editor.commit();
                                if (listView != null) {
                                    listView.invalidateViews();
                                }
                            }
                        });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                showDialog(builder.create());
            } else if (i == settingsNotificationsRow) {
                if (getParentActivity() == null) {
                    return;
                }
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                builder.setItems(
                        new CharSequence[] { LocaleController.getString("Default", R.string.Default),
                                LocaleController.getString("Enabled", R.string.Enabled),
                                LocaleController.getString("NotificationsDisabled",
                                        R.string.NotificationsDisabled) },
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface d, int which) {
                                SharedPreferences preferences = ApplicationLoader.applicationContext
                                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                                SharedPreferences.Editor editor = preferences.edit();
                                editor.putInt("notify2_" + dialog_id, which);
                                if (which == 2) {
                                    NotificationsController.getInstance()
                                            .removeNotificationsForDialog(dialog_id);
                                }
                                MessagesStorage.getInstance().setDialogFlags(dialog_id, which == 2 ? 1 : 0);
                                editor.commit();
                                TLRPC.TL_dialog dialog = MessagesController.getInstance().dialogs_dict
                                        .get(dialog_id);
                                if (dialog != null) {
                                    dialog.notify_settings = new TLRPC.TL_peerNotifySettings();
                                    if (which == 2) {
                                        dialog.notify_settings.mute_until = Integer.MAX_VALUE;
                                    }
                                }
                                if (listView != null) {
                                    listView.invalidateViews();
                                }
                                NotificationsController.updateServerNotificationsSettings(dialog_id);
                            }
                        });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                showDialog(builder.create());
            } else if (i == settingsSoundRow) {
                try {
                    Intent tmpIntent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
                    tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
                    tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
                    tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI,
                            RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
                    SharedPreferences preferences = ApplicationLoader.applicationContext
                            .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                    Uri currentSound = null;

                    String defaultPath = null;
                    Uri defaultUri = Settings.System.DEFAULT_NOTIFICATION_URI;
                    if (defaultUri != null) {
                        defaultPath = defaultUri.getPath();
                    }

                    String path = preferences.getString("sound_path_" + dialog_id, defaultPath);
                    if (path != null && !path.equals("NoSound")) {
                        if (path.equals(defaultPath)) {
                            currentSound = defaultUri;
                        } else {
                            currentSound = Uri.parse(path);
                        }
                    }

                    tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, currentSound);
                    startActivityForResult(tmpIntent, 12);
                } catch (Exception e) {
                    FileLog.e("tmessages", e);
                }
            } else if (i == settingsLedRow) {
                if (getParentActivity() == null) {
                    return;
                }

                LinearLayout linearLayout = new LinearLayout(getParentActivity());
                linearLayout.setOrientation(LinearLayout.VERTICAL);
                final ColorPickerView colorPickerView = new ColorPickerView(getParentActivity());
                linearLayout.addView(colorPickerView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT,
                        LayoutHelper.WRAP_CONTENT, Gravity.CENTER));

                SharedPreferences preferences = ApplicationLoader.applicationContext
                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                if (preferences.contains("color_" + dialog_id)) {
                    colorPickerView.setOldCenterColor(preferences.getInt("color_" + dialog_id, 0xff00ff00));
                } else {
                    if ((int) dialog_id < 0) {
                        colorPickerView.setOldCenterColor(preferences.getInt("GroupLed", 0xff00ff00));
                    } else {
                        colorPickerView.setOldCenterColor(preferences.getInt("MessagesLed", 0xff00ff00));
                    }
                }

                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(LocaleController.getString("LedColor", R.string.LedColor));
                builder.setView(linearLayout);
                builder.setPositiveButton(LocaleController.getString("Set", R.string.Set),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int which) {
                                final SharedPreferences preferences = ApplicationLoader.applicationContext
                                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                                SharedPreferences.Editor editor = preferences.edit();
                                editor.putInt("color_" + dialog_id, colorPickerView.getColor());
                                editor.commit();
                                listView.invalidateViews();
                            }
                        });
                builder.setNeutralButton(LocaleController.getString("LedDisabled", R.string.LedDisabled),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                final SharedPreferences preferences = ApplicationLoader.applicationContext
                                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                                SharedPreferences.Editor editor = preferences.edit();
                                editor.putInt("color_" + dialog_id, 0);
                                editor.commit();
                                listView.invalidateViews();
                            }
                        });
                builder.setNegativeButton(LocaleController.getString("Default", R.string.Default),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                final SharedPreferences preferences = ApplicationLoader.applicationContext
                                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                                SharedPreferences.Editor editor = preferences.edit();
                                editor.remove("color_" + dialog_id);
                                editor.commit();
                                listView.invalidateViews();
                            }
                        });
                showDialog(builder.create());
            } else if (i == settingsPriorityRow) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(
                        LocaleController.getString("NotificationsPriority", R.string.NotificationsPriority));
                builder.setItems(
                        new CharSequence[] {
                                LocaleController.getString("SettingsDefault", R.string.SettingsDefault),
                                LocaleController.getString("NotificationsPriorityDefault",
                                        R.string.NotificationsPriorityDefault),
                                LocaleController.getString("NotificationsPriorityHigh",
                                        R.string.NotificationsPriorityHigh),
                                LocaleController.getString("NotificationsPriorityMax",
                                        R.string.NotificationsPriorityMax) },
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                if (which == 0) {
                                    which = 3;
                                } else {
                                    which--;
                                }
                                SharedPreferences preferences = ApplicationLoader.applicationContext
                                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                                preferences.edit().putInt("priority_" + dialog_id, which).commit();
                                if (listView != null) {
                                    listView.invalidateViews();
                                }
                            }
                        });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                showDialog(builder.create());
            } else if (i == smartRow) {
                if (getParentActivity() == null) {
                    return;
                }
                SharedPreferences preferences = ApplicationLoader.applicationContext
                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                int notifyMaxCount = preferences.getInt("smart_max_count_" + dialog_id, 2);
                int notifyDelay = preferences.getInt("smart_delay_" + dialog_id, 3 * 60);
                if (notifyMaxCount == 0) {
                    notifyMaxCount = 2;
                }

                LinearLayout linearLayout = new LinearLayout(getParentActivity());
                linearLayout.setOrientation(LinearLayout.VERTICAL);

                LinearLayout linearLayout2 = new LinearLayout(getParentActivity());
                linearLayout2.setOrientation(LinearLayout.HORIZONTAL);
                linearLayout.addView(linearLayout2);
                LinearLayout.LayoutParams layoutParams1 = (LinearLayout.LayoutParams) linearLayout2
                        .getLayoutParams();
                layoutParams1.width = LayoutHelper.WRAP_CONTENT;
                layoutParams1.height = LayoutHelper.WRAP_CONTENT;
                layoutParams1.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
                linearLayout2.setLayoutParams(layoutParams1);

                TextView textView = new TextView(getParentActivity());
                textView.setText(LocaleController.getString("SmartNotificationsSoundAtMost",
                        R.string.SmartNotificationsSoundAtMost));
                textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
                linearLayout2.addView(textView);
                layoutParams1 = (LinearLayout.LayoutParams) textView.getLayoutParams();
                layoutParams1.width = LayoutHelper.WRAP_CONTENT;
                layoutParams1.height = LayoutHelper.WRAP_CONTENT;
                layoutParams1.gravity = Gravity.CENTER_VERTICAL | Gravity.LEFT;
                textView.setLayoutParams(layoutParams1);

                final NumberPicker numberPickerTimes = new NumberPicker(getParentActivity());
                numberPickerTimes.setMinValue(1);
                numberPickerTimes.setMaxValue(10);
                numberPickerTimes.setValue(notifyMaxCount);
                linearLayout2.addView(numberPickerTimes);
                layoutParams1 = (LinearLayout.LayoutParams) numberPickerTimes.getLayoutParams();
                layoutParams1.width = AndroidUtilities.dp(50);
                numberPickerTimes.setLayoutParams(layoutParams1);

                textView = new TextView(getParentActivity());
                textView.setText(LocaleController.getString("SmartNotificationsTimes",
                        R.string.SmartNotificationsTimes));
                textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
                linearLayout2.addView(textView);
                layoutParams1 = (LinearLayout.LayoutParams) textView.getLayoutParams();
                layoutParams1.width = LayoutHelper.WRAP_CONTENT;
                layoutParams1.height = LayoutHelper.WRAP_CONTENT;
                layoutParams1.gravity = Gravity.CENTER_VERTICAL | Gravity.LEFT;
                textView.setLayoutParams(layoutParams1);

                linearLayout2 = new LinearLayout(getParentActivity());
                linearLayout2.setOrientation(LinearLayout.HORIZONTAL);
                linearLayout.addView(linearLayout2);
                layoutParams1 = (LinearLayout.LayoutParams) linearLayout2.getLayoutParams();
                layoutParams1.width = LayoutHelper.WRAP_CONTENT;
                layoutParams1.height = LayoutHelper.WRAP_CONTENT;
                layoutParams1.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
                linearLayout2.setLayoutParams(layoutParams1);

                textView = new TextView(getParentActivity());
                textView.setText(LocaleController.getString("SmartNotificationsWithin",
                        R.string.SmartNotificationsWithin));
                textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
                linearLayout2.addView(textView);
                layoutParams1 = (LinearLayout.LayoutParams) textView.getLayoutParams();
                layoutParams1.width = LayoutHelper.WRAP_CONTENT;
                layoutParams1.height = LayoutHelper.WRAP_CONTENT;
                layoutParams1.gravity = Gravity.CENTER_VERTICAL | Gravity.LEFT;
                textView.setLayoutParams(layoutParams1);

                final NumberPicker numberPickerMinutes = new NumberPicker(getParentActivity());
                numberPickerMinutes.setMinValue(1);
                numberPickerMinutes.setMaxValue(10);
                numberPickerMinutes.setValue(notifyDelay / 60);
                linearLayout2.addView(numberPickerMinutes);
                layoutParams1 = (LinearLayout.LayoutParams) numberPickerMinutes.getLayoutParams();
                layoutParams1.width = AndroidUtilities.dp(50);
                numberPickerMinutes.setLayoutParams(layoutParams1);

                textView = new TextView(getParentActivity());
                textView.setText(LocaleController.getString("SmartNotificationsMinutes",
                        R.string.SmartNotificationsMinutes));
                textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
                linearLayout2.addView(textView);
                layoutParams1 = (LinearLayout.LayoutParams) textView.getLayoutParams();
                layoutParams1.width = LayoutHelper.WRAP_CONTENT;
                layoutParams1.height = LayoutHelper.WRAP_CONTENT;
                layoutParams1.gravity = Gravity.CENTER_VERTICAL | Gravity.LEFT;
                textView.setLayoutParams(layoutParams1);

                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(LocaleController.getString("SmartNotifications", R.string.SmartNotifications));
                builder.setView(linearLayout);
                builder.setPositiveButton(LocaleController.getString("OK", R.string.OK),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                SharedPreferences preferences = ApplicationLoader.applicationContext
                                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                                preferences.edit()
                                        .putInt("smart_max_count_" + dialog_id, numberPickerTimes.getValue())
                                        .commit();
                                preferences.edit()
                                        .putInt("smart_delay_" + dialog_id, numberPickerMinutes.getValue() * 60)
                                        .commit();
                                if (listView != null) {
                                    listView.invalidateViews();
                                }
                            }
                        });
                builder.setNegativeButton(LocaleController.getString("SmartNotificationsDisabled",
                        R.string.SmartNotificationsDisabled), new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                SharedPreferences preferences = ApplicationLoader.applicationContext
                                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                                preferences.edit().putInt("smart_max_count_" + dialog_id, 0).commit();
                                if (listView != null) {
                                    listView.invalidateViews();
                                }
                            }
                        });
                showDialog(builder.create());
            }
        }
    });

    return fragmentView;
}