Ad Code

How to get Sketchware Projects List in Android Studio | Get all Sketch Projects path in Java

Hello Developers, In this Article we will show that how to retreve all sketch projects list in android studio. So for doing that follow this Article step by step and Don't forget to add this Website into your browser bookmark.




What is sketch projects ?

Sketch projects means all that projects which is made on sketchware. If you are using Sketchware application then you know that in Sketchware we made projects like Android Studio. With this source code you can easily edit, retrive and make changes in the Sketchware projects. If you dont know what is sketchware then I would like to tell you that Sketchware is an Android Application where you can make your own Android Apps with this application. For using sketchware you do not need to have coding knowladge. Without coding you can make Andorid apps in the Sketchware. But unfortunately sketchaware is not available in Google Play Store. So, If you want to use Sketcware app then please veridy that the app is offcial or a trusted source. Otherwise your personal data may be steel by the app if you download this from untrusted source. You can also directly contect their officials for downloading their application. I personally reccomend users who wan to make app without coding, Sketchware is best choice for you. I hope you have understand.

Before making this project you must have to add FileUtil class which is already added this Article. And also you have to add storage permission in the AndroidManifest.xml file. After doing all this implement this project source in your project.

main.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="match_parent"
		android:orientation="vertical">
		<ListView
			android:id="@+id/listview3"
			android:layout_width="match_parent"
			android:layout_height="match_parent"
			android:padding="8dp"
			android:choiceMode="none" />
	</LinearLayout>
</LinearLayout>
cust.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:gravity="center_vertical"
		android:orientation="horizontal">
		<ImageView
			android:id="@+id/imageview1"
			android:focusable="false"
			android:layout_width="50dp"
			android:layout_height="50dp"
			android:src="@drawable/default_image"
			android:scaleType="fitCenter" />
		<LinearLayout
			android:id="@+id/linear3"
			android:layout_width="match_parent"
			android:layout_height="wrap_content"
			android:orientation="vertical">
			<TextView
				android:id="@+id/textview1"
				android:focusable="false"
				android:layout_width="wrap_content"
				android:layout_height="wrap_content"
				android:paddingLeft="8dp"
				android:paddingTop="8dp"
				android:paddingRight="8dp"
				android:paddingBottom="6dp"
				android:text="TextView"
				android:textSize="16sp"
				android:textStyle="bold"
				android:textColor="#263238" />
			<TextView
				android:id="@+id/textview5"
				android:focusable="false"
				android:layout_width="wrap_content"
				android:layout_height="wrap_content"
				android:padding="8dp"
				android:text="TextView"
				android:textSize="12sp"
				android:textColor="#000000" />
			<TextView
				android:id="@+id/textview3"
				android:focusable="false"
				android:layout_width="wrap_content"
				android:layout_height="wrap_content"
				android:paddingLeft="8dp"
				android:paddingRight="8dp"
				android:paddingBottom="8dp"
				android:text="TextView"
				android:textSize="12sp"
				android:textColor="#000000" />
		</LinearLayout>
	</LinearLayout>
</LinearLayout>
MainActivity.java
package com.my.newproject;

import android.app.Activity;
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.HashMap;
import java.util.ArrayList;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.net.Uri;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.DialogFragment;
import android.Manifest;
import android.content.pm.PackageManager;

public class MainActivity extends Activity {
	
	private HashMap<String, Object> projects_map = new HashMap<>();
	private double extended = 0;
	private double count = 0;
	private String projects_saved = "";
	private double count1 = 0;
	private String returnedValue = "";
	private String GetEval1 = "";
	private String projectId = "";
	private String GetEval2 = "";
	
	private ArrayList<String> file_path = new ArrayList<>();
	private ArrayList<HashMap<String, Object>> project_list_sk = new ArrayList<>();
	
	private LinearLayout linear1;
	private ListView listview3;
	
	@Override
	protected void onCreate(Bundle _savedInstanceState) {
		super.onCreate(_savedInstanceState);
		setContentView(R.layout.main);
		initialize(_savedInstanceState);
		
		if (Build.VERSION.SDK_INT >= 23) {
			if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) {
				requestPermissions(new String[] {Manifest.permission.READ_EXTERNAL_STORAGE}, 1000);
			} else {
				initializeLogic();
			}
		} 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) {
		linear1 = findViewById(R.id.linear1);
		listview3 = findViewById(R.id.listview3);
	}
	
	private void initializeLogic() {
		file_path.clear();
		project_list_sk.clear();
		projects_map.clear();
		extended = -1;
		FileUtil.listDir(FileUtil.getExternalStorageDir().concat("/.sketchware/data/"), file_path);
		FileUtil.listDir(FileUtil.getExternalStorageDir().concat("/.sketchware/mysc/list"), file_path);
		count = 0;
		for(int _repeat18 = 0; _repeat18 < (int)(file_path.size()); _repeat18++) {
			if (FileUtil.isDirectory(file_path.get((int)(count)))) {
				projects_map = new HashMap<>();
				projects_map.put("name", Uri.parse(file_path.get((int)(count))).getLastPathSegment());
				projects_map.put("icon", FileUtil.getExternalStorageDir().concat("/.sketchware/resources/icons/".concat(Uri.parse(file_path.get((int)(count))).getLastPathSegment())).concat("/icon.png"));
				projects_map.put("status", "normal");
				project_list_sk.add(projects_map);
				count++;
			}
			else {
				count++;
			}
		}
		listview3.setAdapter(new Listview3Adapter(project_list_sk));
		((BaseAdapter)listview3.getAdapter()).notifyDataSetChanged();
	}
	
	public void _getPackageNameFor(final String _id) {
		returnedValue = "Package Not Loaded";
		try {
			GetEval1 = FileUtil.readFile(FileUtil.getExternalStorageDir().concat("/.sketchware/mysc/".concat(_id.concat("/app/build.gradle"))));
			GetEval2 = GetEval1.substring((int)(GetEval1.indexOf("applicationId \"") + "applicationId \"".length()), (int)(GetEval1.length()));
			returnedValue = GetEval2.substring((int)(0), (int)(GetEval2.indexOf("\"")));
		} catch(Exception e) {};
	}
	
	public class Listview3Adapter extends BaseAdapter {
		
		ArrayList<HashMap<String, Object>> _data;
		
		public Listview3Adapter(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.cst, null);
			}
			
			final LinearLayout linear1 = _view.findViewById(R.id.linear1);
			final ImageView imageview1 = _view.findViewById(R.id.imageview1);
			final LinearLayout linear3 = _view.findViewById(R.id.linear3);
			final TextView textview1 = _view.findViewById(R.id.textview1);
			final TextView textview5 = _view.findViewById(R.id.textview5);
			final TextView textview3 = _view.findViewById(R.id.textview3);
			
			FileUtil.listDir(FileUtil.getExternalStorageDir().concat("/.sketchware/mysc/".concat("").concat("/bin/")), file_path);
			count1 = 0;
			for(int _repeat23 = 0; _repeat23 < (int)(file_path.size()); _repeat23++) {
				if (!FileUtil.isExistFile(FileUtil.getExternalStorageDir().concat("/.sketchware/mysc/".concat(_data.get((int)(_data.size() - 1) - _position).get("name").toString())))) {
					textview1.setText("Please Run/Compile this Project");
					textview1.setTextColor(0xFFF44336);
				}
				else {
					if (file_path.get((int)(count1)).contains(".apk")) {
						textview1.setText(Uri.parse(file_path.get((int)(count1))).getLastPathSegment());
						textview1.setText(textview1.getText().toString().replace(".apk", ""));
						textview1.setText(textview1.getText().toString().replace(".res", ""));
						textview1.setText(textview1.getText().toString().replace(".d", ""));
					}
					else {
						count1++;
					}
				}
			}
			if (FileUtil.getFileLength(_data.get((int)(_data.size() - 1) - _position).get("icon").toString()) == 0) {
				imageview1.setImageResource(R.drawable.test);
			}
			else {
				imageview1.setImageBitmap(FileUtil.decodeSampleBitmapFromPath(_data.get((int)(_data.size() - 1) - _position).get("icon").toString(), 1024, 1024));
			}
			_getPackageNameFor(_data.get((int)(_data.size() - 1) - _position).get("name").toString());
			textview3.setText(returnedValue);
			
			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;
	}
}

Add below code to your project AndroidManifest.xml file inside Application Tag.

AndroidManifest.xml
	<activity
			android:name=".MainActivity"
			android:configChanges="orientation|screenSize|keyboardHidden|smallestScreenSize|screenLayout"
			android:hardwareAccelerated="true"
			android:supportsPictureInPicture="true"
			android:screenOrientation="portrait">
			<intent-filter>
				<action android:name="android.intent.action.MAIN" />
				<category android:name="android.intent.category.LAUNCHER" />
			</intent-filter>
		</activity>

Thank you for visiting our blog and I hope that you are easily impliment this source code to your project. If you want to make projects according to your interest, then contact us. We will try to make as soon as possible. You can also visit our Youtube chennal Team4Coding for getting more help to the coding community. Thank You

Post a Comment

0 Comments

Ad Code