-
-
Notifications
You must be signed in to change notification settings - Fork 335
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dialog_rotation_fixes' of https://github.com/bitmold/orbot
- Loading branch information
Showing
5 changed files
with
274 additions
and
181 deletions.
There are no files selected for viewing
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
90 changes: 90 additions & 0 deletions
90
app/src/main/java/org/torproject/android/ui/dialog/AboutDialogFragment.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 |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package org.torproject.android.ui.dialog; | ||
|
||
import android.app.AlertDialog; | ||
import android.app.Dialog; | ||
import android.content.Context; | ||
import android.content.pm.PackageManager; | ||
import android.os.Bundle; | ||
import android.text.Html; | ||
import android.view.View; | ||
import android.widget.TextView; | ||
|
||
import androidx.fragment.app.DialogFragment; | ||
|
||
import org.torproject.android.R; | ||
import org.torproject.android.service.OrbotService; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
|
||
public class AboutDialogFragment extends DialogFragment { | ||
|
||
public static final String TAG = AboutDialogFragment.class.getSimpleName(); | ||
|
||
private TextView tvAbout; | ||
private static final String BUNDLE_KEY_TV_ABOUT_TEXT = "about_tv_txt"; | ||
|
||
@Override | ||
public Dialog onCreateDialog(Bundle savedInstanceState) { | ||
View view = getActivity().getLayoutInflater().inflate(R.layout.layout_about, null); | ||
String version; | ||
|
||
try { | ||
version = getContext().getPackageManager().getPackageInfo( | ||
getContext().getPackageName(), 0).versionName + " (Tor " + | ||
OrbotService.BINARY_TOR_VERSION + ")"; | ||
} catch (PackageManager.NameNotFoundException e) { | ||
version = "Version Not Found"; | ||
} | ||
|
||
TextView versionName = view.findViewById(R.id.versionName); | ||
versionName.setText(version); | ||
|
||
tvAbout = view.findViewById(R.id.aboutother); | ||
|
||
boolean buildAboutText = true; | ||
|
||
if (savedInstanceState != null) { | ||
String tvAboutText = savedInstanceState.getString(BUNDLE_KEY_TV_ABOUT_TEXT); | ||
if (tvAboutText != null) { | ||
buildAboutText = false; | ||
tvAbout.setText(tvAboutText); | ||
} | ||
} | ||
|
||
if (buildAboutText) { | ||
try { | ||
String aboutText = readFromAssets(getContext(), "LICENSE"); | ||
aboutText = aboutText.replace("\n", "<br/>"); | ||
tvAbout.setText(Html.fromHtml(aboutText)); | ||
} catch (IOException e) { | ||
} | ||
} | ||
return new AlertDialog.Builder(getContext()) | ||
.setTitle(getString(R.string.button_about)) | ||
.setView(view) | ||
.create(); | ||
} | ||
|
||
@SuppressWarnings("SameParameterValue") | ||
private static String readFromAssets(Context context, String filename) throws IOException { | ||
BufferedReader reader = new BufferedReader(new InputStreamReader(context.getAssets().open(filename))); | ||
|
||
// do reading, usually loop until end of file reading | ||
StringBuilder sb = new StringBuilder(); | ||
String mLine = reader.readLine(); | ||
while (mLine != null) { | ||
sb.append(mLine).append('\n'); // process line | ||
mLine = reader.readLine(); | ||
} | ||
reader.close(); | ||
return sb.toString(); | ||
} | ||
|
||
@Override | ||
public void onSaveInstanceState(Bundle outState) { | ||
super.onSaveInstanceState(outState); | ||
outState.putString(BUNDLE_KEY_TV_ABOUT_TEXT, tvAbout.getText().toString()); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
app/src/main/java/org/torproject/android/ui/dialog/MoatErrorDialogFragment.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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.torproject.android.ui.dialog; | ||
|
||
import android.app.AlertDialog; | ||
import android.app.Dialog; | ||
import android.os.Bundle; | ||
|
||
import androidx.fragment.app.DialogFragment; | ||
|
||
import org.torproject.android.R; | ||
|
||
public class MoatErrorDialogFragment extends DialogFragment { | ||
|
||
public static final String TAG = MoatErrorDialogFragment.class.getSimpleName(); | ||
private static final String BUNDLE_KEY_MSG = "msg"; | ||
|
||
public static MoatErrorDialogFragment newInstance(String message) { | ||
MoatErrorDialogFragment fragment = new MoatErrorDialogFragment(); | ||
Bundle args = new Bundle(); | ||
args.putString(BUNDLE_KEY_MSG, message); | ||
fragment.setArguments(args); | ||
return fragment; | ||
} | ||
|
||
@Override | ||
public Dialog onCreateDialog(Bundle savedInstanceState) { | ||
return new AlertDialog.Builder(getContext()) | ||
.setTitle(R.string.error) | ||
.setMessage(getArguments().getString(BUNDLE_KEY_MSG)) | ||
.setNegativeButton(R.string.btn_okay, null) | ||
.create(); | ||
} | ||
} |
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.