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.example.android.wifidirect.WiFiDirectActivity.java

private void setTabsValue() {
    // Tab?//from www .  ja  v  a 2s.  com
    tabs.setShouldExpand(true);
    // Tab?
    tabs.setDividerColor(Color.TRANSPARENT);
    // Tab
    tabs.setUnderlineHeight((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, dm));
    // Tab Indicator
    tabs.setIndicatorHeight((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, dm));
    // Tab?
    tabs.setTextSize((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 16, dm));
    // Tab Indicator
    tabs.setIndicatorColor(Color.parseColor("#45c01a"));
    // Tab ()
    tabs.setSelectedTextColor(Color.parseColor("#45c01a"));
    // ?Tab
    tabs.setTabBackground(0);

    //?tab
    tabs.setTabPaddingLeftRight(36);

    // tab?tab?tab???
    //tabs.setShouldExpand(true);

}

From source file:co.uk.sentinelweb.drawcustom.api.DrawCustomSetTemplate.java

public boolean fromJSON(String s) {
    try {/*from ww w .  jav a2 s .co m*/
        JSONObject o = new JSONObject(new JSONTokener(s));
        try {
            this.version = o.getInt("version");
        } catch (JSONException e) {
        }
        try {
            this.width = o.getInt("width");
        } catch (JSONException e) {
        }
        try {
            this.height = o.getInt("height");
        } catch (JSONException e) {
        }
        try {
            String colorString = o.getString("bg");
            bgColor = Color.parseColor(colorString);
        } catch (Exception e) {
        }
        try {
            description = o.getString("description");
        } catch (JSONException e) {
        }
        JSONArray itemsJSON = o.getJSONArray("items");
        items.clear();
        itemsOrder.clear();
        //JSONArray names = itemsJSON.names();
        for (int i = 0; i < itemsJSON.length(); i++) {
            JSONObject itemJSON = itemsJSON.getJSONObject(i);
            DrawCustomSetItem dcsi = new DrawCustomSetItem();
            String key = dcsi.fromJSON(itemJSON);
            items.put(key, dcsi);
            itemsOrder.add(key);
        }
        return true;
    } catch (JSONException e) {
        Log.d(DrawCustomGlobals.TAG, "Error parsing JSON template:", e);
        return false;
    }
}

From source file:com.franmontiel.fcmnotificationhandler.RemoteMessageToNotificationMapper.java

@Nullable
private Integer parseColor(RemoteMessage.Notification fcmNotification) {
    String notificationColor = fcmNotification.getColor();

    Integer color = null;/*from w  w  w. j  a  v  a 2s.  c o  m*/
    if (notificationColor != null) {
        try {
            color = Color.parseColor(notificationColor);
        } catch (IllegalArgumentException ignore) {
        }
    }
    if (color == null) {
        int colorResId = getResourceIdFromApplicationMetadata(
                "com.google.firebase.messaging.default_notification_color");
        if (colorResId != 0)
            color = ContextCompat.getColor(context, colorResId);
    }
    return color;
}

From source file:com.dm.xz.views.PinnedSectionListView.java

public void initShadow(boolean visible) {
    if (visible) {
        if (mShadowDrawable == null) {
            mShadowDrawable = new GradientDrawable(Orientation.TOP_BOTTOM,
                    new int[] { Color.parseColor("#ffa0a0a0"), Color.parseColor("#50a0a0a0"),
                            Color.parseColor("#00a0a0a0") });
            mShadowHeight = (int) (8 * getResources().getDisplayMetrics().density);
        }//from  w  w w .  j av a2s.c o m
    } else {
        if (mShadowDrawable != null) {
            mShadowDrawable = null;
            mShadowHeight = 0;
        }
    }
}

From source file:com.musenkishi.atelier.Atelier.java

private static void applyColorToView(final CardView cardView, int color, boolean fromCache) {
    if (fromCache) {
        cardView.setCardBackgroundColor(color);
    } else {/*from  w  w w.jav  a2  s  .  c  om*/
        Integer colorFrom = Color.parseColor("#FFFAFAFA"); //Default light CardView color.
        Integer colorTo = color;
        ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
        colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animator) {
                cardView.setCardBackgroundColor((Integer) animator.getAnimatedValue());
            }
        });
        colorAnimation.setDuration(300);
        colorAnimation.start();
    }
}

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

@Override
public void onActivityCreated(Bundle savedInstanceState) {

    super.onActivityCreated(savedInstanceState);
    s = getArguments().getString("path");
    f = new File(s);
    listView.setVisibility(View.VISIBLE);
    Sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
    res = getResources();//from   w w w. j  av  a 2  s .  c o m

    listView.setVisibility(View.VISIBLE);
    mLayoutManager = new LinearLayoutManager(getActivity());
    listView.setLayoutManager(mLayoutManager);
    if (mainActivity.theme1 == 1)
        rootView.setBackgroundColor(getResources().getColor(R.color.holo_dark_background));
    else

        listView.setBackgroundColor(getResources().getColor(android.R.color.background_light));

    gobackitem = Sp.getBoolean("goBack_checkbox", true);
    coloriseIcons = Sp.getBoolean("coloriseIcons", false);
    Calendar calendar = Calendar.getInstance();
    showSize = Sp.getBoolean("showFileSize", false);
    showLastModified = Sp.getBoolean("showLastModified", true);
    showDividers = Sp.getBoolean("showDividers", true);
    year = ("" + calendar.get(Calendar.YEAR)).substring(2, 4);
    skin = Sp.getString("skin_color", "#3f51b5");
    iconskin = Sp.getString("icon_skin_color", skin);
    String x = getSelectionColor();
    skinselection = Color.parseColor(x);
    files = new ArrayList<File>();
    loadlist(f.getPath());
    mToolbarContainer = getActivity().findViewById(R.id.lin);
    hidemode = Sp.getInt("hidemode", 0);
    try {
        mainActivity.toolbar.setTitle(f.getName());
    } catch (Exception e) {
        mainActivity.toolbar.setTitle(getResources().getString(R.string.zip_viewer));
    }
    mainActivity.tabsSpinner.setVisibility(View.GONE);
    mainActivity.fabHideAnim = AnimationUtils.loadAnimation(getActivity(), R.anim.fab_hide);
    mainActivity.floatingActionButton.setAnimation(mainActivity.fabHideAnim);
    mainActivity.floatingActionButton.animate();
    mainActivity.floatingActionButton.setVisibility(View.GONE);

    mainActivity.supportInvalidateOptionsMenu();
    mToolbarHeight = getToolbarHeight(getActivity());
    paddingTop = (mToolbarHeight) + dpToPx(72);
    if (hidemode == 2)
        mToolbarHeight = paddingTop;
    mToolbarContainer.getViewTreeObserver()
            .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {

                    paddingTop = mToolbarContainer.getHeight();
                    if (hidemode != 2)
                        mToolbarHeight = mainActivity.toolbar.getHeight();
                    else
                        mToolbarHeight = paddingTop;

                    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
                        mToolbarContainer.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                    } else {
                        mToolbarContainer.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                    }
                }

            });
}

From source file:com.android.kalite27.ScriptActivity.java

@SuppressLint("NewApi")
@Override/*from w ww .  ja v  a 2  s. com*/
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // mounted sdcard ?
    //if (!Environment.getExternalStorageState().equals("mounted")) {
    //  Log.e(GlobalConstants.LOG_TAG, "External storage is not mounted");
    //  
    //  Toast toast = Toast.makeText( getApplicationContext(), "External storage not mounted", Toast.LENGTH_LONG);
    //  toast.show();
    //  return;
    //}
    mUtilities = new KaliteUtilities();
    GlobalValues.initialize(this);
    gv = GlobalValues.getInstance();

    // set the lauching ui
    setContentView(R.layout.activity_launching);

    startView = (RelativeLayout) findViewById(R.id.startView);
    retryButton = (Button) findViewById(R.id.buttonStart);
    spinner = (ProgressBar) findViewById(R.id.progressBar);
    webProgressBar = (ProgressBar) findViewById(R.id.webProgressBar);
    ServerStatusTextView = (TextView) findViewById(R.id.ServerStatus);
    FileTextView = (TextView) findViewById(R.id.FileDirectory);

    // check internet
    new InternetCheckAsyncTask().execute();

    retryButton.setVisibility(View.INVISIBLE);

    // install needed ?
    boolean installNeeded = isInstallNeeded();

    // first time running
    if (installNeeded) {
        // this will also call generate_local_settings after unzip library
        spinner.setVisibility(View.INVISIBLE);
        mViewPager = (ViewPager) findViewById(R.id.view_pager);
        mViewPager.setVisibility(View.VISIBLE);
        isGuideClosed = false;
        mViewPager.setAdapter(new GuidePagerAdapter());
        mViewPager.setOnPageChangeListener(new GuidePageChangeListener());
        new InstallAsyncTask().execute();
    } else {
        contentPath = mUtilities.readContentPath(this);
        contentPath = contentPath.replaceAll("\n", "");
        File contentFiles = new File(contentPath);
        if (contentFiles.exists()) {
            FileTextView.setText("Content Location: " + contentPath);
            FileTextView.setBackgroundColor(Color.parseColor("#A3CC7A"));
            runScriptService("start");
        } else {
            //             spinner.setVisibility(View.INVISIBLE);
            ServerStatusTextView.setText("Please set the content folder path first.");
            ServerStatusTextView.setTextColor(Color.parseColor("#FF9966"));
            //                 runScriptService("start");
        }
    }

    wv = (XWalkView) findViewById(R.id.webview);
    wv.setVisibility(View.INVISIBLE);
    wv.setLayerType(View.LAYER_TYPE_HARDWARE, null);

    mCookieManager = new XWalkCookieManager();
    mCookieManager.setAcceptCookie(true);
    mCookieManager.setAcceptFileSchemeCookies(true);

    wv.setResourceClient(new XWalkResourceClient(wv) {
        @Override
        public void onLoadStarted(XWalkView view, String url) {
            super.onLoadStarted(view, url);
            if (!isHeartViewClosed) {
                wv.getNavigationHistory().clear();
            }
        }

        @Override
        public void onLoadFinished(XWalkView view, String url) {
            super.onLoadFinished(view, url);
            webProgressBar.setVisibility(View.INVISIBLE);
            if (url.equals("http://0.0.0.0:8008/") && isHomePageFirstTime) {
                isHomePageFirstTime = false;
                startView.setVisibility(View.GONE);
                view.setVisibility(View.VISIBLE);
                view.getNavigationHistory().clear();
            }
        }

        @Override
        public void onProgressChanged(XWalkView view, int progress) {
            webProgressBar.setProgress(progress);
            if (progress > 99) {
                webProgressBar.setProgress(0);
            }
        }

        @Override
        public boolean shouldOverrideUrlLoading(XWalkView view, String url) {
            if (!isHomePageFirstTime) {
                webProgressBar.setVisibility(View.VISIBLE);
            }
            if (!isHeartViewClosed) {
                webProgressBar.setVisibility(View.VISIBLE);
                wv.getNavigationHistory().clear();
            }
            if (url.startsWith("http://0.0.0.0:8008/api/control_panel/") && url.contains("format=csv")) {
                //               dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
                //               String cookies = mCookieManager.getCookie(url);
                //                 Request request = new Request(
                //                       Uri.parse(url));
                //                 request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
                //                    .setTitle(csv_name)
                //                    .addRequestHeader("Cookie", cookies)
                //                    .setMimeType("text/csv")
                //                    .setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, csv_name);
                //                 dm.enqueue(request);
                new DownloadFile().execute(url);
                return true;
            }
            return false;
        }
    });

    XWalkPreferences.setValue("enable-javascript", true);
    XWalkPreferences.setValue(XWalkPreferences.JAVASCRIPT_CAN_OPEN_WINDOW, true);
    XWalkPreferences.setValue(XWalkPreferences.SUPPORT_MULTIPLE_WINDOWS, false);
    /*
     * !!! remember to disable REMOTE_DEBUGGING in production, it causes error message overflow
     */
    if (GlobalConstants.IS_REMOTE_DEBUGGING) {
        XWalkPreferences.setValue(XWalkPreferences.REMOTE_DEBUGGING, true);
    }

    //      new PreCacheAsyncTask().execute();
    prefs = getSharedPreferences("MyPrefs", MODE_MULTI_PROCESS);
    editor = prefs.edit();
    //clean kalite_command from before, we are not using SharedPreferences in conventional way.
    editor.clear();
    editor.commit();

    prefs_listener = new SharedPreferences.OnSharedPreferenceChangeListener() {
        public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
            if (prefs.getBoolean("from_process", false)) {
                editor.putBoolean("from_process", false);
                int server_status = prefs.getInt("python_exit_code", -7);
                String kalite_command = prefs.getString("kalite_command", "no command yet");

                if (server_status == 0) { // 0 means the server is running
                    isServerRunning = true;
                    openWebViewIfAllConditionsMeet();
                } else if (server_status != 0 && kalite_command.equals("start")
                        || kalite_command.equals("restart")) {
                    runScriptService("status");
                } else if (kalite_command.equals("status")) {
                    ServerStatusTextView.setText(mUtilities.exitCodeTranslate(server_status));
                    ServerStatusTextView.setTextColor(Color.parseColor("#FF9966"));
                    spinner.setVisibility(View.INVISIBLE);
                    retryButton.setVisibility(View.VISIBLE);
                }
            }
        }
    };
    prefs.registerOnSharedPreferenceChangeListener(prefs_listener);
}

From source file:com.arlib.floatingsearchviewdemo.MainActivity.java

private void setupFloatingSearch() {
    mSearchView.setOnQueryChangeListener(new FloatingSearchView.OnQueryChangeListener() {

        @Override//w  w  w . j a va2 s.co  m
        public void onSearchTextChanged(String oldQuery, final String newQuery) {

            if (!oldQuery.equals("") && newQuery.equals("")) {
                mSearchView.clearSuggestions();
            } else {

                //this shows the top left circular progress
                //you can call it where ever you want, but
                //it makes sense to do it when loading something in
                //the background.
                mSearchView.showProgress();

                //simulates a query call to a data source
                //with a new query.
                DataHelper.findSuggestions(MainActivity.this, newQuery, 5, FIND_SUGGESTION_SIMULATED_DELAY,
                        new DataHelper.OnFindSuggestionsListener() {

                            @Override
                            public void onResults(List<ColorSuggestion> results) {

                                //this will swap the data and
                                //render the collapse/expand animations as necessary
                                mSearchView.swapSuggestions(results);

                                //let the users know that the background
                                //process has completed
                                mSearchView.hideProgress();
                            }
                        });
            }

            Log.d(TAG, "onSearchTextChanged()");
        }
    });

    mSearchView.setOnSearchListener(new FloatingSearchView.OnSearchListener() {
        @Override
        public void onSuggestionClicked(SearchSuggestion searchSuggestion) {

            ColorSuggestion colorSuggestion = (ColorSuggestion) searchSuggestion;
            DataHelper.findColors(MainActivity.this, colorSuggestion.getBody(),
                    new DataHelper.OnFindColorsListener() {

                        @Override
                        public void onResults(List<ColorWrapper> results) {
                            mSearchResultsAdapter.swapData(results);
                        }

                    });
            Log.d(TAG, "onSuggestionClicked()");
        }

        @Override
        public void onSearchAction(String query) {

            DataHelper.findColors(MainActivity.this, query, new DataHelper.OnFindColorsListener() {

                @Override
                public void onResults(List<ColorWrapper> results) {
                    mSearchResultsAdapter.swapData(results);
                }

            });
            Log.d(TAG, "onSearchAction()");
        }
    });

    mSearchView.setOnFocusChangeListener(new FloatingSearchView.OnFocusChangeListener() {
        @Override
        public void onFocus() {
            mSearchView.clearQuery();

            //show suggestions when search bar gains focus (typically history suggestions)
            mSearchView.swapSuggestions(DataHelper.getHistory(MainActivity.this, 3));

            Log.d(TAG, "onFocus()");
        }

        @Override
        public void onFocusCleared() {

            Log.d(TAG, "onFocusCleared()");
        }
    });

    //handle menu clicks the same way as you would
    //in a regular activity
    mSearchView.setOnMenuItemClickListener(new FloatingSearchView.OnMenuItemClickListener() {
        @Override
        public void onActionMenuItemSelected(MenuItem item) {

            if (item.getItemId() == R.id.action_change_colors) {

                mIsDarkSearchTheme = true;

                //demonstrate setting colors for items
                mSearchView.setBackgroundColor(Color.parseColor("#787878"));
                mSearchView.setViewTextColor(Color.parseColor("#e9e9e9"));
                mSearchView.setHintTextColor(Color.parseColor("#e9e9e9"));
                mSearchView.setActionMenuOverflowColor(Color.parseColor("#e9e9e9"));
                mSearchView.setMenuItemIconColor(Color.parseColor("#e9e9e9"));
                mSearchView.setLeftActionIconColor(Color.parseColor("#e9e9e9"));
                mSearchView.setClearBtnColor(Color.parseColor("#e9e9e9"));
                mSearchView.setDividerColor(Color.parseColor("#BEBEBE"));
                mSearchView.setLeftActionIconColor(Color.parseColor("#e9e9e9"));
            } else {

                //just print action
                Toast.makeText(getApplicationContext(), item.getTitle(), Toast.LENGTH_SHORT).show();
            }

        }
    });

    //use this listener to listen to menu clicks when app:floatingSearch_leftAction="showHamburger"
    mSearchView.setOnLeftMenuClickListener(new FloatingSearchView.OnLeftMenuClickListener() {
        @Override
        public void onMenuOpened() {

            Log.d(TAG, "onMenuOpened()");
            mDrawerLayout.openDrawer(GravityCompat.START);
        }

        @Override
        public void onMenuClosed() {
            Log.d(TAG, "onMenuClosed()");
        }
    });

    //use this listener to listen to menu clicks when app:floatingSearch_leftAction="showHome"
    mSearchView.setOnHomeActionClickListener(new FloatingSearchView.OnHomeActionClickListener() {
        @Override
        public void onHomeClicked() {

            Log.d(TAG, "onHomeClicked()");
        }
    });

    /*
     * Here you have access to the left icon and the text of a given suggestion
     * item after as it is bound to the suggestion list. You can utilize this
     * callback to change some properties of the left icon and the text. For example, you
     * can load the left icon images using your favorite image loading library, or change text color.
     *
     *
     * Important:
     * Keep in mind that the suggestion list is a RecyclerView, so views are reused for different
     * items in the list.
     */
    mSearchView.setOnBindSuggestionCallback(new SearchSuggestionsAdapter.OnBindSuggestionCallback() {
        @Override
        public void onBindSuggestion(View suggestionView, ImageView leftIcon, TextView textView,
                SearchSuggestion item, int itemPosition) {
            ColorSuggestion colorSuggestion = (ColorSuggestion) item;

            String textColor = mIsDarkSearchTheme ? "#ffffff" : "#000000";
            String textLight = mIsDarkSearchTheme ? "#bfbfbf" : "#787878";

            if (colorSuggestion.getIsHistory()) {
                leftIcon.setImageDrawable(
                        ResourcesCompat.getDrawable(getResources(), R.drawable.ic_history_black_24dp, null));

                Util.setIconColor(leftIcon, Color.parseColor(textColor));
                leftIcon.setAlpha(.36f);
            } else {
                leftIcon.setAlpha(0.0f);
                leftIcon.setImageDrawable(null);
            }

            textView.setTextColor(Color.parseColor(textColor));
            String text = colorSuggestion.getBody().replaceFirst(mSearchView.getQuery(),
                    "<font color=\"" + textLight + "\">" + mSearchView.getQuery() + "</font>");
            textView.setText(Html.fromHtml(text));
        }

    });

    //listen for when suggestion list expands/shrinks in order to move down/up the
    //search results list
    mSearchView.setOnSuggestionsListHeightChanged(new FloatingSearchView.OnSuggestionsListHeightChanged() {
        @Override
        public void onSuggestionsListHeightChanged(float newHeight) {
            mSearchResultsList.setTranslationY(newHeight);
        }
    });
}

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

public MaterialDialog showNameDialog(final MainActivity m, String[] texts) {
    MaterialDialog.Builder a = new MaterialDialog.Builder(m);
    a.input(texts[0], texts[1], false, new MaterialDialog.InputCallback() {
        @Override//from  w  w w  .ja v a  2 s.  c om
        public void onInput(MaterialDialog materialDialog, CharSequence charSequence) {

        }
    });
    a.widgetColor(Color.parseColor(m.fabskin));
    if (m.theme1 == 1)
        a.theme(Theme.DARK);
    a.title(texts[2]);
    a.positiveText(texts[3]);
    a.positiveColor(Color.parseColor(m.fabskin));
    a.neutralText(texts[4]);
    if (texts[5] != (null)) {
        a.negativeText(texts[5]);
        a.negativeColor(Color.parseColor(m.fabskin));
    }
    MaterialDialog dialog = a.build();
    return dialog;
}

From source file:com.esri.android.ecologicalmarineunitexplorer.bottomsheet.BottomSheetFragment.java

/**
 * Build a stateful drawable for a given EMU
 * @param emuName String representing name
 * @return StateListDrawable responsive to selected, pressed, and enabled states
 *//*from  w w w. j  av a2s  .  c om*/
private static StateListDrawable buildStateList(final int emuName) {
    final StateListDrawable stateListDrawable = new StateListDrawable();

    final GradientDrawable defaultShape = new GradientDrawable();
    final int color = Color.parseColor(EmuHelper.getColorForEMUCluster(emuName));
    defaultShape.setColor(color);

    final GradientDrawable selectedPressShape = new GradientDrawable();
    selectedPressShape.setColor(color);
    selectedPressShape.setStroke(5, Color.parseColor("#f4f442"));

    stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, selectedPressShape);
    stateListDrawable.addState(new int[] { android.R.attr.state_selected }, selectedPressShape);
    stateListDrawable.addState(new int[] { android.R.attr.state_enabled }, defaultShape);

    return stateListDrawable;
}