Search in sources :

Example 26 with Nullable

use of android.support.annotation.Nullable in project flexbox-layout by google.

the class FlexItemEditFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_flex_item_edit, container, false);
    getDialog().setTitle(String.valueOf(mFlexItem.index + 1));
    final TextInputLayout orderTextInput = (TextInputLayout) view.findViewById(R.id.input_layout_order);
    EditText orderEdit = (EditText) view.findViewById(R.id.edit_text_order);
    orderEdit.setText(String.valueOf(mFlexItem.order));
    orderEdit.addTextChangedListener(new FlexEditTextWatcher(orderTextInput, new IntegerInputValidator(), R.string.must_be_integer));
    final TextInputLayout flexGrowInput = (TextInputLayout) view.findViewById(R.id.input_layout_flex_grow);
    final EditText flexGrowEdit = (EditText) view.findViewById(R.id.edit_text_flex_grow);
    flexGrowEdit.setText(String.valueOf(mFlexItem.flexGrow));
    flexGrowEdit.addTextChangedListener(new FlexEditTextWatcher(flexGrowInput, new NonNegativeDecimalInputValidator(), R.string.must_be_non_negative_float));
    final TextInputLayout flexShrinkInput = (TextInputLayout) view.findViewById(R.id.input_layout_flex_shrink);
    EditText flexShrinkEdit = (EditText) view.findViewById(R.id.edit_text_flex_shrink);
    flexShrinkEdit.setText(String.valueOf(mFlexItem.flexShrink));
    flexShrinkEdit.addTextChangedListener(new FlexEditTextWatcher(flexShrinkInput, new NonNegativeDecimalInputValidator(), R.string.must_be_non_negative_float));
    final TextInputLayout flexBasisPercentInput = (TextInputLayout) view.findViewById(R.id.input_layout_flex_basis_percent);
    EditText flexBasisPercentEdit = (EditText) view.findViewById(R.id.edit_text_flex_basis_percent);
    if (mFlexItem.flexBasisPercent != FlexboxLayout.LayoutParams.FLEX_BASIS_PERCENT_DEFAULT) {
        flexBasisPercentEdit.setText(String.valueOf(Math.round(mFlexItem.flexBasisPercent * 100)));
    } else {
        flexBasisPercentEdit.setText(String.valueOf((int) mFlexItem.flexBasisPercent));
    }
    flexBasisPercentEdit.addTextChangedListener(new FlexEditTextWatcher(flexBasisPercentInput, new FlexBasisPercentInputValidator(), R.string.must_be_minus_one_or_non_negative_integer));
    final TextInputLayout widthInput = (TextInputLayout) view.findViewById(R.id.input_layout_width);
    EditText widthEdit = (EditText) view.findViewById(R.id.edit_text_width);
    widthEdit.setText(String.valueOf(mFlexItem.width));
    widthEdit.addTextChangedListener(new FlexEditTextWatcher(widthInput, new DimensionInputValidator(), R.string.must_be_minus_one_or_minus_two_or_non_negative_integer));
    final TextInputLayout heightInput = (TextInputLayout) view.findViewById(R.id.input_layout_height);
    EditText heightEdit = (EditText) view.findViewById(R.id.edit_text_height);
    heightEdit.setText(String.valueOf(mFlexItem.height));
    heightEdit.addTextChangedListener(new FlexEditTextWatcher(heightInput, new DimensionInputValidator(), R.string.must_be_minus_one_or_minus_two_or_non_negative_integer));
    final TextInputLayout minWidthInput = (TextInputLayout) view.findViewById(R.id.input_layout_min_width);
    EditText minWidthEdit = (EditText) view.findViewById(R.id.edit_text_min_width);
    minWidthEdit.setText(String.valueOf(mFlexItem.minWidth));
    minWidthEdit.addTextChangedListener(new FlexEditTextWatcher(minWidthInput, new FixedDimensionInputValidator(), R.string.must_be_non_negative_integer));
    final TextInputLayout minHeightInput = (TextInputLayout) view.findViewById(R.id.input_layout_min_height);
    EditText minHeightEdit = (EditText) view.findViewById(R.id.edit_text_min_height);
    minHeightEdit.setText(String.valueOf(mFlexItem.minHeight));
    minHeightEdit.addTextChangedListener(new FlexEditTextWatcher(minHeightInput, new FixedDimensionInputValidator(), R.string.must_be_non_negative_integer));
    final TextInputLayout maxWidthInput = (TextInputLayout) view.findViewById(R.id.input_layout_max_width);
    EditText maxWidthEdit = (EditText) view.findViewById(R.id.edit_text_max_width);
    maxWidthEdit.setText(String.valueOf(mFlexItem.maxWidth));
    maxWidthEdit.addTextChangedListener(new FlexEditTextWatcher(maxWidthInput, new FixedDimensionInputValidator(), R.string.must_be_non_negative_integer));
    final TextInputLayout maxHeightInput = (TextInputLayout) view.findViewById(R.id.input_layout_max_height);
    EditText maxHeightEdit = (EditText) view.findViewById(R.id.edit_text_max_height);
    maxHeightEdit.setText(String.valueOf(mFlexItem.maxHeight));
    maxHeightEdit.addTextChangedListener(new FlexEditTextWatcher(maxHeightInput, new FixedDimensionInputValidator(), R.string.must_be_non_negative_integer));
    setNextFocusesOnEnterDown(orderEdit, flexGrowEdit, flexShrinkEdit, flexBasisPercentEdit, widthEdit, heightEdit, minWidthEdit, minHeightEdit, maxWidthEdit, maxHeightEdit);
    Spinner alignSelfSpinner = (Spinner) view.findViewById(R.id.spinner_align_self);
    ArrayAdapter<CharSequence> arrayAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.array_align_self, R.layout.spinner_item);
    alignSelfSpinner.setAdapter(arrayAdapter);
    alignSelfSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            String selected = parent.getItemAtPosition(position).toString();
            if (selected.equals(ALIGN_SELF_AUTO)) {
                mFlexItem.alignSelf = FlexboxLayout.LayoutParams.ALIGN_SELF_AUTO;
            } else if (selected.equals(ALIGN_SELF_FLEX_START)) {
                mFlexItem.alignSelf = FlexboxLayout.LayoutParams.ALIGN_SELF_FLEX_START;
            } else if (selected.equals(ALIGN_SELF_FLEX_END)) {
                mFlexItem.alignSelf = FlexboxLayout.LayoutParams.ALIGN_SELF_FLEX_END;
            } else if (selected.equals(ALIGN_SELF_CENTER)) {
                mFlexItem.alignSelf = FlexboxLayout.LayoutParams.ALIGN_SELF_CENTER;
            } else if (selected.equals(ALIGN_SELF_BASELINE)) {
                mFlexItem.alignSelf = FlexboxLayout.LayoutParams.ALIGN_SELF_BASELINE;
            } else if (selected.equals(ALIGN_SELF_STRETCH)) {
                mFlexItem.alignSelf = FlexboxLayout.LayoutParams.ALIGN_SELF_STRETCH;
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        // No op
        }
    });
    CheckBox wrapBeforeCheckBox = (CheckBox) view.findViewById(R.id.checkbox_wrap_before);
    wrapBeforeCheckBox.setChecked(mFlexItem.wrapBefore);
    wrapBeforeCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mFlexItem.wrapBefore = isChecked;
        }
    });
    int alignSelfPosition = arrayAdapter.getPosition(alignSelfAsString(mFlexItem.alignSelf));
    alignSelfSpinner.setSelection(alignSelfPosition);
    view.findViewById(R.id.button_cancel).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dismiss();
        }
    });
    final Button okButton = (Button) view.findViewById(R.id.button_ok);
    okButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (orderTextInput.isErrorEnabled() || flexGrowInput.isErrorEnabled() || flexBasisPercentInput.isErrorEnabled() || widthInput.isErrorEnabled() || heightInput.isErrorEnabled() || minWidthInput.isErrorEnabled() || minHeightInput.isErrorEnabled() || maxWidthInput.isErrorEnabled() || maxHeightInput.isErrorEnabled()) {
                Toast.makeText(getActivity(), R.string.invalid_values_exist, Toast.LENGTH_SHORT).show();
                return;
            }
            if (mFlexItemChangedListener != null) {
                mFlexItemChangedListener.onFlexItemChanged(mFlexItem);
            }
            dismiss();
        }
    });
    return view;
}
Also used : DimensionInputValidator(com.google.android.apps.flexbox.validators.DimensionInputValidator) FixedDimensionInputValidator(com.google.android.apps.flexbox.validators.FixedDimensionInputValidator) FixedDimensionInputValidator(com.google.android.apps.flexbox.validators.FixedDimensionInputValidator) Spinner(android.widget.Spinner) IntegerInputValidator(com.google.android.apps.flexbox.validators.IntegerInputValidator) NonNegativeDecimalInputValidator(com.google.android.apps.flexbox.validators.NonNegativeDecimalInputValidator) Button(android.widget.Button) CompoundButton(android.widget.CompoundButton) TextInputLayout(android.support.design.widget.TextInputLayout) EditText(android.widget.EditText) FlexBasisPercentInputValidator(com.google.android.apps.flexbox.validators.FlexBasisPercentInputValidator) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) CheckBox(android.widget.CheckBox) AdapterView(android.widget.AdapterView) CompoundButton(android.widget.CompoundButton) Nullable(android.support.annotation.Nullable)

Example 27 with Nullable

use of android.support.annotation.Nullable in project react-native-image-picker by marcshilling.

the class PermissionUtils method explainingDialog.

@Nullable
public static AlertDialog explainingDialog(@NonNull final ImagePickerModule module, @NonNull final ReadableMap options, @NonNull final OnExplainingPermissionCallback callback) {
    if (module.getContext() == null) {
        return null;
    }
    final ReadableMap permissionDenied = options.getMap("permissionDenied");
    final String title = permissionDenied.getString("title");
    final String text = permissionDenied.getString("text");
    final String btnReTryTitle = permissionDenied.getString("reTryTitle");
    final String btnOkTitle = permissionDenied.getString("okTitle");
    final WeakReference<ImagePickerModule> reference = new WeakReference<>(module);
    final Activity activity = module.getActivity();
    if (activity == null) {
        return null;
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(activity, module.getDialogThemeId());
    builder.setTitle(title).setMessage(text).setCancelable(false).setNegativeButton(btnOkTitle, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(final DialogInterface dialogInterface, int i) {
            callback.onCancel(reference, dialogInterface);
        }
    }).setPositiveButton(btnReTryTitle, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            callback.onReTry(reference, dialogInterface);
        }
    });
    return builder.create();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) ImagePickerModule(com.imagepicker.ImagePickerModule) Activity(android.app.Activity) WeakReference(java.lang.ref.WeakReference) ReadableMap(com.facebook.react.bridge.ReadableMap) Nullable(android.support.annotation.Nullable)

Example 28 with Nullable

use of android.support.annotation.Nullable in project react-native-image-picker by marcshilling.

the class ImagePickerModule method compatUriFromFile.

@Nullable
private static Uri compatUriFromFile(@NonNull final Context context, @NonNull final File file) {
    Uri result = null;
    if (Build.VERSION.SDK_INT < 21) {
        result = Uri.fromFile(file);
    } else {
        final String packageName = context.getApplicationContext().getPackageName();
        final String authority = new StringBuilder(packageName).append(".provider").toString();
        try {
            result = FileProvider.getUriForFile(context, authority, file);
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        }
    }
    return result;
}
Also used : Uri(android.net.Uri) Nullable(android.support.annotation.Nullable)

Example 29 with Nullable

use of android.support.annotation.Nullable in project react-native-image-picker by marcshilling.

the class RealPathUtil method getRealPathFromURI.

@SuppressLint("NewApi")
@Nullable
public static String getRealPathFromURI(@NonNull final Context context, @NonNull final Uri uri) {
    final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
    // DocumentProvider
    if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
        // ExternalStorageProvider
        if (isExternalStorageDocument(uri)) {
            final String docId = DocumentsContract.getDocumentId(uri);
            final String[] split = docId.split(":");
            final String type = split[0];
            if ("primary".equalsIgnoreCase(type)) {
                return Environment.getExternalStorageDirectory() + "/" + split[1];
            }
        // TODO handle non-primary volumes
        } else // DownloadsProvider
        if (isDownloadsDocument(uri)) {
            final String id = DocumentsContract.getDocumentId(uri);
            final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
            return getDataColumn(context, contentUri, null, null);
        } else // MediaProvider
        if (isMediaDocument(uri)) {
            final String docId = DocumentsContract.getDocumentId(uri);
            final String[] split = docId.split(":");
            final String type = split[0];
            Uri contentUri = null;
            if ("image".equals(type)) {
                contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
            } else if ("video".equals(type)) {
                contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
            } else if ("audio".equals(type)) {
                contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
            }
            final String selection = "_id=?";
            final String[] selectionArgs = new String[] { split[1] };
            return getDataColumn(context, contentUri, selection, selectionArgs);
        }
    } else // MediaStore (and general)
    if ("content".equalsIgnoreCase(uri.getScheme())) {
        // Return the remote address
        if (isGooglePhotosUri(uri))
            return uri.getLastPathSegment();
        if (isFileProviderUri(context, uri))
            return getFileProviderPath(context, uri);
        return getDataColumn(context, uri, null, null);
    } else // File
    if ("file".equalsIgnoreCase(uri.getScheme())) {
        return uri.getPath();
    }
    return null;
}
Also used : Uri(android.net.Uri) SuppressLint(android.annotation.SuppressLint) Nullable(android.support.annotation.Nullable)

Example 30 with Nullable

use of android.support.annotation.Nullable in project SimpleNews by liuling07.

the class ImageFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_image, null);
    mSwipeRefreshWidget = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh_widget);
    mSwipeRefreshWidget.setColorSchemeResources(R.color.primary, R.color.primary_dark, R.color.primary_light, R.color.accent);
    mSwipeRefreshWidget.setOnRefreshListener(this);
    mRecyclerView = (RecyclerView) view.findViewById(R.id.recycle_view);
    mRecyclerView.setHasFixedSize(true);
    mLayoutManager = new LinearLayoutManager(getActivity());
    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    mAdapter = new ImageAdapter(getActivity().getApplicationContext());
    mRecyclerView.setAdapter(mAdapter);
    mRecyclerView.addOnScrollListener(mOnScrollListener);
    onRefresh();
    return view;
}
Also used : ImageAdapter(com.lauren.simplenews.images.ImageAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ImageView(com.lauren.simplenews.images.view.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) Nullable(android.support.annotation.Nullable)

Aggregations

Nullable (android.support.annotation.Nullable)582 View (android.view.View)315 TextView (android.widget.TextView)163 RecyclerView (android.support.v7.widget.RecyclerView)85 BindView (butterknife.BindView)57 ImageView (android.widget.ImageView)52 ArrayList (java.util.ArrayList)43 IOException (java.io.IOException)36 Bundle (android.os.Bundle)35 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)35 Intent (android.content.Intent)32 ViewGroup (android.view.ViewGroup)32 Cursor (android.database.Cursor)29 Uri (android.net.Uri)27 File (java.io.File)24 AdapterView (android.widget.AdapterView)22 List (java.util.List)20 NonNull (android.support.annotation.NonNull)19 Context (android.content.Context)15 Bitmap (android.graphics.Bitmap)15