Android: material design, API 21

This commit is contained in:
jendib 2014-11-19 01:18:42 +01:00
parent ffa7d796b5
commit 04752cab0c
22 changed files with 353 additions and 94 deletions

View File

@ -10,9 +10,10 @@
<configuration> <configuration>
<option name="SELECTED_BUILD_VARIANT" value="debug" /> <option name="SELECTED_BUILD_VARIANT" value="debug" />
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" /> <option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugJava" /> <option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" /> <option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
<option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" /> <option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
<option name="TEST_SOURCE_GEN_TASK_NAME" value="generateDebugTestSources" />
<option name="ALLOW_USER_CONFIGURATION" value="false" /> <option name="ALLOW_USER_CONFIGURATION" value="false" />
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" /> <option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" /> <option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
@ -22,58 +23,86 @@
</facet> </facet>
</component> </component>
<component name="NewModuleRootManager" inherit-compiler-output="false"> <component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/classes/debug" /> <output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
<exclude-output /> <exclude-output />
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/build/source/r/debug" isTestSource="false" generated="true" /> <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/source/aidl/debug" isTestSource="false" generated="true" /> <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/source/buildConfig/debug" isTestSource="false" generated="true" /> <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/source/rs/debug" isTestSource="false" generated="true" /> <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/res/rs/debug" type="java-resource" /> <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/source/r/test/debug" isTestSource="true" generated="true" /> <sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/source/aidl/test/debug" isTestSource="true" generated="true" /> <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/source/buildConfig/test/debug" isTestSource="true" generated="true" /> <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/source/rs/test/debug" isTestSource="true" generated="true" /> <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/res/rs/test/debug" type="java-test-resource" /> <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/test/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/test/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/apk" /> <excludeFolder url="file://$MODULE_DIR$/build/apk" />
<excludeFolder url="file://$MODULE_DIR$/build/assets" /> <excludeFolder url="file://$MODULE_DIR$/build/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/classes" /> <excludeFolder url="file://$MODULE_DIR$/build/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/dependency-cache" /> <excludeFolder url="file://$MODULE_DIR$/build/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/dex" />
<excludeFolder url="file://$MODULE_DIR$/build/incremental" /> <excludeFolder url="file://$MODULE_DIR$/build/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/libs" /> <excludeFolder url="file://$MODULE_DIR$/build/libs" />
<excludeFolder url="file://$MODULE_DIR$/build/manifests" /> <excludeFolder url="file://$MODULE_DIR$/build/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/ndk" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/pre-dexed" />
<excludeFolder url="file://$MODULE_DIR$/build/res" /> <excludeFolder url="file://$MODULE_DIR$/build/res" />
<excludeFolder url="file://$MODULE_DIR$/build/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/source" />
<excludeFolder url="file://$MODULE_DIR$/build/symbols" /> <excludeFolder url="file://$MODULE_DIR$/build/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" /> <excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content> </content>
<orderEntry type="jdk" jdkName="Android API 19 Platform" jdkType="Android SDK" /> <orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="android-async-http-1.4.4" level="project" /> <orderEntry type="library" exported="" name="recyclerview-v7-21.0.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-19.1.0" level="project" /> <orderEntry type="library" exported="" name="support-annotations-21.0.2" level="project" />
<orderEntry type="library" exported="" name="support-v4-21.0.2" level="project" />
<orderEntry type="library" exported="" name="android-query.0.26.8" level="project" /> <orderEntry type="library" exported="" name="android-query.0.26.8" level="project" />
<orderEntry type="library" exported="" name="acra-4.5.0" level="project" /> <orderEntry type="library" exported="" name="appcompat-v7-21.0.2" level="project" />
<orderEntry type="library" exported="" name="android-async-http-1.4.6" level="project" />
</component> </component>
</module> </module>

View File

@ -3,22 +3,22 @@ buildscript {
mavenCentral() mavenCentral()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:0.9.+' classpath 'com.android.tools.build:gradle:0.14.2'
} }
} }
apply plugin: 'android' apply plugin: 'com.android.application'
repositories { repositories {
mavenCentral() mavenCentral()
} }
android { android {
compileSdkVersion 19 compileSdkVersion 21
buildToolsVersion "19.1" buildToolsVersion "21.1"
defaultConfig { defaultConfig {
minSdkVersion 14 minSdkVersion 14
targetSdkVersion 19 targetSdkVersion 21
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
} }
@ -37,7 +37,7 @@ android {
dependencies { dependencies {
compile fileTree(dir: 'libs', include: '*.jar') compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.android.support:support-v4:19.1.0' compile 'com.android.support:appcompat-v7:21.0.2'
compile 'ch.acra:acra:4.5.0' compile 'com.android.support:recyclerview-v7:21.0.0'
compile 'com.loopj.android:android-async-http:1.4.4' compile 'com.loopj.android:android-async-http:1.4.6'
} }

View File

@ -0,0 +1,76 @@
package com.sismics.docs;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.View;
public class DividerItemDecoration extends RecyclerView.ItemDecoration {
private Drawable mDivider;
public DividerItemDecoration(Context context, AttributeSet attrs) {
final TypedArray a = context.obtainStyledAttributes(attrs, new int [] { android.R.attr.listDivider });
mDivider = a.getDrawable(0);
a.recycle();
}
public DividerItemDecoration(Drawable divider) { mDivider = divider; }
@Override
public void getItemOffsets (Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
super.getItemOffsets(outRect, view, parent, state);
if (mDivider == null) return;
if (parent.getChildPosition(view) < 1) return;
if (getOrientation(parent) == LinearLayoutManager.VERTICAL) outRect.top = mDivider.getIntrinsicHeight();
else outRect.left = mDivider.getIntrinsicWidth();
}
@Override
public void onDrawOver(Canvas c, RecyclerView parent) {
if (mDivider == null) { super.onDrawOver(c, parent); return; }
if (getOrientation(parent) == LinearLayoutManager.VERTICAL) {
final int left = parent.getPaddingLeft();
final int right = parent.getWidth() - parent.getPaddingRight();
final int childCount = parent.getChildCount();
for (int i=1; i < childCount; i++) {
final View child = parent.getChildAt(i);
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
final int size = mDivider.getIntrinsicHeight();
final int top = child.getTop() - params.topMargin;
final int bottom = top + size;
mDivider.setBounds(left, top, right, bottom);
mDivider.draw(c);
}
} else { //horizontal
final int top = parent.getPaddingTop();
final int bottom = parent.getHeight() - parent.getPaddingBottom();
final int childCount = parent.getChildCount();
for (int i=1; i < childCount; i++) {
final View child = parent.getChildAt(i);
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
final int size = mDivider.getIntrinsicWidth();
final int left = child.getLeft() - params.leftMargin;
final int right = left + size;
mDivider.setBounds(left, top, right, bottom);
mDivider.draw(c);
}
}
}
private int getOrientation(RecyclerView parent) {
if (parent.getLayoutManager() instanceof LinearLayoutManager) {
LinearLayoutManager layoutManager = (LinearLayoutManager) parent.getLayoutManager();
return layoutManager.getOrientation();
} else throw new IllegalStateException("DividerItemDecoration can only be used with a LinearLayoutManager.");
}
}

View File

@ -6,11 +6,6 @@ import com.androidquery.callback.BitmapAjaxCallback;
import com.sismics.docs.model.application.ApplicationContext; import com.sismics.docs.model.application.ApplicationContext;
import com.sismics.docs.util.PreferenceUtil; import com.sismics.docs.util.PreferenceUtil;
import org.acra.ACRA;
import org.acra.ReportingInteractionMode;
import org.acra.annotation.ReportsCrashes;
import org.acra.sender.HttpSender.Method;
import org.acra.sender.HttpSender.Type;
import org.json.JSONObject; import org.json.JSONObject;
/** /**
@ -18,20 +13,9 @@ import org.json.JSONObject;
* *
* @author bgamard * @author bgamard
*/ */
@ReportsCrashes(formKey = "",
httpMethod = Method.PUT,
reportType = Type.JSON,
formUri = "http://acralyzer.sismics.com/docs-report",
formUriBasicAuthLogin = "reporter",
formUriBasicAuthPassword = "jOS9ezJR",
mode = ReportingInteractionMode.TOAST,
forceCloseDialogAfterToast = true,
resToastText = R.string.crash_toast_text)
public class MainApplication extends Application { public class MainApplication extends Application {
@Override @Override
public void onCreate() { public void onCreate() {
ACRA.init(this);
// Fetching /user/info from cache // Fetching /user/info from cache
JSONObject json = PreferenceUtil.getCachedJson(getApplicationContext(), PreferenceUtil.PREF_CACHED_USER_INFO_JSON); JSONObject json = PreferenceUtil.getCachedJson(getApplicationContext(), PreferenceUtil.PREF_CACHED_USER_INFO_JSON);
ApplicationContext.getInstance().setUserInfo(getApplicationContext(), json); ApplicationContext.getInstance().setUserInfo(getApplicationContext(), json);

View File

@ -3,7 +3,7 @@ package com.sismics.docs.activity;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.v4.app.FragmentActivity; import android.support.v7.app.ActionBarActivity;
import android.text.Html; import android.text.Html;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.view.View; import android.view.View;
@ -30,7 +30,7 @@ import org.json.JSONObject;
* *
* @author bgamard * @author bgamard
*/ */
public class LoginActivity extends FragmentActivity { public class LoginActivity extends ActionBarActivity {
/** /**
* User interface. * User interface.
@ -93,7 +93,7 @@ public class LoginActivity extends FragmentActivity {
try { try {
UserResource.login(getApplicationContext(), txtUsername.getText().toString(), txtPassword.getText().toString(), new JsonHttpResponseHandler() { UserResource.login(getApplicationContext(), txtUsername.getText().toString(), txtPassword.getText().toString(), new JsonHttpResponseHandler() {
@Override @Override
public void onSuccess(JSONObject json) { public void onSuccess(int statusCode, Header[] headers, JSONObject json) {
// Empty previous user caches // Empty previous user caches
PreferenceUtil.resetUserCache(getApplicationContext()); PreferenceUtil.resetUserCache(getApplicationContext());
@ -109,11 +109,11 @@ public class LoginActivity extends FragmentActivity {
} }
@Override @Override
public void onFailure(final int statusCode, final Header[] headers, final byte[] responseBytes, final Throwable throwable) { public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
loginForm.setVisibility(View.VISIBLE); loginForm.setVisibility(View.VISIBLE);
progressBar.setVisibility(View.GONE); progressBar.setVisibility(View.GONE);
if (responseBytes != null && new String(responseBytes).contains("\"ForbiddenError\"")) { if (responseString != null && responseString.contains("\"ForbiddenError\"")) {
DialogUtil.showOkDialog(LoginActivity.this, R.string.login_fail_title, R.string.login_fail); DialogUtil.showOkDialog(LoginActivity.this, R.string.login_fail_title, R.string.login_fail);
} else { } else {
DialogUtil.showOkDialog(LoginActivity.this, R.string.network_error_title, R.string.network_error); DialogUtil.showOkDialog(LoginActivity.this, R.string.network_error_title, R.string.network_error);
@ -153,7 +153,7 @@ public class LoginActivity extends FragmentActivity {
// Trying to get user data // Trying to get user data
UserResource.info(getApplicationContext(), new JsonHttpResponseHandler() { UserResource.info(getApplicationContext(), new JsonHttpResponseHandler() {
@Override @Override
public void onSuccess(final JSONObject json) { public void onSuccess(int statusCode, Header[] headers, final JSONObject json) {
if (json.optBoolean("anonymous", true)) { if (json.optBoolean("anonymous", true)) {
loginForm.setVisibility(View.VISIBLE); loginForm.setVisibility(View.VISIBLE);
return; return;
@ -169,7 +169,7 @@ public class LoginActivity extends FragmentActivity {
} }
@Override @Override
public void onFailure(final int statusCode, final Header[] headers, final byte[] responseBytes, final Throwable throwable) { public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
DialogUtil.showOkDialog(LoginActivity.this, R.string.network_error_title, R.string.network_error); DialogUtil.showOkDialog(LoginActivity.this, R.string.network_error_title, R.string.network_error);
loginForm.setVisibility(View.VISIBLE); loginForm.setVisibility(View.VISIBLE);
} }

View File

@ -3,13 +3,11 @@ package com.sismics.docs.activity;
import android.content.Intent; import android.content.Intent;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout; import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBarDrawerToggle;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.Window;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.ListView; import android.widget.ListView;
@ -21,7 +19,7 @@ import com.sismics.docs.model.application.ApplicationContext;
* *
* @author bgamard * @author bgamard
*/ */
public class MainActivity extends FragmentActivity { public class MainActivity extends ActionBarActivity {
private ListView drawerList; private ListView drawerList;
private ActionBarDrawerToggle drawerToggle; private ActionBarDrawerToggle drawerToggle;
@ -38,7 +36,6 @@ public class MainActivity extends FragmentActivity {
} }
// Setup the activity // Setup the activity
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.main_activity); setContentView(R.layout.main_activity);
// Cache view references // Cache view references
@ -53,30 +50,16 @@ public class MainActivity extends FragmentActivity {
}); });
if (drawerLayout != null) { if (drawerLayout != null) {
// Set a custom shadow that overlays the main content when the drawer opens
drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
// Enable ActionBar app icon to behave as action to toggle nav drawer // Enable ActionBar app icon to behave as action to toggle nav drawer
getActionBar().setDisplayHomeAsUpEnabled(true); if (getSupportActionBar() != null) {
getActionBar().setHomeButtonEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
}
// ActionBarDrawerToggle ties together the the proper interactions // ActionBarDrawerToggle ties together the the proper interactions
// between the sliding drawer and the action bar app icon // between the sliding drawer and the action bar app icon
drawerToggle = new ActionBarDrawerToggle( drawerToggle = new ActionBarDrawerToggle(this, drawerLayout,
this, /* host Activity */ R.string.drawer_open, R.string.drawer_close);
drawerLayout, /* DrawerLayout object */
R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) {
@Override
public void onDrawerOpened(View drawerView) {
invalidateOptionsMenu();
}
@Override
public void onDrawerClosed(View drawerView) {
invalidateOptionsMenu();
}
};
drawerLayout.setDrawerListener(drawerToggle); drawerLayout.setDrawerListener(drawerToggle);
} }
} }

View File

@ -0,0 +1,60 @@
package com.sismics.docs.adapter;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.sismics.docs.R;
/**
* Adapter of documents.
*
* @author bgamard
*/
public class DocListAdapter extends RecyclerView.Adapter<DocListAdapter.ViewHolder> {
private String[] mDataset;
// Provide a reference to the views for each data item
// Complex data items may need more than one view per item, and
// you provide access to all the views for a data item in a view holder
public static class ViewHolder extends RecyclerView.ViewHolder {
// each data item is just a string in this case
public TextView titleTextView;
public TextView subtitleTextView;
public ViewHolder(View v) {
super(v);
}
}
// Provide a suitable constructor (depends on the kind of dataset)
public DocListAdapter(String[] myDataset) {
mDataset = myDataset;
}
// Create new views (invoked by the layout manager)
@Override
public DocListAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
// create a new view
View v = LayoutInflater.from(parent.getContext()).
inflate(R.layout.doc_list_item, parent, false);
// set the view's size, margins, paddings and layout parameters
return new ViewHolder(v);
}
// Replace the contents of a view (invoked by the layout manager)
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
// - get element from your dataset at this position
// - replace the contents of the view with that element
// holder.mTextView.setText(mDataset[position]);
}
// Return the size of your dataset (invoked by the layout manager)
@Override
public int getItemCount() {
return mDataset.length;
}
}

View File

@ -0,0 +1,47 @@
package com.sismics.docs.fragment;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import com.sismics.docs.DividerItemDecoration;
import com.sismics.docs.R;
import com.sismics.docs.adapter.DocListAdapter;
import com.sismics.docs.listener.RecyclerItemClickListener;
/**
* @author bgamard.
*/
public class DocListFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.doc_list_fragment, container, false);
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.docList);
recyclerView.setHasFixedSize(true);
recyclerView.setLongClickable(true);
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(layoutManager);
RecyclerView.Adapter adapter = new DocListAdapter(new String[] { "Doc 1", "Doc 2", "Doc 3"});
recyclerView.setAdapter(adapter);
recyclerView.addItemDecoration(new DividerItemDecoration(getResources().getDrawable(R.drawable.abc_list_divider_mtrl_alpha)));
recyclerView.addOnItemTouchListener(new RecyclerItemClickListener(getActivity(), new RecyclerItemClickListener.OnItemClickListener() {
@Override
public void onItemClick(View view, int position) {
Toast.makeText(getActivity(), position + " clicked", Toast.LENGTH_SHORT).show();
}
}));
return view;
}
}

View File

@ -0,0 +1,37 @@
package com.sismics.docs.listener;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
public class RecyclerItemClickListener implements RecyclerView.OnItemTouchListener {
private OnItemClickListener mListener;
public interface OnItemClickListener {
public void onItemClick(View view, int position);
}
GestureDetector mGestureDetector;
public RecyclerItemClickListener(Context context, OnItemClickListener listener) {
mListener = listener;
mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
@Override public boolean onSingleTapUp(MotionEvent e) {
return true;
}
});
}
@Override public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) {
View childView = view.findChildViewUnder(e.getX(), e.getY());
if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) {
mListener.onItemClick(childView, view.getChildPosition(childView));
}
return false;
}
@Override public void onTouchEvent(RecyclerView view, MotionEvent motionEvent) { }
}

View File

@ -8,6 +8,7 @@ import com.sismics.docs.listener.CallbackListener;
import com.sismics.docs.resource.UserResource; import com.sismics.docs.resource.UserResource;
import com.sismics.docs.util.PreferenceUtil; import com.sismics.docs.util.PreferenceUtil;
import org.apache.http.Header;
import org.json.JSONObject; import org.json.JSONObject;
/** /**
@ -47,7 +48,7 @@ public class ApplicationContext {
/** /**
* Returns true if current user is logged in. * Returns true if current user is logged in.
* *
* @return * @return True if the current user is logged in
*/ */
public boolean isLoggedIn() { public boolean isLoggedIn() {
return userInfo != null && !userInfo.optBoolean("anonymous"); return userInfo != null && !userInfo.optBoolean("anonymous");
@ -56,7 +57,7 @@ public class ApplicationContext {
/** /**
* Getter of userInfo * Getter of userInfo
* *
* @return * @return userInfo
*/ */
public JSONObject getUserInfo() { public JSONObject getUserInfo() {
return userInfo; return userInfo;
@ -65,7 +66,7 @@ public class ApplicationContext {
/** /**
* Setter of userInfo * Setter of userInfo
* *
* @param json * @param json userInfo
*/ */
public void setUserInfo(Context context, JSONObject json) { public void setUserInfo(Context context, JSONObject json) {
this.userInfo = json; this.userInfo = json;
@ -75,13 +76,13 @@ public class ApplicationContext {
/** /**
* Asynchronously get user info. * Asynchronously get user info.
* *
* @param activity * @param activity Activity
* @param callbackListener * @param callbackListener CallbackListener
*/ */
public void fetchUserInfo(final Activity activity, final CallbackListener callbackListener) { public void fetchUserInfo(final Activity activity, final CallbackListener callbackListener) {
UserResource.info(activity.getApplicationContext(), new JsonHttpResponseHandler() { UserResource.info(activity.getApplicationContext(), new JsonHttpResponseHandler() {
@Override @Override
public void onSuccess(final JSONObject json) { public void onSuccess(int statusCode, Header[] headers, final JSONObject json) {
// Save data in application context // Save data in application context
if (!json.optBoolean("anonymous", true)) { if (!json.optBoolean("anonymous", true)) {
setUserInfo(activity.getApplicationContext(), json); setUserInfo(activity.getApplicationContext(), json);

View File

@ -65,6 +65,7 @@ public class BaseResource {
/** /**
* Resource initialization. * Resource initialization.
*
* @param context Context * @param context Context
*/ */
protected static void init(Context context) { protected static void init(Context context) {
@ -122,6 +123,7 @@ public class BaseResource {
/** /**
* Returns cleaned API URL. * Returns cleaned API URL.
*
* @param context Context * @param context Context
* @return Cleaned API URL * @return Cleaned API URL
*/ */

View File

@ -14,6 +14,7 @@ public class UserResource extends BaseResource {
/** /**
* POST /user/login. * POST /user/login.
*
* @param context Context * @param context Context
* @param username Username * @param username Username
* @param password Password * @param password Password
@ -31,6 +32,7 @@ public class UserResource extends BaseResource {
/** /**
* GET /user. * GET /user.
*
* @param context Context * @param context Context
* @param responseHandler Callback * @param responseHandler Callback
*/ */
@ -43,6 +45,7 @@ public class UserResource extends BaseResource {
/** /**
* POST /user/logout. * POST /user/logout.
*
* @param context Context * @param context Context
* @param responseHandler Callback * @param responseHandler Callback
*/ */

View File

@ -73,7 +73,7 @@ public class PreferenceUtil {
*/ */
public static void setCachedJson(Context context, String key, JSONObject json) { public static void setCachedJson(Context context, String key, JSONObject json) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
sharedPreferences.edit().putString(key, json != null ? json.toString() : null).commit(); sharedPreferences.edit().putString(key, json != null ? json.toString() : null).apply();
} }
/** /**
@ -98,7 +98,7 @@ public class PreferenceUtil {
*/ */
public static void setServerUrl(Context context, String serverUrl) { public static void setServerUrl(Context context, String serverUrl) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
sharedPreferences.edit().putString(PREF_SERVER_URL, serverUrl).commit(); sharedPreferences.edit().putString(PREF_SERVER_URL, serverUrl).apply();
} }
/** /**
@ -108,8 +108,7 @@ public class PreferenceUtil {
public static void resetUserCache(Context context) { public static void resetUserCache(Context context) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
Editor editor = sharedPreferences.edit(); Editor editor = sharedPreferences.edit();
editor.putString(PREF_CACHED_USER_INFO_JSON, null); editor.putString(PREF_CACHED_USER_INFO_JSON, null).apply();
editor.commit();
} }
/** /**

Binary file not shown.

Before

Width:  |  Height:  |  Size: 171 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 182 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/docList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical">
</android.support.v7.widget.RecyclerView>

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="12dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:text="Facture Amazon"
android:textColor="#212121"
android:textSize="16sp"/>
<TextView
android:layout_marginTop="4dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:text="Appartement, Caluire"
android:textColor="#777777"
android:textSize="16sp"/>
</LinearLayout>

View File

@ -6,10 +6,11 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<FrameLayout <fragment
android:id="@+id/content_frame" android:id="@+id/main_fragment"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent"
class="com.sismics.docs.fragment.DocListFragment"/>
<LinearLayout <LinearLayout
android:id="@+id/left_drawer" android:id="@+id/left_drawer"

View File

@ -1,8 +1,10 @@
<resources> <resources>
<!-- Base application theme. --> <!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Holo.Light"> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. --> <item name="colorPrimary">#263238</item>
<item name="colorPrimaryDark">#21272b</item>
<item name="colorAccent">#009688</item>
</style> </style>
</resources> </resources>

View File

@ -1,6 +1,6 @@
#Sun May 04 15:32:34 CEST 2014 #Tue Nov 18 23:58:08 CET 2014
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.10-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-2.1-all.zip