Skip to content

Commit

Permalink
Merge pull request #2 from nirabpudasaini/master
Browse files Browse the repository at this point in the history
Added Localization Support
  • Loading branch information
oswaldo89 committed Jul 24, 2017
2 parents 285eb45 + e211175 commit ea93999
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 22 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/com/oswaldogh89/imgPicker/ExampleUsage.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ public void onClick(View view) {
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
switch (requestCode) {
case 0:
case ImagePicker.REQUEST_CAMERA:
if (resultCode == RESULT_OK) {
picker.AddNewImage(imageReturnedIntent);
}
break;
case 1:
case ImagePicker.REQUEST_GALLERY:
if (resultCode == RESULT_OK) {
picker.AddNewImage(imageReturnedIntent);
}
Expand Down
11 changes: 11 additions & 0 deletions osw-img-picker/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@
<application android:allowBackup="true" android:label="@string/app_name"
android:supportsRtl="true">

<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.oswaldogh89.imgpicker"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"></meta-data>
</provider>


</application>

</manifest>
103 changes: 90 additions & 13 deletions osw-img-picker/src/main/java/com/oswaldogh89/picker/ImagePicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.content.FileProvider;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
Expand All @@ -21,7 +25,11 @@

import com.bumptech.glide.Glide;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;

import de.hdodenhof.circleimageview.CircleImageView;
Expand All @@ -33,10 +41,17 @@ public class ImagePicker extends LinearLayout implements View.OnClickListener {
private CircleImageView im2, im3, im4, im5, im6, im7, im8, im9, im10, im11;
private DialogOptions dialog;
private Activity mainactivity;
private Fragment fragment;
private boolean calledFromFragment = false;
private HashMap<Integer, String> hmap;
private TextView count;
private Button BorrarTodas;

public static final int REQUEST_CAMERA = 8848;
public static final int REQUEST_GALLERY = 8849;

String mCurrentPhotoPath;

public ImagePicker(final Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
setOrientation(LinearLayout.HORIZONTAL);
Expand All @@ -53,24 +68,28 @@ public void onClick(View view) {
}
});
count = (TextView) findViewById(R.id.CountImg);
count.setText(context.getString(R.string.eip_images) + " 0");
hmap = new HashMap<>();
initImages();

dialog = new DialogOptions(context);
dialog.title("Seleccionar Imagen");
dialog.title(context.getString(R.string.eip_select_image));
dialog.canceledOnTouchOutside(true);
dialog.cancelable(true);
dialog.inflateMenu(R.menu.upload_menu);
dialog.setOnItemSelectedListener(new BottomDialog.OnItemSelectedListener() {
@Override
public boolean onItemSelected(int id) {
if (id == R.id.camera_action) {
Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
mainactivity.startActivityForResult(takePicture, 0);
dispatchTakePictureIntent();
return true;
} else if (id == R.id.gallery_action) {
Intent pickPhoto = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
mainactivity.startActivityForResult(pickPhoto, 1);
if(calledFromFragment){
fragment.startActivityForResult(pickPhoto, REQUEST_GALLERY);
}else{
mainactivity.startActivityForResult(pickPhoto, REQUEST_GALLERY);
}
return true;
} else {
return false;
Expand All @@ -95,6 +114,11 @@ public void setMainactivity(Activity mainactivity) {
this.mainactivity = mainactivity;
}

public void setFragment(Fragment fragment){
this.fragment = fragment;
this.calledFromFragment = true;
}

public void SetBorderImageColor(String color) {
im2.setBorderColor(Color.parseColor(color));
im3.setBorderColor(Color.parseColor(color));
Expand All @@ -109,7 +133,6 @@ public void SetBorderImageColor(String color) {
}

private void initImages() {

im2 = (CircleImageView) findViewById(R.id.im2);
im3 = (CircleImageView) findViewById(R.id.im3);
im4 = (CircleImageView) findViewById(R.id.im4);
Expand Down Expand Up @@ -201,7 +224,7 @@ private void deleteAllImages() {
im9.setVisibility(View.GONE);
im10.setVisibility(View.GONE);
im11.setVisibility(View.GONE);
count.setText("Imagenes: " + getImageCount() + "/10");
count.setText(mainactivity.getString(R.string.eip_images) + " " + getImageCount() + "/10");
}

private String AbrirImagen(int ID) {
Expand Down Expand Up @@ -240,18 +263,26 @@ public void enableDelateAll(Boolean enble) {
}

private void ChangeVisible(CircleImageView image, Intent imageReturnedIntent, int position) {
Uri path = imageReturnedIntent.getData();
if(imageReturnedIntent!=null) {
Uri path = imageReturnedIntent.getData();
Glide.with(getContext()).load(path).override(150, 150).into(image);
hmap.put(position, path.getPath());
}else{
File f = new File(mCurrentPhotoPath);
Uri contentUri = Uri.fromFile(f);
Glide.with(getContext()).load(contentUri).override(150, 150).into(image);
hmap.put(position,contentUri.getPath());
}
image.setVisibility(View.VISIBLE);
Glide.with(getContext()).load(path).override(150, 150).into(image);
hmap.put(position, path.getPath());
count.setText("Imagenes: " + getImageCount() + "/10");
count.setText(mainactivity.getString(R.string.eip_images) + " " + getImageCount() + "/10");

}

private void ChangeVisibleFromUrl(CircleImageView image, String url, int position) {
image.setVisibility(View.VISIBLE);
Glide.with(getContext()).load(url).centerCrop().into(image);
hmap.put(position, url);
count.setText("Imagenes: " + getImageCount() + "/10");
count.setText(mainactivity.getString(R.string.eip_images) + " " + getImageCount() + "/10");
}

public void addImagesFromUrl(ArrayList<String> urls) {
Expand Down Expand Up @@ -285,7 +316,7 @@ public void addImagesFromUrl(ArrayList<String> urls) {
public void onClick(final View view) {
final int ID = view.getId();
DialogOptions dialog2 = new DialogOptions(getContext());
dialog2.title("Opciones de la imagen");
dialog2.title(mainactivity.getString(R.string.eip_image_options));
dialog2.canceledOnTouchOutside(true);
dialog2.cancelable(true);
dialog2.inflateMenu(R.menu.options_menu);
Expand All @@ -295,7 +326,7 @@ public boolean onItemSelected(int id) {
if (id == R.id.delete_action) {
view.setVisibility(View.GONE);
EliminarImagen(ID);
count.setText("Imagenes: " + getImageCount() + "/10");
count.setText(mainactivity.getString(R.string.eip_images) + " " + getImageCount() + "/10");
return true;
} else if (id == R.id.see_action) {
String val = AbrirImagen(ID);
Expand All @@ -308,4 +339,50 @@ public boolean onItemSelected(int id) {
});
dialog2.show();
}

private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = mainactivity.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);

// Save a file: path for use with ACTION_VIEW intents
mCurrentPhotoPath = image.getAbsolutePath();
return image;
}

private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Ensure that there's a camera activity to handle the intent
if (takePictureIntent.resolveActivity(mainactivity.getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
// Error occurred while creating the File
ex.printStackTrace();
}
// Continue only if the File was successfully created
if (photoFile != null) {
Uri photoURI = FileProvider.getUriForFile(mainactivity,
"com.oswaldogh89.imgpicker",
photoFile);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
if(calledFromFragment){
fragment.startActivityForResult(takePictureIntent,REQUEST_CAMERA);
}else{
mainactivity.startActivityForResult(takePictureIntent, REQUEST_CAMERA);
}
}
}
}



}
4 changes: 2 additions & 2 deletions osw-img-picker/src/main/res/layout/template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="right"
android:text="Imagenes: 0"
android:text="@string/eip_images"
android:textStyle="bold" />

<LinearLayout
Expand All @@ -141,7 +141,7 @@
android:layout_height="43dp"
android:layout_marginTop="3dp"
android:enabled="true"
android:text="Borrar Todas"
android:text="@string/eip_delete_all"
android:visibility="gone" />


Expand Down
4 changes: 2 additions & 2 deletions osw-img-picker/src/main/res/menu/options_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
android:id="@+id/see_action"
android:icon="@drawable/eye_icon"
android:orderInCategory="100"
android:title="Ver imagen completa"
android:title="@string/eip_view_full_image"
app:showAsAction="always" />

<!--<item
Expand All @@ -21,6 +21,6 @@
android:id="@+id/delete_action"
android:icon="@drawable/delete_icon"
android:orderInCategory="100"
android:title="Eliminar"
android:title="@string/eip_remove"
app:showAsAction="always" />
</menu>
4 changes: 2 additions & 2 deletions osw-img-picker/src/main/res/menu/upload_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
android:id="@+id/camera_action"
android:icon="@drawable/camera_icon"
android:orderInCategory="100"
android:title="Camara"
android:title="@string/eip_camera"
app:showAsAction="always" />

<item
android:id="@+id/gallery_action"
android:icon="@drawable/gallery_icon"
android:orderInCategory="100"
android:title="Galeria"
android:title="@string/eip_gallery"
app:showAsAction="always" />
</menu>
11 changes: 11 additions & 0 deletions osw-img-picker/src/main/res/values-en/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="eip_camera">Camera</string>
<string name="eip_gallery">Gallery</string>
<string name="eip_remove">Remove</string>
<string name="eip_view_full_image">View Full Image</string>
<string name="eip_delete_all">Delete All</string>
<string name="eip_images">Images:</string>
<string name="eip_image_options">Image Options</string>
<string name="eip_select_image">Select Image</string>
</resources>
10 changes: 10 additions & 0 deletions osw-img-picker/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<resources>
<string name="eip_camera">Camara</string>
<string name="eip_gallery">Galeria</string>
<string name="eip_view_full_image">Ver imagen completa</string>
<string name="eip_remove">Eliminar</string>
<string name="eip_delete_all">Borrar Todas</string>
<string name="eip_images">Imagenes:</string>
<string name="eip_select_image">Seleccionar Imagen</string>
<string name="eip_image_options">Opciones de la imagen</string>
</resources>
11 changes: 11 additions & 0 deletions osw-img-picker/src/main/res/values-ne/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="eip_remove">हटाउनु</string>
<string name="eip_camera">क्यामेरा</string>
<string name="eip_gallery">ग्यालरी</string>
<string name="eip_view_full_image">ठूलो तस्बिर हेर्नुहोस्</string>
<string name="eip_delete_all">सबै मेटाउनु</string>
<string name="eip_images">तस्बिर:</string>
<string name="eip_image_options">तस्बिर विकल्पहरू</string>
<string name="eip_select_image">तस्बिर चयन</string>
</resources>
10 changes: 9 additions & 1 deletion osw-img-picker/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
<resources>
<string name="app_name">novus-logger</string>
<string name="app_name" translatable="false">novus-logger</string>
<string name="eip_camera">Camara</string>
<string name="eip_gallery">Galeria</string>
<string name="eip_view_full_image">Ver imagen completa</string>
<string name="eip_remove">Eliminar</string>
<string name="eip_delete_all">Borrar Todas</string>
<string name="eip_images">Imagenes:</string>
<string name="eip_select_image">Seleccionar Imagen</string>
<string name="eip_image_options">Opciones de la imagen</string>
</resources>
4 changes: 4 additions & 0 deletions osw-img-picker/src/main/res/xml/file_paths.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="my_images" path="Android/data/com.oswaldogh89.imgpicker/files/Pictures" />
</paths>

0 comments on commit ea93999

Please sign in to comment.