fix landscape app bar text size;

refactoring app bar;
This commit is contained in:
Skalii 2021-03-26 15:37:22 +02:00
parent ff26a082f9
commit 16efbfd7f5
2 changed files with 43 additions and 64 deletions

View file

@ -1,5 +1,4 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
@ -10,38 +9,7 @@
android:id="@+id/app_bar" android:id="@+id/app_bar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical" />
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/dashboard_map_toolbar"
android:background="?attr/pstsTabBackground"
android:minHeight="@dimen/dashboard_map_toolbar"
android:theme="?attr/toolbar_theme"
app:contentInsetEnd="0dp"
app:contentInsetLeft="@dimen/settings_divider_margin_start"
app:contentInsetRight="0dp"
app:contentInsetStart="@dimen/settings_divider_margin_start">
<ImageButton
android:id="@+id/toolbar_action"
android:layout_width="@dimen/acceptable_touch_radius"
android:layout_height="@dimen/acceptable_touch_radius"
android:layout_gravity="end"
android:layout_marginStart="@dimen/list_item_button_padding"
android:layout_marginLeft="@dimen/list_item_button_padding"
android:layout_marginEnd="@dimen/list_item_button_padding"
android:layout_marginRight="@dimen/list_item_button_padding"
android:background="@null"
android:contentDescription="@string/shared_string_help"
tools:src="@drawable/ic_action_help" />
</androidx.appcompat.widget.Toolbar>
<include layout="@layout/preference_toolbar_switch" />
</com.google.android.material.appbar.AppBarLayout>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh" android:id="@+id/swipe_refresh"

View file

@ -5,7 +5,6 @@ import android.app.AlarmManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
@ -19,7 +18,7 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.ExpandableListView; import android.widget.ExpandableListView;
import android.widget.ImageButton; import android.widget.FrameLayout;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
@ -27,6 +26,7 @@ import androidx.annotation.ColorRes;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.content.res.AppCompatResources; import androidx.appcompat.content.res.AppCompatResources;
import androidx.appcompat.widget.AppCompatImageButton;
import androidx.appcompat.widget.AppCompatImageView; import androidx.appcompat.widget.AppCompatImageView;
import androidx.appcompat.widget.SwitchCompat; import androidx.appcompat.widget.SwitchCompat;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
@ -36,6 +36,8 @@ import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.google.android.material.appbar.AppBarLayout;
import net.osmand.AndroidNetworkUtils; import net.osmand.AndroidNetworkUtils;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
@ -136,32 +138,7 @@ public class LiveUpdatesFragment extends BaseOsmAndDialogFragment implements OnL
@Override @Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_live_updates, container, false); View view = inflater.inflate(R.layout.fragment_live_updates, container, false);
createToolbar((ViewGroup) view.findViewById(R.id.app_bar));
Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
toolbar.setTitle(R.string.osm_live);
int iconColorResId = nightMode ? R.color.active_buttons_and_links_text_dark : R.color.active_buttons_and_links_text_light;
Drawable icBack = app.getUIUtilities().getIcon(AndroidUtils.getNavigationIconResId(app), iconColorResId);
DrawableCompat.setTint(icBack, ContextCompat.getColor(app, iconColorResId));
toolbar.setNavigationIcon(icBack);
toolbar.setNavigationContentDescription(R.string.access_shared_string_navigate_up);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
ImageButton iconHelp = toolbar.findViewById(R.id.toolbar_action);
Drawable helpDrawable = app.getUIUtilities().getIcon(R.drawable.ic_action_help_online, iconColorResId);
iconHelp.setImageDrawable(helpDrawable);
iconHelp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Activity activity = getActivity();
if (activity != null) {
WikipediaDialogFragment.showFullArticle(activity, Uri.parse(SUBSCRIPTION_URL), nightMode);
}
}
});
listView = (ExpandableListView) view.findViewById(android.R.id.list); listView = (ExpandableListView) view.findViewById(android.R.id.list);
adapter = new LiveMapsAdapter(); adapter = new LiveMapsAdapter();
@ -201,9 +178,6 @@ public class LiveUpdatesFragment extends BaseOsmAndDialogFragment implements OnL
} }
}); });
toolbarSwitchContainer = view.findViewById(R.id.toolbar_switch_container);
updateToolbarSwitch(settings.IS_LIVE_UPDATES_ON.get());
View headerView = inflater.inflate(R.layout.list_item_import, listView, false); View headerView = inflater.inflate(R.layout.list_item_import, listView, false);
View timeContainer = headerView.findViewById(R.id.item_import_container); View timeContainer = headerView.findViewById(R.id.item_import_container);
AndroidUtils.setListItemBackground(app, timeContainer, nightMode); AndroidUtils.setListItemBackground(app, timeContainer, nightMode);
@ -281,6 +255,43 @@ public class LiveUpdatesFragment extends BaseOsmAndDialogFragment implements OnL
} }
} }
protected void createToolbar(ViewGroup appBar) {
AppBarLayout appBarLayout = (AppBarLayout) UiUtilities.getInflater(getActivity(), nightMode)
.inflate(R.layout.global_preferences_toolbar_with_switch, appBar);
Toolbar toolbar = (Toolbar) appBarLayout.findViewById(R.id.toolbar);
TextViewEx toolbarTitle = (TextViewEx) toolbar.findViewById(R.id.toolbar_title);
toolbarTitle.setText(R.string.osm_live);
int iconColorResId = nightMode ? R.color.active_buttons_and_links_text_dark : R.color.active_buttons_and_links_text_light;
Drawable icBack = app.getUIUtilities().getIcon(AndroidUtils.getNavigationIconResId(app), iconColorResId);
DrawableCompat.setTint(icBack, ContextCompat.getColor(app, iconColorResId));
View closeButton = toolbar.findViewById(R.id.close_button);
closeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
FrameLayout iconHelpContainer = toolbar.findViewById(R.id.action_button);
AppCompatImageButton iconHelp = toolbar.findViewById(R.id.action_button_icon);
Drawable helpDrawable = app.getUIUtilities().getIcon(R.drawable.ic_action_help_online, iconColorResId);
iconHelp.setImageDrawable(helpDrawable);
iconHelpContainer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Activity activity = getActivity();
if (activity != null) {
WikipediaDialogFragment.showFullArticle(activity, Uri.parse(SUBSCRIPTION_URL), nightMode);
}
}
});
toolbarSwitchContainer = appBarLayout.findViewById(R.id.toolbar_switch_container);
updateToolbarSwitch(settings.IS_LIVE_UPDATES_ON.get());
}
private void updateToolbarSwitch(final boolean isChecked) { private void updateToolbarSwitch(final boolean isChecked) {
int switchColor = ContextCompat.getColor(app, int switchColor = ContextCompat.getColor(app,
isChecked ? getActiveTextColorId(nightMode) : getSecondaryTextColorId(nightMode)); isChecked ? getActiveTextColorId(nightMode) : getSecondaryTextColorId(nightMode));