Example usage for android.graphics Color rgb

List of usage examples for android.graphics Color rgb

Introduction

In this page you can find the example usage for android.graphics Color rgb.

Prototype

@ColorInt
public static int rgb(float red, float green, float blue) 

Source Link

Document

Return a color-int from red, green, blue float components in the range \([0..1]\).

Usage

From source file:com.michael.feng.textlater.NewActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Remove title bar
    // requestWindowFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.activity_new);
    getSupportActionBar().setDisplayUseLogoEnabled(false);
    getSupportActionBar().setDisplayHomeAsUpEnabled(false);
    getSupportActionBar().setDisplayShowHomeEnabled(false);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    getSupportActionBar().setDisplayShowCustomEnabled(true);
    getSupportActionBar().setCustomView(R.layout.abs_layout_new);

    backButton = (ImageView) findViewById(R.id.back);
    backButton.setOnClickListener(new OnClickListener() {
        @Override// w  w w.j a  v a2  s.c  o  m
        public void onClick(View arg0) {
            finish();
        }
    });
    backButton.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View arg0, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                // touch down code
                backButton.setBackgroundColor(Color.rgb(104, 156, 210));
                break;

            case MotionEvent.ACTION_MOVE:
                // touch move code
                break;

            case MotionEvent.ACTION_UP:
                // touch up code
                backButton.setBackgroundColor(Color.TRANSPARENT);
                break;
            }
            return false;
        }
    });

    // Init Add Contact Button and EditText
    textContact = (EditText) findViewById(R.id.textContact);
    textContact.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable arg0) {
            // TODO Auto-generated method stub
        }

        @Override
        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
            // TODO Auto-generated method stub
        }

        @Override
        public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
            validateMessage();
        }
    });
    textContact.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            textContact.setSelection(textContact.getText().length());
        }
    });

    addContactButton = (Button) findViewById(R.id.addContactButton);
    addContactButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            Log.d("add button click", "hep");
            Intent in = new Intent(getApplicationContext(), ContactsActivity.class);
            contactNames = textContact.getText().toString();
            if (null != contactNames && !"".equals(contactNames)) {
                in.putExtra("contactNames", contactNames);
                in.putExtra("contactNumbers", contactNumbers);
                Log.d("addbutton contactNames", contactNames);
                Log.d("addbutton contactNumbers", contactNumbers);
            }
            int requestCode = 0;
            startActivityForResult(in, requestCode);
        }
    });

    // Init TextDate EditText
    textDate = (EditText) findViewById(R.id.textDate);
    textDate.setInputType(InputType.TYPE_NULL);
    textDate.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean hasFocus) {
            if (hasFocus) {
                showDatePickerDialog(view);
            }
        }
    });
    textDate.setOnClickListener(this);

    // Init TextDate Button
    setDateButton = (Button) findViewById(R.id.setDateButton);
    setDateButton.setOnClickListener(this);

    // Init TextTime EditText
    textTime = (EditText) findViewById(R.id.textTime);
    textTime.setInputType(InputType.TYPE_NULL);
    textTime.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean hasFocus) {
            if (hasFocus) {
                showTimePickerDialog(view);
            }
        }
    });
    textTime.setOnClickListener(this);

    // Init TextTime Button
    setTimeButton = (Button) findViewById(R.id.setTimeButton);
    setTimeButton.setOnClickListener(this);

    // Init Active Button and Content EditText
    textContent = (EditText) findViewById(R.id.textContent);
    textContent.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable arg0) {
            validateMessage();
        }

        @Override
        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
            // TODO Auto-generated method stub
        }

        @Override
        public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
            // TODO
        }
    });
    sendButton = (Button) findViewById(R.id.sendButton);
    sendButton.setOnClickListener(this);
}

From source file:com.esri.arcgisruntime.sample.editfeatureattachments.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // inflate MapView from layout
    mMapView = (MapView) findViewById(R.id.mapView);
    // create a map with the streets basemap
    mMap = new ArcGISMap(Basemap.Type.STREETS, 44.354388, -119.998245, 5);
    // set the map to be displayed in the mapview
    mMapView.setMap(mMap);//w  w  w .ja va 2  s  . co  m

    progressDialog = new ProgressDialog(this);
    progressDialog.setTitle(getApplication().getString(R.string.fetching_no_attachments));
    progressDialog.setMessage(getApplication().getString(R.string.wait));
    createCallout();
    // get callout, set content and show
    mCallout = mMapView.getCallout();
    // create feature layer with its service feature table
    // create the service feature table
    ServiceFeatureTable mServiceFeatureTable = new ServiceFeatureTable(
            getResources().getString(R.string.sample_service_url));
    mServiceFeatureTable.setFeatureRequestMode(ServiceFeatureTable.FeatureRequestMode.ON_INTERACTION_CACHE);
    // create the feature layer using the service feature table
    mFeatureLayer = new FeatureLayer(mServiceFeatureTable);

    // set the color that is applied to a selected feature.
    mFeatureLayer.setSelectionColor(Color.rgb(0, 255, 255)); //cyan, fully opaque
    // set the width of selection color
    mFeatureLayer.setSelectionWidth(3);

    // add the layer to the map
    mMap.getOperationalLayers().add(mFeatureLayer);

    mMapView.setOnTouchListener(new DefaultMapViewOnTouchListener(this, mMapView) {
        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {

            // get the point that was clicked and convert it to a point in map coordinates
            mClickPoint = new android.graphics.Point((int) e.getX(), (int) e.getY());

            // clear any previous selection
            mFeatureLayer.clearSelection();
            mSelectedArcGISFeature = null;

            // identify the GeoElements in the given layer
            final ListenableFuture<IdentifyLayerResult> futureIdentifyLayer = mMapView
                    .identifyLayerAsync(mFeatureLayer, mClickPoint, 5, false, 1);

            // add done loading listener to fire when the selection returns
            futureIdentifyLayer.addDoneListener(new Runnable() {
                @Override
                public void run() {
                    try {
                        // call get on the future to get the result
                        IdentifyLayerResult layerResult = futureIdentifyLayer.get();

                        List<GeoElement> resultGeoElements = layerResult.getElements();
                        if (resultGeoElements.size() > 0) {
                            if (resultGeoElements.get(0) instanceof ArcGISFeature) {
                                progressDialog.show();

                                mSelectedArcGISFeature = (ArcGISFeature) resultGeoElements.get(0);
                                // highlight the selected feature
                                mFeatureLayer.selectFeature(mSelectedArcGISFeature);
                                mAttributeID = mSelectedArcGISFeature.getAttributes().get("objectid")
                                        .toString();
                                // get the number of attachments
                                final ListenableFuture<List<Attachment>> attachmentResults = mSelectedArcGISFeature
                                        .fetchAttachmentsAsync();

                                attachmentResults.addDoneListener(new Runnable() {
                                    @Override
                                    public void run() {
                                        try {
                                            attachments = attachmentResults.get();
                                            Log.d("number of attachments :", attachments.size() + "");
                                            // show callout with the value for the attribute "typdamage" of the selected feature
                                            mSelectedArcGISFeatureAttributeValue = (String) mSelectedArcGISFeature
                                                    .getAttributes().get("typdamage");
                                            if (progressDialog.isShowing()) {
                                                progressDialog.dismiss();
                                            }
                                            showCallout(mSelectedArcGISFeatureAttributeValue,
                                                    attachments.size());
                                            Toast.makeText(getApplicationContext(),
                                                    getApplication().getString(R.string.info_button_message),
                                                    Toast.LENGTH_SHORT).show();

                                        } catch (Exception e) {
                                            Log.e(TAG, e.getMessage());
                                        }
                                    }
                                });
                            }
                        } else {
                            // none of the features on the map were selected
                            mCallout.dismiss();
                        }
                    } catch (Exception e) {
                        Log.e(getResources().getString(R.string.app_name),
                                "Select feature failed: " + e.getMessage());
                    }
                }
            });
            return super.onSingleTapConfirmed(e);
        }
    });
}

From source file:it.durip_app.DataFlow.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_data_flow);
    final int SUPERUSER_REQUEST = 2324; // arbitrary number of your choosing
    Intent intent = new Intent("android.intent.action.superuser"); // superuser request
    intent.putExtra("name", "durip_app"); // tell Superuser the name of the requesting app
    intent.putExtra("packagename", "it.durip_app"); // tel Superuser the name of the requesting package
    //intent.putExtra(SHELL_RESULT, "");

    try {//ww w .  jav a  2  s . c o  m
        startActivityForResult(intent, SUPERUSER_REQUEST); // make the request!
    } catch (Exception e) {
        Log.i("superusering err", e.toString());
    }

    // get handles to our View defined in layout.xml:
    dynamicPlot = (XYPlot) findViewById(R.id.myPingXYPlot);

    plotUpdater = new MyPlotUpdater(dynamicPlot);

    // only display whole numbers in domain labels
    dynamicPlot.getGraphWidget().setDomainValueFormat(new DecimalFormat("0"));

    // getInstance and position datasets:
    DataSource data = new DataSource();

    DynamicGraph CWN = new DynamicGraph(data, 1, "CWN");
    //DynamicGraph AW = new DynamicGraph(data, 2, "AW");
    //DynamicGraph CWASP = new DynamicGraph(data, 3, "CWASP");
    DynamicGraph SSHTHRESH = new DynamicGraph(data, 4, "SSHTHRESH");
    DynamicGraph RTT = new DynamicGraph(data, 5, "RTT");
    DynamicGraph SRTT = new DynamicGraph(data, 6, "SRTT");
    DynamicGraph FLIGHT = new DynamicGraph(data, 7, "FLIGHT");
    DynamicGraph PACKETOUT = new DynamicGraph(data, 8, "PACKETOUT");
    DynamicGraph PACKETLOST = new DynamicGraph(data, 9, "PACKETLOST");
    DynamicGraph PACKETRET = new DynamicGraph(data, 10, "PACKETRET");

    dynamicPlot.addSeries(CWN, new LineAndPointFormatter(Color.rgb(10, 100, 100), Color.rgb(100, 10, 100), null,
            new PointLabelFormatter(0)));
    dynamicPlot.addSeries(SSHTHRESH, new LineAndPointFormatter(Color.rgb(40, 70, 0), Color.rgb(0, 40, 70), null,
            new PointLabelFormatter(0)));
    dynamicPlot.addSeries(RTT, new LineAndPointFormatter(Color.rgb(50, 60, 100), Color.rgb(0, 50, 60), null,
            new PointLabelFormatter(0)));
    dynamicPlot.addSeries(SRTT, new LineAndPointFormatter(Color.rgb(60, 50, 50), Color.rgb(100, 60, 50), null,
            new PointLabelFormatter(0)));
    dynamicPlot.addSeries(FLIGHT, new LineAndPointFormatter(Color.rgb(70, 40, 0), Color.rgb(0, 70, 40), null,
            new PointLabelFormatter(0)));

    dynamicPlot.setGridPadding(5, 0, 5, 0);

    // hook up the plotUpdater to the data model:
    data.addObserver(plotUpdater);

    dynamicPlot.setDomainStepMode(XYStepMode.SUBDIVIDE);
    dynamicPlot.setDomainStepValue(CWN.size());

    // thin out domain/range tick labels so they dont overlap each other:
    dynamicPlot.setTicksPerDomainLabel(100);
    dynamicPlot.setTicksPerRangeLabel(30);

    // freeze the range boundaries:
    dynamicPlot.setRangeBoundaries(0, 300, BoundaryMode.FIXED);

    // kick off the data generating thread:
    mySource = new Thread(data);
    mySource.start();
    //myPingXYPlot
    // Show the Up button in the action bar.
    setupActionBar();
}

From source file:com.todoroo.astrid.sync.SyncProviderPreferences.java

/**
 *
 * @param resource/* w  w w. j  a  v a2  s . c om*/
 *            if null, updates all resources
 */
@Override
public void updatePreferences(Preference preference, Object value) {
    final Resources r = getResources();

    // interval
    if (r.getString(getUtilities().getSyncIntervalKey()).equals(preference.getKey())) {
        int index = AndroidUtilities.indexOf(r.getStringArray(R.array.sync_SPr_interval_values),
                (String) value);
        if (index <= 0)
            preference.setSummary(R.string.sync_SPr_interval_desc_disabled);
        else
            preference.setSummary(r.getString(R.string.sync_SPr_interval_desc,
                    r.getStringArray(R.array.sync_SPr_interval_entries)[index]));
    }

    // status
    else if (r.getString(R.string.sync_SPr_status_key).equals(preference.getKey())) {
        boolean loggedIn = getUtilities().isLoggedIn();
        String status;
        //String subtitle = ""; //$NON-NLS-1$

        // ! logged in - display message, click -> sync
        if (!loggedIn) {
            status = r.getString(R.string.sync_status_loggedout);
            statusColor = Color.rgb(19, 132, 165);
        }
        // sync is occurring
        else if (getUtilities().isOngoing()) {
            status = r.getString(R.string.sync_status_ongoing);
            statusColor = Color.rgb(0, 0, 100);
        }
        // last sync had errors
        else if (getUtilities().getLastError() != null || getUtilities().getLastAttemptedSyncDate() != 0) {
            // last sync was failure
            if (getUtilities().getLastAttemptedSyncDate() != 0) {
                status = r.getString(R.string.sync_status_failed, DateUtilities.getDateStringWithTime(
                        SyncProviderPreferences.this, new Date(getUtilities().getLastAttemptedSyncDate())));
                statusColor = Color.rgb(100, 0, 0);

                if (getUtilities().getLastSyncDate() > 0) {
                    //                        subtitle = r.getString(R.string.sync_status_failed_subtitle,
                    //                                DateUtilities.getDateStringWithTime(SyncProviderPreferences.this,
                    //                                        new Date(getUtilities().getLastSyncDate())));
                }
            } else {
                long lastSyncDate = getUtilities().getLastSyncDate();
                String dateString = lastSyncDate > 0
                        ? DateUtilities.getDateStringWithTime(SyncProviderPreferences.this,
                                new Date(lastSyncDate))
                        : ""; //$NON-NLS-1$
                status = r.getString(R.string.sync_status_errors, dateString);
                statusColor = Color.rgb(100, 100, 0);
            }
        } else if (getUtilities().getLastSyncDate() > 0) {
            status = r.getString(R.string.sync_status_success, DateUtilities.getDateStringWithTime(
                    SyncProviderPreferences.this, new Date(getUtilities().getLastSyncDate())));
            statusColor = Color.rgb(0, 100, 0);
        } else {
            status = r.getString(R.string.sync_status_never);
            statusColor = Color.rgb(0, 0, 100);
        }
        preference.setTitle(R.string.sync_SPr_sync);
        preference.setSummary(r.getString(R.string.sync_SPr_status_subtitle, status));

        preference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            public boolean onPreferenceClick(Preference p) {
                startSync();
                return true;
            }
        });

        View view = findViewById(R.id.status);
        if (view != null)
            view.setBackgroundColor(statusColor);
    } else if (r.getString(R.string.sync_SPr_key_last_error).equals(preference.getKey())) {
        if (getUtilities().getLastError() != null) {
            // Display error
            final String service = getTitle().toString();
            final String lastErrorFull = getUtilities().getLastError();
            final String lastErrorDisplay = adjustErrorForDisplay(r, lastErrorFull, service);
            preference.setTitle(R.string.sync_SPr_last_error);
            preference.setSummary(R.string.sync_SPr_last_error_subtitle);

            preference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                @Override
                @SuppressWarnings("nls")
                public boolean onPreferenceClick(Preference pref) {
                    // Show last error
                    new AlertDialog.Builder(SyncProviderPreferences.this).setTitle(R.string.sync_SPr_last_error)
                            .setMessage(lastErrorDisplay)
                            .setPositiveButton(R.string.sync_SPr_send_report, new OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    Intent emailIntent = new Intent(Intent.ACTION_SEND);
                                    emailIntent.setType("plain/text")
                                            .putExtra(Intent.EXTRA_EMAIL,
                                                    new String[] { "android-bugs@astrid.com" })
                                            .putExtra(Intent.EXTRA_SUBJECT, service + " Sync Error")
                                            .putExtra(Intent.EXTRA_TEXT, lastErrorFull);
                                    startActivity(Intent.createChooser(emailIntent,
                                            r.getString(R.string.sync_SPr_send_report)));
                                }
                            }).setNegativeButton(R.string.DLG_close, null).create().show();
                    return true;
                }
            });

        } else {
            PreferenceCategory statusCategory = (PreferenceCategory) findPreference(
                    r.getString(R.string.sync_SPr_group_status));
            statusCategory.removePreference(findPreference(r.getString(R.string.sync_SPr_key_last_error)));
        }
    }
    // log out button
    else if (r.getString(R.string.sync_SPr_forget_key).equals(preference.getKey())) {
        boolean loggedIn = getUtilities().isLoggedIn();
        preference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            public boolean onPreferenceClick(Preference p) {
                DialogUtilities.okCancelDialog(SyncProviderPreferences.this,
                        r.getString(R.string.sync_forget_confirm), new OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                logOut();
                                initializePreference(getPreferenceScreen());
                            }
                        }, null);
                return true;
            }
        });
        if (!loggedIn) {
            PreferenceCategory category = (PreferenceCategory) findPreference(
                    r.getString(R.string.sync_SPr_key_options));
            category.removePreference(preference);
        }

    }
}

From source file:com.ab.view.sliding.AbSlidingPlayView.java

/**
 * ???View./*from  www . j  ava  2  s . c o m*/
 *
 * @param context the context
 */
public void initView(Context context) {
    this.context = context;
    navLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    this.setOrientation(LinearLayout.VERTICAL);
    this.setBackgroundColor(Color.rgb(255, 255, 255));

    RelativeLayout mRelativeLayout = new RelativeLayout(context);

    mViewPager = new AbInnerViewPager(context);
    //ViewPager,fragmentsetId()id
    mViewPager.setId(1985);
    //
    mNavLayoutParent = new LinearLayout(context);
    mNavLayoutParent.setPadding(0, 5, 0, 5);
    navLinearLayout = new LinearLayout(context);
    navLinearLayout.setPadding(15, 1, 15, 1);
    navLinearLayout.setVisibility(View.INVISIBLE);
    mNavLayoutParent.addView(navLinearLayout,
            new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    RelativeLayout.LayoutParams lp1 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    lp1.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    lp1.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
    lp1.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
    mRelativeLayout.addView(mViewPager, lp1);

    RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    lp2.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    mRelativeLayout.addView(mNavLayoutParent, lp2);
    addView(mRelativeLayout,
            new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

    displayImage = AbFileUtil.getBitmapFromSrc("image/play_display.png");
    hideImage = AbFileUtil.getBitmapFromSrc("image/play_hide.png");

    mListViews = new ArrayList<View>();
    mAbViewPagerAdapter = new AbViewPagerAdapter(context, mListViews);
    mViewPager.setAdapter(mAbViewPagerAdapter);
    mViewPager.setFadingEdgeLength(0);
    mViewPager.setOnPageChangeListener(new OnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            makesurePosition();
            onPageSelectedCallBack(position);
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            onPageScrolledCallBack(position);
        }

    });

}

From source file:com.cwx.daytodayaccount.fragment.SlidingTabsColorsFragment.java

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

    // BEGIN_INCLUDE (populate_tabs)
    /**//  w  w w.jav a2 s .c  o  m
     * Populate our tab list with tabs. Each item contains a title, indicator color and divider
     * color, which are used by {@link SlidingTabLayout}.
     */
    mTabs.add(new SamplePagerItem(getString(R.string.tab_account), // Title
            Color.rgb(0, 188, 212), // Indicator color
            Color.GRAY // Divider color
    ));

    mTabs.add(new SamplePagerItem(getString(R.string.tab_notifications), // Title
            Color.MAGENTA, // Indicator color
            Color.GRAY // Divider color
    ));

    mTabs.add(new SamplePagerItem(getString(R.string.tab_diarys), // Title
            Color.rgb(255, 179, 0), // Indicator color
            Color.GRAY // Divider color
    ));

    mTabs.add(new SamplePagerItem(getString(R.string.tab_photos), // Title
            Color.rgb(102, 187, 106), // Indicator color
            Color.GRAY // Divider color
    ));

    mTabs.add(new SamplePagerItem(getString(R.string.tab_guanyin), // Title
            Color.YELLOW, // Indicator color
            Color.GRAY // Divider color
    ));

    mTabs.add(new SamplePagerItem(getString(R.string.tab_settings), // Title
            Color.BLUE, // Indicator color
            Color.GRAY // Divider color
    ));
    // END_INCLUDE (populate_tabs)
}

From source file:com.ab.view.sliding.AbSlidingTabView.java

/**
 * Instantiates a new ab sliding tab view.
 *
 * @param context the context//from   ww  w . j  ava2  s .  c om
 * @param attrs the attrs
 */
public AbSlidingTabView(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.context = context;

    this.setOrientation(LinearLayout.VERTICAL);
    this.setBackgroundColor(Color.rgb(255, 255, 255));

    mTabScrollView = new HorizontalScrollView(context);
    mTabScrollView.setHorizontalScrollBarEnabled(false);
    mTabScrollView.setSmoothScrollingEnabled(true);

    mTabLayout = new LinearLayout(context);
    mTabLayout.setOrientation(LinearLayout.HORIZONTAL);
    mTabLayout.setGravity(Gravity.CENTER);

    //mTabLayout
    mTabScrollView.addView(mTabLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    this.addView(mTabScrollView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    //View?
    mViewPager = new ViewPager(context);
    //ViewPager,setId()id
    mViewPager.setId(1985);
    pagerItemList = new ArrayList<Fragment>();
    //Tab?
    tabItemList = new ArrayList<TextView>();
    tabItemTextList = new ArrayList<String>();
    tabItemDrawableList = new ArrayList<Drawable>();

    //?FragmentActivity
    if (!(this.context instanceof FragmentActivity)) {
        AbLogUtil.e(AbSlidingTabView.class,
                "AbSlidingTabView?context,FragmentActivity");
    }

    FragmentManager mFragmentManager = ((FragmentActivity) this.context).getFragmentManager();
    mFragmentPagerAdapter = new AbFragmentPagerAdapter(mFragmentManager, pagerItemList);
    mViewPager.setAdapter(mFragmentPagerAdapter);
    mViewPager.setOnPageChangeListener(new MyOnPageChangeListener());
    mViewPager.setOffscreenPageLimit(3);

    this.addView(mViewPager, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

}

From source file:com.ab.view.sliding.AbBottomTabView.java

/**
 * Instantiates a new ab bottom tab view.
 *
 * @param context the context//from w ww  . j  av a2  s .  c o m
 * @param attrs the attrs
 */
public AbBottomTabView(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.context = context;

    this.setOrientation(LinearLayout.VERTICAL);
    this.setBackgroundColor(Color.rgb(255, 255, 255));

    mTabLayout = new LinearLayout(context);
    mTabLayout.setOrientation(LinearLayout.HORIZONTAL);
    mTabLayout.setGravity(Gravity.CENTER);

    //View?
    mViewPager = new ViewPager(context);
    //ViewPager,setId()id
    mViewPager.setId(1985);
    pagerItemList = new ArrayList<Fragment>();
    this.addView(mViewPager, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0, 1));
    addView(mTabLayout, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

    //Tab?
    tabItemList = new ArrayList<AbTabItemView>();
    tabItemTextList = new ArrayList<String>();
    tabItemDrawableList = new ArrayList<Drawable>();
    //?FragmentActivity
    if (!(this.context instanceof FragmentActivity)) {
        AbLogUtil.e(AbBottomTabView.class,
                "AbSlidingTabView?context,FragmentActivity");
    }

    FragmentManager mFragmentManager = ((FragmentActivity) this.context).getFragmentManager();
    mFragmentPagerAdapter = new AbFragmentPagerAdapter(mFragmentManager, pagerItemList);
    mViewPager.setAdapter(mFragmentPagerAdapter);
    mViewPager.setOnPageChangeListener(new MyOnPageChangeListener());
    mViewPager.setOffscreenPageLimit(3);

}

From source file:com.wll.main.widget.AbSlidingPlayView.java

/**
 * ???View.//  w  ww  .  j  av a  2 s .c  om
 *
 * @param context
 *            the context
 */
public void initView(Context context) {
    this.context = context;
    navLayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    this.setOrientation(LinearLayout.VERTICAL);
    this.setBackgroundColor(Color.rgb(255, 255, 255));

    RelativeLayout mRelativeLayout = new RelativeLayout(context);

    mViewPager = new AbInnerViewPager(context);
    // ViewPager,fragmentsetId()id
    mViewPager.setId(getResources().getInteger(R.integer.id_viewPager));
    // 
    mNavLayoutParent = new LinearLayout(context);
    mNavLayoutParent.setPadding(0, 5, 0, 5);
    navLinearLayout = new LinearLayout(context);
    navLinearLayout.setPadding(15, 1, 15, 1);
    navLinearLayout.setVisibility(View.INVISIBLE);
    mNavLayoutParent.addView(navLinearLayout,
            new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    RelativeLayout.LayoutParams lp1 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    lp1.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    lp1.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
    lp1.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
    mRelativeLayout.addView(mViewPager, lp1);

    RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    lp2.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    mRelativeLayout.addView(mNavLayoutParent, lp2);
    addView(mRelativeLayout, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

    //      displayImage = AbFileUtil.getBitmapFromSrc("image/play_display.png");
    //      hideImage = AbFileUtil.getBitmapFromSrc("image/play_hide.png");

    Bitmap bm = BitmapFactory.decodeResource(context.getResources(), R.mipmap.d2);
    Bitmap bm2 = BitmapFactory.decodeResource(context.getResources(), R.mipmap.d1);
    displayImage = bm;
    hideImage = bm2;

    mListViews = new ArrayList<View>();
    mAbViewPagerAdapter = new AbViewPagerAdapter(context, mListViews);
    mViewPager.setAdapter(mAbViewPagerAdapter);
    mViewPager.setFadingEdgeLength(0);
    mViewPager.setOnPageChangeListener(new OnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            makesurePosition();
            onPageSelectedCallBack(position);
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            onPageScrolledCallBack(position);
        }

    });

}

From source file:com.dreamchen.useful.mouserace.view.sliding.AbSlidingTabView.java

/**
 * Instantiates a new ab sliding tab view.
 *
 * @param context the context//from  ww  w  .  ja v a2s.com
 * @param attrs the attrs
 */
public AbSlidingTabView(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.context = context;

    this.setOrientation(LinearLayout.VERTICAL);
    this.setBackgroundColor(Color.rgb(255, 255, 255));

    mTabScrollView = new HorizontalScrollView(context);
    mTabScrollView.setHorizontalScrollBarEnabled(false);
    mTabScrollView.setSmoothScrollingEnabled(true);

    mTabLayout = new LinearLayout(context);
    mTabLayout.setOrientation(LinearLayout.HORIZONTAL);
    mTabLayout.setGravity(Gravity.CENTER);

    //mTabLayout
    mTabScrollView.addView(mTabLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    this.addView(mTabScrollView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    //View?
    mViewPager = new ViewPager(context);
    //ViewPager,setId()id
    mViewPager.setId(1985);
    pagerItemList = new ArrayList<Fragment>();
    //Tab?
    tabItemList = new ArrayList<TextView>();
    tabItemTextList = new ArrayList<String>();
    tabItemDrawableList = new ArrayList<Drawable>();

    //?FragmentActivity
    if (!(this.context instanceof FragmentActivity)) {
        AbLogUtil.e(AbSlidingTabView.class,
                "AbSlidingTabView?context,FragmentActivity");
    }

    FragmentManager mFragmentManager = ((FragmentActivity) this.context).getSupportFragmentManager();
    mFragmentPagerAdapter = new AbFragmentPagerAdapter(mFragmentManager, pagerItemList);
    mViewPager.setAdapter(mFragmentPagerAdapter);
    mViewPager.setOnPageChangeListener(new MyOnPageChangeListener());
    mViewPager.setOffscreenPageLimit(3);

    this.addView(mViewPager, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

}