Search in sources :

Example 1 with ColorRes

use of androidx.annotation.ColorRes in project Osmand by osmandapp.

the class CoordinateInputDialogFragment method enterEditingMode.

private void enterEditingMode(WptPt wptPt) {
    selectedWpt = wptPt;
    Format format = getMyApplication().getSettings().COORDS_INPUT_FORMAT.get();
    double lat = Math.abs(wptPt.lat);
    double lon = Math.abs(wptPt.lon);
    if (format == Format.DD_MM_MMM || format == Format.DD_MM_MMMM) {
        int accuracy = format.getThirdPartSymbolsCount();
        updateInputsDdm(true, CoordinateInputFormats.ddToDdm(lat), accuracy);
        updateInputsDdm(false, CoordinateInputFormats.ddToDdm(lon), accuracy);
    } else if (format == Format.DD_DDDDD || format == Format.DD_DDDDDD) {
        int accuracy = format.getSecondPartSymbolsCount();
        updateInputsDd(true, lat, accuracy);
        updateInputsDd(false, lon, accuracy);
    } else if (format == Format.DD_MM_SS) {
        updateInputsDms(true, CoordinateInputFormats.ddToDms(lat));
        updateInputsDms(false, CoordinateInputFormats.ddToDms(lon));
    }
    boolean latPositive = wptPt.lat > 0;
    if ((latPositive && !north) || (!latPositive && north)) {
        updateSideOfTheWorldBtn(mainView.findViewById(R.id.lat_side_of_the_world_btn), true);
    }
    boolean lonPositive = wptPt.lon > 0;
    if ((lonPositive && !east) || (!lonPositive && east)) {
        updateSideOfTheWorldBtn(mainView.findViewById(R.id.lon_side_of_the_world_btn), true);
    }
    ((EditText) mainView.findViewById(R.id.point_name_et)).setText(wptPt.name);
    ((TextView) mainView.findViewById(R.id.toolbar_text)).setText(R.string.coord_input_edit_point);
    TextView addButton = (TextView) mainView.findViewById(R.id.add_marker_button);
    addButton.setText(R.string.shared_string_apply);
    @ColorRes int colorId = lightTheme ? R.color.wikivoyage_active_light : R.color.wikivoyage_active_dark;
    addButton.setCompoundDrawablesWithIntrinsicBounds(null, null, getColoredIcon(R.drawable.ic_action_type_apply, colorId), null);
    showKeyboard();
}
Also used : EditText(android.widget.EditText) ColorRes(androidx.annotation.ColorRes) Format(net.osmand.plus.mapmarkers.CoordinateInputFormats.Format) DecimalFormat(java.text.DecimalFormat) TextView(android.widget.TextView)

Example 2 with ColorRes

use of androidx.annotation.ColorRes in project Osmand by osmandapp.

the class CoordinateInputDialogFragment method dismissEditingMode.

private void dismissEditingMode() {
    selectedWpt = null;
    TextView addButton = (TextView) mainView.findViewById(R.id.add_marker_button);
    addButton.setText(R.string.shared_string_add);
    @ColorRes int colorId = lightTheme ? R.color.wikivoyage_active_light : R.color.wikivoyage_active_dark;
    addButton.setCompoundDrawablesWithIntrinsicBounds(null, null, getColoredIcon(R.drawable.ic_action_type_add, colorId), null);
    ((TextView) mainView.findViewById(R.id.toolbar_text)).setText(R.string.coord_input_add_point);
}
Also used : ColorRes(androidx.annotation.ColorRes) TextView(android.widget.TextView)

Example 3 with ColorRes

use of androidx.annotation.ColorRes in project Osmand by osmandapp.

the class CoordinateInputDialogFragment method registerMainView.

private void registerMainView() {
    final Context ctx = getContext();
    if (ctx == null) {
        return;
    }
    if (orientationPortrait) {
        View.OnClickListener backspaceOnClickListener = new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (v.getId() == R.id.lat_backspace_btn) {
                    clearInputs(R.id.lat_first_input_et, R.id.lat_second_input_et, R.id.lat_third_input_et);
                } else {
                    clearInputs(R.id.lon_first_input_et, R.id.lon_second_input_et, R.id.lon_third_input_et);
                }
            }
        };
        ImageView latBackspaceBtn = (ImageView) mainView.findViewById(R.id.lat_backspace_btn);
        latBackspaceBtn.setImageDrawable(getActiveIcon(R.drawable.ic_action_clear_all_fields));
        latBackspaceBtn.setOnClickListener(backspaceOnClickListener);
        ImageView lonBackspaceBtn = (ImageView) mainView.findViewById(R.id.lon_backspace_btn);
        lonBackspaceBtn.setImageDrawable(getActiveIcon(R.drawable.ic_action_clear_all_fields));
        lonBackspaceBtn.setOnClickListener(backspaceOnClickListener);
    } else {
        boolean rightHand = getMyApplication().getSettings().COORDS_INPUT_USE_RIGHT_SIDE.get();
        LinearLayout handContainer = (LinearLayout) mainView.findViewById(R.id.hand_container);
        View dataAreaView = View.inflate(ctx, R.layout.coordinate_input_land_data_area, null);
        View keyboardAndListView = View.inflate(ctx, R.layout.coordinate_input_land_keyboard_and_list, null);
        setBackgroundColor(dataAreaView, lightTheme ? R.color.route_info_bg_light : R.color.route_info_bg_dark);
        setBackgroundColor(keyboardAndListView, ColorUtilities.getActivityBgColorId(!lightTheme));
        ((FrameLayout) handContainer.findViewById(R.id.left_container)).addView(rightHand ? dataAreaView : keyboardAndListView, 0);
        ((FrameLayout) handContainer.findViewById(R.id.right_container)).addView(rightHand ? keyboardAndListView : dataAreaView, 0);
        handContainer.findViewById(R.id.input_area_top_padding).setVisibility(View.VISIBLE);
        handContainer.findViewById(R.id.point_name_top_space).setVisibility(View.VISIBLE);
        handContainer.findViewById(R.id.right_shadow).setVisibility(rightHand ? View.VISIBLE : View.GONE);
        handContainer.findViewById(R.id.left_shadow).setVisibility(rightHand ? View.GONE : View.VISIBLE);
        handContainer.findViewById(R.id.lat_backspace_btn).setVisibility(View.GONE);
        handContainer.findViewById(R.id.lon_backspace_btn).setVisibility(View.GONE);
        handContainer.findViewById(R.id.lat_end_padding).setVisibility(View.VISIBLE);
        handContainer.findViewById(R.id.lon_end_padding).setVisibility(View.VISIBLE);
    }
    registerInputs();
    setupSideOfTheWorldBtns(R.id.lat_side_of_the_world_btn, R.id.lon_side_of_the_world_btn);
    setBackgroundColor(R.id.point_name_divider, lightTheme ? R.color.ctx_menu_buttons_divider_light : R.color.ctx_menu_buttons_divider_dark);
    setBackgroundColor(R.id.point_name_et_container, lightTheme ? R.color.keyboard_item_control_light_bg : R.color.route_info_bottom_view_bg_dark);
    ImageView pointNameKeyboardBtn = (ImageView) mainView.findViewById(R.id.point_name_keyboard_btn);
    pointNameKeyboardBtn.setImageDrawable(getColoredIcon(R.drawable.ic_action_keyboard, R.color.icon_color_default_light));
    pointNameKeyboardBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (isOsmandKeyboardCurrentlyVisible()) {
                changeOsmandKeyboardVisibility(false);
                if (isOsmandKeyboardOn()) {
                    shouldShowOsmandKeyboard = true;
                }
            }
            for (EditText et : editTexts) {
                if (et.getId() == R.id.point_name_et) {
                    et.requestFocus();
                }
            }
            final View focusedView = getDialog().getCurrentFocus();
            if (focusedView != null) {
                AndroidUtils.softKeyboardDelayed(getActivity(), focusedView);
            }
        }
    });
    adapter = new CoordinateInputAdapter(getMyApplication(), getGpx());
    recyclerView = (RecyclerView) mainView.findViewById(R.id.markers_recycler_view);
    recyclerView.setLayoutManager(new LinearLayoutManager(ctx));
    recyclerView.setAdapter(adapter);
    recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
            compassUpdateAllowed = newState == RecyclerView.SCROLL_STATE_IDLE;
        }
    });
    adapter.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            int pos = recyclerView.getChildAdapterPosition(v);
            if (pos == RecyclerView.NO_POSITION) {
                return;
            }
            enterEditingMode(adapter.getItem(pos));
        }
    });
    adapter.setOnActionsClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            RecyclerView.ViewHolder viewHolder = recyclerView.findContainingViewHolder(v);
            if (viewHolder != null) {
                int pos = viewHolder.getAdapterPosition();
                if (pos == RecyclerView.NO_POSITION) {
                    return;
                }
                Bundle args = new Bundle();
                args.putInt(CoordinateInputAdapter.ADAPTER_POSITION_KEY, pos);
                CoordinateInputActionsBottomSheet fragment = new CoordinateInputActionsBottomSheet();
                fragment.setUsedOnMap(false);
                fragment.setArguments(args);
                fragment.setListener(createCoordinateInputActionsListener());
                fragment.show(getChildFragmentManager(), CoordinateInputActionsBottomSheet.TAG);
            }
        }
    });
    setBackgroundColor(R.id.bottom_controls_container, lightTheme ? R.color.keyboard_item_control_light_bg : R.color.keyboard_item_control_dark_bg);
    TextView addButton = (TextView) mainView.findViewById(R.id.add_marker_button);
    @ColorRes int colorId = lightTheme ? R.color.wikivoyage_active_light : R.color.wikivoyage_active_dark;
    addButton.setCompoundDrawablesWithIntrinsicBounds(null, null, getColoredIcon(R.drawable.ic_action_type_add, colorId), null);
    addButton.setText(R.string.shared_string_add);
    addButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            addWptPt();
            hasUnsavedChanges = true;
        }
    });
    TextView cancelButton = (TextView) mainView.findViewById(R.id.cancel_button);
    cancelButton.setText(R.string.shared_string_cancel);
    cancelButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            dismissEditingMode();
            clearInputs();
        }
    });
    final View keyboardLayout = mainView.findViewById(R.id.keyboard_layout);
    keyboardLayout.setBackgroundResource(lightTheme ? R.drawable.bg_bottom_menu_light : R.drawable.bg_coordinate_input_keyboard_dark);
    View keyboardView = mainView.findViewById(R.id.keyboard_view);
    int dividersColorResId = lightTheme ? R.color.keyboard_divider_light : R.color.keyboard_divider_dark;
    setBackgroundColor(keyboardView, dividersColorResId);
    setBackgroundColor(R.id.keyboard_divider, dividersColorResId);
    View.OnClickListener onClickListener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (isOsmandKeyboardOn()) {
                View focusedView = getDialog().getCurrentFocus();
                if (focusedView != null && focusedView instanceof EditText) {
                    EditText focusedEditText = (EditText) focusedView;
                    int id = v.getId();
                    if (id == R.id.keyboard_item_clear) {
                        focusedEditText.setText("");
                    } else if (id == R.id.keyboard_item_backspace) {
                        String str = focusedEditText.getText().toString();
                        if (str.length() > 0) {
                            str = str.substring(0, str.length() - 1);
                            focusedEditText.setText(str);
                            focusedEditText.setSelection(str.length());
                        } else {
                            switchEditText(focusedEditText.getId(), false);
                        }
                    } else if (id == R.id.keyboard_item_next_field) {
                        switchEditText(focusedEditText.getId(), true);
                    } else if (id == R.id.keyboard_item_hide) {
                        changeOsmandKeyboardVisibility(false);
                    } else {
                        focusedEditText.setText(focusedEditText.getText().toString() + getItemObjectById(id));
                        focusedEditText.setSelection(focusedEditText.getText().length());
                    }
                }
            }
        }
    };
    setupKeyboardItems(keyboardView, onClickListener, R.id.keyboard_item_0, R.id.keyboard_item_1, R.id.keyboard_item_2, R.id.keyboard_item_3, R.id.keyboard_item_4, R.id.keyboard_item_5, R.id.keyboard_item_6, R.id.keyboard_item_7, R.id.keyboard_item_8, R.id.keyboard_item_9, R.id.keyboard_item_clear, R.id.keyboard_item_next_field, R.id.keyboard_item_backspace, R.id.keyboard_item_hide);
    if (!isOsmandKeyboardOn() && isOsmandKeyboardCurrentlyVisible()) {
        changeOsmandKeyboardVisibility(false);
    }
    if (selectedWpt == null) {
        if ((isOsmandKeyboardCurrentlyVisible() || softKeyboardShown)) {
            scrollToLastPoint();
        }
    } else {
        enterEditingMode(selectedWpt);
    }
    mainView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            Rect r = new Rect();
            mainView.getWindowVisibleDisplayFrame(r);
            int screenHeight = mainView.getRootView().getHeight();
            int keypadHeight = screenHeight - r.bottom;
            boolean softKeyboardVisible = keypadHeight > screenHeight * SOFT_KEYBOARD_MIN_DETECTION_SIZE;
            if (softKeyboardShown && !softKeyboardVisible) {
                if (shouldShowOsmandKeyboard) {
                    changeOsmandKeyboardVisibility(true);
                    shouldShowOsmandKeyboard = false;
                }
            } else if (!softKeyboardShown && softKeyboardVisible && selectedWpt == null) {
                scrollToLastPoint();
            }
            softKeyboardShown = softKeyboardVisible;
            int height = keyboardLayout.getHeight();
            if (height > keyboardViewHeight) {
                keyboardViewHeight = height;
                if (isOsmandKeyboardCurrentlyVisible()) {
                    if (selectedWpt == null && adapter.getItemCount() > 1) {
                        scrollToLastPoint();
                    } else {
                        setPaddingToRecyclerViewBottom(keyboardViewHeight);
                    }
                }
            }
        }
    });
}
Also used : Context(android.content.Context) EditText(android.widget.EditText) ColorRes(androidx.annotation.ColorRes) Rect(android.graphics.Rect) Bundle(android.os.Bundle) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) FrameLayout(android.widget.FrameLayout) CoordinateInputAdapter(net.osmand.plus.mapmarkers.adapters.CoordinateInputAdapter) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) ImageView(android.widget.ImageView) ViewTreeObserver(android.view.ViewTreeObserver) LinearLayout(android.widget.LinearLayout)

Example 4 with ColorRes

use of androidx.annotation.ColorRes in project grocy-android by patzly.

the class StockOverviewItemAdapter method onBindViewHolder.

@SuppressLint("ClickableViewAccessibility")
@Override
public void onBindViewHolder(@NonNull final ViewHolder viewHolder, int positionDoNotUse) {
    GroupedListItem groupedListItem = groupedListItems.get(viewHolder.getAdapterPosition());
    int type = getItemViewType(viewHolder.getAdapterPosition());
    if (type == GroupedListItem.TYPE_HEADER) {
        GroupViewHolder holder = (GroupViewHolder) viewHolder;
        if (((GroupHeader) groupedListItem).getDisplayDivider() == 1) {
            holder.binding.divider.setVisibility(View.VISIBLE);
        } else {
            holder.binding.divider.setVisibility(View.GONE);
        }
        holder.binding.name.setText(((GroupHeader) groupedListItem).getGroupName());
        return;
    }
    StockItem stockItem = (StockItem) groupedListItem;
    StockItemViewHolder holder = (StockItemViewHolder) viewHolder;
    // NAME
    holder.binding.textName.setText(stockItem.getProduct().getName());
    if (shoppingListItemsProductIds.contains(String.valueOf(stockItem.getProduct().getId())) && shoppingListFeatureEnabled) {
        holder.binding.viewOnShoppingList.setVisibility(View.VISIBLE);
    } else {
        holder.binding.viewOnShoppingList.setVisibility(View.GONE);
    }
    Context context = holder.binding.textAmount.getContext();
    // AMOUNT
    QuantityUnit quantityUnit = quantityUnitHashMap.get(stockItem.getProduct().getQuIdStockInt());
    holder.binding.textAmount.setText(AmountUtil.getStockAmountInfo(context, pluralUtil, stockItem, quantityUnit));
    if (missingItemsProductIds.contains(stockItem.getProductId())) {
        holder.binding.textAmount.setTypeface(ResourcesCompat.getFont(context, R.font.jost_medium));
        holder.binding.textAmount.setTextColor(ContextCompat.getColor(context, R.color.retro_blue_fg));
    } else {
        holder.binding.textAmount.setTypeface(ResourcesCompat.getFont(context, R.font.jost_book));
        holder.binding.textAmount.setTextColor(ContextCompat.getColor(context, R.color.on_background_secondary));
    }
    // BEST BEFORE
    String date = stockItem.getBestBeforeDate();
    String days = null;
    boolean colorDays = false;
    if (date != null) {
        days = String.valueOf(DateUtil.getDaysFromNow(date));
    }
    if (!showDateTracking) {
        holder.binding.linearDays.setVisibility(View.GONE);
    } else if (days != null && (sortMode.equals(FilterChipLiveDataStockSort.SORT_DUE_DATE) || Integer.parseInt(days) <= daysExpiringSoon && !date.equals(Constants.DATE.NEVER_OVERDUE))) {
        holder.binding.linearDays.setVisibility(View.VISIBLE);
        holder.binding.textDays.setText(new DateUtil(context).getHumanForDaysFromNow(date));
        if (Integer.parseInt(days) <= daysExpiringSoon) {
            colorDays = true;
        }
    } else {
        holder.binding.linearDays.setVisibility(View.GONE);
        holder.binding.textDays.setText(null);
    }
    if (colorDays) {
        holder.binding.textDays.setTypeface(ResourcesCompat.getFont(context, R.font.jost_medium));
        @ColorRes int color;
        if (Integer.parseInt(days) >= 0) {
            color = R.color.retro_yellow_fg;
        } else if (stockItem.getDueTypeInt() == StockItem.DUE_TYPE_BEST_BEFORE) {
            color = R.color.retro_dirt_fg;
        } else {
            color = R.color.retro_red_fg;
        }
        holder.binding.textDays.setTextColor(ContextCompat.getColor(context, color));
    } else {
        holder.binding.textDays.setTypeface(ResourcesCompat.getFont(context, R.font.jost_book));
        holder.binding.textDays.setTextColor(ContextCompat.getColor(context, R.color.on_background_secondary));
    }
    // CONTAINER
    holder.binding.linearContainer.setOnClickListener(view -> listener.onItemRowClicked(stockItem));
}
Also used : Context(android.content.Context) ColorRes(androidx.annotation.ColorRes) GroupedListItem(xyz.zedler.patrick.grocy.model.GroupedListItem) DateUtil(xyz.zedler.patrick.grocy.util.DateUtil) StockItem(xyz.zedler.patrick.grocy.model.StockItem) SuppressLint(android.annotation.SuppressLint) QuantityUnit(xyz.zedler.patrick.grocy.model.QuantityUnit) SuppressLint(android.annotation.SuppressLint)

Example 5 with ColorRes

use of androidx.annotation.ColorRes in project trackworktime by mathisdt.

the class Widget method updateClockOutBtn.

private void updateClockOutBtn() {
    PendingIntent intent = createIntentForAction(Constants.CLOCK_OUT_ACTION);
    int viewId = R.id.clockOut;
    views.setOnClickPendingIntent(viewId, intent);
    boolean isClockedIn = isClockedIn();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        views.setBoolean(viewId, "setEnabled", isClockedIn);
    } else {
        // setBoolean() is not supported. Make text appear like disabled.
        @ColorRes int textColorRes = isClockedIn ? R.color.accent : R.color.text_disabled;
        @ColorInt int textColor = ContextCompat.getColor(context, textColorRes);
        views.setTextColor(viewId, textColor);
    }
}
Also used : ColorRes(androidx.annotation.ColorRes) ColorInt(androidx.annotation.ColorInt) PendingIntent(android.app.PendingIntent)

Aggregations

ColorRes (androidx.annotation.ColorRes)5 TextView (android.widget.TextView)3 Context (android.content.Context)2 EditText (android.widget.EditText)2 SuppressLint (android.annotation.SuppressLint)1 PendingIntent (android.app.PendingIntent)1 Rect (android.graphics.Rect)1 Bundle (android.os.Bundle)1 View (android.view.View)1 ViewTreeObserver (android.view.ViewTreeObserver)1 FrameLayout (android.widget.FrameLayout)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 ColorInt (androidx.annotation.ColorInt)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 DecimalFormat (java.text.DecimalFormat)1 Format (net.osmand.plus.mapmarkers.CoordinateInputFormats.Format)1 CoordinateInputAdapter (net.osmand.plus.mapmarkers.adapters.CoordinateInputAdapter)1 GroupedListItem (xyz.zedler.patrick.grocy.model.GroupedListItem)1