├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── dictionaries │ └── Steven.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── scopes │ └── scope_settings.xml └── vcs.xml ├── ImageSearch.iml ├── README.md ├── app ├── .gitignore ├── app.iml ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ ├── com │ │ └── stevenschoen │ │ │ └── imagesearchernew │ │ │ ├── AboutActivity.java │ │ │ ├── BingSearchInterface.java │ │ │ ├── FakeGoogleSearchInterface.java │ │ │ ├── FixedFileProvider.java │ │ │ ├── GoogleSearchInterface.java │ │ │ ├── ImagesAdapter.java │ │ │ ├── MainActivity.java │ │ │ ├── PublicFragmentPagerAdapter.java │ │ │ ├── ResultActivity.java │ │ │ ├── ResultFragment.java │ │ │ ├── SearchInterface.java │ │ │ ├── Utils.java │ │ │ └── model │ │ │ ├── Image.java │ │ │ ├── Search.java │ │ │ ├── bing │ │ │ ├── BingImage.java │ │ │ └── BingSearchResponse.java │ │ │ └── google │ │ │ ├── GoogleImage.java │ │ │ └── GoogleSearchResponse.java │ └── de │ │ └── ankri │ │ └── views │ │ └── AutoScaleTextView.java │ └── res │ ├── animator-v21 │ └── fab_state_list_anim.xml │ ├── drawable-hdpi │ ├── fab_shadow_mini.png │ ├── fab_shadow_normal.png │ ├── ic_about_action_github.png │ ├── ic_about_action_rate.png │ ├── ic_fab_back.png │ ├── ic_fab_select.png │ └── ic_launcher.png │ ├── drawable-mdpi │ ├── fab_shadow_mini.png │ ├── fab_shadow_normal.png │ ├── ic_about_action_github.png │ ├── ic_about_action_rate.png │ ├── ic_fab_back.png │ ├── ic_fab_select.png │ └── ic_launcher.png │ ├── drawable-nodpi │ └── more.png │ ├── drawable-v21 │ ├── fab_bg.xml │ └── fab_shadow.xml │ ├── drawable-xhdpi │ ├── fab_shadow_mini.png │ ├── fab_shadow_normal.png │ ├── ic_about_action_github.png │ ├── ic_about_action_rate.png │ ├── ic_fab_back.png │ ├── ic_fab_select.png │ └── ic_launcher.png │ ├── drawable-xxhdpi │ ├── fab_shadow_mini.png │ ├── fab_shadow_normal.png │ ├── ic_about_action_github.png │ ├── ic_about_action_rate.png │ ├── ic_fab_back.png │ ├── ic_fab_select.png │ └── ic_launcher.png │ ├── drawable-xxxhdpi │ ├── fab_shadow_normal.png │ └── ic_launcher.png │ ├── drawable │ └── fab_bg.xml │ ├── layout-v21 │ ├── fab_back.xml │ └── fab_select.xml │ ├── layout │ ├── about.xml │ ├── about_actions.xml │ ├── fab_back.xml │ ├── fab_select.xml │ ├── imageresult_details.xml │ ├── imageresult_full.xml │ ├── imageresult_grid.xml │ ├── imageresult_pager.xml │ └── main.xml │ ├── menu │ ├── menu_main.xml │ └── menu_result.xml │ ├── values-v21 │ └── dimens.xml │ ├── values-w400dp │ └── dimens.xml │ ├── values-w600dp │ └── dimens.xml │ ├── values-w820dp │ └── dimens.xml │ ├── values │ ├── attrs.xml │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml │ └── xml │ └── filepaths.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── promo.psd ├── settings.gradle └── web_icon.psd /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | /.idea/workspace.xml 4 | /.idea/libraries 5 | .DS_Store 6 | /build 7 | app/crashlytics.properties 8 | app/src/main/assets/crashlytics-build.properties 9 | app/src/main/res/values/com_crashlytics_export_strings.xml 10 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | Image Search -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/dictionaries/Steven.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/scopes/scope_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ImageSearch.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #Image Searcher 2 | 3 | Send anything from Google Image Search right from your favorite apps! 4 | 5 | Bug reports and pull requests always welcome. 6 | 7 | Free on the Play Store: https://play.google.com/store/apps/details?id=com.stevenschoen.imagesearchernew 8 | 9 | Don't have the right picture for a message or email? 10 | Attach a photo and select Image Searcher from the list. Then, search through Google Images' massive collection and pick what you want! 11 | It's a lot quicker than searching for the image, downloading it, sharing it, and picking the app you were just in before you were interrupted. 12 | 13 | Works great with Messaging, Hangouts, Gmail, and many others! 14 | 15 | 16 | ###Libraries used: 17 | 18 | Ion by Koush: https://github.com/koush/ion 19 | 20 | Retrofit by Square: http://square.github.io/retrofit/ 21 | 22 | Crashlytics: https://www.crashlytics.com/ 23 | 24 | PhotoView by Chris Banes: https://github.com/chrisbanes/PhotoView 25 | 26 | Material Dialogs by Aidan Follestad: https://github.com/afollestad/material-dialogs 27 | 28 | Play Services by Google: https://developer.android.com/google/play-services/index.html 29 | 30 | Android Support Library by Google: http://developer.android.com/tools/support-library/index.html 31 | 32 | ###License 33 | 34 | Copyright 2014 Steven Schoen 35 | 36 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 37 | 38 | http://www.apache.org/licenses/LICENSE-2.0 39 | 40 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 41 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/app.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'crashlytics' 3 | 4 | android { 5 | compileSdkVersion 21 6 | buildToolsVersion "21.1.2" 7 | 8 | defaultConfig { 9 | applicationId "com.stevenschoen.imagesearchernew" 10 | minSdkVersion 15 11 | targetSdkVersion 21 12 | versionCode 8 13 | versionName "0.3.1" 14 | } 15 | 16 | buildTypes { 17 | release { 18 | minifyEnabled false 19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 20 | } 21 | } 22 | } 23 | 24 | dependencies { 25 | compile 'com.crashlytics.android:crashlytics:1.+' 26 | compile 'com.android.support:support-v13:21.0.3' 27 | compile 'com.android.support:appcompat-v7:21.0.3' 28 | compile 'com.android.support:recyclerview-v7:21.0.3' 29 | compile 'com.afollestad:material-dialogs:0.4.7' 30 | compile 'com.google.android.gms:play-services-base:6.5.+' 31 | compile 'commons-io:commons-io:2.4' 32 | compile 'com.squareup.retrofit:retrofit:1.8.0' 33 | compile 'com.squareup.okhttp:okhttp:2.1.0' 34 | compile 'com.squareup.okhttp:okhttp-urlconnection:2.1.0' 35 | compile 'com.koushikdutta.ion:ion:2.0.2' 36 | compile 'com.github.chrisbanes.photoview:library:1.2.2' 37 | } -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\tools\android-sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 12 | 17 | 20 | 21 | 22 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 50 | 53 | 54 | 58 | 61 | 62 | 63 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /app/src/main/java/com/stevenschoen/imagesearchernew/AboutActivity.java: -------------------------------------------------------------------------------- 1 | package com.stevenschoen.imagesearchernew; 2 | 3 | import android.content.Intent; 4 | import android.content.pm.PackageManager; 5 | import android.net.Uri; 6 | import android.os.Bundle; 7 | import android.support.v4.app.NavUtils; 8 | import android.support.v7.app.ActionBarActivity; 9 | import android.view.View; 10 | import android.widget.TextView; 11 | 12 | import com.google.android.gms.common.ConnectionResult; 13 | import com.google.android.gms.common.GooglePlayServicesUtil; 14 | 15 | public class AboutActivity extends ActionBarActivity { 16 | 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | setContentView(R.layout.about); 21 | 22 | View backButton = findViewById(R.id.about_back); 23 | Utils.setupFab(backButton); 24 | backButton.setOnClickListener(new View.OnClickListener() { 25 | @Override 26 | public void onClick(View v) { 27 | NavUtils.navigateUpFromSameTask(AboutActivity.this); 28 | } 29 | }); 30 | 31 | View rateButton = findViewById(R.id.about_actions_rate_holder); 32 | if (GooglePlayServicesUtil.isGooglePlayServicesAvailable(this) == ConnectionResult.SUCCESS) { 33 | rateButton.setOnClickListener(new View.OnClickListener() { 34 | @Override 35 | public void onClick(View v) { 36 | Uri uri = Uri.parse("market://details?id=" + getPackageName()); 37 | Intent rateIntent = new Intent(Intent.ACTION_VIEW, uri); 38 | startActivity(rateIntent); 39 | } 40 | }); 41 | } else { 42 | rateButton.setVisibility(View.GONE); 43 | } 44 | 45 | View githubButton = findViewById(R.id.about_actions_github_holder); 46 | githubButton.setOnClickListener(new View.OnClickListener() { 47 | @Override 48 | public void onClick(View v) { 49 | Intent githubIntent = new Intent(Intent.ACTION_VIEW); 50 | githubIntent.setData(Uri.parse("https://github.com/DSteve595/Image-Searcher")); 51 | startActivity(githubIntent); 52 | } 53 | }); 54 | 55 | TextView versionText = (TextView) findViewById(R.id.about_version); 56 | try { 57 | String version = getPackageManager().getPackageInfo(getPackageName(), 0).versionName; 58 | versionText.setText(getString(R.string.version_x, version)); 59 | } catch (PackageManager.NameNotFoundException e) { 60 | e.printStackTrace(); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /app/src/main/java/com/stevenschoen/imagesearchernew/BingSearchInterface.java: -------------------------------------------------------------------------------- 1 | package com.stevenschoen.imagesearchernew; 2 | 3 | import com.stevenschoen.imagesearchernew.model.bing.BingSearchResponse; 4 | 5 | import retrofit.http.GET; 6 | import retrofit.http.Query; 7 | 8 | public interface BingSearchInterface { 9 | public static final String BASE_URL = "https://api.datamarket.azure.com/Bing/Search/v1"; 10 | public static final String API_KEY = "IzzjGEoDbc6kUVakkclWmrAYURcokmSrevY8bzm+R+U"; 11 | 12 | public static final String SOURCE_IMAGE = "image"; 13 | public static final String FORMAT_JSON = "json"; 14 | 15 | @GET("/Composite") 16 | public BingSearchResponse search(@Query("Sources") String sources, 17 | @Query("Query") String query, 18 | @Query("$skip") long skip, 19 | @Query("$format") String format); 20 | } -------------------------------------------------------------------------------- /app/src/main/java/com/stevenschoen/imagesearchernew/FakeGoogleSearchInterface.java: -------------------------------------------------------------------------------- 1 | package com.stevenschoen.imagesearchernew; 2 | 3 | import com.stevenschoen.imagesearchernew.model.google.GoogleImage; 4 | import com.stevenschoen.imagesearchernew.model.google.GoogleSearchResponse; 5 | 6 | public class FakeGoogleSearchInterface { 7 | 8 | private static final int ITEMS_COUNT = 10; 9 | 10 | public GoogleSearchResponse search() { 11 | GoogleSearchResponse response = new GoogleSearchResponse(); 12 | 13 | makeItems(response); 14 | makeQueries(response); 15 | makeSearchInformation(response); 16 | 17 | try { 18 | Thread.sleep(1000); 19 | } catch (InterruptedException e) { 20 | e.printStackTrace(); 21 | } 22 | 23 | return response; 24 | } 25 | 26 | private void makeItems(GoogleSearchResponse response) { 27 | GoogleImage[] items = new GoogleImage[ITEMS_COUNT]; 28 | 29 | for (int i = 0; i < items.length; i++) { 30 | GoogleImage result = new GoogleImage(); 31 | result.title = "Test result " + i; 32 | result.link = "http://www.breastcancerwellness.org/bcw/wp-content/uploads/2014/09/test.gif"; 33 | result.displayLink = "www.test.com"; 34 | result.mime = "image/gif"; 35 | result.image = new GoogleImage.Image(); 36 | result.image.height = 828; 37 | result.image.width = 1646; 38 | result.image.byteSize = 22544; 39 | result.image.thumbnailLink = "https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcQ71ukeTGCPLuClWd6MetTtQ0-0mwzo3rn1ug0MUnbpXmKnwNuuBnSWXHU"; 40 | 41 | items[i] = result; 42 | } 43 | 44 | response.items = items; 45 | } 46 | 47 | private void makeQueries(GoogleSearchResponse response) { 48 | GoogleSearchResponse.GoogleQueries queries = new GoogleSearchResponse.GoogleQueries(); 49 | 50 | GoogleSearchResponse.GoogleQueries.GooglePage currentPage = new GoogleSearchResponse.GoogleQueries.GooglePage(); 51 | currentPage.count = ITEMS_COUNT; 52 | currentPage.startIndex = 1; 53 | queries.request[0] = currentPage; 54 | 55 | response.queries = queries; 56 | } 57 | 58 | private void makeSearchInformation(GoogleSearchResponse response) { 59 | GoogleSearchResponse.GoogleSearchInformation searchInformation = new GoogleSearchResponse.GoogleSearchInformation(); 60 | 61 | searchInformation.totalResults = 7000000; 62 | 63 | response.searchInformation = searchInformation; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /app/src/main/java/com/stevenschoen/imagesearchernew/FixedFileProvider.java: -------------------------------------------------------------------------------- 1 | package com.stevenschoen.imagesearchernew; 2 | 3 | import android.database.Cursor; 4 | import android.database.MatrixCursor; 5 | import android.net.Uri; 6 | import android.provider.MediaStore; 7 | 8 | import java.util.Arrays; 9 | 10 | /* Found at http://stackoverflow.com/a/25020642/919716 */ 11 | 12 | public class FixedFileProvider extends android.support.v4.content.FileProvider { 13 | 14 | @Override 15 | public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { 16 | Cursor source = super.query(uri, projection, selection, selectionArgs, sortOrder); 17 | 18 | String[] columnNames = source.getColumnNames(); 19 | String[] newColumnNames = columnNamesWithData(columnNames); 20 | MatrixCursor cursor = new MatrixCursor(newColumnNames, source.getCount()); 21 | 22 | source.moveToPosition(-1); 23 | while (source.moveToNext()) { 24 | MatrixCursor.RowBuilder row = cursor.newRow(); 25 | for (int i = 0; i < columnNames.length; i++) { 26 | row.add(source.getString(i)); 27 | } 28 | } 29 | 30 | return cursor; 31 | } 32 | 33 | private String[] columnNamesWithData(String[] columnNames) { 34 | for (String columnName : columnNames) 35 | if (MediaStore.MediaColumns.DATA.equals(columnName)) 36 | return columnNames; 37 | 38 | String[] newColumnNames = Arrays.copyOf(columnNames, columnNames.length + 1); 39 | newColumnNames[columnNames.length] = MediaStore.MediaColumns.DATA; 40 | return newColumnNames; 41 | } 42 | } -------------------------------------------------------------------------------- /app/src/main/java/com/stevenschoen/imagesearchernew/GoogleSearchInterface.java: -------------------------------------------------------------------------------- 1 | package com.stevenschoen.imagesearchernew; 2 | 3 | import com.stevenschoen.imagesearchernew.model.google.GoogleSearchResponse; 4 | 5 | import retrofit.http.GET; 6 | import retrofit.http.Query; 7 | 8 | public interface GoogleSearchInterface { 9 | public static final String BASE_URL = "https://www.googleapis.com/customsearch"; 10 | public static final String API_KEY = "AIzaSyCCuxxVLzm2sZP-adhRNYKeSck1mMMgsAM"; // Allows all 11 | // public static final String API_KEY = "AIzaSyBxS4Ocy29KrmGZkr2uibqc78JBdtEyxz8"; // Android, not working 12 | public static final String CUSTOM_SEARCH_ID = "006276545175240274241:4xzxdv12bjw"; 13 | 14 | public static final String SEARCH_TYPE_IMAGE = "image"; 15 | 16 | @GET("/v1") 17 | public GoogleSearchResponse search(@Query("q") String query, 18 | @Query("start") long startIndex, 19 | @Query("searchType") String searchType); 20 | } -------------------------------------------------------------------------------- /app/src/main/java/com/stevenschoen/imagesearchernew/ImagesAdapter.java: -------------------------------------------------------------------------------- 1 | package com.stevenschoen.imagesearchernew; 2 | 3 | import android.support.v7.widget.RecyclerView; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.ImageView; 8 | 9 | import com.koushikdutta.ion.Ion; 10 | import com.stevenschoen.imagesearchernew.model.Image; 11 | 12 | import java.util.List; 13 | 14 | public class ImagesAdapter extends RecyclerView.Adapter { 15 | 16 | private static final int TYPE_IMAGE = 1; 17 | private static final int TYPE_MORE_BUTTON = 2; 18 | 19 | private MoreImagesCallback moreImagesCallback; 20 | 21 | public List images; 22 | 23 | private OnItemClickListener itemClickListener; 24 | 25 | public ImagesAdapter(List images) { 26 | super(); 27 | this.images = images; 28 | } 29 | 30 | @Override 31 | public ImageHolder onCreateViewHolder(ViewGroup parent, int viewType) { 32 | int layoutResourceId = R.layout.imageresult_grid; 33 | View view = LayoutInflater.from(parent.getContext()).inflate(layoutResourceId, parent, false); 34 | 35 | ImageHolder holder = new ImageHolder(view); 36 | holder.root = view; 37 | holder.image = (ImageView) view.findViewById(R.id.imageresult_grid_image); 38 | 39 | return holder; 40 | } 41 | 42 | @Override 43 | public void onBindViewHolder(final ImageHolder holder, final int position) { 44 | switch (getItemViewType(position)) { 45 | case TYPE_IMAGE: 46 | final Image image = images.get(position); 47 | holder.root.setOnClickListener(new View.OnClickListener() { 48 | @Override 49 | public void onClick(View v) { 50 | if (itemClickListener != null) { 51 | itemClickListener.onItemClick(holder.root, position); 52 | } 53 | } 54 | }); 55 | holder.root.setOnLongClickListener(new View.OnLongClickListener() { 56 | @Override 57 | public boolean onLongClick(View v) { 58 | if (itemClickListener != null) { 59 | itemClickListener.onItemLongClick(holder.root, position); 60 | return true; 61 | } 62 | return false; 63 | } 64 | }); 65 | Ion.with(holder.image.getContext()).load(image.thumbnailLink).withBitmap().fadeIn(true).intoImageView(holder.image); 66 | holder.image.setContentDescription(image.title); 67 | break; 68 | case TYPE_MORE_BUTTON: 69 | holder.root.setOnClickListener(new View.OnClickListener() { 70 | @Override 71 | public void onClick(View v) { 72 | if (moreImagesCallback != null) { 73 | moreImagesCallback.onMoreImagesPressed(); 74 | } 75 | } 76 | }); 77 | holder.root.setOnLongClickListener(null); 78 | holder.image.setImageResource(R.drawable.more); 79 | holder.image.setContentDescription("More"); 80 | } 81 | } 82 | 83 | @Override 84 | public int getItemCount() { 85 | if (images.isEmpty()) { 86 | return 0; 87 | } else { 88 | return images.size() + 1; 89 | } 90 | } 91 | 92 | @Override 93 | public int getItemViewType(int position) { 94 | if (position < images.size()) { 95 | return TYPE_IMAGE; 96 | } else { 97 | return TYPE_MORE_BUTTON; 98 | } 99 | } 100 | 101 | public void setOnItemClickListener(OnItemClickListener itemClickListener) { 102 | this.itemClickListener = itemClickListener; 103 | } 104 | 105 | public interface OnItemClickListener { 106 | public void onItemClick(View view, int position); 107 | public void onItemLongClick(View view, int position); 108 | } 109 | 110 | public void setMoreImagesCallback(MoreImagesCallback callback) { 111 | this.moreImagesCallback = callback; 112 | } 113 | 114 | public static class ImageHolder extends RecyclerView.ViewHolder { 115 | public View root; 116 | public ImageView image; 117 | 118 | public ImageHolder(View itemView) { 119 | super(itemView); 120 | } 121 | } 122 | 123 | public static interface MoreImagesCallback { 124 | public void onMoreImagesPressed(); 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /app/src/main/java/com/stevenschoen/imagesearchernew/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.stevenschoen.imagesearchernew; 2 | 3 | import android.content.Intent; 4 | import android.graphics.Bitmap; 5 | import android.net.Uri; 6 | import android.os.AsyncTask; 7 | import android.os.Bundle; 8 | import android.support.v4.app.ActivityCompat; 9 | import android.support.v4.app.ActivityOptionsCompat; 10 | import android.support.v7.app.ActionBarActivity; 11 | import android.support.v7.widget.GridLayoutManager; 12 | import android.support.v7.widget.RecyclerView; 13 | import android.support.v7.widget.Toolbar; 14 | import android.text.TextUtils; 15 | import android.view.KeyEvent; 16 | import android.view.Menu; 17 | import android.view.MenuItem; 18 | import android.view.View; 19 | import android.view.WindowManager; 20 | import android.view.animation.DecelerateInterpolator; 21 | import android.webkit.MimeTypeMap; 22 | import android.widget.EditText; 23 | import android.widget.ProgressBar; 24 | import android.widget.TextView; 25 | import android.widget.Toast; 26 | 27 | import com.crashlytics.android.Crashlytics; 28 | import com.koushikdutta.async.future.FutureCallback; 29 | import com.koushikdutta.ion.Ion; 30 | import com.stevenschoen.imagesearchernew.model.Image; 31 | import com.stevenschoen.imagesearchernew.model.Search; 32 | 33 | import org.apache.commons.io.FileUtils; 34 | 35 | import java.io.File; 36 | import java.io.IOException; 37 | import java.text.DecimalFormat; 38 | import java.util.ArrayList; 39 | import java.util.List; 40 | 41 | import retrofit.RetrofitError; 42 | 43 | public class MainActivity extends ActionBarActivity { 44 | 45 | private static final String STATE_SEARCH = "search"; 46 | private static final String STATE_IMAGES = "images"; 47 | 48 | private SearchInterface searchInterface; 49 | private SearchInterface.Service searchService; 50 | 51 | private Search currentSearch; 52 | 53 | private RecyclerView imagesGrid; 54 | private ImagesAdapter imagesAdapter; 55 | private ArrayList images; 56 | 57 | private ProgressBar imagesLoading; 58 | private TextView resultsCountText; 59 | private View resultsCountHolder; 60 | 61 | @Override 62 | protected void onCreate(Bundle savedInstanceState) { 63 | super.onCreate(savedInstanceState); 64 | if (!BuildConfig.DEBUG) { 65 | Crashlytics.start(this); 66 | } 67 | setContentView(R.layout.main); 68 | 69 | searchService = SearchInterface.Service.Google; 70 | searchInterface = new SearchInterface(searchService); 71 | 72 | if (savedInstanceState != null) { 73 | if (savedInstanceState.containsKey(STATE_SEARCH)) { 74 | currentSearch = savedInstanceState.getParcelable(STATE_SEARCH); 75 | } 76 | if (savedInstanceState.containsKey(STATE_IMAGES)) { 77 | images = savedInstanceState.getParcelableArrayList(STATE_IMAGES); 78 | } 79 | } 80 | 81 | if (images == null) { 82 | images = new ArrayList<>(); 83 | } 84 | 85 | Toolbar toolbar = (Toolbar) findViewById(R.id.main_toolbar); 86 | setSupportActionBar(toolbar); 87 | 88 | imagesGrid = (RecyclerView) findViewById(R.id.main_imagesgrid); 89 | imagesGrid.setItemAnimator(null); 90 | final RecyclerView.LayoutManager layoutManager = new GridLayoutManager(this, 4); 91 | imagesGrid.setLayoutManager(layoutManager); 92 | imagesAdapter = new ImagesAdapter(images); 93 | imagesAdapter.setOnItemClickListener(new ImagesAdapter.OnItemClickListener() { 94 | @Override 95 | public void onItemClick(View view, int position) { 96 | openImageResult(position, view); 97 | } 98 | 99 | @Override 100 | public void onItemLongClick(View view, int position) { 101 | finishWithResult(images.get(position)); 102 | } 103 | }); 104 | imagesAdapter.setMoreImagesCallback(new ImagesAdapter.MoreImagesCallback() { 105 | @Override 106 | public void onMoreImagesPressed() { 107 | nextPageAsync(); 108 | } 109 | }); 110 | imagesGrid.setAdapter(imagesAdapter); 111 | 112 | imagesLoading = (ProgressBar) findViewById(R.id.main_imagesloading); 113 | 114 | resultsCountText = (TextView) findViewById(R.id.main_resultscount); 115 | resultsCountHolder = findViewById(R.id.main_resultscount_holder); 116 | resultsCountHolder.animate().setInterpolator(new DecelerateInterpolator()); 117 | if (currentSearch != null && currentSearch.totalResults != -1) { 118 | updateResultsCount(false); 119 | } 120 | 121 | EditText searchText = (EditText) findViewById(R.id.main_searchtext); 122 | searchText.setOnEditorActionListener(new TextView.OnEditorActionListener() { 123 | @Override 124 | public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 125 | if (event == null || event.getAction() == KeyEvent.ACTION_DOWN) { 126 | if (!TextUtils.isEmpty(v.getText())) { 127 | searchAsync(v.getText().toString()); 128 | return true; 129 | } 130 | } 131 | return false; 132 | } 133 | }); 134 | 135 | getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); 136 | } 137 | 138 | @Override 139 | public boolean onCreateOptionsMenu(Menu menu) { 140 | super.onCreateOptionsMenu(menu); 141 | getMenuInflater().inflate(R.menu.menu_main, menu); 142 | return true; 143 | } 144 | 145 | @Override 146 | public boolean onOptionsItemSelected(MenuItem item) { 147 | switch (item.getItemId()) { 148 | case R.id.menu_main_about: 149 | Intent aboutIntent = new Intent(this, AboutActivity.class); 150 | startActivity(aboutIntent); 151 | return true; 152 | } 153 | 154 | return super.onOptionsItemSelected(item); 155 | } 156 | 157 | private void searchAsync(final String query) { 158 | new AsyncTask() { 159 | @Override 160 | protected void onPreExecute() { 161 | notifyAdapterEmpty(); 162 | imagesLoading.setVisibility(View.VISIBLE); 163 | } 164 | 165 | @Override 166 | protected Search doInBackground(Void... nothing) { 167 | try { 168 | return searchInterface.searchImages(query); 169 | } catch (final RetrofitError e) { 170 | e.printStackTrace(); 171 | Crashlytics.logException(e); 172 | runOnUiThread(new Runnable() { 173 | @Override 174 | public void run() { 175 | Toast.makeText(MainActivity.this, "API Error: " + e.getResponse().getReason(), Toast.LENGTH_LONG).show(); 176 | } 177 | }); 178 | } 179 | 180 | return null; 181 | } 182 | 183 | @Override 184 | protected void onPostExecute(Search search) { 185 | currentSearch = search; 186 | imagesLoading.setVisibility(View.GONE); 187 | if (search != null) { 188 | if (search.totalResults != -1) { 189 | updateResultsCount(true); 190 | } else { 191 | hideResultsCount(true); 192 | } 193 | 194 | if (search.images != null) { 195 | notifyAdapterEmpty(); 196 | images.addAll(search.images); 197 | imagesAdapter.notifyItemRangeInserted(0, search.images.size()); 198 | } 199 | } else { 200 | hideResultsCount(true); 201 | } 202 | } 203 | }.execute(); 204 | } 205 | 206 | private void nextPageAsync() { 207 | if (currentSearch != null) { 208 | new AsyncTask() { 209 | @Override 210 | protected Search doInBackground(Void... params) { 211 | return searchInterface.nextPage(currentSearch, currentSearch.images.size()); 212 | } 213 | 214 | @Override 215 | protected void onPostExecute(Search search) { 216 | currentSearch = search; 217 | 218 | if (search.images != null) { 219 | int oldSize = images.size(); 220 | List subList = search.images.subList(oldSize, search.images.size()); 221 | images.addAll(oldSize, subList); 222 | imagesAdapter.notifyItemRangeInserted(oldSize, subList.size()); 223 | } 224 | } 225 | }.execute(); 226 | } 227 | } 228 | 229 | private void notifyAdapterEmpty() { 230 | int oldSize = images.size(); 231 | int offset = images.isEmpty() ? 0 : 1; 232 | images.clear(); 233 | imagesAdapter.notifyItemRangeRemoved(0, oldSize + offset); 234 | } 235 | 236 | private void updateResultsCount(boolean animate) { 237 | String friendlyCount = new DecimalFormat().format(currentSearch.totalResults); 238 | resultsCountText.setText(getString(R.string.x_results, friendlyCount)); 239 | showResultsCount(animate); 240 | } 241 | 242 | private void showResultsCount(boolean animate) { 243 | float translationY = 0; 244 | if (animate) { 245 | resultsCountHolder.animate().translationY(translationY); 246 | } else { 247 | resultsCountHolder.setTranslationY(translationY); 248 | } 249 | } 250 | 251 | private void hideResultsCount(boolean animate) { 252 | float translationY = resultsCountText.getHeight() * -1; 253 | if (animate) { 254 | resultsCountHolder.animate().translationY(translationY); 255 | } else { 256 | resultsCountHolder.setTranslationY(translationY); 257 | } 258 | } 259 | 260 | private void openImageResult(final int position, final View viewToZoomFrom) { 261 | Ion.with(this).load(images.get(position).thumbnailLink).asBitmap().setCallback(new FutureCallback() { 262 | @Override 263 | public void onCompleted(Exception e, Bitmap result) { 264 | Intent resultIntent = new Intent(MainActivity.this, ResultActivity.class); 265 | resultIntent.putParcelableArrayListExtra(ResultActivity.EXTRA_IMAGES, images); 266 | resultIntent.putExtra(ResultActivity.EXTRA_IMAGE_POSITION, position); 267 | resultIntent.putExtra(ResultActivity.EXTRA_THUMBNAIL_BITMAP, result); 268 | 269 | Bundle options = ActivityOptionsCompat.makeScaleUpAnimation(viewToZoomFrom, 270 | 0, 0, 271 | viewToZoomFrom.getWidth(), viewToZoomFrom.getHeight()).toBundle(); 272 | 273 | ActivityCompat.startActivityForResult(MainActivity.this, resultIntent, 0, options); 274 | } 275 | }); 276 | } 277 | 278 | @Override 279 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 280 | super.onActivityResult(requestCode, resultCode, data); 281 | 282 | if (resultCode == RESULT_OK) { 283 | final Image image = data.getParcelableExtra(ResultActivity.EXTRA_RESULT_IMAGE_RESULT); 284 | finishWithResult(image); 285 | } 286 | } 287 | 288 | private void finishWithResult(final Image imageResult) { 289 | File destinationFolder = new File(getFilesDir(), "result"); 290 | destinationFolder.mkdir(); 291 | try { 292 | FileUtils.cleanDirectory(destinationFolder); 293 | } catch (IOException e) { 294 | e.printStackTrace(); 295 | } 296 | 297 | String filename = imageResult.title + "." + MimeTypeMap.getFileExtensionFromUrl(imageResult.link); 298 | final File destinationFile = new File(destinationFolder, filename); 299 | Ion.with(this).load(imageResult.link).write(destinationFile).setCallback(new FutureCallback() { 300 | @Override 301 | public void onCompleted(Exception e, File result) { 302 | Uri uri = FixedFileProvider.getUriForFile( 303 | MainActivity.this, 304 | "com.stevenschoen.imagesearchernew.fileprovider", 305 | destinationFile); 306 | 307 | Intent intent = new Intent(); 308 | intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 309 | intent.setDataAndType(uri, imageResult.mimeType); 310 | setResult(RESULT_OK, intent); 311 | finish(); 312 | } 313 | }); 314 | } 315 | 316 | @Override 317 | protected void onSaveInstanceState(Bundle outState) { 318 | super.onSaveInstanceState(outState); 319 | 320 | outState.putParcelable(STATE_SEARCH, currentSearch); 321 | outState.putParcelableArrayList(STATE_IMAGES, images); 322 | } 323 | } -------------------------------------------------------------------------------- /app/src/main/java/com/stevenschoen/imagesearchernew/PublicFragmentPagerAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.stevenschoen.imagesearchernew; 18 | 19 | import android.app.Fragment; 20 | import android.app.FragmentManager; 21 | import android.app.FragmentTransaction; 22 | import android.os.Parcelable; 23 | import android.support.v4.view.PagerAdapter; 24 | import android.util.Log; 25 | import android.view.View; 26 | import android.view.ViewGroup; 27 | 28 | /** 29 | * Implementation of {@link android.support.v4.view.PagerAdapter} that 30 | * represents each page as a {@link android.support.v4.app.Fragment} that is persistently 31 | * kept in the fragment manager as long as the user can return to the page. 32 | * 33 | *

This version of the pager is best for use when there are a handful of 34 | * typically more static fragments to be paged through, such as a set of tabs. 35 | * The fragment of each page the user visits will be kept in memory, though its 36 | * view hierarchy may be destroyed when not visible. This can result in using 37 | * a significant amount of memory since fragment instances can hold on to an 38 | * arbitrary amount of state. For larger sets of pages, consider 39 | * {@link android.support.v4.app.FragmentStatePagerAdapter}. 40 | * 41 | *

When using FragmentPagerAdapter the host ViewPager must have a 42 | * valid ID set.

43 | * 44 | *

Subclasses only need to implement {@link #getItem(int)} 45 | * and {@link #getCount()} to have a working adapter. 46 | * 47 | *

Here is an example implementation of a pager containing fragments of 48 | * lists: 49 | * 50 | * {@sample development/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentPagerSupport.java 51 | * complete} 52 | * 53 | *

The R.layout.fragment_pager resource of the top-level fragment is: 54 | * 55 | * {@sample development/samples/Support4Demos/res/layout/fragment_pager.xml 56 | * complete} 57 | * 58 | *

The R.layout.fragment_pager_list resource containing each 59 | * individual fragment's layout is: 60 | * 61 | * {@sample development/samples/Support4Demos/res/layout/fragment_pager_list.xml 62 | * complete} 63 | * 64 | * Edited by Steven Schoen, based on FragmentPagerAdapter 65 | */ 66 | public abstract class PublicFragmentPagerAdapter extends PagerAdapter { 67 | private static final String TAG = "FragmentPagerAdapter"; 68 | private static final boolean DEBUG = false; 69 | 70 | private final FragmentManager mFragmentManager; 71 | private FragmentTransaction mCurTransaction = null; 72 | private Fragment mCurrentPrimaryItem = null; 73 | 74 | public PublicFragmentPagerAdapter(FragmentManager fm) { 75 | mFragmentManager = fm; 76 | } 77 | 78 | /** 79 | * Return the Fragment associated with a specified position. 80 | */ 81 | public abstract Fragment getItem(int position); 82 | 83 | @Override 84 | public void startUpdate(ViewGroup container) { 85 | } 86 | 87 | @Override 88 | public Object instantiateItem(ViewGroup container, int position) { 89 | if (mCurTransaction == null) { 90 | mCurTransaction = mFragmentManager.beginTransaction(); 91 | } 92 | 93 | final long itemId = getItemId(position); 94 | 95 | // Do we already have this fragment? 96 | String name = makeFragmentName(container.getId(), itemId); 97 | Fragment fragment = mFragmentManager.findFragmentByTag(name); 98 | if (fragment != null) { 99 | if (DEBUG) Log.v(TAG, "Attaching item #" + itemId + ": f=" + fragment); 100 | mCurTransaction.attach(fragment); 101 | } else { 102 | fragment = getItem(position); 103 | if (DEBUG) Log.v(TAG, "Adding item #" + itemId + ": f=" + fragment); 104 | mCurTransaction.add(container.getId(), fragment, 105 | makeFragmentName(container.getId(), itemId)); 106 | } 107 | if (fragment != mCurrentPrimaryItem) { 108 | fragment.setMenuVisibility(false); 109 | fragment.setUserVisibleHint(false); 110 | } 111 | 112 | return fragment; 113 | } 114 | 115 | @Override 116 | public void destroyItem(ViewGroup container, int position, Object object) { 117 | if (mCurTransaction == null) { 118 | mCurTransaction = mFragmentManager.beginTransaction(); 119 | } 120 | if (DEBUG) Log.v(TAG, "Detaching item #" + getItemId(position) + ": f=" + object 121 | + " v=" + ((Fragment)object).getView()); 122 | mCurTransaction.detach((Fragment)object); 123 | } 124 | 125 | @Override 126 | public void setPrimaryItem(ViewGroup container, int position, Object object) { 127 | Fragment fragment = (Fragment)object; 128 | if (fragment != mCurrentPrimaryItem) { 129 | if (mCurrentPrimaryItem != null) { 130 | mCurrentPrimaryItem.setMenuVisibility(false); 131 | mCurrentPrimaryItem.setUserVisibleHint(false); 132 | } 133 | if (fragment != null) { 134 | fragment.setMenuVisibility(true); 135 | fragment.setUserVisibleHint(true); 136 | } 137 | mCurrentPrimaryItem = fragment; 138 | } 139 | } 140 | 141 | @Override 142 | public void finishUpdate(ViewGroup container) { 143 | if (mCurTransaction != null) { 144 | mCurTransaction.commitAllowingStateLoss(); 145 | mCurTransaction = null; 146 | mFragmentManager.executePendingTransactions(); 147 | } 148 | } 149 | 150 | @Override 151 | public boolean isViewFromObject(View view, Object object) { 152 | return ((Fragment)object).getView() == view; 153 | } 154 | 155 | @Override 156 | public Parcelable saveState() { 157 | return null; 158 | } 159 | 160 | @Override 161 | public void restoreState(Parcelable state, ClassLoader loader) { 162 | } 163 | 164 | /** 165 | * Return a unique identifier for the item at the given position. 166 | * 167 | *

The default implementation returns the given position. 168 | * Subclasses should override this method if the positions of items can change.

169 | * 170 | * @param position Position within this adapter 171 | * @return Unique identifier for the item at position 172 | */ 173 | public long getItemId(int position) { 174 | return position; 175 | } 176 | 177 | private static String makeFragmentName(int viewId, long id) { 178 | return "android:switcher:" + viewId + ":" + id; 179 | } 180 | 181 | public Fragment getFragmentAtPosition(View container, int position) { 182 | return mFragmentManager.findFragmentByTag(makeFragmentName(container.getId(), getItemId(position))); 183 | } 184 | } -------------------------------------------------------------------------------- /app/src/main/java/com/stevenschoen/imagesearchernew/ResultActivity.java: -------------------------------------------------------------------------------- 1 | package com.stevenschoen.imagesearchernew; 2 | 3 | import android.app.Fragment; 4 | import android.content.Intent; 5 | import android.graphics.Bitmap; 6 | import android.os.Bundle; 7 | import android.support.v4.app.NavUtils; 8 | import android.support.v4.view.ViewPager; 9 | import android.support.v7.app.ActionBarActivity; 10 | import android.view.Menu; 11 | import android.view.MenuItem; 12 | import android.view.View; 13 | import android.widget.TextView; 14 | 15 | import com.afollestad.materialdialogs.MaterialDialog; 16 | import com.afollestad.materialdialogs.Theme; 17 | import com.stevenschoen.imagesearchernew.model.Image; 18 | 19 | import java.util.List; 20 | 21 | public class ResultActivity extends ActionBarActivity { 22 | 23 | public static final String EXTRA_IMAGES = "images"; 24 | public static final String EXTRA_IMAGE_POSITION = "imagePosition"; 25 | public static final String EXTRA_THUMBNAIL_BITMAP = "thumbnailBitmap"; 26 | 27 | public static final String EXTRA_RESULT_IMAGE_RESULT = "imageResult"; 28 | 29 | private ViewPager pager; 30 | 31 | private List images; 32 | private int imagePosition; 33 | private Bitmap thumbnailBitmap; 34 | 35 | @Override 36 | protected void onCreate(Bundle savedInstanceState) { 37 | super.onCreate(savedInstanceState); 38 | setContentView(R.layout.imageresult_pager); 39 | 40 | if (getIntent() != null) { 41 | images = getIntent().getParcelableArrayListExtra(EXTRA_IMAGES); 42 | imagePosition = getIntent().getIntExtra(EXTRA_IMAGE_POSITION, 0); 43 | thumbnailBitmap = getIntent().getParcelableExtra(EXTRA_THUMBNAIL_BITMAP); 44 | } else { 45 | finish(); 46 | } 47 | 48 | pager = (ViewPager) findViewById(R.id.imageresult_pager_pager); 49 | final PublicFragmentPagerAdapter pagerAdapter = new PublicFragmentPagerAdapter(getFragmentManager()) { 50 | @Override 51 | public Fragment getItem(int position) { 52 | Bundle args = new Bundle(); 53 | args.putParcelable(ResultFragment.EXTRA_IMAGE_RESULT, images.get(position)); 54 | if (position == imagePosition) { 55 | args.putParcelable(ResultFragment.EXTRA_THUMBNAIL_BITMAP, thumbnailBitmap); 56 | } 57 | return Fragment.instantiate(ResultActivity.this, ResultFragment.class.getName(), args); 58 | } 59 | 60 | @Override 61 | public int getCount() { 62 | return images.size(); 63 | } 64 | }; 65 | pager.setAdapter(pagerAdapter); 66 | pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { 67 | @Override 68 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } 69 | 70 | @Override 71 | public void onPageSelected(int position) { 72 | setTitle(images.get(position).title); 73 | } 74 | 75 | @Override 76 | public void onPageScrollStateChanged(int state) { } 77 | }); 78 | pager.setCurrentItem(imagePosition, false); 79 | 80 | View selectButton = findViewById(R.id.imageresult_pager_select); 81 | Utils.setupFab(selectButton); 82 | selectButton.setOnClickListener(new View.OnClickListener() { 83 | @Override 84 | public void onClick(View v) { 85 | finishWithResult(getCurrentImageResult()); 86 | } 87 | }); 88 | } 89 | 90 | public Image getCurrentImageResult() { 91 | return images.get(pager.getCurrentItem()); 92 | } 93 | 94 | private void showDetailsDialog() { 95 | Image imageResult = getCurrentImageResult(); 96 | 97 | MaterialDialog dialog = new MaterialDialog.Builder(this) 98 | .title(imageResult.title) 99 | .customView(R.layout.imageresult_details) 100 | .neutralText(R.string.close) 101 | .theme(Theme.DARK) 102 | .build(); 103 | 104 | TextView linkText = (TextView) dialog.getCustomView().findViewById(R.id.imageresult_details_link); 105 | linkText.setText(imageResult.link); 106 | 107 | TextView siteText = (TextView) dialog.getCustomView().findViewById(R.id.imageresult_details_site); 108 | siteText.setText(imageResult.displayLink); 109 | 110 | TextView typeText = (TextView) dialog.getCustomView().findViewById(R.id.imageresult_details_type); 111 | typeText.setText(imageResult.mimeType); 112 | 113 | TextView sizeText = (TextView) dialog.getCustomView().findViewById(R.id.imageresult_details_size); 114 | sizeText.setText(Utils.humanReadableByteCount(imageResult.size, false)); 115 | 116 | TextView resolutionText = (TextView) dialog.getCustomView().findViewById(R.id.imageresult_details_resolution); 117 | String resolution = imageResult.width + " x " + imageResult.height; 118 | resolutionText.setText(resolution); 119 | 120 | dialog.show(); 121 | } 122 | 123 | @Override 124 | public boolean onCreateOptionsMenu(Menu menu) { 125 | super.onCreateOptionsMenu(menu); 126 | getMenuInflater().inflate(R.menu.menu_result, menu); 127 | return true; 128 | } 129 | 130 | @Override 131 | public boolean onOptionsItemSelected(MenuItem item) { 132 | switch (item.getItemId()) { 133 | case android.R.id.home: 134 | NavUtils.navigateUpFromSameTask(this); 135 | return true; 136 | case R.id.menu_result_details: 137 | showDetailsDialog(); 138 | return true; 139 | } 140 | 141 | return super.onOptionsItemSelected(item); 142 | } 143 | 144 | private void finishWithResult(Image imageResult) { 145 | Intent intent = new Intent(); 146 | intent.putExtra(EXTRA_RESULT_IMAGE_RESULT, imageResult); 147 | 148 | setResult(RESULT_OK, intent); 149 | finish(); 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /app/src/main/java/com/stevenschoen/imagesearchernew/ResultFragment.java: -------------------------------------------------------------------------------- 1 | package com.stevenschoen.imagesearchernew; 2 | 3 | import android.animation.Animator; 4 | import android.animation.AnimatorListenerAdapter; 5 | import android.app.Fragment; 6 | import android.graphics.Bitmap; 7 | import android.os.Bundle; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.widget.ImageView; 12 | 13 | import com.koushikdutta.async.future.FutureCallback; 14 | import com.koushikdutta.ion.ImageViewBitmapInfo; 15 | import com.koushikdutta.ion.Ion; 16 | import com.stevenschoen.imagesearchernew.model.Image; 17 | 18 | public class ResultFragment extends Fragment { 19 | 20 | public static final String EXTRA_IMAGE_RESULT = "imageResult"; 21 | public static final String EXTRA_THUMBNAIL_BITMAP = "thumbnailBitmap"; 22 | 23 | private Image result; 24 | 25 | private Bitmap thumbnailBitmap; 26 | 27 | @Override 28 | public void onCreate(Bundle savedInstanceState) { 29 | super.onCreate(savedInstanceState); 30 | 31 | thumbnailBitmap = getArguments().getParcelable(EXTRA_THUMBNAIL_BITMAP); 32 | result = getArguments().getParcelable(EXTRA_IMAGE_RESULT); 33 | 34 | if (savedInstanceState != null) { 35 | if (savedInstanceState.containsKey(EXTRA_THUMBNAIL_BITMAP)) { 36 | thumbnailBitmap = savedInstanceState.getParcelable(EXTRA_THUMBNAIL_BITMAP); 37 | } 38 | } 39 | } 40 | 41 | @Override 42 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 43 | View view = inflater.inflate(R.layout.imageresult_full, container, false); 44 | 45 | final ImageView thumbnailImage = (ImageView) view.findViewById(R.id.imageresult_full_thumbnail); 46 | if (thumbnailBitmap != null) { 47 | thumbnailImage.setImageBitmap(thumbnailBitmap); 48 | } else { 49 | Ion.with(getActivity()).load(result.thumbnailLink).intoImageView(thumbnailImage) 50 | .withBitmapInfo().setCallback(new FutureCallback() { 51 | @Override 52 | public void onCompleted(Exception e, ImageViewBitmapInfo result) { 53 | thumbnailBitmap = result.getBitmapInfo().bitmap; 54 | } 55 | }); 56 | } 57 | 58 | final ImageView image = (ImageView) view.findViewById(R.id.imageresult_full_image); 59 | image.setAlpha(0f); 60 | Ion.with(getActivity()).load(result.link).intoImageView(image) 61 | .withBitmapInfo().setCallback(new FutureCallback() { 62 | @Override 63 | public void onCompleted(Exception e, ImageViewBitmapInfo result) { 64 | image.animate().alpha(1f).setListener(new AnimatorListenerAdapter() { 65 | @Override 66 | public void onAnimationEnd(Animator animation) { 67 | thumbnailImage.setVisibility(View.GONE); 68 | } 69 | }); 70 | } 71 | }); 72 | 73 | return view; 74 | } 75 | 76 | public Image getImageResult() { 77 | return result; 78 | } 79 | 80 | @Override 81 | public void onSaveInstanceState(Bundle outState) { 82 | super.onSaveInstanceState(outState); 83 | 84 | if (thumbnailBitmap != null) { 85 | outState.putParcelable(EXTRA_THUMBNAIL_BITMAP, thumbnailBitmap); 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /app/src/main/java/com/stevenschoen/imagesearchernew/SearchInterface.java: -------------------------------------------------------------------------------- 1 | package com.stevenschoen.imagesearchernew; 2 | 3 | import com.squareup.okhttp.Authenticator; 4 | import com.squareup.okhttp.Credentials; 5 | import com.squareup.okhttp.OkHttpClient; 6 | import com.squareup.okhttp.Request; 7 | import com.squareup.okhttp.Response; 8 | import com.stevenschoen.imagesearchernew.model.Image; 9 | import com.stevenschoen.imagesearchernew.model.Search; 10 | import com.stevenschoen.imagesearchernew.model.bing.BingImage; 11 | import com.stevenschoen.imagesearchernew.model.bing.BingSearchResponse; 12 | import com.stevenschoen.imagesearchernew.model.google.GoogleImage; 13 | import com.stevenschoen.imagesearchernew.model.google.GoogleSearchResponse; 14 | 15 | import java.io.IOException; 16 | import java.net.Proxy; 17 | import java.util.ArrayList; 18 | 19 | import retrofit.RequestInterceptor; 20 | import retrofit.RestAdapter; 21 | import retrofit.client.OkClient; 22 | 23 | public class SearchInterface { 24 | public static enum Service { 25 | FakeGoogle, Google, Bing 26 | } 27 | 28 | public Service service; 29 | 30 | private FakeGoogleSearchInterface fakeGoogleSearchInterface; 31 | private GoogleSearchInterface googleSearchInterface; 32 | private BingSearchInterface bingSearchInterface; 33 | 34 | public SearchInterface(Service service) { 35 | this.service = service; 36 | 37 | switch (service) { 38 | case FakeGoogle: 39 | fakeGoogleSearchInterface = new FakeGoogleSearchInterface(); 40 | break; 41 | case Google: 42 | RestAdapter.Builder googleBuilder = new RestAdapter.Builder() 43 | .setEndpoint(GoogleSearchInterface.BASE_URL) 44 | .setLogLevel(RestAdapter.LogLevel.BASIC) 45 | .setRequestInterceptor(new RequestInterceptor() { 46 | @Override 47 | public void intercept(RequestFacade request) { 48 | request.addQueryParam("key", GoogleSearchInterface.API_KEY); 49 | request.addQueryParam("cx", GoogleSearchInterface.CUSTOM_SEARCH_ID); 50 | } 51 | }); 52 | RestAdapter googleAdapter = googleBuilder.build(); 53 | googleSearchInterface = googleAdapter.create(GoogleSearchInterface.class); 54 | break; 55 | case Bing: 56 | OkHttpClient httpClient = new OkHttpClient(); 57 | httpClient.setAuthenticator(new Authenticator() { 58 | @Override 59 | public Request authenticate(Proxy proxy, Response response) throws IOException { 60 | // "API keys are for hipsters and squares" - Microsoft 61 | String credential = Credentials.basic(BingSearchInterface.API_KEY, BingSearchInterface.API_KEY); 62 | return response.request().newBuilder() 63 | .header("Authorization", credential) 64 | .build(); 65 | } 66 | 67 | @Override 68 | public Request authenticateProxy(Proxy proxy, Response response) throws IOException { 69 | return null; 70 | } 71 | }); 72 | RestAdapter.Builder bingBuilder = new RestAdapter.Builder() 73 | .setClient(new OkClient(httpClient)) 74 | .setEndpoint(BingSearchInterface.BASE_URL) 75 | .setLogLevel(RestAdapter.LogLevel.BASIC); 76 | RestAdapter bingAdapter = bingBuilder.build(); 77 | bingSearchInterface = bingAdapter.create(BingSearchInterface.class); 78 | break; 79 | } 80 | } 81 | 82 | public Search searchImages(String query) { 83 | switch (service) { 84 | case FakeGoogle: 85 | return buildSearch(fakeGoogleSearchInterface.search(), query); 86 | case Google: 87 | return buildSearch(googleSearchInterface.search( 88 | query, 89 | 1, 90 | GoogleSearchInterface.SEARCH_TYPE_IMAGE), 91 | query); 92 | case Bing: 93 | // crossFingers(); 94 | return buildSearch(bingSearchInterface.search( 95 | Utils.wrapInBingQuotes(BingSearchInterface.SOURCE_IMAGE), 96 | Utils.wrapInBingQuotes(query), 97 | 0, 98 | BingSearchInterface.FORMAT_JSON), 99 | query); 100 | } 101 | 102 | return null; 103 | } 104 | 105 | public Search nextPage(Search search, long firstIndex) { 106 | // Google starts 'startIndex' at 1, Bing starts 'skip' at 0 107 | // Starting at 0 108 | switch (service) { 109 | case FakeGoogle: 110 | break; 111 | case Google: 112 | Search newGoogleSearch = buildSearch(googleSearchInterface.search( 113 | search.input.query, 114 | firstIndex + 1, 115 | GoogleSearchInterface.SEARCH_TYPE_IMAGE), 116 | search.input.query); 117 | search.images.addAll(newGoogleSearch.images); 118 | break; 119 | case Bing: 120 | Search newBingSearch = buildSearch(bingSearchInterface.search( 121 | Utils.wrapInBingQuotes(BingSearchInterface.SOURCE_IMAGE), 122 | Utils.wrapInBingQuotes(search.input.query), 123 | firstIndex, 124 | BingSearchInterface.FORMAT_JSON), 125 | search.input.query); 126 | search.images.addAll(newBingSearch.images); 127 | break; 128 | } 129 | 130 | return search; 131 | } 132 | 133 | private Search buildSearch(GoogleSearchResponse googleResponse, String query) { 134 | Search search = new Search(query); 135 | 136 | search.images = new ArrayList<>(googleResponse.items.length); 137 | for (GoogleImage image : googleResponse.items) { 138 | search.images.add(buildResult(image)); 139 | } 140 | 141 | search.totalResults = googleResponse.searchInformation.totalResults; 142 | 143 | return search; 144 | } 145 | 146 | private Search buildSearch(BingSearchResponse bingResponse, String query) { 147 | Search search = new Search(query); 148 | 149 | search.images = new ArrayList<>(bingResponse.d.results[0].Image.length); 150 | for (BingImage image : bingResponse.d.results[0].Image) { 151 | search.images.add(buildImage(image)); 152 | } 153 | 154 | search.totalResults = bingResponse.d.results[0].ImageTotal; 155 | 156 | return search; 157 | } 158 | 159 | private Image buildResult(GoogleImage googleImage) { 160 | Image image = new Image(); 161 | 162 | image.title = googleImage.title; 163 | image.link = googleImage.link; 164 | image.thumbnailLink = googleImage.image.thumbnailLink; 165 | image.displayLink = googleImage.displayLink; 166 | image.mimeType = googleImage.mime; 167 | image.width = googleImage.image.width; 168 | image.height = googleImage.image.height; 169 | image.size = googleImage.image.byteSize; 170 | 171 | return image; 172 | } 173 | 174 | private Image buildImage(BingImage bingImage) { 175 | Image image = new Image(); 176 | 177 | image.title = bingImage.Title; 178 | image.link = bingImage.MediaUrl; 179 | image.thumbnailLink = bingImage.Thumbnail.MediaUrl; 180 | image.displayLink = bingImage.SourceUrl; 181 | image.mimeType = bingImage.ContentType; 182 | image.width = bingImage.Width; 183 | image.height = bingImage.Height; 184 | image.size = bingImage.FileSize; 185 | 186 | return image; 187 | } 188 | } 189 | -------------------------------------------------------------------------------- /app/src/main/java/com/stevenschoen/imagesearchernew/Utils.java: -------------------------------------------------------------------------------- 1 | package com.stevenschoen.imagesearchernew; 2 | 3 | import android.annotation.TargetApi; 4 | import android.graphics.Outline; 5 | import android.os.Build; 6 | import android.view.View; 7 | import android.view.ViewOutlineProvider; 8 | 9 | import java.util.Locale; 10 | 11 | public class Utils { 12 | 13 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 14 | public static void setupFab(View floatingActionButton) { 15 | if (hasLollipop()) { 16 | floatingActionButton.setOutlineProvider(new ViewOutlineProvider() { 17 | @Override 18 | public void getOutline(View view, Outline outline) { 19 | outline.setOval(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); 20 | } 21 | }); 22 | floatingActionButton.setClipToOutline(true); 23 | floatingActionButton.setElevation( 24 | floatingActionButton.getResources().getDimension(R.dimen.fab_elevation)); 25 | } 26 | } 27 | 28 | public static String humanReadableByteCount(long bytes, boolean si) { 29 | int unit = si ? 1000 : 1024; 30 | if (bytes < unit) 31 | return bytes + " B"; 32 | int exp = (int) (Math.log(bytes) / Math.log(unit)); 33 | String pre = ("KMGTPE").charAt(exp - 1) 34 | + ""; 35 | return String.format(Locale.US, "%.1f %sB", bytes / Math.pow(unit, exp), pre); 36 | } 37 | 38 | public static String wrapInBingQuotes(String string) { 39 | // Thanks, Microsoft. Super intuitive. 40 | return "'" + string + "'"; 41 | } 42 | 43 | public static boolean hasLollipop() { 44 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /app/src/main/java/com/stevenschoen/imagesearchernew/model/Image.java: -------------------------------------------------------------------------------- 1 | package com.stevenschoen.imagesearchernew.model; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | 6 | public class Image implements Parcelable { 7 | public String title; 8 | public String link; 9 | public String thumbnailLink; 10 | public String displayLink; 11 | public String mimeType; 12 | public long width, height; 13 | public long size; 14 | 15 | @Override 16 | public int describeContents() { 17 | return 0; 18 | } 19 | 20 | @Override 21 | public void writeToParcel(Parcel dest, int flags) { 22 | dest.writeString(this.title); 23 | dest.writeString(this.link); 24 | dest.writeString(this.thumbnailLink); 25 | dest.writeString(this.displayLink); 26 | dest.writeString(this.mimeType); 27 | dest.writeLong(this.width); 28 | dest.writeLong(this.height); 29 | dest.writeLong(this.size); 30 | } 31 | 32 | public Image() { } 33 | 34 | private Image(Parcel in) { 35 | this.title = in.readString(); 36 | this.link = in.readString(); 37 | this.thumbnailLink = in.readString(); 38 | this.displayLink = in.readString(); 39 | this.mimeType = in.readString(); 40 | this.width = in.readLong(); 41 | this.height = in.readLong(); 42 | this.size = in.readLong(); 43 | } 44 | 45 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { 46 | public Image createFromParcel(Parcel source) { 47 | return new Image(source); 48 | } 49 | 50 | public Image[] newArray(int size) { 51 | return new Image[size]; 52 | } 53 | }; 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/java/com/stevenschoen/imagesearchernew/model/Search.java: -------------------------------------------------------------------------------- 1 | package com.stevenschoen.imagesearchernew.model; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | public class Search implements Parcelable { 10 | public Input input; // Not from APIs, details from this app 11 | 12 | public static class Input implements Parcelable { 13 | public String query; 14 | 15 | @Override 16 | public int describeContents() { 17 | return 0; 18 | } 19 | 20 | @Override 21 | public void writeToParcel(Parcel dest, int flags) { 22 | dest.writeString(this.query); 23 | } 24 | 25 | public Input(String query) { 26 | this.query = query; 27 | } 28 | 29 | private Input(Parcel in) { 30 | this.query = in.readString(); 31 | } 32 | 33 | public static final Creator CREATOR = new Creator() { 34 | public Input createFromParcel(Parcel source) { 35 | return new Input(source); 36 | } 37 | 38 | public Input[] newArray(int size) { 39 | return new Input[size]; 40 | } 41 | }; 42 | } 43 | 44 | public List images; 45 | public long totalResults; 46 | 47 | @Override 48 | public int describeContents() { 49 | return 0; 50 | } 51 | 52 | @Override 53 | public void writeToParcel(Parcel dest, int flags) { 54 | dest.writeParcelable(this.input, flags); 55 | dest.writeTypedList(images); 56 | dest.writeLong(totalResults); 57 | } 58 | 59 | public Search() { 60 | images = new ArrayList<>(); 61 | totalResults = -1; 62 | } 63 | 64 | public Search(String query) { 65 | super(); 66 | input = new Input(query); 67 | } 68 | 69 | private Search(Parcel in) { 70 | super(); 71 | this.input = in.readParcelable(Input.class.getClassLoader()); 72 | in.readTypedList(images, Image.CREATOR); 73 | this.totalResults = in.readLong(); 74 | } 75 | 76 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { 77 | public Search createFromParcel(Parcel source) { 78 | return new Search(source); 79 | } 80 | 81 | public Search[] newArray(int size) { 82 | return new Search[size]; 83 | } 84 | }; 85 | } 86 | -------------------------------------------------------------------------------- /app/src/main/java/com/stevenschoen/imagesearchernew/model/bing/BingImage.java: -------------------------------------------------------------------------------- 1 | package com.stevenschoen.imagesearchernew.model.bing; 2 | 3 | public class BingImage { 4 | public String Title; 5 | public String MediaUrl; 6 | public String SourceUrl; 7 | public String DisplayUrl; 8 | public long Width, Height; 9 | public long FileSize; 10 | public String ContentType; 11 | public Thumbnail Thumbnail; 12 | 13 | public static class Thumbnail { 14 | public String MediaUrl; 15 | } 16 | } -------------------------------------------------------------------------------- /app/src/main/java/com/stevenschoen/imagesearchernew/model/bing/BingSearchResponse.java: -------------------------------------------------------------------------------- 1 | package com.stevenschoen.imagesearchernew.model.bing; 2 | 3 | public class BingSearchResponse { 4 | public BingInnerResponse d; // "What should we call the actual content that was asked for? 5 | // "I know! 'd'!" 6 | // "But why not just put that in the response?" 7 | // "You're fired." 8 | 9 | public class BingInnerResponse { 10 | public BingInnerResult[] results; // "So this array, called 'results'.. it's going to 11 | // contain the results, right?" 12 | // "No, you imbecile! It'll have just one object, and 13 | // THAT object will have an array with all the results!" 14 | // "Then why have the original array in the first place?" 15 | // "You're fired, too." 16 | 17 | public class BingInnerResult { 18 | public long ImageTotal; 19 | public BingImage[] Image; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/stevenschoen/imagesearchernew/model/google/GoogleImage.java: -------------------------------------------------------------------------------- 1 | package com.stevenschoen.imagesearchernew.model.google; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | 6 | public class GoogleImage implements Parcelable { 7 | public String title; 8 | public String link; 9 | public String displayLink; 10 | public String mime; 11 | public Image image; 12 | 13 | public static class Image implements Parcelable { 14 | public long height; 15 | public long width; 16 | public long byteSize; 17 | public String thumbnailLink; 18 | 19 | @Override 20 | public int describeContents() { 21 | return 0; 22 | } 23 | 24 | @Override 25 | public void writeToParcel(Parcel dest, int flags) { 26 | dest.writeLong(this.height); 27 | dest.writeLong(this.width); 28 | dest.writeLong(this.byteSize); 29 | dest.writeString(this.thumbnailLink); 30 | } 31 | 32 | public Image() { } 33 | 34 | private Image(Parcel in) { 35 | this.height = in.readLong(); 36 | this.width = in.readLong(); 37 | this.byteSize = in.readLong(); 38 | this.thumbnailLink = in.readString(); 39 | } 40 | 41 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { 42 | public Image createFromParcel(Parcel source) { 43 | return new Image(source); 44 | } 45 | 46 | public Image[] newArray(int size) { 47 | return new Image[size]; 48 | } 49 | }; 50 | } 51 | 52 | @Override 53 | public int describeContents() { 54 | return 0; 55 | } 56 | 57 | @Override 58 | public void writeToParcel(Parcel dest, int flags) { 59 | dest.writeString(this.title); 60 | dest.writeString(this.link); 61 | dest.writeString(this.displayLink); 62 | dest.writeString(this.mime); 63 | dest.writeParcelable(this.image, 0); 64 | } 65 | 66 | public GoogleImage() { 67 | } 68 | 69 | private GoogleImage(Parcel in) { 70 | this.title = in.readString(); 71 | this.link = in.readString(); 72 | this.displayLink = in.readString(); 73 | this.mime = in.readString(); 74 | this.image = in.readParcelable(Image.class.getClassLoader()); 75 | } 76 | 77 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { 78 | public GoogleImage createFromParcel(Parcel source) { 79 | return new GoogleImage(source); 80 | } 81 | 82 | public GoogleImage[] newArray(int size) { 83 | return new GoogleImage[size]; 84 | } 85 | }; 86 | } -------------------------------------------------------------------------------- /app/src/main/java/com/stevenschoen/imagesearchernew/model/google/GoogleSearchResponse.java: -------------------------------------------------------------------------------- 1 | package com.stevenschoen.imagesearchernew.model.google; 2 | 3 | public class GoogleSearchResponse { 4 | public GoogleImage[] items; 5 | public GoogleQueries queries; 6 | public GoogleSearchInformation searchInformation; 7 | 8 | public static class GoogleQueries { 9 | public GooglePage[] nextPage = new GooglePage[1]; 10 | public GooglePage[] request = new GooglePage[1]; 11 | 12 | public static class GooglePage { 13 | public int startIndex; 14 | public int count; 15 | } 16 | 17 | public GooglePage getNextPage() { 18 | return nextPage[0]; 19 | } 20 | 21 | public GooglePage getRequest() { 22 | return request[0]; 23 | } 24 | } 25 | 26 | public static class GoogleSearchInformation { 27 | public long totalResults; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/java/de/ankri/views/AutoScaleTextView.java: -------------------------------------------------------------------------------- 1 | package de.ankri.views; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.Paint; 6 | import android.util.AttributeSet; 7 | import android.util.TypedValue; 8 | import android.widget.TextView; 9 | 10 | import com.stevenschoen.imagesearchernew.R; 11 | 12 | /** 13 | * A custom Text View that lowers the text size when the text is to big for the TextView. Modified version of one found on stackoverflow 14 | * 15 | * @author Andreas Krings - www.ankri.de 16 | * @version 1.0 17 | * 18 | */ 19 | public class AutoScaleTextView extends TextView 20 | { 21 | private Paint textPaint; 22 | 23 | private float preferredTextSize; 24 | private float minTextSize; 25 | 26 | public AutoScaleTextView(Context context) 27 | { 28 | this(context, null); 29 | } 30 | 31 | public AutoScaleTextView(Context context, AttributeSet attrs) 32 | { 33 | this(context, attrs, R.attr.autoScaleTextViewStyle); 34 | 35 | // Use this constructor, if you do not want use the default style 36 | // super(context, attrs); 37 | } 38 | 39 | public AutoScaleTextView(Context context, AttributeSet attrs, int defStyle) 40 | { 41 | super(context, attrs, defStyle); 42 | 43 | this.textPaint = new Paint(); 44 | 45 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AutoScaleTextView, defStyle, 0); 46 | this.minTextSize = a.getDimension(R.styleable.AutoScaleTextView_minTextSize, 10f); 47 | a.recycle(); 48 | 49 | this.preferredTextSize = this.getTextSize(); 50 | } 51 | 52 | /** 53 | * Set the minimum text size for this view 54 | * 55 | * @param minTextSize 56 | * The minimum text size 57 | */ 58 | public void setMinTextSize(float minTextSize) 59 | { 60 | this.minTextSize = minTextSize; 61 | } 62 | 63 | /** 64 | * Resize the text so that it fits 65 | * 66 | * @param text 67 | * The text. Neither null nor empty. 68 | * @param textWidth 69 | * The width of the TextView. > 0 70 | */ 71 | private void refitText(String text, int textWidth) 72 | { 73 | if (textWidth <= 0 || text == null || text.length() == 0) 74 | return; 75 | 76 | // the width 77 | int targetWidth = textWidth - this.getPaddingLeft() - this.getPaddingRight(); 78 | 79 | final float threshold = 0.5f; // How close we have to be 80 | 81 | this.textPaint.set(this.getPaint()); 82 | 83 | while ((this.preferredTextSize - this.minTextSize) > threshold) 84 | { 85 | float size = (this.preferredTextSize + this.minTextSize) / 2; 86 | this.textPaint.setTextSize(size); 87 | if (this.textPaint.measureText(text) >= targetWidth) 88 | this.preferredTextSize = size; // too big 89 | else 90 | this.minTextSize = size; // too small 91 | } 92 | // Use min size so that we undershoot rather than overshoot 93 | this.setTextSize(TypedValue.COMPLEX_UNIT_PX, this.minTextSize); 94 | } 95 | 96 | @Override 97 | protected void onTextChanged(final CharSequence text, final int start, final int before, final int after) 98 | { 99 | this.refitText(text.toString(), this.getWidth()); 100 | } 101 | 102 | @Override 103 | protected void onSizeChanged(int width, int height, int oldwidth, int oldheight) 104 | { 105 | if (width != oldwidth) 106 | this.refitText(this.getText().toString(), width); 107 | } 108 | 109 | } -------------------------------------------------------------------------------- /app/src/main/res/animator-v21/fab_state_list_anim.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 21 | 22 | 27 | 28 | 29 | 30 | 31 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/fab_shadow_mini.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DSteve595/Image-Searcher/e8e002c736566925ff717e39015d1b37c416bad8/app/src/main/res/drawable-hdpi/fab_shadow_mini.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/fab_shadow_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DSteve595/Image-Searcher/e8e002c736566925ff717e39015d1b37c416bad8/app/src/main/res/drawable-hdpi/fab_shadow_normal.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_about_action_github.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DSteve595/Image-Searcher/e8e002c736566925ff717e39015d1b37c416bad8/app/src/main/res/drawable-hdpi/ic_about_action_github.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_about_action_rate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DSteve595/Image-Searcher/e8e002c736566925ff717e39015d1b37c416bad8/app/src/main/res/drawable-hdpi/ic_about_action_rate.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_fab_back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DSteve595/Image-Searcher/e8e002c736566925ff717e39015d1b37c416bad8/app/src/main/res/drawable-hdpi/ic_fab_back.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_fab_select.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DSteve595/Image-Searcher/e8e002c736566925ff717e39015d1b37c416bad8/app/src/main/res/drawable-hdpi/ic_fab_select.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DSteve595/Image-Searcher/e8e002c736566925ff717e39015d1b37c416bad8/app/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/fab_shadow_mini.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DSteve595/Image-Searcher/e8e002c736566925ff717e39015d1b37c416bad8/app/src/main/res/drawable-mdpi/fab_shadow_mini.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/fab_shadow_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DSteve595/Image-Searcher/e8e002c736566925ff717e39015d1b37c416bad8/app/src/main/res/drawable-mdpi/fab_shadow_normal.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_about_action_github.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DSteve595/Image-Searcher/e8e002c736566925ff717e39015d1b37c416bad8/app/src/main/res/drawable-mdpi/ic_about_action_github.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_about_action_rate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DSteve595/Image-Searcher/e8e002c736566925ff717e39015d1b37c416bad8/app/src/main/res/drawable-mdpi/ic_about_action_rate.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_fab_back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DSteve595/Image-Searcher/e8e002c736566925ff717e39015d1b37c416bad8/app/src/main/res/drawable-mdpi/ic_fab_back.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_fab_select.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DSteve595/Image-Searcher/e8e002c736566925ff717e39015d1b37c416bad8/app/src/main/res/drawable-mdpi/ic_fab_select.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DSteve595/Image-Searcher/e8e002c736566925ff717e39015d1b37c416bad8/app/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-nodpi/more.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DSteve595/Image-Searcher/e8e002c736566925ff717e39015d1b37c416bad8/app/src/main/res/drawable-nodpi/more.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-v21/fab_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v21/fab_shadow.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/fab_shadow_mini.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DSteve595/Image-Searcher/e8e002c736566925ff717e39015d1b37c416bad8/app/src/main/res/drawable-xhdpi/fab_shadow_mini.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/fab_shadow_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DSteve595/Image-Searcher/e8e002c736566925ff717e39015d1b37c416bad8/app/src/main/res/drawable-xhdpi/fab_shadow_normal.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_about_action_github.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DSteve595/Image-Searcher/e8e002c736566925ff717e39015d1b37c416bad8/app/src/main/res/drawable-xhdpi/ic_about_action_github.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_about_action_rate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DSteve595/Image-Searcher/e8e002c736566925ff717e39015d1b37c416bad8/app/src/main/res/drawable-xhdpi/ic_about_action_rate.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_fab_back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DSteve595/Image-Searcher/e8e002c736566925ff717e39015d1b37c416bad8/app/src/main/res/drawable-xhdpi/ic_fab_back.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_fab_select.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DSteve595/Image-Searcher/e8e002c736566925ff717e39015d1b37c416bad8/app/src/main/res/drawable-xhdpi/ic_fab_select.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DSteve595/Image-Searcher/e8e002c736566925ff717e39015d1b37c416bad8/app/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/fab_shadow_mini.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DSteve595/Image-Searcher/e8e002c736566925ff717e39015d1b37c416bad8/app/src/main/res/drawable-xxhdpi/fab_shadow_mini.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/fab_shadow_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DSteve595/Image-Searcher/e8e002c736566925ff717e39015d1b37c416bad8/app/src/main/res/drawable-xxhdpi/fab_shadow_normal.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_about_action_github.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DSteve595/Image-Searcher/e8e002c736566925ff717e39015d1b37c416bad8/app/src/main/res/drawable-xxhdpi/ic_about_action_github.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_about_action_rate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DSteve595/Image-Searcher/e8e002c736566925ff717e39015d1b37c416bad8/app/src/main/res/drawable-xxhdpi/ic_about_action_rate.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_fab_back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DSteve595/Image-Searcher/e8e002c736566925ff717e39015d1b37c416bad8/app/src/main/res/drawable-xxhdpi/ic_fab_back.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_fab_select.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DSteve595/Image-Searcher/e8e002c736566925ff717e39015d1b37c416bad8/app/src/main/res/drawable-xxhdpi/ic_fab_select.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DSteve595/Image-Searcher/e8e002c736566925ff717e39015d1b37c416bad8/app/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi/fab_shadow_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DSteve595/Image-Searcher/e8e002c736566925ff717e39015d1b37c416bad8/app/src/main/res/drawable-xxxhdpi/fab_shadow_normal.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DSteve595/Image-Searcher/e8e002c736566925ff717e39015d1b37c416bad8/app/src/main/res/drawable-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/fab_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/layout-v21/fab_back.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /app/src/main/res/layout-v21/fab_select.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /app/src/main/res/layout/about.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 16 | 17 | 30 | 31 | 44 | 45 | 46 | 50 | 51 | 62 | 63 | 69 | 70 | 71 | 72 | 73 | 85 | 86 | -------------------------------------------------------------------------------- /app/src/main/res/layout/about_actions.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 20 | 21 | 28 | 29 | 37 | 38 | 39 | 48 | 49 | 56 | 57 | 65 | 66 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fab_back.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 19 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fab_select.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 22 | -------------------------------------------------------------------------------- /app/src/main/res/layout/imageresult_details.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 22 | 23 | 28 | 29 | 30 | 31 | 37 | 38 | 52 | 53 | 54 | 55 | 56 | 62 | 63 | 73 | 74 | 75 | 76 | 77 | 83 | 84 | 94 | 95 | 96 | 97 | 98 | 104 | 105 | 115 | 116 | 117 | -------------------------------------------------------------------------------- /app/src/main/res/layout/imageresult_full.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 11 | 12 | 17 | 18 | 26 | -------------------------------------------------------------------------------- /app/src/main/res/layout/imageresult_grid.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/layout/imageresult_pager.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 12 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/res/layout/main.xml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 16 | 17 | 24 | 25 | 38 | 39 | 40 | 47 | 48 | 53 | 54 | 67 | 68 | 69 | 72 | 73 | 81 | 82 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_result.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values-v21/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 56dp 4 | 28dp 5 | -28dp 6 | 40dp 7 | 20dp 8 | -20dp 9 | 10 | 8dp 11 | -------------------------------------------------------------------------------- /app/src/main/res/values-w400dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 100dp 4 | -------------------------------------------------------------------------------- /app/src/main/res/values-w600dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 120dp 4 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | 160dp 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #03A9F4 4 | #0288D1 5 | 6 | #40C4FF 7 | #75D3FF 8 | #A8E4FF 9 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 16dp 3 | 16dp 4 | 5 | 64dp 6 | 32dp 7 | -32dp 8 | 56dp 9 | 28dp 10 | -28dp 11 | 4dp 12 | 16dp 13 | 14 | 0dp 15 | 16 | 80dp 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Image Searcher 5 | Search images 6 | Select 7 | About 8 | Version %s 9 | Rate on the Play Store 10 | View source on GitHub 11 | Details 12 | Link 13 | Site 14 | Type 15 | Resolution 16 | Size 17 | Close 18 | %s results 19 | Select service 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 14 | 15 | 20 | 21 | 28 | 29 | 36 | 37 | 40 | 41 | -------------------------------------------------------------------------------- /app/src/main/res/xml/filepaths.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | jcenter() 4 | maven { url 'http://download.crashlytics.com/maven' } 5 | } 6 | dependencies { 7 | classpath 'com.android.tools.build:gradle:1.0.0' 8 | classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+' 9 | } 10 | } 11 | 12 | allprojects { 13 | repositories { 14 | jcenter() 15 | maven { url 'http://download.crashlytics.com/maven' } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DSteve595/Image-Searcher/e8e002c736566925ff717e39015d1b37c416bad8/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Apr 10 15:27:10 PDT 2013 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /promo.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DSteve595/Image-Searcher/e8e002c736566925ff717e39015d1b37c416bad8/promo.psd -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /web_icon.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DSteve595/Image-Searcher/e8e002c736566925ff717e39015d1b37c416bad8/web_icon.psd --------------------------------------------------------------------------------