Skip to content

Commit

Permalink
Merge pull request Chainfire#8 from cernekee/missing-callbacks-v1
Browse files Browse the repository at this point in the history
Looks good to me
  • Loading branch information
Chainfire committed Jan 18, 2014
2 parents b1d6c24 + d3b07aa commit 6aab5ee
Show file tree
Hide file tree
Showing 8 changed files with 1,621 additions and 1,626 deletions.
158 changes: 79 additions & 79 deletions libsuperuser/src/eu/chainfire/libsuperuser/Application.java
Original file line number Diff line number Diff line change
@@ -1,79 +1,79 @@
/*
* Copyright (C) 2012-2013 Jorrit "Chainfire" Jongma
*
* 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 eu.chainfire.libsuperuser;

import android.content.Context;
import android.os.Handler;
import android.widget.Toast;

/**
* Base application class to extend from, solving some issues with
* toasts and AsyncTasks you are likely to run into
*/
public class Application extends android.app.Application {
/**
* Shows a toast message
*
* @param context Any context belonging to this application
* @param message The message to show
*/
public static void toast(Context context, String message) {
// this is a static method so it is easier to call,
// as the context checking and casting is done for you

if (context == null) return;

if (!(context instanceof Application)) {
context = context.getApplicationContext();
}

if (context instanceof Application) {
final Context c = context;
final String m = message;

((Application)context).runInApplicationThread(new Runnable() {
@Override
public void run() {
Toast.makeText(c, m, Toast.LENGTH_LONG).show();
}
});
}
}

private static Handler mApplicationHandler = new Handler();

/**
* Run a runnable in the main application thread
*
* @param r Runnable to run
*/
public void runInApplicationThread(Runnable r) {
mApplicationHandler.post(r);
}

@Override
public void onCreate() {
super.onCreate();

try {
// workaround bug in AsyncTask, can show up (for example) when you toast from a service
// this makes sure AsyncTask's internal handler is created from the right (main) thread
Class.forName("android.os.AsyncTask");
} catch (ClassNotFoundException e) {
}
}
}
/*
* Copyright (C) 2012-2013 Jorrit "Chainfire" Jongma
*
* 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 eu.chainfire.libsuperuser;

import android.content.Context;
import android.os.Handler;
import android.widget.Toast;

/**
* Base application class to extend from, solving some issues with
* toasts and AsyncTasks you are likely to run into
*/
public class Application extends android.app.Application {
/**
* Shows a toast message
*
* @param context Any context belonging to this application
* @param message The message to show
*/
public static void toast(Context context, String message) {
// this is a static method so it is easier to call,
// as the context checking and casting is done for you

if (context == null) return;

if (!(context instanceof Application)) {
context = context.getApplicationContext();
}

if (context instanceof Application) {
final Context c = context;
final String m = message;

((Application)context).runInApplicationThread(new Runnable() {
@Override
public void run() {
Toast.makeText(c, m, Toast.LENGTH_LONG).show();
}
});
}
}

private static Handler mApplicationHandler = new Handler();

/**
* Run a runnable in the main application thread
*
* @param r Runnable to run
*/
public void runInApplicationThread(Runnable r) {
mApplicationHandler.post(r);
}

@Override
public void onCreate() {
super.onCreate();

try {
// workaround bug in AsyncTask, can show up (for example) when you toast from a service
// this makes sure AsyncTask's internal handler is created from the right (main) thread
Class.forName("android.os.AsyncTask");
} catch (ClassNotFoundException e) {
}
}
}
Loading

0 comments on commit 6aab5ee

Please sign in to comment.