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:net.mypapit.mobile.myrepeater.DisplayMap.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_display_map);
    overridePendingTransition(R.anim.activity_open_translate, R.anim.activity_close_scale);

    hashMap = new HashMap<Marker, MapInfoObject>();

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
        getActionBar().setDisplayHomeAsUpEnabled(true);
    }//  w w  w. jav  a  2  s. co  m

    map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

    if (map == null) {

        // Log.e("Map NULL", "MAP NULL");
        Toast.makeText(this, "Unable to display Map", Toast.LENGTH_SHORT).show();

    } else {

        LatLng latlng = (LatLng) getIntent().getExtras().get("LatLong");

        Repeater xlocation = new Repeater("", new Double[] { latlng.latitude, latlng.longitude });

        rl = RepeaterListActivity.loadData(R.raw.repeaterdata5, this);
        xlocation.calcDistanceAll(rl);
        rl.sort();

        map.setMyLocationEnabled(true);
        map.setOnInfoWindowClickListener(this);
        map.getUiSettings().setZoomControlsEnabled(true);

        AdView mAdView = (AdView) findViewById(R.id.adViewMap);
        mAdView.loadAd(new AdRequest.Builder().build());

        // counter i, for mapping marker with integer
        int i = 0;

        for (Repeater repeater : rl) {

            MarkerOptions marking = new MarkerOptions();
            marking.position(new LatLng(repeater.getLatitude(), repeater.getLongitude()));
            marking.title(repeater.getCallsign() + " - " + repeater.getDownlink() + "MHz (" + repeater.getClub()
                    + ")");

            marking.snippet("Tone: " + repeater.getTone() + " Shift: " + repeater.getShift());

            RepeaterMapInfo rmi = new RepeaterMapInfo(repeater);
            rmi.setIndex(i);

            hashMap.put(map.addMarker(marking), rmi);

            i++;

        }

        // Marker RKG = map.addMarker(new MarkerOptions().position(new
        // LatLng(6.1,100.3)).title("9M4RKG"));

        map.moveCamera(CameraUpdateFactory.newLatLngZoom(latlng, 10));
        map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);

        cache = this.getSharedPreferences(CACHE_PREFS, 0);

        Date cachedate = new Date(cache.getLong(CACHE_TIME, new Date(20000).getTime()));

        long secs = (new Date().getTime() - cachedate.getTime()) / 1000;
        long hours = secs / 3600L;
        secs = secs % 3600L;
        long mins = secs / 60L;

        if (mins < 5) {
            String jsoncache = cache.getString(CACHE_JSON, "none");
            if (jsoncache.compareToIgnoreCase("none") == 0) {
                new GetUserInfo(latlng, this).execute();

            } else {

                loadfromCache(jsoncache);
                // Toast.makeText(this, "Loaded from cache: " + mins +
                // " mins", Toast.LENGTH_SHORT).show();
            }

        } else {

            new GetUserInfo(latlng, this).execute();

        }

        map.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {

            @Override
            public View getInfoWindow(Marker marker) {
                // TODO Auto-generated method stub
                return null;
            }

            @Override
            public View getInfoContents(Marker marker) {
                Context context = getApplicationContext(); // or
                // getActivity(),
                // YourActivity.this,
                // etc.

                LinearLayout info = new LinearLayout(context);
                info.setOrientation(LinearLayout.VERTICAL);

                TextView title = new TextView(context);
                title.setTextColor(Color.BLACK);
                title.setGravity(Gravity.CENTER);
                title.setTypeface(null, Typeface.BOLD);
                title.setText(marker.getTitle());

                TextView snippet = new TextView(context);
                snippet.setTextColor(Color.GRAY);
                snippet.setText(marker.getSnippet());

                info.addView(title);
                info.addView(snippet);

                return info;
            }
        });

    }

}

From source file:cc.echonet.coolmicapp.MainActivity.java

private void goAbout() {

    Log.d("MainActivity", "goAbout() ");

    LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View popUpView = inflater.inflate(R.layout.popup_about, null, false);

    final PopupWindow popUp = new PopupWindow(this);

    Button close = (Button) popUpView.findViewById(R.id.cmdPopUpDismiss);
    close.setOnClickListener(new View.OnClickListener() {
        public void onClick(View popupView) {
            popUp.dismiss();//from   w  w w.j a va2s  .c om
        }
    });

    ((TextView) popUpView.findViewById(R.id.txtVersion)).setText(BuildConfig.VERSION_NAME);
    ((TextView) popUpView.findViewById(R.id.txtBuildType)).setText(BuildConfig.BUILD_TYPE);
    ((TextView) popUpView.findViewById(R.id.txtGITBranch)).setText(BuildConfig.GIT_BRANCH);
    ((TextView) popUpView.findViewById(R.id.txtGITRevision)).setText(BuildConfig.GIT_REVISION);
    ((TextView) popUpView.findViewById(R.id.txtGITAuthor)).setText(BuildConfig.GIT_AUTHOR);
    ((TextView) popUpView.findViewById(R.id.txtGITDirty)).setText(BuildConfig.GIT_DIRTY);

    popUpView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);

    popUp.setContentView(popUpView);

    Log.d("MainActivity", String.format("h: %s w: %s h: %s w: %s", popUp.getHeight(), popUp.getWidth(),
            popUpView.getMeasuredHeight(), popUpView.getMeasuredWidth()));

    popUp.setHeight(popUpView.getMeasuredHeight());
    popUp.setWidth(popUpView.getMeasuredWidth());

    popUp.showAtLocation(popUpView, Gravity.CENTER, 0, 0);

    Log.d("MainActivity", "goAbout() end ");
}

From source file:com.axolotl.yanews.customize.SlidingTabLayout.java

/**
 * tabview. tab view/*from w  w w . jav a  2s .  c o m*/
 * {@link #setCustomTabView(int, int)}.
 */
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context, null, 0);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, mTab_text_size_sp);
    if (mBold) {
        textView.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
    } else {
        textView.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
    }
    if (mChangeTextColor) {
        textView.setTextColor(mNormalColor);
    }
    textView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.MATCH_PARENT));

    if (mBackgroundResource != 0) {
        textView.setBackgroundResource(mBackgroundResource);
    } else {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            // If we're running on Honeycomb or newer, then we can use the Theme's
            // selectableItemBackground to ensure that the View has a pressed state
            TypedValue outValue = new TypedValue();
            getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
            textView.setBackgroundResource(outValue.resourceId);
        }
    }

    //wtf
    //        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
    //            // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
    //            textView.setAllCaps(true);
    //        }

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, 0, padding, 0);
    return textView;
}

From source file:android.support.v7.internal.widget.SpinnerCompat.java

/**
 * Construct a new spinner with the given context's theme, the supplied attribute set, and
 * default style. <code>mode</code> may be one of {@link #MODE_DIALOG} or {@link #MODE_DROPDOWN}
 * and determines how the user will select choices from the spinner.
 *
 * @param context  The Context the view is running in, through which it can access the current
 *                 theme, resources, etc.
 * @param attrs    The attributes of the XML tag that is inflating the view.
 * @param defStyle The default style to apply to this view. If 0, no style will be applied
 *                 (beyond what is included in the theme). This may either be an attribute
 *                 resource, whose value will be retrieved from the current theme, or an
 *                 explicit style resource.
 * @param mode     Constant describing how the user will select choices from the spinner.
 * @see #MODE_DIALOG/*from   w  w  w.  j  av  a  2 s .c  om*/
 * @see #MODE_DROPDOWN
 */
SpinnerCompat(Context context, AttributeSet attrs, int defStyle, int mode) {
    super(context, attrs, defStyle);

    TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs, R.styleable.Spinner, defStyle, 0);

    // Need to reset this for tinting purposes
    if (a.hasValue(R.styleable.Spinner_android_background)) {
        setBackgroundDrawable(a.getDrawable(R.styleable.Spinner_android_background));
    }

    if (mode == MODE_THEME) {
        mode = a.getInt(R.styleable.Spinner_spinnerMode, MODE_DIALOG);
    }

    switch (mode) {
    case MODE_DIALOG: {
        mPopup = new DialogPopup();
        break;
    }

    case MODE_DROPDOWN: {
        final DropdownPopup popup = new DropdownPopup(context, attrs, defStyle);

        mDropDownWidth = a.getLayoutDimension(R.styleable.Spinner_android_dropDownWidth,
                ViewGroup.LayoutParams.WRAP_CONTENT);

        popup.setBackgroundDrawable(a.getDrawable(R.styleable.Spinner_android_popupBackground));

        mPopup = popup;
        mForwardingListener = new ListPopupWindow.ForwardingListener(this) {
            @Override
            public ListPopupWindow getPopup() {
                return popup;
            }

            @Override
            public boolean onForwardingStarted() {
                if (!mPopup.isShowing()) {
                    mPopup.show();
                }
                return true;
            }
        };
        break;
    }
    }

    mGravity = a.getInt(R.styleable.Spinner_android_gravity, Gravity.CENTER);

    mPopup.setPromptText(a.getString(R.styleable.Spinner_prompt));

    mDisableChildrenWhenDisabled = a.getBoolean(R.styleable.Spinner_disableChildrenWhenDisabled, false);

    a.recycle();

    // Base constructor can call setAdapter before we initialize mPopup.
    // Finish setting things up if this happened.
    if (mTempAdapter != null) {
        mPopup.setAdapter(mTempAdapter);
        mTempAdapter = null;
    }

    // Keep the TintManager in case we need it later
    mTintManager = a.getTintManager();
}

From source file:cn.bingoogol.tabhost.ui.view.PagerSlidingTabStrip.java

private void addTextTab(final int position, String title) {
    TextView tab = new TextView(getContext());
    tab.setText(title);//  w  w  w  .j a v a  2 s  . c om
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();
    addTab(position, tab);
}

From source file:com.radicaldynamic.groupinform.application.Collect.java

public void showCustomToast(String message) {
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View view = inflater.inflate(R.layout.toast_view, null);

    // Set the text in the view
    TextView tv = (TextView) view.findViewById(R.id.message);
    tv.setText(message);//from w w  w. j  a  va  2  s. c  om

    Toast t = new Toast(this);
    t.setView(view);
    t.setDuration(Toast.LENGTH_SHORT);
    t.setGravity(Gravity.CENTER, 0, 0);
    t.show();
}

From source file:edgargtzg.popularmovies.MovieDetailsFragment.java

/**
 * Updates the content of the view based on the movie data.
 *
 * @param movieItem the current movie item.
 */// ww w.ja v a  2  s .  co  m
private void updateMovieData(MovieItem movieItem) {

    if (isNetworkAvailable()) {
        FetchMovieVideosTask fetchMovieVideosTask = new FetchMovieVideosTask(movieItem);
        fetchMovieVideosTask.execute();
        FetchMovieReviewsTask fetchMovieReviewsTask = new FetchMovieReviewsTask(movieItem);
        fetchMovieReviewsTask.execute();
    } else {
        Toast toast = Toast.makeText(getActivity(), R.string.error_msg_no_network, Toast.LENGTH_LONG);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
    }
}

From source file:ar.com.xpasta.Controls.PagerSlidingTabStrip.java

private void addTextTab(final int position, String title) {
    TextView tab = new TextView(getContext());
    tab.setText(title);//from   w  w  w.  j a  v a 2  s. c  o m
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();

    addTab(position, tab);
}

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

/**
 * ??tab.// w  ww  .  jav  a  2  s.  c o  m
 *
 * @param tabTexts the tab texts
 * @param fragments the fragments
 */
public void addItemViews(List<String> tabTexts, List<Fragment> fragments) {

    tabItemTextList.addAll(tabTexts);
    pagerItemList.addAll(fragments);

    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);
            }
        });
    }

    //?
    mFragmentPagerAdapter.notifyDataSetChanged();
    mViewPager.setCurrentItem(0);
    computeTabImg(0);

}

From source file:com.brodev.socialapp.view.PhotoGridActivity.java

/** Called when the activity is first created. */
@Override/*from  ww w.jav a 2 s  .c  om*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_ptr_grid);

    album_id = null;
    album_user_id = null;
    countImage = 1;
    page_id = null;
    module_id = null;
    group_id = null;
    page = 1;

    mPullRefreshGridView = (PullToRefreshGridView) findViewById(R.id.pull_refresh_grid);
    mGridView = mPullRefreshGridView.getRefreshableView();

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    phraseManager = new PhraseManager(getApplicationContext());
    loading = (ProgressBar) findViewById(R.id.content_loading);

    Bundle bundle = getIntent().getExtras();
    if (bundle != null) {
        if (this.getIntent().hasExtra("album_name")) {
            if (this.getIntent().hasExtra("total_photo")) {
                getSupportActionBar()
                        .setTitle(bundle.getString("album_name") + "(" + bundle.getString("total_photo") + ")");
            } else {
                getSupportActionBar().setTitle(bundle.getString("album_name"));
            }
        }

        if (this.getIntent().hasExtra("user_id")) {
            user_id = bundle.getString("user_id");
            new ShowGridPhoto().execute(user_id, null);

        } else if (this.getIntent().hasExtra("album_user_id")) {
            album_user_id = bundle.getString("album_user_id");
            album_id = bundle.getString("album_id");
            new ShowGridPhoto().execute(album_user_id, album_id);

        } else if (this.getIntent().hasExtra("page_id")) {
            page_id = bundle.getString("page_id");
            new ShowGridPhoto().execute(page_id, null);

        } else if (this.getIntent().hasExtra("module_id")) {
            album_id = bundle.getString("album_id");
            module_id = bundle.getString("module_id");
            group_id = bundle.getString("group_id");
            new ShowGridPhoto().execute(group_id, album_id);

        } else {
            new ShowGridPhoto().execute(null, null);
        }

    }

    // Set a listener to be invoked when the list should be refreshed.
    mPullRefreshGridView.setOnRefreshListener(new OnRefreshListener2<GridView>() {

        @Override
        public void onPullDownToRefresh(PullToRefreshBase<GridView> refreshView) {
            stringArrayList = null;
            imageUrls = null;

            imagePager = null;

            imagePhotoIds = null;

            imageHasLike = null;

            imageFeedisLike = null;

            imageTotal_like = null;

            imageTotal_comment = null;

            imageItemid = null;

            imageType = null;
            page = 1;
            adapter = new ImageAdapter();
            totalImages = 1;

            if (album_user_id != null) {
                new ShowGridPhoto().execute(album_user_id, album_id);
            } else if (module_id != null) {
                new ShowGridPhoto().execute(group_id, album_id);
            } else if (page_id != null) {
                new ShowGridPhoto().execute(page_id, null);
            } else if (user_id != null) {
                new ShowGridPhoto().execute(user_id, null);
            } else {
                new ShowGridPhoto().execute(null, null);
            }
            mPullRefreshGridView.onRefreshComplete();
        }

        @Override
        public void onPullUpToRefresh(PullToRefreshBase<GridView> refreshView) {

            if (album_user_id != null) {
                if (countImage < 2) {
                    itemView = (int) (20 * (countImage));
                } else {
                    countImage = countImage - 1;
                    itemView = itemView + 20;
                }
                adapter.notifyDataSetChanged();
                mPullRefreshGridView.onRefreshComplete();
            } else {
                if (viewmore != 1) {
                    page++;
                    if (module_id != null) {
                        new ShowGridPhoto().execute(group_id, album_id);
                    } else if (page_id != null) {
                        new ShowGridPhoto().execute(page_id, null);
                    } else if (user_id != null) {
                        new ShowGridPhoto().execute(user_id, null);
                    } else {
                        new ShowGridPhoto().execute(null, null);
                    }
                } else {
                    mPullRefreshGridView.onRefreshComplete();
                }
            }

        }

    });

    tv = new TextView(this);
    tv.setGravity(Gravity.CENTER);
    tv.setVisibility(View.GONE);
    mPullRefreshGridView.setEmptyView(tv);

}