Example usage for android.widget LinearLayout HORIZONTAL

List of usage examples for android.widget LinearLayout HORIZONTAL

Introduction

In this page you can find the example usage for android.widget LinearLayout HORIZONTAL.

Prototype

int HORIZONTAL

To view the source code for android.widget LinearLayout HORIZONTAL.

Click Source Link

Usage

From source file:com.googlecode.android_scripting.activity.Main.java

protected void initializeViews() {
    LinearLayout layout = new LinearLayout(this);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    layout.setGravity(Gravity.CENTER_HORIZONTAL);
    TextView textview = new TextView(this);
    textview.setText(" PhpForAndroid " + version);
    ImageView imageView = new ImageView(this);
    imageView.setImageDrawable(getResources().getDrawable(R.drawable.pfa));
    layout.addView(imageView);//www.ja  v  a  2s  . c o m
    mButton = new Button(this);
    mAboutButton = new Button(this);
    MarginLayoutParams marginParams = new MarginLayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT);
    final float scale = getResources().getDisplayMetrics().density;
    int marginPixels = (int) (MARGIN_DIP * scale + 0.5f);
    marginParams.setMargins(marginPixels, marginPixels, marginPixels, marginPixels);
    mButton.setLayoutParams(marginParams);
    mAboutButton.setLayoutParams(marginParams);
    layout.addView(textview);
    layout.addView(mButton);
    layout.addView(mAboutButton);

    mProgressLayout = new LinearLayout(this);
    mProgressLayout.setOrientation(LinearLayout.HORIZONTAL);
    mProgressLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    mProgressLayout.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);

    LinearLayout bottom = new LinearLayout(this);
    bottom.setOrientation(LinearLayout.HORIZONTAL);
    bottom.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    bottom.setGravity(Gravity.CENTER_VERTICAL);
    mProgressLayout.addView(bottom);

    TextView message = new TextView(this);
    message.setText("   In Progress...");
    message.setTextSize(20);
    message.setTypeface(Typeface.DEFAULT_BOLD);
    message.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    ProgressBar bar = new ProgressBar(this);
    bar.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    bottom.addView(bar);
    bottom.addView(message);
    mProgressLayout.setVisibility(View.INVISIBLE);

    layout.addView(mProgressLayout);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setProgressBarIndeterminateVisibility(false);

    setContentView(layout);
}

From source file:au.com.cybersearch2.classyfy.TitleSearchResultsActivityTest.java

@Test
public void test_dynamic_layout() throws Exception {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSSSS", new Locale("en", "AU"));
    RecordCategory recordCategory = new RecordCategory();
    Date created = sdf.parse("2014-02-05 18:45:46.145000");
    Date modified = sdf.parse("2014-02-12 11:55:23.121000");
    recordCategory.setCreated(created);/*from   ww  w  . j av  a 2 s  .  c  om*/
    recordCategory.setModified(modified);
    recordCategory.setCreator("admin");
    recordCategory.setDescription("Information Technology");
    recordCategory.setIdentifier("2014-1391586274589");
    FieldDescriptor descriptionField = new FieldDescriptor();
    descriptionField.setOrder(1);
    descriptionField.setName("description");
    descriptionField.setTitle("Description");
    FieldDescriptor createdField = new FieldDescriptor();
    createdField.setOrder(2);
    createdField.setName("created");
    createdField.setTitle("Created");
    FieldDescriptor creatorField = new FieldDescriptor();
    creatorField.setOrder(3);
    creatorField.setName("creator");
    creatorField.setTitle("Creator");
    FieldDescriptor modifiedField = new FieldDescriptor();
    modifiedField.setOrder(4);
    modifiedField.setName("modified");
    modifiedField.setTitle("Modified");
    FieldDescriptor modifier = new FieldDescriptor();
    modifier.setOrder(5);
    modifier.setName("modifier");
    modifier.setTitle("Modifier");
    FieldDescriptor identifierField = new FieldDescriptor();
    identifierField.setOrder(6);
    identifierField.setName("identifier");
    identifierField.setTitle("Identifier");
    Set<FieldDescriptor> fieldSet = new TreeSet<FieldDescriptor>();
    fieldSet.add(descriptionField);
    fieldSet.add(createdField);
    fieldSet.add(creatorField);
    fieldSet.add(modifiedField);
    fieldSet.add(modifier);
    fieldSet.add(identifierField);
    @SuppressWarnings("unchecked")
    Map<String, Object> valueMap = PropertyUtils.describe(recordCategory);
    titleSearchResultsActivity = (TitleSearchResultsActivity) controller.create().get();
    LinearLayout dynamicLayout = new LinearLayout(titleSearchResultsActivity);
    dynamicLayout.setOrientation(LinearLayout.VERTICAL);
    int layoutHeight = LinearLayout.LayoutParams.MATCH_PARENT;
    int layoutWidth = LinearLayout.LayoutParams.WRAP_CONTENT;
    for (FieldDescriptor descriptor : fieldSet) {
        Object value = valueMap.get(descriptor.getName());
        if (value == null)
            continue;
        TextView titleView = new TextView(titleSearchResultsActivity);
        titleView.setText(descriptor.getTitle());
        TextView valueView = new TextView(titleSearchResultsActivity);
        valueView.setText(value.toString());
        LinearLayout fieldLayout = new LinearLayout(titleSearchResultsActivity);
        fieldLayout.setOrientation(LinearLayout.HORIZONTAL);
        fieldLayout.addView(titleView, new LinearLayout.LayoutParams(layoutWidth, layoutHeight));
        fieldLayout.addView(valueView, new LinearLayout.LayoutParams(layoutWidth, layoutHeight));
    }
}

From source file:activities.Activity_Main.java

/** Called when the activity is first created. */
@Override//  ww w  . j  av a2 s  . co  m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    myself = this;
    setContentView(R.layout.activity_home);

    SP_params = PreferenceManager.getDefaultSharedPreferences(this);
    SP_prefEditor = SP_params.edit();
    Tracer = tracerengine.getInstance(SP_params);

    //Added by Doume
    File storage = new File(Environment.getExternalStorageDirectory() + "/domodroid/.conf/");
    if (!storage.exists())
        storage.mkdirs();
    //Configure Tracer tool initial state
    File logpath = new File(Environment.getExternalStorageDirectory() + "/domodroid/.log/");
    if (!logpath.exists())
        logpath.mkdirs();

    String currlogpath = SP_params.getString("LOGNAME", "");
    if (currlogpath.equals("")) {
        //Not yet existing prefs : Configure debugging by default, to configure Tracer
        currlogpath = Environment.getExternalStorageDirectory() + "/domodroid/.log/";
        SP_prefEditor.putString("LOGPATH", currlogpath);
        SP_prefEditor.putString("LOGNAME", "Domodroid.txt");
        SP_prefEditor.putBoolean("SYSTEMLOG", false);
        SP_prefEditor.putBoolean("TEXTLOG", false);
        SP_prefEditor.putBoolean("SCREENLOG", false);
        SP_prefEditor.putBoolean("LOGCHANGED", true);
        SP_prefEditor.putBoolean("LOGAPPEND", false);
    } else {
        SP_prefEditor.putBoolean("LOGCHANGED", true); //To force Tracer to consider current settings
    }
    //prefEditor.putBoolean("SYSTEMLOG", false);      // For tests : no system logs....
    SP_prefEditor.putBoolean("SYSTEMLOG", true); // For tests : with system logs....

    SP_prefEditor.commit();

    Tracer.set_profile(SP_params);
    // Create .nomedia file, that will prevent Android image gallery from showing domodroid file
    String nomedia = Environment.getExternalStorageDirectory() + "/domodroid/.nomedia";
    try {
        if (!(new File(nomedia).exists())) {
            new FileOutputStream(nomedia).close();
        }
    } catch (Exception e) {
    }

    appname = (ImageView) findViewById(R.id.app_name);

    LoadSelections();

    // Prepare a listener to know when a sync dialog is closed...
    if (sync_listener == null) {
        sync_listener = new DialogInterface.OnDismissListener() {

            public void onDismiss(DialogInterface dialog) {

                Tracer.d(mytag, "sync dialog has been closed !");

                // Is it success or fail ?
                if (((Dialog_Synchronize) dialog).need_refresh) {
                    // Sync has been successful : Force to refresh current main view
                    Tracer.d(mytag, "sync dialog requires a refresh !");
                    reload = true; // Sync being done, consider shared prefs are OK
                    VG_parent.removeAllViews();
                    if (WU_widgetUpdate != null) {
                        WU_widgetUpdate.resync();
                    } else {
                        Tracer.i(mytag + ".onCreate", "WidgetUpdate is null startCacheengine!");
                        startCacheEngine();
                    }
                    Bundle b = new Bundle();
                    //Notify sync complete to parent Dialog
                    b.putInt("id", 0);
                    b.putString("type", "root");
                    Message msg = new Message();
                    msg.setData(b);
                    if (widgetHandler != null)
                        widgetHandler.sendMessage(msg); // That should force to refresh Views
                    /* */
                    if (WU_widgetUpdate != null) {
                        WU_widgetUpdate.Disconnect(0); //That should disconnect all opened widgets from cache engine
                        //widgetUpdate.dump_cache();   //For debug
                        dont_kill = true; // to avoid engines kill when onDestroy()
                    }
                    onResume();
                } else {
                    Tracer.d(mytag, "sync dialog end with no refresh !");

                }
                ((Dialog_Synchronize) dialog).need_refresh = false;
            }
        };
    }

    //update thread
    sbanim = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == 0) {
                appname.setImageDrawable(getResources().getDrawable(R.drawable.app_name2));
            } else if (msg.what == 1) {
                appname.setImageDrawable(getResources().getDrawable(R.drawable.app_name3));
            } else if (msg.what == 2) {
                appname.setImageDrawable(getResources().getDrawable(R.drawable.app_name1));
            } else if (msg.what == 3) {
                appname.setImageDrawable(getResources().getDrawable(R.drawable.app_name4));
            } else if (msg.what == 8000) {
                Tracer.e(mytag, "Request to display message : 8000");
                /*
                if(dialog_message == null) {
                   Create_message_box();
                }
                dialog_message.setMessage("Starting cache engine...");
                dialog_message.show();
                        
                */
            } else if (msg.what == 8999) {
                //Cache engine is ready for use....
                if (Tracer != null)
                    Tracer.e(mytag, "Cache engine has notified it's ready !");
                cache_ready = true;
                if (end_of_init_requested)
                    end_of_init();
                PG_dialog_message.dismiss();
            }
        }
    };

    //power management
    final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    this.PM_WakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "");
    this.PM_WakeLock.acquire();

    //titlebar
    final FrameLayout titlebar = (FrameLayout) findViewById(R.id.TitleBar);
    titlebar.setBackgroundDrawable(Gradients_Manager.LoadDrawable("title", 40));

    //Parent view
    VG_parent = (ViewGroup) findViewById(R.id.home_container);

    LL_house_map = new LinearLayout(this);
    LL_house_map
            .setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    LL_house_map.setOrientation(LinearLayout.HORIZONTAL);
    LL_house_map.setPadding(5, 5, 5, 5);

    house = new Basic_Graphical_zone(getApplicationContext(), 0, Graphics_Manager.Names_Agent(this, "House"),
            "", "house", 0, "", null);
    house.setPadding(0, 0, 5, 0);
    map = new Basic_Graphical_zone(getApplicationContext(), 0, Graphics_Manager.Names_Agent(this, "Map"), "",
            "map", 0, "", null);
    map.setPadding(5, 0, 0, 0);

    LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.FILL_PARENT, 1.0f);

    house.setLayoutParams(param);
    house.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if (SP_params.getBoolean("SYNC", false)) {
                loadWigets(0, "root");
                historyPosition++;
                history.add(historyPosition, new String[] { "0", "root" });
            } else {
                if (AD_notSyncAlert == null)
                    createAlert();
                AD_notSyncAlert.show();
            }
        }
    });

    map.setLayoutParams(param);
    map.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if (SP_params.getBoolean("SYNC", false)) {
                //dont_freeze=true;      //To avoid WidgetUpdate engine freeze
                Tracer.w(mytag, "Before call to Map, Disconnect widgets from engine !");
                if (WU_widgetUpdate != null) {
                    WU_widgetUpdate.Disconnect(0); //That should disconnect all opened widgets from cache engine
                    //widgetUpdate.dump_cache();   //For debug
                    dont_kill = true; // to avoid engines kill when onDestroy()
                }
                INTENT_map = new Intent(Activity_Main.this, Activity_Map.class);
                Tracer.d(mytag, "Call to Map, run it now !");
                Tracer.Map_as_main = false;
                startActivity(INTENT_map);
            } else {
                if (AD_notSyncAlert == null)
                    createAlert();
                AD_notSyncAlert.show();
            }
        }
    });

    LL_house_map.addView(house);
    LL_house_map.addView(map);

    init_done = false;
    // Detect if it's the 1st use after installation...
    if (!SP_params.getBoolean("SPLASH", false)) {
        // Yes, 1st use !
        init_done = false;
        reload = false;
        if (backupprefs.exists()) {
            // A backup exists : Ask if reload it
            Tracer.v(mytag, "settings backup found after a fresh install...");

            DialogInterface.OnClickListener reload_listener = new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {
                    Tracer.e(mytag, "Reload dialog returns : " + which);
                    if (which == dialog.BUTTON_POSITIVE) {
                        reload = true;
                    } else if (which == dialog.BUTTON_NEGATIVE) {
                        reload = false;
                    }
                    check_answer();
                    dialog.dismiss();
                }
            };
            dialog_reload = new AlertDialog.Builder(this);
            dialog_reload.setMessage(getText(R.string.home_reload));
            dialog_reload.setTitle(getText(R.string.reload_title));
            dialog_reload.setPositiveButton(getText(R.string.reloadOK), reload_listener);
            dialog_reload.setNegativeButton(getText(R.string.reloadNO), reload_listener);
            dialog_reload.show();
            init_done = false; //A choice is pending : Rest of init has to be completed...
        } else {
            //No settings backup found
            Tracer.v(mytag, "no settings backup found after fresh install...");
            end_of_init_requested = true;
            // open server config view
            Intent helpI = new Intent(Activity_Main.this, Preference.class);
            startActivity(helpI);
        }
    } else {
        // It's not the 1st use after fresh install
        // This method will be followed by 'onResume()'
        end_of_init_requested = true;
    }
    if (SP_params.getBoolean("SYNC", false)) {
        //A config exists and a sync as been done by past.
        if (WU_widgetUpdate == null) {
            Tracer.i(mytag + ".onCreate", "Params splach is false and WidgetUpdate is null startCacheengine!");
            startCacheEngine();
        }

    }

    Tracer.e(mytag, "OnCreate() complete !");
    // End of onCreate (UIThread)
}

From source file:com.luseen.spacenavigation.SpaceNavigationView.java

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);

    /**//w  w w  .j ava 2  s.co  m
     * Restore current item index from savedInstance
     */
    restoreCurrentItem();

    /**
     * Trow exceptions if items size is greater than 4 or lesser than 2
     */
    if (spaceItems.size() < 2) {
        throw new NullPointerException("Your space item count must be greater than 1 ,"
                + " your current items count is : " + spaceItems.size());
    }

    if (spaceItems.size() > 4) {
        throw new IndexOutOfBoundsException(
                "Your items count maximum can be 4," + " your current items count is : " + spaceItems.size());
    }

    /**
     * Get left or right content width
     */
    contentWidth = (w - spaceNavigationHeight) / 2;

    /**
     * Removing all view for not being duplicated
     */
    removeAllViews();

    /**
     * Views initializations and customizing
     */
    RelativeLayout mainContent = new RelativeLayout(context);
    RelativeLayout centreBackgroundView = new RelativeLayout(context);

    LinearLayout leftContent = new LinearLayout(context);
    LinearLayout rightContent = new LinearLayout(context);

    BezierView centreContent = buildBezierView();

    FloatingActionButton fab = new FloatingActionButton(context);
    fab.setSize(FloatingActionButton.SIZE_NORMAL);
    fab.setBackgroundTintList(ColorStateList.valueOf(centreButtonColor));
    fab.setImageResource(centreButtonIcon);
    fab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            if (spaceOnClickListener != null)
                spaceOnClickListener.onCentreButtonClick();
        }
    });

    /**
     * Set fab layout params
     */
    LayoutParams fabParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    fabParams.addRule(RelativeLayout.CENTER_IN_PARENT);
    fabParams.setMargins(centreContentMargin, centreContentMargin, centreContentMargin, centreContentMargin);

    /**
     * Main content size
     */
    LayoutParams mainContentParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, mainContentHeight);
    mainContentParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);

    /**
     * Centre content size
     */
    LayoutParams centreContentParams = new LayoutParams(centreContentWight, spaceNavigationHeight);
    centreContentParams.addRule(RelativeLayout.CENTER_HORIZONTAL);

    /**
     * Centre Background View content size and position
     */
    LayoutParams centreBackgroundViewParams = new LayoutParams(centreContentWight, mainContentHeight);
    centreBackgroundViewParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
    centreBackgroundViewParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);

    /**
     * Left content size
     */
    LayoutParams leftContentParams = new LayoutParams(contentWidth, ViewGroup.LayoutParams.MATCH_PARENT);
    leftContentParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
    leftContentParams.addRule(LinearLayout.HORIZONTAL);

    /**
     * Right content size
     */
    LayoutParams rightContentParams = new LayoutParams(contentWidth, ViewGroup.LayoutParams.MATCH_PARENT);
    rightContentParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    rightContentParams.addRule(LinearLayout.HORIZONTAL);

    /**
     * Adding views background colors
     */
    leftContent.setBackgroundColor(spaceBackgroundColor);
    rightContent.setBackgroundColor(spaceBackgroundColor);
    centreBackgroundView.setBackgroundColor(spaceBackgroundColor);

    /**
     * Adding view to centreContent
     */
    centreContent.addView(fab, fabParams);

    /**
     * Adding views to mainContent
     */
    mainContent.addView(leftContent, leftContentParams);
    mainContent.addView(rightContent, rightContentParams);

    /**
     * Adding views to mainView
     */
    addView(centreBackgroundView, centreBackgroundViewParams);
    addView(centreContent, centreContentParams);
    addView(mainContent, mainContentParams);

    /**
     * Adding current space items to left and right content
     */
    addSpaceItems(leftContent, rightContent);

    /**
     * Redraw main view to make subviews visible
     */
    Utils.postRequestLayout(this);
}

From source file:com.example.fan.horizontalscrollview.PagerSlidingTabStrip.java

private void addRedDotTab(final int position, String title, int resId) {
    LinearLayout tabLayout = new LinearLayout(getContext());
    tabLayout.setOrientation(LinearLayout.HORIZONTAL);
    tabLayout.setGravity(Gravity.CENTER);
    TextView tab = new TextView(getContext());
    tab.setText(title);/*from   w ww  . j ava2  s . co  m*/
    tab.setFocusable(true);
    tab.setGravity(Gravity.CENTER);

    tab.setSingleLine();
    tab.setTextColor(getResources().getColorStateList(R.color.pst_tab_text_selector));
    tab.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18.0f);
    tabLayout.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (null != mOnPageClickedLisener) {
                mOnPageClickedLisener.onPageClicked(position);
            }
            pager.setCurrentItem(position);
        }
    });

    tabLayout.addView(tab, 0);
    ImageView tabImg = new ImageView(getContext());
    LinearLayout.LayoutParams tabImgParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    tabImgParams.setMargins(DeviceUtils.dip2px(getContext(), 5), DeviceUtils.dip2px(getContext(), 10), 0, 0);
    tabImgParams.gravity = Gravity.TOP;
    tabImg.setLayoutParams(tabImgParams);

    tabLayout.addView(tabImg, 1);
    tabsContainer.addView(tabLayout);
}

From source file:com.cssweb.android.quote.QuoteDetail.java

/**
 * ???//from   www . j  a va  2s  .  c  om
 */
private void initLoading() {
    LinearLayout layout = new LinearLayout(this);
    layout.setOrientation(LinearLayout.HORIZONTAL);
    ProgressBar progressBar = new ProgressBar(this);
    progressBar.setPadding(0, 0, 15, 0);
    LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    LayoutParams layoutParams2 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
            LinearLayout.LayoutParams.FILL_PARENT);
    layout.addView(progressBar, layoutParams);
    TextView textView = new TextView(this);
    textView.setText(getResources().getText(R.string.cjmx_loading));
    textView.setGravity(Gravity.CENTER_VERTICAL);
    layout.addView(textView, layoutParams2);
    layout.setGravity(Gravity.CENTER);
    loadingLayout = new LinearLayout(this);
    loadingLayout.addView(layout, layoutParams);
    loadingLayout.setGravity(Gravity.CENTER);
    table_1.addView(loadingLayout, 0);
}

From source file:com.example.fragmentdemo.views.PagerSlidingTabStrip.java

private void addTab(final int position, CharSequence title, int iconResId, int iLayoutResId, int iTextId,
        int iIconLocation) {
    // final View tabView = ((Activity) getContext()).getLayoutInflater()
    // .inflate(iLayoutResId, null);
    // TextView tab_text_textview = (TextView)
    // tabView.findViewById(iTextId);
    // tab_text_textview.setText(title);
    LinearLayout tabView = new LinearLayout(getContext());
    tabView.setGravity(Gravity.CENTER);/*from  www .ja va 2s. c  o  m*/
    TextView tab_text_textview = new TextView(getContext());
    tab_text_textview.setId(position);
    tab_text_textview.setText(title);
    tab_text_textview.setGravity(Gravity.CENTER_VERTICAL);
    tab_text_textview.setSingleLine();
    // tab_text_textview.setTextColor(tabTextColor);
    // tab_text_textview.setTextColor(getResources().getColor(R.color.indicator_tab_main_text_color));
    XmlPullParser xrp = getResources().getXml(tabTextColor);
    try {
        ColorStateList csl = ColorStateList.createFromXml(getResources(), xrp);

        if (tab_text_textview != null) {
            tab_text_textview.setTextColor(csl);
        }
    } catch (Exception e) {

    }
    tab_text_textview.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
    tab_text_textview.setTypeface(tabTypeface, tabTypefaceStyle);
    LinearLayout.LayoutParams lpText = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    if (iconResId != 0) {
        // tab_text_textview.setCompoundDrawablesWithIntrinsicBounds(
        // iconResId, 0, 0, 0);
        // Drawable mDrawable = ((Activity) getContext()).getResources()
        // .getDrawable(iconResId);
        // mDrawable.setBounds(0, 0, mDrawable.getMinimumWidth(),
        // mDrawable.getMinimumHeight());
        int iPandding = (int) ((Activity) getContext()).getResources().getDimension(R.dimen.common_padding);
        ImageView icon = new ImageView(getContext());
        icon.setImageResource(iconResId);
        icon.setScaleType(ScaleType.CENTER_INSIDE);
        LinearLayout.LayoutParams lpImage = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                iIconHeight);

        switch (iIconLocation) {
        case 1:
            // tab_text_textview.setCompoundDrawables(mDrawable, null, null,
            // null);
            tabView.setOrientation(LinearLayout.HORIZONTAL);
            // tabView.setGravity(Gravity.CENTER_VERTICAL);

            tabView.addView(icon, lpImage);
            lpText.leftMargin = iPandding;
            tabView.addView(tab_text_textview, lpText);
            break;
        case 2:
            // tab_text_textview.setCompoundDrawables(null, mDrawable, null,
            // null);
            tabView.setOrientation(LinearLayout.VERTICAL);
            // tabView.setGravity(Gravity.CENTER_HORIZONTAL);
            tabView.addView(icon, lpImage);
            lpText.topMargin = iPandding;
            tabView.addView(tab_text_textview, lpText);
            break;
        case 3:
            // tab_text_textview.setCompoundDrawables(null, null, mDrawable,
            // null);
            tabView.setOrientation(LinearLayout.HORIZONTAL);
            // tabView.setGravity(Gravity.CENTER_VERTICAL);
            tabView.addView(tab_text_textview, lpText);
            lpImage.leftMargin = iPandding;
            tabView.addView(icon, lpImage);
            break;
        case 4:
            // tab_text_textview.setCompoundDrawables(null, null, null,
            // mDrawable);
            tabView.setOrientation(LinearLayout.VERTICAL);
            // tabView.setGravity(Gravity.CENTER_HORIZONTAL);
            tabView.addView(tab_text_textview, lpText);
            lpImage.topMargin = iPandding;
            tabView.addView(icon, lpImage);
            break;
        default:
            // tab_text_textview.setCompoundDrawables(mDrawable, null, null,
            // null);
            tabView.setOrientation(LinearLayout.HORIZONTAL);
            // tabView.setGravity(Gravity.CENTER_VERTICAL);
            tabView.addView(icon, lpImage);
            lpText.leftMargin = iPandding;
            tabView.addView(tab_text_textview, lpText);
            break;
        }

        // tab_text_textview
        // .setCompoundDrawablePadding((int) ((Activity) getContext())
        // .getResources()
        // .getDimension(R.dimen.common_padding));

    } else {
        tabView.addView(tab_text_textview, lpText);
    }

    tabView.setFocusable(true);
    tabView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            pager.setCurrentItem(position);
        }
    });

    // tab_text_textview.setPadding(tabPadding, 0, tabPadding, 0);
    tabsContainer.addView(tabView, position, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams);
}

From source file:com.wangbb.naruto.app.view.PagerSlidingTabStrip.java

private void addTab(final int position, CharSequence title, int iconResId, int iLayoutResId, int iTextId,
        int iIconLocation) {
    // final View tabView = ((Activity) getContext()).getLayoutInflater()
    // .inflate(iLayoutResId, null);
    // TextView tab_text_textview = (TextView)
    // tabView.findViewById(iTextId);
    // tab_text_textview.setText(title);
    LinearLayout tabView = new LinearLayout(getContext());
    tabView.setGravity(Gravity.CENTER);/* w  w  w  . j a  v a 2 s.  c om*/
    TextView tab_text_textview = new TextView(getContext());
    tab_text_textview.setId(position);
    tab_text_textview.setText(title);
    tab_text_textview.setGravity(Gravity.CENTER_VERTICAL);
    tab_text_textview.setSingleLine();
    // tab_text_textview.setTextColor(tabTextColor);
    // tab_text_textview.setTextColor(getResources().getColor(R.color.indicator_tab_main_text_color));
    //      XmlPullParser xrp = getResources().getXml(tabTextColor);
    //      try {
    //         ColorStateList csl = ColorStateList.createFromXml(getResources(),
    //               xrp);

    //         if (tab_text_textview != null) {
    tab_text_textview.setTextColor(tabTextColor);
    //         }
    //      } catch (Exception e) {
    //
    //      }
    tab_text_textview.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
    tab_text_textview.setTypeface(tabTypeface, tabTypefaceStyle);
    LinearLayout.LayoutParams lpText = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    if (iconResId != 0) {
        // tab_text_textview.setCompoundDrawablesWithIntrinsicBounds(
        // iconResId, 0, 0, 0);
        // Drawable mDrawable = ((Activity) getContext()).getResources()
        // .getDrawable(iconResId);
        // mDrawable.setBounds(0, 0, mDrawable.getMinimumWidth(),
        // mDrawable.getMinimumHeight());
        int iPandding = (int) ((Activity) getContext()).getResources().getDimension(R.dimen.common_padding);
        ImageView icon = new ImageView(getContext());
        icon.setImageResource(iconResId);
        icon.setScaleType(ScaleType.CENTER_INSIDE);
        LinearLayout.LayoutParams lpImage = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                iIconHeight);

        switch (iIconLocation) {
        case 1:
            // tab_text_textview.setCompoundDrawables(mDrawable, null, null,
            // null);
            tabView.setOrientation(LinearLayout.HORIZONTAL);
            // tabView.setGravity(Gravity.CENTER_VERTICAL);

            tabView.addView(icon, lpImage);
            lpText.leftMargin = iPandding;
            tabView.addView(tab_text_textview, lpText);
            break;
        case 2:
            // tab_text_textview.setCompoundDrawables(null, mDrawable, null,
            // null);
            tabView.setOrientation(LinearLayout.VERTICAL);
            // tabView.setGravity(Gravity.CENTER_HORIZONTAL);
            tabView.addView(icon, lpImage);
            lpText.topMargin = iPandding;
            tabView.addView(tab_text_textview, lpText);
            break;
        case 3:
            // tab_text_textview.setCompoundDrawables(null, null, mDrawable,
            // null);
            tabView.setOrientation(LinearLayout.HORIZONTAL);
            // tabView.setGravity(Gravity.CENTER_VERTICAL);
            tabView.addView(tab_text_textview, lpText);
            lpImage.leftMargin = iPandding;
            tabView.addView(icon, lpImage);
            break;
        case 4:
            // tab_text_textview.setCompoundDrawables(null, null, null,
            // mDrawable);
            tabView.setOrientation(LinearLayout.VERTICAL);
            // tabView.setGravity(Gravity.CENTER_HORIZONTAL);
            tabView.addView(tab_text_textview, lpText);
            lpImage.topMargin = iPandding;
            tabView.addView(icon, lpImage);
            break;
        default:
            // tab_text_textview.setCompoundDrawables(mDrawable, null, null,
            // null);
            tabView.setOrientation(LinearLayout.HORIZONTAL);
            // tabView.setGravity(Gravity.CENTER_VERTICAL);
            tabView.addView(icon, lpImage);
            lpText.leftMargin = iPandding;
            tabView.addView(tab_text_textview, lpText);
            break;
        }

        // tab_text_textview
        // .setCompoundDrawablePadding((int) ((Activity) getContext())
        // .getResources()
        // .getDimension(R.dimen.common_padding));

    } else {
        tabView.addView(tab_text_textview, lpText);
    }

    tabView.setFocusable(true);
    tabView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            pager.setCurrentItem(position);
        }
    });

    // tab_text_textview.setPadding(tabPadding, 0, tabPadding, 0);
    tabsContainer.addView(tabView, position, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams);
}

From source file:com.nextgis.forestinspector.fragment.MapFragment.java

protected void fillStatusPanel(Location location) {
    if (!mShowStatusPanel) //mStatusPanel.getVisibility() == FrameLayout.INVISIBLE)
    {//from ww w . j ava  2  s . c  om
        return;
    }

    boolean needViewUpdate = true;
    boolean isCurrentOrientationOneLine = mStatusPanel.getChildCount() > 0
            && ((LinearLayout) mStatusPanel.getChildAt(0)).getOrientation() == LinearLayout.HORIZONTAL;

    View panel;
    if (!isCurrentOrientationOneLine) {
        panel = getActivity().getLayoutInflater().inflate(R.layout.status_panel_land, mStatusPanel, false);
        defineTextViews(panel);
    } else {
        panel = mStatusPanel.getChildAt(0);
        needViewUpdate = false;
    }

    fillTextViews(location);

    if (!isFitOneLine()) {
        panel = getActivity().getLayoutInflater().inflate(R.layout.status_panel, mStatusPanel, false);
        defineTextViews(panel);
        fillTextViews(location);
        needViewUpdate = true;
    }

    if (needViewUpdate) {
        mStatusPanel.removeAllViews();
        panel.getBackground().setAlpha(128);
        mStatusPanel.addView(panel);
    }
}

From source file:cz.metaverse.android.bilingualreader.ReaderActivity.java

/**
 * Called when the device configuration changes.
 *///from  w ww  . j  a v  a2s  .  co m
@Override
public void onConfigurationChanged(Configuration newConfig) {
    Log.d(LOG, LOG + ".onConfigurationChanged");
    super.onConfigurationChanged(newConfig);

    // Signal to the Governor that a runtime change has occurred.
    governor.onRuntimeChange();

    // Change the orientation of the PanelsLayout accordingly.
    LinearLayout panelsLayout = (LinearLayout) findViewById(R.id.PanelsLayout);
    if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
        panelsLayout.setOrientation(LinearLayout.VERTICAL);
    } else {
        panelsLayout.setOrientation(LinearLayout.HORIZONTAL);
    }

    // Set the divider again, because it needs to be redrawn due to the orientation change.
    panelsLayout.setDividerDrawable(ContextCompat.getDrawable(this, R.drawable.divider_panels));

    // Inform ActionBar Drawer Toggle of the change.
    actionBarDrawerToggle.onConfigurationChanged(newConfig);
}