List of usage examples for android.widget TextView setBackgroundColor
@RemotableViewMethod public void setBackgroundColor(@ColorInt int color)
From source file:org.ounl.lifelonglearninghub.fcube.navigate.VisualSectionFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.activity_display_visual, container, false); //// w w w . j a va2 s .c om // Init seekbars // final TextView tvColorSample = (TextView) rootView.findViewById(R.id.tvColorSample); SeekBar sbRed = (SeekBar) rootView.findViewById(R.id.seekBarRed); sbRed.setMax(255); final TextView tvRValue = (TextView) rootView.findViewById(R.id.textViewRedValue); SeekBar sbG = (SeekBar) rootView.findViewById(R.id.seekBarGreen); sbG.setMax(255); final TextView tvGValue = (TextView) rootView.findViewById(R.id.textViewGreenValue); SeekBar sbB = (SeekBar) rootView.findViewById(R.id.seekBarBlue); sbB.setMax(255); final TextView tvBValue = (TextView) rootView.findViewById(R.id.textViewBlueValue); sbRed.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { tvRValue.setText(String.valueOf(progress)); String sR = (String) tvRValue.getText(); Integer IsR = new Integer(sR); String sG = (String) tvGValue.getText(); Integer IsG = new Integer(sG); String sB = (String) tvBValue.getText(); Integer IsB = new Integer(sB); String hex = String.format("#%02x%02x%02x", IsR, IsG, IsB); tvColorSample.setBackgroundColor(Color.parseColor(hex)); } @Override public void onStartTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onStopTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } }); sbG.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { tvGValue.setText(String.valueOf(progress)); String sR = (String) tvRValue.getText(); Integer IsR = new Integer(sR); String sG = (String) tvGValue.getText(); Integer IsG = new Integer(sG); String sB = (String) tvBValue.getText(); Integer IsB = new Integer(sB); String hex = String.format("#%02x%02x%02x", IsR, IsG, IsB); tvColorSample.setBackgroundColor(Color.parseColor(hex)); } @Override public void onStartTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onStopTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } }); sbB.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { tvBValue.setText(String.valueOf(progress)); String sR = (String) tvRValue.getText(); Integer IsR = new Integer(sR); String sG = (String) tvGValue.getText(); Integer IsG = new Integer(sG); String sB = (String) tvBValue.getText(); Integer IsB = new Integer(sB); String hex = String.format("#%02x%02x%02x", IsR, IsG, IsB); tvColorSample.setBackgroundColor(Color.parseColor(hex)); } @Override public void onStartTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onStopTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } }); // // Init number pickers // final RadioButton rbF = (RadioButton) rootView.findViewById(R.id.rbFullColor); final RadioButton rbP = (RadioButton) rootView.findViewById(R.id.rbPartColor); npLedStart = (NumberPicker) rootView.findViewById(R.id.npLedStart); npLedStart.setMaxValue(15); npLedStart.setMinValue(0); npLedStart.setValue(0); //npLedStart.setWrapSelectorWheel(false); npLedStart.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() { @Override public void onValueChange(NumberPicker numberPicker, int i, int i2) { rbP.setChecked(true); rbF.setChecked(false); } }); npLedEnd = (NumberPicker) rootView.findViewById(R.id.npLedStop); npLedEnd.setMaxValue(15); npLedEnd.setMinValue(0); npLedEnd.setValue(15); //npLedEnd.setWrapSelectorWheel(false); npLedEnd.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() { @Override public void onValueChange(NumberPicker numberPicker, int i, int i2) { rbP.setChecked(true); rbF.setChecked(false); } }); return rootView; }
From source file:terse.a1.TerseActivity.java
@Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); glSurfaceView = null; // Forget gl on new activity. requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); if (savedInstanceState != null && savedInstanceState.containsKey("TerseActivity")) { taSaveMe = savedInstanceState.getString("TerseActivity"); } else {/*from w w w.j a v a 2s. c o m*/ taSaveMe = null; } Runnable bg = new Runnable() { @Override public void run() { resetTerp(); } }; Runnable fg = new Runnable() { @Override public void run() { Intent intent = getIntent(); Uri uri = intent.getData(); Bundle extras = intent.getExtras(); String path = uri == null ? "/" : uri.getPath(); String query = uri == null ? "" : uri.getQuery(); viewPath(path, query, extras, savedInstanceState); } }; if (terp == null) { TextView tv = new TextView(TerseActivity.this); tv.setText(Static.fmt("Building new TerseTalk VM for world <%s>...", world)); tv.setTextAppearance(this, R.style.teletype); tv.setBackgroundColor(Color.BLACK); tv.setTextColor(Color.DKGRAY); tv.setTextSize(24); setContentView(tv); setContentViewThenBgThenFg("ResetSplash", tv, bg, fg); } else { fg.run(); } }
From source file:terse.a1.TerseActivity.java
public void viewPath(String path, String queryStr, Bundle extras, Bundle savedInstanceState) { // Stop any running WorkThread before we continue. viewPath1prepare(path, queryStr);/* w w w . ja v a 2 s .co m*/ viewPath2parseQuery(queryStr, extras); final LayoutParams widgetParams = new LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT, 1.0f); TextView splash = new TextView(TerseActivity.this); splash.setText("Launching\n\n" + taPath + "\n\n" + Static.hashMapToMultiLineString(taQuery)); splash.setTextAppearance(this, R.style.teletype); splash.setBackgroundColor(Color.BLACK); splash.setTextColor(Color.DKGRAY); splash.setTextSize(24); Runnable bg = new Runnable() { @Override public void run() { try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } } }; Runnable fg = new Runnable() { @Override public void run() { viewPath9display(taPath, widgetParams); } }; setContentViewThenBgThenFg("viewPath8", splash, bg, fg); }
From source file:net.bible.android.view.util.widget.BookmarkStyleAdapterHelper.java
public void styleView(TextView view, BookmarkStyle bookmarkStyle, Context context, boolean overrideText, boolean centreText) { // prepare text to be shown String baseText;//from ww w .j a v a 2 s . c o m if (overrideText) { baseText = sampleText; } else { baseText = view.getText().toString(); // avoid multiple *'s if (baseText.startsWith("*")) { StringUtils.strip(baseText, "*"); } } int backgroundColor = Color.WHITE; switch (bookmarkStyle) { case YELLOW_STAR: backgroundColor = UiUtils.getThemeBackgroundColour(context); view.setTextColor(UiUtils.getThemeTextColour(context)); CharSequence imgText = addImageAtStart("* " + baseText, R.drawable.goldstar16x16, context); view.setText(imgText, TextView.BufferType.SPANNABLE); break; case RED_HIGHLIGHT: backgroundColor = BookmarkStyle.RED_HIGHLIGHT.getBackgroundColor(); view.setText(baseText); break; case YELLOW_HIGHLIGHT: backgroundColor = BookmarkStyle.YELLOW_HIGHLIGHT.getBackgroundColor(); view.setText(baseText); break; case GREEN_HIGHLIGHT: backgroundColor = BookmarkStyle.GREEN_HIGHLIGHT.getBackgroundColor(); view.setText(baseText); break; case BLUE_HIGHLIGHT: backgroundColor = BookmarkStyle.BLUE_HIGHLIGHT.getBackgroundColor(); view.setText(baseText); break; } view.setBackgroundColor(backgroundColor); view.setHeight(CommonUtils.convertDipsToPx(30)); if (centreText) { view.setGravity(Gravity.CENTER); } }
From source file:com.anjalimacwan.fragment.NoteViewFragment.java
@SuppressLint("SetJavaScriptEnabled") @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override//from w w w. jav a2 s.c om public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // Set values setRetainInstance(true); setHasOptionsMenu(true); // Get filename of saved note filename = getArguments().getString("filename"); // Change window title String title; try { title = listener.loadNoteTitle(filename); } catch (IOException e) { title = getResources().getString(R.string.view_note); } getActivity().setTitle(title); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription(title, null, ContextCompat.getColor(getActivity(), R.color.primary)); getActivity().setTaskDescription(taskDescription); } // Show the Up button in the action bar. ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true); // Animate elevation change if (getActivity().findViewById(R.id.layoutMain).getTag().equals("main-layout-large") && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { LinearLayout noteViewEdit = (LinearLayout) getActivity().findViewById(R.id.noteViewEdit); LinearLayout noteList = (LinearLayout) getActivity().findViewById(R.id.noteList); noteList.animate().z(0f); if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) noteViewEdit.animate() .z(getResources().getDimensionPixelSize(R.dimen.note_view_edit_elevation_land)); else noteViewEdit.animate().z(getResources().getDimensionPixelSize(R.dimen.note_view_edit_elevation)); } // Set up content view TextView noteContents = (TextView) getActivity().findViewById(R.id.textView); markdownView = (MarkdownView) getActivity().findViewById(R.id.markdownView); // Apply theme SharedPreferences pref = getActivity().getSharedPreferences(getActivity().getPackageName() + "_preferences", Context.MODE_PRIVATE); ScrollView scrollView = (ScrollView) getActivity().findViewById(R.id.scrollView); String theme = pref.getString("theme", "light-sans"); int textSize = -1; int textColor = -1; String fontFamily = null; if (theme.contains("light")) { if (noteContents != null) { noteContents.setTextColor(ContextCompat.getColor(getActivity(), R.color.text_color_primary)); noteContents.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background)); } if (markdownView != null) { markdownView.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background)); textColor = ContextCompat.getColor(getActivity(), R.color.text_color_primary); } scrollView.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background)); } if (theme.contains("dark")) { if (noteContents != null) { noteContents.setTextColor(ContextCompat.getColor(getActivity(), R.color.text_color_primary_dark)); noteContents .setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background_dark)); } if (markdownView != null) { markdownView .setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background_dark)); textColor = ContextCompat.getColor(getActivity(), R.color.text_color_primary_dark); } scrollView.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background_dark)); } if (theme.contains("sans")) { if (noteContents != null) noteContents.setTypeface(Typeface.SANS_SERIF); if (markdownView != null) fontFamily = "sans-serif"; } if (theme.contains("serif")) { if (noteContents != null) noteContents.setTypeface(Typeface.SERIF); if (markdownView != null) fontFamily = "serif"; } if (theme.contains("monospace")) { if (noteContents != null) noteContents.setTypeface(Typeface.MONOSPACE); if (markdownView != null) fontFamily = "monospace"; } switch (pref.getString("font_size", "normal")) { case "smallest": textSize = 12; break; case "small": textSize = 14; break; case "normal": textSize = 16; break; case "large": textSize = 18; break; case "largest": textSize = 20; break; } if (noteContents != null) noteContents.setTextSize(textSize); if (markdownView != null) { String topBottom = " " + Float.toString(getResources().getDimension(R.dimen.padding_top_bottom) / getResources().getDisplayMetrics().density) + "px"; String leftRight = " " + Float.toString(getResources().getDimension(R.dimen.padding_left_right) / getResources().getDisplayMetrics().density) + "px"; String fontSize = " " + Integer.toString(textSize) + "px"; String fontColor = " #" + StringUtils.remove(Integer.toHexString(textColor), "ff"); final String css = "body { " + "margin:" + topBottom + topBottom + leftRight + leftRight + "; " + "font-family:" + fontFamily + "; " + "font-size:" + fontSize + "; " + "color:" + fontColor + "; " + "}"; final String js = "var styleNode = document.createElement('style');\n" + "styleNode.type = \"text/css\";\n" + "var styleText = document.createTextNode('" + css + "');\n" + "styleNode.appendChild(styleText);\n" + "document.getElementsByTagName('head')[0].appendChild(styleNode);\n"; markdownView.getSettings().setJavaScriptEnabled(true); markdownView.getSettings().setLoadsImagesAutomatically(false); markdownView.setWebViewClient(new WebViewClient() { @TargetApi(Build.VERSION_CODES.N) @Override public void onLoadResource(WebView view, String url) { view.stopLoading(); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) try { startActivity(intent); } catch (ActivityNotFoundException | FileUriExposedException e) { /* Gracefully fail */ } else try { startActivity(intent); } catch (ActivityNotFoundException e) { /* Gracefully fail */ } } @Override public void onPageFinished(WebView view, String url) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) view.evaluateJavascript(js, null); else view.loadUrl("javascript:" + js); } }); } // Load note contents try { contentsOnLoad = listener.loadNote(filename); } catch (IOException e) { showToast(R.string.error_loading_note); // Add NoteListFragment or WelcomeFragment Fragment fragment; if (getActivity().findViewById(R.id.layoutMain).getTag().equals("main-layout-normal")) fragment = new NoteListFragment(); else fragment = new WelcomeFragment(); getFragmentManager().beginTransaction().replace(R.id.noteViewEdit, fragment, "NoteListFragment") .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN).commit(); } // Set TextView contents if (noteContents != null) noteContents.setText(contentsOnLoad); if (markdownView != null) markdownView.loadMarkdown(contentsOnLoad); // Show a toast message if this is the user's first time viewing a note final SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE); firstLoad = sharedPref.getInt("first-load", 0); if (firstLoad == 0) { // Show dialog with info DialogFragment firstLoad = new FirstViewDialogFragment(); firstLoad.show(getFragmentManager(), "firstloadfragment"); // Set first-load preference to 1; we don't need to show the dialog anymore SharedPreferences.Editor editor = sharedPref.edit(); editor.putInt("first-load", 1); editor.apply(); } // Detect single and double-taps using GestureDetector final GestureDetector detector = new GestureDetector(getActivity(), new GestureDetector.OnGestureListener() { @Override public boolean onSingleTapUp(MotionEvent e) { return false; } @Override public void onShowPress(MotionEvent e) { } @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { return false; } @Override public void onLongPress(MotionEvent e) { } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return false; } @Override public boolean onDown(MotionEvent e) { return false; } }); detector.setOnDoubleTapListener(new GestureDetector.OnDoubleTapListener() { @Override public boolean onDoubleTap(MotionEvent e) { if (sharedPref.getBoolean("show_double_tap_message", true)) { SharedPreferences.Editor editor = sharedPref.edit(); editor.putBoolean("show_double_tap_message", false); editor.apply(); } Bundle bundle = new Bundle(); bundle.putString("filename", filename); Fragment fragment = new NoteEditFragment(); fragment.setArguments(bundle); getFragmentManager().beginTransaction().replace(R.id.noteViewEdit, fragment, "NoteEditFragment") .commit(); return false; } @Override public boolean onDoubleTapEvent(MotionEvent e) { return false; } @Override public boolean onSingleTapConfirmed(MotionEvent e) { if (sharedPref.getBoolean("show_double_tap_message", true) && showMessage) { showToastLong(R.string.double_tap); showMessage = false; } return false; } }); if (noteContents != null) noteContents.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { detector.onTouchEvent(event); return false; } }); if (markdownView != null) markdownView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { detector.onTouchEvent(event); return false; } }); }
From source file:edu.cens.loci.ui.PlaceViewActivity.java
private void updateWifiList(TableLayout table, LociWifiFingerprint wifi) { ArrayList<WifiViewListItem> items = new ArrayList<WifiViewListItem>(); HashMap<String, APInfoMapItem> apMap = wifi.getAps(); Set<String> keys = apMap.keySet(); Iterator<String> iter = keys.iterator(); while (iter.hasNext()) { String bssid = iter.next(); APInfoMapItem ap = apMap.get(bssid); items.add(new WifiViewListItem(bssid, ap.ssid, ap.rss, ap.count, ap.rssBuckets)); }// ww w . ja va2 s .c om Collections.sort(items); table.setColumnCollapsed(0, false); table.setColumnCollapsed(1, true); table.setColumnShrinkable(0, true); for (int i = 0; i < mAddedRows.size(); i++) { table.removeView(mAddedRows.get(i)); } mAddedRows.clear(); int totalCount = wifi.getScanCount(); for (WifiViewListItem item : items) { TableRow row = new TableRow(this); TextView ssidView = new TextView(this); ssidView.setText(item.ssid); //ssidView.setText("very very very veryvery very very very very very"); ssidView.setPadding(2, 2, 2, 2); ssidView.setTextColor(0xffffffff); TextView bssidView = new TextView(this); bssidView.setText(item.bssid); bssidView.setPadding(2, 2, 2, 2); bssidView.setTextColor(0xffffffff); TextView cntView = new TextView(this); cntView.setText("" + (item.count * 100) / totalCount); cntView.setPadding(2, 2, 2, 2); cntView.setGravity(Gravity.CENTER); cntView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12); TextView rssView = new TextView(this); rssView.setText("" + item.rss); rssView.setPadding(2, 2, 6, 2); rssView.setGravity(Gravity.CENTER); rssView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12); row.addView(ssidView, new TableRow.LayoutParams(0)); row.addView(bssidView, new TableRow.LayoutParams(1)); row.addView(cntView, new TableRow.LayoutParams(2)); row.addView(rssView, new TableRow.LayoutParams(3)); //Log.d(TAG, item.ssid); for (int i = 0; i < item.rssBuckets.length; i++) { TextView box = new TextView(this); box.setText(" "); box.setGravity(Gravity.RIGHT); box.setPadding(2, 2, 2, 2); box.setHeight(15); box.setGravity(Gravity.CENTER_VERTICAL); float colorVal = 256 * ((float) item.rssBuckets[i] / (float) wifi.getScanCount()); //Log.d(TAG, "colorVal=" + (int) colorVal + ", " + item.histogram[i]); int colorValInt = ((int) colorVal) - 1; if (colorValInt < 0) colorValInt = 0; box.setBackgroundColor(0xff000000 + colorValInt);//+ 0x000000ff * (item.histogram[i]/totScan)); box.setTextColor(0xffffffff); row.addView(box, new TableRow.LayoutParams(4 + i)); } row.setGravity(Gravity.CENTER); table.addView(row, new TableLayout.LayoutParams()); table.setColumnStretchable(3, true); mAddedRows.add(row); } }
From source file:terse.a1.TerseActivity.java
private void viewPath9display(String path, LayoutParams widgetParams) { String explain;/*from w ww. ja v a 2 s .co m*/ if (terp_error != null) { explain = "terp_error = " + terp_error; } else { try { terp.say("Sending to terp: %s", path); final Dict d = terp.handleUrl(path, taQuery); explain = "DEFAULT EXPLANATION:\n\n" + d.toString(); Str TYPE = d.cls.terp.newStr("type"); Str VALUE = d.cls.terp.newStr("value"); Str TITLE = d.cls.terp.newStr("title"); Str type = (Str) d.dict.get(TYPE); Ur value = d.dict.get(VALUE); Ur title = d.dict.get(TITLE); // { // double ticks = Static.floatAt(d, "ticks", -1); // double nanos = Static.floatAt(d, "nanos", -1); // Toast.makeText( // getApplicationContext(), // Static.fmt("%d ticks, %.3f secs", (long) ticks, // (double) nanos / 1e9), Toast.LENGTH_SHORT) // .show(); // } if (type.str.equals("list") && value instanceof Vec) { final ArrayList<Ur> v = ((Vec) value).vec; final ArrayList<String> labels = new ArrayList<String>(); final ArrayList<String> links = new ArrayList<String>(); for (int i = 0; i < v.size(); i++) { Ur item = v.get(i); String label = item instanceof Str ? ((Str) item).str : item.toString(); if (item instanceof Vec && ((Vec) item).vec.size() == 2) { // OLD STYLE label = ((Vec) item).vec.get(0).toString(); Matcher m = LINK_P.matcher(label); if (m.lookingAt()) { label = m.group(2) + " " + m.group(3); } label += " [" + ((Vec) item).vec.get(1).toString().length() + "]"; links.add(null); // Use old style, not links. } else { // NEW STYLE label = item.toString(); if (label.charAt(0) == '/') { String link = Terp.WHITE_PLUS.split(label, 2)[0]; links.add(link); } else { links.add(""); } } labels.add(label); } if (labels.size() != links.size()) terp.toss("lables#%d links#%d", labels.size(), links.size()); ListView listv = new ListView(this); listv.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item, labels)); listv.setLayoutParams(widgetParams); listv.setTextFilterEnabled(true); listv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // When clicked, show a toast with the TextView text // Toast.makeText(getApplicationContext(), // ((TextView) view).getText(), // Toast.LENGTH_SHORT).show(); String toast_text = ((TextView) view).getText().toString(); // if (v.get(position) instanceof Vec) { if (links.get(position) == null) { // OLD STYLE Vec pair = (Vec) v.get(position); if (pair.vec.size() == 2) { if (pair.vec.get(0) instanceof Str) { String[] words = ((Str) pair.vec.get(0)).str.split("\\|"); Log.i("TT-WORDS", terp.arrayToString(words)); toast_text += "\n\n" + Static.arrayToString(words); if (words[1].equals("link")) { Uri uri = new Uri.Builder().scheme("terse").path(words[2]).build(); Intent intent = new Intent("android.intent.action.MAIN", uri); intent.setClass(getApplicationContext(), TerseActivity.class); startActivity(intent); } } } } else { // NEW STYLE terp.say("NEW STYLE LIST SELECT #%d link=<%s> label=<%s>", position, links.get(position), labels.get(position)); if (links.get(position).length() > 0) { Uri uri = new Uri.Builder().scheme("terse").path(links.get(position)).build(); Intent intent = new Intent("android.intent.action.MAIN", uri); intent.setClass(getApplicationContext(), TerseActivity.class); startActivity(intent); } } // } // Toast.makeText(getApplicationContext(), // ((TextView) view).getText(), // Toast.LENGTH_SHORT).show(); } }); setContentView(listv); return; } else if (type.str.equals("edit") && value instanceof Str) { final EditText ed = new EditText(this); ed.setText(taSaveMe == null ? value.toString() : taSaveMe); ed.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_VARIATION_LONG_MESSAGE | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); ed.setLayoutParams(widgetParams); // ed.setTextSize(TypedValue.COMPLEX_UNIT_SP, 22); ed.setTextAppearance(this, R.style.teletype); ed.setBackgroundColor(Color.BLACK); ed.setGravity(Gravity.TOP); ed.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_INSET); ed.setVerticalFadingEdgeEnabled(true); ed.setVerticalScrollBarEnabled(true); ed.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" // button // if ((event.getAction() == KeyEvent.ACTION_DOWN) // && // (keyCode == KeyEvent.KEYCODE_ENTER)) { // // Perform action on key press // Toast.makeText(TerseActivity.this, ed.getText(), // Toast.LENGTH_SHORT).show(); // return true; // } return false; } }); Button btn = new Button(this); btn.setText("Save"); btn.setOnClickListener(new OnClickListener() { public void onClick(View v) { // Perform action on clicks String text = ed.getText().toString(); text = Parser.charSubsts(text); Toast.makeText(TerseActivity.this, text, Toast.LENGTH_SHORT).show(); String action = stringAt(d, "action"); String query = ""; String f1 = stringAt(d, "field1"); String v1 = stringAt(d, "value1"); String f2 = stringAt(d, "field2"); String v2 = stringAt(d, "value2"); f1 = (f1 == null) ? "f1null" : f1; v1 = (v1 == null) ? "v1null" : v1; f2 = (f2 == null) ? "f2null" : f2; v2 = (v2 == null) ? "v2null" : v2; startTerseActivity(action, query, stringAt(d, "field1"), stringAt(d, "value1"), stringAt(d, "field2"), stringAt(d, "value2"), "text", text); } }); LinearLayout linear = new LinearLayout(this); linear.setOrientation(LinearLayout.VERTICAL); linear.addView(btn); linear.addView(ed); setContentView(linear); return; } else if (type.str.equals("draw") && value instanceof Vec) { Vec v = ((Vec) value); DrawView dv = new DrawView(this, v.vec, d); dv.setLayoutParams(widgetParams); setContentView(dv); return; } else if (type.str.equals("live")) { Blk blk = value.mustBlk(); Blk event = Static.urAt(d, "event").asBlk(); TerseSurfView tsv = new TerseSurfView(this, blk, event); setContentView(tsv); return; } else if (type.str.equals("fnord")) { Blk blk = value.mustBlk(); Blk event = Static.urAt(d, "event").asBlk(); FnordView fnord = new FnordView(this, blk, event); setContentView(fnord); return; } else if (type.str.equals("world") && value instanceof Str) { String newWorld = value.toString(); if (Terp.WORLD_P.matcher(newWorld).matches()) { world = newWorld; resetTerp(); explain = Static.fmt("Switching to world <%s>\nUse menu to go Home.", world); Toast.makeText(getApplicationContext(), explain, Toast.LENGTH_LONG).show(); } else { terp.toss("Bad world syntax (must be 3 letters then 0 to 3 digits: <%s>", newWorld); } // Fall thru for explainv.setText(explain). } else if (type.str.equals("text")) { explain = "<<< " + title + " >>>\n\n" + value.toString(); // Fall thru for explainv.setText(explain). } else if (type.str.equals("html")) { final WebView webview = new WebView(this); // webview.loadData(value.toString(), "text/html", null); webview.loadDataWithBaseURL("terse://terse", value.toString(), "text/html", "UTF-8", null); webview.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { // terp.say("WebView UrlLoading: url=%s", url); URI uri = URI.create("" + url); // terp.say("WebView UrlLoading: URI=%s", uri); terp.say("WebView UrlLoading: getPath=%s", uri.getPath()); terp.say("WebView UrlLoading: getQuery=%s", uri.getQuery()); // Toast.makeText(getApplicationContext(), // uri.toASCIIString(), Toast.LENGTH_SHORT) // .show(); // webview.invalidate(); // // TextView quick = new // TextView(TerseActivity.this); // quick.setText(uri.toASCIIString()); // quick.setBackgroundColor(Color.BLACK); // quick.setTextColor(Color.WHITE); // setContentView(quick); startTerseActivity(uri.getPath(), uri.getQuery()); return true; } }); // webview.setWebChromeClient(new WebChromeClient()); webview.getSettings().setBuiltInZoomControls(true); // webview.getSettings().setJavaScriptEnabled(true); webview.getSettings().setDefaultFontSize(18); webview.getSettings().setNeedInitialFocus(true); webview.getSettings().setSupportZoom(true); webview.getSettings().setSaveFormData(true); setContentView(webview); // ScrollView scrollv = new ScrollView(this); // scrollv.addView(webview); // setContentView(scrollv); return; } else { explain = "Unknown page type: " + type.str + " with vaule type: " + value.cls + "\n\n##############\n\n"; explain += value.toString(); // Fall thru for explainv.setText(explain). } } catch (Exception ex) { ex.printStackTrace(); explain = Static.describe(ex); } } TextView explainv = new TextView(this); explainv.setText(explain); explainv.setBackgroundColor(Color.BLACK); explainv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 24); explainv.setTextColor(Color.YELLOW); SetContentViewWithHomeButtonAndScroll(explainv); }
From source file:com.fastbootmobile.encore.app.fragments.ArtistFragment.java
/** * {@inheritDoc}//from ww w .jav a 2s.c o m */ @Override @TargetApi(Build.VERSION_CODES.LOLLIPOP) public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mHandler = new Handler(); // Setup the inside fragments mArtistTracksFragment = new ArtistTracksFragment(); mArtistTracksFragment.setParentFragment(this); mArtistInfoFragment = new ArtistInfoFragment(); mArtistInfoFragment.setArguments(mArtist); mArtistSimilarFragment = new ArtistSimilarFragment(); mArtistSimilarFragment.setArguments(mArtist); // Inflate the main fragment view mRootView = (ParallaxScrollView) inflater.inflate(R.layout.fragment_artist, container, false); // Set the hero image and artist from arguments mHeroImageView = (ImageView) mRootView.findViewById(R.id.ivHero); if (mHeroImage != null) { mHeroImageView.setImageBitmap(mHeroImage); // The hero image that comes from a transition might be low in quality, so load // the higher quality and fade it in loadArt(false); } else { // Display placeholder and try to get the real art mHeroImageView.setImageResource(R.drawable.album_placeholder); loadArt(true); } final TextView tvArtist = (TextView) mRootView.findViewById(R.id.tvArtist); tvArtist.setBackgroundColor(mBackgroundColor); tvArtist.setText(mArtist.getName()); final PagerTabStrip strip = (PagerTabStrip) mRootView.findViewById(R.id.pagerArtistStrip); strip.setDrawFullUnderline(false); strip.setAlpha(0.0f); strip.setTranslationY(-20); strip.animate().alpha(1.0f).setDuration(ANIMATION_DURATION).setStartDelay(500).translationY(0).start(); if (!Utils.hasLollipop()) { tvArtist.setAlpha(0); tvArtist.animate().alpha(1).setDuration(ANIMATION_DURATION).setStartDelay(500).start(); } // Setup the subfragments pager final WrapContentHeightViewPager pager = (WrapContentHeightViewPager) mRootView .findViewById(R.id.pagerArtist); pager.setAdapter(new ViewPagerAdapter(getChildFragmentManager())); pager.setOffscreenPageLimit(FRAGMENT_COUNT); pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageSelected(int i) { if (mRootView.getScrollY() > tvArtist.getTop()) { mRootView.smoothScrollTo(0, tvArtist.getTop()); } mHandler.post(new Runnable() { @Override public void run() { pager.setMinimumHeight(500); pager.requestLayout(); } }); boolean hasRosetta = ProviderAggregator.getDefault().getRosettaStonePrefix().size() > 0; if (hasRosetta) { if (i == FRAGMENT_ID_BIOGRAPHY) { mArtistInfoFragment.notifyActive(); } else if (i == FRAGMENT_ID_SIMILAR) { mArtistSimilarFragment.notifyActive(); } } else { if (i == FRAGMENT_ID_SIMILAR) { // This is actually BIOGRAPHY if rosetta is not available mArtistInfoFragment.notifyActive(); } } } @Override public void onPageScrollStateChanged(int i) { } }); mRootView.setOnScrollListener(new ObservableScrollView.ScrollViewListener() { @Override public void onScroll(ObservableScrollView scrollView, int x, int y, int oldx, int oldy) { final ActionBar ab = ((AppActivity) getActivity()).getSupportActionBar(); if (ab != null) { if (y >= tvArtist.getTop()) { ab.hide(); } else { ab.show(); } } } }); // Setup the source logo final ImageView ivSource = (ImageView) mRootView.findViewById(R.id.ivSourceLogo); mLogoBitmap = PluginsLookup.getDefault().getCachedLogo(getResources(), mArtist); ivSource.setImageDrawable(mLogoBitmap); // Outline is required for the FAB shadow to be actually oval mFabPlay = (FloatingActionButton) mRootView.findViewById(R.id.fabPlay); showFab(false, false); // Set the FAB animated drawable mFabDrawable = new PlayPauseDrawable(getResources(), 1); mFabDrawable.setShape(PlayPauseDrawable.SHAPE_PLAY); mFabDrawable.setYOffset(6); final Song currentTrack = PlaybackProxy.getCurrentTrack(); if (currentTrack != null && currentTrack.getArtist() != null && currentTrack.getArtist().equals(mArtist.getRef())) { int state = PlaybackProxy.getState(); if (state == PlaybackService.STATE_PLAYING) { mFabDrawable.setShape(PlayPauseDrawable.SHAPE_PAUSE); } else if (state == PlaybackService.STATE_PAUSED) { mFabShouldResume = true; } else if (state == PlaybackService.STATE_BUFFERING) { mFabDrawable.setShape(PlayPauseDrawable.SHAPE_PLAY); mFabDrawable.setBuffering(true); mFabShouldResume = true; } else if (state == PlaybackService.STATE_PAUSING) { mFabDrawable.setShape(PlayPauseDrawable.SHAPE_PAUSE); mFabDrawable.setBuffering(true); mFabShouldResume = true; } } mFabPlay.setImageDrawable(mFabDrawable); mFabPlay.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (mFabDrawable.getCurrentShape() == PlayPauseDrawable.SHAPE_PLAY) { if (mFabShouldResume) { PlaybackProxy.play(); } else { mArtistTracksFragment.playRecommendation(); } } else { mFabDrawable.setShape(PlayPauseDrawable.SHAPE_PAUSE); mFabShouldResume = true; PlaybackProxy.pause(); } } }); return mRootView; }
From source file:org.trakhound.www.trakhound.DeviceDetails.java
private void updateControllerStatus_SystemStatus(DeviceStatus status) { // Set System Status TextView txt = (TextView) findViewById(R.id.SystemStatusText); if (txt != null) { String s1 = status.controllerInfo.systemStatus; txt.setText(s1);/*from w w w . ja v a 2 s .c o m*/ if (s1.equals("Normal")) txt.setTextColor(getResources().getColor(R.color.statusGreen)); else if (s1.equals("Fault")) txt.setTextColor(getResources().getColor(R.color.statusRed)); else txt.setTextColor(getResources().getColor(R.color.foreground_normal_color)); // Set System Message txt = (TextView) findViewById(R.id.SystemMessageText); if (txt != null) { String s2 = status.controllerInfo.systemMessage; // Set System Message Text txt.setText(s2); // Set Visibility of System Message if (s2 == null || s2.isEmpty()) txt.setVisibility(View.GONE); else txt.setVisibility(View.VISIBLE); // Set Colors if (!s1.equals("Normal")) { txt.setTextColor(Color.WHITE); txt.setBackgroundColor(Color.RED); } else { txt.setTextColor(getResources().getColor(R.color.foreground_normal_color)); txt.setBackgroundColor(Color.YELLOW); } } } }
From source file:com.fizz.StickyFragment.java
@Override public void onStart() { super.onStart(); LinearLayout ll = (LinearLayout) getActivity().findViewById(R.id.ll); for (int i = 0; i < drinks.length; i++) { TextView tt = new TextView(getActivity()); tt.setText(drinks[i].toUpperCase(Locale.US) + "\n" + ingredients[i]); tt.setPadding(15, 15, 15, 15);//from w w w .j ava 2s .c o m tt.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { drink = ((TextView) v).getText().toString(); try { Intent venmoIntent = VenmoLibrary.openVenmoPayment("1684", "Fizz", "8123744601", "0.01", drink, "pay"); startActivityForResult(venmoIntent, 1); // 1 is the requestCode we are using for Venmo. Feel // free to change this to another number. // Venmo native app not install on device, so let's // instead open a mobile web version of Venmo in a // WebView } catch (android.content.ActivityNotFoundException e) { Log.e("Fizz", "onClicked"); { Intent venmoIntent = new Intent(getActivity(), VenmoWebViewActivity.class); String venmo_uri = VenmoLibrary.openVenmoPaymentInWebView("1684", "Fizz", "8123744601", "0.01", "Drink", "pay"); venmoIntent.putExtra("url", venmo_uri); startActivityForResult(venmoIntent, 1); } //} catch (android.content.ActivityNotFoundException e) { //e.printStackTrace() ; } } }); tt.setTextSize(22); if (textnum % 2 == 0) { tt.setBackgroundColor(Color.argb(0, 51, 181, 229)); tt.setTextColor(Color.argb(255, 51, 181, 229)); } else { tt.setBackgroundColor(Color.argb(240, 51, 181, 229)); tt.setTextColor(Color.argb(255, 255, 255, 255)); } tt.setTypeface(SplashActivity.tp); ll.addView(tt); textnum++; } }