diff --git a/app/app.iml b/app/app.iml index d8186b9..2c78c1b 100644 --- a/app/app.iml +++ b/app/app.iml @@ -1,5 +1,5 @@ - + @@ -12,10 +12,12 @@ - + @@ -82,11 +84,27 @@ + - + - + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 6d6c95d..315783f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'com.android.application' android { compileSdkVersion 22 - buildToolsVersion "23.0.0 rc3" + buildToolsVersion "23.0.0" defaultConfig { applicationId "com.akozlowski.doomvision" @@ -22,4 +22,25 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:22.2.1' + + compile 'com.squareup.picasso:picasso:2.5.2' + + compile 'org.roboguice:roboguice:3.+' + provided 'org.roboguice:roboblender:3.+' + compile 'com.squareup.retrofit:retrofit:1.9.0' + testCompile 'junit:junit:4.12' + + testCompile 'org.mockito:mockito-core:1.10.19' + androidTestCompile 'org.mockito:mockito-core:1.9.5' + androidTestCompile 'com.google.dexmaker:dexmaker:1.1' + androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.1' + testCompile "org.robolectric:robolectric:3.0" + +// compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar' + compile 'com.android.support:support-v4:22.2.1' + + compile 'io.reactivex:rxandroid:1.0.1' + // Because RxAndroid releases are few and far between, it is recommended you also +// explicitly depend on RxJava's latest version for bug fixes and new features. + compile 'io.reactivex:rxjava:1.0.14' } diff --git a/app/src/androidTest/java/com/akozlowski/doomvision/ApplicationTest.java b/app/src/androidTest/java/com/akozlowski/doomvision/ApplicationTest.java deleted file mode 100644 index 4f70688..0000000 --- a/app/src/androidTest/java/com/akozlowski/doomvision/ApplicationTest.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.akozlowski.doomvision; - -import android.app.Application; -import android.test.ApplicationTestCase; - -/** - * Testing Fundamentals - */ -public class ApplicationTest extends ApplicationTestCase { - public ApplicationTest() { - super(Application.class); - } -} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ed9d7cb..0d31906 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,15 +1,20 @@ + package="com.akozlowski.doomvision"> + + + + android:theme="@style/AppTheme"> + android:name=".ui.MainActivity" + android:configChanges="orientation" + android:label="@string/app_name"> diff --git a/app/src/main/java/com/akozlowski/doomvision/DoomVisionApplication.java b/app/src/main/java/com/akozlowski/doomvision/DoomVisionApplication.java new file mode 100644 index 0000000..cf921e4 --- /dev/null +++ b/app/src/main/java/com/akozlowski/doomvision/DoomVisionApplication.java @@ -0,0 +1,20 @@ +package com.akozlowski.doomvision; + +import android.app.Application; + +import com.akozlowski.doomvision.manager.DataManager; +import com.akozlowski.doomvision.service.InternetConnectivityReceiver; +import com.akozlowski.doomvision.util.DebugLog; + +/** + * Created by akozlowski on 14/08/15. + */ +public class DoomVisionApplication extends Application { + @Override + public void onCreate() { + super.onCreate(); + DebugLog.d("DoomVisionApplication onCreate()"); + DataManager.createInstance(); + InternetConnectivityReceiver.createInstance(this); + } +} diff --git a/app/src/main/java/com/akozlowski/doomvision/MainActivity.java b/app/src/main/java/com/akozlowski/doomvision/MainActivity.java deleted file mode 100644 index d8d413b..0000000 --- a/app/src/main/java/com/akozlowski/doomvision/MainActivity.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.akozlowski.doomvision; - -import android.support.v7.app.ActionBarActivity; -import android.os.Bundle; -import android.view.Menu; -import android.view.MenuItem; - - -public class MainActivity extends ActionBarActivity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - } - - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - // Inflate the menu; this adds items to the action bar if it is present. - getMenuInflater().inflate(R.menu.menu_main, menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - // Handle action bar item clicks here. The action bar will - // automatically handle clicks on the Home/Up button, so long - // as you specify a parent activity in AndroidManifest.xml. - int id = item.getItemId(); - - //noinspection SimplifiableIfStatement - if (id == R.id.action_settings) { - return true; - } - - return super.onOptionsItemSelected(item); - } -} diff --git a/app/src/main/java/com/akozlowski/doomvision/MainActivityFragment.java b/app/src/main/java/com/akozlowski/doomvision/MainActivityFragment.java deleted file mode 100644 index 5df94f0..0000000 --- a/app/src/main/java/com/akozlowski/doomvision/MainActivityFragment.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.akozlowski.doomvision; - -import android.support.v4.app.Fragment; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - - -/** - * A placeholder fragment containing a simple view. - */ -public class MainActivityFragment extends Fragment { - - public MainActivityFragment() { - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - return inflater.inflate(R.layout.fragment_main, container, false); - } -} diff --git a/app/src/main/java/com/akozlowski/doomvision/manager/DataManager.java b/app/src/main/java/com/akozlowski/doomvision/manager/DataManager.java new file mode 100644 index 0000000..34cff09 --- /dev/null +++ b/app/src/main/java/com/akozlowski/doomvision/manager/DataManager.java @@ -0,0 +1,40 @@ +package com.akozlowski.doomvision.manager; + +import com.akozlowski.doomvision.pojo.Response; + +import javax.inject.Singleton; + +/** + * Created by akozlowski on 17/08/15. + */ +@Singleton +public class DataManager { + private static DataManager instance; + + private DataManager() { + } + + public static DataManager getInstance() { + if (instance == null) + throw (new IllegalStateException("BrushingStateManager not initialized")); + return (instance); + } + + public static DataManager createInstance() { + if (instance != null) { + return instance; + } + instance = new DataManager(); + return instance; + } + + public void setResponse(Response response) { + this.response = response; + } + + public Response getResponse() { + return response; + } + + private Response response; +} diff --git a/app/src/main/java/com/akozlowski/doomvision/manager/RestManager.java b/app/src/main/java/com/akozlowski/doomvision/manager/RestManager.java new file mode 100644 index 0000000..cf4124a --- /dev/null +++ b/app/src/main/java/com/akozlowski/doomvision/manager/RestManager.java @@ -0,0 +1,84 @@ +package com.akozlowski.doomvision.manager; + +import android.content.Context; +import android.util.Base64; + +import com.akozlowski.doomvision.R; +import com.akozlowski.doomvision.pojo.EchoTest; +import com.akozlowski.doomvision.pojo.Response; +import com.akozlowski.doomvision.service.SearchImageService; +import com.akozlowski.doomvision.service.SearchImageServiceRx; +import com.akozlowski.doomvision.service.ServiceGenerator; +import com.akozlowski.doomvision.service.TestService; +import com.akozlowski.doomvision.service.ValidateService; +import com.akozlowski.doomvision.util.DebugLog; + +import retrofit.Callback; +import retrofit.RestAdapter; +import rx.Observable; + +/** + * Created by akozlowski on 14/08/15. + */ +public class RestManager { + + private static final String TAG = RestManager.class.getSimpleName(); + //Resicle ListView + private Context context; + + private RestAdapter restAdapter; + private String clientID; + private String clientSecret; + private String authBase64; + + public RestManager(Context context) { + this.context = context; + this.clientID = context.getString(R.string.client_id); + this.clientSecret = context.getString(R.string.client_secret); + this.authBase64 = getAuthBase64(); + } + + public RestManager(Context context, String authBase64) { + this.context = context; + this.authBase64 = authBase64; + } + + private void createRestAdapter() { + restAdapter = new RestAdapter.Builder() + .setEndpoint(getEndPoint()) + .build(); + } + + private String getAuthBase64() { + + String source = clientID + ":" + clientSecret; + String ret = "Basic " + Base64.encodeToString(source.getBytes(), Base64.URL_SAFE | Base64.NO_WRAP); + + DebugLog.d(TAG + " Authorization: " + ret); + return ret; + } + + private String getEndPoint() { + return "https://api.shutterstock.com/v2"; + } + + public void searchImage(String query, Callback cb) { + SearchImageService service = ServiceGenerator.createService(SearchImageService.class, getEndPoint(), authBase64); + service.search(query, "full", cb); + } + + public Observable searchImage(String query) { + SearchImageServiceRx service = ServiceGenerator.createService(SearchImageServiceRx.class, getEndPoint(), authBase64); + return service.search(query, "full"); + } + + public EchoTest test(String testText) { + TestService service = ServiceGenerator.createService(TestService.class, getEndPoint(), getAuthBase64()); + return service.test(testText); + } + + public void validate(String id, String tag1, String tag2, Callback cb) { + ValidateService service = ServiceGenerator.createService(ValidateService.class, getEndPoint(), getAuthBase64()); + service.validate(id, tag1, tag2, cb); + } +} diff --git a/app/src/main/java/com/akozlowski/doomvision/pojo/Assets.java b/app/src/main/java/com/akozlowski/doomvision/pojo/Assets.java new file mode 100644 index 0000000..4204c28 --- /dev/null +++ b/app/src/main/java/com/akozlowski/doomvision/pojo/Assets.java @@ -0,0 +1,164 @@ +package com.akozlowski.doomvision.pojo; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +/** + * Created by akozlowski on 14/08/15. + */ +public class Assets { + + @SerializedName("huge_jpg") + @Expose + private HugeJpg hugeJpg; + @SerializedName("medium_jpg") + @Expose + private MediumJpg mediumJpg; + @SerializedName("huge_tiff") + @Expose + private HugeTiff hugeTiff; + @SerializedName("supersize_jpg") + @Expose + private SupersizeJpg supersizeJpg; + @SerializedName("supersize_tiff") + @Expose + private SupersizeTiff supersizeTiff; + @SerializedName("small_jpg") + @Expose + private SmallJpg smallJpg; + @Expose + private Preview preview; + @SerializedName("small_thumb") + @Expose + private SmallThumb smallThumb; + @SerializedName("large_thumb") + @Expose + private LargeThumb largeThumb; + + /** + * @return The hugeJpg + */ + public HugeJpg getHugeJpg() { + return hugeJpg; + } + + /** + * @param hugeJpg The huge_jpg + */ + public void setHugeJpg(HugeJpg hugeJpg) { + this.hugeJpg = hugeJpg; + } + + /** + * @return The mediumJpg + */ + public MediumJpg getMediumJpg() { + return mediumJpg; + } + + /** + * @param mediumJpg The medium_jpg + */ + public void setMediumJpg(MediumJpg mediumJpg) { + this.mediumJpg = mediumJpg; + } + + /** + * @return The hugeTiff + */ + public HugeTiff getHugeTiff() { + return hugeTiff; + } + + /** + * @param hugeTiff The huge_tiff + */ + public void setHugeTiff(HugeTiff hugeTiff) { + this.hugeTiff = hugeTiff; + } + + /** + * @return The supersizeJpg + */ + public SupersizeJpg getSupersizeJpg() { + return supersizeJpg; + } + + /** + * @param supersizeJpg The supersize_jpg + */ + public void setSupersizeJpg(SupersizeJpg supersizeJpg) { + this.supersizeJpg = supersizeJpg; + } + + /** + * @return The supersizeTiff + */ + public SupersizeTiff getSupersizeTiff() { + return supersizeTiff; + } + + /** + * @param supersizeTiff The supersize_tiff + */ + public void setSupersizeTiff(SupersizeTiff supersizeTiff) { + this.supersizeTiff = supersizeTiff; + } + + /** + * @return The smallJpg + */ + public SmallJpg getSmallJpg() { + return smallJpg; + } + + /** + * @param smallJpg The small_jpg + */ + public void setSmallJpg(SmallJpg smallJpg) { + this.smallJpg = smallJpg; + } + + /** + * @return The preview + */ + public Preview getPreview() { + return preview; + } + + /** + * @param preview The preview + */ + public void setPreview(Preview preview) { + this.preview = preview; + } + + /** + * @return The smallThumb + */ + public SmallThumb getSmallThumb() { + return smallThumb; + } + + /** + * @param smallThumb The small_thumb + */ + public void setSmallThumb(SmallThumb smallThumb) { + this.smallThumb = smallThumb; + } + + /** + * @return The largeThumb + */ + public LargeThumb getLargeThumb() { + return largeThumb; + } + + /** + * @param largeThumb The large_thumb + */ + public void setLargeThumb(LargeThumb largeThumb) { + this.largeThumb = largeThumb; + } + +} diff --git a/app/src/main/java/com/akozlowski/doomvision/pojo/Category.java b/app/src/main/java/com/akozlowski/doomvision/pojo/Category.java new file mode 100644 index 0000000..d37da33 --- /dev/null +++ b/app/src/main/java/com/akozlowski/doomvision/pojo/Category.java @@ -0,0 +1,42 @@ +package com.akozlowski.doomvision.pojo; + +import com.google.gson.annotations.Expose; + +/** + * Created by akozlowski on 14/08/15. + */ +public class Category { + @Expose + private String id; + @Expose + private String name; + + /** + * @return The id + */ + public String getId() { + return id; + } + + /** + * @param id The id + */ + public void setId(String id) { + this.id = id; + } + + /** + * @return The name + */ + public String getName() { + return name; + } + + /** + * @param name The name + */ + public void setName(String name) { + this.name = name; + } + +} diff --git a/app/src/main/java/com/akozlowski/doomvision/pojo/Contributor.java b/app/src/main/java/com/akozlowski/doomvision/pojo/Contributor.java new file mode 100644 index 0000000..1797ba9 --- /dev/null +++ b/app/src/main/java/com/akozlowski/doomvision/pojo/Contributor.java @@ -0,0 +1,25 @@ +package com.akozlowski.doomvision.pojo; + +import com.google.gson.annotations.Expose; + +/** + * Created by akozlowski on 14/08/15. + */ +public class Contributor { + @Expose + private String id; + + /** + * @return The id + */ + public String getId() { + return id; + } + + /** + * @param id The id + */ + public void setId(String id) { + this.id = id; + } +} diff --git a/app/src/main/java/com/akozlowski/doomvision/pojo/Data.java b/app/src/main/java/com/akozlowski/doomvision/pojo/Data.java new file mode 100644 index 0000000..dc150bd --- /dev/null +++ b/app/src/main/java/com/akozlowski/doomvision/pojo/Data.java @@ -0,0 +1,211 @@ +package com.akozlowski.doomvision.pojo; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by akozlowski on 14/08/15. + */ +public class Data { + @Expose + private String id; + @SerializedName("added_date") + @Expose + private String addedDate; + @Expose + private double aspect; + @Expose + private Assets assets; + @Expose + private List categories = new ArrayList(); + @Expose + private Contributor contributor; + @Expose + private String description; + @SerializedName("image_type") + @Expose + private String imageType; + @SerializedName("is_adult") + @Expose + private boolean isAdult; + @SerializedName("is_illustration") + @Expose + private boolean isIllustration; + @Expose + private List keywords = new ArrayList(); + @SerializedName("media_type") + @Expose + private String mediaType; + + /** + * @return The id + */ + public String getId() { + return id; + } + + /** + * @param id The id + */ + public void setId(String id) { + this.id = id; + } + + /** + * @return The addedDate + */ + public String getAddedDate() { + return addedDate; + } + + /** + * @param addedDate The added_date + */ + public void setAddedDate(String addedDate) { + this.addedDate = addedDate; + } + + /** + * @return The aspect + */ + public double getAspect() { + return aspect; + } + + /** + * @param aspect The aspect + */ + public void setAspect(double aspect) { + this.aspect = aspect; + } + + /** + * @return The assets + */ + public Assets getAssets() { + return assets; + } + + /** + * @param assets The assets + */ + public void setAssets(Assets assets) { + this.assets = assets; + } + + /** + * @return The categories + */ + public List getCategories() { + return categories; + } + + /** + * @param categories The categories + */ + public void setCategories(List categories) { + this.categories = categories; + } + + /** + * @return The contributor + */ + public Contributor getContributor() { + return contributor; + } + + /** + * @param contributor The contributor + */ + public void setContributor(Contributor contributor) { + this.contributor = contributor; + } + + /** + * @return The description + */ + public String getDescription() { + return description; + } + + /** + * @param description The description + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * @return The imageType + */ + public String getImageType() { + return imageType; + } + + /** + * @param imageType The image_type + */ + public void setImageType(String imageType) { + this.imageType = imageType; + } + + /** + * @return The isAdult + */ + public boolean isIsAdult() { + return isAdult; + } + + /** + * @param isAdult The is_adult + */ + public void setIsAdult(boolean isAdult) { + this.isAdult = isAdult; + } + + /** + * @return The isIllustration + */ + public boolean isIsIllustration() { + return isIllustration; + } + + /** + * @param isIllustration The is_illustration + */ + public void setIsIllustration(boolean isIllustration) { + this.isIllustration = isIllustration; + } + + /** + * @return The keywords + */ + public List getKeywords() { + return keywords; + } + + /** + * @param keywords The keywords + */ + public void setKeywords(List keywords) { + this.keywords = keywords; + } + + /** + * @return The mediaType + */ + public String getMediaType() { + return mediaType; + } + + /** + * @param mediaType The media_type + */ + public void setMediaType(String mediaType) { + this.mediaType = mediaType; + } + +} diff --git a/app/src/main/java/com/akozlowski/doomvision/pojo/EchoTest.java b/app/src/main/java/com/akozlowski/doomvision/pojo/EchoTest.java new file mode 100644 index 0000000..877e296 --- /dev/null +++ b/app/src/main/java/com/akozlowski/doomvision/pojo/EchoTest.java @@ -0,0 +1,26 @@ +package com.akozlowski.doomvision.pojo; + +import com.google.gson.annotations.Expose; + +/** + * Created by akozlowski on 16/08/15. + */ +public class EchoTest { + + @Expose + private String text; + + /** + * @return The text + */ + public String getText() { + return text; + } + + /** + * @param text The text + */ + public void setText(String text) { + this.text = text; + } +} diff --git a/app/src/main/java/com/akozlowski/doomvision/pojo/HugeJpg.java b/app/src/main/java/com/akozlowski/doomvision/pojo/HugeJpg.java new file mode 100644 index 0000000..079e280 --- /dev/null +++ b/app/src/main/java/com/akozlowski/doomvision/pojo/HugeJpg.java @@ -0,0 +1,126 @@ +package com.akozlowski.doomvision.pojo; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +/** + * Created by akozlowski on 14/08/15. + */ +public class HugeJpg { + @SerializedName("display_name") + @Expose + private String displayName; + @Expose + private int dpi; + @SerializedName("file_size") + @Expose + private int fileSize; + @Expose + private String format; + @Expose + private int height; + @SerializedName("is_licensable") + @Expose + private boolean isLicensable; + @Expose + private int width; + + /** + * @return The displayName + */ + public String getDisplayName() { + return displayName; + } + + /** + * @param displayName The display_name + */ + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + /** + * @return The dpi + */ + public int getDpi() { + return dpi; + } + + /** + * @param dpi The dpi + */ + public void setDpi(int dpi) { + this.dpi = dpi; + } + + /** + * @return The fileSize + */ + public int getFileSize() { + return fileSize; + } + + /** + * @param fileSize The file_size + */ + public void setFileSize(int fileSize) { + this.fileSize = fileSize; + } + + /** + * @return The format + */ + public String getFormat() { + return format; + } + + /** + * @param format The format + */ + public void setFormat(String format) { + this.format = format; + } + + /** + * @return The height + */ + public int getHeight() { + return height; + } + + /** + * @param height The height + */ + public void setHeight(int height) { + this.height = height; + } + + /** + * @return The isLicensable + */ + public boolean isIsLicensable() { + return isLicensable; + } + + /** + * @param isLicensable The is_licensable + */ + public void setIsLicensable(boolean isLicensable) { + this.isLicensable = isLicensable; + } + + /** + * @return The width + */ + public int getWidth() { + return width; + } + + /** + * @param width The width + */ + public void setWidth(int width) { + this.width = width; + } + +} diff --git a/app/src/main/java/com/akozlowski/doomvision/pojo/HugeTiff.java b/app/src/main/java/com/akozlowski/doomvision/pojo/HugeTiff.java new file mode 100644 index 0000000..97f663b --- /dev/null +++ b/app/src/main/java/com/akozlowski/doomvision/pojo/HugeTiff.java @@ -0,0 +1,126 @@ +package com.akozlowski.doomvision.pojo; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +/** + * Created by akozlowski on 14/08/15. + */ +public class HugeTiff { + + @SerializedName("display_name") + @Expose + private String displayName; + @Expose + private int dpi; + @SerializedName("file_size") + @Expose + private int fileSize; + @Expose + private String format; + @Expose + private int height; + @SerializedName("is_licensable") + @Expose + private boolean isLicensable; + @Expose + private int width; + + /** + * @return The displayName + */ + public String getDisplayName() { + return displayName; + } + + /** + * @param displayName The display_name + */ + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + /** + * @return The dpi + */ + public int getDpi() { + return dpi; + } + + /** + * @param dpi The dpi + */ + public void setDpi(int dpi) { + this.dpi = dpi; + } + + /** + * @return The fileSize + */ + public int getFileSize() { + return fileSize; + } + + /** + * @param fileSize The file_size + */ + public void setFileSize(int fileSize) { + this.fileSize = fileSize; + } + + /** + * @return The format + */ + public String getFormat() { + return format; + } + + /** + * @param format The format + */ + public void setFormat(String format) { + this.format = format; + } + + /** + * @return The height + */ + public int getHeight() { + return height; + } + + /** + * @param height The height + */ + public void setHeight(int height) { + this.height = height; + } + + /** + * @return The isLicensable + */ + public boolean isIsLicensable() { + return isLicensable; + } + + /** + * @param isLicensable The is_licensable + */ + public void setIsLicensable(boolean isLicensable) { + this.isLicensable = isLicensable; + } + + /** + * @return The width + */ + public int getWidth() { + return width; + } + + /** + * @param width The width + */ + public void setWidth(int width) { + this.width = width; + } +} diff --git a/app/src/main/java/com/akozlowski/doomvision/pojo/LargeThumb.java b/app/src/main/java/com/akozlowski/doomvision/pojo/LargeThumb.java new file mode 100644 index 0000000..77cce3a --- /dev/null +++ b/app/src/main/java/com/akozlowski/doomvision/pojo/LargeThumb.java @@ -0,0 +1,57 @@ +package com.akozlowski.doomvision.pojo; + +import com.google.gson.annotations.Expose; + +/** + * Created by akozlowski on 14/08/15. + */ +public class LargeThumb { + @Expose + private int height; + @Expose + private String url; + @Expose + private int width; + + /** + * @return The height + */ + public int getHeight() { + return height; + } + + /** + * @param height The height + */ + public void setHeight(int height) { + this.height = height; + } + + /** + * @return The url + */ + public String getUrl() { + return url; + } + + /** + * @param url The url + */ + public void setUrl(String url) { + this.url = url; + } + + /** + * @return The width + */ + public int getWidth() { + return width; + } + + /** + * @param width The width + */ + public void setWidth(int width) { + this.width = width; + } +} diff --git a/app/src/main/java/com/akozlowski/doomvision/pojo/MediumJpg.java b/app/src/main/java/com/akozlowski/doomvision/pojo/MediumJpg.java new file mode 100644 index 0000000..4eb5d48 --- /dev/null +++ b/app/src/main/java/com/akozlowski/doomvision/pojo/MediumJpg.java @@ -0,0 +1,126 @@ +package com.akozlowski.doomvision.pojo; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +/** + * Created by akozlowski on 14/08/15. + */ +public class MediumJpg { + + @SerializedName("display_name") + @Expose + private String displayName; + @Expose + private int dpi; + @SerializedName("file_size") + @Expose + private int fileSize; + @Expose + private String format; + @Expose + private int height; + @SerializedName("is_licensable") + @Expose + private boolean isLicensable; + @Expose + private int width; + + /** + * @return The displayName + */ + public String getDisplayName() { + return displayName; + } + + /** + * @param displayName The display_name + */ + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + /** + * @return The dpi + */ + public int getDpi() { + return dpi; + } + + /** + * @param dpi The dpi + */ + public void setDpi(int dpi) { + this.dpi = dpi; + } + + /** + * @return The fileSize + */ + public int getFileSize() { + return fileSize; + } + + /** + * @param fileSize The file_size + */ + public void setFileSize(int fileSize) { + this.fileSize = fileSize; + } + + /** + * @return The format + */ + public String getFormat() { + return format; + } + + /** + * @param format The format + */ + public void setFormat(String format) { + this.format = format; + } + + /** + * @return The height + */ + public int getHeight() { + return height; + } + + /** + * @param height The height + */ + public void setHeight(int height) { + this.height = height; + } + + /** + * @return The isLicensable + */ + public boolean isIsLicensable() { + return isLicensable; + } + + /** + * @param isLicensable The is_licensable + */ + public void setIsLicensable(boolean isLicensable) { + this.isLicensable = isLicensable; + } + + /** + * @return The width + */ + public int getWidth() { + return width; + } + + /** + * @param width The width + */ + public void setWidth(int width) { + this.width = width; + } +} diff --git a/app/src/main/java/com/akozlowski/doomvision/pojo/Preview.java b/app/src/main/java/com/akozlowski/doomvision/pojo/Preview.java new file mode 100644 index 0000000..329e87d --- /dev/null +++ b/app/src/main/java/com/akozlowski/doomvision/pojo/Preview.java @@ -0,0 +1,57 @@ +package com.akozlowski.doomvision.pojo; + +import com.google.gson.annotations.Expose; + +/** + * Created by akozlowski on 14/08/15. + */ +public class Preview { + @Expose + private int height; + @Expose + private String url; + @Expose + private int width; + + /** + * @return The height + */ + public int getHeight() { + return height; + } + + /** + * @param height The height + */ + public void setHeight(int height) { + this.height = height; + } + + /** + * @return The url + */ + public String getUrl() { + return url; + } + + /** + * @param url The url + */ + public void setUrl(String url) { + this.url = url; + } + + /** + * @return The width + */ + public int getWidth() { + return width; + } + + /** + * @param width The width + */ + public void setWidth(int width) { + this.width = width; + } +} diff --git a/app/src/main/java/com/akozlowski/doomvision/pojo/Response.java b/app/src/main/java/com/akozlowski/doomvision/pojo/Response.java new file mode 100644 index 0000000..9bd5d86 --- /dev/null +++ b/app/src/main/java/com/akozlowski/doomvision/pojo/Response.java @@ -0,0 +1,101 @@ +package com.akozlowski.doomvision.pojo; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by akozlowski on 14/08/15. + */ +public class Response { + + @Expose + private int page; + @SerializedName("per_page") + @Expose + private int perPage; + @SerializedName("total_count") + @Expose + private int totalCount; + @SerializedName("search_id") + @Expose + private String searchId; + @Expose + private List data = new ArrayList(); + + /** + * @return The page + */ + public int getPage() { + return page; + } + + /** + * @param page The page + */ + public void setPage(int page) { + this.page = page; + } + + /** + * @return The perPage + */ + public int getPerPage() { + return perPage; + } + + /** + * @param perPage The per_page + */ + public void setPerPage(int perPage) { + this.perPage = perPage; + } + + /** + * @return The totalCount + */ + public int getTotalCount() { + return totalCount; + } + + /** + * @param totalCount The total_count + */ + public void setTotalCount(int totalCount) { + this.totalCount = totalCount; + } + + /** + * @return The searchId + */ + public String getSearchId() { + return searchId; + } + + /** + * @param searchId The search_id + */ + public void setSearchId(String searchId) { + this.searchId = searchId; + } + + /** + * @return The data + */ + public List getData() { + return data; + } + + /** + * @param data The data + */ + public void setData(List data) { + this.data = data; + } + + public class Assets { + + } +} diff --git a/app/src/main/java/com/akozlowski/doomvision/pojo/SmallJpg.java b/app/src/main/java/com/akozlowski/doomvision/pojo/SmallJpg.java new file mode 100644 index 0000000..a4eab5a --- /dev/null +++ b/app/src/main/java/com/akozlowski/doomvision/pojo/SmallJpg.java @@ -0,0 +1,125 @@ +package com.akozlowski.doomvision.pojo; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +/** + * Created by akozlowski on 14/08/15. + */ +public class SmallJpg { + @SerializedName("display_name") + @Expose + private String displayName; + @Expose + private int dpi; + @SerializedName("file_size") + @Expose + private int fileSize; + @Expose + private String format; + @Expose + private int height; + @SerializedName("is_licensable") + @Expose + private boolean isLicensable; + @Expose + private int width; + + /** + * @return The displayName + */ + public String getDisplayName() { + return displayName; + } + + /** + * @param displayName The display_name + */ + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + /** + * @return The dpi + */ + public int getDpi() { + return dpi; + } + + /** + * @param dpi The dpi + */ + public void setDpi(int dpi) { + this.dpi = dpi; + } + + /** + * @return The fileSize + */ + public int getFileSize() { + return fileSize; + } + + /** + * @param fileSize The file_size + */ + public void setFileSize(int fileSize) { + this.fileSize = fileSize; + } + + /** + * @return The format + */ + public String getFormat() { + return format; + } + + /** + * @param format The format + */ + public void setFormat(String format) { + this.format = format; + } + + /** + * @return The height + */ + public int getHeight() { + return height; + } + + /** + * @param height The height + */ + public void setHeight(int height) { + this.height = height; + } + + /** + * @return The isLicensable + */ + public boolean isIsLicensable() { + return isLicensable; + } + + /** + * @param isLicensable The is_licensable + */ + public void setIsLicensable(boolean isLicensable) { + this.isLicensable = isLicensable; + } + + /** + * @return The width + */ + public int getWidth() { + return width; + } + + /** + * @param width The width + */ + public void setWidth(int width) { + this.width = width; + } +} diff --git a/app/src/main/java/com/akozlowski/doomvision/pojo/SmallThumb.java b/app/src/main/java/com/akozlowski/doomvision/pojo/SmallThumb.java new file mode 100644 index 0000000..8a4d9ad --- /dev/null +++ b/app/src/main/java/com/akozlowski/doomvision/pojo/SmallThumb.java @@ -0,0 +1,57 @@ +package com.akozlowski.doomvision.pojo; + +import com.google.gson.annotations.Expose; + +/** + * Created by akozlowski on 14/08/15. + */ +public class SmallThumb { + @Expose + private int height; + @Expose + private String url; + @Expose + private int width; + + /** + * @return The height + */ + public int getHeight() { + return height; + } + + /** + * @param height The height + */ + public void setHeight(int height) { + this.height = height; + } + + /** + * @return The url + */ + public String getUrl() { + return url; + } + + /** + * @param url The url + */ + public void setUrl(String url) { + this.url = url; + } + + /** + * @return The width + */ + public int getWidth() { + return width; + } + + /** + * @param width The width + */ + public void setWidth(int width) { + this.width = width; + } +} diff --git a/app/src/main/java/com/akozlowski/doomvision/pojo/SupersizeJpg.java b/app/src/main/java/com/akozlowski/doomvision/pojo/SupersizeJpg.java new file mode 100644 index 0000000..d5102c9 --- /dev/null +++ b/app/src/main/java/com/akozlowski/doomvision/pojo/SupersizeJpg.java @@ -0,0 +1,125 @@ +package com.akozlowski.doomvision.pojo; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +/** + * Created by akozlowski on 14/08/15. + */ +public class SupersizeJpg { + @SerializedName("display_name") + @Expose + private String displayName; + @Expose + private int dpi; + @SerializedName("file_size") + @Expose + private int fileSize; + @Expose + private String format; + @Expose + private int height; + @SerializedName("is_licensable") + @Expose + private boolean isLicensable; + @Expose + private int width; + + /** + * @return The displayName + */ + public String getDisplayName() { + return displayName; + } + + /** + * @param displayName The display_name + */ + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + /** + * @return The dpi + */ + public int getDpi() { + return dpi; + } + + /** + * @param dpi The dpi + */ + public void setDpi(int dpi) { + this.dpi = dpi; + } + + /** + * @return The fileSize + */ + public int getFileSize() { + return fileSize; + } + + /** + * @param fileSize The file_size + */ + public void setFileSize(int fileSize) { + this.fileSize = fileSize; + } + + /** + * @return The format + */ + public String getFormat() { + return format; + } + + /** + * @param format The format + */ + public void setFormat(String format) { + this.format = format; + } + + /** + * @return The height + */ + public int getHeight() { + return height; + } + + /** + * @param height The height + */ + public void setHeight(int height) { + this.height = height; + } + + /** + * @return The isLicensable + */ + public boolean isIsLicensable() { + return isLicensable; + } + + /** + * @param isLicensable The is_licensable + */ + public void setIsLicensable(boolean isLicensable) { + this.isLicensable = isLicensable; + } + + /** + * @return The width + */ + public int getWidth() { + return width; + } + + /** + * @param width The width + */ + public void setWidth(int width) { + this.width = width; + } +} diff --git a/app/src/main/java/com/akozlowski/doomvision/pojo/SupersizeTiff.java b/app/src/main/java/com/akozlowski/doomvision/pojo/SupersizeTiff.java new file mode 100644 index 0000000..abe9f62 --- /dev/null +++ b/app/src/main/java/com/akozlowski/doomvision/pojo/SupersizeTiff.java @@ -0,0 +1,125 @@ +package com.akozlowski.doomvision.pojo; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +/** + * Created by akozlowski on 14/08/15. + */ +public class SupersizeTiff { + @SerializedName("display_name") + @Expose + private String displayName; + @Expose + private int dpi; + @SerializedName("file_size") + @Expose + private int fileSize; + @Expose + private String format; + @Expose + private int height; + @SerializedName("is_licensable") + @Expose + private boolean isLicensable; + @Expose + private int width; + + /** + * @return The displayName + */ + public String getDisplayName() { + return displayName; + } + + /** + * @param displayName The display_name + */ + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + /** + * @return The dpi + */ + public int getDpi() { + return dpi; + } + + /** + * @param dpi The dpi + */ + public void setDpi(int dpi) { + this.dpi = dpi; + } + + /** + * @return The fileSize + */ + public int getFileSize() { + return fileSize; + } + + /** + * @param fileSize The file_size + */ + public void setFileSize(int fileSize) { + this.fileSize = fileSize; + } + + /** + * @return The format + */ + public String getFormat() { + return format; + } + + /** + * @param format The format + */ + public void setFormat(String format) { + this.format = format; + } + + /** + * @return The height + */ + public int getHeight() { + return height; + } + + /** + * @param height The height + */ + public void setHeight(int height) { + this.height = height; + } + + /** + * @return The isLicensable + */ + public boolean isIsLicensable() { + return isLicensable; + } + + /** + * @param isLicensable The is_licensable + */ + public void setIsLicensable(boolean isLicensable) { + this.isLicensable = isLicensable; + } + + /** + * @return The width + */ + public int getWidth() { + return width; + } + + /** + * @param width The width + */ + public void setWidth(int width) { + this.width = width; + } +} diff --git a/app/src/main/java/com/akozlowski/doomvision/service/InternetConnectivityReceiver.java b/app/src/main/java/com/akozlowski/doomvision/service/InternetConnectivityReceiver.java new file mode 100644 index 0000000..900a5a2 --- /dev/null +++ b/app/src/main/java/com/akozlowski/doomvision/service/InternetConnectivityReceiver.java @@ -0,0 +1,96 @@ +package com.akozlowski.doomvision.service; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by akozlowski on 15/08/15. + */ +public class InternetConnectivityReceiver { + private List callbacks = new ArrayList(); + private volatile boolean isReceiverRegistered = false; + private ConnectivityManager connectivityManager; + private Context context; + private static InternetConnectivityReceiver instance; + + public static InternetConnectivityReceiver getInstance() { + return instance; + } + + public static synchronized InternetConnectivityReceiver createInstance(Context context) { + instance = new InternetConnectivityReceiver(context); + return instance; + } + + private InternetConnectivityReceiver(Context context) { + this.context = context; + connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + } + + private void addInternetConnectivityListener(InternetConnectivityListener internetConnectivityListener) { + synchronized (callbacks) { + if (!callbacks.contains(internetConnectivityListener)) { + callbacks.add(internetConnectivityListener); + } + } + } + + public boolean isOnline() { + NetworkInfo info = connectivityManager.getActiveNetworkInfo(); + return info != null && info.isConnected() && info.isAvailable(); + } + + public void removeInternetConnectivityListener(InternetConnectivityListener connectivityListener) { + synchronized (callbacks) { + callbacks.remove(connectivityListener); + } + } + + private void notifyListeners() { + synchronized (callbacks) { + for (InternetConnectivityListener internetConnectivityListener : callbacks) { + internetConnectivityListener.onInternetConnectivityCallback(); + } + } + } + + private BroadcastReceiver receiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) { + boolean lackOfConnectivity = intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false); + if (!lackOfConnectivity && isOnline()) { + notifyListeners(); + } + } + } + }; + + /** + * register receiver CONNECTIVITY_ACTION from {@link ConnectivityManager} + * + * @param internetConnectivityListener pass it to get call if connectivity status will get change + */ + public void registerConnectivityReceiver(InternetConnectivityListener + internetConnectivityListener) { + addInternetConnectivityListener(internetConnectivityListener); + if (isReceiverRegistered) { + return; + } + IntentFilter filterInternet = new IntentFilter(); + filterInternet.addAction(ConnectivityManager.CONNECTIVITY_ACTION); + context.registerReceiver(receiver, filterInternet); + isReceiverRegistered = true; + } + + public interface InternetConnectivityListener { + void onInternetConnectivityCallback(); + } +} diff --git a/app/src/main/java/com/akozlowski/doomvision/service/SearchImageService.java b/app/src/main/java/com/akozlowski/doomvision/service/SearchImageService.java new file mode 100644 index 0000000..cf6f6b7 --- /dev/null +++ b/app/src/main/java/com/akozlowski/doomvision/service/SearchImageService.java @@ -0,0 +1,25 @@ +package com.akozlowski.doomvision.service; + +import com.akozlowski.doomvision.pojo.Response; + +import retrofit.Callback; +import retrofit.http.GET; +import retrofit.http.Query; +import rx.Observable; + +/** + * Created by akozlowski on 14/08/15. + * https://api.shutterstock.com/v2/images/search?license=commercial&&&&&&&&&&query=dog&&sort=popular&view=minimal + */ +public interface SearchImageService { + + + @GET("/images/search") + void search(@Query("query") String query, @Query("view") String view, Callback cb); + +// @GET("/search") +// void search(@Query("license") String license, @Query("query") String query, Callback cb); + +// @GET("/search?license=commercial&&&&&&&&&&query={query}") +// void search(@Query("query") String query, Callback cb); +} diff --git a/app/src/main/java/com/akozlowski/doomvision/service/SearchImageServiceRx.java b/app/src/main/java/com/akozlowski/doomvision/service/SearchImageServiceRx.java new file mode 100644 index 0000000..f951d59 --- /dev/null +++ b/app/src/main/java/com/akozlowski/doomvision/service/SearchImageServiceRx.java @@ -0,0 +1,16 @@ +package com.akozlowski.doomvision.service; + +import com.akozlowski.doomvision.pojo.Response; + +import retrofit.Callback; +import retrofit.http.GET; +import retrofit.http.Query; +import rx.Observable; + +/** + * Created by and on 10.09.15. + */ +public interface SearchImageServiceRx { + @GET("/images/search") + Observable search(@Query("query") String query, @Query("view") String view); +} diff --git a/app/src/main/java/com/akozlowski/doomvision/service/ServiceGenerator.java b/app/src/main/java/com/akozlowski/doomvision/service/ServiceGenerator.java new file mode 100644 index 0000000..b75b0e6 --- /dev/null +++ b/app/src/main/java/com/akozlowski/doomvision/service/ServiceGenerator.java @@ -0,0 +1,23 @@ +package com.akozlowski.doomvision.service; + +import retrofit.RequestInterceptor; +import retrofit.RestAdapter; + +/** + * Created by akozlowski on 14/08/15. + */ +public class ServiceGenerator { + public static S createService(Class serviceClass, String baseUrl, final String auth) { + RestAdapter.Builder builder = new RestAdapter.Builder() + .setEndpoint(baseUrl).setRequestInterceptor(new RequestInterceptor() { + @Override + public void intercept(RequestFacade request) { + request.addHeader("Authorization", auth); + request.addHeader("Content-Type", "application/json"); + request.addHeader("Accept", "application/json"); + } + }); + RestAdapter adapter = builder.build(); + return adapter.create(serviceClass); + } +} diff --git a/app/src/main/java/com/akozlowski/doomvision/service/TestService.java b/app/src/main/java/com/akozlowski/doomvision/service/TestService.java new file mode 100644 index 0000000..9a218a7 --- /dev/null +++ b/app/src/main/java/com/akozlowski/doomvision/service/TestService.java @@ -0,0 +1,14 @@ +package com.akozlowski.doomvision.service; + +import com.akozlowski.doomvision.pojo.EchoTest; + +import retrofit.http.GET; +import retrofit.http.Query; + +/** + * Created by akozlowski on 15/08/15. + */ +public interface TestService { + @GET("/test") + EchoTest test(@Query("test") String testText); +} diff --git a/app/src/main/java/com/akozlowski/doomvision/service/ValidateService.java b/app/src/main/java/com/akozlowski/doomvision/service/ValidateService.java new file mode 100644 index 0000000..6c52f41 --- /dev/null +++ b/app/src/main/java/com/akozlowski/doomvision/service/ValidateService.java @@ -0,0 +1,15 @@ +package com.akozlowski.doomvision.service; + +import com.akozlowski.doomvision.pojo.Response; + +import retrofit.Callback; +import retrofit.http.GET; +import retrofit.http.Query; + +/** + * Created by akozlowski on 15/08/15. + */ +public interface ValidateService { + @GET("/test/validate") + void validate(@Query("id") String id, @Query("tag1") String tag1, @Query("tag2") String tag2, Callback cb); +} diff --git a/app/src/main/java/com/akozlowski/doomvision/ui/ImageViewPageFragment.java b/app/src/main/java/com/akozlowski/doomvision/ui/ImageViewPageFragment.java new file mode 100644 index 0000000..cf1c5fa --- /dev/null +++ b/app/src/main/java/com/akozlowski/doomvision/ui/ImageViewPageFragment.java @@ -0,0 +1,56 @@ +package com.akozlowski.doomvision.ui; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; + +import com.akozlowski.doomvision.R; +import com.akozlowski.doomvision.manager.DataManager; +import com.akozlowski.doomvision.pojo.Data; +import com.squareup.picasso.Picasso; + +import roboguice.fragment.RoboFragment; +import roboguice.inject.InjectView; + +/** + * Created by akozlowski on 17/08/15. + */ +public class ImageViewPageFragment extends RoboFragment { + @InjectView(R.id.view_pager_image) + private ImageView imageView; + + + public static final String EXTRA_INDEX_KEY = "extra_index_key"; + + public static ImageViewPageFragment createInstance(int index) { + Bundle bundle = new Bundle(); + bundle.putInt(EXTRA_INDEX_KEY, index); + ImageViewPageFragment imageViewPageFragment = new ImageViewPageFragment(); + imageViewPageFragment.setArguments(bundle); + return imageViewPageFragment; + + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + } + + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + return inflater.inflate(R.layout.image_view_pager_fragment, container, false); + } + + @Override + public void onResume() { + super.onResume(); + if (getArguments() != null && getArguments().containsKey(EXTRA_INDEX_KEY)) { + int index = getArguments().getInt(EXTRA_INDEX_KEY); + Data data = DataManager.getInstance().getResponse().getData().get(index); + Picasso.with(getActivity()).load(data.getAssets().getPreview().getUrl()).into(imageView); + } + } +} diff --git a/app/src/main/java/com/akozlowski/doomvision/ui/IndicatorView.java b/app/src/main/java/com/akozlowski/doomvision/ui/IndicatorView.java new file mode 100644 index 0000000..0d4ea67 --- /dev/null +++ b/app/src/main/java/com/akozlowski/doomvision/ui/IndicatorView.java @@ -0,0 +1,99 @@ +package com.akozlowski.doomvision.ui; + +import android.content.Context; +import android.graphics.Canvas; +import android.graphics.Paint; +import android.util.AttributeSet; +import android.view.View; + +import com.akozlowski.doomvision.R; +import com.akozlowski.doomvision.util.Density; + +/** + * Created by akozlowski on 17/08/15. + */ +public class IndicatorView extends View { + private Context context; + private float RADIUS = 4f; + private boolean isSelected = false; + private Paint selectedPaint; + private Paint normalPaint; + private int selectedResourceColorID = -1; + + /** + * @param context + */ + public IndicatorView(Context context) { + super(context); + this.context = context; + init(); + } + + public IndicatorView(Context context, int selectedResourceColorID) { + super(context); + this.context = context; + this.selectedResourceColorID = selectedResourceColorID; + init(); + } + + /** + * @param context + * @param attrs + */ + public IndicatorView(Context context, AttributeSet attrs) { + super(context, attrs); + this.context = context; + init(); + } + + /** + * @param context + * @param attrs + * @param defStyleAttr + */ + public IndicatorView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + this.context = context; + init(); + } + + + private void init() { + setBackgroundColor(context.getResources().getColor(android.R.color.transparent)); + RADIUS *= Density.getDensityMultiplier(context); + + selectedPaint = new Paint(); + if (selectedResourceColorID > 0) { + selectedPaint.setColor(getResources().getColor(selectedResourceColorID)); + } else { + selectedPaint.setColor(getResources().getColor(R.color.getting_started_circle_indicator_fill_color)); + } + + selectedPaint.setAntiAlias(true); + selectedPaint.setStyle(Paint.Style.FILL); + + normalPaint = new Paint(); + normalPaint.setColor(getResources().getColor(R.color.getting_started_circle_indicator_page_color)); + normalPaint.setAntiAlias(true); + normalPaint.setStyle(Paint.Style.FILL); + } + + @Override + public void onDraw(Canvas canvas) { + int width = getWidth(); + int height = getHeight(); + if (!isSelected) { + canvas.drawCircle(width / 2, height / 2, RADIUS, normalPaint); + } else { + canvas.drawCircle(width / 2, height / 2, RADIUS, selectedPaint); + } + } + + /** + * @param isSelected + */ + public void setIsSelected(boolean isSelected) { + this.isSelected = isSelected; + invalidate(); + } +} diff --git a/app/src/main/java/com/akozlowski/doomvision/ui/ListViewGalleryFragment.java b/app/src/main/java/com/akozlowski/doomvision/ui/ListViewGalleryFragment.java new file mode 100644 index 0000000..6b7f0c6 --- /dev/null +++ b/app/src/main/java/com/akozlowski/doomvision/ui/ListViewGalleryFragment.java @@ -0,0 +1,220 @@ +package com.akozlowski.doomvision.ui; + +import android.content.Context; +import android.os.Bundle; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentTransaction; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.inputmethod.InputMethodManager; +import android.widget.ArrayAdapter; +import android.widget.EditText; +import android.widget.ImageView; +import android.widget.ListView; +import android.widget.ProgressBar; +import android.widget.TextView; +import android.widget.Toast; + +import com.akozlowski.doomvision.R; +import com.akozlowski.doomvision.manager.DataManager; +import com.akozlowski.doomvision.manager.RestManager; +import com.akozlowski.doomvision.pojo.Category; +import com.akozlowski.doomvision.pojo.Data; +import com.akozlowski.doomvision.pojo.Response; +import com.akozlowski.doomvision.service.InternetConnectivityReceiver; +import com.akozlowski.doomvision.ui.listView.CustomAdapter; +import com.akozlowski.doomvision.ui.listView.Item; +import com.akozlowski.doomvision.util.DebugLog; +import com.squareup.picasso.Picasso; + +import java.util.ArrayList; +import java.util.List; + +import roboguice.RoboGuice; +import roboguice.fragment.RoboFragment; +import roboguice.inject.InjectView; +import rx.Observer; +import rx.android.schedulers.AndroidSchedulers; +import rx.schedulers.Schedulers; + + +/** + * A placeholder fragment containing a simple view. + */ +public class ListViewGalleryFragment extends RoboFragment { + private static final String TAG = ListViewGalleryFragment.class.getSimpleName(); + private RestManager restManager; + @InjectView(R.id.response) + private TextView responseTextView; + @InjectView(R.id.search_field) + private EditText searchEditText; + @InjectView(R.id.search_btn) + private ImageView searchBtn; + @InjectView(R.id.listview) + private ListView listView; + private List items = new ArrayList(); + @InjectView(R.id.search_progress) + private ProgressBar progressBar; + + + public ListViewGalleryFragment() { + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + + return inflater.inflate(R.layout.list_view_gallery_fragment, container, false); + } + + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + RoboGuice.getInjector(getActivity()).injectViewMembers(this); + } + + @Override + public void onResume() { + super.onResume(); + restManager = new RestManager(getActivity()); + createListView(); + if (DataManager.getInstance().getResponse() != null) { + createItems(DataManager.getInstance().getResponse()); + } + searchBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + hideKeyboard(); + progressBar.setVisibility(View.VISIBLE); + search(); + } + }); + } + + private void createListView() { + CustomAdapter customAdapter = new CustomAdapter(getActivity(), R.layout.list_view_content, items); + listView.setAdapter(customAdapter); + } + + private void createItems(Response response) { + List dataList = response.getData(); + items.clear(); + DataManager.getInstance().setResponse(response); + + int index = 0; + for (Data data : dataList) { + items.add(new ImageItem(data.getAssets().getPreview().getUrl(), index)); + printCategories(data.getCategories()); + index++; + } + ((ArrayAdapter) listView.getAdapter()).notifyDataSetChanged(); + } + + private void printCategories(List categories) { + for (Category category : categories) { + DebugLog.d(TAG + " cat: " + category.getName()); + } + } + + private void hideKeyboard() { + InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(searchEditText.getWindowToken(), 0); + getView().invalidate(); + } + + private static class ViewItemHolder { + ViewItemHolder(ImageView imageView) { + this.imageView = imageView; + } + + public final ImageView imageView; + } + + private class ImageItem implements Item { + final private String url; + final private int index; + + public ImageItem(String url, int index) { + DebugLog.d(TAG + " create Item url: " + url); + this.url = url; + this.index = index; + + } + + @Override + public int getViewType() { + return Item.ItemType.values().length; + } + + @Override + public View getView(LayoutInflater inflater, View convertView, ViewGroup parent) { + ViewItemHolder viewItemHolder; + if (convertView == null) { + convertView = inflater.inflate(R.layout.image_item, parent, false); + viewItemHolder = new ViewItemHolder((ImageView) convertView.findViewById(R.id.image)); + convertView.setTag(viewItemHolder); + } + viewItemHolder = (ViewItemHolder) convertView.getTag(); + Picasso.with(getActivity()).load(url).into(viewItemHolder.imageView); + viewItemHolder.imageView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + DebugLog.d(TAG + " onClick index " + index); + FragmentManager fm = getActivity().getSupportFragmentManager(); + FragmentTransaction transaction = fm.beginTransaction(); + Bundle bundle = new Bundle(); + bundle.putInt(SlidesGalleryFragment.PAGE_INDEX_KEY, index); + SlidesGalleryFragment slidesGalleryFragment = new SlidesGalleryFragment(); + slidesGalleryFragment.setArguments(bundle); + transaction.replace(R.id.fragment_container, slidesGalleryFragment, SlidesGalleryFragment.class.getSimpleName()).addToBackStack(null).commit(); + } + }); + return convertView; + } + } + +private void search() { + restManager.searchImage(searchEditText.getText().toString()).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer() { + @Override + public void onCompleted() { + + } + + @Override + public void onError(Throwable e) { + if(e != null && e.getMessage() != null) { + DebugLog.d(TAG + " error: " + e.toString() + ", " + e.getMessage() + ", "); + Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show(); + } +// if (e.getKind().equals(RetrofitError.Kind.NETWORK)) { + searchBtn.setEnabled(false); + progressBar.setVisibility(View.GONE); + onNoInternetConnection(); +// } + } + + @Override + public void onNext(Response response) { + DebugLog.d(TAG + " responce: " + response.toString()); + if (response != null && response.getData() != null && response.getData().size() > 0) { + ((MainActivity) getActivity()).changeRequestedOrientation(true); + } else { + ((MainActivity) getActivity()).changeRequestedOrientation(false); + } + createItems(response); + progressBar.setVisibility(View.GONE); + } + }); + +// } +} + private void onNoInternetConnection() { + Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.no_internet_msg), Toast.LENGTH_LONG); + InternetConnectivityReceiver.getInstance().registerConnectivityReceiver(new InternetConnectivityReceiver.InternetConnectivityListener() { + @Override + public void onInternetConnectivityCallback() { + searchBtn.setEnabled(true); + } + }); + } +} diff --git a/app/src/main/java/com/akozlowski/doomvision/ui/MainActivity.java b/app/src/main/java/com/akozlowski/doomvision/ui/MainActivity.java new file mode 100644 index 0000000..5c3d379 --- /dev/null +++ b/app/src/main/java/com/akozlowski/doomvision/ui/MainActivity.java @@ -0,0 +1,152 @@ +package com.akozlowski.doomvision.ui; + +import android.app.Activity; +import android.content.pm.ActivityInfo; +import android.content.res.Configuration; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentActivity; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentTransaction; +import android.view.WindowManager; + +import com.akozlowski.doomvision.R; +import com.akozlowski.doomvision.manager.DataManager; +import com.akozlowski.doomvision.util.DebugLog; +import com.google.inject.Key; + +import java.util.HashMap; +import java.util.Map; + +import javax.inject.Inject; + +import roboguice.RoboGuice; +import roboguice.activity.event.OnContentChangedEvent; +import roboguice.activity.event.OnStopEvent; +import roboguice.context.event.OnCreateEvent; +import roboguice.context.event.OnDestroyEvent; +import roboguice.event.EventManager; +import roboguice.inject.ContentView; +import roboguice.inject.ContentViewListener; +import roboguice.inject.RoboInjector; +import roboguice.util.RoboContext; + +@ContentView(R.layout.activity_main) +public class MainActivity extends FragmentActivity implements RoboContext { + + private static final String TAG = MainActivity.class.getSimpleName(); + protected EventManager eventManager; + protected HashMap, Object> scopedObjects = new HashMap, Object>(); + private static final String STATE_ORIENTATION_KEY = "STATE_ORIENTATION_KEY"; + + @Inject + ContentViewListener ignored; // BUG find a better place to put this + + private void changeFragment(Fragment fragment, String name) { + FragmentManager fragmentManager = getSupportFragmentManager(); + FragmentTransaction transaction = fragmentManager.beginTransaction(); + transaction.replace(R.id.fragment_container, fragment, name).commit(); + } + + + @Override + protected void onCreate(Bundle savedInstanceState) { + DebugLog.d(TAG + " onCreate()..."); + if (DataManager.getInstance().getResponse() == null) { + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + } else { + getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); + } + final RoboInjector injector = RoboGuice.getInjector(this); + eventManager = injector.getInstance(EventManager.class); + injector.injectMembersWithoutViews(this); + super.onCreate(savedInstanceState); + eventManager.fire(new OnCreateEvent(this, savedInstanceState)); + FragmentManager fragmentManager = getSupportFragmentManager(); + FragmentTransaction transaction = fragmentManager.beginTransaction(); + if (savedInstanceState == null) { + DebugLog.d(TAG + " onCreate()..savedInstanceState is null"); + transaction.replace(R.id.fragment_container, new ListViewGalleryFragment()).addToBackStack(null).commit(); + } else { + if (getResources().getConfiguration().orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { + DebugLog.d(TAG + " SCREEN_ORIENTATION_PORTRAIT"); + changeFragment(new ListViewGalleryFragment(), ListViewGalleryFragment.class.getSimpleName()); + } else { + DebugLog.d(TAG + " SCREEN_ORIENTATION_LANDSCAPE"); + changeFragment(new SlidesGalleryFragment(), SlidesGalleryFragment.class.getSimpleName()); + } + } + } + + public void changeRequestedOrientation(boolean sensorOn) { + if (sensorOn) { + getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); + } else { + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + } + } + + @Override + protected void onStop() { + try { + eventManager.fire(new OnStopEvent(this)); + } finally { + super.onStop(); + } + } + + @Override + protected void onDestroy() { + try { + eventManager.fire(new OnDestroyEvent(this)); + } finally { + try { + RoboGuice.destroyInjector(this); + } finally { + super.onDestroy(); + } + } + } + + @Override + public void onContentChanged() { + super.onContentChanged(); + RoboGuice.getInjector(this).injectViewMembers(this); + eventManager.fire(new OnContentChangedEvent(this)); + } + + @Override + protected void onResume() { + super.onResume(); + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + DebugLog.d(TAG + " ***** onSaveInstanceState() "); + if (getResources().getConfiguration().orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { + outState.putInt(STATE_ORIENTATION_KEY, Configuration.ORIENTATION_PORTRAIT); + } else { + outState.putInt(STATE_ORIENTATION_KEY, Configuration.ORIENTATION_LANDSCAPE); + } + super.onSaveInstanceState(outState); + } + + @Override + public void onBackPressed() { + if (getSupportFragmentManager().getBackStackEntryCount() <= 1) { + finish(); + } else { + super.onBackPressed(); + } + + } + + @Override + public Map, Object> getScopedObjectMap() { + return scopedObjects; + } +} + + diff --git a/app/src/main/java/com/akozlowski/doomvision/ui/SlidesGalleryFragment.java b/app/src/main/java/com/akozlowski/doomvision/ui/SlidesGalleryFragment.java new file mode 100644 index 0000000..8b029d8 --- /dev/null +++ b/app/src/main/java/com/akozlowski/doomvision/ui/SlidesGalleryFragment.java @@ -0,0 +1,168 @@ +package com.akozlowski.doomvision.ui; + +import android.os.Bundle; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentStatePagerAdapter; +import android.support.v4.view.ViewPager; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.LinearLayout; +import android.widget.TextView; + +import com.akozlowski.doomvision.R; +import com.akozlowski.doomvision.manager.DataManager; +import com.akozlowski.doomvision.pojo.Category; +import com.akozlowski.doomvision.pojo.Data; +import com.akozlowski.doomvision.pojo.Response; +import com.akozlowski.doomvision.util.DebugLog; + +import java.util.ArrayList; +import java.util.List; + +import roboguice.fragment.RoboFragment; +import roboguice.inject.InjectView; + +/** + * Created by akozlowski on 17/08/15. + */ +public class SlidesGalleryFragment extends RoboFragment { + private static final String TAG = SlidesGalleryFragment.class.getSimpleName(); + @InjectView(R.id.gallery_view_pager) + private ViewPager viewPager; + private List slides = new ArrayList<>(); + + @InjectView(R.id.gallery_image_indicator_layout) + private LinearLayout indicatorsLayout; + private List circleIndicators = new ArrayList(); + private int currentPagePosition = 0; + public static final String PAGE_INDEX_KEY = "page_index_key"; + @InjectView(R.id.details_description) + private TextView textViewDescription; + @InjectView(R.id.details_added_date) + private TextView textViewAddedDate; + @InjectView(R.id.details_image_type) + private TextView textViewImageType; + @InjectView(R.id.details_categories) + private TextView textViewCategories; + + @Override + public void onCreate(Bundle savedInstanceState) { + + super.onCreate(savedInstanceState); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + + return inflater.inflate(R.layout.slides_gallery_fragment, container, false); + } + + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + } + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + + } + + @Override + public void onResume() { + super.onResume(); + if (getArguments() != null) { + currentPagePosition = getArguments().getInt(PAGE_INDEX_KEY); + } + createViewPager(); + } + + + private void createViewPager() { + CustomScreenSlideAdapter pagerAdapter = new CustomScreenSlideAdapter(getChildFragmentManager()); + pagerAdapter.notifyDataSetChanged(); + viewPager.setAdapter(pagerAdapter); + Response response = DataManager.getInstance().getResponse(); + if (response == null) { + return; + } + indicatorsLayout.removeAllViews(); + slides.clear(); + + for (int i = 0; i < response.getData().size(); i++) { + createCircleIndicator(i == currentPagePosition, (LinearLayout.LayoutParams) indicatorsLayout.getLayoutParams()); + slides.add(ImageViewPageFragment.createInstance(i)); + } + viewPager.setOnPageChangeListener(createPageListener()); + viewPager.setCurrentItem(currentPagePosition); + pagerAdapter.notifyDataSetChanged(); + updateDetails(response.getData().get(currentPagePosition)); + } + + private void createCircleIndicator(boolean isSelected, LinearLayout.LayoutParams params) { + DebugLog.d(TAG + " createCircleIndicator()..isSelected: " + isSelected); + IndicatorView circleIndicatorView = new IndicatorView(getActivity(), R.color.getting_started_circle_indicator_stroke_color); + indicatorsLayout.addView(circleIndicatorView); + circleIndicatorView.getLayoutParams().width = (int) getActivity().getResources().getDimension(R.dimen.view_pager_page_width);//40; + circleIndicatorView.getLayoutParams().height = (int) getActivity().getResources().getDimension(R.dimen.view_pager_page_height);//40; + circleIndicatorView.setIsSelected(isSelected); + circleIndicators.add(circleIndicatorView); + } + + private ViewPager.OnPageChangeListener createPageListener() { + return new ViewPager.OnPageChangeListener() { + @Override + public void onPageSelected(int position) { + circleIndicators.get(currentPagePosition).setIsSelected(false); + circleIndicators.get(position).setIsSelected(true); + currentPagePosition = position; + updateDetails(DataManager.getInstance().getResponse().getData().get(currentPagePosition)); + } + + @Override + public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { /* unused */ } + + @Override + public void onPageScrollStateChanged(int state) { /* unused */ } + }; + } + + private void updateDetails(Data data) { + textViewAddedDate.setText(data.getAddedDate()); + setCategories(data.getCategories()); + textViewDescription.setText(data.getDescription()); + textViewImageType.setText(data.getImageType()); + + } + + private void setCategories(List categories) { + if (categories == null) return; + + StringBuilder sb = new StringBuilder(); + for (Category category : categories) { + sb.append(category.getName()); + sb.append(" "); + } + textViewCategories.setText(sb.toString()); + } + + class CustomScreenSlideAdapter extends FragmentStatePagerAdapter { + + public CustomScreenSlideAdapter(FragmentManager fm) { + super(fm); + } + + @Override + public android.support.v4.app.Fragment getItem(int position) { + return slides.get(position); + } + + @Override + public int getCount() { + return slides.size(); + } + } + +} diff --git a/app/src/main/java/com/akozlowski/doomvision/ui/dialog/SearchSettingDialog.java b/app/src/main/java/com/akozlowski/doomvision/ui/dialog/SearchSettingDialog.java new file mode 100644 index 0000000..824a119 --- /dev/null +++ b/app/src/main/java/com/akozlowski/doomvision/ui/dialog/SearchSettingDialog.java @@ -0,0 +1,27 @@ +package com.akozlowski.doomvision.ui.dialog; + +import android.app.Activity; +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.view.LayoutInflater; +import android.view.View; + +import com.akozlowski.doomvision.R; + +/** + * Created by akozlowski on 27/08/15. + */ +public class SearchSettingDialog { + public static AlertDialog createDialog(Activity activity, final DialogInterface.OnClickListener onClick) { + final AlertDialog.Builder builder = new AlertDialog.Builder(activity); + final LayoutInflater inflater = activity.getLayoutInflater(); + final View view = inflater.inflate(R.layout.search_dialog, null); + + final AlertDialog alertDialog = builder.create(); + builder.setView(view); + builder.setTitle(R.string.search_setting) + .setPositiveButton(R.string.btn_ok, onClick) + .setNegativeButton(R.string.btn_cancel, onClick); + return builder.show(); + } +} diff --git a/app/src/main/java/com/akozlowski/doomvision/ui/listView/CustomAdapter.java b/app/src/main/java/com/akozlowski/doomvision/ui/listView/CustomAdapter.java new file mode 100644 index 0000000..fa708b6 --- /dev/null +++ b/app/src/main/java/com/akozlowski/doomvision/ui/listView/CustomAdapter.java @@ -0,0 +1,50 @@ +package com.akozlowski.doomvision.ui.listView; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; + +import java.util.List; + +/** + * Created by akozlowski on 16/08/15. + */ +public class CustomAdapter extends ArrayAdapter { + private final Context context; + private final int resourceID; + private LayoutInflater mInflater; + + public CustomAdapter(Context context, int resource, List items) { + super(context, resource, items); + this.context = context; + this.mInflater = LayoutInflater.from(context); + this.resourceID = resource; + } + + @Override + public boolean areAllItemsEnabled() { + return false; + } + + @Override + public boolean isEnabled(int position) { + return false; + } + + @Override + public int getViewTypeCount() { + return Item.ItemType.values().length; + } + + @Override + public int getItemViewType(int position) { + return getItem(position).getViewType(); + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + return getItem(position).getView(mInflater, convertView, parent); + } +} diff --git a/app/src/main/java/com/akozlowski/doomvision/ui/listView/Item.java b/app/src/main/java/com/akozlowski/doomvision/ui/listView/Item.java new file mode 100644 index 0000000..14e9211 --- /dev/null +++ b/app/src/main/java/com/akozlowski/doomvision/ui/listView/Item.java @@ -0,0 +1,18 @@ +package com.akozlowski.doomvision.ui.listView; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +/** + * Created by akozlowski on 16/08/15. + */ +public interface Item { + int getViewType(); + + View getView(LayoutInflater inflater, View convertView, ViewGroup parent); + + enum ItemType { + IMAGE; + } +} diff --git a/app/src/main/java/com/akozlowski/doomvision/util/DebugLog.java b/app/src/main/java/com/akozlowski/doomvision/util/DebugLog.java new file mode 100644 index 0000000..18a96ee --- /dev/null +++ b/app/src/main/java/com/akozlowski/doomvision/util/DebugLog.java @@ -0,0 +1,86 @@ +package com.akozlowski.doomvision.util; + +import android.util.Log; + +/** + * Created by akozlowski on 14/08/15. + */ +public class DebugLog { + private static boolean SHOW_LOG = true; + public static final String LOG_TAG = "DOOM:LOG"; + + public static void enableLog(boolean enable) { + SHOW_LOG = enable; + } + + /** + * Logs a debug message in the application log. + * + * @param message the message to be logged + */ + public static void d(String message) { + if (SHOW_LOG) + Log.d(LOG_TAG, message); + } + + /** + * Logs an error message in the application log. + * + * @param message the message to be logged + */ + public static void e(String message) { + if (SHOW_LOG) + Log.e(LOG_TAG, message); + } + + /** + * Logs an error message in the application log. + * + * @param message the message to be logged + * @param throwable the {@link Throwable} to be logged + */ + public static void e(String message, Throwable throwable) { + if (SHOW_LOG) + Log.e(LOG_TAG, message, throwable); + } + + /** + * Logs an information message in the application log. + * + * @param message the message to be logged + */ + public static void i(String message) { + if (SHOW_LOG) + Log.i(LOG_TAG, message); + } + + /** + * Logs a verbose message in the application log. + * + * @param message the message to be logged + */ + public static void v(String message) { + if (SHOW_LOG) + Log.v(LOG_TAG, message); + } + + /** + * Logs a warning message in the application log. + * + * @param message the message to be logged + */ + public static void w(String message) { + if (SHOW_LOG) + Log.w(LOG_TAG, message); + } + + /** + * Logs a WTF message in the application log. + * + * @param message the message to be logged + */ + public static void wtf(String message) { + if (SHOW_LOG) + Log.wtf(LOG_TAG, message); + } +} diff --git a/app/src/main/java/com/akozlowski/doomvision/util/Density.java b/app/src/main/java/com/akozlowski/doomvision/util/Density.java new file mode 100644 index 0000000..86fe07c --- /dev/null +++ b/app/src/main/java/com/akozlowski/doomvision/util/Density.java @@ -0,0 +1,25 @@ +package com.akozlowski.doomvision.util; + +import android.content.Context; +import android.util.DisplayMetrics; + +/** + * Created by akozlowski on 17/08/15. + */ +public class Density { + public static float getDensityMultiplier(Context context) { + float densityMultiplier; + float densityScale = 1.0f / DisplayMetrics.DENSITY_DEFAULT; + + try { + densityMultiplier = densityScale * context.getResources().getDisplayMetrics().densityDpi; + } catch (NullPointerException e) { + DebugLog.e("Nullpointer", e); + return 1; + } + + DebugLog.i("DENSITY: multiplier: " + densityMultiplier); + + return densityMultiplier; + } +} diff --git a/app/src/main/res/drawable-hdpi/bg_tile_thumb.9.png b/app/src/main/res/drawable-hdpi/bg_tile_thumb.9.png new file mode 100644 index 0000000..c4f64c9 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/bg_tile_thumb.9.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_search_black_24dp.png b/app/src/main/res/drawable-hdpi/ic_search_black_24dp.png new file mode 100644 index 0000000..c593e7a Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_search_black_24dp.png differ diff --git a/app/src/main/res/drawable-xhdpi/bg_tile_thumb.9.png b/app/src/main/res/drawable-xhdpi/bg_tile_thumb.9.png new file mode 100644 index 0000000..be0c451 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/bg_tile_thumb.9.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_search_black_24dp.png b/app/src/main/res/drawable-xhdpi/ic_search_black_24dp.png new file mode 100644 index 0000000..6381902 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_search_black_24dp.png differ diff --git a/app/src/main/res/drawable-xxhdpi/bg_tile_thumb.9.png b/app/src/main/res/drawable-xxhdpi/bg_tile_thumb.9.png new file mode 100644 index 0000000..4a9a72a Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/bg_tile_thumb.9.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_search_black_24dp.png b/app/src/main/res/drawable-xxhdpi/ic_search_black_24dp.png new file mode 100644 index 0000000..3ae490e Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_search_black_24dp.png differ diff --git a/app/src/main/res/drawable/btn_search_selector.xml b/app/src/main/res/drawable/btn_search_selector.xml new file mode 100644 index 0000000..289de98 --- /dev/null +++ b/app/src/main/res/drawable/btn_search_selector.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/main_background_gradiant.xml b/app/src/main/res/drawable/main_background_gradiant.xml new file mode 100644 index 0000000..4d80f8d --- /dev/null +++ b/app/src/main/res/drawable/main_background_gradiant.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index a000def..53fffae 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,5 +1,4 @@ - diff --git a/app/src/main/res/layout/fragment_main.xml b/app/src/main/res/layout/fragment_main.xml deleted file mode 100644 index 6f07f14..0000000 --- a/app/src/main/res/layout/fragment_main.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - diff --git a/app/src/main/res/layout/image_item.xml b/app/src/main/res/layout/image_item.xml new file mode 100644 index 0000000..0dfc221 --- /dev/null +++ b/app/src/main/res/layout/image_item.xml @@ -0,0 +1,7 @@ + + diff --git a/app/src/main/res/layout/image_view_pager_fragment.xml b/app/src/main/res/layout/image_view_pager_fragment.xml new file mode 100644 index 0000000..9a49878 --- /dev/null +++ b/app/src/main/res/layout/image_view_pager_fragment.xml @@ -0,0 +1,19 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/list_view_content.xml b/app/src/main/res/layout/list_view_content.xml new file mode 100644 index 0000000..508d80d --- /dev/null +++ b/app/src/main/res/layout/list_view_content.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/list_view_gallery_fragment.xml b/app/src/main/res/layout/list_view_gallery_fragment.xml new file mode 100644 index 0000000..b47016b --- /dev/null +++ b/app/src/main/res/layout/list_view_gallery_fragment.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/search_dialog.xml b/app/src/main/res/layout/search_dialog.xml new file mode 100644 index 0000000..f4f7447 --- /dev/null +++ b/app/src/main/res/layout/search_dialog.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/slides_gallery_fragment.xml b/app/src/main/res/layout/slides_gallery_fragment.xml new file mode 100644 index 0000000..8830fcb --- /dev/null +++ b/app/src/main/res/layout/slides_gallery_fragment.xml @@ -0,0 +1,105 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml new file mode 100644 index 0000000..7067861 --- /dev/null +++ b/app/src/main/res/values/colors.xml @@ -0,0 +1,6 @@ + + + #FFFFFF + #74aace + #FFDDDDDD + \ No newline at end of file diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 47c8224..3e784f2 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -2,4 +2,7 @@ 16dp 16dp + 15dp + 15dp + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 743f2ac..e6fc376 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -2,4 +2,45 @@ DoomVision Hello world! Settings + Search + search images, vectors and videos .... + 8f80cdd74ddbef680339 + d1cc912295e23669be555fcadb02b4442b53be9e + No internet connection + image type + license + safe + sort + view + ok + cancel + search setting + description: + added Date: + categories: + --- + image type: + + + photo + ilustration + vector + + + + comercial + editorial + enhanced + + + + popular + newest + relevance + random + + + minimal + full + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 766ab99..e14d90d 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -2,7 +2,7 @@ diff --git a/app/src/test/java/com/akozlowski/doomvision/manager/RestManagerTest.java b/app/src/test/java/com/akozlowski/doomvision/manager/RestManagerTest.java new file mode 100644 index 0000000..7b50ed7 --- /dev/null +++ b/app/src/test/java/com/akozlowski/doomvision/manager/RestManagerTest.java @@ -0,0 +1,47 @@ +package com.akozlowski.doomvision.manager; + +import android.content.Context; +import android.os.Build; +import android.util.Base64; + +import com.akozlowski.doomvision.BuildConfig; +import com.akozlowski.doomvision.pojo.EchoTest; + +import junit.framework.Assert; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.annotation.Config; + +/** + * Created by akozlowski on 16/08/15. + */ +@RunWith(RobolectricGradleTestRunner.class) +@Config(constants = BuildConfig.class, manifest = "app/src/main/AndroidManifest.xml", sdk = Build.VERSION_CODES.JELLY_BEAN) +public class RestManagerTest { + + private static final String TEXT_TEST = "text test"; + @Mock + Base64 base64; + @Mock + Context mMockContext; + RestManager restManager; + private static final String CLIENT_ID = "8f80cdd74ddbef680339"; + private static final String CLIENT_SECRET = "d1cc912295e23669be555fcadb02b4442b53be9e"; + + @Before + public void setUp() throws Exception { + String source = CLIENT_ID + ":" + CLIENT_SECRET; + + restManager = new RestManager(mMockContext, Base64.encodeToString(source.getBytes(), Base64.URL_SAFE | Base64.NO_WRAP)); + } + + @Test + public void testEcho() { + EchoTest echoTest = restManager.test(TEXT_TEST); + Assert.assertNotNull(echoTest); + } +} \ No newline at end of file