Example usage for android.view Window findViewById

List of usage examples for android.view Window findViewById

Introduction

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

Prototype

@Nullable
public <T extends View> T findViewById(@IdRes int id) 

Source Link

Document

Finds a view that was identified by the android:id XML attribute that was processed in android.app.Activity#onCreate .

Usage

From source file:com.hx.hxchat.activity.ChatHistoryFragment.java

/**
 * // w w  w  .  java  2s . c  o  m
 * @param title 
 * @param emContact
 */
private void showMyDialog(String title, final ChatHistoryAdapter adapter, final int position) {

    final AlertDialog dlg = new AlertDialog.Builder(context).create();
    dlg.show();
    Window window = dlg.getWindow();
    // ??,shrew_exit_dialog.xmlview
    window.setContentView(R.layout.alertdialog);

    window.findViewById(R.id.ll_title).setVisibility(View.VISIBLE);

    TextView tv_title = (TextView) window.findViewById(R.id.tv_title);
    tv_title.setText(title);

    TextView tv_content1 = (TextView) window.findViewById(R.id.tv_content1);
    final String username = adapter.getItem(position).getUsername();
    // ??

    if (topMap.containsKey(username)) {
        tv_content1.setText("?");

    } else {
        tv_content1.setText("?");

    }

    tv_content1.setOnClickListener(new View.OnClickListener() {
        @SuppressLint("SdCardPath")
        public void onClick(View v) {

            if (topMap.containsKey(username)) {

                topMap.remove(username);
                TopUserDao topUserDao = new TopUserDao(context);

                topUserDao.deleteTopUser(username);

            } else {
                TopUser topUser = new TopUser();
                topUser.setTime(System.currentTimeMillis());
                // 1---
                topUser.setType(1);
                topUser.setUserName(username);
                Map<String, TopUser> map = new HashMap<String, TopUser>();
                map.put(adapter.getItem(position).getUsername(), topUser);
                topMap.putAll(map);
                TopUserDao topUserDao = new TopUserDao(context);
                topUserDao.saveTopUser(topUser);

            }
            refresh();
            dlg.cancel();
        }
    });
    TextView tv_content2 = (TextView) window.findViewById(R.id.tv_content2);
    tv_content2.setText("?");
    tv_content2.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            EMContact tobeDeleteUser = adapter.getItem(position);
            EMChatManager.getInstance().deleteConversation(adapter.getItem(position).getUsername());
            InviteMessgeDao inviteMessgeDao = new InviteMessgeDao(context);
            inviteMessgeDao.deleteMessage(tobeDeleteUser.getUsername());

            BaseApplication.getApplication().GetLinkerDao().deleteContact(tobeDeleteUser.getUsername());
            adapter.remove(tobeDeleteUser);
            adapter.notifyDataSetChanged();
            //              ((MainActivity) context).homefragment.refresh();

            //           boolean isGroup = false;
            //           
            //           
            //           if (tobeDeleteUser instanceof EMGroup)
            //              isGroup = true;
            //
            //           // ?
            //           boolean deleteConversation = EMChatManager.getInstance().deleteConversation(tobeDeleteUser.getUsername());
            //           InviteMessgeDao inviteMessgeDao = new InviteMessgeDao(getActivity());
            //           inviteMessgeDao.deleteMessage(tobeDeleteUser.getUsername());
            //
            //           BaseApplication.getApplication().GetLinkerDao().deleteContact(tobeDeleteUser.getUsername());
            //           adapter.remove(tobeDeleteUser);
            //           adapter.notifyDataSetChanged();
            //
            //           // ?
            //           // TODO
            //           // ((MainActivity) getActivity()).updateUnreadLabel();
            //
            //              
            //              

            dlg.cancel();

        }
    });

}

From source file:com.jomendezdev.cordova.admob.AdMobAds.java

/**
 * Parses the show ad input parameters and runs the show ad action on the UI thread.
 * /*from   w w  w . ja v  a2  s.co  m*/
 * @param inputs The JSONArray representing input parameters. This function expects the first object in the array to be a JSONObject with the input
 *          parameters.
 * @return A PluginResult representing whether or not an ad was requested succcessfully. Listen for onReceiveAd() and onFailedToReceiveAd() callbacks to see
 *         if an ad was successfully retrieved.
 */
private PluginResult executeShowBannerAd(final boolean show, final CallbackContext callbackContext) {
    if (adView == null) {
        return new PluginResult(Status.ERROR, "adView is null, call createBannerView first.");
    }

    cordova.getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (show == isBannerVisible) {
                // no change

            } else if (show) {
                if (adView.getParent() != null) {
                    ((ViewGroup) adView.getParent()).removeView(adView);
                }

                if (isBannerOverlap) {
                    RelativeLayout.LayoutParams params2 = new RelativeLayout.LayoutParams(
                            RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);

                    if (isOffsetStatusBar) {
                        int titleBarHeight = 0;
                        Rect rectangle = new Rect();
                        Window window = AdMobAds.this.cordova.getActivity().getWindow();
                        window.getDecorView().getWindowVisibleDisplayFrame(rectangle);

                        if (isBannerAtTop) {
                            if (rectangle.top == 0) {
                                int contentViewTop = window.findViewById(Window.ID_ANDROID_CONTENT).getTop();
                                titleBarHeight = contentViewTop - rectangle.top;
                            }
                            params2.topMargin = titleBarHeight;

                        } else {
                            if (rectangle.top > 0) {
                                int contentViewBottom = window.findViewById(Window.ID_ANDROID_CONTENT)
                                        .getBottom();
                                titleBarHeight = contentViewBottom - rectangle.bottom;
                            }
                            params2.bottomMargin = titleBarHeight;
                        }

                    } else if (isBannerAtTop) {
                        params2.addRule(RelativeLayout.ALIGN_PARENT_TOP);

                    } else {
                        params2.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
                    }

                    adViewLayout.addView(adView, params2);
                    adViewLayout.bringToFront();

                } else {
                    ViewGroup parentView = (ViewGroup) webView.getParent();
                    if (isBannerAtTop) {
                        parentView.addView(adView, 0);
                    } else {
                        parentView.addView(adView);
                    }
                    parentView.bringToFront();
                }

                adView.setVisibility(View.VISIBLE);
                isBannerVisible = true;

            } else {
                adView.setVisibility(View.GONE);
                isBannerVisible = false;
            }

            if (callbackContext != null) {
                callbackContext.success();
            }
        }
    });
    return null;
}

From source file:com.appfeel.cordova.admob.AdMobAds.java

/**
 * Parses the show ad input parameters and runs the show ad action on the UI thread.
 * /*from w ww  .ja v  a2 s  . c  o m*/
 * @param inputs The JSONArray representing input parameters. This function expects the first object in the array to be a JSONObject with the input
 *          parameters.
 * @return A PluginResult representing whether or not an ad was requested succcessfully. Listen for onReceiveAd() and onFailedToReceiveAd() callbacks to see
 *         if an ad was successfully retrieved.
 */
private PluginResult executeShowBannerAd(final boolean show, final CallbackContext callbackContext) {
    if (adView == null) {
        return new PluginResult(Status.ERROR, "adView is null, call createBannerView first.");
    }

    cordova.getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (show == isBannerVisible) {
                // no change

            } else if (show) {
                if (adView.getParent() != null) {
                    ((ViewGroup) adView.getParent()).removeView(adView);
                }

                if (isBannerOverlap) {
                    RelativeLayout.LayoutParams params2 = new RelativeLayout.LayoutParams(
                            RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);

                    if (isOffsetStatusBar) {
                        int titleBarHeight = 0;
                        Rect rectangle = new Rect();
                        Window window = AdMobAds.this.cordova.getActivity().getWindow();
                        window.getDecorView().getWindowVisibleDisplayFrame(rectangle);

                        if (isBannerAtTop) {
                            if (rectangle.top == 0) {
                                int contentViewTop = window.findViewById(Window.ID_ANDROID_CONTENT).getTop();
                                titleBarHeight = contentViewTop - rectangle.top;
                            }
                            params2.topMargin = titleBarHeight;

                        } else {
                            if (rectangle.top > 0) {
                                int contentViewBottom = window.findViewById(Window.ID_ANDROID_CONTENT)
                                        .getBottom();
                                titleBarHeight = contentViewBottom - rectangle.bottom;
                            }
                            params2.bottomMargin = titleBarHeight;
                        }

                    } else if (isBannerAtTop) {
                        params2.addRule(RelativeLayout.ALIGN_PARENT_TOP);

                    } else {
                        params2.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
                    }

                    if (adViewLayout == null) {
                        adViewLayout = new RelativeLayout(cordova.getActivity());
                        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                                RelativeLayout.LayoutParams.MATCH_PARENT,
                                RelativeLayout.LayoutParams.MATCH_PARENT);
                        if (CORDOVA_4) {
                            ((ViewGroup) webView.getView().getParent()).addView(adViewLayout, params);
                        } else {
                            ((ViewGroup) webView).addView(adViewLayout, params);
                        }
                    }
                    adViewLayout.addView(adView, params2);
                    adViewLayout.bringToFront();

                } else {
                    if (CORDOVA_4) {
                        ViewGroup wvParentView = (ViewGroup) webView.getView().getParent();

                        if (parentView == null) {
                            parentView = new LinearLayout(webView.getContext());
                        }

                        if (wvParentView != null && wvParentView != parentView) {
                            wvParentView.removeView(webView.getView());
                            ((LinearLayout) parentView).setOrientation(LinearLayout.VERTICAL);
                            parentView.setLayoutParams(
                                    new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                                            ViewGroup.LayoutParams.MATCH_PARENT, 0.0F));
                            webView.getView().setLayoutParams(
                                    new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                                            ViewGroup.LayoutParams.MATCH_PARENT, 1.0F));
                            parentView.addView(webView.getView());
                            cordova.getActivity().setContentView(parentView);
                        }

                    } else {
                        parentView = (ViewGroup) ((ViewGroup) webView).getParent();
                    }

                    if (isBannerAtTop) {
                        parentView.addView(adView, 0);
                    } else {
                        parentView.addView(adView);
                    }
                    parentView.bringToFront();
                    parentView.requestLayout();

                }

                adView.setVisibility(View.VISIBLE);
                isBannerVisible = true;

            } else {
                adView.setVisibility(View.GONE);
                isBannerVisible = false;
            }

            if (callbackContext != null) {
                callbackContext.success();
            }
        }
    });
    return null;
}

From source file:org.getlantern.firetweet.activity.support.ComposeActivity.java

@Override
public void onDestroyActionMode(ActionMode mode) {
    final Window window = getWindow();
    final View contentView = window.findViewById(android.R.id.content);
    contentView.setPadding(contentView.getPaddingLeft(), 0, contentView.getPaddingRight(),
            contentView.getPaddingBottom());
}

From source file:org.getlantern.firetweet.activity.support.ComposeActivity.java

@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
    final Window window = getWindow();
    final Rect rect = new Rect();
    window.getDecorView().getWindowVisibleDisplayFrame(rect);
    final View contentView = window.findViewById(android.R.id.content);
    final int statusBarHeight = rect.top;
    contentView.getWindowVisibleDisplayFrame(rect);
    final int paddingTop = statusBarHeight + Utils.getActionBarHeight(this) - rect.top;
    contentView.setPadding(contentView.getPaddingLeft(), paddingTop, contentView.getPaddingRight(),
            contentView.getPaddingBottom());
    return true;//from  www . jav a2 s . c o  m
}

From source file:org.mariotaku.twidere.activity.support.ComposeActivity.java

@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
    final Window window = getWindow();
    final Rect rect = new Rect();
    window.getDecorView().getWindowVisibleDisplayFrame(rect);
    final int actionBarHeight = ThemeUtils.getActionBarHeight(this);
    final View contentView = window.findViewById(android.R.id.content);
    final int[] location = new int[2];
    contentView.getLocationOnScreen(location);
    if (location[1] > actionBarHeight) {
        contentView.setPadding(contentView.getPaddingLeft(), 0, contentView.getPaddingRight(),
                contentView.getPaddingBottom());
        return true;
    }/*  w w  w  .  j a v a  2 s . co m*/
    final int statusBarHeight = rect.top;
    contentView.getWindowVisibleDisplayFrame(rect);
    final int paddingTop = statusBarHeight + actionBarHeight - rect.top;
    contentView.setPadding(contentView.getPaddingLeft(), paddingTop, contentView.getPaddingRight(),
            contentView.getPaddingBottom());
    return true;
}

From source file:com.mobiletin.inputmethod.indic.LatinIME.java

@Override
public void updateFullscreenMode() {
    // Override layout parameters to expand {@link SoftInputWindow} to the entire screen.
    // See {@link InputMethodService#setinputView(View) and
    // {@link SoftInputWindow#updateWidthHeight(WindowManager.LayoutParams)}.
    final Window window = getWindow().getWindow();
    ViewLayoutUtils.updateLayoutHeightOf(window, LayoutParams.MATCH_PARENT);
    // This method may be called before {@link #setInputView(View)}.
    if (mInputView != null) {
        // In non-fullscreen mode, {@link InputView} and its parent inputArea should expand to
        // the entire screen and be placed at the bottom of {@link SoftInputWindow}.
        // In fullscreen mode, these shouldn't expand to the entire screen and should be
        // coexistent with {@link #mExtractedArea} above.
        // See {@link InputMethodService#setInputView(View) and
        // com.android.internal.R.layout.input_method.xml.
        final int layoutHeight = isFullscreenMode() ? LayoutParams.WRAP_CONTENT : LayoutParams.MATCH_PARENT;
        final View inputArea = window.findViewById(android.R.id.inputArea);
        ViewLayoutUtils.updateLayoutHeightOf(inputArea, layoutHeight);
        ViewLayoutUtils.updateLayoutGravityOf(inputArea, Gravity.BOTTOM);
        ViewLayoutUtils.updateLayoutHeightOf(mInputView, layoutHeight);
    }/*w  w w  .java2s  .  co  m*/
    super.updateFullscreenMode();
    mInputLogic.onUpdateFullscreenMode(isFullscreenMode());
}