Update to toolbar and use new tabs
This commit is contained in:
parent
3ae6c9a4d9
commit
f16d22884c
14 changed files with 804 additions and 451 deletions
|
@ -12,14 +12,9 @@
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
android:layout_weight="1"/>
|
android:layout_weight="1"/>
|
||||||
|
|
||||||
<View android:id="@+id/devider"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="1dp"
|
|
||||||
android:background="@color/dashboard_divider"/>
|
|
||||||
|
|
||||||
<LinearLayout android:orientation="horizontal"
|
<android.support.v7.widget.Toolbar android:orientation="horizontal"
|
||||||
android:id="@+id/bottomControls"
|
android:id="@+id/bottomControls"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:background="@color/dashboard_black"
|
|
||||||
android:layout_height="wrap_content"/>
|
android:layout_height="wrap_content"/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
|
@ -1,38 +1,13 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:id="@android:id/tabhost"
|
|
||||||
android:layout_marginTop="?attr/actionBarSize"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent">
|
|
||||||
|
|
||||||
<TabWidget
|
|
||||||
android:id="@android:id/tabs"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="0" />
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical" >
|
||||||
android:background="@drawable/ic_background_topofsearchactivities">
|
|
||||||
|
|
||||||
<TextView
|
<com.example.android.common.view.SlidingTabLayout
|
||||||
android:id="@+id/textViewADesc"
|
android:id="@+id/sliding_tabs"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content" />
|
||||||
android:layout_gravity="center"
|
|
||||||
android:background="@drawable/ic_background_tabinfotext"
|
|
||||||
android:textColor="@color/color_white"
|
|
||||||
android:text="@string/poi_search_desc"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:id="@android:id/tabcontent"
|
android:id="@android:id/tabcontent"
|
||||||
|
@ -45,19 +20,9 @@
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
android:layout_weight="1" />
|
android:layout_weight="1" />
|
||||||
|
|
||||||
|
<android.support.v7.widget.Toolbar
|
||||||
<View android:id="@+id/divider"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="1dp"
|
|
||||||
android:background="@color/dashboard_divider"/>
|
|
||||||
|
|
||||||
<LinearLayout android:orientation="horizontal"
|
|
||||||
android:id="@+id/bottomControls"
|
android:id="@+id/bottomControls"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:background="@color/dashboard_black"
|
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
</TabHost>
|
|
314
OsmAnd/src/com/example/android/common/view/SlidingTabLayout.java
Normal file
314
OsmAnd/src/com/example/android/common/view/SlidingTabLayout.java
Normal file
|
@ -0,0 +1,314 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013 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 com.example.android.common.view;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Typeface;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.support.v4.view.PagerAdapter;
|
||||||
|
import android.support.v4.view.ViewPager;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.util.TypedValue;
|
||||||
|
import android.view.Gravity;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.HorizontalScrollView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To be used with ViewPager to provide a tab indicator component which give constant feedback as to
|
||||||
|
* the user's scroll progress.
|
||||||
|
* <p>
|
||||||
|
* To use the component, simply add it to your view hierarchy. Then in your
|
||||||
|
* {@link android.app.Activity} or {@link android.support.v4.app.Fragment} call
|
||||||
|
* {@link #setViewPager(ViewPager)} providing it the ViewPager this layout is being used for.
|
||||||
|
* <p>
|
||||||
|
* The colors can be customized in two ways. The first and simplest is to provide an array of colors
|
||||||
|
* via {@link #setSelectedIndicatorColors(int...)} and {@link #setDividerColors(int...)}. The
|
||||||
|
* alternative is via the {@link TabColorizer} interface which provides you complete control over
|
||||||
|
* which color is used for any individual position.
|
||||||
|
* <p>
|
||||||
|
* The views used as tabs can be customized by calling {@link #setCustomTabView(int, int)},
|
||||||
|
* providing the layout ID of your custom layout.
|
||||||
|
*/
|
||||||
|
public class SlidingTabLayout extends HorizontalScrollView {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows complete control over the colors drawn in the tab layout. Set with
|
||||||
|
* {@link #setCustomTabColorizer(TabColorizer)}.
|
||||||
|
*/
|
||||||
|
public interface TabColorizer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return return the color of the indicator used when {@code position} is selected.
|
||||||
|
*/
|
||||||
|
int getIndicatorColor(int position);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return return the color of the divider drawn to the right of {@code position}.
|
||||||
|
*/
|
||||||
|
int getDividerColor(int position);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final int TITLE_OFFSET_DIPS = 24;
|
||||||
|
private static final int TAB_VIEW_PADDING_DIPS = 16;
|
||||||
|
private static final int TAB_VIEW_TEXT_SIZE_SP = 12;
|
||||||
|
|
||||||
|
private int mTitleOffset;
|
||||||
|
|
||||||
|
private int mTabViewLayoutId;
|
||||||
|
private int mTabViewTextViewId;
|
||||||
|
|
||||||
|
private ViewPager mViewPager;
|
||||||
|
private ViewPager.OnPageChangeListener mViewPagerPageChangeListener;
|
||||||
|
|
||||||
|
private final SlidingTabStrip mTabStrip;
|
||||||
|
|
||||||
|
public SlidingTabLayout(Context context) {
|
||||||
|
this(context, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SlidingTabLayout(Context context, AttributeSet attrs) {
|
||||||
|
this(context, attrs, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SlidingTabLayout(Context context, AttributeSet attrs, int defStyle) {
|
||||||
|
super(context, attrs, defStyle);
|
||||||
|
|
||||||
|
// Disable the Scroll Bar
|
||||||
|
setHorizontalScrollBarEnabled(false);
|
||||||
|
// Make sure that the Tab Strips fills this View
|
||||||
|
setFillViewport(true);
|
||||||
|
|
||||||
|
mTitleOffset = (int) (TITLE_OFFSET_DIPS * getResources().getDisplayMetrics().density);
|
||||||
|
|
||||||
|
mTabStrip = new SlidingTabStrip(context);
|
||||||
|
addView(mTabStrip, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the custom {@link TabColorizer} to be used.
|
||||||
|
*
|
||||||
|
* If you only require simple custmisation then you can use
|
||||||
|
* {@link #setSelectedIndicatorColors(int...)} and {@link #setDividerColors(int...)} to achieve
|
||||||
|
* similar effects.
|
||||||
|
*/
|
||||||
|
public void setCustomTabColorizer(TabColorizer tabColorizer) {
|
||||||
|
mTabStrip.setCustomTabColorizer(tabColorizer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the colors to be used for indicating the selected tab. These colors are treated as a
|
||||||
|
* circular array. Providing one color will mean that all tabs are indicated with the same color.
|
||||||
|
*/
|
||||||
|
public void setSelectedIndicatorColors(int... colors) {
|
||||||
|
mTabStrip.setSelectedIndicatorColors(colors);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the colors to be used for tab dividers. These colors are treated as a circular array.
|
||||||
|
* Providing one color will mean that all tabs are indicated with the same color.
|
||||||
|
*/
|
||||||
|
public void setDividerColors(int... colors) {
|
||||||
|
mTabStrip.setDividerColors(colors);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the {@link ViewPager.OnPageChangeListener}. When using {@link SlidingTabLayout} you are
|
||||||
|
* required to set any {@link ViewPager.OnPageChangeListener} through this method. This is so
|
||||||
|
* that the layout can update it's scroll position correctly.
|
||||||
|
*
|
||||||
|
* @see ViewPager#setOnPageChangeListener(ViewPager.OnPageChangeListener)
|
||||||
|
*/
|
||||||
|
public void setOnPageChangeListener(ViewPager.OnPageChangeListener listener) {
|
||||||
|
mViewPagerPageChangeListener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the custom layout to be inflated for the tab views.
|
||||||
|
*
|
||||||
|
* @param layoutResId Layout id to be inflated
|
||||||
|
* @param textViewId id of the {@link TextView} in the inflated view
|
||||||
|
*/
|
||||||
|
public void setCustomTabView(int layoutResId, int textViewId) {
|
||||||
|
mTabViewLayoutId = layoutResId;
|
||||||
|
mTabViewTextViewId = textViewId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the associated view pager. Note that the assumption here is that the pager content
|
||||||
|
* (number of tabs and tab titles) does not change after this call has been made.
|
||||||
|
*/
|
||||||
|
public void setViewPager(ViewPager viewPager) {
|
||||||
|
mTabStrip.removeAllViews();
|
||||||
|
|
||||||
|
mViewPager = viewPager;
|
||||||
|
if (viewPager != null) {
|
||||||
|
viewPager.setOnPageChangeListener(new InternalViewPagerListener());
|
||||||
|
populateTabStrip();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a default view to be used for tabs. This is called if a custom tab view is not set via
|
||||||
|
* {@link #setCustomTabView(int, int)}.
|
||||||
|
*/
|
||||||
|
protected TextView createDefaultTabView(Context context) {
|
||||||
|
TextView textView = new TextView(context);
|
||||||
|
textView.setGravity(Gravity.CENTER);
|
||||||
|
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
|
||||||
|
textView.setTypeface(Typeface.DEFAULT_BOLD);
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||||
|
// If we're running on Honeycomb or newer, then we can use the Theme's
|
||||||
|
// selectableItemBackground to ensure that the View has a pressed state
|
||||||
|
TypedValue outValue = new TypedValue();
|
||||||
|
getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground,
|
||||||
|
outValue, true);
|
||||||
|
textView.setBackgroundResource(outValue.resourceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
|
||||||
|
// If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
|
||||||
|
textView.setAllCaps(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
|
||||||
|
textView.setPadding(padding, padding, padding, padding);
|
||||||
|
|
||||||
|
return textView;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void populateTabStrip() {
|
||||||
|
final PagerAdapter adapter = mViewPager.getAdapter();
|
||||||
|
final View.OnClickListener tabClickListener = new TabClickListener();
|
||||||
|
|
||||||
|
for (int i = 0; i < adapter.getCount(); i++) {
|
||||||
|
View tabView = null;
|
||||||
|
TextView tabTitleView = null;
|
||||||
|
|
||||||
|
if (mTabViewLayoutId != 0) {
|
||||||
|
// If there is a custom tab view layout id set, try and inflate it
|
||||||
|
tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip,
|
||||||
|
false);
|
||||||
|
tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tabView == null) {
|
||||||
|
tabView = createDefaultTabView(getContext());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tabTitleView == null && TextView.class.isInstance(tabView)) {
|
||||||
|
tabTitleView = (TextView) tabView;
|
||||||
|
}
|
||||||
|
|
||||||
|
tabTitleView.setText(adapter.getPageTitle(i));
|
||||||
|
tabView.setOnClickListener(tabClickListener);
|
||||||
|
|
||||||
|
mTabStrip.addView(tabView);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onAttachedToWindow() {
|
||||||
|
super.onAttachedToWindow();
|
||||||
|
|
||||||
|
if (mViewPager != null) {
|
||||||
|
scrollToTab(mViewPager.getCurrentItem(), 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void scrollToTab(int tabIndex, int positionOffset) {
|
||||||
|
final int tabStripChildCount = mTabStrip.getChildCount();
|
||||||
|
if (tabStripChildCount == 0 || tabIndex < 0 || tabIndex >= tabStripChildCount) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
View selectedChild = mTabStrip.getChildAt(tabIndex);
|
||||||
|
if (selectedChild != null) {
|
||||||
|
int targetScrollX = selectedChild.getLeft() + positionOffset;
|
||||||
|
|
||||||
|
if (tabIndex > 0 || positionOffset > 0) {
|
||||||
|
// If we're not at the first child and are mid-scroll, make sure we obey the offset
|
||||||
|
targetScrollX -= mTitleOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
scrollTo(targetScrollX, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class InternalViewPagerListener implements ViewPager.OnPageChangeListener {
|
||||||
|
private int mScrollState;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||||
|
int tabStripChildCount = mTabStrip.getChildCount();
|
||||||
|
if ((tabStripChildCount == 0) || (position < 0) || (position >= tabStripChildCount)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mTabStrip.onViewPagerPageChanged(position, positionOffset);
|
||||||
|
|
||||||
|
View selectedTitle = mTabStrip.getChildAt(position);
|
||||||
|
int extraOffset = (selectedTitle != null)
|
||||||
|
? (int) (positionOffset * selectedTitle.getWidth())
|
||||||
|
: 0;
|
||||||
|
scrollToTab(position, extraOffset);
|
||||||
|
|
||||||
|
if (mViewPagerPageChangeListener != null) {
|
||||||
|
mViewPagerPageChangeListener.onPageScrolled(position, positionOffset,
|
||||||
|
positionOffsetPixels);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPageScrollStateChanged(int state) {
|
||||||
|
mScrollState = state;
|
||||||
|
|
||||||
|
if (mViewPagerPageChangeListener != null) {
|
||||||
|
mViewPagerPageChangeListener.onPageScrollStateChanged(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPageSelected(int position) {
|
||||||
|
if (mScrollState == ViewPager.SCROLL_STATE_IDLE) {
|
||||||
|
mTabStrip.onViewPagerPageChanged(position, 0f);
|
||||||
|
scrollToTab(position, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mViewPagerPageChangeListener != null) {
|
||||||
|
mViewPagerPageChangeListener.onPageSelected(position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TabClickListener implements View.OnClickListener {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
for (int i = 0; i < mTabStrip.getChildCount(); i++) {
|
||||||
|
if (v == mTabStrip.getChildAt(i)) {
|
||||||
|
mViewPager.setCurrentItem(i);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
208
OsmAnd/src/com/example/android/common/view/SlidingTabStrip.java
Normal file
208
OsmAnd/src/com/example/android/common/view/SlidingTabStrip.java
Normal file
|
@ -0,0 +1,208 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013 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 com.example.android.common.view;
|
||||||
|
|
||||||
|
import android.R;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.graphics.Paint;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.util.TypedValue;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
|
||||||
|
class SlidingTabStrip extends LinearLayout {
|
||||||
|
|
||||||
|
private static final int DEFAULT_BOTTOM_BORDER_THICKNESS_DIPS = 2;
|
||||||
|
private static final byte DEFAULT_BOTTOM_BORDER_COLOR_ALPHA = 0x26;
|
||||||
|
private static final int SELECTED_INDICATOR_THICKNESS_DIPS = 8;
|
||||||
|
private static final int DEFAULT_SELECTED_INDICATOR_COLOR = 0xFF33B5E5;
|
||||||
|
|
||||||
|
private static final int DEFAULT_DIVIDER_THICKNESS_DIPS = 1;
|
||||||
|
private static final byte DEFAULT_DIVIDER_COLOR_ALPHA = 0x20;
|
||||||
|
private static final float DEFAULT_DIVIDER_HEIGHT = 0.5f;
|
||||||
|
|
||||||
|
private final int mBottomBorderThickness;
|
||||||
|
private final Paint mBottomBorderPaint;
|
||||||
|
|
||||||
|
private final int mSelectedIndicatorThickness;
|
||||||
|
private final Paint mSelectedIndicatorPaint;
|
||||||
|
|
||||||
|
private final int mDefaultBottomBorderColor;
|
||||||
|
|
||||||
|
private final Paint mDividerPaint;
|
||||||
|
private final float mDividerHeight;
|
||||||
|
|
||||||
|
private int mSelectedPosition;
|
||||||
|
private float mSelectionOffset;
|
||||||
|
|
||||||
|
private SlidingTabLayout.TabColorizer mCustomTabColorizer;
|
||||||
|
private final SimpleTabColorizer mDefaultTabColorizer;
|
||||||
|
|
||||||
|
SlidingTabStrip(Context context) {
|
||||||
|
this(context, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
SlidingTabStrip(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
setWillNotDraw(false);
|
||||||
|
|
||||||
|
final float density = getResources().getDisplayMetrics().density;
|
||||||
|
|
||||||
|
TypedValue outValue = new TypedValue();
|
||||||
|
context.getTheme().resolveAttribute(R.attr.colorForeground, outValue, true);
|
||||||
|
final int themeForegroundColor = outValue.data;
|
||||||
|
|
||||||
|
mDefaultBottomBorderColor = setColorAlpha(themeForegroundColor,
|
||||||
|
DEFAULT_BOTTOM_BORDER_COLOR_ALPHA);
|
||||||
|
|
||||||
|
mDefaultTabColorizer = new SimpleTabColorizer();
|
||||||
|
mDefaultTabColorizer.setIndicatorColors(DEFAULT_SELECTED_INDICATOR_COLOR);
|
||||||
|
mDefaultTabColorizer.setDividerColors(setColorAlpha(themeForegroundColor,
|
||||||
|
DEFAULT_DIVIDER_COLOR_ALPHA));
|
||||||
|
|
||||||
|
mBottomBorderThickness = (int) (DEFAULT_BOTTOM_BORDER_THICKNESS_DIPS * density);
|
||||||
|
mBottomBorderPaint = new Paint();
|
||||||
|
mBottomBorderPaint.setColor(mDefaultBottomBorderColor);
|
||||||
|
|
||||||
|
mSelectedIndicatorThickness = (int) (SELECTED_INDICATOR_THICKNESS_DIPS * density);
|
||||||
|
mSelectedIndicatorPaint = new Paint();
|
||||||
|
|
||||||
|
mDividerHeight = DEFAULT_DIVIDER_HEIGHT;
|
||||||
|
mDividerPaint = new Paint();
|
||||||
|
mDividerPaint.setStrokeWidth((int) (DEFAULT_DIVIDER_THICKNESS_DIPS * density));
|
||||||
|
}
|
||||||
|
|
||||||
|
void setCustomTabColorizer(SlidingTabLayout.TabColorizer customTabColorizer) {
|
||||||
|
mCustomTabColorizer = customTabColorizer;
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setSelectedIndicatorColors(int... colors) {
|
||||||
|
// Make sure that the custom colorizer is removed
|
||||||
|
mCustomTabColorizer = null;
|
||||||
|
mDefaultTabColorizer.setIndicatorColors(colors);
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setDividerColors(int... colors) {
|
||||||
|
// Make sure that the custom colorizer is removed
|
||||||
|
mCustomTabColorizer = null;
|
||||||
|
mDefaultTabColorizer.setDividerColors(colors);
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void onViewPagerPageChanged(int position, float positionOffset) {
|
||||||
|
mSelectedPosition = position;
|
||||||
|
mSelectionOffset = positionOffset;
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDraw(Canvas canvas) {
|
||||||
|
final int height = getHeight();
|
||||||
|
final int childCount = getChildCount();
|
||||||
|
final int dividerHeightPx = (int) (Math.min(Math.max(0f, mDividerHeight), 1f) * height);
|
||||||
|
final SlidingTabLayout.TabColorizer tabColorizer = mCustomTabColorizer != null
|
||||||
|
? mCustomTabColorizer
|
||||||
|
: mDefaultTabColorizer;
|
||||||
|
|
||||||
|
// Thick colored underline below the current selection
|
||||||
|
if (childCount > 0) {
|
||||||
|
View selectedTitle = getChildAt(mSelectedPosition);
|
||||||
|
int left = selectedTitle.getLeft();
|
||||||
|
int right = selectedTitle.getRight();
|
||||||
|
int color = tabColorizer.getIndicatorColor(mSelectedPosition);
|
||||||
|
|
||||||
|
if (mSelectionOffset > 0f && mSelectedPosition < (getChildCount() - 1)) {
|
||||||
|
int nextColor = tabColorizer.getIndicatorColor(mSelectedPosition + 1);
|
||||||
|
if (color != nextColor) {
|
||||||
|
color = blendColors(nextColor, color, mSelectionOffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw the selection partway between the tabs
|
||||||
|
View nextTitle = getChildAt(mSelectedPosition + 1);
|
||||||
|
left = (int) (mSelectionOffset * nextTitle.getLeft() +
|
||||||
|
(1.0f - mSelectionOffset) * left);
|
||||||
|
right = (int) (mSelectionOffset * nextTitle.getRight() +
|
||||||
|
(1.0f - mSelectionOffset) * right);
|
||||||
|
}
|
||||||
|
|
||||||
|
mSelectedIndicatorPaint.setColor(color);
|
||||||
|
|
||||||
|
canvas.drawRect(left, height - mSelectedIndicatorThickness, right,
|
||||||
|
height, mSelectedIndicatorPaint);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Thin underline along the entire bottom edge
|
||||||
|
canvas.drawRect(0, height - mBottomBorderThickness, getWidth(), height, mBottomBorderPaint);
|
||||||
|
|
||||||
|
// Vertical separators between the titles
|
||||||
|
int separatorTop = (height - dividerHeightPx) / 2;
|
||||||
|
for (int i = 0; i < childCount - 1; i++) {
|
||||||
|
View child = getChildAt(i);
|
||||||
|
mDividerPaint.setColor(tabColorizer.getDividerColor(i));
|
||||||
|
canvas.drawLine(child.getRight(), separatorTop, child.getRight(),
|
||||||
|
separatorTop + dividerHeightPx, mDividerPaint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the alpha value of the {@code color} to be the given {@code alpha} value.
|
||||||
|
*/
|
||||||
|
private static int setColorAlpha(int color, byte alpha) {
|
||||||
|
return Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Blend {@code color1} and {@code color2} using the given ratio.
|
||||||
|
*
|
||||||
|
* @param ratio of which to blend. 1.0 will return {@code color1}, 0.5 will give an even blend,
|
||||||
|
* 0.0 will return {@code color2}.
|
||||||
|
*/
|
||||||
|
private static int blendColors(int color1, int color2, float ratio) {
|
||||||
|
final float inverseRation = 1f - ratio;
|
||||||
|
float r = (Color.red(color1) * ratio) + (Color.red(color2) * inverseRation);
|
||||||
|
float g = (Color.green(color1) * ratio) + (Color.green(color2) * inverseRation);
|
||||||
|
float b = (Color.blue(color1) * ratio) + (Color.blue(color2) * inverseRation);
|
||||||
|
return Color.rgb((int) r, (int) g, (int) b);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SimpleTabColorizer implements SlidingTabLayout.TabColorizer {
|
||||||
|
private int[] mIndicatorColors;
|
||||||
|
private int[] mDividerColors;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final int getIndicatorColor(int position) {
|
||||||
|
return mIndicatorColors[position % mIndicatorColors.length];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final int getDividerColor(int position) {
|
||||||
|
return mDividerColors[position % mDividerColors.length];
|
||||||
|
}
|
||||||
|
|
||||||
|
void setIndicatorColors(int... colors) {
|
||||||
|
mIndicatorColors = colors;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setDividerColors(int... colors) {
|
||||||
|
mDividerColors = colors;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,6 +8,7 @@ import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import android.support.v4.app.ListFragment;
|
import android.support.v4.app.ListFragment;
|
||||||
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
import net.osmand.data.FavouritePoint;
|
import net.osmand.data.FavouritePoint;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
|
@ -16,7 +17,6 @@ import net.osmand.plus.OsmAndFormatter;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.OsmandSettings;
|
import net.osmand.plus.OsmandSettings;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.search.BottomMenuItem;
|
|
||||||
import net.osmand.plus.activities.search.SearchActivity;
|
import net.osmand.plus.activities.search.SearchActivity;
|
||||||
import net.osmand.plus.activities.search.SearchActivity.SearchActivityChild;
|
import net.osmand.plus.activities.search.SearchActivity.SearchActivityChild;
|
||||||
import net.osmand.plus.base.FavoriteImageDrawable;
|
import net.osmand.plus.base.FavoriteImageDrawable;
|
||||||
|
@ -102,9 +102,9 @@ public class FavouritesListFragment extends ListFragment implements SearchActivi
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
public void onCreateOptionsMenu(Menu onCreate, MenuInflater inflater) {
|
||||||
if(getActivity() instanceof SearchActivity) {
|
if(getActivity() instanceof SearchActivity) {
|
||||||
((SearchActivity)getActivity()).setupBottomMenu(new ArrayList<BottomMenuItem>());
|
((SearchActivity) getActivity()).getClearToolbar(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,23 +2,14 @@ package net.osmand.plus.activities;
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.text.DecimalFormatSymbols;
|
import java.text.DecimalFormatSymbols;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
import android.support.v4.app.Fragment;
|
|
||||||
import android.support.v4.view.MenuItemCompat;
|
|
||||||
import android.view.Menu;
|
|
||||||
import android.view.MenuInflater;
|
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.view.MenuItem.OnMenuItemClickListener;
|
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.TargetPointsHelper;
|
import net.osmand.plus.TargetPointsHelper;
|
||||||
import net.osmand.plus.activities.search.BottomMenuItem;
|
|
||||||
import net.osmand.plus.activities.search.SearchActivity;
|
import net.osmand.plus.activities.search.SearchActivity;
|
||||||
import net.osmand.plus.activities.search.SearchActivity.SearchActivityChild;
|
import net.osmand.plus.activities.search.SearchActivity.SearchActivityChild;
|
||||||
import net.osmand.plus.dialogs.DirectionsDialogs;
|
import net.osmand.plus.dialogs.DirectionsDialogs;
|
||||||
|
@ -28,9 +19,15 @@ import android.app.Dialog;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.view.MenuItem.OnMenuItemClickListener;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.AdapterView.OnItemSelectedListener;
|
import android.widget.AdapterView.OnItemSelectedListener;
|
||||||
|
@ -111,63 +108,65 @@ public class NavigatePointFragment extends Fragment implements SearchActivityChi
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
public void onCreateOptionsMenu(Menu onCreate, MenuInflater inflater) {
|
||||||
OsmandApplication app = (OsmandApplication) getActivity().getApplication();
|
OsmandApplication app = (OsmandApplication) getActivity().getApplication();
|
||||||
boolean light = app.getSettings().isLightActionBar();
|
boolean light = app.getSettings().isLightActionBar();
|
||||||
|
Menu menu = onCreate;
|
||||||
|
if(getActivity() instanceof SearchActivity) {
|
||||||
|
menu = ((SearchActivity) getActivity()).getClearToolbar(true).getMenu();
|
||||||
|
}
|
||||||
|
MenuItem menuItem = menu.add(0, NAVIGATE_TO, 0, R.string.context_menu_item_directions_to).setShowAsActionFlags(
|
||||||
|
MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||||
|
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_gdirections_light : R.drawable.ic_action_gdirections_dark);
|
||||||
|
menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
|
||||||
|
|
||||||
List<BottomMenuItem> menuItems = new ArrayList<BottomMenuItem>();
|
|
||||||
BottomMenuItem menuItem = new BottomMenuItem().
|
|
||||||
setIcon(light ? R.drawable.ic_action_gdirections_light : R.drawable.ic_action_gdirections_dark).
|
|
||||||
setMsg(R.string.context_menu_item_directions_to).
|
|
||||||
setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
select(NAVIGATE_TO);
|
select(NAVIGATE_TO);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
menuItems.add(menuItem);
|
|
||||||
|
|
||||||
TargetPointsHelper targets = app.getTargetPointsHelper();
|
TargetPointsHelper targets = app.getTargetPointsHelper();
|
||||||
menuItem = new BottomMenuItem();
|
|
||||||
if (targets.getPointToNavigate() != null) {
|
if (targets.getPointToNavigate() != null) {
|
||||||
menuItem.setIcon(light ? R.drawable.ic_action_flage_light : R.drawable.ic_action_flage_dark).
|
menuItem = menu.add(0, ADD_WAYPOINT, 0, R.string.context_menu_item_intermediate_point).setShowAsActionFlags(
|
||||||
setMsg(R.string.context_menu_item_intermediate_point);
|
MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||||
|
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_flage_light
|
||||||
|
: R.drawable.ic_action_flage_dark);
|
||||||
} else {
|
} else {
|
||||||
menuItem.setIcon(light ? R.drawable.ic_action_flag_light : R.drawable.ic_action_flag_dark).
|
menuItem = menu.add(0, ADD_WAYPOINT, 0, R.string.context_menu_item_destination_point).setShowAsActionFlags(
|
||||||
setMsg(R.string.context_menu_item_destination_point);
|
MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||||
|
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_flag_light
|
||||||
|
: R.drawable.ic_action_flag_dark);
|
||||||
}
|
}
|
||||||
menuItem.setOnClickListener(new View.OnClickListener() {
|
menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
select(ADD_WAYPOINT);
|
select(ADD_WAYPOINT);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
menuItems.add(menuItem);
|
//}
|
||||||
|
menuItem = menu.add(0, SHOW_ON_MAP, 0, R.string.search_shown_on_map).setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||||
|
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_marker_light : R.drawable.ic_action_marker_dark);
|
||||||
|
|
||||||
menuItem = new BottomMenuItem().
|
menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
|
||||||
setIcon(light ? R.drawable.ic_action_marker_light : R.drawable.ic_action_marker_dark).
|
|
||||||
setMsg(R.string.search_shown_on_map).
|
|
||||||
setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
select(SHOW_ON_MAP);
|
select(SHOW_ON_MAP);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
menuItems.add(menuItem);
|
|
||||||
|
|
||||||
|
menuItem = menu.add(0, ADD_TO_FAVORITE, 0, R.string.add_to_favourite).setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||||
|
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_fav_light : R.drawable.ic_action_fav_dark);
|
||||||
|
|
||||||
menuItem = new BottomMenuItem().
|
menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
|
||||||
setIcon(light ? R.drawable.ic_action_fav_light : R.drawable.ic_action_fav_dark).
|
|
||||||
setMsg(R.string.add_to_favourite).
|
|
||||||
setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
select(ADD_TO_FAVORITE);
|
select(ADD_TO_FAVORITE);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
menuItems.add(menuItem);
|
|
||||||
|
|
||||||
((SearchActivity)getActivity()).setupBottomMenu(menuItems);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,40 +0,0 @@
|
||||||
package net.osmand.plus.activities.search;
|
|
||||||
|
|
||||||
import android.view.View;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Denis
|
|
||||||
* on 19.01.2015.
|
|
||||||
*/
|
|
||||||
public class BottomMenuItem {
|
|
||||||
private int icon;
|
|
||||||
private View.OnClickListener onClickListener;
|
|
||||||
private int msg;
|
|
||||||
|
|
||||||
public BottomMenuItem setIcon(int iconId) {
|
|
||||||
this.icon = iconId;
|
|
||||||
return BottomMenuItem.this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BottomMenuItem setMsg(int message) {
|
|
||||||
this.msg = message;
|
|
||||||
return BottomMenuItem.this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BottomMenuItem setOnClickListener(View.OnClickListener onClickListener) {
|
|
||||||
this.onClickListener = onClickListener;
|
|
||||||
return BottomMenuItem.this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getIcon() {
|
|
||||||
return icon;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMsg() {
|
|
||||||
return msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
public View.OnClickListener getOnClickListener(){
|
|
||||||
return onClickListener;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,5 +1,6 @@
|
||||||
package net.osmand.plus.activities.search;
|
package net.osmand.plus.activities.search;
|
||||||
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -8,11 +9,6 @@ import java.util.Formatter;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import android.content.pm.ActivityInfo;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.support.v7.app.ActionBarActivity;
|
|
||||||
import android.view.*;
|
|
||||||
import android.widget.*;
|
|
||||||
import net.osmand.data.FavouritePoint;
|
import net.osmand.data.FavouritePoint;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
import net.osmand.plus.OsmAndLocationProvider;
|
import net.osmand.plus.OsmAndLocationProvider;
|
||||||
|
@ -25,24 +21,26 @@ import net.osmand.plus.activities.FavouritesListFragment;
|
||||||
import net.osmand.plus.activities.NavigatePointFragment;
|
import net.osmand.plus.activities.NavigatePointFragment;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
import android.app.ActionBar;
|
import android.app.ActionBar;
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.graphics.Color;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentActivity;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v4.app.FragmentPagerAdapter;
|
import android.support.v4.app.FragmentPagerAdapter;
|
||||||
import android.support.v4.view.ViewPager;
|
import android.support.v4.view.ViewPager;
|
||||||
import android.util.Log;
|
import android.support.v4.view.ViewPager.OnPageChangeListener;
|
||||||
import android.widget.TabHost.TabSpec;
|
|
||||||
import android.support.v7.app.ActionBar.OnNavigationListener;
|
import android.support.v7.app.ActionBar.OnNavigationListener;
|
||||||
|
import android.support.v7.app.ActionBarActivity;
|
||||||
|
import android.support.v7.widget.Toolbar;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.Button;
|
||||||
|
|
||||||
|
import com.example.android.common.view.SlidingTabLayout;
|
||||||
|
|
||||||
public class SearchActivity extends ActionBarActivity implements OsmAndLocationListener {
|
public class SearchActivity extends ActionBarActivity implements OsmAndLocationListener {
|
||||||
private static final String SEARCH_HISTORY = "Search_History";
|
|
||||||
private static final String SEARCH_FAVORITES = "Search_Favorites";
|
|
||||||
private static final String SEARCH_TRANSPORT = "Search_Transport";
|
|
||||||
private static final String SEARCH_LOCATION = "Search_Location";
|
|
||||||
private static final String SEARCH_ADDRESS = "Search_Address";
|
|
||||||
private static final String SEARCH_POI = "Search_POI";
|
|
||||||
public static final int POI_TAB_INDEX = 0;
|
public static final int POI_TAB_INDEX = 0;
|
||||||
public static final int ADDRESS_TAB_INDEX = 1;
|
public static final int ADDRESS_TAB_INDEX = 1;
|
||||||
public static final int LOCATION_TAB_INDEX = 2;
|
public static final int LOCATION_TAB_INDEX = 2;
|
||||||
|
@ -70,24 +68,38 @@ public class SearchActivity extends ActionBarActivity implements OsmAndLocationL
|
||||||
private static boolean searchOnLine = false;
|
private static boolean searchOnLine = false;
|
||||||
private ArrayAdapter<String> spinnerAdapter;
|
private ArrayAdapter<String> spinnerAdapter;
|
||||||
private OsmandSettings settings;
|
private OsmandSettings settings;
|
||||||
private TabsAdapter mTabsAdapter;
|
|
||||||
List<WeakReference<Fragment>> fragList = new ArrayList<WeakReference<Fragment>>();
|
List<WeakReference<Fragment>> fragList = new ArrayList<WeakReference<Fragment>>();
|
||||||
private boolean showOnlyOneTab;
|
private boolean showOnlyOneTab;
|
||||||
|
|
||||||
|
private List<TabItem> mTabs = new ArrayList<TabItem>();
|
||||||
|
private ViewPager mViewPager;
|
||||||
|
private SlidingTabLayout mSlidingTabLayout;
|
||||||
|
|
||||||
public interface SearchActivityChild {
|
public interface SearchActivityChild {
|
||||||
|
|
||||||
public void locationUpdate(LatLon l);
|
public void locationUpdate(LatLon l);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class TabItem {
|
||||||
|
private final CharSequence mTitle;
|
||||||
|
private final int mIcon;
|
||||||
|
private final int mIndicatorColor;
|
||||||
|
private final int mDividerColor;
|
||||||
|
private final Class<?> fragment;
|
||||||
|
|
||||||
|
public TabItem(CharSequence mTitle, int mIcon, int mIndicatorColor, int mDividerColor, Class<?> fragment) {
|
||||||
|
this.mTitle = mTitle;
|
||||||
|
this.mIcon = mIcon;
|
||||||
|
this.mIndicatorColor = mIndicatorColor;
|
||||||
|
this.mDividerColor = mDividerColor;
|
||||||
|
this.fragment = fragment;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private View getTabIndicator(TabHost tabHost, int imageId, int stringId){
|
private TabItem getTabIndicator(int iconId, int resId, Class<?> fragment){
|
||||||
View r = getLayoutInflater().inflate(R.layout.search_main_tab_header, tabHost, false);
|
return new TabItem(getString(resId), iconId, Color.DKGRAY, Color.LTGRAY, fragment);
|
||||||
ImageView tabImage = (ImageView)r.findViewById(R.id.TabImage);
|
|
||||||
tabImage.setImageResource(imageId);
|
|
||||||
tabImage.setBackgroundResource(R.drawable.tab_icon_background);
|
|
||||||
tabImage.setContentDescription(getString(stringId));
|
|
||||||
return r;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -107,34 +119,36 @@ public class SearchActivity extends ActionBarActivity implements OsmAndLocationL
|
||||||
|
|
||||||
|
|
||||||
if (!showOnlyOneTab) {
|
if (!showOnlyOneTab) {
|
||||||
final TextView tabinfo = (TextView) findViewById(R.id.textViewADesc);
|
mViewPager = (ViewPager)findViewById(R.id.pager);
|
||||||
TabWidget tabs = (TabWidget) findViewById(android.R.id.tabs);
|
mSlidingTabLayout = (SlidingTabLayout) findViewById(R.id.sliding_tabs);
|
||||||
tabs.setBackgroundResource(R.drawable.tab_icon_background);
|
|
||||||
|
|
||||||
TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost);
|
mTabs.add(getTabIndicator(R.drawable.tab_search_poi_icon, R.string.poi, getFragment(POI_TAB_INDEX)));
|
||||||
tabHost.setup();
|
mTabs.add(getTabIndicator(R.drawable.tab_search_address_icon, R.string.address, getFragment(ADDRESS_TAB_INDEX)));
|
||||||
ViewPager mViewPager = (ViewPager)findViewById(R.id.pager);
|
mTabs.add(getTabIndicator(R.drawable.tab_search_location_icon, R.string.search_tabs_location, getFragment(LOCATION_TAB_INDEX)));
|
||||||
mTabsAdapter = new TabsAdapter(this, tabHost, tabinfo, mViewPager, settings);
|
mTabs.add(getTabIndicator(R.drawable.tab_search_favorites_icon, R.string.favorite, getFragment(FAVORITES_TAB_INDEX)));
|
||||||
TabSpec poiTab = tabHost.newTabSpec(SEARCH_POI).setIndicator(
|
mTabs.add(getTabIndicator(R.drawable.tab_search_history_icon, R.string.history, getFragment(HISTORY_TAB_INDEX)));
|
||||||
getTabIndicator(tabHost, R.drawable.tab_search_poi_icon, R.string.poi));
|
|
||||||
mTabsAdapter.addTab(poiTab, getFragment(POI_TAB_INDEX), null);
|
|
||||||
TabSpec addressSpec = tabHost.newTabSpec(SEARCH_ADDRESS).setIndicator(
|
|
||||||
getTabIndicator(tabHost, R.drawable.tab_search_address_icon, R.string.address));
|
|
||||||
mTabsAdapter.addTab(addressSpec, getFragment(ADDRESS_TAB_INDEX), null);
|
|
||||||
|
|
||||||
TabSpec locationTab = tabHost.newTabSpec(SEARCH_LOCATION).setIndicator(
|
|
||||||
getTabIndicator(tabHost, R.drawable.tab_search_location_icon, R.string.search_tabs_location));
|
mViewPager.setAdapter(new SearchFragmentPagerAdapter(getSupportFragmentManager()));
|
||||||
mTabsAdapter.addTab(locationTab, getFragment(LOCATION_TAB_INDEX), null);
|
mSlidingTabLayout.setViewPager(mViewPager);
|
||||||
TabSpec favoriteTab = tabHost.newTabSpec(SEARCH_FAVORITES).setIndicator(
|
|
||||||
getTabIndicator(tabHost, R.drawable.tab_search_favorites_icon, R.string.favorite));
|
mViewPager.setCurrentItem(Math.min(tab , HISTORY_TAB_INDEX));
|
||||||
mTabsAdapter.addTab(favoriteTab, getFragment(FAVORITES_TAB_INDEX), null);
|
mSlidingTabLayout.setOnPageChangeListener(new OnPageChangeListener() {
|
||||||
TabSpec historyTab = tabHost.newTabSpec(SEARCH_HISTORY).setIndicator(
|
|
||||||
getTabIndicator(tabHost, R.drawable.tab_search_history_icon, R.string.history));
|
@Override
|
||||||
mTabsAdapter.addTab(historyTab, getFragment(HISTORY_TAB_INDEX), null);
|
public void onPageSelected(int arg0) {
|
||||||
// TabSpec transportTab = tabHost.newTabSpec(SEARCH_TRANSPORT).setIndicator(
|
settings.SEARCH_TAB.set(arg0);
|
||||||
// getTabIndicator(tabHost, R.drawable.tab_search_transport_icon, R.string.transport));
|
}
|
||||||
// mTabsAdapter.addTab(transportTab, getFragment(TRANSPORT_TAB_INDEX), null);
|
|
||||||
tabHost.setCurrentTab(Math.min(tab , HISTORY_TAB_INDEX));
|
@Override
|
||||||
|
public void onPageScrolled(int arg0, float arg1, int arg2) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPageScrollStateChanged(int arg0) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
setContentView(R.layout.search_activity_single);
|
setContentView(R.layout.search_activity_single);
|
||||||
Class<?> cl = getFragment(tab);
|
Class<?> cl = getFragment(tab);
|
||||||
|
@ -285,31 +299,14 @@ public class SearchActivity extends ActionBarActivity implements OsmAndLocationL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setupBottomMenu(List<BottomMenuItem> menuItems) {
|
public Toolbar getClearToolbar(boolean visible) {
|
||||||
LinearLayout bottomControls = (LinearLayout) findViewById(R.id.bottomControls);
|
final Toolbar tb = (Toolbar) findViewById(R.id.bottomControls);
|
||||||
if (bottomControls == null) {
|
tb.setTitle(null);
|
||||||
return;
|
tb.getMenu().clear();
|
||||||
}
|
tb.setVisibility(visible? View.VISIBLE : View.GONE);
|
||||||
bottomControls.removeAllViews();
|
return tb;
|
||||||
|
|
||||||
if (menuItems.size() == 0) {
|
|
||||||
findViewById(R.id.devider).setVisibility(View.GONE);
|
|
||||||
} else {
|
|
||||||
findViewById(R.id.devider).setVisibility(View.VISIBLE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (BottomMenuItem item : menuItems) {
|
|
||||||
ImageButton imageButton = new ImageButton(this);
|
|
||||||
imageButton.setImageResource(item.getIcon());
|
|
||||||
TableRow.LayoutParams params = new TableRow.LayoutParams(0,
|
|
||||||
ViewGroup.LayoutParams.WRAP_CONTENT, 1.0f);
|
|
||||||
params.gravity = Gravity.CENTER_VERTICAL;
|
|
||||||
imageButton.setLayoutParams(params);
|
|
||||||
imageButton.setOnClickListener(item.getOnClickListener());
|
|
||||||
imageButton.setBackgroundResource(R.drawable.bottom_menu_item);
|
|
||||||
bottomControls.addView(imageButton);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateLocation(net.osmand.Location location){
|
public void updateLocation(net.osmand.Location location){
|
||||||
if (location != null) {
|
if (location != null) {
|
||||||
|
@ -410,128 +407,42 @@ public class SearchActivity extends ActionBarActivity implements OsmAndLocationL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class SearchFragmentPagerAdapter extends FragmentPagerAdapter
|
||||||
|
/*implements TabHost.OnTabChangeListener, ViewPager.OnPageChangeListener*/ {
|
||||||
|
|
||||||
|
SearchFragmentPagerAdapter(FragmentManager fm) {
|
||||||
|
super(fm);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a helper class that implements the management of tabs and all
|
* Return the {@link android.support.v4.app.Fragment} to be displayed at {@code position}.
|
||||||
* details of connecting a ViewPager with associated TabHost. It relies on a
|
* <p>
|
||||||
* trick. Normally a tab host has a simple API for supplying a View or
|
* Here we return the value returned from {@link SamplePagerItem#createFragment()}.
|
||||||
* Intent that each tab will show. This is not sufficient for switching
|
|
||||||
* between pages. So instead we make the content part of the tab host
|
|
||||||
* 0dp high (it is not shown) and the TabsAdapter supplies its own dummy
|
|
||||||
* view to show as the tab content. It listens to changes in tabs, and takes
|
|
||||||
* care of switch to the correct paged in the ViewPager whenever the selected
|
|
||||||
* tab changes.
|
|
||||||
*/
|
*/
|
||||||
public static class TabsAdapter extends FragmentPagerAdapter
|
|
||||||
implements TabHost.OnTabChangeListener, ViewPager.OnPageChangeListener {
|
|
||||||
private final Context mContext;
|
|
||||||
private final TabHost mTabHost;
|
|
||||||
private final ViewPager mViewPager;
|
|
||||||
private final ArrayList<TabInfo> mTabs = new ArrayList<TabInfo>();
|
|
||||||
private TextView tabInfo;
|
|
||||||
private OsmandSettings osmSettings;
|
|
||||||
|
|
||||||
static final class TabInfo {
|
|
||||||
private final String tag;
|
|
||||||
private Class<?> clss;
|
|
||||||
private Bundle args;
|
|
||||||
|
|
||||||
TabInfo(String _tag, Class<?> _class, Bundle _args) {
|
|
||||||
tag = _tag;
|
|
||||||
clss = _class;
|
|
||||||
args = _args;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static class DummyTabFactory implements TabHost.TabContentFactory {
|
|
||||||
private final Context mContext;
|
|
||||||
|
|
||||||
public DummyTabFactory(Context context) {
|
|
||||||
mContext = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View createTabContent(String tag) {
|
public Fragment getItem(int i) {
|
||||||
View v = new View(mContext);
|
try {
|
||||||
v.setMinimumWidth(0);
|
return (Fragment) mTabs.get(i).fragment.newInstance();
|
||||||
v.setMinimumHeight(0);
|
} catch (Exception e) {
|
||||||
return v;
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public TabsAdapter(FragmentActivity activity, TabHost tabHost, TextView tabinfo, ViewPager pager, OsmandSettings settings) {
|
|
||||||
super(activity.getSupportFragmentManager());
|
|
||||||
mContext = activity;
|
|
||||||
mTabHost = tabHost;
|
|
||||||
tabInfo = tabinfo;
|
|
||||||
mViewPager = pager;
|
|
||||||
osmSettings = settings;
|
|
||||||
mTabHost.setOnTabChangedListener(this);
|
|
||||||
mViewPager.setAdapter(this);
|
|
||||||
mViewPager.setOnPageChangeListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addTab(TabHost.TabSpec tabSpec, Class<?> clss, Bundle args) {
|
|
||||||
tabSpec.setContent(new DummyTabFactory(mContext));
|
|
||||||
String tag = tabSpec.getTag();
|
|
||||||
|
|
||||||
TabInfo info = new TabInfo(tag, clss, args);
|
|
||||||
mTabs.add(info);
|
|
||||||
mTabHost.addTab(tabSpec);
|
|
||||||
notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
return mTabs.size();
|
return mTabs.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BEGIN_INCLUDE (pageradapter_getpagetitle)
|
||||||
|
/**
|
||||||
|
* Return the title of the item at {@code position}. This is important as what this method
|
||||||
|
* returns is what is displayed in the {@link SlidingTabLayout}.
|
||||||
|
* <p>
|
||||||
|
* Here we return the value returned from {@link SamplePagerItem#getTitle()}.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Fragment getItem(int position) {
|
public CharSequence getPageTitle(int position) {
|
||||||
TabInfo info = mTabs.get(position);
|
return mTabs.get(position).mTitle;
|
||||||
return Fragment.instantiate(mContext, info.clss.getName(), info.args);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onTabChanged(String tabId) {
|
|
||||||
int position = mTabHost.getCurrentTab();
|
|
||||||
osmSettings.SEARCH_TAB.set(position);
|
|
||||||
mViewPager.setCurrentItem(position);
|
|
||||||
if (SEARCH_POI.equals(tabId)) {
|
|
||||||
tabInfo.setText(R.string.poi_search_desc);
|
|
||||||
} else if (SEARCH_ADDRESS.equals(tabId)) {
|
|
||||||
tabInfo.setText(searchOnLine ? R.string.search_osm_nominatim : R.string.address_search_desc);
|
|
||||||
} else if (SEARCH_LOCATION.equals(tabId)) {
|
|
||||||
tabInfo.setText(R.string.navpoint_search_desc);
|
|
||||||
} else if (SEARCH_TRANSPORT.equals(tabId)) {
|
|
||||||
tabInfo.setText(R.string.transport_search_desc);
|
|
||||||
} else if (SEARCH_FAVORITES.equals(tabId)) {
|
|
||||||
tabInfo.setText(R.string.favourites_search_desc);
|
|
||||||
} else if (SEARCH_HISTORY.equals(tabId)) {
|
|
||||||
tabInfo.setText(R.string.history_search_desc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPageSelected(int position) {
|
|
||||||
// Unfortunately when TabHost changes the current tab, it kindly
|
|
||||||
// also takes care of putting focus on it when not in touch mode.
|
|
||||||
// The jerk.
|
|
||||||
// This hack tries to prevent this from pulling focus out of our
|
|
||||||
// ViewPager.
|
|
||||||
TabWidget widget = mTabHost.getTabWidget();
|
|
||||||
int oldFocusability = widget.getDescendantFocusability();
|
|
||||||
widget.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
|
|
||||||
mTabHost.setCurrentTab(position);
|
|
||||||
widget.setDescendantFocusability(oldFocusability);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPageScrollStateChanged(int state) {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import java.util.List;
|
||||||
|
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.view.MenuItemCompat;
|
import android.support.v4.view.MenuItemCompat;
|
||||||
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
@ -80,11 +81,15 @@ public class SearchAddressFragment extends Fragment {
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
public void onCreateOptionsMenu(Menu onCreate, MenuInflater inflater) {
|
||||||
boolean light = ((OsmandApplication) getApplication()).getSettings().isLightActionBar();
|
boolean light = ((OsmandApplication) getApplication()).getSettings().isLightActionBar();
|
||||||
|
Menu menu = onCreate;
|
||||||
|
if(getActivity() instanceof SearchActivity) {
|
||||||
|
menu = ((SearchActivity) getActivity()).getClearToolbar(true).getMenu();
|
||||||
|
}
|
||||||
if(getActivity() instanceof SearchAddressActivity) {
|
if(getActivity() instanceof SearchAddressActivity) {
|
||||||
MenuItem menuItem = menu.add(0, SELECT_POINT, 0, "");
|
MenuItem menuItem = menu.add(0, SELECT_POINT, 0, "").setShowAsActionFlags(
|
||||||
MenuItemCompat.setShowAsAction(menuItem, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
|
MenuItem.SHOW_AS_ACTION_ALWAYS );
|
||||||
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_ok_light : R.drawable.ic_action_ok_dark);
|
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_ok_light : R.drawable.ic_action_ok_dark);
|
||||||
menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
|
menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -94,71 +99,63 @@ public class SearchAddressFragment extends Fragment {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
List<BottomMenuItem> menuItems = new ArrayList<BottomMenuItem>();
|
MenuItem menuItem = menu.add(0, NAVIGATE_TO, 0, R.string.context_menu_item_directions_to).setShowAsActionFlags(
|
||||||
BottomMenuItem menuItem = new BottomMenuItem().
|
MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||||
setIcon(light ? R.drawable.ic_action_gdirections_light : R.drawable.ic_action_gdirections_dark).
|
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_gdirections_light : R.drawable.ic_action_gdirections_dark);
|
||||||
setMsg(R.string.context_menu_item_directions_to).
|
menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
|
||||||
setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
select(NAVIGATE_TO);
|
select(NAVIGATE_TO);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
menuItems.add(menuItem);
|
|
||||||
|
|
||||||
TargetPointsHelper targets = ((OsmandApplication) getApplication()).getTargetPointsHelper();
|
TargetPointsHelper targets = ((OsmandApplication) getApplication()).getTargetPointsHelper();
|
||||||
menuItem = new BottomMenuItem();
|
|
||||||
if (targets.getPointToNavigate() != null) {
|
if (targets.getPointToNavigate() != null) {
|
||||||
menuItem.setIcon(light ? R.drawable.ic_action_flage_light : R.drawable.ic_action_flage_dark).
|
menuItem = menu.add(0, ADD_WAYPOINT, 0, R.string.context_menu_item_intermediate_point).setShowAsActionFlags(
|
||||||
setMsg(R.string.context_menu_item_intermediate_point);
|
MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||||
|
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_flage_light : R.drawable.ic_action_flage_dark);
|
||||||
} else {
|
} else {
|
||||||
menuItem.setIcon(light ? R.drawable.ic_action_flag_light : R.drawable.ic_action_flag_dark).
|
menuItem = menu.add(0, ADD_WAYPOINT, 0, R.string.context_menu_item_destination_point).setShowAsActionFlags(
|
||||||
setMsg(R.string.context_menu_item_destination_point);
|
MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||||
|
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_flag_light : R.drawable.ic_action_flag_dark);
|
||||||
}
|
}
|
||||||
menuItem.setOnClickListener(new View.OnClickListener() {
|
menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
select(ADD_WAYPOINT);
|
select(ADD_WAYPOINT);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
menuItems.add(menuItem);
|
menuItem = menu.add(0, SHOW_ON_MAP, 0, R.string.search_shown_on_map).setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||||
|
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_marker_light : R.drawable.ic_action_marker_dark);
|
||||||
|
|
||||||
menuItem = new BottomMenuItem().
|
menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
|
||||||
setIcon(light ? R.drawable.ic_action_marker_light : R.drawable.ic_action_marker_dark).
|
|
||||||
setMsg(R.string.search_shown_on_map).
|
|
||||||
setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
select(SHOW_ON_MAP);
|
select(SHOW_ON_MAP);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
menuItems.add(menuItem);
|
|
||||||
|
|
||||||
menuItem = new BottomMenuItem().
|
menuItem = menu.add(0, ADD_TO_FAVORITE, 0, R.string.add_to_favourite).setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||||
setIcon(light ? R.drawable.ic_action_fav_light : R.drawable.ic_action_fav_dark).
|
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_fav_light : R.drawable.ic_action_fav_dark);
|
||||||
setMsg(R.string.add_to_favourite).
|
|
||||||
setOnClickListener(new View.OnClickListener() {
|
menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
select(ADD_TO_FAVORITE);
|
select(ADD_TO_FAVORITE);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
menuItems.add(menuItem);
|
menuItem = menu.add(0, ONLINE_SEARCH, 0, R.string.search_online_address).setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||||
|
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_gnext_light : R.drawable.ic_action_gnext_dark);
|
||||||
menuItem = new BottomMenuItem().
|
menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
|
||||||
setIcon(light ? R.drawable.ic_action_gnext_light : R.drawable.ic_action_gnext_dark).
|
|
||||||
setMsg(R.string.search_online_address).
|
|
||||||
setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
((SearchActivity) getActivity()).startSearchAddressOnline();
|
((SearchActivity) getActivity()).startSearchAddressOnline();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
menuItems.add(menuItem);
|
|
||||||
|
|
||||||
if (getActivity() instanceof SearchActivity) {
|
|
||||||
((SearchActivity)getActivity()).setupBottomMenu(menuItems);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import java.util.Locale;
|
||||||
|
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.view.MenuItemCompat;
|
import android.support.v4.view.MenuItemCompat;
|
||||||
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
import android.view.MenuItem.OnMenuItemClickListener;
|
import android.view.MenuItem.OnMenuItemClickListener;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
|
@ -57,34 +58,34 @@ public class SearchAddressOnlineFragment extends Fragment implements SearchActiv
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
public void onCreateOptionsMenu(Menu onCreate, MenuInflater inflater) {
|
||||||
boolean light = ((OsmandApplication) getActivity().getApplication()).getSettings().isLightActionBar();
|
boolean light = ((OsmandApplication) getActivity().getApplication()).getSettings().isLightActionBar();
|
||||||
List<BottomMenuItem> menuItems = new ArrayList<BottomMenuItem>();
|
Menu menu = onCreate;
|
||||||
BottomMenuItem menuItem = new BottomMenuItem().
|
if(getActivity() instanceof SearchActivity) {
|
||||||
setIcon(light ? R.drawable.ic_action_gremove_light : R.drawable.ic_action_gremove_dark).
|
menu = ((SearchActivity) getActivity()).getClearToolbar(true).getMenu();
|
||||||
setMsg(R.string.search_offline_clear_search).
|
}
|
||||||
setOnClickListener(new View.OnClickListener() {
|
MenuItem menuItem = menu.add(0, 1, 0, R.string.search_offline_clear_search).setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT );
|
||||||
|
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_gremove_light : R.drawable.ic_action_gremove_dark);
|
||||||
|
|
||||||
|
menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
searchText.setText("");
|
searchText.setText("");
|
||||||
adapter.clear();
|
adapter.clear();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
menuItems.add(menuItem);
|
|
||||||
|
|
||||||
menuItem = new BottomMenuItem().
|
|
||||||
setIcon(light ? R.drawable.ic_action_gnext_light : R.drawable.ic_action_gnext_dark).
|
|
||||||
setMsg(R.string.search_offline_address).
|
|
||||||
setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
((SearchActivity) getActivity()).startSearchAddressOffline();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
menuItems.add(menuItem);
|
|
||||||
|
|
||||||
if (getActivity() instanceof SearchActivity) {
|
if (getActivity() instanceof SearchActivity) {
|
||||||
((SearchActivity)getActivity()).setupBottomMenu(menuItems);
|
menuItem = menu.add(0, 0, 0, R.string.search_offline_address).setShowAsActionFlags(
|
||||||
|
MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||||
|
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_gnext_light : R.drawable.ic_action_gnext_dark);
|
||||||
|
menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
|
((SearchActivity) getActivity()).startSearchAddressOffline();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ import net.osmand.util.MapUtils;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.FragmentActivity;
|
import android.support.v4.app.FragmentActivity;
|
||||||
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.text.Spannable;
|
import android.text.Spannable;
|
||||||
import android.text.style.ForegroundColorSpan;
|
import android.text.style.ForegroundColorSpan;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
|
@ -177,9 +178,9 @@ public class SearchHistoryFragment extends ListFragment implements SearchActivit
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
public void onCreateOptionsMenu(Menu onCreate, MenuInflater inflater) {
|
||||||
if(getActivity() instanceof SearchActivity) {
|
if(getActivity() instanceof SearchActivity) {
|
||||||
((SearchActivity)getActivity()).setupBottomMenu(new ArrayList<BottomMenuItem>());
|
((SearchActivity) getActivity()).getClearToolbar(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import java.util.List;
|
||||||
import android.support.v4.app.FragmentActivity;
|
import android.support.v4.app.FragmentActivity;
|
||||||
import android.support.v4.app.ListFragment;
|
import android.support.v4.app.ListFragment;
|
||||||
import android.support.v7.app.ActionBarActivity;
|
import android.support.v7.app.ActionBarActivity;
|
||||||
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
import net.osmand.access.AccessibleToast;
|
import net.osmand.access.AccessibleToast;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
|
@ -180,8 +181,10 @@ public class SearchPoiFilterFragment extends ListFragment implements SearchActiv
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
public void onCreateOptionsMenu(Menu onCreate, MenuInflater inflater) {
|
||||||
((SearchActivity)getActivity()).setupBottomMenu(new ArrayList<BottomMenuItem>());
|
if(getActivity() instanceof SearchActivity) {
|
||||||
|
((SearchActivity) getActivity()).getClearToolbar(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -8,6 +8,7 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
import net.osmand.data.TransportRoute;
|
import net.osmand.data.TransportRoute;
|
||||||
|
@ -625,9 +626,9 @@ public class SearchTransportFragment extends Fragment implements SearchActivityC
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
public void onCreateOptionsMenu(Menu onCreate, MenuInflater inflater) {
|
||||||
if(getActivity() instanceof SearchActivity) {
|
if(getActivity() instanceof SearchActivity) {
|
||||||
((SearchActivity)getActivity()).setupBottomMenu(new ArrayList<BottomMenuItem>());
|
((SearchActivity) getActivity()).getClearToolbar(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -162,10 +162,8 @@ public class DashMapFragment extends DashBaseFragment implements IMapDownloaderC
|
||||||
|
|
||||||
WindowManager wm = (WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE);
|
WindowManager wm = (WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE);
|
||||||
Display display = wm.getDefaultDisplay();
|
Display display = wm.getDefaultDisplay();
|
||||||
final Point pnt = new Point();
|
int height = display.getHeight(); // (int) getActivity().getResources().getDimension(R.dimen.dashMapHeight);
|
||||||
display.getSize(pnt);
|
int width = display.getWidth();
|
||||||
int height = pnt.y; // (int) getActivity().getResources().getDimension(R.dimen.dashMapHeight);
|
|
||||||
int width = pnt.x;// display.getWidth();
|
|
||||||
|
|
||||||
WindowManager mgr = (WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE);
|
WindowManager mgr = (WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE);
|
||||||
DisplayMetrics dm = new DisplayMetrics();
|
DisplayMetrics dm = new DisplayMetrics();
|
||||||
|
|
Loading…
Reference in a new issue