-
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.
release 0.1.1 alpha work in progress
- Loading branch information
1 parent
d655ba7
commit af471d6
Showing
50 changed files
with
1,657 additions
and
632 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 |
---|---|---|
|
@@ -21,3 +21,4 @@ test | |
testfiles | ||
testfiles/testrep2.git/ | ||
tools | ||
Lowu/app/src/main/java/taiposwig |
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,5 @@ | ||
<root> | ||
<item name='android.content.SharedPreferences'> | ||
<annotation name='java.lang.Deprecated' /> | ||
</item> | ||
</root> |
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,12 +1,13 @@ | ||
/* 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 android.app.Activity; | ||
import android.content.Intent; | ||
import android.content.SharedPreferences; | ||
import android.os.Bundle; | ||
import android.preference.PreferenceManager; | ||
import android.util.Log; | ||
import android.view.Menu; | ||
import android.view.MenuItem; | ||
|
@@ -29,8 +30,9 @@ public class MainActivity extends AppCompatActivity { | |
} | ||
|
||
private taiposwig.SWIGTYPE_p_LowuData td; | ||
String TAG = "fanling10"; | ||
private final static String TAG = "fanling10"; | ||
private WebView mWebView; | ||
private static final int RESULT_SETTINGS = 1; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
|
@@ -41,39 +43,20 @@ protected void onCreate(Bundle savedInstanceState) { | |
toolbar.setTitle("Fanling10"); | ||
setSupportActionBar(toolbar); | ||
|
||
Log.d(TAG, "making data..."); | ||
JSONObject json = new JSONObject(); | ||
try { | ||
json.put("database_path", getApplicationContext().getDataDir() + "/search.db"); | ||
//json.put("database_path", getApplicationContext().getDataDir() + "/test2.db"); | ||
json.put("git_path", getApplicationContext().getDataDir() + "/test2.git"); | ||
//json.put("git_path", getApplicationContext().getDataDir() + "/store.git"); | ||
json.put("branch", "master"); | ||
json.put("have_url", true); | ||
json.put("url", "[email protected]:martin/data1.git"); | ||
//json.put("url", "[email protected]:fanling/testrep2.git"); | ||
json.put("name", "martin"); | ||
json.put("email", "[email protected]"); | ||
json.put("unique_prefix", "x"); | ||
json.put("ssh_path", getApplicationContext().getDataDir() + "/id_rsa"); | ||
json.put("slurp_ssh", true); | ||
} catch (JSONException e) { | ||
e.printStackTrace(); | ||
} | ||
setInitialPreferencesIfRequired(); | ||
|
||
td = taiposwig.taiposwig.make_data(json.toString()); | ||
Log.d(TAG, "making data..."); | ||
td = taiposwig.taiposwig.make_data(jsonOptions().toString()); | ||
Log.d(TAG, "data made."); | ||
|
||
// mWebView = new WebView(this); | ||
WebView mWebView = findViewById(R.id.webview); | ||
WebView mWebView = findViewById(R.id.webview); | ||
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()); | ||
|
||
// setContentView(mWebView); | ||
Log.d(TAG, "web view set"); | ||
Log.d(TAG, "web view set"); | ||
String ih = taiposwig.taiposwig.initial_html(td); | ||
Log.d(TAG, "have initial html"); | ||
// Log.d(TAG, "initial html: "+ih); | ||
|
@@ -84,19 +67,85 @@ protected void onCreate(Bundle savedInstanceState) { | |
Log.d(TAG, "on create done"); | ||
} | ||
|
||
void setInitialPreferencesIfRequired() { | ||
Log.d(TAG, "setting initial preferences..."); | ||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); | ||
Log.d(TAG, "in main using: " + PreferenceManager.getDefaultSharedPreferencesName(getBaseContext())); | ||
if (sp.getString("unique_prefix", "") == "") { | ||
SharedPreferences.Editor ed = sp.edit(); | ||
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", "[email protected]: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.putBoolean("slurp_ssh", true); | ||
ed.apply(); | ||
Log.d(TAG, "set initial preferences."); | ||
} else { | ||
Log.d(TAG, "preferences already set"); | ||
} | ||
} | ||
|
||
JSONObject jsonOptions() { | ||
Log.d(TAG, "setting options..."); | ||
JSONObject json = new JSONObject(); | ||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); | ||
Log.d(TAG, "in main using: " + PreferenceManager.getDefaultSharedPreferencesName(getBaseContext())); | ||
try { | ||
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("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("slurp_ssh", sp.getBoolean("slurp_ssh", true)); | ||
Log.d(TAG, "options set, prefix is " + sp.getString("unique_prefix", "??")); | ||
} catch (JSONException e) { | ||
e.printStackTrace(); | ||
} | ||
return json; | ||
} | ||
|
||
@Override | ||
protected void onPause() { | ||
Log.d(TAG, "pausing..."); | ||
taiposwig.taiposwig.handle_event(td, CCycleEvent.Pause); | ||
super.onPause(); | ||
} | ||
|
||
@Override | ||
protected void onResume() { | ||
Log.d(TAG, "resuming..."); | ||
taiposwig.taiposwig.handle_event(td, CCycleEvent.Resume); | ||
super.onResume(); | ||
} | ||
|
||
@Override | ||
protected void onStart() { | ||
Log.d(TAG, "starting..."); | ||
super.onStart(); | ||
} | ||
|
||
@Override | ||
protected void onRestart() { | ||
Log.d(TAG, "restarting..."); | ||
super.onRestart(); | ||
} | ||
|
||
@Override | ||
protected void onStop() { | ||
Log.d(TAG, "stopping..."); | ||
taiposwig.taiposwig.handle_event(td, CCycleEvent.Stop); | ||
super.onStop(); | ||
} | ||
|
||
@Override | ||
public boolean onCreateOptionsMenu(Menu menu) { | ||
// Inflate the menu; this adds items to the action bar if it is present. | ||
|
@@ -114,26 +163,52 @@ public boolean onOptionsItemSelected(MenuItem item) { | |
case R.id.menuSettings: | ||
Log.d(TAG, "settings clicked"); | ||
Intent intent = new Intent(MainActivity.this, PreferencesActivity.class); | ||
startActivity(intent); | ||
startActivityForResult(intent, RESULT_SETTINGS); | ||
break; | ||
default: | ||
Log.d(TAG, "some menu option selected"); | ||
} | ||
return super.onOptionsItemSelected(item); | ||
} | ||
|
||
@Override | ||
protected void onActivityResult(int requestCode, int resultCode, Intent data) { | ||
super.onActivityResult(requestCode, resultCode, data); | ||
|
||
switch (requestCode) { | ||
case RESULT_SETTINGS: | ||
switch (resultCode) { | ||
case PreferencesActivity.NOT_CHANGED_RESULT: | ||
Log.d(TAG, "settings done, not changed result"); | ||
break; | ||
case PreferencesActivity.CHANGED_RESULT: | ||
Log.d(TAG, "settings done, changed result"); | ||
Intent i = new Intent(MainActivity.this, MainActivity.class); | ||
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); | ||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | ||
MainActivity.this.startActivity(i); | ||
break; | ||
default: | ||
Log.d(TAG, "settings done, unknown result " + resultCode); | ||
break; | ||
} | ||
break; | ||
default: | ||
throw new IllegalStateException("Unexpected value: " + requestCode); | ||
} | ||
} | ||
|
||
@Override | ||
protected void onDestroy() { | ||
taiposwig.taiposwig.handle_event(td, CCycleEvent.Stop); | ||
Log.d(TAG, "on destroy, releasing rust data..."); | ||
taiposwig.taiposwig.handle_event(td, CCycleEvent.Destroy); | ||
Log.d(TAG, "on destroy, releasing rust data (" + (isFinishing() ? "finishing" : "not finishing") + ")..."); | ||
taiposwig.taiposwig.delete_data(td); | ||
super.onDestroy(); | ||
Log.d(TAG, "done."); | ||
} | ||
|
||
class WebAppInterface { | ||
WebAppInterface(Activity a) { | ||
// mActivity = a; | ||
} | ||
|
||
@JavascriptInterface | ||
|
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
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
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.