Example usage for android.view Gravity CENTER_VERTICAL

List of usage examples for android.view Gravity CENTER_VERTICAL

Introduction

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

Prototype

int CENTER_VERTICAL

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

Click Source Link

Document

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

Usage

From source file:com.neka.cordova.inappbrowser.InAppBrowser.java

/**
 * Display a new browser with the specified URL.
 *
 * @param url           The url to load.
 * @param jsonObject/*from   ww  w  .  ja v  a 2 s  .  co  m*/
 */
public String showWebPage(final String url, HashMap<String, Boolean> features) {
    // Determine if we should hide the location bar.
    showLocationBar = true;
    openWindowHidden = false;
    if (features != null) {
        Boolean show = features.get(LOCATION);
        if (show != null) {
            showLocationBar = show.booleanValue();
        }
        Boolean hidden = features.get(HIDDEN);
        if (hidden != null) {
            openWindowHidden = hidden.booleanValue();
        }
        Boolean cache = features.get(CLEAR_ALL_CACHE);
        if (cache != null) {
            clearAllCache = cache.booleanValue();
        } else {
            cache = features.get(CLEAR_SESSION_CACHE);
            if (cache != null) {
                clearSessionCache = cache.booleanValue();
            }
        }
    }

    final CordovaWebView thatWebView = this.webView;

    // Create dialog in new thread
    Runnable runnable = new Runnable() {
        /**
         * Convert our DIP units to Pixels
         *
         * @return int
         */
        private int dpToPixels(int dipValue) {
            int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) dipValue,
                    cordova.getActivity().getResources().getDisplayMetrics());

            return value;
        }

        public void run() {
            // Let's create the main dialog
            dialog = new InAppBrowserDialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar);
            dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setInAppBroswer(getInAppBrowser());

            // Main container layout
            LinearLayout main = new LinearLayout(cordova.getActivity());
            main.setOrientation(LinearLayout.VERTICAL);

            // Toolbar layout
            RelativeLayout toolbar = new RelativeLayout(cordova.getActivity());
            //Please, no more black! 
            toolbar.setBackgroundColor(android.graphics.Color.LTGRAY);
            toolbar.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44)));
            toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2));
            toolbar.setHorizontalGravity(Gravity.LEFT);
            toolbar.setVerticalGravity(Gravity.TOP);

            // Action Button Container layout
            RelativeLayout actionButtonContainer = new RelativeLayout(cordova.getActivity());
            actionButtonContainer.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            actionButtonContainer.setHorizontalGravity(Gravity.LEFT);
            actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL);
            actionButtonContainer.setId(1);

            // Back button
            Button back = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT);
            back.setLayoutParams(backLayoutParams);
            back.setContentDescription("Back Button");
            back.setId(2);
            /*
            back.setText("<");
            */
            Resources activityRes = cordova.getActivity().getResources();
            int backResId = activityRes.getIdentifier("ic_action_previous_item", "drawable",
                    cordova.getActivity().getPackageName());
            Drawable backIcon = activityRes.getDrawable(backResId);
            if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
                back.setBackgroundDrawable(backIcon);
            } else {
                back.setBackground(backIcon);
            }
            back.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goBack();
                }
            });

            // Forward button
            Button forward = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2);
            forward.setLayoutParams(forwardLayoutParams);
            forward.setContentDescription("Forward Button");
            forward.setId(3);
            //forward.setText(">");
            int fwdResId = activityRes.getIdentifier("ic_action_next_item", "drawable",
                    cordova.getActivity().getPackageName());
            Drawable fwdIcon = activityRes.getDrawable(fwdResId);
            if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
                forward.setBackgroundDrawable(fwdIcon);
            } else {
                forward.setBackground(fwdIcon);
            }
            forward.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goForward();
                }
            });

            // Edit Text Box
            edittext = new EditText(cordova.getActivity());
            RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
            textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1);
            textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5);
            edittext.setLayoutParams(textLayoutParams);
            edittext.setId(4);
            edittext.setSingleLine(true);
            edittext.setText(url);
            edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
            edittext.setImeOptions(EditorInfo.IME_ACTION_GO);
            edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE
            edittext.setOnKeyListener(new View.OnKeyListener() {
                public boolean onKey(View v, int keyCode, KeyEvent event) {
                    // If the event is a key-down event on the "enter" button
                    if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                        navigate(edittext.getText().toString());
                        return true;
                    }
                    return false;
                }
            });

            // Close button
            Button close = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            close.setLayoutParams(closeLayoutParams);
            forward.setContentDescription("Close Button");
            close.setId(5);
            //close.setText(buttonLabel);
            int closeResId = activityRes.getIdentifier("ic_action_remove", "drawable",
                    cordova.getActivity().getPackageName());
            Drawable closeIcon = activityRes.getDrawable(closeResId);
            if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
                close.setBackgroundDrawable(closeIcon);
            } else {
                close.setBackground(closeIcon);
            }
            close.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    closeDialog();
                }
            });

            // WebView
            inAppWebView = new WebView(cordova.getActivity());
            inAppWebView.setLayoutParams(
                    new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
            inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView));
            WebViewClient client = new InAppBrowserClient(thatWebView, edittext);
            inAppWebView.setWebViewClient(client);
            WebSettings settings = inAppWebView.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setJavaScriptCanOpenWindowsAutomatically(true);
            settings.setBuiltInZoomControls(true);
            settings.setPluginState(android.webkit.WebSettings.PluginState.ON);

            //Toggle whether this is enabled or not!
            Bundle appSettings = cordova.getActivity().getIntent().getExtras();
            boolean enableDatabase = appSettings == null ? true
                    : appSettings.getBoolean("InAppBrowserStorageEnabled", true);
            if (enableDatabase) {
                String databasePath = cordova.getActivity().getApplicationContext()
                        .getDir("inAppBrowserDB", Context.MODE_PRIVATE).getPath();
                settings.setDatabasePath(databasePath);
                settings.setDatabaseEnabled(true);
            }
            settings.setDomStorageEnabled(true);

            if (clearAllCache) {
                CookieManager.getInstance().removeAllCookie();
            } else if (clearSessionCache) {
                CookieManager.getInstance().removeSessionCookie();
            }

            inAppWebView.loadUrl(url);
            inAppWebView.setId(6);
            inAppWebView.getSettings().setLoadWithOverviewMode(true);
            inAppWebView.getSettings().setUseWideViewPort(true);
            inAppWebView.requestFocus();
            inAppWebView.requestFocusFromTouch();

            // Add the back and forward buttons to our action button container layout
            actionButtonContainer.addView(back);
            actionButtonContainer.addView(forward);

            // Add the views to our toolbar
            //toolbar.addView(actionButtonContainer);
            //toolbar.addView(edittext);
            toolbar.addView(close);

            // Don't add the toolbar if its been disabled
            if (getShowLocationBar()) {
                // Add our toolbar to our main view/layout
                main.addView(toolbar);
            }

            // Add our webview to our main view/layout
            main.addView(inAppWebView);

            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
            lp.copyFrom(dialog.getWindow().getAttributes());
            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
            lp.height = WindowManager.LayoutParams.MATCH_PARENT;

            dialog.setContentView(main);
            dialog.show();
            dialog.getWindow().setAttributes(lp);
            // the goal of openhidden is to load the url and not display it
            // Show() needs to be called to cause the URL to be loaded
            if (openWindowHidden) {
                dialog.hide();
            }
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
    return "";
}

From source file:com.marlonjones.voidlauncher.allapps.AllAppsGridAdapter.java

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    switch (holder.getItemViewType()) {
    case VIEW_TYPE_ICON: {
        AppInfo info = mApps.getAdapterItems().get(position).appInfo;
        BubbleTextView icon = (BubbleTextView) holder.mContent;
        icon.applyFromApplicationInfo(info);
        icon.setAccessibilityDelegate(mLauncher.getAccessibilityDelegate());
        break;/*from  w  ww .j  a va  2s.c  om*/
    }
    case VIEW_TYPE_PREDICTION_ICON: {
        AppInfo info = mApps.getAdapterItems().get(position).appInfo;
        BubbleTextView icon = (BubbleTextView) holder.mContent;
        icon.applyFromApplicationInfo(info);
        icon.setAccessibilityDelegate(mLauncher.getAccessibilityDelegate());
        break;
    }
    case VIEW_TYPE_EMPTY_SEARCH:
        TextView emptyViewText = (TextView) holder.mContent;
        emptyViewText.setText(mEmptySearchMessage);
        emptyViewText.setGravity(
                mApps.hasNoFilteredResults() ? Gravity.CENTER : Gravity.START | Gravity.CENTER_VERTICAL);
        break;
    case VIEW_TYPE_SEARCH_MARKET:
        TextView searchView = (TextView) holder.mContent;
        if (mMarketSearchIntent != null) {
            searchView.setVisibility(View.VISIBLE);
        } else {
            searchView.setVisibility(View.GONE);
        }
        break;
    }
    if (mBindViewCallback != null) {
        mBindViewCallback.onBindView(holder);
    }
}

From source file:com.actionbarsherlock.internal.view.menu.ActionMenuView.java

@Override
protected LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) {
    if (p instanceof LayoutParams) {
        LayoutParams result = new LayoutParams((LayoutParams) p);
        if (result.gravity <= Gravity.NO_GRAVITY) {
            result.gravity = Gravity.CENTER_VERTICAL;
        }/*from   w  w  w. j  a va 2s .  co  m*/
        return result;
    }
    return generateDefaultLayoutParams();
}

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

@Override
public View createView(Context context) {
    searching = false;//from w  w  w .  java2  s  .com
    searchWas = false;

    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);

    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == done_button) {
                if (currentStep == 0) {
                    if (donePressed) {
                        return;
                    }
                    if (nameTextView.length() == 0) {
                        Vibrator v = (Vibrator) getParentActivity().getSystemService(Context.VIBRATOR_SERVICE);
                        if (v != null) {
                            v.vibrate(200);
                        }
                        AndroidUtilities.shakeView(nameTextView, 2, 0);
                        return;
                    }
                    donePressed = true;
                    if (avatarUpdater.uploadingAvatar != null) {
                        createAfterUpload = true;
                        progressDialog = new ProgressDialog(getParentActivity());
                        progressDialog.setMessage(LocaleController.getString("Loading", R.string.Loading));
                        progressDialog.setCanceledOnTouchOutside(false);
                        progressDialog.setCancelable(false);
                        progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE,
                                LocaleController.getString("Cancel", R.string.Cancel),
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        createAfterUpload = false;
                                        progressDialog = null;
                                        donePressed = false;
                                        try {
                                            dialog.dismiss();
                                        } catch (Exception e) {
                                            FileLog.e("tmessages", e);
                                        }
                                    }
                                });
                        progressDialog.show();
                        return;
                    }
                    final int reqId = MessagesController.getInstance().createChat(
                            nameTextView.getText().toString(), new ArrayList<Integer>(),
                            descriptionTextView.getText().toString(), ChatObject.CHAT_TYPE_CHANNEL,
                            ChannelCreateActivity.this);
                    progressDialog = new ProgressDialog(getParentActivity());
                    progressDialog.setMessage(LocaleController.getString("Loading", R.string.Loading));
                    progressDialog.setCanceledOnTouchOutside(false);
                    progressDialog.setCancelable(false);
                    progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE,
                            LocaleController.getString("Cancel", R.string.Cancel),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    ConnectionsManager.getInstance().cancelRequest(reqId, true);
                                    donePressed = false;
                                    try {
                                        dialog.dismiss();
                                    } catch (Exception e) {
                                        FileLog.e("tmessages", e);
                                    }
                                }
                            });
                    progressDialog.show();
                } else if (currentStep == 1) {
                    if (!isPrivate) {
                        if (nameTextView.length() == 0) {
                            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                            builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                            builder.setMessage(LocaleController.getString("ChannelPublicEmptyUsername",
                                    R.string.ChannelPublicEmptyUsername));
                            builder.setPositiveButton(LocaleController.getString("Close", R.string.Close),
                                    null);
                            showDialog(builder.create());
                            return;
                        } else {
                            if (!lastNameAvailable) {
                                Vibrator v = (Vibrator) getParentActivity()
                                        .getSystemService(Context.VIBRATOR_SERVICE);
                                if (v != null) {
                                    v.vibrate(200);
                                }
                                AndroidUtilities.shakeView(checkTextView, 2, 0);
                                return;
                            } else {
                                MessagesController.getInstance().updateChannelUserName(chatId, lastCheckName);
                            }
                        }
                    }
                    Bundle args = new Bundle();
                    args.putInt("step", 2);
                    args.putInt("chat_id", chatId);
                    presentFragment(new ChannelCreateActivity(args), true);
                } else {
                    ArrayList<TLRPC.InputUser> result = new ArrayList<>();
                    for (Integer uid : selectedContacts.keySet()) {
                        TLRPC.InputUser user = MessagesController
                                .getInputUser(MessagesController.getInstance().getUser(uid));
                        if (user != null) {
                            result.add(user);
                        }
                    }
                    MessagesController.getInstance().addUsersToChannel(chatId, result, null);
                    NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
                    Bundle args2 = new Bundle();
                    args2.putInt("chat_id", chatId);
                    presentFragment(new ChatActivity(args2), true);
                }
            }
        }
    });

    ActionBarMenu menu = actionBar.createMenu();
    doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));

    if (currentStep != 2) {
        fragmentView = new ScrollView(context);
        ScrollView scrollView = (ScrollView) fragmentView;
        scrollView.setFillViewport(true);
        linearLayout = new LinearLayout(context);
        scrollView.addView(linearLayout, new ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
    } else {
        fragmentView = new LinearLayout(context);
        fragmentView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return true;
            }
        });
        linearLayout = (LinearLayout) fragmentView;
    }
    linearLayout.setOrientation(LinearLayout.VERTICAL);

    if (currentStep == 0) {
        actionBar.setTitle(LocaleController.getString("NewChannel", R.string.NewChannel));
        fragmentView.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background));
        FrameLayout frameLayout = new FrameLayout(context);
        linearLayout.addView(frameLayout,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

        avatarImage = new BackupImageView(context);
        avatarImage.setRoundRadius(AndroidUtilities.dp(32));
        avatarDrawable.setInfo(5, null, null, false);
        avatarDrawable.setDrawPhoto(true);
        avatarImage.setImageDrawable(avatarDrawable);
        frameLayout.addView(avatarImage,
                LayoutHelper.createFrame(64, 64,
                        Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT),
                        LocaleController.isRTL ? 0 : 16, 12, LocaleController.isRTL ? 16 : 0, 12));
        avatarImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (getParentActivity() == null) {
                    return;
                }
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());

                CharSequence[] items;

                if (avatar != null) {
                    items = new CharSequence[] { LocaleController.getString("FromCamera", R.string.FromCamera),
                            LocaleController.getString("FromGalley", R.string.FromGalley),
                            LocaleController.getString("DeletePhoto", R.string.DeletePhoto) };
                } else {
                    items = new CharSequence[] { LocaleController.getString("FromCamera", R.string.FromCamera),
                            LocaleController.getString("FromGalley", R.string.FromGalley) };
                }

                builder.setItems(items, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        if (i == 0) {
                            avatarUpdater.openCamera();
                        } else if (i == 1) {
                            avatarUpdater.openGallery();
                        } else if (i == 2) {
                            avatar = null;
                            uploadedAvatar = null;
                            avatarImage.setImage(avatar, "50_50", avatarDrawable);
                        }
                    }
                });
                showDialog(builder.create());
            }
        });

        nameTextView = new EditText(context);
        nameTextView.setHint(LocaleController.getString("EnterChannelName", R.string.EnterChannelName));
        if (nameToSet != null) {
            nameTextView.setText(nameToSet);
            nameToSet = null;
        }
        nameTextView.setMaxLines(4);
        nameTextView
                .setGravity(Gravity.CENTER_VERTICAL | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
        nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
        //nameTextView.setHintTextColor(0xff979797);
        nameTextView.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
        nameTextView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
        InputFilter[] inputFilters = new InputFilter[1];
        inputFilters[0] = new InputFilter.LengthFilter(100);
        nameTextView.setFilters(inputFilters);
        nameTextView.setPadding(0, 0, 0, AndroidUtilities.dp(8));
        AndroidUtilities.clearCursorDrawable(nameTextView);
        nameTextView.setTextColor(ContextCompat.getColor(context, R.color.primary_text));
        frameLayout.addView(nameTextView,
                LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT,
                        Gravity.CENTER_VERTICAL, LocaleController.isRTL ? 16 : 96, 0,
                        LocaleController.isRTL ? 96 : 16, 0));
        nameTextView.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                avatarDrawable.setInfo(5, nameTextView.length() > 0 ? nameTextView.getText().toString() : null,
                        null, false);
                avatarImage.invalidate();
            }
        });

        descriptionTextView = new EditText(context);
        descriptionTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
        //descriptionTextView.setHintTextColor(0xff979797);
        descriptionTextView.setTextColor(ContextCompat.getColor(context, R.color.primary_text));
        descriptionTextView.setPadding(0, 0, 0, AndroidUtilities.dp(6));
        descriptionTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
        descriptionTextView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES
                | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
        descriptionTextView.setImeOptions(EditorInfo.IME_ACTION_DONE);
        inputFilters = new InputFilter[1];
        inputFilters[0] = new InputFilter.LengthFilter(120);
        descriptionTextView.setFilters(inputFilters);
        descriptionTextView
                .setHint(LocaleController.getString("DescriptionPlaceholder", R.string.DescriptionPlaceholder));
        AndroidUtilities.clearCursorDrawable(descriptionTextView);
        linearLayout.addView(descriptionTextView,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 24, 18, 24, 0));
        descriptionTextView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
                if (i == EditorInfo.IME_ACTION_DONE && doneButton != null) {
                    doneButton.performClick();
                    return true;
                }
                return false;
            }
        });
        descriptionTextView.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {

            }

            @Override
            public void afterTextChanged(Editable editable) {

            }
        });

        TextView helpTextView = new TextView(context);
        helpTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
        //helpTextView.setTextColor(0xff6d6d72);
        helpTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
        helpTextView.setText(LocaleController.getString("DescriptionInfo", R.string.DescriptionInfo));
        linearLayout.addView(helpTextView,
                LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT,
                        LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT, 24, 10, 24, 20));
    } else if (currentStep == 1) {
        actionBar.setTitle(LocaleController.getString("ChannelSettings", R.string.ChannelSettings));
        fragmentView.setBackgroundColor(ContextCompat.getColor(context, R.color.settings_background));

        LinearLayout linearLayout2 = new LinearLayout(context);
        linearLayout2.setOrientation(LinearLayout.VERTICAL);
        linearLayout2.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background));
        linearLayout2.setElevation(AndroidUtilities.dp(2));
        linearLayout.addView(linearLayout2,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

        radioButtonCell1 = new RadioButtonCell(context);
        radioButtonCell1.setElevation(0);
        radioButtonCell1.setForeground(R.drawable.list_selector);
        radioButtonCell1.setTextAndValue(LocaleController.getString("ChannelPublic", R.string.ChannelPublic),
                LocaleController.getString("ChannelPublicInfo", R.string.ChannelPublicInfo), !isPrivate, false);
        linearLayout2.addView(radioButtonCell1,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
        radioButtonCell1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!isPrivate) {
                    return;
                }
                isPrivate = false;
                updatePrivatePublic();
            }
        });

        radioButtonCell2 = new RadioButtonCell(context);
        radioButtonCell2.setElevation(0);
        radioButtonCell2.setForeground(R.drawable.list_selector);
        radioButtonCell2.setTextAndValue(LocaleController.getString("ChannelPrivate", R.string.ChannelPrivate),
                LocaleController.getString("ChannelPrivateInfo", R.string.ChannelPrivateInfo), isPrivate,
                false);
        linearLayout2.addView(radioButtonCell2,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
        radioButtonCell2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (isPrivate) {
                    return;
                }
                isPrivate = true;
                updatePrivatePublic();
            }
        });

        sectionCell = new ShadowSectionCell(context);
        linearLayout.addView(sectionCell,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

        linkContainer = new LinearLayout(context);
        linkContainer.setOrientation(LinearLayout.VERTICAL);
        linkContainer.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background));
        linkContainer.setElevation(AndroidUtilities.dp(2));
        linearLayout.addView(linkContainer,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

        headerCell = new HeaderCell(context);
        linkContainer.addView(headerCell);

        publicContainer = new LinearLayout(context);
        publicContainer.setOrientation(LinearLayout.HORIZONTAL);
        linkContainer.addView(publicContainer,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, 17, 7, 17, 0));

        EditText editText = new EditText(context);
        editText.setText("telegram.me/");
        editText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
        //editText.setHintTextColor(0xff979797);
        editText.setTextColor(ContextCompat.getColor(context, R.color.primary_text));
        editText.setMaxLines(1);
        editText.setLines(1);
        editText.setEnabled(false);
        editText.setBackgroundDrawable(null);
        editText.setPadding(0, 0, 0, 0);
        editText.setSingleLine(true);
        editText.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
        editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
        publicContainer.addView(editText, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, 36));

        nameTextView = new EditText(context);
        nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
        //nameTextView.setHintTextColor(0xff979797);
        nameTextView.setTextColor(ContextCompat.getColor(context, R.color.primary_text));
        nameTextView.setMaxLines(1);
        nameTextView.setLines(1);
        nameTextView.setBackgroundDrawable(null);
        nameTextView.setPadding(0, 0, 0, 0);
        nameTextView.setSingleLine(true);
        nameTextView.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS
                | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
        nameTextView.setImeOptions(EditorInfo.IME_ACTION_DONE);
        nameTextView.setHint(
                LocaleController.getString("ChannelUsernamePlaceholder", R.string.ChannelUsernamePlaceholder));
        AndroidUtilities.clearCursorDrawable(nameTextView);
        publicContainer.addView(nameTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36));
        nameTextView.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
                checkUserName(nameTextView.getText().toString());
            }

            @Override
            public void afterTextChanged(Editable editable) {

            }
        });

        privateContainer = new TextBlockCell(context);
        privateContainer.setForeground(R.drawable.list_selector);
        privateContainer.setElevation(0);
        linkContainer.addView(privateContainer);
        privateContainer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (invite == null) {
                    return;
                }
                try {
                    android.content.ClipboardManager clipboard = (android.content.ClipboardManager) ApplicationLoader.applicationContext
                            .getSystemService(Context.CLIPBOARD_SERVICE);
                    android.content.ClipData clip = android.content.ClipData.newPlainText("label", invite.link);
                    clipboard.setPrimaryClip(clip);
                    Toast.makeText(getParentActivity(),
                            LocaleController.getString("LinkCopied", R.string.LinkCopied), Toast.LENGTH_SHORT)
                            .show();
                } catch (Exception e) {
                    FileLog.e("tmessages", e);
                }
            }
        });

        checkTextView = new TextView(context);
        checkTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
        checkTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
        checkTextView.setVisibility(View.GONE);
        linkContainer.addView(checkTextView,
                LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT,
                        LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT, 17, 3, 17, 7));

        typeInfoCell = new TextInfoPrivacyCell(context);
        //typeInfoCell.setBackgroundResource(R.drawable.greydivider_bottom);
        linearLayout.addView(typeInfoCell,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

        loadingAdminedCell = new LoadingCell(context);
        linearLayout.addView(loadingAdminedCell,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

        adminedInfoCell = new TextInfoPrivacyCell(context);
        //adminedInfoCell.setBackgroundResource(R.drawable.greydivider_bottom);
        linearLayout.addView(adminedInfoCell,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

        updatePrivatePublic();
    } else if (currentStep == 2) {
        actionBar.setTitle(LocaleController.getString("ChannelAddMembers", R.string.ChannelAddMembers));
        actionBar.setSubtitle(LocaleController.formatPluralString("Members", selectedContacts.size()));

        searchListViewAdapter = new SearchAdapter(context, null, false, false, false, false);
        searchListViewAdapter.setCheckedMap(selectedContacts);
        searchListViewAdapter.setUseUserCell(true);
        listViewAdapter = new ContactsAdapter(context, 1, false, null, false);
        listViewAdapter.setCheckedMap(selectedContacts);

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

        linearLayout.addView(frameLayout,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

        nameTextView = new EditText(context);
        nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
        //nameTextView.setHintTextColor(0xff979797);
        nameTextView.setTextColor(ContextCompat.getColor(context, R.color.primary_text));
        nameTextView.setInputType(InputType.TYPE_TEXT_VARIATION_FILTER | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
                | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
        nameTextView.setMinimumHeight(AndroidUtilities.dp(54));
        nameTextView.setSingleLine(false);
        nameTextView.setLines(2);
        nameTextView.setMaxLines(2);
        nameTextView.setVerticalScrollBarEnabled(true);
        nameTextView.setHorizontalScrollBarEnabled(false);
        nameTextView.setPadding(0, 0, 0, 0);
        nameTextView.setHint(LocaleController.getString("AddMutual", R.string.AddMutual));
        nameTextView.setTextIsSelectable(false);
        nameTextView.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
        nameTextView
                .setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
        AndroidUtilities.clearCursorDrawable(nameTextView);
        frameLayout.addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
                LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 10, 0, 10, 0));

        nameTextView.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int start, int count, int after) {
                if (!ignoreChange) {
                    beforeChangeIndex = nameTextView.getSelectionStart();
                    changeString = new SpannableString(charSequence);
                }
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                if (!ignoreChange) {
                    boolean search = false;
                    int afterChangeIndex = nameTextView.getSelectionEnd();
                    if (editable.toString().length() < changeString.toString().length()) {
                        String deletedString = "";
                        try {
                            deletedString = changeString.toString().substring(afterChangeIndex,
                                    beforeChangeIndex);
                        } catch (Exception e) {
                            FileLog.e("tmessages", e);
                        }
                        if (deletedString.length() > 0) {
                            if (searching && searchWas) {
                                search = true;
                            }
                            Spannable span = nameTextView.getText();
                            for (int a = 0; a < allSpans.size(); a++) {
                                ChipSpan sp = allSpans.get(a);
                                if (span.getSpanStart(sp) == -1) {
                                    allSpans.remove(sp);
                                    selectedContacts.remove(sp.uid);
                                }
                            }
                            actionBar.setSubtitle(
                                    LocaleController.formatPluralString("Members", selectedContacts.size()));
                            listView.invalidateViews();
                        } else {
                            search = true;
                        }
                    } else {
                        search = true;
                    }
                    if (search) {
                        String text = nameTextView.getText().toString().replace("<", "");
                        if (text.length() != 0) {
                            searching = true;
                            searchWas = true;
                            if (listView != null) {
                                listView.setAdapter(searchListViewAdapter);
                                searchListViewAdapter.notifyDataSetChanged();
                                listView.setFastScrollAlwaysVisible(false);
                                listView.setFastScrollEnabled(false);
                                listView.setVerticalScrollBarEnabled(true);
                            }
                            if (emptyTextView != null) {
                                emptyTextView
                                        .setText(LocaleController.getString("NoResult", R.string.NoResult));
                            }
                            searchListViewAdapter.searchDialogs(text);
                        } else {
                            searchListViewAdapter.searchDialogs(null);
                            searching = false;
                            searchWas = false;
                            listView.setAdapter(listViewAdapter);
                            listViewAdapter.notifyDataSetChanged();
                            listView.setFastScrollAlwaysVisible(true);
                            listView.setFastScrollEnabled(true);
                            listView.setVerticalScrollBarEnabled(false);
                            emptyTextView
                                    .setText(LocaleController.getString("NoContacts", R.string.NoContacts));
                        }
                    }
                }
            }
        });

        LinearLayout emptyTextLayout = new LinearLayout(context);
        emptyTextLayout.setVisibility(View.INVISIBLE);
        emptyTextLayout.setOrientation(LinearLayout.VERTICAL);
        linearLayout.addView(emptyTextLayout,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
        emptyTextLayout.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return true;
            }
        });

        emptyTextView = new TextView(context);
        emptyTextView.setTextColor(0xff808080);
        emptyTextView.setTextSize(20);
        emptyTextView.setGravity(Gravity.CENTER);
        emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts));
        emptyTextLayout.addView(emptyTextView,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 0.5f));

        FrameLayout frameLayout2 = new FrameLayout(context);
        emptyTextLayout.addView(frameLayout2,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 0.5f));

        listView = new LetterSectionsListView(context);
        listView.setEmptyView(emptyTextLayout);
        listView.setVerticalScrollBarEnabled(false);
        listView.setDivider(null);
        listView.setDividerHeight(0);
        listView.setFastScrollEnabled(true);
        listView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
        listView.setAdapter(listViewAdapter);
        listView.setFastScrollAlwaysVisible(true);
        listView.setVerticalScrollbarPosition(
                LocaleController.isRTL ? ListView.SCROLLBAR_POSITION_LEFT : ListView.SCROLLBAR_POSITION_RIGHT);
        linearLayout.addView(listView,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                TLRPC.User user;
                if (searching && searchWas) {
                    user = (TLRPC.User) searchListViewAdapter.getItem(i);
                } else {
                    int section = listViewAdapter.getSectionForPosition(i);
                    int row = listViewAdapter.getPositionInSectionForPosition(i);
                    if (row < 0 || section < 0) {
                        return;
                    }
                    user = (TLRPC.User) listViewAdapter.getItem(section, row);
                }
                if (user == null) {
                    return;
                }

                boolean check = true;
                if (selectedContacts.containsKey(user.id)) {
                    check = false;
                    try {
                        ChipSpan span = selectedContacts.get(user.id);
                        selectedContacts.remove(user.id);
                        SpannableStringBuilder text = new SpannableStringBuilder(nameTextView.getText());
                        text.delete(text.getSpanStart(span), text.getSpanEnd(span));
                        allSpans.remove(span);
                        ignoreChange = true;
                        nameTextView.setText(text);
                        nameTextView.setSelection(text.length());
                        ignoreChange = false;
                    } catch (Exception e) {
                        FileLog.e("tmessages", e);
                    }
                } else {
                    ignoreChange = true;
                    ChipSpan span = createAndPutChipForUser(user);
                    if (span != null) {
                        span.uid = user.id;
                    }
                    ignoreChange = false;
                    if (span == null) {
                        return;
                    }
                }
                actionBar.setSubtitle(LocaleController.formatPluralString("Members", selectedContacts.size()));
                if (searching || searchWas) {
                    ignoreChange = true;
                    SpannableStringBuilder ssb = new SpannableStringBuilder("");
                    for (ImageSpan sp : allSpans) {
                        ssb.append("<<");
                        ssb.setSpan(sp, ssb.length() - 2, ssb.length(),
                                SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
                    }
                    nameTextView.setText(ssb);
                    nameTextView.setSelection(ssb.length());
                    ignoreChange = false;

                    searchListViewAdapter.searchDialogs(null);
                    searching = false;
                    searchWas = false;
                    listView.setAdapter(listViewAdapter);
                    listViewAdapter.notifyDataSetChanged();
                    listView.setFastScrollAlwaysVisible(true);
                    listView.setFastScrollEnabled(true);
                    listView.setVerticalScrollBarEnabled(false);
                    emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts));
                } else {
                    if (view instanceof UserCell) {
                        ((UserCell) view).setChecked(check, true);
                    }
                }
            }
        });
        listView.setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView absListView, int i) {
                if (i == SCROLL_STATE_TOUCH_SCROLL) {
                    AndroidUtilities.hideKeyboard(nameTextView);
                }
                if (listViewAdapter != null) {
                    listViewAdapter.setIsScrolling(i != SCROLL_STATE_IDLE);
                }
            }

            @Override
            public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount,
                    int totalItemCount) {
                if (absListView.isFastScrollEnabled()) {
                    AndroidUtilities.clearDrawableAnimation(absListView);
                }
            }
        });
    }

    return fragmentView;
}

From source file:com.hippo.widget.slidingdrawerlayout.SlidingDrawerLayout.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    mInLayout = true;/* w  ww  .  j  a  va  2 s.c om*/
    final int width = r - l;
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);

        if (child.getVisibility() == GONE) {
            continue;
        }

        final LayoutParams lp = (LayoutParams) child.getLayoutParams();
        int paddingTop = 0;
        int paddingBottom = mFitPaddingBottom;
        if (child instanceof DrawerLayoutChild) {
            DrawerLayoutChild dlc = (DrawerLayoutChild) child;
            paddingTop = dlc.getLayoutPaddingTop();
            paddingBottom = dlc.getLayoutPaddingBottom() + mFitPaddingBottom;
        }
        if (child == mContentView) {
            child.layout(lp.leftMargin, lp.topMargin + paddingTop, lp.leftMargin + child.getMeasuredWidth(),
                    lp.topMargin + paddingTop + child.getMeasuredHeight());
        } else if (child == mShadow) {
            child.layout(0, 0, child.getMeasuredWidth(), child.getMeasuredHeight());
        } else { // Drawer, if it wasn't onMeasure would have thrown an exception.
            final int childWidth = child.getMeasuredWidth();
            final int childHeight = child.getMeasuredHeight();
            int childLeft;
            float percent;

            if (child == mLeftDrawer) {
                percent = mLeftPercent;
                childLeft = -childWidth + (int) (childWidth * percent);
            } else { // Right; onMeasure checked for us.
                percent = mRightPercent;
                childLeft = width - (int) (childWidth * percent);
            }

            final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;

            switch (vgrav) {
            default:
            case Gravity.TOP: {
                child.layout(childLeft, lp.topMargin + paddingTop, childLeft + childWidth,
                        lp.topMargin + paddingTop + childHeight);
                break;
            }

            case Gravity.BOTTOM: {
                final int height = b - t;
                child.layout(childLeft, height - lp.bottomMargin - paddingBottom - child.getMeasuredHeight(),
                        childLeft + childWidth, height - lp.bottomMargin - paddingBottom);
                break;
            }

            case Gravity.CENTER_VERTICAL: {
                final int height = b - t;
                int childTop = (height - childHeight - paddingTop - paddingBottom - lp.topMargin
                        - lp.bottomMargin) / 2 + paddingTop;
                // Offset for margins. If things don't fit right because of
                // bad measurement before, oh well.
                if (childTop < lp.topMargin + paddingTop) {
                    childTop = lp.topMargin + paddingTop;
                } else if (childTop + childHeight > height - paddingBottom - lp.bottomMargin) {
                    childTop = height - paddingBottom - lp.bottomMargin - childHeight;
                }
                child.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight);
                break;
            }
            }

            final int newVisibility = percent > 0 ? VISIBLE : INVISIBLE;
            if (child.getVisibility() != newVisibility) {
                child.setVisibility(newVisibility);
            }
        }
    }
    mInLayout = false;
}

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//from  w  ww  .  jav a 2 s.c om
        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;
}

From source file:org.nla.tarotdroid.lib.ui.GameSetHistoryActivity.java

/**
 * Starts the whole Facebook post process.
 * //from  w w  w  . j  a v a 2  s .  c om
 * @param session
 */
private void launchPostProcess(final Session session) {

    LayoutInflater inflater = getLayoutInflater();
    View layout = inflater.inflate(R.layout.toast, (ViewGroup) findViewById(R.id.toast_layout_root));

    ImageView image = (ImageView) layout.findViewById(R.id.image);
    image.setImageResource(R.drawable.icon_facebook_released);
    TextView text = (TextView) layout.findViewById(R.id.text);
    text.setText("Publication en cours");

    Toast toast = new Toast(getApplicationContext());
    toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.setView(layout);
    toast.show();

    Request request = Request.newMeRequest(session, new Request.GraphUserCallback() {

        @Override
        public void onCompleted(GraphUser user, Response response) {
            if (session == Session.getActiveSession()) {
                if (user != null) {
                    int notificationId = FacebookHelper
                            .showNotificationStartProgress(GameSetHistoryActivity.this);
                    AppContext.getApplication().getNotificationIds().put(tempGameSet.getUuid(), notificationId);

                    AppContext.getApplication().setLoggedFacebookUser(user);
                    UpSyncGameSetTask task = new UpSyncGameSetTask(GameSetHistoryActivity.this, progressDialog);
                    task.setCallback(GameSetHistoryActivity.this.upSyncCallback);
                    task.execute(tempGameSet);
                    currentRunningTask = task;
                }
            }
            if (response.getError() != null) {
                // //progressDialog.dismiss();
                // Session newSession = new
                // Session(GameSetHistoryActivity.this);
                // Session.setActiveSession(newSession);
                // newSession.openForPublish(new
                // Session.OpenRequest(GameSetHistoryActivity.this).setPermissions(Arrays.asList("publish_actions",
                // "email")).setCallback(facebookSessionStatusCallback));
            }
        }
    });
    request.executeAsync();
}

From source file:com.b44t.ui.Components.PasscodeView.java

private void checkFingerprint() {
    Activity parentActivity = (Activity) getContext();
    if (Build.VERSION.SDK_INT >= 23 && parentActivity != null && UserConfig.useFingerprint
            && !ApplicationLoader.mainInterfacePaused) {
        try {//from  w ww  . j a v  a  2  s  . co  m
            if (fingerprintDialog != null && fingerprintDialog.isShowing()) {
                return;
            }
        } catch (Exception e) {
            FileLog.e("messenger", e);
        }
        try {
            FingerprintManagerCompat fingerprintManager = FingerprintManagerCompat
                    .from(ApplicationLoader.applicationContext);
            if (fingerprintManager.isHardwareDetected() && fingerprintManager.hasEnrolledFingerprints()) {
                RelativeLayout relativeLayout = new RelativeLayout(getContext());
                relativeLayout.setPadding(AndroidUtilities.dp(16), AndroidUtilities.dp(16),
                        AndroidUtilities.dp(16), AndroidUtilities.dp(8));

                fingerprintStatusTextView = new TextView(getContext());
                fingerprintStatusTextView.setGravity(Gravity.CENTER_VERTICAL);
                fingerprintStatusTextView
                        .setText(ApplicationLoader.applicationContext.getString(R.string.FingerprintInfo));
                fingerprintStatusTextView.setTextAppearance(android.R.style.TextAppearance_Material_Subhead);
                relativeLayout.addView(fingerprintStatusTextView);
                RelativeLayout.LayoutParams layoutParams = LayoutHelper
                        .createRelative(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT);
                fingerprintStatusTextView.setLayoutParams(layoutParams);

                AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
                builder.setView(relativeLayout);
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
                    @Override
                    public void onDismiss(DialogInterface dialog) {
                        if (cancellationSignal != null) {
                            selfCancelled = true;
                            cancellationSignal.cancel();
                            cancellationSignal = null;
                        }
                    }
                });
                if (fingerprintDialog != null) {
                    try {
                        if (fingerprintDialog.isShowing()) {
                            fingerprintDialog.dismiss();
                        }
                    } catch (Exception e) {
                        FileLog.e("messenger", e);
                    }
                }
                fingerprintDialog = builder.show();

                cancellationSignal = new CancellationSignal();
                selfCancelled = false;
                fingerprintManager.authenticate(null, 0, cancellationSignal,
                        new FingerprintManagerCompat.AuthenticationCallback() {
                            @Override
                            public void onAuthenticationError(int errMsgId, CharSequence errString) {
                                if (!selfCancelled) {
                                    showFingerprintError(errString);
                                }
                            }

                            @Override
                            public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) {
                                showFingerprintError(helpString);
                            }

                            @Override
                            public void onAuthenticationFailed() {
                                showFingerprintError(LocaleController.getString("FingerprintNotRecognized",
                                        R.string.FingerprintNotRecognized));
                            }

                            @Override
                            public void onAuthenticationSucceeded(
                                    FingerprintManagerCompat.AuthenticationResult result) {
                                try {
                                    if (fingerprintDialog.isShowing()) {
                                        fingerprintDialog.dismiss();
                                    }
                                } catch (Exception e) {
                                    FileLog.e("messenger", e);
                                }
                                fingerprintDialog = null;
                                processDone(true);
                            }
                        }, null);
            }
        } catch (Throwable e) {
            //ignore
        }
    }
}

From source file:com.android.mylauncher3.allapps.AllAppsGridAdapter.java

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    switch (holder.getItemViewType()) {
    case ICON_VIEW_TYPE: {
        AppInfo info = mApps.getAdapterItems().get(position).appInfo;
        BubbleTextView icon = (BubbleTextView) holder.mContent;
        icon.applyFromApplicationInfo(info);
        break;/*from   w  w w  . j a v  a2 s.com*/
    }
    case PREDICTION_ICON_VIEW_TYPE: {
        AppInfo info = mApps.getAdapterItems().get(position).appInfo;
        BubbleTextView icon = (BubbleTextView) holder.mContent;
        icon.applyFromApplicationInfo(info);
        break;
    }
    case EMPTY_SEARCH_VIEW_TYPE:
        TextView emptyViewText = (TextView) holder.mContent;
        emptyViewText.setText(mEmptySearchMessage);
        emptyViewText.setGravity(
                mApps.hasNoFilteredResults() ? Gravity.CENTER : Gravity.START | Gravity.CENTER_VERTICAL);
        break;
    case SEARCH_MARKET_VIEW_TYPE:
        TextView searchView = (TextView) holder.mContent;
        if (mMarketSearchIntent != null) {
            searchView.setVisibility(View.VISIBLE);
            searchView.setContentDescription(mMarketSearchMessage);
            searchView.setGravity(
                    mApps.hasNoFilteredResults() ? Gravity.CENTER : Gravity.START | Gravity.CENTER_VERTICAL);
            searchView.setText(mMarketSearchMessage);
        } else {
            searchView.setVisibility(View.GONE);
        }
        break;
    }
}

From source file:at.alladin.rmbt.android.map.RMBTMapFragment.java

private void showInfoToast() {
    final Map<String, String> currentMapOptionTitles = ((RMBTMainActivity) getActivity())
            .getCurrentMapOptionTitles();
    String infoString = "";
    for (final String s : currentMapOptionTitles.values()) {
        if (infoString.length() > 0)
            infoString += "\n";

        infoString += s;//from  w  w w  .j a v a2s  . c om
    }
    if (infoString.length() > 0) {
        final Toast toast = Toast.makeText(getActivity(), infoString, Toast.LENGTH_LONG);
        toast.setGravity(Gravity.CENTER_VERTICAL | Gravity.BOTTOM, 0, 0);
        toast.show();
    }
}