正在查看: xDrip+ v04633772025.07.16 应用的 InstallPebbleWatchFace.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: xDrip+ v04633772025.07.16 应用的 InstallPebbleWatchFace.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.eveningoutpost.dexdrip.utilitymodels.pebble.watchface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.widget.Toast;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import com.eveningoutpost.dexdrip.BaseAppCompatActivity;
import com.eveningoutpost.dexdrip.models.JoH;
import com.eveningoutpost.dexdrip.models.UserError;
import com.eveningoutpost.dexdrip.xdrip;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
public class InstallPebbleWatchFace extends BaseAppCompatActivity {
private static String TAG = "InstallPebbleWatchFace";
protected String getOutputFilename() {
return "xDrip-plus-pebble-auto-install.pbw";
}
protected String getTag() {
return TAG;
}
@Override
protected void onCreate(Bundle bundle) {
setTheme(2131820554);
super.onCreate(bundle);
if (installFile()) {
finish();
}
}
protected boolean isExternalStorageWritable() {
String externalStorageState = Environment.getExternalStorageState();
if (checkPermissions()) {
return "mounted".equals(externalStorageState);
}
return false;
}
private boolean checkPermissions() {
if (ContextCompat.checkSelfPermission(getApplicationContext(), "android.permission.WRITE_EXTERNAL_STORAGE") == 0) {
return true;
}
JoH.show_ok_dialog(this, xdrip.gs(2131756012), "Need storage permission to install watchface", new Runnable() {
@Override
public void run() {
ActivityCompat.requestPermissions(this, new String[]{"android.permission.WRITE_EXTERNAL_STORAGE"}, 99);
}
});
return false;
}
@Override
public void onRequestPermissionsResult(int i, String[] strArr, int[] iArr) {
super.onRequestPermissionsResult(i, strArr, iArr);
if (i == 99) {
if (iArr.length > 0 && iArr[0] == 0) {
installFile();
finish();
} else {
toast("Need permission to write watchface");
finish();
}
}
}
protected InputStream openRawResource() {
return getResources().openRawResource(2131689972);
}
protected void toast(String str) {
try {
Toast.makeText(getApplicationContext(), str, 0).show();
Log.d(getTag(), "Toast msg: " + str);
} catch (Exception unused) {
Log.e(getTag(), "Couldn't display toast: " + str);
}
}
public boolean installFile() {
if (!isExternalStorageWritable()) {
toast("External storage is not writable!");
return false;
}
try {
InputStream openRawResource = openRawResource();
String str = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/" + getOutputFilename();
FileOutputStream fileOutputStream = new FileOutputStream(str);
byte[] bArr = new byte[8192];
while (true) {
int read = openRawResource.read(bArr);
if (read != -1) {
fileOutputStream.write(bArr, 0, read);
} else {
openRawResource.close();
fileOutputStream.flush();
fileOutputStream.close();
Intent intent = new Intent("android.intent.action.VIEW");
intent.setDataAndType(Uri.fromFile(new File(str)), "application/octet-stream");
intent.setFlags(268435456);
startActivity(intent);
return true;
}
}
} catch (Exception e) {
UserError.Log.e(getTag(), " Got exception: " + e.toString());
toast("Error: " + e.getLocalizedMessage());
return true;
}
}
}