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:com.akshayomkar.instavansporter.SlidingTabLayout.java

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;//from   w w w.ja  v  a2 s . c o  m
        TextView tabTitleView = null;

        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
        }

        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }

        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
        }

        if (mDistributeEvenly) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
            lp.width = 0;
            lp.weight = 1;
        }

        tabTitleView.setText(adapter.getPageTitle(i));
        tabTitleView.setTextColor(Color.parseColor("#ffffff"));
        tabView.setOnClickListener(tabClickListener);
        String desc = mContentDescriptions.get(i, null);
        if (desc != null) {
            tabView.setContentDescription(desc);
        }

        mTabStrip.addView(tabView);
        if (i == mViewPager.getCurrentItem()) {
            tabView.setSelected(true);
        }
    }
}

From source file:com.samsung.richnotification.RichNotificationHelper.java

public static SrnPrimaryTemplate createPrimaryTemplate(Context mContext, RichNotificationOptions options) {
    SrnPrimaryTemplate primaryTemplate = null;
    SrnStandardTemplate stdPrimaryTemplate = null;
    SrnLargeHeaderTemplate largeTemplate = null;
    SrnQRTemplate qrPrimaryTemplate = null;

    // Code duplication in case of SMALL, MEDIUM, FULL_SCREEN and default
    if (options.headerSizeType.equals(RichNotificationHelper.HEADER_TYPE_SMALL)) {
        stdPrimaryTemplate = new SrnStandardTemplate(HeaderSizeType.SMALL);
        stdPrimaryTemplate.setSubHeader(options.primarySubHeader);
        stdPrimaryTemplate.setBody(options.primaryBody);
        primaryTemplate = stdPrimaryTemplate;
    } else if (options.headerSizeType.equals(RichNotificationHelper.HEADER_TYPE_MEDIUM)) {
        stdPrimaryTemplate = new SrnStandardTemplate(HeaderSizeType.MEDIUM);
        stdPrimaryTemplate.setSubHeader(options.primarySubHeader);
        stdPrimaryTemplate.setBody(options.primaryBody);
        primaryTemplate = stdPrimaryTemplate;
    } else if (options.headerSizeType.equals(RichNotificationHelper.HEADER_TYPE_FULL)) {
        stdPrimaryTemplate = new SrnStandardTemplate(HeaderSizeType.FULL_SCREEN);
        stdPrimaryTemplate.setSubHeader(options.primarySubHeader);
        stdPrimaryTemplate.setBody(options.primaryBody);
        primaryTemplate = stdPrimaryTemplate;
    } else if (options.headerSizeType.equals(RichNotificationHelper.HEADER_TYPE_LARGE)) {
        largeTemplate = new SrnLargeHeaderTemplate();
        primaryTemplate = largeTemplate;
    } else if (options.headerSizeType.equals(RichNotificationHelper.HEADER_TYPE_QR)) {
        qrPrimaryTemplate = new SrnQRTemplate();
        Bitmap imageBitmap = getIconBitmap(mContext, "file://" + options.qrImage);
        SrnImageAsset imageAsset = new SrnImageAsset(mContext, "QR Image", imageBitmap);
        qrPrimaryTemplate.setImage(imageAsset);
        qrPrimaryTemplate.setSubHeader(options.primarySubHeader);
        primaryTemplate = qrPrimaryTemplate;
    } else {/*w  w  w . ja  v  a2 s  .  com*/
        Log.e(TAG, "Header type invalid. Creating SMALL header.");
        stdPrimaryTemplate = new SrnStandardTemplate();
        stdPrimaryTemplate.setSubHeader(options.primarySubHeader);
        stdPrimaryTemplate.setBody(options.primaryBody);
        primaryTemplate = stdPrimaryTemplate;
    }
    // Set the background image of the primary template
    if (!options.primaryBackgroundImage.equals("")) {
        Bitmap priBgBit = getIconBitmap(mContext, "file://" + options.primaryBackgroundImage);
        SrnImageAsset priBgAsst = new SrnImageAsset(mContext, "PrimaryBG", priBgBit);
        primaryTemplate.setBackgroundImage(priBgAsst);
    }
    // Set the background color of the primary template
    if (!options.primaryBackgroundColor.isEmpty()) {
        try {
            int color = Color.parseColor(options.primaryBackgroundColor);
            primaryTemplate.setBackgroundColor(color);
        } catch (IllegalArgumentException illArgEx) {
            Log.e(TAG, "Invalid color string for Primary Background");
        }
    } else {
        Log.e(TAG, "Empty string for Primary Background");
    }

    return primaryTemplate;
}

From source file:com.citrus.sdk.CitrusActivity.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void setActionBarBackground() {
    // Set primary color
    if (mColorPrimary != null && mActionBar != null) {
        mActionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor(mColorPrimary)));
    }//from  w w  w. j a va 2  s . c  o m

    // Set action bar color. Available only on android version Lollipop or higher.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && mColorPrimaryDark != null) {
        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(Color.parseColor(mColorPrimaryDark));
    }
}

From source file:com.amaze.filemanager.utils.Futils.java

private ColorStateList createEditTextColorStateList(int color) {
    int[][] states = new int[3][];
    int[] colors = new int[3];
    int i = 0;/*from w  ww.  j a  v a2 s.com*/
    states[i] = new int[] { -android.R.attr.state_enabled };
    colors[i] = Color.parseColor("#f6f6f6");
    i++;
    states[i] = new int[] { -android.R.attr.state_pressed, -android.R.attr.state_focused };
    colors[i] = Color.parseColor("#666666");
    i++;
    states[i] = new int[] {};
    colors[i] = color;
    return new ColorStateList(states, colors);
}

From source file:com.amaze.filemanager.fragments.Main.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    MAIN_ACTIVITY = (MainActivity) getActivity();
    setRetainInstance(true);//from w w w  .j  a v  a2 s  .c o  m
    no = getArguments().getInt("no", 1);
    home = getArguments().getString("home");
    CURRENT_PATH = getArguments().getString("lastpath");
    tabHandler = new TabHandler(getActivity(), null, null, 1);
    Sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
    skin = PreferenceUtils.getPrimaryColorString(Sp);
    fabSkin = PreferenceUtils.getAccentString(Sp);
    int icon = Sp.getInt("icon_skin_color_position", -1);
    iconskin = PreferenceUtils.getFolderColorString(Sp);
    skin_color = Color.parseColor(skin);
    icon_skin_color = Color.parseColor(iconskin);
    Calendar calendar = Calendar.getInstance();
    year = ("" + calendar.get(Calendar.YEAR)).substring(2, 4);
    theme = Integer.parseInt(Sp.getString("theme", "0"));
    theme1 = theme == 2 ? PreferenceUtils.hourOfDay() : theme;
    hidemode = Sp.getInt("hidemode", 0);

    SHOW_PERMISSIONS = Sp.getBoolean("showPermissions", false);
    SHOW_SIZE = Sp.getBoolean("showFileSize", false);
    SHOW_DIVIDERS = Sp.getBoolean("showDividers", true);
    GO_BACK_ITEM = Sp.getBoolean("goBack_checkbox", false);
    CIRCULAR_IMAGES = Sp.getBoolean("circularimages", true);
    SHOW_LAST_MODIFIED = Sp.getBoolean("showLastModified", true);
    icons = new IconUtils(Sp, getActivity());
}

From source file:com.ibuildapp.romanblack.MultiContactsPlugin.MultiContactsActivity.java

@Override
public void create() {
    try {//from   w w  w  .j a  v a2s. co m
        setContentView(R.layout.grouped_contacts_main);

        setTopBarLeftButtonTextAndColor(getResources().getString(R.string.common_back_upper),
                getResources().getColor(android.R.color.black), true, new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        finish();
                        return;
                    }
                });
        setTopBarTitleColor(getResources().getColor(android.R.color.black));
        setTopBarBackgroundColor(Statics.color1);

        LinearLayout inputSearchLayout = (LinearLayout) findViewById(R.id.grouped_contacts_search_layout);
        inputSearchLayout.setVisibility(View.GONE);

        resources = getResources();

        Intent currentIntent = getIntent();
        Bundle store = currentIntent.getExtras();
        widget = (Widget) store.getSerializable("Widget");
        category = store.getString("category");
        setTopBarTitle(category);

        if (widget == null) {
            handler.sendEmptyMessage(INITIALIZATION_FAILED);
            return;
        }

        cachePath = widget.getCachePath() + "/contacts-" + widget.getOrder();

        root = (LinearLayout) findViewById(R.id.grouped_contacts_main_root);
        listView = (ListView) findViewById(R.id.grouped_contacts_list);
        separator = findViewById(R.id.gc_head_separator);
        backSeparator = findViewById(R.id.gc_back_separator);

        backSeparator.setBackgroundColor(Statics.color1);
        if (Statics.isLight) {
            separator.setBackgroundColor(Color.parseColor("#4d000000"));
        } else {
            separator.setBackgroundColor(Color.parseColor("#4dFFFFFF"));
        }

        handler.sendEmptyMessage(SET_ROOT_BACKGROUND);
    } catch (Exception e) {
    }
}

From source file:com.example.pkogler.jsonparser.SlidingTabLayout.java

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final View.OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;/*from w ww .j a v  a 2  s . c o m*/
        TextView tabTitleView = null;

        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
        }

        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }

        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
        }

        if (mDistributeEvenly) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
            lp.width = 0;
            lp.weight = 1;
        }

        tabTitleView.setText(adapter.getPageTitle(i));
        tabView.setOnClickListener(tabClickListener);
        String desc = mContentDescriptions.get(i, null);
        if (desc != null) {
            tabView.setContentDescription(desc);
        }

        mTabStrip.addView(tabView);
        if (i == mViewPager.getCurrentItem()) {
            tabView.setSelected(true);
        }
        tabTitleView.setTextColor(Color.parseColor("#FFFFFF"));
        tabTitleView.setTextSize(14);
    }
}

From source file:com.odoo.addons.customers.CustomerDetails.java

private void setCustomerImage() {
    if (!record.getString("image_small").equals("false")) {
        userImage.setScaleType(ImageView.ScaleType.CENTER_CROP);
        userImage.setColorFilter(null);//from   www.  ja  v  a2 s . c o  m
        String base64 = newImage;
        if (newImage == null) {
            if (!record.getString("large_image").equals("false")) {
                base64 = record.getString("large_image");
            } else {
                base64 = record.getString("image_small");
            }
        }
        userImage.setImageBitmap(BitmapUtils.getBitmapImage(this, base64));
    } else {
        userImage.setColorFilter(Color.parseColor("#ffffff"));
    }
}

From source file:br.com.carlos.ceciliaapp.slidingtabs.SlidingTabLayout.java

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final View.OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;//from w w  w. jav  a  2  s .  c o m
        TextView tabTitleView = null;

        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
        }

        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }

        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
        }

        if (mDistributeEvenly) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
            lp.width = 0;
            lp.weight = 1;
        }

        tabTitleView.setText(adapter.getPageTitle(i));

        tabView.setOnClickListener(tabClickListener);
        String desc = mContentDescriptions.get(i, null);
        if (desc != null) {
            tabView.setContentDescription(desc);
        }

        mTabStrip.addView(tabView);
        if (i == mViewPager.getCurrentItem()) {
            tabView.setSelected(true);
        }

        tabTitleView.setTextColor(Color.parseColor("#ffffff"));

    }
}

From source file:com.dycody.android.idealnote.async.DataBackupIntentService.java

/**
  * Imports notes and notebooks from Springpad exported archive
  */*from   ww  w.ja va2  s  .  c om*/
  * @param intent
  */
synchronized private void importDataFromSpringpad(Intent intent) {
    String backupPath = intent.getStringExtra(EXTRA_SPRINGPAD_BACKUP);
    Importer importer = new Importer();
    try {
        importer.setZipProgressesListener(percentage -> mNotificationsHelper
                .setMessage(getString(com.dycody.android.idealnote.R.string.extracted) + " " + percentage + "%")
                .show());
        importer.doImport(backupPath);
        // Updating notification
        updateImportNotification(importer);
    } catch (ImportException e) {
        new NotificationsHelper(this)
                .createNotification(com.dycody.android.idealnote.R.drawable.ic_emoticon_sad_white_24dp,
                        getString(com.dycody.android.idealnote.R.string.import_fail) + ": " + e.getMessage(),
                        null)
                .setLedActive().show();
        return;
    }
    List<SpringpadElement> elements = importer.getSpringpadNotes();

    // If nothing is retrieved it will exit
    if (elements == null || elements.size() == 0) {
        return;
    }

    // These maps are used to associate with post processing notes to categories (notebooks)
    HashMap<String, Category> categoriesWithUuid = new HashMap<>();

    // Adds all the notebooks (categories)
    for (SpringpadElement springpadElement : importer.getNotebooks()) {
        Category cat = new Category();
        cat.setName(springpadElement.getName());
        cat.setColor(String.valueOf(Color.parseColor("#F9EA1B")));
        DbHelper.getInstance().updateCategory(cat);
        categoriesWithUuid.put(springpadElement.getUuid(), cat);

        // Updating notification
        importedSpringpadNotebooks++;
        updateImportNotification(importer);
    }
    // And creates a default one for notes without notebook 
    Category defaulCategory = new Category();
    defaulCategory.setName("Springpad");
    defaulCategory.setColor(String.valueOf(Color.parseColor("#F9EA1B")));
    DbHelper.getInstance().updateCategory(defaulCategory);

    // And then notes are created
    Note note;
    Attachment mAttachment = null;
    Uri uri;
    for (SpringpadElement springpadElement : importer.getNotes()) {
        note = new Note();

        // Title
        note.setTitle(springpadElement.getName());

        // Content dependent from type of Springpad note
        StringBuilder content = new StringBuilder();
        content.append(
                TextUtils.isEmpty(springpadElement.getText()) ? "" : Html.fromHtml(springpadElement.getText()));
        content.append(
                TextUtils.isEmpty(springpadElement.getDescription()) ? "" : springpadElement.getDescription());

        // Some notes could have been exported wrongly
        if (springpadElement.getType() == null) {
            Toast.makeText(this, getString(com.dycody.android.idealnote.R.string.error), Toast.LENGTH_SHORT)
                    .show();
            continue;
        }

        if (springpadElement.getType().equals(SpringpadElement.TYPE_VIDEO)) {
            try {
                content.append(System.getProperty("line.separator"))
                        .append(springpadElement.getVideos().get(0));
            } catch (IndexOutOfBoundsException e) {
                content.append(System.getProperty("line.separator")).append(springpadElement.getUrl());
            }
        }
        if (springpadElement.getType().equals(SpringpadElement.TYPE_TVSHOW)) {
            content.append(System.getProperty("line.separator"))
                    .append(TextUtils.join(", ", springpadElement.getCast()));
        }
        if (springpadElement.getType().equals(SpringpadElement.TYPE_BOOK)) {
            content.append(System.getProperty("line.separator")).append("Author: ")
                    .append(springpadElement.getAuthor()).append(System.getProperty("line.separator"))
                    .append("Publication date: ").append(springpadElement.getPublicationDate());
        }
        if (springpadElement.getType().equals(SpringpadElement.TYPE_RECIPE)) {
            content.append(System.getProperty("line.separator")).append("Ingredients: ")
                    .append(springpadElement.getIngredients()).append(System.getProperty("line.separator"))
                    .append("Directions: ").append(springpadElement.getDirections());
        }
        if (springpadElement.getType().equals(SpringpadElement.TYPE_BOOKMARK)) {
            content.append(System.getProperty("line.separator")).append(springpadElement.getUrl());
        }
        if (springpadElement.getType().equals(SpringpadElement.TYPE_BUSINESS)
                && springpadElement.getPhoneNumbers() != null) {
            content.append(System.getProperty("line.separator")).append("Phone number: ")
                    .append(springpadElement.getPhoneNumbers().getPhone());
        }
        if (springpadElement.getType().equals(SpringpadElement.TYPE_PRODUCT)) {
            content.append(System.getProperty("line.separator")).append("Category: ")
                    .append(springpadElement.getCategory()).append(System.getProperty("line.separator"))
                    .append("Manufacturer: ").append(springpadElement.getManufacturer())
                    .append(System.getProperty("line.separator")).append("Price: ")
                    .append(springpadElement.getPrice());
        }
        if (springpadElement.getType().equals(SpringpadElement.TYPE_WINE)) {
            content.append(System.getProperty("line.separator")).append("Wine type: ")
                    .append(springpadElement.getWine_type()).append(System.getProperty("line.separator"))
                    .append("Varietal: ").append(springpadElement.getVarietal())
                    .append(System.getProperty("line.separator")).append("Price: ")
                    .append(springpadElement.getPrice());
        }
        if (springpadElement.getType().equals(SpringpadElement.TYPE_ALBUM)) {
            content.append(System.getProperty("line.separator")).append("Artist: ")
                    .append(springpadElement.getArtist());
        }
        for (SpringpadComment springpadComment : springpadElement.getComments()) {
            content.append(System.getProperty("line.separator")).append(springpadComment.getCommenter())
                    .append(" commented at 0").append(springpadComment.getDate()).append(": ")
                    .append(springpadElement.getArtist());
        }

        note.setContent(content.toString());

        // Checklists
        if (springpadElement.getType().equals(SpringpadElement.TYPE_CHECKLIST)) {
            StringBuilder sb = new StringBuilder();
            String checkmark;
            for (SpringpadItem mSpringpadItem : springpadElement.getItems()) {
                checkmark = mSpringpadItem.getComplete()
                        ? it.feio.android.checklistview.interfaces.Constants.CHECKED_SYM
                        : it.feio.android.checklistview.interfaces.Constants.UNCHECKED_SYM;
                sb.append(checkmark).append(mSpringpadItem.getName())
                        .append(System.getProperty("line.separator"));
            }
            note.setContent(sb.toString());
            note.setChecklist(true);
        }

        // Tags
        String tags = springpadElement.getTags().size() > 0
                ? "#" + TextUtils.join(" #", springpadElement.getTags())
                : "";
        if (note.isChecklist()) {
            note.setTitle(note.getTitle() + tags);
        } else {
            note.setContent(note.getContent() + System.getProperty("line.separator") + tags);
        }

        // Address
        String address = springpadElement.getAddresses() != null ? springpadElement.getAddresses().getAddress()
                : "";
        if (!TextUtils.isEmpty(address)) {
            try {
                double[] coords = GeocodeHelper.getCoordinatesFromAddress(this, address);
                note.setLatitude(coords[0]);
                note.setLongitude(coords[1]);
            } catch (IOException e) {
                Log.e(Constants.TAG,
                        "An error occurred trying to resolve address to coords during Springpad import");
            }
            note.setAddress(address);
        }

        // Reminder
        if (springpadElement.getDate() != null) {
            note.setAlarm(springpadElement.getDate().getTime());
        }

        // Creation, modification, category
        note.setCreation(springpadElement.getCreated().getTime());
        note.setLastModification(springpadElement.getModified().getTime());

        // Image
        String image = springpadElement.getImage();
        if (!TextUtils.isEmpty(image)) {
            try {
                File file = StorageHelper.createNewAttachmentFileFromHttp(this, image);
                uri = Uri.fromFile(file);
                String mimeType = StorageHelper.getMimeType(uri.getPath());
                mAttachment = new Attachment(uri, mimeType);
            } catch (MalformedURLException e) {
                uri = Uri.parse(importer.getWorkingPath() + image);
                mAttachment = StorageHelper.createAttachmentFromUri(this, uri, true);
            } catch (IOException e) {
                Log.e(Constants.TAG, "Error retrieving Springpad online image");
            }
            if (mAttachment != null) {
                note.addAttachment(mAttachment);
            }
            mAttachment = null;
        }

        // Other attachments
        for (SpringpadAttachment springpadAttachment : springpadElement.getAttachments()) {
            // The attachment could be the image itself so it's jumped
            if (image != null && image.equals(springpadAttachment.getUrl()))
                continue;

            if (TextUtils.isEmpty(springpadAttachment.getUrl())) {
                continue;
            }

            // Tries first with online images
            try {
                File file = StorageHelper.createNewAttachmentFileFromHttp(this, springpadAttachment.getUrl());
                uri = Uri.fromFile(file);
                String mimeType = StorageHelper.getMimeType(uri.getPath());
                mAttachment = new Attachment(uri, mimeType);
            } catch (MalformedURLException e) {
                uri = Uri.parse(importer.getWorkingPath() + springpadAttachment.getUrl());
                mAttachment = StorageHelper.createAttachmentFromUri(this, uri, true);
            } catch (IOException e) {
                Log.e(Constants.TAG, "Error retrieving Springpad online image");
            }
            if (mAttachment != null) {
                note.addAttachment(mAttachment);
            }
            mAttachment = null;
        }

        // If the note has a category is added to the map to be post-processed
        if (springpadElement.getNotebooks().size() > 0) {
            note.setCategory(categoriesWithUuid.get(springpadElement.getNotebooks().get(0)));
        } else {
            note.setCategory(defaulCategory);
        }

        // The note is saved
        DbHelper.getInstance().updateNote(note, false);
        ReminderHelper.addReminder(IdealNote.getAppContext(), note);

        // Updating notification
        importedSpringpadNotes++;
        updateImportNotification(importer);
    }

    // Delete temp data
    try {
        importer.clean();
    } catch (IOException e) {
        Log.w(Constants.TAG, "Springpad import temp files not deleted");
    }

    String title = getString(com.dycody.android.idealnote.R.string.data_import_completed);
    String text = getString(com.dycody.android.idealnote.R.string.click_to_refresh_application);
    createNotification(intent, this, title, text, null);
}