Example usage for android.widget RelativeLayout setLayoutParams

List of usage examples for android.widget RelativeLayout setLayoutParams

Introduction

In this page you can find the example usage for android.widget RelativeLayout setLayoutParams.

Prototype

public void setLayoutParams(ViewGroup.LayoutParams params) 

Source Link

Document

Set the layout parameters associated with this view.

Usage

From source file:cn.mailchat.view.PagerSlidingTabStrip.java

private void addTextTab(final int position, String title) {
    //layout/*from   w ww  .  j  a  v  a 2 s.c o m*/
    RelativeLayout tabLayout = new RelativeLayout(getContext());
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    tabLayout.setLayoutParams(layoutParams);

    RelativeLayout.LayoutParams textParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    textParams.addRule(RelativeLayout.CENTER_IN_PARENT);
    //tab
    TextView tab = new TextView(getContext());
    tab.setId(100 + position);
    tab.setText(title);
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();
    tabLayout.addView(tab, textParams);

    //???
    RelativeLayout.LayoutParams viewParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    viewParams.addRule(RelativeLayout.RIGHT_OF, tab.getId());
    viewParams.addRule(RelativeLayout.CENTER_VERTICAL);
    View view = new View(getContext());
    ViewGroup.LayoutParams vParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    view.setLayoutParams(vParams);
    tabLayout.addView(view, viewParams);

    addTab(position, tabLayout);

}

From source file:cn.mailchat.view.PagerSlidingTabStrip.java

private void addIconTab(final int position, int resId) {

    //layout//from  w  w  w .j  a v  a 2s . co m
    RelativeLayout tabLayout = new RelativeLayout(getContext());
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    tabLayout.setLayoutParams(layoutParams);
    tabLayout.setGravity(Gravity.CENTER);

    //tab
    RelativeLayout.LayoutParams imgParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    imgParams.addRule(RelativeLayout.CENTER_IN_PARENT);
    ImageButton tab = new ImageButton(getContext());
    tab.setId(100 + position);
    tab.setImageResource(resId);
    tabLayout.addView(tab, imgParams);

    //???
    RelativeLayout.LayoutParams viewParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    viewParams.addRule(RelativeLayout.RIGHT_OF, tab.getId());
    View view = new View(getContext());
    ViewGroup.LayoutParams vParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    view.setLayoutParams(vParams);
    tabLayout.addView(view, viewParams);

    addTab(position, tabLayout);

    /*BadgeView badgeView = new BadgeView(getContext(), view);
      badgeView.setText("");
      badgeView.setTextSize(10);
      badgeView.setGravity(Gravity.CENTER);
      badgeView.setBackgroundResource(R.drawable.main_tab_new_message_notify);
      badgeView.setBadgePosition(BadgeView.POSITION_VERTICAL_LEFT);
      badgeView.show();*/
}

From source file:com.cleanwiz.applock.ui.activity.LockMainActivity.java

private void initView() {
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    RelativeLayout menu = (RelativeLayout) findViewById(R.id.menu);
    int width = getResources().getDisplayMetrics().widthPixels - DensityUtil.dip2px(mContext, 56 - 8);
    DrawerLayout.LayoutParams params = (android.support.v4.widget.DrawerLayout.LayoutParams) menu
            .getLayoutParams();/*  w  ww  .  ja v  a2  s .co  m*/
    params.width = width;
    menu.setLayoutParams(params);
    drawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() {
        @Override
        public void onDrawerSlide(View view, float v) {

        }

        @Override
        public void onDrawerOpened(View view) {
            closePopView();
            updateLockStatus();
        }

        @Override
        public void onDrawerClosed(View view) {

        }

        @Override
        public void onDrawerStateChanged(int i) {

        }
    });

    tv_lock_status = (TextView) findViewById(R.id.tv_lock_status);
    drawer_logo = (ImageView) findViewById(R.id.drawer_logo);

    actionView = (ActionView) findViewById(R.id.btn_more);
    tv_tab_box = (TextView) findViewById(R.id.tab_box);
    tv_tab_lock = (TextView) findViewById(R.id.tab_lock);

    // tab_thumb
    tab_thumb = findViewById(R.id.tab_thumb);
    RelativeLayout.LayoutParams thumbLp = (RelativeLayout.LayoutParams) tab_thumb.getLayoutParams();
    thumbLp.width = 0;
    tab_thumb.requestLayout();

    // vp_main
    vp_main = (ViewPager) findViewById(R.id.vp_main);
    mainAdapter = new MainPagerAdapter(mContext);
    vp_main.setAdapter(mainAdapter);
    vp_main.setOnPageChangeListener(new PagerListener());

    // pop
    popView = findViewById(R.id.layout_pop);
    pop_background = findViewById(R.id.pop_background);
    pop_background.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            closePopView();
        }
    });
    pop_background.setVisibility(View.INVISIBLE);

    // image info
    btn_menu = (ImageView) findViewById(R.id.btn_menu);

    // txt
    txt_drawer_version_num = (TextView) findViewById(R.id.txt_drawer_version_num);
    txt_drawer_info_reply = (TextView) findViewById(R.id.txt_drawer_info_reply);
}

From source file:com.yibairun.ui.components.PagerSlidingTabStrip.java

private void addTextTab(final int position, String title) {
    //layout/*from   ww  w . ja v  a  2s .c o m*/
    RelativeLayout tabLayout = new RelativeLayout(getContext());
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    tabLayout.setLayoutParams(layoutParams);

    RelativeLayout.LayoutParams textParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    textParams.addRule(RelativeLayout.CENTER_IN_PARENT);
    //tab
    TextView tab = new TextView(getContext());
    tab.setId(100 + position);
    tab.setText(title);
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();
    tabLayout.addView(tab, textParams);

    //???
    RelativeLayout.LayoutParams viewParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    viewParams.addRule(RelativeLayout.RIGHT_OF, tab.getId());
    viewParams.addRule(RelativeLayout.CENTER_VERTICAL);
    View view = new View(getContext());
    ViewGroup.LayoutParams vParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    view.setLayoutParams(vParams);
    tabLayout.addView(view, viewParams);

    BadgeView badgeView = new BadgeView(getContext(), view);
    badgeView.setTextSize(10);
    badgeView.setGravity(Gravity.CENTER);
    badgeView.setBadgePosition(BadgeView.POSITION_TOP_LEFT);
    badgeView.setTag(BAGE_TAG);

    addTab(position, tabLayout);

}

From source file:com.cranberrygame.cordova.plugin.ad.admob.Util.java

private void _preloadBannerAd_overlap() {
    if (bannerViewLayout == null) {
        bannerViewLayout = new RelativeLayout(cordova.getActivity());//   
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
        //webView.addView(bannerViewLayout, params);
        bannerViewLayout.setLayoutParams(params);
        webView.addView(bannerViewLayout);
    }/* ww w .j  a v  a 2  s.  co  m*/

    if (bannerView != null) {
        //if banner is showing
        RelativeLayout bannerViewLayout = (RelativeLayout) bannerView.getParent();
        if (bannerViewLayout != null) {
            bannerViewLayout.removeView(bannerView);
            bannerView.destroy();
            bannerView = null;
        }
    }
}

From source file:org.ale.scanner.zotero.MainActivity.java

private void redrawPendingList() {
    /* Pretty terrible hack, Android doesn't like my ListView inside a
     * relative layout as a header in an expandable list view. Go figure.
     * It wasn't getting the height of said element correctly. */
    int count = mPendingAdapter.getCount();
    RelativeLayout r = ((RelativeLayout) findViewById(R.id.pending_item_holder));
    AbsListView.LayoutParams params = (AbsListView.LayoutParams) r.getLayoutParams();
    params.height = count * mPendingAdapter._hack_childSize;
    r.setLayoutParams(params);
}

From source file:com.eeshana.icstories.activities.UploadVideoActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // this will copy the license file and the demo video file.
    // to the videokit work folder location.
    // without the license file the library will not work.
    //copyLicenseAndDemoFilesFromAssetsToSDIfNeeded();
    setContentView(R.layout.upload_video_activity);

    height = SignInActivity.getScreenHeight(UploadVideoActivity.this);
    width = SignInActivity.getScreenWidth(UploadVideoActivity.this);
    mProgressDialog = new ProgressDialog(UploadVideoActivity.this);
    pDialog = new ProgressDialog(UploadVideoActivity.this);
    showCustomToast = new ShowCustomToast();
    connectionDetector = new ConnectionDetector(UploadVideoActivity.this);
    //      mProgressDialog=new ProgressDialog(UploadVideoActivity.this,AlertDialog.THEME_HOLO_LIGHT);
    //      mProgressDialog.setFeatureDrawableResource(height,R.drawable.rounded_toast);
    prefs = getSharedPreferences("PREF", MODE_PRIVATE);
    regId = prefs.getString("regid", "NA");
    SharedPreferences pref = getSharedPreferences("DB", 0);
    userid = pref.getString("userid", "1");
    SharedPreferences assign_prefs = getSharedPreferences("ASSIGN", 0);
    assignment_id = assign_prefs.getString("ASSIGN_ID", "");
    videoPath = getIntent().getStringExtra("VIDEOPATH");

    //      iCTextView=(TextView) findViewById(R.id.tvIC);
    //      iCTextView.setTypeface(CaptureVideoActivity.ic_typeface,Typeface.BOLD);
    //      storiesTextView=(TextView) findViewById(R.id.tvStories);
    //      storiesTextView.setTypeface(CaptureVideoActivity.stories_typeface,Typeface.BOLD);
    //      watsStoryTextView=(TextView) findViewById(R.id.tvWhatsStory);
    //      watsStoryTextView.setTypeface(CaptureVideoActivity.stories_typeface,Typeface.ITALIC);

    //      logoImageView=(ImageView) findViewById(R.id.ivLogo);
    //      RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams((int) (width/1.9), (int) (height/9.5));
    //      lp.addRule(RelativeLayout.CENTER_HORIZONTAL);
    //      lp.setMargins(0, 0, 0, 0);
    //      logoImageView.setLayoutParams(lp);

    uploadtTextView = (TextView) findViewById(R.id.tvUpload);
    uploadtTextView.setTypeface(CaptureVideoActivity.stories_typeface, Typeface.BOLD);
    //      extension=getIntent().getStringExtra("EXTENSION");
    //      folderPath = Environment.getExternalStorageDirectory().getPath()+"/ICStoriesFolder";
    //      if (!FileUtils.checkIfFolderExists(folderPath)) {
    //         boolean isFolderCreated = FileUtils.createFolder(folderPath);
    //         Log.i(Prefs.TAG, folderPath + " created? " + isFolderCreated);
    //         if (isFolderCreated) {
    ///* w ww  . j a va  2 s .  c  o m*/
    //         }
    //      }
    //command for rotating video 90 degree
    //String commandStr="ffmpeg -y -i "+videoPath+" -strict experimental -vf transpose=1 -s 160x120 -r 30 -aspect 4:3 -ab 48000 -ac 2 -ar 22050 -b 2097k "+folderPath+"/out."+extension;

    //Change Video Resolution:
    //String commandStr="ffmpeg -y -i "+videoPath+" -strict experimental -vf transpose=3 -s 320x240 -r 15 -aspect 3:4 -ab 12288 -vcodec mpeg4 -b 2097152 -sample_fmt s16 "+folderPath+"/res."+extension;

    //command for compressing video 
    //      String commandStr="ffmpeg -y -i "+videoPath+" -strict experimental -s 320x240 -r 15 -aspect 3:4 -ab 12288 -vcodec mpeg4 -b 2097152 -sample_fmt s16 "+folderPath+"/test."+extension;
    //      setCommand(commandStr);
    //      runTranscoing();

    thumb = ThumbnailUtils.createVideoThumbnail(videoPath, MediaStore.Images.Thumbnails.MINI_KIND);
    System.out.println("THUMB IMG  in uplaod== " + thumb);

    titleEditText = (EditText) findViewById(R.id.etTitle);
    titleEditText.setTypeface(CaptureVideoActivity.stories_typeface);
    descriptionEditText = (EditText) findViewById(R.id.etDescripton);
    descriptionEditText.setTypeface(CaptureVideoActivity.stories_typeface);
    locationEditText = (EditText) findViewById(R.id.etLocation);
    locationEditText.setTypeface(CaptureVideoActivity.stories_typeface);
    isAssignmentButton = (Button) findViewById(R.id.buttonCheck);
    isAssignmentButton.setTypeface(CaptureVideoActivity.stories_typeface);
    isAssignmentButton.setOnClickListener(this);
    dailyAssignTextView = (TextView) findViewById(R.id.tvDailyAssignment);
    dailyAssignTextView.setTypeface(CaptureVideoActivity.stories_typeface, Typeface.BOLD);
    uploadButton = (Button) findViewById(R.id.buttonUpload);
    uploadButton.setTypeface(CaptureVideoActivity.stories_typeface, Typeface.BOLD);
    RelativeLayout uploadRelativeLayout = (RelativeLayout) findViewById(R.id.rlUpload);
    RelativeLayout.LayoutParams lp9 = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, height / 17);
    lp9.addRule(RelativeLayout.BELOW, R.id.rlDailyAssignment);
    lp9.setMargins(width / 7, 30, width / 7, 0);
    uploadRelativeLayout.setLayoutParams(lp9);
    uploadButton.setOnClickListener(this);

    //bottom bar

    homeRelativeLayout = (RelativeLayout) findViewById(R.id.rlHome);
    homeRelativeLayout.setBackgroundResource(R.drawable.press_border);
    homeRelativeLayout.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
    homeTextView = (TextView) homeRelativeLayout.findViewById(R.id.tvHome);
    homeTextView.setTypeface(CaptureVideoActivity.stories_typeface, Typeface.BOLD);
    homeTextView.setTextColor(Color.parseColor("#fffffe"));
    RelativeLayout.LayoutParams lp4 = new RelativeLayout.LayoutParams(width / 3, width / 5);
    lp4.addRule(RelativeLayout.ALIGN_LEFT);
    homeRelativeLayout.setLayoutParams(lp4);
    homeRelativeLayout.setOnClickListener(this);

    wallRelativeLayout = (RelativeLayout) findViewById(R.id.rlWall);
    wallRelativeLayout.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
    wallTextView = (TextView) wallRelativeLayout.findViewById(R.id.tvWall);
    wallTextView.setTypeface(CaptureVideoActivity.stories_typeface, Typeface.BOLD);
    RelativeLayout.LayoutParams lp5 = new RelativeLayout.LayoutParams(width / 3, width / 5);
    lp5.addRule(RelativeLayout.RIGHT_OF, R.id.rlHome);
    wallRelativeLayout.setLayoutParams(lp5);
    wallRelativeLayout.setOnClickListener(this);

    settingsRelativeLayout = (RelativeLayout) findViewById(R.id.rlSettings);
    settingsRelativeLayout.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
    settingsTextView = (TextView) settingsRelativeLayout.findViewById(R.id.tvSettings);
    settingsTextView.setTypeface(CaptureVideoActivity.stories_typeface, Typeface.BOLD);
    RelativeLayout.LayoutParams lp6 = new RelativeLayout.LayoutParams(width / 3, width / 5);
    lp6.addRule(RelativeLayout.RIGHT_OF, R.id.rlWall);
    settingsRelativeLayout.setLayoutParams(lp6);
    settingsRelativeLayout.setOnClickListener(this);

    // current location
    locationDialog = new Dialog(UploadVideoActivity.this);
    locationDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
    locationDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    locationDialog.setContentView(R.layout.location_dialog);
    locationDialog.setCancelable(true);
    LinearLayout dialogLayout = (LinearLayout) locationDialog.findViewById(R.id.ll1);
    okButton = (Button) dialogLayout.findViewById(R.id.OkBtn);
    okButton.setOnClickListener(this);
    cancelButton = (Button) dialogLayout.findViewById(R.id.cancelBtn);
    cancelButton.setOnClickListener(this);

    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    boolean network_enabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
    if (network_enabled) {
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
    } else {
        showCustomToast.showToast(UploadVideoActivity.this,
                "Could not find current location. Please enable location services of your device.");
    }
    //      else if(gps_enabled == false){
    //         locationDialog.show();
    //      }
}

From source file:com.luseen.spacenavigation.SpaceNavigationView.java

/**
 * Adding given space items to content//  w ww . java  2s  .c  o m
 *
 * @param leftContent  to left content
 * @param rightContent and right content
 */
private void addSpaceItems(LinearLayout leftContent, LinearLayout rightContent) {

    /**
     * Removing all views for not being duplicated
     */
    if (leftContent.getChildCount() > 0 || rightContent.getChildCount() > 0) {
        leftContent.removeAllViews();
        rightContent.removeAllViews();
    }

    /**
     * Clear spaceItemList and badgeList for not being duplicated
     */
    spaceItemList.clear();
    badgeList.clear();

    /**
     * Getting LayoutInflater to inflate space item view from XML
     */
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    for (int i = 0; i < spaceItems.size(); i++) {
        final int index = i;
        int targetWidth;
        if (spaceItems.size() > 2)
            targetWidth = contentWidth / 2;
        else
            targetWidth = contentWidth;

        RelativeLayout.LayoutParams textAndIconContainerParams = new RelativeLayout.LayoutParams(targetWidth,
                mainContentHeight);
        RelativeLayout textAndIconContainer = (RelativeLayout) inflater.inflate(R.layout.space_item_view, this,
                false);
        textAndIconContainer.setLayoutParams(textAndIconContainerParams);

        ImageView spaceItemIcon = (ImageView) textAndIconContainer.findViewById(R.id.space_icon);
        TextView spaceItemText = (TextView) textAndIconContainer.findViewById(R.id.space_text);
        RelativeLayout badgeContainer = (RelativeLayout) textAndIconContainer
                .findViewById(R.id.badge_container);
        spaceItemIcon.setImageResource(spaceItems.get(i).getItemIcon());
        spaceItemText.setText(spaceItems.get(i).getItemName());
        spaceItemText.setTextSize(TypedValue.COMPLEX_UNIT_PX, spaceItemTextSize);

        /**
         * Set custom font to space item textView
         */
        if (isCustomFont)
            spaceItemText.setTypeface(customFont);

        /**
         * Hide item icon and show only text
         */
        if (textOnly)
            Utils.changeViewVisibilityGone(spaceItemIcon);

        /**
         * Hide item text and change icon size
         */
        ViewGroup.LayoutParams iconParams = spaceItemIcon.getLayoutParams();
        if (iconOnly) {
            iconParams.height = spaceItemIconOnlySize;
            iconParams.width = spaceItemIconOnlySize;
            spaceItemIcon.setLayoutParams(iconParams);
            Utils.changeViewVisibilityGone(spaceItemText);
        } else {
            iconParams.height = spaceItemIconSize;
            iconParams.width = spaceItemIconSize;
            spaceItemIcon.setLayoutParams(iconParams);
        }

        /**
         * Adding space items to item list for future
         */
        spaceItemList.add(textAndIconContainer);

        /**
         * Adding badge items to badge list for future
         */
        badgeList.add(badgeContainer);

        /**
         * Adding sub views to left and right sides
         */
        if (spaceItems.size() == 2 && leftContent.getChildCount() == 1) {
            rightContent.addView(textAndIconContainer, textAndIconContainerParams);
        } else if (spaceItems.size() > 2 && leftContent.getChildCount() == 2) {
            rightContent.addView(textAndIconContainer, textAndIconContainerParams);
        } else {
            leftContent.addView(textAndIconContainer, textAndIconContainerParams);
        }

        /**
         * Changing current selected item tint
         */
        if (i == currentSelectedItem) {
            spaceItemText.setTextColor(activeSpaceItemColor);
            Utils.changeImageViewTint(spaceItemIcon, activeSpaceItemColor);
        } else {
            spaceItemText.setTextColor(inActiveSpaceItemColor);
            Utils.changeImageViewTint(spaceItemIcon, inActiveSpaceItemColor);
        }

        textAndIconContainer.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                updateSpaceItems(index);
            }
        });
    }

    /**
     * Restore available badges from saveInstance
     */
    restoreBadges();
}

From source file:com.raspi.chatapp.ui.chatting.SendImageFragment.java

/**
 * this function will initialize the ui showing the current image and reload
 * everything to make sure it is shown correctly
 *///from w w  w.  j  a  v  a 2 s  .  co m
private void initUI() {
    // set the actionBar title and subtitle
    if (actionBar != null) {
        actionBar.setTitle(R.string.send_image);
        actionBar.setSubtitle(name);
        //      actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor
        //              (R.color.action_bar_transparent)));
        //      // set the statusBar color
        //      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        //        getActivity().getWindow().setStatusBarColor(getResources().getColor(R
        //                .color.action_bar_transparent));
    }

    // instantiate the ViewPager
    viewPager = (ViewPager) getActivity().findViewById(R.id.send_image_view_pager);
    viewPager.setAdapter(new MyPagerAdapter());
    viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
            changePage(position, false, false);
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });

    //Cancel button pressed
    getView().findViewById(R.id.send_image_cancel).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // just return to the chatFragment
            mListener.onReturnClick();
        }
    });
    //Send button pressed
    getView().findViewById(R.id.send_image_send).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // create the progressDialog that is to be shown while saving
            // the image
            ProgressDialog progressDialog = new ProgressDialog(getContext());
            if (images.size() > 1)
                progressDialog.setTitle(
                        String.format(getResources().getString(R.string.sending_images), images.size()));
            else
                progressDialog.setTitle(R.string.sending_image);
            // run the sendImage in a new thread because I am saving the
            // image and this should be done in a new thread
            new Thread(new SendImagesRunnable(new Handler(), getContext(), progressDialog)).start();
        }
    });

    // generate the overview only if there are at least 2 images
    if (images.size() > 1) {
        // the layoutParams for the imageView which has the following attributes:
        // width = height = 65dp
        // margin = 5dp
        getActivity().findViewById(R.id.send_image_overview).setVisibility(View.VISIBLE);
        int a = Constants.dipToPixel(getContext(), 65);
        RelativeLayout.LayoutParams imageViewParams = new RelativeLayout.LayoutParams(a, a);
        int b = Constants.dipToPixel(getContext(), 5);
        imageViewParams.setMargins(b, b, b, b);
        // the layoutParams for the backgroundView which has the following
        // attributes:
        // width = height = 71dp
        // margin = 2dp
        int c = Constants.dipToPixel(getContext(), 71);
        RelativeLayout.LayoutParams backgroundParams = new RelativeLayout.LayoutParams(c, c);
        int d = Constants.dipToPixel(getContext(), 2);
        backgroundParams.setMargins(d, d, d, d);
        // the layoutParams for the relativeLayout containing the image and
        // the background which has the following attributes:
        // width = height = wrap_content
        LinearLayout.LayoutParams relativeLayoutParams = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        LinearLayout linearLayout = (LinearLayout) getActivity().findViewById(R.id.send_image_overview_content);
        linearLayout.removeAllViewsInLayout();
        int i = 0;
        for (Message msg : images) {
            // set up the imageView
            ImageView imageView = new ImageView(getContext());
            imageView.setLayoutParams(imageViewParams);
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            // load the bitmap async
            AsyncDrawable.BitmapWorkerTask bitmapWorker = new AsyncDrawable.BitmapWorkerTask(imageView, a, a,
                    true);
            imageView.setImageDrawable(new AsyncDrawable(getResources(), null, bitmapWorker));
            imageView.setOnClickListener(new overviewSelectListener(i++));
            bitmapWorker.execute(FileUtils.getFile(getContext(), msg.getImageUri()));
            // set up the background
            View background = new View(getContext());
            background.setLayoutParams(backgroundParams);
            background.setBackgroundColor(getActivity().getResources().getColor(R.color.colorPrimaryDark));
            // make it invisible in the beginning
            background.setVisibility(View.GONE);

            // create the relativeLayout containing them
            RelativeLayout relativeLayout = new RelativeLayout(getContext());
            relativeLayout.setLayoutParams(relativeLayoutParams);
            relativeLayout.addView(background);
            relativeLayout.addView(imageView);
            // combination of Message and overviewViews
            msg.setLayout(relativeLayout);
            msg.setBackground(background);
            linearLayout.addView(relativeLayout);
        }
    } else
        getActivity().findViewById(R.id.send_image_overview).setVisibility(View.GONE);
    changePage(current, true, true);
    showSystemUI();
}

From source file:com.amazon.android.tv.tenfoot.ui.fragments.ContentSearchFragment.java

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

    final View view = super.onCreateView(inflater, container, savedInstanceState);

    if (view != null) {
        // Set background color and drawable.
        view.setBackgroundColor(ContextCompat.getColor(getActivity(), android.R.color.transparent));
        view.setBackground(ContextCompat.getDrawable(getActivity(), R.drawable.search_background));

        final SearchBar searchBar = (SearchBar) view.findViewById(R.id.lb_search_bar);
        if (searchBar != null) {

            // Set the left margin of the search bar.
            ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) searchBar
                    .getLayoutParams();/*w  w w. j av  a2 s.  co m*/

            layoutParams.setMarginStart((int) getResources().getDimension(R.dimen.search_bar_margin_left));

            searchBar.setLayoutParams(layoutParams);

            // Move the search bar items next to the search icon.
            RelativeLayout searchBarItems = (RelativeLayout) searchBar.findViewById(R.id.lb_search_bar_items);

            if (searchBarItems != null) {

                RelativeLayout.LayoutParams searchBarItemsLayoutParams = (RelativeLayout.LayoutParams) searchBarItems
                        .getLayoutParams();

                searchBarItemsLayoutParams.setMarginStart(
                        (int) getResources().getDimension(R.dimen.search_bar_items_margin_left));

                searchBarItems.setLayoutParams(searchBarItemsLayoutParams);

                // Set the search bar items background selector.
                searchBarItems.setBackground(ContextCompat.getDrawable(getActivity(),
                        R.drawable.search_edit_text_bg_color_selector));
            }

            // Set speech orb icon.
            mSpeechOrbView = (SpeechOrbView) searchBar.findViewById(R.id.lb_search_bar_speech_orb);

            if (mSpeechOrbView != null) {
                mSpeechOrbView.setOrbIcon(ContextCompat.getDrawable(getActivity(), R.drawable.search_icon));
            }

            final SearchEditText searchEditText = (SearchEditText) searchBar
                    .findViewById(R.id.lb_search_text_editor);

            if (searchEditText != null) {

                mSearchEditText = searchEditText;

                // Handle keyboard being dismissed to prevent focus going to SearchOrb
                // If user presses back from keyboard, you don't get KeyboardDismissListener
                // so handle that here.
                searchEditText.setOnEditorActionListener((textView, actionId, keyEvent) -> {

                    // Track search if keyboard is closed with IME_ACTION_PREVIOUS or
                    // if IME_ACTION_SEARCH occurs.
                    if (actionId == EditorInfo.IME_ACTION_SEARCH
                            || actionId == EditorInfo.IME_ACTION_PREVIOUS) {

                        if (mQuery != null) {
                            AnalyticsHelper.trackSearchQuery(mQuery);
                        }
                    }

                    if (actionId == EditorInfo.IME_ACTION_PREVIOUS) {

                        // Prevent highlighting SearchOrb
                        mSpeechOrbView.setFocusable(false);
                        mSpeechOrbView.clearFocus();
                        // If there are results allow first result to be selected
                        if (mHasResults) {
                            mSearchEditText.clearFocus();
                        }

                        // Hide keyboard since we are handling the action
                        if (isAdded()) {
                            // Ensure we are added before calling getActivity
                            InputMethodManager inputManager = (InputMethodManager) getActivity()
                                    .getSystemService(Context.INPUT_METHOD_SERVICE);
                            if (inputManager != null) {
                                inputManager.hideSoftInputFromWindow(
                                        getActivity().getCurrentFocus().getWindowToken(),
                                        InputMethodManager.HIDE_NOT_ALWAYS);
                            }
                        } else {
                            Log.e(TAG, "Cannot find activity, can't dismiss keyboard");
                            // Couldn't handle action.
                            // Will expose other focus issues potentially.
                            return false;
                        }
                        // No more processing of this action.
                        return true;
                    }
                    // Someone else needs to handle this action.
                    return false;
                });

                // Override the dismiss listener to get around keyboard issue where dismissing
                // keyboard takes user into first search result's
                // content_details_activity_layout page.
                searchEditText.setOnKeyboardDismissListener(() -> {
                    // If search returns results, focus on the first item in the result list.
                    // If search doesn't have results, this will focus on searchEditText again.
                    mSpeechOrbView.setFocusable(false);
                    mSpeechOrbView.clearFocus();
                    // We don't need to clearFocus on SearchEditText here, the first
                    // result will be selected already.
                });
            }
        }
    }
    return view;
}