Ad Code

How to Make a Simple File Manager Android App with Android Studio Java | Free source code and project for android studio

Hello Developers, In this Article we will provide you free source code of a File Manager project which was Made for Android 10 and lower. You can convert this project by adding permission for Android 11 and newer versions. This File Manager project is made on Android Studio Java language. Lets Start




Before adding this project to Android Studio you must add the resources like folder icon, app icon etc. After adding drawable resources add this project to your Android Studio. If you find any error then contect us. We will try to solvw this problem as soon as possible.

main.xml
<androidx.coordinatorlayout.widget.CoordinatorLayout
	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:id="@+id/_coordinator"
	android:layout_width="match_parent"
	android:layout_height="match_parent">
	<com.google.android.material.appbar.AppBarLayout
		android:id="@+id/_app_bar"
		android:layout_width="match_parent"
		android:layout_height="wrap_content"
		android:theme="@style/AppTheme.AppBarOverlay">
		<androidx.appcompat.widget.Toolbar
			android:id="@+id/_toolbar"
			android:layout_width="match_parent"
			android:layout_height="?attr/actionBarSize"
			android:background="?attr/colorPrimary"
			app:popupTheme="@style/AppTheme.PopupOverlay" />
	</com.google.android.material.appbar.AppBarLayout>
	<LinearLayout
		android:layout_width="match_parent"
		android:layout_height="match_parent"
		android:orientation="vertical"
		app:layout_behavior="@string/appbar_scrolling_view_behavior">
		<ListView
			android:id="@+id/listview1"
			android:layout_width="match_parent"
			android:layout_height="wrap_content"
			android:padding="8dp"
			android:choiceMode="none" />
	</LinearLayout>
	<com.google.android.material.floatingactionbutton.FloatingActionButton
		android:id="@+id/_fab"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:layout_margin="16dp"
		android:layout_gravity="right|bottom"
		app:srcCompat="@drawable/ic_add_circle_outline_black" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
txt.xml
<androidx.coordinatorlayout.widget.CoordinatorLayout
	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:id="@+id/_coordinator"
	android:layout_width="match_parent"
	android:layout_height="match_parent">
	<com.google.android.material.appbar.AppBarLayout
		android:id="@+id/_app_bar"
		android:layout_width="match_parent"
		android:layout_height="wrap_content"
		android:theme="@style/AppTheme.AppBarOverlay">
		<androidx.appcompat.widget.Toolbar
			android:id="@+id/_toolbar"
			android:layout_width="match_parent"
			android:layout_height="?attr/actionBarSize"
			android:background="?attr/colorPrimary"
			app:popupTheme="@style/AppTheme.PopupOverlay" />
	</com.google.android.material.appbar.AppBarLayout>
	<LinearLayout
		android:layout_width="match_parent"
		android:layout_height="match_parent"
		android:orientation="vertical"
		app:layout_behavior="@string/appbar_scrolling_view_behavior">
		<LinearLayout
			android:id="@+id/linear1"
			android:layout_width="match_parent"
			android:layout_height="wrap_content"
			android:padding="8dp"
			android:orientation="horizontal">
			<ImageView
				android:id="@+id/imageview1"
				android:layout_width="30dp"
				android:layout_height="30dp"
				android:src="@drawable/ic_border_color_black"
				android:scaleType="fitXY" />
			<ImageView
				android:id="@+id/imageview2"
				android:layout_width="30dp"
				android:layout_height="30dp"
				android:src="@drawable/ic_cancel_black"
				android:scaleType="fitXY" />
		</LinearLayout>
		<EditText
			android:id="@+id/edittext1"
			android:layout_width="wrap_content"
			android:layout_height="wrap_content"
			android:padding="8dp"
			android:textSize="12sp"
			android:textColor="#000000"
			android:textColorHint="#607D8B" />
		<TextView
			android:id="@+id/textview1"
			android:layout_width="wrap_content"
			android:layout_height="wrap_content"
			android:padding="8dp"
			android:text="TextView"
			android:textSize="12sp"
			android:textColor="#000000" />
	</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
web.xml
<androidx.coordinatorlayout.widget.CoordinatorLayout
	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:id="@+id/_coordinator"
	android:layout_width="match_parent"
	android:layout_height="match_parent">
	<LinearLayout
		android:layout_width="match_parent"
		android:layout_height="match_parent"
		android:orientation="vertical">
		<LinearLayout
			android:id="@+id/linear1"
			android:layout_width="match_parent"
			android:layout_height="wrap_content"
			android:padding="8dp"
			android:orientation="horizontal">
			<ImageView
				android:id="@+id/imageview1"
				android:layout_width="30dp"
				android:layout_height="30dp"
				android:src="@drawable/ic_save_black"
				android:scaleType="fitXY" />
			<ImageView
				android:id="@+id/imageview2"
				android:layout_width="30dp"
				android:layout_height="30dp"
				android:src="@drawable/ic_cancel_black"
				android:scaleType="fitXY" />
			<EditText
				android:id="@+id/edittext1"
				android:layout_width="wrap_content"
				android:layout_height="wrap_content"
				android:padding="8dp"
				android:textSize="12sp"
				android:textColor="#000000"
				android:hint="Edit Text"
				android:textColorHint="#607D8B" />
		</LinearLayout>
		<LinearLayout
			android:id="@+id/linear2"
			android:layout_width="match_parent"
			android:layout_height="match_parent"
			android:orientation="vertical"
			android:layout_weight="1">
			<WebView
				android:id="@+id/webview1"
				android:layout_width="match_parent"
				android:layout_height="match_parent"
				android:layout_weight="1" />
		</LinearLayout>
	</LinearLayout>
	<com.google.android.material.floatingactionbutton.FloatingActionButton
		android:id="@+id/_fab"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:layout_margin="16dp"
		android:layout_gravity="right|bottom"
		app:srcCompat="@drawable/ic_border_color_black" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
path.xml
<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:orientation="vertical">
	<LinearLayout
		android:id="@+id/linear1"
		android:layout_width="match_parent"
		android:layout_height="wrap_content"
		android:padding="8dp"
		android:gravity="center_vertical"
		android:orientation="horizontal"
		android:layout_gravity="center_vertical">
		<ImageView
			android:id="@+id/imageview1"
			android:focusable="false"
			android:layout_width="50dp"
			android:layout_height="50dp"
			android:src="@drawable/default_image"
			android:scaleType="fitXY" />
		<TextView
			android:id="@+id/textview1"
			android:focusable="false"
			android:layout_width="wrap_content"
			android:layout_height="wrap_content"
			android:gravity="center_vertical"
			android:text="TextView"
			android:textSize="20sp"
			android:textColor="#000000"
			android:layout_gravity="center_vertical" />
	</LinearLayout>
</LinearLayout>
MainActivity.java
package com.my.newproject17;

import androidx.appcompat.app.AppCompatActivity;
import androidx.annotation.*;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import android.app.*;
import android.os.*;
import android.view.*;
import android.view.View.*;
import android.widget.*;
import android.content.*;
import android.content.res.*;
import android.graphics.*;
import android.graphics.drawable.*;
import android.media.*;
import android.net.*;
import android.text.*;
import android.text.style.*;
import android.util.*;
import android.webkit.*;
import android.animation.*;
import android.view.animation.*;
import java.io.*;
import java.util.*;
import java.util.regex.*;
import java.text.*;
import org.json.*;
import java.util.ArrayList;
import java.util.HashMap;
import android.widget.ListView;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.app.Activity;
import android.content.SharedPreferences;
import android.content.Intent;
import android.net.Uri;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.widget.AdapterView;
import android.view.View;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.DialogFragment;
import androidx.core.content.ContextCompat;
import androidx.core.app.ActivityCompat;
import android.Manifest;
import android.content.pm.PackageManager;

public class MainActivity extends AppCompatActivity {
	
	private Toolbar _toolbar;
	private AppBarLayout _app_bar;
	private CoordinatorLayout _coordinator;
	private FloatingActionButton _fab;
	private double nr = 0;
	private String currentFilePath = "";
	private String path = "";
	private String fileName = "";
	private String folderName = "";
	private String newName = "";
	private double pos = 0;
	private String newNamePath = "";
	private String itemsInFolder = "";
	private double nrFiles = 0;
	private double nrFolders = 0;
	private double checkItemsNumber = 0;
	private String item_ = "";
	private double wh_ = 0;
	private double nr2 = 0;
	private boolean mainBack = false;
	private double nr3 = 0;
	private String mcPath = "";
	
	private ArrayList<String> list = new ArrayList<>();
	private ArrayList<HashMap<String, Object>> listmap = new ArrayList<>();
	private ArrayList<String> checkItemsFolder = new ArrayList<>();
	private ArrayList<String> viewItemsInFolde = new ArrayList<>();
	private ArrayList<String> copyMove = new ArrayList<>();
	private ArrayList<String> copyMoveSelectPath = new ArrayList<>();
	private ArrayList<String> showOnlyFolderCM = new ArrayList<>();
	private ArrayList<String> OnlyPath = new ArrayList<>();
	
	private ListView listview1;
	
	private SharedPreferences file;
	private Intent intent = new Intent();
	private AlertDialog.Builder d;
	private AlertDialog.Builder createFile;
	private AlertDialog.Builder createFolder;
	private AlertDialog.Builder longClickedOptions;
	private AlertDialog.Builder deleteDialog;
	private AlertDialog.Builder renameDialog;
	private AlertDialog.Builder viewItemsInFolder;
	private AlertDialog.Builder moveCopy;
	private AlertDialog.Builder selectPath;
	
	@Override
	protected void onCreate(Bundle _savedInstanceState) {
		super.onCreate(_savedInstanceState);
		setContentView(R.layout.main);
		initialize(_savedInstanceState);
		
		if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED
		|| ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) {
			ActivityCompat.requestPermissions(this, new String[] {Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1000);
		} else {
			initializeLogic();
		}
	}
	
	@Override
	public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
		super.onRequestPermissionsResult(requestCode, permissions, grantResults);
		if (requestCode == 1000) {
			initializeLogic();
		}
	}
	
	private void initialize(Bundle _savedInstanceState) {
		_app_bar = findViewById(R.id._app_bar);
		_coordinator = findViewById(R.id._coordinator);
		_toolbar = findViewById(R.id._toolbar);
		setSupportActionBar(_toolbar);
		getSupportActionBar().setDisplayHomeAsUpEnabled(true);
		getSupportActionBar().setHomeButtonEnabled(true);
		_toolbar.setNavigationOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View _v) {
				onBackPressed();
			}
		});
		_fab = findViewById(R.id._fab);
		
		listview1 = findViewById(R.id.listview1);
		file = getSharedPreferences("file", Activity.MODE_PRIVATE);
		d = new AlertDialog.Builder(this);
		createFile = new AlertDialog.Builder(this);
		createFolder = new AlertDialog.Builder(this);
		longClickedOptions = new AlertDialog.Builder(this);
		deleteDialog = new AlertDialog.Builder(this);
		renameDialog = new AlertDialog.Builder(this);
		viewItemsInFolder = new AlertDialog.Builder(this);
		moveCopy = new AlertDialog.Builder(this);
		selectPath = new AlertDialog.Builder(this);
		
		listview1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> _param1, View _param2, int _param3, long _param4) {
				final int _position = _param3;
				path = listmap.get((int)_position).get("path").toString();
				if (FileUtil.isFile(listmap.get((int)_position).get("path").toString())) {
					if (path.contains(".mp4") || path.contains(".avi")) {
						file.edit().putString("dat", path).commit();
						intent.setClass(getApplicationContext(), WebActivity.class);
						startActivity(intent);
					}
					else {
						if (path.contains(".mp3") || path.contains(".wav")) {
							file.edit().putString("dat", path).commit();
							intent.setClass(getApplicationContext(), WebActivity.class);
							startActivity(intent);
						}
						else {
							if (path.contains(".html") || (path.contains(".php") || path.contains(".pdf"))) {
								file.edit().putString("dat", path).commit();
								intent.setClass(getApplicationContext(), WebActivity.class);
								startActivity(intent);
							}
							else {
								if (path.contains(".jpg") || (path.contains(".jpeg") || path.contains(".png"))) {
									file.edit().putString("dat", path).commit();
									intent.setClass(getApplicationContext(), WebActivity.class);
									startActivity(intent);
								}
								else {
									file.edit().putString("dat", path).commit();
									intent.setClass(getApplicationContext(), TxtActivity.class);
									startActivity(intent);
								}
							}
						}
					}
				}
				else {
					_getFileList(listmap.get((int)_position).get("path").toString());
				}
			}
		});
		
		listview1.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
			@Override
			public boolean onItemLongClick(AdapterView<?> _param1, View _param2, int _param3, long _param4) {
				final int _position = _param3;
				pos = _position;
				longClickedOptions.setTitle(Uri.parse(Uri.parse(listmap.get((int)_position).get("path").toString()).getLastPathSegment()).getLastPathSegment().concat("`O que Deseja Fazer : "));
				longClickedOptions.setPositiveButton("Renomear", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface _dialog, int _which) {
						_renameDialogBlock();
					}
				});
				longClickedOptions.setNegativeButton("Apagar", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface _dialog, int _which) {
						deleteDialog.setTitle("Atenção");
						if (FileUtil.isFile(listmap.get((int)_position).get("path").toString())) {
							deleteDialog.setMessage("Você Realmente Deseja Apagar o Arquivo".concat(Uri.parse(Uri.parse(listmap.get((int)_position).get("path").toString()).getLastPathSegment()).getLastPathSegment().concat("?")));
						}
						else {
							_checkItemsInFolder(listmap.get((int)_position).get("path").toString());
							deleteDialog.setMessage("Você Realmente Deseja Apagar a Pasta".concat(Uri.parse(Uri.parse(listmap.get((int)_position).get("path").toString()).getLastPathSegment()).getLastPathSegment().concat("com".concat(itemsInFolder.concat("?")))));
							deleteDialog.setNeutralButton("Ver Itens", new DialogInterface.OnClickListener() {
								@Override
								public void onClick(DialogInterface _dialog, int _which) {
									viewItemsInFolde.clear();
									checkItemsFolder.clear();
									FileUtil.listDir(listmap.get((int)_position).get("path").toString(), checkItemsFolder);
									nr2 = 0;
									for(int _repeat78 = 0; _repeat78 < (int)(checkItemsFolder.size()); _repeat78++) {
										viewItemsInFolde.add(Uri.parse(Uri.parse(checkItemsFolder.get((int)(nr2))).getLastPathSegment()).getLastPathSegment());
										nr2++;
									}
									_List_Dialog(viewItemsInFolder, viewItemsInFolde);
									viewItemsInFolder.create().show();
								}
							});
						}
						deleteDialog.setPositiveButton("Apagar", new DialogInterface.OnClickListener() {
							@Override
							public void onClick(DialogInterface _dialog, int _which) {
								FileUtil.deleteFile(listmap.get((int)_position).get("path").toString());
								if (!FileUtil.isExistFile(listmap.get((int)_position).get("path").toString())) {
									SketchwareUtil.showMessage(getApplicationContext(), "Apagado Com Sucesso");
								}
								else {
									SketchwareUtil.showMessage(getApplicationContext(), "Erro ao tentar Apagar");
								}
								_getFileList(currentFilePath);
							}
						});
						deleteDialog.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
							@Override
							public void onClick(DialogInterface _dialog, int _which) {
								
							}
						});
						deleteDialog.create().show();
					}
				});
				longClickedOptions.create().show();
				return true;
			}
		});
		
		_fab.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View _view) {
				d.setTitle("create new folder");
				d.setPositiveButton("text editor", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface _dialog, int _which) {
						_edit_dialog();
					}
				});
				d.setNegativeButton("new folder", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface _dialog, int _which) {
						_createFoldet();
					}
				});
				d.create().show();
			}
		});
	}
	
	private void initializeLogic() {
		_getFileList(FileUtil.getExternalStorageDir());
		copyMove.add("Move");
		copyMove.add("Copy");
		mainBack = true;
	}
	
	@Override
	public void onBackPressed() {
		if (mainBack) {
			_getFileList(currentFilePath.replace(Uri.parse(Uri.parse(currentFilePath).getLastPathSegment()).getLastPathSegment(), ""));
		}
		else {
			finish();
		}
	}
	public void _getFileList(final String _fromPath) {
		list.clear();
		listmap.clear();
		FileUtil.listDir(_fromPath, list);
		nr = 0;
		for(int _repeat15 = 0; _repeat15 < (int)(list.size()); _repeat15++) {
			{
				HashMap<String, Object> _item = new HashMap<>();
				_item.put("path", list.get((int)(nr)));
				listmap.add(_item);
			}
			
			nr++;
		}
		currentFilePath = _fromPath;
		listview1.setAdapter(new Listview1Adapter(listmap));
	}
	
	
	public void _edit_dialog() {
		createFile.setTitle("create new text editor file");
		createFile.setMessage("edit text editor");
		LinearLayout layout = new LinearLayout(MainActivity.this);
		layout.setOrientation(LinearLayout.VERTICAL);
		
		LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); 
		final EditText edittxt2 = new EditText(MainActivity.this);
		edittxt2.setHint("Filename");
		edittxt2.setLayoutParams(lp);
		edittxt2.setElevation(6f);
		layout.addView(edittxt2);
		createFile.setView(layout);
		createFile.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface _dialog, int _which) {
				
			}
		});
		createFile.setPositiveButton("ok", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface _dialog, int _which) {
				fileName = edittxt2.getText().toString();
				if (fileName.equals("")) {
					SketchwareUtil.showMessage(getApplicationContext(), " text editor");
					_edit_dialog();
				}
				else {
					if (!fileName.contains("/")) {
						FileUtil.writeFile(currentFilePath.concat("/".concat(fileName)), "#Created by FileManager#");
						if (FileUtil.isExistFile(currentFilePath.concat("/".concat(fileName)))) {
							SketchwareUtil.showMessage(getApplicationContext(), "successful");
						}
						else {
							SketchwareUtil.showMessage(getApplicationContext(), "Erro!!!");
						}
						_getFileList(currentFilePath);
					}
					else {
						SketchwareUtil.showMessage(getApplicationContext(), "valid???");
						_edit_dialog();
					}
				}
			}
		});
		createFile.create().show();
	}
	
	
	public void _createFoldet() {
		createFolder.setTitle("Criar Pasta");
		createFolder.setMessage("Digite o Nome Da Pasta");
		LinearLayout layout = new LinearLayout(MainActivity.this);
		layout.setOrientation(LinearLayout.VERTICAL);
		
		LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); 
		final EditText edittxt1 = new EditText(MainActivity.this);
		edittxt1.setHint("Foldername");
		edittxt1.setLayoutParams(lp);
		edittxt1.setElevation(6f);
		layout.addView(edittxt1);
		createFolder.setView(layout);
		createFolder.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface _dialog, int _which) {
				
			}
		});
		createFolder.setPositiveButton("Criar", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface _dialog, int _which) {
				folderName = edittxt1.getText().toString();
				if (folderName.equals("")) {
					SketchwareUtil.showMessage(getApplicationContext(), "Digite o Nome Da Pasta");
					_createFoldet();
				}
				else {
					if (!folderName.contains("/")) {
						FileUtil.writeFile(currentFilePath.concat("/".concat(folderName.concat("/"))), "");
						if (FileUtil.isExistFile(currentFilePath.concat("/".concat(folderName.concat("/"))))) {
							SketchwareUtil.showMessage(getApplicationContext(), "Pasta Criada Com Sucesso");
						}
						else {
							SketchwareUtil.showMessage(getApplicationContext(), "Erro ao Criar");
						}
						_getFileList(currentFilePath);
					}
					else {
						SketchwareUtil.showMessage(getApplicationContext(), "O Nome Digitado Não é Valido[ / ]");
						_createFoldet();
					}
				}
			}
		});
		createFolder.create().show();
	}
	
	
	public void _renameDialogBlock() {
		renameDialog.setTitle("Renomear");
		renameDialog.setMessage("Digite o Novo Nome");
		LinearLayout layout = new LinearLayout(MainActivity.this);
		layout.setOrientation(LinearLayout.VERTICAL);
		
		LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); 
		final EditText edittxt3 = new EditText(MainActivity.this);
		edittxt3.setHint("Filename");
		edittxt3.setLayoutParams(lp);
		edittxt3.setElevation(6f);
		layout.addView(edittxt3);
		renameDialog.setView(layout);
		renameDialog.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface _dialog, int _which) {
				
			}
		});
		renameDialog.setPositiveButton("Renomear", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface _dialog, int _which) {
				newName = edittxt3.getText().toString();
				if (newName.equals("")) {
					SketchwareUtil.showMessage(getApplicationContext(), "Digite o Novo Nome");
				}
				else {
					if (!newName.contains("/")) {
						newNamePath = listmap.get((int)pos).get("path").toString().replace(Uri.parse(Uri.parse(listmap.get((int)pos).get("path").toString()).getLastPathSegment()).getLastPathSegment(), newName);
						FileUtil.moveFile(listmap.get((int)pos).get("path").toString(), newNamePath);
						if (FileUtil.isExistFile(newNamePath)) {
							SketchwareUtil.showMessage(getApplicationContext(), "Renomeado Com Sucesso");
						}
						else {
							SketchwareUtil.showMessage(getApplicationContext(), "Erro ao Renomear");
						}
						_getFileList(currentFilePath);
					}
					else {
						_renameDialogBlock();
						SketchwareUtil.showMessage(getApplicationContext(), "Nome Digitado Não é Valido[ / ]");
					}
				}
			}
		});
		renameDialog.create().show();
	}
	
	
	public void _checkItemsInFolder(final String _fFPath) {
		if (!FileUtil.isFile(_fFPath)) {
			checkItemsFolder.clear();
			FileUtil.listDir(_fFPath, checkItemsFolder);
			checkItemsNumber = 0;
			nrFiles = 0;
			nrFolders = 0;
			for(int _repeat17 = 0; _repeat17 < (int)(checkItemsFolder.size()); _repeat17++) {
				if (FileUtil.isFile(checkItemsFolder.get((int)(checkItemsNumber)))) {
					nrFiles++;
				}
				else {
					nrFolders++;
				}
				checkItemsNumber++;
			}
			itemsInFolder = String.valueOf((long)(nrFiles)).concat(" files and ".concat(String.valueOf((long)(nrFolders)).concat(" folders")));
		}
	}
	
	
	public void _List_Dialog(final AlertDialog.Builder _dialog, final ArrayList<String> _list) {
		final CharSequence[] _items = _list.toArray(new String[_list.size()]);
		_dialog.setItems(_items, new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int which) {
				wh_ = which;
				if (!FileUtil.isFile(checkItemsFolder.get((int)(wh_)))) {
					getFileList(checkItemsFolder.get((int)(wh)));
				}
				
			}});
		viewItemsInFolder.setPositiveButton("Voltar", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface _dialog, int _which) {
				deleteDialog.create().show();
			}
		});
	}
	
	public class Listview1Adapter extends BaseAdapter {
		
		ArrayList<HashMap<String, Object>> _data;
		
		public Listview1Adapter(ArrayList<HashMap<String, Object>> _arr) {
			_data = _arr;
		}
		
		@Override
		public int getCount() {
			return _data.size();
		}
		
		@Override
		public HashMap<String, Object> getItem(int _index) {
			return _data.get(_index);
		}
		
		@Override
		public long getItemId(int _index) {
			return _index;
		}
		
		@Override
		public View getView(final int _position, View _v, ViewGroup _container) {
			LayoutInflater _inflater = getLayoutInflater();
			View _view = _v;
			if (_view == null) {
				_view = _inflater.inflate(R.layout.path, null);
			}
			
			final LinearLayout linear1 = _view.findViewById(R.id.linear1);
			final ImageView imageview1 = _view.findViewById(R.id.imageview1);
			final TextView textview1 = _view.findViewById(R.id.textview1);
			
			textview1.setText(Uri.parse(Uri.parse(listmap.get((int)_position).get("path").toString()).getLastPathSegment()).getLastPathSegment());
			if (FileUtil.isFile(listmap.get((int)_position).get("path").toString())) {
				if (textview1.getText().toString().contains(".mp4") || textview1.getText().toString().contains(".avi")) {
					imageview1.setImageResource(R.drawable.ic_play_circle_fill_black);
				}
				else {
					if (textview1.getText().toString().contains(".mp3") || textview1.getText().toString().contains(".wav")) {
						imageview1.setImageResource(R.drawable.ic_play_circle_fill_black);
					}
					else {
						if (textview1.getText().toString().contains(".html") || (textview1.getText().toString().contains(".php") || textview1.getText().toString().contains(".pdf"))) {
							imageview1.setImageResource(R.drawable.ic_website_black);
						}
						else {
							if (textview1.getText().toString().contains(".jpg") || (textview1.getText().toString().contains(".jpeg") || textview1.getText().toString().contains(".png"))) {
								imageview1.setImageBitmap(FileUtil.decodeSampleBitmapFromPath(listmap.get((int)_position).get("path").toString(), 1024, 1024));
							}
							else {
								imageview1.setImageResource(R.drawable.ic_description_black);
							}
						}
					}
				}
			}
			else {
				imageview1.setImageResource(R.drawable.ic_folder_open_black);
			}
			
			return _view;
		}
	}
	
	@Deprecated
	public void showMessage(String _s) {
		Toast.makeText(getApplicationContext(), _s, Toast.LENGTH_SHORT).show();
	}
	
	@Deprecated
	public int getLocationX(View _v) {
		int _location[] = new int[2];
		_v.getLocationInWindow(_location);
		return _location[0];
	}
	
	@Deprecated
	public int getLocationY(View _v) {
		int _location[] = new int[2];
		_v.getLocationInWindow(_location);
		return _location[1];
	}
	
	@Deprecated
	public int getRandom(int _min, int _max) {
		Random random = new Random();
		return random.nextInt(_max - _min + 1) + _min;
	}
	
	@Deprecated
	public ArrayList<Double> getCheckedItemPositionsToArray(ListView _list) {
		ArrayList<Double> _result = new ArrayList<Double>();
		SparseBooleanArray _arr = _list.getCheckedItemPositions();
		for (int _iIdx = 0; _iIdx < _arr.size(); _iIdx++) {
			if (_arr.valueAt(_iIdx))
			_result.add((double)_arr.keyAt(_iIdx));
		}
		return _result;
	}
	
	@Deprecated
	public float getDip(int _input) {
		return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, _input, getResources().getDisplayMetrics());
	}
	
	@Deprecated
	public int getDisplayWidthPixels() {
		return getResources().getDisplayMetrics().widthPixels;
	}
	
	@Deprecated
	public int getDisplayHeightPixels() {
		return getResources().getDisplayMetrics().heightPixels;
	}
}
TxtActivity.java
package com.my.newproject17;

import androidx.appcompat.app.AppCompatActivity;
import androidx.annotation.*;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import com.google.android.material.appbar.AppBarLayout;
import android.app.*;
import android.os.*;
import android.view.*;
import android.view.View.*;
import android.widget.*;
import android.content.*;
import android.content.res.*;
import android.graphics.*;
import android.graphics.drawable.*;
import android.media.*;
import android.net.*;
import android.text.*;
import android.text.style.*;
import android.util.*;
import android.webkit.*;
import android.animation.*;
import android.view.animation.*;
import java.io.*;
import java.util.*;
import java.util.regex.*;
import java.text.*;
import org.json.*;
import android.widget.LinearLayout;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.ImageView;
import android.app.Activity;
import android.content.SharedPreferences;
import android.view.View;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.DialogFragment;
import androidx.core.content.ContextCompat;
import androidx.core.app.ActivityCompat;
import android.Manifest;
import android.content.pm.PackageManager;

public class TxtActivity extends AppCompatActivity {
	
	private Toolbar _toolbar;
	private AppBarLayout _app_bar;
	private CoordinatorLayout _coordinator;
	private boolean bool = false;
	
	private LinearLayout linear1;
	private EditText edittext1;
	private TextView textview1;
	private ImageView imageview1;
	private ImageView imageview2;
	
	private SharedPreferences file;
	
	@Override
	protected void onCreate(Bundle _savedInstanceState) {
		super.onCreate(_savedInstanceState);
		setContentView(R.layout.txt);
		initialize(_savedInstanceState);
		
		if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED
		|| ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) {
			ActivityCompat.requestPermissions(this, new String[] {Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1000);
		} else {
			initializeLogic();
		}
	}
	
	@Override
	public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
		super.onRequestPermissionsResult(requestCode, permissions, grantResults);
		if (requestCode == 1000) {
			initializeLogic();
		}
	}
	
	private void initialize(Bundle _savedInstanceState) {
		_app_bar = findViewById(R.id._app_bar);
		_coordinator = findViewById(R.id._coordinator);
		_toolbar = findViewById(R.id._toolbar);
		setSupportActionBar(_toolbar);
		getSupportActionBar().setDisplayHomeAsUpEnabled(true);
		getSupportActionBar().setHomeButtonEnabled(true);
		_toolbar.setNavigationOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View _v) {
				onBackPressed();
			}
		});
		linear1 = findViewById(R.id.linear1);
		edittext1 = findViewById(R.id.edittext1);
		textview1 = findViewById(R.id.textview1);
		imageview1 = findViewById(R.id.imageview1);
		imageview2 = findViewById(R.id.imageview2);
		file = getSharedPreferences("file", Activity.MODE_PRIVATE);
		
		imageview1.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View _view) {
				if (bool) {
					textview1.setVisibility(View.VISIBLE);
					FileUtil.writeFile(file.getString("dat", ""), edittext1.getText().toString());
					textview1.setText(FileUtil.readFile(file.getString("dat", "")));
					imageview2.setVisibility(View.INVISIBLE);
					edittext1.setVisibility(View.INVISIBLE);
					bool = false;
					imageview1.setImageResource(R.drawable.ic_border_color_black);
				}
				else {
					textview1.setVisibility(View.INVISIBLE);
					edittext1.setText(FileUtil.readFile(file.getString("dat", "")));
					imageview2.setVisibility(View.VISIBLE);
					edittext1.setVisibility(View.VISIBLE);
					imageview1.setImageResource(R.drawable.ic_save_black);
					bool = true;
				}
			}
		});
		
		imageview2.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View _view) {
				textview1.setText(FileUtil.readFile(file.getString("dat", "")));
				edittext1.setVisibility(View.GONE);
				textview1.setVisibility(View.VISIBLE);
				imageview2.setVisibility(View.GONE);
				imageview1.setImageResource(R.drawable.ic_border_color_black);
				bool = false;
			}
		});
	}
	
	private void initializeLogic() {
		textview1.setText(FileUtil.readFile(file.getString("dat", "")));
		_enable_copy_textview(textview1);
		edittext1.setVisibility(View.GONE);
		bool = false;
		imageview2.setVisibility(View.GONE);
	}
	
	public void _enable_copy_textview(final TextView _tv) {
		_tv.setTextIsSelectable(true);
	}
	
	
	@Deprecated
	public void showMessage(String _s) {
		Toast.makeText(getApplicationContext(), _s, Toast.LENGTH_SHORT).show();
	}
	
	@Deprecated
	public int getLocationX(View _v) {
		int _location[] = new int[2];
		_v.getLocationInWindow(_location);
		return _location[0];
	}
	
	@Deprecated
	public int getLocationY(View _v) {
		int _location[] = new int[2];
		_v.getLocationInWindow(_location);
		return _location[1];
	}
	
	@Deprecated
	public int getRandom(int _min, int _max) {
		Random random = new Random();
		return random.nextInt(_max - _min + 1) + _min;
	}
	
	@Deprecated
	public ArrayList<Double> getCheckedItemPositionsToArray(ListView _list) {
		ArrayList<Double> _result = new ArrayList<Double>();
		SparseBooleanArray _arr = _list.getCheckedItemPositions();
		for (int _iIdx = 0; _iIdx < _arr.size(); _iIdx++) {
			if (_arr.valueAt(_iIdx))
			_result.add((double)_arr.keyAt(_iIdx));
		}
		return _result;
	}
	
	@Deprecated
	public float getDip(int _input) {
		return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, _input, getResources().getDisplayMetrics());
	}
	
	@Deprecated
	public int getDisplayWidthPixels() {
		return getResources().getDisplayMetrics().widthPixels;
	}
	
	@Deprecated
	public int getDisplayHeightPixels() {
		return getResources().getDisplayMetrics().heightPixels;
	}
}
WebActicity.java
package com.my.newproject17;

import androidx.appcompat.app.AppCompatActivity;
import androidx.annotation.*;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import android.app.*;
import android.os.*;
import android.view.*;
import android.view.View.*;
import android.widget.*;
import android.content.*;
import android.content.res.*;
import android.graphics.*;
import android.graphics.drawable.*;
import android.media.*;
import android.net.*;
import android.text.*;
import android.text.style.*;
import android.util.*;
import android.webkit.*;
import android.animation.*;
import android.view.animation.*;
import java.io.*;
import java.util.*;
import java.util.regex.*;
import java.text.*;
import org.json.*;
import java.util.ArrayList;
import android.widget.LinearLayout;
import android.widget.ImageView;
import android.widget.EditText;
import android.webkit.WebView;
import android.webkit.WebSettings;
import android.app.Activity;
import android.content.SharedPreferences;
import android.webkit.WebViewClient;
import android.view.View;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.DialogFragment;
import androidx.core.content.ContextCompat;
import androidx.core.app.ActivityCompat;
import android.Manifest;
import android.content.pm.PackageManager;

public class WebActivity extends AppCompatActivity {
	
	private FloatingActionButton _fab;
	private boolean bool = false;
	private double page = 0;
	private String pdfFile = "";
	private double pageCount = 0;
	
	private ArrayList<String> filePath = new ArrayList<>();
	
	private LinearLayout linear1;
	private LinearLayout linear2;
	private ImageView imageview1;
	private ImageView imageview2;
	private EditText edittext1;
	private WebView webview1;
	
	private SharedPreferences file;
	
	@Override
	protected void onCreate(Bundle _savedInstanceState) {
		super.onCreate(_savedInstanceState);
		setContentView(R.layout.web);
		initialize(_savedInstanceState);
		
		if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED
		|| ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) {
			ActivityCompat.requestPermissions(this, new String[] {Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1000);
		} else {
			initializeLogic();
		}
	}
	
	@Override
	public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
		super.onRequestPermissionsResult(requestCode, permissions, grantResults);
		if (requestCode == 1000) {
			initializeLogic();
		}
	}
	
	private void initialize(Bundle _savedInstanceState) {
		_fab = findViewById(R.id._fab);
		
		linear1 = findViewById(R.id.linear1);
		linear2 = findViewById(R.id.linear2);
		imageview1 = findViewById(R.id.imageview1);
		imageview2 = findViewById(R.id.imageview2);
		edittext1 = findViewById(R.id.edittext1);
		webview1 = findViewById(R.id.webview1);
		webview1.getSettings().setJavaScriptEnabled(true);
		webview1.getSettings().setSupportZoom(true);
		file = getSharedPreferences("file", Activity.MODE_PRIVATE);
		
		linear1.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View _view) {
				
			}
		});
		
		imageview1.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View _view) {
				FileUtil.writeFile(file.getString("dat", ""), edittext1.getText().toString());
				SketchwareUtil.showMessage(getApplicationContext(), "Salvo!");
			}
		});
		
		imageview2.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View _view) {
				linear1.setVisibility(View.GONE);
				webview1.loadUrl("file://".concat(file.getString("dat", "")));
				bool = false;
				SketchwareUtil.showMessage(getApplicationContext(), "Exited the editor mode");
			}
		});
		
		webview1.setWebViewClient(new WebViewClient() {
			@Override
			public void onPageStarted(WebView _param1, String _param2, Bitmap _param3) {
				final String _url = _param2;
				
				super.onPageStarted(_param1, _param2, _param3);
			}
			
			@Override
			public void onPageFinished(WebView _param1, String _param2) {
				final String _url = _param2;
				
				super.onPageFinished(_param1, _param2);
			}
		});
		
		_fab.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View _view) {
				if (bool) {
					linear1.setVisibility(View.GONE);
					webview1.setVisibility(View.VISIBLE);
					webview1.loadUrl("file://".concat(file.getString("dat", "")));
					bool = false;
				}
				else {
					webview1.setVisibility(View.GONE);
					linear1.setVisibility(View.VISIBLE);
					edittext1.setText(FileUtil.readFile(file.getString("dat", "")));
					SketchwareUtil.showMessage(getApplicationContext(), "To exit click here again or on the image with the \"X\"");
					bool = true;
				}
			}
		});
	}
	
	private void initializeLogic() {
		
		webview1.getSettings().setLoadWithOverviewMode(true); webview1.getSettings().setUseWideViewPort(true); final WebSettings webSettings = webview1.getSettings(); final String newUserAgent; newUserAgent = "Mozilla/5.0 (Android) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"; webSettings.setUserAgentString(newUserAgent);
		
		webview1.getSettings().setBuiltInZoomControls(true);webview1.getSettings().setDisplayZoomControls(false);
		touch = new
		ZoomableImageView(this);
		linear2.addView(touch);
		webview1.loadUrl("file://".concat(file.getString("dat", "")));
		bool = false;
		linear1.setVisibility(View.GONE);
		if (file.getString("dat", "").contains(".mp4") || file.getString("dat", "").contains(".avi")) {
			_fab_visibility(false);
			_rotateActivity(true);
		}
		else {
			if (file.getString("dat", "").contains(".mp3") || file.getString("dat", "").contains(".wav")) {
				_fab_visibility(false);
			}
			else {
				if (file.getString("dat", "").contains(".pdf")) {
					webview1.setVisibility(View.GONE);
					try {
						
						renderer = new android.graphics.pdf.PdfRenderer(new ParcelFileDescriptor(ParcelFileDescriptor.open(new java.io.File(pdfFile), ParcelFileDescriptor.MODE_READ_ONLY)));
						
						pageCount = renderer.getPageCount();
						
						
						_display(page);
						edittext1.setText("of".concat(String.valueOf((long)(pageCount))));
					} catch (Exception e){ }
				}
				else {
					if (file.getString("dat", "").contains(".jpg") || (file.getString("dat", "").contains(".jpeg") || file.getString("dat", "").contains(".png"))) {
						_fab_visibility(false);
					}
					else {
						_fab_visibility(true);
					}
				}
			}
		}
	}
	
	public void _fab_visibility(final boolean _visiblity) {
		if (_visiblity) {
			
			
			_fab.setVisibility(View.VISIBLE);
		}
		else {
			
			
			_fab.setVisibility(View.GONE);
		}
	}
	
	
	public void _rotateActivity(final boolean _l) {
		if (_l) {
			setRequestedOrientation(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
		}
		else {
			setRequestedOrientation(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		}
	}
	
	
	public void _display(final double _page) {
		edittext1.setText(String.valueOf((long)(_page + 2)));
		android.graphics.pdf.PdfRenderer.Page page = renderer.openPage((int)_page);
		
		Bitmap mBitmap = Bitmap.createBitmap((int)getDip(page.getWidth()), (int)getDip(page.getHeight()), Bitmap.Config.ARGB_8888);
		
		page.render(mBitmap, null, null, android.graphics.pdf.PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY);
		
		touch.setImageBitmap(mBitmap);
		
		page.close();
		
	}
	
	
	public void _extra() {
	}
	private
	android.graphics.pdf.PdfRenderer
	renderer;
	ZoomableImageView touch;
	public class ZoomableImageView extends ImageView {
		
		
		Matrix matrix = new Matrix();
		
		static final int NONE = 0;
		
		static final int DRAG = 1;
		
		static final int ZOOM = 2;
		
		static final int CLICK = 3;
		
		int mode = NONE;
		
		PointF last = new PointF();
		
		PointF start = new PointF();
		
		float minScale = 1f;
		
		float maxScale = 4f;
		
		float[] m;
		
		float redundantXSpace, redundantYSpace;
		
		float width, height;
		
		float saveScale = 1f;
		
		float right, bottom, origWidth, origHeight, bmWidth, bmHeight;
		
		ScaleGestureDetector mScaleDetector;
		
		Context context;
		
		
		public ZoomableImageView(Context context) {
			
			super(context);
			
			super.setClickable(true);
			
			this.context = context;
			
			mScaleDetector = new ScaleGestureDetector(context, new ScaleListener());
			
			matrix.setTranslate(1f, 1f);
			
			m = new float[9];
			
			setImageMatrix(matrix); setScaleType(ScaleType.MATRIX);
			
			
			setOnTouchListener(new OnTouchListener() {
				
				@Override
				
				public boolean onTouch(View v, MotionEvent event) {
					
					mScaleDetector.onTouchEvent(event);
					
					matrix.getValues(m);
					
					float x = m[Matrix.MTRANS_X];
					
					float y = m[Matrix.MTRANS_Y];
					
					PointF curr = new PointF(event.getX(), event.getY());
					
					switch (event.getAction()) {
						
						case MotionEvent.ACTION_DOWN: last.set(event.getX(), event.getY()); start.set(last); mode = DRAG;
						
						break;
						
						case MotionEvent.ACTION_POINTER_DOWN: last.set(event.getX(), event.getY()); start.set(last);
						
						mode = ZOOM;
						
						break;
						
						case MotionEvent.ACTION_MOVE:
						
						if (mode == ZOOM || (mode == DRAG && saveScale > minScale)) {
							
							float deltaX = curr.x - last.x;
							
							float deltaY = curr.y - last.y;
							
							float scaleWidth = Math.round(origWidth * saveScale);
							
							float scaleHeight = Math.round(origHeight * saveScale);
							
							if (scaleWidth < width) {
								
								deltaX = 0;
								
								if (y + deltaY > 0) deltaY = -y;
								
								else if (y + deltaY < -bottom) deltaY = -(y + bottom);
								
							} else if (scaleHeight < height) {
								
								deltaY = 0;
								
								if (x + deltaX > 0) deltaX = -x;
								
								else if (x + deltaX < -right) deltaX = -(x + right);
								
							} else {
								
								if (x + deltaX > 0) deltaX = -x;
								
								else if (x + deltaX < -right) deltaX = -(x + right);
								
								if (y + deltaY > 0) deltaY = -y;
								
								else if (y + deltaY < -bottom) deltaY = -(y + bottom);
								
							}
							
							matrix.postTranslate(deltaX, deltaY);
							
							last.set(curr.x, curr.y);
							
						}
						
						break;
						
						case MotionEvent.ACTION_UP:
						
						mode = NONE;
						
						int xDiff = (int) Math.abs(curr.x - start.x);
						
						int yDiff = (int) Math.abs(curr.y - start.y);
						
						if (xDiff < CLICK && yDiff < CLICK) performClick();
						
						break;
						
						case MotionEvent.ACTION_POINTER_UP:
						
						mode = NONE;
						
						break;
						
					}
					
					setImageMatrix(matrix);
					
					invalidate();
					
					return true;
					
				}
				
			});
			
		}
		
		
		@Override
		
		public void setImageBitmap(Bitmap bm) {
			
			super.setImageBitmap(bm);
			
			bmWidth = bm.getWidth();
			
			bmHeight = bm.getHeight(); }
		
		
		public void setMaxZoom(float x) {
			
			maxScale = x; }
		
		
		private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
			
			@Override
			
			public boolean onScaleBegin(ScaleGestureDetector detector) {
				
				mode = ZOOM;
				
				return true;}
			
			@Override
			
			public boolean onScale(ScaleGestureDetector detector) {
				
				float mScaleFactor = detector.getScaleFactor();
				
				float origScale = saveScale;
				
				saveScale *= mScaleFactor;
				
				if (saveScale > maxScale){
					
					saveScale = maxScale;
					
					mScaleFactor = maxScale / origScale;
					
				} else if (saveScale < minScale) {
					
					saveScale = minScale;
					
					mScaleFactor = minScale / origScale;}
				
				right = width * saveScale - width - (2 * redundantXSpace * saveScale);
				
				bottom = height * saveScale - height - (2 * redundantYSpace * saveScale);
				
				if (origWidth * saveScale <= width || origHeight * saveScale <= height) {
					
					matrix.postScale(mScaleFactor, mScaleFactor, width / 2, height / 2);
					
					if (mScaleFactor < 1) {
						
						matrix.getValues(m);
						
						float x = m[Matrix.MTRANS_X];
						
						float y = m[Matrix.MTRANS_Y];
						
						if (mScaleFactor < 1) {
							
							if (Math.round(origWidth * saveScale) < width) {
								
								if (y < -bottom) matrix.postTranslate(0, -(y + bottom));
								
								else if (y > 0) matrix.postTranslate(0, -y);
								
							} else {
								
								if (x < -right) matrix.postTranslate(-(x + right), 0);
								
								else if (x > 0) matrix.postTranslate(-x, 0);}
							
						}
						
					}
					
				} else {
					
					matrix.postScale(mScaleFactor, mScaleFactor, detector.getFocusX(), detector.getFocusY()); matrix.getValues(m);
					
					float x = m[Matrix.MTRANS_X];
					
					float y = m[Matrix.MTRANS_Y];
					
					if (mScaleFactor < 1) {
						
						if (x < -right) matrix.postTranslate(-(x + right), 0);
						
						else if (x > 0) matrix.postTranslate(-x, 0);
						
						if (y < -bottom) matrix.postTranslate(0, -(y + bottom));
						
						else if (y > 0) matrix.postTranslate(0, -y);}
					
				}
				
				return true;
				
			}
			
		}
		
		
		@Override
		
		protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) {
			
			super.onMeasure(widthMeasureSpec, heightMeasureSpec);
			
			width = MeasureSpec.getSize(widthMeasureSpec);
			
			height = MeasureSpec.getSize(heightMeasureSpec);
			
			float scale;
			
			float scaleX = width / bmWidth;
			
			float scaleY = height / bmHeight;
			
			scale = Math.min(scaleX, scaleY); matrix.setScale(scale, scale); setImageMatrix(matrix);
			
			saveScale = 1f;
			
			redundantYSpace = height - (scale * bmHeight) ;
			
			redundantXSpace = width - (scale * bmWidth);
			
			redundantYSpace /= 2;
			
			redundantXSpace /= 2; matrix.postTranslate(redundantXSpace, redundantYSpace);
			
			origWidth = width - 2 * redundantXSpace;
			
			origHeight = height - 2 * redundantYSpace;
			
			right = width * saveScale - width - (2 * redundantXSpace * saveScale);
			
			bottom = height * saveScale - height - (2 * redundantYSpace * saveScale); setImageMatrix(matrix);}
		
	}
	
	    
	{
	}
	
	
	@Deprecated
	public void showMessage(String _s) {
		Toast.makeText(getApplicationContext(), _s, Toast.LENGTH_SHORT).show();
	}
	
	@Deprecated
	public int getLocationX(View _v) {
		int _location[] = new int[2];
		_v.getLocationInWindow(_location);
		return _location[0];
	}
	
	@Deprecated
	public int getLocationY(View _v) {
		int _location[] = new int[2];
		_v.getLocationInWindow(_location);
		return _location[1];
	}
	
	@Deprecated
	public int getRandom(int _min, int _max) {
		Random random = new Random();
		return random.nextInt(_max - _min + 1) + _min;
	}
	
	@Deprecated
	public ArrayList<Double> getCheckedItemPositionsToArray(ListView _list) {
		ArrayList<Double> _result = new ArrayList<Double>();
		SparseBooleanArray _arr = _list.getCheckedItemPositions();
		for (int _iIdx = 0; _iIdx < _arr.size(); _iIdx++) {
			if (_arr.valueAt(_iIdx))
			_result.add((double)_arr.keyAt(_iIdx));
		}
		return _result;
	}
	
	@Deprecated
	public float getDip(int _input) {
		return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, _input, getResources().getDisplayMetrics());
	}
	
	@Deprecated
	public int getDisplayWidthPixels() {
		return getResources().getDisplayMetrics().widthPixels;
	}
	
	@Deprecated
	public int getDisplayHeightPixels() {
		return getResources().getDisplayMetrics().heightPixels;
	}
}
Manifest Permissions
uses-permission android:name="android.permission.INTERNET" />
	<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
	<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
	<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
 <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />

Thank you for visiting our blog and don't forget to add our blog into your bookmark.

Post a Comment

0 Comments

Ad Code