[GUIDE] How to control mod from other app - Android General

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

Related

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.

HELP - Image Gallery In gridview to display images from spicifc folder on sdcard

I have done a lot of searching and I have come up with this code to try and display images that are located in a Folder on my SDCard. The folder is located at /.data/ToDo/.nomedia/ (I am trying to hide this images from the Main Android Gallery) The Code seems to run fine, i don't get any errors, but it's just not displaying the images. I was hoping someone could tell me what I am missing. Any Help would be greatly appreciated!!
Here is my GalleryActivity
Code:
import java.io.File;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.AdapterView.OnItemClickListener;
public class GalleryActivity extends Activity {
/** Called when the activity is first created. */
private Cursor imagecursor, actualimagecursor, cursor;
private int image_column_index, actual_image_column_index;
File sdCardDir = Environment.getExternalStorageDirectory(); //SDCard Location
String imagesDir = ("sdCardDir" + "/.data/ToDo/.nomedia/"); //Path to Images
GridView imagegrid;
private int count;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gallery);
init_phone_image_grid();
}
private void init_phone_image_grid() {
String[] img = { MediaStore.Images.Media._ID };
imagecursor = managedQuery( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, img, MediaStore.Images.Media.DATA + " like ? ", new String[] {imagesDir}, null);
image_column_index = imagecursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID);
count = imagecursor.getCount();
imagegrid = (GridView) findViewById(R.id.sdcard);
imagegrid.setAdapter(new ImageAdapter(getApplicationContext()));
imagegrid.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,int position, long id) {
System.gc();
String[] proj = { MediaStore.Images.Media.DATA };
actualimagecursor = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, proj,null, null, null);
actual_image_column_index = actualimagecursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
actualimagecursor.moveToPosition(position);
String i = actualimagecursor.getString(actual_image_column_index);
System.gc();
Intent intent = new Intent(getApplicationContext(), GalleryFlow.class);
intent.putExtra("filename", i);
startActivity(intent);
}
});
}
public class ImageAdapter extends BaseAdapter {
private Context mContext;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return count;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position,View convertView,ViewGroup parent) {
System.gc();
ImageView i = new ImageView(mContext.getApplicationContext());
if (convertView == null) {
imagecursor.moveToPosition(position);
int id = imagecursor.getInt(image_column_index);
int imageID = 0;
Uri uri = Uri.withAppendedPath( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, Integer.toString(imageID) );
String url = uri.toString();
// Set the content of the image based on the image URI
int originalImageId = Integer.parseInt(url.substring(url.lastIndexOf("/") + 1, url.length()));
Bitmap b = MediaStore.Images.Thumbnails.getThumbnail(getContentResolver(), originalImageId, MediaStore.Images.Thumbnails.MINI_KIND, null);
//i.setImageURI(Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, Integer.toString(imageID)));
i.setImageBitmap(b);
i.setLayoutParams(new Gallery.LayoutParams(150, 100));
i.setScaleType(ImageView.ScaleType.FIT_XY);
}
else {
i = (ImageView) convertView;
}
return i;
}
}
}

[Q] Building Nyandroid + platlogo into an app

I've been hacking away at a few java files (PlatlogoActivity.java, Nyandroid.java) extracted from AOSP ICS source in Eclipse. There were some errors that I was able to solve (some funky ones about vibration, but I just removed all code related to vibration instead) but now there is one error, that no matter what, I can't solve. In the Nyandroid.java, I keep on getting the error "Cannot cast from TimeAnimator to ValueAnimator" on the line "((ValueAnimator) mAnim).cancel();" no matter how much I try changing that line (for example to "mAnim.cancel();") based on some custom ROM sources that I've looked through, and some stackoverflow questions. The app source is attached to this post, and below you can find the Nyandroid.java if you're willing to help - please do. I want to get into app developing for Android, or atleast understanding some java. I managed to port the Gingerbread platlogo for all Android versions but it's obviously much easier to do because it's just one still image and a toast. But I really want to port the ICS Nyandroid easter egg, for some practice with java.
/*);
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.nyandroid;
import android.animation.AnimatorSet;
import android.animation.PropertyValuesHolder;
import android.animation.ObjectAnimator;
import android.animation.TimeAnimator;
import android.animation.ValueAnimator;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.RectF;
import android.os.Handler;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Pair;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.ImageView;
import java.util.HashMap;
import java.util.Random;
public class Nyandroid extends Activity {
final static boolean DEBUG = false;
public static class Board extends FrameLayout
{
public static final boolean FIXED_STARS = true;
public static final int NUM_CATS = 20;
static Random sRNG = new Random();
static float lerp(float a, float b, float f) {
return (b-a)*f + a;
}
static float randfrange(float a, float b) {
return lerp(a, b, sRNG.nextFloat());
}
static int randsign() {
return sRNG.nextBoolean() ? 1 : -1;
}
static <E> E pick(E[] array) {
if (array.length == 0) return null;
return array[sRNG.nextInt(array.length)];
}
public class FlyingCat extends ImageView {
public static final float VMAX = 1000.0f;
public static final float VMIN = 100.0f;
public float v, vr;
public float dist;
public float z;
public ComponentName component;
public FlyingCat(Context context, AttributeSet as) {
super(context, as);
setImageResource(R.drawable.nyandroid_anim); // @@@
if (DEBUG) setBackgroundColor(0x80FF0000);
}
public String toString() {
return String.format("<cat (%.1f, %.1f) (%d x %d)>",
getX(), getY(), getWidth(), getHeight());
}
public void reset() {
final float scale = lerp(0.1f,2f,z);
setScaleX(scale); setScaleY(scale);
setX(-scale*getWidth()+1);
setY(randfrange(0, Board.this.getHeight()-scale*getHeight()));
v = lerp(VMIN, VMAX, z);
dist = 0;
// android.util.Log.d("Nyandroid", "reset cat: " + this);
}
public void update(float dt) {
dist += v * dt;
setX(getX() + v * dt);
}
}
TimeAnimator mAnim;
public Board(Context context, AttributeSet as) {
super(context, as);
setLayerType(View.LAYER_TYPE_HARDWARE, null);
setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
setBackgroundColor(0xFF003366);
}
private void reset() {
// android.util.Log.d("Nyandroid", "board reset");
removeAllViews();
final ViewGroup.LayoutParams wrap = new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
if (FIXED_STARS) {
for(int i=0; i<20; i++) {
ImageView fixedStar = new ImageView(getContext(), null);
if (DEBUG) fixedStar.setBackgroundColor(0x8000FF80);
fixedStar.setImageResource(R.drawable.star_anim); // @@@
addView(fixedStar, wrap);
final float scale = randfrange(0.1f, 1f);
fixedStar.setScaleX(scale); fixedStar.setScaleY(scale);
fixedStar.setX(randfrange(0, getWidth()));
fixedStar.setY(randfrange(0, getHeight()));
final AnimationDrawable anim = (AnimationDrawable) fixedStar.getDrawable();
postDelayed(new Runnable() {
public void run() {
anim.start();
}}, (int) randfrange(0, 1000));
}
}
for(int i=0; i<NUM_CATS; i++) {
FlyingCat nv = new FlyingCat(getContext(), null);
addView(nv, wrap);
nv.z = ((float)i/NUM_CATS);
nv.z *= nv.z;
nv.reset();
nv.setX(randfrange(0,Board.this.getWidth()));
final AnimationDrawable anim = (AnimationDrawable) nv.getDrawable();
postDelayed(new Runnable() {
public void run() {
anim.start();
}}, (int) randfrange(0, 1000));
}
if (mAnim != null) {
((ValueAnimator) mAnim).cancel();
}
mAnim = new TimeAnimator();
mAnim.setTimeListener(new TimeAnimator.TimeListener() {
public void onTimeUpdate(TimeAnimator animation, long totalTime, long deltaTime) {
// setRotation(totalTime * 0.01f); // not as cool as you would think
// android.util.Log.d("Nyandroid", "t=" + totalTime);
for (int i=0; i<getChildCount(); i++) {
View v = getChildAt(i);
if (!(v instanceof FlyingCat)) continue;
FlyingCat nv = (FlyingCat) v;
nv.update(deltaTime / 1000f);
final float catWidth = nv.getWidth() * nv.getScaleX();
final float catHeight = nv.getHeight() * nv.getScaleY();
if ( nv.getX() + catWidth < -2
|| nv.getX() > getWidth() + 2
|| nv.getY() + catHeight < -2
|| nv.getY() > getHeight() + 2)
{
nv.reset();
}
}
}
});
}
@Override
protected void onSizeChanged (int w, int h, int oldw, int oldh) {
super.onSizeChanged(w,h,oldw,oldh);
// android.util.Log.d("Nyandroid", "resized: " + w + "x" + h);
post(new Runnable() { public void run() {
reset();
mAnim.start();
} });
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
mAnim.cancel();
}
@Override
public boolean isOpaque() {
return true;
}
}
private Board mBoard;
@Override
public void onStart() {
super.onStart();
getWindow().addFlags(
WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
);
}
@Override
public void onResume() {
super.onResume();
mBoard = new Board(this, null);
setContentView(mBoard);
mBoard.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int vis) {
if (0 == (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION)) {
Nyandroid.this.finish();
}
}
});
}
@Override
public void onUserInteraction() {
// android.util.Log.d("Nyandroid", "finishing on user interaction");
finish();
}
}
Click to expand...
Click to collapse

[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] AutomateIt Plug-in Development

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).

Categories

Resources