-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
387 additions
and
47 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
260 changes: 237 additions & 23 deletions
260
app/src/main/java/im/hoho/alipayInstallB/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,264 @@ | ||
package im.hoho.alipayInstallB; | ||
|
||
import android.Manifest; | ||
import android.app.Activity; | ||
import android.content.Intent; | ||
import android.content.pm.PackageManager; | ||
import android.net.Uri; | ||
import android.os.Build; | ||
import android.os.Bundle; | ||
import android.os.Environment; | ||
import android.os.Handler; | ||
import android.os.Looper; | ||
import android.provider.Settings; | ||
import android.view.View; | ||
import android.widget.AdapterView; | ||
import android.widget.ArrayAdapter; | ||
import android.widget.ListView; | ||
import android.widget.Button; | ||
import android.widget.ImageView; | ||
import android.widget.ProgressBar; | ||
import android.widget.TextView; | ||
import android.widget.Toast; | ||
|
||
import net.lingala.zip4j.ZipFile; | ||
import net.lingala.zip4j.exception.ZipException; | ||
|
||
import java.io.BufferedInputStream; | ||
import java.io.BufferedOutputStream; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.net.URL; | ||
import java.net.URLConnection; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
|
||
public class MainActivity extends Activity { | ||
|
||
// | ||
private static final String EXTERNAL_STORAGE_PATH = Environment.getExternalStorageDirectory() + "/Android/media/com.eg.android.AlipayGphone/000_HOHO_ALIPAY_SKIN"; | ||
private static final String EXPORT_FILE = EXTERNAL_STORAGE_PATH + "/export"; | ||
private static final String DELETE_FILE = EXTERNAL_STORAGE_PATH + "/delete"; | ||
private static final String UPDATE_FILE = EXTERNAL_STORAGE_PATH + "/update"; | ||
private static final String ACTIVATE_FILE = EXTERNAL_STORAGE_PATH + "/actived"; | ||
private static final int PERMISSION_REQUEST_CODE = 1001; | ||
private static final String DOWNLOAD_URL = "https://github.com/nov30th/AlipayHighHeadsomeRichAndroid/raw/master/SD%E5%8D%A1%E8%B5%84%E6%BA%90%E6%96%87%E4%BB%B6%E5%8C%85/SD%E8%B5%84%E6%BA%90%E6%96%87%E4%BB%B6.zip"; | ||
private static final String EXTRACT_PATH = Environment.getExternalStorageDirectory() + "/Android/media/com.eg.android.AlipayGphone/"; | ||
private Button btnExport, btnDelete, btnUpdate, btnActivate; | ||
private ImageView ivExportStatus, ivDeleteStatus, ivUpdateStatus, ivActivateStatus; | ||
private Button btnDownload; | ||
private ProgressBar progressBar; | ||
private ExecutorService executorService; | ||
private Handler mainHandler; | ||
|
||
|
||
@Override | ||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { | ||
if (requestCode == PERMISSION_REQUEST_CODE) { | ||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { | ||
// 权限被授予 | ||
Toast.makeText(this, "Storage permission granted", Toast.LENGTH_SHORT).show(); | ||
} else { | ||
// 权限被拒绝 | ||
Toast.makeText(this, "Storage permission denied", Toast.LENGTH_SHORT).show(); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
setContentView(R.layout.activity_main); | ||
|
||
ListView listview = (ListView) findViewById(R.id.listview); | ||
TextView textView = (TextView) findViewById(R.id.textView2); | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { | ||
if (!Environment.isExternalStorageManager()) { | ||
Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION); | ||
Uri uri = Uri.fromParts("package", getPackageName(), null); | ||
intent.setData(uri); | ||
startActivity(intent); | ||
} | ||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | ||
if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { | ||
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE); | ||
} | ||
} | ||
|
||
|
||
TextView tvVersion = findViewById(R.id.tvVersion); | ||
tvVersion.setText("Version: " + BuildConfig.VERSION_NAME); | ||
|
||
btnExport = findViewById(R.id.btnExport); | ||
btnDelete = findViewById(R.id.btnDelete); | ||
btnUpdate = findViewById(R.id.btnUpdate); | ||
btnActivate = findViewById(R.id.btnActivate); | ||
|
||
ivExportStatus = findViewById(R.id.ivExportStatus); | ||
ivDeleteStatus = findViewById(R.id.ivDeleteStatus); | ||
ivUpdateStatus = findViewById(R.id.ivUpdateStatus); | ||
ivActivateStatus = findViewById(R.id.ivActivateStatus); | ||
|
||
setupButtons(); | ||
updateStatuses(); | ||
|
||
textView.setText("2.5.0"); | ||
|
||
listview.setDividerHeight(0);//屏蔽掉listview的横线 | ||
listview.setDivider(null); | ||
btnDownload = findViewById(R.id.btnDownload); | ||
progressBar = findViewById(R.id.progressBar); | ||
|
||
String[] listContent = {"Author: 裘小杰 - hoho.im 杭州亚运会版", "支付宝付款显示钻石会员背景。", "自定义付款码皮肤(可随机变换).", "没有界面控件,请参考文档操作。", "", "文档及源代码项目地址:", "https://github.com/nov30th/AlipayHighHeadsomeRichAndroid", | ||
executorService = Executors.newSingleThreadExecutor(); | ||
mainHandler = new Handler(Looper.getMainLooper()); | ||
|
||
}; | ||
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1, listContent); | ||
listview.setAdapter(adapter); | ||
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() { | ||
updateDownloadButtonText(); | ||
|
||
btnDownload.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
downloadAndExtract(); | ||
} | ||
}); | ||
|
||
} | ||
|
||
private void setupButtons() { | ||
btnExport.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { | ||
String text = (String) ((TextView) view).getText(); | ||
if (text.contains("https")) { | ||
Uri uri = Uri.parse(text); | ||
Intent intent = new Intent(Intent.ACTION_VIEW); | ||
intent.setData(uri); | ||
startActivity(intent); | ||
public void onClick(View v) { | ||
toggleFile(EXPORT_FILE); | ||
} | ||
}); | ||
btnDelete.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
toggleFile(DELETE_FILE); | ||
} | ||
}); | ||
btnUpdate.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
toggleFile(UPDATE_FILE); | ||
} | ||
}); | ||
btnActivate.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
toggleFile(ACTIVATE_FILE); | ||
} | ||
}); | ||
} | ||
|
||
private void toggleFile(String filePath) { | ||
File file = new File(filePath); | ||
if (file.exists()) { | ||
file.delete(); | ||
} else { | ||
try { | ||
new File(EXTERNAL_STORAGE_PATH).mkdirs(); | ||
new File(filePath).mkdirs(); | ||
// file.createNewFile(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
Toast.makeText(this, "Error creating file", Toast.LENGTH_SHORT).show(); | ||
} | ||
} | ||
updateStatuses(); | ||
Toast.makeText(this, "Reopen payment code to take effect", Toast.LENGTH_SHORT).show(); | ||
} | ||
|
||
private void updateStatuses() { | ||
updateStatus(ivExportStatus, EXPORT_FILE); | ||
updateStatus(ivDeleteStatus, DELETE_FILE); | ||
updateStatus(ivUpdateStatus, UPDATE_FILE); | ||
updateStatus(ivActivateStatus, ACTIVATE_FILE); | ||
|
||
btnActivate.setText(new File(ACTIVATE_FILE).exists() ? "Deactivate" : "Activate"); | ||
} | ||
|
||
private void updateStatus(ImageView imageView, String filePath) { | ||
imageView.setImageResource(new File(filePath).exists() ? R.drawable.green_circle : R.drawable.red_circle); | ||
} | ||
|
||
private void updateDownloadButtonText() { | ||
File skinFolder = new File(EXTRACT_PATH + "000_HOHO_ALIPAY_SKIN"); | ||
btnDownload.setText(skinFolder.exists() ? "Redownload Resources" : "Download Resources"); | ||
} | ||
|
||
private void downloadAndExtract() { | ||
btnDownload.setEnabled(false); | ||
progressBar.setVisibility(View.VISIBLE); | ||
progressBar.setProgress(0); | ||
|
||
executorService.execute(new Runnable() { | ||
@Override | ||
public void run() { | ||
try { | ||
URL url = new URL(DOWNLOAD_URL); | ||
URLConnection connection = url.openConnection(); | ||
connection.connect(); | ||
|
||
int fileLength = connection.getContentLength(); | ||
|
||
InputStream input = new BufferedInputStream(url.openStream()); | ||
OutputStream output = new FileOutputStream(EXTRACT_PATH + "temp.zip"); | ||
|
||
byte[] data = new byte[1024]; | ||
long total = 0; | ||
int count; | ||
while ((count = input.read(data)) != -1) { | ||
total += count; | ||
final int progress = (int) (total * 100 / fileLength); | ||
mainHandler.post(new Runnable() { | ||
@Override | ||
public void run() { | ||
progressBar.setProgress(progress); | ||
} | ||
}); | ||
output.write(data, 0, count); | ||
} | ||
|
||
output.flush(); | ||
output.close(); | ||
input.close(); | ||
|
||
// 解压文件 | ||
unzip(EXTRACT_PATH + "temp.zip", EXTRACT_PATH); | ||
|
||
mainHandler.post(new Runnable() { | ||
@Override | ||
public void run() { | ||
btnDownload.setEnabled(true); | ||
progressBar.setVisibility(View.GONE); | ||
Toast.makeText(MainActivity.this, "Download and extraction completed", Toast.LENGTH_LONG).show(); | ||
updateDownloadButtonText(); | ||
} | ||
}); | ||
} catch (final Exception e) { | ||
mainHandler.post(new Runnable() { | ||
@Override | ||
public void run() { | ||
btnDownload.setEnabled(true); | ||
progressBar.setVisibility(View.GONE); | ||
Toast.makeText(MainActivity.this, "Error: " + e.getMessage(), Toast.LENGTH_LONG).show(); | ||
} | ||
}); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
public void unzip(String zipFilePath, String destDirectory) { | ||
try { | ||
ZipFile zipFile = new ZipFile(zipFilePath); | ||
zipFile.extractAll(destDirectory); | ||
} catch (ZipException e) { | ||
e.printStackTrace(); | ||
// 处理异常 | ||
} | ||
} | ||
|
||
@Override | ||
protected void onDestroy() { | ||
super.onDestroy(); | ||
if (executorService != null) { | ||
executorService.shutdown(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:shape="oval"> | ||
<solid android:color="#4CAF50" /> | ||
<size | ||
android:width="24dp" | ||
android:height="24dp" /> | ||
</shape> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:shape="oval"> | ||
<solid android:color="#F44336" /> | ||
<size | ||
android:width="24dp" | ||
android:height="24dp" /> | ||
</shape> |
Oops, something went wrong.