From 2437dfe04c2971aaa5e38bfe49d057247ea735b0 Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Mon, 27 Apr 2015 21:41:19 +0800 Subject: [PATCH] moved map to link handler --- twidere/src/fdroid/AndroidManifest.xml | 23 +-- .../twidere/util/MapFragmentFactoryImpl.java | 35 +++++ .../fdroid/res/layout/activity_osm_viewer.xml | 9 +- twidere/src/google/AndroidManifest.xml | 22 +-- .../assets/images/loading_tile.png | Bin .../src/{main => google}/assets/mapview.html | 0 .../support/GoogleMapViewerActivity.java | 103 ------------- .../fragment/support/GoogleMapFragment.java | 98 ++++++++++-- .../fragment/support/WebMapFragment.java | 140 ++++++++++++++++++ .../twidere/util/MapFragmentFactoryImpl.java | 42 ++++++ .../res/layout/fragment_google_maps.xml | 24 +++ .../java/org/mariotaku/twidere/Constants.java | 1 + .../twidere/activity/BaseThemedActivity.java | 23 +-- .../activity/support/LinkHandlerActivity.java | 9 ++ .../activity/support/SignInActivity.java | 86 ++++++++++- .../support/ThemedFragmentActivity.java | 5 + .../support/AbsContentListViewFragment.java | 1 - .../AbsContentRecyclerViewFragment.java | 1 - .../support/AccountsDashboardFragment.java | 7 +- .../support/AccountsManagerFragment.java | 8 - .../fragment/support/BaseSupportFragment.java | 5 +- .../support/BaseSupportWebViewFragment.java | 69 ++++++++- .../fragment/support/DraftsFragment.java | 8 - .../fragment/support/FiltersFragment.java | 10 -- .../support/MessagesConversationFragment.java | 7 - .../support/OpenStreetMapViewerFragment.java} | 100 ++++++------- .../fragment/support/SearchFragment.java | 1 - .../fragment/support/StatusFragment.java | 9 -- .../support/SupportWebViewFragment.java | 98 ------------ .../fragment/support/UserFragment.java | 1 - .../fragment/support/UserListFragment.java | 1 - .../fragment/support/UserListsFragment.java | 10 -- .../support/UserMediaTimelineFragment.java | 1 - .../fragment/support/WebMapFragment.java | 116 --------------- .../twidere/util/MapFragmentFactory.java | 36 +++++ .../org/mariotaku/twidere/util/Utils.java | 33 ++--- 36 files changed, 607 insertions(+), 535 deletions(-) create mode 100644 twidere/src/fdroid/java/org/mariotaku/twidere/util/MapFragmentFactoryImpl.java rename twidere/src/{main => google}/assets/images/loading_tile.png (100%) rename twidere/src/{main => google}/assets/mapview.html (100%) delete mode 100644 twidere/src/google/java/org/mariotaku/twidere/activity/support/GoogleMapViewerActivity.java create mode 100644 twidere/src/google/java/org/mariotaku/twidere/fragment/support/WebMapFragment.java create mode 100644 twidere/src/google/java/org/mariotaku/twidere/util/MapFragmentFactoryImpl.java create mode 100644 twidere/src/google/res/layout/fragment_google_maps.xml rename twidere/src/{fdroid/java/org/mariotaku/twidere/activity/support/OpenStreetMapViewerActivity.java => main/java/org/mariotaku/twidere/fragment/support/OpenStreetMapViewerFragment.java} (74%) delete mode 100644 twidere/src/main/java/org/mariotaku/twidere/fragment/support/SupportWebViewFragment.java delete mode 100644 twidere/src/main/java/org/mariotaku/twidere/fragment/support/WebMapFragment.java create mode 100644 twidere/src/main/java/org/mariotaku/twidere/util/MapFragmentFactory.java diff --git a/twidere/src/fdroid/AndroidManifest.xml b/twidere/src/fdroid/AndroidManifest.xml index 39c2bf438..67caabf74 100644 --- a/twidere/src/fdroid/AndroidManifest.xml +++ b/twidere/src/fdroid/AndroidManifest.xml @@ -1,5 +1,4 @@ - - - + - - - - - - - - - - - - \ No newline at end of file diff --git a/twidere/src/fdroid/java/org/mariotaku/twidere/util/MapFragmentFactoryImpl.java b/twidere/src/fdroid/java/org/mariotaku/twidere/util/MapFragmentFactoryImpl.java new file mode 100644 index 000000000..4d8726ac1 --- /dev/null +++ b/twidere/src/fdroid/java/org/mariotaku/twidere/util/MapFragmentFactoryImpl.java @@ -0,0 +1,35 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2015 Mariotaku Lee + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.mariotaku.twidere.util; + +import android.content.Context; +import android.support.v4.app.Fragment; + +import org.mariotaku.twidere.fragment.support.OpenStreetMapViewerFragment; + +/** + * Created by mariotaku on 15/4/27. + */ +public class MapFragmentFactoryImpl extends MapFragmentFactory { + @Override + public Fragment createMapFragment(Context context) { + return new OpenStreetMapViewerFragment(); + } +} diff --git a/twidere/src/fdroid/res/layout/activity_osm_viewer.xml b/twidere/src/fdroid/res/layout/activity_osm_viewer.xml index 31e7e7607..4bb321054 100644 --- a/twidere/src/fdroid/res/layout/activity_osm_viewer.xml +++ b/twidere/src/fdroid/res/layout/activity_osm_viewer.xml @@ -16,16 +16,13 @@ ~ You should have received a copy of the GNU General Public License ~ along with this program. If not, see . --> - - - - \ No newline at end of file + \ No newline at end of file diff --git a/twidere/src/google/AndroidManifest.xml b/twidere/src/google/AndroidManifest.xml index d542c891f..8536ee30f 100644 --- a/twidere/src/google/AndroidManifest.xml +++ b/twidere/src/google/AndroidManifest.xml @@ -1,32 +1,16 @@ - + + android:value="@integer/google_play_services_version" /> + android:value="AIzaSyCVdCIMFFxdNqHnCPrJ9yKUzoTfs8jhYGc" /> - - - - - - - - - - \ No newline at end of file diff --git a/twidere/src/main/assets/images/loading_tile.png b/twidere/src/google/assets/images/loading_tile.png similarity index 100% rename from twidere/src/main/assets/images/loading_tile.png rename to twidere/src/google/assets/images/loading_tile.png diff --git a/twidere/src/main/assets/mapview.html b/twidere/src/google/assets/mapview.html similarity index 100% rename from twidere/src/main/assets/mapview.html rename to twidere/src/google/assets/mapview.html diff --git a/twidere/src/google/java/org/mariotaku/twidere/activity/support/GoogleMapViewerActivity.java b/twidere/src/google/java/org/mariotaku/twidere/activity/support/GoogleMapViewerActivity.java deleted file mode 100644 index bf4add60d..000000000 --- a/twidere/src/google/java/org/mariotaku/twidere/activity/support/GoogleMapViewerActivity.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package org.mariotaku.twidere.activity.support; - -import android.net.Uri; -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentTransaction; -import android.support.v7.app.ActionBar; -import android.view.Menu; -import android.view.MenuItem; - -import com.google.android.gms.common.ConnectionResult; -import com.google.android.gms.common.GooglePlayServicesUtil; - -import org.mariotaku.twidere.Constants; -import org.mariotaku.twidere.R; -import org.mariotaku.twidere.fragment.iface.IMapFragment; -import org.mariotaku.twidere.fragment.support.GoogleMapFragment; -import org.mariotaku.twidere.fragment.support.WebMapFragment; -import org.mariotaku.twidere.util.ParseUtils; - -public class GoogleMapViewerActivity extends BaseDialogWhenLargeActivity implements Constants { - - @Override - public boolean onCreateOptionsMenu(final Menu menu) { - getMenuInflater().inflate(R.menu.menu_google_maps_viewer, menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(final MenuItem item) { - switch (item.getItemId()) { - case MENU_HOME: { - onBackPressed(); - break; - } - case MENU_CENTER: { - final Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.main_content); - if ((fragment instanceof IMapFragment)) { - ((IMapFragment) fragment).center(); - } - break; - } - } - return true; - } - - @Override - protected void onCreate(final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_content_fragment); - getMainContent().setSetPaddingEnabled(true); - final Uri uri = getIntent().getData(); - if (uri == null || !AUTHORITY_MAP.equals(uri.getAuthority())) { - finish(); - return; - } - final Bundle bundle = new Bundle(); - final double latitude = ParseUtils.parseDouble(uri.getQueryParameter(QUERY_PARAM_LAT), Double.NaN); - final double longitude = ParseUtils.parseDouble(uri.getQueryParameter(QUERY_PARAM_LNG), Double.NaN); - if (Double.isNaN(latitude) || Double.isNaN(longitude)) { - finish(); - return; - } - try { - bundle.putDouble(EXTRA_LATITUDE, latitude); - bundle.putDouble(EXTRA_LONGITUDE, longitude); - } catch (final NumberFormatException e) { - finish(); - return; - } - final ActionBar actionBar = getSupportActionBar(); - if (actionBar != null) { - actionBar.setDisplayHomeAsUpEnabled(true); - } - final Fragment fragment = isNativeMapSupported() ? new GoogleMapFragment() : new WebMapFragment(); - fragment.setArguments(bundle); - final FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); - ft.replace(R.id.main_content, fragment).commit(); - } - - private boolean isNativeMapSupported() { - return GooglePlayServicesUtil.isGooglePlayServicesAvailable(this) == ConnectionResult.SUCCESS; - } -} diff --git a/twidere/src/google/java/org/mariotaku/twidere/fragment/support/GoogleMapFragment.java b/twidere/src/google/java/org/mariotaku/twidere/fragment/support/GoogleMapFragment.java index 07839a3e2..97347e4ea 100644 --- a/twidere/src/google/java/org/mariotaku/twidere/fragment/support/GoogleMapFragment.java +++ b/twidere/src/google/java/org/mariotaku/twidere/fragment/support/GoogleMapFragment.java @@ -19,7 +19,14 @@ package org.mariotaku.twidere.fragment.support; +import android.app.Activity; +import android.graphics.Rect; import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.View; import com.google.android.gms.maps.CameraUpdate; import com.google.android.gms.maps.CameraUpdateFactory; @@ -29,12 +36,53 @@ import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.MarkerOptions; import org.mariotaku.twidere.Constants; +import org.mariotaku.twidere.R; +import org.mariotaku.twidere.fragment.iface.IBaseFragment; import org.mariotaku.twidere.fragment.iface.IMapFragment; -public class GoogleMapFragment extends SupportMapFragment implements Constants, IMapFragment { +public class GoogleMapFragment extends SupportMapFragment implements Constants, IMapFragment, IBaseFragment { private GoogleMap mMapView; + @Override + public void onActivityCreated(final Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + setHasOptionsMenu(true); + final Bundle args = getArguments(); + if (args == null || !args.containsKey(EXTRA_LATITUDE) || !args.containsKey(EXTRA_LONGITUDE)) + return; + final double lat = args.getDouble(EXTRA_LATITUDE, 0.0), lng = args.getDouble(EXTRA_LONGITUDE, 0.0); + mMapView = getMap(); + final MarkerOptions marker = new MarkerOptions(); + marker.position(new LatLng(lat, lng)); + mMapView.addMarker(marker); + center(false); + } + + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + inflater.inflate(R.menu.menu_google_maps_viewer, menu); + } + + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + onBaseViewCreated(view, savedInstanceState); + requestFitSystemWindows(); + } + + @Override + public boolean onOptionsItemSelected(final MenuItem item) { + switch (item.getItemId()) { + case MENU_CENTER: { + center(); + break; + } + } + return true; + } + + @Override public void center() { center(true); @@ -53,18 +101,44 @@ public class GoogleMapFragment extends SupportMapFragment implements Constants, } } + @Override - public void onActivityCreated(final Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - final Bundle args = getArguments(); - if (args == null || !args.containsKey(EXTRA_LATITUDE) || !args.containsKey(EXTRA_LONGITUDE)) - return; - final double lat = args.getDouble(EXTRA_LATITUDE, 0.0), lng = args.getDouble(EXTRA_LONGITUDE, 0.0); - mMapView = getMap(); - final MarkerOptions marker = new MarkerOptions(); - marker.position(new LatLng(lat, lng)); - mMapView.addMarker(marker); - center(false); + public Bundle getExtraConfiguration() { + return null; } + @Override + public int getTabPosition() { + return 0; + } + + @Override + public void requestFitSystemWindows() { + final Activity activity = getActivity(); + final Fragment parentFragment = getParentFragment(); + final IBaseFragment.SystemWindowsInsetsCallback callback; + if (parentFragment instanceof IBaseFragment.SystemWindowsInsetsCallback) { + callback = (IBaseFragment.SystemWindowsInsetsCallback) parentFragment; + } else if (activity instanceof IBaseFragment.SystemWindowsInsetsCallback) { + callback = (IBaseFragment.SystemWindowsInsetsCallback) activity; + } else { + return; + } + final Rect insets = new Rect(); + if (callback.getSystemWindowsInsets(insets)) { + fitSystemWindows(insets); + } + } + + @Override + public void onBaseViewCreated(View view, Bundle savedInstanceState) { + + } + + protected void fitSystemWindows(Rect insets) { + final View view = getView(); + if (view != null) { + view.setPadding(insets.left, insets.top, insets.right, insets.bottom); + } + } } diff --git a/twidere/src/google/java/org/mariotaku/twidere/fragment/support/WebMapFragment.java b/twidere/src/google/java/org/mariotaku/twidere/fragment/support/WebMapFragment.java new file mode 100644 index 000000000..0aa73e92c --- /dev/null +++ b/twidere/src/google/java/org/mariotaku/twidere/fragment/support/WebMapFragment.java @@ -0,0 +1,140 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2014 Mariotaku Lee + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.mariotaku.twidere.fragment.support; + +import android.app.Activity; +import android.content.Intent; +import android.net.Uri; +import android.os.Bundle; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.View; +import android.webkit.JavascriptInterface; +import android.webkit.WebSettings; +import android.webkit.WebView; + +import org.mariotaku.twidere.R; +import org.mariotaku.twidere.fragment.iface.IMapFragment; +import org.mariotaku.twidere.util.webkit.DefaultWebViewClient; + +public class WebMapFragment extends BaseSupportWebViewFragment implements IMapFragment { + + private static final String MAPVIEW_URI = "file:///android_asset/mapview.html"; + + private double latitude, longitude; + + @Override + public void center() { + final WebView webview = getWebView(); + webview.loadUrl("javascript:center();"); + } + + @Override + public boolean onOptionsItemSelected(final MenuItem item) { + switch (item.getItemId()) { + case MENU_CENTER: { + center(); + break; + } + } + return true; + } + + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + inflater.inflate(R.menu.menu_google_maps_viewer, menu); + } + + + @Override + public void onActivityCreated(final Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + setHasOptionsMenu(true); + getLocation(); + setupWebView(); + } + + /** + * The Location Manager manages location providers. This code searches for + * the best provider of data (GPS, WiFi/cell phone tower lookup, some other + * mechanism) and finds the last known location. + */ + private void getLocation() { + final Bundle bundle = getArguments(); + if (bundle != null) { + latitude = bundle.getDouble(EXTRA_LATITUDE, 0.0); + longitude = bundle.getDouble(EXTRA_LONGITUDE, 0.0); + } + } + + /** + * Sets up the WebView object and loads the URL of the page * + */ + private void setupWebView() { + + final WebView webview = getWebView(); + webview.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); + webview.setWebViewClient(new MapWebViewClient(getActivity())); + webview.loadUrl(MAPVIEW_URI); + + final WebSettings settings = webview.getSettings(); + settings.setBuiltInZoomControls(false); + + /** Allows JavaScript calls to access application resources **/ + webview.addJavascriptInterface(new MapJavaScriptInterface(), "android"); + + } + + /** + * Sets up the interface for getting access to Latitude and Longitude data + * from device + */ + class MapJavaScriptInterface { + + @JavascriptInterface + public double getLatitude() { + return latitude; + } + + @JavascriptInterface + public double getLongitude() { + return longitude; + } + + } + + class MapWebViewClient extends DefaultWebViewClient { + + public MapWebViewClient(final Activity activity) { + super(activity); + } + + @Override + public boolean shouldOverrideUrlLoading(final WebView view, final String url) { + final Uri uri = Uri.parse(url); + if (uri.getScheme().equals(Uri.parse(MAPVIEW_URI).getScheme())) return false; + final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); + startActivity(intent); + return true; + } + } + +} diff --git a/twidere/src/google/java/org/mariotaku/twidere/util/MapFragmentFactoryImpl.java b/twidere/src/google/java/org/mariotaku/twidere/util/MapFragmentFactoryImpl.java new file mode 100644 index 000000000..d7681ffb6 --- /dev/null +++ b/twidere/src/google/java/org/mariotaku/twidere/util/MapFragmentFactoryImpl.java @@ -0,0 +1,42 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2015 Mariotaku Lee + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.mariotaku.twidere.util; + +import android.content.Context; +import android.support.v4.app.Fragment; + +import com.google.android.gms.common.ConnectionResult; +import com.google.android.gms.common.GooglePlayServicesUtil; + +import org.mariotaku.twidere.fragment.support.GoogleMapFragment; +import org.mariotaku.twidere.fragment.support.WebMapFragment; + +/** + * Created by mariotaku on 15/4/27. + */ +public class MapFragmentFactoryImpl extends MapFragmentFactory { + @Override + public Fragment createMapFragment(Context context) { + if (GooglePlayServicesUtil.isGooglePlayServicesAvailable(context) == ConnectionResult.SUCCESS) { + return new GoogleMapFragment(); + } + return new WebMapFragment(); + } +} diff --git a/twidere/src/google/res/layout/fragment_google_maps.xml b/twidere/src/google/res/layout/fragment_google_maps.xml new file mode 100644 index 000000000..38120bb81 --- /dev/null +++ b/twidere/src/google/res/layout/fragment_google_maps.xml @@ -0,0 +1,24 @@ + + + diff --git a/twidere/src/main/java/org/mariotaku/twidere/Constants.java b/twidere/src/main/java/org/mariotaku/twidere/Constants.java index 328d615ee..a74ecf316 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/Constants.java +++ b/twidere/src/main/java/org/mariotaku/twidere/Constants.java @@ -141,6 +141,7 @@ public interface Constants extends TwidereConstants { int LINK_ID_STATUS_FAVORITERS = 27; int LINK_ID_SEARCH = 28; int LINK_ID_MUTES_USERS = 41; + int LINK_ID_MAP = 51; int LINK_ID_ACCOUNTS = 101; int LINK_ID_DRAFTS = 102; int LINK_ID_FILTERS = 103; diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/BaseThemedActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/BaseThemedActivity.java index b7f555286..fadc121c6 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/BaseThemedActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/BaseThemedActivity.java @@ -25,7 +25,6 @@ import android.os.Bundle; import android.support.annotation.NonNull; import org.mariotaku.twidere.activity.iface.IThemedActivity; -import org.mariotaku.twidere.util.CompareUtils; import org.mariotaku.twidere.util.StrictModeUtils; import org.mariotaku.twidere.util.ThemeUtils; import org.mariotaku.twidere.util.Utils; @@ -92,11 +91,6 @@ public abstract class BaseThemedActivity extends Activity implements IThemedActi Utils.restartActivity(this); } - protected final boolean isThemeChanged() { - return getThemeResourceId() != mCurrentThemeResource || getThemeColor() != mCurrentThemeColor - || !CompareUtils.objectEquals(getThemeFontFamily(), mCurrentThemeFontFamily) - || getThemeBackgroundAlpha() != mCurrentThemeBackgroundAlpha; - } @Override protected void onCreate(final Bundle savedInstanceState) { @@ -108,31 +102,24 @@ public abstract class BaseThemedActivity extends Activity implements IThemedActi setActionBarBackground(); } - @Override - protected void onResume() { - super.onResume(); - if (isThemeChanged()) { - restart(); - } - } - private void setActionBarBackground() { } @Override - public void setTheme(int resid) { - super.setTheme(mCurrentThemeResource = getThemeResourceId()); + public void setTheme(int resId) { + final int themeResourceId = getThemeResourceId(); + super.setTheme(mCurrentThemeResource = themeResourceId != 0 ? themeResourceId : resId); } @Override - protected void onApplyThemeResource(@NonNull Resources.Theme theme, int resid, boolean first) { + protected void onApplyThemeResource(@NonNull Resources.Theme theme, int resId, boolean first) { mCurrentThemeColor = getThemeColor(); mCurrentThemeFontFamily = getThemeFontFamily(); mCurrentThemeBackgroundAlpha = getThemeBackgroundAlpha(); mCurrentThemeBackgroundOption = getThemeBackgroundOption(); mProfileImageStyle = Utils.getProfileImageStyle(this); ThemeUtils.applyWindowBackground(this, getWindow(), mCurrentThemeResource, mCurrentThemeBackgroundOption, mCurrentThemeBackgroundAlpha); - super.onApplyThemeResource(theme, resid, first); + super.onApplyThemeResource(theme, resId, first); } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/LinkHandlerActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/LinkHandlerActivity.java index 375038837..64eeecfca 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/LinkHandlerActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/LinkHandlerActivity.java @@ -369,6 +369,7 @@ public class LinkHandlerActivity extends BaseAppCompatActivity implements System intent.setExtrasClassLoader(getClassLoader()); final Fragment fragment = createFragmentForIntent(this, linkId, intent); if (uri == null || fragment == null) return false; + setSubtitle(null); switch (linkId) { case LINK_ID_STATUS: { setTitle(R.string.status); @@ -483,6 +484,14 @@ public class LinkHandlerActivity extends BaseAppCompatActivity implements System setTitle(R.string.filters); break; } + case LINK_ID_MAP: { + setTitle(R.string.view_map); + break; + } + default: { + setTitle(getString(R.string.app_name)); + break; + } } mFinishOnly = Boolean.parseBoolean(uri.getQueryParameter(QUERY_PARAM_FINISH_ONLY)); final FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/SignInActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/SignInActivity.java index 09863585b..5a196f4af 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/SignInActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/SignInActivity.java @@ -31,6 +31,7 @@ import android.content.res.Resources; import android.graphics.Color; import android.net.Uri; import android.os.AsyncTask; +import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.support.annotation.NonNull; @@ -39,6 +40,8 @@ import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; import android.support.v4.view.ViewCompat; +import android.support.v7.app.ActionBar; +import android.support.v7.widget.ActionMenuView; import android.support.v7.widget.Toolbar; import android.text.Editable; import android.text.TextUtils; @@ -47,6 +50,7 @@ import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; +import android.view.WindowManager; import android.widget.Button; import android.widget.EditText; import android.widget.LinearLayout; @@ -69,6 +73,8 @@ import org.mariotaku.twidere.util.ThemeUtils; import org.mariotaku.twidere.util.Utils; import org.mariotaku.twidere.util.net.OkHttpClientFactory; import org.mariotaku.twidere.util.net.TwidereHostResolverFactory; +import org.mariotaku.twidere.util.support.ViewSupport; +import org.mariotaku.twidere.view.iface.TintedStatusLayout; import twitter4j.Twitter; import twitter4j.TwitterConstants; @@ -90,7 +96,7 @@ import static org.mariotaku.twidere.util.Utils.isUserLoggedIn; import static org.mariotaku.twidere.util.Utils.showErrorMessage; import static org.mariotaku.twidere.util.Utils.trim; -public class SignInActivity extends BaseDialogWhenLargeActivity implements TwitterConstants, OnClickListener, +public class SignInActivity extends BaseAppCompatActivity implements TwitterConstants, OnClickListener, TextWatcher { private static final String TWITTER_SIGNUP_URL = "https://twitter.com/signup"; @@ -114,6 +120,7 @@ public class SignInActivity extends BaseDialogWhenLargeActivity implements Twitt private SharedPreferences mPreferences; private ContentResolver mResolver; private AbstractSignInTask mTask; + private TintedStatusLayout mMainContent; @Override public void afterTextChanged(final Editable s) { @@ -121,9 +128,10 @@ public class SignInActivity extends BaseDialogWhenLargeActivity implements Twitt } @Override - public int getThemeResourceId() { + public int getThemeResourceId() { return ThemeUtils.getThemeResource(this); } + @Override public void beforeTextChanged(final CharSequence s, final int start, final int count, final int after) { @@ -180,7 +188,6 @@ public class SignInActivity extends BaseDialogWhenLargeActivity implements Twitt } - @Override public void onContentChanged() { super.onContentChanged(); @@ -190,6 +197,8 @@ public class SignInActivity extends BaseDialogWhenLargeActivity implements Twitt mSignUpButton = (Button) findViewById(R.id.sign_up); mSignInSignUpContainer = (LinearLayout) findViewById(R.id.sign_in_sign_up); mUsernamePasswordContainer = (LinearLayout) findViewById(R.id.username_password); + mMainContent = (TintedStatusLayout) findViewById(R.id.main_content); + setupTintStatusBar(); } @Override @@ -257,7 +266,17 @@ public class SignInActivity extends BaseDialogWhenLargeActivity implements Twitt itemBrowser.setVisible(is_oauth); itemBrowser.setEnabled(is_oauth); } - return super.onPrepareOptionsMenu(menu); + final boolean result = super.onPrepareOptionsMenu(menu); + if (!shouldSetActionItemColor()) return result; + final Toolbar toolbar = peekActionBarToolbar(); + if (toolbar != null) { + final int themeColor = getCurrentThemeColor(); + final int themeId = getCurrentThemeResourceId(); + final int itemColor = ThemeUtils.getContrastActionBarItemColor(this, themeId, themeColor); + ThemeUtils.setActionBarOverflowColor(toolbar, itemColor); + ThemeUtils.wrapToolbarMenuIcon(ViewSupport.findViewByType(toolbar, ActionMenuView.class), itemColor, itemColor); + } + return result; } @Override @@ -284,6 +303,7 @@ public class SignInActivity extends BaseDialogWhenLargeActivity implements Twitt @Override protected void onCreate(final Bundle savedInstanceState) { + setupWindow(); super.onCreate(savedInstanceState); mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, MODE_PRIVATE); mResolver = getContentResolver(); @@ -497,6 +517,64 @@ public class SignInActivity extends BaseDialogWhenLargeActivity implements Twitt }); } + protected TintedStatusLayout getMainContent() { + return mMainContent; + } + + protected boolean isActionBarOutlineEnabled() { + return true; + } + + protected boolean shouldSetActionItemColor() { + return true; + } + + @Override + protected void onPostCreate(Bundle savedInstanceState) { + super.onPostCreate(savedInstanceState); + setupActionBar(); + } + + private void setupActionBar() { + final ActionBar actionBar = getSupportActionBar(); + if (actionBar == null) return; + + final int themeColor = getCurrentThemeColor(); + final int themeId = getCurrentThemeResourceId(); + final String option = getThemeBackgroundOption(); + final int titleColor = ThemeUtils.getContrastActionBarTitleColor(this, themeId, themeColor); + final int actionBarItemsColor = ThemeUtils.getContrastActionBarItemColor(this, themeId, themeColor); + ThemeUtils.applyActionBarBackground(actionBar, this, themeId, themeColor, option, isActionBarOutlineEnabled()); + final Toolbar toolbar = peekActionBarToolbar(); + if (toolbar != null) { + ThemeUtils.setToolBarColor(toolbar, titleColor, actionBarItemsColor); + } else { + ThemeUtils.setActionBarColor(getWindow(), getSupportActionBar(), titleColor, actionBarItemsColor); + } + } + + private void setupTintStatusBar() { + if (mMainContent == null) return; + + final int color = getCurrentThemeColor(); + final int alpha = ThemeUtils.isTransparentBackground(getThemeBackgroundOption()) ? getCurrentThemeBackgroundAlpha() : 0xFF; + if (ThemeUtils.isDarkTheme(getCurrentThemeResourceId())) { + mMainContent.setColor(getResources().getColor(R.color.background_color_action_bar_dark), alpha); + } else { + mMainContent.setColor(color, alpha); + } + + mMainContent.setDrawShadow(false); + mMainContent.setDrawColor(true); + mMainContent.setFactor(1); + } + + private void setupWindow() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); + } + } + public static abstract class AbstractSignInTask extends AsyncTask { protected final Configuration conf; diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/ThemedFragmentActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/ThemedFragmentActivity.java index d32db29a4..c8849f5ec 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/ThemedFragmentActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/ThemedFragmentActivity.java @@ -184,4 +184,9 @@ public abstract class ThemedFragmentActivity extends FragmentActivity implements return true; return super.onKeyDown(keyCode, event); } + + @Override + public int getThemeResourceId() { + return 0; + } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsContentListViewFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsContentListViewFragment.java index ba3434857..2dbd4a19c 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsContentListViewFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsContentListViewFragment.java @@ -187,7 +187,6 @@ public abstract class AbsContentListViewFragment extends @Override protected void fitSystemWindows(Rect insets) { - super.fitSystemWindows(insets); mListView.setPadding(insets.left, insets.top, insets.right, insets.bottom); mErrorContainer.setPadding(insets.left, insets.top, insets.right, insets.bottom); mProgressContainer.setPadding(insets.left, insets.top, insets.right, insets.bottom); diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsContentRecyclerViewFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsContentRecyclerViewFragment.java index e3112db34..be759857d 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsContentRecyclerViewFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsContentRecyclerViewFragment.java @@ -262,7 +262,6 @@ public abstract class AbsContentRecyclerViewFragment onCreateLoader(final int id, final Bundle args) { final long accountId = args != null ? args.getLong(EXTRA_ACCOUNT_ID, -1) : -1; diff --git a/twidere/src/fdroid/java/org/mariotaku/twidere/activity/support/OpenStreetMapViewerActivity.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/OpenStreetMapViewerFragment.java similarity index 74% rename from twidere/src/fdroid/java/org/mariotaku/twidere/activity/support/OpenStreetMapViewerActivity.java rename to twidere/src/main/java/org/mariotaku/twidere/fragment/support/OpenStreetMapViewerFragment.java index 344bd4664..4c98f7d90 100644 --- a/twidere/src/fdroid/java/org/mariotaku/twidere/activity/support/OpenStreetMapViewerActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/OpenStreetMapViewerFragment.java @@ -17,20 +17,23 @@ * along with this program. If not, see . */ -package org.mariotaku.twidere.activity.support; +package org.mariotaku.twidere.fragment.support; import android.graphics.Point; import android.graphics.drawable.Drawable; -import android.net.Uri; import android.os.Bundle; +import android.support.annotation.Nullable; import android.support.v4.content.res.ResourcesCompat; -import android.support.v7.app.ActionBar; +import android.view.LayoutInflater; import android.view.Menu; +import android.view.MenuInflater; import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; import org.mariotaku.twidere.Constants; import org.mariotaku.twidere.R; -import org.mariotaku.twidere.util.ParseUtils; +import org.mariotaku.twidere.fragment.support.BaseSupportFragment; import org.osmdroid.ResourceProxy; import org.osmdroid.api.IMapController; import org.osmdroid.api.IMapView; @@ -43,65 +46,23 @@ import org.osmdroid.views.overlay.OverlayItem; import java.util.ArrayList; import java.util.List; -public class OpenStreetMapViewerActivity extends BaseDialogWhenLargeActivity implements Constants { +public class OpenStreetMapViewerFragment extends BaseSupportFragment implements Constants { private MapView mMapView; private double mLatitude, mLongitude; @Override - public boolean onCreateOptionsMenu(final Menu menu) { - getMenuInflater().inflate(R.menu.menu_osm_viewer, menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(final MenuItem item) { - switch (item.getItemId()) { - case MENU_HOME: { - onBackPressed(); - break; - } - case MENU_CENTER: { - moveToCenter(mLatitude, mLongitude); - break; - } - } - return true; - } - - private void moveToCenter(double lat, double lng) { - final GeoPoint gp = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6)); - final IMapController mc = mMapView.getController(); - mc.animateTo(gp); - } - - @Override - public void onContentChanged() { - super.onContentChanged(); - mMapView = (MapView) findViewById(R.id.map_view); - } - - @Override - protected void onCreate(final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_osm_viewer); - final Uri uri = getIntent().getData(); - if (uri == null || !AUTHORITY_MAP.equals(uri.getAuthority())) { - finish(); - return; - } - final double latitude = ParseUtils.parseDouble(uri.getQueryParameter(QUERY_PARAM_LAT), Double.NaN); - final double longitude = ParseUtils.parseDouble(uri.getQueryParameter(QUERY_PARAM_LNG), Double.NaN); + public void onActivityCreated(final Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + final Bundle args = getArguments(); + final double latitude = args.getDouble(EXTRA_LATITUDE, Double.NaN); + final double longitude = args.getDouble(EXTRA_LONGITUDE, Double.NaN); if (Double.isNaN(latitude) || Double.isNaN(longitude)) { - finish(); + getActivity().finish(); return; } mLatitude = latitude; mLongitude = longitude; - final ActionBar actionBar = getSupportActionBar(); - if (actionBar != null) { - actionBar.setDisplayHomeAsUpEnabled(true); - } mMapView.setMultiTouchControls(true); mMapView.setBuiltInZoomControls(true); mMapView.setTilesScaledToDpi(true); @@ -117,6 +78,39 @@ public class OpenStreetMapViewerActivity extends BaseDialogWhenLargeActivity imp mc.setCenter(gp); } + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + return inflater.inflate(R.layout.activity_osm_viewer, container, false); + } + + @Override + public void onBaseViewCreated(View view, Bundle savedInstanceState) { + super.onBaseViewCreated(view, savedInstanceState); + mMapView = (MapView) view.findViewById(R.id.map_view); + } + + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + inflater.inflate(R.menu.menu_osm_viewer, menu); + } + + @Override + public boolean onOptionsItemSelected(final MenuItem item) { + switch (item.getItemId()) { + case MENU_CENTER: { + moveToCenter(mLatitude, mLongitude); + break; + } + } + return true; + } + + private void moveToCenter(double lat, double lng) { + final GeoPoint gp = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6)); + final IMapController mc = mMapView.getController(); + mc.animateTo(gp); + } static class Itemization extends ItemizedOverlay { diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/SearchFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/SearchFragment.java index 2282adcb0..1410aeeab 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/SearchFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/SearchFragment.java @@ -240,7 +240,6 @@ public class SearchFragment extends BaseSupportFragment implements RefreshScroll @Override protected void fitSystemWindows(Rect insets) { - super.fitSystemWindows(insets); final View view = getView(); if (view != null) { final int top = Utils.getInsetsTopWithoutActionBarHeight(getActivity(), insets.top); diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/StatusFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/StatusFragment.java index 435e92e7a..4d0eebf0f 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/StatusFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/StatusFragment.java @@ -285,15 +285,6 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac mErrorContainer = view.findViewById(R.id.error_container); } - @Override - protected void fitSystemWindows(Rect insets) { - super.fitSystemWindows(insets); - final View view = getView(); - if (view != null) { - view.setPadding(insets.left, insets.top, insets.right, insets.bottom); - } - } - @Override public void onGapClick(GapViewHolder holder, int position) { diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/SupportWebViewFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/SupportWebViewFragment.java deleted file mode 100644 index f20513566..000000000 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/SupportWebViewFragment.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.mariotaku.twidere.fragment.support; - -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.webkit.WebView; - -/** - * A fragment that displays a WebView. - *

- * The WebView is automically paused or resumed when the Fragment is paused or resumed. - */ -public class SupportWebViewFragment extends Fragment { - private WebView mWebView; - private boolean mIsWebViewAvailable; - - public SupportWebViewFragment() { - } - - /** - * Called to instantiate the view. Creates and returns the WebView. - */ - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - if (mWebView != null) { - mWebView.destroy(); - } - mWebView = new WebView(getActivity()); - mIsWebViewAvailable = true; - return mWebView; - } - - /** - * Called when the fragment is visible to the user and actively running. Resumes the WebView. - */ - @Override - public void onPause() { - super.onPause(); - mWebView.onPause(); - } - - /** - * Called when the fragment is no longer resumed. Pauses the WebView. - */ - @Override - public void onResume() { - mWebView.onResume(); - super.onResume(); - } - - /** - * Called when the WebView has been detached from the fragment. - * The WebView is no longer available after this time. - */ - @Override - public void onDestroyView() { - mIsWebViewAvailable = false; - super.onDestroyView(); - } - - /** - * Called when the fragment is no longer in use. Destroys the internal state of the WebView. - */ - @Override - public void onDestroy() { - if (mWebView != null) { - mWebView.destroy(); - mWebView = null; - } - super.onDestroy(); - } - - /** - * Gets the WebView. - */ - public WebView getWebView() { - return mIsWebViewAvailable ? mWebView : null; - } -} diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFragment.java index 404ca5a61..80e25f812 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFragment.java @@ -1133,7 +1133,6 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener @Override protected void fitSystemWindows(Rect insets) { - super.fitSystemWindows(insets); final ThemedAppCompatActivity activity = (ThemedAppCompatActivity) getActivity(); mHeaderDrawerLayout.setPadding(insets.left, insets.top, insets.right, insets.bottom); final String backgroundOption = activity.getCurrentThemeBackgroundOption(); diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserListFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserListFragment.java index c581748c9..63876d861 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserListFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserListFragment.java @@ -543,7 +543,6 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList @Override protected void fitSystemWindows(Rect insets) { - super.fitSystemWindows(insets); final View progress = mProgressContainer, error = mErrorContainer; final HeaderDrawerLayout content = mHeaderDrawerLayout; if (progress == null || error == null || content == null) { diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserListsFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserListsFragment.java index 78f59f0b9..c9364bcfc 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserListsFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserListsFragment.java @@ -101,16 +101,6 @@ public class UserListsFragment extends BaseSupportFragment implements RefreshScr return (Fragment) mPagerAdapter.instantiateItem(mViewPager, currentItem); } - @Override - protected void fitSystemWindows(Rect insets) { - super.fitSystemWindows(insets); - final View view = getView(); - if (view == null) { - return; - } - view.setPadding(insets.left, insets.top, insets.right, insets.bottom); - } - @Override public boolean triggerRefresh(final int position) { return false; diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserMediaTimelineFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserMediaTimelineFragment.java index f6daf22f3..2a29f5005 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserMediaTimelineFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserMediaTimelineFragment.java @@ -122,7 +122,6 @@ public class UserMediaTimelineFragment extends BaseSupportFragment @Override protected void fitSystemWindows(Rect insets) { - super.fitSystemWindows(insets); if (mRecyclerView != null) { mRecyclerView.setClipToPadding(false); mRecyclerView.setPadding(insets.left, insets.top, insets.right, insets.bottom); diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/WebMapFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/WebMapFragment.java deleted file mode 100644 index 1425dcff6..000000000 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/WebMapFragment.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package org.mariotaku.twidere.fragment.support; - -import android.app.Activity; -import android.content.Intent; -import android.net.Uri; -import android.os.Bundle; -import android.view.View; -import android.webkit.JavascriptInterface; -import android.webkit.WebSettings; -import android.webkit.WebView; - -import org.mariotaku.twidere.fragment.iface.IMapFragment; -import org.mariotaku.twidere.util.webkit.DefaultWebViewClient; - -public class WebMapFragment extends BaseSupportWebViewFragment implements IMapFragment { - - private static final String MAPVIEW_URI = "file:///android_asset/mapview.html"; - - private double latitude, longitude; - - @Override - public void center() { - final WebView webview = getWebView(); - webview.loadUrl("javascript:center();"); - } - - @Override - public void onActivityCreated(final Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - getLocation(); - setupWebView(); - } - - /** - * The Location Manager manages location providers. This code searches for - * the best provider of data (GPS, WiFi/cell phone tower lookup, some other - * mechanism) and finds the last known location. - **/ - private void getLocation() { - final Bundle bundle = getArguments(); - if (bundle != null) { - latitude = bundle.getDouble(EXTRA_LATITUDE, 0.0); - longitude = bundle.getDouble(EXTRA_LONGITUDE, 0.0); - } - } - - /** Sets up the WebView object and loads the URL of the page **/ - private void setupWebView() { - - final WebView webview = getWebView(); - webview.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); - webview.setWebViewClient(new MapWebViewClient(getActivity())); - webview.loadUrl(MAPVIEW_URI); - - final WebSettings settings = webview.getSettings(); - settings.setBuiltInZoomControls(false); - - /** Allows JavaScript calls to access application resources **/ - webview.addJavascriptInterface(new MapJavaScriptInterface(), "android"); - - } - - /** - * Sets up the interface for getting access to Latitude and Longitude data - * from device - **/ - class MapJavaScriptInterface { - - @JavascriptInterface - public double getLatitude() { - return latitude; - } - - @JavascriptInterface - public double getLongitude() { - return longitude; - } - - } - - class MapWebViewClient extends DefaultWebViewClient { - - public MapWebViewClient(final Activity activity) { - super(activity); - } - - @Override - public boolean shouldOverrideUrlLoading(final WebView view, final String url) { - final Uri uri = Uri.parse(url); - if (uri.getScheme().equals(Uri.parse(MAPVIEW_URI).getScheme())) return false; - final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); - startActivity(intent); - return true; - } - } - -} diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/MapFragmentFactory.java b/twidere/src/main/java/org/mariotaku/twidere/util/MapFragmentFactory.java new file mode 100644 index 000000000..a8fa566b2 --- /dev/null +++ b/twidere/src/main/java/org/mariotaku/twidere/util/MapFragmentFactory.java @@ -0,0 +1,36 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2015 Mariotaku Lee + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.mariotaku.twidere.util; + +import android.content.Context; +import android.support.v4.app.Fragment; + +import org.mariotaku.twidere.model.ParcelableStatus; + +/** + * Created by mariotaku on 15/4/27. + */ +public abstract class MapFragmentFactory { + + public static final MapFragmentFactory SINGLETON = new MapFragmentFactoryImpl(); + + public abstract Fragment createMapFragment(Context context); + +} diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java b/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java index 39430880e..2686e595b 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java @@ -99,7 +99,6 @@ import android.view.Menu; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; -import android.view.View.MeasureSpec; import android.view.Window; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityManager; @@ -395,6 +394,7 @@ public final class Utils implements Constants, TwitterConstants { LINK_HANDLER_URI_MATCHER.addURI(AUTHORITY_STATUS_REPLIES, null, LINK_ID_STATUS_REPLIES); LINK_HANDLER_URI_MATCHER.addURI(AUTHORITY_SEARCH, null, LINK_ID_SEARCH); LINK_HANDLER_URI_MATCHER.addURI(AUTHORITY_MUTES_USERS, null, LINK_ID_MUTES_USERS); + LINK_HANDLER_URI_MATCHER.addURI(AUTHORITY_MAP, null, LINK_ID_MAP); LINK_HANDLER_URI_MATCHER.addURI(AUTHORITY_ACCOUNTS, null, LINK_ID_ACCOUNTS); LINK_HANDLER_URI_MATCHER.addURI(AUTHORITY_DRAFTS, null, LINK_ID_DRAFTS); @@ -410,7 +410,6 @@ public final class Utils implements Constants, TwitterConstants { private static LongSparseArray sAccountColors = new LongSparseArray<>(); private static LongSparseArray sAccountScreenNames = new LongSparseArray<>(); private static LongSparseArray sAccountNames = new LongSparseArray<>(); - static final String MAPS_STATIC_IMAGE_URI_TEMPLATE = "https://maps.googleapis.com/maps/api/staticmap?zoom=%d&size=%dx%d&sensor=false&language=%s¢er=%f,%f&markers=%f,%f"; private Utils() { throw new AssertionError("You are trying to create an instance for this utility class!"); @@ -774,10 +773,21 @@ public final class Utils implements Constants, TwitterConstants { break; } case LINK_ID_PROFILE_EDITOR: { - fragment = new UserProfileEditorFragment(); if (!args.containsKey(EXTRA_ACCOUNT_ID) && uri.getQueryParameter(QUERY_PARAM_ACCOUNT_ID) == null) { return null; } + fragment = new UserProfileEditorFragment(); + break; + } + case LINK_ID_MAP: { + if (!args.containsKey(EXTRA_LATITUDE) && !args.containsKey(EXTRA_LONGITUDE)) { + final double lat = ParseUtils.parseDouble(uri.getQueryParameter(QUERY_PARAM_LAT), Double.NaN); + final double lng = ParseUtils.parseDouble(uri.getQueryParameter(QUERY_PARAM_LNG), Double.NaN); + if (Double.isNaN(lat) || Double.isNaN(lng)) return null; + args.putDouble(EXTRA_LATITUDE, lat); + args.putDouble(EXTRA_LONGITUDE, lng); + } + fragment = MapFragmentFactory.SINGLETON.createMapFragment(context); break; } case LINK_ID_STATUS: { @@ -1950,21 +1960,6 @@ public final class Utils implements Constants, TwitterConstants { return nf.format(number); } - public static String getMapStaticImageUri(final double lat, final double lng, final int zoom, final int w, - final int h, final Locale locale) { - return String.format(Locale.US, MAPS_STATIC_IMAGE_URI_TEMPLATE, zoom, w, h, locale.toString(), lat, lng, lat, - lng); - } - - public static String getMapStaticImageUri(final double lat, final double lng, final View v) { - if (v == null) return null; - final int wSpec = MeasureSpec.makeMeasureSpec(v.getWidth(), MeasureSpec.UNSPECIFIED); - final int hSpec = MeasureSpec.makeMeasureSpec(v.getHeight(), MeasureSpec.UNSPECIFIED); - v.measure(wSpec, hSpec); - return getMapStaticImageUri(lat, lng, 12, v.getMeasuredWidth(), v.getMeasuredHeight(), v.getResources() - .getConfiguration().locale); - } - public static long[] getMatchedNicknameIds(final String str, UserColorNameManager manager) { if (isEmpty(str)) return new long[0]; final List list = new ArrayList<>(); @@ -3052,7 +3047,7 @@ public final class Utils implements Constants, TwitterConstants { builder.appendQueryParameter(QUERY_PARAM_LAT, String.valueOf(latitude)); builder.appendQueryParameter(QUERY_PARAM_LNG, String.valueOf(longitude)); final Intent intent = new Intent(Intent.ACTION_VIEW, builder.build()); - intent.setPackage(context.getPackageName()); + intent.setPackage(BuildConfig.APPLICATION_ID); context.startActivity(Intent.createChooser(intent, null)); }