Skip to content

Commit

Permalink
Merge pull request #12 from Knightwood/master
Browse files Browse the repository at this point in the history
  • Loading branch information
linesoft2 committed Apr 13, 2024
2 parents 4eee987 + c823783 commit f83ad55
Show file tree
Hide file tree
Showing 18 changed files with 295 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.preference:preference:1.2.0'
implementation 'com.google.android.material:material:1.7.0'
implementation('com.github.knightwood:material3-preference:1.3'){
exclude group: "androidx.lifecycle", module: "lifecycle-viewmodel-ktx"
}

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/open2share_icon_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:theme="@style/Theme.Open2Share.Material3"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".GuideActivity"
Expand Down
43 changes: 29 additions & 14 deletions app/src/main/java/top/linesoft/open2share/ReceiveOpenActivity.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package top.linesoft.open2share;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.StrictMode;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ShareCompat;
import androidx.preference.PreferenceManager;


public class ReceiveOpenActivity extends AppCompatActivity {

Expand All @@ -27,19 +31,30 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

//解决极少数旧App未使用URI分享会导致报错的问题
//目前来看这类应用极少,先注释掉了
// StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
// StrictMode.setVmPolicy(builder.build());
// builder.detectFileUriExposure();

//setContentView(R.layout.activity_receive_open);
//Toast.makeText(this,"已经将打开文件转换为分享文件",Toast.LENGTH_LONG).show();

new ShareCompat.IntentBuilder(this)
.addStream(getIntent().getData())
.setType(getIntent().getType())
.startChooser();
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
sendIntent.addCategory("android.intent.category.DEFAULT");
Uri uri = getIntent().getData();
// Log.d("分享","Data:"+ getIntent().getData().toString()+ uri.getScheme());
// Log.d("分享","Type:"+ getIntent().getType());
if (uri.getScheme().equals("file")) {
boolean b= PreferenceManager.getDefaultSharedPreferences(this).getBoolean("use_file_uri",false);
if (b){
//API24以上系统分享支持file:///开头
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
builder.detectFileUriExposure();
}else{
Toast.makeText(getApplicationContext(), R.string.no_use_file_uri_msg, Toast.LENGTH_LONG).show();
finishAffinity();
}
}
sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
sendIntent.setType(getIntent().getType());
sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivityForResult(Intent.createChooser(sendIntent, getString(R.string.share_title)), 1);
//finish();

}
}
68 changes: 44 additions & 24 deletions app/src/main/java/top/linesoft/open2share/SettingsActivity.java
Original file line number Diff line number Diff line change
@@ -1,49 +1,54 @@
package top.linesoft.open2share;

import android.content.ComponentName;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.SwitchPreference;
import androidx.preference.SwitchPreferenceCompat;

import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.kiylx.m3preference.ui.BaseSettingsFragment;

public class SettingsActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings_activity);
SettingsFragment settingsFragment = new SettingsFragment();
settingsFragment.setIconHide(false);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.settings, new SettingsFragment())
.replace(R.id.settings, settingsFragment)
.commit();
ActionBar actionBar = getSupportActionBar();
//actionBar.setDisplayHomeAsUpEnabled(true);

}

public static class SettingsFragment extends PreferenceFragmentCompat implements Preference.OnPreferenceClickListener, Preference.OnPreferenceChangeListener {
public static class SettingsFragment extends BaseSettingsFragment implements Preference.OnPreferenceClickListener, Preference.OnPreferenceChangeListener {
Preference guidePreference;
SwitchPreference hidePreference;
SwitchPreferenceCompat hidePreference;
SwitchPreferenceCompat fileUriPreference;
Preference aboutPreference;

@Override
public boolean onPreferenceClick(Preference preference) {
if (preference == guidePreference){
if (preference == guidePreference) {
Intent intent = new Intent(getActivity(), GuideActivity.class);
startActivity(intent);
return true;
}else if(preference == aboutPreference){
new AlertDialog.Builder(requireContext())
} else if (preference == aboutPreference) {
new MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.about_dialogue_title)
.setMessage(R.string.about_dialogue_msg)
.setPositiveButton(R.string.ok,null)
.setPositiveButton(R.string.ok, null)
.setNeutralButton(R.string.website, (dialog, which) -> {
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
Expand All @@ -61,18 +66,19 @@ public boolean onPreferenceClick(Preference preference) {
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.root_preferences, rootKey);
guidePreference = findPreference("guide");
if(guidePreference != null){
if (guidePreference != null) {
guidePreference.setOnPreferenceClickListener(this);
}
hidePreference = findPreference("hide_icon");
if(hidePreference != null){
if (hidePreference != null) {
hidePreference.setOnPreferenceChangeListener(this);
}
fileUriPreference = findPreference("use_file_uri");
if (fileUriPreference != null) {
fileUriPreference.setOnPreferenceChangeListener(this);
}
aboutPreference = findPreference("about");
aboutPreference.setOnPreferenceClickListener(this);



}

/**
Expand All @@ -86,30 +92,44 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
// Log.d("onPreferenceChange", "onPreferenceChange: 被触发");
if(preference == hidePreference){
if (preference == hidePreference) {
// Toast.makeText(getContext(),"当前值为:"+newValue,Toast.LENGTH_LONG).show();
PackageManager pm = requireContext().getPackageManager();
ComponentName hideComponentName = new ComponentName(requireContext(), "top.linesoft.open2share.hide_icon");
ComponentName unhideComponentName = new ComponentName(getContext(), "top.linesoft.open2share.unhide_icon");
if((Boolean) newValue){
if ((Boolean) newValue) {

AlertDialog.Builder mDialogBuilder = new AlertDialog.Builder(getContext());
MaterialAlertDialogBuilder mDialogBuilder = new MaterialAlertDialogBuilder(requireActivity());
mDialogBuilder.setTitle(R.string.warn)
.setMessage(R.string.hide_tips)
.setPositiveButton(R.string.yes, (dialog, which) -> {
pm.setComponentEnabledSetting(hideComponentName,PackageManager.COMPONENT_ENABLED_STATE_ENABLED,PackageManager.DONT_KILL_APP);
pm.setComponentEnabledSetting(unhideComponentName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED,PackageManager.DONT_KILL_APP);
pm.setComponentEnabledSetting(hideComponentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
pm.setComponentEnabledSetting(unhideComponentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
SettingsFragment.this.hidePreference.setChecked(true);
}).setNegativeButton(R.string.no,null).create().show();
}).setNegativeButton(R.string.no, null).create().show();
return false;


}else{
pm.setComponentEnabledSetting(hideComponentName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED,PackageManager.DONT_KILL_APP);
pm.setComponentEnabledSetting(unhideComponentName,PackageManager.COMPONENT_ENABLED_STATE_ENABLED,PackageManager.DONT_KILL_APP);
} else {
pm.setComponentEnabledSetting(hideComponentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
pm.setComponentEnabledSetting(unhideComponentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
return true;
}

} else if (preference == fileUriPreference) {
if ((Boolean) newValue) {
MaterialAlertDialogBuilder mDialogBuilder = new MaterialAlertDialogBuilder(requireActivity());
mDialogBuilder.setTitle(R.string.warn)
.setMessage(R.string.open_file_uri_msg)
.setPositiveButton(R.string.yes, (dialog, which) -> {
SettingsFragment.this.fileUriPreference.setChecked(true);
}).setNegativeButton(R.string.no, (dialog, which) -> {
SettingsFragment.this.fileUriPreference.setChecked(false);
}).create().show();
return false;
} else {
return true;
}
}
return false;
}
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_baseline_healing_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M17.73,12.02l3.98,-3.98c0.39,-0.39 0.39,-1.02 0,-1.41l-4.34,-4.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-3.98,3.98L8,2.29C7.8,2.1 7.55,2 7.29,2c-0.25,0 -0.51,0.1 -0.7,0.29L2.25,6.63c-0.39,0.39 -0.39,1.02 0,1.41l3.98,3.98L2.25,16c-0.39,0.39 -0.39,1.02 0,1.41l4.34,4.34c0.39,0.39 1.02,0.39 1.41,0l3.98,-3.98 3.98,3.98c0.2,0.2 0.45,0.29 0.71,0.29 0.26,0 0.51,-0.1 0.71,-0.29l4.34,-4.34c0.39,-0.39 0.39,-1.02 0,-1.41l-3.99,-3.98zM12,9c0.55,0 1,0.45 1,1s-0.45,1 -1,1 -1,-0.45 -1,-1 0.45,-1 1,-1zM7.29,10.96L3.66,7.34l3.63,-3.63 3.62,3.62 -3.62,3.63zM10,13c-0.55,0 -1,-0.45 -1,-1s0.45,-1 1,-1 1,0.45 1,1 -0.45,1 -1,1zM12,15c-0.55,0 -1,-0.45 -1,-1s0.45,-1 1,-1 1,0.45 1,1 -0.45,1 -1,1zM14,11c0.55,0 1,0.45 1,1s-0.45,1 -1,1 -1,-0.45 -1,-1 0.45,-1 1,-1zM16.66,20.34l-3.63,-3.62 3.63,-3.63 3.62,3.62 -3.62,3.63z"/>
</vector>
48 changes: 48 additions & 0 deletions app/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.Open2Share.Material2" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_200</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/black</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_200</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>

<style name="Theme.Open2Share.Material3" parent="Theme.Material3.DayNight">
<item name="colorPrimary">@color/md_theme_dark_primary</item>
<item name="colorOnPrimary">@color/md_theme_dark_onPrimary</item>
<item name="colorPrimaryContainer">@color/md_theme_dark_primaryContainer</item>
<item name="colorOnPrimaryContainer">@color/md_theme_dark_onPrimaryContainer</item>
<item name="colorSecondary">@color/md_theme_dark_secondary</item>
<item name="colorOnSecondary">@color/md_theme_dark_onSecondary</item>
<item name="colorSecondaryContainer">@color/md_theme_dark_secondaryContainer</item>
<item name="colorOnSecondaryContainer">@color/md_theme_dark_onSecondaryContainer</item>
<item name="colorTertiary">@color/md_theme_dark_tertiary</item>
<item name="colorOnTertiary">@color/md_theme_dark_onTertiary</item>
<item name="colorTertiaryContainer">@color/md_theme_dark_tertiaryContainer</item>
<item name="colorOnTertiaryContainer">@color/md_theme_dark_onTertiaryContainer</item>
<item name="colorError">@color/md_theme_dark_error</item>
<item name="colorOnError">@color/md_theme_dark_onError</item>
<item name="colorErrorContainer">@color/md_theme_dark_errorContainer</item>
<item name="colorOnErrorContainer">@color/md_theme_dark_onErrorContainer</item>
<item name="android:colorBackground">@color/md_theme_dark_background</item>
<item name="colorOnBackground">@color/md_theme_dark_onBackground</item>
<item name="colorSurface">@color/md_theme_dark_surface</item>
<item name="colorOnSurface">@color/md_theme_dark_onSurface</item>
<item name="colorSurfaceVariant">@color/md_theme_dark_surfaceVariant</item>
<item name="colorOnSurfaceVariant">@color/md_theme_dark_onSurfaceVariant</item>
<item name="colorOutline">@color/md_theme_dark_outline</item>
<item name="colorSurfaceInverse">@color/md_theme_dark_inverseSurface</item>
<item name="colorOnSurfaceInverse">@color/md_theme_dark_inverseOnSurface</item>
<item name="elevationOverlayColor">@color/md_theme_dark_surfaceTint</item>
<item name="colorPrimaryInverse">@color/md_theme_dark_inversePrimary</item>
<item name="preferenceTheme">@style/M3PreferenceStyle</item>

</style>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@
<string name="about_dialogue_msg">作者:双霖 (LineSoft)</string>
<string name="ok">确定</string>
<string name="website">网站</string>
<string name="open_file_uri">兼容fileUri类型</string>
<string name="open_file_uri_msg">android7以上,因为安全问题不提倡使用fileUri,因此,打开此选项将同意带来的安全风险</string>
<string name="no_use_file_uri_msg">未允许打开fileUri兼容</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values-zh-rHK/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@
<string name="about_dialogue_msg">作者:雙霖 (LineSoft)</string>
<string name="ok">確定</string>
<string name="website">網站</string>
<string name="open_file_uri">相容fileUri類型</string>
<string name="open_file_uri_msg">android7以上,因為安全問題不提倡使用fileUri,因此,打開此選項將同意帶來的安全風險</string>
<string name="no_use_file_uri_msg">未允許打開fileUri相容</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@
<string name="about_dialogue_msg">作者:雙霖 (LineSoft)</string>
<string name="ok">確定</string>
<string name="website">網站</string>
<string name="open_file_uri">相容fileUri類型</string>
<string name="open_file_uri_msg">android7以上,因為安全問題不提倡使用fileUri,因此,打開此選項將同意帶來的安全風險</string>
<string name="no_use_file_uri_msg">未允許打開fileUri相容</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@
<string name="about_dialogue_msg">作者:双霖 (LineSoft)</string>
<string name="ok">确定</string>
<string name="website">网站</string>
<string name="open_file_uri">兼容fileUri类型</string>
<string name="open_file_uri_msg">android7以上,因为安全问题不提倡使用fileUri,因此,打开此选项将同意带来的安全风险</string>
<string name="no_use_file_uri_msg">未允许打开fileUri兼容</string>
</resources>
Loading

0 comments on commit f83ad55

Please sign in to comment.