List of usage examples for android.graphics Color parseColor
@ColorInt public static int parseColor(@Size(min = 1) String colorString)
From source file:cn.psvmc.demo.MainActivity.java
public void onColorClicked(View v) { int color = Color.parseColor(v.getTag().toString()); changeColor(color); }
From source file:chrisrenke.drawerarrowdrawable.SlidingTabsColorsFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // BEGIN_INCLUDE (populate_tabs) /**//from w ww .ja v a2 s . c o m * Populate our tab list with tabs. Each item contains a title, indicator color and divider * color, which are used by {@link SlidingTabLayout}. */ mTabs.add(new SamplePagerItem(getString(R.string.tab_stream), // Title Color.parseColor("#E8E8B7"), // Indicator color Color.WHITE // Divider color )); mTabs.add(new SamplePagerItem(getString(R.string.tab_messages), // Title Color.parseColor("#E8E8B7"), // Indicator color Color.WHITE // Divider color )); mTabs.add(new SamplePagerItem(getString(R.string.tab_photos), // Title Color.parseColor("#E8E8B7"), // Indicator color Color.WHITE // Divider color )); mTabs.add(new SamplePagerItem(getString(R.string.tab_notifications), // Title Color.parseColor("#E8E8B7"), // Indicator color Color.WHITE // Divider color )); // END_INCLUDE (populate_tabs) }
From source file:net.henryco.opalette.application.programs.sub.programs.bFilter.EdFilter.java
private static List<EdFilter> loadFilterListFromJSON() { /*/*from w w w . j a v a 2s .c o m*/ { "type": "t255" | "t01" , "filters": [{ "name": "filter1", "color": "#FFFFFFFF", "contrast": "0", "gamma": "1", "hue": "0", "saturation": "0", "lightness": "0", "bw": "false", "min": ["0", "0", "0"], "max": ["255", "255", "255"], "add": ["0", "0", "0"] }] } */ List<EdFilter> filterList = new ArrayList<>(); filterList.add(getDefaultFilter()); String file = GodConfig.TEXTURE_FILTERS_DATA_FILE; InputStream in = EdFilter.class.getClassLoader().getResourceAsStream(file); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); StringBuilder builder = new StringBuilder(); try { String line; while ((line = reader.readLine()) != null) builder.append(line).append('\n'); in.close(); JSONObject data = new JSONObject(builder.toString()); String type = "t01"; try { type = data.getString("type"); } catch (Exception ignored) { } final OPallFunction<Float, Float> corrector; final boolean type255 = type.equalsIgnoreCase("t255"); if (type255) corrector = f -> f / 255f; else corrector = Float::floatValue; ArrayList<String> nameList = new ArrayList<>(); JSONArray filters = data.getJSONArray("filters"); for (int i = 0; i < filters.length(); i++) { JSONObject filter = filters.getJSONObject(i); String f_name = filter.getString("name"); if (nameList.contains(f_name)) throw new RuntimeException("FILTER NAME: " + f_name + " is already exist at position: " + i); nameList.add(f_name); boolean bw = false; float contrast = 1f; float gamma = 1f; int col = 0xFFFFFFFF; float light = 0f; float sat = 0f; float hue = 0f; try { sat = (float) filter.getDouble("saturation"); if (type255) sat /= GodConfig.NORM_RANGE; } catch (Exception ignored) { } try { hue = (float) filter.getDouble("hue"); if (type255) hue /= GodConfig.HUE_CLAMP_RANGE; } catch (Exception ignored) { } try { light = (float) filter.getDouble("lightness"); if (type255) light /= GodConfig.NORM_RANGE; } catch (Exception ignored) { } try { col = Color.parseColor(filter.getString("color")); } catch (Exception ignored) { } try { contrast = (float) filter.getDouble("contrast"); if (type255) contrast /= GodConfig.NORM_RANGE; contrast += 1f; } catch (Exception ignored) { } try { gamma = (float) filter.getDouble("gamma"); } catch (Exception ignored) { } try { bw = filter.getBoolean("bw"); } catch (Exception ignored) { } OPallFunction<float[], String> colorFunc = s -> { try { JSONArray color = filter.getJSONArray(s); float r = corrector.apply((float) color.getDouble(0)); float g = corrector.apply((float) color.getDouble(1)); float b = corrector.apply((float) color.getDouble(2)); return new float[] { r, g, b }; } catch (JSONException e) { return null; } }; float[] add = colorFunc.apply("add"); float[] min = colorFunc.apply("min"); float[] max = colorFunc.apply("max"); EdFilter extFilter = new EdFilter(f_name, col, gamma, contrast, hue, sat, light, bw); if (add != null) extFilter.setAdd(add[0], add[1], add[2]); if (min != null) extFilter.setMin(min[0], min[1], min[2]); if (max != null) extFilter.setMax(max[0], max[1], max[2]); filterList.add(extFilter); } } catch (IOException | JSONException e) { e.printStackTrace(); } Collections.reverse(filterList); return filterList; }
From source file:com.njlabs.amrita.aid.aums.AumsResourcesActivity.java
@Override public void init(Bundle savedInstanceState) { setupLayout(R.layout.activity_aums_list, Color.parseColor("#e91e63")); String server = getIntent().getStringExtra("server"); swipeRefreshLayout = (ExtendedSwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout); recyclerView = (RecyclerView) findViewById(R.id.list); swipeRefreshLayout.setColorSchemeColors(Color.parseColor("#e91e63")); swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override// w w w . j a va 2s . c om public void onRefresh() { reloadList(); } }); final LinearLayoutManager layoutParams = new LinearLayoutManager(this); recyclerView.setLayoutManager(layoutParams); recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { super.onScrollStateChanged(recyclerView, newState); } @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); } }); swipeRefreshLayout.setRefreshing(true); progressDialog = new ProgressDialog(baseContext); progressDialog.setTitle("Downloading ... "); progressDialog.setIndeterminate(false); progressDialog.setCancelable(false); progressDialog.setCanceledOnTouchOutside(false); progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { fileNameToDownload = null; } }); aums = new Aums(baseContext, new ProgressResponseBody.ProgressListener() { @Override public void update(final long bytesRead, final long contentLength, boolean done) { final int progress = (int) ((bytesRead / contentLength) * 100); ((Activity) baseContext).runOnUiThread(new Runnable() { @Override public void run() { progressDialog.setMessage( humanReadableByteCount(bytesRead) + " of " + humanReadableByteCount(contentLength)); progressDialog.setProgress(progress); } }); } }); aums.setServer(server); reloadList(); }
From source file:com.brodev.socialapp.view.FriendTabsPager.java
@Override protected void onCreate(Bundle savedInstanceState) { // setTheme(SampleList.THEME); //Used for theme switching in samples super.onCreate(savedInstanceState); phraseManager = new PhraseManager(getApplicationContext()); user = (User) getApplication().getApplicationContext(); colorView = new ColorView(getApplicationContext()); colorCode = colorView.getColorCode(getApplicationContext(), user); setContentView(R.layout.fragment_tabs_pager); mTabHost = (TabHost) findViewById(android.R.id.tabhost); mTabHost.setup();/* www . ja v a 2s . co m*/ mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setOffscreenPageLimit(3); mTabsAdapter = new TabsAdapter(this, mTabHost, mViewPager); getSupportActionBar().setDisplayHomeAsUpEnabled(true); Bundle extras = getIntent().getExtras(); mTabsAdapter.addTab( mTabHost.newTabSpec("wall") .setIndicator(phraseManager.getPhrase(getApplicationContext(), "profile.wall")), UserFragment.class, extras); mTabsAdapter.addTab( mTabHost.newTabSpec("info") .setIndicator(phraseManager.getPhrase(getApplicationContext(), "profile.info")), InfoFragment.class, extras); mTabsAdapter.addTab( mTabHost.newTabSpec("photo") .setIndicator(phraseManager.getPhrase(getApplicationContext(), "profile.photos")), AlbumsFragment.class, extras); if (savedInstanceState != null) { mTabHost.setCurrentTabByTag(savedInstanceState.getString("tab")); } //set color for tabhost for (int i = 0; i < mTabHost.getTabWidget().getChildCount(); i++) { mTabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#272727")); tv = (TextView) mTabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.title); tv.setTextColor(Color.parseColor("#ffffffff")); } mTabHost.getTabWidget().setCurrentTab(0); mTabHost.getTabWidget().getChildAt(0).setBackgroundColor(Color.parseColor(colorCode)); }
From source file:com.amaze.filemanager.adapters.TabSpinnerAdapter.java
@Override public View getDropDownView(final int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); View row = inflater.inflate(R.layout.spinner_dropdown_layout, parent, false); ma = ((Main) fragmentTransaction.findFragmentById(R.id.content_frame)); final TextView textView = (TextView) row.findViewById(R.id.spinnerText); LinearLayout linearLayout = (LinearLayout) row.findViewById(R.id.textParent); final SharedPreferences sharedPreferences1 = PreferenceManager.getDefaultSharedPreferences(context); String skin = sharedPreferences1.getString("skin_color", "#5677fc"); final int spinner_current = sharedPreferences1.getInt("spinner_selected", 0); ImageButton imageButton = (ImageButton) row.findViewById(R.id.spinnerButton); if (items.get(position).equals("/")) textView.setText(R.string.rootdirectory); else/* w w w .ja v a2s . co m*/ textView.setText(new File(items.get(position)).getName()); imageButton.setBackgroundColor(Color.parseColor(skin)); if (position == spinner_current) { textView.setTextColor(Color.parseColor(skin)); textView.setTypeface(null, Typeface.BOLD); } linearLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { hideSpinnerDropDown(spinner); if (position == spinner_current) { } else { TabHandler tabHandler1 = new TabHandler(context, null, null, 1); Tab tab = tabHandler1.findTab(position); String name = tab.getPath(); //Toast.makeText(getActivity(), name, Toast.LENGTH_SHORT).show(); sharedPreferences1.edit().putString("current", name).apply(); sharedPreferences1.edit().putInt("spinner_selected", position).apply(); Main ma = ((Main) fragmentTransaction.findFragmentById(R.id.content_frame)); ma.loadlist(new File(tab.getPath()), false); Animation animationLeft = AnimationUtils.loadAnimation(getContext(), R.anim.tab_selection_left); Animation animationRight = AnimationUtils.loadAnimation(getContext(), R.anim.tab_selection_right); if (position < spinner_current) { ma.listView.setAnimation(animationLeft); ma.gridView.setAnimation(animationLeft); } else { ma.listView.setAnimation(animationRight); ma.gridView.setAnimation(animationRight); } } } }); imageButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { TabHandler tabHandler = new TabHandler(context, null, null, 1); Tab tab = tabHandler.findTab(position); if (position > spinner_current) { //Toast.makeText(getContext(), "Closed", Toast.LENGTH_SHORT).show(); items.remove(position); int old_tab = tab.getTab(); int a; for (a = old_tab; a < tabHandler.getTabsCount() - 1; a++) { int new_tab = a + 1; Tab tab1 = tabHandler.findTab(new_tab); String next_label = tab1.getLabel(); String next_path = tab1.getPath(); tabHandler.updateTab(new Tab(a, next_label, next_path)); } tabHandler.deleteTab(tabHandler.getTabsCount() - 1); hideSpinnerDropDown(spinner); } else if (position < spinner_current) { // Toast.makeText(getContext(), "Closed", Toast.LENGTH_SHORT).show(); items.remove(position); int old_tab = tab.getTab(); int a; for (a = old_tab; a < tabHandler.getTabsCount() - 1; a++) { int new_tab = a + 1; Tab tab1 = tabHandler.findTab(new_tab); String next_label = tab1.getLabel(); String next_path = tab1.getPath(); tabHandler.updateTab(new Tab(a, next_label, next_path)); } tabHandler.deleteTab(tabHandler.getTabsCount() - 1); int older_spinner_selected = sharedPreferences1.getInt("spinner_selected", 0); older_spinner_selected--; sharedPreferences1.edit().putInt("spinner_selected", older_spinner_selected).apply(); hideSpinnerDropDown(spinner); } else if (position == spinner_current) { if (tabHandler.getTabsCount() == 1) { // Toast.makeText(getContext(), "exits the app", Toast.LENGTH_SHORT).show(); ma.home(); } else if (tabHandler.getTabsCount() - 1 > position) { items.remove(position); int old_tab = tab.getTab(); int a; for (a = old_tab; a < tabHandler.getTabsCount() - 1; a++) { int new_tab = a + 1; Tab tab1 = tabHandler.findTab(new_tab); String next_label = tab1.getLabel(); String next_path = tab1.getPath(); tabHandler.updateTab(new Tab(a, next_label, next_path)); } tabHandler.deleteTab(tabHandler.getTabsCount() - 1); Tab tab1 = tabHandler.findTab(spinner_current); ma.loadlist(new File(tab1.getPath()), false); } else if (tabHandler.getTabsCount() - 1 == position) { items.remove(position); tabHandler.deleteTab(tabHandler.getTabsCount() - 1); int older_spinner_selected = sharedPreferences1.getInt("spinner_selected", 0); older_spinner_selected--; sharedPreferences1.edit().putInt("spinner_selected", older_spinner_selected).apply(); Tab tab1 = tabHandler.findTab(older_spinner_selected); Main ma = ((Main) fragmentTransaction.findFragmentById(R.id.content_frame)); ma.loadlist(new File(tab1.getPath()), false); } } } }); return row; }
From source file:com.byteshaft.licenseservice.ResultActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);//from ww w . j a v a2s. co m ArrayList<String> dataList = getIntent().getStringArrayListExtra(AppGlobals.TOTAL_CATEGORIES); listView = (ListView) findViewById(R.id.result_list_view); HashMap<String, String> hashMap = (HashMap<String, String>) getIntent() .getSerializableExtra(AppGlobals.ANSWER_DATA); totalQuestions = getIntent().getIntExtra(AppGlobals.TOTAL_QUESTIONS, 0); Log.i("Total ques received", String.valueOf(totalQuestions)); for (String category : dataList) { if (hashMap.get(category) != null) { if (!category.equals(Data.sGeneralKnowledge) && !category.equals(Data.sTrafficSignsSection)) { totalTrue = totalTrue + Integer.parseInt(String.valueOf(hashMap.get(category))); } } } Log.i("HashMap", String.valueOf(hashMap)); Adapter adapter = new Adapter(getApplicationContext(), R.layout.layout_result_delegate, dataList, hashMap); listView.setAdapter(adapter); final DrawerLayout 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(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); disableNavigationViewScrollbars(navigationView); header = navigationView.getHeaderView(0); generalAnswer = (TextView) header.findViewById(R.id.general_knowledge_answer); roadSafetyEssentials = (TextView) header.findViewById(R.id.road_safety_answer); trafficSigns = (TextView) header.findViewById(R.id.traffic_signs_answer); testStatus = (TextView) header.findViewById(R.id.test_status); roadSafetyEssentials.setText(String.valueOf(totalTrue) + "/" + "20"); String generalAnswers = String.valueOf(hashMap.get(Data.sGeneralKnowledge)); String trafficAnswers = String.valueOf(hashMap.get(Data.sTrafficSignsSection)); generalAnswer.setText(generalAnswers + "/" + "15"); if (Integer.valueOf(generalAnswers) < 12) { failInGeneral = true; generalAnswer.setTextColor(Color.RED); } else { generalAnswer.setTextColor(Color.parseColor("#009900")); } trafficSigns.setText(trafficAnswers + "/" + "10"); if (Integer.valueOf(trafficAnswers) < 10) { trafficSigns.setTextColor(Color.RED); } else { trafficSigns.setTextColor(Color.parseColor("#009900")); } if (totalTrue < 20) { roadSafetyEssentials.setTextColor(Color.RED); } else { roadSafetyEssentials.setTextColor(Color.parseColor("#009900")); } if (Integer.valueOf(trafficAnswers) < 10 || totalTrue < 20) { failInOverAll = true; } if (failInOverAll || failInGeneral) { testStatus.setText("Fail"); testStatus.setTextColor(Color.RED); } else { testStatus.setText("Pass"); testStatus.setTextColor(Color.parseColor("#009900")); } Calendar c = Calendar.getInstance(); System.out.println("Current time => " + c.getTime()); SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy"); String formattedDate = df.format(c.getTime()); TextView date = (TextView) header.findViewById(R.id.date); date.setText(formattedDate); Button haveAnotherGo = (Button) header.findViewById(R.id.button); haveAnotherGo.setOnClickListener(this); drawer.openDrawer(GravityCompat.START); }
From source file:com.example.android.uvdemo.UVFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); getListView().setDivider(null);//from w ww . j a va 2 s .c o m getListView().setDividerHeight(0); mUvItems = new ArrayList<UvItem>(); mFeedListAdapter = new UVListAdapter(getActivity(), mUvItems); // 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(); } }); doRequest(); // END_INCLUDE (setup_refreshlistener) }
From source file:com.example.appf.CS3570.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = getIntent();/*w ww . j a v a2 s . c o m*/ Bundle extras = intent.getExtras(); cam = false; // Just in case we are coming from the ServerActivity if (extras != null) { if (extras.containsKey("server_name")) SERVER_IP = extras.getString("server_name"); if (extras.containsKey("server_port")) SERVERPORT = Integer.parseInt(extras.getString("server_port")); } filter = new IMUfilter(.1f, 5); filter.reset(); // Set up reset button Button b = new Button(this); b.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { filter.reset(); } }); b.setText("Reset"); // Set up camera mode. Are we going to use this? Button c = new Button(this); c.setText("Camera Mode"); c.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { filter.reset(); mGLView.mRenderer.mCamera = new Camera(); cam = !cam; } }); LinearLayout ll = new LinearLayout(this); ll.setOrientation(LinearLayout.VERTICAL); ll.setBackgroundColor(Color.parseColor("#21C9FF")); ll.addView(b); ll.addView(c); // Create a GLSurfaceView instance and set it // as the ContentView for this Activity mGLView = new MyGLSurfaceView(this, this); ll.addView(mGLView); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); gyroscope = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE); accelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); magnetometer = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); setContentView(ll); new Thread(new SocketThread()).start(); }
From source file:com.armtimes.fragments.FragmentAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { ViewHolder viewHolder = (ViewHolder) view.getTag(); final String title = cursor.getString(viewHolder.titleIndex); final String description = cursor.getString(viewHolder.shortDescriptionIndex); final int isRead = cursor.getInt(viewHolder.isRead); viewHolder.textViewInfo.setText(Html.fromHtml(String.format("<b>%s</b> %s", title, description))); final String imagePath = cursor.getString(viewHolder.imagePathIndex); if (imagePath != null && !imagePath.isEmpty()) { // Read image from storage. InputStream is = null;/*from w w w . jav a2 s . com*/ try { is = new FileInputStream(new File(imagePath)); // Set Bitmap to Image View. viewHolder.imageViewThumbnail.setImageBitmap(BitmapFactory.decodeStream(is)); // Set visibility of Image view to VISIBLE. viewHolder.imageViewThumbnail.setVisibility(View.VISIBLE); // In the case if Image was successfully set to the // image view change layout_weight parameter of image // view to (=2) and layout_width to (=0) in order to // show text and image view in a right way. viewHolder.textViewInfo.setLayoutParams(params2f); } catch (IOException ignore) { viewHolder.textViewInfo.setLayoutParams(params3f); // In the case if exception occurs and image can't be set. // Hide Thumbnail image. viewHolder.imageViewThumbnail.setVisibility(View.GONE); } finally { if (is != null) { try { is.close(); } catch (IOException ignore) { } } } } else { viewHolder.imageViewThumbnail.setVisibility(View.GONE); viewHolder.textViewInfo.setLayoutParams(params3f); } view.setBackgroundColor(isRead != 1 ? Color.parseColor("#EEEEEE") : Color.WHITE); }