Search in sources :

Example 6 with LayoutParams

use of android.view.ViewGroup.LayoutParams in project android_frameworks_base by ParanoidAndroid.

the class RenderSessionImpl method inflate.

/**
     * Inflates the layout.
     * <p>
     * {@link #acquire(long)} must have been called before this.
     *
     * @throws IllegalStateException if the current context is different than the one owned by
     *      the scene, or if {@link #init(long)} was not called.
     */
public Result inflate() {
    checkLock();
    try {
        SessionParams params = getParams();
        HardwareConfig hardwareConfig = params.getHardwareConfig();
        BridgeContext context = getContext();
        // the view group that receives the window background.
        ViewGroup backgroundView = null;
        if (mWindowIsFloating || params.isForceNoDecor()) {
            backgroundView = mViewRoot = mContentRoot = new FrameLayout(context);
        } else {
            if (hasSoftwareButtons() && mNavigationBarOrientation == LinearLayout.VERTICAL) {
                /*
                     * This is a special case where the navigation bar is on the right.
                       +-------------------------------------------------+---+
                       | Status bar (always)                             |   |
                       +-------------------------------------------------+   |
                       | (Layout with background drawable)               |   |
                       | +---------------------------------------------+ |   |
                       | | Title/Action bar (optional)                 | |   |
                       | +---------------------------------------------+ |   |
                       | | Content, vertical extending                 | |   |
                       | |                                             | |   |
                       | +---------------------------------------------+ |   |
                       +-------------------------------------------------+---+

                       So we create a horizontal layout, with the nav bar on the right,
                       and the left part is the normal layout below without the nav bar at
                       the bottom
                     */
                LinearLayout topLayout = new LinearLayout(context);
                mViewRoot = topLayout;
                topLayout.setOrientation(LinearLayout.HORIZONTAL);
                try {
                    NavigationBar navigationBar = new NavigationBar(context, hardwareConfig.getDensity(), LinearLayout.VERTICAL);
                    navigationBar.setLayoutParams(new LinearLayout.LayoutParams(mNavigationBarSize, LayoutParams.MATCH_PARENT));
                    topLayout.addView(navigationBar);
                } catch (XmlPullParserException e) {
                }
            }
            /*
                 * we're creating the following layout
                 *
                   +-------------------------------------------------+
                   | Status bar (always)                             |
                   +-------------------------------------------------+
                   | (Layout with background drawable)               |
                   | +---------------------------------------------+ |
                   | | Title/Action bar (optional)                 | |
                   | +---------------------------------------------+ |
                   | | Content, vertical extending                 | |
                   | |                                             | |
                   | +---------------------------------------------+ |
                   +-------------------------------------------------+
                   | Navigation bar for soft buttons, maybe see above|
                   +-------------------------------------------------+

                 */
            LinearLayout topLayout = new LinearLayout(context);
            topLayout.setOrientation(LinearLayout.VERTICAL);
            // if we don't already have a view root this is it
            if (mViewRoot == null) {
                mViewRoot = topLayout;
            } else {
                LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
                layoutParams.weight = 1;
                topLayout.setLayoutParams(layoutParams);
                // this is the case of soft buttons + vertical bar.
                // this top layout is the first layout in the horizontal layout. see above)
                mViewRoot.addView(topLayout, 0);
            }
            if (mStatusBarSize > 0) {
                // system bar
                try {
                    StatusBar systemBar = new StatusBar(context, hardwareConfig.getDensity());
                    systemBar.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, mStatusBarSize));
                    topLayout.addView(systemBar);
                } catch (XmlPullParserException e) {
                }
            }
            LinearLayout backgroundLayout = new LinearLayout(context);
            backgroundView = backgroundLayout;
            backgroundLayout.setOrientation(LinearLayout.VERTICAL);
            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
            layoutParams.weight = 1;
            backgroundLayout.setLayoutParams(layoutParams);
            topLayout.addView(backgroundLayout);
            // if the theme says no title/action bar, then the size will be 0
            if (mActionBarSize > 0) {
                try {
                    FakeActionBar actionBar = new FakeActionBar(context, hardwareConfig.getDensity(), params.getAppLabel(), params.getAppIcon());
                    actionBar.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, mActionBarSize));
                    backgroundLayout.addView(actionBar);
                } catch (XmlPullParserException e) {
                }
            } else if (mTitleBarSize > 0) {
                try {
                    TitleBar titleBar = new TitleBar(context, hardwareConfig.getDensity(), params.getAppLabel());
                    titleBar.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, mTitleBarSize));
                    backgroundLayout.addView(titleBar);
                } catch (XmlPullParserException e) {
                }
            }
            // content frame
            mContentRoot = new FrameLayout(context);
            layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
            layoutParams.weight = 1;
            mContentRoot.setLayoutParams(layoutParams);
            backgroundLayout.addView(mContentRoot);
            if (mNavigationBarOrientation == LinearLayout.HORIZONTAL && mNavigationBarSize > 0) {
                // system bar
                try {
                    NavigationBar navigationBar = new NavigationBar(context, hardwareConfig.getDensity(), LinearLayout.HORIZONTAL);
                    navigationBar.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, mNavigationBarSize));
                    topLayout.addView(navigationBar);
                } catch (XmlPullParserException e) {
                }
            }
        }
        // Sets the project callback (custom view loader) to the fragment delegate so that
        // it can instantiate the custom Fragment.
        Fragment_Delegate.setProjectCallback(params.getProjectCallback());
        View view = mInflater.inflate(mBlockParser, mContentRoot);
        // done with the parser, pop it.
        context.popParser();
        Fragment_Delegate.setProjectCallback(null);
        // set the AttachInfo on the root view.
        AttachInfo_Accessor.setAttachInfo(mViewRoot);
        // post-inflate process. For now this supports TabHost/TabWidget
        postInflateProcess(view, params.getProjectCallback());
        // get the background drawable
        if (mWindowBackground != null && backgroundView != null) {
            Drawable d = ResourceHelper.getDrawable(mWindowBackground, context);
            backgroundView.setBackground(d);
        }
        return SUCCESS.createResult();
    } catch (PostInflateException e) {
        return ERROR_INFLATION.createResult(e.getMessage(), e);
    } catch (Throwable e) {
        // get the real cause of the exception.
        Throwable t = e;
        while (t.getCause() != null) {
            t = t.getCause();
        }
        return ERROR_INFLATION.createResult(t.getMessage(), t);
    }
}
Also used : SessionParams(com.android.ide.common.rendering.api.SessionParams) HardwareConfig(com.android.ide.common.rendering.api.HardwareConfig) MarginLayoutParams(android.view.ViewGroup.MarginLayoutParams) LayoutParams(android.view.ViewGroup.LayoutParams) ViewGroup(android.view.ViewGroup) Drawable(android.graphics.drawable.Drawable) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) StatusBar(com.android.layoutlib.bridge.bars.StatusBar) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) ExpandableListView(android.widget.ExpandableListView) NavigationBar(com.android.layoutlib.bridge.bars.NavigationBar) FrameLayout(android.widget.FrameLayout) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) LinearLayout(android.widget.LinearLayout) FakeActionBar(com.android.layoutlib.bridge.bars.FakeActionBar) TitleBar(com.android.layoutlib.bridge.bars.TitleBar)

Example 7 with LayoutParams

use of android.view.ViewGroup.LayoutParams in project HoloEverywhere by Prototik.

the class _HoloActivity method requestDecorView.

private boolean requestDecorView(View view, LayoutParams params, int layoutRes) {
    if (mDecorView != null) {
        return true;
    }
    mDecorView = new ActivityDecorView();
    mDecorView.setId(android.R.id.content);
    mDecorView.setProvider(this);
    if (view != null) {
        mDecorView.addView(view, params);
    } else if (layoutRes > 0) {
        getThemedLayoutInflater().inflate(layoutRes, mDecorView, true);
    }
    final LayoutParams p = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    performAddonAction(new AddonCallback<IAddonActivity>() {

        @Override
        public boolean action(IAddonActivity addon) {
            return addon.installDecorView(mDecorView, p);
        }

        @Override
        public void justPost() {
            _HoloActivity.super.setContentView(mDecorView, p);
        }
    });
    return false;
}
Also used : LayoutParams(android.view.ViewGroup.LayoutParams) IAddonActivity(org.holoeverywhere.addon.IAddonActivity)

Example 8 with LayoutParams

use of android.view.ViewGroup.LayoutParams in project HoloEverywhere by Prototik.

the class Dialog method requestDecorView.

private boolean requestDecorView(View view, LayoutParams params, int layoutRes) {
    if (mDecorView != null) {
        return true;
    }
    mDecorView = new WindowDecorView(getContext());
    mDecorView.setId(android.R.id.content);
    mDecorView.setProvider(this);
    if (view != null) {
        mDecorView.addView(view, params);
    } else if (layoutRes > 0) {
        getLayoutInflater().inflate(layoutRes, mDecorView, true);
    }
    getWindow().setContentView(mDecorView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    return false;
}
Also used : LayoutParams(android.view.ViewGroup.LayoutParams) WindowDecorView(org.holoeverywhere.widget.WindowDecorView)

Example 9 with LayoutParams

use of android.view.ViewGroup.LayoutParams in project Anki-Android by Ramblurr.

the class StudyOptionsFragment method updateChart.

private void updateChart(double[][] serieslist) {
    if (mSmallChart != null) {
        Resources res = getResources();
        XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
        XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
        XYSeriesRenderer r = new XYSeriesRenderer();
        r.setColor(res.getColor(R.color.stats_young));
        renderer.addSeriesRenderer(r);
        r = new XYSeriesRenderer();
        r.setColor(res.getColor(R.color.stats_mature));
        renderer.addSeriesRenderer(r);
        for (int i = 1; i < serieslist.length; i++) {
            XYSeries series = new XYSeries("");
            for (int j = 0; j < serieslist[i].length; j++) {
                series.add(serieslist[0][j], serieslist[i][j]);
            }
            dataset.addSeries(series);
        }
        renderer.setBarSpacing(0.4);
        renderer.setShowLegend(false);
        renderer.setLabelsTextSize(13);
        renderer.setXAxisMin(-0.5);
        renderer.setXAxisMax(7.5);
        renderer.setYAxisMin(0);
        renderer.setGridColor(Color.LTGRAY);
        renderer.setShowGrid(true);
        renderer.setBackgroundColor(Color.WHITE);
        renderer.setMarginsColor(Color.WHITE);
        renderer.setAxesColor(Color.BLACK);
        renderer.setLabelsColor(Color.BLACK);
        renderer.setYLabelsColor(0, Color.BLACK);
        renderer.setYLabelsAngle(-90);
        renderer.setXLabelsColor(Color.BLACK);
        renderer.setXLabelsAlign(Align.CENTER);
        renderer.setYLabelsAlign(Align.CENTER);
        renderer.setZoomEnabled(false, false);
        // mRenderer.setMargins(new int[] { 15, 48, 30, 10 });
        renderer.setAntialiasing(true);
        renderer.setPanEnabled(true, false);
        GraphicalView chartView = ChartFactory.getBarChartView(getActivity(), dataset, renderer, BarChart.Type.STACKED);
        mSmallChart.addView(chartView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
        if (mDeckChart.getVisibility() == View.INVISIBLE) {
            mDeckChart.setVisibility(View.VISIBLE);
            mDeckChart.setAnimation(ViewAnimation.fade(ViewAnimation.FADE_IN, 500, 0));
        }
    }
}
Also used : XYSeries(org.achartengine.model.XYSeries) XYMultipleSeriesRenderer(org.achartengine.renderer.XYMultipleSeriesRenderer) LayoutParams(android.view.ViewGroup.LayoutParams) GraphicalView(org.achartengine.GraphicalView) XYSeriesRenderer(org.achartengine.renderer.XYSeriesRenderer) Resources(android.content.res.Resources) XYMultipleSeriesDataset(org.achartengine.model.XYMultipleSeriesDataset)

Example 10 with LayoutParams

use of android.view.ViewGroup.LayoutParams in project Anki-Android by Ramblurr.

the class ChartBuilder method onCreate.

// public void setRenderer(int type, int row) {
// Resources res = getResources();
// XYSeriesRenderer renderer = new XYSeriesRenderer();
// if (type <= 2) {
// switch (row) {
// case 0:
// renderer.setColor(res.getColor(R.color.statistics_due_young_cards));
// break;
// case 1:
// renderer.setColor(res.getColor(R.color.statistics_due_mature_cards));
// break;
// case 2:
// // renderer.setColor(res.getColor(R.color.statistics_due_failed_cards));
// break;
// }
// } else if (type == 3) {
// switch (row) {
// case 0:
// // renderer.setColor(res.getColor(R.color.statistics_reps_new_cards));
// break;
// case 1:
// renderer.setColor(res.getColor(R.color.statistics_reps_young_cards));
// break;
// case 2:
// renderer.setColor(res.getColor(R.color.statistics_reps_mature_cards));
// break;
// }
// } else {
// renderer.setColor(res.getColor(R.color.statistics_default));
// }
// mRenderer.addSeriesRenderer(renderer);
// }
@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.i(AnkiDroidApp.TAG, "ChartBuilder.OnCreate");
    Themes.applyTheme(this);
    super.onCreate(savedInstanceState);
    restorePreferences();
    Resources res = getResources();
    Stats stats = Stats.currentStats();
    if (stats != null) {
        mSeriesList = stats.getSeriesList();
        mMeta = stats.getMetaInfo();
    } else if (savedInstanceState != null) {
        int len = savedInstanceState.getInt("seriesListLen");
        mSeriesList = new double[len][];
        for (int i = 0; i < len; i++) {
            mSeriesList[i] = (double[]) savedInstanceState.getSerializable("seriesList" + i);
        }
        mMeta = (Object[]) savedInstanceState.getSerializable("meta");
    } else {
        finish();
    }
    String title = res.getString((Integer) mMeta[1]);
    boolean backwards = (Boolean) mMeta[2];
    int[] valueLabels = (int[]) mMeta[3];
    int[] barColors = (int[]) mMeta[4];
    int[] axisTitles = (int[]) mMeta[5];
    String subTitle = (String) mMeta[6];
    if (mSeriesList == null || mSeriesList[0].length < 2) {
        Log.i(AnkiDroidApp.TAG, "ChartBuilder - Data variable empty, closing chartbuilder");
        finish();
        return;
    }
    if (mFullScreen) {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
    }
    View mainView = getLayoutInflater().inflate(R.layout.statistics, null);
    setContentView(mainView);
    mainView.setBackgroundColor(Color.WHITE);
    mTitle = (TextView) findViewById(R.id.statistics_title);
    if (mChartView == null) {
        if (mFullScreen) {
            mTitle.setText(title);
            mTitle.setTextColor(Color.BLACK);
        } else {
            setTitle(title);
            AnkiDroidApp.getCompat().setSubtitle(this, subTitle);
            mTitle.setVisibility(View.GONE);
        }
        for (int i = 1; i < mSeriesList.length; i++) {
            XYSeries series = new XYSeries(res.getString(valueLabels[i - 1]));
            for (int j = 0; j < mSeriesList[i].length; j++) {
                series.add(mSeriesList[0][j], mSeriesList[i][j]);
            }
            mDataset.addSeries(series);
            XYSeriesRenderer renderer = new XYSeriesRenderer();
            renderer.setColor(res.getColor(barColors[i - 1]));
            mRenderer.addSeriesRenderer(renderer);
        }
        if (mSeriesList.length == 1) {
            mRenderer.setShowLegend(false);
        }
        if (backwards) {
            mPan = new double[] { mSeriesList[0][0] - 0.5, 0.5 };
        } else {
            mPan = new double[] { -0.5, mSeriesList[0][mSeriesList[0].length - 1] + 0.5 };
        }
        mRenderer.setLegendTextSize(17);
        mRenderer.setBarSpacing(0.4);
        mRenderer.setLegendHeight(60);
        mRenderer.setAxisTitleTextSize(17);
        mRenderer.setLabelsTextSize(17);
        mRenderer.setXAxisMin(mPan[0]);
        mRenderer.setXAxisMax(mPan[1]);
        mRenderer.setYAxisMin(0);
        mRenderer.setGridColor(Color.LTGRAY);
        mRenderer.setShowGrid(true);
        mRenderer.setXTitle(res.getStringArray(R.array.due_x_axis_title)[axisTitles[0]]);
        mRenderer.setYTitle(res.getString(axisTitles[1]));
        mRenderer.setBackgroundColor(Color.WHITE);
        mRenderer.setMarginsColor(Color.WHITE);
        mRenderer.setAxesColor(Color.BLACK);
        mRenderer.setLabelsColor(Color.BLACK);
        mRenderer.setYLabelsColor(0, Color.BLACK);
        mRenderer.setYLabelsAngle(-90);
        mRenderer.setXLabelsColor(Color.BLACK);
        mRenderer.setXLabelsAlign(Align.CENTER);
        mRenderer.setYLabelsAlign(Align.CENTER);
        mRenderer.setZoomEnabled(false, false);
        mRenderer.setMargins(new int[] { 15, 48, 30, 10 });
        mRenderer.setAntialiasing(true);
        mRenderer.setPanEnabled(true, false);
        mRenderer.setPanLimits(mPan);
        mChartView = ChartFactory.getBarChartView(this, mDataset, mRenderer, BarChart.Type.STACKED);
        LinearLayout layout = (LinearLayout) findViewById(R.id.chart);
        layout.addView(mChartView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    } else {
        mChartView.repaint();
    }
    gestureDetector = new GestureDetector(new MyGestureDetector());
    mChartView.setOnTouchListener(new View.OnTouchListener() {

        public boolean onTouch(View v, MotionEvent event) {
            if (gestureDetector.onTouchEvent(event)) {
                return true;
            }
            return false;
        }
    });
}
Also used : XYSeries(org.achartengine.model.XYSeries) LayoutParams(android.view.ViewGroup.LayoutParams) GestureDetector(android.view.GestureDetector) View(android.view.View) GraphicalView(org.achartengine.GraphicalView) TextView(android.widget.TextView) MotionEvent(android.view.MotionEvent) Stats(com.ichi2.libanki.Stats) XYSeriesRenderer(org.achartengine.renderer.XYSeriesRenderer) Resources(android.content.res.Resources) LinearLayout(android.widget.LinearLayout)

Aggregations

LayoutParams (android.view.ViewGroup.LayoutParams)263 TextView (android.widget.TextView)54 View (android.view.View)50 ViewGroup (android.view.ViewGroup)50 FrameLayout (android.widget.FrameLayout)35 LinearLayout (android.widget.LinearLayout)32 ImageView (android.widget.ImageView)30 Test (org.junit.Test)26 ListView (android.widget.ListView)22 ScrollView (android.widget.ScrollView)22 Paint (android.graphics.Paint)21 MarginLayoutParams (android.view.ViewGroup.MarginLayoutParams)19 Context (android.content.Context)18 AdapterView (android.widget.AdapterView)17 RelativeLayout (android.widget.RelativeLayout)14 DisplayMetrics (android.util.DisplayMetrics)12 CheckedTextView (android.widget.CheckedTextView)12 Rect (android.graphics.Rect)9 ViewParent (android.view.ViewParent)9 TypedArray (android.content.res.TypedArray)8