Minggu, 11 Oktober 2020

JSON XML LINK EXAMPLE

 https://www.vice.com/id_id/sitemap/articles?page=1

https://www.vice.com/id_id/sitemap/

https://www.vice.com/id_id/read

Android Code Dijkstra

 package com.example.parmalteng;


import android.app.Activity;

import android.app.ProgressDialog;

import android.content.Intent;

import android.graphics.Bitmap;

import android.graphics.BitmapFactory;

import android.net.Uri;

import android.os.AsyncTask;

import android.os.Bundle;

import android.text.Html;

import android.text.TextUtils;

import android.util.Log;

import android.view.KeyEvent;

import android.view.View;

import android.widget.Button;

import android.widget.ImageView;

import android.widget.TextView;


import org.apache.http.NameValuePair;

import org.apache.http.message.BasicNameValuePair;

import org.json.JSONArray;

import org.json.JSONException;

import org.json.JSONObject;


import java.io.InputStream;

import java.util.ArrayList;

import java.util.Calendar;

import java.util.List;


public class Dijkstra extends Activity {



int jb=5;

String[]arB;

String kodenode1A,namanode1A,kodenode1B,namanode1B;

double jarak1A,jarak1B;


int jd=28;

String[]arKode;

double[]arLati;

double[]arLongi;

double[]arJarakA;

double[]arJarakB;

String[]arNama;




String ip="";

String id_wisata0="";


TextView txtnama_wisata;

TextView txtalamat,txtalamat2;

TextView txtkategori;

TextView txtdeskripsi;

TextView txtketerangan;


String gambar,gabKoor="";

String latitude;

String longitude;


Button btnDjikstra;


private ProgressDialog pDialog;

JSONParser jsonParser = new JSONParser();


private static final String TAG_SUKSES = "sukses";

private static final String TAG_record = "record";


private static final String TAG_nama_wisata = "nama_wisata";

private static final String TAG_alamat = "alamat";

private static final String TAG_kategori = "kategori";

private static final String TAG_latitude = "latitude";

private static final String TAG_longitude = "longitude";

private static final String TAG_deskripsi = "deskripsi";

private static final String TAG_gambar = "gambar";

private static final String TAG_keterangan = "keterangan";


String myLati = "";//-3.705235

String myLongi = "";//128.088799

String myPosisi = "";//Bandar Udara Internasional Pattimura


String myLati2 = "";//-3.705235

String myLongi2 = "";//128.088799

String myPosisi2 = "";//Bandar Udara Internasional Pattimura


String NW="", KATW="";

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.dijkstra);


ip=jsonParser.getIP();

// callMarquee();



txtnama_wisata= (TextView) findViewById(R.id.txtnama_wisata);

txtkategori= (TextView) findViewById(R.id.txtkategori);

txtalamat= (TextView) findViewById(R.id.txtalamat);

txtalamat2= (TextView) findViewById(R.id.txtalamat2);

txtdeskripsi= (TextView) findViewById(R.id.txtdeskripsi);

txtketerangan= (TextView) findViewById(R.id.txtketerangan);



btnDjikstra = (Button) findViewById(R.id.btnDjikstra);



Intent i = getIntent();

id_wisata0 = i.getStringExtra("pk");


myLati = i.getStringExtra("myLati");

myLongi= i.getStringExtra("myLongi");

myPosisi = i.getStringExtra("myPosisi");


myLati2 = i.getStringExtra("myLati2");

myLongi2= i.getStringExtra("myLongi2");

myPosisi2 = i.getStringExtra("myPosisi2");



NW = i.getStringExtra("NW");

KATW= i.getStringExtra("KATW");

gambar = i.getStringExtra("gambar");



txtnama_wisata.setText(NW+" ("+id_wisata0+")");

txtkategori.setText(KATW);




btnDjikstra.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View arg0) {

cetak(gabKoor);

    Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(gabKoor));

//intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");

startActivity(intent);


}});




String arUrlFoto=ip+"ypathfile/"+gambar;

new DownloadImageTask((ImageView) findViewById(R.id.myGambar)).execute(arUrlFoto);

callMarquee();



start();

}

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="Selamat Datang Aplikasi Android Wisata Maluku Tengah "+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);

}


void start(){

init();

double mlati=Double.parseDouble(myLati);

double mlongi=Double.parseDouble(myLongi);


double mlati2=Double.parseDouble(myLati2);

double mlongi2=Double.parseDouble(myLongi2);



double jmaxA=1000000000;

int indexA=0;

for(int i=0;i<jd;i++){

double r=0;

try{

r=getJarak(mlati,mlongi,arLati[i],arLongi[i]);

arJarakA[i]=r;

if(r<jmaxA){

jmaxA=r;

indexA=i;

}

}

catch(Exception ee){}

}


double jmaxB=1000000000;

int indexB=0;

for(int i=0;i<jd;i++){

double r=0;

try{

r=getJarak(mlati2,mlongi2,arLati[i],arLongi[i]);

arJarakB[i]=r;

if(r<jmaxB){

jmaxB=r;

indexB=i;

}

}

catch(Exception ee){}

}



kodenode1A=arKode[indexA];

jarak1A=arJarakA[indexA];

namanode1A=arNama[indexA];


kodenode1B=arKode[indexB];

jarak1B=arJarakB[indexB];

namanode1B=arNama[indexB];


cetak("LOKASI:"+kodenode1A+"-"+kodenode1B);

//==========================

//mulai("A","b");

mulai(kodenode1A,kodenode1B);


}


void mulai(String src,String dst) {


Graph a=new Graph();

a.ins_simpul('A');   ////0

a.ins_simpul('B');   ////1

a.ins_simpul('C');   ////2

a.ins_simpul('D');   ////3

a.ins_simpul('E');   ////4

a.ins_simpul('F');   ////5

a.ins_simpul('G');   ////6

a.ins_simpul('H');   ////7

a.ins_simpul('I');   ////8

a.ins_simpul('J');   ////9

a.ins_simpul('K');   ////10

a.ins_simpul('L');   ////11

a.ins_simpul('M');   ////12

a.ins_simpul('N');   ////13

a.ins_simpul('O');   ////14

a.ins_simpul('P');   ////15

a.ins_simpul('Q');   ////16

a.ins_simpul('R');   ////17

a.ins_simpul('S');   ////18

a.ins_simpul('T');   ////19

a.ins_simpul('U');   ////20

a.ins_simpul('V');   ////21

a.ins_simpul('W');   ////22

a.ins_simpul('X');   ////23

a.ins_simpul('Y');   ////24

a.ins_simpul('Z');   ////25

a.ins_simpul('a');   ////26

a.ins_simpul('b');   ////27


a.ins_adjacent(0, 1, 3338);//AB

a.ins_adjacent(0, 2, 7544);//AC


a.ins_adjacent(1, 0, 3338);//BA

a.ins_adjacent(1, 7, 9897);//BH

a.ins_adjacent(1, 8, 9926);//BI


a.ins_adjacent(2, 0, 12892);//CA

a.ins_adjacent(2, 3, 10166);//CD


a.ins_adjacent(3, 2, 5893);//DC

a.ins_adjacent(3, 4, 10501);//DE


a.ins_adjacent(4, 3, 10501);//ED

a.ins_adjacent(4, 5, 21118);//EF


a.ins_adjacent(5, 4, 21118);//FE

a.ins_adjacent(5, 6, 9949);//FG


a.ins_adjacent(6, 5, 9949);//GF

a.ins_adjacent(6, 10, 6627);//GK

a.ins_adjacent(6, 26, 18860);//Gb


a.ins_adjacent(7, 1, 9897);//HB

a.ins_adjacent(7, 8, 885);//HI

a.ins_adjacent(7, 10, 2899);//HK


a.ins_adjacent(8, 1, 9926);//IB

a.ins_adjacent(8, 7, 885);//IH

a.ins_adjacent(8, 9, 1873);//IJ


a.ins_adjacent(9, 8, 1873);//JI

a.ins_adjacent(9, 13, 7361);//JN


a.ins_adjacent(10, 6, 6627);//KG

a.ins_adjacent(10, 7, 2289);//KH

a.ins_adjacent(10, 11, 3107);//KL


a.ins_adjacent(11, 10, 3107);//LK

a.ins_adjacent(11, 12, 1207);//LM


a.ins_adjacent(12, 11, 1207);//ML

a.ins_adjacent(12, 13, 1003);//MN

a.ins_adjacent(12, 15, 1110);//MP


a.ins_adjacent(13, 9, 7361);//NJ

a.ins_adjacent(13, 12, 1003);//NM

a.ins_adjacent(13, 14, 417);//NO


a.ins_adjacent(14, 13, 417);//ON

a.ins_adjacent(14, 15, 1185);//OP


a.ins_adjacent(15, 12, 1110);//PM

a.ins_adjacent(15, 14, 1185);//PO

a.ins_adjacent(15, 16, 3850);//PQ


a.ins_adjacent(16, 15, 3850);//QP

a.ins_adjacent(16, 17, 7146);//QR

a.ins_adjacent(16, 18, 5392);//QS


a.ins_adjacent(17, 16, 7146);//RQ

a.ins_adjacent(17, 18, 3166);//RS


a.ins_adjacent(18, 16, 5392);//SQ

a.ins_adjacent(18, 17, 3166);//SR

a.ins_adjacent(18, 19, 1608);//ST

a.ins_adjacent(18, 20, 1227);//SU


a.ins_adjacent(19, 18, 1608);//TS


a.ins_adjacent(20, 18, 1227);//US

a.ins_adjacent(20, 21, 1802);//UV

a.ins_adjacent(20, 23, 1375);//UX


a.ins_adjacent(21, 20, 1802);//VU

a.ins_adjacent(21, 22, 1016);//VW

a.ins_adjacent(21, 24, 947);//VY


a.ins_adjacent(22, 21, 1016);//WV


a.ins_adjacent(23, 20, 1376);//XU

a.ins_adjacent(23, 24, 1110);//XY


a.ins_adjacent(23, 21, 947);//YV

a.ins_adjacent(24, 23, 1110);//YX

a.ins_adjacent(24, 25, 4876);//YZ


a.ins_adjacent(25, 24, 4876);//ZY

a.ins_adjacent(25, 26, 1105);//Za

a.ins_adjacent(25, 27, 1799);//Zb


a.ins_adjacent(26, 25, 1105);//aZ

a.ins_adjacent(26, 27, 1995);//ab


a.ins_adjacent(27, 6, 18860);//bG

a.ins_adjacent(27, 25, 1799);//bZ

a.ins_adjacent(27, 26, 1995);//ba


String []HSL= a.Dijkstra();

System.out.println("++++++++++++++++++++++++++++++++++");

//System.out.println("HS="+HSL);


int total=0;

String gab1="Posisi Awal:"+myPosisi+" ("+myLati+","+myLongi+") =>Dekat "+namanode1A+"#"+kodenode1A+" :"+String.valueOf(jarak1A)+" m";

String gab2="Posisi Ahir:"+myPosisi2+" ("+myLati2+","+myLongi2+") =>Dekat "+namanode1B+"#"+kodenode1B+" :"+String.valueOf(jarak1B)+" m";


txtdeskripsi.setText(myPosisi+" ("+myLati+","+myLongi+") =>Dekat "+namanode1A+"#"+kodenode1A+" :"+String.valueOf(jarak1A)+" m");

txtketerangan.setText(myPosisi2+" ("+myLati2+","+myLongi2+") =>Dekat "+namanode1B+"#"+kodenode1B+" :"+String.valueOf(jarak1B)+" m");




String mrute="";



for(int k=1;k<HSL.length;k++){

if(HSL[k].length()>3){

String mHasil="A#"+HSL[k];

int AW=mHasil.indexOf(src);

int AH=mHasil.indexOf(dst);

if(AW>=0 && AH>=0){//ADA

if(AW<=AH){//MAJU

mrute=mHasil;

cetak("FF="+mrute);

}

else{//REVERSE

mrute=mHasil+"#";

String reverse="";

for (int i = mrute.length() - 1 ; i >= 0 ; i--){

reverse = reverse + mrute.charAt(i);

}

mrute =reverse;

mrute=mrute.substring(1,mrute.length());

cetak("REV="+mrute);

}


}//ada >=0

//=========================

}

}//k

if(mrute.length()<3){

for(int b=0;b<jb;b++){

String lrute=arB[b];

int AW=lrute.indexOf(src);

int AH=lrute.indexOf(dst);

if(AW>=0 && AH>=0){//ADA

if(AW<=AH){//MAJU

mrute=lrute;

cetak("F2="+mrute);

}

else{//REVERSE


mrute=lrute;

String reverse="";

for (int i = lrute.length() - 1 ; i >= 0 ; i--){

reverse = reverse + lrute.charAt(i);

}

mrute =reverse;

cetak("REV2="+mrute);

}

}

else{

cetak("NONE");

}

}//jb

}//for

double totalJarak=0;

if(mrute.length()>0){

double LAT1=0,LON1=0;

double LAT2=0,LON2=0;



LAT1=Double.parseDouble(myLati);

LON1=Double.parseDouble(myLongi);

LAT2=Double.parseDouble(myLati2);

LON2=Double.parseDouble(myLongi2);

double jarak=0;

String gabKota=myPosisi+"-";

String gabKode="GPS-";

gabKoor="https://www.google.co.id/maps/dir/"+LAT1+","+LON1;


String gabJarak="";

mrute=mrute.replaceAll("#", "");

cetak("GET="+mrute);

//aZYWVUSQPMLKHIBACD

int x1=mrute.indexOf(src);

int y1=mrute.indexOf(dst)+1;



mrute=mrute.substring(x1,y1);


cetak("GET="+mrute);

// mrute=mrute+"A";

char[]ar=mrute.toCharArray();


String kode2="",kota2="";

int id1=getIndex(String.valueOf(ar[0]));

int id2=getIndex(String.valueOf(ar[0]));

jarak=  getJarak(LAT1,LON1,arLati[id1],arLongi[id1]);

gabJarak=String.valueOf(jarak)+"+";

totalJarak=jarak;


for(int i=1;i<ar.length;i++){

String kode1=String.valueOf(ar[i-1]);

kode2=String.valueOf(ar[i]);

id1=getIndex(kode1);

id2=getIndex(kode2);

String kota1=arNama[id1];

kota2=arNama[id2];

LAT1=arLati[id1];

LON1=arLongi[id1];

LAT2=arLati[id2];

LON2=arLongi[id2];

jarak=getJarak(LAT1,LON1,LAT2,LON2);

gabKota+=kota1+"-";

gabKode+=kode1+"-";

gabKoor+="/"+LAT1+","+LON1;

gabJarak+=jarak+"+";


String br=kode1+"-"+kode2+"="+jarak;

cetak(i+"."+br);


totalJarak+=jarak;

}

jarak=  getJarak(arLati[id2],arLongi[id2],LAT2,LON2);

//totalJarak+=jarak;

totalJarak+=jarak1B;


//gabJarak+=String.valueOf(jarak);

gabJarak+=String.valueOf(jarak1B);


gabKode+=kode2+"-"+"TUJUAN_WISATA";

gabKota+=kota2+"-"+myPosisi2;

gabKoor+="/"+LAT2+","+LON2+"/"+myLati2+","+myLongi2;


cetak(gabKode);

cetak(gabJarak+"\nTOTAL JARAK="+String.valueOf(totalJarak)+" m");

cetak(gabKota);

cetak(gabKoor);


txtalamat2.setText(gabKota);

txtalamat.setText(gabKode+"==>"+gabJarak);


}

else{

cetak("No Route.....");

}

}



void cekJarak(String aw,String ah){

int index1=getIndex(aw);

int index2=getIndex(ah);


double lat1=arLati[index1];

double lon1=arLongi[index1];

double lat2=arLati[index2];

double lon2=arLongi[index2];


double jrk=getJarak(lat1,lon1,lat2,lon2);

String gab=aw+"-"+ah+"="+String.valueOf(jrk)+" m";

cetak(gab);

}


int getIndex(String ch){

int index=0;

for(int i=0;i<arKode.length;i++){

if(ch.equals(arKode[i])){index=i;break;}

}

return index;

}


void cetak(String info){

Log.d("Info",info);

//System.out.println(info);

}

void init(){

int jd=28;

arKode = new String[jd];


arLati = new double[jd];

arLongi = new double[jd];

arJarakA = new double[jd];

arJarakB = new double[jd];

arNama=new String[jd];


arKode[0]="A";

arLati[0]=-3.704186;

arLongi[0]=128.088038;

arNama[0]="Jl. Propinsi Bandara";


arKode[1]="B";

arLati[1]=-3.688551;

arLongi[1]=128.113615;

arNama[1]="Jl. Propinsi Tawiri";


arKode[2]="C";

arLati[2]=-3.742976;

arLongi[2]=128.032114;

arNama[2]="Jl. Propinsi Allang";


arKode[3]="D";

arLati[3]=-3.773732;

arLongi[3]=127.945806;

arNama[3]="Jl. Propinsi Wakasihu";


arKode[4]="E";

arLati[4]=-3.682396;

arLongi[4]=127.921659;

arNama[4]="Jl. Propinsi Asilulu";


arKode[5]="F";

arLati[5]=-3.584788;

arLongi[5]=128.084958;

arNama[5]="Jl. Propinsi Hila";


arKode[6]="G";

arLati[6]=-3.585407;

arLongi[6]=128.174626;

arNama[6]="Jl. Propinsi Hitu";


arKode[7]="H";

arLati[7]=-3.648689;

arLongi[7]=128.193389;

arNama[7]="Poka";


arKode[8]="I";

arLati[8]=-3.655857;

arLongi[8]=128.196871;

arNama[8]="Jl. Dr. J. Leimena";


arKode[9]="J";

arLati[9]=-3.672499;

arLongi[9]=128.199532;

arNama[9]="Sirimau";


arKode[10]="K";

arLati[10]=-3.631248;

arLongi[10]=128.212820;

arNama[10]="Hunuth";


arKode[11]="L";

arLati[11]=-3.630785;

arLongi[11]=128.240829;

arNama[11]="Negeri Lama";


arKode[12]="M";

arLati[12]=-3.623666;

arLongi[12]=128.249054;

arNama[12]="Passo";


arKode[13]="N";

arLati[13]=-3.632148;

arLongi[13]=128.252139;

arNama[13]="Passo, Baguala 1";


arKode[14]="O";

arLati[14]=-3.630758;

arLongi[14]=128.255635;

arNama[14]="Passo, Baguala 2";


arKode[15]="P";

arLati[15]=-3.620501;

arLongi[15]=128.258551;

arNama[15]="Passo, Singsingamangaraja";


arKode[16]="Q";

arLati[16]=-3.621413;

arLongi[16]=128.291651;

arNama[16]="Suli";


arKode[17]="R";

arLati[17]=-3.599242;

arLongi[17]=128.353811;

arNama[17]="Tulehu 1";


arKode[18]="S";

arLati[18]=-3.587181;

arLongi[18]=128.327961;

arNama[18]="Jl. Propinsi Tulehu ";


arKode[19]="T";

arLati[19]=-3.586484;

arLongi[19]=128.313485;

arNama[19]="Tulehu 2";


arKode[20]="U";

arLati[20]=-3.576531;

arLongi[20]=128.325056;

arNama[20]="Jl. Propinsi Waai 1";


arKode[21]="V";

arLati[21]=-3.561847;

arLongi[21]=128.318215;

arNama[21]="Jl. Propinsi Waai 2";


arKode[22]="W";

arLati[22]=-3.558669;

arLongi[22]=128.309599;

arNama[22]="Waai";


arKode[23]="X";

arLati[23]=-3.564994;

arLongi[23]=128.320583;

arNama[23]="Jl. Propinsi Waai 3";


arKode[24]="Y";

arLati[24]=-3.555631;

arLongi[24]=128.324060;

arNama[24]="Jl. Propinsi Waai 4";


arKode[25]="Z";

arLati[25]=-3.514292;

arLongi[25]=128.338754;

arNama[25]="Jl. Propinsi Liang 1";


arKode[26]="a";

arLati[26]=-3.505168;

arLongi[26]=128.342712;

arNama[26]="Liang 1";


arKode[27]="b";

arLati[27]=-3.506121;

arLongi[27]=128.324752;

arNama[27]="Jl. Propinsi Liang 2";



jb=29;

arB=new String[jb];

arB[0]="EFGbZ";

arB[1]="EFGKLMPQSUVYZb";

arB[2]="EDCABIJNOPQSUVYZb";

}



public static double getJarak(double lat1, double lng1, double lat2, double lng2) {

double earthRadius = 3958.75;

double dLat = Math.toRadians(lat2-lat1);

double dLng = Math.toRadians(lng2-lng1);

double a = Math.sin(dLat/2) * Math.sin(dLat/2) +

Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) *

Math.sin(dLng/2) * Math.sin(dLng/2);

double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));

double dist = earthRadius * c;


int meterConversion = 1609;

double myjr=dist * meterConversion;

return Math.floor(myjr);


}

}


Sabtu, 03 Oktober 2020

BackSound

 package com.me;


import android.app.Service;
import android.content.Intent;
import android.content.SharedPreferences;
import android.media.MediaPlayer;
import android.os.IBinder;
import android.preference.PreferenceManager;

import androidx.annotation.Nullable;

public class MyService extends Service {

private MediaPlayer player;
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getBaseContext());//customer.this
Boolean on= sharedPref.getBoolean("on", true);
if (on){
player = MediaPlayer.create(this, R.raw.backsound);
player.setLooping(true);
player.start();
}

return START_NOT_STICKY;

}

@Override
public void onDestroy() {
super.onDestroy();
try {
player.stop();
player.release();
}
catch (Exception ee){}
}
}

=======================
  <activity
android:name=".Video_Thumbnail2"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>


<service android:name=".MyService"/>
</application>

</manifest>
============================
public void login(View view){
MediaPlayer klik = new MediaPlayer().create(this, R.raw.clik);
klik.start();

Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
startService(new Intent(getApplicationContext(), MyService.class));
}


@Override
public void onBackPressed() {
super.onBackPressed();
moveTaskToBack(true);
stopService(new Intent(getApplicationContext(), MyService.class));
}


hasil   = findViewById(R.id.hasil);
nilai = findViewById(R.id.nilai);
Typeface typeface = Typeface.createFromAsset(getAssets(),"fonts/FredokaOneRegular.ttf");
hasil.setTypeface(typeface);
nilai.setTypeface(typeface);


Reff: https://android-coffee.com/tutorial-how-to-play-youtube-videos-in-android-with-videoview/

Android Code VideoPlayer


Toast.makeText(getBaseContext(), "Terimakasih....", Toast.LENGTH_LONG).show();

Create:

final SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getBaseContext());//Login.this

SharedPreferences.Editor editor = sharedPref.edit();

editor.putBoolean("Registered", true);

editor.putString("kode_pegawai", kode_pegawai);

editor.apply();


Update:

SharedPreferences.Editor editor = sharedPref.edit();

editor.putString("kode_pemesanan", kode_pemesanan);

              

Get:   

SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getBaseContext());//customer.this

Boolean Registered = sharedPref.getBoolean("Registered", false);

if (!Registered){finish();}

else {

kode_customer = sharedPref.getString("kode_customer", ""); 

}

YOUTUBE:

How to get 3gp link of Youtube video: For example we have the link www.youtube.com/watch?v=Xprog0HC3aQ 1) open new tab in your browser and write:  m.youtube.com/watch?v=VIDEO_ID&app=m 2) now change VIDEO_ID from above with your video id code (Xprog0HC3aQ) and the result should be: m.youtube.com/watch?v=Xprog0HC3aQ&app=m and press enter. 3) right click on your video and Copy Link Location. 4) the result: rtsp://r7—sn-4g57kue6.googlevideo.com/Ck0LENy73wIaRAmk3cJBg-iaXhMYDSANFC0k8JRWMOCoAUIJbXYtZ29vZ2xlSARSBXdhdGNoYKK205Ti2LaNVooBC2lZYlRtN201YTlRDA==/9EFB79E36D6A4191F3BF60D01A0AE429B5C9AA32.B774C6D2C0948C3A49A088F9F5CCCFBE34864B29/yt6/1/video.3gp This is what you use on Uri.parse. Watch the video tutorial how to play Youtube videos in Android with VideoView with Android Studio version 1.5:


XML

<?xml version="1.0" encoding="utf-8"?>
<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/begroun"
tools:context=".VideoView"
android:orientation="vertical"
android:gravity="center">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginRight="20dp"
android:layout_marginLeft="20dp"
android:gravity="center">

<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="15dp"
android:foreground="?selectableItemBackground">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginBottom="50dp">

<TextView
android:id="@+id/txtjudul"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:textSize="28sp"
tools:ignore="MissingConstraints"
android:text="Presentasi"
android:layout_gravity="center"
android:textAlignment="center"/>

<RelativeLayout
android:id="@+id/layoutVid"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="@id/txtjudul"
android:gravity="center"
tools:ignore="MissingConstraints"
android:background="@android:color/background_dark">

<VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>

</RelativeLayout>


</LinearLayout>

</androidx.cardview.widget.CardView>

<Button
android:id="@+id/btnback"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginTop="-30dp"
android:background="@drawable/logo_home_biru"
android:layout_gravity="center"
android:onClick="back"/>

</LinearLayout>

</LinearLayout>

JAVA
package com.iak.belajar.asambasa;

import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.MediaController;

public class VideoView extends AppCompatActivity {

android.widget.VideoView videoV;
MediaController mc;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_view);

videoV = findViewById(R.id.videoView);
mc = new MediaController(this);

Intent intent = getIntent();
String title = intent.getStringExtra("video");

switch (title){
case "vpresentasi":
String path1="android.resource://"+getPackageName()+"/"+R.raw.presentasi_video_instrumen;
//path1="rtsp://r4---sn-npoeene6.googlevideo.com/Cj0LENy73wIaNAmPXH9pbuVaCBMYESARFC3hOHlfMOCoAUIASARgy5n9j9WNzJ5eigELdjBsRkRYLVJ1ZWsM/54C228E664CACEE02A38601EF853CCEF0C154385.807944B86439375E612BD42999C527F5EDACDC27/yt8/1/video.3gp";
videoV.setVideoURI(Uri.parse(path1));
break;
default:
break;
}

videoV.setMediaController(mc);
mc.setAnchorView(videoV);
videoV.start();

videoV.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
Intent intent = new Intent(VideoView.this, MainActivity.class);
startActivity(intent);
}
});

}

public void back(View view){
MediaPlayer klik = new MediaPlayer().create(this, R.raw.clik);
klik.start();

Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
startService(new Intent(getApplicationContext(), MyService.class));
}

@Override
public void onBackPressed() {
super.onBackPressed();
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
startService(new Intent(getApplicationContext(), MyService.class));
}
}


ATAU:
android.widget.VideoView videoView  = findViewById(R.id.videoplay);
MediaController mediaController= new MediaController(this);
mediaController.setAnchorView(videoView);
Uri uri=Uri.parse("rtsp://r7---sn-4g57kue6.googlevideo.com/Ck0LENy73wIaRAmk3cJBg-iaXhMYDSANFC3u0pRWMOCoAUIJbXYtZ29vZ2xlSARSBXdhdGNoYIaluaTkzciOVooBCzVxRjNraG5XcXdnDA==/D693A8E7577C3A29E60C292B42C9C87D7C25A565.762A63DC4CA0A028DA83256C6A79E5F160CBEDA3/yt6/1/video.3gp");
videoView.setMediaController(mediaController);
videoView.setVideoURI(uri);
videoView.requestFocus();
videoView.start();

Video = https://youtu.be/BYJcMZtHDag
Mobile =https://m.youtube.com/watch?v=BYJcMZtHDag&app=m

RTSP =
rtsp://r3---sn-npoe7ne6.googlevideo.com/Cj0LENy73wIaNAmoDUebMVyCBRMYESARFC1SNnlfMOCoAUIASARgy5n9j9WNzJ5eigELdjBsRkRYLVJ1ZWsM/3106EFC698A86E21C8DDEAECBBF2FF66A382AC42.5547FD412BD275DD9ED11A1D179863D04012CBC5/yt8/1/video.3gp

Minggu, 02 Agustus 2020

Android Code Format Rupiah

   String RP(double rp){
      rp=Math.ceil(rp);
      Locale localeID = new Locale("in", "ID");
      NumberFormat formatRupiah = NumberFormat.getCurrencyInstance(localeID);
      String hs=formatRupiah.format(rp);
      return hs;
      }  




Implmntasi:
String txtnominal=txtNominal.getText().toString();
        double NOMINAL=0;
       
       
        shasil="";
        NOMINAL=Double.parseDouble(txtnominal);;
       
        if(jw>0){
for(int  j=0;j<jw;j++){
if(ar[j].equalsIgnoreCase("Ayah")){
shasil+=ar[j]+" ("+String.valueOf(int1)+") @Rp."+RP((drumus_1 *  NOMINAL)/int1)+"\n";
}
else if(ar[j].equalsIgnoreCase("Ibu")){
shasil+=ar[j]+" ("+String.valueOf(int2)+") @Rp."+RP((drumus_1 *  NOMINAL)/int2)+"\n";
}
else if(ar[j].equalsIgnoreCase("Saudara Laki-laki SeIbu")){
shasil+=ar[j]+" ("+String.valueOf(int3)+") @Rp."+RP((drumus_1 *  NOMINAL)/int3)+"\n";
}
else if(ar[j].equalsIgnoreCase("Saudara Perempuan SeIbu")){
shasil+=ar[j]+" ("+String.valueOf(int4)+") @Rp."+RP((drumus_1 *  NOMINAL)/int4)+"\n";
}
else if(ar[j].equalsIgnoreCase("Anak Laki-laki")){
shasil+=ar[j]+" ("+String.valueOf(int5)+") @Rp."+RP((drumus_1 *  NOMINAL)/int5)+"\n";
}


Sabtu, 01 Agustus 2020

Upload Image To Server


uploadserver.php
<?php

    $file_path = "ypathfile/";
   
   $IMG=$_FILES['uploaded_file']['name'];
    $file_path = $file_path . basename( $IMG);
    if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $file_path)) {
        echo "success";
    } else{
        echo "fail";
    }
 ?>

PERMISSION

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature    android:name="android.hardware.camera"    android:required="false" />
<uses-feature    android:name="android.hardware.camera.autofocus"    android:required="false" />
<uses-feature    android:name="android.hardware.camera.front"    android:required="false" />
<uses-feature    android:name="android.hardware.camera.front.autofocus"    android:required="false" />

UploadImage.java

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Base64;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;


public class UploadImage extends Activity {
    String myip="", myFILE="";

    private static final int PICK_IMAGE = 1;
    private static final int PICK_Camera_IMAGE = 2;
    private ImageView imgView;
    private Button upload,cancel;
    private Bitmap bitmap;
    Uri imageUri;
    JSONParser jsonParser = new JSONParser();
    String URL="",NFUpload="";
    TextView messageText;
    Button uploadButton,btnpilih,btncamera;
    int serverResponseCode = 0;
    ProgressDialog dialog = null;
    String upLoadServerUri = null;

    final String uploadFilePath = "/mnt/sdcard/";
    String uploadFileName = "myfile.jpg";

    @Override    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.uploadserver);
        imgView = (ImageView) findViewById(R.id.imageView);
        uploadButton = (Button)findViewById(R.id.uploadButton);
        messageText  = (TextView)findViewById(R.id.messageText);

        btnpilih = (Button)findViewById(R.id.btnpilih);
        btncamera = (Button)findViewById(R.id.btncamera);

        messageText.setText(uploadFilePath+"/"+uploadFileName+"'");

        URL=jsonParser.getIP()+"uploadserver.php";
        upLoadServerUri =   URL;

        uploadButton.setOnClickListener(new OnClickListener() {
            @Override            public void onClick(View v) {
                dialog = ProgressDialog.show(UploadImage.this, "", "Uploading file...", true);
                new Thread(new Runnable() {
                    public void run() {
                        runOnUiThread(new Runnable() {
                            public void run() {messageText.setText("uploading started.....");
                            }
                        });
                        String AL=messageText.getText().toString();
                        File f=new File(AL);
                        myFILE=f.getName();
                        uploadFiles(AL);
                    }
                }).start();
            }
        });


        btnpilih.setOnClickListener(new OnClickListener() {
            @Override            public void onClick(View v) {
                try {
                    Intent gintent = new Intent();
                    gintent.setType("image/*");
                    gintent.setAction(Intent.ACTION_GET_CONTENT);
                    startActivityForResult(Intent.createChooser(gintent, "Select Picture"),PICK_IMAGE);
                } catch (Exception e) {
                    Toast.makeText(getApplicationContext(),e.getMessage(),Toast.LENGTH_LONG).show();
                    Log.e(e.getClass().getName(), e.getMessage(), e);
                }
            }
        });


        btncamera.setOnClickListener(new OnClickListener() {
            @Override            public void onClick(View v) {
                String fileName = "new-photo-name.jpg";
                //create parameters for Intent with filename                ContentValues values = new ContentValues();
                values.put(MediaStore.Images.Media.TITLE, fileName);
                values.put(MediaStore.Images.Media.DESCRIPTION,"Image captured by camera");
                //imageUri is the current activity attribute, define and save it for later usage (also in onSaveInstanceState)                //imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);                //create new Intent                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
                intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
                startActivityForResult(intent, PICK_Camera_IMAGE);
            }
        });
    }

    public int uploadFiles(String sourceFileUri) {
        String fileName = sourceFileUri;
        NFUpload=fileName;
        uploadFileName=NFUpload;
        HttpURLConnection conn = null;
        DataOutputStream dos = null;
        String lineEnd = "\r\n";
        String twoHyphens = "--";
        String boundary = "*****";
        int bytesRead, bytesAvailable, bufferSize;
        byte[] buffer;
        int maxBufferSize = 1 * 1024 * 1024;
        File sourceFile = new File(sourceFileUri);

        if (!sourceFile.isFile()) {
            dialog.dismiss();
            Log.d("uploadFile", "Source File not exist :"+uploadFilePath + "" + uploadFileName);
            runOnUiThread(new Runnable() {
                public void run() { messageText.setText("Source File not exist :"                            +uploadFilePath + "" + uploadFileName);    }
            });
            return 0;
        }
        else{
            try {
                FileInputStream fileInputStream = new FileInputStream(sourceFile);
                URL url = new URL(upLoadServerUri);
                conn = (HttpURLConnection) url.openConnection();
                conn.setDoInput(true); // Allow Inputs                conn.setDoOutput(true); // Allow Outputs                conn.setUseCaches(false); // Don't use a Cached Copy                conn.setRequestMethod("POST");
                conn.setRequestProperty("Connection", "Keep-Alive");
                conn.setRequestProperty("ENCTYPE", "multipart/form-data");
                conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
                conn.setRequestProperty("uploaded_file", fileName);

                dos = new DataOutputStream(conn.getOutputStream());
                dos.writeBytes(twoHyphens + boundary + lineEnd);
                dos.writeBytes("Content-Disposition: form-data; name=\"uploaded_file\";filename=\"" + fileName + "\"" + lineEnd);
                dos.writeBytes(lineEnd);
                bytesAvailable = fileInputStream.available();
                bufferSize = Math.min(bytesAvailable, maxBufferSize);
                buffer = new byte[bufferSize];
                bytesRead = fileInputStream.read(buffer, 0, bufferSize);
                while (bytesRead > 0) {
                    dos.write(buffer, 0, bufferSize);
                    bytesAvailable = fileInputStream.available();
                    bufferSize = Math.min(bytesAvailable, maxBufferSize);
                    bytesRead = fileInputStream.read(buffer, 0, bufferSize);
                }
                dos.writeBytes(lineEnd);
                dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
                serverResponseCode = conn.getResponseCode();
                String serverResponseMessage = conn.getResponseMessage();
                Log.i("uploadFile", "HTTP Response is : "+ serverResponseMessage + ": " + serverResponseCode);
                if(serverResponseCode == 200){
                    runOnUiThread(new Runnable() {
                        public void run() {
                            String msg = "File Upload Completed:" + uploadFileName;
                            messageText.setText(msg);
                            Toast.makeText(UploadImage.this, "File Upload Complete.",Toast.LENGTH_SHORT).show();
                        }
                    });
                }

                fileInputStream.close();
                dos.flush();
                dos.close();

                Intent i = new Intent(getApplicationContext(),Aplikasi.class);
                i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                i.putExtra("gambar0", myFILE);
                startActivity(i);
                finish();

            } catch (MalformedURLException ex) {
                dialog.dismiss();
                ex.printStackTrace();
                runOnUiThread(new Runnable() {
                    public void run() {
                        messageText.setText("MalformedURLException Exception : check script url.");
                        Toast.makeText(UploadImage.this, "MalformedURLException", Toast.LENGTH_SHORT).show();
                    }
                });
                Log.e("Upload file to server", "error: " + ex.getMessage(), ex);
            } catch (Exception e) {
                dialog.dismiss();
                e.printStackTrace();
                runOnUiThread(new Runnable() {
                    public void run() {
                        messageText.setText("Got Exception : see logcat ");
                        Toast.makeText(UploadImage.this, "Got Exception : see logcat ",Toast.LENGTH_SHORT).show();
                    }
                });
            }
            dialog.dismiss();
            return serverResponseCode;
        } // End else block    }



    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        Uri selectedImageUri = null;
        String filePath = null;
        switch (requestCode) {
            case PICK_IMAGE:
                if (resultCode == Activity.RESULT_OK) {
                    selectedImageUri = data.getData();
                }
                break;
            case PICK_Camera_IMAGE:
                if (resultCode == RESULT_OK) {
                    selectedImageUri = imageUri;
          /*Bitmap mPic = (Bitmap) data.getExtras().get("data");      selectedImageUri = Uri.parse(MediaStore.Images.Media.insertImage(getContentResolver(), mPic, getResources().getString(R.string.app_name), Long.toString(System.currentTimeMillis())));*/                } else if (resultCode == RESULT_CANCELED) {
                    Toast.makeText(this, "Picture was not taken", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(this, "Picture was not taken", Toast.LENGTH_SHORT).show();
                }
                break;
        }

        if(selectedImageUri != null){
            try {
                String filemanagerstring = selectedImageUri.getPath();
                String selectedImagePath = getPath(selectedImageUri);
                messageText.setText(selectedImagePath);
                if (selectedImagePath != null) {
                    filePath = selectedImagePath;
                } else if (filemanagerstring != null) {
                    filePath = filemanagerstring;
                } else {
                    Toast.makeText(getApplicationContext(), "Unknown path", Toast.LENGTH_LONG).show();
                    Log.e("Bitmap", "Unknown path");
                }
                if (filePath != null) {
                    decodeFile(filePath);
                } else {
                    bitmap = null;
                }
            } catch (Exception e) {
                Toast.makeText(getApplicationContext(), "Internal error", Toast.LENGTH_LONG).show();
                Log.e(e.getClass().getName(), e.getMessage(), e);
            }
        }

    }



    class ImageGalleryTask extends AsyncTask<Void, Void, String> {
        @SuppressWarnings("unused")
        @Override        protected String doInBackground(Void... unsued) {
            InputStream is;
            BitmapFactory.Options bfo;
            Bitmap bitmapOrg;
            ByteArrayOutputStream bao ;

            bfo = new BitmapFactory.Options();
            bfo.inSampleSize = 2;
            //bitmapOrg = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory() + "/" + customImage, bfo);
            bao = new ByteArrayOutputStream();
            bitmap.compress(Bitmap.CompressFormat.JPEG, 90, bao);
            byte [] ba = bao.toByteArray();
            String ba1 = Base64.encodeToString(ba,1);
            ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
            nameValuePairs.add(new BasicNameValuePair("image",ba1));
            nameValuePairs.add(new BasicNameValuePair("cmd","image_android"));
            Log.v("log_tag", System.currentTimeMillis()+".jpg");
            try{
                HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new                        //  Here you need to put your server file address

                HttpPost(URL);//"http://www.picsily.com/upload_photo.php");                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                HttpResponse response = httpclient.execute(httppost);
                HttpEntity entity = response.getEntity();
                is = entity.getContent();
                Log.v("log_tag", "In the try Loop" );
            }catch(Exception e){
                Log.v("log_tag", "Error in http connection "+e.toString());
            }
            return "Success";
            // (null);        }

        @Override        protected void onProgressUpdate(Void... unsued) {

        }

        @Override        protected void onPostExecute(String sResponse) {
            try {
                if (dialog.isShowing())
                    dialog.dismiss();
            } catch (Exception e) {
                Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
                Log.e(e.getClass().getName(), e.getMessage(), e);
            }
        }

    }

    public String getPath(Uri uri) {
        String[] projection = { MediaStore.Images.Media.DATA };
        Cursor cursor = managedQuery(uri, projection, null, null, null);
        if (cursor != null) {
            // HERE YOU WILL GET A NULLPOINTER IF CURSOR IS NULL            // THIS CAN BE, IF YOU USED OI FILE MANAGER FOR PICKING THE MEDIA            int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            cursor.moveToFirst();
            return cursor.getString(column_index);
        } else            return null;
    }

    public void decodeFile(String filePath) {
        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(filePath, o);
        final int REQUIRED_SIZE = 1024;
        int width_tmp = o.outWidth, height_tmp = o.outHeight;
        int scale = 1;
        while (true) {
            if (width_tmp < REQUIRED_SIZE && height_tmp < REQUIRED_SIZE)
                break;
            width_tmp /= 2;
            height_tmp /= 2;
            scale *= 2;
        }

        BitmapFactory.Options o2 = new BitmapFactory.Options();
        o2.inSampleSize = scale;
        bitmap = BitmapFactory.decodeFile(filePath, o2);
        imgView.setImageBitmap(bitmap);

    }
}


Aplikasi.java

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;



Intent ia = getIntent();
gambar= ia.getStringExtra("gambar");



 if(gambar.length()>5){
String arUrlFoto=ip+"ypathfile/"+gambar;
new DownloadImageTask((ImageView) findViewById(R.id.myGambar)).execute(arUrlFoto);
}

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); }
}










++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
NB Jika kembalian dari Galeri:
@Overrideprotected void onCreate(Bundle savedInstanceState) {
....
.......
                 if(gambar.length()>5){
                    decodeFile(gambar);
                }
}

public void decodeFile(String filePath) {
    BitmapFactory.Options o = new BitmapFactory.Options();
    o.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(filePath, o);
    final int REQUIRED_SIZE = 1024;
    int width_tmp = o.outWidth, height_tmp = o.outHeight;
    int scale = 1;
    while (true) {
        if (width_tmp < REQUIRED_SIZE && height_tmp < REQUIRED_SIZE)
            break;
        width_tmp /= 2;
        height_tmp /= 2;
        scale *= 2;
    }
    Toast.makeText(getApplicationContext(), "Sukses LOAD IMAGE", Toast.LENGTH_LONG).show();
    BitmapFactory.Options o2 = new BitmapFactory.Options();
    o2.inSampleSize = scale;
    Bitmap bitmap = BitmapFactory.decodeFile(filePath, o2);
    myGambar.setImageBitmap(bitmap);

}