Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,31 @@ android {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
buildTypes.each{
it.buildConfigField('String','API_KEY','"[ApiKey]"')
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/INDEX.LIST'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
}

buildFeatures {
viewBinding true
}

aaptOptions {
noCompress "json"
}
}

dependencies {
Expand All @@ -59,4 +72,11 @@ dependencies {
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

implementation platform('com.google.cloud:libraries-bom:20.3.0')
implementation 'com.google.cloud:google-cloud-vision'
implementation 'io.grpc:grpc-netty-shaded:1.24.0'
implementation 'io.grpc:grpc-okhttp:1.24.0'


}
2 changes: 0 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
android:supportsRtl="true"
android:theme="@style/Theme.RIDProject">
<activity android:name=".ui.activity.SignInActivity">

<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/assets/jsons/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// rid-project-cb50d-5fdfabd30d79.jsoon 파일 내용 복붙하면 됨
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.example.rid_project.repository;

import android.util.Log;

import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.cloud.vision.v1.AnnotateImageRequest;
import com.google.cloud.vision.v1.AnnotateImageResponse;
import com.google.cloud.vision.v1.BatchAnnotateImagesResponse;
import com.google.cloud.vision.v1.EntityAnnotation;
import com.google.cloud.vision.v1.Feature;
import com.google.cloud.vision.v1.Image;
import com.google.cloud.vision.v1.ImageAnnotatorClient;
import com.google.cloud.vision.v1.ImageAnnotatorSettings;
import com.google.cloud.vision.v1.ImageSource;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class DetectTextGcs {

// Detects text in the specified remote image on Google Cloud Storage.
public static void detectTextGcs(FixedCredentialsProvider f) throws IOException {

List<AnnotateImageRequest> requests = new ArrayList<>();

String gcsPath = "gs://rid_bucket/a.jpg";


ImageSource imgSource = ImageSource.newBuilder().setGcsImageUri(gcsPath).build();
Image img = Image.newBuilder().setSource(imgSource).build();

Feature feat = Feature.newBuilder().setType(Feature.Type.TEXT_DETECTION).build();

AnnotateImageRequest request =
AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
requests.add(request);

Log.e("test", "2");


ImageAnnotatorSettings imageAnnotatorSettings = null;
ImageAnnotatorClient client = null;

try {

imageAnnotatorSettings = ImageAnnotatorSettings.newBuilder()
.setCredentialsProvider(f).build();
client = ImageAnnotatorClient.create(imageAnnotatorSettings);

BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
List<AnnotateImageResponse> responses = response.getResponsesList();

Log.e("test", "1");
for (AnnotateImageResponse res : responses) {
if (res.hasError()) {
System.out.format("Error: %s%n", res.getError().getMessage());
return ;
}

// For full list of available annotations, see http://g.co/cloud/vision/docs
for (EntityAnnotation annotation : res.getTextAnnotationsList()) {
System.out.format("Text: %s%n", annotation.getDescription());
System.out.format("Position : %s%n", annotation.getBoundingPoly());
}
}
}catch (IOException e){
e.printStackTrace();
}

}

}
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
package com.example.rid_project.ui.activity;

import android.content.Intent;
import android.content.res.AssetFileDescriptor;
import android.content.res.AssetManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.FrameLayout;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.example.rid_project.repository.DetectTextGcs;
import com.example.rid_project.ui.fragment.BottomNavigationFragment;
import com.example.rid_project.ui.fragment.MainFragment;
import com.example.rid_project.R;
import com.example.rid_project.databinding.ActivityMainBinding;
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;


public class MainActivity extends AppCompatActivity {
private FragmentManager fragmentManager; // 프래그먼트 매니저
Expand All @@ -24,6 +35,7 @@ public class MainActivity extends AppCompatActivity {
private FrameLayout fragmentView;
private FragmentTransaction transaction;
private TextView textViewMain;
private DetectTextGcs ex;


@Override
Expand All @@ -46,5 +58,39 @@ protected void onCreate(Bundle savedInstanceState) {
//textViewMain = fragment_view.findViewById(R.id.textView_main_topBar); // 책장 유저이름 칸
// textViewMain.setText(userName + "의 책장");

Log.e("MainActivity","성공");
// System.out.format("Position : %s%n", );

try {
launch();
} catch (IOException e) {
e.printStackTrace();
}
}

private void launch() throws IOException {
AssetManager am = getAssets();
FileInputStream credentialsStream = null;

try {
AssetFileDescriptor fileDescriptor = am.openFd("jsons/test.json");
credentialsStream = fileDescriptor.createInputStream();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

GoogleCredentials credentials = null;
try {
credentials = GoogleCredentials.fromStream(credentialsStream);
} catch (IOException e) {
e.printStackTrace();
}
FixedCredentialsProvider credentialsProvider = FixedCredentialsProvider.create(credentials);

ex.detectTextGcs(credentialsProvider);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,24 @@

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import com.example.rid_project.R;
import com.example.rid_project.databinding.FragmentReadTextBinding;

public class ReadTextFragment extends Fragment {

private FragmentReadTextBinding binding;


@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
binding = FragmentReadTextBinding.inflate(inflater, container, false);



View view = inflater.inflate(R.layout.fragment_read_text, container, false); //container <-부모 사이즈를 주고 , false=아직 붙이지 않는다.

return view;
return binding.getRoot();

}
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_read_text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
app:layout_constraintStart_toStartOf="parent" />

<TextView
android:id="@+id/textview_book_message"
android:id="@+id/textview_detect"
android:layout_width="335dp"
android:layout_height="437dp"
android:text="나에게는 하나의 목적지가 있다. 유일한 목적지...언제쯤 도착할 수 있을까"
Expand Down