Improve UI
This commit is contained in:
parent
6a8f5036b2
commit
1e594574b5
4 changed files with 79 additions and 65 deletions
|
@ -36,9 +36,9 @@
|
||||||
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"></activity>
|
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"></activity>
|
||||||
<activity
|
<activity
|
||||||
android:name=".BImportActivity"
|
android:name=".BImportActivity"
|
||||||
android:label="BRouter Profile Import"
|
android:label="Import Profile"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:theme="@android:style/Theme">
|
android:theme="@android:style/Theme.NoTitleBar">
|
||||||
<!-- some apps (bluemail) do not recognize the .brf file extention, startactivity+intent is done for attachement with text/plain -->
|
<!-- some apps (bluemail) do not recognize the .brf file extention, startactivity+intent is done for attachement with text/plain -->
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.VIEW" />
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
|
|
@ -7,7 +7,9 @@ import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.provider.OpenableColumns;
|
import android.provider.OpenableColumns;
|
||||||
import android.text.format.Formatter;
|
import android.text.format.Formatter;
|
||||||
import android.widget.TextView;
|
import android.widget.Button;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
@ -21,14 +23,28 @@ import java.io.InputStreamReader;
|
||||||
public class BImportActivity extends Activity {
|
public class BImportActivity extends Activity {
|
||||||
// profile size is generally < 30 kb, so set max size to 100 kb
|
// profile size is generally < 30 kb, so set max size to 100 kb
|
||||||
private static final int MAX_PROFILE_SIZE = 100000;
|
private static final int MAX_PROFILE_SIZE = 100000;
|
||||||
TextView mImportResultView;
|
private EditText mTextFilename;
|
||||||
|
private Button mButtonImport;
|
||||||
|
private String mProfileData;
|
||||||
|
private EditText mTextProfile;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
setContentView(R.layout.import_intent);
|
setContentView(R.layout.import_intent);
|
||||||
mImportResultView = findViewById(R.id.Info_brouter);
|
mTextFilename = findViewById(R.id.editTextFilename);
|
||||||
|
mButtonImport = findViewById(R.id.buttonImport);
|
||||||
|
mButtonImport.setEnabled(false);
|
||||||
|
mButtonImport.setOnClickListener(view -> {
|
||||||
|
String filename = mTextFilename.getText().toString();
|
||||||
|
if (isValidProfileFilename(filename)) {
|
||||||
|
writeProfile(filename, mProfileData);
|
||||||
|
} else {
|
||||||
|
displayMessage("ERROR: File extention must be \".brf\"\n");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mTextProfile = findViewById(R.id.editTextProfile);
|
||||||
|
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
String action = intent.getAction();
|
String action = intent.getAction();
|
||||||
|
@ -37,17 +53,17 @@ public class BImportActivity extends Activity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isValidProfileFilename(String filename) {
|
||||||
|
return filename.endsWith(".brf");
|
||||||
|
}
|
||||||
|
|
||||||
private void importProfile(Intent intent) {
|
private void importProfile(Intent intent) {
|
||||||
StringBuilder resultMessage = new StringBuilder();
|
|
||||||
if (intent.getData() == null) {
|
if (intent.getData() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setContentView(R.layout.import_intent);
|
|
||||||
mImportResultView = findViewById(R.id.Info_brouter);
|
|
||||||
mImportResultView.setText("Start importing profile: \n");
|
|
||||||
|
|
||||||
|
StringBuilder resultMessage = new StringBuilder();
|
||||||
Uri dataUri = intent.getData();
|
Uri dataUri = intent.getData();
|
||||||
System.out.println("Brouter DATA=" + dataUri);
|
|
||||||
|
|
||||||
// by some apps (bluemail) the file name must be "extracted" from the URI, as example with the following code
|
// by some apps (bluemail) the file name must be "extracted" from the URI, as example with the following code
|
||||||
// see https://stackoverflow.com/questions/14364091/retrieve-file-path-from-caught-downloadmanager-intent
|
// see https://stackoverflow.com/questions/14364091/retrieve-file-path-from-caught-downloadmanager-intent
|
||||||
|
@ -61,24 +77,21 @@ public class BImportActivity extends Activity {
|
||||||
filesize = cursor.getLong(cursor.getColumnIndex(OpenableColumns.SIZE));
|
filesize = cursor.getLong(cursor.getColumnIndex(OpenableColumns.SIZE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.println("Brouter filename=" + filename + "\n file size=" + filesize);
|
|
||||||
resultMessage.append("File name=").append(filename).append("\n");
|
|
||||||
resultMessage.append("File size=").append(Formatter.formatFileSize(this, filesize)).append(" bytes\n");
|
|
||||||
mImportResultView.setText(resultMessage);
|
|
||||||
// is the file extention ".brf" in the file name
|
// is the file extention ".brf" in the file name
|
||||||
if (filename == null || !filename.endsWith(".brf")) {
|
if (filename == null || !isValidProfileFilename(filename)) {
|
||||||
resultMessage.append("ERROR: File extention must be \".brf\"\n");
|
resultMessage.append("ERROR: File extention must be \".brf\"\n");
|
||||||
mImportResultView.setText(resultMessage);
|
displayMessage(resultMessage.toString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filesize > MAX_PROFILE_SIZE) {
|
if (filesize > MAX_PROFILE_SIZE) {
|
||||||
resultMessage.append("ERROR: File size exceeds limit (").append(Formatter.formatFileSize(this, MAX_PROFILE_SIZE)).append(")\n");
|
String errorMessage = String.format("ERROR: File size (%s) exceeds limit (%s)\n",
|
||||||
mImportResultView.setText(resultMessage);
|
Formatter.formatFileSize(this, filesize),
|
||||||
|
Formatter.formatFileSize(this, MAX_PROFILE_SIZE));
|
||||||
|
displayMessage(errorMessage);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String profileData = "";
|
|
||||||
try (
|
try (
|
||||||
InputStream inputStream = getContentResolver().openInputStream(dataUri);
|
InputStream inputStream = getContentResolver().openInputStream(dataUri);
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream))) {
|
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream))) {
|
||||||
|
@ -90,20 +103,25 @@ public class BImportActivity extends Activity {
|
||||||
sb.append(System.getProperty("line.separator"));
|
sb.append(System.getProperty("line.separator"));
|
||||||
line = br.readLine();
|
line = br.readLine();
|
||||||
}
|
}
|
||||||
profileData = sb.toString();
|
mProfileData = sb.toString();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println(e);
|
resultMessage.append(String.format("ERROR: failed to load profile content (%S)", e.getMessage()));
|
||||||
resultMessage.append("ERROR: " + e + "\n");
|
displayMessage(resultMessage.toString());
|
||||||
mImportResultView.setText(resultMessage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!profileData.contains("highway=") || (!profileData.contains("costfactor")) || (!profileData.contains("---context:global"))) {
|
if (!mProfileData.contains("highway=") || (!mProfileData.contains("costfactor")) || (!mProfileData.contains("---context:global"))) {
|
||||||
resultMessage.append("ERROR: this file is not a valid brouter-profile\n");
|
resultMessage.append("ERROR: this file is not a valid brouter-profile\n");
|
||||||
mImportResultView.setText(resultMessage);
|
displayMessage(resultMessage.toString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
writeProfile(filename, profileData);
|
mTextFilename.setText(filename);
|
||||||
|
mTextProfile.setText(mProfileData);
|
||||||
|
mButtonImport.setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void displayMessage(String message) {
|
||||||
|
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeProfile(String filename, String profileData) {
|
void writeProfile(String filename, String profileData) {
|
||||||
|
@ -114,13 +132,9 @@ public class BImportActivity extends Activity {
|
||||||
FileOutputStream stream = new FileOutputStream(file);
|
FileOutputStream stream = new FileOutputStream(file);
|
||||||
stream.write(profileData.getBytes());
|
stream.write(profileData.getBytes());
|
||||||
stream.close();
|
stream.close();
|
||||||
System.out.println("Brouter: profile was installed in ./brouter/profiles2");
|
displayMessage("Profile successfully imported");
|
||||||
// report success in UI and stop
|
|
||||||
mImportResultView.setText(mImportResultView.getText() + "Profile successfully imported into:\n" + baseDir + "brouter/profiles2/" + filename + " \n\nIt can be used now in the same way as a basis profile! ");
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println("Exception, File write failed: " + e.toString());
|
displayMessage(String.format("Profile import failed: %s", e.getMessage()));
|
||||||
// report error in UI and stop
|
|
||||||
mImportResultView.setText(mImportResultView.getText() + "ERROR: " + e + " \n");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,45 +1,43 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="8dp"
|
||||||
tools:context=".BImportActivity">
|
tools:context=".BImportActivity">
|
||||||
|
|
||||||
|
<Button
|
||||||
<TextView
|
android:id="@+id/buttonImport"
|
||||||
android:id="@+id/Info_brouter"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="377dp"
|
|
||||||
android:layout_below="@+id/textView3"
|
|
||||||
android:layout_alignParentStart="true"
|
|
||||||
android:layout_alignParentLeft="true"
|
|
||||||
android:layout_alignParentEnd="true"
|
|
||||||
android:layout_alignParentRight="true"
|
|
||||||
android:layout_marginStart="22dp"
|
|
||||||
android:layout_marginLeft="22dp"
|
|
||||||
android:layout_marginTop="13dp"
|
|
||||||
android:layout_marginEnd="18dp"
|
|
||||||
android:layout_marginRight="18dp"
|
|
||||||
android:background="@android:color/holo_blue_dark"
|
|
||||||
android:text="....."
|
|
||||||
android:textSize="20sp" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/textView3"
|
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentStart="true"
|
|
||||||
android:layout_alignParentLeft="true"
|
|
||||||
android:layout_alignParentEnd="true"
|
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
android:layout_marginStart="95dp"
|
android:layout_alignParentBottom="true"
|
||||||
android:layout_marginLeft="95dp"
|
android:text="@string/import_profile"
|
||||||
android:layout_marginTop="55dp"
|
android:layout_alignParentEnd="true" />
|
||||||
android:layout_marginEnd="98dp"
|
|
||||||
android:layout_marginRight="98dp"
|
<EditText
|
||||||
android:text="BROUTER"
|
android:id="@+id/editTextFilename"
|
||||||
android:textSize="34sp" />
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="8dp"
|
||||||
|
android:ems="10"
|
||||||
|
android:hint="@string/profile_filename_example"
|
||||||
|
android:importantForAutofill="no"
|
||||||
|
android:inputType="textUri"
|
||||||
|
android:minHeight="48dp" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/editTextProfile"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_above="@id/buttonImport"
|
||||||
|
android:layout_below="@id/editTextFilename"
|
||||||
|
android:ems="8"
|
||||||
|
android:enabled="false"
|
||||||
|
android:gravity="start|top"
|
||||||
|
android:inputType="none"
|
||||||
|
android:minHeight="48dp"
|
||||||
|
android:importantForAutofill="no" />
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
|
|
|
@ -16,4 +16,6 @@
|
||||||
|
|
||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">BRouter</string>
|
<string name="app_name">BRouter</string>
|
||||||
|
<string name="import_profile">Import Profile</string>
|
||||||
|
<string name="profile_filename_example">filename.brf</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in a new issue