Search in sources :

Example 41 with LinearLayout

use of android.widget.LinearLayout in project platform_frameworks_base by android.

the class SurfaceCompositionMeasuringActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    // Detect Andromeda devices by having free-form window management feature.
    mAndromeda = getPackageManager().hasSystemFeature(PackageManager.FEATURE_FREEFORM_WINDOW_MANAGEMENT);
    detectRefreshRate();
    // To layouts in parent. First contains list of Surfaces and second
    // controls. Controls stay on top.
    RelativeLayout rootLayout = new RelativeLayout(this);
    rootLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    CustomLayout layout = new CustomLayout(this);
    layout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    Rect rect = new Rect();
    getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
    mWidth = rect.right;
    mHeight = rect.bottom;
    long maxMemoryPerSurface = roundToNextPowerOf2(mWidth) * roundToNextPowerOf2(mHeight) * 4;
    // Use 75% of available memory.
    int surfaceCnt = (int) ((getMemoryInfo().availMem * 3) / (4 * maxMemoryPerSurface));
    if (surfaceCnt < MIN_NUMBER_OF_SURFACES) {
        throw new RuntimeException("Not enough memory to allocate " + MIN_NUMBER_OF_SURFACES + " surfaces.");
    }
    if (surfaceCnt > MAX_NUMBER_OF_SURFACES) {
        surfaceCnt = MAX_NUMBER_OF_SURFACES;
    }
    LinearLayout controlLayout = new LinearLayout(this);
    controlLayout.setOrientation(LinearLayout.VERTICAL);
    controlLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    mMeasureCompositionButton = createButton("Compositor speed.", controlLayout);
    mMeasureAllocationButton = createButton("Allocation speed", controlLayout);
    String[] pixelFomats = new String[PIXEL_FORMATS.length];
    for (int i = 0; i < pixelFomats.length; ++i) {
        pixelFomats[i] = getPixelFormatInfo(PIXEL_FORMATS[i]);
    }
    mPixelFormatSelector = new Spinner(this);
    ArrayAdapter<String> pixelFormatSelectorAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, pixelFomats);
    pixelFormatSelectorAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mPixelFormatSelector.setAdapter(pixelFormatSelectorAdapter);
    mPixelFormatSelector.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    controlLayout.addView(mPixelFormatSelector);
    mResultView = new TextView(this);
    mResultView.setBackgroundColor(0);
    mResultView.setText("Press button to start test.");
    mResultView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    controlLayout.addView(mResultView);
    mSystemInfoView = new TextView(this);
    mSystemInfoView.setBackgroundColor(0);
    mSystemInfoView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    controlLayout.addView(mSystemInfoView);
    for (int i = 0; i < surfaceCnt; ++i) {
        CustomSurfaceView view = new CustomSurfaceView(this, "Surface:" + i);
        // to mark as media overlay.
        if (i == 0) {
            view.setLayoutParams(new CustomLayout.LayoutParams(0, 0, mWidth, mHeight));
            view.setZOrderMediaOverlay(false);
        } else {
            // Z order of other layers is not predefined so make offset on x and reverse
            // offset on y to make sure that surface is visible in any layout.
            int x = i;
            int y = (surfaceCnt - i);
            view.setLayoutParams(new CustomLayout.LayoutParams(x, y, x + mWidth, y + mHeight));
            view.setZOrderMediaOverlay(true);
        }
        view.setVisibility(View.INVISIBLE);
        layout.addView(view);
        mViews.add(view);
    }
    rootLayout.addView(layout);
    rootLayout.addView(controlLayout);
    setContentView(rootLayout);
}
Also used : Rect(android.graphics.Rect) ViewGroup(android.view.ViewGroup) Spinner(android.widget.Spinner) RelativeLayout(android.widget.RelativeLayout) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout) ArrayAdapter(android.widget.ArrayAdapter)

Example 42 with LinearLayout

use of android.widget.LinearLayout in project platform_frameworks_base by android.

the class RenderSessionImpl method setupTabHost.

/**
     * Sets up a {@link TabHost} object.
     * @param tabHost the TabHost to setup.
     * @param layoutlibCallback The project callback object to access the project R class.
     * @throws PostInflateException
     */
private void setupTabHost(TabHost tabHost, LayoutlibCallback layoutlibCallback) throws PostInflateException {
    // look for the TabWidget, and the FrameLayout. They have their own specific names
    View v = tabHost.findViewById(android.R.id.tabs);
    if (v == null) {
        throw new PostInflateException("TabHost requires a TabWidget with id \"android:id/tabs\".\n");
    }
    if (!(v instanceof TabWidget)) {
        throw new PostInflateException(String.format("TabHost requires a TabWidget with id \"android:id/tabs\".\n" + "View found with id 'tabs' is '%s'", v.getClass().getCanonicalName()));
    }
    v = tabHost.findViewById(android.R.id.tabcontent);
    if (v == null) {
        //noinspection SpellCheckingInspection
        throw new PostInflateException("TabHost requires a FrameLayout with id \"android:id/tabcontent\".");
    }
    if (!(v instanceof FrameLayout)) {
        //noinspection SpellCheckingInspection
        throw new PostInflateException(String.format("TabHost requires a FrameLayout with id \"android:id/tabcontent\".\n" + "View found with id 'tabcontent' is '%s'", v.getClass().getCanonicalName()));
    }
    FrameLayout content = (FrameLayout) v;
    // now process the content of the frameLayout and dynamically create tabs for it.
    final int count = content.getChildCount();
    // this must be called before addTab() so that the TabHost searches its TabWidget
    // and FrameLayout.
    tabHost.setup();
    if (count == 0) {
        // Create a dummy child to get a single tab
        TabSpec spec = tabHost.newTabSpec("tag").setIndicator("Tab Label", tabHost.getResources().getDrawable(android.R.drawable.ic_menu_info_details, null)).setContent(new TabHost.TabContentFactory() {

            @Override
            public View createTabContent(String tag) {
                return new LinearLayout(getContext());
            }
        });
        tabHost.addTab(spec);
    } else {
        // for each child of the frameLayout, add a new TabSpec
        for (int i = 0; i < count; i++) {
            View child = content.getChildAt(i);
            String tabSpec = String.format("tab_spec%d", i + 1);
            // child cannot be null.
            @SuppressWarnings("ConstantConditions") int id = child.getId();
            @SuppressWarnings("deprecation") Pair<ResourceType, String> resource = layoutlibCallback.resolveResourceId(id);
            String name;
            if (resource != null) {
                name = resource.getSecond();
            } else {
                // default name if id is unresolved.
                name = String.format("Tab %d", i + 1);
            }
            tabHost.addTab(tabHost.newTabSpec(tabSpec).setIndicator(name).setContent(id));
        }
    }
}
Also used : TabHost(android.widget.TabHost) ResourceType(com.android.resources.ResourceType) TabWidget(android.widget.TabWidget) MenuView(com.android.internal.view.menu.MenuView) View(android.view.View) AdapterView(android.widget.AdapterView) ActionMenuItemView(com.android.internal.view.menu.ActionMenuItemView) IconMenuItemView(com.android.internal.view.menu.IconMenuItemView) ListView(android.widget.ListView) ListMenuItemView(com.android.internal.view.menu.ListMenuItemView) AbsListView(android.widget.AbsListView) ActionMenuView(android.widget.ActionMenuView) ExpandableListView(android.widget.ExpandableListView) TabSpec(android.widget.TabHost.TabSpec) FrameLayout(android.widget.FrameLayout) LinearLayout(android.widget.LinearLayout)

Example 43 with LinearLayout

use of android.widget.LinearLayout in project platform_frameworks_base by android.

the class ActionBarView method setNavigationMode.

public void setNavigationMode(int mode) {
    final int oldMode = mNavigationMode;
    if (mode != oldMode) {
        switch(oldMode) {
            case ActionBar.NAVIGATION_MODE_LIST:
                if (mListNavLayout != null) {
                    removeView(mListNavLayout);
                }
                break;
            case ActionBar.NAVIGATION_MODE_TABS:
                if (mTabScrollView != null && mIncludeTabs) {
                    removeView(mTabScrollView);
                }
        }
        switch(mode) {
            case ActionBar.NAVIGATION_MODE_LIST:
                if (mSpinner == null) {
                    mSpinner = new Spinner(mContext, null, com.android.internal.R.attr.actionDropDownStyle);
                    mSpinner.setId(com.android.internal.R.id.action_bar_spinner);
                    mListNavLayout = new LinearLayout(mContext, null, com.android.internal.R.attr.actionBarTabBarStyle);
                    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
                    params.gravity = Gravity.CENTER;
                    mListNavLayout.addView(mSpinner, params);
                }
                if (mSpinner.getAdapter() != mSpinnerAdapter) {
                    mSpinner.setAdapter(mSpinnerAdapter);
                }
                mSpinner.setOnItemSelectedListener(mNavItemSelectedListener);
                addView(mListNavLayout);
                break;
            case ActionBar.NAVIGATION_MODE_TABS:
                if (mTabScrollView != null && mIncludeTabs) {
                    addView(mTabScrollView);
                }
                break;
        }
        mNavigationMode = mode;
        requestLayout();
    }
}
Also used : Spinner(android.widget.Spinner) LinearLayout(android.widget.LinearLayout)

Example 44 with LinearLayout

use of android.widget.LinearLayout in project platform_frameworks_base by android.

the class ListItemFactory method horizontalButtonSlots.

/**
     * Create a horizontal linear layout divided into thirds (with some margins
     * separating the thirds), filled with buttons into some slots.
     * @param context The context.
     * @param desiredHeight The height of the LL.
     * @param slots Which slots to fill with buttons.
     * @return The linear layout.
     */
public static View horizontalButtonSlots(Context context, int desiredHeight, Slot... slots) {
    final LinearLayout ll = new LinearLayout(context);
    ll.setOrientation(LinearLayout.HORIZONTAL);
    final LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, desiredHeight);
    lp.setMargins(10, 0, 10, 0);
    lp.weight = 0.33f;
    boolean left = false;
    boolean middle = false;
    boolean right = false;
    for (Slot slot : slots) {
        switch(slot) {
            case Left:
                left = true;
                break;
            case Middle:
                middle = true;
                break;
            case Right:
                right = true;
                break;
        }
    }
    if (left) {
        final Button button = new Button(context);
        button.setText("left");
        ll.addView(button, lp);
    } else {
        ll.addView(new View(context), lp);
    }
    if (middle) {
        final Button button = new Button(context);
        button.setText("center");
        ll.addView(button, lp);
    } else {
        ll.addView(new View(context), lp);
    }
    if (right) {
        final Button button = new Button(context);
        button.setText("right");
        ll.addView(button, lp);
    } else {
        ll.addView(new View(context), lp);
    }
    return ll;
}
Also used : Button(android.widget.Button) TextView(android.widget.TextView) View(android.view.View) AbsListView(android.widget.AbsListView) LinearLayout(android.widget.LinearLayout)

Example 45 with LinearLayout

use of android.widget.LinearLayout in project platform_frameworks_base by android.

the class ListItemFactory method doubleText.

/**
     * Create a text view ready to be a list item.
     *
     * @param position      The position within the list.
     * @param context       The context.
     * @param text          The text of the button
     * @param desiredHeight The desired height of the button
     * @return The created view.
     */
public static View doubleText(int position, Context context, String text, int desiredHeight) {
    final LinearLayout ll = new LinearLayout(context);
    ll.setOrientation(LinearLayout.HORIZONTAL);
    final AbsListView.LayoutParams lp = new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, desiredHeight);
    ll.setLayoutParams(lp);
    ll.setId(position);
    TextView t1 = new TextView(context);
    t1.setHeight(desiredHeight);
    t1.setText(text);
    t1.setGravity(Gravity.START | Gravity.CENTER_VERTICAL);
    final ViewGroup.LayoutParams lp1 = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1.0f);
    ll.addView(t1, lp1);
    TextView t2 = new TextView(context);
    t2.setHeight(desiredHeight);
    t2.setText(text);
    t2.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL);
    final ViewGroup.LayoutParams lp2 = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1.0f);
    ll.addView(t2, lp2);
    ll.setTag("double");
    return ll;
}
Also used : ViewGroup(android.view.ViewGroup) AbsListView(android.widget.AbsListView) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout)

Aggregations

LinearLayout (android.widget.LinearLayout)1205 View (android.view.View)473 TextView (android.widget.TextView)455 ViewGroup (android.view.ViewGroup)203 ImageView (android.widget.ImageView)196 Button (android.widget.Button)167 ScrollView (android.widget.ScrollView)125 ListView (android.widget.ListView)100 LayoutInflater (android.view.LayoutInflater)90 FrameLayout (android.widget.FrameLayout)85 Context (android.content.Context)80 AdapterView (android.widget.AdapterView)74 EditText (android.widget.EditText)74 Intent (android.content.Intent)66 AbsListView (android.widget.AbsListView)58 LayoutParams (android.widget.LinearLayout.LayoutParams)48 RelativeLayout (android.widget.RelativeLayout)48 Bitmap (android.graphics.Bitmap)46 OnClickListener (android.view.View.OnClickListener)44 Drawable (android.graphics.drawable.Drawable)42