use of android.content.ContextWrapper in project kcanotify by antest1.
the class KcaUtils method getJsonArrayFromAsset.
public static JsonArray getJsonArrayFromAsset(Context context, String name, KcaDBHelper helper) {
ContextWrapper cw = new ContextWrapper(context);
JsonArray data = new JsonArray();
AssetManager am = cw.getAssets();
try {
AssetManager.AssetInputStream ais = (AssetManager.AssetInputStream) am.open(name);
byte[] bytes = ByteStreams.toByteArray(ais);
data = new JsonParser().parse(new String(bytes)).getAsJsonArray();
ais.close();
} catch (IOException e1) {
e1.printStackTrace();
if (helper != null)
helper.recordErrorLog(ERROR_TYPE_DATALOAD, name, "getJsonArrayFromStorage", "1", getStringFromException(e1));
}
return data;
}
use of android.content.ContextWrapper in project kcanotify by antest1.
the class KcaUtils method checkFairyImageInStorage.
public static boolean checkFairyImageInStorage(Context context, String name) {
ContextWrapper cw = new ContextWrapper(context);
File directory = cw.getDir("fairy", Context.MODE_PRIVATE);
File image = new File(directory, name);
return image.exists();
}
use of android.content.ContextWrapper in project kcanotify by antest1.
the class KcaUtils method validateResourceFiles.
public static boolean validateResourceFiles(Context context, KcaDBHelper helper) {
int count = 0;
ContextWrapper cw = new ContextWrapper(context);
File directory = cw.getDir("data", Context.MODE_PRIVATE);
for (final File entry : directory.listFiles()) {
try {
Reader reader = new FileReader(entry);
new JsonParser().parse(reader);
count += 1;
} catch (FileNotFoundException | IllegalStateException | JsonSyntaxException e) {
e.printStackTrace();
if (helper != null)
helper.recordErrorLog(ERROR_TYPE_DATALOAD, entry.getName(), "validateResourceFiles", "2", getStringFromException(e));
setPreferences(context, PREF_DATALOAD_ERROR_FLAG, true);
return false;
}
}
return count > 0;
}
use of android.content.ContextWrapper in project kcanotify by antest1.
the class KcaUtils method getJsonObjectFromAsset.
public static JsonObject getJsonObjectFromAsset(Context context, String name, KcaDBHelper helper) {
ContextWrapper cw = new ContextWrapper(context);
JsonObject data = null;
AssetManager am = cw.getAssets();
try {
AssetManager.AssetInputStream ais = (AssetManager.AssetInputStream) am.open(name);
byte[] bytes = ByteStreams.toByteArray(ais);
data = new JsonParser().parse(new String(bytes)).getAsJsonObject();
ais.close();
} catch (IOException e1) {
e1.printStackTrace();
if (helper != null)
helper.recordErrorLog(ERROR_TYPE_DATALOAD, name, "getJsonObjectFromStorage", "1", getStringFromException(e1));
}
return data;
}
use of android.content.ContextWrapper in project Android-skin-support by ximsfei.
the class SkinCompatViewInflater method checkOnClickListener.
/**
* android:onClick doesn't handle views with a ContextWrapper context. This method
* backports new framework functionality to traverse the Context wrappers to find a
* suitable target.
*/
private void checkOnClickListener(View view, AttributeSet attrs) {
final Context context = view.getContext();
if (!(context instanceof ContextWrapper) || (Build.VERSION.SDK_INT >= 15 && !ViewCompat.hasOnClickListeners(view))) {
// always use our compat code on older devices)
return;
}
final TypedArray a = context.obtainStyledAttributes(attrs, sOnClickAttrs);
final String handlerName = a.getString(0);
if (handlerName != null) {
view.setOnClickListener(new DeclaredOnClickListener(view, handlerName));
}
a.recycle();
}
Aggregations