Sample DevicePolicyManager codes from Android 2.2 work? - java

Im looking for some sample codes to start with thanks, although i can read the api ,this will be a big help for others to help with a simple code.

Taken from the API Demo:
// Password quality spinner choices
// This list must match the list found in
// samples/ApiDemos/res/values/arrays.xml
final static int mPasswordQualityValues[] = new int[] {
DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED,
DevicePolicyManager.PASSWORD_QUALITY_SOMETHING,
DevicePolicyManager.PASSWORD_QUALITY_NUMERIC,
DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC,
DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC
};
Ref: DeviceAdminSample.java

Related

Anychart Android Java export chart as SVG or PNG in specific local folder

I was trying to create and save an image with AnyChart for an android application. This image is created without being rendered since the idea is to use the data from a vector to generate the image and save it on the phone's memory. I am using Java for programming the android application.
I have been testing the ".saveAsPng()" and ".saveAsSVG()" functions from the Anychart Library but there has been no success... I don't receive an error but I don't get the image either... and I don't know exactly how to proceed...
I tried to follow this guideline (https://docs.anychart.com/Common_Settings/Server-Side_Rendering) but as I said, I haven't succeeded in generating and saving the file.
This is the code that I have been using:
private class CustomDataEntry2 extends ValueDataEntry {
CustomDataEntry2(double x, Number value) {
super(x, value);
}
}
_
List<DataEntry> dataLateral = new ArrayList<>();
for (int p=0; p<DataX.size();p++) {
dataLateral.add(new CustomDataEntry2(DataY.get(p), DataX.get(p)));
}
AnyChartView anyChartViewLateral = new com.anychart.AnyChartView(this);
APIlib.getInstance().setActiveAnyChartView(anyChartViewLateral);
anyChartViewLateral.setProgressBar(new ProgressBar(this));
Polar polarLateralImage = AnyChart.polar();
polarLateralImage.startAngle(90);
Linear xScaleLateral = Linear.instantiate();
xScaleLateral.minimum(-180).maximum(180);
xScaleLateral.ticks().interval(90);
polarLateralImage.xScale(xScaleLateral);
Line polarSeriesLine = polarLateralImage.line(dataLateral);
polarSeriesLine.closed(false).markers(true);
polarSeriesLine.markers().size(3);
polarLateralImage.autoRedraw(true);
anyChartViewLateral.setChart(polarLateralImage);
polarLateralImage.saveAsPng(400,400,0.3,"testImage.png");
Could anyone tell me what am I missing or what amb I doing wrong? I know I might be asking too much, but if it were possible, I would be happy if someone could provide a code snippet that works.
Thank you very much!
Unfortunately, the current version of the AnyChart Android native library doesn't support exporting features, it was no implemented yet.

Convert Android view to PDF of A4 size

I have an android resume building application. I want to generate a PDF of size A4 from my view. Here's how my layout looks like - At the top I have a Top App Bar, and the whole view in encapsulated in drawer. The main part which contains user's details is encapsulated in nestedScrollView, which contains multiple LinearLayout and TextView. In this screenshot below, I have populated it with mock data, but in actuality, I am fetching data from the Firebase Realtime Database and displaying it on the UI.
I tried to understand iTextPdf solution and multiple question of similar type that has been asked here, but I couldn't find something solid. Please help me out, it would be of great help.
Also, please don't close this question by giving a reason that the question doesn't contain any code. It doesn't because I don't have any. I am trying to solve this problem from scratch. I have tried to describe my problem as much as I could.
try this:
create a WebView and copy the text of your edittext in it:
webview.loadData(youredittext.gettext().tostring, "text/html", "UTF-8");
and convert webview to pdf by below function:
private void createWebPrintJob(WebView webView) {
PrintManager printManager = (PrintManager) this
.getSystemService(Context.PRINT_SERVICE);
PrintDocumentAdapter printAdapter =
webView.createPrintDocumentAdapter();
String jobName = getString(R.string.app_name) + " Print Test";
if (printManager != null) {
printManager.print(jobName, printAdapter,
new PrintAttributes.Builder().build());
}
}
after that user can select page size for example A4
There are a lot of libraries that convert layouts to PDF, but let's opt for popular one so we could find answers if we're stuck.
The libraries I listed works like so : They take screenshot of your layout as bitmap image and convert it to pdf.
- 1st solution: iTextPDF https://github.com/itext/itext7 (New Version).
check this detailed tutorial which treates also the case of taking screenshot of a scrollview https://www.codeproject.com/Articles/989236/How-to-Convert-Android-View-to-PDF-2
and this stackoverflow answer https://stackoverflow.com/a/29731275/12802591
- 2nd solution: PdfMyXML library https://github.com/HendrixString/Android-PdfMyXml just follow the steps in the documentation.
They may be other solutions, but these are the popular ones.
Let Me know if it works for you and also if you're stuck. Thank you!

How to add title and content after Facebook deprecation?

Here's some code that successfully shares a link to Facebook after a button click:
public void onClick(View view) {
if (ShareDialog.canShow(ShareLinkContent.class)) {
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentTitle("A title")
.setContentDescription("Some description.")
.setContentUrl(Uri.parse("www.website.com"))
.build();
shareDialog.show(linkContent);
}
}
Using Android Studio, the ".setContentTitle" and ".setContentDescription" are deprecated, with a line through them. When I post the link, it is shared without the title and description. I assume this is because they are deprecated.
How could I add a title and description in? What were the deprecated terms replaced with? This isn't pre-filling a a post, and it wouldn't make sense for Facebook to get rid of these features completely. I have tried a few different links as the URL, none made a difference to this issue.
Many thanks in advance.
Edit: Please note that meta tags aren't an option, because if I were to link to an app in the Google Play Store, I can't control what tags the page has. I am looking to provide a title/description from the app, as was previously possible using the deprecated features mentioned.
I have found a suitable way around this, though not one that specifically replaces title and description. Another way to automatically add text to a post without pre-filling the user's text box is to use .setQuote().
For example with the code I provided above:
public void onClick(View view) {
if (ShareDialog.canShow(ShareLinkContent.class)) {
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setQuote("This may be used to replace setTitle and setDescription.")
.setContentUrl(Uri.parse("www.website.com"))
.build();
shareDialog.show(linkContent);
}
}
If anyone knows a way to replace the deprecated functions properly, without such a different alternative like the one I just provided, please post it and I'll mark it as solved.
Many thanks.
You can use ShareOpenGraphContent that uses ShareOpenGraphAction and ShareOpenGraphObject.
Look at the code I answered in this question.
https://stackoverflow.com/a/46459350/4107421
That way you can add a title, description and even an image to your post.
It works for ShareDialog.show() but unfortunately on my experience it doesn't on MessageDialog.show()

Subject Region Estimation using OpenImaj Library

I came across functions in the OpenImaj library (LuoTangSubjectRegion and Achanta Saliency) that I would love to use them , however the problem is that Java is far from my first language. Therefore I wanted to ask if somebody could help me with trying to implement a simple piece of code that would read in an image, compute its saliency map and save that saliency map?
Cheers.
Here is sample. I am not sure it works, but i suspect it is closer than what you have.
I am not a maven expert. Apparently, you need maven to download the library. http://openimaj.org/UseLibrary.html. Sadly, this means I can't test this sample.
Good luck, for more code samples see http://openimaj.org/tutorial/processing-your-first-image.html.
import org.openimaj.image.MBFImage;
import org.openimaj.image.FImage;
//You will need several more imports. Your IDE can handle that.
public class SampleImage {
public static Main(String args[])
{
//Read image in
MBFImage image = ImageUtilities.readMBF(new File("c:\\file.jpg"));
//Print out random information
System.out.println(image.colourSpace);
//Create Object to preform work.
AchantaSaliency test = new AchantaSaliency();
//Get Saliency Map
test.analyseImage(image);
FImage newImage = test.getSaliencyMap();
//Display original image
DisplayUtilities.displayImage(image);
//Display new image
DisplayUtilities.displayImage(newImage);
//Save new image to file
ImageUtilities.write(newImage, new File("C:\\test_output.jpg"));
}
}

Android Emoticons Implementation

Hello everyone ,
I am developing an application which required implementation of emoticons ( smiley). I can replace specific strings with drawable but it would be very time consuming. Is there any we to use system built in emoticons or some library to shorten my work? What I want is when I send text like this :) , the receiver get emoticon. Or when I send an emoticon he will get the same. Getting android system emoticons can help me too much.Your help would be great favor for me. Thanks
Emoji is a list of unicode emoticons which has a github that can implement emoticons into code (Found here).
From there you could use regex(\ue415\ue056\ue057) to find them or build them by char array (below).
Example:
StringBuilder sb = new StringBuilder();
for (char curr : str.toCharArray()) {
sb.append((SUPPORTED_EMOJI_SET.contains(curr)) ? convertCharToImgTag(curr) : curr);
}
where SUPPORTED_EMOJI_SET is just a set of chars, for example:
new HashSet<Character>() {{
add('\ue415');
add('\ue056');
...
}}
For more ideas: go here!

Categories