Remove pop-up icon that appears once device connected: simplify NsBroadcastReceiver.java

Add Traditional Chinese translation #5 by @qazrfv1234
Fix failures on old android versions (before lollipop).
Add split-screen and window-in-window support for 'modern' android versions
Move to newer toolkit
Set version to 1.0 ;)
This commit is contained in:
Dmitry Isaenko 2020-08-03 14:02:24 +03:00
parent 0061551e6b
commit f01f312cbb
17 changed files with 119 additions and 96 deletions

View file

@ -1,13 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<compositeConfiguration>
<compositeBuild compositeDefinitionSource="SCRIPT" />
</compositeConfiguration>
<option name="delegatedBuild" value="false" />
<option name="testRunner" value="PLATFORM" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
</GradleProjectSettings>
</option>

25
.idea/jarRepositories.xml Normal file
View file

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="BintrayJCenter" />
<option name="name" value="BintrayJCenter" />
<option name="url" value="https://jcenter.bintray.com/" />
</remote-repository>
<remote-repository>
<option name="id" value="Google" />
<option name="name" value="Google" />
<option name="url" value="https://dl.google.com/dl/android/maven2/" />
</remote-repository>
</component>
</project>

View file

@ -2,13 +2,13 @@ apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.0"
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.blogspot.developersu.ns_usbloader"
minSdkVersion 15
targetSdkVersion 29
versionCode 2
versionName "0.2"
versionCode 3
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
android.defaultConfig.vectorDrawables.useSupportLibrary = true
}

View file

@ -18,6 +18,8 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:resizeableActivity="true"
android:supportsPictureInPicture="true"
tools:ignore="GoogleAppIndexingWarning"> <!-- <- IDK WTF, RTFM MB -->
<activity
android:name=".SettingsActivity"
@ -66,21 +68,12 @@
android:name=".NsBroadcastReceiver"
android:exported="true">
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
<action android:name="android.hardware.usb.action.USB_DEVICE_DETACHED" />
<action android:name="com.blogspot.developersu.ns_usbloader.SERVICE_TRANSFER_TASK_FINISHED" />
<!--
<action android:name="com.blogspot.developersu.ns_usbloader.ACTION_USB_PERMISSION" />
<action android:name="com.blogspot.developersu.ns_usbloader.RISE_NOTIFICATION_OR_ACTIVITY" /> to handle if not handled by internally-registered receiver of MainActivity
-->
</intent-filter>
<meta-data
android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="@xml/device_filter" />
<meta-data
android:name="android.hardware.usb.action.USB_DEVICE_DETACHED"
android:resource="@xml/device_filter" />
</receiver>
<service android:name=".service.CommunicationsService"

View file

@ -4,7 +4,9 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.recyclerview.widget.ItemTouchHelper;
@ -54,14 +56,18 @@ public class MainActivity extends AppCompatActivity implements NsResultReciever.
private UsbDevice usbDevice;
private boolean isUsbDeviceAccessible;
private Button selectBtn;
private Button uploadToNsBtn;
private Button selectBtn,
uploadToNsBtn;
private ProgressBar progressBarMain;
private NavigationView drawerNavView;
private NsResultReciever nsResultReciever;
static {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
@Override
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
@ -88,7 +94,6 @@ public class MainActivity extends AppCompatActivity implements NsResultReciever.
registerReceiver(innerBroadcastReceiver, intentFilter);
nsResultReciever.setReceiver(this);
blockUI(CommunicationsService.isServiceActive());
}
@Override
@ -201,6 +206,7 @@ public class MainActivity extends AppCompatActivity implements NsResultReciever.
else {
mDataset = new ArrayList<>();
usbDevice = getIntent().getParcelableExtra(UsbManager.EXTRA_DEVICE); // If it's started initially, then check if it's started from notification.
//Log.i("LPR", "DEVICE " +usbDevice);
if (usbDevice != null){
UsbManager usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
// If somehow we can't get system service
@ -419,7 +425,7 @@ public class MainActivity extends AppCompatActivity implements NsResultReciever.
if (shouldBlock) {
selectBtn.setEnabled(false);
recyclerView.suppressLayout(true);
uploadToNsBtn.setCompoundDrawablesWithIntrinsicBounds(null, getResources().getDrawable(R.drawable.ic_cancel), null, null);
uploadToNsBtn.setCompoundDrawablesWithIntrinsicBounds(null, ContextCompat.getDrawable(this, R.drawable.ic_cancel), null, null);
uploadToNsBtn.setText(R.string.interrupt_btn);
uploadToNsBtn.setOnClickListener(e -> stopService(new Intent(this, CommunicationsService.class)));
progressBarMain.setVisibility(ProgressBar.VISIBLE);
@ -429,7 +435,7 @@ public class MainActivity extends AppCompatActivity implements NsResultReciever.
}
selectBtn.setEnabled(true);
recyclerView.suppressLayout(false);
uploadToNsBtn.setCompoundDrawablesWithIntrinsicBounds(null, getResources().getDrawable(R.drawable.ic_upload_btn), null, null);
uploadToNsBtn.setCompoundDrawablesWithIntrinsicBounds(null, ContextCompat.getDrawable(this, R.drawable.ic_upload_btn), null, null);
uploadToNsBtn.setText(R.string.upload_btn);
uploadToNsBtn.setOnClickListener(e -> this.uploadFiles() );
progressBarMain.setVisibility(ProgressBar.INVISIBLE);

View file

@ -1,74 +1,24 @@
package com.blogspot.developersu.ns_usbloader;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager;
import android.os.Build;
import android.widget.Toast;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
public class NsBroadcastReceiver extends BroadcastReceiver {
@Override
public synchronized void onReceive(Context context, Intent intent) {
if (intent.getAction() == null)
return;
switch (intent.getAction()) {
case UsbManager.ACTION_USB_DEVICE_ATTACHED: {
showNotification(context, intent.getParcelableExtra(UsbManager.EXTRA_DEVICE));
break;
}
case UsbManager.ACTION_USB_DEVICE_DETACHED: {
hideNotification(context);
break;
}
case NsConstants.SERVICE_TRANSFER_TASK_FINISHED_INTENT:
if (intent.getAction().equals(NsConstants.SERVICE_TRANSFER_TASK_FINISHED_INTENT)){
String issues = intent.getStringExtra("ISSUES");
if (issues != null) {
Toast.makeText(context, context.getString(R.string.transfers_service_stopped) + " " + issues, Toast.LENGTH_LONG).show();
break;
return;
}
Toast.makeText(context, context.getString(R.string.transfers_service_stopped), Toast.LENGTH_SHORT).show();
break;
}
}
private void showNotification(Context context, UsbDevice usbDevice){
NotificationCompat.Builder notification = new NotificationCompat.Builder(context, NsConstants.NOTIFICATION_NS_CONNECTED_CHAN_ID);
notification.setSmallIcon(R.drawable.ic_notification)
.setContentTitle(context.getString(R.string.ns_connected_info))
//.setAutoCancel(true)
.setOngoing(true) // Prevent swipe-notification-to-remove
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class).putExtra(UsbManager.EXTRA_DEVICE, usbDevice), 0));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence notificationChanName = context.getString(R.string.notification_chan_name_usb);
String notificationChanDesc = context.getString(R.string.notification_chan_desc_usb);
NotificationChannel channel = new NotificationChannel(
NsConstants.NOTIFICATION_NS_CONNECTED_CHAN_ID,
notificationChanName,
NotificationManager.IMPORTANCE_DEFAULT);
channel.setDescription(notificationChanDesc);
// Register the channel with the system; you can't change the importance
// or other notification behaviors after this
NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
notificationManager.notify(NsConstants.NOTIFICATION_NS_CONNECTED_ID, notification.build());
}
else {
NotificationManagerCompat.from(context).notify(NsConstants.NOTIFICATION_NS_CONNECTED_ID, notification.build());
}
}
private void hideNotification(Context context){
NotificationManagerCompat.from(context).cancel(NsConstants.NOTIFICATION_NS_CONNECTED_ID);
}
// .setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class).putExtra(UsbManager.EXTRA_DEVICE, usbDevice), 0));
}

View file

@ -23,7 +23,4 @@ public class NsConstants {
public static final String NOTIFICATION_FOREGROUND_SERVICE_CHAN_ID = "com.blogspot.developersu.ns_usbloader.CHAN_ID_FOREGROUND_SERVICE";
public static final int NOTIFICATION_TRANSFER_ID = 1;
public static final String NOTIFICATION_NS_CONNECTED_CHAN_ID = "com.blogspot.developersu.ns_usbloader.CHAN_ID_NS_CONNECTED";
public static final int NOTIFICATION_NS_CONNECTED_ID = 2;
}

View file

@ -5,9 +5,9 @@ import android.content.Context;
import android.content.DialogInterface;
public class NsNotificationPopUp {
public static void getAlertWindow(Context context, String titile, String message){
public static void getAlertWindow(Context context, String title, String message){
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(titile)
builder.setTitle(title)
.setMessage(message)
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {

View file

@ -13,6 +13,7 @@ import com.blogspot.developersu.ns_usbloader.R;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Locale;
public class NspItemsAdapter extends RecyclerView.Adapter<NspItemsAdapter.NspViewHolder> {
private ArrayList<NSPElement> mDataset;
@ -44,11 +45,11 @@ public class NspItemsAdapter extends RecyclerView.Adapter<NspItemsAdapter.NspVie
private String getCuteSize(long byteSize){
if (byteSize/1024.0/1024.0/1024.0 > 1)
return String.format("%.2f", byteSize/1024.0/1024.0/1024.0)+" GB";
return String.format(Locale.getDefault(), "%.2f", byteSize/1024.0/1024.0/1024.0)+" GB";
else if (byteSize/1024.0/1024.0 > 1)
return String.format("%.2f", byteSize/1024.0/1024.0)+" MB";
return String.format(Locale.getDefault(), "%.2f", byteSize/1024.0/1024.0)+" MB";
else
return String.format("%.2f", byteSize/1024.0)+" kB";
return String.format(Locale.getDefault(), "%.2f", byteSize/1024.0)+" kB";
}
public NSPElement getData(){

View file

@ -22,8 +22,4 @@
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer"
/>
<!--
-->
</androidx.drawerlayout.widget.DrawerLayout>

View file

@ -45,7 +45,7 @@
android:layout_marginEnd="4dp"
android:layout_marginRight="4dp"
android:layout_marginBottom="8dp"
android:drawableTop="@drawable/ic_file_select_file"
app:drawableTopCompat="@drawable/ic_select_file"
android:text="@string/select_file_btn"
android:theme="@style/ControlButton"
app:layout_constraintBottom_toBottomOf="parent"
@ -61,7 +61,7 @@
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:drawableTop="@drawable/ic_upload_btn"
app:drawableTopCompat="@drawable/ic_upload_btn"
android:text="@string/upload_btn"
android:theme="@style/ControlButton"
app:layout_constraintBottom_toBottomOf="parent"

View file

@ -4,7 +4,7 @@
<string name="popup_non_supported_format">Тип файла не поддерживается</string>
<string name="popup_error">Ошибка</string>
<string name="upload_btn">Отправить в NS</string>
<string name="install_file_explorer">Не установлено ни одного файлового менеджера.\n Пожалуйста установите один. Например Total Commander.</string>
<string name="install_file_explorer">Не установлено ни одного файлового менеджера.\nПожалуйста установите один. Например Total Commander.</string>
<string name="ns_connected_info">NS подключён</string>
<string name="notification_chan_name_usb">Устройство подключено</string>
<string name="notification_chan_desc_usb">Уведомление повяляется когда пользователь подключает NS к устройству</string>

View file

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name" translatable="false">NS-USBloader</string>
<string name="select_file_btn">選擇檔案</string>
<string name="popup_non_supported_format">所選的檔案格式尚未支援</string>
<string name="popup_error">錯誤</string>
<string name="upload_btn">上傳至NS</string>
<string name="install_file_explorer">裝置沒有安裝檔案管理器.\\n 請至PLAY商店內安裝檔案管理器. 例如:Total Commander</string>
<string name="ns_connected_info">NS已連接</string>
<string name="notification_chan_name_usb">已連線的裝置</string>
<string name="notification_chan_desc_usb">當使用者將行動裝置與NS連線時進行系統通知</string>
<string name="ns_not_found_in_connected">在已連線的裝置內沒有找到NS.</string>
<string name="transfer_protocol">通訊協定</string>
<string name="transfer_transport">傳輸層</string>
<string name="nothing_selected_message">尚未選取任何項目</string>
<string name="transfers_service_stopped">資料傳輸程序已被中斷.</string>
<string name="interrupt_btn">中斷</string>
<string name="navigation_drawer_open">開啟側邊選單</string>
<string name="navigation_drawer_close">關閉側邊選單</string>
<string name="tf_usb" translatable="false">TinFoil USB</string>
<string name="gl" translatable="false">GoldLeaf v0.5</string>
<string name="tf_net" translatable="false">TinFoil NET</string>
<string name="about_app">關於此程式</string>
<string name="other">其他</string>
<string name="one_item_for_gl_notification">透過GoldLeaf v0.5連線時僅可單獨選取一個檔案來進行傳輸</string>
<string name="no_protocol_selected_message">尚未選擇通訊協定</string>
<string name="title_activity_about">程式相關說明</string>
<string name="about_line_1" translatable="false">NS-USBloader mobile</string>
<string name="about_line_2">本程式<a href="https://www.gnu.org/licenses/gpl-3.0.html">依據GNU公共授權條款GPLv3(或更新版本)</a>開發.</string>
<string name="about_line_3">程式開發: Dmitry Isaenko.</string>
<string name="about_line_4">程式首頁: <a href="https://github.com/developersu/ns-usbloader-mobile">https://github.com/developersu/ns-usbloader-mobile</a></string>
<string name="about_line_5">翻譯人員: 會在程式首頁內提供本程式介面在地化翻譯的人員名單.</string>
<string name="about_line_6">如果本程式對你有助益,請在程式的GitHub頁面上按星號加分,也歡迎贊助我們(金額隨意) <a href="https://www.paypal.me/developersu">paypal.me/developersu</a>, <a href="https://money.yandex.ru/to/410014301951665">Yandex.Money</a>. More information on home page.</string>
<string name="popup_incorrect_file">檔案錯誤</string>
<string name="status_failed_to_upload">(上傳失敗)</string>
<string name="status_wrong_file">(NSP壞檔)</string>
<string name="status_uploaded">(已上傳)</string>
<string name="status_unkown" translatable="false">(?)</string>
<string name="settings">設定</string>
<string name="title_activity_settings">設定</string>
<string name="settings_nsIp" translatable="false">NS IP</string>
<string name="settings_phone_ip">手機 IP</string>
<string name="settings_phone_port">手機連接埠</string>
<string name="settings_autodtct_phn_ip">自動偵測手機 IP</string>
<string name="unknown_protocol_error">已選取未知的通訊協定 (?)</string>
<string name="notification_transfer_in_progress">正在進行資料傳輸</string>
<string name="notification_chan_name_progress">正在進行傳輸</string>
<string name="notification_chan_desc_progress">在通知欄顯示傳輸檔案進度</string>
</resources>

View file

@ -4,7 +4,7 @@
<string name="popup_non_supported_format">File type not supported</string>
<string name="popup_error">Error</string>
<string name="upload_btn">Upload to NS</string>
<string name="install_file_explorer">No file explorer installed.\\n Please install one. For example Total Commander.</string>
<string name="install_file_explorer">No file explorer installed.\nPlease install one. For example Total Commander.</string>
<string name="ns_connected_info">NS Connected</string>
<string name="notification_chan_name_usb">Device connected</string>
<string name="notification_chan_desc_usb">Notification appears when user connects NS to device</string>

View file

@ -7,7 +7,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.android.tools.build:gradle:4.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files

View file

@ -1,6 +1,6 @@
#Mon Mar 23 02:19:51 MSK 2020
#Mon Aug 03 11:11:52 MSK 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip