Example usage for android.view Gravity CENTER

List of usage examples for android.view Gravity CENTER

Introduction

In this page you can find the example usage for android.view Gravity CENTER.

Prototype

int CENTER

To view the source code for android.view Gravity CENTER.

Click Source Link

Document

Place the object in the center of its container in both the vertical and horizontal axis, not changing its size.

Usage

From source file:com.astuetz.PagerSlidingTabStripPlus.java

private void addTab(final int position, View tab) {
    tab.setFocusable(true);//from   www  .java 2 s.c  o m
    tab.setPadding(tabPaddingLeft, tabPaddingTop, tabPaddingRight, tabPaddingBottom);
    LinearLayout tabLayout = new LinearLayout(getContext());
    tabLayout.setOrientation(LinearLayout.VERTICAL);
    tabLayout.setGravity(Gravity.CENTER);
    tabLayout.addView(tab, 0, defaultTabLayoutParams);
    tabLayout.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            pager.setCurrentItem(position);
        }
    });
    tabsContainer.addView(tabLayout, position, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams);
}

From source file:com.ab.view.sliding.AbSlidingTabView2.java

/**
 * /*  w  ww .j a  v a 2s .  com*/
 * ??tab
 * @throws 
 */
public void addItemView(String tabText, Fragment fragment) {

    tabItemTextList.add(tabText);
    pagerItemList.add(fragment);

    tabItemList.clear();
    mTabLayout.removeAllViews();

    for (int i = 0; i < tabItemTextList.size(); i++) {
        final int index = i;
        String text = tabItemTextList.get(i);
        TextView tv = new TextView(this.context);
        tv.setTextColor(tabColor);
        tv.setTextSize(tabTextSize);
        tv.setText(text);
        tv.setGravity(Gravity.CENTER);
        tv.setLayoutParams(new LayoutParams(0, LayoutParams.FILL_PARENT, 1));
        tv.setPadding(12, 5, 12, 5);
        tv.setFocusable(false);
        tabItemList.add(tv);
        mTabLayout.addView(tv);
        tv.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                mViewPager.setCurrentItem(index);
            }
        });
    }

    //?
    Log.d(TAG, "addItemView finish");
    mFragmentPagerAdapter.notifyDataSetChanged();
    mViewPager.setCurrentItem(0);
    computeTabImg(0);
}

From source file:fr.univsavoie.ltp.client.map.Popup.java

public final void popupGetStatus(JSONArray pStatusesArray) {
    DisplayMetrics dm = new DisplayMetrics();
    this.activity.getWindowManager().getDefaultDisplay().getMetrics(dm);

    //final int height = dm.heightPixels;
    final int width = dm.widthPixels;
    final int height = dm.heightPixels;

    int popupWidth = (int) (width * 0.75);
    int popupHeight = height;

    // Inflate the popup_layout.xml
    ScrollView viewGroup = (ScrollView) this.activity.findViewById(R.id.popupGetStatus);
    LayoutInflater layoutInflater = (LayoutInflater) this.activity
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    final View layout = layoutInflater.inflate(R.layout.popup_get_status, viewGroup);
    layout.setBackgroundResource(R.drawable.popup_gradient);

    // Crer le PopupWindow
    final PopupWindow popupPublishStatus = new PopupWindow(layout, popupWidth, LayoutParams.WRAP_CONTENT, true);
    popupPublishStatus.setBackgroundDrawable(new BitmapDrawable());
    popupPublishStatus.setOutsideTouchable(true);

    // Some offset to align the popup a bit to the right, and a bit down, relative to button's position.
    final int OFFSET_X = 0;
    final int OFFSET_Y = 0;

    // Displaying the popup at the specified location, + offsets.
    this.activity.findViewById(R.id.layoutMain).post(new Runnable() {
        public void run() {
            popupPublishStatus.showAtLocation(layout, Gravity.CENTER, OFFSET_X, OFFSET_Y);
        }// ww  w .j av a2s . co  m
    });

    /*
     * Evenements composants du PopupWindow
     */

    // Find the ListView resource. 
    ListView mainListView = (ListView) layout.findViewById(R.id.listViewStatus);

    ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();

    SimpleAdapter adapter = new SimpleAdapter(this.activity, list, R.layout.custom_row_view,
            new String[] { "content", "lat", "lon" }, new int[] { R.id.text1, R.id.text2, R.id.text3 });

    try {
        // Appel REST pour recuperer les status de l'utilisateur connect
        //Session session = new Session(this.activity);
        //session.parseJSONUrl("https://jibiki.univ-savoie.fr/ltpdev/rest.php/api/1/statuses", "STATUSES", "GET");

        // Parser la liste des amis dans le OverlayItem ArrayList
        HashMap<String, String> temp;
        for (int i = 0; (i < 6); i++) {
            // Obtenir le status
            JSONObject status = pStatusesArray.getJSONObject(i);

            temp = new HashMap<String, String>();
            temp.put("content", status.getString("content"));
            temp.put("lat", String.valueOf(status.getDouble("lat")));
            temp.put("lon", String.valueOf(status.getDouble("lon")));
            list.add(temp);
        }
    } catch (JSONException jex) {
        Log.e("Catch", "popupGetStatus / JSONException : " + jex.getStackTrace());
    } catch (Exception ex) {
        Log.e("Catch", "popupGetStatus / Exception : " + ex.getLocalizedMessage());
    }

    mainListView.setAdapter(adapter);
}

From source file:com.zia.freshdocs.widget.adapter.CMISAdapter.java

/**
 * Display file information//  w w w .ja  v  a 2s  .  co m
 * 
 * @param context
 */

public void showFileInfo(Context context, int position, boolean isFile) {

    final NodeRef ref = getItem(position);
    try {
        //We need to get the instance of the LayoutInflater, use the context of this activity
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        //Inflate the view from a predefined XML layout
        View layout = inflater.inflate(R.layout.file_info_dialog, null, false);
        // create a WRAP_CONTENT PopupWindow
        PopupWindow mPopUp = new PopupWindow(layout, WindowManager.LayoutParams.FILL_PARENT,
                WindowManager.LayoutParams.WRAP_CONTENT, true);
        mPopUp.setBackgroundDrawable(new BitmapDrawable());
        mPopUp.setOutsideTouchable(true);
        // display the popup in the center
        mPopUp.showAtLocation(layout, Gravity.CENTER, 0, 0);

        TextView title = (TextView) layout.findViewById(R.id.dialog_title);
        if (isFile)
            title.setText(context.getString(R.string.str_file_information));
        else
            title.setText(context.getString(R.string.str_folder_information));

        UITableView tableView = (UITableView) layout.findViewById(R.id.tableView);

        ViewItem viewItem;

        if (ref.getName() != null) {
            viewItem = Utils.createCustomView(context, context.getString(R.string.str_name), ref.getName());
            tableView.addViewItem(viewItem);
        }
        if (ref.getCreateBy() != null) {
            viewItem = Utils.createCustomView(context, context.getString(R.string.str_created_by),
                    ref.getCreateBy());
            tableView.addViewItem(viewItem);
        }

        if (ref.getLastModificationDate() != null) {
            viewItem = Utils.createCustomView(context, context.getString(R.string.str_last_modification_date),
                    ref.getLastModificationDate());
            tableView.addViewItem(viewItem);
        }

        if (ref.getLastModifiedBy() != null) {
            viewItem = Utils.createCustomView(context, context.getString(R.string.str_last_modified_by),
                    ref.getLastModifiedBy());
            tableView.addViewItem(viewItem);
        }

        if (ref.getContent() != null) {
            viewItem = Utils.createCustomView(context, context.getString(R.string.str_content),
                    ref.getContent());
            tableView.addViewItem(viewItem);
        }

        if (ref.getContentType() != null) {
            viewItem = Utils.createCustomView(context, context.getString(R.string.str_content_type),
                    ref.getContentType());
            tableView.addViewItem(viewItem);
        }

        if (ref.getObjectId() != null) {
            viewItem = Utils.createCustomView(context, context.getString(R.string.str_object_id),
                    ref.getObjectId());
            tableView.addViewItem(viewItem);
        }

        if (ref.getParentId() != null) {
            viewItem = Utils.createCustomView(context, context.getString(R.string.str_parent_id),
                    ref.getParentId());
            tableView.addViewItem(viewItem);
        }

        if (ref.getVersion() != null) {
            viewItem = Utils.createCustomView(context, context.getString(R.string.str_version),
                    ref.getVersion());
            tableView.addViewItem(viewItem);
        }

        tableView.commit();

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.jaspersoft.android.jaspermobile.activities.profile.ServerProfileActivity.java

@UiThread
protected void checkUniqueConstraintFulfilled(Cursor cursor) {
    boolean entryExists = cursor.getCount() > 0;
    getSupportLoaderManager().destroyLoader(QUERY_UNIQUENESS);

    if (entryExists) {
        aliasEdit.setError(getString(R.string.sp_error_duplicate_alias));
        aliasEdit.requestFocus();// www  .  j a v a2 s .  c  o  m

        Toast toast = Toast.makeText(this, getString(R.string.sp_error_unique_alias, alias),
                Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.TOP | Gravity.CENTER, 0, mActionBarSize + (mActionBarSize / 2));
        toast.show();
    } else {
        JsServerProfile oldProfile = jsRestClient.getServerProfile();
        if (oldProfile != null && oldProfile.getId() == profileId) {
            updateServerProfile(oldProfile);
        } else {
            persistProfileData();
            setOkResult();
            finish();
        }

        hideKeyboard();
    }
}

From source file:com.cssweb.android.quote.QuoteDetail.java

/**
 * ???//from  www . ja  va2s.com
 */
private void initLoading() {
    LinearLayout layout = new LinearLayout(this);
    layout.setOrientation(LinearLayout.HORIZONTAL);
    ProgressBar progressBar = new ProgressBar(this);
    progressBar.setPadding(0, 0, 15, 0);
    LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    LayoutParams layoutParams2 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
            LinearLayout.LayoutParams.FILL_PARENT);
    layout.addView(progressBar, layoutParams);
    TextView textView = new TextView(this);
    textView.setText(getResources().getText(R.string.cjmx_loading));
    textView.setGravity(Gravity.CENTER_VERTICAL);
    layout.addView(textView, layoutParams2);
    layout.setGravity(Gravity.CENTER);
    loadingLayout = new LinearLayout(this);
    loadingLayout.addView(layout, layoutParams);
    loadingLayout.setGravity(Gravity.CENTER);
    table_1.addView(loadingLayout, 0);
}

From source file:biz.incomsystems.fwknop2.ConfigDetailFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) { // This handles the qrcode results
    if (requestCode == 0) {
        if (resultCode == Activity.RESULT_OK) {
            String contents = data.getStringExtra("SCAN_RESULT");
            for (String stanzas : contents.split(" ")) {
                String[] tmp = stanzas.split(":");
                if (tmp[0].equalsIgnoreCase("KEY_BASE64")) {
                    txt_KEY.setText(tmp[1]);
                    chkb64key.setChecked(true);
                } else if (tmp[0].equalsIgnoreCase("KEY")) {
                    txt_KEY.setText(tmp[1]);
                    chkb64key.setChecked(false);
                } else if (tmp[0].equalsIgnoreCase("HMAC_KEY_BASE64")) {
                    txt_HMAC.setText(tmp[1]);
                    chkb64hmac.setChecked(true);
                } else if (tmp[0].equalsIgnoreCase("HMAC_KEY")) {
                    txt_HMAC.setText(tmp[1]);
                    chkb64hmac.setChecked(false);
                }//from  ww w  .j a  v  a2s . co m
            } // end for loop
        }
        if (resultCode == Activity.RESULT_CANCELED) {
            //handle cancel
            Context context = getActivity();
            CharSequence text = " QR Code Canceled";
            int duration = Toast.LENGTH_LONG;
            Toast toast = Toast.makeText(context, text, duration);
            toast.setGravity(Gravity.CENTER, 0, 0);
            LinearLayout toastLayout = (LinearLayout) toast.getView();
            TextView toastTV = (TextView) toastLayout.getChildAt(0);
            toastTV.setTextSize(30);
            toast.show();
        }
    }
}

From source file:tm.veriloft.mapsplayground.MapsActivity.java

public void showCenteredToast(String string) {
    if (string == null || string.equals(""))
        string = "null";
    Toast toast = Toast.makeText(this.getApplicationContext(), string, Toast.LENGTH_LONG);
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.show();// ww w .  j a  va2 s.  com
}

From source file:com.bangqu.eshow.view.sliding.ESSlidingSmoothTabView.java

/**
 * ??tab.//from  w  w  w .j  a  v  a  2 s .c o  m
 *
 * @param tabText the tab text
 * @param fragment the fragment
 */
public void addItemView(String tabText, Fragment fragment) {

    tabItemTextList.add(tabText);
    pagerItemList.add(fragment);

    tabItemList.clear();
    mTabLayout.removeAllViews();

    for (int i = 0; i < tabItemTextList.size(); i++) {
        final int index = i;
        String text = tabItemTextList.get(i);
        TextView tv = new TextView(this.context);
        tv.setTextColor(tabColor);
        tv.setTextSize(tabTextSize);
        tv.setText(text);
        tv.setGravity(Gravity.CENTER);
        tv.setLayoutParams(new LayoutParams(0, LayoutParams.FILL_PARENT, 1));
        tv.setPadding(12, 5, 12, 5);
        tv.setFocusable(false);
        tabItemList.add(tv);
        mTabLayout.addView(tv);
        tv.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                mViewPager.setCurrentItem(index);
            }
        });
    }

    //?
    ESLogUtil.d(ESSlidingSmoothTabView.class, "addItemView finish");
    mFragmentPagerAdapter.notifyDataSetChanged();
    mViewPager.setCurrentItem(0);
    computeTabImg(0);
}

From source file:cn.org.eshow.framwork.view.sliding.AbSlidingSmoothTabView.java

/**
 * ??tab.//  w ww . j a va  2 s  . c o  m
 *
 * @param tabText the tab text
 * @param fragment the fragment
 */
public void addItemView(String tabText, Fragment fragment) {

    tabItemTextList.add(tabText);
    pagerItemList.add(fragment);

    tabItemList.clear();
    mTabLayout.removeAllViews();

    for (int i = 0; i < tabItemTextList.size(); i++) {
        final int index = i;
        String text = tabItemTextList.get(i);
        TextView tv = new TextView(this.context);
        tv.setTextColor(tabColor);
        tv.setTextSize(tabTextSize);
        tv.setText(text);
        tv.setGravity(Gravity.CENTER);
        tv.setLayoutParams(new LayoutParams(0, LayoutParams.FILL_PARENT, 1));
        tv.setPadding(12, 5, 12, 5);
        tv.setFocusable(false);
        tabItemList.add(tv);
        mTabLayout.addView(tv);
        tv.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                mViewPager.setCurrentItem(index);
            }
        });
    }

    //?
    AbLogUtil.d(AbSlidingSmoothTabView.class, "addItemView finish");
    mFragmentPagerAdapter.notifyDataSetChanged();
    mViewPager.setCurrentItem(0);
    computeTabImg(0);
}