Excuse me…. Can we make toogle with LLX script? something like vibrateSilent-Ring toogle? < SOLVED >
Excuse me…. Can we make toogle with LLX script? something like vibrateSilent-Ring toogle? < SOLVED >
#toogle
]]>
< ![CDATA[
LL.bindClass(“android.media.AudioManager”);
LL.bindClass(“android.app.AlertDialog”);
LL.bindClass(“android.content.DialogInterface”);
var state = LL.getContext().getSystemService(LL.getContext().AUDIO_SERVICE);
var adb = new AlertDialog.Builder(LL.getContext());
adb.setTitle(“Profile”);
adb.setCancelable(true);
adb.setNegativeButton(“Silent”, new DialogInterface.OnClickListener(){
onClick:function(Dialog, id){
state.setRingerMode(AudioManager.RINGER_MODE_SILENT);
Android.makeNewToast(“Profile changed to Silent/Vibrate”, true).show();
}
});
adb.setPositiveButton(“Loud”, new DialogInterface.OnClickListener(){
onClick:function(Dialog, id){
state.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
Android.makeNewToast(“Profile changed to Loud”, true).show();
}
});
var a = adb.create();
adb.show();
]]>
< ![CDATA[
Thank you Jay M , I’ll try it 🙂
]]>
< ![CDATA[
Jay M It’s not “a.show()” at the end?
]]>
< ![CDATA[
Whoops never noticed that nice catch, it still works though for some reason :/
]]>
< ![CDATA[
Cool it works with adb.show(); or a.show();
I also disabled every bindClass statement and it still works.
I gotta feeling it might cause problems after a reboot though 🙂
Abednego JS change the last line to a.show();
]]>
< ![CDATA[
Jay M , I tried the script.. That show alert dialog to choose between LOUD and SILENT, but what I need is toogle (press to make phone SilentVibrate and press again to make phone RING / LOUD)
With Tasker I do something like this:
If ( %var_sound = 1)
then
{
if ( %VOLUME > 0);
then VIBRATE;
%var_sound to 0;
}
else
{
if ( %SILENT isSet )
then unset SILENT;
%var_sound to 1;
}
How build toogle with pure LLX script?
]]>
< ![CDATA[
Press silent again it should switch to vibrate.
I was gunna use 3 buttons Silent/Vibrate/Loud but when I got the mode it was telling me that vibrate and silent were both 0 and that loud was 2 so I couldn’t do anything.
On lolipop
]]>
< ![CDATA[
Yeah I actually wrote this for myself I flashed CM12 and there was no profiles toggle in the powermenu and I need them and I really like AlertDialogs for some reason.
]]>
< ![CDATA[
all LL.bindClass are needed only once ! then they are loaded in the js environnement.. In fact you only need to import them when LLX starts !! I tried to do a “class” loading system, but I don’t have time towork on…
]]>
< ![CDATA[
Jay M that’s really cool! You should add it the script repository.
]]>
< ![CDATA[
Aye could do, cheers 🙂
]]>
< ![CDATA[
Then Jay M what I learn from your script is I need these to make toogle widget VIBRATE-RING:
LL.bindClass(“android.media.AudioManager”);
var state = LL.getContext().getSystemService(LL.getContext().AUDIO_SERVICE);
state.setRingerMode(AudioManager.RINGER_MODE_SILENT);
Android.makeNewToast(“Profile changed to Silent/Vibrate”, true).show();
state.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
Android.makeNewToast(“Profile changed to Loud”, true).show();
Now…. how to make the toogle?
😀
if (RINGER_MODE_NORMAL) // How to get system audio status?
then state.setRingerMode(AudioManager.RINGER_MODE_SILENT);
else state.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
]]>
< ![CDATA[
IIRC to get the status i used var status = state.getRingerMode();
But like i said it was telling me that loud was 2 and vibrate and silent were both 0, but tbh I could of just did it wrong my skills/knowledge are very limited and I still find the Android documentation hard to understand.
]]>
< ![CDATA[
I see android documentation and find:
public static final int RINGER_MODE_VIBRATE
Ringer mode that will be silent and will vibrate. (This will cause the phone ringer to always vibrate, but the notification vibrate to only vibrate if set.)
Constant Value: 1 (0x00000001)
How about that? Constant value for VIBRATE is 1?
So the script will be:
LL.bindClass(“android.media.AudioManager”);
var state = LL.getContext().getSystemService(LL.getContext().AUDIO_SERVICE);
var ac = state.getRingerMode();
if (ac = 2) // Is this right for checking phone audio’s state?
{
state.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
}
else
{
state.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
}
]]>
< ![CDATA[
Try it, if it doesn’t work I’ll have another go at it when i wake up. Its 9am here and I ain’t been to sleep yet :/
]]>
< ![CDATA[
It’s WORKING!
XD
Thank you very much for your script Jay M I just adjust it to be more simple as I need, toogle to switch between “silent vibrate” to “normal” fixed.
My previous script have wrong if statement, this is the right script for VIBRATE-RING TOOGLE:
LL.bindClass(“android.media.AudioManager”);
var state = LL.getContext().getSystemService(LL.getContext().AUDIO_SERVICE);
var ac = state.getRingerMode();
if (ac == 2)
{
state.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
}
else
{
state.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
}
]]>
< ![CDATA[
Nice 🙂 glad it was helpfull yeah I see what happened you used if (ac = 2 ) and it should be if (ac == 2)
]]>
< ![CDATA[
Well I tried adding this to the wiki but the instructions confused me so it’s not happening lol.
Unless someone else wants to add it. I don’t need credit for it just wanna share it and as a bonus having it there in the wiki means I’ll never lose it, i lost my Quick Note script twice now 🙁 free storage FTW 😉
]]>
< ![CDATA[
Ugh, so LL have “Script Repository” and Wiki too
But I also didn’t know how to fill it… lol
XD
]]>