Example usage for android.view Window getDecorView

List of usage examples for android.view Window getDecorView

Introduction

In this page you can find the example usage for android.view Window getDecorView.

Prototype

public abstract View getDecorView();

Source Link

Document

Retrieve the top-level window decor view (containing the standard window frame/decorations and the client's content inside of that), which can be added as a window to the window manager.

Usage

From source file:com.vuze.android.remote.fragment.TorrentListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    fragView = inflater.inflate(R.layout.frag_torrent_list, container, false);

    setupActionModeCallback();//from w ww .  j  a  va  2 s . c  o m

    final SwipeRefreshLayoutExtra swipeRefresh = (SwipeRefreshLayoutExtra) fragView
            .findViewById(R.id.swipe_container);
    if (swipeRefresh != null) {
        swipeRefresh.setExtraLayout(R.layout.swipe_layout_extra);

        LastUpdatedInfo lui = getLastUpdatedString();
        if (lui != null) {
            View extraView = swipeRefresh.getExtraView();
            if (extraView != null) {
                TextView tvSwipeText = (TextView) extraView.findViewById(R.id.swipe_text);
                tvSwipeText.setText(lui.s);
            }
        }
        swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                if (sessionInfo == null) {
                    return;
                }
                sessionInfo.addTorrentListReceivedListener(new TorrentListReceivedListener() {

                    @Override
                    public void rpcTorrentListReceived(String callID, List<?> addedTorrentMaps,
                            List<?> removedTorrentIDs) {
                        AndroidUtils.runOnUIThread(TorrentListFragment.this, new Runnable() {
                            @Override
                            public void run() {
                                if (getActivity() == null) {
                                    return;
                                }
                                swipeRefresh.setRefreshing(false);
                                LastUpdatedInfo lui = getLastUpdatedString();
                                View extraView = swipeRefresh.getExtraView();
                                if (extraView != null) {
                                    TextView tvSwipeText = (TextView) extraView.findViewById(R.id.swipe_text);
                                    tvSwipeText.setText(lui.s);
                                }
                            }
                        });
                        sessionInfo.removeTorrentListReceivedListener(this);
                    }
                }, false);
                sessionInfo.triggerRefresh(true);
            }
        });
        swipeRefresh.setOnExtraViewVisibilityChange(
                new SwipeRefreshLayoutExtra.OnExtraViewVisibilityChangeListener() {
                    private Handler pullRefreshHandler;

                    @Override
                    public void onExtraViewVisibilityChange(final View view, int visibility) {
                        if (pullRefreshHandler != null) {
                            pullRefreshHandler.removeCallbacksAndMessages(null);
                            pullRefreshHandler = null;
                        }
                        if (visibility != View.VISIBLE) {
                            return;
                        }

                        pullRefreshHandler = new Handler(Looper.getMainLooper());

                        pullRefreshHandler.postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                if (getActivity() == null) {
                                    return;
                                }
                                LastUpdatedInfo lui = getLastUpdatedString();
                                if (lui == null) {
                                    return;
                                }
                                TextView tvSwipeText = (TextView) view.findViewById(R.id.swipe_text);
                                tvSwipeText.setText(lui.s);

                                if (pullRefreshHandler != null) {
                                    pullRefreshHandler.postDelayed(this,
                                            lui.sinceMS < DateUtils.MINUTE_IN_MILLIS
                                                    ? DateUtils.SECOND_IN_MILLIS
                                                    : lui.sinceMS < DateUtils.HOUR_IN_MILLIS
                                                            ? DateUtils.MINUTE_IN_MILLIS
                                                            : DateUtils.HOUR_IN_MILLIS);
                                }
                            }
                        }, 0);
                    }
                });
    }

    listview = (RecyclerView) fragView.findViewById(R.id.listTorrents);
    listview.setLayoutManager(new PreCachingLayoutManager(getContext()));
    listview.setAdapter(torrentListAdapter);

    if (AndroidUtils.isTV()) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            listview.setVerticalScrollbarPosition(View.SCROLLBAR_POSITION_LEFT);
        }
        ((FastScrollRecyclerView) listview).setEnableFastScrolling(false);
        ((FlexibleRecyclerView) listview).setFixedVerticalHeight(AndroidUtilsUI.dpToPx(48));
        listview.setVerticalFadingEdgeEnabled(true);
        listview.setFadingEdgeLength(AndroidUtilsUI.dpToPx((int) (48 * 1.5)));
    }

    filterEditText = (EditText) fragView.findViewById(R.id.filterText);
    filterEditText.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            Filter filter = torrentListAdapter.getFilter();
            filter.filter(s);
        }

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

        @Override
        public void afterTextChanged(Editable s) {
        }
    });

    setupSideListArea(fragView);

    /** Handy code to watch the states of row 2
     listview.postDelayed(new Runnable() {
     String oldS = "";
            
     @Override public void run() {
            
     String s = (listview.getChildCount() < 3 ? ""
     : AndroidUtils.getStatesString(listview.getChildAt(2).getDrawableState
     ()));
            
     if (!s.equals(oldS)) {
     oldS = s;
     Log.e(TAG, "States of 2: " + s);
     }
            
     listview.postDelayed(this, 500);
     }
     }, 500);
     */

    setHasOptionsMenu(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        onCreateViewHC(fragView);
    }

    if (sideListArea != null) {
        fragView.post(new Runnable() {
            @Override
            public void run() {
                FragmentActivity activity = getActivity();
                if (activity == null) {
                    return;
                }
                Window window = activity.getWindow();
                if (window == null) {
                    return;
                }
                int dpHeight = window.getDecorView().getHeight();
                hideUnselectedSideHeaders = dpHeight < SIDELIST_HIDE_UNSELECTED_HEADERS_MAX_PX;
                expandSideListWidth(sidelistInFocus);
                if (AndroidUtils.DEBUG) {
                    Log.d(TAG, "onAttach: hide? " + hideUnselectedSideHeaders + ";" + dpHeight);
                }
            }
        });
    }

    return fragView;

}

From source file:org.godotengine.godot.Godot.java

@Override
protected void onCreate(Bundle icicle) {

    super.onCreate(icicle);
    Window window = getWindow();
    //window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
    mClipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);

    //check for apk expansion API
    if (true) {/*from   ww w  . j ava  2  s. c  o m*/
        boolean md5mismatch = false;
        command_line = getCommandLine();
        String main_pack_md5 = null;
        String main_pack_key = null;

        List<String> new_args = new LinkedList<String>();

        for (int i = 0; i < command_line.length; i++) {

            boolean has_extra = i < command_line.length - 1;
            if (command_line[i].equals("--use_depth_32")) {
                use_32_bits = true;
            } else if (command_line[i].equals("--debug_opengl")) {
                use_debug_opengl = true;
            } else if (command_line[i].equals("--use_immersive")) {
                use_immersive = true;
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // check if the application runs on an android 4.4+
                    window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | // hide nav bar
                            View.SYSTEM_UI_FLAG_FULLSCREEN | // hide status bar
                            View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

                    UiChangeListener();
                }
            } else if (command_line[i].equals("--use_apk_expansion")) {
                use_apk_expansion = true;
            } else if (has_extra && command_line[i].equals("--apk_expansion_md5")) {
                main_pack_md5 = command_line[i + 1];
                i++;
            } else if (has_extra && command_line[i].equals("--apk_expansion_key")) {
                main_pack_key = command_line[i + 1];
                SharedPreferences prefs = getSharedPreferences("app_data_keys", MODE_PRIVATE);
                Editor editor = prefs.edit();
                editor.putString("store_public_key", main_pack_key);

                editor.apply();
                i++;
            } else if (command_line[i].trim().length() != 0) {
                new_args.add(command_line[i]);
            }
        }

        if (new_args.isEmpty()) {
            command_line = null;
        } else {

            command_line = new_args.toArray(new String[new_args.size()]);
        }
        if (use_apk_expansion && main_pack_md5 != null && main_pack_key != null) {
            //check that environment is ok!
            if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
                //show popup and die
            }

            // Build the full path to the app's expansion files
            try {
                expansion_pack_path = Helpers.getSaveFilePath(getApplicationContext());
                expansion_pack_path += "/main."
                        + getPackageManager().getPackageInfo(getPackageName(), 0).versionCode + "."
                        + this.getPackageName() + ".obb";
            } catch (Exception e) {
                e.printStackTrace();
            }

            File f = new File(expansion_pack_path);

            boolean pack_valid = true;

            if (!f.exists()) {

                pack_valid = false;

            } else if (obbIsCorrupted(expansion_pack_path, main_pack_md5)) {
                pack_valid = false;
                try {
                    f.delete();
                } catch (Exception e) {
                }
            }

            if (!pack_valid) {

                Intent notifierIntent = new Intent(this, this.getClass());
                notifierIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);

                PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notifierIntent,
                        PendingIntent.FLAG_UPDATE_CURRENT);

                int startResult;
                try {
                    startResult = DownloaderClientMarshaller.startDownloadServiceIfRequired(
                            getApplicationContext(), pendingIntent, GodotDownloaderService.class);

                    if (startResult != DownloaderClientMarshaller.NO_DOWNLOAD_REQUIRED) {
                        // This is where you do set up to display the download
                        // progress (next step)
                        mDownloaderClientStub = DownloaderClientMarshaller.CreateStub(this,
                                GodotDownloaderService.class);

                        setContentView(com.godot.game.R.layout.downloading_expansion);
                        mPB = (ProgressBar) findViewById(com.godot.game.R.id.progressBar);
                        mStatusText = (TextView) findViewById(com.godot.game.R.id.statusText);
                        mProgressFraction = (TextView) findViewById(com.godot.game.R.id.progressAsFraction);
                        mProgressPercent = (TextView) findViewById(com.godot.game.R.id.progressAsPercentage);
                        mAverageSpeed = (TextView) findViewById(com.godot.game.R.id.progressAverageSpeed);
                        mTimeRemaining = (TextView) findViewById(com.godot.game.R.id.progressTimeRemaining);
                        mDashboard = findViewById(com.godot.game.R.id.downloaderDashboard);
                        mCellMessage = findViewById(com.godot.game.R.id.approveCellular);
                        mPauseButton = (Button) findViewById(com.godot.game.R.id.pauseButton);
                        mWiFiSettingsButton = (Button) findViewById(com.godot.game.R.id.wifiSettingsButton);

                        return;
                    } else {
                    }
                } catch (NameNotFoundException e) {
                    // TODO Auto-generated catch block
                }
            }
        }
    }

    mCurrentIntent = getIntent();

    initializeGodot();

    //instanceSingleton( new GodotFacebook(this) );
}

From source file:org.mozilla.gecko.GeckoApp.java

public void setFullScreen(final boolean fullscreen) {
    mMainHandler.post(new Runnable() {
        public void run() {
            // Hide/show the system notification bar
            Window window = getWindow();
            window.setFlags(fullscreen ? WindowManager.LayoutParams.FLAG_FULLSCREEN : 0,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);

            if (Build.VERSION.SDK_INT >= 11)
                window.getDecorView().setSystemUiVisibility(fullscreen ? 1 : 0);
        }//from www .j a  v a 2s  .co m
    });
}

From source file:de.vanita5.twittnuker.util.Utils.java

public static int inferStatusBarHeight(final Activity activity) {
    final Window w = activity.getWindow();
    final View decorView = w.getDecorView();
    final Rect rect = new Rect();
    decorView.getWindowVisibleDisplayFrame(rect);
    return rect.top;
}

From source file:ren.qinc.markdowneditors.base.BaseActivity.java

/**
 * ???ActionMode??//  w w w  .ja v  a 2s  . c  om
 *
 * @param activity
 * @param mode
 */
private void fixActionModeCallback(AppCompatActivity activity, ActionMode mode) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
        return;

    if (!(mode instanceof StandaloneActionMode))
        return;

    try {
        final Field mCallbackField = mode.getClass().getDeclaredField("mCallback");
        mCallbackField.setAccessible(true);
        final Object mCallback = mCallbackField.get(mode);

        final Field mWrappedField = mCallback.getClass().getDeclaredField("mWrapped");
        mWrappedField.setAccessible(true);
        final ActionMode.Callback mWrapped = (ActionMode.Callback) mWrappedField.get(mCallback);

        final Field mDelegateField = AppCompatActivity.class.getDeclaredField("mDelegate");
        mDelegateField.setAccessible(true);
        final Object mDelegate = mDelegateField.get(activity);

        mCallbackField.set(mode, new ActionMode.Callback() {

            @Override
            public boolean onCreateActionMode(android.support.v7.view.ActionMode mode, Menu menu) {
                return mWrapped.onCreateActionMode(mode, menu);
            }

            @Override
            public boolean onPrepareActionMode(android.support.v7.view.ActionMode mode, Menu menu) {
                return mWrapped.onPrepareActionMode(mode, menu);
            }

            @Override
            public boolean onActionItemClicked(android.support.v7.view.ActionMode mode, MenuItem item) {
                return mWrapped.onActionItemClicked(mode, item);
            }

            @Override
            public void onDestroyActionMode(final android.support.v7.view.ActionMode mode) {
                Class mDelegateClass = mDelegate.getClass().getSuperclass();
                Window mWindow = null;
                PopupWindow mActionModePopup = null;
                Runnable mShowActionModePopup = null;
                ActionBarContextView mActionModeView = null;
                AppCompatCallback mAppCompatCallback = null;
                ViewPropertyAnimatorCompat mFadeAnim = null;
                android.support.v7.view.ActionMode mActionMode = null;

                Field mFadeAnimField = null;
                Field mActionModeField = null;

                while (mDelegateClass != null) {
                    try {
                        if (TextUtils.equals("AppCompatDelegateImplV7", mDelegateClass.getSimpleName())) {
                            Field mActionModePopupField = mDelegateClass.getDeclaredField("mActionModePopup");
                            mActionModePopupField.setAccessible(true);
                            mActionModePopup = (PopupWindow) mActionModePopupField.get(mDelegate);

                            Field mShowActionModePopupField = mDelegateClass
                                    .getDeclaredField("mShowActionModePopup");
                            mShowActionModePopupField.setAccessible(true);
                            mShowActionModePopup = (Runnable) mShowActionModePopupField.get(mDelegate);

                            Field mActionModeViewField = mDelegateClass.getDeclaredField("mActionModeView");
                            mActionModeViewField.setAccessible(true);
                            mActionModeView = (ActionBarContextView) mActionModeViewField.get(mDelegate);

                            mFadeAnimField = mDelegateClass.getDeclaredField("mFadeAnim");
                            mFadeAnimField.setAccessible(true);
                            mFadeAnim = (ViewPropertyAnimatorCompat) mFadeAnimField.get(mDelegate);

                            mActionModeField = mDelegateClass.getDeclaredField("mActionMode");
                            mActionModeField.setAccessible(true);
                            mActionMode = (android.support.v7.view.ActionMode) mActionModeField.get(mDelegate);

                        } else if (TextUtils.equals("AppCompatDelegateImplBase",
                                mDelegateClass.getSimpleName())) {
                            Field mAppCompatCallbackField = mDelegateClass
                                    .getDeclaredField("mAppCompatCallback");
                            mAppCompatCallbackField.setAccessible(true);
                            mAppCompatCallback = (AppCompatCallback) mAppCompatCallbackField.get(mDelegate);

                            Field mWindowField = mDelegateClass.getDeclaredField("mWindow");
                            mWindowField.setAccessible(true);
                            mWindow = (Window) mWindowField.get(mDelegate);
                        }

                        mDelegateClass = mDelegateClass.getSuperclass();
                    } catch (NoSuchFieldException e) {
                        e.printStackTrace();
                    } catch (IllegalAccessException e) {
                        e.printStackTrace();
                    }
                }

                if (mActionModePopup != null) {
                    mWindow.getDecorView().removeCallbacks(mShowActionModePopup);
                }

                if (mActionModeView != null) {
                    if (mFadeAnim != null) {
                        mFadeAnim.cancel();
                    }

                    mFadeAnim = ViewCompat.animate(mActionModeView).alpha(0.0F);

                    final PopupWindow mActionModePopupFinal = mActionModePopup;
                    final ActionBarContextView mActionModeViewFinal = mActionModeView;
                    final ViewPropertyAnimatorCompat mFadeAnimFinal = mFadeAnim;
                    final AppCompatCallback mAppCompatCallbackFinal = mAppCompatCallback;
                    final android.support.v7.view.ActionMode mActionModeFinal = mActionMode;
                    final Field mFadeAnimFieldFinal = mFadeAnimField;
                    final Field mActionModeFieldFinal = mActionModeField;

                    mFadeAnim.setListener(new ViewPropertyAnimatorListenerAdapter() {
                        public void onAnimationEnd(View view) {
                            mActionModeViewFinal.setVisibility(View.GONE);
                            if (mActionModePopupFinal != null) {
                                mActionModePopupFinal.dismiss();
                            } else if (mActionModeViewFinal.getParent() instanceof View) {
                                ViewCompat.requestApplyInsets((View) mActionModeViewFinal.getParent());
                            }

                            mActionModeViewFinal.removeAllViews();
                            mFadeAnimFinal.setListener((ViewPropertyAnimatorListener) null);

                            try {
                                if (mFadeAnimFieldFinal != null) {
                                    mFadeAnimFieldFinal.set(mDelegate, null);
                                }
                            } catch (IllegalAccessException e) {
                                e.printStackTrace();
                            }

                            mWrapped.onDestroyActionMode(mode);

                            if (mAppCompatCallbackFinal != null) {
                                mAppCompatCallbackFinal.onSupportActionModeFinished(mActionModeFinal);
                            }

                            try {
                                if (mActionModeFieldFinal != null) {
                                    mActionModeFieldFinal.set(mDelegate, null);
                                }
                            } catch (IllegalAccessException e) {
                                e.printStackTrace();
                            }
                        }
                    });
                }
            }
        });

    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}

From source file:android.app.Activity.java

/**
 * Returns true if this activity's <em>main</em> window currently has window focus.
 * Note that this is not the same as the view itself having focus.
 * /*w w w  .  j  av a 2s .com*/
 * @return True if this activity's main window currently has window focus.
 * 
 * @see #onWindowAttributesChanged(android.view.WindowManager.LayoutParams)
 */
public boolean hasWindowFocus() {
    Window w = getWindow();
    if (w != null) {
        View d = w.getDecorView();
        if (d != null) {
            return d.hasWindowFocus();
        }
    }
    return false;
}

From source file:android.app.Activity.java

/**
 * Called to process key events.  You can override this to intercept all 
 * key events before they are dispatched to the window.  Be sure to call 
 * this implementation for key events that should be handled normally.
 * //from   w w  w . j  a va 2s .co m
 * @param event The key event.
 * 
 * @return boolean Return true if this event was consumed.
 */
public boolean dispatchKeyEvent(KeyEvent event) {
    onUserInteraction();
    Window win = getWindow();
    if (win.superDispatchKeyEvent(event)) {
        return true;
    }
    View decor = mDecor;
    if (decor == null)
        decor = win.getDecorView();
    return event.dispatch(this, decor != null ? decor.getKeyDispatcherState() : null, this);
}

From source file:android.app.Activity.java

/**
 * Creates a new ActionBar, locates the inflated ActionBarView,
 * initializes the ActionBar with the view, and sets mActionBar.
 *///from w w  w.  ja  v  a2 s.  com
private void initActionBar() {
    Window window = getWindow();

    // Initializing the window decor can change window feature flags.
    // Make sure that we have the correct set before performing the test below.
    window.getDecorView();

    if (isChild() || !window.hasFeature(Window.FEATURE_ACTION_BAR) || mActionBar != null) {
        return;
    }

    mActionBar = new ActionBarImpl(this);
    mActionBar.setDefaultDisplayHomeAsUpEnabled(mEnableDefaultActionBarUp);

    mWindow.setDefaultIcon(mActivityInfo.getIconResource());
    mWindow.setDefaultLogo(mActivityInfo.getLogoResource());
}

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  .  jav a 2 s  .  c o  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();/* w w  w . java2  s.co 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;
}