picture load

This commit is contained in:
Page Asgardius 2022-11-04 15:27:05 -07:00
parent 0dd64bc432
commit 68f8f1969e
2 changed files with 36 additions and 3 deletions

View file

@ -25,6 +25,7 @@ import android.content.ContextWrapper;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.graphics.drawable.Drawable;
import android.location.Location; import android.location.Location;
import android.location.LocationListener; import android.location.LocationListener;
import android.location.LocationManager; import android.location.LocationManager;
@ -122,6 +123,7 @@ public class MainScreen extends AppCompatActivity {
startRequestingLocation(); startRequestingLocation();
crashsound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + this.getPackageName() + "/" + R.raw.crash); crashsound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + this.getPackageName() + "/" + R.raw.crash);
id.setText(username); id.setText(username);
pictureLoad();
Thread login = new Thread(new Runnable() { Thread login = new Thread(new Runnable() {
@Override @Override
@ -489,9 +491,6 @@ public class MainScreen extends AppCompatActivity {
} }
public void pictureUpdate() { public void pictureUpdate() {
String path = getFilesDir().getAbsolutePath() + "/profile";
ContextWrapper contextWrapper = new ContextWrapper(getApplicationContext());
File directory = contextWrapper.getDir(getFilesDir().getName(), Context.MODE_PRIVATE);
File file = new File(getFilesDir(),"profile"); File file = new File(getFilesDir(),"profile");
try { try {
InputStream in = getContentResolver().openInputStream(fileuri); InputStream in = getContentResolver().openInputStream(fileuri);
@ -503,10 +502,43 @@ public class MainScreen extends AppCompatActivity {
out.close(); out.close();
in.close(); in.close();
Toast.makeText(getApplicationContext(),"Imagen de perfil actualizada", Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(),"Imagen de perfil actualizada", Toast.LENGTH_SHORT).show();
pictureLoad();
} catch (Exception e) { } catch (Exception e) {
System.out.println(e); System.out.println(e);
Toast.makeText(getApplicationContext(),"No se pudo actualizar la imagen de perfil", Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(),"No se pudo actualizar la imagen de perfil", Toast.LENGTH_SHORT).show();
} }
}
public void pictureLoad() {
Thread imgread = new Thread(new Runnable() {
@Override
public void run() {
try {
//Your code goes here
File file = new File(getFilesDir(),"profile");
Drawable thumb_d = Drawable.createFromPath(file.toString());
runOnUiThread(new Runnable() {
@Override
public void run() {
profile.setImageDrawable(thumb_d);
}
});
} catch (Exception e) {
e.printStackTrace();
runOnUiThread(new Runnable() {
@Override
public void run() {
}
});
}
}
});
imgread.start();
} }
} }

View file

@ -24,6 +24,7 @@
android:layout_width="70dp" android:layout_width="70dp"
android:layout_height="70dp" android:layout_height="70dp"
android:background="#000000" android:background="#000000"
android:scaleType="centerCrop"
app:srcCompat="@drawable/user" app:srcCompat="@drawable/user"
tools:ignore="MissingConstraints" tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="0dp" tools:layout_editor_absoluteX="0dp"