Example usage for android.graphics Color parseColor

List of usage examples for android.graphics Color parseColor

Introduction

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

Prototype

@ColorInt
public static int parseColor(@Size(min = 1) String colorString) 

Source Link

Document

Parse the color string, and return the corresponding color-int.

Usage

From source file:alexander.martinz.libs.materialpreferences.MaterialEditTextPreference.java

@Override
public boolean init(Context context, AttributeSet attrs) {
    if (mInit) {/* ww w .j  a v  a  2 s. com*/
        return false;
    }
    mInit = true;

    if (!super.init(context, attrs)) {
        return false;
    }

    if (mEditTextValue == null) {
        mEditTextValue = new EditText(context);
        mEditTextValue.setText(mDefaultValue);
        if (mPrefTextColor != -1) {
            if (isInEditMode()) {
                mEditTextValue.setTextColor(Color.parseColor("#009688"));
            } else {
                mEditTextValue.setTextColor(ContextCompat.getColor(context, mPrefTextColor));
            }
        }
        if (mPrefTextSize != -1) {
            mEditTextValue.setTextSize(TypedValue.COMPLEX_UNIT_SP, mPrefTextSize);
        }
        mEditTextValue.setInputType(InputType.TYPE_NULL);
        mEditTextValue.setEllipsize(TextUtils.TruncateAt.END);
        mEditTextValue.setOnClickListener(this);
        addToWidgetFrame(mEditTextValue);
    }

    setOnClickListener(this);

    return true;
}

From source file:ca.ippetad.geerweekapp.view.MainActivity.java

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

    /** View **//*from w ww .  java  2s. c om*/
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_main);

    /** FRAGMENTS **/
    _frame = (FrameLayout) findViewById(R.id.container);

    _feed = new FeedFragment();
    _events = new EventsFragment();
    _kidnap = new KidnapFragment();
    _godiva = new GodivaFragment();
    _misc = new MiscFragment();

    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction().add(R.id.container, _feed).commit();
    }

    /** SLIDING MENU **/
    _slide = new SlidingMenu(this);
    _slide.setMode(SlidingMenu.LEFT);
    _slide.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
    _slide.setBehindOffset(250);
    _slide.setFadeDegree(.9f);
    _slide.setBackgroundColor(Color.parseColor("#444444"));
    _slide.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
    _slide.setMenu(R.layout.layout_menu);

    _slide.setOnOpenedListener(new SlidingMenu.OnOpenedListener() {
        @Override
        public void onOpened() {
            MENU_STATE = HIDDEN;
            invalidateOptionsMenu();
        }
    });
    _slide.setOnClosedListener(new SlidingMenu.OnClosedListener() {
        @Override
        public void onClosed() {
            MENU_STATE = VISIBLE;
            invalidateOptionsMenu();
        }
    });

    CustomTopBar bar = (CustomTopBar) findViewById(R.id.topbar);
    bar.setOnDrawerClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            _slide.toggle();
        }
    });

    ListView sliderList = (ListView) _slide.getRootView().findViewById(R.id.listview);
    CustomArrayAdapter slider_adapter = new CustomArrayAdapter(this, android.R.layout.simple_list_item_1,
            new String[] { "Home", "Events", "Kidnapping", "Godiva", "Misc" });
    sliderList.setAdapter(slider_adapter);
    sliderList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            switch (i) {
            case 0:
                getSupportFragmentManager().beginTransaction().replace(R.id.container, _feed)
                        .addToBackStack(null).commit();
                break;
            case 1:
                getSupportFragmentManager().beginTransaction().replace(R.id.container, _events)
                        .addToBackStack(null).commit();
                break;
            case 2:
                getSupportFragmentManager().beginTransaction().replace(R.id.container, _kidnap)
                        .addToBackStack(null).commit();
                break;
            case 3:
                getSupportFragmentManager().beginTransaction().replace(R.id.container, _godiva)
                        .addToBackStack(null).commit();
                break;
            case 4:
                getSupportFragmentManager().beginTransaction().replace(R.id.container, _misc)
                        .addToBackStack(null).commit();
                break;
            }
            _slide.toggle();
        }
    });

}

From source file:Main.java

private static int getColorInt(String color) {
    color = color.toUpperCase();/*from w  ww .j a v  a 2  s  .c o m*/
    // following the game's convention. see
    // http://bazaar.launchpad.net/~armagetronad-dev/armagetronad/trunk-armagetronad-work/view/head:/src/render/rFont.cpp#L775
    color = (color == "RESETT") ? "F8F8F8" : color;
    // we make sure the value is valid. (maybe unexpected color for people not using right codes)
    color = color.replaceAll("[^0-9A-F]", "F");
    return Color.parseColor("#" + color);
}

From source file:com.example.hllut.app.Deprecated.MainActivity.java

/**
 * Fills the pie-graph with appropriate data
 *//*from   w  ww  . j a  v  a2 s .c  o  m*/
private void populateGraph() {
    PieGraph pg = (PieGraph) findViewById(R.id.graph);

    int slices = 0;

    for (String category : food.keySet()) {
        if (food.get(category) != null) {
            PieSlice slice = new PieSlice();
            slice.setColor(Color.parseColor(colors.get(category)));
            slice.setValue(food.get(category) * 1000);
            slice.setTitle(category);
            pg.addSlice(slice);
            System.out.println(category + ": " + food.get(category));
            slices++;
        }
    }

    System.out.println("Slices: " + slices);

    TextView yourCO2 = (TextView) findViewById(R.id.yourCO2TextView);
    yourCO2.setText(total + " KG of CO2");
}

From source file:com.filemanager.free.activities.Preferences.java

@Override
public void onCreate(Bundle savedInstanceState) {
    SharedPreferences Sp = PreferenceManager.getDefaultSharedPreferences(this);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.prefsfrag);//from   w  ww . j  a  v  a2 s . c  o m
    mHandler = new Handler();

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    skin = PreferenceUtils.getSkinColor(Sp.getInt("skin_color_position", 9));
    if (Build.VERSION.SDK_INT >= 21) {
        ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription("File Manager",
                ((BitmapDrawable) ContextCompat.getDrawable(getBaseContext(), R.mipmap.ic_launcher))
                        .getBitmap(),
                Color.parseColor(skin));
        setTaskDescription(taskDescription);
    }
    skinStatusBar = PreferenceUtils.getStatusColor(skin);
    setSupportActionBar(toolbar);
    assert (getSupportActionBar()) != null;
    getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_TITLE);
    getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor(skin)));
    int sdk = Build.VERSION.SDK_INT;

    if (sdk == 20 || sdk == 19) {
        SystemBarTintManager tintManager = new SystemBarTintManager(this);
        tintManager.setStatusBarTintEnabled(true);
        tintManager.setStatusBarTintColor(Color.parseColor(skin));

        FrameLayout.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) findViewById(R.id.preferences)
                .getLayoutParams();
        SystemBarTintManager.SystemBarConfig config = tintManager.getConfig();
        p.setMargins(0, config.getStatusBarHeight(), 0, 0);
    } else if (Build.VERSION.SDK_INT >= 21) {
        boolean colourednavigation = Sp.getBoolean("colorednavigation", true);
        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.setStatusBarColor((PreferenceUtils.getStatusColor(skin)));
        if (colourednavigation)
            window.setNavigationBarColor((PreferenceUtils.getStatusColor(skin)));

    }
    selectItem(0);
}

From source file:com.baiiu.autoloopviewpager.indicator.LinePageIndicator.java

private void init(Context context, AttributeSet attrs) {

    if (isInEditMode())
        return;//from   ww w .j ava  2  s .c  o m

    final Resources res = getResources();

    //Load defaults from resources
    final int defaultSelectedColor = Color.parseColor("#FF33B5E5");
    final int defaultUnselectedColor = Color.parseColor("#FFBBBBBB");
    final float defaultLineWidth = 36;
    final float defaultGapWidth = 12;
    final float defaultStrokeWidth = 3;
    final boolean defaultCentered = true;

    //Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LinePageIndicator);

    mCentered = a.getBoolean(R.styleable.LinePageIndicator_centered, defaultCentered);
    mLineWidth = a.getDimension(R.styleable.LinePageIndicator_lineWidth, defaultLineWidth);
    mGapWidth = a.getDimension(R.styleable.LinePageIndicator_gapWidth, defaultGapWidth);
    setStrokeWidth(a.getDimension(R.styleable.LinePageIndicator_strokeWidth, defaultStrokeWidth));
    mPaintUnselected
            .setColor(a.getColor(R.styleable.LinePageIndicator_unselectedColor, defaultUnselectedColor));
    mPaintSelected.setColor(a.getColor(R.styleable.LinePageIndicator_selectedColor, defaultSelectedColor));

    Drawable background = a.getDrawable(R.styleable.LinePageIndicator_android_background);
    if (background != null) {
        setBackgroundDrawable(background);
    }

    a.recycle();
}

From source file:com.linkedin.android.eventsapp.ProfileActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_profile);

    Bundle extras = getIntent() != null ? getIntent().getExtras() : new Bundle();
    final Person person = extras.getParcelable("person");
    final Activity currentActivity = this;
    final ActionBar bar = getActionBar();
    View viewActionBar = getLayoutInflater().inflate(R.layout.layout_action_bar, null);

    ImageView backView = (ImageView) viewActionBar.findViewById(R.id.actionbar_left);
    backView.setImageResource(R.drawable.arrow_left);
    backView.setVisibility(View.VISIBLE);
    backView.setClickable(true);/*from   www .j a v a2s .co m*/
    backView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            currentActivity.finish();
        }
    });

    ActionBar.LayoutParams params = new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT,
            ActionBar.LayoutParams.MATCH_PARENT);
    bar.setCustomView(viewActionBar, params);
    bar.setDisplayShowCustomEnabled(true);
    bar.setDisplayShowTitleEnabled(false);
    bar.setIcon(new ColorDrawable(Color.TRANSPARENT));
    bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#F15153")));

    TextView attendeeNameView = (TextView) findViewById(R.id.attendeeName);
    attendeeNameView.setText(person.getFirstName() + " " + person.getLastName());

    final ImageView attendeeImageView = (ImageView) findViewById(R.id.attendeeImage);
    final TextView attendeeHeadlineView = (TextView) findViewById(R.id.attendeeHeadline);
    final TextView attendeeLocationView = (TextView) findViewById(R.id.attendeeLocation);

    boolean isAccessTokenValid = LISessionManager.getInstance(currentActivity).getSession().isValid();
    if (isAccessTokenValid) {
        String url = Constants.personByIdBaseUrl + person.getLinkedinId() + Constants.personProjection;
        APIHelper.getInstance(currentActivity).getRequest(currentActivity, url, new ApiListener() {
            @Override
            public void onApiSuccess(ApiResponse apiResponse) {
                try {
                    JSONObject s = apiResponse.getResponseDataAsJson();
                    String headline = s.has("headline") ? s.getString("headline") : "";
                    String pictureUrl = s.has("pictureUrl") ? s.getString("pictureUrl") : null;
                    JSONObject location = s.getJSONObject("location");
                    String locationName = location != null && location.has("name") ? location.getString("name")
                            : "";

                    attendeeHeadlineView.setText(headline);
                    attendeeLocationView.setText(locationName);
                    if (pictureUrl != null) {
                        new FetchImageTask(attendeeImageView).execute(pictureUrl);
                    } else {
                        attendeeImageView.setImageResource(R.drawable.ghost_person);
                    }
                } catch (JSONException e) {

                }

            }

            @Override
            public void onApiError(LIApiError apiError) {

            }
        });

        ViewStub viewOnLIStub = (ViewStub) findViewById(R.id.viewOnLIStub);
        View viewOnLI = viewOnLIStub.inflate();
        Button viewOnLIButton = (Button) viewOnLI.findViewById(R.id.viewOnLinkedInButton);
        viewOnLIButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DeepLinkHelper.getInstance().openOtherProfile(currentActivity, person.getLinkedinId(),
                        new DeepLinkListener() {
                            @Override
                            public void onDeepLinkSuccess() {

                            }

                            @Override
                            public void onDeepLinkError(LIDeepLinkError error) {

                            }
                        });
            }
        });
    } else {
        attendeeImageView.setImageResource(R.drawable.ghost_person);
    }
}

From source file:net.olejon.mdapp.LvhCategoriesAdapter.java

@Override
public void onBindViewHolder(CategoryViewHolder viewHolder, int i) {
    try {//from  ww  w.  j a  va2 s . com
        final JSONObject categoriesJsonObject = mCategories.getJSONObject(i);

        viewHolder.card.setCardBackgroundColor(Color.parseColor(mColor));

        switch (mIcon) {
        case "lvh_urgent": {
            viewHolder.icon.setImageResource(R.drawable.ic_favorite_white_24dp);
            break;
        }
        case "lvh_symptoms": {
            viewHolder.icon.setImageResource(R.drawable.ic_stethoscope);
            break;
        }
        case "lvh_injuries": {
            viewHolder.icon.setImageResource(R.drawable.ic_healing_white_24dp);
            break;
        }
        case "lvh_administrative": {
            viewHolder.icon.setImageResource(R.drawable.ic_my_library_books_white_24dp);
            break;
        }
        }

        viewHolder.title.setText(categoriesJsonObject.getString("title"));

        viewHolder.categories.removeAllViews();

        final JSONArray itemsJsonArray = categoriesJsonObject.getJSONArray("items");

        for (int f = 0; f < itemsJsonArray.length(); f++) {
            final JSONObject categoryJsonObject = itemsJsonArray.getJSONObject(f);

            final String name = categoryJsonObject.getString("name");
            final String uri = categoryJsonObject.getString("uri");

            TextView textView = (TextView) mLayoutInflater
                    .inflate(R.layout.activity_lvh_categories_card_categories_item, null);
            textView.setText(name);

            textView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent = new Intent(mContext, MainWebViewActivity.class);
                    intent.putExtra("title", name);
                    intent.putExtra("uri", uri);
                    mContext.startActivity(intent);
                }
            });

            viewHolder.categories.addView(textView);
        }

        animateView(viewHolder.card, i);
    } catch (Exception e) {
        Log.e("LvhCategoriesAdapter", Log.getStackTraceString(e));
    }
}

From source file:com.userhook.view.UHMessageView.java

private void init(Context context) {

    if (!isInEditMode()) {
        overlay = new LinearLayout(context);
        // set a transparent black background
        overlay.setBackgroundColor(Color.parseColor("#99000000"));
        overlay.setVisibility(GONE);//w  ww. j  a  va  2  s.co m

        addView(overlay,
                new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        overlay.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                hideDialog();
            }
        });

    }

}

From source file:com.daking.sports.view.banner.CirclePageIndicator.java

public CirclePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;//www . jav a2 s  .  c o  m

    //Load defaults from resources
    final int defaultPageColor = Color.parseColor("#00000000");
    final int defaultFillColor = Color.parseColor("#FFFFFFFF");
    final int defaultOrientation = 0;
    final int defaultStrokeColor = Color.parseColor("#FFDDDDDD");
    final float defaultStrokeWidth = 2;
    final float defaultRadius = 6;
    final boolean defaultCentered = true;
    final boolean defaultSnap = false;

    //Retrieve styles attributes
    //        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CirclePageIndicator, defStyle, 0);

    mCentered = defaultCentered;
    mOrientation = defaultOrientation;
    mPaintPageFill.setStyle(Style.FILL);
    mPaintPageFill.setColor(defaultPageColor);
    mPaintStroke.setStyle(Style.STROKE);
    mPaintStroke.setColor(defaultStrokeColor);
    mPaintStroke.setStrokeWidth(defaultStrokeWidth);
    mPaintFill.setStyle(Style.FILL);
    mPaintFill.setColor(defaultFillColor);
    mRadius = defaultRadius;
    mSelectedRadius = defaultRadius;
    mSnap = defaultSnap;

    Drawable background = new ColorDrawable(Color.parseColor("#FFFFFF"));
    setBackgroundDrawable(background);
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}