Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vadim Semenov, 2539 #40

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3b1e94f
.gitignore added
vadimsemenov Jan 16, 2015
a8a5452
Initial commit
vadimsemenov Jan 16, 2015
3acee9e
Adapter and Holder were added
vadimsemenov Jan 16, 2015
e97d91b
Spaghetti-Downloader was added
vadimsemenov Jan 18, 2015
269ec3e
Database was added
vadimsemenov Jan 18, 2015
7b680f1
Small fixes
vadimsemenov Jan 18, 2015
2545521
Downloaders were added
vadimsemenov Jan 18, 2015
f4cae0a
Loader was added
vadimsemenov Jan 18, 2015
9742d83
Memory utils were added
vadimsemenov Jan 18, 2015
e513f1e
DisplayPhotoActivity was added
vadimsemenov Jan 18, 2015
f8b246d
Database and memory cleaning were added
vadimsemenov Jan 18, 2015
edb7bf3
*.apk was added
vadimsemenov Jan 18, 2015
1dee88d
Code cleaning, minor bug fixes
vadimsemenov Jan 22, 2015
a342a88
Save photo on SD added
vadimsemenov Jan 22, 2015
c162c90
Available to set wallpaper
vadimsemenov Jan 22, 2015
1410956
Now you can open image in browser
vadimsemenov Jan 22, 2015
0cdd5f6
*.apk were added
vadimsemenov Jan 22, 2015
8f5a603
Update README
vadimsemenov Dec 15, 2015
c999981
Update project to SDK23; replace legacy org.apache.http.* with modern…
vadimsemenov Dec 15, 2015
c716885
Update file headers
vadimsemenov Jan 26, 2016
e37d981
Minor changes, cleanup from warnings
vadimsemenov Jan 26, 2016
c17ae5e
Update target SDK to 22, to avoid problems with Runtime Permission
vadimsemenov Jan 27, 2016
fd8ef5c
Move .refresh() from UI-thread to AsyncTask
vadimsemenov Jan 27, 2016
f2561c7
*.apk added
vadimsemenov Jan 27, 2016
1cce28a
New *.apk
vadimsemenov Jan 27, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.*
!.gitignore
*.iml
6 changes: 6 additions & 0 deletions PhotooftheDay/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
1 change: 1 addition & 0 deletions PhotooftheDay/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
26 changes: 26 additions & 0 deletions PhotooftheDay/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "21.1.2"

defaultConfig {
applicationId "ru.ifmo.md.photooftheday"
minSdkVersion 19
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.google.android.gms:play-services-appindexing:8.4.0'
}
17 changes: 17 additions & 0 deletions PhotooftheDay/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package ru.ifmo.md.photooftheday;

import android.app.Application;
import android.test.ApplicationTestCase;

/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}
47 changes: 47 additions & 0 deletions PhotooftheDay/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ru.ifmo.md.photooftheday" >


<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.SET_WALLPAPER" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<provider
android:name=".photodatabase.PhotoProvider"
android:authorities="ru.ifmo.md.photooftheday.photodatabase.PhotoProvider"
android:exported="false" />

<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="orientation|screenSize" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".DisplayPhotoActivity"
android:label="@string/title_activity_display_photo"
android:configChanges="orientation|screenSize"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="ru.ifmo.md.photooftheday.MainActivity" />
</activity>
<!-- ATTENTION: This was auto-generated to add Google Play services to your project for
App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. -->
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
package ru.ifmo.md.photooftheday;

import android.app.Activity;
import android.app.WallpaperManager;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.Toast;

import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.common.api.GoogleApiClient;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

import ru.ifmo.md.photooftheday.memoryutils.FilesUtils;

/**
* @author Vadim Semenov <[email protected]>
*/
public class DisplayPhotoActivity extends Activity {
public static final String TAG = DisplayPhotoActivity.class.getSimpleName();

private Photo photo;
/**
* ATTENTION: This was auto-generated to implement the App Indexing API.
* See https://g.co/AppIndexing/AndroidStudio for more information.
*/
private GoogleApiClient client;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_photo);
ImageView imageView = (ImageView) findViewById(R.id.full_image_view);
photo = getIntent().getParcelableExtra(MainActivity.PHOTO);
imageView.setImageBitmap(photo.getFullBitmap());
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}

@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_display_photo, 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();

if (id == R.id.action_save) {
File input = photo.getPathToFullBitmap();
FileChannel src = null;
try {
src = new FileInputStream(input).getChannel();
} catch (FileNotFoundException e) {
Log.e(TAG, e.getMessage(), e);
}
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
if (!FilesUtils.isExternalStorageWritable()) {
Log.e(TAG, "External storage is not writable");
Toast.makeText(this, getString(R.string.photo_not_saved), Toast.LENGTH_SHORT).show();
}

File output = FilesUtils.createFile(path, photo.name + ".png");
if (output == null) throw new AssertionError("bad path [" + path + "]");
FileChannel dest = null;
try {
dest = new FileOutputStream(output).getChannel();
} catch (FileNotFoundException e) {
Log.e(TAG, e.getMessage(), e);
}

boolean saved = false;
if (src != null && dest != null) {
try {
dest.transferFrom(src, 0, src.size());
saved = true;
} catch (IOException e) {
Log.e(TAG, e.getMessage(), e);
}
}
if (saved) {
Toast.makeText(this, getString(R.string.photo_saved), Toast.LENGTH_SHORT).show();
} else {
Log.e(TAG, "Can not save this photo");
Toast.makeText(this, getString(R.string.photo_not_saved), Toast.LENGTH_SHORT).show();
}
try {
if (src != null) {
src.close();
}
if (dest != null) {
dest.close();
}
} catch (IOException e) {
Log.e(TAG, e.getMessage(), e);
}
} else if (id == R.id.action_set_wallpaper) {
try {
WallpaperManager.getInstance(getApplicationContext()).setBitmap(photo.getFullBitmap());
Toast.makeText(this, getString(R.string.wallpaper_set), Toast.LENGTH_SHORT).show();
} catch (IOException e) {
Log.e(TAG, e.getMessage(), e);
Toast.makeText(this, getString(R.string.wallpaper_not_set), Toast.LENGTH_SHORT).show();
}
} else if (id == R.id.action_open_in_browser) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(photo.fullUrl.toString()));
startActivity(browserIntent);
}

return super.onOptionsItemSelected(item);
}

@Override
public void onStart() {
super.onStart();

// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client.connect();
Action viewAction = Action.newAction(
Action.TYPE_VIEW, // TODO: choose an action type.
"DisplayPhoto Page", // TODO: Define a title for the content shown.
// TODO: If you have web page content that matches this app activity's content,
// make sure this auto-generated web page URL is correct.
// Otherwise, set the URL to null.
Uri.parse("http://host/path"),
// TODO: Make sure this auto-generated app deep link URI is correct.
Uri.parse("android-app://ru.ifmo.md.photooftheday/http/host/path")
);
AppIndex.AppIndexApi.start(client, viewAction);
}

@Override
public void onStop() {
super.onStop();

// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
Action viewAction = Action.newAction(
Action.TYPE_VIEW, // TODO: choose an action type.
"DisplayPhoto Page", // TODO: Define a title for the content shown.
// TODO: If you have web page content that matches this app activity's content,
// make sure this auto-generated web page URL is correct.
// Otherwise, set the URL to null.
Uri.parse("http://host/path"),
// TODO: Make sure this auto-generated app deep link URI is correct.
Uri.parse("android-app://ru.ifmo.md.photooftheday/http/host/path")
);
AppIndex.AppIndexApi.end(client, viewAction);
client.disconnect();
}
}
Loading