Skip to content

Commit 138ab68

Browse files
committed
1st commit
0 parents  commit 138ab68

38 files changed

+1023
-0
lines changed

SourceCode/.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/libraries
5+
/.idea/modules.xml
6+
/.idea/workspace.xml
7+
.DS_Store
8+
/build
9+
/captures
10+
.externalNativeBuild
539 Bytes
Binary file not shown.

SourceCode/.idea/codeStyles/Project.xml

+29
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SourceCode/.idea/gradle.xml

+18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SourceCode/.idea/misc.xml

+34
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SourceCode/.idea/runConfigurations.xml

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SourceCode/app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

SourceCode/app/build.gradle

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 27
5+
defaultConfig {
6+
applicationId "com.wangsun.android.translator"
7+
minSdkVersion 16
8+
targetSdkVersion 27
9+
versionCode 1
10+
versionName "1.0"
11+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12+
}
13+
buildTypes {
14+
release {
15+
minifyEnabled false
16+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17+
}
18+
}
19+
}
20+
21+
dependencies {
22+
implementation fileTree(dir: 'libs', include: ['*.jar'])
23+
implementation 'com.android.support:appcompat-v7:27.1.1'
24+
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
25+
testImplementation 'junit:junit:4.12'
26+
androidTestImplementation 'com.android.support.test:runner:1.0.2'
27+
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
28+
}

SourceCode/app/proguard-rules.pro

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.wangsun.android.translator">
4+
5+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
6+
<uses-permission android:name="android.permission.INTERNET"/>
7+
8+
<application
9+
android:allowBackup="true"
10+
android:icon="@mipmap/ic_launcher"
11+
android:label="@string/app_name"
12+
android:roundIcon="@mipmap/ic_launcher_round"
13+
android:supportsRtl="true"
14+
android:theme="@style/AppTheme">
15+
<activity android:name=".Main"
16+
android:windowSoftInputMode="stateHidden">
17+
<intent-filter>
18+
<action android:name="android.intent.action.MAIN" />
19+
20+
<category android:name="android.intent.category.LAUNCHER" />
21+
</intent-filter>
22+
</activity>
23+
</application>
24+
25+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package com.wangsun.android.translator;
2+
3+
import android.app.ProgressDialog;
4+
import android.content.Context;
5+
import android.os.AsyncTask;
6+
import android.widget.TextView;
7+
8+
import org.json.JSONArray;
9+
import org.json.JSONException;
10+
import org.json.JSONObject;
11+
12+
import java.io.BufferedReader;
13+
import java.io.IOException;
14+
import java.io.InputStream;
15+
import java.io.InputStreamReader;
16+
import java.io.UnsupportedEncodingException;
17+
import java.net.HttpURLConnection;
18+
import java.net.MalformedURLException;
19+
import java.net.ProtocolException;
20+
import java.net.URL;
21+
22+
23+
/**
24+
* Created by WANGSUN on 03-Aug-18.
25+
*/
26+
27+
public class HttpRequest extends AsyncTask<String,Void,String> {
28+
String API_KEY="Your API KEY";
29+
30+
Context context;
31+
32+
JSONObject root_object,data_object,translated_object;
33+
JSONArray jsonArray;
34+
35+
TextView txt_hindi;
36+
37+
ProgressDialog progressDialog;
38+
39+
40+
public HttpRequest(Context context, TextView txt_hindi){
41+
this.context=context;
42+
this.txt_hindi=txt_hindi;
43+
}
44+
45+
@Override
46+
protected void onPreExecute() {
47+
progressDialog=new ProgressDialog(context);
48+
progressDialog.setCancelable(false);
49+
progressDialog.setMessage("Converting....");
50+
progressDialog.show();
51+
}
52+
53+
@Override
54+
protected String doInBackground(String... params) {
55+
String temp_input=params[0];
56+
57+
try {
58+
URL url = new URL("https://translation.googleapis.com/language/translate/v2?target=hi&key="+API_KEY+"&q="+temp_input);
59+
HttpURLConnection httpURLConnection=(HttpURLConnection) url.openConnection();
60+
InputStream inputStream = httpURLConnection.getInputStream();
61+
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
62+
StringBuilder stringBuilder = new StringBuilder();
63+
64+
String json_string;
65+
while((json_string=bufferedReader.readLine())!=null){
66+
stringBuilder.append(json_string+"\n");
67+
}
68+
69+
bufferedReader.close();
70+
inputStream.close();
71+
httpURLConnection.disconnect();
72+
return stringBuilder.toString().trim();
73+
}
74+
75+
catch (MalformedURLException e) {
76+
e.printStackTrace();
77+
} catch (UnsupportedEncodingException e) {
78+
e.printStackTrace();
79+
} catch (ProtocolException e) {
80+
e.printStackTrace();
81+
} catch (IOException e) {
82+
e.printStackTrace();
83+
}
84+
return null;
85+
}
86+
87+
@Override
88+
protected void onProgressUpdate(Void... values) {
89+
super.onProgressUpdate(values);
90+
}
91+
92+
@Override
93+
protected void onPostExecute(String result) {
94+
convertJson(result);
95+
}
96+
97+
private void convertJson(String result){
98+
try {
99+
root_object = new JSONObject(result);
100+
data_object = root_object.getJSONObject("data"); //new JSONObject("data");
101+
jsonArray = data_object.getJSONArray("translations");
102+
translated_object = jsonArray.getJSONObject(0);
103+
String temp_hindi=translated_object.getString("translatedText");
104+
105+
txt_hindi.setText(temp_hindi);
106+
107+
108+
} catch (JSONException e) {
109+
e.printStackTrace();
110+
}
111+
112+
progressDialog.dismiss();
113+
}
114+
}

0 commit comments

Comments
 (0)