diff --git a/app/src/main/java/com/termux/app/TermuxActivity.java b/app/src/main/java/com/termux/app/TermuxActivity.java index 7bf806be1e..50cf6b2192 100644 --- a/app/src/main/java/com/termux/app/TermuxActivity.java +++ b/app/src/main/java/com/termux/app/TermuxActivity.java @@ -33,6 +33,7 @@ import com.termux.shared.termux.TermuxConstants; import com.termux.shared.termux.TermuxConstants.TERMUX_APP.TERMUX_ACTIVITY; import com.termux.app.activities.HelpActivity; +import com.termux.app.activities.ContribActivity; import com.termux.app.activities.SettingsActivity; import com.termux.shared.settings.preferences.TermuxAppSharedPreferences; import com.termux.app.terminal.TermuxSessionsListViewController; @@ -539,6 +540,7 @@ public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuIn menu.add(Menu.NONE, CONTEXT_MENU_HELP_ID, Menu.NONE, R.string.action_open_help); menu.add(Menu.NONE, CONTEXT_MENU_SETTINGS_ID, Menu.NONE, R.string.action_open_settings); menu.add(Menu.NONE, CONTEXT_MENU_REPORT_ID, Menu.NONE, R.string.action_report_issue); + menu.add(Menu.NONE, CONTEXT_MENU_CONTRIBUTING_ID, Menu.NONE, R.string.action_contribute); } /** Hook system menu to show context menu instead. */ @@ -583,6 +585,9 @@ public boolean onContextItemSelected(MenuItem item) { case CONTEXT_MENU_REPORT_ID: mTermuxTerminalViewClient.reportIssueFromTranscript(); return true; + case CONTEXT_MENU_CONTRIBUTING_ID: + startAactivity(new Intent(this, ContibActivity.class)); + return true; default: return super.onContextItemSelected(item); } diff --git a/app/src/main/java/com/termux/app/activities/ContribActivty.java b/app/src/main/java/com/termux/app/activities/ContribActivty.java new file mode 100644 index 0000000000..22d407c310 --- /dev/null +++ b/app/src/main/java/com/termux/app/activities/ContribActivty.java @@ -0,0 +1,75 @@ +package com.termux.app.activities; + +import android.app.Activity; +import android.content.ActivityNotFoundException; +import android.content.Intent; +import android.net.Uri; +import android.os.Bundle; +import android.view.ViewGroup; +import android.webkit.WebSettings; +import android.webkit.WebView; +import android.webkit.WebViewClient; +import android.widget.ProgressBar; +import android.widget.RelativeLayout; + +/** Basic embedded browser for viewing help pages. */ +public final class ContribActivity extends Activity { + + WebView mWebView; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + final RelativeLayout progressLayout = new RelativeLayout(this); + RelativeLayout.LayoutParams lParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); + lParams.addRule(RelativeLayout.CENTER_IN_PARENT); + ProgressBar progressBar = new ProgressBar(this); + progressBar.setIndeterminate(true); + progressBar.setLayoutParams(lParams); + progressLayout.addView(progressBar); + + mWebView = new WebView(this); + WebSettings settings = mWebView.getSettings(); + settings.setCacheMode(WebSettings.LOAD_NO_CACHE); + settings.setAppCacheEnabled(false); + setContentView(progressLayout); + mWebView.clearCache(true); + + mWebView.setWebViewClient(new WebViewClient() { + @Override + public boolean shouldOverrideUrlLoading(WebView view, String url) { + if (url.startsWith("https://github.com/termux")) { + // Inline help. + setContentView(progressLayout); + return false; + } + + try { + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); + } catch (ActivityNotFoundException e) { + // Android TV does not have a system browser. + setContentView(progressLayout); + return false; + } + return true; + } + + @Override + public void onPageFinished(WebView view, String url) { + setContentView(mWebView); + } + }); + mWebView.loadUrl("https://github.com/termux/termux-packages/wiki"); + } + + @Override + public void onBackPressed() { + if (mWebView.canGoBack()) { + mWebView.goBack(); + } else { + super.onBackPressed(); + } + } + +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ca4cb76663..86d238bf41 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -75,6 +75,7 @@ Keep screen on Help Settings + Contribute Report Issue Generating Report