Minggu, 19 Mei 2019

Detail galeri



galeridetail.xml

<?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"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:background="#fff"  >

    <LinearLayout        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:orientation="vertical"        android:padding="6dip" >
        <TextView            android:id="@+id/txtMarquee"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text=""            android:textSize="14sp"            android:typeface="sans"            android:textColor="#ffffff"            android:background="#000000"            android:singleLine="true"            android:ellipsize="marquee"            android:marqueeRepeatLimit="marquee_forever">
        </TextView>

        <ImageView            android:id="@+id/myGambar"            android:gravity="center"            android:layout_width="match_parent"            android:layout_height="match_parent"            android:layout_centerHorizontal="true"            android:layout_centerVertical="true"            android:src="@drawable/gallery" />
             />

        <ZoomControls            android:layout_marginTop="10dip"            android:id="@+id/simpleZoomControl"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:background="#000" />


        <TextView            android:id="@+id/title"            android:layout_width="fill_parent"            android:layout_marginTop="6dip"            android:layout_height="wrap_content"            android:text="Judul"            android:textColor="#000000"            android:textSize="20sp"            android:textStyle="bold" />

        <TextView            android:id="@+id/title2"            android:layout_width="fill_parent"            android:layout_marginTop="6dip"            android:layout_height="wrap_content"            android:text="Keterangan"            android:textColor="#000000"            android:textSize="20sp" />

        <TextView            android:id="@+id/title3"            android:layout_width="fill_parent"            android:layout_marginTop="6dip"            android:layout_height="wrap_content"            android:text="Tgl"            android:textColor="#000000"            android:textSize="20sp" />

        <TextView            android:id="@+id/title4"            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:layout_marginTop="6dip"            android:text="Pengriim"            android:textColor="#000000"            android:textSize="20sp"/>

        <TableRow            android:id="@+id/TableRow02"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_gravity="center">

            <Button                android:id="@+id/btnShare"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="Share"                android:textColor="#000000"                android:textStyle="bold" />

            <Button                android:id="@+id/btnsave"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="Download"                android:textColor="#000000"                android:textStyle="bold" />

        </TableRow>
        <TextView
        android:layout_width="fill_parent"        android:layout_marginTop="6dip"        android:layout_height="wrap_content"        android:text=""        android:textColor="#000000"        android:textSize="20sp"        android:textStyle="bold" />
    </LinearLayout>

</ScrollView>


package com.kriptograph.mygaleri;

import android.Manifest;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.text.Html;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ZoomControls;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.Calendar;

public class DetailGaleri extends AppCompatActivity {
    JSONParser jsonParser = new JSONParser();

    String tkode="",tnama="",tmail="",thp="",tlati="",tlongi="",talamat="",tangkatan="",tstatus="",tgambar="",waktu="";
    String skodelogin="",snamalogin="",smaillogin="";
    String myLati="-6.352953";
    String myLongi="106.831389";
    String myPosisi="UI";
    ZoomControls simpleZoomControls;
    ImageView myGambar;

String ip="";
    private ProgressDialog pDialog;
    JSONParser jParser = new JSONParser();
    String title,title2, title3, title4, gambar;

    String currentImage = "";

    private static final int MY_PERMISSION_REQUEST = 1;

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.galeridetail);
        myGambar=(ImageView) findViewById(R.id.myGambar);

        simpleZoomControls = (ZoomControls) findViewById(R.id.simpleZoomControl);
        simpleZoomControls.setOnZoomInClickListener(new View.OnClickListener() {
            @Override            public void onClick(View v) {
                float x=simpleZoomControls.getScaleX();
                float y=simpleZoomControls.getScaleY();
                myGambar.setScaleX((float) (x+1));
                myGambar.setScaleY((float) (y+1));
            }
        });

        simpleZoomControls.setOnZoomOutClickListener(new View.OnClickListener() {
            @Override            public void onClick(View v) {
                float x=simpleZoomControls.getScaleX();
                float y=simpleZoomControls.getScaleY();
                myGambar.setScaleX((float) (x-1));
                myGambar.setScaleY((float) (y-1));
            }
        });

        //meminta izin penyimpanan        if (ContextCompat.checkSelfPermission(DetailGaleri.this,
                Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            if (ActivityCompat.shouldShowRequestPermissionRationale(DetailGaleri.this,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                ActivityCompat.requestPermissions(DetailGaleri.this,
                        new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, MY_PERMISSION_REQUEST);
            } else {
                ActivityCompat.requestPermissions(DetailGaleri.this,
                        new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, MY_PERMISSION_REQUEST);
            }
        } else {
            //DO NOTHING        }

        ip=jParser.getIP();

         title = getIntent().getStringExtra("title");
      
        //int gb= getIntent().getIntExtra("gambar",R.drawable.ic_produk);        //Bitmap bitmap = getIntent().getParcelableExtra("image");
        String arUrlFoto=ip+"ypathfile/"+gambar;
        new DownloadImageTask(myGambar).execute(arUrlFoto);


        Button    btnShare=(Button)findViewById(R.id.btnShare);
        btnShare.setOnClickListener(new View.OnClickListener() {
            public void onClick(View arg0) {
                Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                sharingIntent.setType("text/plain");
                sharingIntent.putExtra(Intent.EXTRA_TEXT, "Judul :"+title+"\n\nKet :"+title3+"\n\nWaktu :"+waktu+"\n\nPengirim :"+title4);
                sharingIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
                startActivity(Intent.createChooser(sharingIntent, "Share using"));

            }});


        Button    btnsave=(Button)findViewById(R.id.btnsave);btnsave.setText("Download");
        btnsave.setVisibility(View.VISIBLE);
        btnsave.setOnClickListener(new View.OnClickListener() {
            public void onClick(View arg0) {
                savepicture();
            }});
        callMarquee();
    }




    private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
        ImageView bmImage;

        public DownloadImageTask(ImageView bmImage) {
            this.bmImage = bmImage;
        }

        protected Bitmap doInBackground(String... urls) {
            String urldisplay = urls[0];
            Bitmap mIcon11 = null;
            try {
                InputStream in = new java.net.URL(urldisplay).openStream();
                mIcon11 = BitmapFactory.decodeStream(in);
            }
            catch (Exception e) {
                Log.e("Error", e.getMessage());e.printStackTrace();}
            return mIcon11;
        }

        protected void onPostExecute(Bitmap result) {bmImage.setImageBitmap(result); }
    }


    void callMarquee(){
        Calendar cal = Calendar.getInstance();
        int jam = cal.get(Calendar.HOUR);
        int menit= cal.get(Calendar.MINUTE);
        int detik= cal.get(Calendar.SECOND);

        int tgl= cal.get(Calendar.DATE);
        int bln= cal.get(Calendar.MONTH)+1;
        int thn= cal.get(Calendar.YEAR);

        String stgl= String.valueOf(tgl)+"-"+ String.valueOf(bln)+"-"+ String.valueOf(thn);
        String sjam= String.valueOf(jam)+":"+ String.valueOf(menit)+":"+ String.valueOf(detik);

        TextView txtMarquee=(TextView)findViewById(R.id.txtMarquee);
        txtMarquee.setSelected(true);
        String kata=jsonParser.getNama()+stgl+"/"+sjam+" #";
        String kalimat= String.format("%1$s", TextUtils.htmlEncode(kata));
        txtMarquee.setText(Html.fromHtml(kalimat+kalimat+kalimat));
    }

    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            finish();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
    public void savepicture() {
        AlertDialog.Builder ad = new AlertDialog.Builder(DetailGaleri.this);
        ad.setTitle("Save Picture");
        ad.setMessage(title+" \n"+title3+"\n"+title4);

        ad.setPositiveButton("Save", new DialogInterface.OnClickListener() {
            @Override            public void onClick(DialogInterface dialog, int which) {

                View content = findViewById(R.id.myGambar);
                Bitmap bitmap = getScreenShot(content);
//                currentImage = "image" + System.currentTimeMillis() + ".jpg";                currentImage = title+" \n"+title3+"\n"+title4+".jpg";
                store(bitmap, currentImage);
//                b_share.setEnabled(true);               // finish();            }
        });
        ad.setNegativeButton("Cancle", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface arg0, int arg1) {
            }
        });
        ad.show();
    }

    private static Bitmap getScreenShot(View view) {
        view.setDrawingCacheEnabled(true);
        Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache());
        view.setDrawingCacheEnabled(false);
        return bitmap;
    }

    private void store(Bitmap bm, String fileName) {
        String dirPath = Environment.getExternalStorageDirectory().getAbsolutePath()+"/FILEPROJEK";
        File dir = new File(dirPath);
        if (!dir.exists()) {
            dir.mkdirs();
        }
        File file = new File(dirPath, fileName);
        try {
            FileOutputStream fos = new FileOutputStream(file);
            bm.compress(Bitmap.CompressFormat.JPEG, 100, fos);
            fos.flush();
            fos.close();
            Toast.makeText(this, "Saved to "+dirPath +"..!", Toast.LENGTH_SHORT).show();
        } catch (Exception e) {
            e.printStackTrace();

        }
    }



    public boolean onCreateOptionsMenu(Menu menu) {
        menu.add(0, 1, 0, "Profile");
        menu.add(0, 2, 0, "Call");
        menu.add(0, 3, 0, "Mail");
        menu.add(0, 4, 0, "Message");
        menu.add(0, 5, 0, "Location");
        menu.add(0, 6, 0, "Direction");
        menu.add(0, 7, 0, "Activity");
        menu.add(0, 8, 0, "Back");
        return true;
    }

    final Context c = this;
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case 1:
                Intent i1 = new Intent(getApplicationContext(), Galeri.class);
                i1.putExtra("pk",tkode);
                startActivityForResult(i1, 100);
                return true;
            case 2:
                String toDial="tel:"+thp;
                startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse(toDial)));
                return true;
            case 3:
                //Mail                LayoutInflater layoutInflaterAndroid = LayoutInflater.from(c);
                View mView = layoutInflaterAndroid.inflate(R.layout.user_input_dialog_box, null);
                AlertDialog.Builder alertDialogBuilderUserInput = new AlertDialog.Builder(c);
                alertDialogBuilderUserInput.setView(mView);

                final EditText userInputDialogEditText = (EditText) mView.findViewById(R.id.userInputDialog);
                alertDialogBuilderUserInput
                        .setCancelable(false)
                        .setPositiveButton("Send", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialogBox, int id) {

                                //========================
                                String pesan=userInputDialogEditText.getText().toString();
                                if(pesan.length()>0) {
                                    String to = tmail;
                                    String subject = "Kirim Pesan Via APP-M8 ";
                                    String message = pesan + "\nTertanda:" + snamalogin + " /" + skodelogin + " (" + smaillogin + ")";

                                    Intent email = new Intent(Intent.ACTION_SEND);
                                    email.putExtra(Intent.EXTRA_EMAIL, new String[]{to});
                                    //email.putExtra(Intent.EXTRA_CC, new String[]{ to});                                    //email.putExtra(Intent.EXTRA_BCC, new String[]{to});                                    email.putExtra(Intent.EXTRA_SUBJECT, subject);
                                    email.putExtra(Intent.EXTRA_TEXT, message);

                                    //need this to prompts email client only                                    email.setType("message/rfc822");

                                    startActivity(Intent.createChooser(email, "Fr:" + smaillogin));
                                    new AlertDialog.Builder(DetailGaleri.this)
                                            .setTitle("Mail to "+tnama)
                                            .setMessage("Sukses Kirim mail ke "+tmail+" /"+tnama+" ("+tkode+")")
                                            .setNeutralButton("OK", new DialogInterface.OnClickListener() {
                                                public void onClick(DialogInterface dlg, int sumthin) {
                                                    finish();
                                                }}).show();
                                }
                                else{
                                    LayoutInflater inflater = getLayoutInflater();
                                    View layout = inflater.inflate(R.layout.custom_toast,(ViewGroup) findViewById(R.id.custom_toast_layout_id));
                                    ImageView image = (ImageView) layout.findViewById(R.id.image);
                                    image.setImageResource(R.drawable.logochat);
                                    TextView text = (TextView) layout.findViewById(R.id.text);
                                    text.setText("Silakan isi pesan Mail Anda");

                                    Toast toast = new Toast(getApplicationContext());
                                    toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
                                    toast.setDuration(Toast.LENGTH_LONG);
                                    toast.setView(layout);
                                    toast.show();
                                }
                                //========================                            }
                        })

                        .setNegativeButton("Cancel",
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialogBox, int id) {
                                        dialogBox.cancel();
                                    }
                                });

                AlertDialog alertDialogAndroid = alertDialogBuilderUserInput.create();
                alertDialogAndroid.show();


                return true;
            case 4:
                //Inbox message                Intent i2 = new Intent(getApplicationContext(), Galeri.class);
                i2.putExtra("tkode",tkode);
                i2.putExtra("tnama",tnama);
                startActivityForResult(i2, 100);
                return true;
            case 5:
                //Location                Intent i3 = new Intent(getApplicationContext(), Galeri.class);
                i3.putExtra("tkode",tkode);
                i3.putExtra("tnama",tnama);
                i3.putExtra("myLati",myLati);
                i3.putExtra("myLongi",myLongi);
                i3.putExtra("myPosisi",myPosisi);
                i3.putExtra("myLati2",tlati);
                i3.putExtra("myLongi2",tlongi);
                i3.putExtra("myPosisi2",talamat);

                startActivityForResult(i3, 100);
                return true;
            case 6:
                //direction                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://maps.google.com/maps?saddr="+myLati+","+myLongi+"&daddr="+tlati+","+tlongi));
                startActivity(intent);
                return true;
            case 7:
                //activity                Intent i4 = new Intent(getApplicationContext(), Galeri.class);
                i4.putExtra("tkode",tkode);
                i4.putExtra("tnama",tnama);
                i4.putExtra("tangkatan",tangkatan);
                i4.putExtra("tstatus",tstatus);
                i4.putExtra("tgambar",tgambar);
                startActivityForResult(i4, 100);
                return true;
            case 8:
                //back                finish();
                return true;

        }
        return false;
    }
}


user_input_dialog_box.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@+id/custom_dialog_layout_design_user_input"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    android:padding="16dp">

    <TextView        android:id="@+id/dialogTitle"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="Send Mail"        android:textAppearance="?android:attr/textAppearanceLarge" />

    <EditText        android:id="@+id/userInputDialog"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:hint="Pesan Mail"        android:inputType="text" />
</LinearLayout>



custom_toast.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@+id/custom_toast_layout_id"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:background="#FFF"    android:orientation="horizontal"    android:padding="5dp" >

    <ImageView        android:id="@+id/image"        android:layout_width="wrap_content"        android:layout_height="fill_parent"        android:layout_marginRight="5dp" />

    <TextView        android:id="@+id/text"        android:layout_width="wrap_content"        android:layout_height="fill_parent"        android:textColor="#000" />

</LinearLayout>



Tidak ada komentar:

Posting Komentar