Search in sources :

Example 51 with ContextThemeWrapper

use of android.support.v7.view.ContextThemeWrapper in project Slide by ccrama.

the class SubredditListView method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Context contextThemeWrapper = new ContextThemeWrapper(getActivity(), new ColorPreferences(inflater.getContext()).getThemeSubreddit(where));
    View v = ((LayoutInflater) contextThemeWrapper.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.fragment_verticalcontent, container, false);
    rv = ((RecyclerView) v.findViewById(R.id.vertical_content));
    final RecyclerView.LayoutManager mLayoutManager = new PreCachingLayoutManager(getActivity());
    rv.setLayoutManager(mLayoutManager);
    rv.setItemAnimator(new SlideUpAlphaAnimator());
    mSwipeRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.activity_main_swipe_refresh_layout);
    mSwipeRefreshLayout.setColorSchemeColors(Palette.getColors("no sub", getContext()));
    // If we use 'findViewById(R.id.header).getMeasuredHeight()', 0 is always returned.
    // So, we estimate the height of the header in dp
    mSwipeRefreshLayout.setProgressViewOffset(false, Constants.TAB_HEADER_VIEW_OFFSET - Constants.PTR_OFFSET_TOP, Constants.TAB_HEADER_VIEW_OFFSET + Constants.PTR_OFFSET_BOTTOM);
    v.findViewById(R.id.post_floating_action_button).setVisibility(View.GONE);
    doAdapter();
    return v;
}
Also used : Context(android.content.Context) ContextThemeWrapper(android.support.v7.view.ContextThemeWrapper) ColorPreferences(me.ccrama.redditslide.ColorPreferences) LayoutInflater(android.view.LayoutInflater) RecyclerView(android.support.v7.widget.RecyclerView) PreCachingLayoutManager(me.ccrama.redditslide.Views.PreCachingLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) SlideUpAlphaAnimator(com.mikepenz.itemanimators.SlideUpAlphaAnimator)

Example 52 with ContextThemeWrapper

use of android.support.v7.view.ContextThemeWrapper in project sbt-android by scala-android.

the class TelescopeAppContainer method showTelescopeDialog.

public void showTelescopeDialog(final Activity activity) {
    LayoutInflater inflater = LayoutInflater.from(activity);
    TelescopeLayout content = (TelescopeLayout) inflater.inflate(R.layout.telescope_tutorial_dialog, null);
    final AlertDialog dialog = new AlertDialog.Builder(activity).setView(content).setCancelable(false).create();
    content.setLens(new Lens() {

        @Override
        public void onCapture(File file) {
            dialog.dismiss();
            Context toastContext = new ContextThemeWrapper(activity, android.R.style.Theme_DeviceDefault_Dialog);
            LayoutInflater toastInflater = LayoutInflater.from(toastContext);
            Toast toast = Toast.makeText(toastContext, "", Toast.LENGTH_SHORT);
            View toastView = toastInflater.inflate(R.layout.telescope_tutorial_toast, null);
            toast.setView(toastView);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }
    });
    dialog.show();
}
Also used : TelescopeLayout(com.mattprecious.telescope.TelescopeLayout) AlertDialog(android.support.v7.app.AlertDialog) Context(android.content.Context) ContextThemeWrapper(android.view.ContextThemeWrapper) Toast(android.widget.Toast) LayoutInflater(android.view.LayoutInflater) Lens(com.mattprecious.telescope.Lens) BugReportLens(com.jakewharton.u2020.ui.bugreport.BugReportLens) File(java.io.File) View(android.view.View)

Example 53 with ContextThemeWrapper

use of android.support.v7.view.ContextThemeWrapper in project Memento-Calendar by alexstyl.

the class PersonModule method callProvider.

@Provides
PersonCallProvider callProvider(ContentResolver contentResolver, Resources resources, Context context, PackageManager packageManager, CrashAndErrorTracker tracker, Strings strings) {
    MementoTheme theme = ThemingPreferences.newInstance(context).getSelectedTheme();
    ContextThemeWrapper wrapper = new ContextThemeWrapper(context, theme.androidTheme());
    return new PersonCallProvider(new AndroidContactActionsProvider(contentResolver, resources, wrapper, packageManager, tracker), new FacebookContactActionsProvider(strings, resources));
}
Also used : ContextThemeWrapper(android.support.v7.view.ContextThemeWrapper) MementoTheme(com.alexstyl.specialdates.theming.MementoTheme) Provides(dagger.Provides)

Example 54 with ContextThemeWrapper

use of android.support.v7.view.ContextThemeWrapper in project Osmand by osmandapp.

the class MeasurementToolFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    final MapActivity mapActivity = (MapActivity) getActivity();
    final MeasurementToolLayer measurementLayer = mapActivity.getMapLayers().getMeasurementToolLayer();
    editingCtx.setApplication(mapActivity.getMyApplication());
    editingCtx.setProgressListener(new MeasurementEditingContext.SnapToRoadProgressListener() {

        @Override
        public void showProgressBar() {
            MeasurementToolFragment.this.showProgressBar();
        }

        @Override
        public void updateProgress(int progress) {
            ((ProgressBar) mainView.findViewById(R.id.snap_to_road_progress_bar)).setProgress(progress);
        }

        @Override
        public void hideProgressBar() {
            ((ProgressBar) mainView.findViewById(R.id.snap_to_road_progress_bar)).setVisibility(View.GONE);
            progressBarVisible = false;
        }

        @Override
        public void refresh() {
            measurementLayer.refreshMap();
            updateText();
        }
    });
    measurementLayer.setEditingCtx(editingCtx);
    // Handling screen rotation
    FragmentManager fragmentManager = mapActivity.getSupportFragmentManager();
    Fragment selectedPointFragment = fragmentManager.findFragmentByTag(SelectedPointBottomSheetDialogFragment.TAG);
    if (selectedPointFragment != null) {
        SelectedPointBottomSheetDialogFragment fragment = (SelectedPointBottomSheetDialogFragment) selectedPointFragment;
        fragment.setListener(createSelectedPointFragmentListener());
    }
    Fragment optionsFragment = fragmentManager.findFragmentByTag(OptionsBottomSheetDialogFragment.TAG);
    if (optionsFragment != null) {
        ((OptionsBottomSheetDialogFragment) optionsFragment).setListener(createOptionsFragmentListener());
    }
    Fragment snapToRoadFragment = fragmentManager.findFragmentByTag(SnapToRoadBottomSheetDialogFragment.TAG);
    if (snapToRoadFragment != null) {
        ((SnapToRoadBottomSheetDialogFragment) snapToRoadFragment).setListener(createSnapToRoadFragmentListener());
    }
    Fragment saveAsNewTrackFragment = mapActivity.getSupportFragmentManager().findFragmentByTag(SaveAsNewTrackBottomSheetDialogFragment.TAG);
    if (saveAsNewTrackFragment != null) {
        ((SaveAsNewTrackBottomSheetDialogFragment) saveAsNewTrackFragment).setListener(createSaveAsNewTrackFragmentListener());
    }
    // the RecyclerViewFragment will exist without view. This is necessary to remove it.
    if (!portrait) {
        hidePointsListFragment();
    }
    editingCtx.getCommandManager().resetMeasurementLayer(measurementLayer);
    nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
    final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
    final int backgroundColor = ContextCompat.getColor(getActivity(), nightMode ? R.color.ctx_menu_info_view_bg_dark : R.color.ctx_menu_info_view_bg_light);
    portrait = AndroidUiHelper.isOrientationPortrait(getActivity());
    upIcon = getContentIcon(R.drawable.ic_action_arrow_up);
    downIcon = getContentIcon(R.drawable.ic_action_arrow_down);
    pointsSt = getString(R.string.points).toLowerCase();
    View view = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_measurement_tool, null);
    mainView = view.findViewById(R.id.main_view);
    AndroidUtils.setBackground(mapActivity, mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark);
    pointsListContainer = view.findViewById(R.id.points_list_container);
    if (portrait && pointsListContainer != null) {
        pointsListContainer.setBackgroundColor(backgroundColor);
    }
    if (progressBarVisible) {
        showProgressBar();
    }
    distanceTv = (TextView) mainView.findViewById(R.id.measurement_distance_text_view);
    pointsTv = (TextView) mainView.findViewById(R.id.measurement_points_text_view);
    distanceToCenterTv = (TextView) mainView.findViewById(R.id.distance_to_center_text_view);
    mainIcon = (ImageView) mainView.findViewById(R.id.main_icon);
    final NewGpxData newGpxData = editingCtx.getNewGpxData();
    if (editingCtx.getNewGpxData() != null) {
        ActionType actionType = newGpxData.getActionType();
        if (actionType == ActionType.ADD_SEGMENT || actionType == ActionType.EDIT_SEGMENT) {
            mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_polygom_dark));
        } else {
            mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_markers_dark));
        }
    } else {
        mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_ruler));
    }
    upDownBtn = (ImageView) mainView.findViewById(R.id.up_down_button);
    upDownBtn.setImageDrawable(upIcon);
    mainView.findViewById(R.id.cancel_move_point_button).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            cancelMovePointMode();
        }
    });
    mainView.findViewById(R.id.cancel_point_before_after_button).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            cancelAddPointBeforeOrAfterMode();
        }
    });
    upDownRow = mainView.findViewById(R.id.up_down_row);
    upDownRow.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (!pointsListOpened && editingCtx.getPointsCount() > 0 && editingCtx.getSelectedPointPosition() == -1) {
                showPointsList();
            } else {
                hidePointsList();
            }
        }
    });
    mainView.findViewById(R.id.apply_move_point_button).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            applyMovePointMode();
        }
    });
    mainView.findViewById(R.id.apply_point_before_after_point_button).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            applyAddPointBeforeAfterMode();
        }
    });
    mainView.findViewById(R.id.add_point_before_after_button).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            addPointBeforeAfter();
        }
    });
    mainView.findViewById(R.id.options_button).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Bundle args = new Bundle();
            args.putBoolean(OptionsBottomSheetDialogFragment.SNAP_TO_ROAD_ENABLED_KEY, editingCtx.isInSnapToRoadMode());
            args.putBoolean(OptionsBottomSheetDialogFragment.ADD_LINE_MODE_KEY, newGpxData != null);
            OptionsBottomSheetDialogFragment fragment = new OptionsBottomSheetDialogFragment();
            fragment.setArguments(args);
            fragment.setUsedOnMap(true);
            fragment.setListener(createOptionsFragmentListener());
            fragment.show(mapActivity.getSupportFragmentManager(), OptionsBottomSheetDialogFragment.TAG);
        }
    });
    undoBtn = ((ImageButton) mainView.findViewById(R.id.undo_point_button));
    redoBtn = ((ImageButton) mainView.findViewById(R.id.redo_point_button));
    undoBtn.setImageDrawable(getContentIcon(R.drawable.ic_action_undo_dark));
    undoBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            editingCtx.getCommandManager().undo();
            if (editingCtx.getCommandManager().canUndo()) {
                enable(undoBtn);
            } else {
                disable(undoBtn);
            }
            hidePointsListIfNoPoints();
            if (editingCtx.getPointsCount() > 0) {
                enable(upDownBtn);
            }
            adapter.notifyDataSetChanged();
            enable(redoBtn);
            updateText();
        }
    });
    redoBtn.setImageDrawable(getContentIcon(R.drawable.ic_action_redo_dark));
    redoBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            editingCtx.getCommandManager().redo();
            if (editingCtx.getCommandManager().canRedo()) {
                enable(redoBtn);
            } else {
                disable(redoBtn);
            }
            hidePointsListIfNoPoints();
            if (editingCtx.getPointsCount() > 0) {
                enable(upDownBtn);
            }
            adapter.notifyDataSetChanged();
            enable(undoBtn);
            updateText();
        }
    });
    mainView.findViewById(R.id.add_point_button).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            addCenterPoint();
        }
    });
    measurementLayer.setOnSingleTapListener(new MeasurementToolLayer.OnSingleTapListener() {

        @Override
        public void onAddPoint() {
            addPoint();
        }

        @Override
        public void onSelectPoint(int selectedPointPos) {
            if (pointsListOpened) {
                hidePointsList();
            }
            if (selectedPointPos != -1) {
                openSelectedPointMenu(mapActivity);
            }
        }
    });
    measurementLayer.setOnMeasureDistanceToCenterListener(new MeasurementToolLayer.OnMeasureDistanceToCenter() {

        @Override
        public void onMeasure(float distance) {
            String distStr = OsmAndFormatter.getFormattedDistance(distance, mapActivity.getMyApplication());
            distanceToCenterTv.setText(" – " + distStr);
        }
    });
    measurementLayer.setOnEnterMovePointModeListener(new MeasurementToolLayer.OnEnterMovePointModeListener() {

        @Override
        public void onEnterMovePointMode() {
            if (pointsListOpened) {
                hidePointsList();
            }
            switchMovePointMode(true);
        }
    });
    if (!editingCtx.getCommandManager().canUndo()) {
        disable(undoBtn);
    }
    if (!editingCtx.getCommandManager().canRedo()) {
        disable(redoBtn);
    }
    if (editingCtx.getPointsCount() < 1) {
        disable(upDownBtn);
    }
    toolBarController = new MeasurementToolBarController(newGpxData);
    if (editingCtx.getSelectedPointPosition() != -1) {
        toolBarController.setBackBtnIconIds(R.drawable.ic_action_mode_back, R.drawable.ic_action_mode_back);
    } else {
        toolBarController.setBackBtnIconIds(R.drawable.ic_action_remove_dark, R.drawable.ic_action_remove_dark);
    }
    if (newGpxData != null) {
        NewGpxData.ActionType actionType = newGpxData.getActionType();
        if (actionType == NewGpxData.ActionType.ADD_ROUTE_POINTS) {
            toolBarController.setTitle(getString(R.string.add_route_points));
        } else if (actionType == NewGpxData.ActionType.ADD_SEGMENT) {
            toolBarController.setTitle(getString(R.string.add_line));
        } else if (actionType == NewGpxData.ActionType.EDIT_SEGMENT) {
            toolBarController.setTitle(getString(R.string.edit_line));
        }
    } else {
        toolBarController.setTitle(getString(R.string.measurement_tool_action_bar));
    }
    toolBarController.setOnBackButtonClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            quit(false);
        }
    });
    toolBarController.setOnSaveViewClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (editingCtx.getPointsCount() > 0) {
                addToGpx(mapActivity);
            } else {
                Toast.makeText(mapActivity, getString(R.string.none_point_error), Toast.LENGTH_SHORT).show();
            }
        }
    });
    toolBarController.setOnSwitchCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
            if (!checked) {
                disableSnapToRoadMode();
            }
        }
    });
    mapActivity.showTopToolbar(toolBarController);
    adapter = new MeasurementToolAdapter(getMapActivity(), editingCtx.getPoints(), newGpxData != null ? newGpxData.getActionType() : null);
    if (portrait) {
        pointsRv = mainView.findViewById(R.id.measure_points_recycler_view);
    } else {
        pointsRv = new RecyclerView(getActivity());
    }
    final ItemTouchHelper touchHelper = new ItemTouchHelper(new MeasurementToolItemTouchHelperCallback(adapter));
    touchHelper.attachToRecyclerView(pointsRv);
    adapter.setAdapterListener(createMeasurementAdapterListener(touchHelper));
    pointsRv.setLayoutManager(new LinearLayoutManager(getContext()));
    pointsRv.setAdapter(adapter);
    enterMeasurementMode();
    if (editingCtx.isInSnapToRoadMode()) {
        showSnapToRoadControls();
    }
    if (newGpxData != null && !gpxPointsAdded) {
        NewGpxData.ActionType actionType = newGpxData.getActionType();
        if (actionType == NewGpxData.ActionType.ADD_ROUTE_POINTS) {
            displayRoutePoints();
            gpxPointsAdded = true;
        } else if (actionType == NewGpxData.ActionType.EDIT_SEGMENT) {
            displaySegmentPoints();
            gpxPointsAdded = true;
        }
    }
    if (saved == null) {
        saved = newGpxData != null && (newGpxData.getActionType() == NewGpxData.ActionType.ADD_ROUTE_POINTS || newGpxData.getActionType() == NewGpxData.ActionType.EDIT_SEGMENT);
    }
    return view;
}
Also used : MeasurementToolItemTouchHelperCallback(net.osmand.plus.measurementtool.adapter.MeasurementToolItemTouchHelperCallback) ActionType(net.osmand.plus.measurementtool.NewGpxData.ActionType) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Fragment(android.support.v4.app.Fragment) BaseOsmAndFragment(net.osmand.plus.base.BaseOsmAndFragment) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) ImageButton(android.widget.ImageButton) MapActivity(net.osmand.plus.activities.MapActivity) Bundle(android.os.Bundle) MeasurementToolAdapter(net.osmand.plus.measurementtool.adapter.MeasurementToolAdapter) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) RecyclerView(android.support.v7.widget.RecyclerView) FragmentManager(android.support.v4.app.FragmentManager) ContextThemeWrapper(android.view.ContextThemeWrapper) RecyclerView(android.support.v7.widget.RecyclerView) CompoundButton(android.widget.CompoundButton) ActionType(net.osmand.plus.measurementtool.NewGpxData.ActionType) Nullable(android.support.annotation.Nullable)

Example 55 with ContextThemeWrapper

use of android.support.v7.view.ContextThemeWrapper in project Osmand by osmandapp.

the class MenuBuilder method buildButtonInCollapsableView.

protected TextViewEx buildButtonInCollapsableView(Context context, boolean selected, boolean showAll, boolean singleLine) {
    TextViewEx button = new TextViewEx(new ContextThemeWrapper(context, light ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme));
    LinearLayout.LayoutParams llWikiButtonParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    llWikiButtonParams.setMargins(0, 0, 0, dpToPx(8f));
    // button.setMinimumHeight(dpToPx(36f));
    button.setLayoutParams(llWikiButtonParams);
    button.setTypeface(FontCache.getRobotoRegular(context));
    int bg;
    if (selected) {
        bg = light ? R.drawable.context_menu_controller_bg_light_selected : R.drawable.context_menu_controller_bg_dark_selected;
    } else if (showAll) {
        bg = light ? R.drawable.context_menu_controller_bg_light_show_all : R.drawable.context_menu_controller_bg_dark_show_all;
    } else {
        bg = light ? R.drawable.context_menu_controller_bg_light : R.drawable.context_menu_controller_bg_dark;
    }
    button.setBackgroundResource(bg);
    button.setTextSize(14);
    int paddingSides = dpToPx(10f);
    button.setPadding(paddingSides, paddingSides, paddingSides, paddingSides);
    if (!selected) {
        ColorStateList buttonColorStateList = AndroidUtils.createColorStateList(context, !light, R.color.ctx_menu_controller_button_text_color_light_n, R.color.ctx_menu_controller_button_text_color_light_p, R.color.ctx_menu_controller_button_text_color_dark_n, R.color.ctx_menu_controller_button_text_color_dark_p);
        button.setTextColor(buttonColorStateList);
    } else {
        button.setTextColor(ContextCompat.getColor(context, light ? R.color.ctx_menu_bottom_view_text_color_light : R.color.ctx_menu_bottom_view_text_color_dark));
    }
    button.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
    button.setSingleLine(singleLine);
    button.setEllipsize(TextUtils.TruncateAt.END);
    return button;
}
Also used : ContextThemeWrapper(android.support.v7.view.ContextThemeWrapper) TextViewEx(net.osmand.plus.widgets.TextViewEx) ColorStateList(android.content.res.ColorStateList) LinearLayout(android.widget.LinearLayout)

Aggregations

View (android.view.View)41 ContextThemeWrapper (android.support.v7.view.ContextThemeWrapper)38 ContextThemeWrapper (android.view.ContextThemeWrapper)35 DialogInterface (android.content.DialogInterface)26 Context (android.content.Context)25 AlertDialog (android.support.v7.app.AlertDialog)24 TextView (android.widget.TextView)23 RecyclerView (android.support.v7.widget.RecyclerView)21 ImageView (android.widget.ImageView)21 LayoutInflater (android.view.LayoutInflater)18 Intent (android.content.Intent)13 Nullable (android.support.annotation.Nullable)10 ColorPreferences (me.ccrama.redditslide.ColorPreferences)10 Drawable (android.graphics.drawable.Drawable)9 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)9 EditText (android.widget.EditText)9 Bundle (android.os.Bundle)7 NonNull (android.support.annotation.NonNull)7 ArrayList (java.util.ArrayList)7 SuppressLint (android.annotation.SuppressLint)6