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;
}
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);
}
}
}
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;
}
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;
}
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;
}
Aggregations