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!
Related
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);
For a little game I'm programming I'm trying to supply the user with some voice lines for flavor reasons. I've already recorded several lines, and they're all in the format of languageCode_packageName_name01.mp3.
Since I don't want the same few lines to play all the time, I intend to record several versions, and randomly pick one when retrieving them. For example, retrieving lines for "start" two times could result in playback of de_std_start01 and then de_std_start06.
Since I am quite new to android I'd like to ask for help regarding this implementation. I'm not sure whether I should utilize the raw folder for this task, or the assets folder. If possible, I would like to implement a folder structure like this, which would to my understanding need the use of the assets folder, in order to be able to simply drag & drop new files inside the folder, which will then be taken into account for random selection.:
<root folder>
- de
-- std
--- start
---- start01.mp3
---- start02.mp3
...
When given arguments specifying de, std and start, how would I go about retrieving the different files and randomly pick one of them? Thanks for your help!
If you include them in the raw folder, you should be able to access them as so:
//from your activity
AudioService audioService = new AudioService;
int randomTune = audioService.getRandom();
MediaPlayer mediaPlayer = MediaPlayer.create(context, randomTune);
mediaplayer.start;
//From a seperate service class
Class AudioService {
private int[] audioFiles = {
R.raw.song1, R.raw.song2, R.raw.song3, R.raw.song4, R.raw.song5, R.raw.song6
};
I believe that your folder structure will be somewhat flexible since you are wrapping the actual resource with the R class and referencing that in your code.
public int getRandom(){
// Here i am asking for a random number between 0 and 1, multiplying by 6, rounding
// it down, and explicitly casting to int.
// Result will be random int between 0 and 5. This will be the array index that
// randomly chooses the song.
private int randomIndex;
randomindex = (int) Math.floor(6 * Math.random);
return this.audioFiles[randomIndex];
}
}
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
I'm trying to do the next thing - let's say i have a menu with 5 drawable images (could be more but that's not the point), now when a user press on one drawable then it will be shown next a text that is already shown in the edittext.
Also I would like to allow the user add as many drawables as he wants.
So what i do understand is the next code lines -
Using map and defines the pairs of keyword and matching drawable -
private HashMap<String, Integer> emoticons = new HashMap<String, Integer>();
emoticons.put("[-smile-]", R.drawable.smile);
emoticons.put("[-tongue-]", R.drawable.tongue);
emoticons.put("[-cool-]", R.drawable.cool);
emoticons.put("[-sad-]", R.drawable.sad);
emoticons.put("[-cry-]", R.drawable.cry);
fillArrayList();
private void fillArrayList() {
Iterator<Entry<String, Integer>> iterator = emoticons.entrySet().iterator();
while(iterator.hasNext()){
Entry<String, Integer> entry = iterator.next();
arrayListSmileys.add(entry.getKey());
}
}
First of all - I've decided to define the keywords like the next pattern - [-keyword-] - because I assume in that way it will be much more easy to get the keywords from the String.
Now, the thing that I'm getting stuck in, is how should I read the String, and how to change the keywords from the String into the drawable.
So let's say the user want to write the next line (using the drawables) -
I am [-smile-] everything [-cool-]
So what I try to do is, something that can read this string and when it getting into [-keyword-], then it knows to show it to the user as drawable from the map pairs.
Thanks for any kind of help
If I'm working out your problem correctly you want to use "smileys" in your text?
You can use HTML in TextViews and display the images with image tags.
yourTextView.setText(Html.fromHtml("I am <img src='img_smile'>smile</img> everything <img src='img_cool'>cool</img>"));
I have a MyObj class with a name and an id. I have an AutoCompleteTextView that is currently letting you type MyObj names and it auto-completes them for you. There's a button next to the AutoCompleteTextView that, when pressed, I want to:
initiate a search based on the id of the selected MyObj, if one of the auto-complete suggestions was used, OR
initiate a search based on the value in the AutoCompleteTextView if none of the auto-complete suggestions was used (so a partial name string).
How should I go about this? I'm new to Android, so suggestions for other ways to do this are very welcome. Here's some of my current code:
AutoCompleteTextView actv = (AutoCompleteTextView)findViewById(R.id.searchText);
ArrayAdapter<MyObj> adapter = new ArrayAdapter<MyObj>(this,
android.R.layout.simple_dropdown_item_1line, myObjectsList);
actv.setAdapter(adapter);
And also:
public void searchButtonOnClick(View view) {
// Don't know how to get id of selected MyObj here, or just the value in the
// AutoCompleteTextView otherwise
}
I ended up creating a search instead of using an AutoCompleteTextView, since the search gives suggestions as you type also. I was able to pass the id along via the URI in an Intent to display another Activity with the MyObj details.