I am making a Xposed Module that would allow users to modify the message displayed on the lock screen when Wrong pattern, pin or password is entered.
I am following this tutorial.
After digging into the android source code on GitHub, I found out the method that displays the message on the lock screen, that was onPatternChecked() in the class com.android.keyguard.KeyguardPatternView.java. The method uses the kg_wrong_pattern string resource which has the value Wrong Pattern when wrong pattern is drawn.
This is how my class looks like:-
package com.batrashubham.customlockscreenerrormessage;
import android.content.res.XResources;
import de.robv.android.xposed.IXposedHookInitPackageResources;
import de.robv.android.xposed.IXposedHookZygoteInit;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.callbacks.XC_InitPackageResources;
/**
* Created by shubham on 19/7/16.
*/
public class CustomErrorMessage implements IXposedHookInitPackageResources,IXposedHookZygoteInit {
#Override
public void initZygote(StartupParam startupParam) throws Throwable {
XResources.setSystemWideReplacement("android","bool","config_unplugTurnsOnScreen",false);
}
#Override
public void handleInitPackageResources(XC_InitPackageResources.InitPackageResourcesParam resparam) throws Throwable {
if(!resparam.packageName.equals("com.android.keyguard")){
return;
}
XposedBridge.log("I just got into your lock screen");
resparam.res.setReplacement("com.android.keyguard", "string", "kg_wrong_pattern", "Nice try.!!");
}
}
The module is showing up in the Xposed Installer app and is successful activated, but still the original message is showing up on the lock screen when I draw a wrong pattern.
I am currently testing it on Android 6.0.1 (CyanogenMod 13).
What am I doing wrong?
Related
So in my server /me is an enabled command. I wanted to disable this because I don't want people to be able to do this.
I'm learning java, so I decided to code something that disabled /me myself.
So I wrote the following code:
package com.ste999.disableme;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.event.player.AsyncPlayerChatEvent;
public class Main extends JavaPlugin implements Listener
#Override
public void onEnable() {
getLogger().info("disable me enabled");
PluginManager pm = this.getServer().getPluginManager();
pm.registerEvents(this, (this));
}
#Override
public void onDisable() {
getLogger().info("disable me disabled");
}
#EventHandler
public void OnMe(AsyncPlayerChatEvent event)
{
Player p = event.getPlayer();
if(!p.hasPermission("ste999.me")) {
if (event.getMessage().startsWith("/me")) {
event.setCancelled(true);
p.sendMessage("§4Dont me me!");
}
}
}
}
with the following plugin.yml file:
name: Disable_Me
main: com.ste999.disableme.Main
version: 1.0
load: startup
description: this is should disable me
commands:
Now if someone without op would run /me hello it shouldn't output to the chat and the user should get a message like Dont me me!
But it doesn't. the user is still able to do /me hello without op and the code should prevent that
As I'm fairly new to java this error is probably easy to find, and any help would be much appreciated.
The problem is that AsyncPlayerChatEvent only gets called when actually typing chat messages (not commands). For commands you have to use PlayerCommandPreprocessEvent as wonderfully explained by Mischa in the comments. Changing the event will make it work:
#EventHandler
public void disableMeCommand(PlayerCommandPreprocessEvent event) {
Player p = event.getPlayer();
if(!p.hasPermission("ste999.me")) {
if(event.getMessage().startsWith("/me")) {
event.setCancelled(true);
p.sendMessage("§4Dont me me!");
}
}
}
However, note that PlayerCommandPreprocessEvent should be avoided. Luckily there is another way to disable a command completely in a bukkit server. You should have a commands.yml file located in your server folder. Simply add the "me" alias and set it to null inside the file:
aliases:
me:
- null
I'm trying to get a groovy / griffon project to prompt a user before closing the main window. There are numerous examples of this on the web and it seems pretty straightforward: set defaultCloseOperation to DO_NOTHING_ON_CLOSE and then skip the application.shutdown() call.
When I try this, however, the window is still destroyed. I'm new to griffon and this is not my project, so there may be other things I'm missing and was hoping you experts could help.
Below is the beginning of the view creation code:
#ArtifactProviderFor(GriffonView)
class TceView {
JFrame mainFrame
...
masterPage = builder.with {
def masterApp = application(size: [890, 700], id: 'mainWindow',minimumSize: [890, 700],//[890, 700]
title: application.configuration['application.title'] + " " + Launcher.version,
iconImage: imageIcon('/tce_1.png').image,
iconImages: [imageIcon('/tce_1.png').image,
imageIcon('/tce_1.png').image,
imageIcon('/tce_1.png').image],
defaultCloseOperation: WindowConstants.DO_NOTHING_ON_CLOSE,
windowClosing: { evt ->
mainFrame = evt.source
println("In windowClosing")
// The below is to check to see if our frame is invisible or destroyed.
// It turns out that mainFrame is undefined when the timer ticks.
def timer = new Timer(5000, new ActionListener() {
#Override
void actionPerformed(ActionEvent e) {
mainFrame.setVisible(true)
}
})
timer.start()
if (false)
application.shutdown()
}) {
// all the other code
}
}
In the above code, if I set the application.shutdown() to run, the program terminates when the 'x' is pressed in the upper right of the window. If the application.shutdown() is skipped, the window closes, but the program is still running when the 'x' is pressed.
Thanks in advance for any help you can provide!
One way to solve this is to use a ShutdownHandler as shown at https://github.com/aalmiray/griffon-examples/tree/master/shutdown
That particular example uses JavaFX and Java but the base code can be translated to Swing and Groovy.
The first thing is to define an implementation of the ShutdownHandler interface like this one
package org.kordamp.griffon.examples.shutdown;
import griffon.core.GriffonApplication;
import griffon.core.ShutdownHandler;
import griffon.core.i18n.MessageSource;
import griffon.core.threading.UIThreadManager;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javax.annotation.Nonnull;
import javax.inject.Inject;
import javax.inject.Named;
public class MyShutdownHandler implements ShutdownHandler {
private final MessageSource messageSource;
private final UIThreadManager uiThreadManager;
#Inject
public MyShutdownHandler(#Nonnull #Named("applicationMessageSource") MessageSource messageSource, #Nonnull UIThreadManager uiThreadManager) {
this.messageSource = messageSource;
this.uiThreadManager = uiThreadManager;
}
#Override
public boolean canShutdown(#Nonnull GriffonApplication application) {
return uiThreadManager.runInsideUISync(() -> {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle(msg(".alert.title"));
alert.setHeaderText(msg(".alert.header"));
alert.setContentText(msg(".alert.content"));
return alert.showAndWait().orElse(ButtonType.CANCEL) != ButtonType.CANCEL;
});
}
private String msg(String key) {
return messageSource.getMessage(getClass().getName() + key);
}
#Override
public void onShutdown(#Nonnull GriffonApplication application) {
System.out.println("Saving workspace ...");
}
}
The ShutdownHandler interface defines 2 methods you must implement
canShutdown() returning true if the shutdown procedure can continue or false to stop it.
onShutdown() perform a particular cleanup when the shutdown procedure is executed.
In your case you my implement the first method with code similar to what you have in the windowClosing handler.
The last bit is registering this shutdown handler with the application, you can do this at anytime you have access to the application instance. You may do it in a controller, or an event handler, or a lifecycle script. The link shown earlier performa this registration using an event handler. Have a look at the ApplicationModule found in that example.
We are using the Ereza CustomActivityOnCrash library to handle unexpected issues with our android app. It's activity offers some debug output which we enable in develop and test builds but disable on production builds. In addition we want to log that information about crash details (log entries, stack trace, error details) in background.
CustomActivityOnCrash offers to call event listeners which sounds convenient. I wanted to implement the interface in our logging service, however I do not understand how I can access the existing information in the crash activity that way. Which puzzles me, cause isn't that a natural expectation?
Basically I need to access public methods of an android activity object from an event listener method that does not get handed over anything. How can I access that activity in the handler method? And how can I get the intent of the activity leading to the crash which is the argument the crash activity expects in those public methods it offers to access the existing information it offers? The examples given in the libraries documentation and those I could find on the internet are trivial, they only dump example strings, not the actual data collected by the library.
This all sounds counter intuitive to me. Which is why I think I generally miss something here. Maybe someone has a short hint for me to bring me on track again. Thanks!
Here is the basics of the LogService implementation I imagine:
...
import cat.ereza.customactivityoncrash.CustomActivityOnCrash;
...
public class LogService
implements CustomActivityOnCrash.EventListener {
private static LogService instance;
...
public void log(LogLevel level, String message) {
....
}
public void logCrashDetails(String activityLog, String stackTrace, String errorDetails) {
String message = String.format(
"--- CRASH REPORT ---\n\n-- Activity log:\n%s\n\n- Stack trace:\n%s\n\nError details:\n%s",
activityLog,
stackTrace,
errorDetails);
log(LogLevel.ERROR, message);
}
....
// CustomActivityOnCrash EventListener interface
#Override
public void onLaunchErrorActivity() {
log(LogLevel.INFO, "COAC: app crashed");
logCrashDetails(
// CustomActivityOnCrash.getActivityLogFromIntent(...some intent...),
// CustomActivityOnCrash.getStackTraceFromIntent(...some intent...),
// CustomActivityOnCrash.getAllErrorDetailsFromIntent(...some intent...)
);
}
#Override
public void onRestartAppFromErrorActivity() {
log(LogLevel.INFO, "COAC: app restarted");
}
#Override
public void onCloseAppFromErrorActivity() {
log(LogLevel.INFO, "COAC: app closed");
}
}
I am trying to do a simple translator by NetBeans. Firstly, I tried to implement the code below from a forum page:(https://www.java-forums.org/java-applets/38563-language-translation.html)
import com.google.api.translate.Language;
import com.google.api.translate.Translate;
public class Main {
public static void main(String[] args) throws Exception {
// Set the HTTP referrer to your website address.
Translate.setHttpReferrer("http://code.google.com/p/google-api-translate-java");
String translatedText = Translate.execute("Bonjour monde le",
Language.FRENCH, Language.ENGLISH);
System.out.println(translatedText);
}
}
I cannot compile the code. I got cannot resolve symbol for setHttpReferrer() although I added related jar.
Secondly, I tried to implement another solution from the page (https://www.java-forums.org/java-applets/61655-language-translation-using-google-api.html). I got my API key and set it.
import com.google.api.GoogleAPI;
import com.google.api.translate.Language;
import com.google.api.translate.Translate;
public class Translation
{
public static void main(String[] args) throws Exception {
GoogleAPI.setHttpReferrer("http://code.google.com/p/google-api-translate-java");
GoogleAPI.setKey("i have set my Api key");
String translatedText = Translate.DEFAULT.execute("Bonjour le monde", Language.FRENCH, Language.ENGLISH);
System.out.println(translatedText);
}
}
When I try to run this I got 403 error as null. Is there a simple way to call Google Translator from Java application?
403 error is documented on the faq as "exceeding your quota". https://cloud.google.com/translate/faq
I suspect however, you get the error because you haven't initialised the API properly, i.e authenticated, ...
Have a look at the setup in this code. Also search for hello welt.
https://github.com/GoogleCloudPlatform/google-cloud-java/blob/master/google-cloud-translate/src/test/java/com/google/cloud/translate/TranslateImplTest.java
Hope this helps.
I posted this earlier, but it wasn't quite up to par with stackoverflow standards. I cleaned up the code and articulated my question a bit more, so here goes:
I'm making a two player asteroids game in an applet for a CS1 project. I'm trying to figure out how to implement sound effects using methods I can call at certain times. I found this tutorial (http://www.dreamincode.net/forums/topic/14083-incredibly-easy-way-to-play-sounds/) on doing just that, but I'm having some trouble with the nested loop syntax.
How do I construct the 'Sound' object within the Sound class from a different class (in my case, AsteroidsGame.java) ?
Because of the messiness of the tutorial code, here's mine for improved readability.
//Import Statements
import java.applet.*;
import javax.swing.*;
import java.io.*;
import java.net.*;
public class Audioapp extends JApplet
{
public class Sound // Holds one audio file
{
private AudioClip song; // Sound player
private URL songPath; // Sound path
Sound(String filename)
{
try
{
songPath = new URL(getCodeBase(),filename); // Get the Sound URL
song = Applet.newAudioClip(songPath); // Load the Sound
}
catch(Exception e){} // Satisfy the catch
}
//Loops audio file
public void playSound()
{
song.loop();
}
//Stops audio file
public void stopSound()
{
song.stop();
}
//Plays audio file once
public void playSoundOnce()
{
song.play();
}
} //Closes Sound()
public void init()
{
Sound testsong = new Sound("song.mid");
testsong.playSound();
}
} //Closes Audioapp()
Edit 1: Just remembered someone from the last thread suggested I post what this does when I compile/run it. This .java on it's own does nothing; but it does indeed compile without errors when placed with the rest of my project.
Edit 2: Thanks a lot Zim-Zam for all your help, if anyone finds this thread and has the same issue, please consult his comments.
I recommend that you change your inner class to public static class Sound - this will let you construct instances of the class without needing an instance of Audioapp.
Then, to create an instance of Sound, you simply treat it as though its name were Audioapp.Sound, e.g. Audioapp.Sound sound = new Audioapp.Sound()
If the inner class isn't static, then you would use Audioapp.Sound sound = audioApp.new Sound(), where audioapp is an instance of Audioapp