Example usage for android.view.inputmethod InputMethodManager showSoftInput

List of usage examples for android.view.inputmethod InputMethodManager showSoftInput

Introduction

In this page you can find the example usage for android.view.inputmethod InputMethodManager showSoftInput.

Prototype

public boolean showSoftInput(View view, int flags) 

Source Link

Document

Synonym for #showSoftInput(View,int,ResultReceiver) without a result receiver: explicitly request that the current input method's soft input area be shown to the user, if needed.

Usage

From source file:ua.mkh.settings.full.MainActivity.java

@SuppressLint("NewApi")
@Override/*w w  w.java2 s. c  o  m*/
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //try {
    String roman = "fonts/Regular.otf";
    String medium = "fonts/Medium.otf";
    String bold = "fonts/Bold.otf";
    String thin = "fonts/Thin.otf";
    typefaceRoman = Typeface.createFromAsset(getAssets(), roman);
    typefaceMedium = Typeface.createFromAsset(getAssets(), medium);
    typefaceBold = Typeface.createFromAsset(getAssets(), bold);
    typefaceThin = Typeface.createFromAsset(getAssets(), thin);

    mSettings = getSharedPreferences(APP_PREFERENCES, Context.MODE_PRIVATE);

    ll1 = (LinearLayout) findViewById(R.id.ll1);
    ll1.requestFocus();
    searchView = (SearchView) findViewById(R.id.search);
    searchView.setIconifiedByDefault(false);
    searchView.setOnQueryTextListener(this);
    searchView.setOnCloseListener(this);

    mListView = (ListView) findViewById(R.id.list);

    b1 = (Button) findViewById(R.id.button1);
    b2 = (Button) findViewById(R.id.button2);
    b11 = (Button) findViewById(R.id.button11);
    b21 = (Button) findViewById(R.id.button21);
    ed1 = (EditText) findViewById(R.id.EditText01);
    ed11 = (EditText) findViewById(R.id.EditText011);

    b21.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            b11.setVisibility(View.GONE);
            b21.setVisibility(View.GONE);
            ed11.clearFocus();
            ed1.clearFocus();
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(ed1.getWindowToken(), 0);
            ed11.setText("");
            ed1.setText("");
            LinearLayout list_res_top = (LinearLayout) findViewById(R.id.list_res_top);
            list_res_top.setVisibility(View.GONE);
            LinearLayout list_res = (LinearLayout) findViewById(R.id.list_res);
            list_res.setVisibility(View.GONE);
            ll1.setVisibility(View.VISIBLE);
            sear = false;
        }
    });

    ed1.setOnFocusChangeListener(new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                b11.setVisibility(View.VISIBLE);
                b21.setVisibility(View.VISIBLE);
                LinearLayout list_res_top = (LinearLayout) findViewById(R.id.list_res_top);
                list_res_top.setVisibility(View.VISIBLE);
                LinearLayout list_res = (LinearLayout) findViewById(R.id.list_res);
                list_res.setVisibility(View.VISIBLE);
                sear = true;

                //ll1.setVisibility(View.INVISIBLE);

                ed11.requestFocus();
                ed1.clearFocus();
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(ed11, InputMethodManager.SHOW_IMPLICIT);
                //LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
                //lp.setMargins(0, 0, 0, 0);
                //ll1.setLayoutParams(lp);

            } else {
                ll1.setVisibility(View.GONE);
                b11.setVisibility(View.VISIBLE);
                LinearLayout list_res = (LinearLayout) findViewById(R.id.list_res);
                list_res.setVisibility(View.VISIBLE);
                //LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
                //lp.setMargins(0, (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 39, getResources().getDisplayMetrics()), 0, 0);
                //ll1.setLayoutParams(lp);
            }
        }
    });

    ed11.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
            // When user changed the Text
            searchView.setQuery(cs, false);
            mListView.setVisibility(View.VISIBLE);

        }

        @Override
        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {

        }

        @Override
        public void afterTextChanged(Editable arg0) {

        }
    });

    mDbHelper = new CustomersDbAdapter(this);
    mDbHelper.open();

    /*
            
    //Clean all Customers
    mDbHelper.deleteAllCustomers();
            
    */
    //////////////////////

    LinearLayoutWiFi = (LinearLayout) findViewById(R.id.LinearLayoutWiFi);
    LinearLayoutBluetooth = (LinearLayout) findViewById(R.id.LinearLayoutBluetooth);
    LinearLayoutSotSvyaz = (LinearLayout) findViewById(R.id.LinearLayoutSotSvyaz);
    LinearLayoutOperator = (LinearLayout) findViewById(R.id.LinearLayoutOperator);
    LinearLayoutGeo = (LinearLayout) findViewById(R.id.LinearLayoutGeo);
    LinearLayoutNotif = (LinearLayout) findViewById(R.id.LinearLayoutNotif);
    LinearLayoutControl = (LinearLayout) findViewById(R.id.LinearLayoutControl);
    LinearLayoutMail = (LinearLayout) findViewById(R.id.LinearLayoutMail);
    LinearLayoutNotes = (LinearLayout) findViewById(R.id.LinearLayoutNotes);
    LinearLayoutMessages = (LinearLayout) findViewById(R.id.LinearLayoutMessages);
    LinearLayoutPhone = (LinearLayout) findViewById(R.id.LinearLayoutPhone);
    LinearLayoutSafari = (LinearLayout) findViewById(R.id.LinearLayoutSafari);
    LinearLayoutMusic = (LinearLayout) findViewById(R.id.LinearLayoutMusic);
    LinearLayoutCompass = (LinearLayout) findViewById(R.id.LinearLayoutCompass);
    LinearLayoutWeather = (LinearLayout) findViewById(R.id.LinearLayoutWeather);
    LinearLayoutGameCenter = (LinearLayout) findViewById(R.id.LinearLayoutGameCenter);
    LinearLayoutPasscode = (LinearLayout) findViewById(R.id.LinearLayoutPasscode);
    LinearLayoutPrivacy = (LinearLayout) findViewById(R.id.LinearLayoutPrivacy);
    LinearLayoutApn = (LinearLayout) findViewById(R.id.LinearLayoutApn);
    LinearLayoutCloud = (LinearLayout) findViewById(R.id.LinearLayoutCloud);
    LinearLayoutTunes = (LinearLayout) findViewById(R.id.LinearLayoutTunes);
    LinearLayoutMaps = (LinearLayout) findViewById(R.id.LinearLayoutMaps);
    LinearLayoutVk = (LinearLayout) findViewById(R.id.LinearLayoutVk);
    LinearLayoutViber = (LinearLayout) findViewById(R.id.LinearLayoutViber);
    LinearLayoutOk = (LinearLayout) findViewById(R.id.LinearLayoutOK);
    LinearLayoutSkype = (LinearLayout) findViewById(R.id.LinearLayoutSkype);
    LinearLayoutWhatsapp = (LinearLayout) findViewById(R.id.LinearLayoutWhatsApp);
    LinearLayoutTwitter = (LinearLayout) findViewById(R.id.LinearLayoutTwitter);
    LinearLayoutFacebook = (LinearLayout) findViewById(R.id.LinearLayoutFacebook);
    LinearLayoutInstagram = (LinearLayout) findViewById(R.id.LinearLayoutInstagram);

    LinearLayoutNew1 = (LinearLayout) findViewById(R.id.LinearLayoutApp1);
    LinearLayoutNew2 = (LinearLayout) findViewById(R.id.LinearLayoutApp2);
    LinearLayoutNew3 = (LinearLayout) findViewById(R.id.LinearLayoutApp3);
    LinearLayoutNew4 = (LinearLayout) findViewById(R.id.LinearLayoutApp4);

    LinearLayoutNew1.setVisibility(View.GONE);
    LinearLayoutNew2.setVisibility(View.GONE);
    LinearLayoutNew3.setVisibility(View.GONE);
    LinearLayoutNew4.setVisibility(View.GONE);

    LinearLayoutGeo.setVisibility(View.GONE);
    LinearLayoutMail.setVisibility(View.GONE);
    LinearLayoutNotes.setVisibility(View.GONE);
    LinearLayoutMessages.setVisibility(View.GONE);
    LinearLayoutPhone.setVisibility(View.GONE);
    LinearLayoutSafari.setVisibility(View.GONE);
    LinearLayoutMusic.setVisibility(View.GONE);
    LinearLayoutCompass.setVisibility(View.GONE);
    LinearLayoutWeather.setVisibility(View.GONE);
    LinearLayoutGameCenter.setVisibility(View.GONE);
    LinearLayoutNotif.setVisibility(View.GONE);
    LinearLayoutControl.setVisibility(View.GONE);
    LinearLayoutTunes.setVisibility(View.GONE);
    LinearLayoutMaps.setVisibility(View.GONE);
    LinearLayoutVk.setVisibility(View.GONE);
    LinearLayoutViber.setVisibility(View.GONE);
    LinearLayoutOk.setVisibility(View.GONE);
    LinearLayoutSkype.setVisibility(View.GONE);
    LinearLayoutWhatsapp.setVisibility(View.GONE);
    LinearLayoutTwitter.setVisibility(View.GONE);
    LinearLayoutFacebook.setVisibility(View.GONE);
    LinearLayoutInstagram.setVisibility(View.GONE);

    textwifi = (TextView) findViewById(R.id.textwifi);
    textbt = (TextView) findViewById(R.id.textbt);
    TextOper = (TextView) findViewById(R.id.TextOper);
    textVPN = (TextView) findViewById(R.id.TextView01);

    wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);

    btn_avia = (Button) findViewById(R.id.Button01);
    tb_am = (ToggleButton) findViewById(R.id.ToggleButton01);
    tb_am.setOnClickListener(this);

    btn_wifi = (Button) findViewById(R.id.ButtonWifi);
    btn_wifi.setOnClickListener(this);

    btn_bluetooth = (Button) findViewById(R.id.ButtonBluetooth);
    btn_bluetooth.setOnClickListener(this);

    btn_sota = (Button) findViewById(R.id.ButtonSota);
    btn_sota.setOnClickListener(this);

    startService(new Intent(this, NotificationService.class));

    btn_operator = (Button) findViewById(R.id.ButtonOperator);
    btn_operator.setOnClickListener(this);

    btn_osnova = (Button) findViewById(R.id.ButtonOsnova);
    btn_osnova.setOnClickListener(this);

    btn_zvuki = (Button) findViewById(R.id.ButtonZvuki);
    btn_zvuki.setOnClickListener(this);

    btn_oboi = (Button) findViewById(R.id.ButtonOboi);
    btn_oboi.setOnClickListener(this);

    btn_gps = (Button) findViewById(R.id.ButtonGeo);
    btn_gps.setOnClickListener(this);

    btn_passcode = (Button) findViewById(R.id.ButtonPasscode);
    btn_passcode.setOnClickListener(this);

    btn_battery = (Button) findViewById(R.id.ButtonBattery);
    btn_battery.setOnClickListener(this);

    btn_privacy = (Button) findViewById(R.id.ButtonPrivacy);
    btn_privacy.setOnClickListener(this);

    btn_notification = (Button) findViewById(R.id.ButtonNotification);
    btn_notification.setOnClickListener(this);

    btn_control = (Button) findViewById(R.id.ButtonControl);
    btn_control.setOnClickListener(this);

    btn_disturb = (Button) findViewById(R.id.ButtonDisturb);
    btn_disturb.setOnClickListener(this);

    btn_mail = (Button) findViewById(R.id.ButtonMail);
    btn_mail.setOnClickListener(this);

    btn_notes = (Button) findViewById(R.id.ButtonNotes);
    btn_notes.setOnClickListener(this);

    btn_messages = (Button) findViewById(R.id.ButtonMessages);
    btn_messages.setOnClickListener(this);

    btn_phone = (Button) findViewById(R.id.ButtonPhone);
    btn_phone.setOnClickListener(this);

    btn_safari = (Button) findViewById(R.id.ButtonSafari);
    btn_safari.setOnClickListener(this);

    btn_music = (Button) findViewById(R.id.ButtonMusic);
    btn_music.setOnClickListener(this);

    btn_compass = (Button) findViewById(R.id.ButtonCompass);
    btn_compass.setOnClickListener(this);

    btn_weather = (Button) findViewById(R.id.ButtonWeather);
    btn_weather.setOnClickListener(this);

    btn_games = (Button) findViewById(R.id.ButtonGameCenter);
    btn_games.setOnClickListener(this);

    btn_maps = (Button) findViewById(R.id.ButtonMaps);
    btn_maps.setOnClickListener(this);

    btn_vk = (Button) findViewById(R.id.ButtonVk);
    btn_vk.setOnClickListener(this);

    btn_viber = (Button) findViewById(R.id.ButtonViber);
    btn_viber.setOnClickListener(this);

    btn_ok = (Button) findViewById(R.id.ButtonOk);
    btn_ok.setOnClickListener(this);

    btn_skype = (Button) findViewById(R.id.ButtonSkype);
    btn_skype.setOnClickListener(this);

    btn_whatsapp = (Button) findViewById(R.id.ButtonWhatsapp);
    btn_whatsapp.setOnClickListener(this);

    btn_twitter = (Button) findViewById(R.id.ButtonTwitter);
    btn_twitter.setOnClickListener(this);

    btn_facebook = (Button) findViewById(R.id.ButtonFacebook);
    btn_facebook.setOnClickListener(this);

    btn_instagram = (Button) findViewById(R.id.ButtonInstagram);
    btn_instagram.setOnClickListener(this);

    btn_new1 = (Button) findViewById(R.id.Button02);
    btn_new1.setOnClickListener(this);

    btn_new2 = (Button) findViewById(R.id.Button03);
    btn_new2.setOnClickListener(this);

    btn_new3 = (Button) findViewById(R.id.Button04);
    btn_new3.setOnClickListener(this);

    btn_new4 = (Button) findViewById(R.id.Button05);
    btn_new4.setOnClickListener(this);

    btn_vpn = (Button) findViewById(R.id.Button06);
    btn_vpn.setOnClickListener(this);

    btn_display = (Button) findViewById(R.id.ButtonDisplay);
    btn_display.setOnClickListener(this);

    btn_iCloud = (Button) findViewById(R.id.ButtonCloud);
    btn_iCloud.setOnClickListener(this);

    btn_iTunes = (Button) findViewById(R.id.ButtonTunes);
    btn_iTunes.setOnClickListener(this);

    buttonBack = (Button) findViewById(R.id.buttonBack);
    btn_menu_settings = (Button) findViewById(R.id.ButtonMenuSettings);
    btn_menu_cancel = (Button) findViewById(R.id.ButtonMenuCancel);

    textView1 = (TextView) findViewById(R.id.textView1);
    textView2 = (TextView) findViewById(R.id.textView2);
    textView3 = (TextView) findViewById(R.id.textView3);

    text_app_main = (TextView) findViewById(R.id.text_app_main);

    text_app_main.setText(R.string.text_app_name);

    ImageView imageView2 = (ImageView) findViewById(R.id.imageView2);
    imageView2.setVisibility(View.GONE);

    text_app_main.setTypeface(typefaceBold);
    btn_avia.setTypeface(typefaceRoman);
    //textView1.setTypeface(typefaceRoman);
    textView3.setTypeface(typefaceRoman);
    btn_wifi.setTypeface(typefaceRoman);
    btn_bluetooth.setTypeface(typefaceRoman);
    btn_sota.setTypeface(typefaceRoman);
    btn_operator.setTypeface(typefaceRoman);
    btn_osnova.setTypeface(typefaceRoman);
    btn_passcode.setTypeface(typefaceRoman);
    btn_battery.setTypeface(typefaceRoman);
    btn_privacy.setTypeface(typefaceRoman);
    btn_zvuki.setTypeface(typefaceRoman);
    btn_oboi.setTypeface(typefaceRoman);
    btn_notification.setTypeface(typefaceRoman);
    btn_control.setTypeface(typefaceRoman);
    btn_disturb.setTypeface(typefaceRoman);
    btn_gps.setTypeface(typefaceRoman);
    btn_mail.setTypeface(typefaceRoman);
    btn_notes.setTypeface(typefaceRoman);
    btn_messages.setTypeface(typefaceRoman);
    btn_phone.setTypeface(typefaceRoman);
    btn_safari.setTypeface(typefaceRoman);
    btn_music.setTypeface(typefaceRoman);
    btn_compass.setTypeface(typefaceRoman);
    btn_weather.setTypeface(typefaceRoman);
    btn_games.setTypeface(typefaceRoman);
    btn_new1.setTypeface(typefaceRoman);
    btn_new2.setTypeface(typefaceRoman);
    btn_new3.setTypeface(typefaceRoman);
    btn_new4.setTypeface(typefaceRoman);
    btn_vpn.setTypeface(typefaceRoman);
    btn_display.setTypeface(typefaceRoman);
    btn_maps.setTypeface(typefaceRoman);
    btn_vk.setTypeface(typefaceRoman);
    btn_viber.setTypeface(typefaceRoman);
    btn_ok.setTypeface(typefaceRoman);
    btn_skype.setTypeface(typefaceRoman);
    btn_whatsapp.setTypeface(typefaceRoman);
    btn_twitter.setTypeface(typefaceRoman);
    btn_facebook.setTypeface(typefaceRoman);
    btn_instagram.setTypeface(typefaceRoman);

    btn_iCloud.setTypeface(typefaceRoman);
    btn_iTunes.setTypeface(typefaceRoman);

    textwifi.setTypeface(typefaceRoman);
    textbt.setTypeface(typefaceRoman);
    TextOper.setTypeface(typefaceRoman);
    textVPN.setTypeface(typefaceRoman);

    //LinearLayoutPrivacy.setVisibility(View.GONE);
    //LinearLayoutApn.setVisibility(View.GONE);
    //LinearLayoutPasscode.setVisibility(View.GONE);
    //layoutTunes.setVisibility(View.GONE);

    //////////////////START///////////////////   

    ///////////////////APP//////////////
    pm = this.getPackageManager();
    //Notification 
    notif_inoty = pm.getLaunchIntentForPackage("net.suckga.inoty");
    notif_espier = pm.getLaunchIntentForPackage("mobi.espier.launcher.plugin.notifications7pro");
    //Control Center
    control_hi = pm.getLaunchIntentForPackage("com.hi.apps.studio.control.center");
    control_espier = pm.getLaunchIntentForPackage("mobi.espier.launcher.plugin.controller7pro");
    //Mail
    mail_stok = pm.getLaunchIntentForPackage("com.android.email");
    //Phone
    phone_stok = pm.getLaunchIntentForPackage("com.android.dialer");
    //Messages
    messages_stok = pm.getLaunchIntentForPackage("com.android.mms");
    //Safari
    safari_stok = pm.getLaunchIntentForPackage("com.android.browser");
    //Music;
    music_stok = pm.getLaunchIntentForPackage("com.android.music");
    //VK
    vk_stok = pm.getLaunchIntentForPackage("com.vkontakte.android");
    //Viber
    viber_stok = pm.getLaunchIntentForPackage("com.viber.voip");
    //Ok
    ok_stok = pm.getLaunchIntentForPackage("ru.ok.android");
    //Skype
    skype_stok = pm.getLaunchIntentForPackage("com.skype.raider");
    //WhatsApp!!!!
    whatsapp_stok = pm.getLaunchIntentForPackage("com.whatsapp");
    //Twitter
    twitter_stok = pm.getLaunchIntentForPackage("com.twitter.android");
    //Facebook
    facebook_stok = pm.getLaunchIntentForPackage("com.facebook.katana");
    //Instagram
    instagram_stok = pm.getLaunchIntentForPackage("com.instagram.android");
    //Maps
    maps_stok = pm.getLaunchIntentForPackage("com.google.android.apps.maps");

    bt = BluetoothAdapter.getDefaultAdapter();
    //Check Availability of bluetooth
    if (bt == null) {
        LinearLayoutBluetooth.setVisibility(View.GONE);
    }
}

From source file:com.skytree.epubtest.BookViewActivity.java

public void showKeyboard() {
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(noteEditor, 0);
    noteEditor.requestFocus();/*from  w w w  .  ja  v a2s.  c o  m*/
}

From source file:com.irccloud.android.activity.MainActivity.java

@Override
public void onUserDoubleClicked(String from) {
    if (messageTxt == null || from == null || from.length() == 0)
        return;//from   ww  w  .  j  a va 2  s  .c  o  m

    if (!getSharedPreferences("prefs", 0).getBoolean("mentionTip", false)) {
        SharedPreferences.Editor editor = getSharedPreferences("prefs", 0).edit();
        editor.putBoolean("mentionTip", true);
        editor.commit();
    }

    if (drawerLayout != null)
        drawerLayout.closeDrawers();

    if (messageTxt.getText().length() == 0) {
        messageTxt.append(from + ": ");
    } else {
        int oldPosition = messageTxt.getSelectionStart();
        if (oldPosition < 0)
            oldPosition = 0;
        String text = messageTxt.getText().toString();
        int start = oldPosition - 1;
        if (start > 0 && text.charAt(start) == ' ')
            start--;
        while (start > 0 && text.charAt(start) != ' ')
            start--;
        int match = text.indexOf(from, start);
        int end = oldPosition + from.length();
        if (end > text.length() - 1)
            end = text.length() - 1;
        char nextChar = (match + from.length() < text.length()) ? text.charAt(match + from.length()) : 0;
        if (match >= 0 && match < end && (nextChar == 0 || nextChar == ' ' || nextChar == ':')) {
            String newtext = "";
            if (match > 1 && text.charAt(match - 1) == ' ')
                newtext = text.substring(0, match - 1);
            else
                newtext = text.substring(0, match);
            if (match + from.length() < text.length() && text.charAt(match + from.length()) == ':'
                    && match + from.length() + 1 < text.length()
                    && text.charAt(match + from.length() + 1) == ' ') {
                if (match + from.length() + 2 < text.length())
                    newtext += text.substring(match + from.length() + 2, text.length());
            } else if (match + from.length() < text.length()) {
                newtext += text.substring(match + from.length(), text.length());
            }
            if (newtext.endsWith(" "))
                newtext = newtext.substring(0, newtext.length() - 1);
            if (newtext.equals(":"))
                newtext = "";
            messageTxt.setText(newtext);
            if (match < newtext.length())
                messageTxt.setSelection(match);
            else
                messageTxt.setSelection(newtext.length());
        } else {
            if (oldPosition == text.length() - 1) {
                text += " " + from + " ";
            } else {
                String newtext = oldPosition > 0 ? text.substring(0, oldPosition) : "";
                if (!newtext.endsWith(" "))
                    from = " " + from;
                if (!text.substring(oldPosition, text.length()).startsWith(" "))
                    from += " ";
                newtext += from;
                newtext += text.substring(oldPosition, text.length());
                if (newtext.endsWith(" "))
                    newtext = newtext.substring(0, newtext.length() - 1);
                text = newtext + " ";
            }
            messageTxt.setText(text);
            if (text.length() > 0) {
                if (oldPosition + from.length() + 2 < text.length())
                    messageTxt.setSelection(oldPosition + from.length());
                else
                    messageTxt.setSelection(text.length());
            }
        }
    }
    messageTxt.requestFocus();
    InputMethodManager keyboard = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
    keyboard.showSoftInput(messageTxt, 0);
}

From source file:pl.edu.agh.mindmapex.gui.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    switch (item.getItemId()) {
    case R.id.action_settings:
        Intent intent = new Intent(MainActivity.this, EditSheetScreen.class);
        if (sheet1.getStyleId() != null && styleSheet.findStyle(sheet1.getStyleId()) != null
                && styleSheet.findStyle(sheet1.getStyleId()).getProperty(Styles.FillColor) != null) {
            intent.putExtra(BACKGROUNDCOLOR,
                    Color.parseColor(styleSheet.findStyle(sheet1.getStyleId()).getProperty(Styles.FillColor)));
        } else {//from  w ww.  j ava  2s  . co  m
            intent.putExtra(BACKGROUNDCOLOR, Color.WHITE);
        }
        startActivity(intent);
        return true;
    case R.id.action_undo:
        if (commandsUndo.size() == 1) {
            commandsUndo.getFirst().undo();
            if (commandsUndo.getFirst() instanceof EditBox) {
                Callback call = new Callback() {
                    @Override
                    public void execute() {
                        lay.updateBoxWithText(((EditBox) commandsUndo.getFirst()).box);
                        for (Box b : ((EditBox) commandsUndo.getLast()).edited) {
                            lay.updateBoxWithText(b);
                        }
                    }
                };
            } else if (commandsUndo.getFirst() instanceof EditSheet) {
                lay.setBackgroundColor((Color.parseColor(
                        MainActivity.styleSheet.findStyle(sheet1.getStyleId()).getProperty(Styles.FillColor))));
            } else {
                Callback call = new Callback() {
                    @Override
                    public void execute() {
                    }
                };
                try {
                    AsyncInvalidate async = new AsyncInvalidate(MainActivity.this);
                    async.setCallback(call);
                    async.execute();
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
            commandsRedo.add(commandsUndo.getFirst());
            commandsUndo.removeFirst();
            menu.getItem(6).setVisible(true);
            menu.getItem(5).setVisible(false);
        } else {
            commandsUndo.getLast().undo();
            if (commandsUndo.getLast() instanceof EditBox) {
                lay.updateBoxWithText(((EditBox) commandsUndo.getLast()).box);
                for (Box b : ((EditBox) commandsUndo.getLast()).edited) {
                    lay.updateBoxWithText(b);
                }
            } else if (commandsUndo.getLast() instanceof EditSheet) {
                lay.setBackgroundColor(Integer.parseInt(sheet1.getTheme().getProperty(Styles.FillColor)));
            } else if (commandsUndo.getLast() instanceof AddBox || commandsUndo.getLast() instanceof RemoveLine
                    || commandsUndo.getLast() instanceof RemoveBox) {
            }
            commandsRedo.add(commandsUndo.getLast());
            menu.getItem(6).setVisible(true);
            commandsUndo.removeLast();
        }
        return true;
    case R.id.action_new:
        IStyle boxEditedStyle = workbook.getStyleSheet().findStyle(boxEdited.topic.getStyleId());
        Intent intent1 = new Intent(MainActivity.this, EditBoxScreen.class);
        if (boxEditedStyle != null) {

            intent1.putExtra(EditBoxScreen.BOX_COLOR, boxEditedStyle.getProperty(Styles.FillColor));
            intent1.putExtra(EditBoxScreen.TEXT_COLOR, boxEdited.topic.getTitleText());
            intent1.putExtra(EditBoxScreen.LINE_SHAPE, boxEditedStyle.getProperty(Styles.LineClass));
            intent1.putExtra(EditBoxScreen.LINE_COLOR, boxEditedStyle.getProperty(Styles.LineColor));
            intent1.putExtra(EditBoxScreen.BOX_SHAPE, boxEditedStyle.getProperty(Styles.ShapeClass));
            intent1.putExtra(EditBoxScreen.LINE_THICKNESS, boxEditedStyle.getProperty(Styles.LineWidth));
        }
        startActivity(intent1);
        // lay.invalidateDrawable(boxEdited.drawableShape);
        return true;
    case R.id.new_line:
        Properties properties1 = new Properties();
        properties1.put("child", MainActivity.toEditBoxes.getFirst());
        if (MainActivity.toEditBoxes.size() == 2) {
            properties1.put("parent", MainActivity.toEditBoxes.getLast());
        }
        AddLine addLine = new AddLine();
        addLine.execute(properties1);
        MainActivity.addCommendUndo(addLine);
        //   lay.invalidate();
        return true;
    case R.id.action_redo:
        if (commandsRedo.size() == 1) {
            commandsRedo.getFirst().redo();
            if (commandsRedo.getFirst() instanceof EditBox) {
                //     Callback call = new Callback() {
                //         @Override
                //        public void execute() {
                lay.updateBoxWithText(((EditBox) commandsRedo.getFirst()).box);
                for (Box b : ((EditBox) commandsRedo.getLast()).edited) {
                    lay.updateBoxWithText(b);
                }

            } else if (commandsRedo.getFirst() instanceof EditSheet) {
                lay.setBackgroundColor((Color.parseColor(
                        MainActivity.styleSheet.findStyle(sheet1.getStyleId()).getProperty(Styles.FillColor))));
            }
            //    lay.invalidate();
            commandsUndo.add(commandsRedo.getFirst());
            commandsRedo.removeFirst();
            menu.getItem(5).setVisible(true);
            menu.getItem(6).setVisible(false);
        } else {
            commandsRedo.getLast().redo();
            if (commandsRedo.getLast() instanceof EditBox) {
                lay.updateBoxWithText(((EditBox) commandsRedo.getLast()).box);
                for (Box b : ((EditBox) commandsRedo.getLast()).edited) {
                    lay.updateBoxWithText(b);
                }

            } else if (commandsRedo.getLast() instanceof EditSheet) {
                lay.setBackgroundColor(Integer.parseInt(sheet1.getTheme().getProperty(Styles.FillColor)));
            }
            //  lay.invalidate();
            commandsUndo.add(commandsRedo.getLast());
            menu.getItem(5).setVisible(true);
            commandsRedo.removeLast();
        }
        return true;
    case R.id.action_trash:
        RemoveBox removeBox = new RemoveBox();
        Properties properties = new Properties();
        HashMap<Box, Line> boxes = new HashMap<>();
        boxes.put(MainActivity.boxEdited, MainActivity.boxEdited.parent.getLines().get(MainActivity.boxEdited));
        for (Box b : MainActivity.toEditBoxes) {
            b.isSelected = false;
            boxes.put(b, b.parent.getLines().get(b));
            if (boxes.size() > 0) {
                properties.put("boxes", boxes);
                removeBox.execute(properties);
                MainActivity.addCommendUndo(removeBox);
            }
            //  return true;
        }
        menu.getItem(4).setVisible(false);
        menu.getItem(1).setVisible(false);
        menu.getItem(2).setVisible(false);
        menu.getItem(3).setVisible(false);
        MainActivity.toEditBoxes.clear();
        //   lay.invalidate();
        return true;
    case R.id.new_rel:
        if (!MainActivity.toEditBoxes.getFirst().relationships
                .containsValue(MainActivity.toEditBoxes.getLast())) {
            final Dialog dialog = DialogFactory.boxContentDialog(MainActivity.this);
            final Button btn = (Button) dialog.findViewById(R.id.dialogButtonOK);
            final EditText et = (EditText) dialog.findViewById(R.id.editText);
            et.requestFocus();
            final Button btn2 = (Button) dialog.findViewById(R.id.button2);
            btn2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                }
            });

            btn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Callback call = null;

                    InputMethodManager imm = (InputMethodManager) getSystemService(
                            Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(et.getWindowToken(), 0);
                    String text = (et.getText().toString());
                    AddRelationship addRel = new AddRelationship();
                    Properties p = new Properties();
                    p.put("boxes", MainActivity.toEditBoxes);
                    p.put("text", text);
                    addRel.execute(p);
                    MainActivity.addCommendUndo(addRel);
                    lay.drawRelationship(MainActivity.toEditBoxes.getFirst(), addRel.relation);
                    dialog.dismiss();

                }
            });

            final int MAX_LINES = 3;

            //ogranicza do 3 linii widok w zawartoci bloczka
            et.addTextChangedListener(new TextWatcher() {
                private int lines;

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

                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                    lines = Utils.countLines(s.toString());
                }

                @Override
                public void afterTextChanged(Editable s) {
                    int counter = Utils.countLines(s.toString());

                    int diff = lines - counter;
                    if (diff > 0) {
                        //w gore
                        if (counter < MAX_LINES - 1 && et.getLayoutParams().height > 75) {
                            LinearLayout.LayoutParams buttonLayoutParams = (LinearLayout.LayoutParams) btn
                                    .getLayoutParams();
                            buttonLayoutParams.setMargins(buttonLayoutParams.leftMargin,
                                    buttonLayoutParams.topMargin - 30, buttonLayoutParams.rightMargin,
                                    buttonLayoutParams.bottomMargin);
                            btn.setLayoutParams(buttonLayoutParams);
                            btn2.setLayoutParams(buttonLayoutParams);
                            et.getLayoutParams().height -= 30;
                        }
                    } else if (diff < 0) {
                        //w dol
                        if (counter < MAX_LINES && et.getLayoutParams().height < 135) {
                            LinearLayout.LayoutParams buttonLayoutParams = (LinearLayout.LayoutParams) btn
                                    .getLayoutParams();
                            buttonLayoutParams.setMargins(buttonLayoutParams.leftMargin,
                                    buttonLayoutParams.topMargin + 30, buttonLayoutParams.rightMargin,
                                    buttonLayoutParams.bottomMargin);
                            btn.setLayoutParams(buttonLayoutParams);
                            btn2.setLayoutParams(buttonLayoutParams);
                            et.getLayoutParams().height += 30;
                        }
                    }
                }
            });

            //                    et.setText(pair.first.topic.getNotes().getContent(INotes.PLAIN).getFormat());
            int k = Utils.countLines(et.getText().toString());
            int ile = Math.min(MAX_LINES - 1, k);

            et.getLayoutParams().height = 75 + ile * 30;
            LinearLayout.LayoutParams buttonLayoutParams = (LinearLayout.LayoutParams) btn.getLayoutParams();
            buttonLayoutParams.setMargins(buttonLayoutParams.leftMargin,
                    buttonLayoutParams.topMargin + 30 * ((k < 2) ? 0 : (k == 2) ? ile - 1 : ile),
                    buttonLayoutParams.rightMargin, buttonLayoutParams.bottomMargin);
            btn.setLayoutParams(buttonLayoutParams);
            btn2.setLayoutParams(buttonLayoutParams);

            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.showSoftInput(et, InputMethodManager.SHOW_IMPLICIT);

            dialog.show();
        } else {
            RemoveRelationship remRel = new RemoveRelationship();
            Properties p = new Properties();
            p.put("boxes", MainActivity.toEditBoxes);
            remRel.execute(p);
            MainActivity.addCommendUndo(remRel);
        }

    default:
        return super.onContextItemSelected(item);
    }
}

From source file:me.ububble.speakall.fragment.ConversationGroupFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_conversation_group, container, false);
    activity = getActivity();/*from   w ww . j ava2  s .  co  m*/
    f = new Finder(activity);
    ButterKnife.inject(this, view);
    ((MainActivity) activity).menuBottom.setVisibility(View.GONE);
    ((MainActivity) activity).actionBar.setVisibility(View.VISIBLE);
    //        if (!setted)
    if (BackgroundFragment.getBackgroundChat(activity) != 0)
        backgroundChat.setImageDrawable(
                activity.getResources().getDrawable(BackgroundFragment.getBackgroundChat(activity)));

    messageText.conversationGroupFragment = this;
    TFCache.apply(activity, messageSend, TFCache.TF_SPEAKALL);
    TFCache.apply(activity, messageTranslate, TFCache.TF_SPEAKALL);
    TFCache.apply(activity, messageClock, TFCache.TF_SPEAKALL);
    TFCache.apply(activity, messageText, TFCache.TF_WHITNEY_LIGHT);
    TFCache.apply(activity, temporLanel, TFCache.TF_WHITNEY_BOLD);
    TFCache.apply(activity, temporizadorCancel, TFCache.TF_WHITNEY_LIGHT);
    TFCache.apply(activity, temporizadorAcept, TFCache.TF_WHITNEY_LIGHT);
    TFCache.apply(activity, textRecordingPress, TFCache.TF_WHITNEY_LIGHT);
    temporizadorAcept.setVisibility(View.INVISIBLE);

    TFCache.apply(activity, adjuntContact, TFCache.TF_SPEAKALL);
    TFCache.apply(activity, adjuntPhoto, TFCache.TF_SPEAKALL);
    TFCache.apply(activity, adjuntAudio, TFCache.TF_SPEAKALL);
    TFCache.apply(activity, adjuntLocation, TFCache.TF_SPEAKALL);
    TFCache.apply(activity, adjuntVideo, TFCache.TF_SPEAKALL);
    TFCache.apply(activity, adjuntImage, TFCache.TF_SPEAKON);

    messageText.setOnClickListener(this);
    messageTranslate.setOnClickListener(this);
    messageClock.setOnClickListener(this);
    temporizadorAcept.setOnClickListener(this);
    temporizadorCancel.setOnClickListener(this);
    adjuntContact.setOnClickListener(this);
    adjuntPhoto.setOnClickListener(this);
    adjuntAudio.setOnClickListener(this);
    adjuntLocation.setOnClickListener(this);
    adjuntVideo.setOnClickListener(this);
    adjuntImage.setOnClickListener(this);
    time1.setOnClickListener(this);
    time2.setOnClickListener(this);
    time3.setOnClickListener(this);
    time4.setOnClickListener(this);
    time5.setOnClickListener(this);
    time6.setOnClickListener(this);
    time7.setOnClickListener(this);
    time8.setOnClickListener(this);
    time9.setOnClickListener(this);
    time10.setOnClickListener(this);
    time11.setOnClickListener(this);
    time12.setOnClickListener(this);
    recordAudioButton.setOnTouchListener(this);
    messageText.requestFocus();

    messageSend.setText(Finder.STRING.ICN_SEND_MSJ.toString());
    messageTranslate.setText(Finder.STRING.ICN_TRANSLATE.toString());
    messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
    sv.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });
    sv.setVerticalScrollBarEnabled(false);
    sv.setHorizontalScrollBarEnabled(false);
    final SharedPreferences settings = activity.getSharedPreferences(Finder.STRING.APP_PREF.toString(),
            Context.MODE_PRIVATE);
    keyBoardHeight = settings.getInt("INPUTKEY", 0);
    if (keyBoardHeight == 0) {
        getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        messageText.postDelayed(new Runnable() {
            @Override
            public void run() { // TODO Auto-generated method stub
                InputMethodManager keyboard = (InputMethodManager) getActivity()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                keyboard.showSoftInput(messageText, 0);
            }
        }, 50);
        isShowKeyboard = true;
        final Window mRootWindow = activity.getWindow();
        final View mRootView = mRootWindow.getDecorView().findViewById(android.R.id.content);
        mRootView.getViewTreeObserver()
                .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                    public void onGlobalLayout() {
                        Rect r = new Rect();
                        View view = mRootWindow.getDecorView();
                        view.getWindowVisibleDisplayFrame(r);
                        if (prevSize == 0)
                            prevSize = r.bottom;
                        else if (prevSize != r.bottom) {
                            if (prevSize - r.bottom > 150) {
                                keyBoardHeight = prevSize - r.bottom;
                                SharedPreferences.Editor editor = settings.edit();
                                editor.putInt("INPUTKEY", keyBoardHeight);
                                editor.apply();
                                keyboardLayout.setLayoutParams(new LinearLayout.LayoutParams(
                                        ViewGroup.LayoutParams.MATCH_PARENT, keyBoardHeight));
                                isShowKeyboard = true;
                                isShowKeyboard = true;
                                isShowCustomKeyboard = false;
                                mRootView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                            }
                        }
                        // r.left, r.top, r.right, r.bottom
                    }//2464   -- 1772 -- 692
                     //1184    -- 660  -- 524
                });
    } else {
        isShowKeyboard = false;
        getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
        keyboardLayout.setLayoutParams(
                new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, keyBoardHeight));
        Log.e("tamao teclado",
                keyBoardHeight + " : " + pxFromDp(activity, 240) + " : " + pxFromDp(activity, 180));
        if (keyBoardHeight > pxFromDp(activity, 240)) {
            ((LinearLayout.LayoutParams) seekBarContent.getLayoutParams()).width = (int) pxFromDp(activity,
                    180);
            ((LinearLayout.LayoutParams) seekBarContent.getLayoutParams()).height = (int) pxFromDp(activity,
                    180);

            ((RelativeLayout.LayoutParams) tapsContent.getLayoutParams()).width = (int) pxFromDp(activity, 180);
            ((RelativeLayout.LayoutParams) tapsContent.getLayoutParams()).height = (int) pxFromDp(activity,
                    180);

            ((RelativeLayout.LayoutParams) temporizadorSeek.getLayoutParams()).width = (int) pxFromDp(activity,
                    140);
            ((RelativeLayout.LayoutParams) temporizadorSeek.getLayoutParams()).height = (int) pxFromDp(activity,
                    140);
            temporizadorSeek.atributesCode(20, 16, 25);
            temporLanel.setTextSize(18);

            ((RelativeLayout.LayoutParams) time1.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time1.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time1.getLayoutParams()).topMargin = (int) pxFromDp(activity, 25);
            ((RelativeLayout.LayoutParams) time1.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 90);

            ((RelativeLayout.LayoutParams) time2.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time2.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time2.getLayoutParams()).topMargin = (int) pxFromDp(activity, 35);
            ((RelativeLayout.LayoutParams) time2.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 115);

            ((RelativeLayout.LayoutParams) time3.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time3.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time3.getLayoutParams()).topMargin = (int) pxFromDp(activity, 65);
            ((RelativeLayout.LayoutParams) time3.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 128);

            ((RelativeLayout.LayoutParams) time4.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time4.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time4.getLayoutParams()).topMargin = (int) pxFromDp(activity, 92);
            ((RelativeLayout.LayoutParams) time4.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 128);

            ((RelativeLayout.LayoutParams) time5.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time5.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time5.getLayoutParams()).topMargin = (int) pxFromDp(activity, 118);
            ((RelativeLayout.LayoutParams) time5.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 115);

            ((RelativeLayout.LayoutParams) time6.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time6.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time6.getLayoutParams()).topMargin = (int) pxFromDp(activity, 130);
            ((RelativeLayout.LayoutParams) time6.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 90);

            ((RelativeLayout.LayoutParams) time7.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time7.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time7.getLayoutParams()).topMargin = (int) pxFromDp(activity, 130);
            ((RelativeLayout.LayoutParams) time7.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 60);

            ((RelativeLayout.LayoutParams) time8.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time8.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time8.getLayoutParams()).topMargin = (int) pxFromDp(activity, 118);
            ((RelativeLayout.LayoutParams) time8.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 37);

            ((RelativeLayout.LayoutParams) time9.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time9.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time9.getLayoutParams()).topMargin = (int) pxFromDp(activity, 92);
            ((RelativeLayout.LayoutParams) time9.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 24);

            ((RelativeLayout.LayoutParams) time10.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time10.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time10.getLayoutParams()).topMargin = (int) pxFromDp(activity, 65);
            ((RelativeLayout.LayoutParams) time10.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 24);

            ((RelativeLayout.LayoutParams) time11.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time11.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time11.getLayoutParams()).topMargin = (int) pxFromDp(activity, 35);
            ((RelativeLayout.LayoutParams) time11.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 37);

            ((RelativeLayout.LayoutParams) time12.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time12.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time12.getLayoutParams()).topMargin = (int) pxFromDp(activity, 25);
            ((RelativeLayout.LayoutParams) time12.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 60);
        } else if (keyBoardHeight > pxFromDp(activity, 180)) {
            ((LinearLayout.LayoutParams) seekBarContent.getLayoutParams()).width = (int) pxFromDp(activity,
                    130);
            ((LinearLayout.LayoutParams) seekBarContent.getLayoutParams()).height = (int) pxFromDp(activity,
                    130);

            ((RelativeLayout.LayoutParams) tapsContent.getLayoutParams()).width = (int) pxFromDp(activity, 130);
            ((RelativeLayout.LayoutParams) tapsContent.getLayoutParams()).height = (int) pxFromDp(activity,
                    130);

            ((RelativeLayout.LayoutParams) temporizadorSeek.getLayoutParams()).width = (int) pxFromDp(activity,
                    110);
            ((RelativeLayout.LayoutParams) temporizadorSeek.getLayoutParams()).height = (int) pxFromDp(activity,
                    110);
            temporizadorSeek.atributesCode(15, 16, 9);
            temporLanel.setTextSize(14);

            ((RelativeLayout.LayoutParams) time1.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time1.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time1.getLayoutParams()).topMargin = (int) pxFromDp(activity, 19);
            ((RelativeLayout.LayoutParams) time1.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 66);

            ((RelativeLayout.LayoutParams) time2.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time2.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time2.getLayoutParams()).topMargin = (int) pxFromDp(activity, 29);
            ((RelativeLayout.LayoutParams) time2.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 85);

            ((RelativeLayout.LayoutParams) time3.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time3.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time3.getLayoutParams()).topMargin = (int) pxFromDp(activity, 47);
            ((RelativeLayout.LayoutParams) time3.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 94);

            ((RelativeLayout.LayoutParams) time4.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time4.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time4.getLayoutParams()).topMargin = (int) pxFromDp(activity, 67);
            ((RelativeLayout.LayoutParams) time4.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 94);

            ((RelativeLayout.LayoutParams) time5.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time5.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time5.getLayoutParams()).topMargin = (int) pxFromDp(activity, 85);
            ((RelativeLayout.LayoutParams) time5.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 85);

            ((RelativeLayout.LayoutParams) time6.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time6.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time6.getLayoutParams()).topMargin = (int) pxFromDp(activity, 95);
            ((RelativeLayout.LayoutParams) time6.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 66);

            ((RelativeLayout.LayoutParams) time7.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time7.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time7.getLayoutParams()).topMargin = (int) pxFromDp(activity, 95);
            ((RelativeLayout.LayoutParams) time7.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 45);

            ((RelativeLayout.LayoutParams) time8.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time8.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time8.getLayoutParams()).topMargin = (int) pxFromDp(activity, 85);
            ((RelativeLayout.LayoutParams) time8.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 28);

            ((RelativeLayout.LayoutParams) time9.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time9.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time9.getLayoutParams()).topMargin = (int) pxFromDp(activity, 67);
            ((RelativeLayout.LayoutParams) time9.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 18);

            ((RelativeLayout.LayoutParams) time10.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time10.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time10.getLayoutParams()).topMargin = (int) pxFromDp(activity, 47);
            ((RelativeLayout.LayoutParams) time10.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 18);

            ((RelativeLayout.LayoutParams) time11.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time11.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time11.getLayoutParams()).topMargin = (int) pxFromDp(activity, 29);
            ((RelativeLayout.LayoutParams) time11.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 28);

            ((RelativeLayout.LayoutParams) time12.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time12.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time12.getLayoutParams()).topMargin = (int) pxFromDp(activity, 19);
            ((RelativeLayout.LayoutParams) time12.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 45);

        }
    }
    messagesList.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (scrollOnBottom) {
                messagesListScroll.scrollTo(0, messagesList.getBottom());
            } else {
                messagesListScroll.scrollTo(0, ((messagesList.getHeight() - messagesValuePrev) + scrollValue)
                        + (scrollHeight - messagesListScroll.getHeight()));
                messagesListScroll.setVerticalScrollBarEnabled(true);
            }

        }
    });
    messagesListScroll.getViewTreeObserver()
            .addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
                @Override
                public void onScrollChanged() {
                    if (messagesList.getHeight() - messagesListScroll.getScrollY() <= messagesListScroll
                            .getHeight()) {
                        scrollOnBottom = true;
                    } else {
                        scrollOnBottom = false;
                        messagesValuePrev = messagesList.getHeight();
                        scrollValue = messagesListScroll.getScrollY();
                        scrollHeight = messagesListScroll.getHeight();
                    }
                }
            });

    messageSend.setOnClickListener(this);
    messageText.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable arg0) {
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (messageText.getText().length() > 0) {
                messageSend.setVisibility(View.VISIBLE);
                messageSednDivider.setVisibility(View.VISIBLE);
            } else {
                messageSend.setVisibility(View.GONE);
                messageSednDivider.setVisibility(View.GONE);
            }
        }
    });
    u = new Select().from(User.class).executeSingle();
    ((MainActivity) activity).setOnBackPressedListener(null);

    return view;
}

From source file:me.ububble.speakall.fragment.ConversationChatFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_conversation_chat, container, false);
    activity = getActivity();// ww w . j  av a  2  s. c o  m
    f = new Finder(activity);
    ButterKnife.inject(this, view);
    ((MainActivity) activity).actionBar.setVisibility(View.VISIBLE);
    ((MainActivity) activity).menuBottom.setVisibility(View.GONE);

    if (BackgroundFragment.getBackgroundChat(activity) != 0)
        backgroundChat.setImageDrawable(
                activity.getResources().getDrawable(BackgroundFragment.getBackgroundChat(activity)));

    messageText.conversationChatFragment = this;
    TFCache.apply(activity, messageSend, TFCache.TF_SPEAKALL);
    TFCache.apply(activity, messageTranslate, TFCache.TF_SPEAKALL);
    TFCache.apply(activity, messageClock, TFCache.TF_SPEAKALL);
    TFCache.apply(activity, messageText, TFCache.TF_WHITNEY_LIGHT);
    TFCache.apply(activity, temporLanel, TFCache.TF_WHITNEY_BOLD);
    TFCache.apply(activity, addToContacts, TFCache.TF_WHITNEY_LIGHT);
    TFCache.apply(activity, temporizadorCancel, TFCache.TF_WHITNEY_LIGHT);
    TFCache.apply(activity, temporizadorAcept, TFCache.TF_WHITNEY_LIGHT);
    TFCache.apply(activity, textRecording, TFCache.TF_WHITNEY_LIGHT);
    TFCache.apply(activity, textRecordingPress, TFCache.TF_WHITNEY_LIGHT);
    TFCache.apply(activity, timerAudio, TFCache.TF_WHITNEY_LIGHT);
    TFCache.apply(activity, cancelAudio, TFCache.TF_WHITNEY_LIGHT);
    TFCache.apply(activity, audioRecordBackground, TFCache.TF_WHITNEY_LIGHT);
    temporizadorAcept.setVisibility(View.INVISIBLE);
    longclick = false;
    saveAudio = false;

    TFCache.apply(activity, adjuntContact, TFCache.TF_SPEAKALL);
    TFCache.apply(activity, adjuntPhoto, TFCache.TF_SPEAKALL);
    TFCache.apply(activity, adjuntAudio, TFCache.TF_SPEAKALL);
    TFCache.apply(activity, adjuntLocation, TFCache.TF_SPEAKALL);
    TFCache.apply(activity, adjuntVideo, TFCache.TF_SPEAKALL);
    TFCache.apply(activity, adjuntImage, TFCache.TF_SPEAKALL);

    messageText.setOnClickListener(this);
    messageTranslate.setOnClickListener(this);
    messageClock.setOnClickListener(this);
    temporizadorAcept.setOnClickListener(this);
    temporizadorCancel.setOnClickListener(this);
    adjuntContact.setOnClickListener(this);
    adjuntPhoto.setOnClickListener(this);
    adjuntAudio.setOnClickListener(this);
    adjuntLocation.setOnClickListener(this);
    adjuntVideo.setOnClickListener(this);
    adjuntImage.setOnClickListener(this);
    addToContacts.setOnClickListener(this);
    time1.setOnClickListener(this);
    time2.setOnClickListener(this);
    time3.setOnClickListener(this);
    time4.setOnClickListener(this);
    time5.setOnClickListener(this);
    time6.setOnClickListener(this);
    time7.setOnClickListener(this);
    time8.setOnClickListener(this);
    time9.setOnClickListener(this);
    time10.setOnClickListener(this);
    time11.setOnClickListener(this);
    time12.setOnClickListener(this);
    recordAudioButton.setOnTouchListener(this);
    messageText.requestFocus();

    dateDay1 = new SimpleDateFormat("d");
    dateDayText1 = new SimpleDateFormat("EEEE");
    dateMonth1 = new SimpleDateFormat("MMMM");
    dateYear1 = new SimpleDateFormat("yyyy");
    timeFormat1 = new SimpleDateFormat("h:mm a");

    messageSend.setText(Finder.STRING.ICN_SEND_MSJ.toString());
    messageTranslate.setText(Finder.STRING.ICN_TRANSLATE.toString());
    messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
    sv.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });
    sv.setVerticalScrollBarEnabled(false);
    sv.setHorizontalScrollBarEnabled(false);

    final SharedPreferences settings = activity.getSharedPreferences(Finder.STRING.APP_PREF.toString(),
            Context.MODE_PRIVATE);
    keyBoardHeight = settings.getInt("INPUTKEY", 0);

    if (keyBoardHeight == 0) {
        getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        messageText.postDelayed(new Runnable() {
            @Override
            public void run() {
                InputMethodManager keyboard = (InputMethodManager) getActivity()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                keyboard.showSoftInput(messageText, 0);

            }
        }, 50);
        isShowKeyboard = true;
        final Window mRootWindow = activity.getWindow();
        final View mRootView = mRootWindow.getDecorView().findViewById(android.R.id.content);
        mRootView.getViewTreeObserver()
                .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                    public void onGlobalLayout() {

                        Rect r = new Rect();
                        View view = mRootWindow.getDecorView();
                        view.getWindowVisibleDisplayFrame(r);
                        if (prevSize == 0)
                            prevSize = r.bottom;
                        else if (prevSize != r.bottom) {
                            if (prevSize - r.bottom > 150) {
                                keyBoardHeight = prevSize - r.bottom;
                                SharedPreferences.Editor editor = settings.edit();
                                editor.putInt("INPUTKEY", keyBoardHeight);
                                editor.apply();
                                keyboardLayout.setLayoutParams(new LinearLayout.LayoutParams(
                                        ViewGroup.LayoutParams.MATCH_PARENT, keyBoardHeight));
                                isShowKeyboard = true;
                                isShowCustomKeyboard = false;
                                mRootView.getViewTreeObserver().removeGlobalOnLayoutListener(this);

                            }
                        }
                    }
                });

    } else {
        isShowKeyboard = false;
        getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
        keyboardLayout.setLayoutParams(
                new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, keyBoardHeight));
        if (keyBoardHeight > pxFromDp(activity, 240)) {
            ((LinearLayout.LayoutParams) seekBarContent.getLayoutParams()).width = (int) pxFromDp(activity,
                    180);
            ((LinearLayout.LayoutParams) seekBarContent.getLayoutParams()).height = (int) pxFromDp(activity,
                    180);

            ((RelativeLayout.LayoutParams) tapsContent.getLayoutParams()).width = (int) pxFromDp(activity, 180);
            ((RelativeLayout.LayoutParams) tapsContent.getLayoutParams()).height = (int) pxFromDp(activity,
                    180);

            ((RelativeLayout.LayoutParams) temporizadorSeek.getLayoutParams()).width = (int) pxFromDp(activity,
                    140);
            ((RelativeLayout.LayoutParams) temporizadorSeek.getLayoutParams()).height = (int) pxFromDp(activity,
                    140);
            temporizadorSeek.atributesCode(20, 16, 25);
            temporLanel.setTextSize(18);

            ((RelativeLayout.LayoutParams) time1.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time1.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time1.getLayoutParams()).topMargin = (int) pxFromDp(activity, 25);
            ((RelativeLayout.LayoutParams) time1.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 90);

            ((RelativeLayout.LayoutParams) time2.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time2.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time2.getLayoutParams()).topMargin = (int) pxFromDp(activity, 35);
            ((RelativeLayout.LayoutParams) time2.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 115);

            ((RelativeLayout.LayoutParams) time3.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time3.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time3.getLayoutParams()).topMargin = (int) pxFromDp(activity, 65);
            ((RelativeLayout.LayoutParams) time3.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 128);

            ((RelativeLayout.LayoutParams) time4.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time4.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time4.getLayoutParams()).topMargin = (int) pxFromDp(activity, 92);
            ((RelativeLayout.LayoutParams) time4.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 128);

            ((RelativeLayout.LayoutParams) time5.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time5.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time5.getLayoutParams()).topMargin = (int) pxFromDp(activity, 118);
            ((RelativeLayout.LayoutParams) time5.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 115);

            ((RelativeLayout.LayoutParams) time6.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time6.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time6.getLayoutParams()).topMargin = (int) pxFromDp(activity, 130);
            ((RelativeLayout.LayoutParams) time6.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 90);

            ((RelativeLayout.LayoutParams) time7.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time7.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time7.getLayoutParams()).topMargin = (int) pxFromDp(activity, 130);
            ((RelativeLayout.LayoutParams) time7.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 60);

            ((RelativeLayout.LayoutParams) time8.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time8.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time8.getLayoutParams()).topMargin = (int) pxFromDp(activity, 118);
            ((RelativeLayout.LayoutParams) time8.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 37);

            ((RelativeLayout.LayoutParams) time9.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time9.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time9.getLayoutParams()).topMargin = (int) pxFromDp(activity, 92);
            ((RelativeLayout.LayoutParams) time9.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 24);

            ((RelativeLayout.LayoutParams) time10.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time10.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time10.getLayoutParams()).topMargin = (int) pxFromDp(activity, 65);
            ((RelativeLayout.LayoutParams) time10.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 24);

            ((RelativeLayout.LayoutParams) time11.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time11.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time11.getLayoutParams()).topMargin = (int) pxFromDp(activity, 35);
            ((RelativeLayout.LayoutParams) time11.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 37);

            ((RelativeLayout.LayoutParams) time12.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time12.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time12.getLayoutParams()).topMargin = (int) pxFromDp(activity, 25);
            ((RelativeLayout.LayoutParams) time12.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 60);
        } else if (keyBoardHeight > pxFromDp(activity, 180)) {
            ((LinearLayout.LayoutParams) seekBarContent.getLayoutParams()).width = (int) pxFromDp(activity,
                    130);
            ((LinearLayout.LayoutParams) seekBarContent.getLayoutParams()).height = (int) pxFromDp(activity,
                    130);

            ((RelativeLayout.LayoutParams) tapsContent.getLayoutParams()).width = (int) pxFromDp(activity, 130);
            ((RelativeLayout.LayoutParams) tapsContent.getLayoutParams()).height = (int) pxFromDp(activity,
                    130);

            ((RelativeLayout.LayoutParams) temporizadorSeek.getLayoutParams()).width = (int) pxFromDp(activity,
                    110);
            ((RelativeLayout.LayoutParams) temporizadorSeek.getLayoutParams()).height = (int) pxFromDp(activity,
                    110);
            temporizadorSeek.atributesCode(15, 16, 9);
            temporLanel.setTextSize(14);

            ((RelativeLayout.LayoutParams) time1.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time1.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time1.getLayoutParams()).topMargin = (int) pxFromDp(activity, 19);
            ((RelativeLayout.LayoutParams) time1.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 66);

            ((RelativeLayout.LayoutParams) time2.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time2.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time2.getLayoutParams()).topMargin = (int) pxFromDp(activity, 29);
            ((RelativeLayout.LayoutParams) time2.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 85);

            ((RelativeLayout.LayoutParams) time3.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time3.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time3.getLayoutParams()).topMargin = (int) pxFromDp(activity, 47);
            ((RelativeLayout.LayoutParams) time3.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 94);

            ((RelativeLayout.LayoutParams) time4.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time4.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time4.getLayoutParams()).topMargin = (int) pxFromDp(activity, 67);
            ((RelativeLayout.LayoutParams) time4.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 94);

            ((RelativeLayout.LayoutParams) time5.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time5.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time5.getLayoutParams()).topMargin = (int) pxFromDp(activity, 85);
            ((RelativeLayout.LayoutParams) time5.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 85);

            ((RelativeLayout.LayoutParams) time6.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time6.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time6.getLayoutParams()).topMargin = (int) pxFromDp(activity, 95);
            ((RelativeLayout.LayoutParams) time6.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 66);

            ((RelativeLayout.LayoutParams) time7.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time7.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time7.getLayoutParams()).topMargin = (int) pxFromDp(activity, 95);
            ((RelativeLayout.LayoutParams) time7.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 45);

            ((RelativeLayout.LayoutParams) time8.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time8.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time8.getLayoutParams()).topMargin = (int) pxFromDp(activity, 85);
            ((RelativeLayout.LayoutParams) time8.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 28);

            ((RelativeLayout.LayoutParams) time9.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time9.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time9.getLayoutParams()).topMargin = (int) pxFromDp(activity, 67);
            ((RelativeLayout.LayoutParams) time9.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 18);

            ((RelativeLayout.LayoutParams) time10.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time10.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time10.getLayoutParams()).topMargin = (int) pxFromDp(activity, 47);
            ((RelativeLayout.LayoutParams) time10.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 18);

            ((RelativeLayout.LayoutParams) time11.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time11.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time11.getLayoutParams()).topMargin = (int) pxFromDp(activity, 29);
            ((RelativeLayout.LayoutParams) time11.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 28);

            ((RelativeLayout.LayoutParams) time12.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time12.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time12.getLayoutParams()).topMargin = (int) pxFromDp(activity, 19);
            ((RelativeLayout.LayoutParams) time12.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 45);

        }
    }
    messagesList.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (scrollOnBottom) {
                messagesListScroll.scrollTo(0, messagesList.getBottom());
            } else {
                messagesListScroll.scrollTo(0, ((messagesList.getHeight() - messagesValuePrev) + scrollValue)
                        + (scrollHeight - messagesListScroll.getHeight()));
                messagesListScroll.setVerticalScrollBarEnabled(true);
            }

        }
    });
    messagesListScroll.getViewTreeObserver()
            .addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
                @Override
                public void onScrollChanged() {
                    if (messagesList.getHeight() - messagesListScroll.getScrollY() <= messagesListScroll
                            .getHeight()) {
                        scrollOnBottom = true;
                    } else {
                        scrollOnBottom = false;
                        messagesValuePrev = messagesList.getHeight();
                        scrollValue = messagesListScroll.getScrollY();
                        scrollHeight = messagesListScroll.getHeight();
                    }
                }
            });

    messageSend.setOnClickListener(this);
    messageText.addTextChangedListener(new TextWatcher() {
        boolean delayed = false;

        @Override
        public void afterTextChanged(Editable arg0) {
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        private void sendWritingStatus() {
            if (SpeakSocket.isRunning()) {
                try {
                    JSONObject data = new JSONObject();
                    data.put("source", u.id);
                    data.put("target", contact.idContacto);
                    data.put("type", 1);
                    if (SpeakSocket.mSocket != null)
                        if (SpeakSocket.mSocket.connected())
                            SpeakSocket.mSocket.emit("contact-status", data);
                    Log.e("STATUS WRITE", data.toString());
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (messageText.getText().length() > 0) {
                messageSend.setVisibility(View.VISIBLE);
                messageSednDivider.setVisibility(View.VISIBLE);
                if (!delayed) {
                    delayed = true;
                    sendWritingStatus();
                    new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            delayed = false;
                        }
                    }, C.CONTACT_STATUS_DELAY_MS);
                }
            } else {
                messageSend.setVisibility(View.GONE);
                messageSednDivider.setVisibility(View.GONE);
            }

        }
    });
    u = new Select().from(User.class).executeSingle();

    handlerContactStatus = new Handler();
    runnableContactStatus = new Runnable() {

        @Override
        public void run() {
            JSONObject dataLastSeen = new JSONObject();
            try {
                dataLastSeen.put("source", u.id);
                dataLastSeen.put("target", contact.idContacto);
                if (SpeakSocket.mSocket != null)
                    if (SpeakSocket.mSocket.connected()) {
                        Log.e("Pidiendo lastseen", dataLastSeen.toString());
                        SpeakSocket.mSocket.emit("contact-lastseen", dataLastSeen);
                    }
            } catch (JSONException e) {
                e.printStackTrace();
            }
            handlerContactStatus.postDelayed(runnableContactStatus, 5000);
        }
    };
    handlerContactStatus.postDelayed(runnableContactStatus, 500);
    Contact contAdd = new Select().from(Contact.class).where("id_contact = ?", contact.idContacto)
            .executeSingle();
    if (contAdd == null) {
        addToContacts.setVisibility(View.VISIBLE);
    } else {
        addToContacts.setVisibility(View.GONE);
    }

    return view;
}

From source file:me.ububble.speakall.fragment.ConversationGroupFragment.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.icn_message_send:
        String message = messageText.getText().toString();
        MsgGroups msgGroup = new MsgGroups();
        try {//www.  j  a v a  2  s . c  om
            Calendar fecha = Calendar.getInstance();
            JSONArray targets = new JSONArray();
            JSONArray contactos = new JSONArray(grupo.targets);
            String contactosId = null;
            if (SpeakSocket.mSocket != null) {
                if (SpeakSocket.mSocket.connected()) {
                    for (int i = 0; i < contactos.length(); i++) {
                        JSONObject contacto = contactos.getJSONObject(i);
                        JSONObject newContact = new JSONObject();
                        Contact contact = new Select().from(Contact.class)
                                .where("id_contact = ?", contacto.getString("name")).executeSingle();
                        if (contact != null) {
                            if (!contact.idContacto.equals(u.id)) {
                                if (translate)
                                    newContact.put("lang", contact.lang);
                                else
                                    newContact.put("lang", u.lang);
                                newContact.put("name", contact.idContacto);
                                newContact.put("screen_name", contact.screenName);
                                newContact.put("status", 1);
                                contactosId += contact.idContacto;
                                targets.put(targets.length(), newContact);
                            }
                        }
                    }
                } else {
                    for (int i = 0; i < contactos.length(); i++) {
                        JSONObject contacto = contactos.getJSONObject(i);
                        JSONObject newContact = new JSONObject();
                        Contact contact = new Select().from(Contact.class)
                                .where("id_contact = ?", contacto.getString("name")).executeSingle();
                        if (contact != null) {
                            if (!contact.idContacto.equals(u.id)) {
                                if (translate)
                                    newContact.put("lang", contact.lang);
                                else
                                    newContact.put("lang", u.lang);
                                newContact.put("name", contact.idContacto);
                                newContact.put("screen_name", contact.screenName);
                                newContact.put("status", -1);
                                contactosId += contact.idContacto;
                                targets.put(targets.length(), newContact);
                            }
                        }
                    }
                }
            }
            msgGroup.grupoId = grupo.grupoId;
            msgGroup.mensajeId = u.id + grupo.grupoId + fecha.getTimeInMillis()
                    + Settings.Secure.getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID);
            msgGroup.emisor = u.id;
            msgGroup.receptores = targets.toString();
            msgGroup.mensaje = message;
            msgGroup.emisorEmail = u.email;
            msgGroup.emisorLang = u.lang;
            msgGroup.translation = translate;
            msgGroup.emitedAt = fecha.getTimeInMillis();
            msgGroup.tipo = Integer.parseInt(getString(R.string.MSG_TYPE_GROUP_TEXT));
            if (tiempoMensaje) {
                msgGroup.delay = temporizadorSeek.getValue();
            } else {
                msgGroup.delay = 0;
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        msgGroup.save();
        messageText.setText("");
        showNewMessage(msgGroup);
        messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
        messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
        tiempoMensaje = false;
        break;
    case R.id.message_text:
        SharedPreferences settings = getActivity().getSharedPreferences(Finder.STRING.APP_PREF.toString(),
                Context.MODE_PRIVATE);
        if (settings.getInt("INPUTKEY", 0) == 0) {
            customKeyboardLayout.setVisibility(View.GONE);
            customKeyboardAudio.setVisibility(View.GONE);
            keyboardLayout.setVisibility(View.GONE);
            isShowCustomKeyboard = false;
            if (tiempoMensaje) {
                messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
            } else {
                messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
            }
            isShowKeyboard = true;
        } else {
            if (!isShowKeyboard) {
                if (!isShowCustomKeyboard) {
                    messagesListScroll.setVerticalScrollBarEnabled(false);
                    final InputMethodManager imm = (InputMethodManager) activity
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    if (tiempoMensaje) {
                        messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                        messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                    } else {
                        messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                        messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    }
                    imm.showSoftInput(messageText, 0);
                    keyboardLayout.setVisibility(View.GONE);
                    AnimatorSet set = new AnimatorSet();
                    set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                    set.setDuration(220).start();
                    set.addListener(new Animator.AnimatorListener() {
                        @Override
                        public void onAnimationStart(Animator animation) {

                        }

                        @Override
                        public void onAnimationEnd(Animator animation) {
                            keyboardLayout.setVisibility(View.VISIBLE);
                        }

                        @Override
                        public void onAnimationCancel(Animator animation) {

                        }

                        @Override
                        public void onAnimationRepeat(Animator animation) {

                        }
                    });
                    keyboardLayout
                            .setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                    isShowKeyboard = true;
                    ((MainActivity) activity).setOnBackPressedListener(null);
                    customKeyboardLayout.setVisibility(View.GONE);
                    customKeyboardAudio.setVisibility(View.GONE);
                    isShowCustomKeyboard = false;
                } else {
                    keyboardLayout.setVisibility(View.GONE);
                    AnimatorSet set = new AnimatorSet();
                    set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                    set.setDuration(220).start();
                    set.addListener(new Animator.AnimatorListener() {
                        @Override
                        public void onAnimationStart(Animator animation) {

                        }

                        @Override
                        public void onAnimationEnd(Animator animation) {
                            keyboardLayout.setVisibility(View.VISIBLE);
                        }

                        @Override
                        public void onAnimationCancel(Animator animation) {

                        }

                        @Override
                        public void onAnimationRepeat(Animator animation) {

                        }
                    });
                    ((MainActivity) activity).setOnBackPressedListener(null);
                    messagesListScroll.setVerticalScrollBarEnabled(false);
                    if (tiempoMensaje) {
                        messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                        messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                    } else {
                        messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                        messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    }
                    final InputMethodManager imm = (InputMethodManager) activity
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.showSoftInput(messageText, 0);
                    keyboardLayout
                            .setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                    isShowKeyboard = true;
                    customKeyboardLayout.setVisibility(View.GONE);
                    customKeyboardAudio.setVisibility(View.GONE);
                    isShowCustomKeyboard = false;
                }
            }
        }
        break;
    case R.id.icn_message_translate:
        if (translate)
            messageTranslate.setTextColor(getResources().getColor(R.color.speak_all_red));
        else
            messageTranslate.setTextColor(getResources().getColor(R.color.speak_all_gray));
        //initAdapter();
        break;
    case R.id.icn_message_clock:
        tiempoMensaje = false;
        temporizadorAcept.setVisibility(View.INVISIBLE);
        temporizadorSeek.setInitPosition(0);
        SharedPreferences settings1 = getActivity().getSharedPreferences(Finder.STRING.APP_PREF.toString(),
                Context.MODE_PRIVATE);
        if (settings1.getInt("INPUTKEY", 0) != 0) {
            getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
        }
        if (!isShowCustomKeyboard) {
            if (!isShowKeyboard) {
                keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                }
                keyboardLayout.setVisibility(View.GONE);
                AnimatorSet set = new AnimatorSet();
                set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                set.setDuration(220).start();
                set.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        keyboardLayout.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
                customKeyboardLayout.setVisibility(View.VISIBLE);
                customKeyboardAudio.setVisibility(View.GONE);
                ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) {
                    @Override
                    public void doBack() {
                        if (tiempoMensaje) {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                        } else {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                        }
                        keyboardLayout.setVisibility(View.GONE);
                        customKeyboardLayout.setVisibility(View.GONE);
                        customKeyboardAudio.setVisibility(View.GONE);
                        isShowCustomKeyboard = false;
                        ((MainActivity) activity).setOnBackPressedListener(null);
                    }
                });
                isShowCustomKeyboard = true;
                isShowKeyboard = false;
            } else {
                keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                keyboardLayout.setVisibility(View.GONE);
                AnimatorSet set = new AnimatorSet();
                set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                set.setDuration(220).start();
                set.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        keyboardLayout.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
                hideKeyBoard();
                ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) {
                    @Override
                    public void doBack() {
                        if (tiempoMensaje) {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                        } else {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                        }
                        keyboardLayout.setVisibility(View.GONE);
                        customKeyboardLayout.setVisibility(View.GONE);
                        customKeyboardAudio.setVisibility(View.GONE);
                        isShowCustomKeyboard = false;
                        ((MainActivity) activity).setOnBackPressedListener(null);
                    }
                });
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                }
                customKeyboardLayout.setVisibility(View.VISIBLE);
                customKeyboardAudio.setVisibility(View.GONE);
                isShowCustomKeyboard = true;
                isShowKeyboard = false;
            }
        } else {
            customKeyboardAudio.setVisibility(View.GONE);
            if (!customKeyboardLayout.isShown()) {
                customKeyboardLayout.setVisibility(View.VISIBLE);
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                }
            } else {
                temporizadorAcept.setVisibility(View.INVISIBLE);
                keyboardLayout.setVisibility(View.GONE);
                customKeyboardLayout.setVisibility(View.GONE);
                customKeyboardAudio.setVisibility(View.GONE);
                isShowCustomKeyboard = false;
                tiempoMensaje = false;
                if (tiempoMensaje) {
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                } else {
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                }
            }
        }
        break;
    case R.id.temporizador_cancel:
        temporizadorAcept.setVisibility(View.INVISIBLE);
        messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
        messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
        keyboardLayout.setVisibility(View.GONE);
        customKeyboardLayout.setVisibility(View.GONE);
        customKeyboardAudio.setVisibility(View.GONE);
        temporizadorSeek.setInitPosition(0);
        isShowCustomKeyboard = false;
        tiempoMensaje = false;
        break;
    case R.id.temporizador_acept:
        temporizadorAcept.setVisibility(View.INVISIBLE);
        messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
        messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
        keyboardLayout.setVisibility(View.GONE);
        customKeyboardLayout.setVisibility(View.GONE);
        customKeyboardAudio.setVisibility(View.GONE);
        temporizadorSeek.setInitPosition(15);
        isShowCustomKeyboard = false;
        tiempoMensaje = true;
        if (!isShowKeyboard) {
            if (!isShowCustomKeyboard) {
                messagesListScroll.setVerticalScrollBarEnabled(false);
                final InputMethodManager imm = (InputMethodManager) activity
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                }
                imm.showSoftInput(messageText, 0);
                keyboardLayout.setVisibility(View.GONE);
                AnimatorSet set = new AnimatorSet();
                set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                set.setDuration(220).start();
                set.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        keyboardLayout.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
                keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                isShowKeyboard = true;
                ((MainActivity) activity).setOnBackPressedListener(null);
                customKeyboardLayout.setVisibility(View.GONE);
                customKeyboardAudio.setVisibility(View.GONE);
                isShowCustomKeyboard = false;
            } else {
                keyboardLayout.setVisibility(View.GONE);
                AnimatorSet set = new AnimatorSet();
                set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                set.setDuration(220).start();
                set.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        keyboardLayout.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
                ((MainActivity) activity).setOnBackPressedListener(null);
                messagesListScroll.setVerticalScrollBarEnabled(false);
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                }
                final InputMethodManager imm = (InputMethodManager) activity
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(messageText, 0);
                keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                isShowKeyboard = true;
                customKeyboardLayout.setVisibility(View.GONE);
                customKeyboardAudio.setVisibility(View.GONE);
                isShowCustomKeyboard = false;
            }
        }
        break;
    case R.id._1:
        temporizadorSeek.setInitPosition(15);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._2:
        temporizadorSeek.setInitPosition(30);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._3:
        temporizadorSeek.setInitPosition(45);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._4:
        temporizadorSeek.setInitPosition(60);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._5:
        temporizadorSeek.setInitPosition(75);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._6:
        temporizadorSeek.setInitPosition(90);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._7:
        temporizadorSeek.setInitPosition(105);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._8:
        temporizadorSeek.setInitPosition(120);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._9:
        temporizadorSeek.setInitPosition(135);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._10:
        temporizadorSeek.setInitPosition(150);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._11:
        temporizadorSeek.setInitPosition(165);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._12:
        temporizadorSeek.setInitPosition(180);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id.adjunt_image:
        System.gc();
        getFragmentManager().beginTransaction().replace(R.id.container3, CreatePollFragment.newInstance(grupo))
                .addToBackStack(null).commit();
        ((MainActivity) activity).setOnBackPressedListener(null);
        menuAdjunt = false;
        adjuntLayout.setVisibility(View.GONE);
        break;
    case R.id.adjunt_contact:
        System.gc();
        dontClose = true;
        ((MainActivity) activity).dontClose = true;
        hideKeyBoard();
        Intent i = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
        startActivityForResult(i, 34);
        menuAdjunt = false;
        adjuntLayout.setVisibility(View.GONE);
        break;
    case R.id.adjunt_audio:
        menuAdjunt = false;
        adjuntLayout.setVisibility(View.GONE);
        AnimatorSet set3 = new AnimatorSet();
        set3.playTogether(ObjectAnimator.ofFloat(adjuntLayout, "alpha", 1, 0));
        set3.setDuration(200).start();
        SharedPreferences settings2 = getActivity().getSharedPreferences(Finder.STRING.APP_PREF.toString(),
                Context.MODE_PRIVATE);
        if (settings2.getInt("INPUTKEY", 0) != 0) {
            getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
        }
        if (!isShowCustomKeyboard) {
            if (!isShowKeyboard) {
                keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                }
                keyboardLayout.setVisibility(View.GONE);
                AnimatorSet set4 = new AnimatorSet();
                set4.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                set4.setDuration(220).start();
                set4.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        keyboardLayout.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
                customKeyboardLayout.setVisibility(View.GONE);
                customKeyboardAudio.setVisibility(View.VISIBLE);
                ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) {
                    @Override
                    public void doBack() {
                        if (tiempoMensaje) {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                        } else {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                        }
                        keyboardLayout.setVisibility(View.GONE);
                        customKeyboardLayout.setVisibility(View.GONE);
                        customKeyboardAudio.setVisibility(View.GONE);
                        isShowCustomKeyboard = false;
                        ((MainActivity) activity).setOnBackPressedListener(null);
                    }
                });
                isShowCustomKeyboard = true;
                isShowKeyboard = false;
            } else {
                keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                keyboardLayout.setVisibility(View.GONE);
                AnimatorSet set5 = new AnimatorSet();
                set5.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                set5.setDuration(220).start();
                set5.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        keyboardLayout.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
                hideKeyBoard();
                ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) {
                    @Override
                    public void doBack() {
                        if (tiempoMensaje) {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                        } else {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                        }
                        keyboardLayout.setVisibility(View.GONE);
                        customKeyboardLayout.setVisibility(View.GONE);
                        customKeyboardAudio.setVisibility(View.GONE);
                        isShowCustomKeyboard = false;
                        ((MainActivity) activity).setOnBackPressedListener(null);
                    }
                });
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                }
                customKeyboardLayout.setVisibility(View.GONE);
                customKeyboardAudio.setVisibility(View.VISIBLE);
                isShowCustomKeyboard = true;
                isShowKeyboard = false;
            }
        } else {
            customKeyboardLayout.setVisibility(View.GONE);
            if (!customKeyboardAudio.isShown()) {
                customKeyboardAudio.setVisibility(View.VISIBLE);
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                }
            } else {
                temporizadorAcept.setVisibility(View.INVISIBLE);
                keyboardLayout.setVisibility(View.GONE);
                customKeyboardLayout.setVisibility(View.GONE);
                customKeyboardAudio.setVisibility(View.GONE);
                isShowCustomKeyboard = false;
            }
        }
        break;
    case R.id.adjunt_photo:
        System.gc();
        choosePicture();
        break;
    case R.id.adjunt_video:
        System.gc();
        dontClose = true;
        ((MainActivity) activity).dontClose = true;
        hideKeyBoard();
        Intent videoPickerIntent = new Intent(Intent.ACTION_PICK);
        videoPickerIntent.setType("video/*");
        startActivityForResult(videoPickerIntent, 18);
        menuAdjunt = false;
        adjuntLayout.setVisibility(View.GONE);
        break;
    case R.id.adjunt_location:
        adjuntLayout.setVisibility(View.GONE);
        hideKeyBoard();
        menuAdjunt = false;
        milocManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
        List<String> allProviders = milocManager.getAllProviders();
        boolean gpsProvider = false;
        boolean netProvider = false;
        for (String providerName : allProviders) {
            if (providerName.equals(LocationManager.GPS_PROVIDER)) {
                gpsProvider = true;
            }
            if (providerName.equals(LocationManager.NETWORK_PROVIDER)) {
                netProvider = true;
            }
        }
        checkCountryLocation(gpsProvider, netProvider);
        break;
    }
}

From source file:me.ububble.speakall.fragment.ConversationChatFragment.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.icn_message_send:
        temporizadorAcept.setVisibility(View.INVISIBLE);
        String message = messageText.getText().toString();
        Message msjNew = new Message();
        Calendar fecha = Calendar.getInstance();
        String id = u.id + contact.idContacto + fecha.getTimeInMillis()
                + Settings.Secure.getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID);

        msjNew.mensajeId = id;/*  w w  w .j a va2s.c o  m*/
        msjNew.emisor = u.id;
        msjNew.receptor = contact.idContacto;
        msjNew.mensaje = message;
        msjNew.emisorEmail = u.email;
        msjNew.receptorEmail = contact.email;
        msjNew.emisorLang = u.lang;
        msjNew.receptorLang = contact.lang;
        msjNew.emitedAt = fecha.getTimeInMillis();
        msjNew.tipo = Integer.parseInt(getString(R.string.MSG_TYPE_TEXT));
        if (tiempoMensaje)
            msjNew.delay = temporizadorSeek.getValue();
        else
            msjNew.delay = 0;
        msjNew.translation = translate;
        if (SpeakSocket.mSocket != null)
            if (SpeakSocket.mSocket.connected()) {
                msjNew.status = 1;
            } else {
                msjNew.status = -1;
            }

        msjNew.save();
        Chats chat = new Select().from(Chats.class).where("idContacto = ?", msjNew.receptor).executeSingle();
        if (chat == null) {
            Contact contact = new Select().from(Contact.class).where("id_contact = ?", msjNew.receptor)
                    .executeSingle();
            Chats newChat = new Chats();
            newChat.mensajeId = msjNew.mensajeId;
            newChat.idContacto = msjNew.receptor;
            newChat.isLockedConversation = false;
            newChat.lastStatus = msjNew.status;
            newChat.email = msjNew.receptorEmail;
            if (contact != null) {
                newChat.photo = contact.photo;
                newChat.fullName = contact.fullName;
                newChat.lang = contact.lang;
                newChat.screenName = contact.screenName;
                newChat.photoload = true;
                newChat.phone = contact.phone;
            } else {
                newChat.photo = null;
                newChat.photoload = false;
                newChat.fullName = msjNew.receptorEmail;
                newChat.lang = msjNew.receptorLang;
                newChat.screenName = msjNew.receptorEmail;
                newChat.phone = null;
            }
            newChat.emitedAt = msjNew.emitedAt;
            newChat.notRead = 0;
            newChat.lastMessage = msjNew.mensaje;
            newChat.show = true;
            newChat.save();
        } else {
            if (!chat.photoload) {
                Contact contact = new Select().from(Contact.class).where("id_contact = ?", msjNew.emisor)
                        .executeSingle();
                if (contact != null) {
                    chat.photo = contact.photo;
                    chat.photoload = true;
                } else {
                    chat.photo = null;
                    chat.photoload = false;
                }
            }
            chat.mensajeId = msjNew.mensajeId;
            chat.lastStatus = msjNew.status;
            chat.emitedAt = msjNew.emitedAt;
            chat.notRead = 0;
            chat.lastMessage = msjNew.mensaje;
            chat.save();
        }
        messageText.setText("");
        showNewMessage(msjNew);
        messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
        messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
        tiempoMensaje = false;
        break;
    case R.id.message_text:
        SharedPreferences settings = getActivity().getSharedPreferences(Finder.STRING.APP_PREF.toString(),
                Context.MODE_PRIVATE);
        if (settings.getInt("INPUTKEY", 0) == 0) {
            customKeyboardLayout.setVisibility(View.GONE);
            customKeyboardAudio.setVisibility(View.GONE);
            keyboardLayout.setVisibility(View.GONE);
            isShowCustomKeyboard = false;
            if (tiempoMensaje) {
                messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
            } else {
                messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
            }
            isShowKeyboard = true;
        } else {
            if (!isShowKeyboard) {
                if (!isShowCustomKeyboard) {
                    messagesListScroll.setVerticalScrollBarEnabled(false);
                    final InputMethodManager imm = (InputMethodManager) activity
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    if (tiempoMensaje) {
                        messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                        messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                    } else {
                        messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                        messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    }
                    imm.showSoftInput(messageText, 0);
                    keyboardLayout.setVisibility(View.GONE);
                    AnimatorSet set = new AnimatorSet();
                    set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                    set.setDuration(220).start();
                    set.addListener(new Animator.AnimatorListener() {
                        @Override
                        public void onAnimationStart(Animator animation) {

                        }

                        @Override
                        public void onAnimationEnd(Animator animation) {
                            keyboardLayout.setVisibility(View.VISIBLE);
                        }

                        @Override
                        public void onAnimationCancel(Animator animation) {

                        }

                        @Override
                        public void onAnimationRepeat(Animator animation) {

                        }
                    });
                    keyboardLayout
                            .setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                    isShowKeyboard = true;
                    ((MainActivity) activity).setOnBackPressedListener(null);
                    customKeyboardLayout.setVisibility(View.GONE);
                    customKeyboardAudio.setVisibility(View.GONE);
                    isShowCustomKeyboard = false;
                } else {
                    keyboardLayout.setVisibility(View.GONE);
                    AnimatorSet set = new AnimatorSet();
                    set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                    set.setDuration(220).start();
                    set.addListener(new Animator.AnimatorListener() {
                        @Override
                        public void onAnimationStart(Animator animation) {

                        }

                        @Override
                        public void onAnimationEnd(Animator animation) {
                            keyboardLayout.setVisibility(View.VISIBLE);
                        }

                        @Override
                        public void onAnimationCancel(Animator animation) {

                        }

                        @Override
                        public void onAnimationRepeat(Animator animation) {

                        }
                    });
                    ((MainActivity) activity).setOnBackPressedListener(null);
                    messagesListScroll.setVerticalScrollBarEnabled(false);
                    if (tiempoMensaje) {
                        messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                        messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                    } else {
                        messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                        messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    }
                    final InputMethodManager imm = (InputMethodManager) activity
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.showSoftInput(messageText, 0);
                    keyboardLayout
                            .setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                    isShowKeyboard = true;
                    customKeyboardLayout.setVisibility(View.GONE);
                    customKeyboardAudio.setVisibility(View.GONE);
                    isShowCustomKeyboard = false;
                }
            }
        }
        break;
    case R.id.icn_message_translate:
        translate = !translate;
        if (translate)
            messageTranslate.setTextColor(getResources().getColor(R.color.speak_all_red));
        else
            messageTranslate.setTextColor(getResources().getColor(R.color.speak_all_gray));
        break;
    case R.id.icn_message_clock:
        tiempoMensaje = false;
        temporizadorAcept.setVisibility(View.INVISIBLE);
        temporizadorSeek.setInitPosition(0);
        SharedPreferences settings1 = getActivity().getSharedPreferences(Finder.STRING.APP_PREF.toString(),
                Context.MODE_PRIVATE);
        if (settings1.getInt("INPUTKEY", 0) != 0) {
            getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
        }
        if (!isShowCustomKeyboard) {
            if (!isShowKeyboard) {
                keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                }
                keyboardLayout.setVisibility(View.GONE);
                AnimatorSet set = new AnimatorSet();
                set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                set.setDuration(220).start();
                set.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        keyboardLayout.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
                customKeyboardLayout.setVisibility(View.VISIBLE);
                customKeyboardAudio.setVisibility(View.GONE);
                ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) {
                    @Override
                    public void doBack() {
                        if (tiempoMensaje) {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                        } else {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                        }
                        keyboardLayout.setVisibility(View.GONE);
                        customKeyboardLayout.setVisibility(View.GONE);
                        customKeyboardAudio.setVisibility(View.GONE);
                        isShowCustomKeyboard = false;
                        ((MainActivity) activity).setOnBackPressedListener(null);
                    }
                });
                isShowCustomKeyboard = true;
                isShowKeyboard = false;
            } else {
                keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                keyboardLayout.setVisibility(View.GONE);
                AnimatorSet set = new AnimatorSet();
                set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                set.setDuration(220).start();
                set.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        keyboardLayout.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
                hideKeyBoard();
                ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) {
                    @Override
                    public void doBack() {
                        if (tiempoMensaje) {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                        } else {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                        }
                        keyboardLayout.setVisibility(View.GONE);
                        customKeyboardLayout.setVisibility(View.GONE);
                        customKeyboardAudio.setVisibility(View.GONE);
                        isShowCustomKeyboard = false;
                        ((MainActivity) activity).setOnBackPressedListener(null);
                    }
                });
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                }
                customKeyboardLayout.setVisibility(View.VISIBLE);
                customKeyboardAudio.setVisibility(View.GONE);
                isShowCustomKeyboard = true;
                isShowKeyboard = false;
            }
        } else {
            customKeyboardAudio.setVisibility(View.GONE);
            if (!customKeyboardLayout.isShown()) {
                customKeyboardLayout.setVisibility(View.VISIBLE);
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                }
            } else {
                temporizadorAcept.setVisibility(View.INVISIBLE);
                keyboardLayout.setVisibility(View.GONE);
                customKeyboardLayout.setVisibility(View.GONE);
                customKeyboardAudio.setVisibility(View.GONE);
                isShowCustomKeyboard = false;
                tiempoMensaje = false;
                if (tiempoMensaje) {
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                } else {
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                }
            }
        }
        break;
    case R.id.temporizador_cancel:
        temporizadorAcept.setVisibility(View.INVISIBLE);
        messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
        messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
        keyboardLayout.setVisibility(View.GONE);
        customKeyboardLayout.setVisibility(View.GONE);
        customKeyboardAudio.setVisibility(View.GONE);
        temporizadorSeek.setInitPosition(0);
        isShowCustomKeyboard = false;
        tiempoMensaje = false;
        break;
    case R.id.temporizador_acept:
        temporizadorAcept.setVisibility(View.INVISIBLE);
        messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
        messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
        keyboardLayout.setVisibility(View.GONE);
        customKeyboardLayout.setVisibility(View.GONE);
        customKeyboardAudio.setVisibility(View.GONE);
        isShowCustomKeyboard = false;
        tiempoMensaje = true;
        if (!isShowKeyboard) {
            if (!isShowCustomKeyboard) {
                messagesListScroll.setVerticalScrollBarEnabled(false);
                final InputMethodManager imm = (InputMethodManager) activity
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                }
                imm.showSoftInput(messageText, 0);
                keyboardLayout.setVisibility(View.GONE);
                AnimatorSet set = new AnimatorSet();
                set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                set.setDuration(220).start();
                set.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        keyboardLayout.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
                keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                isShowKeyboard = true;
                ((MainActivity) activity).setOnBackPressedListener(null);
                customKeyboardLayout.setVisibility(View.GONE);
                customKeyboardAudio.setVisibility(View.GONE);
                isShowCustomKeyboard = false;
            } else {
                keyboardLayout.setVisibility(View.GONE);
                AnimatorSet set = new AnimatorSet();
                set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                set.setDuration(220).start();
                set.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        keyboardLayout.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
                ((MainActivity) activity).setOnBackPressedListener(null);
                messagesListScroll.setVerticalScrollBarEnabled(false);
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                }
                final InputMethodManager imm = (InputMethodManager) activity
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(messageText, 0);
                keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                isShowKeyboard = true;
                customKeyboardLayout.setVisibility(View.GONE);
                customKeyboardAudio.setVisibility(View.GONE);
                isShowCustomKeyboard = false;
            }
        }
        break;
    case R.id._1:
        temporizadorSeek.setInitPosition(15);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._2:
        temporizadorSeek.setInitPosition(30);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._3:
        temporizadorSeek.setInitPosition(45);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._4:
        temporizadorSeek.setInitPosition(60);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._5:
        temporizadorSeek.setInitPosition(75);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._6:
        temporizadorSeek.setInitPosition(90);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._7:
        temporizadorSeek.setInitPosition(105);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._8:
        temporizadorSeek.setInitPosition(120);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._9:
        temporizadorSeek.setInitPosition(135);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._10:
        temporizadorSeek.setInitPosition(150);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._11:
        temporizadorSeek.setInitPosition(165);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._12:
        temporizadorSeek.setInitPosition(180);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id.adjunt_image:
        System.gc();
        dontClose = true;
        ((MainActivity) activity).dontClose = true;
        hideKeyBoard();
        Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
        photoPickerIntent.setType("image/*");
        startActivityForResult(photoPickerIntent, 1);
        menuAdjunt = false;
        adjuntLayout.setVisibility(View.GONE);
        break;
    case R.id.adjunt_contact:
        System.gc();
        dontClose = true;
        ((MainActivity) activity).dontClose = true;
        hideKeyBoard();
        Intent i = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
        startActivityForResult(i, 34);
        menuAdjunt = false;
        adjuntLayout.setVisibility(View.GONE);
        break;
    case R.id.adjunt_audio:
        menuAdjunt = false;
        adjuntLayout.setVisibility(View.GONE);
        SharedPreferences settings2 = getActivity().getSharedPreferences(Finder.STRING.APP_PREF.toString(),
                Context.MODE_PRIVATE);
        if (settings2.getInt("INPUTKEY", 0) != 0) {
            getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
        }
        if (!isShowCustomKeyboard) {
            if (!isShowKeyboard) {
                keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                }
                keyboardLayout.setVisibility(View.GONE);
                AnimatorSet set4 = new AnimatorSet();
                set4.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                set4.setDuration(220).start();
                set4.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        keyboardLayout.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
                customKeyboardLayout.setVisibility(View.GONE);
                customKeyboardAudio.setVisibility(View.VISIBLE);
                ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) {
                    @Override
                    public void doBack() {
                        if (tiempoMensaje) {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                        } else {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                        }
                        keyboardLayout.setVisibility(View.GONE);
                        customKeyboardLayout.setVisibility(View.GONE);
                        customKeyboardAudio.setVisibility(View.GONE);
                        isShowCustomKeyboard = false;
                        ((MainActivity) activity).setOnBackPressedListener(null);
                    }
                });
                isShowCustomKeyboard = true;
                isShowKeyboard = false;
            } else {
                keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                keyboardLayout.setVisibility(View.GONE);
                AnimatorSet set5 = new AnimatorSet();
                set5.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                set5.setDuration(220).start();
                set5.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        keyboardLayout.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
                hideKeyBoard();
                ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) {
                    @Override
                    public void doBack() {
                        if (tiempoMensaje) {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                        } else {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                        }
                        keyboardLayout.setVisibility(View.GONE);
                        customKeyboardLayout.setVisibility(View.GONE);
                        customKeyboardAudio.setVisibility(View.GONE);
                        isShowCustomKeyboard = false;
                        ((MainActivity) activity).setOnBackPressedListener(null);
                    }
                });
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                }
                customKeyboardLayout.setVisibility(View.GONE);
                customKeyboardAudio.setVisibility(View.VISIBLE);
                isShowCustomKeyboard = true;
                isShowKeyboard = false;
            }
        } else {
            customKeyboardLayout.setVisibility(View.GONE);
            if (!customKeyboardAudio.isShown()) {
                customKeyboardAudio.setVisibility(View.VISIBLE);
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                }
            } else {
                temporizadorAcept.setVisibility(View.INVISIBLE);
                keyboardLayout.setVisibility(View.GONE);
                customKeyboardLayout.setVisibility(View.GONE);
                customKeyboardAudio.setVisibility(View.GONE);
                isShowCustomKeyboard = false;
            }
        }
        break;
    case R.id.add_to_contacts:
        try {
            JSONArray jsonArr = new JSONArray();
            JSONObject jsonObj = new JSONObject();
            jsonObj.put(C.c_id_contact, contact.idContacto);
            RequestParams params = new RequestParams();
            params.put("contacts", jsonArr.put(jsonObj));
            addToContacts(params);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        break;
    case R.id.adjunt_photo:
        System.gc();
        dontClose = true;
        ((MainActivity) activity).dontClose = true;
        hideKeyBoard();
        File imagesFolder = new File(
                Environment.getExternalStorageDirectory().getAbsolutePath() + "/SpeakOn/Image/Sent");
        imagesFolder.mkdirs();
        adjuntLayout.setVisibility(View.GONE);
        dateToCamera = Calendar.getInstance().getTimeInMillis();
        File image = new File(imagesFolder, dateToCamera + ".png");
        Uri uriSavedImage = Uri.fromFile(image);
        Intent pictureActionIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        pictureActionIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
        startActivityForResult(pictureActionIntent, 23);
        break;
    case R.id.adjunt_video:
        System.gc();
        dontClose = true;
        ((MainActivity) activity).dontClose = true;
        hideKeyBoard();
        Intent videoPickerIntent = new Intent(Intent.ACTION_PICK);
        videoPickerIntent.setType("video/*");
        startActivityForResult(videoPickerIntent, 18);
        menuAdjunt = false;
        adjuntLayout.setVisibility(View.GONE);
        break;
    case R.id.adjunt_location:
        adjuntLayout.setVisibility(View.GONE);
        hideKeyBoard();
        menuAdjunt = false;
        milocManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
        List<String> allProviders = milocManager.getAllProviders();
        boolean gpsProvider = false;
        boolean netProvider = false;
        for (String providerName : allProviders) {
            if (providerName.equals(LocationManager.GPS_PROVIDER)) {
                gpsProvider = true;
            }
            if (providerName.equals(LocationManager.NETWORK_PROVIDER)) {
                netProvider = true;
            }
        }
        checkCountryLocation(gpsProvider, netProvider);
        break;
    }
}