├── .gitattributes
├── Dictionary
├── .gitignore
├── .idea
│ ├── .gitignore
│ ├── compiler.xml
│ ├── gradle.xml
│ └── misc.xml
├── app
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src
│ │ ├── androidTest
│ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── dictionary
│ │ │ └── ExampleInstrumentedTest.java
│ │ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── example
│ │ │ │ └── dictionary
│ │ │ │ ├── Adapters
│ │ │ │ ├── DefinitionAdapter.java
│ │ │ │ ├── MeaningAdapter.java
│ │ │ │ └── PhoneticsAdapter.java
│ │ │ │ ├── MainActivity.java
│ │ │ │ ├── Models
│ │ │ │ ├── APIResponse.java
│ │ │ │ ├── Definitions.java
│ │ │ │ ├── Meanings.java
│ │ │ │ └── Phonetics.java
│ │ │ │ ├── OnFetchDataListener.java
│ │ │ │ ├── RequestManager.java
│ │ │ │ └── ViewHolders
│ │ │ │ ├── DefinitionViewHolder.java
│ │ │ │ ├── MeaningsViewHolder.java
│ │ │ │ └── PhoneticViewHolder.java
│ │ └── res
│ │ │ ├── drawable-v24
│ │ │ └── ic_launcher_foreground.xml
│ │ │ ├── drawable
│ │ │ ├── ic_launcher_background.xml
│ │ │ └── ic_play.xml
│ │ │ ├── layout
│ │ │ ├── activity_main.xml
│ │ │ ├── definitions_list_items.xml
│ │ │ ├── meanings_list_items.xml
│ │ │ └── phonetic_list_items.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.webp
│ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.webp
│ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.webp
│ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.webp
│ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.webp
│ │ │ └── ic_launcher_round.webp
│ │ │ ├── values-night
│ │ │ └── themes.xml
│ │ │ └── values
│ │ │ ├── colors.xml
│ │ │ ├── strings.xml
│ │ │ └── themes.xml
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── dictionary
│ │ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
├── Music_Player
├── MainActivity.java
├── PlayerActivity.java
├── activity_main.xml
├── activity_player.xml
└── list_item.xml
├── Open_Whatsapp
├── MainActivity.java
└── activity_main.xml
├── README.md
└── Scientific_Calculator
├── MainActivity.java
├── activity_main.xml
└── eval_func.txt
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/Dictionary/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 | local.properties
16 |
--------------------------------------------------------------------------------
/Dictionary/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/Dictionary/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Dictionary/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
19 |
20 |
--------------------------------------------------------------------------------
/Dictionary/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/Dictionary/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/Dictionary/app/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | }
4 |
5 | android {
6 | compileSdk 31
7 |
8 | defaultConfig {
9 | applicationId "com.example.dictionary"
10 | minSdk 24
11 | targetSdk 31
12 | versionCode 1
13 | versionName "1.0"
14 |
15 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
16 | }
17 |
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 | compileOptions {
25 | sourceCompatibility JavaVersion.VERSION_1_8
26 | targetCompatibility JavaVersion.VERSION_1_8
27 | }
28 | }
29 |
30 | dependencies {
31 |
32 | implementation 'androidx.appcompat:appcompat:1.3.1'
33 | implementation 'com.google.android.material:material:1.4.0'
34 | implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
35 |
36 | implementation 'com.squareup.retrofit2:retrofit:2.9.0'
37 | implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
38 |
39 | testImplementation 'junit:junit:4.+'
40 | androidTestImplementation 'androidx.test.ext:junit:1.1.3'
41 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
42 | }
--------------------------------------------------------------------------------
/Dictionary/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/Dictionary/app/src/androidTest/java/com/example/dictionary/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.example.dictionary;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.platform.app.InstrumentationRegistry;
6 | import androidx.test.ext.junit.runners.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24 | assertEquals("com.example.dictionary", appContext.getPackageName());
25 | }
26 | }
--------------------------------------------------------------------------------
/Dictionary/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
14 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/Dictionary/app/src/main/java/com/example/dictionary/Adapters/DefinitionAdapter.java:
--------------------------------------------------------------------------------
1 | package com.example.dictionary.Adapters;
2 |
3 | import android.content.Context;
4 | import android.view.LayoutInflater;
5 | import android.view.ViewGroup;
6 |
7 | import androidx.annotation.NonNull;
8 | import androidx.recyclerview.widget.RecyclerView;
9 |
10 | import com.example.dictionary.Models.Definitions;
11 | import com.example.dictionary.R;
12 | import com.example.dictionary.ViewHolders.DefinitionViewHolder;
13 |
14 | import java.util.List;
15 |
16 | public class DefinitionAdapter extends RecyclerView.Adapter {
17 | private Context context;
18 | private List definitionsList;
19 |
20 | public DefinitionAdapter(Context context, List definitionsList) {
21 | this.context = context;
22 | this.definitionsList = definitionsList;
23 | }
24 |
25 | @NonNull
26 | @Override
27 | public DefinitionViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
28 | return new DefinitionViewHolder(LayoutInflater.from(context).inflate(R.layout.definitions_list_items, parent, false));
29 |
30 | }
31 |
32 | @Override
33 | public void onBindViewHolder(@NonNull DefinitionViewHolder holder, int position) {
34 | holder.textView_definition.setText("Definition: " + definitionsList.get(position).getDefinition());
35 | holder.textView_example.setText("Example: " + definitionsList.get(position).getExample());
36 | StringBuilder synonyms = new StringBuilder();
37 | StringBuilder antonyms = new StringBuilder();
38 |
39 | synonyms.append(definitionsList.get(position).getSynonyms());
40 | antonyms.append(definitionsList.get(position).getAntonyms());
41 |
42 | holder.textView_synonyms.setText(synonyms);
43 | holder.textView_antonyms.setText(antonyms);
44 |
45 | holder.textView_synonyms.setSelected(true);
46 | holder.textView_antonyms.setSelected(true);
47 | }
48 |
49 | @Override
50 | public int getItemCount() {
51 | return definitionsList.size();
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/Dictionary/app/src/main/java/com/example/dictionary/Adapters/MeaningAdapter.java:
--------------------------------------------------------------------------------
1 | package com.example.dictionary.Adapters;
2 |
3 | import android.content.Context;
4 | import android.view.LayoutInflater;
5 | import android.view.ViewGroup;
6 |
7 | import androidx.annotation.NonNull;
8 | import androidx.recyclerview.widget.GridLayoutManager;
9 | import androidx.recyclerview.widget.RecyclerView;
10 |
11 | import com.example.dictionary.Models.Meanings;
12 | import com.example.dictionary.R;
13 | import com.example.dictionary.ViewHolders.MeaningsViewHolder;
14 |
15 | import java.util.List;
16 |
17 | public class MeaningAdapter extends RecyclerView.Adapter {
18 | private Context context;
19 | protected List meaningsList;
20 |
21 | public MeaningAdapter(Context context, List meaningsList) {
22 | this.context = context;
23 | this.meaningsList = meaningsList;
24 | }
25 |
26 | @NonNull
27 | @Override
28 | public MeaningsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
29 | return new MeaningsViewHolder(LayoutInflater.from(context).inflate(R.layout.meanings_list_items, parent, false));
30 |
31 | }
32 |
33 | @Override
34 | public void onBindViewHolder(@NonNull MeaningsViewHolder holder, int position) {
35 | holder.textView_partsOfSpeech.setText("Parts of Speech: " + meaningsList.get(position).getPartOfSpeech());
36 | holder.recycler_definitions.setHasFixedSize(true);
37 | holder.recycler_definitions.setLayoutManager(new GridLayoutManager(context, 1));
38 | DefinitionAdapter definitionAdapter = new DefinitionAdapter(context, meaningsList.get(position).getDefinitions());
39 | holder.recycler_definitions.setAdapter(definitionAdapter);
40 | }
41 |
42 | @Override
43 | public int getItemCount() {
44 | return meaningsList.size();
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/Dictionary/app/src/main/java/com/example/dictionary/Adapters/PhoneticsAdapter.java:
--------------------------------------------------------------------------------
1 | package com.example.dictionary.Adapters;
2 |
3 | import android.content.Context;
4 | import android.media.AudioManager;
5 | import android.media.MediaPlayer;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.Toast;
10 |
11 | import androidx.annotation.NonNull;
12 | import androidx.recyclerview.widget.RecyclerView;
13 |
14 | import com.example.dictionary.Models.Phonetics;
15 | import com.example.dictionary.R;
16 | import com.example.dictionary.ViewHolders.PhoneticViewHolder;
17 |
18 | import java.util.List;
19 |
20 | public class PhoneticsAdapter extends RecyclerView.Adapter {
21 | private Context context;
22 | private List phoneticsList;
23 |
24 | public PhoneticsAdapter(Context context, List phoneticsList) {
25 | this.context = context;
26 | this.phoneticsList = phoneticsList;
27 | }
28 |
29 | @NonNull
30 | @Override
31 | public PhoneticViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
32 | return new PhoneticViewHolder(LayoutInflater.from(context).inflate(R.layout.phonetic_list_items, parent, false));
33 |
34 | }
35 |
36 | @Override
37 | public void onBindViewHolder(@NonNull PhoneticViewHolder holder, int position) {
38 | holder.textView_phonetic.setText(phoneticsList.get(position).getText());
39 | holder.imageButton_audio.setOnClickListener(new View.OnClickListener() {
40 | @Override
41 | public void onClick(View view) {
42 | MediaPlayer player = new MediaPlayer();
43 | try{
44 | player.setAudioStreamType(AudioManager.STREAM_MUSIC);
45 | player.setDataSource("https:" + phoneticsList.get(position).getAudio());
46 | player.prepare();
47 | player.start();
48 | } catch (Exception e){
49 | e.printStackTrace();
50 | Toast.makeText(context, "Couldn't play audio!", Toast.LENGTH_SHORT).show();
51 | }
52 | }
53 | });
54 | }
55 |
56 | @Override
57 | public int getItemCount() {
58 | return phoneticsList.size();
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/Dictionary/app/src/main/java/com/example/dictionary/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.dictionary;
2 |
3 | import androidx.appcompat.app.AppCompatActivity;
4 | import androidx.appcompat.widget.SearchView;
5 | import androidx.recyclerview.widget.GridLayoutManager;
6 | import androidx.recyclerview.widget.RecyclerView;
7 |
8 | import android.app.ProgressDialog;
9 | import android.os.Bundle;
10 | import android.widget.TextView;
11 | import android.widget.Toast;
12 |
13 | import com.example.dictionary.Adapters.MeaningAdapter;
14 | import com.example.dictionary.Adapters.PhoneticsAdapter;
15 | import com.example.dictionary.Models.APIResponse;
16 |
17 | public class MainActivity extends AppCompatActivity {
18 | SearchView search_view;
19 | TextView textView_word;
20 | RecyclerView recycler_phonetics, recycler_meanings;
21 | ProgressDialog progressDialog;
22 | PhoneticsAdapter phoneticsAdapter;
23 | MeaningAdapter meaningAdapter;
24 |
25 | @Override
26 | protected void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | setContentView(R.layout.activity_main);
29 |
30 | search_view = findViewById(R.id.search_view);
31 | textView_word = findViewById(R.id.textView_word);
32 | recycler_phonetics = findViewById(R.id.recycler_phonetics);
33 | recycler_meanings = findViewById(R.id.recycler_meanings);
34 | progressDialog = new ProgressDialog(this);
35 |
36 | progressDialog.setTitle("Loading...");
37 | progressDialog.show();
38 | RequestManager manager = new RequestManager(MainActivity.this);
39 | manager.getWordMeaning(listener, "hello");
40 |
41 | search_view.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
42 | @Override
43 | public boolean onQueryTextSubmit(String query) {
44 | progressDialog.setTitle("Fetching response for " + query);
45 | progressDialog.show();
46 | RequestManager manager = new RequestManager(MainActivity.this);
47 | manager.getWordMeaning(listener, query);
48 | return true;
49 | }
50 |
51 | @Override
52 | public boolean onQueryTextChange(String newText) {
53 | return false;
54 | }
55 | });
56 | }
57 |
58 | private final OnFetchDataListener listener = new OnFetchDataListener() {
59 | @Override
60 | public void onFetchData(APIResponse apiResponse, String message) {
61 | progressDialog.dismiss();
62 | if (apiResponse==null){
63 | Toast.makeText(MainActivity.this, "No data found!!!", Toast.LENGTH_SHORT).show();
64 | return;
65 | }
66 | showData(apiResponse);
67 | }
68 |
69 | @Override
70 | public void onError(String message) {
71 | progressDialog.dismiss();
72 | Toast.makeText(MainActivity.this, message, Toast.LENGTH_SHORT).show();
73 | }
74 | };
75 |
76 | private void showData(APIResponse apiResponse) {
77 | textView_word.setText("Word: " + apiResponse.getWord());
78 | recycler_phonetics.setHasFixedSize(true);
79 | recycler_phonetics.setLayoutManager(new GridLayoutManager(this, 1));
80 | phoneticsAdapter = new PhoneticsAdapter(this, apiResponse.getPhonetics());
81 | recycler_phonetics.setAdapter(phoneticsAdapter);
82 |
83 | recycler_meanings.setHasFixedSize(true);
84 | recycler_meanings.setLayoutManager(new GridLayoutManager(this, 1));
85 | meaningAdapter = new MeaningAdapter(this, apiResponse.getMeanings());
86 | recycler_meanings.setAdapter(meaningAdapter);
87 | }
88 | }
--------------------------------------------------------------------------------
/Dictionary/app/src/main/java/com/example/dictionary/Models/APIResponse.java:
--------------------------------------------------------------------------------
1 | package com.example.dictionary.Models;
2 |
3 | import java.util.List;
4 |
5 | public class APIResponse {
6 | String word = "";
7 | List phonetics = null;
8 | List meanings = null;
9 |
10 | public String getWord() {
11 | return word;
12 | }
13 |
14 | public void setWord(String word) {
15 | this.word = word;
16 | }
17 |
18 | public List getPhonetics() {
19 | return phonetics;
20 | }
21 |
22 | public void setPhonetics(List phonetics) {
23 | this.phonetics = phonetics;
24 | }
25 |
26 | public List getMeanings() {
27 | return meanings;
28 | }
29 |
30 | public void setMeanings(List meanings) {
31 | this.meanings = meanings;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/Dictionary/app/src/main/java/com/example/dictionary/Models/Definitions.java:
--------------------------------------------------------------------------------
1 | package com.example.dictionary.Models;
2 |
3 | import java.util.List;
4 |
5 | public class Definitions {
6 | String definition = "";
7 | String example = "";
8 | List synonyms = null;
9 | List antonyms = null;
10 |
11 | public List getSynonyms() {
12 | return synonyms;
13 | }
14 |
15 | public void setSynonyms(List synonyms) {
16 | this.synonyms = synonyms;
17 | }
18 |
19 | public List getAntonyms() {
20 | return antonyms;
21 | }
22 |
23 | public void setAntonyms(List antonyms) {
24 | this.antonyms = antonyms;
25 | }
26 |
27 | public String getDefinition() {
28 | return definition;
29 | }
30 |
31 | public void setDefinition(String definition) {
32 | this.definition = definition;
33 | }
34 |
35 | public String getExample() {
36 | return example;
37 | }
38 |
39 | public void setExample(String example) {
40 | this.example = example;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/Dictionary/app/src/main/java/com/example/dictionary/Models/Meanings.java:
--------------------------------------------------------------------------------
1 | package com.example.dictionary.Models;
2 |
3 | import java.util.List;
4 |
5 | public class Meanings {
6 | String partOfSpeech = "";
7 | List definitions = null;
8 |
9 | public String getPartOfSpeech() {
10 | return partOfSpeech;
11 | }
12 |
13 | public void setPartOfSpeech(String partOfSpeech) {
14 | this.partOfSpeech = partOfSpeech;
15 | }
16 |
17 | public List getDefinitions() {
18 | return definitions;
19 | }
20 |
21 | public void setDefinitions(List definitions) {
22 | this.definitions = definitions;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Dictionary/app/src/main/java/com/example/dictionary/Models/Phonetics.java:
--------------------------------------------------------------------------------
1 | package com.example.dictionary.Models;
2 |
3 | public class Phonetics {
4 | String text = "";
5 | String audio = "";
6 |
7 | public String getText() {
8 | return text;
9 | }
10 |
11 | public void setText(String text) {
12 | this.text = text;
13 | }
14 |
15 | public String getAudio() {
16 | return audio;
17 | }
18 |
19 | public void setAudio(String audio) {
20 | this.audio = audio;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Dictionary/app/src/main/java/com/example/dictionary/OnFetchDataListener.java:
--------------------------------------------------------------------------------
1 | package com.example.dictionary;
2 |
3 | import com.example.dictionary.Models.APIResponse;
4 |
5 | public interface OnFetchDataListener {
6 | void onFetchData(APIResponse apiResponse, String message);
7 | void onError(String message);
8 | }
9 |
--------------------------------------------------------------------------------
/Dictionary/app/src/main/java/com/example/dictionary/RequestManager.java:
--------------------------------------------------------------------------------
1 | package com.example.dictionary;
2 |
3 | import android.content.Context;
4 | import android.widget.Toast;
5 |
6 | import com.example.dictionary.Models.APIResponse;
7 |
8 | import java.util.List;
9 |
10 | import retrofit2.Call;
11 | import retrofit2.Callback;
12 | import retrofit2.Response;
13 | import retrofit2.Retrofit;
14 | import retrofit2.converter.gson.GsonConverterFactory;
15 | import retrofit2.http.GET;
16 | import retrofit2.http.Path;
17 |
18 | public class RequestManager {
19 | Context context;
20 |
21 | Retrofit retrofit = new Retrofit.Builder()
22 | .baseUrl("https://api.dictionaryapi.dev/api/v2/")
23 | .addConverterFactory(GsonConverterFactory.create())
24 | .build();
25 |
26 | public RequestManager(Context context) {
27 | this.context = context;
28 | }
29 |
30 | public void getWordMeaning(OnFetchDataListener listener, String word){
31 | CallDictionary callDictionary = retrofit.create(CallDictionary.class);
32 | Call> call = callDictionary.callMeanings(word);
33 |
34 | try{
35 | call.enqueue(new Callback>() {
36 | @Override
37 | public void onResponse(Call> call, Response> response) {
38 | if (!response.isSuccessful()){
39 | Toast.makeText(context, "Error!!", Toast.LENGTH_SHORT).show();
40 | return;
41 | }
42 | listener.onFetchData(response.body().get(0), response.message());
43 | }
44 |
45 | @Override
46 | public void onFailure(Call> call, Throwable t) {
47 | listener.onError("Request Failed!!");
48 | }
49 | });
50 | } catch (Exception e){
51 | e.printStackTrace();
52 | Toast.makeText(context, "An Error Occurred!!!", Toast.LENGTH_SHORT).show();
53 | }
54 | }
55 |
56 | public interface CallDictionary {
57 | @GET("entries/en/{word}")
58 | Call> callMeanings(
59 | @Path("word") String word
60 | );
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/Dictionary/app/src/main/java/com/example/dictionary/ViewHolders/DefinitionViewHolder.java:
--------------------------------------------------------------------------------
1 | package com.example.dictionary.ViewHolders;
2 |
3 | import android.view.View;
4 | import android.widget.TextView;
5 |
6 | import androidx.annotation.NonNull;
7 | import androidx.recyclerview.widget.RecyclerView;
8 |
9 | import com.example.dictionary.R;
10 |
11 | public class DefinitionViewHolder extends RecyclerView.ViewHolder {
12 | public TextView textView_definition, textView_example, textView_synonyms, textView_antonyms;
13 | public DefinitionViewHolder(@NonNull View itemView) {
14 | super(itemView);
15 | textView_definition = itemView.findViewById(R.id.textView_definition);
16 | textView_example = itemView.findViewById(R.id.textView_example);
17 | textView_synonyms = itemView.findViewById(R.id.textView_synonyms);
18 | textView_antonyms = itemView.findViewById(R.id.textView_antonyms);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Dictionary/app/src/main/java/com/example/dictionary/ViewHolders/MeaningsViewHolder.java:
--------------------------------------------------------------------------------
1 | package com.example.dictionary.ViewHolders;
2 |
3 | import android.view.View;
4 | import android.widget.TextView;
5 |
6 | import androidx.annotation.NonNull;
7 | import androidx.recyclerview.widget.RecyclerView;
8 |
9 | import com.example.dictionary.R;
10 |
11 | public class MeaningsViewHolder extends RecyclerView.ViewHolder {
12 | public TextView textView_partsOfSpeech;
13 | public RecyclerView recycler_definitions;
14 | public MeaningsViewHolder(@NonNull View itemView) {
15 | super(itemView);
16 | textView_partsOfSpeech = itemView.findViewById(R.id.textView_partsOfSpeech);
17 | recycler_definitions = itemView.findViewById(R.id.recycler_definitions);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Dictionary/app/src/main/java/com/example/dictionary/ViewHolders/PhoneticViewHolder.java:
--------------------------------------------------------------------------------
1 | package com.example.dictionary.ViewHolders;
2 |
3 | import android.view.View;
4 | import android.widget.ImageButton;
5 | import android.widget.TextView;
6 |
7 | import androidx.annotation.NonNull;
8 | import androidx.recyclerview.widget.RecyclerView;
9 |
10 | import com.example.dictionary.R;
11 |
12 | public class PhoneticViewHolder extends RecyclerView.ViewHolder {
13 | public TextView textView_phonetic;
14 | public ImageButton imageButton_audio;
15 | public PhoneticViewHolder(@NonNull View itemView) {
16 | super(itemView);
17 | textView_phonetic = itemView.findViewById(R.id.textView_phonetic);
18 | imageButton_audio = itemView.findViewById(R.id.imageButton_audio);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Dictionary/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/Dictionary/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/Dictionary/app/src/main/res/drawable/ic_play.xml:
--------------------------------------------------------------------------------
1 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/Dictionary/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
21 |
27 |
28 |
29 |
34 |
44 |
48 |
57 |
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/Dictionary/app/src/main/res/layout/definitions_list_items.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
14 |
24 |
34 |
35 |
44 |
58 |
59 |
68 |
82 |
83 |
84 |
--------------------------------------------------------------------------------
/Dictionary/app/src/main/res/layout/meanings_list_items.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
15 |
16 |
26 |
31 |
32 |
--------------------------------------------------------------------------------
/Dictionary/app/src/main/res/layout/phonetic_list_items.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
15 |
24 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/Dictionary/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Dictionary/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Dictionary/app/src/main/res/mipmap-hdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/evanemran/Android_Tutorials/044d1b7ee9b46d638c749cf1c930767a89d8731e/Dictionary/app/src/main/res/mipmap-hdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/Dictionary/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/evanemran/Android_Tutorials/044d1b7ee9b46d638c749cf1c930767a89d8731e/Dictionary/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/Dictionary/app/src/main/res/mipmap-mdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/evanemran/Android_Tutorials/044d1b7ee9b46d638c749cf1c930767a89d8731e/Dictionary/app/src/main/res/mipmap-mdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/Dictionary/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/evanemran/Android_Tutorials/044d1b7ee9b46d638c749cf1c930767a89d8731e/Dictionary/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/Dictionary/app/src/main/res/mipmap-xhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/evanemran/Android_Tutorials/044d1b7ee9b46d638c749cf1c930767a89d8731e/Dictionary/app/src/main/res/mipmap-xhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/Dictionary/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/evanemran/Android_Tutorials/044d1b7ee9b46d638c749cf1c930767a89d8731e/Dictionary/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/Dictionary/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/evanemran/Android_Tutorials/044d1b7ee9b46d638c749cf1c930767a89d8731e/Dictionary/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/Dictionary/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/evanemran/Android_Tutorials/044d1b7ee9b46d638c749cf1c930767a89d8731e/Dictionary/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/Dictionary/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/evanemran/Android_Tutorials/044d1b7ee9b46d638c749cf1c930767a89d8731e/Dictionary/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/Dictionary/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/evanemran/Android_Tutorials/044d1b7ee9b46d638c749cf1c930767a89d8731e/Dictionary/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/Dictionary/app/src/main/res/values-night/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/Dictionary/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFBB86FC
4 | #F7CD2E
5 | #F7CD2E
6 | #FF03DAC5
7 | #FF018786
8 | #FF000000
9 | #FFFFFFFF
10 | #F7CD2E
11 | #242B2E
12 |
--------------------------------------------------------------------------------
/Dictionary/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Dictionary
3 |
--------------------------------------------------------------------------------
/Dictionary/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/Dictionary/app/src/test/java/com/example/dictionary/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.example.dictionary;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/Dictionary/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 | buildscript {
3 | repositories {
4 | google()
5 | mavenCentral()
6 | }
7 | dependencies {
8 | classpath "com.android.tools.build:gradle:7.0.1"
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | task clean(type: Delete) {
16 | delete rootProject.buildDir
17 | }
--------------------------------------------------------------------------------
/Dictionary/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app"s APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
--------------------------------------------------------------------------------
/Dictionary/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/evanemran/Android_Tutorials/044d1b7ee9b46d638c749cf1c930767a89d8731e/Dictionary/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/Dictionary/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Sep 25 02:04:07 BDT 2021
2 | distributionBase=GRADLE_USER_HOME
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
4 | distributionPath=wrapper/dists
5 | zipStorePath=wrapper/dists
6 | zipStoreBase=GRADLE_USER_HOME
7 |
--------------------------------------------------------------------------------
/Dictionary/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 |
86 | # Determine the Java command to use to start the JVM.
87 | if [ -n "$JAVA_HOME" ] ; then
88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89 | # IBM's JDK on AIX uses strange locations for the executables
90 | JAVACMD="$JAVA_HOME/jre/sh/java"
91 | else
92 | JAVACMD="$JAVA_HOME/bin/java"
93 | fi
94 | if [ ! -x "$JAVACMD" ] ; then
95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96 |
97 | Please set the JAVA_HOME variable in your environment to match the
98 | location of your Java installation."
99 | fi
100 | else
101 | JAVACMD="java"
102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103 |
104 | Please set the JAVA_HOME variable in your environment to match the
105 | location of your Java installation."
106 | fi
107 |
108 | # Increase the maximum file descriptors if we can.
109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110 | MAX_FD_LIMIT=`ulimit -H -n`
111 | if [ $? -eq 0 ] ; then
112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113 | MAX_FD="$MAX_FD_LIMIT"
114 | fi
115 | ulimit -n $MAX_FD
116 | if [ $? -ne 0 ] ; then
117 | warn "Could not set maximum file descriptor limit: $MAX_FD"
118 | fi
119 | else
120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121 | fi
122 | fi
123 |
124 | # For Darwin, add options to specify how the application appears in the dock
125 | if $darwin; then
126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127 | fi
128 |
129 | # For Cygwin or MSYS, switch paths to Windows format before running java
130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133 |
134 | JAVACMD=`cygpath --unix "$JAVACMD"`
135 |
136 | # We build the pattern for arguments to be converted via cygpath
137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 | SEP=""
139 | for dir in $ROOTDIRSRAW ; do
140 | ROOTDIRS="$ROOTDIRS$SEP$dir"
141 | SEP="|"
142 | done
143 | OURCYGPATTERN="(^($ROOTDIRS))"
144 | # Add a user-defined pattern to the cygpath arguments
145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 | fi
148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 | i=0
150 | for arg in "$@" ; do
151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153 |
154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 | else
157 | eval `echo args$i`="\"$arg\""
158 | fi
159 | i=`expr $i + 1`
160 | done
161 | case $i in
162 | 0) set -- ;;
163 | 1) set -- "$args0" ;;
164 | 2) set -- "$args0" "$args1" ;;
165 | 3) set -- "$args0" "$args1" "$args2" ;;
166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 | esac
173 | fi
174 |
175 | # Escape application args
176 | save () {
177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178 | echo " "
179 | }
180 | APP_ARGS=`save "$@"`
181 |
182 | # Collect all arguments for the java command, following the shell quoting and substitution rules
183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184 |
185 | exec "$JAVACMD" "$@"
186 |
--------------------------------------------------------------------------------
/Dictionary/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/Dictionary/settings.gradle:
--------------------------------------------------------------------------------
1 | dependencyResolutionManagement {
2 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
3 | repositories {
4 | google()
5 | mavenCentral()
6 | jcenter() // Warning: this repository is going to shut down soon
7 | }
8 | }
9 | rootProject.name = "Dictionary"
10 | include ':app'
11 |
--------------------------------------------------------------------------------
/Music_Player/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.music_player;
2 |
3 | import androidx.appcompat.app.AppCompatActivity;
4 |
5 | import android.Manifest;
6 | import android.content.Intent;
7 | import android.os.Bundle;
8 | import android.os.Environment;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.AdapterView;
12 | import android.widget.ArrayAdapter;
13 | import android.widget.BaseAdapter;
14 | import android.widget.ListView;
15 | import android.widget.TextView;
16 |
17 | import com.karumi.dexter.Dexter;
18 | import com.karumi.dexter.MultiplePermissionsReport;
19 | import com.karumi.dexter.PermissionToken;
20 | import com.karumi.dexter.listener.PermissionDeniedResponse;
21 | import com.karumi.dexter.listener.PermissionGrantedResponse;
22 | import com.karumi.dexter.listener.PermissionRequest;
23 | import com.karumi.dexter.listener.multi.MultiplePermissionsListener;
24 | import com.karumi.dexter.listener.single.PermissionListener;
25 |
26 | import java.io.File;
27 | import java.util.ArrayList;
28 | import java.util.List;
29 |
30 | public class MainActivity extends AppCompatActivity {
31 | ListView listView;
32 | String[] items;
33 |
34 | @Override
35 | protected void onCreate(Bundle savedInstanceState) {
36 | super.onCreate(savedInstanceState);
37 | setContentView(R.layout.activity_main);
38 |
39 | listView = findViewById(R.id.listViewSong);
40 |
41 | runtimePermission();
42 |
43 |
44 | }
45 |
46 | public void runtimePermission()
47 | {
48 | Dexter.withContext(this).withPermissions(Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.RECORD_AUDIO)
49 | .withListener(new MultiplePermissionsListener() {
50 | @Override
51 | public void onPermissionsChecked(MultiplePermissionsReport multiplePermissionsReport) {
52 | displaySongs();
53 | }
54 |
55 | @Override
56 | public void onPermissionRationaleShouldBeShown(List list, PermissionToken permissionToken) {
57 | permissionToken.continuePermissionRequest();
58 |
59 | }
60 | }).check();
61 |
62 | }
63 |
64 | public ArrayList findSong (File file)
65 | {
66 | ArrayList arrayList = new ArrayList<>();
67 |
68 | File[] files = file.listFiles();
69 |
70 | for (File singlefile: files)
71 | {
72 | if (singlefile.isDirectory() && !singlefile.isHidden())
73 | {
74 | arrayList.addAll(findSong(singlefile));
75 | }
76 | else
77 | {
78 | if (singlefile.getName().endsWith(".mp3") || singlefile.getName().endsWith(".wav") )
79 | {
80 | arrayList.add(singlefile);
81 | }
82 | }
83 | }
84 | return arrayList;
85 | }
86 |
87 | void displaySongs()
88 | {
89 | final ArrayList mySongs = findSong(Environment.getExternalStorageDirectory());
90 |
91 | items = new String[mySongs.size()];
92 | for (int i = 0; i myAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, items);
98 | listView.setAdapter(myAdapter);*/
99 |
100 | customAdapter customAdapter = new customAdapter();
101 | listView.setAdapter(customAdapter);
102 |
103 | listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
104 | @Override
105 | public void onItemClick(AdapterView> adapterView, View view, int i, long l) {
106 | String songName = (String) listView.getItemAtPosition(i);
107 | startActivity(new Intent(getApplicationContext(), PlayerActivity.class)
108 | .putExtra("songs", mySongs)
109 | .putExtra("songname", songName)
110 | .putExtra("pos", i));
111 | }
112 | });
113 | }
114 |
115 |
116 | class customAdapter extends BaseAdapter
117 | {
118 |
119 | @Override
120 | public int getCount() {
121 | return items.length;
122 | }
123 |
124 | @Override
125 | public Object getItem(int i) {
126 | return null;
127 | }
128 |
129 | @Override
130 | public long getItemId(int i) {
131 | return 0;
132 | }
133 |
134 | @Override
135 | public View getView(int i, View view, ViewGroup viewGroup) {
136 |
137 | View myView = getLayoutInflater().inflate(R.layout.list_item, null);
138 | TextView textsong = myView.findViewById(R.id.txtsongname);
139 | textsong.setSelected(true);
140 | textsong.setText(items[i]);
141 |
142 | return myView;
143 | }
144 | }
145 | }
146 |
--------------------------------------------------------------------------------
/Music_Player/PlayerActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.music_player;
2 |
3 | import androidx.annotation.NonNull;
4 | import androidx.appcompat.app.AppCompatActivity;
5 |
6 | import android.animation.AnimatorSet;
7 | import android.animation.ObjectAnimator;
8 | import android.content.Intent;
9 | import android.graphics.PorterDuff;
10 | import android.media.MediaPlayer;
11 | import android.net.Uri;
12 | import android.os.Bundle;
13 | import android.os.Handler;
14 | import android.view.MenuItem;
15 | import android.view.View;
16 | import android.widget.Button;
17 | import android.widget.ImageView;
18 | import android.widget.SeekBar;
19 | import android.widget.TextView;
20 |
21 | import com.gauravk.audiovisualizer.visualizer.BarVisualizer;
22 |
23 | import java.io.File;
24 | import java.util.ArrayList;
25 |
26 | public class PlayerActivity extends AppCompatActivity {
27 | Button btnplay, btnnext, btnprev, btnff, btnfr;
28 | TextView txtsname, txtsstart, txtsstop;
29 | SeekBar seekmusic;
30 | BarVisualizer visualizer;
31 | ImageView imageView;
32 |
33 | String sname;
34 | public static final String EXTRA_NAME = "song_name";
35 | static MediaPlayer mediaPlayer;
36 | int position;
37 | ArrayList mySongs;
38 | Thread updateseekbar;
39 |
40 | @Override
41 | public boolean onOptionsItemSelected(@NonNull MenuItem item) {
42 | if (item.getItemId()==android.R.id.home)
43 | {
44 | onBackPressed();
45 | }
46 | return super.onOptionsItemSelected(item);
47 | }
48 |
49 | @Override
50 | protected void onDestroy() {
51 | if (visualizer != null)
52 | {
53 | visualizer.release();
54 | }
55 | super.onDestroy();
56 | }
57 |
58 | @Override
59 | protected void onCreate(Bundle savedInstanceState) {
60 | super.onCreate(savedInstanceState);
61 | setContentView(R.layout.activity_player);
62 |
63 | getSupportActionBar().setTitle("Now Playing");
64 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
65 | getSupportActionBar().setDisplayShowHomeEnabled(true);
66 |
67 | btnprev = findViewById(R.id.btnprev);
68 | btnnext = findViewById(R.id.btnnext);
69 | btnplay = findViewById(R.id.playbtn);
70 | btnff = findViewById(R.id.btnff);
71 | btnfr = findViewById(R.id.btnfr);
72 | txtsname = findViewById(R.id.txtsn);
73 | txtsstart = findViewById(R.id.txtsstart);
74 | txtsstop = findViewById(R.id.txtsstop);
75 | seekmusic = findViewById(R.id.seekbar);
76 | visualizer = findViewById(R.id.blast);
77 | imageView = findViewById(R.id.imageview);
78 |
79 | if (mediaPlayer != null)
80 | {
81 | mediaPlayer.stop();
82 | mediaPlayer.release();
83 | }
84 |
85 | Intent i = getIntent();
86 | Bundle bundle = i.getExtras();
87 |
88 | mySongs = (ArrayList) bundle.getParcelableArrayList("songs");
89 | String songName = i.getStringExtra("songname");
90 | position = bundle.getInt("pos",0);
91 | txtsname.setSelected(true);
92 | Uri uri = Uri.parse(mySongs.get(position).toString());
93 | sname = mySongs.get(position).getName();
94 | txtsname.setText(sname);
95 |
96 | mediaPlayer = MediaPlayer.create(getApplicationContext(), uri);
97 | mediaPlayer.start();
98 |
99 | updateseekbar = new Thread()
100 | {
101 | @Override
102 | public void run() {
103 | int totalDuration = mediaPlayer.getDuration();
104 | int currentposition = 0;
105 |
106 | while (currentposition
2 |
9 |
10 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/Music_Player/activity_player.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
18 |
32 |
33 |
34 |
35 |
41 |
42 |
43 |
44 |
48 |
56 |
57 |
58 |
69 |
70 |
71 |
82 |
83 |
84 |
85 |
86 |
87 |
91 |
94 |
102 |
103 |
112 |
113 |
122 |
123 |
133 |
143 |
144 |
155 |
156 |
157 |
158 |
--------------------------------------------------------------------------------
/Music_Player/list_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
25 |
26 |
27 |
28 |
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/Open_Whatsapp/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.whtspp;
2 |
3 | import androidx.appcompat.app.AppCompatActivity;
4 |
5 | import android.content.Intent;
6 | import android.content.pm.PackageManager;
7 | import android.net.Uri;
8 | import android.os.Bundle;
9 | import android.view.View;
10 | import android.widget.Button;
11 | import android.widget.Toast;
12 |
13 | public class MainActivity extends AppCompatActivity {
14 | Button btn;
15 |
16 |
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_main);
21 |
22 | btn = findViewById(R.id.btn);
23 |
24 | final String num = "+8801521329977";
25 | final String text = "Hello";
26 |
27 | btn.setOnClickListener(new View.OnClickListener() {
28 | @Override
29 | public void onClick(View v) {
30 |
31 | boolean installed = isAppInstalled("com.whatsapp");
32 |
33 | if (installed)
34 | {
35 | Intent intent = new Intent(Intent.ACTION_VIEW);
36 | intent.setData(Uri.parse("http://api.whatsapp.com/send?phone="+num+"&text="+ text));
37 | startActivity(intent);
38 | }
39 | else
40 | {
41 | Toast.makeText(MainActivity.this, "Whatsapp is not installed!", Toast.LENGTH_SHORT).show();
42 | }
43 | }
44 | });
45 |
46 | }
47 |
48 | private boolean isAppInstalled(String s) {
49 | PackageManager packageManager = getPackageManager();
50 | boolean is_installed;
51 |
52 | try {
53 | packageManager.getPackageInfo(s, PackageManager.GET_ACTIVITIES);
54 | is_installed = true;
55 | } catch (PackageManager.NameNotFoundException e) {
56 | is_installed = false;
57 | e.printStackTrace();
58 | }
59 | return is_installed;
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/Open_Whatsapp/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
18 |
19 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Android_Tutorials
2 | all the source code of android tutorials.
3 |
--------------------------------------------------------------------------------
/Scientific_Calculator/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.s_calculator;
2 |
3 | import androidx.appcompat.app.AppCompatActivity;
4 |
5 | import android.os.Bundle;
6 | import android.view.View;
7 | import android.widget.Button;
8 | import android.widget.TextView;
9 |
10 | public class MainActivity extends AppCompatActivity {
11 | Button b1,b2,b3,b4,b5,b6,b7,b8,b9,b0,bdot,bpi,bequal,bplus,bmin,bmul,bdiv,binv,bsqrt,bsquare,bfact,bln,blog,btan,bcos,bsin,bb1,bb2,bc,bac;
12 | TextView tvmain,tvsec;
13 | String pi = "3.14159265";
14 |
15 | @Override
16 | protected void onCreate(Bundle savedInstanceState) {
17 | super.onCreate(savedInstanceState);
18 | setContentView(R.layout.activity_main);
19 |
20 | b1 = findViewById(R.id.b1);
21 | b2 = findViewById(R.id.b2);
22 | b3 = findViewById(R.id.b3);
23 | b4 = findViewById(R.id.b4);
24 | b5 = findViewById(R.id.b5);
25 | b6 = findViewById(R.id.b6);
26 | b7 = findViewById(R.id.b7);
27 | b8 = findViewById(R.id.b8);
28 | b9 = findViewById(R.id.b9);
29 | b0 = findViewById(R.id.b0);
30 | bpi = findViewById(R.id.bpi);
31 | bdot = findViewById(R.id.bdot);
32 | bequal = findViewById(R.id.bequal);
33 | bplus = findViewById(R.id.bplus);
34 | bmin = findViewById(R.id.bmin);
35 | bmul = findViewById(R.id.bmul);
36 | bdiv = findViewById(R.id.bdiv);
37 | binv = findViewById(R.id.binv);
38 | bsqrt = findViewById(R.id.bsqrt);
39 | bsquare = findViewById(R.id.bsquare);
40 | bfact = findViewById(R.id.bfact);
41 | bln = findViewById(R.id.bln);
42 | blog = findViewById(R.id.blog);
43 | btan = findViewById(R.id.btan);
44 | bsin = findViewById(R.id.bsin);
45 | bcos = findViewById(R.id.bcos);
46 | bb1 = findViewById(R.id.bb1);
47 | bb2 = findViewById(R.id.bb2);
48 | bc = findViewById(R.id.bc);
49 | bac = findViewById(R.id.bac);
50 |
51 | tvmain = findViewById(R.id.tvmain);
52 | tvsec = findViewById(R.id.tvsec);
53 |
54 | //onclick listeners
55 | b1.setOnClickListener(new View.OnClickListener() {
56 | @Override
57 | public void onClick(View v) {
58 | tvmain.setText(tvmain.getText()+"1");
59 | }
60 | });
61 | b2.setOnClickListener(new View.OnClickListener() {
62 | @Override
63 | public void onClick(View v) {
64 | tvmain.setText(tvmain.getText()+"2");
65 | }
66 | });
67 | b3.setOnClickListener(new View.OnClickListener() {
68 | @Override
69 | public void onClick(View v) {
70 | tvmain.setText(tvmain.getText()+"3");
71 | }
72 | });
73 | b4.setOnClickListener(new View.OnClickListener() {
74 | @Override
75 | public void onClick(View v) {
76 | tvmain.setText(tvmain.getText()+"4");
77 | }
78 | });
79 | b5.setOnClickListener(new View.OnClickListener() {
80 | @Override
81 | public void onClick(View v) {
82 | tvmain.setText(tvmain.getText()+"5");
83 | }
84 | });
85 | b6.setOnClickListener(new View.OnClickListener() {
86 | @Override
87 | public void onClick(View v) {
88 | tvmain.setText(tvmain.getText()+"6");
89 | }
90 | });
91 | b7.setOnClickListener(new View.OnClickListener() {
92 | @Override
93 | public void onClick(View v) {
94 | tvmain.setText(tvmain.getText()+"7");
95 | }
96 | });
97 | b8.setOnClickListener(new View.OnClickListener() {
98 | @Override
99 | public void onClick(View v) {
100 | tvmain.setText(tvmain.getText()+"8");
101 | }
102 | });
103 | b9.setOnClickListener(new View.OnClickListener() {
104 | @Override
105 | public void onClick(View v) {
106 | tvmain.setText(tvmain.getText()+"9");
107 | }
108 | });
109 | b0.setOnClickListener(new View.OnClickListener() {
110 | @Override
111 | public void onClick(View v) {
112 | tvmain.setText(tvmain.getText()+"0");
113 | }
114 | });
115 | bdot.setOnClickListener(new View.OnClickListener() {
116 | @Override
117 | public void onClick(View v) {
118 | tvmain.setText(tvmain.getText()+".");
119 | }
120 | });
121 | bac.setOnClickListener(new View.OnClickListener() {
122 | @Override
123 | public void onClick(View v) {
124 | tvmain.setText("");
125 | tvsec.setText("");
126 | }
127 | });
128 | bc.setOnClickListener(new View.OnClickListener() {
129 | @Override
130 | public void onClick(View v) {
131 | String val = tvmain.getText().toString();
132 | val = val.substring(0, val.length() - 1);
133 | tvmain.setText(val);
134 | }
135 | });
136 | bplus.setOnClickListener(new View.OnClickListener() {
137 | @Override
138 | public void onClick(View v) {
139 | tvmain.setText(tvmain.getText()+"+");
140 | }
141 | });
142 | bmin.setOnClickListener(new View.OnClickListener() {
143 | @Override
144 | public void onClick(View v) {
145 | tvmain.setText(tvmain.getText()+"-");
146 | }
147 | });
148 | bmul.setOnClickListener(new View.OnClickListener() {
149 | @Override
150 | public void onClick(View v) {
151 | tvmain.setText(tvmain.getText()+"×");
152 | }
153 | });
154 | bdiv.setOnClickListener(new View.OnClickListener() {
155 | @Override
156 | public void onClick(View v) {
157 | tvmain.setText(tvmain.getText()+"÷");
158 | }
159 | });
160 | bsqrt.setOnClickListener(new View.OnClickListener() {
161 | @Override
162 | public void onClick(View v) {
163 | String val = tvmain.getText().toString();
164 | double r = Math.sqrt(Double.parseDouble(val));
165 | tvmain.setText(String.valueOf(r));
166 | }
167 | });
168 | bb1.setOnClickListener(new View.OnClickListener() {
169 | @Override
170 | public void onClick(View v) {
171 | tvmain.setText(tvmain.getText()+"(");
172 | }
173 | });
174 | bb2.setOnClickListener(new View.OnClickListener() {
175 | @Override
176 | public void onClick(View v) {
177 | tvmain.setText(tvmain.getText()+")");
178 | }
179 | });
180 | bpi.setOnClickListener(new View.OnClickListener() {
181 | @Override
182 | public void onClick(View v) {
183 | tvsec.setText(bpi.getText());
184 | tvmain.setText(tvmain.getText()+pi);
185 | }
186 | });
187 | bsin.setOnClickListener(new View.OnClickListener() {
188 | @Override
189 | public void onClick(View v) {
190 | tvmain.setText(tvmain.getText()+"sin");
191 | }
192 | });
193 | bcos.setOnClickListener(new View.OnClickListener() {
194 | @Override
195 | public void onClick(View v) {
196 | tvmain.setText(tvmain.getText()+"cos");
197 | }
198 | });
199 | btan.setOnClickListener(new View.OnClickListener() {
200 | @Override
201 | public void onClick(View v) {
202 | tvmain.setText(tvmain.getText()+"tan");
203 | }
204 | });
205 | binv.setOnClickListener(new View.OnClickListener() {
206 | @Override
207 | public void onClick(View v) {
208 | tvmain.setText(tvmain.getText()+"^"+"(-1)");
209 | }
210 | });
211 | bfact.setOnClickListener(new View.OnClickListener() {
212 | @Override
213 | public void onClick(View v) {
214 | int val = Integer.parseInt(tvmain.getText().toString());
215 | int fact = factorial(val);
216 | tvmain.setText(String.valueOf(fact));
217 | tvsec.setText(val+"!");
218 | }
219 | });
220 | bsquare.setOnClickListener(new View.OnClickListener() {
221 | @Override
222 | public void onClick(View v) {
223 | double d = Double.parseDouble(tvmain.getText().toString());
224 | double square = d*d;
225 | tvmain.setText(String.valueOf(square));
226 | tvsec.setText(d+"²");
227 | }
228 | });
229 | bln.setOnClickListener(new View.OnClickListener() {
230 | @Override
231 | public void onClick(View v) {
232 | tvmain.setText(tvmain.getText()+"ln");
233 | }
234 | });
235 | blog.setOnClickListener(new View.OnClickListener() {
236 | @Override
237 | public void onClick(View v) {
238 | tvmain.setText(tvmain.getText()+"log");
239 | }
240 | });
241 | bequal.setOnClickListener(new View.OnClickListener() {
242 | @Override
243 | public void onClick(View v) {
244 | String val = tvmain.getText().toString();
245 | String replacedstr = val.replace('÷','/').replace('×','*');
246 | double result = eval(replacedstr);
247 | tvmain.setText(String.valueOf(result));
248 | tvsec.setText(val);
249 | }
250 | });
251 |
252 | }
253 |
254 | //factorial function
255 | int factorial(int n)
256 | {
257 | return (n==1 || n==0) ? 1 : n*factorial(n-1);
258 | }
259 |
260 |
261 | //eval function
262 | public static double eval(final String str) {
263 | return new Object() {
264 | int pos = -1, ch;
265 |
266 | void nextChar() {
267 | ch = (++pos < str.length()) ? str.charAt(pos) : -1;
268 | }
269 |
270 | boolean eat(int charToEat) {
271 | while (ch == ' ') nextChar();
272 | if (ch == charToEat) {
273 | nextChar();
274 | return true;
275 | }
276 | return false;
277 | }
278 |
279 | double parse() {
280 | nextChar();
281 | double x = parseExpression();
282 | if (pos < str.length()) throw new RuntimeException("Unexpected: " + (char)ch);
283 | return x;
284 | }
285 |
286 | // Grammar:
287 | // expression = term | expression `+` term | expression `-` term
288 | // term = factor | term `*` factor | term `/` factor
289 | // factor = `+` factor | `-` factor | `(` expression `)`
290 | // | number | functionName factor | factor `^` factor
291 |
292 | double parseExpression() {
293 | double x = parseTerm();
294 | for (;;) {
295 | if (eat('+')) x += parseTerm(); // addition
296 | else if (eat('-')) x -= parseTerm(); // subtraction
297 | else return x;
298 | }
299 | }
300 |
301 | double parseTerm() {
302 | double x = parseFactor();
303 | for (;;) {
304 | if (eat('*')) x *= parseFactor(); // multiplication
305 | else if (eat('/')) x /= parseFactor(); // division
306 | else return x;
307 | }
308 | }
309 |
310 | double parseFactor() {
311 | if (eat('+')) return parseFactor(); // unary plus
312 | if (eat('-')) return -parseFactor(); // unary minus
313 |
314 | double x;
315 | int startPos = this.pos;
316 | if (eat('(')) { // parentheses
317 | x = parseExpression();
318 | eat(')');
319 | } else if ((ch >= '0' && ch <= '9') || ch == '.') { // numbers
320 | while ((ch >= '0' && ch <= '9') || ch == '.') nextChar();
321 | x = Double.parseDouble(str.substring(startPos, this.pos));
322 | } else if (ch >= 'a' && ch <= 'z') { // functions
323 | while (ch >= 'a' && ch <= 'z') nextChar();
324 | String func = str.substring(startPos, this.pos);
325 | x = parseFactor();
326 | if (func.equals("sqrt")) x = Math.sqrt(x);
327 | else if (func.equals("sin")) x = Math.sin(Math.toRadians(x));
328 | else if (func.equals("cos")) x = Math.cos(Math.toRadians(x));
329 | else if (func.equals("tan")) x = Math.tan(Math.toRadians(x));
330 | else if (func.equals("log")) x = Math.log10(x);
331 | else if (func.equals("ln")) x = Math.log(x);
332 | else throw new RuntimeException("Unknown function: " + func);
333 | } else {
334 | throw new RuntimeException("Unexpected: " + (char)ch);
335 | }
336 |
337 | if (eat('^')) x = Math.pow(x, parseFactor()); // exponentiation
338 |
339 | return x;
340 | }
341 | }.parse();
342 | }
343 | }
344 |
--------------------------------------------------------------------------------
/Scientific_Calculator/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
23 |
24 |
25 |
38 |
39 |
40 |
45 |
50 |
55 |
60 |
71 |
82 |
93 |
104 |
105 |
106 |
111 |
116 |
128 |
140 |
152 |
164 |
176 |
177 |
178 |
183 |
188 |
200 |
212 |
224 |
236 |
247 |
248 |
249 |
254 |
259 |
270 |
281 |
292 |
303 |
304 |
305 |
310 |
315 |
326 |
337 |
348 |
359 |
360 |
361 |
366 |
371 |
382 |
393 |
404 |
415 |
416 |
417 |
422 |
427 |
438 |
449 |
460 |
471 |
472 |
473 |
474 |
475 |
476 |
--------------------------------------------------------------------------------
/Scientific_Calculator/eval_func.txt:
--------------------------------------------------------------------------------
1 | //eval function
2 | public static double eval(final String str) {
3 | return new Object() {
4 | int pos = -1, ch;
5 |
6 | void nextChar() {
7 | ch = (++pos < str.length()) ? str.charAt(pos) : -1;
8 | }
9 |
10 | boolean eat(int charToEat) {
11 | while (ch == ' ') nextChar();
12 | if (ch == charToEat) {
13 | nextChar();
14 | return true;
15 | }
16 | return false;
17 | }
18 |
19 | double parse() {
20 | nextChar();
21 | double x = parseExpression();
22 | if (pos < str.length()) throw new RuntimeException("Unexpected: " + (char)ch);
23 | return x;
24 | }
25 |
26 | // Grammar:
27 | // expression = term | expression `+` term | expression `-` term
28 | // term = factor | term `*` factor | term `/` factor
29 | // factor = `+` factor | `-` factor | `(` expression `)`
30 | // | number | functionName factor | factor `^` factor
31 |
32 | double parseExpression() {
33 | double x = parseTerm();
34 | for (;;) {
35 | if (eat('+')) x += parseTerm(); // addition
36 | else if (eat('-')) x -= parseTerm(); // subtraction
37 | else return x;
38 | }
39 | }
40 |
41 | double parseTerm() {
42 | double x = parseFactor();
43 | for (;;) {
44 | if (eat('*')) x *= parseFactor(); // multiplication
45 | else if (eat('/')) x /= parseFactor(); // division
46 | else return x;
47 | }
48 | }
49 |
50 | double parseFactor() {
51 | if (eat('+')) return parseFactor(); // unary plus
52 | if (eat('-')) return -parseFactor(); // unary minus
53 |
54 | double x;
55 | int startPos = this.pos;
56 | if (eat('(')) { // parentheses
57 | x = parseExpression();
58 | eat(')');
59 | } else if ((ch >= '0' && ch <= '9') || ch == '.') { // numbers
60 | while ((ch >= '0' && ch <= '9') || ch == '.') nextChar();
61 | x = Double.parseDouble(str.substring(startPos, this.pos));
62 | } else if (ch >= 'a' && ch <= 'z') { // functions
63 | while (ch >= 'a' && ch <= 'z') nextChar();
64 | String func = str.substring(startPos, this.pos);
65 | x = parseFactor();
66 | if (func.equals("sqrt")) x = Math.sqrt(x);
67 | else if (func.equals("sin")) x = Math.sin(Math.toRadians(x));
68 | else if (func.equals("cos")) x = Math.cos(Math.toRadians(x));
69 | else if (func.equals("tan")) x = Math.tan(Math.toRadians(x));
70 | else if (func.equals("log")) x = Math.log10(x);
71 | else if (func.equals("ln")) x = Math.log(x);
72 | else throw new RuntimeException("Unknown function: " + func);
73 | } else {
74 | throw new RuntimeException("Unexpected: " + (char)ch);
75 | }
76 |
77 | if (eat('^')) x = Math.pow(x, parseFactor()); // exponentiation
78 |
79 | return x;
80 | }
81 | }.parse();
82 | }
--------------------------------------------------------------------------------