Example usage for android.widget LinearLayout setOnTouchListener

List of usage examples for android.widget LinearLayout setOnTouchListener

Introduction

In this page you can find the example usage for android.widget LinearLayout setOnTouchListener.

Prototype

public void setOnTouchListener(OnTouchListener l) 

Source Link

Document

Register a callback to be invoked when a touch event is sent to this view.

Usage

From source file:com.ezeeideas.wordjam.TestDialog.java

private void refreshData() {
    if (mType == TEST_RESULT_PASS) {
        setContentView(R.layout.test_pass);
    } else if (mType == TEST_RESULT_FAIL) {
        setContentView(R.layout.test_fail);

        TextView title = (TextView) findViewById(R.id.test_fail_title);
        TextView text = (TextView) findViewById(R.id.test_fail_text);

        if (mAnswer.length() > 0) {
            title.setText(mContext.getResources().getString(R.string.test_fail_title_with_answer));

            String text_str = String
                    .format(mContext.getResources().getString(R.string.test_fail_text_with_answer), mAnswer);
            text.setText(text_str);//from w w  w  .j  a v a 2  s  . co m
        } else {
            title.setText(mContext.getResources().getString(R.string.test_fail_title_without_answer));
            text.setText(mContext.getResources().getString(R.string.test_fail_text_without_answer));
        }

        LinearLayout layout = (LinearLayout) findViewById(R.id.layout_root);
        layout.setOnTouchListener(this);

        ImageView imageView = (ImageView) findViewById(R.id.test_fail_image);
        imageView.setOnTouchListener(new View.OnTouchListener() {

            public boolean onTouch(View v, MotionEvent event) {
                // TODO Auto-generated method stub
                Utils.Log("onTouch called for layout");
                return true;
            }
        });

        /*
        imageView.setOnTouchListener(new View.OnTouchListener() {
                   
           public boolean onTouch(View v, MotionEvent event) {
              // TODO Auto-generated method stub
              Utils.Log("onTouch2 called!");
              return true;
           }
        });
        */

    } else if (mType == TEST_RESULT_SUMMARY) {
        setContentView(R.layout.test_result);

        TextView total_tests = (TextView) findViewById(R.id.test_result_total_tests);
        total_tests.setText(Integer.toString(mNumTests));

        TextView passed_tests = (TextView) findViewById(R.id.test_result_passed_tests);
        passed_tests.setText(Integer.toString(mNumTestsPassed));

        TextView hints_used = (TextView) findViewById(R.id.test_result_hints_used);
        hints_used.setText(Integer.toString(mNumHintsUsed));
    }
}

From source file:com.yamin.kk.fragment.AudioMiniPlayer.java

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

    // Initialize the children
    mCover = (ImageView) v.findViewById(R.id.cover);
    mTitle = (TextView) v.findViewById(R.id.title);
    mArtist = (TextView) v.findViewById(R.id.artist);
    mPlayPause = (ImageButton) v.findViewById(R.id.play_pause);
    mForward = (ImageButton) v.findViewById(R.id.forward);
    mBackward = (ImageButton) v.findViewById(R.id.backward);
    mPlayPause.setOnClickListener(onMediaControlClickListener);
    mForward.setOnClickListener(onMediaControlClickListener);
    mBackward.setOnClickListener(onMediaControlClickListener);
    mProgressBar = (ProgressBar) v.findViewById(R.id.timeline);

    final LinearLayout root = (LinearLayout) v.findViewById(R.id.root_node);

    root.setOnTouchListener(new View.OnTouchListener() {
        @Override//from   w  w  w  .j  a  v  a2 s  . c  o m
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                mTouchX = event.getRawX();
                mTouchY = event.getRawY();
                break;
            case MotionEvent.ACTION_UP:
                if (mTouchY - event.getRawY() > root.getHeight()) {
                    Toast.makeText(AudioMiniPlayer.this.getActivity(), "AudioMiniPlayer swipe up",
                            Toast.LENGTH_SHORT).show();
                    return true;
                } else if (Math.abs(mTouchY - event.getRawY()) < 5 && Math.abs(mTouchX - event.getRawX()) < 5) {
                    // effectively a click
                    AudioPlayerFragment.start(getActivity());
                    return true;
                } else
                    return false;
            }
            return true;
        }
    });

    registerForContextMenu(v);
    return v;
}

From source file:com.hybris.mobile.activity.AccountListActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.account_list);
    setTitle(R.string.account_page_title);

    mLinks = new ArrayList<String>();
    mAdapter = new ArrayAdapter<String>(this, R.layout.row_singleline_with_icon, R.id.textViewSingleLine,
            mLinks);//from  w  w w .j a  va 2s.c om
    setListAdapter(mAdapter);

    getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> a, View v, int position, long l) {
            Intent intent = null;
            if (StringUtils.equals(mLinks.get(position), mLogin)) {
                intent = new Intent(AccountListActivity.this, LoginActivity.class);
                startActivity(intent);
            } else if (StringUtils.equals(mLinks.get(position), mLogout)) {
                logoutUser();
            } else if (StringUtils.equals(mLinks.get(position), mOrderHistory)) {
                intent = new Intent(AccountListActivity.this, OrderListActivity.class);
                startActivity(intent);
            } else if (StringUtils.equals(mLinks.get(position), mAddressBook)) {
                intent = new Intent(AccountListActivity.this, AddressListActivity.class);
                startActivity(intent);
            } else if (StringUtils.equals(mLinks.get(position), mChangePassword)) {
                intent = new Intent(AccountListActivity.this, ChangePasswordActivity.class);
                startActivity(intent);
            } else if (StringUtils.equals(mLinks.get(position), mUpdateProfile)) {
                intent = new Intent(AccountListActivity.this, ProfileDetailActivity.class);
                // TODO
                intent.putExtra("value", JsonUtils.toJson(mProfileDetail));
                startActivity(intent);
            } else if (StringUtils.equals(mLinks.get(position), mPaymentDetails)) {
                intent = new Intent(AccountListActivity.this, PaymentListActivity.class);
                startActivity(intent);
            } else {
                return;
            }
        }
    });

    LinearLayout layoutSwipe = (LinearLayout) findViewById(R.id.layoutSwipe);
    layoutSwipe.setOnTouchListener(new SwipeDetector(new SwipeDetector.OnSwipeListener() {

        @Override
        public void onTopToBottomSwipe() {
            // TODO Auto-generated method stub

        }

        @Override
        public void onRightToLeftSwipe() {
            // TODO Auto-generated method stub

        }

        @Override
        public void onLeftToRightSwipe() {
            Intent intent = new Intent(AccountListActivity.this, SettingsActivity.class);
            startActivity(intent);
        }

        @Override
        public void onBottomToTopSwipe() {
            // TODO Auto-generated method stub

        }
    }));
}

From source file:com.nanostuffs.yurdriver.fragment.BankDetails.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // TODO Auto-generated method stub

    View view = inflater.inflate(R.layout.bank_details, container, false);

    submit = (MyFontTextView) view.findViewById(R.id.tvRegisterSubmit);
    edt_accno = (EditText) view.findViewById(R.id.accountnumber);
    edt_bankname = (EditText) view.findViewById(R.id.bankname);
    edt_routing = (EditText) view.findViewById(R.id.routing);
    edit_paypal = (EditText) view.findViewById(R.id.paypal);

    preferenceHelper = new PreferenceHelper(registerActivity);

    submit.setOnClickListener(this);

    LinearLayout lin = (LinearLayout) view.findViewById(R.id.mainLay);
    lin.setOnTouchListener(new OnTouchListener() {

        @Override/*from  w  w  w.j  a va2s  . co m*/
        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
            HideSoftKeyBoard hid = new HideSoftKeyBoard(getActivity());
            hid.hideKeyboard(getActivity());
            return false;
        }
    });

    return view;

}

From source file:com.synchophy.ui.CoverFlowActivity.java

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

    setContentView(R.layout.coverflow);/*from  www.  j  a  v  a  2 s  .c om*/

    Spinner browseSpinner = (Spinner) this.findViewById(R.id.browseSpinner);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
            new String[] { "Covers", "Albums", "Artists" });
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    browseSpinner.setAdapter(adapter);

    ActivitySwipeDetector activitySwipeDetector = new ActivitySwipeDetector(this) {
        @Override
        public void onLeftToRightSwipe() {
            CoverFlowActivity.this.finish();
            overridePendingTransition(R.anim.hold, R.anim.push_out_to_right);
        }

        @Override
        public void onBottomToTopSwipe() {
            showPlaylist();
        }

    };

    LinearLayout lowestLayout = (LinearLayout) this.findViewById(R.id.coverflowBack);
    lowestLayout.setOnTouchListener(activitySwipeDetector);

    coverFlow = (CoverFlow) findViewById(R.id.coverflow);
    coverFlow.setSpacing(-25);
    coverFlow.setSelection(4, true);
    coverFlow.setAnimationDuration(1000);
    registerForContextMenu(coverFlow);

    ImageAdapter coverImageAdapter = new ImageAdapter(CoverFlowActivity.this);
    coverFlow.setAdapter(coverImageAdapter);

    refresh();
}

From source file:edu.Groove9.TunesMaster.songplayer.SongPlayerFragment.java

private void setupSongPanel(View root) {
    //Set up song panel (gestures)
    LinearLayout songPanel = (LinearLayout) root.findViewById(R.id.song_player_song_panel);
    songPanel.setOnTouchListener(new OnSwipeTouchListener(getActivity()) {
        public void onSwipeTop() {
            Toast.makeText(getActivity(), "Increase Volume", Toast.LENGTH_SHORT).show();
            mPresenter.volumeUp();/*from   w  ww.ja  v  a  2 s .com*/
        }

        public void onSwipeRight() {
            mPresenter.lastSong();
            Logger.get().log(new UserEvent(UserEvent.Source.Gesture, UserEvent.Action.Next));
        }

        public void onSwipeLeft() {
            mPresenter.nextSong();
            Logger.get().log(new UserEvent(UserEvent.Source.Gesture, UserEvent.Action.Last));
        }

        public void onSwipeBottom() {
            Toast.makeText(getActivity(), "Decrease Volume", Toast.LENGTH_SHORT).show();
            mPresenter.volumeDown();
        }

        public void onSingleTap() {
            mPresenter.playPauseSong();
            Logger.get().log(new UserEvent(UserEvent.Source.Gesture, UserEvent.Action.PlayPause));
        }
    });
}

From source file:org.cafemember.messenger.mytg.fragments.TransfareActivity.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    context = getContext();//w w w  .  java2s  .  c o m
    //        View layout = inflater.inflate(R.layout.channels_layout, null);
    /*this.context = context;
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setTitle(LocaleController.getString("MenuTransfare", R.string.MenuTransfare));
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
    @Override
    public void onItemClick(int id) {
        if (id == -1) {
            finishFragment();
        } else if (id == done_button) {
            saveName();
        }else if (id == contact_button) {
            getContacts();
        }
    }
    });
            
    ActionBarMenu menu = actionBar.createMenu();
    contactsButton = menu.addItemWithWidth(contact_button, R.drawable.user_profile, AndroidUtilities.dp(56));
    doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
    */

    LinearLayout fragmentView = new LinearLayout(context);
    ((LinearLayout) fragmentView).setOrientation(LinearLayout.VERTICAL);
    fragmentView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });
    TextView ruleTextView = new TextView(context);
    ruleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
    ruleTextView.setTextColor(0xff212121);
    ruleTextView.setGravity(Gravity.RIGHT);
    //        ruleTextView.setText(AndroidUtilities.replaceTags(LocaleController.getString("ShareText", R.string.ShareText)));
    ruleTextView.setText(LocaleController.getString("transfare_rule", R.string.transfare_rule));
    ((LinearLayout) fragmentView).addView(ruleTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT,
            LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 24, 10, 24, 30));

    phoneField = new EditText(context);
    phoneField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    phoneField.setHintTextColor(0xff979797);
    phoneField.setTextColor(0xff212121);
    phoneField.setMaxLines(1);
    phoneField.setLines(1);
    phoneField.setGravity(Gravity.RIGHT);
    phoneField.setPadding(0, 0, 0, 0);
    phoneField.setSingleLine(true);
    phoneField.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
    phoneField.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_TEXT_FLAG_MULTI_LINE
            | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
    phoneField.setImeOptions(EditorInfo.IME_ACTION_DONE);
    phoneField.setHint(LocaleController.getString("TransfareUserHint", R.string.TransfareUserHint));
    AndroidUtilities.clearCursorDrawable(phoneField);

    amountField = new EditText(context);
    amountField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    amountField.setHintTextColor(0xff979797);
    amountField.setTextColor(0xff212121);
    amountField.setMaxLines(1);
    amountField.setGravity(Gravity.RIGHT);
    amountField.setLines(1);
    amountField.setPadding(0, 0, 0, 0);
    amountField.setSingleLine(true);
    amountField.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
    amountField.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_TEXT_FLAG_MULTI_LINE
            | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
    amountField.setImeOptions(EditorInfo.IME_ACTION_DONE);
    amountField.setHint(LocaleController.getString("TransfareAmountHint", R.string.TransfareAmountHint));
    AndroidUtilities.clearCursorDrawable(amountField);

    phoneField.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;
        }
    });

    ((LinearLayout) fragmentView).addView(phoneField,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, 24, 24, 24, 0));

    checkTextView = new TextView(context);
    checkTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
    checkTextView.setGravity(Gravity.RIGHT);
    ((LinearLayout) fragmentView).addView(checkTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT,
            LayoutHelper.WRAP_CONTENT, LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT, 24, 12, 24, 0));

    Button button = new Button(context);

    button.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
    button.setTextColor(0xff6d6d72);
    button.setGravity(Gravity.CENTER);
    TextView helpTextView = new TextView(context);
    helpTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
    helpTextView.setTextColor(0xff6d6d72);
    helpTextView.setGravity(Gravity.RIGHT);
    helpTextView.setText(AndroidUtilities.replaceTags(LocaleController.getString("RefHelp", R.string.RefHelp)));
    button.setText("");
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            saveName();
        }
    });
    ((LinearLayout) fragmentView).addView(helpTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT,
            LayoutHelper.WRAP_CONTENT, LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT, 24, 10, 24, 0));
    ((LinearLayout) fragmentView).addView(amountField,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, 24, 24, 24, 0));
    ((LinearLayout) fragmentView).addView(button,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 24, 24, 24, 0));

    /*View v = LayoutInflater.from(context).inflate(R.layout.transfare_type, null);
    typeJoin = (RadioButton)v.findViewById(R.id.joinRadio);
    typeView = (RadioButton)v.findViewById(R.id.viewRadio);
    ((LinearLayout) fragmentView).addView(v, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, 24, 24, 24, 0));*/
    phoneField.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(phoneField.getText().toString(), false);
        }

        @Override
        public void afterTextChanged(Editable editable) {

        }
    });

    checkTextView.setVisibility(View.GONE);
    FontManager.instance().setTypefaceImmediate(fragmentView);

    return fragmentView;
}

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

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    if (addContact) {
        actionBar.setTitle(LocaleController.getString("AddContactTitle", R.string.AddContactTitle));
    } else {/*ww  w  .  ja v a  2 s  .c om*/
        actionBar.setTitle(LocaleController.getString("EditName", R.string.EditName));
    }
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == done_button) {
                if (firstNameField.getText().length() != 0) {
                    TLRPC.User user = MessagesController.getInstance().getUser(user_id);
                    user.first_name = firstNameField.getText().toString();
                    user.last_name = lastNameField.getText().toString();
                    ContactsController.getInstance().addContact(user);
                    finishFragment();
                    SharedPreferences preferences = ApplicationLoader.applicationContext
                            .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                    preferences.edit().putInt("spam3_" + user_id, 1).commit();
                    NotificationCenter.getInstance().postNotificationName(NotificationCenter.updateInterfaces,
                            MessagesController.UPDATE_MASK_NAME);
                }
            }
        }
    });

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

    fragmentView = new ScrollView(context);

    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    ((ScrollView) fragmentView).addView(linearLayout);
    ScrollView.LayoutParams layoutParams2 = (ScrollView.LayoutParams) linearLayout.getLayoutParams();
    layoutParams2.width = ScrollView.LayoutParams.MATCH_PARENT;
    layoutParams2.height = ScrollView.LayoutParams.WRAP_CONTENT;
    linearLayout.setLayoutParams(layoutParams2);
    linearLayout.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });

    FrameLayout frameLayout = new FrameLayout(context);
    linearLayout.addView(frameLayout);
    LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) frameLayout.getLayoutParams();
    layoutParams.topMargin = AndroidUtilities.dp(24);
    layoutParams.leftMargin = AndroidUtilities.dp(24);
    layoutParams.rightMargin = AndroidUtilities.dp(24);
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.WRAP_CONTENT;
    frameLayout.setLayoutParams(layoutParams);

    avatarImage = new BackupImageView(context);
    avatarImage.setRoundRadius(AndroidUtilities.dp(30));
    frameLayout.addView(avatarImage);
    FrameLayout.LayoutParams layoutParams3 = (FrameLayout.LayoutParams) avatarImage.getLayoutParams();
    layoutParams3.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP;
    layoutParams3.width = AndroidUtilities.dp(60);
    layoutParams3.height = AndroidUtilities.dp(60);
    avatarImage.setLayoutParams(layoutParams3);

    nameTextView = new TextView(context);
    nameTextView.setTextColor(ContextCompat.getColor(context, R.color.primary_text));
    nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
    nameTextView.setLines(1);
    nameTextView.setMaxLines(1);
    nameTextView.setSingleLine(true);
    nameTextView.setEllipsize(TextUtils.TruncateAt.END);
    nameTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
    nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    frameLayout.addView(nameTextView);
    layoutParams3 = (FrameLayout.LayoutParams) nameTextView.getLayoutParams();
    layoutParams3.width = LayoutHelper.WRAP_CONTENT;
    layoutParams3.height = LayoutHelper.WRAP_CONTENT;
    layoutParams3.leftMargin = AndroidUtilities.dp(LocaleController.isRTL ? 0 : 80);
    layoutParams3.rightMargin = AndroidUtilities.dp(LocaleController.isRTL ? 80 : 0);
    layoutParams3.topMargin = AndroidUtilities.dp(3);
    layoutParams3.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP;
    nameTextView.setLayoutParams(layoutParams3);

    onlineTextView = new TextView(context);
    onlineTextView.setTextColor(0xff999999);
    onlineTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    onlineTextView.setLines(1);
    onlineTextView.setMaxLines(1);
    onlineTextView.setSingleLine(true);
    onlineTextView.setEllipsize(TextUtils.TruncateAt.END);
    onlineTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
    frameLayout.addView(onlineTextView);
    layoutParams3 = (FrameLayout.LayoutParams) onlineTextView.getLayoutParams();
    layoutParams3.width = LayoutHelper.WRAP_CONTENT;
    layoutParams3.height = LayoutHelper.WRAP_CONTENT;
    layoutParams3.leftMargin = AndroidUtilities.dp(LocaleController.isRTL ? 0 : 80);
    layoutParams3.rightMargin = AndroidUtilities.dp(LocaleController.isRTL ? 80 : 0);
    layoutParams3.topMargin = AndroidUtilities.dp(32);
    layoutParams3.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP;
    onlineTextView.setLayoutParams(layoutParams3);

    firstNameField = new EditText(context);
    firstNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    //firstNameField.setHintTextColor(0xff979797);
    firstNameField.setTextColor(ContextCompat.getColor(context, R.color.primary_text));
    firstNameField.setMaxLines(1);
    firstNameField.setLines(1);
    firstNameField.setSingleLine(true);
    firstNameField.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
    firstNameField.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
    firstNameField.setImeOptions(EditorInfo.IME_ACTION_NEXT);
    firstNameField.setHint(LocaleController.getString("FirstName", R.string.FirstName));
    AndroidUtilities.clearCursorDrawable(firstNameField);
    linearLayout.addView(firstNameField);
    layoutParams = (LinearLayout.LayoutParams) firstNameField.getLayoutParams();
    layoutParams.topMargin = AndroidUtilities.dp(24);
    layoutParams.height = AndroidUtilities.dp(36);
    layoutParams.leftMargin = AndroidUtilities.dp(24);
    layoutParams.rightMargin = AndroidUtilities.dp(24);
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    firstNameField.setLayoutParams(layoutParams);
    firstNameField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            if (i == EditorInfo.IME_ACTION_NEXT) {
                lastNameField.requestFocus();
                lastNameField.setSelection(lastNameField.length());
                return true;
            }
            return false;
        }
    });

    lastNameField = new EditText(context);
    lastNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    //lastNameField.setHintTextColor(0xff979797);
    lastNameField.setTextColor(ContextCompat.getColor(context, R.color.primary_text));
    lastNameField.setMaxLines(1);
    lastNameField.setLines(1);
    lastNameField.setSingleLine(true);
    lastNameField.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
    lastNameField.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
    lastNameField.setImeOptions(EditorInfo.IME_ACTION_DONE);
    lastNameField.setHint(LocaleController.getString("LastName", R.string.LastName));
    AndroidUtilities.clearCursorDrawable(lastNameField);
    linearLayout.addView(lastNameField);
    layoutParams = (LinearLayout.LayoutParams) lastNameField.getLayoutParams();
    layoutParams.topMargin = AndroidUtilities.dp(16);
    layoutParams.height = AndroidUtilities.dp(36);
    layoutParams.leftMargin = AndroidUtilities.dp(24);
    layoutParams.rightMargin = AndroidUtilities.dp(24);
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    lastNameField.setLayoutParams(layoutParams);
    lastNameField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            if (i == EditorInfo.IME_ACTION_DONE) {
                doneButton.performClick();
                return true;
            }
            return false;
        }
    });

    TLRPC.User user = MessagesController.getInstance().getUser(user_id);
    if (user != null) {
        if (user.phone == null) {
            if (phone != null) {
                user.phone = PhoneFormat.stripExceptNumbers(phone);
            }
        }
        firstNameField.setText(user.first_name);
        firstNameField.setSelection(firstNameField.length());
        lastNameField.setText(user.last_name);
    }

    return fragmentView;
}

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

@Override
public View createView(Context context) {
    searching = false;/*from   w  w w . j a  v a 2 s .  c o m*/
    searchWas = false;

    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setTitle(LocaleController.getString("Language", R.string.Language));

    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });

    ActionBarMenu menu = actionBar.createMenu();
    ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true)
            .setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
                @Override
                public void onSearchExpand() {
                    searching = true;
                }

                @Override
                public void onSearchCollapse() {
                    search(null);
                    searching = false;
                    searchWas = false;
                    if (listView != null) {
                        emptyTextView.setVisibility(View.GONE);
                        listView.setAdapter(listAdapter);
                    }
                }

                @Override
                public void onTextChanged(EditText editText) {
                    String text = editText.getText().toString();
                    search(text);
                    if (text.length() != 0) {
                        searchWas = true;
                        if (listView != null) {
                            listView.setAdapter(searchListViewAdapter);
                        }
                    }
                }
            });
    item.getSearchField().setHint(LocaleController.getString("Search", R.string.Search));

    listAdapter = new ListAdapter(context);
    searchListViewAdapter = new SearchAdapter(context);

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

    LinearLayout emptyTextLayout = new LinearLayout(context);
    emptyTextLayout.setVisibility(View.INVISIBLE);
    emptyTextLayout.setOrientation(LinearLayout.VERTICAL);
    ((FrameLayout) fragmentView).addView(emptyTextLayout);
    FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) emptyTextLayout.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    layoutParams.gravity = Gravity.TOP;
    emptyTextLayout.setLayoutParams(layoutParams);
    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("NoResult", R.string.NoResult));
    emptyTextLayout.addView(emptyTextView);
    LinearLayout.LayoutParams layoutParams1 = (LinearLayout.LayoutParams) emptyTextView.getLayoutParams();
    layoutParams1.width = LayoutHelper.MATCH_PARENT;
    layoutParams1.height = LayoutHelper.MATCH_PARENT;
    layoutParams1.weight = 0.5f;
    emptyTextView.setLayoutParams(layoutParams1);

    FrameLayout frameLayout = new FrameLayout(context);
    emptyTextLayout.addView(frameLayout);
    layoutParams1 = (LinearLayout.LayoutParams) frameLayout.getLayoutParams();
    layoutParams1.width = LayoutHelper.MATCH_PARENT;
    layoutParams1.height = LayoutHelper.MATCH_PARENT;
    layoutParams1.weight = 0.5f;
    frameLayout.setLayoutParams(layoutParams1);

    listView = new ListView(context);
    listView.setEmptyView(emptyTextLayout);
    listView.setVerticalScrollBarEnabled(false);
    listView.setDivider(null);
    listView.setDividerHeight(0);
    listView.setAdapter(listAdapter);
    ((FrameLayout) fragmentView).addView(listView);
    layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    listView.setLayoutParams(layoutParams);

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            LocaleController.LocaleInfo localeInfo = null;
            if (searching && searchWas) {
                if (i >= 0 && i < searchResult.size()) {
                    localeInfo = searchResult.get(i);
                }
            } else {
                if (i >= 0 && i < LocaleController.getInstance().sortedLanguages.size()) {
                    localeInfo = LocaleController.getInstance().sortedLanguages.get(i);
                }
            }
            if (localeInfo != null) {
                LocaleController.getInstance().applyLanguage(localeInfo, true);
                parentLayout.rebuildAllFragmentViews(false);
            }
            finishFragment();
        }
    });

    listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
            LocaleController.LocaleInfo localeInfo = null;
            if (searching && searchWas) {
                if (i >= 0 && i < searchResult.size()) {
                    localeInfo = searchResult.get(i);
                }
            } else {
                if (i >= 0 && i < LocaleController.getInstance().sortedLanguages.size()) {
                    localeInfo = LocaleController.getInstance().sortedLanguages.get(i);
                }
            }
            if (localeInfo == null || localeInfo.pathToFile == null || getParentActivity() == null) {
                return false;
            }
            final LocaleController.LocaleInfo finalLocaleInfo = localeInfo;
            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
            builder.setMessage(LocaleController.getString("DeleteLocalization", R.string.DeleteLocalization));
            builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
            builder.setPositiveButton(LocaleController.getString("Delete", R.string.Delete),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            if (LocaleController.getInstance().deleteLanguage(finalLocaleInfo)) {
                                if (searchResult != null) {
                                    searchResult.remove(finalLocaleInfo);
                                }
                                if (listAdapter != null) {
                                    listAdapter.notifyDataSetChanged();
                                }
                                if (searchListViewAdapter != null) {
                                    searchListViewAdapter.notifyDataSetChanged();
                                }
                            }
                        }
                    });
            builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
            showDialog(builder.create());
            return true;
        }
    });

    listView.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView absListView, int i) {
            if (i == SCROLL_STATE_TOUCH_SCROLL && searching && searchWas) {
                AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
            }
        }

        @Override
        public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount,
                int totalItemCount) {
        }
    });

    return fragmentView;
}

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

@Override
public View createView(Context context) {
    searching = false;//from w  ww  .j  a v  a  2  s  .c  o m
    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;
}