forked from w2016561536/android_virtual_cam
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
增加应用内配置工具 fix multi users bug in 4.2 add in-app configuration tool
- Loading branch information
1 parent
91cf9d7
commit 77fda64
Showing
19 changed files
with
476 additions
and
150 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.
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
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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,101 +1,257 @@ | ||
package com.example.vcam; | ||
|
||
|
||
import android.annotation.SuppressLint; | ||
import android.annotation.TargetApi; | ||
import android.Manifest; | ||
import android.app.Activity; | ||
import android.app.AlertDialog; | ||
import android.app.Application; | ||
import android.content.DialogInterface; | ||
import android.content.Intent; | ||
import android.content.SharedPreferences; | ||
import android.content.pm.PackageManager; | ||
import android.net.Uri; | ||
import android.os.Build; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.os.Environment; | ||
import android.util.Log; | ||
import android.widget.Button; | ||
import android.widget.CompoundButton; | ||
import android.widget.Switch; | ||
import android.widget.Toast; | ||
|
||
import java.io.File; | ||
|
||
import de.robv.android.xposed.XposedBridge; | ||
import java.io.IOException; | ||
|
||
public class MainActivity extends Activity { | ||
@SuppressLint("CommitPrefEdits") | ||
public void onCreate(Bundle savedInstanceState) { | ||
makeWorldReadable(); | ||
|
||
SharedPreferences preference; | ||
preference = this.getSharedPreferences("module_set", MODE_PRIVATE); | ||
private Switch force_show_switch; | ||
private Switch disable_switch; | ||
private Switch play_sound_switch; | ||
private Switch force_private_dir; | ||
private Switch disable_toast_switch; | ||
|
||
@Override | ||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { | ||
super.onRequestPermissionsResult(requestCode, permissions, grantResults); | ||
if (grantResults.length > 0) { | ||
if (grantResults[0] == PackageManager.PERMISSION_DENIED) { | ||
Toast.makeText(MainActivity.this, R.string.permission_lack_warn, Toast.LENGTH_SHORT).show(); | ||
}else { | ||
File camera_dir = new File (Environment.getExternalStorageDirectory().getAbsolutePath()+"/DCIM/Camera1/"); | ||
if (!camera_dir.exists()){ | ||
camera_dir.mkdir(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
protected void onResume() { | ||
super.onResume(); | ||
sync_statue_with_files(); | ||
} | ||
|
||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
Button repo_button = findViewById(R.id.button); | ||
Switch force_display = findViewById(R.id.switch2); | ||
Switch disable_module_switch = findViewById(R.id.switch1); | ||
force_show_switch = findViewById(R.id.switch1); | ||
disable_switch = findViewById(R.id.switch2); | ||
play_sound_switch = findViewById(R.id.switch3); | ||
force_private_dir = findViewById(R.id.switch4); | ||
disable_toast_switch = findViewById(R.id.switch5); | ||
|
||
disable_module_switch.setChecked(preference.getBoolean("disable", false)); | ||
force_display.setChecked(preference.getBoolean("force_display",false)); | ||
|
||
repo_button.setOnClickListener(new View.OnClickListener() { | ||
|
||
@Override | ||
public void onClick(View v) { | ||
sync_statue_with_files(); | ||
|
||
Uri uri = Uri.parse("https://github.com/w2016561536/android_virtual_cam"); | ||
Intent intent = new Intent(Intent.ACTION_VIEW, uri); | ||
startActivity(intent); | ||
} | ||
repo_button.setOnClickListener(v -> { | ||
|
||
Uri uri = Uri.parse("https://github.com/w2016561536/android_virtual_cam"); | ||
Intent intent = new Intent(Intent.ACTION_VIEW, uri); | ||
startActivity(intent); | ||
}); | ||
|
||
Button repo_button_chinamainland = findViewById(R.id.button2); | ||
repo_button_chinamainland.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
Uri uri = Uri.parse("https://gitee.com/w2016561536/android_virtual_cam"); | ||
Intent intent = new Intent(Intent.ACTION_VIEW, uri); | ||
startActivity(intent); | ||
repo_button_chinamainland.setOnClickListener(view -> { | ||
Uri uri = Uri.parse("https://gitee.com/w2016561536/android_virtual_cam"); | ||
Intent intent = new Intent(Intent.ACTION_VIEW, uri); | ||
startActivity(intent); | ||
}); | ||
|
||
disable_switch.setOnCheckedChangeListener((compoundButton, b) -> { | ||
if (compoundButton.isPressed()) { | ||
if (!has_permission()) { | ||
request_permission(); | ||
} else { | ||
File disable_file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/DCIM/Camera1/disable.jpg"); | ||
if (disable_file.exists() != b){ | ||
if (b){ | ||
try { | ||
disable_file.createNewFile(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
}else { | ||
disable_file.delete(); | ||
} | ||
} | ||
} | ||
sync_statue_with_files(); | ||
} | ||
}); | ||
|
||
force_show_switch.setOnCheckedChangeListener((compoundButton, b) -> { | ||
if (compoundButton.isPressed()) { | ||
if (!has_permission()) { | ||
request_permission(); | ||
} else { | ||
File force_show_switch = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/DCIM/Camera1/force_show.jpg"); | ||
if (force_show_switch.exists() != b){ | ||
if (b){ | ||
try { | ||
force_show_switch.createNewFile(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
}else { | ||
force_show_switch.delete(); | ||
} | ||
} | ||
} | ||
sync_statue_with_files(); | ||
} | ||
}); | ||
|
||
SharedPreferences finalPreference = preference; | ||
disable_module_switch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { | ||
play_sound_switch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { | ||
@Override | ||
public void onCheckedChanged(CompoundButton compoundButton, boolean b) { | ||
SharedPreferences.Editor editor = finalPreference.edit(); | ||
editor.putBoolean("disable",b); | ||
editor.apply(); | ||
editor.commit(); | ||
makeWorldReadable(); | ||
if (compoundButton.isPressed()) { | ||
if (!has_permission()) { | ||
request_permission(); | ||
} else { | ||
File play_sound_switch = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/DCIM/Camera1/no-silent.jpg"); | ||
if (play_sound_switch.exists() != b){ | ||
if (b){ | ||
try { | ||
play_sound_switch.createNewFile(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
}else { | ||
play_sound_switch.delete(); | ||
} | ||
} | ||
} | ||
sync_statue_with_files(); | ||
} | ||
} | ||
}); | ||
|
||
force_display.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { | ||
@Override | ||
public void onCheckedChanged(CompoundButton compoundButton, boolean b) { | ||
SharedPreferences.Editor editor = finalPreference.edit(); | ||
editor.putBoolean("force_display",b); | ||
editor.apply(); | ||
editor.commit(); | ||
makeWorldReadable(); | ||
force_private_dir.setOnCheckedChangeListener((compoundButton, b) -> { | ||
if (compoundButton.isPressed()) { | ||
if (!has_permission()) { | ||
request_permission(); | ||
} else { | ||
File force_private_dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/DCIM/Camera1/private_dir.jpg"); | ||
if (force_private_dir.exists() != b){ | ||
if (b){ | ||
try { | ||
force_private_dir.createNewFile(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
}else { | ||
force_private_dir.delete(); | ||
} | ||
} | ||
} | ||
sync_statue_with_files(); | ||
} | ||
}); | ||
|
||
|
||
disable_toast_switch.setOnCheckedChangeListener((compoundButton, b) -> { | ||
if (compoundButton.isPressed()) { | ||
if (!has_permission()) { | ||
request_permission(); | ||
} else { | ||
File disable_toast_file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/DCIM/Camera1/no_toast.jpg"); | ||
if (disable_toast_file.exists() != b){ | ||
if (b){ | ||
try { | ||
disable_toast_file.createNewFile(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
}else { | ||
disable_toast_file.delete(); | ||
} | ||
} | ||
} | ||
sync_statue_with_files(); | ||
} | ||
}); | ||
|
||
} | ||
|
||
@TargetApi(Build.VERSION_CODES.N) | ||
@SuppressLint({"SetWorldReadable", "SetWorldWritable"}) | ||
private void makeWorldReadable() { | ||
try { | ||
File f = new File(this.getDataDir().getAbsolutePath()+"/shared_prefs/module_set.xml"); | ||
f.setReadable(true, false); | ||
f.setExecutable(true, false); | ||
f.setWritable(true, false); | ||
} catch (Exception e) { | ||
XposedBridge.log("【VCAM】权限设置失败"+ e.toString()); | ||
private void request_permission() { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | ||
if (this.checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED | ||
|| this.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) { | ||
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); | ||
builder.setTitle(R.string.permission_lack_warn); | ||
builder.setMessage(R.string.permission_description); | ||
|
||
builder.setNegativeButton(R.string.negative, (dialogInterface, i) -> Toast.makeText(MainActivity.this, R.string.permission_lack_warn, Toast.LENGTH_SHORT).show()); | ||
|
||
builder.setPositiveButton(R.string.positive, (dialogInterface, i) -> requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1)); | ||
builder.show(); | ||
} | ||
} | ||
} | ||
|
||
private boolean has_permission() { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | ||
return this.checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_DENIED | ||
&& this.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_DENIED; | ||
} | ||
return true; | ||
} | ||
|
||
|
||
private void sync_statue_with_files() { | ||
Log.d(this.getApplication().getPackageName(), "【VCAM】[sync]同步开关状态"); | ||
|
||
if (!has_permission()){ | ||
request_permission(); | ||
}else { | ||
File camera_dir = new File (Environment.getExternalStorageDirectory().getAbsolutePath()+"/DCIM/Camera1"); | ||
if (!camera_dir.exists()){ | ||
camera_dir.mkdir(); | ||
} | ||
} | ||
|
||
File disable_file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/DCIM/Camera1/disable.jpg"); | ||
disable_switch.setChecked(disable_file.exists()); | ||
|
||
File force_show_file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/DCIM/Camera1/force_show.jpg"); | ||
force_show_switch.setChecked(force_show_file.exists()); | ||
|
||
File play_sound_file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/DCIM/Camera1/no-silent.jpg"); | ||
play_sound_switch.setChecked(play_sound_file.exists()); | ||
|
||
File force_private_dir_file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/DCIM/Camera1/private_dir.jpg"); | ||
force_private_dir.setChecked(force_private_dir_file.exists()); | ||
|
||
File disable_toast_file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/DCIM/Camera1/no_toast.jpg"); | ||
disable_toast_switch.setChecked(disable_toast_file.exists()); | ||
|
||
} | ||
|
||
|
||
} | ||
|
||
|
||
|
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
Oops, something went wrong.