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.appnexus.opensdkapp.PreviewFragment.java

public void loadNewAd() {
    Log.d(Constants.BASE_LOG_TAG, "Loading new ad");
    //resetBanner();

    Context context = getActivity();
    if (context == null) {
        Clog.e(Constants.PREFS_TAG, "activity context null. don't load ad");
        return;/*from   w  w w.  j  a  v  a2  s  .c  o  m*/
    }

    SettingsWrapper settingsWrapper = SettingsWrapper.getSettingsWrapperFromPrefs(context);
    Clog.d(Constants.BASE_LOG_TAG, settingsWrapper.toString());

    if (settingsWrapper.isAdTypeBanner()) {
        // Load and display a banner
        bav.setAutoRefreshInterval(settingsWrapper.getRefreshPeriod());
        bav.setAdWidth(settingsWrapper.getWidth());
        bav.setAdHeight(settingsWrapper.getHeight());

        bav.setShouldServePSAs(settingsWrapper.isAllowPsas());
        bav.setOpensNativeBrowser(!settingsWrapper.isBrowserInApp());
        bav.setPlacementID(settingsWrapper.getPlacementId());
        if (!bav.loadAd()) {
            adListener.onAdRequestFailed(null);
        }
    } else {
        bav.setAutoRefreshInterval(0);
        bav.setVisibility(View.GONE);
        bannerText.setVisibility(TextView.VISIBLE);
        // Load and display an interstitial
        iav.setShouldServePSAs(settingsWrapper.isAllowPsas());
        iav.setOpensNativeBrowser(!settingsWrapper.isBrowserInApp());
        iav.setPlacementID(settingsWrapper.getPlacementId());

        int color = DEF_COLOR;

        // try to retrieve background color. default if not
        String backgroundHex = settingsWrapper.getBackgroundColor();
        if (backgroundHex.length() == 8) {
            try {
                color = Color.parseColor("#" + backgroundHex);
            } catch (IllegalArgumentException e) {
                Clog.d(Constants.BASE_LOG_TAG, "Invalid hex color");
            }
        }
        iav.setBackgroundColor(color);
        if (!iav.loadAd()) {
            adListener.onAdRequestFailed(null);
        }
    }
}

From source file:com.github.hobbe.android.openkarotz.fragment.ColorFragment.java

private void initializeColorLayout(View view) {
    colorLayout = (FlowLayout) view.findViewById(R.id.layoutColors);

    buttonMap = new HashMap<String, Button>();

    for (String c : colors) {
        int color = Color.parseColor('#' + c);

        // Button
        Button btn = new ColorButton(getActivity(), color);
        btn.setId(color);/*from   w w  w. jav  a2  s. co m*/
        btn.setOnClickListener(new ColorButtonOnClickListener(color));

        buttonMap.put(c, btn);
        colorLayout.addView(btn, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    }
}

From source file:com.example.android.swiperefreshlistfragment.SwipeRefreshListFragmentFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    /**//from   w w w  .j  a v  a2 s  .  c  om
     * Create an ArrayAdapter to contain the data for the ListView. Each item in the ListView
     * uses the system-defined simple_list_item_1 layout that contains one TextView.
     */
    //        ListAdapter adapter = new ArrayAdapter<String>(
    //                getActivity(),
    //                android.R.layout.simple_list_item_1,
    //                android.R.id.text1,
    //                Cheeses.randomList(LIST_ITEM_COUNT));
    mFeedItems = new ArrayList<FeedItem>();
    mFeedListAdapter = new FeedListAdapter(getActivity(), mFeedItems);

    // Set the adapter between the ListView and its backing data.
    setListAdapter(mFeedListAdapter);

    // BEGIN_INCLUDE (setup_refreshlistener)
    /**
     * Implement {@link SwipeRefreshLayout.OnRefreshListener}. When users do the "swipe to
     * refresh" gesture, SwipeRefreshLayout invokes
     * {@link SwipeRefreshLayout.OnRefreshListener#onRefresh onRefresh()}. In
     * {@link SwipeRefreshLayout.OnRefreshListener#onRefresh onRefresh()}, call a method that
     * refreshes the content. Call the same method in response to the Refresh action from the
     * action bar.
     */
    // These two lines not needed,
    // just to get the look of facebook (changing background color & hiding the icon)
    getActivity().getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#3b5998")));
    getActivity().getActionBar()
            .setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent)));
    setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            Log.i(LOG_TAG, "onRefresh called from SwipeRefreshLayout");
            doRequest();
            //                initiateRefresh();
        }
    });

    // END_INCLUDE (setup_refreshlistener)
}

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

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

    if (theme1 == 1) {
        getWindow().getDecorView().setBackgroundColor(ContextCompat.getColor(c, R.color.holo_dark_background));
    }//  w w  w . jav  a2 s . c  o  m
    setContentView(R.layout.search);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    skin = PreferenceUtils.getPrimaryColorString(Sp);
    findViewById(R.id.lin).setBackgroundColor(Color.parseColor(skin));
    if (Build.VERSION.SDK_INT >= 21) {
        ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription("File Manager",
                ((BitmapDrawable) ContextCompat.getDrawable(c, R.mipmap.ic_launcher)).getBitmap(),
                Color.parseColor(skin));
        ((Activity) this).setTaskDescription(taskDescription);
    }
    int skinStatusBar = PreferenceUtils.getStatusColor(skin);
    assert (getSupportActionBar()) != null;
    getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor(skin)));
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    if (Build.VERSION.SDK_INT == 20 || Build.VERSION.SDK_INT == 19) {
        SystemBarTintManager tintManager = new SystemBarTintManager(this);
        tintManager.setStatusBarTintEnabled(true);
        tintManager.setStatusBarTintColor(Color.parseColor(skin));
        FrameLayout.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) findViewById(R.id.texteditor)
                .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)));

    }
    mInput = (EditText) findViewById(R.id.fname);
    scrollView = (ScrollView) findViewById(R.id.editscroll);

    try {
        if (getIntent().getData() != null) {
            uri = getIntent().getData();

            mFile = new File(getIntent().getData().getPath());
        } else
            mFile = new File(getIntent().getStringExtra("path"));
    } catch (Exception e) {
        mFile = null;
    }
    String fileName = null;
    try {
        if (uri.getScheme().equals("file")) {
            fileName = uri.getLastPathSegment();
        } else {
            Cursor cursor = null;
            try {
                cursor = getContentResolver().query(uri,
                        new String[] { MediaStore.Images.ImageColumns.DISPLAY_NAME }, null, null, null);

                if (cursor != null && cursor.moveToFirst()) {
                    fileName = cursor
                            .getString(cursor.getColumnIndex(MediaStore.Images.ImageColumns.DISPLAY_NAME));
                }
            } finally {

                if (cursor != null) {
                    cursor.close();
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (fileName == null || fileName.trim().length() == 0)
        fileName = f.getName();
    getSupportActionBar().setTitle(fileName);
    mInput.addTextChangedListener(this);
    try {
        if (theme1 == 1)
            mInput.setBackgroundColor(ContextCompat.getColor(c, R.color.holo_dark_background));
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    } catch (Exception ignored) {

    }
    if (savedInstanceState != null) {
        mOriginal = savedInstanceState.getString(KEY_ORIGINAL_TEXT);
        int index = savedInstanceState.getInt(KEY_INDEX);
        mInput.setText(savedInstanceState.getString(KEY_MODIFIED_TEXT));
        mInput.setScrollY(index);
    } else {
        load(mFile);
    }
}

From source file:beihua.example.com.kouding_app.MainActivity.java

public void onColorClicked(View v) {

    int color = Color.parseColor(v.getTag().toString());
    changeColor(color);

}

From source file:com.dw.bartinter.BarTinter.java

private void navigationBar(final String colorPref) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        if (colorPref != null && !colorPref.isEmpty()) {
            final Window window = cordova.getActivity().getWindow();
            window.clearFlags(0x04000000);
            window.addFlags(0x80000000);
            try {
                window.getClass().getDeclaredMethod("setNavigationBarColor", int.class).invoke(window,
                        Color.parseColor(colorPref));
            } catch (IllegalArgumentException ignore) {
                Log.e(PLUGIN, "Invalid hexString argument.");
            } catch (Exception ignore) {
                Log.w(PLUGIN,/*from   w w  w.j  a  va 2  s  .co  m*/
                        "Method window.setNavigationBarColor not found for SDK level " + Build.VERSION.SDK_INT);
            }
        }
    }
}

From source file:com.pspdfkit.cordova.PSPDFCordovaPlugin.java

@SuppressWarnings("ConstantConditions")
@NonNull/*from ww w .j a v a2s . c o  m*/
private PSPDFActivityConfiguration parseOptionsToConfiguration(@NonNull final JSONObject options)
        throws JSONException {
    final Activity activity = cordova.getActivity();
    int theme;

    try {
        ActivityInfo info = activity.getPackageManager()
                .getActivityInfo(new ComponentName(activity, PSPDFActivity.class), 0);
        theme = info.theme;
    } catch (PackageManager.NameNotFoundException e) {
        theme = R.style.Theme_AppCompat_NoActionBar;
    }

    final ContextThemeWrapper themedContext = new ContextThemeWrapper(activity, theme);
    final PSPDFActivityConfiguration.Builder builder = new PSPDFActivityConfiguration.Builder(themedContext,
            licenseKey);
    final Iterator<String> optionIterator = options.keys();

    while (optionIterator.hasNext()) {
        final String option = optionIterator.next();
        final Object value = options.get(option);

        try {
            if ("backgroundColor".equals(option)) {
                builder.backgroundColor(Color.parseColor((String) value));
            } else if ("disableOutline".equals(option) && ((Boolean) value)) {
                builder.disableOutline();
            } else if ("disableSearch".equals(option) && ((Boolean) value)) {
                builder.disableSearch();
            } else if ("hidePageLabels".equals(option) && ((Boolean) value)) {
                builder.hidePageLabels();
            } else if ("hidePageNumberOverlay".equals(option) && ((Boolean) value)) {
                builder.hidePageNumberOverlay();
            } else if ("hideThumbnailBar".equals(option) && ((Boolean) value)) {
                builder.hideThumbnailBar();
            } else if ("hideThumbnailGrid".equals(option) && ((Boolean) value)) {
                builder.hideThumbnailGrid();
            } else if ("diskCacheSize".equals(option)) {
                builder.diskCacheSize((Integer) value);
            } else if ("memoryCacheSize".equals(option)) {
                builder.memoryCacheSize((Integer) value);
            } else if ("pageFitMode".equals(option)) {
                builder.fitMode(PageFitMode.valueOf((String) value));
            } else if ("scrollDirection".equals(option)) {
                builder.scrollDirection(PageScrollDirection.valueOf((String) value));
            } else if ("scrollMode".equals(option)) {
                builder.scrollMode(PageScrollMode.valueOf((String) value));
            } else if ("invertColors".equals(option)) {
                builder.invertColors((Boolean) value);
            } else if ("toGrayscale".equals(option)) {
                builder.toGrayscale((Boolean) value);
            } else if ("loggingEnabled".equals(option)) {
                builder.loggingEnabled((Boolean) value);
            } else if ("title".equals(option)) {
                builder.title(fromJsonString(options.getString("title")));
            } else if ("startZoomScale".equals(option)) {
                builder.startZoomScale((float) options.getDouble("startZoomScale"));
            } else if ("maxZoomScale".equals(option)) {
                builder.maxZoomScale((float) options.getDouble("maxZoomScale"));
            } else if ("zoomOutBounce".equals(option)) {
                builder.zoomOutBounce(options.getBoolean("zoomOutBounce"));
            } else if ("page".equals(option)) {
                builder.page(options.getInt("page"));
            } else if ("useImmersiveMode".equals(option)) {
                builder.useImmersiveMode(options.getBoolean("useImmersiveMode"));
            } else if ("searchType".equals(option)) {
                final String searchType = options.getString("searchType");
                if ("SEARCH_INLINE".equals(searchType))
                    builder.setSearchType(PSPDFActivityConfiguration.SEARCH_INLINE);
                else if ("SEARCH_MODULAR".equals(searchType))
                    builder.setSearchType(PSPDFActivityConfiguration.SEARCH_MODULAR);
                else
                    throw new IllegalArgumentException(String.format("Invalid search type: %s", value));
            } else if ("autosaveEnabled".equals(option)) {
                builder.autosaveEnabled(options.getBoolean("autosaveEnabled"));
            } else if ("annotationEditing".equals(option)) {
                final AnnotationEditingConfiguration.Builder annotationBuilder = new AnnotationEditingConfiguration.Builder(
                        themedContext);
                final JSONObject annotationEditing = options.getJSONObject("annotationEditing");
                final Iterator<String> annotationOptionIterator = annotationEditing.keys();

                while (annotationOptionIterator.hasNext()) {
                    final String annotationEditingOption = annotationOptionIterator.next();
                    final Object annotationEditingValue = annotationEditing.get(annotationEditingOption);

                    if ("enabled".equals(annotationEditingOption)) {
                        if ((Boolean) annotationEditingValue)
                            annotationBuilder.enableAnnotationEditing();
                        else
                            annotationBuilder.disableAnnotationEditing();
                    } else if ("creatorName".equals(annotationEditingOption)) {
                        annotationBuilder.defaultAnnotationCreator(
                                fromJsonString(annotationEditing.getString("creatorName")));
                    } else {
                        throw new IllegalArgumentException(String
                                .format("Invalid annotation editing option '%s'", annotationEditingOption));
                    }
                }

                builder.annotationEditingConfiguration(annotationBuilder.build());
            } else {
                throw new IllegalArgumentException(String.format("Invalid plugin option '%s'", option));
            }
        } catch (Exception ex) {
            throw new PSPDFCordovaPluginException(String.format("Error while parsing option '%s'", option), ex);
        }
    }

    return builder.build();
}

From source file:com.forrestguice.suntimeswidget.settings.ColorChooser.java

/**
 * Set the color.//w ww  .j a va 2 s .  c o m
 * @param hexCode hex color code #aarrggbb
 */
public void setColor(String hexCode) {
    this.color = Color.parseColor(hexCode);
    updateViews();
}

From source file:com.cryart.sabbathschool.view.SSQuarterliesActivity.java

private void updateColorScheme() {
    int primaryColor = Color.parseColor(SSColorTheme.getInstance().getColorPrimary());
    binding.ssAppBar.ssToolbar.setBackgroundColor(primaryColor);
    binding.ssLanguageMenu.ssLanguageMenuHeader.setBackgroundColor(primaryColor);

    updateWindowColorScheme();/*from w  w  w .  j a va  2 s .c  om*/
}

From source file:com.elekso.potfix.MainActivity.java

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

    PowerManager pm = (PowerManager) getApplicationContext()
            .getSystemService(getApplicationContext().POWER_SERVICE);
    PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, " POTFIX holding wake lock");
    wl.acquire();/*from   w  w  w  .  j av  a 2  s .  c o m*/
    Globals.getInstance().setFlexiblemap(true);

    //
    //
    //        new Thread(new Runnable(){
    //            @Override
    //            public void run() {
    //                try {
    //                    LALpotfixservicePortBinding service = new LALpotfixservicePortBinding();
    //                    try {
    //                        globaldata_test=service.CheckWS("mandar");
    //
    //                    } catch (Exception e) {
    //                        e.printStackTrace();
    //                    }
    //                } catch (Exception ex) {
    //                    ex.printStackTrace();
    //                }
    //            }
    //        }).start();

    String login = "";

    //  Config.getInstance(getBaseContext(),getCacheDir()).setProfile("df","asd");
    login = Config.getInstance(getBaseContext(), getCacheDir()).getProfileName();
    if (login == null || login.isEmpty()) {
        Intent intent = new Intent(this, LoginActivity.class);
        startActivity(intent);
        return;
    }
    //remove
    //  Stetho.initializeWithDefaults(this);

    // Toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    // Drawer
    drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    tusername = (TextView) drawer.findViewById(R.id.tvusername);
    //        tuseremail =(TextView) findViewById(R.id.tvuseremail);
    //
    //        if(login!=null)
    //            tusername.setText("jhjhjhjh");
    //   if(Config.getInstance().getProfileEmail()!=null)
    //tuseremail.setText(Config.getInstance().getProfileEmail());

    // FAB
    fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setRippleColor(Color.parseColor("#78D6F3"));
    fab.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#039FDC")));
    fab.setImageResource(R.drawable.ic_gps_fixed_white_24dp);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            switch (currentFragment) {
            case 1: //profile
                Snackbar.make(view, "Updating Information", Snackbar.LENGTH_LONG).setAction("Action", null)
                        .show();
                Fragment frg = new ProfileFragment();
                FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
                transaction.replace(R.id.frame_containerone, frg);
                transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
                transaction.commit();
                break;
            case 2: //map

                if (Globals.getInstance().getFlexiblemap()) {
                    Snackbar.make(view, "Free to Scroll", Snackbar.LENGTH_LONG).setAction("Action", null)
                            .show();
                    Globals.getInstance().setFlexiblemap(false);
                    fab.setRippleColor(Color.parseColor("#FFE082"));
                    fab.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#FFB300")));
                    fab.setImageResource(R.drawable.ic_gps_off_white_24dp);
                } else {
                    Snackbar.make(view, "Follow Potfix", Snackbar.LENGTH_LONG).setAction("Action", null).show();
                    Globals.getInstance().setFlexiblemap(true);
                    fab.setRippleColor(Color.parseColor("#78D6F3"));
                    fab.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#039FDC")));
                    fab.setImageResource(R.drawable.ic_gps_fixed_white_24dp);
                }
                break;
            case 3: //share
                //Snackbar.make(view, "Some sharing action", Snackbar.LENGTH_LONG).setAction("Action", null).show();
                String[] TO = { "aziz@potfix.com" };
                String[] CC = { "" };
                Intent emailIntent = new Intent(Intent.ACTION_SEND);

                emailIntent.setData(Uri.parse("mailto:"));
                emailIntent.setType("text/plain");
                emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
                emailIntent.putExtra(Intent.EXTRA_CC, CC);
                emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Potfix Communication");
                emailIntent.putExtra(Intent.EXTRA_TEXT, "Email message...");

                try {
                    startActivity(Intent.createChooser(emailIntent, "Send mail..."));
                    finish();
                } catch (android.content.ActivityNotFoundException ex) {
                    Toast.makeText(MainActivity.this, "There is no email client installed.", Toast.LENGTH_SHORT)
                            .show();
                }
                break;
            case 4: //legal
                Snackbar.make(view, "Software License", Snackbar.LENGTH_LONG).setAction("Action", null).show();
                drawer.openDrawer(Gravity.LEFT);
                break;
            }

        }
    });

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    startService(new Intent(getBaseContext(), BackgroundService.class));

    FragmentTransaction mTransaction = getSupportFragmentManager().beginTransaction();
    MapsFragment mFRaFragment = new MapsFragment();
    mTransaction.add(R.id.frame_containerone, mFRaFragment);
    mTransaction.commit();

    LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

    if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        Toast.makeText(this, "GPS is Enabled in your devide", Toast.LENGTH_SHORT).show();
    } else {
        showGPSDisabledAlertToUser();
    }

    //        if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)){
    //            Toast.makeText(this, "Network is Enabled in your devide", Toast.LENGTH_SHORT).show();
    //        }else{
    //            showNetDisabledAlertToUser();
    //        }
    createNotification();
}