Example usage for android.view Gravity CENTER_HORIZONTAL

List of usage examples for android.view Gravity CENTER_HORIZONTAL

Introduction

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

Prototype

int CENTER_HORIZONTAL

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

Click Source Link

Document

Place object in the horizontal center of its container, not changing its size.

Usage

From source file:com.xargsgrep.portknocker.activity.EditHostActivity.java

private boolean validateAndDisplayErrors(Host host) {
    //      boolean validHostname = HOSTNAME_PATTERN.matcher(host.getHostname()).matches();
    //      boolean validIP = InetAddressUtils.isIPv4Address(host.getHostname());

    String errorText = "";
    if (StringUtils.isBlank(host.getLabel())) {
        errorText = getString(R.string.toast_msg_enter_label);
    } else if (StringUtils.isBlank(host.getHostname())) {
        errorText = getString(R.string.toast_msg_enter_hostname);
    }/*w w  w.  j  a v a  2 s . c om*/
    //      else if (!validHostname && !validIP) {
    //         errorText = getString(R.string.toast_msg_invalid_hostname);
    //      }
    else if (host.getPorts() == null || host.getPorts().size() == 0) {
        errorText = getString(R.string.toast_msg_enter_port);
    } else if (host.getDelay() > MAX_DELAY_VALUE) {
        errorText = getString(R.string.toast_msg_delay_max_value) + MAX_DELAY_VALUE;
    } else {
        for (Port port : host.getPorts()) {
            if (port.getPort() > MAX_PORT_VALUE) {
                errorText = getString(R.string.toast_msg_invalid_port) + port.getPort();
                break;
            }
        }
    }

    if (StringUtils.isNotBlank(errorText)) {
        Toast toast = Toast.makeText(this, errorText, Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL, 0, 0);
        toast.show();
        return false;
    }

    return true;
}

From source file:com.jaredrummler.android.colorpicker.ColorPanelView.java

/**
 * Show a toast message with the hex color code below the view.
 *//*from  w w w.jav a  2 s.  c  om*/
public void showHint() {
    final int[] screenPos = new int[2];
    final Rect displayFrame = new Rect();
    getLocationOnScreen(screenPos);
    getWindowVisibleDisplayFrame(displayFrame);
    final Context context = getContext();
    final int width = getWidth();
    final int height = getHeight();
    final int midy = screenPos[1] + height / 2;
    int referenceX = screenPos[0] + width / 2;
    if (ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_LTR) {
        final int screenWidth = context.getResources().getDisplayMetrics().widthPixels;
        referenceX = screenWidth - referenceX; // mirror
    }
    StringBuilder hint = new StringBuilder("#");
    if (Color.alpha(color) != 255) {
        hint.append(Integer.toHexString(color).toUpperCase(Locale.ENGLISH));
    } else {
        hint.append(String.format("%06X", 0xFFFFFF & color).toUpperCase(Locale.ENGLISH));
    }
    Toast cheatSheet = Toast.makeText(context, hint.toString(), Toast.LENGTH_SHORT);
    if (midy < displayFrame.height()) {
        // Show along the top; follow action buttons
        cheatSheet.setGravity(Gravity.TOP | GravityCompat.END, referenceX,
                screenPos[1] + height - displayFrame.top);
    } else {
        // Show along the bottom center
        cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height);
    }
    cheatSheet.show();
}

From source file:com.tmall.ultraviewpager.sample.PagerActivity.java

/**
 *
 *//*from   w  w w  .  ja v a 2s  .  com*/
private void defaultUltraViewPager() {
    UltraViewPager ultraViewPager = (UltraViewPager) findViewById(R.id.ultra_viewpager);
    ultraViewPager.setScrollMode(UltraViewPager.ScrollMode.HORIZONTAL);
    //initialize UltraPagerAdapterand add child view to UltraViewPager
    PagerAdapter adapter = new UltraPagerAdapter(false);
    ultraViewPager.setAdapter(adapter);

    //initialize built-in indicator
    ultraViewPager.initIndicator();
    //set style of indicators
    ultraViewPager.getIndicator().setOrientation(UltraViewPager.Orientation.HORIZONTAL)
            .setFocusColor(Color.GREEN).setNormalColor(Color.WHITE).setRadius((int) TypedValue
                    .applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, getResources().getDisplayMetrics()));
    //set the alignment
    ultraViewPager.getIndicator().setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
    //construct built-in indicator, and add it to  UltraViewPager
    ultraViewPager.getIndicator().build();

    //set an infinite loop
    ultraViewPager.setInfiniteLoop(true);
    //enable auto-scroll mode
    ultraViewPager.setAutoScroll(2000);
}

From source file:it.redturtle.mobile.apparpav.MeteogramAdapter.java

/**
 * SINGLE TEXT ROW/*from  ww w  .j a va2s .c  o  m*/
 * @param att
 * @param linear
 * @return
 */
public LinearLayout getSingleTextRow(Map<String, String> att, LinearLayout linear) {

    LinearLayout container_layout = new LinearLayout(context);
    container_layout.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.view_shape_meteo));
    container_layout.setMinimumHeight(46);
    container_layout.setVerticalGravity(Gravity.CENTER);

    LinearLayout.LayoutParams value = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT, 0.5f);
    TextView tx = new TextView(context);
    tx.setText(att.get("title"));
    tx.setTextSize(11);
    tx.setTypeface(null, Typeface.BOLD);
    tx.setGravity(Gravity.LEFT);
    tx.setPadding(3, 0, 0, 2);
    tx.setTextColor(Color.rgb(66, 66, 66));
    container_layout.addView(tx, value);

    LinearLayout.LayoutParams value_params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT, 0.5f);
    TextView t2 = new TextView(context);
    t2.setText(att.get("value").equals("") ? " - " : att.get("value"));
    t2.setTextSize(11);
    t2.setGravity(Gravity.CENTER_HORIZONTAL);
    t2.setPadding(2, 0, 0, 2);
    t2.setTextColor(Color.rgb(66, 66, 66));
    container_layout.addView(t2, value_params);

    linear.addView(container_layout);
    return linear;
}

From source file:com.adamkruger.myipaddressinfo.NetworkInfoFragment.java

private void addTableRow(Row row) {
    if (row.mLabel.length() > 0 || row.mValue.length() > 0) {
        int horizontalPadding = (int) (getResources().getDisplayMetrics().density
                * getResources().getDimension(R.dimen.label_value_padding) + 0.5f);
        TextView labelView = makeTextView(row.mLabel, getResources().getColor(R.color.dark_text_color),
                horizontalPadding);//ww  w  .  j a  v  a 2  s  .c om
        labelView.setGravity(Gravity.RIGHT);
        TextView valueView = makeTextView(row.mValue, getResources().getColor(R.color.dark_text_color),
                horizontalPadding);
        TableRow tableRow = makeTableRow(labelView, valueView);
        int verticalPadding = (int) (getResources().getDisplayMetrics().density
                * getResources().getDimension(R.dimen.network_info_vertical_padding) + 0.5f);
        tableRow.setPadding(0, verticalPadding, 0, verticalPadding);
        tableRow.setBackgroundColor(getResources().getColor(R.color.background_color_white));
        tableRow.setGravity(Gravity.CENTER_HORIZONTAL);
        mNetworkInfoTableLayout.addView(tableRow);
    }
}

From source file:net.mypapit.mobile.callsignview.MainActivity.java

private void showToast(String message) {
    Context context = getApplicationContext();
    LayoutInflater inflater = getLayoutInflater();

    View customToastroot = inflater.inflate(R.layout.custom_toast, null);
    TextView tvToast = (TextView) customToastroot.findViewById(R.id.tvToast);
    tvToast.setText(message);//from w  w  w. ja v a  2s. c o m

    Toast customtoast = new Toast(context);

    customtoast.setView(customToastroot);
    customtoast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL, 0, 0);
    customtoast.setDuration(Toast.LENGTH_SHORT);
    customtoast.show();

}

From source file:android.support.v7.app.MediaRouteButton.java

@Override
public boolean performLongClick() {
    if (super.performLongClick()) {
        return true;
    }/*from  www.  j  a v a2  s. c  o m*/

    if (!mCheatSheetEnabled) {
        return false;
    }

    final CharSequence contentDesc = getContentDescription();
    if (TextUtils.isEmpty(contentDesc)) {
        // Don't show the cheat sheet if we have no description
        return false;
    }

    final int[] screenPos = new int[2];
    final Rect displayFrame = new Rect();
    getLocationOnScreen(screenPos);
    getWindowVisibleDisplayFrame(displayFrame);

    final Context context = getContext();
    final int width = getWidth();
    final int height = getHeight();
    final int midy = screenPos[1] + height / 2;
    final int screenWidth = context.getResources().getDisplayMetrics().widthPixels;

    Toast cheatSheet = Toast.makeText(context, contentDesc, Toast.LENGTH_SHORT);
    if (midy < displayFrame.height()) {
        // Show along the top; follow action buttons
        cheatSheet.setGravity(Gravity.TOP | GravityCompat.END, screenWidth - screenPos[0] - width / 2, height);
    } else {
        // Show along the bottom center
        cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height);
    }
    cheatSheet.show();
    performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
    return true;
}

From source file:hr.abunicic.angular.CameraActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ApplicationContext.getInstance().init(getApplicationContext());
    setContentView(R.layout.activity_camera);

    //Left drawer
    drawerLayout = (DrawerLayout) findViewById(R.id.camera_activity_drawer_layout);

    //Binding the RecyclerView
    recyclerView = (RecyclerView) findViewById(R.id.r_list);
    recyclerView.setHasFixedSize(true);//w  w  w  . j av  a  2 s . c o m

    //Informative text when database is empty
    infoNothingSaved = (TextView) findViewById(R.id.infoNothing);

    //Getting all saved shaped from the database and populating the RecyclerView
    db = new DatabaseHandler(CameraActivity.this);
    historyItems = (ArrayList) db.getAllShapes();
    setHistoryItems();

    //Card at the bottom
    cardBottom = (CardView) findViewById(R.id.cardBottom);
    cardBottom.bringToFront();
    //Elements inside the CardView
    tvShape = (TextView) findViewById(R.id.tvGeomLik);
    tvCardTitle = (TextView) findViewById(R.id.titleText);
    tvShape.setMovementMethod(new ScrollingMovementMethod());
    final ImageButton imgSave = (ImageButton) findViewById(R.id.imgSave);

    //Getting instance of the sensor service
    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    mGyroSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR);

    //Initializing the camera and setting up screen size
    initCamera();
    DisplayMetrics displayMetrics = new DisplayMetrics();
    this.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    screenHeight = displayMetrics.heightPixels;
    screenWidth = displayMetrics.widthPixels;

    //Flash button
    final ImageButton imgFlash = (ImageButton) findViewById(R.id.imgFlash);
    if (this.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)) {
        imgFlash.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (params.getFlashMode().equals(Camera.Parameters.FLASH_MODE_TORCH)) {
                    params.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);

                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                        imgFlash.setBackground(getResources().getDrawable(R.drawable.ic_flash_on_white_36dp));
                    }
                } else {
                    params.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);

                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                        imgFlash.setBackground(getResources().getDrawable(R.drawable.ic_flash_off_white_36dp));
                    }
                }
                mCamera.setParameters(params);
            }
        });
    } else {
        imgFlash.setVisibility(View.GONE);
    }

    //Delete all button in the drawer view
    ImageButton imgDeleteAll = (ImageButton) findViewById(R.id.imgDeleteAll);
    imgDeleteAll.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            db.deleteAllShapes();
            historyItems.clear();

            setHistoryItems();
        }
    });

    //Menu icon for opening the drawer
    ImageButton imgMenu = (ImageButton) findViewById(R.id.imgMenu);
    imgMenu.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            drawerLayout.openDrawer(Gravity.LEFT);
        }
    });

    //Fab button functionality
    fabCapture = (FloatingActionButton) findViewById(R.id.fab);
    fabCapture.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startDetection();
            fabCapture.setClickable(false);
            FabTransformation.with(fabCapture).transformTo(cardBottom);

            imgSave.setVisibility(View.VISIBLE);

            imgSave.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Animation animation = AnimationUtils.loadAnimation(CameraActivity.this, R.anim.anim);
                    mCameraView.startAnimation(animation);

                    Toast toast = Toast.makeText(getApplicationContext(),
                            getResources().getString(R.string.toast_saved), Toast.LENGTH_LONG); //Dodati u strings i u engl verziju
                    toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0);
                    toast.show();

                    ShapeInDatabase shapeToAdd = new ShapeInDatabase(mCameraView.getBitmap(),
                            tvCardTitle.getText().toString(), tvShape.getText().toString());
                    db.addShape(shapeToAdd);
                    historyItems.add(0, shapeToAdd);

                    setHistoryItems();

                }
            });

            if (rp != null) {
                Shape shape = ShapeHeuristic.getShape(rp);
                if (shape != null) {
                    tvCardTitle.setText(shape.getName());
                    tvShape.setText(shape.toString());
                    if (shape instanceof DefaultPolygon && ((DefaultPolygon) shape).getN() == 5) {
                        tvCardTitle.setText("Pravilni peterokut");
                        tvShape.setText(
                                "Sve stranice pravilnog peterokuta su jednake duljine. \n     a = 5 cm \n     P = 43.01 \n     O = 25");
                    }
                }
            }

        }
    });

    //Button inside the card for going back
    Button buttonBack = (Button) findViewById(R.id.buttonBack);
    buttonBack.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startDetection();

            FabTransformation.with(fabCapture).transformFrom(cardBottom);
            fabCapture.setClickable(true);

            imgSave.setVisibility(View.INVISIBLE);
        }
    });

    //Button inside the card for opening the ResultActivity with more info about the shape
    Button buttonMore = (Button) findViewById(R.id.buttonMore);
    buttonMore.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Shape shape = ShapeHeuristic.getShape(rp);
            if (shape instanceof DefaultPolygon && ((DefaultPolygon) shape).getN() == 5) {
                Intent intentPeterokut = new Intent(CameraActivity.this, PeterokutActivity.class);
                startActivity(intentPeterokut);
            } else {
                Intent intent = new Intent(CameraActivity.this, ResultActivity.class);
                intent.putExtra("RESULT_TITLE", tvCardTitle.getText().toString());
                intent.putExtra("RESULT_INFO", tvShape.getText().toString());

                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                mCameraView.getBitmap().compress(Bitmap.CompressFormat.PNG, 100, bos);
                byte[] byteArray = bos.toByteArray();

                intent.putExtra("RESULT_IMAGE", byteArray);
                startActivity(intent);
            }

        }
    });

    //Corners View
    DisplayMetrics displaymetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    cornersView = (CornersView) findViewById(R.id.cornersView);
    shadow = (FrameLayout) findViewById(R.id.shadowLayout);
    cornersView.setShadow(shadow);

    //Starting the detection process
    startDetection();

    //Microblink OCR
    try {
        mRecognizer = Recognizer.getSingletonInstance();
    } catch (FeatureNotSupportedException e) {
        Toast.makeText(CameraActivity.this, "Feature not supported! Reason: " + e.getReason().getDescription(),
                Toast.LENGTH_LONG).show();
        finish();
        return;
    }
    try {
        // set license key
        mRecognizer.setLicenseKey(CameraActivity.this,
                "Y5352CQ5-A7KVPD26-UOAUEX4P-D2GQM63S-J6TCRGNH-T5WFKI24-QQZJRAXL-AT55KX4N");
    } catch (InvalidLicenceKeyException exc) {
        finish();
        return;
    }
    RecognitionSettings settings = new RecognitionSettings();
    // setupSettingsArray method is described in chapter "Recognition settings and results")
    settings.setRecognizerSettingsArray(setupSettingsArray());
    mRecognizer.initialize(CameraActivity.this, settings, new DirectApiErrorListener() {
        @Override
        public void onRecognizerError(Throwable t) {
            Toast.makeText(CameraActivity.this,
                    "There was an error in initialization of Recognizer: " + t.getMessage(), Toast.LENGTH_SHORT)
                    .show();
            finish();
        }
    });

}

From source file:paulscode.android.mupen64plusae.game.GameActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.i("GameActivity", "onCreate");
    super.setTheme(android.support.v7.appcompat.R.style.Theme_AppCompat_NoActionBar);

    //Allow volume keys to control media volume if they are not mapped
    final SharedPreferences mPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    final boolean volKeyMapped = mPreferences.getBoolean("inputVolumeMappable", false);
    final AppData appData = new AppData(this);
    final GlobalPrefs globalPrefs = new GlobalPrefs(this, appData);
    if (!volKeyMapped && globalPrefs.audioPlugin.enabled) {
        setVolumeControlStream(AudioManager.STREAM_MUSIC);
    }//from   w  w w . ja  v  a 2s  .com

    mControllers = new ArrayList<>();
    mMogaController = Controller.getInstance(this);

    // Get the intent data
    final Bundle extras = this.getIntent().getExtras();
    if (extras == null)
        throw new Error("ROM path and MD5 must be passed via the extras bundle when starting GameActivity");
    mRomPath = extras.getString(ActivityHelper.Keys.ROM_PATH);
    mRomMd5 = extras.getString(ActivityHelper.Keys.ROM_MD5);
    mRomCrc = extras.getString(ActivityHelper.Keys.ROM_CRC);
    String romHeaderName = extras.getString(ActivityHelper.Keys.ROM_HEADER_NAME);
    byte romCountryCode = extras.getByte(ActivityHelper.Keys.ROM_COUNTRY_CODE);
    String artPath = extras.getString(ActivityHelper.Keys.ROM_ART_PATH);
    String romGoodName = extras.getString(ActivityHelper.Keys.ROM_GOOD_NAME);
    String legacySaveName = extras.getString(ActivityHelper.Keys.ROM_LEGACY_SAVE);
    boolean doRestart = extras.getBoolean(ActivityHelper.Keys.DO_RESTART, false);
    if (TextUtils.isEmpty(mRomPath) || TextUtils.isEmpty(mRomMd5))
        throw new Error("ROM path and MD5 must be passed via the extras bundle when starting GameActivity");

    // Initialize MOGA controller API
    // TODO: Remove hack after MOGA SDK is fixed
    // mMogaController.init();
    MogaHack.init(mMogaController, this);

    // Get app data and user preferences
    mGlobalPrefs = new GlobalPrefs(this, appData);

    mGamePrefs = new GamePrefs(this, mRomMd5, mRomCrc, romHeaderName, romGoodName,
            RomHeader.countryCodeToSymbol(romCountryCode), appData, mGlobalPrefs, legacySaveName);
    String cheatArgs = mGamePrefs.getCheatArgs();

    mAutoSaveManager = new GameAutoSaveManager(mGamePrefs, mGlobalPrefs.maxAutoSaves);

    mGlobalPrefs.enforceLocale(this);

    final Window window = this.getWindow();

    // Enable full-screen mode
    window.setFlags(LayoutParams.FLAG_FULLSCREEN, LayoutParams.FLAG_FULLSCREEN);
    window.setFlags(LayoutParams.FLAG_LAYOUT_IN_SCREEN, LayoutParams.FLAG_LAYOUT_IN_SCREEN);

    // Keep screen from going to sleep
    window.setFlags(LayoutParams.FLAG_KEEP_SCREEN_ON, LayoutParams.FLAG_KEEP_SCREEN_ON);

    // Set the screen orientation
    this.setRequestedOrientation(mGlobalPrefs.displayOrientation);

    // If the orientation changes, the screensize info changes, so we must refresh dependencies
    mGlobalPrefs = new GlobalPrefs(this, appData);
    mGamePrefs = new GamePrefs(this, mRomMd5, mRomCrc, romHeaderName, romGoodName,
            RomHeader.countryCodeToSymbol(romCountryCode), appData, mGlobalPrefs, legacySaveName);

    mFirstStart = true;

    //TODO: Figure out why we call this in the middle
    super.onCreate(savedInstanceState);

    // Lay out content and get the views
    this.setContentView(R.layout.game_activity);
    mSurface = (GameSurface) this.findViewById(R.id.gameSurface);
    mOverlay = (GameOverlay) this.findViewById(R.id.gameOverlay);
    mDrawerLayout = (GameDrawerLayout) this.findViewById(R.id.drawerLayout);
    mGameSidebar = (GameSidebar) this.findViewById(R.id.gameSidebar);

    // Don't darken the game screen when the drawer is open
    mDrawerLayout.setScrimColor(0x0);

    // Make the background solid black
    mSurface.getRootView().setBackgroundColor(0xFF000000);
    mSurface.SetGameSurfaceCreatedListener(this);

    if (!TextUtils.isEmpty(artPath) && new File(artPath).exists())
        mGameSidebar.setImage(new BitmapDrawable(this.getResources(), artPath));

    mGameSidebar.setTitle(romGoodName);
    // Initialize the objects and data files interfacing to the emulator core
    CoreInterface.initialize(this, mSurface, mGamePrefs, mRomPath, mRomMd5, cheatArgs, doRestart);

    // Handle events from the side bar
    mGameSidebar.setActionHandler(this, R.menu.game_drawer);

    //Reload menus
    ReloadAllMenus();

    // Listen to game surface events (created, changed, destroyed)
    mSurface.getHolder().addCallback(this);

    // Update the GameSurface size
    mSurface.getHolder().setFixedSize(mGamePrefs.videoRenderWidth, mGamePrefs.videoRenderHeight);
    final FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mSurface.getLayoutParams();
    params.width = Math.round(mGamePrefs.videoSurfaceWidth * (mGamePrefs.videoSurfaceZoom / 100.f));
    params.height = Math.round(mGamePrefs.videoSurfaceHeight * (mGamePrefs.videoSurfaceZoom / 100.f));

    if ((mGlobalPrefs.displayOrientation & 1) == 1)
        params.gravity = mGlobalPrefs.displayPosition | Gravity.CENTER_HORIZONTAL;
    else
        params.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL;

    mSurface.setLayoutParams(params);

    // Initialize the screen elements
    if (mGamePrefs.isTouchscreenEnabled || mGlobalPrefs.isFpsEnabled) {
        // The touch map and overlay are needed to display frame rate and/or controls
        mTouchscreenMap = new VisibleTouchMap(this.getResources());
        mTouchscreenMap.load(mGamePrefs.touchscreenSkin, mGamePrefs.touchscreenProfile,
                mGamePrefs.isTouchscreenAnimated, mGlobalPrefs.isFpsEnabled, mGlobalPrefs.touchscreenScale,
                mGlobalPrefs.touchscreenTransparency);
        mOverlay.initialize(mTouchscreenMap, !mGamePrefs.isTouchscreenHidden, mGlobalPrefs.isFpsEnabled,
                mGamePrefs.isAnalogHiddenWhenSensor, mGamePrefs.isTouchscreenAnimated);
    }

    // Initialize user interface devices
    initControllers(mOverlay);

    // Override the peripheral controllers' key provider, to add some extra
    // functionality
    mOverlay.setOnKeyListener(this);

    if (savedInstanceState == null) {
        // Show the drawer at the start and have it hide itself
        // automatically
        mDrawerLayout.openDrawer(GravityCompat.START);
        mDrawerLayout.postDelayed(new Runnable() {
            @Override
            public void run() {
                mDrawerLayout.closeDrawer(GravityCompat.START);
            }
        }, 1000);
    }

    mDrawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() {

        @Override
        public void onDrawerClosed(View arg0) {
            NativeExports.emuResume();
        }

        @Override
        public void onDrawerOpened(View arg0) {
            NativeExports.emuPause();
            ReloadAllMenus();
        }

        @Override
        public void onDrawerSlide(View arg0, float arg1) {

        }

        @Override
        public void onDrawerStateChanged(int newState) {

        }

    });
}

From source file:nuclei.ui.view.ButtonBarView.java

void dataSetChanged() {
    mLabelAnimators.clear();//from w  ww.ja  v a 2s . c o  m
    mButtons.removeAllViews();

    if (mAdapter == null) {
        mItems = null;
        return;
    }

    final int count = mAdapter.getCount();
    final View.OnClickListener listener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            int position = 0;
            for (Item item : mItems) {
                if (item.view == v) {
                    setSelectedItem(position);
                    break;
                }
                position++;
            }
        }
    };

    final LayoutInflater inflater = LayoutInflater.from(getContext());

    if (mItems == null || mItems.length != count)
        mItems = new Item[count];

    for (int i = 0; i < count; i++) {
        final int textId = mAdapter.getTitle(i);
        final int imageId = mAdapter.getDrawable(i);
        Item item = new Item(textId, imageId);

        item.view = (ViewGroup) inflater
                .inflate(mOrientation == 1 ? R.layout.cyto_view_button_horizontal_bar_item
                        : R.layout.cyto_view_button_vertical_bar_item, this, false);
        item.view.setOnClickListener(listener);

        item.imageView = (ImageView) item.view.findViewById(R.id.image);
        if (item.textId != 0)
            item.imageView.setContentDescription(getResources().getString(item.textId));
        item.imageView.setImageResource(item.imageId);
        item.imageView.setColorFilter(mUnselectedTint, PorterDuff.Mode.SRC_ATOP);

        item.textView = (TextView) item.view.findViewById(R.id.text);
        if (item.textView != null) {
            item.textView.setText(item.textId);

            if (count > 4)
                item.textView.setVisibility(GONE);
        }

        mItems[i] = item;

        LinearLayout.LayoutParams params = mOrientation == 1
                ? new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 1)
                : new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT);
        params.gravity = mOrientation == 1 ? Gravity.CENTER_VERTICAL : Gravity.CENTER_HORIZONTAL;
        mButtons.addView(item.view, params);
    }
}