-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bcdb464
commit 20d4520
Showing
35 changed files
with
482 additions
and
166 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
"??" | ||
**/?? | ||
**/"??" | ||
**/#*# | ||
**/*.rs.bk | ||
**/.#* | ||
|
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
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
65 changes: 65 additions & 0 deletions
65
Lowu/app/src/main/java/hk/jennyemily/work/lowu/LoadSSHActivity.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,65 @@ | ||
package hk.jennyemily.work.lowu; | ||
|
||
import android.content.Context; | ||
import android.content.SharedPreferences; | ||
import android.os.Bundle; | ||
import android.preference.PreferenceManager; | ||
import android.util.Log; | ||
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.OutputStreamWriter; | ||
|
||
import androidx.appcompat.app.AppCompatActivity; | ||
import androidx.appcompat.widget.Toolbar; | ||
|
||
public class LoadSSHActivity extends AppCompatActivity { | ||
private final static String TAG = "fanling10-load-SSH"; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_load_ssh); | ||
final Toolbar toolbar = findViewById(R.id.toolbar); | ||
setSupportActionBar(toolbar); | ||
final Button button = (Button) findViewById(R.id.buttonAddFiles); | ||
button.setOnClickListener(new View.OnClickListener() { | ||
public void onClick(View v) { | ||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); | ||
final String ssh_path = sp.getString("ssh_path", "??"); | ||
if (ssh_path != "??") { | ||
final Context context = getApplicationContext(); | ||
uploadUsingEditText(R.id.editTextPrivateKey, ssh_path, context); | ||
uploadUsingEditText(R.id.editTextPublicKey, ssh_path + ".pub", context); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
private void uploadUsingEditText(int id, String filePath, Context context) { | ||
final EditText editText = (EditText) findViewById(id); | ||
final String key = editText.getText().toString(); | ||
writeToFile(filePath, key, context); | ||
} | ||
|
||
private void writeToFile(String filePath, String data, Context context) { | ||
try { | ||
Log.d(TAG, "Writing to " + filePath + "..."); | ||
File file = new File(getFilesDir(), filePath); | ||
Log.d(TAG, "Writing to " + file.getAbsolutePath() +"..."); | ||
FileOutputStream fileOutputStream = new FileOutputStream(file); | ||
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream); | ||
Log.d(TAG, "Writing '" + data.substring(0, 20) + "'..."); | ||
outputStreamWriter.write(data); | ||
outputStreamWriter.close(); | ||
Log.d(TAG, "Written to " + filePath + "."); | ||
} catch ( | ||
IOException e) { | ||
Log.e("Exception", "File write failed: " + e.toString()); | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -51,17 +51,20 @@ protected void onCreate(Bundle savedInstanceState) { | |
setInitialPreferencesIfRequired(); | ||
|
||
Log.d(TAG, "making data..."); | ||
td = taiposwig.taiposwig.make_data(jsonOptions().toString()); | ||
final String optionsString = jsonOptions().toString(); | ||
Log.d(TAG, "options as JSON: " + optionsString); | ||
td = taiposwig.taiposwig.make_data(optionsString); | ||
Log.d(TAG, "data made."); | ||
|
||
mWebView = findViewById(R.id.webview); | ||
mWebView.setVerticalScrollBarEnabled(true); | ||
WebSettings webSettings = mWebView.getSettings(); | ||
webSettings.setJavaScriptEnabled(true); | ||
mWebView.addJavascriptInterface(new WebAppInterface(this), "taipo"); | ||
//!!! add some code here to set platform-specific javascript (look at the PC version) | ||
mWebView.setWebViewClient(new WebViewClient()); | ||
Log.d(TAG, "web view set"); | ||
// if (savedInstanceState != null) mWebView.restoreState(savedInstanceState); | ||
// if (savedInstanceState != null) mWebView.restoreState(savedInstanceState); | ||
if (appStatus.equals("initial")) { | ||
String ih = taiposwig.taiposwig.initial_html(td); | ||
Log.d(TAG, "have initial html, displaying..."); | ||
|
@@ -79,15 +82,16 @@ void setInitialPreferencesIfRequired() { | |
Log.d(TAG, "in main using: " + PreferenceManager.getDefaultSharedPreferencesName(getBaseContext())); | ||
if (sp.getString("unique_prefix", "") == "") { | ||
SharedPreferences.Editor ed = sp.edit(); | ||
ed.putBoolean("correct", false); | ||
ed.putString("database_path", getApplicationContext().getDataDir() + "/search.db"); | ||
ed.putString("git_path", getApplicationContext().getDataDir() + "/test2.git"); | ||
ed.putString("git_branch", "master"); | ||
ed.putBoolean("git_has_url", true); | ||
ed.putString("git_url", "git@test.jennyemily.hk:martin/data1.git"); | ||
ed.putString("git_branch", "main"); | ||
ed.putBoolean("git_has_url", false); | ||
ed.putString("git_url", "git@work.jennyemily.hk:martin/data1.git"); | ||
ed.putString("git_name", "martin"); | ||
ed.putString("git_email", "[email protected]"); | ||
ed.putString("unique_prefix", "x"); | ||
ed.putString("ssh_path", getApplicationContext().getDataDir() + "/id_rsa"); | ||
ed.putString("ssh_path", "id_rsa"); | ||
ed.putBoolean("slurp_ssh", true); | ||
ed.putBoolean("auto_link", false); | ||
ed.apply(); | ||
|
@@ -103,18 +107,20 @@ JSONObject jsonOptions() { | |
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); | ||
Log.d(TAG, "in main using: " + PreferenceManager.getDefaultSharedPreferencesName(getBaseContext())); | ||
try { | ||
json.put("correct", sp.getBoolean("correct", false)); | ||
json.put("database_path", sp.getString("database_path", "??")); | ||
json.put("git_path", sp.getString("git_path", "??")); | ||
json.put("branch", sp.getString("git_branch", "??")); | ||
json.put("have_url", sp.getBoolean("git_have_url", false)); | ||
json.put("have_url", sp.getBoolean("git_has_url", false)); | ||
json.put("url", sp.getString("git_url", "??")); | ||
json.put("name", sp.getString("git_name", "??")); | ||
json.put("email", sp.getString("git_email", "??")); | ||
json.put("unique_prefix", sp.getString("unique_prefix", "??")); | ||
json.put("ssh_path", sp.getString("ssh_path", "??")); | ||
json.put("ssh_path", getApplicationContext().getFilesDir() + "/" + sp.getString("ssh_path", "??")); | ||
json.put("slurp_ssh", sp.getBoolean("slurp_ssh", true)); | ||
json.put("auto_link", sp.getBoolean("auto_link", false)); | ||
Log.d(TAG, "options set, prefix is " + sp.getString("unique_prefix", "??")); | ||
Log.d(TAG, "options set, prefix is " + sp.getString("unique_prefix", "??") + ", " + ( | ||
sp.getBoolean("git_have_url", false) ? "no url" : ("url is " + sp.getString("git_url", "??")))); | ||
} catch (JSONException e) { | ||
e.printStackTrace(); | ||
} | ||
|
@@ -128,15 +134,15 @@ public void onRestoreInstanceState(Bundle savedState) { | |
String restoredState = savedState.getString(APP_STATUS); | ||
if (restoredState != appStatus) | ||
Log.e(TAG, "restored state is " + restoredState + " but current state is " + appStatus); | ||
mWebView.restoreState(savedState); | ||
mWebView.restoreState(savedState); | ||
} | ||
|
||
@Override | ||
public void onSaveInstanceState(Bundle outState) { | ||
Log.d(TAG, "saving instance state..."); | ||
outState.putString(APP_STATUS, appStatus); | ||
if (mWebView == null) Log.e(TAG, "no web view, cannot save"); | ||
else mWebView.saveState(outState); | ||
if (mWebView == null) Log.e(TAG, "no web view, cannot save"); | ||
else mWebView.saveState(outState); | ||
super.onSaveInstanceState(outState); | ||
} | ||
|
||
|
@@ -182,15 +188,17 @@ public boolean onCreateOptionsMenu(Menu menu) { | |
|
||
@Override | ||
public boolean onOptionsItemSelected(MenuItem item) { | ||
// Handle action bar item clicks here. The action bar will | ||
// automatically handle clicks on the Home/Up button, so long | ||
// as you specify a parent activity in AndroidManifest.xml. | ||
int id = item.getItemId(); | ||
switch (id) { | ||
case R.id.menuSettings: | ||
Log.d(TAG, "settings clicked"); | ||
Intent intent = new Intent(MainActivity.this, PreferencesActivity.class); | ||
startActivityForResult(intent, RESULT_SETTINGS); | ||
Intent intentPreferences = new Intent(MainActivity.this, PreferencesActivity.class); | ||
startActivityForResult(intentPreferences, RESULT_SETTINGS); | ||
break; | ||
case R.id.menuLoadSSH: | ||
Log.d(TAG, "load files clicked"); | ||
Intent intentLoadFiles = new Intent(MainActivity.this, LoadSSHActivity.class); | ||
startActivity(intentLoadFiles); | ||
break; | ||
default: | ||
Log.d(TAG, "some menu option selected"); | ||
|
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
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,25 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.coordinatorlayout.widget.CoordinatorLayout 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" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".LoadSSHActivity"> | ||
|
||
<com.google.android.material.appbar.AppBarLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:theme="@style/AppTheme.AppBarOverlay"> | ||
|
||
<androidx.appcompat.widget.Toolbar | ||
android:id="@+id/toolbar" | ||
android:layout_width="match_parent" | ||
android:layout_height="?attr/actionBarSize" | ||
android:background="?attr/colorPrimary" | ||
app:popupTheme="@style/AppTheme.PopupOverlay" /> | ||
|
||
</com.google.android.material.appbar.AppBarLayout> | ||
|
||
<include layout="@layout/content_load_ssh" /> | ||
|
||
</androidx.coordinatorlayout.widget.CoordinatorLayout> |
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,35 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<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" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
app:layout_behavior="@string/appbar_scrolling_view_behavior" | ||
tools:context=".LoadSSHActivity" | ||
tools:showIn="@layout/activity_load_ssh"> | ||
|
||
<EditText | ||
android:id="@+id/editTextPrivateKey" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_alignParentTop="true" | ||
android:hint="Enter the SSH private key here" | ||
android:inputType="textMultiLine" | ||
android:lines="5" /> | ||
|
||
<EditText | ||
android:id="@+id/editTextPublicKey" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_below="@id/editTextPrivateKey" | ||
android:hint="Enter the SSH public key here" | ||
android:inputType="textMultiLine" | ||
android:lines="5" /> | ||
|
||
<Button | ||
android:id="@+id/buttonAddFiles" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_below="@id/editTextPublicKey" | ||
android:text="Set keys" /> | ||
</RelativeLayout> |
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 |
---|---|---|
@@ -1,10 +1,13 @@ | ||
<menu 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" | ||
tools:context="hk.jennyemily.work.lowu.MainActivity"> | ||
|
||
<item | ||
android:id="@+id/menuSettings" | ||
android:orderInCategory="100" | ||
android:title="Settings" /> | ||
<item | ||
android:id="@+id/menuLoadSSH" | ||
android:orderInCategory="110" | ||
android:title="Load SSH keys" /> | ||
</menu> |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
<resources> | ||
<string name="app_name">Lowu</string> | ||
<string name="action_settings">Settings</string> | ||
<string name="title_activity_preferences">PreferencesActivity</string> | ||
<string name="title_activity_preferences">Preferences</string> | ||
<string name="title_activity_load_ssh">Load SSH keys</string> | ||
</resources> |
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
21 changes: 21 additions & 0 deletions
21
Lowu/app/src/test/java/hk/jennyemily/work/lowu/ExampleUnitTest.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,21 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
License, v. 2.0. If a copy of the MPL was not distributed with this | ||
file, You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
package hk.jennyemily.work.lowu; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Example local unit test, which will execute on the development machine (host). | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
public class ExampleUnitTest { | ||
@Test | ||
public void addition_isCorrect() { | ||
assertEquals(4, 2 + 2); | ||
} | ||
} |
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
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.