use of android.support.v7.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 = QuickActionFactory.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(new OnClickListener() {
@Override
public void onClick(View view) {
if (selectionListener != null)
selectionListener.onActionSelected(action);
}
});
if (action.isActionEditable()) {
view.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
CreateEditActionDialog dialog = CreateEditActionDialog.newInstance(action.id);
dialog.show(((AppCompatActivity) getContext()).getSupportFragmentManager(), AddQuickActionDialog.TAG);
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 android.support.v7.widget.GridLayout in project PhoneProfilesPlus by henrichg.
the class ColorChooserPreference method showDialog.
@Override
protected void showDialog(Bundle state) {
MaterialDialog.Builder mBuilder = new MaterialDialog.Builder(getContext()).title(getDialogTitle()).icon(getDialogIcon()).negativeText(getNegativeButtonText()).content(getDialogMessage()).customView(R.layout.dialog_color_chooser, false);
mDialog = mBuilder.build();
View layout = mDialog.getCustomView();
int preselect = 0;
for (int i = 0; i < mColors.length; i++) {
if (mColors[i] == Integer.valueOf(value)) {
preselect = i;
break;
}
}
// noinspection ConstantConditions
final GridLayout list = layout.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 = createSelector(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[] { shiftColor(mColors[i]), mColors[i] };
ColorStateList rippleColors = new ColorStateList(states, colors);
setBackgroundCompat(child, new RippleDrawable(rippleColors, selector, null));
} else {
setBackgroundCompat(child, selector);
}
}
GlobalGUIRoutines.registerOnActivityDestroyListener(this, this);
if (state != null)
mDialog.onRestoreInstanceState(state);
mDialog.setOnDismissListener(this);
mDialog.show();
}
use of android.support.v7.widget.GridLayout in project PhoneProfiles by henrichg.
the class ColorChooserPreference method showDialog.
@Override
protected void showDialog(Bundle state) {
MaterialDialog.Builder mBuilder = new MaterialDialog.Builder(getContext()).title(getDialogTitle()).icon(getDialogIcon()).negativeText(getNegativeButtonText()).content(getDialogMessage()).customView(R.layout.dialog_color_chooser, false);
mDialog = mBuilder.build();
View layout = mDialog.getCustomView();
int preselect = 0;
for (int i = 0; i < mColors.length; i++) {
if (mColors[i] == Integer.valueOf(value)) {
preselect = i;
break;
}
}
// noinspection ConstantConditions
final GridLayout list = layout.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 = createSelector(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[] { shiftColor(mColors[i]), mColors[i] };
ColorStateList rippleColors = new ColorStateList(states, colors);
setBackgroundCompat(child, new RippleDrawable(rippleColors, selector, null));
} else {
setBackgroundCompat(child, selector);
}
}
GlobalGUIRoutines.registerOnActivityDestroyListener(this, this);
if (state != null)
mDialog.onRestoreInstanceState(state);
mDialog.setOnDismissListener(this);
mDialog.show();
}
use of android.support.v7.widget.GridLayout in project PhotoNoter by yydcdut.
the class ColorChooserDialog method onCreateDialog.
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
View v = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_color_chooser, null);
AlertDialog dialog = new AlertDialog.Builder(getActivity(), R.style.note_dialog).setTitle(R.string.color_chooser).setCancelable(true).setView(v).create();
final TypedArray ta = getActivity().getResources().obtainTypedArray(R.array.colors);
mColors = new int[ta.length()];
for (int i = 0; i < ta.length(); i++) {
mColors[i] = ta.getColor(i, 0);
}
ta.recycle();
final GridLayout list = (GridLayout) v.findViewById(R.id.grid);
final int preselect = getArguments().getInt("preselect", -1);
for (int i = 0; i < mColors.length; 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 = createSelector(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[] { shiftColor(mColors[i]), mColors[i] };
ColorStateList rippleColors = new ColorStateList(states, colors);
setBackgroundCompat(child, new RippleDrawable(rippleColors, selector, null));
} else {
setBackgroundCompat(child, selector);
}
}
return dialog;
}
use of android.support.v7.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