List of usage examples for android.widget TextView setTextSize
@android.view.RemotableViewMethod public void setTextSize(float size)
From source file:com.androidquery.AQuery.java
/** * Set the text size (in sp) of a TextView. * * @param size size//from w w w . j a v a2 s . c o m * @return self */ public AQuery textSize(float size) { if (view instanceof TextView) { TextView tv = (TextView) view; tv.setTextSize(size); } return self(); }
From source file:com.androidquery.AbstractAQuery.java
/** * Set the text size (in sp) of a TextView. * * @param size size//from w w w .j av a2s . c o m * @return self */ public T textSize(float size) { if (view instanceof TextView) { TextView tv = (TextView) view; tv.setTextSize(size); } return self(); }
From source file:org.smilec.smile.student.CourseList.java
private void createScoreTable(Vector<Integer> _myscore, String username) { int num_right = countrightquestion(_myscore); int total_question = LAST_SCENE_NUM; TableLayout tl = (TableLayout) findViewById(R.id.tableLayoutSeeR); TextView text1 = (TextView) findViewById(R.id.Header01); text1.setText(getString(R.string.name) + ": " + username); TextView text2 = (TextView) findViewById(R.id.Header11); text2.setText(getString(R.string.t_score) + ":" + num_right + "/" + total_question); for (int i = 0; i < _myscore.size(); i++) { TableRow tr = new TableRow(getApplicationContext()); tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT)); int number = 0; number = i + 1;/*from ww w .j av a2s. c o m*/ int score = _myscore.get(i); Button b = new Button(getApplicationContext()); b.setText("(" + number + ")"); b.setTextSize(resultSize1); // b.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT)); TableRow.LayoutParams params = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); params.setMargins(returnPixels(30.0f), 0, returnPixels(30.0f), 0); b.setLayoutParams(params); b.setOnClickListener(new MyButtonListener(number)); /* Add Button to row. */ tr.addView(b); TextView text = new TextView(getApplicationContext()); if (score == 1) { // right text.setText("0"); } else { // wrong text.setText("X"); } text.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT)); text.setTextColor(Color.BLACK); text.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL); text.setTextSize(resultSize2); tr.addView(text); //tr.setBackgroundResource(R.drawable.sf_gradient_03); tl.addView(tr, new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT)); } return; }
From source file:com.eveningoutpost.dexdrip.Home.java
private void updateCurrentBgInfo(String source) { Log.d(TAG, "updateCurrentBgInfo from: " + source); if (!activityVisible) { Log.d(TAG, "Display not visible - not updating chart"); return;//from w w w . java2 s . c o m } if (reset_viewport) { reset_viewport = false; holdViewport.set(0, 0, 0, 0); if (chart != null) chart.setZoomType(ZoomType.HORIZONTAL); } setupCharts(); final TextView notificationText = (TextView) findViewById(R.id.notices); final TextView lowPredictText = (TextView) findViewById(R.id.lowpredict); if (BgGraphBuilder.isXLargeTablet(getApplicationContext())) { notificationText.setTextSize(40); } notificationText.setText(""); notificationText.setTextColor(Color.RED); UndoRedo.purgeQueues(); if (UndoRedo.undoListHasItems()) { btnUndo.setVisibility(View.VISIBLE); showcasemenu(SHOWCASE_UNDO); } else { btnUndo.setVisibility(View.INVISIBLE); } if (UndoRedo.redoListHasItems()) { btnRedo.setVisibility(View.VISIBLE); showcasemenu(SHOWCASE_REDO); } else { btnRedo.setVisibility(View.INVISIBLE); } boolean isBTWixel = CollectionServiceStarter.isBTWixel(getApplicationContext()); // port this lot to DexCollectionType to avoid multiple lookups of the same preference boolean isDexbridgeWixel = CollectionServiceStarter.isDexBridgeOrWifiandDexBridge(); boolean isWifiBluetoothWixel = CollectionServiceStarter.isWifiandBTWixel(getApplicationContext()); isBTShare = CollectionServiceStarter.isBTShare(getApplicationContext()); isG5Share = CollectionServiceStarter.isBTG5(getApplicationContext()); boolean isWifiWixel = CollectionServiceStarter.isWifiWixel(getApplicationContext()); alreadyDisplayedBgInfoCommon = false; // reset flag if (isBTShare) { updateCurrentBgInfoForBtShare(notificationText); } if (isG5Share) { updateCurrentBgInfoCommon(notificationText); } if (isBTWixel || isDexbridgeWixel || isWifiBluetoothWixel) { updateCurrentBgInfoForBtBasedWixel(notificationText); } if (isWifiWixel || isWifiBluetoothWixel) { updateCurrentBgInfoForWifiWixel(notificationText); } else if (is_follower) { displayCurrentInfo(); getApplicationContext().startService(new Intent(getApplicationContext(), Notifications.class)); } else if (!alreadyDisplayedBgInfoCommon && DexCollectionType.getDexCollectionType() == DexCollectionType.LibreAlarm) { updateCurrentBgInfoCommon(notificationText); } if (prefs.getLong("alerts_disabled_until", 0) > new Date().getTime()) { notificationText.append("\n ALL ALERTS CURRENTLY DISABLED"); } else if (prefs.getLong("low_alerts_disabled_until", 0) > new Date().getTime() && prefs.getLong("high_alerts_disabled_until", 0) > new Date().getTime()) { notificationText.append("\n LOW AND HIGH ALERTS CURRENTLY DISABLED"); } else if (prefs.getLong("low_alerts_disabled_until", 0) > new Date().getTime()) { notificationText.append("\n LOW ALERTS CURRENTLY DISABLED"); } else if (prefs.getLong("high_alerts_disabled_until", 0) > new Date().getTime()) { notificationText.append("\n HIGH ALERTS CURRENTLY DISABLED"); } NavigationDrawerFragment navigationDrawerFragment = (NavigationDrawerFragment) getFragmentManager() .findFragmentById(R.id.navigation_drawer); // DEBUG ONLY if ((BgGraphBuilder.last_noise > 0) && (prefs.getBoolean("show_noise_workings", false))) { notificationText.append("\nSensor Noise: " + JoH.qs(BgGraphBuilder.last_noise, 1)); if ((BgGraphBuilder.best_bg_estimate > 0) && (BgGraphBuilder.last_bg_estimate > 0)) { final double estimated_delta = BgGraphBuilder.best_bg_estimate - BgGraphBuilder.last_bg_estimate; notificationText.append("\nBG Original: " + bgGraphBuilder.unitized_string(BgReading.lastNoSenssor().calculated_value) + " \u0394 " + bgGraphBuilder.unitizedDeltaString(false, true, true) + " " + BgReading.lastNoSenssor().slopeArrow()); notificationText.append("\nBG Estimate: " + bgGraphBuilder.unitized_string(BgGraphBuilder.best_bg_estimate) + " \u0394 " + bgGraphBuilder.unitizedDeltaStringRaw(false, true, estimated_delta) + " " + BgReading.slopeToArrowSymbol(estimated_delta / (BgGraphBuilder.DEXCOM_PERIOD / 60000))); } } // TODO we need to consider noise level? // when to raise the alarm lowPredictText.setText(""); lowPredictText.setVisibility(View.INVISIBLE); if (BgGraphBuilder.low_occurs_at > 0) { final double low_predicted_alarm_minutes = Double .parseDouble(prefs.getString("low_predict_alarm_level", "50")); final double now = JoH.ts(); final double predicted_low_in_mins = (BgGraphBuilder.low_occurs_at - now) / 60000; if (predicted_low_in_mins > 1) { lowPredictText.append(getString(R.string.low_predicted) + "\n" + getString(R.string.in) + ": " + (int) predicted_low_in_mins + getString(R.string.space_mins)); if (predicted_low_in_mins < low_predicted_alarm_minutes) { lowPredictText.setTextColor(Color.RED); // low front getting too close! } else { final double previous_predicted_low_in_mins = (BgGraphBuilder.previous_low_occurs_at - now) / 60000; if ((BgGraphBuilder.previous_low_occurs_at > 0) && ((previous_predicted_low_in_mins + 5) < predicted_low_in_mins)) { lowPredictText.setTextColor(Color.GREEN); // low front is getting further away } else { lowPredictText.setTextColor(Color.YELLOW); // low front is getting nearer! } } lowPredictText.setVisibility(View.VISIBLE); } BgGraphBuilder.previous_low_occurs_at = BgGraphBuilder.low_occurs_at; } if (navigationDrawerFragment == null) Log.e("Runtime", "navigationdrawerfragment is null"); try { navigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), menu_name, this); } catch (Exception e) { Log.e("Runtime", "Exception with navigrationdrawerfragment: " + e.toString()); } if (nexttoast != null) { toast(nexttoast); nexttoast = null; } // hide the treatment recognition text after some seconds if ((last_speech_time > 0) && ((JoH.ts() - last_speech_time) > 20000)) { voiceRecognitionText.setVisibility(View.INVISIBLE); last_speech_time = 0; } if (ActivityRecognizedService.is_in_vehicle_mode()) { btnVehicleMode.setVisibility(View.VISIBLE); } else { btnVehicleMode.setVisibility(View.INVISIBLE); } //showcasemenu(1); // 3 dot menu }
From source file:org.ednovo.goorusearchwidget.SearchResults_resource.java
public LinearLayout createResourceEmptyView() { LinearLayout scrollChild = new LinearLayout(this); scrollChild.setPadding(10, 0, 10, 0); resourcelayout = LayoutInflater.from(this).inflate(R.layout.resource_view, null); TextView title = (TextView) resourcelayout.findViewById(R.id.textViewTitle); title.setText("Sorry! No Results Found"); title.setTextColor(getResources().getColor(R.color.Grey)); title.setPadding(50, 50, 0, 10);/* w w w. j a v a 2s. c o m*/ title.setTextSize(25); scrollChild.addView(resourcelayout, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT)); scrollChild.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); return scrollChild; }
From source file:com.lifehackinnovations.siteaudit.FloorPlanActivity.java
public static AlertDialog getaddtextdialog(String title, final int itemnumber, Context ctx) { AlertDialog.Builder getaddtext = new AlertDialog.Builder(ctx); final LinearLayout linearlayout = new LinearLayout(ctx); linearlayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); linearlayout.setOrientation(LinearLayout.VERTICAL); final EditText nameet = new EditText(ctx); nameet.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); final TextView fontname = new TextView(ctx); fontname.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); final TextView colorname = new TextView(ctx); colorname.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); final Spinner fontsizespinner = new Spinner(ctx); fontsizespinner.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); final Spinner colorspinner = new Spinner(ctx); fontsizespinner.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); List<String> fontsizelist = new ArrayList<String>(); for (int t = 1; t < 200; t++) { fontsizelist.add(u.s(t));//from w ww. j a v a 2s.c om } ArrayAdapter<String> fontsizearrayadapter = new ArrayAdapter<String>(ctx, R.layout.spinnertextview, fontsizelist); fontsizearrayadapter.setDropDownViewResource(R.layout.spinnertextview); List<String> colorlist = new ArrayList<String>(); { colorlist.add("RED"); colorlist.add("BLACK"); colorlist.add("BLUE"); colorlist.add("GREEN"); colorlist.add("WHITE"); colorlist.add("GRAY"); } ArrayAdapter<String> colorlistarrayadapter = new ArrayAdapter<String>(ctx, R.layout.spinnertextview, colorlist); fontsizearrayadapter.setDropDownViewResource(R.layout.spinnertextview); colorspinner.setAdapter(colorlistarrayadapter); fontsizespinner.setAdapter(fontsizearrayadapter); fontsizespinner.setSelection(getIndexofSpinner(fontsizespinner, "25")); fontname.setText("Select Font Size"); fontname.setTextSize(20f); colorname.setText("Select Color"); colorname.setTextSize(20f); linearlayout.addView(nameet); linearlayout.addView(fontname); linearlayout.addView(fontsizespinner); linearlayout.addView(colorname); linearlayout.addView(colorspinner); if (!(itemnumber == view.i)) { nameet.setText(view.ITEMstring[itemnumber]); fontsizespinner.setSelection(getIndexofSpinner(fontsizespinner, u.s(view.ITEMfontsize[itemnumber]))); colorspinner.setSelection(getIndexofSpinner(colorspinner, u.s(view.ITEMfontcolor[itemnumber]))); } getaddtext.setView(linearlayout); getaddtext.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); getaddtext.setTitle(title); getaddtext.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub String string = nameet.getText().toString(); float fontsize = fontsizespinner.getSelectedItemPosition() + 1; //ITEMelcnumber[itemselectednumber]=u.i(string); int colpos = colorspinner.getSelectedItemPosition(); int[] col = new int[] { Color.RED, Color.BLACK, Color.BLUE, Color.GREEN, Color.WHITE, Color.GRAY }; int color = col[colpos]; Log.d("addtext", u.s((int) fontsize) + colpos + color); view.ITEMstring[itemnumber] = string; view.ITEMfontsize[itemnumber] = (int) fontsize; view.ITEMfontcolor[itemnumber] = color; view.itemname = string; view.fontsize = (int) fontsize; view.color = color; view.invalidate(); dialog.dismiss(); FloorPlanActivity.writeonedbitem(itemnumber); } }); return getaddtext.create(); }
From source file:com.farmerbb.notepad.fragment.NoteViewFragment.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override//from w w w. j a va2 s . c o m 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) { Bitmap bitmap = ((BitmapDrawable) ContextCompat.getDrawable(getActivity(), R.drawable.ic_recents_logo)) .getBitmap(); ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription(title, bitmap, 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 = getActivity().findViewById(R.id.noteViewEdit); LinearLayout noteList = 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 = getActivity().findViewById(R.id.textView); markdownView = getActivity().findViewById(R.id.markdownView); // Apply theme SharedPreferences pref = getActivity().getSharedPreferences(getActivity().getPackageName() + "_preferences", Context.MODE_PRIVATE); 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); String css = ""; 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"); String linkColor = " #" + StringUtils.remove( Integer.toHexString(new TextView(getActivity()).getLinkTextColors().getDefaultColor()), "ff"); css = "body { " + "margin:" + topBottom + topBottom + leftRight + leftRight + "; " + "font-family:" + fontFamily + "; " + "font-size:" + fontSize + "; " + "color:" + fontColor + "; " + "}" + "a { " + "color:" + linkColor + "; " + "}"; markdownView.getSettings().setJavaScriptEnabled(false); markdownView.getSettings().setLoadsImagesAutomatically(false); markdownView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { 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 */ } return true; } }); } // 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, "data:text/css;base64," + Base64.encodeToString(css.getBytes(), Base64.DEFAULT)); // 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((v, event) -> { detector.onTouchEvent(event); return false; }); if (markdownView != null) markdownView.setOnTouchListener((v, event) -> { detector.onTouchEvent(event); return false; }); }
From source file:com.anjalimacwan.fragment.NoteViewFragment.java
@SuppressLint("SetJavaScriptEnabled") @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override//from w w w. ja v a2s. c o m 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:com.skytree.epubtest.BookViewActivity.java
public TextView makeLabel(int id, String text, int gravity, float textSize, int textColor) { TextView label = new TextView(this); label.setId(id);/*from ww w. j a v a2 s . c om*/ label.setGravity(gravity); label.setBackgroundColor(Color.TRANSPARENT); label.setText(text); label.setTextColor(textColor); label.setTextSize(textSize); return label; }