Search in sources :

Example 1 with GridLayout

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;
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) AppCompatActivity(android.support.v7.app.AppCompatActivity) AppCompatActivity(android.support.v7.app.AppCompatActivity) 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) GridLayout(android.support.v7.widget.GridLayout) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) ImageView(android.widget.ImageView)

Example 2 with 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();
}
Also used : GridLayout(android.support.v7.widget.GridLayout) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) FrameLayout(android.widget.FrameLayout) Drawable(android.graphics.drawable.Drawable) StateListDrawable(android.graphics.drawable.StateListDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable) ColorStateList(android.content.res.ColorStateList) View(android.view.View) RippleDrawable(android.graphics.drawable.RippleDrawable)

Example 3 with GridLayout

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();
}
Also used : GridLayout(android.support.v7.widget.GridLayout) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) FrameLayout(android.widget.FrameLayout) Drawable(android.graphics.drawable.Drawable) StateListDrawable(android.graphics.drawable.StateListDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable) ColorStateList(android.content.res.ColorStateList) View(android.view.View) RippleDrawable(android.graphics.drawable.RippleDrawable)

Example 4 with GridLayout

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;
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) GridLayout(android.widget.GridLayout) TypedArray(android.content.res.TypedArray) FrameLayout(android.widget.FrameLayout) ShapeDrawable(android.graphics.drawable.ShapeDrawable) Drawable(android.graphics.drawable.Drawable) StateListDrawable(android.graphics.drawable.StateListDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable) ColorStateList(android.content.res.ColorStateList) View(android.view.View) RippleDrawable(android.graphics.drawable.RippleDrawable)

Example 5 with GridLayout

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;
}
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(android.support.v7.widget.GridLayout) Random(java.util.Random) Button(android.widget.Button) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) ImageView(android.widget.ImageView) NonNull(android.support.annotation.NonNull)

Aggregations

View (android.view.View)5 GridLayout (android.support.v7.widget.GridLayout)4 ColorStateList (android.content.res.ColorStateList)3 Drawable (android.graphics.drawable.Drawable)3 RippleDrawable (android.graphics.drawable.RippleDrawable)3 StateListDrawable (android.graphics.drawable.StateListDrawable)3 FrameLayout (android.widget.FrameLayout)3 GradientDrawable (android.graphics.drawable.GradientDrawable)2 GridLayoutManager (android.support.v7.widget.GridLayoutManager)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 RecyclerView (android.support.v7.widget.RecyclerView)2 StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)2 LayoutInflater (android.view.LayoutInflater)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)2 Activity (android.app.Activity)1 AlertDialog (android.app.AlertDialog)1 ContentValues (android.content.ContentValues)1 Intent (android.content.Intent)1