Remove LLM dependency

This commit is contained in:
serso 2016-03-02 07:28:15 +01:00
parent ba6480d101
commit c661775772
6 changed files with 185 additions and 22 deletions

View File

@ -92,7 +92,6 @@ dependencies {
exclude(module: 'xpp3')
}
compile 'com.jakewharton:butterknife:7.0.1'
compile 'org.solovyev.android.views:linear-layout-manager:0.5@aar'
compile 'com.google.dagger:dagger:2.0.2'
apt "com.google.dagger:dagger-compiler:2.0.2"

View File

@ -36,8 +36,11 @@ import android.widget.TextView;
import butterknife.Bind;
import butterknife.ButterKnife;
import org.solovyev.android.Check;
import org.solovyev.android.calculator.*;
import org.solovyev.android.views.llm.DividerItemDecoration;
import org.solovyev.android.calculator.BaseFragment;
import org.solovyev.android.calculator.CalculatorActivity;
import org.solovyev.android.calculator.Keyboard;
import org.solovyev.android.calculator.R;
import org.solovyev.android.views.DividerItemDecoration;
import org.solovyev.common.math.MathEntity;
import org.solovyev.common.text.Strings;

View File

@ -40,7 +40,7 @@ import com.squareup.otto.Subscribe;
import org.solovyev.android.Check;
import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.jscl.JsclOperation;
import org.solovyev.android.views.llm.DividerItemDecoration;
import org.solovyev.android.views.DividerItemDecoration;
import org.solovyev.common.text.Strings;
import javax.annotation.Nonnull;

View File

@ -3,13 +3,12 @@ package org.solovyev.android.calculator.plot;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.*;
import android.widget.TextView;
@ -23,8 +22,7 @@ import org.solovyev.android.plotter.BasePlotterListener;
import org.solovyev.android.plotter.PlotFunction;
import org.solovyev.android.plotter.PlotIconView;
import org.solovyev.android.plotter.Plotter;
import org.solovyev.android.views.llm.DividerItemDecoration;
import org.solovyev.android.views.llm.LinearLayoutManager;
import org.solovyev.android.views.DividerItemDecoration;
import javax.annotation.Nonnull;
import javax.inject.Inject;
@ -64,27 +62,15 @@ public class PlotFunctionsFragment extends BaseDialogFragment {
@NonNull
protected RecyclerView onCreateDialogView(@NonNull Context context, @NonNull LayoutInflater inflater, Bundle savedInstanceState) {
@SuppressLint("InflateParams") final RecyclerView view = (RecyclerView) inflater.inflate(R.layout.fragment_functions, null);
final LinearLayoutManager layoutManager = new LinearLayoutManager(context, VERTICAL, false);
final int itemHeight = context.getResources().getDimensionPixelSize(R.dimen.list_item_height);
layoutManager.setChildSize(itemHeight + getDividerHeight(context));
view.setLayoutManager(layoutManager);
@SuppressLint("InflateParams") final RecyclerView view = (RecyclerView) inflater.inflate(R.layout.fragment_plot_functions, null);
view.setLayoutManager(new LinearLayoutManager(context, VERTICAL, false));
view.addItemDecoration(new DividerItemDecoration(context, null));
adapter = new Adapter(plotter.getPlotData().functions);
view.setAdapter(adapter);
return view;
}
private int getDividerHeight(@NonNull Context context) {
final TypedArray a = context.obtainStyledAttributes(null, new int[]{android.R.attr.listDivider});
final Drawable divider = a.getDrawable(0);
final int dividerHeight = divider == null ? 0 : divider.getIntrinsicHeight();
a.recycle();
return dividerHeight;
}
@Override
public void onDestroyView() {
plotter.removeListener(plotterListener);

View File

@ -0,0 +1,175 @@
/*
* Copyright 2015 serso aka se.solovyev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* Contact details
*
* Email: se.solovyev@gmail.com
* Site: http://se.solovyev.org
*/
package org.solovyev.android.views;
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 divider;
private int dividerHeight;
private int dividerWidth;
private boolean first = false;
private boolean last = false;
@SuppressWarnings("UnusedDeclaration")
public DividerItemDecoration(Context context, AttributeSet attrs) {
final TypedArray a = context.obtainStyledAttributes(attrs, new int[]{android.R.attr.listDivider});
setDivider(a.getDrawable(0));
a.recycle();
}
@SuppressWarnings("UnusedDeclaration")
public DividerItemDecoration(Context context, AttributeSet attrs, boolean showFirstDivider,
boolean showLastDivider) {
this(context, attrs);
first = showFirstDivider;
last = showLastDivider;
}
@SuppressWarnings("UnusedDeclaration")
public DividerItemDecoration(Drawable divider) {
setDivider(divider);
}
@SuppressWarnings("UnusedDeclaration")
public DividerItemDecoration(Drawable divider, boolean showFirstDivider,
boolean showLastDivider) {
this(divider);
first = showFirstDivider;
last = showLastDivider;
}
private void setDivider(Drawable divider) {
this.divider = divider;
this.dividerHeight = divider == null ? 0 : divider.getIntrinsicHeight();
this.dividerWidth = divider == null ? 0 : divider.getIntrinsicWidth();
}
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent,
RecyclerView.State state) {
if (divider == null) {
super.getItemOffsets(outRect, view, parent, state);
return;
}
final int position = ((RecyclerView.LayoutParams) view.getLayoutParams()).getViewLayoutPosition();
final boolean firstItem = position == 0;
final boolean lastItem = position == parent.getAdapter().getItemCount() - 1;
final boolean dividerBefore = first || !firstItem;
final boolean dividerAfter = last && lastItem;
if (getOrientation(parent) == LinearLayoutManager.VERTICAL) {
outRect.top = dividerBefore ? dividerHeight : 0;
outRect.bottom = dividerAfter ? dividerHeight : 0;
} else {
outRect.left = dividerBefore ? dividerWidth : 0;
outRect.right = dividerAfter ? dividerWidth : 0;
}
}
@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
if (divider == null) {
super.onDraw(c, parent, state);
return;
}
int left = 0;
int right = 0;
int top = 0;
int bottom = 0;
final int orientation = getOrientation(parent);
final int childCount = parent.getChildCount();
final RecyclerView.Adapter adapter = parent.getAdapter();
final int adapterCount = adapter != null ? adapter.getItemCount() : 0;
final boolean vertical = orientation == LinearLayoutManager.VERTICAL;
final int size;
if (vertical) {
size = dividerHeight;
left = parent.getPaddingLeft();
right = parent.getWidth() - parent.getPaddingRight();
} else {
size = dividerWidth;
top = parent.getPaddingTop();
bottom = parent.getHeight() - parent.getPaddingBottom();
}
for (int i = 0; i < childCount; i++) {
final View child = parent.getChildAt(i);
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
final int position = params.getViewLayoutPosition();
if (position == 0 && !first) {
continue;
}
if (vertical) {
top = child.getTop() - params.topMargin - size;
bottom = top + size;
} else {
left = child.getLeft() - params.leftMargin - size;
right = left + size;
}
divider.setBounds(left, top, right, bottom);
divider.draw(c);
}
if (last && childCount > 0) {
final View child = parent.getChildAt(childCount - 1);
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
final int position = params.getViewLayoutPosition();
if (position == adapterCount - 1) {
if (vertical) {
top = child.getBottom() + params.bottomMargin;
bottom = top + size;
} else {
left = child.getRight() + params.rightMargin;
right = left + size;
}
divider.setBounds(left, top, right, bottom);
divider.draw(c);
}
}
}
private int getOrientation(RecyclerView parent) {
final RecyclerView.LayoutManager lm = parent.getLayoutManager();
if (lm instanceof LinearLayoutManager) {
return ((LinearLayoutManager) lm).getOrientation();
} else {
throw new IllegalStateException("DividerItemDecoration can only be used with a LinearLayoutManager");
}
}
}