moved map to link handler
This commit is contained in:
parent
b1e00a9dce
commit
2437dfe04c
|
@ -1,5 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
~ Twidere - Twitter client for Android
|
||||
~
|
||||
~ Copyright (C) 2012-2014 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||
|
@ -18,24 +17,6 @@
|
|||
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<manifest>
|
||||
|
||||
<application>
|
||||
<activity
|
||||
android:name=".activity.support.OpenStreetMapViewerActivity"
|
||||
android:exported="false"
|
||||
android:label="@string/view_map"
|
||||
android:theme="@style/Theme.Twidere.Dark.DialogWhenLarge.NoActionBar">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
|
||||
<category android:name="android.intent.category.BROWSABLE"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
|
||||
<data
|
||||
android:host="map"
|
||||
android:scheme="twidere"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Twidere - Twitter client for Android
|
||||
*
|
||||
* Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
|
@ -16,16 +16,13 @@
|
|||
~ You should have received a copy of the GNU General Public License
|
||||
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<org.mariotaku.twidere.view.TintedStatusFrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
app:setPadding="true"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<org.osmdroid.views.MapView
|
||||
<org.osmdroid.views.MapView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/map_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tilesource="Mapnik" />
|
||||
</org.mariotaku.twidere.view.TintedStatusFrameLayout>
|
||||
</FrameLayout>
|
|
@ -1,32 +1,16 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
|
||||
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
|
||||
|
||||
<application>
|
||||
|
||||
<meta-data
|
||||
android:name="com.google.android.gms.version"
|
||||
android:value="@integer/google_play_services_version"/>
|
||||
android:value="@integer/google_play_services_version" />
|
||||
<meta-data
|
||||
android:name="com.google.android.maps.v2.API_KEY"
|
||||
android:value="AIzaSyCVdCIMFFxdNqHnCPrJ9yKUzoTfs8jhYGc"/>
|
||||
android:value="AIzaSyCVdCIMFFxdNqHnCPrJ9yKUzoTfs8jhYGc" />
|
||||
|
||||
<activity
|
||||
android:name=".activity.support.GoogleMapViewerActivity"
|
||||
android:exported="false"
|
||||
android:label="@string/view_map"
|
||||
android:theme="@style/Theme.Twidere.Dark.DialogWhenLarge.NoActionBar">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
|
||||
<category android:name="android.intent.category.BROWSABLE"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
|
||||
<data
|
||||
android:host="map"
|
||||
android:scheme="twidere"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>
|
Before Width: | Height: | Size: 140 B After Width: | Height: | Size: 140 B |
|
@ -1,103 +0,0 @@
|
|||
/*
|
||||
* Twidere - Twitter client for Android
|
||||
*
|
||||
* Copyright (C) 2012-2014 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,140 @@
|
|||
/*
|
||||
* Twidere - Twitter client for Android
|
||||
*
|
||||
* Copyright (C) 2012-2014 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Twidere - Twitter client for Android
|
||||
*
|
||||
* Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
~ Twidere - Twitter client for Android
|
||||
~
|
||||
~ Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||
~
|
||||
~ 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 <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:id="@+id/map_fragment"
|
||||
android:layout_height="match_parent" />
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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<Object, Object, SignInResponse> {
|
||||
|
||||
protected final Configuration conf;
|
||||
|
|
|
@ -184,4 +184,9 @@ public abstract class ThemedFragmentActivity extends FragmentActivity implements
|
|||
return true;
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getThemeResourceId() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -187,7 +187,6 @@ public abstract class AbsContentListViewFragment<A extends ListAdapter> 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);
|
||||
|
|
|
@ -262,7 +262,6 @@ public abstract class AbsContentRecyclerViewFragment<A extends IContentCardAdapt
|
|||
|
||||
@Override
|
||||
protected void fitSystemWindows(Rect insets) {
|
||||
super.fitSystemWindows(insets);
|
||||
mRecyclerView.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);
|
||||
|
|
|
@ -298,12 +298,7 @@ public class AccountsDashboardFragment extends BaseSupportFragment implements Lo
|
|||
break;
|
||||
}
|
||||
case MENU_EDIT: {
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putLong(EXTRA_ACCOUNT_ID, account.account_id);
|
||||
final Intent intent = new Intent(INTENT_ACTION_EDIT_USER_PROFILE);
|
||||
intent.setClass(getActivity(), UserProfileEditorFragment.class);
|
||||
intent.putExtras(bundle);
|
||||
startActivity(intent);
|
||||
Utils.openProfileEditor(getActivity(), account.account_id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,14 +76,6 @@ public class AccountsManagerFragment extends BaseSupportFragment implements Load
|
|||
mProgressContainer.setVisibility(shown ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fitSystemWindows(Rect insets) {
|
||||
final View view = getView();
|
||||
if (view != null) {
|
||||
view.setPadding(insets.left, insets.top, insets.right, insets.bottom);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
|
|
|
@ -171,7 +171,10 @@ public class BaseSupportFragment extends Fragment implements IBaseFragment, Cons
|
|||
return getActivity();
|
||||
}
|
||||
|
||||
|
||||
protected void fitSystemWindows(Rect insets) {
|
||||
final View view = getView();
|
||||
if (view != null) {
|
||||
view.setPadding(insets.left, insets.top, insets.right, insets.bottom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,9 @@ package org.mariotaku.twidere.fragment.support;
|
|||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
|
@ -30,7 +33,10 @@ import org.mariotaku.twidere.util.accessor.WebSettingsAccessor;
|
|||
import org.mariotaku.twidere.util.webkit.DefaultWebViewClient;
|
||||
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
public class BaseSupportWebViewFragment extends SupportWebViewFragment implements Constants {
|
||||
public class BaseSupportWebViewFragment extends BaseSupportFragment implements Constants {
|
||||
|
||||
private WebView mWebView;
|
||||
private boolean mIsWebViewAvailable;
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(final Bundle savedInstanceState) {
|
||||
|
@ -47,4 +53,65 @@ public class BaseSupportWebViewFragment extends SupportWebViewFragment implement
|
|||
protected WebViewClient createWebViewClient() {
|
||||
return new DefaultWebViewClient(getActivity());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -248,14 +248,6 @@ public class DraftsFragment extends BaseSupportFragment implements Constants, Lo
|
|||
mEmptyView.setVisibility(listShown && mAdapter.isEmpty() ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fitSystemWindows(Rect insets) {
|
||||
final View view = getView();
|
||||
if (view != null) {
|
||||
view.setPadding(insets.left, insets.top, insets.right, insets.bottom);
|
||||
}
|
||||
}
|
||||
|
||||
private void editDraft(final DraftItem draft) {
|
||||
final Intent intent = new Intent(INTENT_ACTION_EDIT_DRAFT);
|
||||
final Bundle bundle = new Bundle();
|
||||
|
|
|
@ -106,16 +106,6 @@ public class FiltersFragment extends BaseSupportFragment implements RefreshScrol
|
|||
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 getSystemWindowsInsets(Rect insets) {
|
||||
return false;
|
||||
|
|
|
@ -423,13 +423,6 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
|
|||
mAddImageButton = (ImageView) mInputPanel.findViewById(R.id.add_image);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fitSystemWindows(Rect insets) {
|
||||
final View view = getView();
|
||||
if (view == null) return;
|
||||
view.setPadding(insets.left, insets.top, insets.right, insets.bottom);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Loader<Cursor> onCreateLoader(final int id, final Bundle args) {
|
||||
final long accountId = args != null ? args.getLong(EXTRA_ACCOUNT_ID, -1) : -1;
|
||||
|
|
|
@ -17,20 +17,23 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<OverlayItem> {
|
||||
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
||||
|
|
|
@ -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.
|
||||
* <p/>
|
||||
* 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;
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -1,116 +0,0 @@
|
|||
/*
|
||||
* Twidere - Twitter client for Android
|
||||
*
|
||||
* Copyright (C) 2012-2014 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Twidere - Twitter client for Android
|
||||
*
|
||||
* Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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);
|
||||
|
||||
}
|
|
@ -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<Integer> sAccountColors = new LongSparseArray<>();
|
||||
private static LongSparseArray<String> sAccountScreenNames = new LongSparseArray<>();
|
||||
private static LongSparseArray<String> 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<Long> 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));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue