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.insthub.O2OMobile.Activity.C17_ApplyFormActivity.java

@Override
public void OnMessageResponse(String url, JSONObject jo, AjaxStatus status) throws JSONException {
    if (url.endsWith(ApiInterface.USER_APPLY_SERVICE)) {
        ToastView toast = new ToastView(C17_ApplyFormActivity.this,
                getString(R.string.apply_certificate_success));
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();//from   w  w  w  .j a  va 2 s .  c  o  m
        finish();
    } else if (url.endsWith(ApiInterface.SERVICETYPE_LIST)) {
        mServiceTypeList = mServiceModel.publicServiceTypeList;
        mServiceTypeTitle.setText(mServiceTypeList.get(0).title);
        mSecondCategoryTitle.setText("");
        mServiceModel.publicIsSecondCategory = false;
        mServiceTypeId = mServiceTypeList.get(0).id;
        mServiceModel.getCategoryList(mServiceTypeList.get(0).id);
    } else if (url.endsWith(ApiInterface.SERVICECATEGORY_LIST)) {
        if (mServiceModel.publicIsSecondCategory) {
            mSecondCategoryList = mServiceModel.publicSecondCategories;
            if (mSecondCategoryList.size() == 0) {
                mSecondCategoryTitle.setText(getString(R.string.none));
                mSecondCategoryArrow.setVisibility(View.INVISIBLE);
                mSecondVlassServiceCategory = 0;
                mSecondCategory.setClickable(false);
            } else {
                mFirstCategoryArrow.setVisibility(View.VISIBLE);
                mSecondCategoryArrow.setVisibility(View.VISIBLE);
                mFirstCategory.setClickable(true);
                mSecondCategory.setClickable(true);
                mSecondCategoryTitle.setText(mSecondCategoryList.get(0).title);
                mSecondVlassServiceCategory = mSecondCategoryList.get(0).id;
            }
        } else {
            mFirstCategoryList = mServiceModel.publicSecondCategories;
            if (mFirstCategoryList.size() == 0) {
                mFirstCategoryTitle.setText(getString(R.string.none));
                mSecondCategoryTitle.setText(getString(R.string.none));
                mFirstCategoryArrow.setVisibility(View.INVISIBLE);
                mSecondCategoryArrow.setVisibility(View.INVISIBLE);
                mFirstCategory.setClickable(false);
                mSecondCategory.setClickable(false);
                mFirstClassServiceCategory = 0;
                mSecondVlassServiceCategory = 0;
            } else {
                mFirstCategoryTitle.setText(mFirstCategoryList.get(0).title);
                mFirstClassServiceCategory = mFirstCategoryList.get(0).id;
                mServiceModel.publicIsSecondCategory = true;
                mServiceModel.getCategoryList(mFirstCategoryList.get(0).id);
            }
        }

    }
}

From source file:fm.smart.r1.activity.ItemActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ExceptionHandler.register(this);

    // could check here to see if this was suspended for login and go
    // straight to add_item ...

    setContentView(R.layout.item);/*from   w w  w.j av a  2  s.  c  o  m*/

    /*
     * ImageView author_icon = (ImageView)
     * findViewById(R.id.item_author_icon); if (item.author_image != null){
     * author_icon.setImageBitmap(item.author_image); }
     */

    TextView cue_and_pronunciation = (TextView) findViewById(R.id.cue_and_pronunciation);
    cue_and_pronunciation.setText(item.cue_text); // TODO handle case where item is null?
    TextView cue_part_of_speech = (TextView) findViewById(R.id.cue_part_of_speech);
    if (!TextUtils.equals(item.part_of_speech, "None")) {
        cue_part_of_speech.setText(item.part_of_speech);
    } else {
        cue_part_of_speech.setVisibility(View.INVISIBLE);
    }
    /*
     * TextView author = (TextView) findViewById(R.id.item_author);
     * author.setText(item.author_name);
     */

    TextView response_and_pronunciation = (TextView) findViewById(R.id.response_and_pronunciation);
    response_and_pronunciation.setText(item.children[0][0]);
    TextView response_part_of_speech = (TextView) findViewById(R.id.response_part_of_speech);
    if (item.type != null && item.type.equals("meaning")) {
        item.type = "Translation";
    }
    response_part_of_speech.setText(item.type);
    response_part_of_speech.setVisibility(View.INVISIBLE);

    ImageView cue_sound = (ImageView) findViewById(R.id.cue_sound);
    setSound(cue_sound, item.cue_sound_url, this, R.id.cue_sound, (String) item.item_node.atts.get("id"),
            item.cue_text);

    ImageView response_sound = (ImageView) findViewById(R.id.response_sound);
    setSound(response_sound, item.response_sound_url, this, R.id.response_sound,
            (String) item.item_node.atts.get("id"), item.response_node.getFirstContents("text"));
    EfficientAdapter adapter = new EfficientAdapter(ItemActivity.this, item.sentence_vector);
    setListAdapter(adapter);
    if (adapter.getCount() == 0 && !ItemActivity.shown_toast) {
        Toast t = Toast.makeText(this, "Know a good example? Click the menu button to add one", 250);
        t.setGravity(Gravity.CENTER, 0, 0);
        t.show();
        ItemActivity.shown_toast = true;
    }
    // notify();
}

From source file:br.com.laboratorio.hemope.View.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}./*from  w w w . ja v  a2  s  . co  m*/
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
    textView.setBackgroundResource(outValue.resourceId);
    textView.setAllCaps(true);
    textView.setTextColor(Color.WHITE);

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

    return textView;
}

From source file:com.ahmeddonkl.superbuzz.Miscellaneous.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}.//from   ww  w  . j a v a  2s  .  c  o  m
 */
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
    textView.setBackgroundResource(outValue.resourceId);
    textView.setAllCaps(true);

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

    return textView;
}

From source file:com.androcast.illusion.illusionmod.MainActivity.java

/**
 * Dialog which asks the user to enter his password
 *
 * @param password current encoded password
 *///from   w w  w. j  a  va  2s  .c o m
private void askPassword(final String password) {
    LinearLayout linearLayout = new LinearLayout(this);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setGravity(Gravity.CENTER);
    linearLayout.setPadding(30, 20, 30, 20);

    final AppCompatEditText mPassword = new AppCompatEditText(this);
    mPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    mPassword.setHint(getString(R.string.password));
    linearLayout.addView(mPassword);

    new AlertDialog.Builder(this).setView(linearLayout).setCancelable(false)
            .setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    if (mPassword.getText().toString().equals(Utils.decodeString(password)))
                        new Task().execute();
                    else {
                        Utils.toast(getString(R.string.password_wrong), MainActivity.this);
                        finish();
                    }
                }
            }).show();
}

From source file:com.androidquery.simplefeed.base.BaseActivity.java

public void showToast(String message) {

    if (message == null || message.length() == 0)
        return;//from www. java  2  s.  c  o m

    try {
        Toast toast = Toast.makeText(this, message, Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
    } catch (Exception e) {
        AQUtility.report(e);
    }
}

From source file:com.facebook.notifications.internal.activity.CardActivity.java

private void beginLoadingContent() {
    if (assetManager == null || contentManager == null) {
        Log.e(LOG_TAG, "Asset & content manager should be available!");
        return;//from   w  ww  .j a va 2s .  c o m
    }

    if (configurationPayload == null) {
        Log.e(LOG_TAG, "No card payload is available!");
        return;
    }

    ProgressBar loadingView = new ProgressBar(this);
    loadingView.setIndeterminate(true);

    int backgroundColor = ColorAssetHandler.fromRGBAHex(configurationPayload.optString("backdropColor"));

    FrameLayout loadingViewFrame = new FrameLayout(this);
    loadingViewFrame.setBackgroundColor(backgroundColor);

    LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    layoutParams.gravity = Gravity.CENTER;
    loadingViewFrame.addView(loadingView, layoutParams);

    setContentView(loadingViewFrame);

    final Handler handler = new Handler();
    if (configurationPayload == null) {
        return;
    }

    assetManager.cachePayload(configurationPayload, new AssetManager.CacheCompletionCallback() {
        @Override
        public void onCacheCompleted(@NonNull JSONObject payload) {
            final CardConfiguration configuration;
            try {
                configuration = new CardConfiguration(configurationPayload, assetManager, contentManager);
            } catch (JSONException ex) {
                Log.e(LOG_TAG, "Error while parsing JSON", ex);
                return;
            }

            handler.post(new Runnable() {
                @Override
                public void run() {
                    displayConfiguration(configuration);
                }
            });
        }
    });
}

From source file:br.org.ftsl.sliding.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}./*w w  w. j av a2  s . co m*/
 */

protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);

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

    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, padding, padding, padding);

    return textView;
}

From source file:adi.sf1.targaryen.newyorktimes.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}.//  w w w.j  a  va  2  s.  c o  m
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);

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

    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, padding, padding, padding);

    return textView;
}

From source file:fm.smart.r1.ItemActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ExceptionHandler.register(this);

    // could check here to see if this was suspended for login and go
    // straight to add_item ...

    setContentView(R.layout.item);/*from  ww w. j a v  a2s  .c  om*/

    TextView cue_and_pronunciation = (TextView) findViewById(R.id.cue_and_pronunciation);
    cue_and_pronunciation.setText(item.cue_text); // TODO handle case where
    // item is null?
    TextView cue_part_of_speech = (TextView) findViewById(R.id.cue_part_of_speech);
    if (!TextUtils.equals(item.part_of_speech, "None")) {
        cue_part_of_speech.setText(item.part_of_speech);
    } else {
        cue_part_of_speech.setVisibility(View.INVISIBLE);
    }

    TextView response_and_pronunciation = (TextView) findViewById(R.id.response_and_pronunciation);
    response_and_pronunciation.setText(item.children[0][0]);
    TextView response_part_of_speech = (TextView) findViewById(R.id.response_part_of_speech);
    if (item.type != null && item.type.equals("meaning")) {
        item.type = "Translation";
    }
    response_part_of_speech.setText(item.type);
    response_part_of_speech.setVisibility(View.INVISIBLE);

    ImageView cue_sound = (ImageView) findViewById(R.id.cue_sound);
    try {
        setSound(cue_sound, item.cue_sound_url, this, R.id.cue_sound, (String) item.item_node.getString("id"),
                item.cue_text);
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    ImageView response_sound = (ImageView) findViewById(R.id.response_sound);
    try {
        setSound(response_sound, item.response_sound_url, this, R.id.response_sound,
                (String) item.item_node.getString("id"),
                item.response_node.getJSONObject("content").getString("text"));
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    EfficientAdapter adapter = new EfficientAdapter(ItemActivity.this, item.sentence_vector);
    cache = new Cache(adapter);
    setListAdapter(adapter);
    if (adapter.getCount() == 0 && !ItemActivity.shown_toast) {
        Toast t = Toast.makeText(this, "Know a good example? Click the menu button to add one", 250);
        t.setGravity(Gravity.CENTER, 0, 0);
        t.show();
        ItemActivity.shown_toast = true;
    }
    // notify();
}