[GUIDE] AutomateIt Plug-in Development - Android Software/Hacking General [Developers Only]

Prerequisite
Don't know what is AutomateIt ? Read more on this thread.
What is AutomateIt Plugin ?
Plugins are applications that by installing them, you add new actions and triggers that you can use within AutomateIt. Sounds easy, right ?
Each plugin can provide additional triggers and actions that extend the capabilities of AutomateIt, so you can focus on the functionality and take advantage of the AutomateIt platform to connect each trigger or action with existing capabilities of AutomateIt or with other plugins.
More details and a list of available plugins are available on the app website.
Getting started
Although developing a plugin is super-easy and requires only several simple steps, you are deeply encouraged to read the full documentation on the app website.
To summarize it for you, here are the steps you need to follow when developing a new plugin:
Download AutomateIt Plugin SDK
Setup your environment
Develop your plugin
Test your plugin
Setting up your environment after downloading the plugin SDK is done by adding a single dependency needs to be added to your build.gradle file:
Code:
compile 'com.automateitapp:automateit.plugin.sdk:1.0.3'
Creating a new plugin action or trigger is done by implementing a class that extends either PluginAction or PluginTrigger in your plugin project that references the AutomateItPluginLibrary.
Each of these abstract classes requires a set of simple functions to be implemented that provide metadata for the action or trigger (such as title, description, icons and parameters) and the functionality of the action or trigger. See sample code below for an action that shows a Toast message.
a complete sample app is available as a git repo that can be cloned from here.
When the plugin app is installed on a user device, it communicates with AutomateIt so that the plugin actions and triggers become available within AutomateIt.
Additional Documentation
AutomateIt Plugin Developer Guide
AutomateIt Plugin SDK Reference
Looking forward to seeing some awesome plugins !
Sample Action Code
Code:
package com.smarterapps.demoplugin.actions;
import java.util.List;
import android.content.Context;
import android.widget.Toast;
import com.smarterapps.automateitplugin.sdk.PluginDataFieldCollection;
import com.smarterapps.automateitplugin.sdk.PluginValidationResult;
import com.smarterapps.automateitplugin.sdk.RequiredApp;
import com.smarterapps.automateitplugin.sdk.fields.PluginDataFieldBoolean;
import com.smarterapps.automateitplugin.sdk.fields.PluginDataFieldString;
import com.smarterapps.demoplugin.R;
public class Action1 extends com.smarterapps.automateitplugin.sdk.PluginAction
{
private static final int FIELD_ID_TEXT_TO_SHOW = 1;
private static final int FIELD_ID_DURATION_LONG = 2;
@Override
public String getActionTitle(Context context)
{
return context.getString(R.string.action1_title);
}
@Override
public String getActionDescription(Context context)
{
return context.getString(R.string.action1_default_description);
}
@Override
public String getActionDescription(Context context, PluginDataFieldCollection data)
{
if (null != data)
{
String msgText = (String) data.getFieldById(FIELD_ID_TEXT_TO_SHOW).getValue();
boolean durationLong = (Boolean) data.getFieldById(FIELD_ID_DURATION_LONG).getValue();
int toastDurationStringId = durationLong ? R.string.duration_long: R.string.duration_short;
return context.getString(R.string.action1_description,
context.getString(toastDurationStringId),
msgText);
}
return getActionDescription(context);
}
@Override
public int getActionIconResourceId()
{
return R.drawable.ic_action1;
}
@Override
public int getActionSmallIconResourceId()
{
return R.drawable.ic_action1_small;
}
@Override
public PluginDataFieldCollection getActionFields(Context context)
{
PluginDataFieldCollection retval = new PluginDataFieldCollection();
retval.add(new PluginDataFieldBoolean(
FIELD_ID_DURATION_LONG,
context.getString(R.string.action1_field_duration_title),
context.getString(R.string.action1_field_duration_description),
true));
retval.add(new PluginDataFieldString(
FIELD_ID_TEXT_TO_SHOW,
context.getString(R.string.action1_field_msg_title),
context.getString(R.string.action1_field_msg_description),
""));
return retval;
}
@Override
public void doAction(Context context, PluginDataFieldCollection data)
{
boolean durationLong = (Boolean) data.getFieldById(FIELD_ID_DURATION_LONG).getValue();
int toastDuration = durationLong ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT;
String toastMsg = (String) data.getFieldById(FIELD_ID_TEXT_TO_SHOW).getValue();
Toast.makeText(context, toastMsg, toastDuration).show();
}
@Override
public PluginValidationResult validateData(Context context, PluginDataFieldCollection data)
{
// Validate action1
String toastMsg = (String) data.getFieldById(FIELD_ID_TEXT_TO_SHOW).getValue();
if (null == toastMsg || toastMsg.trim().length() == 0)
{
return new PluginValidationResult(false, "Toast message can't be empty");
}
return PluginValidationResult.getValidResult();
}
@Override
public List<RequiredApp> getRequiredApps()
{
return null;
}
}

AutomateIt Plugin SDK has been updated so it is now even easier to integrate actions and triggers into your apps, or build a brand new plugin.
It requires a single dependency in your build.gradle file and the rest is up to you!
Sample app is available as a git repo on bitbucket.org:
https://bitbucket.org/AutomateIt/automateit-plugin-demo
(Instructions were updated on the developer website and this post).

Related

Exception during setContentView

Hi guys,
I am writing a program which has to display content provided by a web platform. Therefore, I split the program up into four classes. The "Main" class (Activity) just initializes the Controller "AppScheduler" (Intent) which then initializes the "PlatformConnector" (Service) and the "UI" (Activity).
Since I am a newbie in programming apps for Adroid, I am having trouble with getting setup a view in the UI. In case I define a view there, the app returns an exception. Does anyone of you knows what I am doing wrong?
Main Class:
public class Main extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AppScheduler controller = new AppScheduler(this);
controller.Initialize();
// everything else happens in AppScheduler class
}
}
-------------------------
AppScheduler Class:
public class AppScheduler extends Intent {
// PLATFORM CONNECTOR ATTRIBUTES
protected PlatformConnector pfconnect = null;
// VIEW ATTRIBUTES
protected UI uiMain = null;
// AppScheduler Constructor
public AppScheduler(Main main) {
// TODO Auto-generated constructor stub
}
public void Initialize (){
//initialize Web Service Connector
pfconnect = new PlatformConnector();
pfconnect.initialize();
// create and initalize GUI
uiMain = new UI();
uiMain.onCreate(null);
}
}
---------------------------
UI Class:
public class UI extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
The Error occurs in case I include "setContentView(R.layout.main);". Note: The main.xml exists and normally runs without any problems.
I don't know why you are using the Intent the way you are. It isn't intended to be used as a controller class base.
An intent is meant invoke an event in the system, and the system figures out the best way to handle it.
Oh and you are trying to instantiate an Activity class and show it; you aren't supposed to do that either. My guess is you haven't done any Android development yet. I recommend starting with the basics and the sample programs.
http://code.google.com/android/intro/hello-android.html

Android Developers: HelloGallery tutorial: "android.R.styleable cannot be resolved"

Android Developers: HelloGallery tutorial: "android.R.styleable cannot be resolved"
Hello,
I've been following the Views tutorials included in the android developer site:
http://developer.android.com/guide/t...o-gallery.html
When testing the "Hello Gallery" view, I get the compile-time error:
"android.R.styleable cannot be resolved"
I searched for this error on this group but is wasn't answered.
Can anyone help?
The problem reference occurs in the imageAdapter class that is appended after the onCreate() method in the HelloGallery class:
public class ImageAdapter extends BaseAdapter
{
...
TypedArray a = obtainStyledAttributes(android.R.styleable.Theme);
}
Strangely enough, when I insert this line into the onCreate() method at the start of the package, there is no problem. It seems that the android.R class is not known to this class.
Thanks,
Paul
any resolution to this issue?
I am running into the same issue and was wondring if you had found a resolution?
Thanks in advance,
-Nathan
tell me you know what is import
If it is what you mean, "import android.R.styleable" is not possible.
vincebodi said:
If it is what you mean, "import android.R.styleable" is not possible.
Click to expand...
Click to collapse
No, it's impossible. As I realized after I did that post, they changed the example codes in 1.5 SDK and broke some applications. If you lose "android." the code should compile.
I copied "ImageAdapter" Class into "HelloGallery" Class. And it's work.
Here is my code:
package com.example.hellogallery;
import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
public class HelloGallery extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Gallery g = (Gallery) findViewById(R.id.gallery);
g.setAdapter(new ImageAdapter(this));
g.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position,
long id) {
Toast.makeText(HelloGallery.this, "" + position,
Toast.LENGTH_SHORT).show();
}
});
}
public class ImageAdapter extends BaseAdapter {
int mGalleryItemBackground;
private Context mContext;
private Integer[] mImageIds = { R.drawable.sample_1, R.drawable.sample_2,
R.drawable.sample_3, R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7 };
public ImageAdapter(Context c) {
mContext = c;
TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);
mGalleryItemBackground = a.getResourceId(
R.styleable.Gallery1_android_galleryItemBackground, 0);
a.recycle();
}
public int getCount() {
return mImageIds.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView i = new ImageView(mContext);
i.setImageResource(mImageIds[position]);
i.setLayoutParams(new Gallery.LayoutParams(150, 100));
i.setScaleType(ImageView.ScaleType.FIT_XY);
i.setBackgroundResource(mGalleryItemBackground);
return i;
}
}
}
attrs.xml and obtainStyledAttributes
Thanks for the code tonghoho...I still had the same problem until I uploaded attrs.xml from the samples, following instructions here: http://www.mail-archive.com/[email protected]/msg34088.html . I used the same code above, but now I'm getting another error. Here's the part with the problem:
public ImageAdapter(Context c) {
mContext = c;
TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);
mGalleryItemBackground = a.getResourceId(
R.styleable.Gallery1_android_galleryItemBackground, 0);
a.recycle();
}
The error is for obtainStyledAttributes, and is:
The method obtainStyledAttributes(int[]) is undefined for the type ImageAdapter
Any ideas?
Thanks ahead of time...
@Collene: you probably have ImageAdapter in a separate file and not as an inner class of HelloGalery? obtainStyledAttributes() is a method of the Context class so you have to change the code like so:
public ImageAdapter(Context c) {
mContext = c;
TypedArray a = c.obtainStyledAttributes(R.styleable.default_gallery);
Complete solution can be found in this thread: http://www.mail-archive.com/[email protected]/msg11862.html
Thank you so much for your help David B. I can see now that the tutorial left off the letter "c" there, and eclipse, while awesome, wasn't really helping me out with diagnosing the problem.

Capturing Screenshots using background agent WP7.1

Hi, i am trying to write a application that can be used for streaming my phone to my windows desktop running a Java client to receive the images. However when i tried to create a background task following a tutorial by microsoft i am unable to access the UIElement. Does anyone know how to work around this?
the below code in the OnInvoke is able to run in a application however if i were to create it under a Task Agent project , i cant because i cant get the FrameElement.
Code:
using System.Windows;
using Microsoft.Phone.Scheduler;
using Microsoft.Phone.Shell;
using System;
namespace ScheduledTaskAgent1
{
public class ScheduledAgent : ScheduledTaskAgent
{
private static volatile bool _classInitialized;
/// <remarks>
/// ScheduledAgent constructor, initializes the UnhandledException handler
/// </remarks>
public ScheduledAgent()
{
if (!_classInitialized)
{
_classInitialized = true;
// Subscribe to the managed exception handler
Deployment.Current.Dispatcher.BeginInvoke(delegate
{
Application.Current.UnhandledException += ScheduledAgent_UnhandledException;
});
}
}
/// Code to execute on Unhandled Exceptions
private void ScheduledAgent_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
if (System.Diagnostics.Debugger.IsAttached)
{
// An unhandled exception has occurred; break into the debugger
System.Diagnostics.Debugger.Break();
}
}
protected override void OnInvoke(ScheduledTask task)
{
var timer = new System.Windows.Threading.DispatcherTimer
{
Interval = System.TimeSpan.FromSeconds(10)
};
timer.Tick += (sender, args) =>
{
Microsoft.Devices.VibrateController.Default.Start(
TimeSpan.FromSeconds(0.1));
var bitmap = new System.Windows.Media.Imaging.WriteableBitmap(this.Parent, null);
var stream = new System.IO.MemoryStream();
System.Windows.Media.Imaging.Extensions.SaveJpeg(bitmap, stream,
bitmap.PixelWidth, bitmap.PixelHeight, 0, 100);
stream.Position = 0;
var mediaLib = new Microsoft.Xna.Framework.Media.MediaLibrary();
var datetime = System.DateTime.Now;
var filename =
System.String.Format("Capture-{0}-{1}-{2}-{3}-{4}-{5}",
datetime.Year % 100, datetime.Month, datetime.Day,
datetime.Hour, datetime.Minute, datetime.Second);
mediaLib.SavePicture(filename, stream);
};
timer.Start();
// Call NotifyComplete to let the system know the agent is done working.
NotifyComplete();
}
}
}
kyrogue said:
i am unable to access the UIElement
Click to expand...
Click to collapse
Hmm... Background agents don't have UIElements at all (and by the sandbox concept you can't access anything not belong to your app).
To capture WP7 screen, you should have an interop-unlock phone and use DllImport library.
Interop-unlock is *not* required to use anything in DllImport, actually - normal dev-unlock works fine.
There actually used to be an app that did what you described (stream the screen contents to a PC in real-time) but I don't think it ever got updated to work on Mango.

[Q] WebView app opens up default browser.

Hello I am a Android newbie and I am currently learning how to code applications using Eclipse so I made one yesterday using webview on eclipse but everytime I open the app it takes me to the website but on my default browser. I want the website to open up in the app not on my browser. Anyone know how to fix this?
You need to read the WebView Reference on Android.
Apparently you open the website on a Intent, so the website is opened on the default browser.
Instead, you need to make you Activity act as a WebView on the 'onCreate()' :
Code:
WebView webview = new WebView(this);
setContentView(webview);
And then open the website :
Code:
// Simplest usage: note that an exception will NOT be thrown
// if there is an error loading this page (see below).
webview.loadUrl("my_url");
// OR, you can also load from an HTML string:
String summary = "<html><body>You scored <b>192</b> points.</body></html>";
webview.loadData(summary, "text/html", null);
// ... although note that there are restrictions on what this HTML can do.
// See the JavaDocs for loadData() and loadDataWithBaseURL() for more info.
Um this is my MainActivity.java
package com.graaltailor.JFA;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.webkit.WebView;
public class MainActivity extends Activity {
WebView mWebView;
/** Called when the activity is first created. */
@override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("examplewebsite");
}
}
You need to do something like this to overwrite urlredirect opened in the default browser :
Code:
package com.graaltailor.JFA;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.webkit.WebView;
public class MainActivity extends Activity {
WebView mWebView;
/** Called when the activity is first created. */
@override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("examplewebsite");
}
mWebView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url){
// do your handling codes here, which url is the requested url
// probably you need to open that url rather than redirect:
view.loadUrl(url);
return false; // then it is not handled by default action
}
});
}
I replaced the code with the one you replied with and I get a bunch of errors.
sorry I made a mistake in the code
Code:
package com.graaltailor.JFA;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.webkit.WebView;
public class MainActivity extends Activity {
WebView mWebView;
/** Called when the activity is first created. */
@override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("examplewebsite");
mWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
// do your handling codes here, which url is the requested url
// probably you need to open that url rather than redirect:
view.loadUrl(url);
return false; // then it is not handled by default action
}
});
}
}

[GUIDE] How to control mod from other app

Hello Guys I am Back with guide.Generally i am going to show how to control mod from other app i think you have seen in rom etc when we click show toggle it show toggle but when we click on disable toggle it disable toggle what is that how to do that let gonna do.Basically you should have basic android programming knowledge and how to make java into smali how to put it into the apk and debug.This guide i created because of @ShadeSK request so i created otherwise i wont . Okay Lets start.
Instruction
First of all create android project in your ide . Then make class which extends PreferenceActivity then make xml name setting then addPreferencesFromResource(id_to_xml) then make checkbox in the xml then populate the checkbox from the java class you can populate by
HTML:
CheckBoxPreference mClockColor = (ColorPickerPreference) findPreference(" in the xml which you have declared as key");
then make class FireSender and add content
HTML:
package com.androidfire;
import android.content.Context;
import android.content.Intent;
public class FireSender {
public static void mailTo(Context c,String id,boolean value) {
Intent intent = new Intent();
intent.setAction(id);
intent.putExtra(id,value);
c.sendBroadcast(intent);
}
}
then make another class named FireObserver add content
HTML:
/**
* AndroidFire 2015
* All files of AndroidFire are free to use reproduce utilise
* fork re use change package name and class name as you want
* (( but )) please give credit
*/
package com.androidfire;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import static android.content.SharedPreferences.*;
public class FireObserver {
/**
* Use this class as brain don't touch any file maybe FC or etc
*/
// Context must be passed other wise cant do anything
private Context mContext;
// Specific url for class
private String mSPECIFIC_URL;
// Required to get data from this
public BroadcastReceiver mBroadcastReceiver;
// Need to save data so we need it
public SharedPreferences mSPHelper;
// This is it status of that thing
private boolean mStatus;
/**
* Passed these parameter to this class otherwise it will wont work
* [user=955119]@param[/user] context set specific context
* [user=955119]@param[/user] Specific_url this means you have to set id like com.bla (This is most important thing
* you have to add unique for one mod)
* [user=955119]@param[/user] observerListener default value is this and implement it on the class
*/
public FireObserver(Context context,String Specific_url, final ObserverListener observerListener) {
setContext(context);
setSPECIFIC_URL(Specific_url);
mSPHelper = getContext().getSharedPreferences("AndroidFire",Context.MODE_PRIVATE);
mStatus = mSPHelper.getBoolean(Specific_url, true);
mSPHelper.registerOnSharedPreferenceChangeListener(new OnSharedPreferenceChangeListener() {
[user=439709]@override[/user]
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
mStatus = sharedPreferences.getBoolean(getSPECIFIC_URL(), true);
if (mStatus) {
observerListener.onEnabled();
}
else if (!mStatus) {
observerListener.onDisabled();
}
}
});
if (mStatus) {
observerListener.onEnabled();
}
else if (!mStatus) {
observerListener.onDisabled();
}
mBroadcastReceiver = new BroadcastReceiver() {
[user=439709]@override[/user]
public void onReceive(Context context, Intent intent) {
boolean status = intent.getBooleanExtra(getSPECIFIC_URL(),true);
mStatus = status;
SharedPreferences.Editor ed = mSPHelper.edit();
ed.putBoolean(getSPECIFIC_URL(),status);
ed.apply();
}
};
context.registerReceiver(mBroadcastReceiver,new IntentFilter(Specific_url));
}
public Context getContext() {
return mContext;
}
public void setContext(Context mContext) {
this.mContext = mContext;
}
public String getSPECIFIC_URL() {
return mSPECIFIC_URL;
}
public void setSPECIFIC_URL(String mSPECIFIC_URL) {
this.mSPECIFIC_URL = mSPECIFIC_URL;
}
public interface ObserverListener {
public void onEnabled();
public void onDisabled();
}
}
then in the mod class that you have prepare go to that class as in this i have TestText
then declare FireObserver as
HTML:
FireObserver fireObserver = new FireObserver(getContext(),"com.SimpleText",this);
getContext(); means you have to pass context
then com.SimpleText means the url you have to register according mod like com.androidfire.CLOCK_ON_STATUSBAR etc
this means you have to implement FireObserver.ObserverListener into class on the method onEnabled declare that what you want to do if the it is checked on the other hand onDisbaled is opposite in case of my i want change the visibility.
then go the main class where you have extend PreferanceActivity then
add
HTML:
if (Cb.isChecked()) {
FireSender.mailTo(getApplicationContext(),"com.SimpleText",true);
}
else {
FireSender.mailTo(getApplicationContext(),"com.SimpleText",false);
}
then compile it and attached to pulled out three smali mod one , FireSender and FireObserver then attached to the apk where you want to add then install apk that you have made and run the app you have modify and check does it work if does not work give me the source i will find your error
AndroidFire said:
Hello Guys I am Back with guide.Generally i am going to show how to control mod from other app i think you have seen in rom etc when we click show toggle it show toggle but when we click on disable toggle it disable toggle what is that how to do that let gonna do.Basically you should have basic android programming knowledge and how to make java into smali how to put it into the apk and debug.This guide i created because of @ShadeSK request so i created otherwise i wont . Okay Lets start.
Instruction
First of all create android project in your ide . Then make class which extends PreferenceActivity then make xml name setting then addPreferencesFromResource(id_to_xml) then make checkbox in the xml then populate the checkbox from the java class you can populate by
HTML:
CheckBoxPreference mClockColor = (ColorPickerPreference) findPreference(" in the xml which you have declared as key");
then make class FireSender and add content
HTML:
package com.androidfire;
import android.content.Context;
import android.content.Intent;
public class FireSender {
public static void mailTo(Context c,String id,boolean value) {
Intent intent = new Intent();
intent.setAction(id);
intent.putExtra(id,value);
c.sendBroadcast(intent);
}
}
then make another class named FireObserver add content
HTML:
/**
* AndroidFire 2015
* All files of AndroidFire are free to use reproduce utilise
* fork re use change package name and class name as you want
* (( but )) please give credit
*/
package com.androidfire;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import static android.content.SharedPreferences.*;
public class FireObserver {
/**
* Use this class as brain don't touch any file maybe FC or etc
*/
// Context must be passed other wise cant do anything
private Context mContext;
// Specific url for class
private String mSPECIFIC_URL;
// Required to get data from this
public BroadcastReceiver mBroadcastReceiver;
// Need to save data so we need it
public SharedPreferences mSPHelper;
// This is it status of that thing
private boolean mStatus;
/**
* Passed these parameter to this class otherwise it will wont work
* [user=955119]@param[/user] context set specific context
* [user=955119]@param[/user] Specific_url this means you have to set id like com.bla (This is most important thing
* you have to add unique for one mod)
* [user=955119]@param[/user] observerListener default value is this and implement it on the class
*/
public FireObserver(Context context,String Specific_url, final ObserverListener observerListener) {
setContext(context);
setSPECIFIC_URL(Specific_url);
mSPHelper = getContext().getSharedPreferences("AndroidFire",Context.MODE_PRIVATE);
mStatus = mSPHelper.getBoolean(Specific_url, true);
mSPHelper.registerOnSharedPreferenceChangeListener(new OnSharedPreferenceChangeListener() {
[user=439709]@override[/user]
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
mStatus = sharedPreferences.getBoolean(getSPECIFIC_URL(), true);
if (mStatus) {
observerListener.onEnabled();
}
else if (!mStatus) {
observerListener.onDisabled();
}
}
});
if (mStatus) {
observerListener.onEnabled();
}
else if (!mStatus) {
observerListener.onDisabled();
}
mBroadcastReceiver = new BroadcastReceiver() {
[user=439709]@override[/user]
public void onReceive(Context context, Intent intent) {
boolean status = intent.getBooleanExtra(getSPECIFIC_URL(),true);
mStatus = status;
SharedPreferences.Editor ed = mSPHelper.edit();
ed.putBoolean(getSPECIFIC_URL(),status);
ed.apply();
}
};
context.registerReceiver(mBroadcastReceiver,new IntentFilter(Specific_url));
}
public Context getContext() {
return mContext;
}
public void setContext(Context mContext) {
this.mContext = mContext;
}
public String getSPECIFIC_URL() {
return mSPECIFIC_URL;
}
public void setSPECIFIC_URL(String mSPECIFIC_URL) {
this.mSPECIFIC_URL = mSPECIFIC_URL;
}
public interface ObserverListener {
public void onEnabled();
public void onDisabled();
}
}
then in the mod class that you have prepare go to that class as in this i have TestText
then declare FireObserver as
HTML:
FireObserver fireObserver = new FireObserver(getContext(),"com.SimpleText",this);
getContext(); means you have to pass context
then com.SimpleText means the url you have to register according mod like com.androidfire.CLOCK_ON_STATUSBAR etc
this means you have to implement FireObserver.ObserverListener into class on the method onEnabled declare that what you want to do if the it is checked on the other hand onDisbaled is opposite in case of my i want change the visibility.
then go the main class where you have extend PreferanceActivity then
add
HTML:
if (Cb.isChecked()) {
FireSender.mailTo(getApplicationContext(),"com.SimpleText",true);
}
else {
FireSender.mailTo(getApplicationContext(),"com.SimpleText",false);
}
then compile it and attached to pulled out three smali mod one , FireSender and FireObserver then attached to the apk where you want to add then install apk that you have made and run the app you have modify and check does it work if does not work give me the source i will find your error
Click to expand...
Click to collapse
No words Bro Thanks alot

Categories

Resources