2 Commits f44326030b ... 3e6f00a6eb

Author SHA1 Message Date
  nanabee 3e6f00a6eb camera 4 years ago
  nanabee ba4b61ee3b workong butoons 4 years ago

+ 1 - 0
app/build.gradle

@@ -41,6 +41,7 @@ dependencies {
     implementation 'com.squareup.retrofit2:converter-scalars:2.5.0'
     implementation 'com.nineoldandroids:library:2.4.0'
     implementation 'com.jakewharton:butterknife:8.5.1'
+    implementation 'com.karumi:dexter:5.0.0'
     annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
     implementation 'com.github.sd6352051.niftydialogeffects:niftydialogeffects:1.0.0@aar'
 

+ 6 - 1
app/src/main/AndroidManifest.xml

@@ -4,6 +4,9 @@
 
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
     <uses-permission android:name="android.permission.INTERNET" />
+    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
+    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
+    <uses-permission android:name="android.permission.CAMERA"/>
 
     <application
         android:allowBackup="true"
@@ -62,7 +65,8 @@
                 android:name="android.support.PARENT_ACTIVITY"
                 android:value=".activities.MstagesActivity" />
         </activity>
-        <activity android:name=".activities.MajorStagesActivity"
+        <activity
+            android:name=".activities.MajorStagesActivity"
             android:label="@string/site1"
             android:parentActivityName=".activities.MinorStagesActivity"
             android:theme="@style/AppTheme">
@@ -70,6 +74,7 @@
                 android:name="android.support.PARENT_ACTIVITY"
                 android:value=".activities.MinorStagesActivity" />
         </activity>
+        <activity android:name=".activities.ProgressActivity"></activity>
     </application>
 
 </manifest>

+ 9 - 8
app/src/main/java/com/bkgrands/fpmu/Adapters/MajorstagesAdapter.java

@@ -1,6 +1,7 @@
 package com.bkgrands.fpmu.Adapters;
 
 import android.content.Context;
+import android.content.Intent;
 import android.support.annotation.NonNull;
 import android.support.v7.widget.RecyclerView;
 import android.view.LayoutInflater;
@@ -9,6 +10,7 @@ import android.view.ViewGroup;
 import android.widget.TextView;
 
 import com.bkgrands.fpmu.R;
+import com.bkgrands.fpmu.activities.ProgressActivity;
 import com.bkgrands.fpmu.classes.Payload;
 
 import java.util.List;
@@ -35,14 +37,13 @@ public class MajorstagesAdapter extends RecyclerView.Adapter<MajorstagesAdapter.
     public void onBindViewHolder(@NonNull MajorstagesAdapter.ViewHolder viewHolder, final int i) {
         viewHolder.tv_facility.setText(payloads.get(i).getMstages().get(i).getMinorStages().get(i).getMajorStage().getName());
 
-//        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
-//            @Override
-//            public void onClick(View v) {
-//                Intent intent = new Intent(v.getContext(), MinorStagesActivity.class);
-//                intent.putExtra( "majorsites", String.valueOf(payloads.get(i).getMstages().get(i).getName()));
-//                context.startActivity(intent);
-//            }
-//        });
+        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                Intent intent = new Intent(v.getContext(), ProgressActivity.class);
+                context.startActivity(intent);
+            }
+        });
     }
 
     @Override

+ 261 - 0
app/src/main/java/com/bkgrands/fpmu/activities/ProgressActivity.java

@@ -0,0 +1,261 @@
+package com.bkgrands.fpmu.activities;
+
+import android.Manifest;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.database.Cursor;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.Color;
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
+import android.media.MediaScannerConnection;
+import android.net.Uri;
+import android.os.Environment;
+import android.provider.MediaStore;
+import android.support.v7.app.AlertDialog;
+import android.support.v7.app.AppCompatActivity;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.KeyEvent;
+import android.view.MotionEvent;
+import android.view.View;
+import android.webkit.PermissionRequest;
+import android.widget.Button;
+import android.widget.ImageButton;
+import android.widget.ImageView;
+import android.widget.Toast;
+
+import com.bkgrands.fpmu.R;
+import com.karumi.dexter.Dexter;
+import com.karumi.dexter.MultiplePermissionsReport;
+import com.karumi.dexter.PermissionToken;
+import com.karumi.dexter.listener.DexterError;
+import com.karumi.dexter.listener.PermissionRequestErrorListener;
+import com.karumi.dexter.listener.multi.MultiplePermissionsListener;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Calendar;
+import java.util.List;
+
+public class ProgressActivity extends AppCompatActivity {
+    Button wait, start, done;
+    ImageButton capture;
+    ImageView shot;
+    private Context mContext;
+    private int GALLERY = 1, CAMERA = 2;
+    private static final String IMAGE_DIRECTORY = "/YourDirectName";
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_progress);
+        wait = (Button) findViewById(R.id.waiting);
+        start = (Button) findViewById(R.id.notyet);
+        done = (Button) findViewById(R.id.done);
+        capture=(ImageButton)findViewById(R.id.capture);
+        shot=(ImageView)findViewById(R.id.shot);
+
+
+        requestMultiplePermissions();
+
+        start.setOnTouchListener(new View.OnTouchListener() {
+
+            @Override
+            public boolean onTouch(View v, MotionEvent event) {
+                // TODO Auto-generated method stub
+                if (event.getAction() == KeyEvent.ACTION_DOWN) {
+                    start.setBackgroundColor(Color.RED);
+
+                } else if (event.getAction() == KeyEvent.ACTION_UP) {
+                    wait.setTextColor(Color.BLACK);
+                    wait.setBackground(getResources().getDrawable(R.drawable.yellow));
+                    done.setTextColor(Color.BLACK);
+                    done.setBackground(getResources().getDrawable(R.drawable.green));
+                }
+                return false;
+            }
+        });
+
+        //Change the button background color from black to red on touch and  red to black on release
+
+        wait.setOnTouchListener(new View.OnTouchListener() {
+
+            @Override
+            public boolean onTouch(View v, MotionEvent event) {
+                // TODO Auto-generated method stub
+                if (event.getAction() == KeyEvent.ACTION_DOWN) {
+                    wait.setBackgroundColor(Color.YELLOW);
+
+                } else if (event.getAction() == KeyEvent.ACTION_UP) {
+                    start.setTextColor(Color.BLACK);
+                    start.setBackground(getResources().getDrawable(R.drawable.red));
+                    done.setTextColor(Color.BLACK);
+                    done.setBackground(getResources().getDrawable(R.drawable.green));
+                }
+                return false;
+            }
+        });
+
+
+        done.setOnTouchListener(new View.OnTouchListener() {
+
+            @Override
+            public boolean onTouch(View v, MotionEvent event) {
+                // TODO Auto-generated method stub
+                if (event.getAction() == KeyEvent.ACTION_DOWN) {
+                    done.setBackgroundColor(Color.GREEN);
+
+                } else if (event.getAction() == KeyEvent.ACTION_UP) {
+                    start.setTextColor(Color.BLACK);
+                    start.setBackground(getResources().getDrawable(R.drawable.red));
+                    wait.setTextColor(Color.BLACK);
+                    wait.setBackground(getResources().getDrawable(R.drawable.yellow));
+                }
+                return false;
+            }
+        });
+
+        capture.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+          showPictureDialog();
+            }
+        });
+
+
+    }
+
+
+    private void showPictureDialog() {
+        AlertDialog.Builder pictureDialog = new AlertDialog.Builder(this);
+        pictureDialog.setTitle("Select Action");
+        String[] pictureDialogItems = {"Select photo from gallery", "Capture photo from camera"};
+        pictureDialog.setItems(pictureDialogItems,
+                new DialogInterface.OnClickListener() {
+                    @Override
+                    public void onClick(DialogInterface dialog, int which) {
+                        switch (which) {
+                            case 0:
+                                choosePhotoFromGallary();
+                                break;
+                            case 1:
+                                takePhotoFromCamera();
+                                break;
+                        }
+                    }
+                });
+        pictureDialog.show();
+    }
+
+    public void choosePhotoFromGallary() {
+        Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
+        startActivityForResult(galleryIntent, GALLERY);
+    }
+
+    private void takePhotoFromCamera() {
+        Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
+        startActivityForResult(intent, CAMERA);
+    }
+
+    @Override
+    public void onActivityResult(int requestCode, int resultCode, Intent data) {
+
+        super.onActivityResult(requestCode, resultCode, data);
+        if (resultCode == this.RESULT_CANCELED) {
+            return;
+        }
+        if (requestCode == GALLERY) {
+            if (data != null) {
+                Uri contentURI = data.getData();
+                try {
+                    Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), contentURI);
+                    String path = saveImage(bitmap);
+                    Toast.makeText(getApplicationContext(), "Image Saved!", Toast.LENGTH_SHORT).show();
+                    shot.setImageBitmap(bitmap);
+
+                } catch (IOException e) {
+                    e.printStackTrace();
+                    Toast.makeText(getApplicationContext(), "Failed!", Toast.LENGTH_SHORT).show();
+                }
+            }
+
+        } else if (requestCode == CAMERA) {
+            Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
+            shot.setImageBitmap(thumbnail);
+            saveImage(thumbnail);
+            Toast.makeText(getApplicationContext(), "Image Saved!", Toast.LENGTH_SHORT).show();
+        }
+    }
+
+    public String saveImage(Bitmap myBitmap) {
+        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+        myBitmap.compress(Bitmap.CompressFormat.JPEG, 90, bytes);
+        File wallpaperDirectory = new File(Environment.getExternalStorageDirectory() + IMAGE_DIRECTORY);
+        if (!wallpaperDirectory.exists()) {  // have the object build the directory structure, if needed.
+            wallpaperDirectory.mkdirs();
+        }
+
+        try {
+            File f = new File(wallpaperDirectory, Calendar.getInstance().getTimeInMillis() + ".jpg");
+            f.createNewFile();
+            FileOutputStream fo = new FileOutputStream(f);
+            fo.write(bytes.toByteArray());
+            MediaScannerConnection.scanFile(this,
+                    new String[]{f.getPath()},
+                    new String[]{"image/jpeg"}, null);
+            fo.close();
+            Log.d("TAG", "File Saved::---&gt;" + f.getAbsolutePath());
+
+            return f.getAbsolutePath();
+        } catch (IOException e1) {
+            e1.printStackTrace();
+        }
+        return "";
+    }
+
+    private void requestMultiplePermissions() {
+        Dexter.withActivity(this)
+                .withPermissions(
+                        Manifest.permission.CAMERA,
+                        Manifest.permission.WRITE_EXTERNAL_STORAGE,
+                        Manifest.permission.READ_EXTERNAL_STORAGE)
+                .withListener(new MultiplePermissionsListener() {
+                    @Override
+                    public void onPermissionsChecked(MultiplePermissionsReport report) {
+                        if (report.areAllPermissionsGranted()) {  // check if all permissions are granted
+                            Toast.makeText(getApplicationContext(), "All permissions are granted by user!", Toast.LENGTH_SHORT).show();
+                        }
+
+                        if (report.isAnyPermissionPermanentlyDenied()) { // check for permanent denial of any permission
+                            // show alert dialog navigating to Settings
+                            //openSettingsDialog();
+                        }
+                    }
+
+                    @Override
+                    public void onPermissionRationaleShouldBeShown(List<com.karumi.dexter.listener.PermissionRequest> permissions, PermissionToken token) {
+
+                    }
+
+//                    @Override
+//                    public void onPermissionRationaleShouldBeShown(List<PermissionRequest> permissions, PermissionToken token) {
+//                        token.continuePermissionRequest();
+//                    }
+                }).
+                withErrorListener(new PermissionRequestErrorListener() {
+                    @Override
+                    public void onError(DexterError error) {
+                        Toast.makeText(getApplicationContext(), "Some Error! ", Toast.LENGTH_SHORT).show();
+                    }
+                })
+                .onSameThread()
+                .check();
+    }
+
+
+}

+ 0 - 9
app/src/main/res/drawable/circle.xml

@@ -1,9 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<shape
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    android:shape="oval">
-    <stroke
-        android:width="3dp"
-        android:color="@android:color/white"/>
-    <solid android:color="@color/colorAccent"/>
-</shape>

+ 12 - 0
app/src/main/res/drawable/green.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+    <item>
+        <shape android:shape="rectangle">
+            <!--apply button background transparent, full opacity-->
+            <solid android:color="#00ffffff"/>
+            <!--make button border solid color, nontransparent-->
+            <stroke android:color="#259b24" android:width="2dp"/>
+            <corners android:radius="2dp"/>
+        </shape>
+    </item>
+</selector>

+ 12 - 0
app/src/main/res/drawable/red.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+    <item>
+        <shape android:shape="rectangle">
+            <!--apply button background transparent, full opacity-->
+            <solid android:color="#00ffffff"/>
+            <!--make button border solid color, nontransparent-->
+            <stroke android:color="#f44336" android:width="2dp"/>
+            <corners android:radius="2dp"/>
+        </shape>
+    </item>
+</selector>

+ 12 - 0
app/src/main/res/drawable/yellow.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+    <item>
+        <shape android:shape="rectangle">
+            <!--apply button background transparent, full opacity-->
+            <solid android:color="#00ffffff"/>
+            <!--make button border solid color, nontransparent-->
+            <stroke android:color="#ffeb3b" android:width="2dp"/>
+            <corners android:radius="2dp"/>
+        </shape>
+    </item>
+</selector>

+ 113 - 0
app/src/main/res/layout/activity_progress.xml

@@ -0,0 +1,113 @@
+<?xml version="1.0" encoding="utf-8"?>
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:background="@drawable/background"
+    android:layout_height="match_parent">
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:background="@drawable/shapewhite"
+    android:layout_gravity="center_vertical"
+    android:layout_marginLeft="@dimen/_20sdp"
+    android:layout_marginRight="@dimen/_20sdp"
+    android:orientation="vertical"
+    tools:context=".activities.ProgressActivity">
+
+    <TextView
+        android:id="@+id/section_label1"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="10sp"
+        android:layout_alignParentLeft="true"
+        android:textColor="#000000"
+        android:text="Project Status"
+        android:textAllCaps="true"
+        android:textSize="@dimen/_20sdp" />
+
+    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+        android:layout_width="fill_parent"
+        android:layout_height="@dimen/_40sdp"
+        android:weightSum="3"
+        android:layout_marginTop="@dimen/_10sdp"
+        android:orientation="horizontal">
+
+        <Button
+            android:id="@+id/notyet"
+            android:layout_width="0dp"
+            android:layout_height="@dimen/_35sdp"
+            android:layout_weight="1"
+            android:textAlignment="center"
+            android:background="@drawable/red"
+            android:text="Not-Started" />
+
+        <Button
+            android:id="@+id/waiting"
+            android:layout_width="0dp"
+            android:layout_height="@dimen/_35sdp"
+            android:layout_weight="1"
+            android:textAlignment="center"
+            android:background="@drawable/yellow"
+            android:text="Pending" />
+
+        <Button
+            android:id="@+id/done"
+            android:layout_width="0dp"
+            android:layout_height="@dimen/_35sdp"
+            android:layout_weight="1"
+            android:textAlignment="center"
+            android:background="@drawable/green"
+            android:text="Done" />
+    </LinearLayout>
+
+    <TextView
+        android:id="@+id/take"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="10sp"
+        android:layout_alignParentLeft="true"
+        android:text="Tab to Capture"
+        android:textSize="@dimen/_15sdp" />
+
+    <RelativeLayout
+        android:layout_weight="0.5"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent">
+
+        <ImageView
+            android:id="@+id/shot"
+            android:layout_width="match_parent"
+            android:layout_height="@dimen/_135sdp"
+            android:layout_alignParentTop="true"
+            android:layout_gravity="center_horizontal"
+            android:layout_toEndOf="@+id/capture" />
+
+    <ImageButton
+        android:id="@+id/capture"
+        android:layout_width="@dimen/_50sdp"
+        android:layout_height="@dimen/_50sdp"
+        android:background="@drawable/shapewhite"
+        android:layout_marginTop="@dimen/_10sdp"
+        android:layout_gravity="center_horizontal"
+        android:layout_marginBottom="@dimen/_10sdp"
+        android:src="@drawable/camera" />
+
+    </RelativeLayout>
+
+    <Button
+        android:id="@+id/btncontinue"
+        android:background="@drawable/button_background"
+        android:textColor="@color/primaryTextColor"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="center_horizontal"
+        android:layout_marginTop="@dimen/_12sdp"
+        android:layout_marginBottom="@dimen/_10sdp"
+        android:text="@string/cont" />
+
+
+</LinearLayout>
+</ScrollView>

+ 0 - 0
app/src/main/res/values/colors.xml


Some files were not shown because too many files changed in this diff