TextView Outline in Android - java

I am trying to implement TextView outline in one of my android application which is described here
I have made custom textView class as mentioned and there no any error. I am trying to use it in my activity but as I am learning yet, I am confused to use it in Activity as setStroke method.
I am trying as below
text_quotes.setStroke(0,R.color.toolbar_color,0,0);
can anybody please suggest me this four filed which value I should enter?
in CustomeTextView class is defined as below
strokeWidth = width;
strokeColor = color;
strokeJoin = join;
strokeMiter = miter;
I have issue in strokeJoin field, which value I should enter for it ?
Thanks

StrokeJoin seems to be a value of the Paint.Join enumeration.
So you should try one of the Paint.Join values like :
Paint.Join.MITER;
Paint.Join.BEVEL;
Paint.Join.ROUND;
Look the different values here : https://developer.android.com/reference/android/graphics/Paint.Join.html

Related

JasperReports export to Excel uses only last set background color

Im pretty pretty new to Dynamic-Jasper, but due to work i had to add a new feature to our already implemented solution.
My Problem
The Goal is to add a Column to a report that consists only out of a background-color based on some Information. I managed to do that, but while testing I stumbled upon a Problem. While all my Columns in the html and pdf view had the right color, the Excel one only colored the fields in the last Color.
While debugging i noticed, that the same colored Fields had the same templateId, but while all Views run through mostly the same Code the Excel one showed different behavior and had the same ID in all fields.
My Code where I manipulate the template
for(JRPrintElement elemt : jasperPrint.getPages().get(0).getElements()) {
if(elemt instanceof JRTemplatePrintText) {
JRTemplatePrintText text = (JRTemplatePrintText) elemt;
(...)
if (text.getFullText().startsWith("COLOR_IDENTIFIER")) {
String marker = text.getFullText().substring(text.getFullText().indexOf('#') + 1);
text.setText("ID = " + ((JRTemplatePrintText) elemt).getTemplate().getId());
int rgb = TypeConverter.string2int(Integer.parseInt(marker, 16) + "", 0);
((JRTemplatePrintText) elemt).getTemplate().setBackcolor(new Color(rgb));
}
}
}
The html view
The Excel view
Temporary Conclusion
The same styles uses the same Objects in the background and the JR-Excel export messes something up by assigning the same Object to all the Fields that I manipulated there. If anyone knows of a misstake by me or potential Solutions to change something different to result the same thing please let me know.
Something different I tried earlier, was trying to set the field in an evaluate Method that was called by Jasper. In that method we assign the textvalue of each field. It contained a map with JRFillFields, but unfortunatelly the Map-Implementation denied access to them and just retuned the Value of those. The map was provided by dj and couldn't be switched with a different one.
Edit
We are using JasperReports 6.7.1
I found a Solution, where I replaced each template with a new one that was supposed to look exactly alike. That way every Field has its own ID guaranteed and its not up to chance, how JasperReports handles its Data internaly.
JRTemplateElement custom =
new JRTemplateText(((JRTemplatePrintText) elemt).getTemplate().getOrigin(),
((JRTemplatePrintText) elemt).getTemplate().getDefaultStyleProvider());
custom.setBackcolor(new Color(rgb));
custom.setStyle(((JRTemplatePrintText) elemt).getTemplate().getStyle());
((JRTemplatePrintText) elemt).setTemplate(custom);

How to create a cardview with a specific layout using only Java (android studio)

I am making an app similar to facebook where i have a news feed which shows all the posts. However, the number of post in this feed varies with each user, depending on the amount of friends they have and how many posts they have made. I want to create a CardView for every post item which will show the name of the user who posted it, the time it was posted and the actual post itself. The layout will be split horizontally once with the post in the bottom half and the name of the person with the time it was posted on the top half.
Currently i can only find ways to do this by altering the xml text, but i want to create these CardViews as and when i need them, in my Java code.
I know i can alter TextViews by using such functions as setText() & setTextSize(). Is there a way for me to use similar functions on a CardView which can alter the base layout.
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
CardView TVcard = new CardView(Home.this);
TextView TVposts = new TextView(Home.this);
TextView test = new TextView(Home.this);
TVcard.addView(TVposts);
TVcard.addView(test);
test.setText("test");
test.setBackgroundColor(Color.GREEN);
TVposts.setText(snapshot.getValue().toString());
TVposts.setTextColor(Color.WHITE);
TVposts.setTextSize(25);
TVposts.setBackgroundColor(Color.BLACK);
TVposts.setHeight(200);
linearLayout.addView(TVcard);
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) TVcard.getLayoutParams();
params.setMargins(0, 20, 0, 0);
TVcard.setLayoutParams(params);
}
Thanks

ImageView hiding and showing

I'm struggling to get my android app to show and hide imageView objects programmatically. Actually I'm struggling to get expected behavior from imageView objects full stop.
Following the answers to this question,
Here's what I'm testing with:
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback{
#Override
protected void onCreate(Bundle savedInstanceState) {
ImageView warn = (ImageView)findViewById(R.id.gpsStatusWarning);
warn.setImageResource(R.drawable.gps_error);
warn.getLayoutParams().height = 64;
warn.getLayoutParams().width = 64;
}
}
The above code is called in the parent activity's OnCreate method, and it does exactly what I expect: It changes the image of the object to be the one designated, and it sets the height and width of said object. However, what I can't seem to do is to set the object as INVISIBLE or GONE. I just can't make it vanish at all, in fact. I've tried both:
warn.setVisibility(View.INVISIBLE);
warn.setVisibility(View.GONE);
But the image is still visible. I've even tried changing it in the XML to
android:visibility="gone"
But even that hasn't helped. The image is still visible.
What am I doing wrong? Am I missing a call to some update method? Does setting the image resource force the image to be drawn?
Try :
warn.setImageResource(0);
Or : warn.setImageResource(android.R.color.transparent);
This is how you set the visibility of ImageView objects on Android programatically:
yourImage.setVisibility(View.VISIBLE);
yourImage.setVisibility(View.INVISIBLE);
yourImage.setVisibility(View.GONE);
You can also set the initial states of ImageView objects in XML layout files like this:
visibility="visible"
visibility="gone"
visibility="invisible"
You can follow the official documentation about ImageView controls to try it on yourself on this link below. Learn how to set the visibility state of a view.
imageView.setVisibility(View.GONE);
imageView.setVisibility(View.VISIBLE);

Edittext list editing

In my app there's a large EditText field that contains barcodes separated by "\n". Barcodes can be added to this EditText field either programmatically(in onActivityResult returning from a scanning Activity) or manually.
Random example:
010566510415
40541651654556
561516551588
0043211652
003789453
I need each of these barcodes to be saved locally with their barcode type.
Random example:
012315612323 - Code128 (scanned)
561516551588 - Custom (manually inputted)
0123156124xx - Code128_Custom (scanned, then edited by user!!)
The scanning library I use identifies the barcode types on scan, so I have an ArrayList of objects that saves the scanned barcodes with their respective barcode type.
public class BarcodeObject
{
private int _position = -1;
private String _barcode = "";
private String _barcodeType = "";
}
The problem I'm having is keeping the ArrayList<BarcodeObject> in sync with the editText, when the user manually edits a barcode.
Do you have any ideas as how I should accomplish this?
Edit 1 : Thank you for your answers. One issue is that I don't know what barcode the user is modifying. I managed to solve it by using numbersList.getSelectionStart(); to find out where the cursor is and then look for the nearest "\n" so as to identify the correct barcode(bcs all barcodes are between "\n"). But what happens if the user click selects more than one barcodes and changes them. I just don't know how to keep them in sync.
you can update the array list based of index, example :
private ArrayList<BarcodeObject> barcodes = new ArrayList<Object>();
barcodes.set(#indexposition#, #BarcodeObject#);
and add getter and setter in your BarcodeObject class, for update the object;
Assuming you have an EditText only and you want to save the data after the user stop typing...
You have to extend the class with TextWatcher and override afterTextChanged(),beforeTextChanged(), onTextChanged().
You have to write your desired logic in afterTextChanged() method to achieve functionality needed by you.
That means, in your afterTextChanged(), you can write the following code and it will work well..
bcodes.set(#position#, #Barcode-Object#);
Assuming you have already initilized bcodes...
private ArrayList<BarcodeObject> bcodes = new ArrayList<Object>();
Hope it helps. Cheers!

ClassCastException in Android ScrollView

There is a class in my project (B) which extends (not directly) ScrollView (A) which can be used to set a value in the month field scroll which is vertical
Here is the inheritance heirarchy:
B extends D which extends an abstract class E which extends A
I am using a robotium method which gets all the scroll views in the present activity which returns an ArrayList of scrollviews(ArrayList) .
I am trying to assign the first element of that arraylist ArrayList.get(0) and trying to cast it to the B object doing it as follows:
ScrollView scrview = new ScrollView(a.getApplicationContext());
ChildScrollView scrview1 = new ChildScrollView(a.getApplicationContext());
scrview = solo.getScrollViews().get[0];
scrview1 = (ChildScrollView) scrview; // I get the classcastexception here
Is there any way to get around this?
I also tried
ChildScrollView scrview1 = new ChildScrollView(a.getApplicationContext());
ScrollView scrview = (ScrollView)new childScrollView(a.getApplicationContext());
//Also tried this --> ScrollView scrview = (ScrollView) scrview1;
scrview = solo.getScrollViews().get[0];
scrview1 = (ChildScrollView) scrview; // I get the classcastexception here
Any help would be appreciated. Let me know if I am missing something.
You are getting an exception because the cast cannot work like that. Think about it this way: All ChildScrollView are also ScrollView, so it makes sense to use them in a ScrollView context. But a ScrollView object may or may not be a ChildScrollView.
You could use reflection to try to determine the object's class at runtime before casting to ensure that the cast is safe. However, I'm not sure what you're trying to accomplish with your code above. You created a new object referred to by scrview1, but then immediately assign that variable to scrview? Can you give any more details about what you want to accomplish?

Categories