Search in sources :

Example 1 with GridLayout

use of androidx.gridlayout.widget.GridLayout in project Osmand by osmandapp.

the class QuickActionsWidget method createPageView.

private View createPageView(ViewGroup container, int position) {
    OsmandApplication application = ((OsmandApplication) getContext().getApplicationContext());
    boolean light = application.getSettings().isLightContent() && !application.getDaynightHelper().isNightMode();
    LayoutInflater li = getLayoutInflater(light ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme);
    View page = li.inflate(R.layout.quick_action_widget_page, container, false);
    GridLayout gridLayout = (GridLayout) page.findViewById(R.id.grid);
    final boolean land = !AndroidUiHelper.isOrientationPortrait((Activity) getContext());
    final int maxItems = actions.size() == 1 ? 1 : ELEMENT_PER_PAGE;
    for (int i = 0; i < maxItems; i++) {
        View view = li.inflate(R.layout.quick_action_widget_item, gridLayout, false);
        if (i + (position * ELEMENT_PER_PAGE) < actions.size()) {
            final QuickAction action = QuickActionRegistry.produceAction(actions.get(i + (position * ELEMENT_PER_PAGE)));
            ((ImageView) view.findViewById(imageView)).setImageResource(action.getIconRes(getContext()));
            ((TextView) view.findViewById(R.id.title)).setText(action.getActionText(application));
            if (action.isActionWithSlash(application)) {
                ((ImageView) view.findViewById(R.id.imageSlash)).setImageResource(light ? R.drawable.ic_action_icon_hide_white : R.drawable.ic_action_icon_hide_dark);
            }
            view.setOnClickListener(v -> {
                if (selectionListener != null) {
                    selectionListener.onActionSelected(action);
                }
            });
            // if (action.isActionEditable()) {
            view.setOnLongClickListener(new OnLongClickListener() {

                @Override
                public boolean onLongClick(View v) {
                    FragmentActivity activity = (AppCompatActivity) getContext();
                    FragmentManager fragmentManager = activity.getSupportFragmentManager();
                    if (action instanceof NewAction) {
                        QuickActionListFragment.showInstance(activity);
                    } else {
                        CreateEditActionDialog.showInstance(fragmentManager, action);
                    }
                    return true;
                }
            });
            // }
            if (!action.isActionEnable(application)) {
                view.setEnabled(false);
                view.setAlpha(0.5f);
            }
        }
        if (land) {
            view.findViewById(R.id.dividerBot).setVisibility(GONE);
            view.findViewById(R.id.dividerRight).setVisibility(VISIBLE);
        } else {
            view.findViewById(R.id.dividerBot).setVisibility(i < ELEMENT_PER_PAGE / 2 ? VISIBLE : GONE);
            view.findViewById(R.id.dividerRight).setVisibility(((i + 1) % 3) == 0 ? GONE : VISIBLE);
        }
        gridLayout.addView(view);
    }
    return gridLayout;
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) FragmentActivity(androidx.fragment.app.FragmentActivity) Activity(android.app.Activity) ImageView(android.widget.ImageView) R.id.imageView(net.osmand.plus.R.id.imageView) View(android.view.View) TextView(android.widget.TextView) FragmentManager(androidx.fragment.app.FragmentManager) FragmentActivity(androidx.fragment.app.FragmentActivity) GridLayout(androidx.gridlayout.widget.GridLayout) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) ImageView(android.widget.ImageView) NewAction(net.osmand.plus.quickaction.actions.NewAction)

Example 2 with GridLayout

use of androidx.gridlayout.widget.GridLayout in project PhoneProfiles by henrichg.

the class ColorChooserPreferenceFragmentX method onBindDialogView.

@Override
protected void onBindDialogView(View view) {
    super.onBindDialogView(view);
    int preselect = 0;
    for (int i = 0; i < preference.mColors.length; i++) {
        if (preference.mColors[i] == Integer.parseInt(preference.value)) {
            preselect = i;
            break;
        }
    }
    final GridLayout list = view.findViewById(R.id.dialog_color_chooser_grid);
    for (int i = 0; i < list.getChildCount(); i++) {
        FrameLayout child = (FrameLayout) list.getChildAt(i);
        child.setTag(i);
        child.setOnClickListener(this);
        child.getChildAt(0).setVisibility(preselect == i ? View.VISIBLE : View.GONE);
        Drawable selector = preference.createSelector(preference.mColors[i]);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            int[][] states = new int[][] { new int[] { -android.R.attr.state_pressed }, new int[] { android.R.attr.state_pressed } };
            int[] colors = new int[] { preference.shiftColor(preference.mColors[i]), preference.mColors[i] };
            ColorStateList rippleColors = new ColorStateList(states, colors);
            preference.setBackgroundCompat(child, new RippleDrawable(rippleColors, selector, null));
        } else {
            preference.setBackgroundCompat(child, selector);
        }
    }
}
Also used : GridLayout(androidx.gridlayout.widget.GridLayout) FrameLayout(android.widget.FrameLayout) RippleDrawable(android.graphics.drawable.RippleDrawable) Drawable(android.graphics.drawable.Drawable) ColorStateList(android.content.res.ColorStateList) SuppressLint(android.annotation.SuppressLint) RippleDrawable(android.graphics.drawable.RippleDrawable)

Example 3 with GridLayout

use of androidx.gridlayout.widget.GridLayout in project OsmAnd by osmandapp.

the class QuickActionsWidget method createPageView.

private View createPageView(ViewGroup container, int position) {
    OsmandApplication application = ((OsmandApplication) getContext().getApplicationContext());
    boolean light = application.getSettings().isLightContent() && !application.getDaynightHelper().isNightMode();
    LayoutInflater li = getLayoutInflater(light ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme);
    View page = li.inflate(R.layout.quick_action_widget_page, container, false);
    GridLayout gridLayout = (GridLayout) page.findViewById(R.id.grid);
    final boolean land = !AndroidUiHelper.isOrientationPortrait((Activity) getContext());
    final int maxItems = actions.size() == 1 ? 1 : ELEMENT_PER_PAGE;
    for (int i = 0; i < maxItems; i++) {
        View view = li.inflate(R.layout.quick_action_widget_item, gridLayout, false);
        if (i + (position * ELEMENT_PER_PAGE) < actions.size()) {
            final QuickAction action = QuickActionRegistry.produceAction(actions.get(i + (position * ELEMENT_PER_PAGE)));
            ((ImageView) view.findViewById(imageView)).setImageResource(action.getIconRes(getContext()));
            ((TextView) view.findViewById(R.id.title)).setText(action.getActionText(application));
            if (action.isActionWithSlash(application)) {
                ((ImageView) view.findViewById(R.id.imageSlash)).setImageResource(light ? R.drawable.ic_action_icon_hide_white : R.drawable.ic_action_icon_hide_dark);
            }
            view.setOnClickListener(v -> {
                if (selectionListener != null) {
                    selectionListener.onActionSelected(action);
                }
            });
            // if (action.isActionEditable()) {
            view.setOnLongClickListener(new OnLongClickListener() {

                @Override
                public boolean onLongClick(View v) {
                    FragmentActivity activity = (AppCompatActivity) getContext();
                    FragmentManager fragmentManager = activity.getSupportFragmentManager();
                    if (action instanceof NewAction) {
                        QuickActionListFragment.showInstance(activity);
                    } else {
                        CreateEditActionDialog.showInstance(fragmentManager, action);
                    }
                    return true;
                }
            });
            // }
            if (!action.isActionEnable(application)) {
                view.setEnabled(false);
                view.setAlpha(0.5f);
            }
        }
        if (land) {
            view.findViewById(R.id.dividerBot).setVisibility(GONE);
            view.findViewById(R.id.dividerRight).setVisibility(VISIBLE);
        } else {
            view.findViewById(R.id.dividerBot).setVisibility(i < ELEMENT_PER_PAGE / 2 ? VISIBLE : GONE);
            view.findViewById(R.id.dividerRight).setVisibility(((i + 1) % 3) == 0 ? GONE : VISIBLE);
        }
        gridLayout.addView(view);
    }
    return gridLayout;
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) FragmentActivity(androidx.fragment.app.FragmentActivity) Activity(android.app.Activity) ImageView(android.widget.ImageView) R.id.imageView(net.osmand.plus.R.id.imageView) View(android.view.View) TextView(android.widget.TextView) FragmentManager(androidx.fragment.app.FragmentManager) FragmentActivity(androidx.fragment.app.FragmentActivity) GridLayout(androidx.gridlayout.widget.GridLayout) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) ImageView(android.widget.ImageView) NewAction(net.osmand.plus.quickaction.actions.NewAction)

Example 4 with GridLayout

use of androidx.gridlayout.widget.GridLayout in project a-medic-log by rh-id.

the class MedicineItemSV method createView.

@Override
protected View createView(Activity activity, ViewGroup container) {
    View rootLayout = activity.getLayoutInflater().inflate(R.layout.item_medicine, container, false);
    rootLayout.setOnClickListener(this);
    TextView nameText = rootLayout.findViewById(R.id.text_name);
    TextView descriptionText = rootLayout.findViewById(R.id.text_description);
    TextView lastIntakeText = rootLayout.findViewById(R.id.text_last_intake);
    Button editButton = rootLayout.findViewById(R.id.button_edit);
    editButton.setOnClickListener(this);
    Button deleteButton = rootLayout.findViewById(R.id.button_delete);
    deleteButton.setOnClickListener(this);
    Button moreAction = rootLayout.findViewById(R.id.button_more_action);
    moreAction.setOnClickListener(this);
    GridLayout containerReminder = rootLayout.findViewById(R.id.container_reminder);
    mRxDisposer.add("createView_onMedicineStateChanged", mMedicineStateSubject.getSubject().debounce(16, TimeUnit.MILLISECONDS).observeOn(AndroidSchedulers.mainThread()).subscribe(medicineState -> {
        nameText.setText(medicineState.getMedicineName());
        descriptionText.setText(medicineState.getMedicineDescription());
        if (medicineState.getMedicineId() != null) {
            moreAction.setVisibility(View.VISIBLE);
        } else {
            moreAction.setVisibility(View.GONE);
        }
        queryLastMedicineIntake(medicineState.getMedicineId());
        containerReminder.removeAllViews();
        ArrayList<MedicineReminder> medicineReminders = medicineState.getMedicineReminderList();
        if (medicineReminders != null && !medicineReminders.isEmpty()) {
            containerReminder.setVisibility(View.VISIBLE);
            for (MedicineReminder medicineReminder : medicineReminders) {
                MaterialTextView materialTextView = new MaterialTextView(activity);
                materialTextView.setText(mTimeFormat.format(medicineReminder.startDateTime));
                GridLayout.LayoutParams params = new GridLayout.LayoutParams();
                params.width = GridLayout.LayoutParams.WRAP_CONTENT;
                params.height = GridLayout.LayoutParams.WRAP_CONTENT;
                params.columnSpec = GridLayout.spec(GridLayout.UNDEFINED, 1.0f);
                materialTextView.setLayoutParams(params);
                materialTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
                int tintColor = activity.getResources().getColor(R.color.daynight_black_white);
                Drawable icon;
                if (medicineReminder.reminderEnabled) {
                    icon = AppCompatResources.getDrawable(activity, R.drawable.ic_timer_black);
                } else {
                    icon = AppCompatResources.getDrawable(activity, R.drawable.ic_timer_off_black);
                }
                icon = DrawableCompat.wrap(icon);
                DrawableCompat.setTint(icon, tintColor);
                materialTextView.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
                containerReminder.addView(materialTextView);
            }
        } else {
            containerReminder.setVisibility(View.GONE);
        }
    }));
    mRxDisposer.add("createView_onLastMedicineIntakeChanged", mLastMedicineIntakeSubject.getSubject().debounce(100, TimeUnit.MILLISECONDS).observeOn(AndroidSchedulers.mainThread()).subscribe(medicineIntakeOpt -> {
        if (medicineIntakeOpt.isPresent()) {
            Date takenDateTime = medicineIntakeOpt.get().takenDateTime;
            lastIntakeText.setText(mDateTimeFormat.format(takenDateTime));
            lastIntakeText.setVisibility(View.VISIBLE);
        } else {
            lastIntakeText.setText(null);
            lastIntakeText.setVisibility(View.GONE);
        }
    }));
    mRxDisposer.add("createView_onMedicineIntakeAdded", mMedicineIntakeChangeNotifier.getAddedMedicineIntake().observeOn(Schedulers.from(mExecutorService)).subscribe(medicineIntake -> {
        if (medicineIntake.medicineId != null && medicineIntake.medicineId.equals(mMedicineStateSubject.getValue().getMedicineId())) {
            queryLastMedicineIntake(medicineIntake.medicineId);
        }
    }));
    mRxDisposer.add("createView_onMedicineIntakeUpdated", mMedicineIntakeChangeNotifier.getUpdatedMedicineIntake().observeOn(Schedulers.from(mExecutorService)).subscribe(updateMedicineIntakeEvent -> {
        MedicineIntake medicineIntake = updateMedicineIntakeEvent.getAfter();
        if (medicineIntake.medicineId != null && medicineIntake.medicineId.equals(mMedicineStateSubject.getValue().getMedicineId())) {
            queryLastMedicineIntake(medicineIntake.medicineId);
        }
    }));
    mRxDisposer.add("createView_onMedicineIntakeDeleted", mMedicineIntakeChangeNotifier.getDeletedMedicineIntake().observeOn(Schedulers.from(mExecutorService)).subscribe(medicineIntake -> {
        if (medicineIntake.medicineId != null && medicineIntake.medicineId.equals(mMedicineStateSubject.getValue().getMedicineId())) {
            queryLastMedicineIntake(medicineIntake.medicineId);
        }
    }));
    return rootLayout;
}
Also used : AppCompatResources(androidx.appcompat.content.res.AppCompatResources) Date(java.util.Date) MedicineIntake(m.co.rh.id.a_medic_log.base.entity.MedicineIntake) SimpleDateFormat(java.text.SimpleDateFormat) DrawableCompat(androidx.core.graphics.drawable.DrawableCompat) Drawable(android.graphics.drawable.Drawable) MedicineIntakeChangeNotifier(m.co.rh.id.a_medic_log.app.provider.notifier.MedicineIntakeChangeNotifier) MedicineReminder(m.co.rh.id.a_medic_log.base.entity.MedicineReminder) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) Schedulers(io.reactivex.rxjava3.schedulers.Schedulers) View(android.view.View) Button(android.widget.Button) GridLayout(androidx.gridlayout.widget.GridLayout) QueryMedicineCmd(m.co.rh.id.a_medic_log.app.provider.command.QueryMedicineCmd) DateFormat(java.text.DateFormat) ExecutorService(java.util.concurrent.ExecutorService) OptionalBehaviorSubject(m.co.rh.id.a_medic_log.base.rx.OptionalBehaviorSubject) SerialBehaviorSubject(m.co.rh.id.a_medic_log.base.rx.SerialBehaviorSubject) StatefulView(m.co.rh.id.anavigator.StatefulView) Provider(m.co.rh.id.aprovider.Provider) MedicineState(m.co.rh.id.a_medic_log.base.state.MedicineState) ViewGroup(android.view.ViewGroup) PopupMenu(androidx.appcompat.widget.PopupMenu) TimeUnit(java.util.concurrent.TimeUnit) AndroidSchedulers(io.reactivex.rxjava3.android.schedulers.AndroidSchedulers) MaterialTextView(com.google.android.material.textview.MaterialTextView) TextView(android.widget.TextView) StatefulViewProvider(m.co.rh.id.a_medic_log.app.provider.StatefulViewProvider) RequireComponent(m.co.rh.id.anavigator.component.RequireComponent) TypedValue(android.util.TypedValue) RxDisposer(m.co.rh.id.a_medic_log.app.rx.RxDisposer) R(m.co.rh.id.a_medic_log.R) Activity(android.app.Activity) MaterialTextView(com.google.android.material.textview.MaterialTextView) ArrayList(java.util.ArrayList) Drawable(android.graphics.drawable.Drawable) View(android.view.View) StatefulView(m.co.rh.id.anavigator.StatefulView) MaterialTextView(com.google.android.material.textview.MaterialTextView) TextView(android.widget.TextView) Date(java.util.Date) GridLayout(androidx.gridlayout.widget.GridLayout) Button(android.widget.Button) MedicineIntake(m.co.rh.id.a_medic_log.base.entity.MedicineIntake) MaterialTextView(com.google.android.material.textview.MaterialTextView) TextView(android.widget.TextView) MedicineReminder(m.co.rh.id.a_medic_log.base.entity.MedicineReminder)

Example 5 with GridLayout

use of androidx.gridlayout.widget.GridLayout in project aware-client by denzilferreira.

the class ESM_PAM method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    super.onCreateDialog(savedInstanceState);
    pam_selected = "";
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View ui = inflater.inflate(R.layout.esm_pam, null);
    builder.setView(ui);
    esm_dialog = builder.create();
    esm_dialog.setCanceledOnTouchOutside(false);
    try {
        TextView esm_title = (TextView) ui.findViewById(R.id.esm_title);
        esm_title.setText(getTitle());
        TextView esm_instructions = (TextView) ui.findViewById(R.id.esm_instructions);
        esm_instructions.setText(getInstructions());
        final GridLayout answersHolder = (GridLayout) ui.findViewById(R.id.esm_pam);
        answersHolder.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                try {
                    if (getExpirationThreshold() > 0 && expire_monitor != null)
                        expire_monitor.cancel(true);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
        // 0-indexed
        JSONArray moods = getPAM();
        if (moods.length() == 0) {
            // Load by default ours
            moods.put("http://awareframework.com/public/pam/afraid");
            moods.put("http://awareframework.com/public/pam/tense");
            moods.put("http://awareframework.com/public/pam/excited");
            moods.put("http://awareframework.com/public/pam/delighted");
            moods.put("http://awareframework.com/public/pam/frustrated");
            moods.put("http://awareframework.com/public/pam/angry");
            moods.put("http://awareframework.com/public/pam/happy");
            moods.put("http://awareframework.com/public/pam/glad");
            moods.put("http://awareframework.com/public/pam/miserable");
            moods.put("http://awareframework.com/public/pam/sad");
            moods.put("http://awareframework.com/public/pam/calm");
            moods.put("http://awareframework.com/public/pam/satisfied");
            moods.put("http://awareframework.com/public/pam/gloomy");
            moods.put("http://awareframework.com/public/pam/tired");
            moods.put("http://awareframework.com/public/pam/sleepy");
            moods.put("http://awareframework.com/public/pam/serene");
        }
        for (int i = 1; i < 17; i++) {
            final int childPos = i;
            ImageView moodOption = (ImageView) ui.findViewById(getResources().getIdentifier("pos" + i, "id", getActivity().getPackageName()));
            String mood_picture_url = moods.getString(i - 1);
            Random rand_pic = new Random(System.currentTimeMillis());
            Integer pic = 1 + rand_pic.nextInt(3);
            // Asynchronously download mood image and caches automatically
            Ion.getDefault(getActivity().getApplicationContext()).getConscryptMiddleware().enable(false);
            Ion.with(moodOption).placeholder(R.drawable.square).load(mood_picture_url + "/" + pic + ".jpg");
            moodOption.setTag(moodDescription(i));
            moodOption.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    try {
                        if (getExpirationThreshold() > 0 && expire_monitor != null)
                            expire_monitor.cancel(true);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    pam_selected = view.getTag().toString();
                    answersHolder.getChildAt(childPos - 1).setSelected(true);
                    for (int j = 1; j < 17; j++) {
                        if (childPos == j) {
                            continue;
                        } else
                            answersHolder.getChildAt(j - 1).setSelected(false);
                    }
                }
            });
        }
        Button cancel_text = (Button) ui.findViewById(R.id.esm_cancel);
        cancel_text.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                esm_dialog.cancel();
            }
        });
        Button submit_number = (Button) ui.findViewById(R.id.esm_submit);
        submit_number.setText(getSubmitButton());
        submit_number.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                try {
                    if (getExpirationThreshold() > 0 && expire_monitor != null)
                        expire_monitor.cancel(true);
                    ContentValues rowData = new ContentValues();
                    rowData.put(ESM_Provider.ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis());
                    rowData.put(ESM_Provider.ESM_Data.ANSWER, pam_selected);
                    rowData.put(ESM_Provider.ESM_Data.STATUS, ESM.STATUS_ANSWERED);
                    getActivity().getContentResolver().update(ESM_Provider.ESM_Data.CONTENT_URI, rowData, ESM_Provider.ESM_Data._ID + "=" + getID(), null);
                    Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED);
                    answer.putExtra(ESM.EXTRA_ANSWER, rowData.getAsString(ESM_Provider.ESM_Data.ANSWER));
                    getActivity().sendBroadcast(answer);
                    if (Aware.DEBUG)
                        Log.d(Aware.TAG, "Answer:" + rowData.toString());
                    esm_dialog.dismiss();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return esm_dialog;
}
Also used : AlertDialog(android.app.AlertDialog) ContentValues(android.content.ContentValues) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) Intent(android.content.Intent) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) GridLayout(androidx.gridlayout.widget.GridLayout) Random(java.util.Random) Button(android.widget.Button) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) ImageView(android.widget.ImageView) NonNull(androidx.annotation.NonNull)

Aggregations

GridLayout (androidx.gridlayout.widget.GridLayout)5 View (android.view.View)4 TextView (android.widget.TextView)4 Activity (android.app.Activity)3 LayoutInflater (android.view.LayoutInflater)3 ImageView (android.widget.ImageView)3 Drawable (android.graphics.drawable.Drawable)2 Button (android.widget.Button)2 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)2 FragmentActivity (androidx.fragment.app.FragmentActivity)2 FragmentManager (androidx.fragment.app.FragmentManager)2 OsmandApplication (net.osmand.plus.OsmandApplication)2 R.id.imageView (net.osmand.plus.R.id.imageView)2 NewAction (net.osmand.plus.quickaction.actions.NewAction)2 SuppressLint (android.annotation.SuppressLint)1 AlertDialog (android.app.AlertDialog)1 ContentValues (android.content.ContentValues)1 Intent (android.content.Intent)1 ColorStateList (android.content.res.ColorStateList)1 RippleDrawable (android.graphics.drawable.RippleDrawable)1