Skip to content

Commit

Permalink
Auto landscape when video shows, add text reflow setting and fix some…
Browse files Browse the repository at this point in the history
… bugs.
  • Loading branch information
mthli committed Jun 21, 2015
1 parent ebfd967 commit 8e42837
Show file tree
Hide file tree
Showing 14 changed files with 314 additions and 257 deletions.
485 changes: 245 additions & 240 deletions Ninja/.idea/workspace.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Ninja/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<manifest xmlns:android="http:https://schemas.android.com/apk/res/android"
package="io.github.mthli.Ninja"
android:versionCode="25"
android:versionCode="26"
android:versionName="@string/app_version">

<!-- SDK -->
Expand Down
2 changes: 1 addition & 1 deletion Ninja/res/values-fr/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,4 @@
<item>3</item>
</string-array>

</resources>
</resources>
9 changes: 8 additions & 1 deletion Ninja/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@
Contrôle de l\'omnibox
</string>
<string name="setting_summary_omnibox_control">
Glisser l'omnibox à gauche/droite pour changer d\'onglet
Glisser l\'omnibox à gauche/droite pour passer changer d\'onglet
</string>
<!-- Volume key scroll -->
<string name="setting_title_volume_control">
Expand Down Expand Up @@ -272,6 +272,13 @@
<string name="setting_summary_scroll_bar">
Afficher/Cacher la Barre de défilement dans les pages Web
</string>
<!-- Text reflow -->
<string name="setting_title_text_reflow">
Redistribution de texte
</string>
<string name="setting_summary_text_reflow">
Activer le reflux du texte
</string>
<!-- User Agent -->
<string name="setting_title_user_agent">
Agent utilisateur(User-Agent)
Expand Down
7 changes: 7 additions & 0 deletions Ninja/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,13 @@
<string name="setting_summary_scroll_bar">
允许在网页中显示滚动条
</string>
<!-- Text reflow -->
<string name="setting_title_text_reflow">
文本重排
</string>
<string name="setting_summary_text_reflow">
允许浏览器对网页文本进行调整
</string>
<!-- User Agent -->
<string name="setting_title_user_agent">
浏览器标识
Expand Down
7 changes: 7 additions & 0 deletions Ninja/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,13 @@
<string name="setting_summary_scroll_bar">
允許在網頁中顯示滾動條
</string>
<!-- Text reflow -->
<string name="setting_title_text_reflow">
文本重排
</string>
<string name="setting_summary_text_reflow">
允許浏覽器對網頁文本進行調整
</string>
<!-- User Agent -->
<string name="setting_title_user_agent">
浏覽器標識
Expand Down
7 changes: 7 additions & 0 deletions Ninja/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,13 @@
<string name="setting_summary_scroll_bar">
Show/Hide scroll bar on webpages
</string>
<!-- Text reflow -->
<string name="setting_title_text_reflow">
Text Reflow
</string>
<string name="setting_summary_text_reflow">
Enable text reflow
</string>
<!-- User Agent -->
<string name="setting_title_user_agent">
User Environment
Expand Down
2 changes: 1 addition & 1 deletion Ninja/res/values/strings_app.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
Ninja
</string>
<string name="app_version">
1.3.3
1.3.4
</string>

<!-- AndroidSlidingUpPanel -->
Expand Down
5 changes: 4 additions & 1 deletion Ninja/res/values/strings_key.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<resources>

<string name="sp_first">
SP_FIRST_25
SP_FIRST_26
</string>

<!-- General -->
Expand Down Expand Up @@ -46,6 +46,9 @@
<string name="sp_search_engine_custom">
SP_SEARCH_ENGINE_CUSTOM_9
</string>
<string name="sp_text_reflow">
SP_TEXT_REFLOW_9
</string>
<string name="sp_user_agent">
SP_USER_AGENT_9
</string>
Expand Down
6 changes: 6 additions & 0 deletions Ninja/res/xml/preference_setting.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@
android:summary="@string/setting_summary_scroll_bar">
</CheckBoxPreference>

<CheckBoxPreference android:key="@string/sp_text_reflow"
android:defaultValue="true"
android:title="@string/setting_title_text_reflow"
android:summary="@string/setting_summary_text_reflow">
</CheckBoxPreference>

<io.github.mthli.Ninja.View.UserAgentListPreference
android:key="@string/sp_user_agent"
android:defaultValue="0"
Expand Down
13 changes: 9 additions & 4 deletions Ninja/src/io/github/mthli/Ninja/Activity/BrowserActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
Expand Down Expand Up @@ -266,15 +267,19 @@ public void onDestroy() {
stopService(toHolderService);

SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
boolean exit = true;
if (sp.getBoolean(getString(R.string.sp_clear_quit), false)) {
Intent toClearService = new Intent(this, ClearService.class);
startService(toClearService);
exit = false;
}

BrowserContainer.clear();
IntentUnit.setContext(null);
super.onDestroy();
System.exit(0); // For remove all WebView thread
if (exit) {
System.exit(0); // For remove all WebView thread
}
}

@Override
Expand Down Expand Up @@ -822,7 +827,6 @@ private synchronized void pinAlbums(String url) {
hideSoftInput(inputBox);
hideSearchPanel();
switcherContainer.removeAllViews();
// contentFrame.removeAllViews();

for (AlbumController controller : BrowserContainer.list()) {
if (controller instanceof NinjaWebView) {
Expand All @@ -845,7 +849,7 @@ private synchronized void pinAlbums(String url) {

int index = BrowserContainer.size() - 1;
currentAlbumController = BrowserContainer.get(index);
contentFrame.removeAllViews(); //
contentFrame.removeAllViews();
contentFrame.addView((View) currentAlbumController);
currentAlbumController.activate();

Expand All @@ -870,7 +874,7 @@ public void run() {
final View albumView = webView.getAlbumView();
albumView.setVisibility(View.VISIBLE);
switcherContainer.addView(albumView, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
contentFrame.removeAllViews(); //
contentFrame.removeAllViews();
contentFrame.addView(webView);

if (currentAlbumController != null) {
Expand Down Expand Up @@ -1233,6 +1237,7 @@ public boolean onShowCustomView(View view, WebChromeClient.CustomViewCallback ca
}
}
customViewCallback = callback;
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); // Auto landscape when video shows

return true;
}
Expand Down
5 changes: 5 additions & 0 deletions Ninja/src/io/github/mthli/Ninja/Service/ClearService.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ public IBinder onBind(Intent intent) {
return null;
}

@Override
public void onDestroy() {
System.exit(0); // For remove all WebView thread
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
clear();
Expand Down
13 changes: 12 additions & 1 deletion Ninja/src/io/github/mthli/Ninja/View/NinjaWebView.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ public synchronized void initPreferences() {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
WebSettings webSettings = getSettings();

webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
webSettings.setLoadWithOverviewMode(true);
webSettings.setTextZoom(100);
webSettings.setUseWideViewPort(true);
Expand All @@ -167,6 +166,18 @@ public synchronized void initPreferences() {
webSettings.setSupportMultipleWindows(sp.getBoolean(context.getString(R.string.sp_multiple_windows), false));
webSettings.setSaveFormData(sp.getBoolean(context.getString(R.string.sp_passwords), true));

boolean textReflow = sp.getBoolean(context.getString(R.string.sp_text_reflow), true);
if (textReflow) {
webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
try {
webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING);
} catch (Exception e) {}
}
} else {
webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
}

int userAgent = Integer.valueOf(sp.getString(context.getString(R.string.sp_user_agent), "0"));
if (userAgent == 1) {
webSettings.setUserAgentString(BrowserUnit.UA_DESKTOP);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.view.*;
import io.github.mthli.Ninja.Unit.ViewUnit;

public class SwipeToBoundListener implements View.OnTouchListener {
public interface BoundCallback {
Expand All @@ -23,7 +22,6 @@ public interface BoundCallback {
private float translationX;
private boolean swiping;
private boolean swipingLeft;
private boolean canOnBound;
private int swipingSlop;
private VelocityTracker velocityTracker;

Expand All @@ -36,7 +34,6 @@ public SwipeToBoundListener(View view, BoundCallback callback) {
this.animTime = this.view.getContext().getResources().getInteger(android.R.integer.config_shortAnimTime);
this.swiping = false;
this.swipingLeft = false;
this.canOnBound = false;
}

@Override
Expand Down Expand Up @@ -73,9 +70,7 @@ public boolean onTouch(View v, MotionEvent event) {
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (canOnBound) {
callback.onBound(swipingLeft);
}
callback.onBound(swipingLeft);
}
});
}
Expand Down Expand Up @@ -115,7 +110,6 @@ public void onAnimationEnd(Animator animation) {
if (Math.abs(deltaX) > slop) {
swiping = true;
swipingLeft = deltaX < 0;
canOnBound = Math.abs(deltaX) >= ViewUnit.dp2px(view.getContext(), 48);
swipingSlop = (deltaX > 0 ? slop : -slop);
view.getParent().requestDisallowInterceptTouchEvent(true);

Expand Down

0 comments on commit 8e42837

Please sign in to comment.