Java - Android - Installed packages' icons not showing in listview - java

I'm trying to load installed packages' icons into a listview, but they are not showing in anyway, searched and used everything I found on the web but they just won't show, while they work if I use
R.drawable.ic_launcher
So I guess it's not a layout-related issue.
Here's the code I'm using
for(int i = 0; i < numeroElementi; i++){
boolean nonSystem = (packages.get(i).flags & ApplicationInfo.FLAG_SYSTEM) == 0;
if(nonSystem == true){
HashMap<String,Object> app = new HashMap<String,Object>();
app.put("appName", packages.get(i).loadLabel(pm)); // these both work
app.put("appPackageName", packages.get(i).packageName);
try {
//app.put("appIcon", pm.getApplicationIcon(packages.get(i).packageName));
//app.put("appIcon", packages.get(i).icon + "");
//app.put("appIcon", packages.get(i).loadIcon(pm));
app.put("appIcon",packages.get(i).icon);
//app.put("appIcon", R.drawable.ic_launcher); <- this works
} catch (NameNotFoundException e) {
app.put("appIcon", R.drawable.ic_launcher);
}
installedList.add(app);
}
}
Is then there another way to grab the icon? As said earlier, if I force the ic_launcher icon, then it works... testing with packages.get(i).icon I found out that some of the voices have got the ic_launcher icon shown, so I thought that method just directed to that specific icon... anyone can help me get this work, please?

Related

How to Detect Multiple Images with AR core

I'm trying out detecting multiple augmented images with AR core, with
https://developers.google.com/ar/develop/java/augmented-images/guide
and other online tutorials. Currently, I have the database setup and loaded with images. However
Collection<AugmentedImage> augmentedImages = frame.getUpdatedTrackables(AugmentedImage.class);
did not seem to capture and match the feature points of my images in my db.
Can you advise me about what I need to do?
I have set up and loaded multiple images from db. The app is able to detect only 1 image previously. However, after tweaking my code to detect multiple images, it did not work properly.
Tried researching and debugging however, still unable to solve it.
private void onUpdateFrame(FrameTime frameTime)
{
Frame frame = arFragment.getArSceneView().getArFrame();
Collection<AugmentedImage> augmentedImages = frame.getUpdatedTrackables(AugmentedImage.class);
for (AugmentedImage augmentedImage : augmentedImages)
{
int i =augmentedImages.size();
Log.d("NoImage",""+i);
if (augmentedImage.getTrackingState() == TrackingState.TRACKING)
{
if (augmentedImage.getName().contains("img1") && !modelAdded)
{
renderObject(arFragment, augmentedImage.createAnchor(augmentedImage.getCenterPose()),R.raw.car);
modelAdded = true;
}
else if (augmentedImage.getName().contains("img2") && !modelAdded)
{
renderObject(arFragment, augmentedImage.createAnchor(augmentedImage.getCenterPose()), R.raw.car);
modelAdded = true;
}
else if (augmentedImage.getName().contains("img3") && !modelAdded)
{
renderObject(arFragment, augmentedImage.createAnchor(augmentedImage.getCenterPose()), R.raw.car);
modelAdded = true;
}
}
}
}

Netbeans module development - How to modify opened file

I am writing my own Netbeans plugin to edit opened files. I have managed to get some information about currently active file using
TopComponent activeTC = TopComponent.getRegistry().getActivated();
FileObject fo = activeTC.getLookup().lookup(FileObject.class);
io.getOut().println(fo.getNameExt());
io.getOut().println(fo.canWrite());
io.getOut().println(fo.asText());
But I have no idea how to modify this file. Can someone help me with this?
And second question, how to get text selection ranges? I want to run my command only on selected text.
For modifying the file you could use the NetBeans org.openide.filesystems.FileUtil.toFile() and then the regular Java stuff to read and write files and for getting the selected text of the current editor window you would have to do something like:
Node[] arr = activeTC.getActivatedNodes();
for (int j = 0; j < arr.length; j++) {
EditorCookie ec = (EditorCookie) arr[j].getCookie(EditorCookie.class);
if (ec != null) {
JEditorPane[] panes = ec.getOpenedPanes();
if (panes != null) {
// USE panes
}
}
}
For more code examples see also here
After several hours of research I found out that:
The code I posted in Question can be used to obtain basic information about active file.
To get caret position or get selection range you can do:
JTextComponent editor = EditorRegistry.lastFocusedComponent();
io.getOut().println("Caret pos: "+ editor.getCaretPosition());
io.getOut().println("Selection start: "+ editor.getSelectionStart());
io.getOut().println("Selection end: "+ editor.getSelectionEnd());
To modify content of active file (in a way that the modification can be undo by Ctrl+z) you may use this code:
final StyledDocument doc = context.openDocument();
NbDocument.runAtomicAsUser(doc, new Runnable() {
public void run() {
try {
doc.insertString(ofset, "New text.", SimpleAttributeSet.EMPTY);
} catch (Exception e) {
}
}
});

ImageView with Russian web URL

ImageView dont show Image with URL with Russian letters.
Tried URLEncode, but still dont work/ In project was used Fresco
String norm = "http://www.rts-tender.ru/Portals/0/EasyDNNNews/1523/1523риадагестан.jpg";
for(int j = 0; j < 32; j++){
try {
s = s.replace(""+((char)('а'+j)),""+URLEncoder.encode(""+ ((char)‌​('а'+j)),encoding));
}
catch (Exception e) {
e.printStackTrace();
}
}
viewHolder.imagePreview.setImageURI(Uri.parse(norm));
That's because ImageView does not support remote content. You need to download the image, or use Glide or Picasso to do that for you.
In me project was used Fresco, excuse me, i forgot.
Then it smells like Fresco's bug as image's source is completely irrelevant for ImageView.
Here's more useful link in this case:https://github.com/facebook/fresco/issues
Try:
String norm = "http://www.rtstender.ru/Portals/0/EasyDNNNews/1523/1523риадагестан.jpg";
URLEncoder.encode(norm, HTTP.UTF-8);
viewHolder.imagePreview.setImageURI(Uri.parse(norm));

Java Printing Tray Selection Saga

While there are several questions regarding tray selection out there, none of them relate to my problem.
Here's the code I'm using to print:
private static void finalPrint(PDDocument pdoc, boolean pbStationary)
throws BigBangJewelException
{
PrintService lrefSvc;
PrinterJob lrefPJob;
Media lrefMedia;
HashPrintRequestAttributeSet lobjSet;
lrefSvc = getPrinter();
lrefPJob = PrinterJob.getPrinterJob();
try
{
lrefPJob.setPrintService(lrefSvc);
lrefPJob.setPageable(pdoc);
lrefMedia = null;
if ( pbStationary )
lrefMedia = getTray(lrefSvc);
if ( lrefMedia != null )
{
lobjSet = new HashPrintRequestAttributeSet();
lobjSet.add(lrefMedia);
lrefPJob.print(lobjSet);
}
else
lrefPJob.print();
}
catch (Throwable e)
{
throw new BigBangJewelException(e.getMessage(), e);
}
}
private static PrintService getPrinter()
throws BigBangJewelException
{
String lstrPrinter;
PrintService[] larrServices;
int i;
try
{
lstrPrinter = (String)Engine.getUserData().get("Printer");
larrServices = PrinterJob.lookupPrintServices();
for ( i = 0; i < larrServices.length; i++ )
{
if (larrServices[i].getName().indexOf(lstrPrinter) != -1)
return larrServices[i];
}
}
catch (Throwable e)
{
throw new BigBangJewelException(e.getMessage(), e);
}
throw new BigBangJewelException("Impressora definida (" + lstrPrinter + ") não encontrada.");
}
private static Media getTray(PrintService prefSvc)
{
Media[] larrMedia;
String lstrAux;
int i;
larrMedia = (Media[])prefSvc.getSupportedAttributeValues(Media.class, null, null);
if ( larrMedia == null )
return null;
for ( i = 0; i < larrMedia.length; i++ )
{
lstrAux = larrMedia[i].toString().toLowerCase();
if (lstrAux.contains("tray") && lstrAux.contains("3"))
{
return larrMedia[i];
}
}
return null;
}
The baffling thing is, this code used to work. The machine had a bunch of Xerox printers defined, and the code would correctly identify the wanted printer, and the wanted tray, and everything worked wonderfully.
Then, one day, overnight, it stopped working. It still finds the right printer, but now, it always prints to tray 1.
The only thing that changed was that an extra HP printer was added to the machine.
I can confirm that the code is finding the tray and sending it to the print job, but it's getting ignored.
Again, there are many questions out there regarding this issue, but my problem is that the code worked well for four years, then stopped working for no apparent reason.
Can anyone shed any light on this subject?
Edit: New information: Uninstalling the HP printer made the Xerox printers work right again. Why would installing one driver affect Java's ability to communicate with a different driver?
Edit 2: Further information: If we install the HP global printer driver instead of the specific printer driver, everything works correctly. I'll leave the question unanswered to see if anyone can come up with a good explanation before the bounty expires, then I'm going to put this edit in an answer and accept it.
If I got you question correctly, you the content of lobjSet is unchanged, yet it the print result is different, with the new driver installed.
I checked the code for PnterJob.print(PrintRequestAttributeSet) and was surprised that it completely ignores the attribute set.
So I looked at where the PrintService is coming from, the code is a little lengthy, but I guess it interacts somehow with the installed printer drivers to create appropriate instances. So the new driver changes this, returning a different PrintService. There is no way I can tell in what exact way this thing changes, but if you can recreate both scenarios (and it seems you can), it should be fairly easy to use a debugger to find the exact place where the behavior of the code changes.
The solution to our particular situation was to change the printer drivers for the HP printer.
Originally, we had installed the specific driver for the printer in question, which caused this behavior. Installing HP's global driver instead made the problem go away.
Unfortunately, we do not know why. Jens Schauder's answer contains clues as to how to go about finding out.

External camera doesn't work JavaCV

I have a JavaCV application using external camera, but it's not working... The result is a black image from the camera...
I have another project that use the same code and it's works fine...
I don't understando why it's not working in my new project
capture = cvCreateCameraCapture(1);
imgCamera = cvQueryFrame(capture);
the code is simple, first capture the image from external webcam and set it in a IplImage
why it works in a project and don't in another?
You can iterate through all your camera attached to your system and then get index for particular device either it is a webcam or external camera and use it in code. I am giving you a sample code for it
String cameraInformation = "";
int n = com.googlecode.javacv.cpp.videoInputLib.videoInput.listDevices();
for (int i = 0; i < n; i++) {
String info = com.googlecode.javacv.cpp.videoInputLib.videoInput
.getDeviceName(i);
//cameraInformation = info + " Device id:" + i + "\n";
system.out.println("Your information for camera:"+info+" and device index is="+i);
}
From here you come to know which is the index of which device and use it in this code
capture = cvCreateCameraCapture(deviceIndex);
imgCamera = cvQueryFrame(capture);
Hope this helps

Categories

Resources